Skip to content

Commit 765dd33

Browse files
authored
Merge pull request #48 from UnstableDesign/ml_datagen
Ml datagen
2 parents 5eec1d4 + 506081e commit 765dd33

12 files changed

+544
-281
lines changed

src/app/core/model/draft.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ export class Draft{
969969
* @param i: the tieups array, j: the treadling array, the threading array
970970
* @returns (nothing) in the future - this can return the specific points to update on the draft
971971
*/
972-
recalculateDraft(tieup, treadling, threading) {
972+
recalculateDraft(tieup: Array<Array<boolean>>, treadling: Array<number>, threading: Array<number>) {
973973
for (var i = 0; i < treadling.length;i++) {
974974
var active_treadle = treadling[i];
975975
if (active_treadle != -1) {

src/app/core/topbar/topbar.component.html

+6-9
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,26 @@
1919

2020
<span class="right">
2121

22-
<button mat-icon-button matTooltip ="print screen">
23-
<a class="print-link" #printLink (click)="saveAsPrint($event)" mat-menu-item>
22+
<button mat-icon-button matTooltip ="print screen" (click)="saveAsPrint()" >
2423
<i class="fas fa-print"></i>
25-
</a>
2624
</button>
2725

2826

2927
<button mat-icon-button
3028
[matMenuTriggerFor]="downloadDropdown"
31-
matTooltip ="save current file"
29+
matTooltip ="export adacad workspace"
3230
>
3331
<i class="fas fa-download"></i>
3432
</button>
3533
<mat-menu #downloadDropdown mat-raised-button>
36-
37-
<a #bmpLink (click)="saveAsBmp($event)" mat-menu-item> as Bitmap</a>
38-
<a #adaLink (click)="saveAsAda($event)" mat-menu-item> as AdaCAD file</a>
39-
<a #wifLink (click)="saveAsWif($event)" mat-menu-item> as Wif file</a>
34+
<a (click)="saveAsAda()" mat-menu-item> as AdaCAD workspace file</a>
35+
<a (click)="saveAsBmp()" mat-menu-item> export all visible drafts as bitmaps</a>
36+
<a (click)="saveAsWif()" mat-menu-item> export all visible drafts as .WIF files</a>
4037
</mat-menu>
4138

4239

4340
<button mat-icon-button="Open"
44-
matTooltip ="open or start a new draft"
41+
matTooltip ="open a new workspace"
4542
(click)="openNewFileDialog(null)">
4643
<i class="fas fa-folder-open"></i>
4744
</button>

src/app/core/topbar/topbar.component.ts

+1-22
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,19 @@ export class TopbarComponent implements OnInit {
2828
@Input() loomtypes;
2929
@Input() density_units;
3030
@Input() source;
31-
32-
@ViewChild('bmpLink', {static: true}) bmpLink: any;
33-
@ViewChild('adaLink', {static: true}) adaLink: any;
34-
@ViewChild('wifLink', {static: true}) wifLink: any;
35-
@ViewChild('printLink', {static: true}) printLink: any;
36-
37-
downloadBmp: ElementRef;
38-
downloadAda: ElementRef;
39-
downloadWif: ElementRef;
40-
downloadPrint: ElementRef;
41-
4231

4332
constructor(private dialog: MatDialog) { }
4433

4534
ngOnInit(){
4635
}
4736

4837
ngAfterViewInit() {
49-
if(this.source == 'weaver'){
50-
this.downloadBmp = this.bmpLink._elementRef;
51-
this.downloadWif = this.wifLink._elementRef;
52-
}
53-
this.downloadAda = this.adaLink._elementRef;
54-
this.downloadPrint = this.printLink._elementRef;
38+
5539
}
5640

5741
public saveAsBmp(e: any) {
5842
var obj: any = {
5943
name: this.filename,
60-
downloadLink: this.downloadBmp,
6144
type: "bmp"
6245
}
6346
console.log(obj);
@@ -67,7 +50,6 @@ export class TopbarComponent implements OnInit {
6750
public saveAsAda(e: any) {
6851
var obj: any = {
6952
name: this.filename,
70-
downloadLink: this.downloadAda,
7153
type: "ada"
7254
}
7355
console.log(obj);
@@ -77,17 +59,14 @@ export class TopbarComponent implements OnInit {
7759
public saveAsWif(e: any) {
7860
var obj: any = {
7961
name: this.filename,
80-
downloadLink: this.downloadWif,
8162
type: "wif"
8263
}
83-
console.log(obj);
8464
this.onSave.emit(obj);
8565
}
8666

8767
public saveAsPrint(e: any) {
8868
var obj: any = {
8969
name: this.filename,
90-
downloadLink: this.downloadPrint,
9170
type: "jpg"
9271
}
9372
this.onSave.emit(obj);

src/app/mixer/mixer.component.ts

+18-23
Original file line numberDiff line numberDiff line change
@@ -422,42 +422,28 @@ export class MixerComponent implements OnInit {
422422
* @param {Event} e - Press Control + x
423423
* @returns {void}
424424
*/
425-
// @HostListener('window:keydown.p', ['$event'])
426-
// private keyEventPaste(e) {
427-
// this.onPaste({});
428-
// }
429-
430-
431-
// /**
432-
// * this is called when import has been called from the sidebar
433-
// * @param result
434-
// */
435-
// public draftUploaded(result: LoadResponse){
436-
437-
// console.log("import", result);
438-
// const data: FileObj = result.data;
439425

440-
// data.drafts.forEach().
441-
442-
// const draft: Draft = new Draft(result);
443-
// this.palette.addSubdraftFromDraft(draft);
444-
// }
445426

446427
/**
447428
* this is called when a user pushes bring from the topbar
448429
* @param event
449-
* @todo add interface to select which draft to export if BMP or WIF
450430
*/
451-
public onSave(e: any){
431+
public async onSave(e: any) : Promise<any>{
432+
433+
const link = document.createElement('a')
452434

453-
console.log(e);
454-
let link = e.downloadLink.nativeElement;
455435

456436
switch(e.type){
457437
case 'jpg':
458438
link.href = this.fs.saver.jpg(this.palette.getPrintableCanvas(e));
459439
link.download = e.name + ".jpg";
460440
this.palette.clearCanvas();
441+
link.click();
442+
443+
break;
444+
445+
case 'wif':
446+
this.palette.downloadVisibleDraftsAsWif();
461447
break;
462448

463449
case 'ada':
@@ -467,7 +453,16 @@ export class MixerComponent implements OnInit {
467453
[],
468454
false);
469455
link.download = e.name + ".ada";
456+
link.click();
457+
break;
458+
459+
case 'bmp':
460+
this.palette.downloadVisibleDraftsAsBmp();
461+
break;
470462
}
463+
return Promise.resolve(null);
464+
465+
471466
}
472467

473468
/**

src/app/mixer/palette/operation/operation.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</button>
3636
</div>
3737

38+
3839
<button
3940
matTooltip= "Duplilcate"
4041
class="button is-small is-primary fa fa-clone"

src/app/mixer/palette/operation/operation.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export class OperationComponent implements OnInit {
8383

8484
has_connections_in: boolean = false;
8585

86+
subdraft_visible: boolean = true;
87+
8688
constructor(
8789
private operations: OperationService,
8890
private dialog: MatDialog,
@@ -269,7 +271,6 @@ export class OperationComponent implements OnInit {
269271

270272

271273

272-
273274
dragStart($event: any) {
274275

275276
}

src/app/mixer/palette/palette.component.ts

+67-20
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,36 @@ export class PaletteComponent implements OnInit{
340340

341341
}
342342

343+
/**
344+
* this cycles through all subdrafts and calls the download call on any subdrafts
345+
* who are currently visible.
346+
*/
347+
downloadVisibleDraftsAsBmp(){
348+
349+
const drafts: Array<SubdraftComponent> = this.tree.getDrafts();
350+
const visible_drafts: Array<SubdraftComponent> = drafts.filter(el => el.draft_visible)
351+
const functions: Array<Promise<any>> = visible_drafts.map(el => el.saveAsBmp());
352+
Promise.all(functions).then(el =>
353+
console.log("Downloaded "+functions.length+" files")
354+
);
355+
356+
}
357+
358+
/**
359+
* this cycles through all subdrafts and calls the download call on any subdrafts
360+
* who are currently visible.
361+
*/
362+
downloadVisibleDraftsAsWif(){
363+
364+
const drafts: Array<SubdraftComponent> = this.tree.getDrafts();
365+
const visible_drafts: Array<SubdraftComponent> = drafts.filter(el => el.draft_visible)
366+
const functions: Array<Promise<any>> = visible_drafts.map(el => el.saveAsWif());
367+
Promise.all(functions).then(el =>
368+
console.log("Downloaded "+functions.length+" files")
369+
);
370+
371+
}
372+
343373

344374

345375
/**
@@ -675,31 +705,38 @@ export class PaletteComponent implements OnInit{
675705
}
676706

677707
/**
708+
* a subdraft can only have an operation for a parent
678709
* removes the subdraft sent to the function
679710
* updates the tree view_id's in response
680711
* @param id {number}
681712
682713
*/
683714
removeSubdraft(id: number){
684715

716+
console.log("removing subdraft id", id);
717+
685718
const parent_id = this.tree.getSubdraftParent(id);
686719

687-
//removoe the node but get alll the ops before it is removed
720+
//remove the node but get all the ops before it is removed
688721
const ref:ViewRef = this.tree.getViewRef(id);
689-
const inputs:Array<number> = this.tree.getNonCxnInputs(id);
722+
// const inputs:Array<number> = this.tree.getNonCxnInputs(id);
690723

691-
inputs.forEach(input => {
692-
if(this.tree.getType(input) == 'draft'){
693-
const comp = <SubdraftComponent> this.tree.getComponent(input);
694-
comp.has_active_connection = false;
695-
comp.active_connection_order = 0;
696-
}
697-
})
724+
725+
//inputs will always be of type op
726+
// inputs.forEach(input => {
727+
// console.log("inputs = ", this.tree.getType(input));
728+
// if(this.tree.getType(input) == 'draft'){
729+
// const comp = <SubdraftComponent> this.tree.getComponent(input);
730+
// comp.has_active_connection = false;
731+
// comp.active_connection_order = 0;
732+
// }
733+
// })
698734

699735
const downstream_ops:Array<number> = this.tree.getDownstreamOperations(id);
700736
this.tree.removeNode(id);
701737

702738
const old_cxns:Array<number> = this.tree.getUnusuedConnections();
739+
console.log("unused connection cxn ", old_cxns);
703740
old_cxns.forEach(cxn => {
704741
const cxn_view_ref = this.tree.getViewRef(cxn);
705742
this.removeFromViewContainer(cxn_view_ref);
@@ -711,25 +748,26 @@ export class PaletteComponent implements OnInit{
711748
this.removeFromViewContainer(ref);
712749
this.viewport.removeObj(id);
713750

714-
//if it has a parent, recursively call on its parent
715-
if(parent_id != -1){
716-
this.removeSubdraft(parent_id);
717-
}
718751

719-
752+
753+
754+
// if the parent op has no children, remove the operation parent as well
755+
if(parent_id != -1 && !this.tree.isParent(parent_id)){
756+
this.removeOperation(parent_id);
757+
}
720758

721759
}
722760

723761
/**
724762
* this function will
725-
* 1. delete the associated output subdraft
763+
* 1. delete the associated output subdrafts
726764
* 2. recompue downsteam operations
727765
* 3. delete all input + output connections
728766
* @param id
729767
*/
730768
removeOperation(id:number){
731769

732-
//removoe the node but get alll the ops before it is removed
770+
//remove the node but get alll the ops before it is removed
733771
const ref:ViewRef = this.tree.getViewRef(id);
734772
const outputs:Array<number> = this.tree.getNonCxnOutputs(id);
735773

@@ -738,20 +776,24 @@ export class PaletteComponent implements OnInit{
738776
const comp = <SubdraftComponent> this.tree.getComponent(output);
739777
comp.has_active_connection = false;
740778
comp.active_connection_order = 0;
741-
comp.parent_id = 0;
779+
comp.parent_id = -1;
742780
}
743781
})
744782

745783
const downstream_ops:Array<number> = this.tree.getDownstreamOperations(id);
746784
this.tree.removeNode(id);
747785

786+
787+
748788
const old_cxns:Array<number> = this.tree.getUnusuedConnections();
749789
old_cxns.forEach(cxn => {
750790
const cxn_view_ref = this.tree.getViewRef(cxn);
751791
this.removeFromViewContainer(cxn_view_ref);
752792
this.tree.removeNode(cxn);
753793
});
754794

795+
796+
755797
//calls manually here so that the affected branches can be pinged before the node is deleted
756798
this.recalculateDownstreamDrafts(downstream_ops);
757799
this.removeFromViewContainer(ref);
@@ -1048,7 +1090,7 @@ export class PaletteComponent implements OnInit{
10481090
}
10491091

10501092
/**
1051-
* Deletes the subdraft that called this function.
1093+
* Duplicates the operation that called this function.
10521094
*/
10531095
onDuplicateOpCalled(obj: any){
10541096
console.log("duplicating "+obj.id);
@@ -1074,6 +1116,9 @@ export class PaletteComponent implements OnInit{
10741116
}
10751117

10761118

1119+
1120+
1121+
10771122
/**
10781123
* Deletes the subdraft that called this function.
10791124
*/
@@ -1331,7 +1376,9 @@ recalculateDownstreamDrafts(downstream_ops:Array<number>){
13311376
.then(draft_map => {
13321377
const leftoffset: Point = {x: op.bounds.topleft.x, y: op.bounds.topleft.y};
13331378

1334-
draft_map.forEach(el => {
1379+
console.log(draft_map);
1380+
1381+
draft_map.forEach((el, ndx) => {
13351382
let sd:SubdraftComponent = null;
13361383

13371384
if(el.component_id >= 0){
@@ -1341,7 +1388,7 @@ recalculateDownstreamDrafts(downstream_ops:Array<number>){
13411388
}else{
13421389
sd = this.createSubDraft(el. draft);
13431390
op.addOutput({component_id: sd.id, draft:el.draft});
1344-
sd.setPosition({x: leftoffset.x, y: leftoffset.y + op.bounds.height});
1391+
sd.setPosition({x: leftoffset.x+(el.draft.warps+1)*ndx*this.scale, y: leftoffset.y + op.bounds.height});
13451392
sd.setComponentSize(el.draft.warps * this.scale, el.draft.wefts * this.scale);
13461393
sd.setParent(op.id);
13471394
const interlacement = utilInstance.resolvePointToAbsoluteNdx(sd.bounds.topleft, this.scale);

0 commit comments

Comments
 (0)