Skip to content

Commit 020ecfd

Browse files
committed
[NAB-375] Variables with no init values referenced in arcs will cause arcs not to load
- arcs which referenced data has non integer value will be displayed/represented with value 0 in edit + simulation mode
1 parent 801cd32 commit 020ecfd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/app/modeler/services/model/model.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,10 @@ export class ModelService {
483483
const referencedData = model.getData(id);
484484
if (referencedData) {
485485
if (referencedData.init.value) {
486-
return Number(referencedData.init.value);
487-
// TODO: NAB-326 check if isFinite and >= 0
486+
if (/^[1-9]\d*$/.test(referencedData.init.value.trim())) {
487+
return Number(referencedData.init.value);
488+
}
489+
return 0;
488490
}
489491
return 0;
490492
}

src/app/modeler/simulation-mode/simulation-mode.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ export class SimulationModeService extends CanvasModeService<SimulationTool> {
8787
this.originalModel = new BehaviorSubject<PetriNet>(this.modelService.model.clone());
8888
this.originalModel.subscribe(model => {
8989
this.data = new Map(model.getArcs().filter(a => !!a.reference && !!model.getData(a.reference))
90-
.map(a => [a.reference, Number.parseInt(model.getData(a.reference).init?.value, 10) || 0]));
90+
.map(a => {
91+
const data = model.getData(a.reference);
92+
if (!!data.init && !!data.init.value && /^[1-9]\d*$/.test(data.init.value)) {
93+
return [a.reference, Number.parseInt(data.init.value, 10)];
94+
}
95+
return [a.reference, 0];
96+
}));
9197
this.simulation = new BasicSimulation(model, this.data);
9298
this.renderModel(model);
9399
});

0 commit comments

Comments
 (0)