@@ -11,7 +11,6 @@ import {StaticDomTags} from "../../../editor-main-view/data-views/static.dom.tag
1111import { ColorRefType } from "../../../../data-structures/technical.data.structures" ;
1212import { TrainrunSectionTimesService } from "../../../../services/data/trainrun-section-times.service" ;
1313import { LeftAndRightTimeStructure } from "../trainrunsection-tab/trainrun-section-tab.component" ;
14- import { GeneralViewFunctions } from "../../../util/generalViewFunctions" ;
1514
1615@Component ( {
1716 selector : "sbb-trainrunsection-card" ,
@@ -23,14 +22,13 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
2322 @Input ( ) trainrunDialogParameter : TrainrunDialogParameter ;
2423 @Input ( ) innerContentScaleFactor = "1.0" ;
2524
26- public startNode : string [ ] = [ "" , "" ] ;
27- public endNode : string [ ] = [ "" , "" ] ;
25+ public leftNode : Node ;
26+ public rightNode : Node ;
2827 public frequencyLinePattern : LinePatternRefs ;
2928 public categoryColorRef : ColorRefType ;
3029 public timeCategoryLinePattern : LinePatternRefs ;
3130 public chosenCard : "top" | "bottom" ;
3231
33- private trainrunSectionHelper : TrainrunsectionHelper ;
3432 private destroyed = new Subject < void > ( ) ;
3533
3634 public get nodesOrdered ( ) : Node [ ] {
@@ -43,8 +41,6 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
4341 private changeDetection : ChangeDetectorRef ,
4442 public trainrunSectionTimesService : TrainrunSectionTimesService ,
4543 ) {
46- this . trainrunSectionHelper = new TrainrunsectionHelper ( this . trainrunService ) ;
47-
4844 this . trainrunSectionTimesService . setOffset ( 0 ) ;
4945 this . trainrunService . trainruns . pipe ( takeUntil ( this . destroyed ) ) . subscribe ( ( ) => {
5046 this . updateAllValues ( ) ;
@@ -65,15 +61,19 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
6561 }
6662 const trainrunSection = this . trainrunService . getFirstTrainrunSection ( selectedTrainrun ) ;
6763
68- this . trainrunSectionTimesService . setOffset ( 0 ) ;
64+ this . leftNode = this . trainrunService . getLeftOrTopNodeWithTrainrunId (
65+ trainrunSection . getTrainrunId ( ) ,
66+ ) ;
67+ this . rightNode = this . trainrunService . getRightOrBottomNodeWithTrainrunId (
68+ trainrunSection . getTrainrunId ( ) ,
69+ ) ;
6970
70- // Initialize the selected trainrun as one-way, selecting the [source] → [target] card
71+ this . trainrunSectionTimesService . setOffset ( 0 ) ;
7172 if ( selectedTrainrun . isRoundTrip ( ) ) {
72- if ( TrainrunsectionHelper . isTargetRightOrBottom ( trainrunSection ) ) {
73- this . onTrainrunSectionCardClick ( "top" ) ;
74- } else {
75- this . onTrainrunSectionCardClick ( "bottom" ) ;
76- }
73+ // Initialize round trip trainrun with top card
74+ this . onTrainrunSectionCardClick ( "top" ) ;
75+ } else {
76+ this . chosenCard = this . trainrunService . isTrainrunTargetRightOrBottom ( ) ? "top" : "bottom" ;
7777 }
7878
7979 this . trainrunSectionTimesService . setTrainrunSection ( trainrunSection ) ;
@@ -82,19 +82,6 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
8282 this . timeCategoryLinePattern = selectedTrainrun . getTimeCategoryLinePatternRef ( ) ;
8383 this . trainrunSectionTimesService . setHighlightTravelTimeElement ( false ) ;
8484 this . trainrunSectionTimesService . applyOffsetAndTransformTimeStructure ( ) ;
85-
86- const startNode = this . trainrunService . getStartNodeWithTrainrunId (
87- trainrunSection . getTrainrunId ( ) ,
88- ) ;
89- this . startNode = [ startNode . getFullName ( ) , startNode . getBetriebspunktName ( ) ] ;
90- const endNode = this . trainrunService . getEndNodeWithTrainrunId ( trainrunSection . getTrainrunId ( ) ) ;
91- this . endNode = [ endNode . getFullName ( ) , endNode . getBetriebspunktName ( ) ] ;
92-
93- if ( ! selectedTrainrun . isRoundTrip ( ) ) {
94- this . chosenCard = TrainrunsectionHelper . isTargetRightOrBottom ( trainrunSection )
95- ? "top"
96- : "bottom" ;
97- }
9885 }
9986
10087 ngOnDestroy ( ) {
@@ -173,33 +160,15 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
173160 return ;
174161 }
175162
176- let trainrunSection = undefined ;
177- let wantedSourceNode = undefined ;
163+ let trainrunSection = this . trainrunService . getFirstTrainrunSection ( selectedTrainrun ) ;
178164 if ( selectedTrainrun . isRoundTrip ( ) ) {
179- const bothEndNodes = this . trainrunService . getBothEndNodesWithTrainrunId (
180- selectedTrainrun . getId ( ) ,
181- ) ;
182- // direction top-left -> default
183- wantedSourceNode = GeneralViewFunctions . getLeftOrTopNode (
184- bothEndNodes . endNode1 ,
185- bothEndNodes . endNode2 ,
186- ) ;
187- trainrunSection = wantedSourceNode . getStartTrainrunSection ( selectedTrainrun . getId ( ) ) ;
188- } else {
189- trainrunSection = this . trainrunService . getFirstTrainrunSection ( selectedTrainrun ) ;
190- // Get the left and right nodes to determine the cards order
191- const leftNode = this . trainrunSectionHelper . getNextStopLeftNode (
192- trainrunSection ,
193- this . nodesOrdered ,
194- ) ;
195- const rightNode = this . trainrunSectionHelper . getNextStopRightNode (
196- trainrunSection ,
197- this . nodesOrdered ,
198- ) ;
199- wantedSourceNode = position === "top" ? leftNode : rightNode ;
165+ // For a round trip trainrun, we want to choose the most top/left
166+ // section as reference when switching to a one-way trainrun
167+ trainrunSection = this . trainrunService . getLeftOrTopExtremitySection ( ) ;
200168 }
201169
202- if ( wantedSourceNode !== trainrunSection . getSourceNode ( ) ) {
170+ const referenceNode = position === "top" ? this . leftNode : this . rightNode ;
171+ if ( referenceNode !== trainrunSection . getSourceNode ( ) ) {
203172 this . trainrunSectionService . invertTrainrunSectionsSourceAndTarget (
204173 trainrunSection . getTrainrunId ( ) ,
205174 ) ;
@@ -217,8 +186,8 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
217186 const trainrunSections =
218187 this . trainrunSectionService . getAllTrainrunSectionsForTrainrun ( selectedTrainrunId ) ;
219188 const [ startNode , endNode ] = [
220- this . trainrunService . getStartNodeWithTrainrunId ( selectedTrainrunId ) ,
221- this . trainrunService . getEndNodeWithTrainrunId ( selectedTrainrunId ) ,
189+ this . trainrunService . getLeftOrTopNodeWithTrainrunId ( selectedTrainrunId ) ,
190+ this . trainrunService . getRightOrBottomNodeWithTrainrunId ( selectedTrainrunId ) ,
222191 ] ;
223192
224193 // Try to find startNode → endNode
0 commit comments