@@ -12,7 +12,7 @@ import {
12
12
} from '@netgrif/petriflow.svg' ;
13
13
import {
14
14
Arc ,
15
- InhibitorArc ,
15
+ InhibitorArc , Place ,
16
16
ReadArc ,
17
17
RegularPlaceTransitionArc ,
18
18
RegularTransitionPlaceArc ,
@@ -25,6 +25,10 @@ import {TransitionImport} from '../../resources/interface/transition-import';
25
25
import { PlaceImport } from '../../resources/interface/place-import' ;
26
26
import { ArcImport } from '../../resources/interface/arc-import' ;
27
27
import { ArcType } from '../../resources/interface/arc-type' ;
28
+ import { PetriNetImport } from '../../resources/interface/petri-net-import' ;
29
+ import { LoggerService } from '../../logger/services/logger.service' ;
30
+ import { SnackBarService } from '../../snack-bar/services/snack-bar.service' ;
31
+ import { TranslateService } from '@ngx-translate/core' ;
28
32
29
33
@Component ( {
30
34
selector : 'ncc-abstract-case-ref-field' ,
@@ -36,14 +40,16 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
36
40
37
41
constructor ( protected _petriflowCanvasService : PetriflowCanvasService , protected _petriflowFactoryService : PetriflowCanvasFactoryService ,
38
42
protected _petriflowConfigService : PetriflowCanvasConfigurationService , protected _caseResourceService : CaseResourceService ,
39
- protected _petriNetResourceService : PetriNetResourceService ) {
43
+ protected _petriNetResourceService : PetriNetResourceService , protected _log : LoggerService , protected _snackBar : SnackBarService ,
44
+ protected _translate : TranslateService ) {
40
45
}
41
46
42
47
ngAfterViewInit ( ) : void {
43
48
this . _petriNetResourceService . getNetByCaseId ( this . dataField . value ) . subscribe ( net => {
44
49
if ( net ) {
45
50
const trans : Array < PetriflowTransition > = [ ] ;
46
51
const places : Array < PetriflowPlace > = [ ] ;
52
+ const arcs : Array < PetriflowArc < any > > = [ ] ;
47
53
let minX : number = Number . MAX_SAFE_INTEGER ;
48
54
let minY : number = Number . MAX_SAFE_INTEGER ;
49
55
net . transitions . forEach ( ( value ) => {
@@ -57,17 +63,30 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
57
63
minY = Math . min ( minY , value . position . y ) ;
58
64
} )
59
65
net . arcs . forEach ( ( arc ) => {
60
- this . createArcs ( trans , places , arc ) ;
66
+ arcs . push ( this . createArcs ( trans , places , arc , net ) ) ;
61
67
arc . breakpoints ?. forEach ( value => {
62
68
minX = Math . min ( minX , value . x ) ;
63
69
minY = Math . min ( minY , value . y ) ;
64
70
} ) ;
65
71
} ) ;
66
- this . _petriflowCanvasService . panzoom ?. moveTo ( - minX + 20 , - minY + 20 ) ;
67
- setTimeout ( ( ) => {
68
- this . _petriflowCanvasService . panzoom ?. pause ( ) ;
69
- } )
72
+ trans . forEach ( value => {
73
+ if ( net . assignedTasks . includes ( value . canvasElement . label . textContent ) ) {
74
+ value . activate ( ) ;
75
+ }
76
+ if ( this . isEnabled ( value , places , arcs ) ) {
77
+ value . canvasElement . element . classList . add ( 'svg-transition-enabled' ) ;
78
+ }
79
+ } ) ;
80
+ this . _petriflowCanvasService . panzoom ?. moveTo ( - minX + 20 , - minY + 20 ) ;
81
+ if ( this . dataField . component ?. properties ?. lock === 'true' ) {
82
+ setTimeout ( ( ) => {
83
+ this . _petriflowCanvasService . panzoom ?. pause ( ) ;
84
+ } )
85
+ }
70
86
}
87
+ } , error => {
88
+ this . _log . error ( 'Getting net by Case ID failed' , error ) ;
89
+ this . _snackBar . openErrorSnackBar ( this . _translate . instant ( 'dataField.snackBar.caseNetGetFailed' ) ) ;
71
90
} ) ;
72
91
}
73
92
@@ -85,23 +104,38 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
85
104
return place ;
86
105
}
87
106
88
- protected createArcs ( trans : Array < PetriflowTransition > , places : Array < PetriflowPlace > , arc : ArcImport ) {
107
+ protected createArcs ( trans : Array < PetriflowTransition > , places : Array < PetriflowPlace > , arc : ArcImport , net : PetriNetImport ) {
89
108
let source : PetriflowPlace | PetriflowTransition = trans . find ( value => value . canvasElement . label . textContent === arc . sourceId ) ;
90
109
let destination : PetriflowPlace | PetriflowTransition ;
110
+ let activable : boolean = false ;
91
111
if ( source === undefined ) {
92
112
source = places . find ( value => value . canvasElement . label . textContent === arc . sourceId ) ;
93
113
destination = trans . find ( value => value . canvasElement . label . textContent === arc . destinationId ) ;
114
+ if ( net . assignedTasks . includes ( destination . canvasElement . label . textContent ) ) {
115
+ source . activate ( ) ;
116
+ destination . activate ( ) ;
117
+ activable = true ;
118
+ }
94
119
} else {
95
120
destination = places . find ( value => value . canvasElement . label . textContent === arc . destinationId ) ;
121
+ if ( net . finishedTasks . includes ( source . canvasElement . label . textContent ) ) {
122
+ source . activate ( ) ;
123
+ activable = true ;
124
+ }
96
125
}
97
126
if ( source === undefined || destination === undefined ) {
98
- console . error ( "Can't find source or destination for arc [" + arc . importId + "]" ) ;
127
+ this . _log . error ( "Can't find source or destination for arc [" + arc . importId + "]" ) ;
99
128
} else {
100
129
const newArc : Arc = this . createArc ( arc , source , destination ) ;
130
+ if ( activable ) {
131
+ newArc . activate ( ) ;
132
+ }
101
133
const petriflowArc : PetriflowArc < Arc > = this . createPetriflowArc ( arc , newArc , source ) ;
102
134
this . _petriflowCanvasService . canvas . container . appendChild ( newArc . container ) ;
103
135
this . _petriflowCanvasService . petriflowElementsCollection . arcs . push ( petriflowArc ) ;
136
+ return petriflowArc ;
104
137
}
138
+ return undefined
105
139
}
106
140
107
141
protected createArc ( arc : ArcImport , source : PetriflowTransition | PetriflowPlace , destination : PetriflowPlace | PetriflowTransition ) {
@@ -155,4 +189,40 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
155
189
return undefined ;
156
190
}
157
191
}
192
+
193
+ protected isEnabled ( t : PetriflowTransition , places : Array < PetriflowPlace > , arcs : Array < PetriflowArc < any > > ) : boolean {
194
+ const testMarking : Map < string , number > = new Map ( ) ;
195
+
196
+ for ( const place of places ) {
197
+ testMarking . set ( place . canvasElement . id , place . canvasElement . tokensCount ) ;
198
+ }
199
+ for ( const arc of arcs ) {
200
+ if ( arc . element . end . id === t . canvasElement . id && ( arc instanceof PetriflowInhibitorArc ) && testMarking . get ( ( arc . element . start as Place ) . id ) >= parseInt ( arc . element . multiplicity . data , 10 ) ) {
201
+ return false ;
202
+ }
203
+ }
204
+ for ( const arc of arcs ) {
205
+ if ( arc . element . end . id === t . canvasElement . id && ( arc instanceof PetriflowReadArc ) && testMarking . get ( ( arc . element . start as Place ) . id ) < parseInt ( arc . element . multiplicity . data , 10 ) ) {
206
+ return false ;
207
+ }
208
+ }
209
+ for ( const arc of arcs ) {
210
+ if ( arc . element . end . id === t . canvasElement . id && arc instanceof PetriflowPlaceTransitionArc ) {
211
+ const place = testMarking . get ( ( arc . element . start as Place ) . id )
212
+ testMarking . set ( ( arc . element . start as Place ) . id , place - parseInt ( arc . element . multiplicity . data , 10 ) ) ;
213
+ }
214
+ }
215
+ for ( const place of testMarking . values ( ) ) {
216
+ if ( place < 0 ) {
217
+ return false ;
218
+ }
219
+ }
220
+
221
+ return true ;
222
+ }
223
+
224
+ public getHeight ( ) {
225
+ return ( this . dataField . layout && this . dataField . layout . rows && this . dataField . layout . rows ) > 1 ?
226
+ this . dataField . layout . rows * CaseRefField . FIELD_HEIGHT : CaseRefField . FIELD_HEIGHT ;
227
+ }
158
228
}
0 commit comments