Skip to content

Commit

Permalink
Further code simplification/bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnstee committed Oct 21, 2024
1 parent a5fa5b3 commit 77d3c20
Showing 1 changed file with 5 additions and 79 deletions.
84 changes: 5 additions & 79 deletions src/OPCUAViewer/I4AASNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,8 @@ public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> e
_rootAAS = CreateFolder(null, "AASROOT");
objectsFolderReferences.Add(new NodeStateReference(ReferenceTypes.Organizes, false, _rootAAS.NodeId));

_rootConceptDescriptions = CreateObject(
_rootAAS,
"Concept Descriptions",
ReferenceTypeIds.HasComponent,
c_dictionaryFolderTypeNodeId);

_rootMissingDictionaryEntries = CreateObject(
_rootAAS,
"Dictionary Entries",
ReferenceTypeIds.HasComponent,
c_dictionaryFolderTypeNodeId);
_rootConceptDescriptions = CreateFolder(_rootAAS, "Concept Descriptions");
_rootMissingDictionaryEntries = CreateFolder(_rootAAS, "Dictionary Entries");

foreach (AssetAdministrationShellEnvironment env in _packageService.Packages.Values)
{
Expand Down Expand Up @@ -299,15 +290,7 @@ public NodeState CreateObject(NodeState parent, AssetAdministrationShellEnvironm
return null;
}

string extraName = null;
string browseName = "AssetAdministrationShell";
if (aas.IdShort != null && aas.IdShort.Trim().Length > 0)
{
extraName = "AssetAdministrationShell:" + aas.IdShort;
browseName = aas.IdShort;
}

var o = CreateObject(parent, browseName, ReferenceTypeIds.HasComponent, c_administrationNodeId, extraName);
var o = CreateFolder(parent, "AssetAdministrationShell_" + aas.IdShort);

CreateVariable<string>(o, "Referable", c_referableTypeNodeId, aas.Identification.Value);
CreateVariable<string>(o, "Identification", c_identifiableTypeNodeId, aas.Id);
Expand Down Expand Up @@ -340,7 +323,7 @@ public NodeState CreateObject(NodeState parent, AssetAdministrationShellEnvironm
{
for (int i = 0; i < env.Submodels.Count; i++)
{
NodeState sm = CreateVariable<string>(o, "Submodel Definition " + i.ToString(), c_submodelNodeId, env.Submodels[i].IdShort);
NodeState sm = CreateFolder(o, "Submodel Definition " + i.ToString() + "_" + env.Submodels[i].IdShort);

if (env.Submodels[i].SubmodelElements.Count > 0)
{
Expand Down Expand Up @@ -371,7 +354,7 @@ private void CreateSubmodelElement(NodeState parent, SubmodelElement sme)
}
else
{
CreateVariable<string>(parent, sme.DisplayName, c_submodelElementNodeId, sme.IdShort);
CreateVariable<string>(parent, sme.IdShort, c_submodelElementNodeId, string.Empty);
}
}

Expand All @@ -395,63 +378,6 @@ public FolderState CreateFolder(NodeState parent, string browseDisplayName)
return x;
}

public BaseObjectState CreateObject(
NodeState parent,
string browseDisplayName,
NodeId referenceTypeFromParentId = null,
NodeId typeDefinitionId = null,
string extraName = null)
{
BaseObjectState x = new(parent)
{
BrowseName = browseDisplayName,
DisplayName = browseDisplayName,
Description = new Opc.Ua.LocalizedText("en", browseDisplayName)
};

if (extraName != null)
{
x.DisplayName = extraName;
}

if (typeDefinitionId != null)
{
x.TypeDefinitionId = typeDefinitionId;
}

x.NodeId = new NodeId(browseDisplayName, _namespaceIndex);

AddPredefinedNode(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);
}
}
}

return x;
}

public BaseDataVariableState<T> CreateVariable<T>(
NodeState parent,
string browseDisplayName,
Expand Down

0 comments on commit 77d3c20

Please sign in to comment.