Skip to content

Commit

Permalink
* update before refactor
Browse files Browse the repository at this point in the history
   ProgressChanged
  • Loading branch information
festo-i40 committed Dec 23, 2024
1 parent 8662edc commit e6d6bcb
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 47 deletions.
10 changes: 10 additions & 0 deletions src/AasxCsharpLibrary/AdminShellCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public void Add(K key, V value)
dict.Add(key, new List<V> { value });
}

public void AddIfValueIsNew(K key, V value)
{
if (dict.TryGetValue(key, out var list))
{
if (!list.Contains(value))
list.Add(value);
}
else
dict.Add(key, new List<V> { value });
}
public void Remove(K key)
{
if (dict.ContainsKey(key))
Expand Down
15 changes: 15 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,21 @@ public static IEnumerable<LocatedReference> FindAllSemanticIdsForAas(
return refs;
}

/// <summary>
/// Warning: very inefficient!
/// </summary>
public static IEnumerable<LocatedReference> FindAllReferencedSemanticIds(
this AasCore.Aas3_0.IEnvironment env)
{
// unique set of references
var refs = new List<LocatedReference>();

foreach (var aas in env.AllAssetAdministrationShells())
refs.AddRange(env.FindAllSemanticIdsForAas(aas));

return refs;
}

/// <summary>
/// Warning: very inefficient!
/// </summary>
Expand Down
17 changes: 15 additions & 2 deletions src/AasxIntegrationBase/AasxPluginOptionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ This source code may use other Open Source software components (see LICENSE.txt)

namespace AasxIntegrationBase
{

/// <summary>
/// With a lot of reluctance, this forms a global variable to be exchanged among all plugins.
/// Note: as not all plugins do have default options, this is the only way to make plugin
/// behaviour configurable by main application.
/// </summary>
public static class AasxPluginsGlobal
{
/// <summary>
/// Only check the <c>value (id)</c> field of keys of semanticId for Submodels.
/// </summary>
public static bool SubmodelCheckOnlyId = false;
}

/// <summary>
/// Base class for an options record. This is a piece of options information, which is
/// associated with an id of a Submodel template.
Expand Down Expand Up @@ -249,13 +263,12 @@ public AasxPluginLookupOptionsBase(
}
#endif


private string GenerateIndexKey(Aas.IKey key)
{
if (key == null)
return null;
var k = new Aas.Key(key.Type, key.Value);
var ndx = k?.ToStringExtended();
var ndx = k?.ToStringExtended(format: AasxPluginsGlobal.SubmodelCheckOnlyId ? 2 : 0);
return ndx;
}

Expand Down
1 change: 0 additions & 1 deletion src/AasxPackageExplorer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public static OptionsInformation InferOptions(string exePath, string[] args)
var loadedPlugins = Plugins.TryActivatePlugins(pluginDllInfos);

Plugins.TrySetOptionsForPlugins(pluginDllInfos, loadedPlugins);

return loadedPlugins;
}

Expand Down
81 changes: 78 additions & 3 deletions src/AasxPackageExplorer/MainWindow.CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ This source code may use other Open Source software components (see LICENSE.txt)
using Aas = AasCore.Aas3_0;

namespace AasxPackageExplorer
{
{
/// <summary>
/// This partial class contains all command bindings, such as for the main menu, in order to reduce the
/// complexity of MainWindow.xaml.cs
/// </summary>
public partial class MainWindow : Window, IFlyoutProvider
public partial class MainWindow : Window, IFlyoutProvider, IExecuteMainCommand
{
private string lastFnForInitialDirectory = null;

Expand All @@ -49,7 +49,6 @@ public partial class MainWindow : Window, IFlyoutProvider
//// <MenuItem Header="([^"]+)"\s+([^I]|InputGestureText="([^"]+)")(.*?)Command="{StaticResource (\w+)}"/>
//// .AddWpf\(name: "\5", header: "\1", inputGesture: "\3", \4\)


public void RememberForInitialDirectory(string fn)
{
this.lastFnForInitialDirectory = fn;
Expand Down Expand Up @@ -97,6 +96,82 @@ public void CommandExecution_RedrawAll()
/// Set to <c>true</c>, if the application shall be shut down via script
/// </summary>
public bool ScriptModeShutdown = false;

public async Task<int> ExecuteMainMenuCommand(string menuItemName, params object[] args)
{
if (menuItemName?.HasContent() != true)
{
Log.Singleton.Error("MainWindow execute menu command: menu item name missing!");
return -1;
}

// name of tool, find it
var foundMenu = this.GetMainMenu();
var mi = foundMenu.FindName(menuItemName);
if (mi == null)
{
foundMenu = this.GetDynamicMenu();
mi = foundMenu.FindName(menuItemName);
}
if (mi == null)
{
Log.Singleton.Error($"MainWindow execute menu command: menu item name invalid: {menuItemName}");
return -1;
}

// create a ticket
var ticket = new AasxMenuActionTicket()
{
MenuItem = mi,
ScriptMode = true,
ArgValue = new AasxMenuArgDictionary()
};

// go thru the remaining arguments and find arg names and values
var argi = 0;
while (args != null && argi < args.Length)
{
// get arg name
if (!(args[argi] is string argname))
{
Log.Singleton.Error($"MainWindow execute menu command: Argument at index {argi} is " +
$"not string type for argument name.");
return -1;
}

// find argname?
var ad = mi.ArgDefs?.Find(argname);
if (ad == null)
{
Log.Singleton.Error($"MainWindow execute menu command: Argument at index {argi} is " +
$"not valid argument name.");
return -1;
}

// create arg value (not available is okay)
object av = null;
if (argi + 1 < args.Length)
av = args[argi + 1];

// into ticket
ticket.ArgValue.Add(ad, av);

// 2 forward!
argi += 2;
}

// invoke action
await foundMenu.ActivateAction(mi, ticket);

// perform UI updates if required
if (ticket.UiLambdaAction != null && !(ticket.UiLambdaAction is AnyUiLambdaActionNone))
{
// add to "normal" event quoue
this.AddWishForToplevelAction(ticket.UiLambdaAction);
}

return 0;
}

private async Task CommandBinding_GeneralDispatch(
string cmd,
Expand Down
77 changes: 58 additions & 19 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public void UiLoadPackageWithNew(
if (info == null)
info = loadLocalFilename;
Log.Singleton.Info("Loading new AASX from: {0} as auxiliary {1} ..", info, onlyAuxiliary);

if (!packItem.Load(PackageCentral, loadLocalFilename, loadLocalFilename,
overrideLoadResident: true,
PackageContainerOptionsBase.CreateDefault(Options.Curr)))
Expand Down Expand Up @@ -965,6 +966,7 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
RepoListControl.PackageCentral = PackageCentral;
RepoListControl.FlyoutProvider = this;
RepoListControl.ManageVisuElems = DisplayElements;
RepoListControl.ExecuteMainCommand = this;
this.UiShowRepositories(visible: false);

// event viewer
Expand Down Expand Up @@ -1011,26 +1013,63 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)

if (repo is PackageContainerListHttpRestRepository restRepo)
{
var fetchContext = new PackageContainerHttpRepoSubsetFetchContext()
// find a specific location
if (PackageContainerHttpRepoSubset.IsValidUriAnyMatch(fi?.Location))
{
Record = new ConnectExtendedRecord()
// try load that specific location
// check if load fresh or aggregate
if (PackageCentral.Main is AdminShellPackageDynamicFetchEnv)
{
BaseType = ConnectExtendedRecord.BaseTypeEnum.Repository,
BaseAddress = restRepo.Endpoint?.ToString()
// load aggregate
Log.Singleton.Info("Aggregating location {0} ..", fi.Location);
var res = await UiSearchRepoAndExtendEnvironmentAsync(
PackageCentral.Main,
fullItemLocation: fi.Location,
trySelect: true);

// error?
if (res == null)
Log.Singleton.Error("Not able to access location {0}", fi.Location);

// in any case, stop here
return;
}
else
{
// load
Log.Singleton.Info("Switching to location {0} ..", fi.Location);
UiLoadPackageWithNew(PackageCentral.MainItem, null,
fi.Location, onlyAuxiliary: false, preserveEditMode: true);

// in any case, stop here
return;
}
};

// refer to (static) function
var res = await DispEditHelperEntities.ExecuteUiForFetchOfElements(
PackageCentral, DisplayContext,
ticket : null,
mainWindow: this,
fetchContext: fetchContext,
preserveEditMode: true,
doEditNewRecord: true,
doCheckTainted: true,
doFetchGoNext: false,
doFetchExec: true);
}

// if not a specific location is available, display general dialogue
if (true)
{
var fetchContext = new PackageContainerHttpRepoSubsetFetchContext()
{
Record = new ConnectExtendedRecord()
{
BaseType = ConnectExtendedRecord.BaseTypeEnum.Repository,
BaseAddress = restRepo.Endpoint?.ToString()
}
};

// refer to (static) function
var res = await DispEditHelperEntities.ExecuteUiForFetchOfElements(
PackageCentral, DisplayContext,
ticket: null,
mainWindow: this,
fetchContext: fetchContext,
preserveEditMode: true,
doEditNewRecord: true,
doCheckTainted: true,
doFetchGoNext: false,
doFetchExec: true);
}
}

//
Expand Down Expand Up @@ -1766,7 +1805,7 @@ private void UiHandleReRenderAnyUiInEntityPanel(
AdminShellPackageEnvBase packEnv,
Aas.IReference workRef = null,
string fullItemLocation = null,
bool tryDisplay = false)
bool trySelect = false)
{
await Task.Yield();

Expand Down Expand Up @@ -1841,7 +1880,7 @@ private void UiHandleReRenderAnyUiInEntityPanel(
var newIdf = newIdfs.FirstOrDefault();

// display
if (tryDisplay)
if (trySelect)
{
var veFound = this.DisplayElements.SearchVisualElementOnMainDataObject(newIdf, alsoDereferenceObjects: true);
if (veFound != null)
Expand Down
1 change: 1 addition & 0 deletions src/AasxPackageExplorer/debug.MIHO.script
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// Tool("exportsmtasciidoc", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\new.zip", "AntoraStyle", "true");
Tool("editkey");
// Tool("createrepofromapi", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository");
Tool("connectextended", "BaseAddress", "http://smt-repo.admin-shell-io.com/api/v3.0", "BaseType", "Repository", "AasId", "https://admin-shell.io/idta/aas/DigitalNameplate/3/0", "AutoLoadOnDemand", "false", "AutoLoadCds", "true");
// Tool("connectextended", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository", "GetSingleAas", "false", "GetAllAas", "true", "PageLimit", "99", "AutoLoadOnDemand", "false");
// Tool("connectextended", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository", "GetSingleAas", "true", "AasId", "http://smart.festo.com/id/demo-box/aas/instance/99920202206560529000071817", "AutoLoadOnDemand", "false");
// Tool("connectextended", "BaseAddress", "https://eis-data.aas-voyager.com/", "BaseType", "Repository", "GetSingleAas", "true", "PageLimit", "2", "AutoLoadOnDemand", "false", "AasId", "https://new.abb.com/products/de/2CSF204101R1400/aas");
Expand Down
8 changes: 6 additions & 2 deletions src/AasxPackageExplorer/options-debug.MIHO.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\test-data\\MTP\\test-data-SMT_MTP.aasx",
"AasxToLoad": "C:\\Users\\Micha\\Desktop\\Demo\\AASX\\8001203_SPAU-P10R-T-R18M-L-PNLK-PNVBA-M8D_060ff64f-9fd2-422d-81ce-b17e49f007c5_work.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\00_FestoDemoBox-Module-2-Kopie.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\8001203_SPAU-P10R-T-R18M-L-PNLK-PNVBA-M8D_060ff64f-9fd2-422d-81ce-b17e49f007c5_work_spiel.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\1449600_NEBM-SM12G8-E-1.5-Q5-LE6_511946fb-00c1-4aa8-9877-9ba23d86146e.aasx",
"AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\1449600_NEBM-SM12G8-E-1.5-Q5-LE6_511946fb-00c1-4aa8-9877-9ba23d86146e.aasx",
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\1449600_NEBM-SM12G8-E-1.5-Q5-LE6_511946fb-00c1-4aa8-9877-9ba23d86146e.aasx",
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\a33.aasx",
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\SMT_and_SAMM_Showcase_v02.aasx",
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\SMT_and_SAMM_Showcase_v01.aasx",
Expand All @@ -72,7 +73,9 @@
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_ProductChangeNotification\\SMT_ProductChangeNotification_Draft_play_02.aasx",
"AasxRepositoryFns": [
"C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\Festo-DemoCase-repo-V3-local.json",
"C:\\HOMI\\Develop\\Aasx\\repo\\local-5001.json"
"C:\\HOMI\\Develop\\Aasx\\repo\\local-5001.json",
"C:\\HOMI\\Develop\\Aasx\\repo\\eis-voyager.json",
"C:\\HOMI\\Develop\\Aasx\\repo\\smt-repo.json"
],
// "AasxRepositoryFn": "C:\\HOMI\\Develop\\Aasx\\repo\\local-5001.json",
// "AasxRepositoryFn": "C:\\Users\\homi0002\\Desktop\\test3\\new-aasx-repo.json" ,
Expand Down Expand Up @@ -135,6 +138,7 @@
"VerboseConnect": true,
"WorkDir": ".\\work",
"CdSortOrder": "Structured",
"SubmodelCheckOnlyId": true,
"ObserveEvents": true,
"CompressEvents": true,
"CheckSmtElements": false,
Expand Down
4 changes: 4 additions & 0 deletions src/AasxPackageLogic/DispEditHelperModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,10 @@ public void DisplayOrEditEntityDataSpecificationIec61360(
return new AnyUiLambdaActionRedrawEntity();
}))
{
// TODO (MIHO, 2024-12-09): check if to allow further Iec data types such as "File":
// comboBoxItems: (AdminShellUtil.GetEnumValues<Aas.DataTypeIec61360>()
// .Select((dt) => dt.ToString())).ToArray(),

AddKeyValueExRef(
stack, "dataType", dsiec, Aas.Stringification.ToString(dsiec.DataType), null, repo,
v =>
Expand Down
2 changes: 1 addition & 1 deletion src/AasxPackageLogic/DispEditHelperSammModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ public void ImportCreateCDandIds(
DispEditHelperSammModules.SammExtensionHelperUpdateJson(newSammExt, si.SammType, si.SammInst);

// save CD
env?.ConceptDescriptions?.Add(newCD);
env?.Add(newCD);
}

public void ImportSammModelToConceptDescriptions(
Expand Down
4 changes: 3 additions & 1 deletion src/AasxPackageLogic/ExplorerMenuFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ public static AasxMenu CreateMainMenu()
.AddWpfBlazor(name: "ConnectExtended", header: "Connect (extended) …",
args: new AasxMenuListOfArgDefs()
.AddFromReflection(new PackageContainerHttpRepoSubset.ConnectExtendedRecord()))
.AddWpfBlazor(name: "ApiUploadAssistant", header: "Upload assistant …")
.AddWpfBlazor(name: "ApiUploadAssistant", header: "Upload assistant …",
args: new AasxMenuListOfArgDefs()
.AddFromReflection(new PackageContainerHttpRepoSubset.UploadAssistantJobRecord()))
.AddWpf(name: "CreateRepoFromApi", header: "Create (local) file repository from API base …",
args: new AasxMenuListOfArgDefs()
.AddFromReflection(new PackageContainerHttpRepoSubset.ConnectExtendedRecord()))
Expand Down
13 changes: 13 additions & 0 deletions src/AasxPackageLogic/IExecuteMainCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AasxPackageLogic
{
public interface IExecuteMainCommand
{
Task<int> ExecuteMainMenuCommand(string menuItemName, params object[] args);
}
}
Loading

0 comments on commit e6d6bcb

Please sign in to comment.