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

Commit

Permalink
* add missing CDs from pool
Browse files Browse the repository at this point in the history
  • Loading branch information
festo-i40 committed Jul 29, 2023
1 parent a8564ab commit e1a5c44
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 23 deletions.
32 changes: 16 additions & 16 deletions src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,22 +539,22 @@ public static ISubmodel FindSubmodelById(this AasCore.Aas3_0.Environment environ
return null;
}

public static IEnumerable<ISubmodel> FindAllSubmodelsGroupedByAAS(this AasCore.Aas3_0.Environment environment, Func<IAssetAdministrationShell, ISubmodel, bool> p = null)
{
if (environment.AssetAdministrationShells == null || environment.Submodels == null)
yield break;
foreach (var aas in environment.AssetAdministrationShells)
{
if (aas?.Submodels == null)
continue;
foreach (var submodelReference in aas.Submodels)
{
var submodel = environment.FindSubmodel(submodelReference);
if (submodel != null && (p == null || p(aas, submodel)))
yield return submodel;
}
}
}
//public static IEnumerable<ISubmodel> FindAllSubmodelsGroupedByAAS(this AasCore.Aas3_0.Environment environment, Func<IAssetAdministrationShell, ISubmodel, bool> p = null)
//{
// if (environment.AssetAdministrationShells == null || environment.Submodels == null)
// yield break;
// foreach (var aas in environment.AssetAdministrationShells)
// {
// if (aas?.Submodels == null)
// continue;
// foreach (var submodelReference in aas.Submodels)
// {
// var submodel = environment.FindSubmodel(submodelReference);
// if (submodel != null && (p == null || p(aas, submodel)))
// yield return submodel;
// }
// }
//}

public static IEnumerable<ISubmodel> FindAllSubmodelBySemanticId(this AasCore.Aas3_0.Environment environment, string semanticId)
{
Expand Down
17 changes: 14 additions & 3 deletions src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ namespace Extensions
{
public static class ExtendIReferable
{
#region AasxPackageExplorer

public static void RecurseOnReferables(this IReferable referable,
#region AasxPackageExplorer

/// <summary>
/// Recurses on all Submodel elements of a Submodel or SME, which allows children.
/// The <c>state</c> object will be passed to the lambda function in order to provide
/// stateful approaches. Include this element, as well.
/// </summary>
/// <param name="state">State object to be provided to lambda. Could be <c>null.</c></param>
/// <param name="lambda">The lambda function as <c>(state, parents, SME)</c>
/// The lambda shall return <c>TRUE</c> in order to deep into recursion.</param>
/// <param name="includeThis">Include this element as well. <c>parents</c> will then
/// include this element as well!</param>
public static void RecurseOnReferables(this IReferable referable,
object state, Func<object, List<IReferable>, IReferable, bool> lambda,
bool includeThis = false)
{
// TODO (MIHO, 2023-07-28): not all elements are covered
if (referable is Submodel submodel)
{
submodel.RecurseOnReferables(state, lambda, includeThis);
Expand Down
4 changes: 2 additions & 2 deletions src/AasxPackageExplorer/options-debug.MIHO.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/* "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\AasxFesto\\AasxFesto\\AasxFctTool\\bin\\Debug\\net472\\test.aasx", */
/* "AasxToLoad": "C:\\Users\\miho\\Desktop\\Festo_SPAU_VR3_UA.aasx", */
/* "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\Festo_SPAU_VR3.aasx", */
"AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\PxC_aasT_2900542_ELR_H3_I_SC__24DC_500AC_0_6.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\Festo_SPAU-B2R-H-G18FD-L-PNLK-PNVBA-M8U_V3a.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\PxC_aasT_2900542_ELR_H3_I_SC__24DC_500AC_0_6.aasx",
"AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\Festo_SPAU-B2R-H-G18FD-L-PNLK-PNVBA-M8U_V3a.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\01_Festo_SPAU_VR3_DPPV2.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\bomtest1.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\IDTA 02006-2-1_Template_Digital Nameplate_V3_lang.aasx",
Expand Down
5 changes: 4 additions & 1 deletion src/AasxPackageLogic/ExplorerMenuFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ public static AasxMenu CreateMainMenu()
help: "Creates a new Submodel based on defintions provided by a pool of known definitions.",
args: new AasxMenuListOfArgDefs()
.Add("Domain", "Domain of knowledge/ name of the Submodel (partially)")
.Add("SmRef", "Return: Submodel generated", hidden: true)))
.Add("SmRef", "Return: Submodel generated", hidden: true))
.AddWpfBlazor(name: "MissingCdsFromKnown", header: "Missing ConceptDescriptions from pool of known",
help: "For the selected element: checks which SME refer to missing " +
"ConceptDescriptions, which can be created from pool of known definitions."))
.AddMenu(header: "Visualize …", attachPoint: "Visualize")
.AddSeparator()
.AddWpfBlazor(name: "ConvertElement", header: "Convert …",
Expand Down
19 changes: 19 additions & 0 deletions src/AasxPackageLogic/MainWindowAnyUiDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,25 @@ await DisplayContextPlus.CheckIfDownloadAndStart(
MainWindow.RedrawAllElementsAndFocus(nextFocus: ticket["SmRef"]);
}

if (cmd == "missingcdsfromknown")
{
// simply pass on
try
{
// delegate futher
await CommandBinding_GeneralDispatchHeadless(cmd, menuItem, ticket);
}
catch (Exception ex)
{
LogErrorToTicket(ticket, ex,
$"When executing command {cmd}, an error occurred");
}

// redisplay
if (ticket.Success)
MainWindow.RedrawAllElementsAndFocus();
}

if (cmd == "convertelement")
{
// check
Expand Down
100 changes: 100 additions & 0 deletions src/AasxPackageLogic/MainWindowHeadless.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Aas = AasCore.Aas3_0;

// ReSharper disable MethodHasAsyncOverload
Expand Down Expand Up @@ -1099,6 +1100,105 @@ record = rec;
#endif
}

if (cmd == "missingcdsfromknown")
{
//
// Step 1: analyze selected entity
//

var rfToCheck = new List<Aas.IReferable>();
if (ticket.SelectedDereferencedMainDataObjects != null)
foreach (var mdo in ticket.SelectedDereferencedMainDataObjects)
if (mdo is Aas.AssetAdministrationShell mdoAas)
foreach (var sm in ticket.Env.FindAllSubmodelGroupedByAAS((aas, sm) => aas == mdoAas))
rfToCheck.Add(sm);
else if (mdo is Aas.Submodel mdoSm)
rfToCheck.Add(mdoSm);
else if (mdo is Aas.ISubmodelElement mdoSme)
rfToCheck.Add(mdoSme);

if (rfToCheck.Count < 1)
{
LogErrorToTicket(ticket, "No valid element selected to be checked for missing CDs.");
return;
}

//
// Step 2: collect missing CDs
//

var cdsMissing = new List<string>();
foreach (var rf in rfToCheck)
foreach (var x in rf.Descend())
if (x is Aas.ISubmodelElement sme && sme.SemanticId != null
&& ticket.Env.FindConceptDescriptionByReference(sme.SemanticId) == null
&& sme.SemanticId.IsValid() && sme.SemanticId.Count() == 1
&& !cdsMissing.Contains(sme.SemanticId.Keys[0].Value))
cdsMissing.Add(sme.SemanticId.Keys[0].Value);

if (cdsMissing.Count < 1)
{
LogErrorToTicket(ticket, "No missing CDs could be found for selected element. Aborting!");
return;
}

//
// Step 3: check, which CDs could be provided by pool
//

var cdsAvail = new List<Aas.ConceptDescription>();
var duplicates = false;
foreach (var cdm in cdsMissing)
{
int count = 0;
foreach (var frf in AasxPredefinedConcepts.DefinitionsPool.Static
.FindReferableByReference(cdm))
if (frf is Aas.ConceptDescription fcd)
{
var cpy = fcd.Copy();
count++;
if (count > 1)
{
cpy.Id += $"__{count:000}";
Log.Singleton.Error(
$"Multiple CDs found for Id={cdm}. CD added with altered Id={cpy.Id}.");
duplicates = true;
}
cdsAvail.Add(cpy);
}
}

if (cdsAvail.Count < 1)
{
LogErrorToTicket(ticket, "No missing CDs could be found in pool of known. Aborting!");
return;
}

//
// Step 4: Ask
//

if (AnyUiMessageBoxResult.Yes != await DisplayContext.MessageBoxFlyoutShowAsync(
$"{cdsMissing.Count} CDs missing. {cdsAvail.Count} CDs available in pool of knonw. " +
"Add these available CDs to Environment?",
"Add CDs from pool of known",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Question))
return;

//
// Step 5: Go, add
//

foreach (var cd in cdsAvail)
ticket.Env.Add(cd);

Log.Singleton.Info($"Added {cdsAvail.Count} missing CDs from pool of known.");
if (duplicates)
Log.Singleton.Error("Duplicated CDs found while adding missing CDs from pool of known. " +
"See log.");
ticket.Success = true;
}

if (cmd == "convertelement")
{
// arguments
Expand Down
28 changes: 28 additions & 0 deletions src/AasxPluginExportTable/AasxPluginExportTable.options.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,34 @@
"null",
"%SME.multiplicity%"
]
},
{
"Name": "Export scratch info",
"Format": 2,
"RowsTop": 1,
"RowsBody": 1,
"RowsGap": 2,
"Cols": 2,
"ReplaceFailedMatches": true,
"FailText": "-",
"ActInHierarchy": true,
"NoHeadings": false,
"Top": [
"",
"",
"",
"",
"",
""
],
"Body": [
"",
"",
"",
"",
"[%SME.elementShort%]\r\n%SME.idShort%",
"idShort: %SME.idShort%\r\nsemanticId: %SME.semanticId[0].value%"
]
}
]
}
3 changes: 2 additions & 1 deletion src/AasxPluginExportTable/Table/AnyUiDialogueTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ record = newRec;
verticalAlignment: AnyUiVerticalAlignment.Stretch,
verticalContentAlignment: AnyUiVerticalAlignment.Top,
textWrap: AnyUiTextWrapping.Wrap,
fontSize: 0.7, multiLine: true),
fontSize: 0.7,
multiLine: true),
minWidth: 100,
minHeight: 60,
horizontalAlignment: AnyUiHorizontalAlignment.Stretch),
Expand Down
14 changes: 14 additions & 0 deletions src/AasxPredefinedConcepts/DefinitionsPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,19 @@ public void IndexDefinitions(AasxDefinitionBase bs)
return;
IndexReferables(bs.DomainInfo, bs.GetAllReferables());
}

public IEnumerable<Aas.IReferable> FindReferableByReference(string id)
{
if (id?.HasContent() != true)
yield break;

foreach (var ldp in pool.Values)
foreach (var dpeb in ldp)
if (dpeb is DefinitionsPoolReferableEntity dpre
&& dpre.Ref is Aas.IIdentifiable dpreid
&& dpreid.Id == id)
yield return dpre.Ref;

}
}
}
1 change: 1 addition & 0 deletions src/Notes_V3.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ if (reference.Keys == null || reference.Keys.Count == 0 || otherReference?.Keys

Soll ich den Bug im Repository eintragen bzw. ein PullRequest starten? Oder pflegst du so etwas „auf dem kurzen Dienstweg“ ein?

* Export table / cells / allow return

## Done (w.r.t. recently V3.0)

Expand Down

0 comments on commit e1a5c44

Please sign in to comment.