Skip to content

Commit c4cc009

Browse files
committed
fix : calc without temporal dto changes + avoid manual handroll
1 parent 185666b commit c4cc009

File tree

6 files changed

+613
-158
lines changed

6 files changed

+613
-158
lines changed

src/app/services/data/trainrun.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import {DataService} from "./data.service";
1717
import {Node} from "../../models/node.model";
1818
import {TrainrunSection} from "../../models/trainrunsection.model";
1919
import {GeneralViewFunctions} from "../../view/util/generalViewFunctions";
20-
import {NonStopTrainrunIterator, TrainrunIterator} from "../util/trainrun.iterator";
20+
import {
21+
NonStopTrainrunIterator,
22+
TrainrunIterator,
23+
ExpandedTrainrunIterator,
24+
} from "../util/trainrun.iterator";
2125
import {LogService} from "../../logger/log.service";
2226
import {LabelService} from "./label.service";
2327
import {FilterService} from "../ui/filter.service";
@@ -760,6 +764,10 @@ export class TrainrunService {
760764
return new NonStopTrainrunIterator(this.logService, node, trainrunSection);
761765
}
762766

767+
public getExpandedIterator(node: Node, trainrunSection: TrainrunSection) {
768+
return new ExpandedTrainrunIterator(this.logService, node, trainrunSection);
769+
}
770+
763771
// For each trainrun, get iterator from the smallest consecutiveTime.
764772
public getRootIterators(): Map<number, TrainrunIterator> {
765773
const trainrunSections = this.trainrunSectionService.getTrainrunSections();

src/app/services/data/trainrunsection.service.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,19 +1472,16 @@ export class TrainrunSectionService implements OnDestroy {
14721472

14731473
/**
14741474
* Groups consecutive TrainrunSections that have collapsed nodes between them
1475-
* into chains with start and end nodes. Each chain starts and ends with a non-collapsed node.
1475+
* into chains. Each chain starts and ends with a non-collapsed node.
1476+
* Start and end nodes can be accessed via: sections[0].getSourceNode() and sections[sections.length - 1].getTargetNode()
14761477
* @param trainrunSections List of TrainrunSections to group
1477-
* @returns Array of section groups with start/end nodes
1478+
* @returns Array of section chains
14781479
*/
14791480
groupTrainrunSectionsIntoChains(trainrunSections: TrainrunSection[]): Array<{
14801481
sections: TrainrunSection[];
1481-
startNode: Node;
1482-
endNode: Node;
14831482
}> {
14841483
const groups: Array<{
14851484
sections: TrainrunSection[];
1486-
startNode: Node;
1487-
endNode: Node;
14881485
}> = [];
14891486
const visitedSections = new Set<number>();
14901487

@@ -1494,44 +1491,34 @@ export class TrainrunSectionService implements OnDestroy {
14941491
}
14951492

14961493
// Start a new group from this section
1497-
const chain: TrainrunSection[] = [];
1498-
let currentSection = section;
1494+
const chain: TrainrunSection[] = [section];
1495+
visitedSections.add(section.getId());
14991496

1500-
// Add the first section
1501-
chain.push(currentSection);
1502-
visitedSections.add(currentSection.getId());
1497+
const startNode = this.nodeService.getNodeFromId(section.getSourceNodeId());
1498+
let currentSection = section;
15031499

1504-
// Look for consecutive sections with collapsed intermediate nodes
1500+
// Continue traversing to find consecutive sections with collapsed intermediate nodes
1501+
// Use the node's getNextTrainrunSection method instead of manual search
15051502
// eslint-disable-next-line no-constant-condition
15061503
while (true) {
15071504
const targetNode = this.nodeService.getNodeFromId(currentSection.getTargetNodeId());
15081505
if (!targetNode || !targetNode.getIsCollapsed()) {
15091506
break; // End of chain if target node is not collapsed
15101507
}
15111508

1512-
// Find next section starting from this collapsed node
1513-
const nextSection = trainrunSections.find(
1514-
(ts) =>
1515-
ts.getSourceNodeId() === currentSection.getTargetNodeId() &&
1516-
ts.getTrainrunId() === currentSection.getTrainrunId() &&
1517-
!visitedSections.has(ts.getId()),
1518-
);
1519-
if (!nextSection) {
1520-
break; // No further section found, end of chain
1509+
// Use the node's getNextTrainrunSection method to find the connected section
1510+
const nextSection = targetNode.getNextTrainrunSection(currentSection);
1511+
if (!nextSection || visitedSections.has(nextSection.getId())) {
1512+
break; // No further section found or already visited, end of chain
15211513
}
1514+
15221515
chain.push(nextSection);
15231516
visitedSections.add(nextSection.getId());
15241517
currentSection = nextSection;
15251518
}
15261519

1527-
// Create group with start and end nodes
1528-
const startNode = this.nodeService.getNodeFromId(chain[0].getSourceNodeId());
1529-
const endNode = this.nodeService.getNodeFromId(chain[chain.length - 1].getTargetNodeId());
1530-
15311520
groups.push({
15321521
sections: chain,
1533-
startNode: startNode,
1534-
endNode: endNode,
15351522
});
15361523
});
15371524

src/app/services/util/trainrun.iterator.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@ export class NonStopTrainrunIterator extends TrainrunIterator {
8484
return super.next();
8585
}
8686
}
87+
88+
export class ExpandedTrainrunIterator extends TrainrunIterator {
89+
public next(): TrainrunSectionNodePair {
90+
// Continue traversing only if the current node is collapsed
91+
// Stop when we reach an expanded (non-collapsed) node
92+
if (!this.pointerElement.node.getIsCollapsed()) {
93+
// The trainrun has reached an expanded (non-collapsed) node and break the forward iteration
94+
this.currentElement = Object.assign({}, this.pointerElement);
95+
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);
96+
return this.currentElement;
97+
}
98+
return super.next();
99+
}
100+
}

src/app/view/editor-main-view/data-views/trainrunSectionViewObject.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ export class TrainrunSectionViewObject {
156156
d.getPath().forEach((p) => {
157157
key += p.toString();
158158
});
159+
160+
// Include source and target node positions to detect when they move
161+
key += "_SRC_" + d.getSourceNode().getPositionX() + "_" + d.getSourceNode().getPositionY();
162+
key += "_TRG_" + d.getTargetNode().getPositionX() + "_" + d.getTargetNode().getPositionY();
163+
164+
// Disable cache for collapsed chains to ensure proper recalculation
165+
// TODO: Optimize by including only relevant node positions
166+
if (d.getSourceNode().getIsCollapsed() || d.getTargetNode().getIsCollapsed()) {
167+
key += "_NOCACHE_" + Date.now();
168+
}
169+
159170
return key;
160171
}
161172
}

0 commit comments

Comments
 (0)