Skip to content

Commit

Permalink
Recursively create submodel elements for I4AAS mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnstee committed Oct 20, 2024
1 parent 2785cf9 commit a5fa5b3
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/OPCUAViewer/I4AASNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> e

foreach (AssetAdministrationShellEnvironment env in _packageService.Packages.Values)
{
CreateInstanceObjects(env);
CreateObjects(env);
}

try
Expand Down Expand Up @@ -268,7 +268,7 @@ public static Referable FindReferableByReference(AssetAdministrationShellEnviron
return null;
}

public void CreateInstanceObjects(AssetAdministrationShellEnvironment env)
public void CreateObjects(AssetAdministrationShellEnvironment env)
{
if (_rootAAS == null)
{
Expand Down Expand Up @@ -340,13 +340,41 @@ public NodeState CreateObject(NodeState parent, AssetAdministrationShellEnvironm
{
for (int i = 0; i < env.Submodels.Count; i++)
{
CreateVariable<string>(o, "Submodel Definition " + i.ToString(), c_submodelNodeId, env.Submodels[i].IdShort);
NodeState sm = CreateVariable<string>(o, "Submodel Definition " + i.ToString(), c_submodelNodeId, env.Submodels[i].IdShort);

if (env.Submodels[i].SubmodelElements.Count > 0)
{
foreach (SubmodelElementWrapper smew in env.Submodels[i].SubmodelElements)
{
CreateSubmodelElement(sm, smew.SubmodelElement);
}
}
}
}

return o;
}

private void CreateSubmodelElement(NodeState parent, SubmodelElement sme)
{
if (sme is SubmodelElementCollection collection)
{
if (collection.Value != null)
{
NodeState collectionFolder = CreateFolder(parent, "Submodel Elements");

foreach (SubmodelElementWrapper smew in collection.Value)
{
CreateSubmodelElement(collectionFolder, smew.SubmodelElement);
}
}
}
else
{
CreateVariable<string>(parent, sme.DisplayName, c_submodelElementNodeId, sme.IdShort);
}
}

public FolderState CreateFolder(NodeState parent, string browseDisplayName)
{
FolderState x = new(parent)
Expand Down

0 comments on commit a5fa5b3

Please sign in to comment.