@@ -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