Skip to content

Commit

Permalink
* work on empty list
Browse files Browse the repository at this point in the history
   for CDs
* find statistics fixed
  • Loading branch information
festo-i40 committed Aug 14, 2024
1 parent 7a1de31 commit 09eaabc
Show file tree
Hide file tree
Showing 11 changed files with 459 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,42 @@ namespace Extensions
{
public static class ExtendILangStringDefinitionTypeIec61360
{
public static List<ILangStringDefinitionTypeIec61360> CreateLangStringDefinitionType(string language, string text)
public static string GetDefaultString(this List<ILangStringDefinitionTypeIec61360> langStringSet, string defaultLang = null)
{
return new List<ILangStringDefinitionTypeIec61360> { new LangStringDefinitionTypeIec61360(language, text) };
return ExtendLangString.GetDefaultStringGen(langStringSet, defaultLang);
}
public static string GetDefaultString(this List<ILangStringDefinitionTypeIec61360> langStringSet, string defaultLang = null)

public static List<ILangStringDefinitionTypeIec61360> CreateFrom(string text, string lang = "en")
{
// start
if (defaultLang == null)
defaultLang = "en"; //Default Lang in old implementation is en
if (text == null)
return null;

string res = null;
var res = new List<ILangStringDefinitionTypeIec61360>();
res.Add(new LangStringDefinitionTypeIec61360(lang, text));
return res;
}

// search
foreach (var langString in langStringSet)
if (langString.Language.Equals(defaultLang, StringComparison.OrdinalIgnoreCase))
res = langString.Text;
public static bool IsEmpty(this List<ILangStringDefinitionTypeIec61360> langStringSet)
{
if (langStringSet == null || langStringSet.Count == 0)
{
return true;
}

if (res == null && langStringSet.Count > 0)
res = langStringSet[0].Text;
return false;
}

// found?
return res;
public static bool IsValid(this List<ILangStringDefinitionTypeIec61360> elems)
{
if (elems == null || elems.Count < 1)
return false;
foreach (var ls in elems)
if (ls?.Language == null || ls.Language.Trim().Length < 1
|| ls.Text == null || ls.Text.Trim().Length < 1)
return false;
return true;
}

public static List<ILangStringDefinitionTypeIec61360> ConvertFromV20(
this List<ILangStringDefinitionTypeIec61360> lss,
AasxCompatibilityModels.AdminShellV20.LangStringSetIEC61360 src)
Expand Down
24 changes: 24 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendILevelType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
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 Extensions;
using System.Collections.Generic;
using System.Linq;
using AdminShellNS;
using Aas = AasCore.Aas3_0;

namespace Extensions
{
public static class ExtendILevelType
{
public static bool IsEmpty(this ILevelType level)
{
return !(level.Nom || level.Typ || level.Min || level.Max);
}
}
}
38 changes: 38 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendIValueList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
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 Extensions;
using System.Collections.Generic;
using System.Linq;
using AdminShellNS;
using Aas = AasCore.Aas3_0;

namespace Extensions
{
public static class ExtendIValueList
{
public static bool IsEmpty(this IValueList list)
{
return list.ValueReferencePairs == null
|| list.ValueReferencePairs.Count < 1;
}

public static bool IsValid(this IValueList list)
{
if (IsEmpty(list))
return false;

foreach (var vp in list.ValueReferencePairs)
if (vp.Value?.HasContent() != true
|| vp.ValueId?.IsValid() != true)
return false;

return true;
}
}
}
4 changes: 2 additions & 2 deletions src/AasxPackageLogic/DispEditHelperBasics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,8 +1997,8 @@ uc.ResultItem is AasxPredefinedConcepts.DefinitionsPoolReferableEntity pe
if (topContextMenu)
{
List<string> contextHeaders = new();
contextHeaders.AddRange(new[] { "\u2205", "Set all \u2192 blank" });
contextHeaders.AddRange(new[] { "\u2702", "Delete completely" });
contextHeaders.AddRange(new[] { "\u2205", "Set all keys \u2192 1 blank" });
contextHeaders.AddRange(new[] { "\u2702", "Delete keys completely" });

if (addEclassIrdi)
contextHeaders.AddRange(new[] { "\U0001f517", "Add ECLASS" });
Expand Down
21 changes: 13 additions & 8 deletions src/AasxPackageLogic/DispEditHelperMiniModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ public void ValueListHelper(
Aas.IEnvironment env,
AnyUiStackPanel stack, ModifyRepo repo, string key,
List<Aas.IValueReferencePair> valuePairs,
Action<IValueList> setValueList = null,
Aas.IReferable relatedReferable = null,
AasxMenu superMenu = null)
{
Expand All @@ -1493,10 +1494,7 @@ public void ValueListHelper(
if (buttonNdx == 0)
{
valuePairs.Add(new Aas.ValueReferencePair(
"",
new Aas.Reference(Aas.ReferenceTypes.ExternalReference, new List<Aas.IKey> {
new Aas.Key(Aas.KeyTypes.GlobalReference, "")
})));
"", Options.Curr.GetDefaultEmptyReference()));
this.AddDiaryEntry(relatedReferable, new DiaryEntryStructChange());
}
Expand Down Expand Up @@ -1535,8 +1533,13 @@ public void ValueListHelper(
}
}
if (buttonNdx == 3 && valuePairs.Count > 0)
valuePairs.RemoveAt(valuePairs.Count - 1);
if (buttonNdx == 3)
{
if (valuePairs.Count > 0)
valuePairs.RemoveAt(valuePairs.Count - 1);
if (valuePairs.Count < 1)
setValueList?.Invoke(null);
}
return new AnyUiLambdaActionRedrawEntity();
});
Expand Down Expand Up @@ -1573,8 +1576,8 @@ public void ValueListHelper(
.CreateFrom(
AdminShellUtil.GetDefaultLngIso639(), "" + valuePairs[i].Value),
definition: ExtendILangStringDefinitionTypeIec61360
.CreateLangStringDefinitionType(
AdminShellUtil.GetDefaultLngIso639(), "" + valuePairs[i].Value),
.CreateFrom("" + valuePairs[i].Value,
lang: AdminShellUtil.GetDefaultLngIso639()),
dataType: Aas.DataTypeIec61360.StringTranslatable));
var cd = new Aas.ConceptDescription(
Expand Down Expand Up @@ -1622,6 +1625,8 @@ public void ValueListHelper(
{
case 0:
valuePairs.Remove(vp);
if (valuePairs.Count < 1)
setValueList?.Invoke(null);
action = true;
break;
case 1:
Expand Down
Loading

0 comments on commit 09eaabc

Please sign in to comment.