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

Commit

Permalink
* checking based on CDs
Browse files Browse the repository at this point in the history
   works first time
  • Loading branch information
festo-i40 committed Nov 12, 2023
1 parent 8f79617 commit afb8218
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 126 deletions.
3 changes: 3 additions & 0 deletions src/AasxPackageExplorer/MainWindow.CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ private async Task CommandBinding_GeneralDispatch(
MainMenu?.SetChecked("HintsMenu", hintsMode);
}

// trigger re-indexing
TriggerPendingReIndexElements();

// try to remember current selected data object
object currMdo = null;
if (DisplayElements.SelectedItem != null)
Expand Down
37 changes: 35 additions & 2 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ public void UiLoadPackageWithNew(
if (!doNotNavigateAfterLoaded)
Logic?.UiCheckIfActivateLoadedNavTo();

TriggerPendingReIndexElements();

if (indexItems && packItem?.Container?.Env?.AasEnv != null)
packItem.Container.SignificantElements
= new IndexOfSignificantAasElements(packItem.Container.Env.AasEnv);
Expand Down Expand Up @@ -1167,6 +1169,9 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
if (Options.Curr.ShowEvents)
PanelConcurrentSetVisibleIfRequired(true, targetEvents: true);

// trigger re-index
TriggerPendingReIndexElements();

// script file to launch?
if (Options.Curr.ScriptFn.HasContent())
{
Expand Down Expand Up @@ -1494,6 +1499,11 @@ private async Task MainTimer_HandleLambdaAction(AnyUiLambdaActionBase lab)
UiHandleReRenderAnyUiInEntityPanel("", larrep.Mode, larrep.UseInnerGrid,
updateElemsOnly: larrep.UpdateElemsOnly);
}

if (lab is AnyUiLambdaActionReIndexIdentifiables lareii)
{
TriggerPendingReIndexElements();
}
}

private async Task MainTimer_HandleEntityPanel()
Expand Down Expand Up @@ -2492,6 +2502,9 @@ public void MainTaimer_HandleIncomingAasEvents()
private DateTime _mainTimer_LastCheckForDiaryEvents;
private DateTime _mainTimer_LastCheckForAnimationElements = DateTime.Now;

private bool _mainTimer_PendingReIndexElements = false;
private DateTime _mainTimer_LastCheckForReIndexElements = DateTime.Now;

private async Task MainTimer_Tick(object sender, EventArgs e)
{
MainTimer_HandleLogMessages();
Expand All @@ -2518,14 +2531,34 @@ 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;

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

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

MainTimer_PeriodicalTaskForSelectedEntity();
MainTaimer_HandleIncomingAasEvents();
DisplayElements.UpdateFromQueuedEvents();
}

private void SetProgressBar()
public void TriggerPendingReIndexElements()
{
_mainTimer_LastCheckForReIndexElements = DateTime.Now;
_mainTimer_PendingReIndexElements = true;
}

private void SetProgressBar()
{
SetProgressBar(0.0, "");
}
Expand Down
2 changes: 1 addition & 1 deletion src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,7 @@ public void DisplayOrEditAasEntityConceptDescription(
}
else
{
lambdaRf(false);
lambdaRf(true);
lambdaIdf();
lambdaIsCaseOf();
lambdaEDS(false);
Expand Down
20 changes: 19 additions & 1 deletion src/AasxPackageLogic/DispEditHelperModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2475,14 +2475,32 @@ public List<SmtAttributeCheckItem> DisplayOrEditEntityCheckValueEvalItems(
if (rf == null)
return checkItems;

// what to check
// try gain information from the given referable itself
var rec = CheckReferableForExtensionRecords<SmtAttributeRecord>(rf).FirstOrDefault();
if (rec == null)
{
// can analyze qualifiers?
rec = AasSmtQualifiers.FindSmtQualifiers(rf, removeQualifers: false);
}

// if not, can access semanticId -> ConcepTdescription?
if (rec == null && rf is Aas.IHasSemantics rfsem
&& rfsem.SemanticId?.IsValid() == true
&& rfsem.SemanticId.Count() == 1
&& packages != null)
{
// try find
foreach (var x in packages.LookupAllIdent(rfsem.SemanticId.Keys[0].Value))
if (x.Item2 is Aas.IConceptDescription rfsemCd)
{
var rec2 = CheckReferableForExtensionRecords<SmtAttributeRecord>(rfsemCd).FirstOrDefault();
if (rec2 == null)
rec2 = AasSmtQualifiers.FindSmtQualifiers(rf, removeQualifers: false);
if (rec2 != null)
rec = rec2;
}
}

// some checks can be done on the static record function, as record entities might
// be only on subordinate elements

Expand Down
128 changes: 15 additions & 113 deletions src/AasxPackageLogic/DispEditHelperSammModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2319,117 +2319,6 @@ public void ExportSammModelFromConceptDescription(
}
}

/// <summary>
/// This class provides a layered access to a list (a <c>IEnumerable</c>) of
/// <c>Aas.IIdentifiable</c>. This access could be provided by each time
/// blindly iterating through the list or by caching the <c>Id</c>s in a
/// dictionary. Result can be access immedeatily or selected by an
/// lambda, so that only portions of the Identifiable are directly available
/// and strongly typed.
/// </summary>
/// <typeparam name="I">Subtype of <c>Aas.IIdentifiable</c></typeparam>
/// <typeparam name="ME">Result type, selected by an lambda</typeparam>
public class IdentifiableLookupStore<I,ME> where I : Aas.IIdentifiable where ME : class
{
protected IEnumerable<I> _originalData = null;

protected Func<I, ME> _lambdaSelectResult = null;

protected MultiValueDictionary<string, I> _lookup = null;

protected bool IsValidForDict() =>
_originalData != null && _lambdaSelectResult != null && _lookup != null;

public void StartDictionaryAccess(
IEnumerable<I> originalData,
Func<I, ME> lambdaSelectResult)
{
// remember
_originalData = originalData;
_lambdaSelectResult = lambdaSelectResult;

// create the dictionary
_lookup = new MultiValueDictionary<string, I>();
if (!IsValidForDict())
{
_lookup = null;
return;
}

// populate
foreach (var idf in _originalData)
if (idf?.Id != null)
_lookup.Add(idf.Id, idf);
}

/// <summary>
/// Lookup all elements for id <c>idKey</c> and
/// return the declared Identifiable subtype.
/// </summary>
public IEnumerable<I> LookupAllIdent(string idKey)
{
if (idKey == null || !IsValidForDict() || !_lookup.ContainsKey(idKey))
yield break;

foreach (var idf in _lookup[idKey])
yield return idf;
}

/// <summary>
/// Lookup first element for id <c>idKey</c> and
/// return the declared Identifiable subtype. Else: return <c>null</c>
/// </summary>
public I LookupFirstIdent(string idKey)
{
return LookupAllIdent(idKey).FirstOrDefault();
}

/// <summary>
/// Lookup all elements for id <c>idKey</c> and
/// return the result of the given lambda selection.
/// </summary>
public IEnumerable<ME> LookupAllResult(string idKey)
{
foreach (var idf in LookupAllIdent(idKey))
{
var res = _lambdaSelectResult?.Invoke(idf);
if (res != null)
yield return res;
}
}

/// <summary>
/// Lookup first element for id <c>idKey</c> and
/// return the result of the given lambda selection.
/// </summary>
public ME LookupFirstResult(string idKey)
{
return LookupAllResult(idKey).FirstOrDefault();
}

/// <summary>
/// Lookup first element for id <c>idKey</c> and
/// return the result of the given lambda selection.
/// Note: just a shortcut to <c>LookupFirstResult()</c>
/// </summary>
public ME Lookup(string idKey)
{
return LookupFirstResult(idKey);
}

public IEnumerable<ME> LookupFor(IEnumerable<Samm.SammReference> references)
{
// access
if (references == null)
yield break;

// translare
foreach (var inref in references)
{
yield return LookupFirstResult(inref?.Value);
}
}
}

public class SammIdfTuple
{
Expand All @@ -2450,7 +2339,7 @@ public SammIdfTuple(
/// <summary>
/// Dedicated <c>IdentifiableLookupStore</c> for <c>Samm.ModelElements</c> in <c>ConceptDescriptions.</c>
/// </summary>
public class SammModelElementLookupStore : IdentifiableLookupStore<Aas.IConceptDescription, SammIdfTuple>
public class SammModelElementLookupStore : PackageCentral.IdentifiableLookupStore<Aas.IConceptDescription, SammIdfTuple>
{
/// <summary>
/// Lookup first element for id <c>idKey</c> and
Expand All @@ -2471,6 +2360,19 @@ public T Lookup<T>(SammReference sr) where T : Samm.ModelElement
{
return LookupFirstResult(sr?.Value) as T;
}

public IEnumerable<SammIdfTuple> LookupFor(IEnumerable<Samm.SammReference> references)
{
// access
if (references == null)
yield break;

// translare
foreach (var inref in references)
{
yield return LookupFirstResult(inref?.Value);
}
}
}

/// <summary>
Expand Down Expand Up @@ -2625,7 +2527,7 @@ public void CreateSubmodelInstanceFromAspectCD(
// create store
var store = new SammModelElementLookupStore();
store.StartDictionaryAccess(
env.ConceptDescriptions,
new[] { env.ConceptDescriptions },
lambdaSelectResult: (cd) => {
var me = DispEditHelperSammModules.CheckReferableForSammElements(cd).FirstOrDefault();
return new SammIdfTuple(cd, me);
Expand Down
2 changes: 2 additions & 0 deletions src/AasxPackageLogic/MainWindowAnyUiDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public async Task CommandBinding_GeneralDispatchAnyUiDialogs(
PackageCentral.MainItem.Container.SignificantElements
= new IndexOfSignificantAasElements(PackageCentral.MainItem.Container.Env.AasEnv);

DisplayContext.EmitOutsideAction(new AnyUiLambdaActionReIndexIdentifiables());

// may be was saved to flush events
MainWindow.CheckIfToFlushEvents();

Expand Down
Loading

0 comments on commit afb8218

Please sign in to comment.