Skip to content

Commit

Permalink
Merge Jtikekar/GitHub issues/165 (#183)
Browse files Browse the repository at this point in the history
* Fix for GitHub Issue 165

* Fix for GitHub issue 26

* Fix for GitHub Issue 158

* Fix for GitHub Issue 157

* Fix for GitHub Issue 11

* Fix for GitHub Issue 179

* Fix for GitHub Issue 142
  • Loading branch information
juileetikekar authored Mar 12, 2024
1 parent d5828dc commit 95abf0a
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/AasxCsharpLibrary/AdminShellPackageEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,8 @@ public void TemporarilySaveCloseAndReOpenPackage(
{
_openPackage = Package.Open(Filename, FileMode.OpenOrCreate);

} }
}
}
}

private int BackupIndex = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/AasxCsharpLibrary/Extensions/ExtendBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public static Blob ConvertFromV10(this Blob blob, AasxCompatibilityModels.AdminS
public static Blob ConvertFromV20(this Blob blob, AasxCompatibilityModels.AdminShellV20.Blob sourceBlob)
{
blob.ContentType = sourceBlob.mimeType;
blob.Value = Encoding.ASCII.GetBytes(sourceBlob.value);
if (!string.IsNullOrEmpty(sourceBlob.value))
{
blob.Value = Encoding.ASCII.GetBytes(sourceBlob.value);
}
return blob;
}

Expand Down
16 changes: 11 additions & 5 deletions src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,19 @@ public static ConceptDescription ConvertFromV20(

if (srcCD.IsCaseOf != null && srcCD.IsCaseOf.Count != 0)
{
if (cd.IsCaseOf == null)
{
cd.IsCaseOf = new List<IReference>();
}
foreach (var caseOf in srcCD.IsCaseOf)
{
cd.IsCaseOf.Add(ExtensionsUtil.ConvertReferenceFromV20(caseOf, ReferenceTypes.ModelReference));
IReference newCaseOf = null;
if(caseOf != null && !caseOf.IsEmpty)
{
newCaseOf = ExtensionsUtil.ConvertReferenceFromV20(caseOf, ReferenceTypes.ModelReference);
}

if(newCaseOf != null)
{
cd.IsCaseOf ??= new List<IReference>();
cd.IsCaseOf.Add(newCaseOf);
}
}
}

Expand Down
43 changes: 25 additions & 18 deletions src/AasxCsharpLibrary/Extensions/ExtendEmbeddedDataSpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,38 @@ public static EmbeddedDataSpecification ConvertFromV20(this EmbeddedDataSpecific
{
if (sourceEmbeddedSpec != null)
{
embeddedDataSpecification.DataSpecification = ExtensionsUtil.ConvertReferenceFromV20(sourceEmbeddedSpec.dataSpecification, ReferenceTypes.ExternalReference);
if (sourceEmbeddedSpec.dataSpecification != null)
{
embeddedDataSpecification.DataSpecification = ExtensionsUtil.ConvertReferenceFromV20(sourceEmbeddedSpec.dataSpecification, ReferenceTypes.ExternalReference);

// TODO (MIHO, 2022-19-12): check again, see questions
var oldid = new[] {
// TODO (MIHO, 2022-19-12): check again, see questions
var oldid = new[] {
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/2/0",
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360",
"www.admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360"
};
var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0";
};
var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0";

// map all "usable" old ids to new one ..
foreach (var oi in oldid)
if (sourceEmbeddedSpec.dataSpecification?.Matches("", false, "IRI", oi,
AasxCompatibilityModels.AdminShellV20.Key.MatchMode.Identification) == true)
{
embeddedDataSpecification.DataSpecification.Keys[0].Value = newid;
}
}
// map all "usable" old ids to new one ..
foreach (var oi in oldid)
if (sourceEmbeddedSpec.dataSpecification?.Matches("", false, "IRI", oi,
AasxCompatibilityModels.AdminShellV20.Key.MatchMode.Identification) == true)
{
embeddedDataSpecification.DataSpecification.Keys[0].Value = newid;
}
}

if (sourceEmbeddedSpec.dataSpecificationContent?.dataSpecificationIEC61360 != null)
{
embeddedDataSpecification.DataSpecificationContent =
new DataSpecificationIec61360(null).ConvertFromV20(
sourceEmbeddedSpec.dataSpecificationContent.dataSpecificationIEC61360);
if (sourceEmbeddedSpec.dataSpecificationContent != null)
{
if (sourceEmbeddedSpec.dataSpecificationContent?.dataSpecificationIEC61360 != null)
{
embeddedDataSpecification.DataSpecificationContent =
new DataSpecificationIec61360(null).ConvertFromV20(
sourceEmbeddedSpec.dataSpecificationContent.dataSpecificationIEC61360);
}
}
}

return embeddedDataSpecification;
}

Expand Down
15 changes: 14 additions & 1 deletion src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,24 @@ public static IReferable FindReferableByReference(
}
}



if (firstKeyType.IsSME() && submodelElems != null)
{
var submodelElement = submodelElems.Where(
ISubmodelElement submodelElement;
//check if key.value is index
bool isIndex = int.TryParse(firstKeyId, out int index);
if (isIndex)
{
var smeList = submodelElems.ToList();
submodelElement = smeList[index];
}
else
{
submodelElement = submodelElems.Where(
sme => sme.IdShort.Equals(keyList[keyIndex].Value,
StringComparison.OrdinalIgnoreCase)).First();
}

//This is required element
if (keyIndex + 1 >= keyList.Count)
Expand Down
19 changes: 10 additions & 9 deletions src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,15 @@ private static void BasicConversionFromV20(this ISubmodelElement submodelElement

if (sourceSubmodelElement.hasDataSpecification != null && sourceSubmodelElement.hasDataSpecification.Count > 0)
{
//TODO (jtikekar, 0000-00-00): EmbeddedDataSpecification?? (as per old implementation)
submodelElement.EmbeddedDataSpecifications ??= new List<IEmbeddedDataSpecification>();

//TODO (jtikekar, 0000-00-00): DataSpecificationContent?? (as per old implementation)
foreach (var sourceDataSpec in sourceSubmodelElement.hasDataSpecification)
foreach (var sourceEmbeddedDataSpec in sourceSubmodelElement.hasDataSpecification)
{
submodelElement.EmbeddedDataSpecifications.Add(
new EmbeddedDataSpecification(
ExtensionsUtil.ConvertReferenceFromV20(sourceDataSpec.dataSpecification, ReferenceTypes.ExternalReference),
null));
var newEmbeddedDataSpec = new EmbeddedDataSpecification (null, null);
newEmbeddedDataSpec.ConvertFromV20(sourceEmbeddedDataSpec);
if(newEmbeddedDataSpec.DataSpecification != null || newEmbeddedDataSpec.DataSpecificationContent != null)
{
submodelElement.EmbeddedDataSpecifications ??= new List<IEmbeddedDataSpecification>();
submodelElement.EmbeddedDataSpecifications.Add(newEmbeddedDataSpec);
}
}
}

Expand Down Expand Up @@ -991,6 +990,8 @@ public static IEnumerable<T> FindAllSemanticIdAs<T>(this List<ISubmodelElement>
IKey semId, MatchMode matchMode = MatchMode.Strict)
where T : ISubmodelElement
{
if (submodelELements.IsNullOrEmpty())
yield return default(T);
foreach (var submodelElement in submodelELements)
if (submodelElement != null && submodelElement is T
&& submodelElement.SemanticId != null)
Expand Down
11 changes: 11 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ public static string GetAsIdentifier(this IReference reference)
return reference.Keys[0].Value;
}

//TODO (jtikekar, 2024-03-06): Refactor, added w.r.t. GitHub issue 11
if(reference.Type == ReferenceTypes.ModelReference)
{
if (reference.Keys == null || reference.Keys.Count < 1)
{
return null;
}

return reference.Keys[0].Value;
}

return null;
}

Expand Down
7 changes: 5 additions & 2 deletions src/AasxCsharpLibrary/Extensions/ExtendSubmodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ public static void Validate(this Submodel submodel, AasValidationRecordList resu

// check
submodel.BaseValidation(results);
submodel.Kind.Value.Validate(results, submodel);
submodel.SemanticId.Keys.Validate(results, submodel);
submodel.Kind?.Validate(results, submodel);
if (submodel.SemanticId != null && !submodel.SemanticId.IsEmpty())
{
submodel.SemanticId.Keys.Validate(results, submodel);
}
}

public static Submodel ConvertFromV10(this Submodel submodel, AasxCompatibilityModels.AdminShellV10.Submodel sourceSubmodel, bool shallowCopy = false)
Expand Down
5 changes: 3 additions & 2 deletions src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ public void DisplayOrEditAasEntityAas(
Options.Curr.TemplateIdSubmodelInstance);
// create ref
var smr = new Aas.Reference(Aas.ReferenceTypes.ExternalReference, new List<Aas.IKey>() { new Aas.Key(Aas.KeyTypes.Submodel, submodel.Id) });
var smr = new Aas.Reference(Aas.ReferenceTypes.ModelReference, new List<Aas.IKey>() { new Aas.Key(Aas.KeyTypes.Submodel, submodel.Id) });
aas.Submodels.Add(smr);
// event for AAS
Expand Down Expand Up @@ -2702,7 +2702,8 @@ public void DisplayOrEditAasEntitySubmodelElement(
if (ks != null)
{
// set the semantic id
sme.SemanticId = new Aas.Reference(Aas.ReferenceTypes.ExternalReference, new List<Aas.IKey>(ks));
//Using ModelReference for "Use existing" as this cd is being fetched from model/env
sme.SemanticId = new Aas.Reference(Aas.ReferenceTypes.ModelReference, new List<Aas.IKey>(ks));
// if empty take over shortName
var cd = env.FindConceptDescriptionByReference(sme.SemanticId);
Expand Down
3 changes: 1 addition & 2 deletions src/AasxPackageLogic/DispEditHelperModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,8 @@ public void DisplayOrEditEntityHasEmbeddedSpecification(
});
}

// which content is possible?
var cntByDs = ExtendIDataSpecificationContent.GuessContentTypeFor(
hasDataSpecification[i].DataSpecification);
hasDataSpecification[i].DataSpecificationContent);

AddHintBubble(
stack, hintMode, new[] {
Expand Down
14 changes: 11 additions & 3 deletions src/AasxPackageLogic/VisualAasxElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,17 @@ public VisualElementGeneric FindSibling(bool before = true, bool after = true)
if (ve.GetMainDataObject() is Aas.IReferable rf)
{
// add a key and go up ..
res.Insert(
0,
new Aas.Key((Aas.KeyTypes)Aas.Stringification.KeyTypesFromString(rf.GetSelfDescription().AasElementName), rf.IdShort));
IKey key;
if (ve.Parent.GetMainDataObject() is ISubmodelElementList smeList)
{
var index = smeList.Value.IndexOf((ISubmodelElement)rf);
key = new Aas.Key((Aas.KeyTypes)Aas.Stringification.KeyTypesFromString(rf.GetSelfDescription().AasElementName), index.ToString());
}
else
{
key = new Aas.Key((Aas.KeyTypes)Aas.Stringification.KeyTypesFromString(rf.GetSelfDescription().AasElementName), rf.IdShort);
}
res.Insert(0,key);
}
else
// uups!
Expand Down
1 change: 1 addition & 0 deletions src/AasxPluginGenericForms/GenericFormsAnyUiControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private async Task<AnyUiLambdaActionBase> ButtonTabPanels_Click(string cmd)
List<Aas.ISubmodelElement> currentElements = null;
if (_form.InUpdateMode)
{
_submodel.SubmodelElements ??= new List<Aas.ISubmodelElement>();
currentElements = _submodel.SubmodelElements;
}
else
Expand Down

0 comments on commit 95abf0a

Please sign in to comment.