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

Commit

Permalink
* fix SMT organizes
Browse files Browse the repository at this point in the history
* add SMT elements
* working on add SAMM
  • Loading branch information
festo-i40 committed Nov 17, 2023
1 parent afb8218 commit 5053485
Show file tree
Hide file tree
Showing 21 changed files with 2,061 additions and 124 deletions.
7 changes: 7 additions & 0 deletions src/AasxCsharpLibrary/AdminShellCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public V GetValueOrDefault(K key)
public class MultiValueDictionary<K, V>
{
private Dictionary<K, List<V>> dict = new Dictionary<K, List<V>>();

public void Add(K key, V value)
{
if (dict.TryGetValue(key, out var list))
Expand All @@ -38,6 +39,12 @@ public void Add(K key, V value)
dict.Add(key, new List<V> { value });
}

public void Remove(K key)
{
if (dict.ContainsKey(key))
dict.Remove(key);
}

public bool ContainsKey(K key) => dict.ContainsKey(key);

public List<V> this[K key] => dict[key];
Expand Down
2 changes: 1 addition & 1 deletion src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ public static IAssetAdministrationShell FindAasWithAssetInformation(this AasCore

foreach (var aas in environment.AssetAdministrationShells)
{
if (aas.AssetInformation.GlobalAssetId.Equals(globalAssetId))
if (aas.AssetInformation?.GlobalAssetId?.Equals(globalAssetId) == true)
{
return aas;
}
Expand Down
31 changes: 31 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendIHasSemantics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2018-2023 Festo SE & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>
Author: Michael Hoffmeister
This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
This source code may use other Open Source software components (see LICENSE.txt).
*/
using System.Runtime.Intrinsics.X86;

namespace Extensions
{
public static class ExtendIHasSemantics
{
public static string GetConceptDescriptionId(this IHasSemantics ihs)
{
if (ihs?.SemanticId != null
&& ihs.SemanticId.IsValid() == true
&& ihs.SemanticId.Count() == 1
&& (ihs.SemanticId.Keys[0].Type == KeyTypes.ConceptDescription
|| ihs.SemanticId.Keys[0].Type == KeyTypes.Submodel
|| ihs.SemanticId.Keys[0].Type == KeyTypes.GlobalReference)
&& ihs.SemanticId.Keys[0].Value != null
&& ihs.SemanticId.Keys[0].Value.Trim().Length > 0)
{
return ihs.SemanticId.Keys[0].Value;
}
return null;
}
}
}
23 changes: 12 additions & 11 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)

// display elements has a cache
DisplayElements.ActivateElementStateCache();
VisualElementEnvironmentItem.SetCdSortOrderByString(Options.Curr.CdSortOrder);

// show Logo?
if (Options.Curr.LogoFile != null)
Expand Down Expand Up @@ -2531,20 +2532,20 @@ private async Task MainTimer_Tick(object sender, EventArgs e)
PackageCentral.MainItem.Container.SignificantElements);
_mainTimer_LastCheckForAnimationElements = DateTime.Now;
}
}

// do re-index?
deltaSecs = (DateTime.Now - _mainTimer_LastCheckForReIndexElements).TotalSeconds;
if (deltaSecs >= 1.0 && _mainTimer_PendingReIndexElements)
{
// dis-engage
_mainTimer_PendingReIndexElements = false;
// do re-index?
var deltaSecs2 = (DateTime.Now - _mainTimer_LastCheckForReIndexElements).TotalSeconds;
if (deltaSecs2 >= 1.0 && _mainTimer_PendingReIndexElements)
{
// dis-engage
_mainTimer_PendingReIndexElements = false;

// be modest for the time being
PackageCentral.MainItem?.Container?.ReIndexIdentifiables();
// be modest for the time being
PackageCentral.MainItem?.Container?.ReIndexIdentifiables();

// Info
Log.Singleton.Info("Re-indexing Identifiables for faster access.");
}
// Info
Log.Singleton.Info("Re-indexing Identifiables for faster access.");
}

MainTimer_PeriodicalTaskForSelectedEntity();
Expand Down
17 changes: 17 additions & 0 deletions src/AasxPackageExplorer/extension-presets.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
[
{
"name": "Main app | Submodel template attribute set",
"extension": {
"semanticId": {
"type": "ExternalReference",
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/SubmodelTemplates/smt-attribute-set/v1/0"
}
]
},
"name": "smt-attrtibute-set",
"value": "{ type: \"Sin\", ofs: 230.0, scale: 10.0, freq: 0.05, timer: 500 }",
"valueId": null
}
},
{
"name": "Main app | Animation of values",
"extension": {
Expand Down
3 changes: 2 additions & 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:\\HOMI\\Develop\\Aasx\\repo\\samm-test\\samm_spiel_empty-smt.aasx",
"AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\samm-test\\SMT_and_SAMM_Showcase_v01.aasx",
"WindowLeft": 200,
"WindowTop": -1,
"WindowWidth": 900,
Expand Down Expand Up @@ -61,6 +61,7 @@
"ShowIdAsIri": false,
"VerboseConnect": true,
"WorkDir": ".\\work",
"CdSortOrder" : "Structured",
"ObserveEvents": true,
"CompressEvents": true,
"CheckSmtElements": false,
Expand Down
37 changes: 24 additions & 13 deletions src/AasxPackageLogic/DispEditHelperBasics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void AddKeyValueExRef(
AnyUiLambdaActionBase takeOverLambdaAction = null,
bool limitToOneRowForNoEdit = false,
int comboBoxMinWidth = -1,
bool noFirstColumnWidth = false,
int firstColumnWidth = -1, // -1 = Standard
int maxLines = -1,
bool keyVertCenter = false)
{
Expand All @@ -312,7 +312,7 @@ public void AddKeyValueExRef(
(value == null) ? 0 : value.GetHashCode(), containingObject: containingObject,
limitToOneRowForNoEdit: limitToOneRowForNoEdit,
comboBoxMinWidth: comboBoxMinWidth,
noFirstColumnWidth: noFirstColumnWidth,
firstColumnWidth: firstColumnWidth,
maxLines: maxLines,
keyVertCenter: keyVertCenter);
}
Expand Down Expand Up @@ -351,7 +351,7 @@ public void AddKeyValue(
object containingObject = null,
bool limitToOneRowForNoEdit = false,
int comboBoxMinWidth = -1,
bool noFirstColumnWidth = false,
int firstColumnWidth = -1, // -1 = Standard
int maxLines = -1,
bool keyVertCenter = false)
{
Expand Down Expand Up @@ -389,7 +389,9 @@ public void AddKeyValue(
g.Margin = new AnyUiThickness(0, 1, 0, 1);
var gc1 = new AnyUiColumnDefinition();
gc1.Width = AnyUiGridLength.Auto;
if (!noFirstColumnWidth)
if (firstColumnWidth >= 0)
gc1.MinWidth = firstColumnWidth;
if (firstColumnWidth == -1)
gc1.MinWidth = this.GetWidth(FirstColumnWidth.Standard);
g.ColumnDefinitions.Add(gc1);
var gc2 = new AnyUiColumnDefinition();
Expand Down Expand Up @@ -615,8 +617,12 @@ public void AddKeyMultiValue(AnyUiStackPanel view, string key, string[][] value,
view.Children.Add(g);
}

public void AddCheckBox(AnyUiStackPanel panel, string key, bool initialValue, string additionalInfo = "",
Action<bool> valueChanged = null)
public void AddSmallCheckBox(
AnyUiStackPanel panel, string key,
bool value,
Func<bool, AnyUiLambdaActionBase> setValue = null,
string additionalInfo = "",
string[] boolTexts = null)
{
// make grid
var g = this.AddSmallGrid(1, 2, new[] { "" + this.GetWidth(FirstColumnWidth.Standard) + ":", "*" },
Expand All @@ -626,20 +632,25 @@ public void AddCheckBox(AnyUiStackPanel panel, string key, bool initialValue, st
this.AddSmallLabelTo(g, 0, 0, padding: new AnyUiThickness(5, 0, 0, 0), content: key);

// Column 1 = Check box or info
if (repo == null || valueChanged == null)
if (repo == null || setValue == null)
{
this.AddSmallLabelTo(g, 0, 1, padding: new AnyUiThickness(2, 0, 0, 0),
content: initialValue ? "True" : "False");
// label
var strVal = (value) ? "True" : "False";
if (boolTexts != null && boolTexts.Length >= 2)
strVal = (value) ? boolTexts[1] : boolTexts[0];

this.AddSmallLabelTo(g, 0, 1, padding: new AnyUiThickness(2, 0, 0, 0),
content: strVal);
}
else
{
AnyUiUIElement.RegisterControl(this.AddSmallCheckBoxTo(g, 0, 1, margin: new AnyUiThickness(2, 2, 2, 2),
content: additionalInfo, verticalContentAlignment: AnyUiVerticalAlignment.Center,
isChecked: initialValue),
isChecked: value),
(o) =>
{
if (o is bool)
valueChanged((bool)o);
if (o is bool && setValue != null)
return setValue((bool)o);
return new AnyUiLambdaActionNone();
});
}
Expand All @@ -648,7 +659,7 @@ public void AddCheckBox(AnyUiStackPanel panel, string key, bool initialValue, st
panel.Children.Add(g);
}

public void AddActionPanel(
public void AddActionPanel(
AnyUiPanel view, string key, string[] actionStr = null, ModifyRepo repo = null,
Func<int, AnyUiLambdaActionBase> action = null,
string[] actionTags = null,
Expand Down
85 changes: 77 additions & 8 deletions src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,8 @@ public void DisplayOrEditAasEntitySubmodelOrRef(
key: "SubmodelElement:",
submodel.SubmodelElements,
setValueLambda: (sml) => submodel.SubmodelElements = sml,
superMenu: superMenu);
superMenu: superMenu,
basedOnSemanticId: submodel.SemanticId);

this.AddHintBubble(stack, hintMode, new[] {
new HintCheck(
Expand Down Expand Up @@ -1844,6 +1845,8 @@ public void DisplayOrEditAasEntitySubmodelOrRef(
"Upgrades particular qualifiers from V2.0 to V3.0 for selected element.")
.AddAction("SMT-qualifiers-convert", "Convert SMT qualifiers",
"Converts particular SMT qualifiers to SMT extension for selected element.")
.AddAction("SMT-set-organize", "Set SMT organize",
"Take over Submodel's element relationships to associated concepts.")
.AddAction("remove-qualifiers", "Remove qualifiers",
"Removes all qualifiers for selected element.")
.AddAction("remove-extensions", "Remove extensions",
Expand Down Expand Up @@ -1935,6 +1938,63 @@ public void DisplayOrEditAasEntitySubmodelOrRef(
}

if (buttonNdx == 2)
{
// ask 1
if (ticket?.ScriptMode != true
&& AnyUiMessageBoxResult.Yes != this.context.MessageBoxFlyoutShow(
"This operation analyzes the element relatioships in the Submodel " +
"and will take over these as organize references into SMT attribute " +
"records of associated ConceptDescriptions. Do you want to proceed?",
"Take over SM element relationships to CDs",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Warning))
return new AnyUiLambdaActionNone();

// ask 2
var eachElemDetails = true;
if (ticket?.ScriptMode != true)
eachElemDetails = AnyUiMessageBoxResult.Yes == this.context.MessageBoxFlyoutShow(
"Create detailed SMT attributes for each relevant ConceptDescription, " +
"include SubmodelElement type list?",
"Take over SM element relationships to CDs",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Warning);

#if __not_useful
// ask 2
var resetOrganize = true;
if (ticket?.ScriptMode != true)
resetOrganize = AnyUiMessageBoxResult.Yes == this.context.MessageBoxFlyoutShow(
"Reset existing organize references in CDs?",
"Take over SM element relationships to CDs",
AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Warning);
#endif

// do
int anyChanges = 0;
Action<Aas.IReferable> lambdaConvert = (o) => {
if (SmtAttributeRecord.TakeoverSmOrganizeToCds(env, o,
eachElemDetails: eachElemDetails))
anyChanges++;
};

lambdaConvert(submodel);
submodel.RecurseOnSubmodelElements(null, (o, parents, sme) =>
{
// do
lambdaConvert(sme);
// recurse
return true;
});

// report
Log.Singleton.Info($"Take over SM element relationships to CDs: {anyChanges} changes done.");

// emit event for Submodel and children
this.AddDiaryEntry(submodel, new DiaryEntryStructChange(), allChildrenAffected: true);

return new AnyUiLambdaActionRedrawAllElements(nextFocus: smref, isExpanded: true);
}

if (buttonNdx == 3)
{
if (ticket?.ScriptMode != true
&& AnyUiMessageBoxResult.Yes != this.context.MessageBoxFlyoutShow(
Expand Down Expand Up @@ -1962,7 +2022,7 @@ public void DisplayOrEditAasEntitySubmodelOrRef(
return new AnyUiLambdaActionRedrawAllElements(nextFocus: smref, isExpanded: true);
}

if (buttonNdx == 3)
if (buttonNdx == 4)
{
if (ticket?.ScriptMode != true
&& AnyUiMessageBoxResult.Yes != this.context.MessageBoxFlyoutShow(
Expand Down Expand Up @@ -2388,7 +2448,13 @@ public void DisplayOrEditAasEntityConceptDescription(
lambdaRf(true);
lambdaIdf();
lambdaIsCaseOf();
lambdaEDS(false);

DisplayOrEditEntityListOfExtension(
stack: stack, extensions: cd.Extensions,
setOutput: (v) => { cd.Extensions = v; },
relatedReferable: cd);

lambdaEDS(false);
lambdaSammExt();
lambdaExtRecs();
}
Expand Down Expand Up @@ -3007,7 +3073,8 @@ public void DisplayOrEditAasEntitySubmodelElement(
if (sme is Aas.Entity)
(sme as Aas.Entity).Statements = sml;
},
superMenu: superMenu);
superMenu: superMenu,
basedOnSemanticId: sme.SemanticId);

// Copy

Expand Down Expand Up @@ -3240,7 +3307,8 @@ public void DisplayOrEditAasEntitySubmodelElement(
key: "annotation:",
are.Annotations,
setValueLambda: (sml) => are.Annotations = sml,
superMenu: superMenu);
superMenu: superMenu,
basedOnSemanticId: are.SemanticId);

this.AddHintBubble(
substack, hintMode,
Expand Down Expand Up @@ -4061,9 +4129,10 @@ public void DisplayOrEditAasEntitySubmodelElement(
else
this.AddKeyValue(stack, "Values", "Please add elements via editing of sub-ordinate entities");

this.AddCheckBox(
stack, "orderRelevant:", sml.OrderRelevant ?? false, " (true if order in list is relevant)",
(b) => { sml.OrderRelevant = b; });
this.AddSmallCheckBox(
stack, "orderRelevant:", sml.OrderRelevant ?? false,
additionalInfo: " (true if order in list is relevant)",
setValue: (b) => { sml.OrderRelevant = b; return new AnyUiLambdaActionNone(); });

// stats
var stats = sml.EvalConstraintStat();
Expand Down
Loading

0 comments on commit 5053485

Please sign in to comment.