Skip to content

Commit 5287c0d

Browse files
committed
Fix for GitHub Issue 142
1 parent 15e75ff commit 5287c0d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,24 @@ public static IReferable FindReferableByReference(
748748
}
749749
}
750750

751+
752+
751753
if (firstKeyType.IsSME() && submodelElems != null)
752754
{
753-
var submodelElement = submodelElems.Where(
755+
ISubmodelElement submodelElement;
756+
//check if key.value is index
757+
bool isIndex = int.TryParse(firstKeyId, out int index);
758+
if (isIndex)
759+
{
760+
var smeList = submodelElems.ToList();
761+
submodelElement = smeList[index];
762+
}
763+
else
764+
{
765+
submodelElement = submodelElems.Where(
754766
sme => sme.IdShort.Equals(keyList[keyIndex].Value,
755767
StringComparison.OrdinalIgnoreCase)).First();
768+
}
756769

757770
//This is required element
758771
if (keyIndex + 1 >= keyList.Count)

src/AasxPackageLogic/VisualAasxElements.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,17 @@ public VisualElementGeneric FindSibling(bool before = true, bool after = true)
406406
if (ve.GetMainDataObject() is Aas.IReferable rf)
407407
{
408408
// add a key and go up ..
409-
res.Insert(
410-
0,
411-
new Aas.Key((Aas.KeyTypes)Aas.Stringification.KeyTypesFromString(rf.GetSelfDescription().AasElementName), rf.IdShort));
409+
IKey key;
410+
if (ve.Parent.GetMainDataObject() is ISubmodelElementList smeList)
411+
{
412+
var index = smeList.Value.IndexOf((ISubmodelElement)rf);
413+
key = new Aas.Key((Aas.KeyTypes)Aas.Stringification.KeyTypesFromString(rf.GetSelfDescription().AasElementName), index.ToString());
414+
}
415+
else
416+
{
417+
key = new Aas.Key((Aas.KeyTypes)Aas.Stringification.KeyTypesFromString(rf.GetSelfDescription().AasElementName), rf.IdShort);
418+
}
419+
res.Insert(0,key);
412420
}
413421
else
414422
// uups!

0 commit comments

Comments
 (0)