@@ -178,15 +178,16 @@ export class NodeService implements OnDestroy {
178178 initPortOrdering ( ) {
179179 this . nodesStore . nodes . forEach ( ( node ) => {
180180 node . getPorts ( ) . forEach ( ( port ) => {
181- const oppositeNode = node . getOppositeNode ( port . getTrainrunSection ( ) ) ;
181+ const oppositeExpandedNode = this . getOppositeExpandedNode ( port . getTrainrunSection ( ) , node ) ;
182182 const portAlignments = VisAVisPortPlacement . placePortsOnSourceAndTargetNode (
183183 node ,
184- oppositeNode ,
184+ oppositeExpandedNode ,
185185 ) ;
186+ console . log ( port , portAlignments ) ;
186187 port . setPositionAlignment ( portAlignments . sourcePortPlacement ) ;
187- oppositeNode
188+ oppositeExpandedNode
188189 . getPortOfTrainrunSection ( port . getTrainrunSection ( ) . getId ( ) )
189- . setPositionAlignment ( portAlignments . targetPortPlacement ) ;
190+ ? .setPositionAlignment ( portAlignments . targetPortPlacement ) ;
190191 } ) ;
191192
192193 node . updateTransitionsAndConnections ( ) ;
@@ -479,8 +480,15 @@ export class NodeService implements OnDestroy {
479480 }
480481
481482 addPortsToNodes ( sourceNodeId : number , targetNodeId : number , trainrunSection : TrainrunSection ) {
482- const sourceNode = this . getNodeFromId ( sourceNodeId ) ;
483- const targetNode = this . getNodeFromId ( targetNodeId ) ;
483+ const sourceNode = this . getOppositeExpandedNode (
484+ trainrunSection ,
485+ this . getNodeFromId ( targetNodeId ) ,
486+ ) ;
487+ const targetNode = this . getOppositeExpandedNode (
488+ trainrunSection ,
489+ this . getNodeFromId ( sourceNodeId ) ,
490+ ) ;
491+ // console.log(trainrunSection, sourceNode, targetNode);
484492 const portAlignments = VisAVisPortPlacement . placePortsOnSourceAndTargetNode (
485493 sourceNode ,
486494 targetNode ,
@@ -1128,6 +1136,30 @@ export class NodeService implements OnDestroy {
11281136 return { minCoordX : minX , minCoordY : minY , maxCoordX : maxX , maxCoordY : maxY } ;
11291137 }
11301138
1139+ getOppositeExpandedNode ( trainrunSection : TrainrunSection , currentNode : Node ) : Node | undefined {
1140+ const groups = this . trainrunSectionService . groupTrainrunSectionsIntoChains (
1141+ this . trainrunSectionService . getAllTrainrunSectionsForTrainrun (
1142+ trainrunSection . getTrainrunId ( ) ,
1143+ ) ,
1144+ ) ;
1145+ // keep only the groups which contain the given trainrun section
1146+ const filteredGroup = groups . find (
1147+ ( group ) => group . find ( ( trs ) => trs . getId ( ) === trainrunSection . getId ( ) ) !== undefined ,
1148+ ) ;
1149+ if ( filteredGroup === undefined ) {
1150+ return undefined ;
1151+ }
1152+ if ( currentNode . getId ( ) === trainrunSection . getSourceNodeId ( ) ) {
1153+ // get target node of the last trainrun section in the group
1154+ const lastTrainrunSection = filteredGroup . at ( - 1 ) ;
1155+ return this . getNodeFromId ( lastTrainrunSection . getTargetNodeId ( ) ) ;
1156+ } else {
1157+ // get source node of the first trainrun section in the group
1158+ const firstTrainrunSection = filteredGroup . at ( 0 ) ;
1159+ return this . getNodeFromId ( firstTrainrunSection . getSourceNodeId ( ) ) ;
1160+ }
1161+ }
1162+
11311163 private deleteNodeWithoutUpdate ( nodeId : number , enforceUpdate = true ) {
11321164 const node = this . getNodeFromId ( nodeId ) ;
11331165 const connectedTrainrunSections = node . getConnectedTrainrunSections ( ) ;
@@ -1152,17 +1184,20 @@ export class NodeService implements OnDestroy {
11521184 node . setPosition ( newPositionX , newPositionY ) ;
11531185 if ( dragEnd ) {
11541186 node . getPorts ( ) . forEach ( ( port ) => {
1155- const oppositeNode = node . getOppositeNode ( port . getTrainrunSection ( ) ) ;
1187+ const oppositeExpandedNode = this . getOppositeExpandedNode ( port . getTrainrunSection ( ) , node ) ;
11561188 const portAlignments = VisAVisPortPlacement . placePortsOnSourceAndTargetNode (
11571189 node ,
1158- oppositeNode ,
1190+ oppositeExpandedNode ,
11591191 ) ;
11601192 port . setPositionAlignment ( portAlignments . sourcePortPlacement ) ;
1161- oppositeNode
1193+ oppositeExpandedNode
11621194 . getPortOfTrainrunSection ( port . getTrainrunSection ( ) . getId ( ) )
1163- . setPositionAlignment ( portAlignments . targetPortPlacement ) ;
1164- oppositeNode . updateTransitionsAndConnections ( ) ;
1165- this . trainrunSectionService . updateTrainrunSectionRouting ( oppositeNode , enforceUpdate ) ;
1195+ ?. setPositionAlignment ( portAlignments . targetPortPlacement ) ;
1196+ oppositeExpandedNode . updateTransitionsAndConnections ( ) ;
1197+ this . trainrunSectionService . updateTrainrunSectionRouting (
1198+ oppositeExpandedNode ,
1199+ enforceUpdate ,
1200+ ) ;
11661201 } ) ;
11671202 node . reorderAllPorts ( ) ;
11681203 this . operation . emit ( new NodeOperation ( OperationType . update , node ) ) ;
0 commit comments