Skip to content

Commit 465988e

Browse files
committed
[PF-34] - Simulation
- refactor arc types
1 parent eef1bf0 commit 465988e

13 files changed

+66
-46
lines changed

local_build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Build and publish to local Verdaccio npm registry
2+
npm run build
3+
npm publish --registry http://localhost:4873

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netgrif/petriflow",
3-
"version": "1.3.6",
3+
"version": "1.4.0-rc4",
44
"description": "Javascript / Typescript library of Petriflow objects",
55
"main": "dist/petriflow.js",
66
"module": "dist/petriflow.esm.js",

src/lib/export/export-utils.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {
22
Action,
3+
ArcType,
34
CaseLogic,
45
Event,
56
Expression,
67
I18nString,
78
I18nWithDynamic,
89
Logic,
9-
PetriflowFunction
10+
PetriflowFunction,
11+
XmlArcType
1012
} from '../model';
1113

1214
export class ExportUtils {
@@ -145,4 +147,20 @@ export class ExportUtils {
145147
}
146148
element.appendChild(exportLogic);
147149
}
150+
151+
public arcTypeMapping: Map<ArcType, XmlArcType> = new Map([
152+
[ArcType.REGULAR_TP, XmlArcType.REGULAR],
153+
[ArcType.REGULAR_PT, XmlArcType.REGULAR],
154+
[ArcType.READ, XmlArcType.READ],
155+
[ArcType.RESET, XmlArcType.RESET],
156+
[ArcType.INHIBITOR, XmlArcType.INHIBITOR],
157+
]);
158+
159+
public exportArcType(type: ArcType): XmlArcType {
160+
const xmlType = this.arcTypeMapping.get(type);
161+
if (!xmlType) {
162+
throw new Error(`Unknown export mapping for arc type ${type}`);
163+
}
164+
return xmlType;
165+
}
148166
}

src/lib/export/export.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ export class ExportService {
433433
model.getArcs().forEach(arc => {
434434
const exportArc = this.xmlConstructor.createElement('arc');
435435
this._exportUtils.exportTag(exportArc, 'id', arc.id, true);
436-
this._exportUtils.exportTag(exportArc, 'type', arc.type);
436+
this._exportUtils.exportTag(exportArc, 'type', this._exportUtils.exportArcType(arc.type));
437437
this._exportUtils.exportTag(exportArc, 'sourceId', arc.source.id);
438438
this._exportUtils.exportTag(exportArc, 'destinationId', arc.destination.id);
439439
this._exportUtils.exportTag(exportArc, 'multiplicity', arc.multiplicity?.toString());

src/lib/import/import-utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Alignment,
44
Appearance,
55
Arc,
6-
ArcType,
76
CompactDirection,
87
Component,
98
DataEvent,
@@ -34,7 +33,7 @@ import {
3433
Template,
3534
Trigger,
3635
TriggerType,
37-
UserRef
36+
UserRef, XmlArcType
3837
} from '../model';
3938

4039
export class ImportUtils {
@@ -356,10 +355,10 @@ export class ImportUtils {
356355
return isStatic;
357356
}
358357

359-
public parseArcType(xmlArc: Element): ArcType {
360-
let parsedArcType = ArcType.REGULAR;
358+
public parseArcType(xmlArc: Element): XmlArcType {
359+
let parsedArcType = XmlArcType.REGULAR;
361360
if (this.checkLengthAndNodes(xmlArc, 'type')) {
362-
parsedArcType = xmlArc.getElementsByTagName('type')[0].childNodes[0].nodeValue as ArcType;
361+
parsedArcType = xmlArc.getElementsByTagName('type')[0].childNodes[0].nodeValue as XmlArcType;
363362
}
364363
return parsedArcType;
365364
}

src/lib/import/import.service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Alignment,
33
Arc,
4-
ArcType,
54
AssignedUser,
65
AssignPolicy,
76
Breakpoint,
@@ -45,7 +44,8 @@ import {
4544
TransitionEventType,
4645
TransitionLayout,
4746
UserRef,
48-
Validation
47+
Validation,
48+
XmlArcType
4949
} from '../model';
5050
import {ImportUtils} from './import-utils';
5151
import {PetriNetResult} from './petri-net-result';
@@ -592,7 +592,7 @@ export class ImportService {
592592
const parsedArcType = this.importUtils.parseArcType(xmlArc);
593593
const arc = this.resolveArc(source, target, parsedArcType, arcId, result);
594594
arc.multiplicity = this.importUtils.parseNumberValue(xmlArc, 'multiplicity') ?? 0;
595-
if (parsedArcType === ArcType.VARIABLE) {
595+
if (parsedArcType as string === 'variable') {
596596
arc.reference = xmlArc.getElementsByTagName('multiplicity')[0]?.childNodes[0]?.nodeValue ?? undefined;
597597
this.importUtils.checkVariability(result.model, arc, arc.reference);
598598
result.addInfo(`Variable arc '${arc.id}' converted to regular with data field reference`);
@@ -605,21 +605,21 @@ export class ImportService {
605605
return arc;
606606
}
607607

608-
resolveArc(source: string, target: string, parsedArcType: ArcType, arcId: string, result: PetriNetResult): Arc<NodeElement, NodeElement> {
608+
resolveArc(source: string, target: string, parsedArcType: XmlArcType, arcId: string, result: PetriNetResult): Arc<NodeElement, NodeElement> {
609609
// TODO: refactor
610610
let place, transition;
611611
switch (parsedArcType) {
612-
case ArcType.INHIBITOR:
612+
case XmlArcType.INHIBITOR:
613613
[place, transition] = this.getPlaceTransition(result, source, target, arcId);
614614
return new InhibitorArc(place, transition, arcId);
615-
case ArcType.RESET:
615+
case XmlArcType.RESET:
616616
[place, transition] = this.getPlaceTransition(result, source, target, arcId);
617617
return new ResetArc(place, transition, arcId);
618-
case ArcType.READ:
618+
case XmlArcType.READ:
619619
[place, transition] = this.getPlaceTransition(result, source, target, arcId);
620620
return new ReadArc(place, transition, arcId);
621-
case ArcType.REGULAR:
622-
case ArcType.VARIABLE:
621+
case XmlArcType.REGULAR:
622+
case 'variable' as XmlArcType:
623623
if (result.model.getPlace(source)) {
624624
[place, transition] = this.getPlaceTransition(result, source, target, arcId);
625625
return new RegularPlaceTransitionArc(place, transition, arcId);

src/lib/model/arc/arc-type.enum.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
export enum ArcType {
2+
REGULAR_PT = 'regular_pt',
3+
REGULAR_TP = 'regular_tp',
4+
READ = 'read',
5+
RESET = 'reset',
6+
INHIBITOR = 'inhibitor',
7+
}
8+
9+
export enum XmlArcType {
210
REGULAR = 'regular',
311
READ = 'read',
412
RESET = 'reset',
513
INHIBITOR = 'inhibitor',
6-
VARIABLE = 'variable'
714
}

src/lib/model/arc/arc.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
import {Element} from '../petrinet/element';
12
import {NodeElement} from '../petrinet/node-element';
23
import {ArcType} from './arc-type.enum';
34
import {Breakpoint} from './breakpoint';
45

5-
export abstract class Arc<S extends NodeElement, D extends NodeElement> {
6-
private _id: string;
6+
export abstract class Arc<S extends NodeElement, D extends NodeElement> extends Element {
77
private _source: S;
88
private _destination: D;
99
private _multiplicity: number;
1010
private _reference?: string;
1111
private _breakpoints: Array<Breakpoint>;
1212

1313
constructor(source: S, target: D, id: string) {
14-
this._id = id;
14+
super(id);
1515
this._source = source;
1616
this._destination = target;
1717
this._multiplicity = 1;
@@ -20,14 +20,6 @@ export abstract class Arc<S extends NodeElement, D extends NodeElement> {
2020

2121
abstract get type(): ArcType;
2222

23-
get id(): string {
24-
return this._id;
25-
}
26-
27-
set id(value: string) {
28-
this._id = value;
29-
}
30-
3123
get source(): S {
3224
return this._source;
3325
}

src/lib/model/arc/regular-place-transition-arc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class RegularPlaceTransitionArc extends PlaceTransitionArc {
2424
}
2525

2626
get type(): ArcType {
27-
return ArcType.REGULAR;
27+
return ArcType.REGULAR_PT;
2828
}
2929

3030
clone(): RegularPlaceTransitionArc {

src/lib/model/arc/regular-transition-place-arc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class RegularTransitionPlaceArc extends TransitionPlaceArc {
1111
}
1212

1313
get type(): ArcType {
14-
return ArcType.REGULAR;
14+
return ArcType.REGULAR_TP;
1515
}
1616

1717
clone(): RegularTransitionPlaceArc {

0 commit comments

Comments
 (0)