Skip to content

Commit df603bd

Browse files
* update
1 parent a167462 commit df603bd

12 files changed

+279
-45
lines changed

src/AasxCsharpLibrary/Extensions/ExtendKeyList.cs

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public static List<IKey> ReplaceLastKey(this List<IKey> keys, List<IKey> newKeys
4444
return res;
4545
}
4646

47+
public static void AddCheckBlank(this List<IKey> keys, IKey newKey)
48+
{
49+
if (keys.Count > 0 && (keys.Last().Value == null || keys.Last().Value.Trim().Length < 1))
50+
keys.RemoveAt(keys.Count - 1);
51+
keys.Add(newKey);
52+
}
53+
4754
public static bool StartsWith(this List<IKey> keyList, List<IKey> otherKeyList)
4855
{
4956
if (otherKeyList == null || otherKeyList.Count == 0)

src/AasxCsharpLibrary/Extensions/ExtendReference.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ public static AasElementSelfDescription GetSelfDescription(this Reference refere
2323

2424
public static bool IsValid(this IReference reference)
2525
{
26-
return reference.Keys != null && !reference.Keys.IsEmpty();
26+
if (reference?.Keys == null || reference.Keys.Count < 1)
27+
return false;
28+
foreach (var k in reference.Keys)
29+
if (k.Value == null || k.Value.Trim().Length < 1)
30+
return false;
31+
return true;
2732
}
2833

2934
public static bool IsValid(this List<IReference> references)
@@ -132,7 +137,7 @@ public static bool IsEmpty(this IReference reference)
132137
}
133138

134139
return false;
135-
}
140+
}
136141

137142
#endregion
138143

src/AasxPackageExplorer/options-debug.MIHO.json

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"TemplateIdConceptDescription": "www.example.com/ids/cd/DDDD_DDDD_DDDD_DDDD",
6363
"EclassDir": ".\\eclass\\",
6464
"DefaultLang": "en,de",
65+
"DefaultEmptyLangText": "", /* change for having a preset when creating new language lists */
66+
"DefaultEmptyReferenceKey": "", /* change for having a preset when creating new References */
6567
/* "LogoFile": "SpecPI40_t.png", */
6668
"LogoFile": "PI40_and_IDTA.png",
6769
"QualifiersFile": "qualifier-presets.json",

src/AasxPackageLogic/DispEditHelperBasics.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,9 @@ public Aas.ISubmodelElement SmartRefactorSme(Aas.ISubmodelElement oldSme)
11721172
return null;
11731173
}
11741174

1175+
// TODO (MIHO, 2024-06-02): remove, if not anymore required? Seems so!
1176+
#if __SEEMS_OBSOLETE
1177+
11751178
// see below
11761179
public void AddKeyListOfIdentifier(
11771180
AnyUiStackPanel view, string key,
@@ -1658,6 +1661,8 @@ It shall be replaced (after intergrating AnyUI) by a better repo handling */
16581661
view.Children.Add(g);
16591662
}
16601663

1664+
#endif
1665+
16611666
public AnyUiButton AddSmallContextMenuItemTo(
16621667
AnyUiGrid g, int row, int col,
16631668
string content,
@@ -1690,6 +1695,7 @@ public AnyUiButton AddSmallContextMenuItemTo(
16901695
public void AddKeyListKeys(
16911696
AnyUiStackPanel view, string key,
16921697
List<Aas.IKey> keys,
1698+
Action setKeysNull = null,
16931699
ModifyRepo repo = null,
16941700
PackageCentral.PackageCentral packages = null,
16951701
PackageCentral.PackageCentral.Selector selector = PackageCentral.PackageCentral.Selector.Main,
@@ -1834,7 +1840,7 @@ uc.ResultItem is AasxPredefinedConcepts.DefinitionsPoolReferableEntity pe
18341840
&& pe.Ref is Aas.IIdentifiable id
18351841
&& id.Id != null)
18361842
// DECISION: references to concepts are always GlobalReferences
1837-
keys.Add(new Aas.Key(Aas.KeyTypes.GlobalReference, id.Id));
1843+
keys.AddCheckBlank(new Aas.Key(Aas.KeyTypes.GlobalReference, id.Id));
18381844

18391845
emitCustomEvent?.Invoke(relatedReferable);
18401846

@@ -1878,7 +1884,8 @@ uc.ResultItem is AasxPredefinedConcepts.DefinitionsPoolReferableEntity pe
18781884
k2[0].Type = Aas.KeyTypes.GlobalReference;
18791885

18801886
if (k2 != null)
1881-
keys.AddRange(k2);
1887+
foreach (var k2k in k2)
1888+
keys.AddCheckBlank(k2k);
18821889

18831890
emitCustomEvent?.Invoke(relatedReferable);
18841891

@@ -2168,6 +2175,11 @@ It shall be replaced (after intergrating AnyUI) by a better repo handling */
21682175
{
21692176
case 0:
21702177
keys.RemoveAt(currentI);
2178+
if (keys.Count < 1)
2179+
{
2180+
keys = null;
2181+
setKeysNull?.Invoke();
2182+
}
21712183
action = true;
21722184
break;
21732185
case 1:

src/AasxPackageLogic/DispEditHelperEntities.cs

+60-14
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,9 @@ public void DisplayOrEditAasEntityAas(
15281528
};
15291529

15301530
this.AddKeyReference(
1531-
stack, "derivedFrom", aas.DerivedFrom, repo,
1531+
stack, "derivedFrom",
1532+
aas.DerivedFrom, () => aas.DerivedFrom = null,
1533+
repo,
15321534
packages, PackageCentral.PackageCentral.Selector.MainAuxFileRepo, "AssetAdministrationShell",
15331535
showRefSemId: false,
15341536
jumpLambda: lambda, noEditJumpLambda: lambda, relatedReferable: aas,
@@ -1599,7 +1601,10 @@ public void DisplayOrEditAasEntityAas(
15991601
public void DisplayOrEditAasEntitySubmodelOrRef(
16001602
PackageCentral.PackageCentral packages, Aas.Environment env,
16011603
Aas.IAssetAdministrationShell aas,
1602-
Aas.IReference smref, Aas.ISubmodel submodel, bool editMode,
1604+
Aas.IReference smref,
1605+
Action setSmRefNull,
1606+
Aas.ISubmodel submodel,
1607+
bool editMode,
16031608
AnyUiStackPanel stack, bool hintMode = false, bool checkSmt = false,
16041609
AasxMenu superMenu = null)
16051610
{
@@ -1615,7 +1620,9 @@ public void DisplayOrEditAasEntitySubmodelOrRef(
16151620
};
16161621

16171622
this.AddKeyListKeys(
1618-
stack, "submodelRef", smref.Keys, repo,
1623+
stack, "submodelRef",
1624+
smref.Keys, setSmRefNull,
1625+
repo,
16191626
packages, PackageCentral.PackageCentral.Selector.Main, "Reference Submodel ",
16201627
takeOverLambdaAction: new AnyUiLambdaActionRedrawAllElements(smref),
16211628
jumpLambda: lambda, relatedReferable: aas);
@@ -3666,7 +3673,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
36663673
this.AddGroup(stack, "ValueId:", this.levelColors.SubSection);
36673674

36683675
this.AddKeyReference(
3669-
stack, "valueId", p.ValueId, repo,
3676+
stack, "valueId",
3677+
p.ValueId, () => p.ValueId = null,
3678+
repo,
36703679
packages, PackageCentral.PackageCentral.Selector.MainAuxFileRepo,
36713680
addExistingEntities: "All", // no restriction
36723681
relatedReferable: p,
@@ -3707,7 +3716,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
37073716
stack, repo, mlp.Value, "value:", "Create data element!",
37083717
v =>
37093718
{
3710-
mlp.Value = new List<Aas.ILangStringTextType>();
3719+
mlp.Value = ExtendILangStringTextType.CreateFrom(
3720+
lang: AdminShellUtil.GetDefaultLngIso639(),
3721+
text: Options.Curr.DefaultEmptyLangText);
37113722
this.AddDiaryEntry(mlp, new DiaryEntryUpdateValue());
37123723
return new AnyUiLambdaActionRedrawEntity();
37133724
}))
@@ -3744,18 +3755,30 @@ public void DisplayOrEditAasEntitySubmodelElement(
37443755

37453756
// ValueId
37463757

3758+
this.AddHintBubble(
3759+
stack, hintMode,
3760+
new[] {
3761+
new HintCheck(
3762+
() => mlp.ValueId != null && mlp.ValueId.IsValid() != true,
3763+
"According to the specification, an existing list of elements shall contain " +
3764+
"at least one element and for each element all mandatory fields shall be " +
3765+
"not empty.")
3766+
});
3767+
37473768
if (this.SafeguardAccess(
37483769
stack, repo, mlp.ValueId, "valueId:", "Create data element!",
37493770
v =>
37503771
{
3751-
mlp.ValueId = new Aas.Reference(Aas.ReferenceTypes.ExternalReference, new List<Aas.IKey>());
3772+
mlp.ValueId = Options.Curr.GetDefaultEmptyReference();
37523773
this.AddDiaryEntry(mlp, new DiaryEntryUpdateValue());
37533774
return new AnyUiLambdaActionRedrawEntity();
37543775
}))
37553776
{
37563777
this.AddGroup(stack, "ValueID", this.levelColors.SubSection);
37573778
this.AddKeyListKeys(
3758-
stack, "valueId", mlp.ValueId.Keys, repo,
3779+
stack, "valueId",
3780+
mlp.ValueId.Keys, () => mlp.ValueId = null,
3781+
repo,
37593782
packages, PackageCentral.PackageCentral.Selector.MainAuxFileRepo,
37603783
Aas.Stringification.ToString(Aas.KeyTypes.GlobalReference),
37613784
relatedReferable: mlp,
@@ -4113,7 +4136,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
41134136
return new AnyUiLambdaActionNavigateTo(
41144137
new Aas.Reference(Aas.ReferenceTypes.ModelReference, new List<Aas.IKey>(kl)), translateAssetToAAS: true);
41154138
};
4116-
this.AddKeyReference(stack, "value", rfe.Value, repo,
4139+
this.AddKeyReference(stack, "value",
4140+
rfe.Value, () => rfe.Value = null,
4141+
repo,
41174142
packages, PackageCentral.PackageCentral.Selector.MainAuxFileRepo,
41184143
addExistingEntities: "All", // no restriction
41194144
addPresetNames: bufferKeys.Item1,
@@ -4165,7 +4190,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
41654190
}))
41664191
{
41674192
this.AddKeyReference(
4168-
stack, "first", rele.First, repo,
4193+
stack, "first",
4194+
rele.First, () => rele.First = null,
4195+
repo,
41694196
packages, PackageCentral.PackageCentral.Selector.MainAuxFileRepo,
41704197
addExistingEntities: "All", // no restriction
41714198
addPresetNames: bufferKeys.Item1,
@@ -4202,7 +4229,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
42024229
}))
42034230
{
42044231
this.AddKeyReference(
4205-
stack, "second", rele.Second, repo,
4232+
stack, "second",
4233+
rele.Second, () => rele.Second = null,
4234+
repo,
42064235
packages, PackageCentral.PackageCentral.Selector.MainAuxFileRepo,
42074236
addExistingEntities: "All", // no restriction
42084237
addPresetNames: bufferKeys.Item1,
@@ -4323,7 +4352,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
43234352
return new AnyUiLambdaActionRedrawEntity();
43244353
}))
43254354
AddKeyReference(
4326-
stack, "semanticIdListElement", sml.SemanticIdListElement, repo,
4355+
stack, "semanticIdListElement",
4356+
sml.SemanticIdListElement, () => sml.SemanticIdListElement = null,
4357+
repo,
43274358
packages, PackageCentral.PackageCentral.Selector.MainAux,
43284359
showRefSemId: false,
43294360
addExistingEntities: "Submodel SubmodelElement ConceptDescription ", addFromKnown: true,
@@ -4527,7 +4558,9 @@ public void DisplayOrEditAasEntitySubmodelElement(
45274558
return new AnyUiLambdaActionRedrawEntity();
45284559
}))
45294560
{
4530-
this.AddKeyListKeys(stack, "observed", bev.Observed.Keys, repo,
4561+
this.AddKeyListKeys(stack, "observed",
4562+
bev.Observed.Keys, () => bev.Observed = null,
4563+
repo,
45314564
packages, PackageCentral.PackageCentral.Selector.Main,
45324565
addExistingEntities: "All",
45334566
addPresetNames: bufferKeys.Item1,
@@ -4637,14 +4670,27 @@ public bool DisplayOrEditCommonEntity(
46374670

46384671
// edit
46394672
DisplayOrEditAasEntitySubmodelOrRef(
4640-
packages, vesmref.theEnv, aas, vesmref.theSubmodelRef, vesmref.theSubmodel, editMode, stack,
4673+
packages, vesmref.theEnv, aas,
4674+
vesmref.theSubmodelRef,
4675+
() =>
4676+
{
4677+
// challenge to remove the reference to the Submodel
4678+
if (vesmref.theAas?.Submodels == null)
4679+
return;
4680+
vesmref.theAas.Submodels.Remove(vesmref.theSubmodelRef);
4681+
if (vesmref.theAas.Submodels.Count < 1)
4682+
vesmref.theAas.Submodels = null;
4683+
},
4684+
vesmref.theSubmodel, editMode, stack,
46414685
hintMode: hintMode, checkSmt: checkSmt,
46424686
superMenu: superMenu);
46434687
}
46444688
else if (entity is VisualElementSubmodel vesm && vesm.theSubmodel != null)
46454689
{
46464690
DisplayOrEditAasEntitySubmodelOrRef(
4647-
packages, vesm.theEnv, null, null, vesm.theSubmodel, editMode, stack,
4691+
packages, vesm.theEnv,
4692+
aas: null, smref: null, setSmRefNull: null,
4693+
submodel: vesm.theSubmodel, editMode: editMode, stack: stack,
46484694
hintMode: hintMode, checkSmt: checkSmt,
46494695
superMenu: superMenu);
46504696
}

0 commit comments

Comments
 (0)