-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathAasEntityBuilder.cs
More file actions
823 lines (713 loc) · 35.4 KB
/
AasEntityBuilder.cs
File metadata and controls
823 lines (713 loc) · 35.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
/*
Copyright (c) 2018-2019 Festo AG & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>
Author: Michael Hoffmeister
This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
This source code may use other Open Source software components (see LICENSE.txt).
*/
using AdminShellNS;
using Extensions;
using Opc.Ua;
using System.Collections.Generic;
namespace AasOpcUaServer
{
public class AasEntityBuilder
{
//// Static singleton for AAS entity builders
// ugly, but simple: the singleton variables gives access to information
//
public static AasModeManager nodeMgr = null;
public AdminShellPackageEnv[] packages = null;
public AasxUaServerOptions theServerOptions = null;
public IDictionary<NodeId, IList<Opc.Ua.IReference>> nodeMgrExternalReferences = null;
/// <summary>
/// Root of AASes
/// </summary>
public NodeState RootAAS = null;
/// <summary>
/// Root for CDs
/// </summary>
public NodeState RootConceptDescriptions = null;
/// <summary>
/// Root for DataSpecifications
/// </summary>
public NodeState RootDataSpecifications = null;
/// <summary>
/// Provide a root node, if semantic ids shall create missing dictionary entry (targets),
/// which can not be found in the AAS environment.
/// </summary>
public NodeState RootMissingDictionaryEntries = null;
public AasEntityBuilder(AasModeManager nodeMgr, AdminShellPackageEnv[] package,
IDictionary<NodeId, IList<Opc.Ua.IReference>> externalReferences, AasxUaServerOptions options)
{
AasEntityBuilder.nodeMgr = nodeMgr;
this.packages = package;
this.nodeMgrExternalReferences = externalReferences;
this.aasTypes = new AasTypeEntities();
this.theServerOptions = options;
this.aasTypes.BuildEntites(this);
}
public class NodeRecord
{
public NodeState uanode = null;
public IReferable referable = null;
public string identification = null;
public NodeRecord() { }
public NodeRecord(NodeState uanode, IReferable referable)
{
this.uanode = uanode;
this.referable = referable;
}
public NodeRecord(NodeState uanode, string identification)
{
this.uanode = uanode;
this.identification = identification;
}
}
private Dictionary<IReferable, NodeRecord> NodeRecordFromReferable
= new Dictionary<IReferable, NodeRecord>();
private Dictionary<string, NodeRecord> NodeRecordFromIdentificationHash
= new Dictionary<string, NodeRecord>();
/// <summary>
/// Use this function always to remeber new node records.
/// </summary>
/// <param name="nr"></param>
public void AddNodeRecord(NodeRecord nr)
{
if (nr.referable != null && !NodeRecordFromReferable.ContainsKey(nr.referable))
NodeRecordFromReferable.Add(nr.referable, nr);
if (nr.identification != null && nr.identification != "")
{
var hash = "" + nr.identification.Trim().ToUpper();
if (!NodeRecordFromIdentificationHash.ContainsKey(hash))
NodeRecordFromIdentificationHash.Add(hash, nr);
}
}
/// <summary>
/// Use this always to lookup node records from Referable
/// </summary>
/// <param name="referable"></param>
/// <returns></returns>
public NodeRecord LookupNodeRecordFromReferable(IReferable referable)
{
if (NodeRecordFromReferable == null || !NodeRecordFromReferable.ContainsKey(referable))
return null;
return NodeRecordFromReferable[referable];
}
/// <summary>
/// Use this always to lookup node records from Indentifiable
/// </summary>
/// <param name="identification"></param>
/// <returns></returns>
public NodeRecord LookupNodeRecordFromIdentification(string identification)
{
var hash = "" + identification.Trim().ToUpper();
if (NodeRecordFromReferable == null || !NodeRecordFromIdentificationHash.ContainsKey(hash))
return null;
return NodeRecordFromIdentificationHash[hash];
}
/// <summary>
/// Base class for actions, which shall be done on the 2nd pass of the information model building
/// </summary>
public class NodeLateAction
{
public NodeState uanode = null;
}
/// <summary>
/// Make a late reference to another node identified by a AAS reference information
/// </summary>
public class NodeLateActionLinkToReference : NodeLateAction
{
public enum ActionType { None, SetAasReference, SetDictionaryEntry }
public Reference targetReference = null;
public ActionType actionType = ActionType.None;
public NodeLateActionLinkToReference(NodeState uanode, Reference targetReference,
ActionType actionType)
{
this.uanode = uanode;
this.targetReference = targetReference;
this.actionType = actionType;
}
}
private List<NodeLateAction> noteLateActions = new List<NodeLateAction>();
/// <summary>
/// Add a late action, which will be processed as 2nd phase of info model preparation
/// </summary>
/// <param name="la"></param>
public void AddNodeLateAction(NodeLateAction la)
{
this.noteLateActions.Add(la);
}
private IReferable FindAllReferableByReference(AdminShellPackageEnv[] packages,
Reference rf)
{
// access
if (packages == null || rf == null)
return null;
// find
foreach (var pck in packages)
{
var x = pck?.AasEnv?.FindReferableByReference(rf);
if (x != null)
return x;
}
// oh, no
return null;
}
/// <summary>
/// Top level creation functions. Uses the definitions of RootAAS, RootConceptDescriptions,
/// RootDataSpecifications to synthesize information model
/// </summary>
public void CreateAddInstanceObjects(AasCore.Aas3_0.Environment env)
{
if (RootAAS == null)
return;
// CDs (build 1st to be "remembered" as targets for "HasDictionaryEntry")
if (env.ConceptDescriptions != null && this.RootConceptDescriptions != null)
foreach (var cd in env.ConceptDescriptions)
{
this.AasTypes.ConceptDescription.CreateAddElements(this.RootConceptDescriptions,
AasUaBaseEntity.CreateMode.Instance, cd);
}
// AAS
if (env.AssetAdministrationShells != null)
foreach (var aas in env.AssetAdministrationShells)
this.AasTypes.AAS.CreateAddInstanceObject(RootAAS, env, aas);
// go through late actions
foreach (var la in this.noteLateActions)
{
// make a Reference ??
var lax = la as NodeLateActionLinkToReference;
// more simple case: AasReference between known entities
if (lax != null && lax.actionType == NodeLateActionLinkToReference.ActionType.SetAasReference
&& lax.uanode != null
&& this.packages != null)
{
// 1st, take reference and turn it into Referable
var targetReferable = FindAllReferableByReference(this.packages, lax.targetReference);
if (targetReferable == null)
continue;
// 2nd, try to lookup the Referable and turn it into a uanode
var targetNodeRec = this.LookupNodeRecordFromReferable(targetReferable);
if (targetNodeRec == null || targetNodeRec.uanode == null)
continue;
// now, we have everything to formulate a reference
if (!lax.uanode.ReferenceExists(this.AasTypes.HasAasReference.GetTypeNodeId(), false,
targetNodeRec.uanode.NodeId))
{
lax.uanode.AddReference(this.AasTypes.HasAasReference.GetTypeNodeId(), false,
targetNodeRec.uanode.NodeId);
}
}
// a bit more complicated: could include a "empty reference" to outside concept
if (lax != null && lax.actionType == NodeLateActionLinkToReference.ActionType.SetDictionaryEntry
&& lax.uanode != null
&& this.packages != null)
{
// tracking
var foundAtAll = false;
// 1st, take reference and turn it into Referable
var targetReferable = FindAllReferableByReference(this.packages, lax.targetReference);
if (targetReferable != null)
{
// 2nd, try to lookup the Referable and turn it into a uanode
var targetNodeRec = this.LookupNodeRecordFromReferable(targetReferable);
if (targetNodeRec != null && targetNodeRec.uanode != null)
{
// simple case: have a target node, just make a link
if (lax.uanode.ReferenceExists(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
targetNodeRec.uanode.NodeId))
{
lax.uanode.AddReference(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
targetNodeRec.uanode.NodeId);
}
foundAtAll = true;
}
}
// make "empty reference"??
// by definition, this makes only sense if the targetReference has exactly 1 key, as we could
// only have one key in a dictionary entry
if (!foundAtAll && lax.targetReference.Keys.Count == 1)
{
// can turn the targetReference to a simple identification
//var targetId = new AdminShellConverters().Identifier(lax.targetReference.Keys[0].Value);
var targetId = lax.targetReference.Keys[0].Value;
// we might have such an (empty) target already available as uanode
var nr = this.LookupNodeRecordFromIdentification(targetId);
if (nr != null)
{
// just create the missing link
if (!lax.uanode.ReferenceExists(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
nr.uanode?.NodeId))
{
lax.uanode.AddReference(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
nr.uanode?.NodeId);
}
}
else
{
// create NEW empty reference?
if (this.RootMissingDictionaryEntries != null)
{
// create missing object
var miss = this.CreateAddObject(
this.RootMissingDictionaryEntries,
AasUaBaseEntity.CreateMode.Instance,
targetId,
ReferenceTypeIds.HasComponent,
this.AasTypes.ConceptDescription.GetTypeObjectFor(targetId)?.NodeId);
// add the reference
if (lax.uanode.ReferenceExists(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
miss?.NodeId))
{
lax.uanode.AddReference(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
miss?.NodeId);
}
// put it into the NodeRecords, that it can be re-used?? no!!
this.AddNodeRecord(new AasEntityBuilder.NodeRecord(miss, targetId));
}
else
{
// just create the missing link
// TODO (MIHO, 2020-08-06): check, which namespace shall be used
var missingTarget = new ExpandedNodeId("" + targetId, 99);
lax.uanode.AddReference(this.AasTypes.HasDictionaryEntry.GetTypeNodeId(), false,
missingTarget);
}
}
}
}
}
}
//// references
//
// ReSharper disable once UnusedType.Global
public class AasReference : Opc.Ua.IReference
{
// private members
private NodeId referenceTypeId = null;
private bool isInverse = false;
private ExpandedNodeId targetId = null;
// public getters for IReference
public NodeId ReferenceTypeId { get { return referenceTypeId; } }
public bool IsInverse { get { return isInverse; } }
public ExpandedNodeId TargetId { get { return targetId; } }
public AasReference()
{
}
public AasReference(NodeId referenceTypeId, bool isInverse, ExpandedNodeId targetId)
{
this.referenceTypeId = referenceTypeId;
this.isInverse = isInverse;
this.targetId = targetId;
}
}
//// Reference types
//
public ReferenceTypeState CreateAddReferenceType(
string browseDisplayName, string inverseName,
uint preferredNumId = 0, bool useZeroNS = false, NodeId sourceId = null)
{
// create node itself
var x = new ReferenceTypeState();
x.BrowseName = browseDisplayName;
x.DisplayName = browseDisplayName;
x.InverseName = inverseName;
x.Symmetric = false;
x.IsAbstract = false;
x.NodeId = nodeMgr.NewType(nodeMgr.SystemContext, AasUaBaseEntity.CreateMode.Type, x, preferredNumId);
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
// set Subtype reference
if (sourceId == null)
sourceId = new NodeId(32, 0);
nodeMgr.AddExternalReferencePublic(sourceId, ReferenceTypeIds.HasSubtype, false,
x.NodeId, nodeMgrExternalReferences);
// done
return x;
}
//// Folders
//
public FolderState CreateAddFolder(AasUaBaseEntity.CreateMode mode,
NodeState parent, string browseDisplayName)
{
var x = new FolderState(parent);
x.BrowseName = browseDisplayName;
x.DisplayName = browseDisplayName;
x.NodeId = nodeMgr.NewFromParent(nodeMgr.SystemContext, mode, x, parent);
x.TypeDefinitionId = ObjectTypeIds.FolderType;
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
if (parent != null)
parent.AddChild(x);
return x;
}
//// DataTypes
//
public DataTypeState CreateAddDataType(
string browseDisplayName, NodeId superTypeId, uint preferredNumId = 0)
{
var x = new DataTypeState();
x.BrowseName = "" + browseDisplayName;
x.DisplayName = "" + browseDisplayName;
x.Description = new LocalizedText("en", browseDisplayName);
x.SuperTypeId = superTypeId;
x.NodeId = nodeMgr.NewType(nodeMgr.SystemContext, AasUaBaseEntity.CreateMode.Type, x, preferredNumId);
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
return x;
}
//// Object types
//
/// <summary>
/// Helper to create an ObjectType-Node and it to the information model.
/// </summary>
/// <param name="browseDisplayName">Name displayed in the node tree</param>
/// <param name="superTypeId">Base class or similar</param>
/// <param name="preferredNumId">Numerical id of the node in the default name space to be set fixed</param>
/// <param name="descriptionKey">Lookup a Description on AAS literal/ refSemantics</param>
/// <param name="modellingRule">Modeling Rule, if not None</param>
public BaseObjectTypeState CreateAddObjectType(
string browseDisplayName,
NodeId superTypeId,
uint preferredNumId = 0,
string descriptionKey = null,
AasUaNodeHelper.ModellingRule modellingRule = AasUaNodeHelper.ModellingRule.None)
{
var x = AasUaNodeHelper.CreateObjectType(browseDisplayName, superTypeId, descriptionKey: descriptionKey);
x.NodeId = nodeMgr.NewType(nodeMgr.SystemContext, AasUaBaseEntity.CreateMode.Type,
x, preferredNumId);
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
return x;
}
//// Variable types
//
public class AasVariableTypeState : BaseVariableTypeState
{
// ReSharper disable once EmptyConstructor
public AasVariableTypeState()
: base()
{ }
}
public AasVariableTypeState CreateAddVariableType(string browseDisplayName, NodeId superTypeId,
uint preferredNumId = 0)
{
var x = new AasVariableTypeState();
x.BrowseName = "" + browseDisplayName;
x.DisplayName = "" + browseDisplayName;
x.Description = new LocalizedText("en", browseDisplayName);
x.SuperTypeId = superTypeId;
x.NodeId = nodeMgr.NewType(nodeMgr.SystemContext, AasUaBaseEntity.CreateMode.Type,
x, preferredNumId);
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
return x;
}
//// Objects
//
/// <summary>
/// Helper to create an Object-Node. Note: __NO__ NodeId is created by the default! Must be done by outer
/// functionality!!
/// </summary>
/// <param name="parent">Parent node</param>
/// <param name="mode">Type or instance</param>
/// <param name="browseDisplayName">Name displayed in the node tree</param>
/// <param name="referenceTypeFromParentId"></param>
/// <param name="typeDefinitionId">Type of the Object</param>
/// <param name="modellingRule">Modeling Rule, if not None</param>
/// <param name="extraName"></param>
/// <returns>The node</returns>
public BaseObjectState CreateAddObject(
NodeState parent, AasUaBaseEntity.CreateMode mode,
string browseDisplayName,
NodeId referenceTypeFromParentId = null,
NodeId typeDefinitionId = null,
AasUaNodeHelper.ModellingRule modellingRule = AasUaNodeHelper.ModellingRule.None,
string extraName = null)
{
var x = AasUaNodeHelper.CreateObject(parent, browseDisplayName, typeDefinitionId: typeDefinitionId,
modellingRule: modellingRule, extraName: extraName);
x.NodeId = nodeMgr.NewFromParent(nodeMgr.SystemContext, mode, x, parent);
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
if (parent != null)
parent.AddChild(x);
if (referenceTypeFromParentId != null)
{
if (parent != null)
{
if (!parent.ReferenceExists(referenceTypeFromParentId, false, x.NodeId))
parent.AddReference(referenceTypeFromParentId, false, x.NodeId);
if (referenceTypeFromParentId == ReferenceTypeIds.HasComponent)
x.AddReference(referenceTypeFromParentId, true, parent.NodeId);
if (referenceTypeFromParentId == ReferenceTypeIds.HasProperty)
x.AddReference(referenceTypeFromParentId, true, parent.NodeId);
}
//// nodeMgr.AddReference(parentNodeId, new AasReference(referenceTypeId, false, x.NodeId));
}
//// if (typeDefinitionId != null)
//// {
//// x.TypeDefinitionId = typeDefinitionId;
//// x.AddReference(ReferenceTypeIds.HasTypeDefinition, false, typeDefinitionId);
//// // nodeMgr.AddReference(x.NodeId, new AasReference(ReferenceTypeIds.HasTypeDefinition, false,
//// // typeDefinitionId));
//// }
return x;
}
//// Properties
//
/// <summary>
/// Helper to create an PropertyState-Node for a certain type and add it to the information model.
/// Note: __NO__ NodeId is created by the default! Must be done by outer functionality!!
/// </summary>
/// <typeparam name="T">C# type of the proprty</typeparam>
/// <param name="parent">Parent node</param>
/// <param name="mode">Type or instance</param>
/// <param name="browseDisplayName">Name displayed in the node tree</param>
/// <param name="dataTypeId">Data type, such as String.. Given by DataTypeIds...</param>
/// <param name="value">Value of the type T or Null</param>
/// <param name="referenceTypeFromParentId"></param>
/// <param name="typeDefinitionId">Type definition; independent from DataType!</param>
/// <param name="valueRank">-1 or e.g. 1 for array</param>
/// <param name="defaultSettings">Apply default settings for a normal Property</param>
/// <param name="modellingRule">Modeling Rule, if not None</param>
/// <returns>NodeState</returns>
public PropertyState<T> CreateAddPropertyState<T>(
NodeState parent, AasUaBaseEntity.CreateMode mode,
string browseDisplayName,
NodeId dataTypeId, T value,
NodeId referenceTypeFromParentId = null,
NodeId typeDefinitionId = null,
int valueRank = -2,
bool defaultSettings = false,
AasUaNodeHelper.ModellingRule modellingRule = AasUaNodeHelper.ModellingRule.None)
{
// apply cumulative settings
if (defaultSettings)
{
referenceTypeFromParentId = ReferenceTypeIds.HasProperty;
typeDefinitionId = VariableTypeIds.PropertyType;
if (valueRank == -2)
valueRank = -1;
}
// make Property
var x = new PropertyState<T>(parent);
x.BrowseName = "" + browseDisplayName;
x.DisplayName = "" + browseDisplayName;
x.Description = new LocalizedText("en", browseDisplayName);
x.DataType = dataTypeId;
if (valueRank > -2)
x.ValueRank = valueRank;
// ReSharper disable once RedundantCast
x.Value = (T)value;
AasUaNodeHelper.CheckSetModellingRule(modellingRule, x);
x.NodeId = nodeMgr.NewFromParent(nodeMgr.SystemContext, mode, x, parent);
// add Node
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
if (parent != null)
parent.AddChild(x);
// set relations
if (referenceTypeFromParentId != null)
{
if (parent != null)
{
if (!parent.ReferenceExists(referenceTypeFromParentId, false, x.NodeId))
{
parent.AddReference(referenceTypeFromParentId, false, x.NodeId);
}
if (referenceTypeFromParentId == ReferenceTypeIds.HasComponent)
x.AddReference(referenceTypeFromParentId, true, parent.NodeId);
if (referenceTypeFromParentId == ReferenceTypeIds.HasProperty)
x.AddReference(referenceTypeFromParentId, true, parent.NodeId);
}
}
if (typeDefinitionId != null)
{
x.TypeDefinitionId = typeDefinitionId;
}
x.AccessLevel = AccessLevels.CurrentReadOrWrite;
x.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
return x;
}
public MethodState CreateAddMethodState(
NodeState parent, AasUaBaseEntity.CreateMode mode,
string browseDisplayName,
Argument[] inputArgs = null, Argument[] outputArgs = null, NodeId referenceTypeFromParentId = null,
NodeId methodDeclarationId = null, GenericMethodCalledEventHandler onCalled = null)
{
// method node
var m = new MethodState(parent);
m.BrowseName = "" + browseDisplayName;
m.DisplayName = "" + browseDisplayName;
m.Description = new LocalizedText("en", browseDisplayName);
m.NodeId = nodeMgr.NewFromParent(nodeMgr.SystemContext, mode, m, parent);
if (methodDeclarationId != null)
m.MethodDeclarationId = methodDeclarationId;
m.Executable = true;
m.UserExecutable = true;
nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, m);
if (parent != null)
parent.AddChild(m);
if (referenceTypeFromParentId != null)
{
if (parent != null)
{
parent.AddReference(referenceTypeFromParentId, false, m.NodeId);
if (referenceTypeFromParentId == ReferenceTypeIds.HasComponent)
m.AddReference(referenceTypeFromParentId, true, parent.NodeId);
if (referenceTypeFromParentId == ReferenceTypeIds.HasProperty)
m.AddReference(referenceTypeFromParentId, true, parent.NodeId);
}
}
// can have inputs, outputs
for (int i = 0; i < 2; i++)
{
// pretty argument list
var arguments = (i == 0) ? inputArgs : outputArgs;
if (arguments == null || arguments.Length < 1)
continue;
// make a property for this
var prop = CreateAddPropertyState<Argument[]>(
m, mode,
(i == 0) ? "InputArguments" : "OutputArguments",
DataTypeIds.Argument,
arguments,
ReferenceTypeIds.HasProperty,
typeDefinitionId: VariableTypeIds.PropertyType,
valueRank: 1);
// explicitely add arguments ass well?
if (i == 0)
m.InputArguments = prop;
if (i == 1)
m.OutputArguments = prop;
}
// event handler
if (onCalled != null)
m.OnCallMethod = onCalled;
return m;
}
//// Entities
//
public class AasTypeEntities
{
public AasUaEntityPathType PathType;
public AasUaEntityMimeType MimeType;
public AasUaEntityIdentification Identification;
public AasUaEntityAdministration Administration;
public AasUaEntityQualifier Qualifier;
public AasUaEntityAssetKind AssetKind;
public AasUaEntityModelingKind ModelingKind;
public AasUaEntityReferable Referable;
public AasUaEntityReferenceBase ReferenceBase;
public AasUaEntityReference Reference;
public AasUaEntitySemanticId SemanticId;
public AasUaEntitySubmodel Submodel;
public AasUaEntityProperty Property;
public AasUaEntityCollection Collection;
public AasUaEntitySubmodelElement SubmodelElement;
public AasUaEntitySubmodelWrapper SubmodelWrapper;
public AasUaEntityFile File;
public AasUaEntityFileType FileType;
public AasUaEntityBlob Blob;
public AasUaEntityReferenceElement ReferenceElement;
public AasUaEntityRelationshipElement RelationshipElement;
public AasUaEntityOperationVariable OperationVariable;
public AasUaEntityOperation Operation;
public AasUaEntityConceptDescription ConceptDescription;
public AasUaEntityAsset Asset;
public AasUaEntityAAS AAS;
public AasUaEntityDataSpecification DataSpecification;
public AasUaEntityDataSpecificationIEC61360 DataSpecificationIEC61360;
public AasUaInterfaceAASIdentifiableType IAASIdentifiableType;
public AasUaInterfaceAASReferableType IAASReferableType;
public AasUaNamespaceZeroEntity BaseInterfaceType;
public AasUaNamespaceZeroReference HasDictionaryEntry;
public AasUaReferenceHasAasReference HasAasReference;
public AasUaNamespaceZeroReference HasInterface;
public AasUaNamespaceZeroReference HasAddIn;
public AasUaNamespaceZeroEntity DictionaryEntryType;
public AasUaNamespaceZeroEntity UriDictionaryEntryType;
public AasUaNamespaceZeroEntity IrdiDictionaryEntryType;
public AasUaNamespaceZeroEntity DictionaryFolderType;
public void BuildEntites(AasEntityBuilder builder)
{
// build up entities, which are in the UA specs, but not in this Stack
BaseInterfaceType = new AasUaNamespaceZeroEntity(builder, 17602);
HasDictionaryEntry = new AasUaNamespaceZeroReference(builder, 17597);
HasInterface = new AasUaNamespaceZeroReference(builder, 17603);
HasAddIn = new AasUaNamespaceZeroReference(builder, 17604);
DictionaryEntryType = new AasUaNamespaceZeroEntity(builder, 17589);
UriDictionaryEntryType = new AasUaNamespaceZeroEntity(builder, 17600);
IrdiDictionaryEntryType = new AasUaNamespaceZeroEntity(builder, 17598);
DictionaryFolderType = new AasUaNamespaceZeroEntity(builder, 17591);
// AAS DataTypes
PathType = new AasUaEntityPathType(builder);
MimeType = new AasUaEntityMimeType(builder);
// first entities
Referable = new AasUaEntityReferable(builder, 1004);
Identification = new AasUaEntityIdentification(builder, 1000);
Administration = new AasUaEntityAdministration(builder, 1001);
// interfaces
IAASReferableType = new AasUaInterfaceAASReferableType(
builder, 2001); // dependencies: Referable
IAASIdentifiableType = new AasUaInterfaceAASIdentifiableType(
builder, 2000); // dependencies: IAASReferable
// AAS References
ReferenceBase = new AasUaEntityReferenceBase(builder, 0);
Reference = new AasUaEntityReference(builder, 1005);
SemanticId = new AasUaEntitySemanticId(builder, 1006); // dependecies: Reference
HasAasReference = new AasUaReferenceHasAasReference(builder, 4000); // dependencies: Referable
// Data Specifications
DataSpecification = new AasUaEntityDataSpecification(builder, 3000);
DataSpecificationIEC61360 = new AasUaEntityDataSpecificationIEC61360(
builder, 3001); // dependencies: Reference, Identification, Administration
// rest
Qualifier = new AasUaEntityQualifier(builder, 1002); // dependencies: SemanticId, Reference
AssetKind = new AasUaEntityAssetKind(builder, 1025);
ModelingKind = new AasUaEntityModelingKind(builder, 1003);
SubmodelElement = new AasUaEntitySubmodelElement(builder, 1008);
SubmodelWrapper = new AasUaEntitySubmodelWrapper(builder, 1012); // dependencies: SubmodelElement
Submodel = new AasUaEntitySubmodel(builder, 1007); // dependencies: SubmodelWrapper
Property = new AasUaEntityProperty(builder, 1009);
Collection = new AasUaEntityCollection(builder, 1010); // needs 2 ids!
FileType = new AasUaEntityFileType(builder, 1014);
File = new AasUaEntityFile(builder, 1013); // dependencies: FileType
Blob = new AasUaEntityBlob(builder, 1015);
ReferenceElement = new AasUaEntityReferenceElement(builder, 1016);
RelationshipElement = new AasUaEntityRelationshipElement(builder, 1017);
OperationVariable = new AasUaEntityOperationVariable(builder, 1018);
Operation = new AasUaEntityOperation(builder, 1019);
//TODO:Remove
//ConceptDictionary = new AasUaEntityConceptDictionary(builder, 1020);
ConceptDescription = new AasUaEntityConceptDescription(builder, 1021);
//TODO:Remove
//View = new AasUaEntityView(builder, 1022);
Asset = new AasUaEntityAsset(builder, 1023);
AAS = new AasUaEntityAAS(builder, 1024);
}
}
private AasTypeEntities aasTypes = null;
public AasTypeEntities AasTypes { get { return aasTypes; } }
//// Annotations
//
private Dictionary<NodeState, List<object>> nodeStateAnnotations = new Dictionary<NodeState, List<object>>();
public void AddNodeStateAnnotation(NodeState nodeState, object businessObject)
{
if (!nodeStateAnnotations.ContainsKey(nodeState))
nodeStateAnnotations[nodeState] = new List<object>();
nodeStateAnnotations[nodeState].Add(businessObject);
}
public void RemoveNodeStateAnnotation(NodeState nodeState, object businessObject)
{
if (!nodeStateAnnotations.ContainsKey(nodeState))
return;
if (nodeStateAnnotations[nodeState].Contains(businessObject))
nodeStateAnnotations[nodeState].Remove(businessObject);
}
public T FindNoteStateAnnotation<T>(NodeState nodeState) where T : class
{
if (nodeState == null)
return null;
if (!nodeStateAnnotations.ContainsKey(nodeState))
return null;
foreach (var bo in nodeStateAnnotations[nodeState])
if (bo is T)
return bo as T;
return null;
}
}
}