Skip to content

Commit e6d6bcb

Browse files
committed
* update before refactor
ProgressChanged
1 parent 8662edc commit e6d6bcb

18 files changed

+391
-47
lines changed

src/AasxCsharpLibrary/AdminShellCollections.cs

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public void Add(K key, V value)
3939
dict.Add(key, new List<V> { value });
4040
}
4141

42+
public void AddIfValueIsNew(K key, V value)
43+
{
44+
if (dict.TryGetValue(key, out var list))
45+
{
46+
if (!list.Contains(value))
47+
list.Add(value);
48+
}
49+
else
50+
dict.Add(key, new List<V> { value });
51+
}
4252
public void Remove(K key)
4353
{
4454
if (dict.ContainsKey(key))

src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,21 @@ public static IEnumerable<LocatedReference> FindAllSemanticIdsForAas(
10711071
return refs;
10721072
}
10731073

1074+
/// <summary>
1075+
/// Warning: very inefficient!
1076+
/// </summary>
1077+
public static IEnumerable<LocatedReference> FindAllReferencedSemanticIds(
1078+
this AasCore.Aas3_0.IEnvironment env)
1079+
{
1080+
// unique set of references
1081+
var refs = new List<LocatedReference>();
1082+
1083+
foreach (var aas in env.AllAssetAdministrationShells())
1084+
refs.AddRange(env.FindAllSemanticIdsForAas(aas));
1085+
1086+
return refs;
1087+
}
1088+
10741089
/// <summary>
10751090
/// Warning: very inefficient!
10761091
/// </summary>

src/AasxIntegrationBase/AasxPluginOptionsBase.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ This source code may use other Open Source software components (see LICENSE.txt)
2323

2424
namespace AasxIntegrationBase
2525
{
26+
27+
/// <summary>
28+
/// With a lot of reluctance, this forms a global variable to be exchanged among all plugins.
29+
/// Note: as not all plugins do have default options, this is the only way to make plugin
30+
/// behaviour configurable by main application.
31+
/// </summary>
32+
public static class AasxPluginsGlobal
33+
{
34+
/// <summary>
35+
/// Only check the <c>value (id)</c> field of keys of semanticId for Submodels.
36+
/// </summary>
37+
public static bool SubmodelCheckOnlyId = false;
38+
}
39+
2640
/// <summary>
2741
/// Base class for an options record. This is a piece of options information, which is
2842
/// associated with an id of a Submodel template.
@@ -249,13 +263,12 @@ public AasxPluginLookupOptionsBase(
249263
}
250264
#endif
251265

252-
253266
private string GenerateIndexKey(Aas.IKey key)
254267
{
255268
if (key == null)
256269
return null;
257270
var k = new Aas.Key(key.Type, key.Value);
258-
var ndx = k?.ToStringExtended();
271+
var ndx = k?.ToStringExtended(format: AasxPluginsGlobal.SubmodelCheckOnlyId ? 2 : 0);
259272
return ndx;
260273
}
261274

src/AasxPackageExplorer/App.xaml.cs

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public static OptionsInformation InferOptions(string exePath, string[] args)
8888
var loadedPlugins = Plugins.TryActivatePlugins(pluginDllInfos);
8989

9090
Plugins.TrySetOptionsForPlugins(pluginDllInfos, loadedPlugins);
91-
9291
return loadedPlugins;
9392
}
9493

src/AasxPackageExplorer/MainWindow.CommandBindings.cs

+78-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ This source code may use other Open Source software components (see LICENSE.txt)
3333
using Aas = AasCore.Aas3_0;
3434

3535
namespace AasxPackageExplorer
36-
{
36+
{
3737
/// <summary>
3838
/// This partial class contains all command bindings, such as for the main menu, in order to reduce the
3939
/// complexity of MainWindow.xaml.cs
4040
/// </summary>
41-
public partial class MainWindow : Window, IFlyoutProvider
41+
public partial class MainWindow : Window, IFlyoutProvider, IExecuteMainCommand
4242
{
4343
private string lastFnForInitialDirectory = null;
4444

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

52-
5352
public void RememberForInitialDirectory(string fn)
5453
{
5554
this.lastFnForInitialDirectory = fn;
@@ -97,6 +96,82 @@ public void CommandExecution_RedrawAll()
9796
/// Set to <c>true</c>, if the application shall be shut down via script
9897
/// </summary>
9998
public bool ScriptModeShutdown = false;
99+
100+
public async Task<int> ExecuteMainMenuCommand(string menuItemName, params object[] args)
101+
{
102+
if (menuItemName?.HasContent() != true)
103+
{
104+
Log.Singleton.Error("MainWindow execute menu command: menu item name missing!");
105+
return -1;
106+
}
107+
108+
// name of tool, find it
109+
var foundMenu = this.GetMainMenu();
110+
var mi = foundMenu.FindName(menuItemName);
111+
if (mi == null)
112+
{
113+
foundMenu = this.GetDynamicMenu();
114+
mi = foundMenu.FindName(menuItemName);
115+
}
116+
if (mi == null)
117+
{
118+
Log.Singleton.Error($"MainWindow execute menu command: menu item name invalid: {menuItemName}");
119+
return -1;
120+
}
121+
122+
// create a ticket
123+
var ticket = new AasxMenuActionTicket()
124+
{
125+
MenuItem = mi,
126+
ScriptMode = true,
127+
ArgValue = new AasxMenuArgDictionary()
128+
};
129+
130+
// go thru the remaining arguments and find arg names and values
131+
var argi = 0;
132+
while (args != null && argi < args.Length)
133+
{
134+
// get arg name
135+
if (!(args[argi] is string argname))
136+
{
137+
Log.Singleton.Error($"MainWindow execute menu command: Argument at index {argi} is " +
138+
$"not string type for argument name.");
139+
return -1;
140+
}
141+
142+
// find argname?
143+
var ad = mi.ArgDefs?.Find(argname);
144+
if (ad == null)
145+
{
146+
Log.Singleton.Error($"MainWindow execute menu command: Argument at index {argi} is " +
147+
$"not valid argument name.");
148+
return -1;
149+
}
150+
151+
// create arg value (not available is okay)
152+
object av = null;
153+
if (argi + 1 < args.Length)
154+
av = args[argi + 1];
155+
156+
// into ticket
157+
ticket.ArgValue.Add(ad, av);
158+
159+
// 2 forward!
160+
argi += 2;
161+
}
162+
163+
// invoke action
164+
await foundMenu.ActivateAction(mi, ticket);
165+
166+
// perform UI updates if required
167+
if (ticket.UiLambdaAction != null && !(ticket.UiLambdaAction is AnyUiLambdaActionNone))
168+
{
169+
// add to "normal" event quoue
170+
this.AddWishForToplevelAction(ticket.UiLambdaAction);
171+
}
172+
173+
return 0;
174+
}
100175

101176
private async Task CommandBinding_GeneralDispatch(
102177
string cmd,

src/AasxPackageExplorer/MainWindow.xaml.cs

+58-19
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ public void UiLoadPackageWithNew(
404404
if (info == null)
405405
info = loadLocalFilename;
406406
Log.Singleton.Info("Loading new AASX from: {0} as auxiliary {1} ..", info, onlyAuxiliary);
407+
407408
if (!packItem.Load(PackageCentral, loadLocalFilename, loadLocalFilename,
408409
overrideLoadResident: true,
409410
PackageContainerOptionsBase.CreateDefault(Options.Curr)))
@@ -965,6 +966,7 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
965966
RepoListControl.PackageCentral = PackageCentral;
966967
RepoListControl.FlyoutProvider = this;
967968
RepoListControl.ManageVisuElems = DisplayElements;
969+
RepoListControl.ExecuteMainCommand = this;
968970
this.UiShowRepositories(visible: false);
969971

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

10121014
if (repo is PackageContainerListHttpRestRepository restRepo)
10131015
{
1014-
var fetchContext = new PackageContainerHttpRepoSubsetFetchContext()
1016+
// find a specific location
1017+
if (PackageContainerHttpRepoSubset.IsValidUriAnyMatch(fi?.Location))
10151018
{
1016-
Record = new ConnectExtendedRecord()
1019+
// try load that specific location
1020+
// check if load fresh or aggregate
1021+
if (PackageCentral.Main is AdminShellPackageDynamicFetchEnv)
10171022
{
1018-
BaseType = ConnectExtendedRecord.BaseTypeEnum.Repository,
1019-
BaseAddress = restRepo.Endpoint?.ToString()
1023+
// load aggregate
1024+
Log.Singleton.Info("Aggregating location {0} ..", fi.Location);
1025+
var res = await UiSearchRepoAndExtendEnvironmentAsync(
1026+
PackageCentral.Main,
1027+
fullItemLocation: fi.Location,
1028+
trySelect: true);
1029+
1030+
// error?
1031+
if (res == null)
1032+
Log.Singleton.Error("Not able to access location {0}", fi.Location);
1033+
1034+
// in any case, stop here
1035+
return;
1036+
}
1037+
else
1038+
{
1039+
// load
1040+
Log.Singleton.Info("Switching to location {0} ..", fi.Location);
1041+
UiLoadPackageWithNew(PackageCentral.MainItem, null,
1042+
fi.Location, onlyAuxiliary: false, preserveEditMode: true);
1043+
1044+
// in any case, stop here
1045+
return;
10201046
}
1021-
};
1022-
1023-
// refer to (static) function
1024-
var res = await DispEditHelperEntities.ExecuteUiForFetchOfElements(
1025-
PackageCentral, DisplayContext,
1026-
ticket : null,
1027-
mainWindow: this,
1028-
fetchContext: fetchContext,
1029-
preserveEditMode: true,
1030-
doEditNewRecord: true,
1031-
doCheckTainted: true,
1032-
doFetchGoNext: false,
1033-
doFetchExec: true);
1047+
}
1048+
1049+
// if not a specific location is available, display general dialogue
1050+
if (true)
1051+
{
1052+
var fetchContext = new PackageContainerHttpRepoSubsetFetchContext()
1053+
{
1054+
Record = new ConnectExtendedRecord()
1055+
{
1056+
BaseType = ConnectExtendedRecord.BaseTypeEnum.Repository,
1057+
BaseAddress = restRepo.Endpoint?.ToString()
1058+
}
1059+
};
1060+
1061+
// refer to (static) function
1062+
var res = await DispEditHelperEntities.ExecuteUiForFetchOfElements(
1063+
PackageCentral, DisplayContext,
1064+
ticket: null,
1065+
mainWindow: this,
1066+
fetchContext: fetchContext,
1067+
preserveEditMode: true,
1068+
doEditNewRecord: true,
1069+
doCheckTainted: true,
1070+
doFetchGoNext: false,
1071+
doFetchExec: true);
1072+
}
10341073
}
10351074

10361075
//
@@ -1766,7 +1805,7 @@ private void UiHandleReRenderAnyUiInEntityPanel(
17661805
AdminShellPackageEnvBase packEnv,
17671806
Aas.IReference workRef = null,
17681807
string fullItemLocation = null,
1769-
bool tryDisplay = false)
1808+
bool trySelect = false)
17701809
{
17711810
await Task.Yield();
17721811

@@ -1841,7 +1880,7 @@ private void UiHandleReRenderAnyUiInEntityPanel(
18411880
var newIdf = newIdfs.FirstOrDefault();
18421881

18431882
// display
1844-
if (tryDisplay)
1883+
if (trySelect)
18451884
{
18461885
var veFound = this.DisplayElements.SearchVisualElementOnMainDataObject(newIdf, alsoDereferenceObjects: true);
18471886
if (veFound != null)

src/AasxPackageExplorer/debug.MIHO.script

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Tool("exportsmtasciidoc", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\new.zip", "AntoraStyle", "true");
1111
Tool("editkey");
1212
// Tool("createrepofromapi", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository");
13+
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");
1314
// Tool("connectextended", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository", "GetSingleAas", "false", "GetAllAas", "true", "PageLimit", "99", "AutoLoadOnDemand", "false");
1415
// 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");
1516
// 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");

src/AasxPackageExplorer/options-debug.MIHO.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
5151
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\Syn2tecMachine_P2518_AAS__V3_DL2.aasx",
5252
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\test-data\\MTP\\test-data-SMT_MTP.aasx",
53+
"AasxToLoad": "C:\\Users\\Micha\\Desktop\\Demo\\AASX\\8001203_SPAU-P10R-T-R18M-L-PNLK-PNVBA-M8D_060ff64f-9fd2-422d-81ce-b17e49f007c5_work.aasx",
5354
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\00_FestoDemoBox-Module-2-Kopie.aasx",
5455
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\8001203_SPAU-P10R-T-R18M-L-PNLK-PNVBA-M8D_060ff64f-9fd2-422d-81ce-b17e49f007c5_work_spiel.aasx",
5556
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\1449600_NEBM-SM12G8-E-1.5-Q5-LE6_511946fb-00c1-4aa8-9877-9ba23d86146e.aasx",
56-
"AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\1449600_NEBM-SM12G8-E-1.5-Q5-LE6_511946fb-00c1-4aa8-9877-9ba23d86146e.aasx",
57+
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\1449600_NEBM-SM12G8-E-1.5-Q5-LE6_511946fb-00c1-4aa8-9877-9ba23d86146e.aasx",
5758
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\a33.aasx",
5859
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\SMT_and_SAMM_Showcase_v02.aasx",
5960
// "AasxToLoad": "C:\\MIHO\\Develop\\Aasx\\repo\\SMT_and_SAMM_Showcase_v01.aasx",
@@ -72,7 +73,9 @@
7273
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_ProductChangeNotification\\SMT_ProductChangeNotification_Draft_play_02.aasx",
7374
"AasxRepositoryFns": [
7475
"C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\Festo-DemoCase-repo-V3-local.json",
75-
"C:\\HOMI\\Develop\\Aasx\\repo\\local-5001.json"
76+
"C:\\HOMI\\Develop\\Aasx\\repo\\local-5001.json",
77+
"C:\\HOMI\\Develop\\Aasx\\repo\\eis-voyager.json",
78+
"C:\\HOMI\\Develop\\Aasx\\repo\\smt-repo.json"
7679
],
7780
// "AasxRepositoryFn": "C:\\HOMI\\Develop\\Aasx\\repo\\local-5001.json",
7881
// "AasxRepositoryFn": "C:\\Users\\homi0002\\Desktop\\test3\\new-aasx-repo.json" ,
@@ -135,6 +138,7 @@
135138
"VerboseConnect": true,
136139
"WorkDir": ".\\work",
137140
"CdSortOrder": "Structured",
141+
"SubmodelCheckOnlyId": true,
138142
"ObserveEvents": true,
139143
"CompressEvents": true,
140144
"CheckSmtElements": false,

src/AasxPackageLogic/DispEditHelperModules.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,10 @@ public void DisplayOrEditEntityDataSpecificationIec61360(
18181818
return new AnyUiLambdaActionRedrawEntity();
18191819
}))
18201820
{
1821+
// TODO (MIHO, 2024-12-09): check if to allow further Iec data types such as "File":
1822+
// comboBoxItems: (AdminShellUtil.GetEnumValues<Aas.DataTypeIec61360>()
1823+
// .Select((dt) => dt.ToString())).ToArray(),
1824+
18211825
AddKeyValueExRef(
18221826
stack, "dataType", dsiec, Aas.Stringification.ToString(dsiec.DataType), null, repo,
18231827
v =>

src/AasxPackageLogic/DispEditHelperSammModules.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ public void ImportCreateCDandIds(
17141714
DispEditHelperSammModules.SammExtensionHelperUpdateJson(newSammExt, si.SammType, si.SammInst);
17151715

17161716
// save CD
1717-
env?.ConceptDescriptions?.Add(newCD);
1717+
env?.Add(newCD);
17181718
}
17191719

17201720
public void ImportSammModelToConceptDescriptions(

src/AasxPackageLogic/ExplorerMenuFactory.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public static AasxMenu CreateMainMenu()
122122
.AddWpfBlazor(name: "ConnectExtended", header: "Connect (extended) …",
123123
args: new AasxMenuListOfArgDefs()
124124
.AddFromReflection(new PackageContainerHttpRepoSubset.ConnectExtendedRecord()))
125-
.AddWpfBlazor(name: "ApiUploadAssistant", header: "Upload assistant …")
125+
.AddWpfBlazor(name: "ApiUploadAssistant", header: "Upload assistant …",
126+
args: new AasxMenuListOfArgDefs()
127+
.AddFromReflection(new PackageContainerHttpRepoSubset.UploadAssistantJobRecord()))
126128
.AddWpf(name: "CreateRepoFromApi", header: "Create (local) file repository from API base …",
127129
args: new AasxMenuListOfArgDefs()
128130
.AddFromReflection(new PackageContainerHttpRepoSubset.ConnectExtendedRecord()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AasxPackageLogic
8+
{
9+
public interface IExecuteMainCommand
10+
{
11+
Task<int> ExecuteMainMenuCommand(string menuItemName, params object[] args);
12+
}
13+
}

0 commit comments

Comments
 (0)