1
1
import { AfterViewInit , Component , Input } from '@angular/core' ;
2
- import { CaseRefField } from '@netgrif/components-core' ;
2
+ import { CaseRefField , CaseResourceService , PetriNetResourceService , ArcImport } from '@netgrif/components-core' ;
3
3
import {
4
+ PetriflowArc ,
4
5
PetriflowCanvasConfigurationService ,
5
6
PetriflowCanvasFactoryService ,
6
- PetriflowCanvasService
7
+ PetriflowCanvasService ,
8
+ PetriflowInhibitorArc ,
9
+ PetriflowPlace ,
10
+ PetriflowPlaceTransitionArc , PetriflowReadArc ,
11
+ PetriflowResetArc ,
12
+ PetriflowTransition ,
13
+ PetriflowTransitionPlaceArc
7
14
} from '@netgrif/petriflow.svg' ;
15
+ import {
16
+ Arc , InhibitorArc , ReadArc , RegularPlaceTransitionArc ,
17
+ RegularTransitionPlaceArc , ResetArc
18
+ } from '@netgrif/petri.svg' ;
8
19
9
20
@Component ( {
10
21
selector : 'nc-case-ref-field' ,
@@ -16,15 +27,112 @@ export class CaseRefFieldComponent implements AfterViewInit{
16
27
@Input ( ) public dataField : CaseRefField ;
17
28
18
29
constructor ( private _petriflowCanvasService : PetriflowCanvasService , private _petriflowFactoryService : PetriflowCanvasFactoryService ,
19
- private _petriflowConfigService : PetriflowCanvasConfigurationService ) {
30
+ private _petriflowConfigService : PetriflowCanvasConfigurationService , private _caseResourceService : CaseResourceService ,
31
+ private _petriNetResourceService : PetriNetResourceService ) {
20
32
}
21
33
22
34
ngAfterViewInit ( ) : void {
23
- const transition = this . _petriflowFactoryService . createTransition ( new DOMPoint ( 100 , 100 ) ) ;
24
- this . _petriflowConfigService . addTransitionEvents ( transition ) ;
35
+ this . _petriNetResourceService . getNetByCaseId ( this . dataField . value ) . subscribe ( net => {
36
+ if ( net ) {
37
+ const trans : Array < PetriflowTransition > = [ ] ;
38
+ const places : Array < PetriflowPlace > = [ ] ;
39
+ let minX : number = 1000 ;
40
+ let minY : number = 1000 ;
41
+ net . transitions . forEach ( ( value ) => {
42
+ const transition = this . _petriflowFactoryService . createTransition ( new DOMPoint ( value . position . x , value . position . y ) ) ;
43
+ transition . changeId ( value . stringId ) ;
44
+ minX = Math . min ( minX , value . position . x ) ;
45
+ minY = Math . min ( minY , value . position . y ) ;
46
+ this . _petriflowConfigService . addTransitionEvents ( transition ) ;
47
+ trans . push ( transition ) ;
48
+ } )
49
+ net . places . forEach ( ( value ) => {
50
+ const place = this . _petriflowFactoryService . createPlace ( value . tokens , new DOMPoint ( value . position . x , value . position . y ) ) ;
51
+ place . changeId ( value . stringId ) ;
52
+ minX = Math . min ( minX , value . position . x ) ;
53
+ minY = Math . min ( minY , value . position . y ) ;
54
+ this . _petriflowConfigService . addPlaceEvents ( place ) ;
55
+ places . push ( place ) ;
56
+ } )
57
+ net . arcs . forEach ( ( arc ) => {
58
+ let source : PetriflowPlace | PetriflowTransition = trans . find ( value => value . canvasElement . label . textContent === arc . sourceId ) ;
59
+ let destination : PetriflowPlace | PetriflowTransition ;
60
+ if ( source === undefined ) {
61
+ source = places . find ( value => value . canvasElement . label . textContent === arc . sourceId ) ;
62
+ destination = trans . find ( value => value . canvasElement . label . textContent === arc . destinationId ) ;
63
+ } else {
64
+ destination = places . find ( value => value . canvasElement . label . textContent === arc . destinationId ) ;
65
+ }
66
+ if ( source === undefined || destination === undefined ) {
67
+ console . error ( "Can't find source or destination for arc [" + arc . importId + "]" ) ;
68
+ } else {
69
+ const newArc : Arc = this . createArc ( arc , source , destination ) ;
70
+ const petriflowArc : PetriflowArc < Arc > = this . createPetriflowArc ( arc , newArc , source ) ;
71
+ this . _petriflowCanvasService . canvas . container . appendChild ( newArc . container ) ;
72
+ this . _petriflowCanvasService . petriflowElementsCollection . arcs . push ( petriflowArc ) ;
73
+ arc . breakpoints ?. forEach ( value => {
74
+ minX = Math . min ( minX , value . x ) ;
75
+ minY = Math . min ( minY , value . y ) ;
76
+ } ) ;
77
+ }
78
+ } ) ;
79
+ this . _petriflowCanvasService . panzoom ?. moveTo ( - minX + 20 , - minY + 20 ) ;
80
+ setTimeout ( ( ) => {
81
+ this . _petriflowCanvasService . panzoom ?. pause ( ) ;
82
+ } )
83
+ }
84
+ } ) ;
85
+ }
25
86
26
- const place = this . _petriflowFactoryService . createPlace ( 1 , new DOMPoint ( 150 , 100 ) ) ;
27
- this . _petriflowConfigService . addPlaceEvents ( place ) ;
87
+ private createArc ( arc : ArcImport , source : PetriflowTransition | PetriflowPlace , destination : PetriflowPlace | PetriflowTransition ) {
88
+ if ( source instanceof PetriflowPlace ) {
89
+ switch ( arc . type ) {
90
+ case 'arc' : {
91
+ return this . _petriflowFactoryService . createArc ( RegularPlaceTransitionArc , source . canvasElement , destination . canvasElement , arc . breakpoints , arc . multiplicity ) ;
92
+ }
93
+ case 'reset' : {
94
+ return this . _petriflowFactoryService . createArc ( ResetArc , source . canvasElement , destination . canvasElement , arc . breakpoints , arc . multiplicity ) ;
95
+ }
96
+ case 'inhibitor' : {
97
+ return this . _petriflowFactoryService . createArc ( InhibitorArc , source . canvasElement , destination . canvasElement , arc . breakpoints , arc . multiplicity ) ;
98
+ }
99
+ case 'read' : {
100
+ return this . _petriflowFactoryService . createArc ( ReadArc , source . canvasElement , destination . canvasElement , arc . breakpoints , arc . multiplicity ) ;
101
+ }
102
+ default : {
103
+ return undefined ;
104
+ }
105
+ }
106
+ } else if ( arc . type === 'arc' ) {
107
+ return this . _petriflowFactoryService . createArc ( RegularTransitionPlaceArc , source . canvasElement , destination . canvasElement , arc . breakpoints , arc . multiplicity ) ;
108
+ } else {
109
+ return undefined ;
110
+ }
28
111
}
29
112
113
+ private createPetriflowArc ( arc : ArcImport , newArc : Arc , source : PetriflowTransition | PetriflowPlace ) {
114
+ if ( source instanceof PetriflowPlace ) {
115
+ switch ( arc . type ) {
116
+ case 'arc' : {
117
+ return this . _petriflowFactoryService . createArc ( PetriflowPlaceTransitionArc , newArc ) ;
118
+ }
119
+ case 'reset' : {
120
+ return this . _petriflowFactoryService . createArc ( PetriflowResetArc , newArc ) ;
121
+ }
122
+ case 'inhibitor' : {
123
+ return this . _petriflowFactoryService . createArc ( PetriflowInhibitorArc , newArc ) ;
124
+ }
125
+ case 'read' : {
126
+ return this . _petriflowFactoryService . createArc ( PetriflowReadArc , newArc ) ;
127
+ }
128
+ default : {
129
+ return undefined ;
130
+ }
131
+ }
132
+ } else if ( arc . type === 'arc' ) {
133
+ return this . _petriflowFactoryService . createArc ( PetriflowTransitionPlaceArc , newArc ) ;
134
+ } else {
135
+ return undefined ;
136
+ }
137
+ }
30
138
}
0 commit comments