@@ -10,20 +10,27 @@ export default class ModelInterpreter {
10
10
jsonModel : Object ;
11
11
modelMap : { [ key : string ] : Map < String , CompositionNode | MechanismNode | ProjectionLink | any > } ;
12
12
pnlModel : { [ key : string ] : Array < CompositionNode | MechanismNode | ProjectionLink | any > } ;
13
+ metaModelMap : { [ key : string ] : Map < String , CompositionNode | MechanismNode | ProjectionLink | any > } ;
13
14
metaModel : { [ key : string ] : Array < MetaNode | MetaLink > } ;
14
15
nodeIdsMap : Map < any , any > ;
15
16
linkIdsMap : Map < any , any > ;
16
17
17
18
constructor ( model : any ) {
18
19
this . modelMap = {
19
- 'nodes' : new Map ( ) ,
20
- 'links' : new Map ( )
20
+ [ PNLClasses . COMPOSITION ] : new Map ( ) ,
21
+ [ PNLClasses . MECHANISM ] : new Map ( ) ,
22
+ [ PNLClasses . PROJECTION ] : new Map ( ) ,
21
23
} ;
22
24
this . pnlModel = {
23
25
[ PNLClasses . COMPOSITION ] : [ ] ,
24
26
[ PNLClasses . MECHANISM ] : [ ] ,
25
27
[ PNLClasses . PROJECTION ] : [ ] ,
26
28
} ;
29
+ this . metaModelMap = {
30
+ [ PNLClasses . COMPOSITION ] : new Map ( ) ,
31
+ [ PNLClasses . MECHANISM ] : new Map ( ) ,
32
+ [ PNLClasses . PROJECTION ] : new Map ( ) ,
33
+ } ;
27
34
this . metaModel = {
28
35
[ PNLClasses . COMPOSITION ] : [ ] ,
29
36
[ PNLClasses . MECHANISM ] : [ ] ,
@@ -48,10 +55,6 @@ export default class ModelInterpreter {
48
55
return this . pnlModel ;
49
56
}
50
57
51
- updateModel ( newModel : any ) {
52
- this . jsonModel = this . _convertModel ( newModel ) ;
53
- }
54
-
55
58
getModel ( ) {
56
59
return this . jsonModel ;
57
60
}
@@ -60,12 +63,29 @@ export default class ModelInterpreter {
60
63
this . metaModel [ PNLClasses . COMPOSITION ] = this . pnlModel [ PNLClasses . COMPOSITION ] . map (
61
64
( item :CompositionNode ) => item . getMetaNode ( )
62
65
) ;
66
+ this . metaModelMap [ PNLClasses . COMPOSITION ] = new Map (
67
+ this . metaModel [ PNLClasses . COMPOSITION ] . map ( object => {
68
+ return [ object . getId ( ) , object ] ;
69
+ } )
70
+ ) ;
71
+
63
72
this . metaModel [ PNLClasses . MECHANISM ] = this . pnlModel [ PNLClasses . MECHANISM ] . map (
64
73
( item :MechanismNode ) => item . getMetaNode ( )
65
74
) ;
75
+ this . metaModelMap [ PNLClasses . MECHANISM ] = new Map (
76
+ this . metaModel [ PNLClasses . MECHANISM ] . map ( object => {
77
+ return [ object . getId ( ) , object ] ;
78
+ } )
79
+ ) ;
80
+
66
81
this . metaModel [ PNLClasses . PROJECTION ] = this . pnlModel [ PNLClasses . PROJECTION ] . map (
67
82
( item :ProjectionLink ) => item . getMetaLink ( )
68
83
) ;
84
+ this . metaModelMap [ PNLClasses . PROJECTION ] = new Map (
85
+ this . metaModel [ PNLClasses . PROJECTION ] . map ( object => {
86
+ return [ object . getId ( ) , object ] ;
87
+ } )
88
+ ) ;
69
89
}
70
90
71
91
getMetaModel ( ) {
@@ -80,6 +100,13 @@ export default class ModelInterpreter {
80
100
return this . modelMap ;
81
101
}
82
102
103
+ updateModel ( item : MetaNode | MetaLink ) {
104
+ // if (this.metaModelMap[item.getShape()].has(item.getId())) {
105
+ console . log ( 'this is where I update the node' ) ;
106
+ console . log ( item ) ;
107
+ // }
108
+ }
109
+
83
110
parseNodePorts ( name : string , type : string ) : { [ key : string ] : any } {
84
111
let ports : { [ key : string ] : any [ ] } = {
85
112
[ PortTypes . INPUT_PORT ] : [ ] ,
@@ -136,7 +163,7 @@ export default class ModelInterpreter {
136
163
}
137
164
extra [ 'isExpanded' ] = false ;
138
165
newNode = new CompositionNode ( item ?. name , parent , ports , extra ) ;
139
- modelMap [ 'nodes' ] . set ( newNode . getName ( ) , newNode ) ;
166
+ modelMap [ PNLClasses . COMPOSITION ] . set ( newNode . getName ( ) , newNode ) ;
140
167
// temp array to host all the nested compositions
141
168
let childrenCompositions : Array < any > = [ ] ;
142
169
@@ -147,7 +174,7 @@ export default class ModelInterpreter {
147
174
// we park for now nested compositions
148
175
childrenCompositions . push ( child )
149
176
} else {
150
- newChild = this . castMechanism ( child , newNode , this . modelMap ) ;
177
+ newChild = this . castMechanism ( child , newNode , modelMap ) ;
151
178
newChild . setParent ( newNode ) ;
152
179
newNode . addChild ( newChild ) ;
153
180
}
@@ -159,7 +186,7 @@ export default class ModelInterpreter {
159
186
// Now da we have all the mechanisms in the idsMap we continue with the compositions
160
187
childrenCompositions . forEach ( ( child : any ) => {
161
188
let newChild = undefined ;
162
- newChild = this . nestedComposition ( child , newNode , this . modelMap ) ;
189
+ newChild = this . nestedComposition ( child , newNode , modelMap ) ;
163
190
newNode . addChild ( newChild ) ;
164
191
165
192
if ( newChild && ! this . nodeIdsMap . has ( child ?. _gvid ) ) {
@@ -170,7 +197,7 @@ export default class ModelInterpreter {
170
197
item . edges . forEach ( ( edge : any ) => {
171
198
let tail = this . nodeIdsMap . get ( edge . tail ) ;
172
199
let head = this . nodeIdsMap . get ( edge . head ) ;
173
- let newChild = this . castEdge ( edge , tail , head , newNode , this . modelMap ) ;
200
+ let newChild = this . castEdge ( edge , tail , head , newNode , modelMap ) ;
174
201
if ( newChild && ! this . linkIdsMap . has ( edge ?. _gvid ) ) {
175
202
this . linkIdsMap . set ( edge ?. _gvid , newChild ) ;
176
203
}
@@ -209,7 +236,7 @@ export default class ModelInterpreter {
209
236
}
210
237
extra [ 'isExpanded' ] = false ;
211
238
newNode = new CompositionNode ( item ?. name , parent , ports , extra ) ;
212
- modelMap [ 'nodes' ] . set ( newNode . getName ( ) , newNode ) ;
239
+ modelMap [ PNLClasses . COMPOSITION ] . set ( newNode . getName ( ) , newNode ) ;
213
240
214
241
// Iterates nodes of the nested composition to fill the children map/array
215
242
item . nodes . forEach ( ( id : any ) => {
@@ -240,7 +267,7 @@ export default class ModelInterpreter {
240
267
}
241
268
} ;
242
269
newNode = new MechanismNode ( item ?. name , parent , ports , extra , ) ;
243
- modelMap [ 'nodes' ] . set ( newNode . getName ( ) , newNode ) ;
270
+ modelMap [ PNLClasses . MECHANISM ] . set ( newNode . getName ( ) , newNode ) ;
244
271
this . pnlModel [ PNLClasses . MECHANISM ] . push ( newNode ) ;
245
272
return newNode ;
246
273
}
@@ -267,7 +294,7 @@ export default class ModelInterpreter {
267
294
false ,
268
295
extra
269
296
) ;
270
- modelMap [ 'links' ] . set ( newNode . getName ( ) , newNode ) ;
297
+ modelMap [ PNLClasses . PROJECTION ] . set ( newNode . getName ( ) , newNode ) ;
271
298
this . pnlModel [ PNLClasses . PROJECTION ] . push ( newNode ) ;
272
299
return newNode ;
273
300
}
0 commit comments