Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
* create Submodel from SMT/SAMM CDs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaHofft committed Nov 18, 2023
1 parent 491451e commit 3c2758c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/AasxPackageExplorer/options-debug.MIHO.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
68 changes: 65 additions & 3 deletions src/AasxPackageLogic/DispEditHelperMiniModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1571,12 +1572,14 @@ protected class DispSmeListAddNewSmtItemRecord
public AasSubmodelElements? Sme;
}

protected List<AnyUiDialogueDataGridRow> DispSmeListAddNewCheckForSmtItems(
protected static List<AnyUiDialogueDataGridRow> DispSmeListAddNewCheckForSmtItems(
PackageCentral.PackageCentral packages,
Aas.IReference basedOnSemanticId)
{
// access
var res = new List<AnyUiDialogueDataGridRow>();
if (basedOnSemanticId?.IsValid() != true
if (packages == null
|| basedOnSemanticId?.IsValid() != true
|| basedOnSemanticId.Count() != 1)
return res;

Expand Down Expand Up @@ -1691,7 +1694,7 @@ public void DispSmeListAddNewHelper<T>(
return;

// gather potential SMT element items
var smtElemItem = DispSmeListAddNewCheckForSmtItems(basedOnSemanticId);
var smtElemItem = DispSmeListAddNewCheckForSmtItems(packages, basedOnSemanticId);

// hint
this.AddHintBubble(stack, hintMode, new[] {
Expand Down Expand Up @@ -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<Aas.IConceptDescription, List<Aas.ISubmodelElement>> lambdaCreateSmes = null;
lambdaCreateSmes = (parentCd) =>
{
// start
var res = new List<Aas.ISubmodelElement>();
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<ISubmodelElement>();
submodel.SubmodelElements.AddRange(lambdaCreateSmes(rootCd));

// info
Log.Singleton.Info($"Added {numAdded}. {numErrors} errors.");

// ok
return submodel;
}
Expand Down

0 comments on commit 3c2758c

Please sign in to comment.