@@ -340,6 +340,36 @@ export class PaletteComponent implements OnInit{
340
340
341
341
}
342
342
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
+
343
373
344
374
345
375
/**
@@ -675,31 +705,38 @@ export class PaletteComponent implements OnInit{
675
705
}
676
706
677
707
/**
708
+ * a subdraft can only have an operation for a parent
678
709
* removes the subdraft sent to the function
679
710
* updates the tree view_id's in response
680
711
* @param id {number}
681
712
682
713
*/
683
714
removeSubdraft ( id : number ) {
684
715
716
+ console . log ( "removing subdraft id" , id ) ;
717
+
685
718
const parent_id = this . tree . getSubdraftParent ( id ) ;
686
719
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
688
721
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);
690
723
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
+ // })
698
734
699
735
const downstream_ops :Array < number > = this . tree . getDownstreamOperations ( id ) ;
700
736
this . tree . removeNode ( id ) ;
701
737
702
738
const old_cxns :Array < number > = this . tree . getUnusuedConnections ( ) ;
739
+ console . log ( "unused connection cxn " , old_cxns ) ;
703
740
old_cxns . forEach ( cxn => {
704
741
const cxn_view_ref = this . tree . getViewRef ( cxn ) ;
705
742
this . removeFromViewContainer ( cxn_view_ref ) ;
@@ -711,25 +748,26 @@ export class PaletteComponent implements OnInit{
711
748
this . removeFromViewContainer ( ref ) ;
712
749
this . viewport . removeObj ( id ) ;
713
750
714
- //if it has a parent, recursively call on its parent
715
- if ( parent_id != - 1 ) {
716
- this . removeSubdraft ( parent_id ) ;
717
- }
718
751
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
+ }
720
758
721
759
}
722
760
723
761
/**
724
762
* this function will
725
- * 1. delete the associated output subdraft
763
+ * 1. delete the associated output subdrafts
726
764
* 2. recompue downsteam operations
727
765
* 3. delete all input + output connections
728
766
* @param id
729
767
*/
730
768
removeOperation ( id :number ) {
731
769
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
733
771
const ref :ViewRef = this . tree . getViewRef ( id ) ;
734
772
const outputs :Array < number > = this . tree . getNonCxnOutputs ( id ) ;
735
773
@@ -738,20 +776,24 @@ export class PaletteComponent implements OnInit{
738
776
const comp = < SubdraftComponent > this . tree . getComponent ( output ) ;
739
777
comp . has_active_connection = false ;
740
778
comp . active_connection_order = 0 ;
741
- comp . parent_id = 0 ;
779
+ comp . parent_id = - 1 ;
742
780
}
743
781
} )
744
782
745
783
const downstream_ops :Array < number > = this . tree . getDownstreamOperations ( id ) ;
746
784
this . tree . removeNode ( id ) ;
747
785
786
+
787
+
748
788
const old_cxns :Array < number > = this . tree . getUnusuedConnections ( ) ;
749
789
old_cxns . forEach ( cxn => {
750
790
const cxn_view_ref = this . tree . getViewRef ( cxn ) ;
751
791
this . removeFromViewContainer ( cxn_view_ref ) ;
752
792
this . tree . removeNode ( cxn ) ;
753
793
} ) ;
754
794
795
+
796
+
755
797
//calls manually here so that the affected branches can be pinged before the node is deleted
756
798
this . recalculateDownstreamDrafts ( downstream_ops ) ;
757
799
this . removeFromViewContainer ( ref ) ;
@@ -1048,7 +1090,7 @@ export class PaletteComponent implements OnInit{
1048
1090
}
1049
1091
1050
1092
/**
1051
- * Deletes the subdraft that called this function.
1093
+ * Duplicates the operation that called this function.
1052
1094
*/
1053
1095
onDuplicateOpCalled ( obj : any ) {
1054
1096
console . log ( "duplicating " + obj . id ) ;
@@ -1074,6 +1116,9 @@ export class PaletteComponent implements OnInit{
1074
1116
}
1075
1117
1076
1118
1119
+
1120
+
1121
+
1077
1122
/**
1078
1123
* Deletes the subdraft that called this function.
1079
1124
*/
@@ -1331,7 +1376,9 @@ recalculateDownstreamDrafts(downstream_ops:Array<number>){
1331
1376
. then ( draft_map => {
1332
1377
const leftoffset : Point = { x : op . bounds . topleft . x , y : op . bounds . topleft . y } ;
1333
1378
1334
- draft_map . forEach ( el => {
1379
+ console . log ( draft_map ) ;
1380
+
1381
+ draft_map . forEach ( ( el , ndx ) => {
1335
1382
let sd :SubdraftComponent = null ;
1336
1383
1337
1384
if ( el . component_id >= 0 ) {
@@ -1341,7 +1388,7 @@ recalculateDownstreamDrafts(downstream_ops:Array<number>){
1341
1388
} else {
1342
1389
sd = this . createSubDraft ( el . draft ) ;
1343
1390
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 } ) ;
1345
1392
sd . setComponentSize ( el . draft . warps * this . scale , el . draft . wefts * this . scale ) ;
1346
1393
sd . setParent ( op . id ) ;
1347
1394
const interlacement = utilInstance . resolvePointToAbsoluteNdx ( sd . bounds . topleft , this . scale ) ;
0 commit comments