diff --git a/src/AasxPackageExplorer/options-debug.MIHO.json b/src/AasxPackageExplorer/options-debug.MIHO.json index c04eff80..23e174ee 100644 --- a/src/AasxPackageExplorer/options-debug.MIHO.json +++ b/src/AasxPackageExplorer/options-debug.MIHO.json @@ -26,7 +26,7 @@ // "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\SMT_Sample_B.aasx", // "AuxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\SMT_Sample_A.aasx", // "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\00_FestoDemoBox-Module-2-Kopie2.aasx", - "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\SMT_and_SAMM_Showcase_v01.aasx", + "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\SMT_and_SAMM_Showcase_v01.aasx", "WindowLeft": 200, "WindowTop": -1, "WindowWidth": 900, diff --git a/src/AasxPackageLogic/DispEditHelperMiniModules.cs b/src/AasxPackageLogic/DispEditHelperMiniModules.cs index 25fa140a..049d4fbe 100644 --- a/src/AasxPackageLogic/DispEditHelperMiniModules.cs +++ b/src/AasxPackageLogic/DispEditHelperMiniModules.cs @@ -13,6 +13,7 @@ This source code may use other Open Source software components (see LICENSE.txt) using AdminShellNS; using AnyUi; using Extensions; +using Lucene.Net.Util; using Newtonsoft.Json; using System; using System.Collections; @@ -1571,12 +1572,14 @@ protected class DispSmeListAddNewSmtItemRecord public AasSubmodelElements? Sme; } - protected List DispSmeListAddNewCheckForSmtItems( + protected static List DispSmeListAddNewCheckForSmtItems( + PackageCentral.PackageCentral packages, Aas.IReference basedOnSemanticId) { // access var res = new List(); - if (basedOnSemanticId?.IsValid() != true + if (packages == null + || basedOnSemanticId?.IsValid() != true || basedOnSemanticId.Count() != 1) return res; @@ -1691,7 +1694,7 @@ public void DispSmeListAddNewHelper( return; // gather potential SMT element items - var smtElemItem = DispSmeListAddNewCheckForSmtItems(basedOnSemanticId); + var smtElemItem = DispSmeListAddNewCheckForSmtItems(packages, basedOnSemanticId); // hint this.AddHintBubble(stack, hintMode, new[] { @@ -1893,6 +1896,65 @@ public static Aas.ISubmodel DispEditHelperCreateSubmodelFromSmtSamm( if (aas1 != null) aas1.Submodels.Add(submodel.GetReference()); + // lambda to recurse + int numAdded = 0; + int numErrors = 0; + Func> lambdaCreateSmes = null; + lambdaCreateSmes = (parentCd) => + { + // start + var res = new List(); + if (parentCd?.Id == null) + return res; + + // childs? + var childInfo = DispSmeListAddNewCheckForSmtItems( + packages, basedOnSemanticId: parentCd.GetCdReference()); + + // try to create + foreach (var ci in childInfo) + { + // get item? + if (!(ci.Tag is DispSmeListAddNewSmtItemRecord item)) + continue; + + // create a new SME + var sme = AdminShellUtil.CreateSubmodelElementFromEnum(item.Sme.Value); + if (sme == null) + { + Log.Singleton.Error("Creating type provided by SMT attributes."); + numErrors++; + continue; + } + + // populate by SMT attributes + item.SmtRec.PopulateReferable(sme, item.Cd); + + // add + res.Add(sme); + numAdded++; + + // recurse + if (createChilds) + { + var childs2 = lambdaCreateSmes(item.Cd); + if (childs2 != null) + foreach (var c2 in childs2) + sme.Add(c2); + } + } + + // result + return res; + }; + + // into Submodel? + submodel.SubmodelElements = new List(); + submodel.SubmodelElements.AddRange(lambdaCreateSmes(rootCd)); + + // info + Log.Singleton.Info($"Added {numAdded}. {numErrors} errors."); + // ok return submodel; }