Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/AasxCsharpLibrary/AdminShellUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,31 @@ public static string FilterFriendlyName(string src,
return src;
}

/// <summary>
/// Is very strict and filter out everything which is not letter or digit!
/// This even applies to underscores!
/// Result is a PascalCased string with no whitespace.
/// </summary>
public static string FullyPascalCase(string str)
{
var res = new StringBuilder();
bool nextUpper = true;
foreach (var s in str)
{
// fully skip everything which is not letter or digit,
if (!char.IsLetterOrDigit(s))
{
nextUpper = true;
continue;
}

// else add
res.Append(nextUpper ? char.ToUpper(s) : s);
nextUpper = false;
}
return res.ToString();
}

public static string GiveRandomIdShort(IReferable rf)
{
var sd = rf?.GetSelfDescription();
Expand Down
40 changes: 35 additions & 5 deletions src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,8 +1196,8 @@ public static IEnumerable<IIdentifiable> FindAllReferencedIdentifiablesFor(
/// <summary>
/// Tries renaming an Identifiable, specifically: the identification of an Identifiable and
/// all references to it.
/// Currently supported: ConceptDescriptions
/// Returns a list of Referables, which were changed or <c>null</c> in case of error
/// Currently supported: ConceptDescriptions, Submodels a bit of AAS
/// Returns a list of Referables (not de-duplicated), which were changed or <c>null</c> in case of error
/// </summary>
public static List<IReferable> RenameIdentifiable<T>(this AasCore.Aas3_1.IEnvironment environment, string oldId, string newId)
where T : IClass
Expand All @@ -1221,14 +1221,44 @@ public static List<IReferable> RenameIdentifiable<T>(this AasCore.Aas3_1.IEnviro

// search all SMEs referring to this CD
foreach (var sme in environment.FindAllSubmodelElements<ISubmodelElement>(match: (s) =>
{
return (s != null && s.SemanticId != null && s.SemanticId.Matches(oldId));
}))
(s != null && s.SemanticId != null && s.SemanticId.Matches(oldId))
))
{
sme.SemanticId.Keys[0].Value = newId;
res.Add(sme);
}

foreach (var sme in environment.FindAllSubmodelElements<ISubmodelElement>(match: (s) =>
(s != null && s.SupplementalSemanticIds != null && s.SupplementalSemanticIds.Count() > 0)
))
{
foreach (var ssid in sme.SupplementalSemanticIds)
if (ssid?.Matches(oldId) == true)
{
ssid.Keys[0].Value = newId;
res.Add(sme);
}
}

foreach (var sme in environment.FindAllSubmodelElements<IProperty>(match: (s) =>
(s != null && s.ValueId != null && s.ValueId.Matches(oldId))
))
{
sme.ValueId.Keys[0].Value = newId;
res.Add(sme);
}

foreach (var cd in environment.AllConceptDescriptions())
if (cd != cdOld && cd.GetIEC61360()?.ValueList?.ValueReferencePairs != null)
{
foreach (var vrp in cd.GetIEC61360().ValueList.ValueReferencePairs)
if (vrp?.ValueId?.Matches(oldId) == true)
{
vrp.ValueId.Keys[0].Value = newId;
res.Add(cd);
}
}

// seems fine
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions src/AasxCsharpLibrary/Extensions/ExtendLangStringSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public static List<ILangStringTextType> ConvertFromV20(
/// If <c>input</c> has a trailing '@xx' code, the 'xx' will be returned and the
/// <c>input</c> is shortened. Else: returns <c>null</c>.
/// </summary>
public static string GetOneTrailingLanguage(ref string input)
public static string GetOneTrailingLanguageTag(ref string input)
{
if (input?.HasContent() != true)
return null;
int p = input.LastIndexOf('@');
if (p < 0 && input.Length <= p + 1)
if (p < 0 || input.Length <= p + 1)
return null;
var res = input.Substring(p+1);
input = input.Substring(0, p);
Expand Down
4 changes: 3 additions & 1 deletion src/AasxPackageExplorer/MainWindow.CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ private async Task CommandBinding_GeneralDispatch(
object currMdo = null;
if (DisplayElements.SelectedItem != null)
currMdo = DisplayElements.SelectedItem.GetMainDataObject();
if (currMdo is Aas.IReferable rf)
Log.Singleton.Info("TreeSelect2: " + rf.IdShort);

// edit mode affects the total element view
await RedrawAllAasxElementsAsync();
Expand All @@ -313,7 +315,7 @@ private async Task CommandBinding_GeneralDispatch(
// select last object
if (currMdo != null)
{
DisplayElements.TrySelectMainDataObject(currMdo, wishExpanded: true);
DisplayElements.TrySelectMainDataObject(currMdo, wishExpanded: true, specialTreeUpdate: true);
}
}

Expand Down
49 changes: 32 additions & 17 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,37 @@ public async Task RedrawAllAasxElementsAsync(bool keepFocus = false,
// rebuild middle section
DisplayElements.RebuildAasxElements(
PackageCentral, PackageCentral.Selector.Main, MainMenu?.IsChecked("EditMenu") == true,
lazyLoadingFirst: true);
// MIHO TODO: set to "true" after testing!
lazyLoadingFirst: false,
doNotSelectFirstItem: keepFocus);

DisplayElements.Refresh();

// ok .. try re-focus!!
if (keepFocus)
// according to AI, give the UI first time internally rebuild the items
Dispatcher.BeginInvoke(new Action(() =>
{
// make sure that Submodel is expanded
this.DisplayElements.ExpandAllItems();

// still proceed?
var veFound = this.DisplayElements.SearchVisualElementOnMainDataObject(focusMdo,
alsoDereferenceObjects: true);
// ok .. try re-focus!!
if (keepFocus)
{
// make sure that Submodel is expanded
this.DisplayElements.ExpandAllItems();

if (veFound != null)
DisplayElements.TrySelectVisualElement(veFound, wishExpanded: true);
}
// still proceed?
var veFound = this.DisplayElements.SearchVisualElementOnMainDataObject(focusMdo,
alsoDereferenceObjects: true);

// display again
DisplayElements.Refresh();
if (veFound != null)
{
DisplayElements.TrySelectVisualElement(veFound, wishExpanded: true,
specialTreeUpdate: true);
}
}

// display again
DisplayElements.Refresh();

}), DispatcherPriority.Background);

#if _log_times
Log.Singleton.Info("Time 90 is: " + DateTime.Now.ToString("hh:mm:ss.fff"));
Expand Down Expand Up @@ -1658,7 +1671,8 @@ private async Task MainTimer_HandleLambdaAction(AnyUiLambdaActionBase lab)
// MIHO 24-06-09: add dereferenced object to find operation vars, submodelrefs?
DisplayElements.TrySelectMainDataObject(
wish.NextFocus, wish.IsExpanded,
alsoDereferenceObjects: true);
alsoDereferenceObjects: true,
specialTreeUpdate: true);
}

// fake selection
Expand Down Expand Up @@ -2193,7 +2207,8 @@ private async Task UiHandleNavigateTo(
if (veFound != null)
{
// show ve
DisplayElements.TrySelectVisualElement(veFound, wishExpanded: true);
DisplayElements.TrySelectVisualElement(veFound, wishExpanded: true,
specialTreeUpdate: true);
// remember in history
Logic?.LocationHistory?.Push(veFound);
// fake selection
Expand Down Expand Up @@ -3140,7 +3155,7 @@ private async Task ButtonHistory_ObjectRequested(object sender, VisualElementHis
{
// is directly contain in actual tree
// show it
if (DisplayElements.TrySelectVisualElement(ve, wishExpanded: true))
if (DisplayElements.TrySelectVisualElement(ve, wishExpanded: true, specialTreeUpdate: true))
{
// fake selection
await RedrawElementViewAsync();
Expand Down Expand Up @@ -3215,7 +3230,7 @@ private async Task ButtonHistory_ObjectRequested(object sender, VisualElementHis
try
{
// show ve
DisplayElements?.TrySelectVisualElement(veFocus, wishExpanded: true);
DisplayElements?.TrySelectVisualElement(veFocus, wishExpanded: true, specialTreeUpdate: true);
// remember in history
//TODO (MIHO, 0000-00-00): this was a bug??
// ButtonHistory.Push(veFocus);
Expand Down
145 changes: 76 additions & 69 deletions src/AasxPackageLogic/AnyUiforAas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ public class AnyUiDialogueDataSelectAasEntity : AnyUiDialogueDataBase
// in
public PackageCentral.PackageCentral.Selector Selector;
public string Filter;
public bool MultiSelect = false;

// out
public List<Aas.IKey> ResultKeys;
public VisualElementGeneric ResultVisualElement;
public IEnumerable<VisualElementGeneric> ResultVisualElements;

public AnyUiDialogueDataSelectAasEntity(
string caption = "",
Expand Down Expand Up @@ -159,92 +161,97 @@ public static bool CheckFilter(string givenFilter, string singleName)
}

public bool PrepareResult(
VisualElementGeneric selectedItem,
IEnumerable<VisualElementGeneric> selectedItems,
string filter)
{
// access
if (selectedItem == null)
if (selectedItems == null || selectedItems.Count() < 1)
return false;
var siMdo = selectedItem.GetMainDataObject();

// already one result
ResultVisualElement = selectedItem;
// already one/ all result(s)
ResultVisualElement = selectedItems?.First();
ResultVisualElements = selectedItems?.ToArray();

//
// IReferable
//
if (siMdo is Aas.IReferable dataRef)
// more information?
var siMdo = selectedItems?.First().GetMainDataObject();
if (siMdo != null)
{
// check if a valuable item was selected
// new special case: "GlobalReference" allows to select all (2021-09-11)
var skip = filter != null &&
filter.Trim().ToLower() == Aas.Stringification.ToString(Aas.KeyTypes.GlobalReference).Trim().ToLower();
if (!skip)
//
// IReferable
//
if (siMdo is Aas.IReferable dataRef)
{
var elemname = dataRef.GetSelfDescription().AasElementName;
var fullFilter = AnyUiDialogueDataSelectAasEntity.ApplyFullFilterString(filter);
if (fullFilter != null && !(fullFilter.IndexOf(elemname + " ", StringComparison.Ordinal) >= 0))
return false;
}

// ok, prepare list of keys
ResultKeys = selectedItem.BuildKeyListToTop();

return true;
}
// check if a valuable item was selected
// new special case: "GlobalReference" allows to select all (2021-09-11)
var skip = filter != null &&
filter.Trim().ToLower() == Aas.Stringification.ToString(Aas.KeyTypes.GlobalReference).Trim().ToLower();
if (!skip)
{
var elemname = dataRef.GetSelfDescription().AasElementName;
var fullFilter = AnyUiDialogueDataSelectAasEntity.ApplyFullFilterString(filter);
if (fullFilter != null && !(fullFilter.IndexOf(elemname + " ", StringComparison.Ordinal) >= 0))
return false;
}

// ok, prepare list of keys
ResultKeys = selectedItems.First().BuildKeyListToTop();

//
// other special cases
//
if (siMdo is Aas.Reference smref &&
AnyUiDialogueDataSelectAasEntity.CheckFilter(filter, "submodelref"))
{
ResultKeys = new List<Aas.IKey>();
ResultKeys.AddRange(smref.Keys);
return true;
}
return true;
}

if (selectedItem is VisualElementPluginExtension vepe)
{
// get main data object of the parent of the plug in ..
var parentMdo = vepe.Parent.GetMainDataObject();
if (parentMdo != null)
//
// other special cases
//
if (siMdo is Aas.Reference smref &&
AnyUiDialogueDataSelectAasEntity.CheckFilter(filter, "submodelref"))
{
// safe to return a list for the parent ..
// (include AAS, as this is important to plug-ins)
ResultKeys = selectedItem.BuildKeyListToTop(includeAas: true);
ResultKeys = new List<Aas.IKey>();
ResultKeys.AddRange(smref.Keys);
return true;
}

// .. enriched by a last element
ResultKeys.Add(new Aas.Key(Aas.KeyTypes.FragmentReference, "Plugin:" + vepe.theExt.Tag));
if (selectedItems is VisualElementPluginExtension vepe)
{
// get main data object of the parent of the plug in ..
var parentMdo = vepe.Parent.GetMainDataObject();
if (parentMdo != null)
{
// safe to return a list for the parent ..
// (include AAS, as this is important to plug-ins)
ResultKeys = selectedItems.First().BuildKeyListToTop(includeAas: true);

// .. enriched by a last element
ResultKeys.Add(new Aas.Key(Aas.KeyTypes.FragmentReference, "Plugin:" + vepe.theExt.Tag));

// ok
return true;
}
}

// ok
if (selectedItems is VisualElementAsset veass
&& AnyUiDialogueDataSelectAasEntity.CheckFilter(filter, "AssetInformation")
&& veass.theAsset != null)
{
// prepare data
ResultKeys = selectedItems.First().BuildKeyListToTop(includeAas: true);
return true;
}
}

if (selectedItem is VisualElementAsset veass
&& AnyUiDialogueDataSelectAasEntity.CheckFilter(filter, "AssetInformation")
&& veass.theAsset != null)
{
// prepare data
ResultKeys = selectedItem.BuildKeyListToTop(includeAas: true);
return true;
}

if (selectedItem is VisualElementOperationVariable veov
&& AnyUiDialogueDataSelectAasEntity.CheckFilter(filter, "OperationVariable")
&& veov.theOpVar?.Value != null)
{
// prepare data
ResultKeys = selectedItem.BuildKeyListToTop(includeAas: true);
return true;
}
if (selectedItems is VisualElementOperationVariable veov
&& AnyUiDialogueDataSelectAasEntity.CheckFilter(filter, "OperationVariable")
&& veov.theOpVar?.Value != null)
{
// prepare data
ResultKeys = selectedItems.First().BuildKeyListToTop(includeAas: true);
return true;
}

if (selectedItem is VisualElementSupplementalFile vesf && vesf.theFile != null)
{
// prepare data
ResultKeys = selectedItem.BuildKeyListToTop(includeAas: true);
return true;
if (selectedItems is VisualElementSupplementalFile vesf && vesf.theFile != null)
{
// prepare data
ResultKeys = selectedItems.First().BuildKeyListToTop(includeAas: true);
return true;
}
}

// uups
Expand Down
Loading
Loading