@@ -308,11 +308,7 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
308308 const newNodeUI = this . __addNode ( service , nodePos ) ;
309309 if ( nodeLeftId !== null || nodeRightId !== null ) {
310310 const newNodeId = newNodeUI . getNodeId ( ) ;
311- this . _createEdgeBetweenNodes ( {
312- nodeId : nodeLeftId ? nodeLeftId : newNodeId
313- } , {
314- nodeId : nodeRightId ? nodeRightId : newNodeId
315- } ) ;
311+ this . _createEdgeBetweenNodes ( nodeLeftId ? nodeLeftId : newNodeId , nodeRightId ? nodeRightId : newNodeId , true ) ;
316312 }
317313 } , this ) ;
318314 srvCat . open ( ) ;
@@ -326,8 +322,9 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
326322 }
327323
328324 const newNodeUI = this . _createNodeUI ( node . getNodeId ( ) ) ;
329- this . __createDragDropMechanism ( newNodeUI ) ;
330325 this . _addNodeUIToWorkbench ( newNodeUI , pos ) ;
326+ qx . ui . core . queue . Layout . flush ( ) ;
327+ this . __createDragDropMechanism ( newNodeUI ) ;
331328 return newNodeUI ;
332329 } ,
333330
@@ -359,7 +356,6 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
359356 let onNodeUI = null ;
360357 this . __nodesUI . forEach ( nodeUI => {
361358 const nBounds = nodeUI . getBounds ( ) ;
362- console . log ( ) ;
363359 if ( onNodeUI === null &&
364360 pos . x > nBounds . left &&
365361 pos . x < nBounds . left + nBounds . width &&
@@ -386,9 +382,7 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
386382 nodeUI . open ( ) ;
387383 this . __nodesUI . push ( nodeUI ) ;
388384
389- nodeUI . addListener ( "appear" , ( ) => {
390- this . __updateNodeUIPos ( nodeUI ) ;
391- } , this ) ;
385+ nodeUI . addListener ( "appear" , ( ) => this . __updateNodeUIPos ( nodeUI ) , this ) ;
392386
393387 const isStudyReadOnly = this . getStudy ( ) . isReadOnly ( ) ;
394388 nodeUI . set ( {
@@ -404,8 +398,6 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
404398 this . __addNodeListeners ( nodeUI ) ;
405399 }
406400
407- qx . ui . core . queue . Layout . flush ( ) ;
408-
409401 this . __updateHint ( ) ;
410402 } ,
411403
@@ -600,58 +592,6 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
600592 return nodeUI ;
601593 } ,
602594
603- __createEdgeUI : function ( node1Id , node2Id , edgeId ) {
604- const edge = this . __getWorkbench ( ) . createEdge ( edgeId , node1Id , node2Id ) ;
605- if ( ! edge ) {
606- return null ;
607- }
608- if ( this . __edgeRepresentationExists ( edge ) ) {
609- return null ;
610- }
611-
612- // build representation
613- const nodeUI1 = this . getNodeUI ( node1Id ) ;
614- const nodeUI2 = this . getNodeUI ( node2Id ) ;
615- if ( nodeUI1 . getCurrentBounds ( ) === null || nodeUI2 . getCurrentBounds ( ) === null ) {
616- console . error ( "bounds not ready" ) ;
617- return null ;
618- }
619- const port1 = nodeUI1 . getOutputPort ( ) ;
620- const port2 = nodeUI2 . getInputPort ( ) ;
621- if ( port1 && port2 ) {
622- nodeUI2 . getNode ( ) . addInputNode ( node1Id ) ;
623- const pointList = this . __getEdgePoints ( nodeUI1 , port1 , nodeUI2 , port2 ) ;
624- const x1 = pointList [ 0 ] ? pointList [ 0 ] [ 0 ] : 0 ;
625- const y1 = pointList [ 0 ] ? pointList [ 0 ] [ 1 ] : 0 ;
626- const x2 = pointList [ 1 ] ? pointList [ 1 ] [ 0 ] : 0 ;
627- const y2 = pointList [ 1 ] ? pointList [ 1 ] [ 1 ] : 0 ;
628- const edgeRepresentation = this . __svgLayer . drawCurve ( x1 , y1 , x2 , y2 , ! edge . isPortConnected ( ) ) ;
629-
630- edge . addListener ( "changePortConnected" , e => {
631- const portConnected = e . getData ( ) ;
632- osparc . wrapper . Svg . updateCurveDashes ( edgeRepresentation , ! portConnected ) ;
633- } , this ) ;
634-
635- const edgeUI = new osparc . component . workbench . EdgeUI ( edge , edgeRepresentation ) ;
636- this . __edgesUI . push ( edgeUI ) ;
637-
638- const that = this ;
639- edgeUI . getRepresentation ( ) . widerCurve . node . addEventListener ( "click" , e => {
640- // this is needed to get out of the context of svg
641- that . __selectedItemChanged ( edgeUI . getEdgeId ( ) ) ; // eslint-disable-line no-underscore-dangle
642- e . stopPropagation ( ) ;
643- } , this ) ;
644- edgeUI . getRepresentation ( ) . node . addEventListener ( "click" , e => {
645- // this is needed to get out of the context of svg
646- that . __selectedItemChanged ( edgeUI . getEdgeId ( ) ) ; // eslint-disable-line no-underscore-dangle
647- e . stopPropagation ( ) ;
648- } , this ) ;
649-
650- return edgeUI ;
651- }
652- return null ;
653- } ,
654-
655595 __edgeRepresentationExists : function ( edge ) {
656596 for ( let i = 0 ; i < this . __edgesUI . length ; i ++ ) {
657597 const edgeUI = this . __edgesUI [ i ] ;
@@ -732,11 +672,7 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
732672 let nodeAId = dropIsInput ? dragNodeId : dropNodeId ;
733673 let nodeBId = dragIsInput ? dragNodeId : dropNodeId ;
734674
735- this . _createEdgeBetweenNodes ( {
736- nodeId : nodeAId
737- } , {
738- nodeId : nodeBId
739- } ) ;
675+ this . _createEdgeBetweenNodes ( nodeAId , nodeBId , true ) ;
740676 this . __removeTempEdge ( ) ;
741677 this . __removePointerMoveListener ( ) ;
742678 }
@@ -759,10 +695,54 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
759695 } , this ) ;
760696 } ,
761697
762- _createEdgeBetweenNodes : function ( from , to , edgeId ) {
763- const node1Id = from . nodeId ;
764- const node2Id = to . nodeId ;
765- this . __createEdgeUI ( node1Id , node2Id , edgeId ) ;
698+ _createEdgeBetweenNodes : function ( node1Id , node2Id , autoConnect = true ) {
699+ const edge = this . __getWorkbench ( ) . createEdge ( null , node1Id , node2Id , autoConnect ) ;
700+ if ( ! edge ) {
701+ return ;
702+ }
703+ if ( this . __edgeRepresentationExists ( edge ) ) {
704+ return ;
705+ }
706+
707+ // build representation
708+ const nodeUI1 = this . getNodeUI ( node1Id ) ;
709+ const nodeUI2 = this . getNodeUI ( node2Id ) ;
710+ if ( nodeUI1 . getCurrentBounds ( ) === null || nodeUI2 . getCurrentBounds ( ) === null ) {
711+ console . error ( "bounds not ready" ) ;
712+ return ;
713+ }
714+
715+ const port1 = nodeUI1 . getOutputPort ( ) ;
716+ const port2 = nodeUI2 . getInputPort ( ) ;
717+ if ( port1 && port2 ) {
718+ nodeUI2 . getNode ( ) . addInputNode ( node1Id ) ;
719+ const pointList = this . __getEdgePoints ( nodeUI1 , port1 , nodeUI2 , port2 ) ;
720+ const x1 = pointList [ 0 ] ? pointList [ 0 ] [ 0 ] : 0 ;
721+ const y1 = pointList [ 0 ] ? pointList [ 0 ] [ 1 ] : 0 ;
722+ const x2 = pointList [ 1 ] ? pointList [ 1 ] [ 0 ] : 0 ;
723+ const y2 = pointList [ 1 ] ? pointList [ 1 ] [ 1 ] : 0 ;
724+ const edgeRepresentation = this . __svgLayer . drawCurve ( x1 , y1 , x2 , y2 , ! edge . isPortConnected ( ) ) ;
725+
726+ edge . addListener ( "changePortConnected" , e => {
727+ const portConnected = e . getData ( ) ;
728+ osparc . wrapper . Svg . updateCurveDashes ( edgeRepresentation , ! portConnected ) ;
729+ } , this ) ;
730+
731+ const edgeUI = new osparc . component . workbench . EdgeUI ( edge , edgeRepresentation ) ;
732+ this . __edgesUI . push ( edgeUI ) ;
733+
734+ const that = this ;
735+ edgeUI . getRepresentation ( ) . widerCurve . node . addEventListener ( "click" , e => {
736+ // this is needed to get out of the context of svg
737+ that . __selectedItemChanged ( edgeUI . getEdgeId ( ) ) ; // eslint-disable-line no-underscore-dangle
738+ e . stopPropagation ( ) ;
739+ } , this ) ;
740+ edgeUI . getRepresentation ( ) . node . addEventListener ( "click" , e => {
741+ // this is needed to get out of the context of svg
742+ that . __selectedItemChanged ( edgeUI . getEdgeId ( ) ) ; // eslint-disable-line no-underscore-dangle
743+ e . stopPropagation ( ) ;
744+ } , this ) ;
745+ }
766746 } ,
767747
768748 __updateAllEdges : function ( ) {
@@ -1041,38 +1021,34 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
10411021 this . __clearAllAnnotations ( ) ;
10421022 } ,
10431023
1024+ __reloadCurrentModel : function ( ) {
1025+ if ( this . _currentModel ) {
1026+ this . loadModel ( this . getStudy ( ) . getWorkbench ( ) ) ;
1027+ }
1028+ } ,
1029+
10441030 loadModel : function ( model ) {
10451031 if ( this . __svgLayer . getReady ( ) ) {
10461032 this . _loadModel ( model ) ;
10471033 } else {
1048- this . __svgLayer . addListenerOnce ( "SvgWidgetReady" , ( ) => {
1049- this . _loadModel ( model ) ;
1050- } , this ) ;
1051- }
1052- } ,
1053-
1054- __reloadCurrentModel : function ( ) {
1055- if ( this . _currentModel ) {
1056- this . loadModel ( this . _currentModel ) ;
1034+ this . __svgLayer . addListenerOnce ( "SvgWidgetReady" , ( ) => this . _loadModel ( model ) , this ) ;
10571035 }
10581036 } ,
10591037
10601038 _loadModel : async function ( model ) {
10611039 this . _clearAll ( ) ;
10621040 this . _currentModel = model ;
10631041 if ( model ) {
1064- qx . ui . core . queue . Visibility . flush ( ) ;
1065-
10661042 // create nodes
10671043 const nodes = model . getNodes ( ) ;
10681044 const nodeUIs = [ ] ;
10691045 for ( const nodeId in nodes ) {
10701046 const node = nodes [ nodeId ] ;
10711047 const nodeUI = this . _createNodeUI ( nodeId ) ;
1072- this . __createDragDropMechanism ( nodeUI ) ;
10731048 this . _addNodeUIToWorkbench ( nodeUI , node . getPosition ( ) ) ;
10741049 nodeUIs . push ( nodeUI ) ;
10751050 }
1051+ qx . ui . core . queue . Layout . flush ( ) ;
10761052
10771053 let tries = 0 ;
10781054 const maxTries = 40 ;
@@ -1084,17 +1060,15 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
10841060 }
10851061 console . log ( "nodes visible" , nodeUIs . length , tries * sleepFor ) ;
10861062
1063+ nodeUIs . forEach ( nodeUI => this . __createDragDropMechanism ( nodeUI ) ) ;
1064+
10871065 // create edges
10881066 for ( const nodeId in nodes ) {
10891067 const node = nodes [ nodeId ] ;
10901068 const inputNodeIDs = node . getInputNodes ( ) ;
10911069 inputNodeIDs . forEach ( inputNodeId => {
10921070 if ( inputNodeId in nodes ) {
1093- this . _createEdgeBetweenNodes ( {
1094- nodeId : inputNodeId
1095- } , {
1096- nodeId : nodeId
1097- } ) ;
1071+ this . _createEdgeBetweenNodes ( inputNodeId , nodeId , false ) ;
10981072 }
10991073 } ) ;
11001074 }
0 commit comments