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

Add plugin to import Web of Thing description #438

Merged
merged 14 commits into from
Dec 14, 2021
3 changes: 3 additions & 0 deletions src/AasxIntegrationBaseWpf/IFlyoverAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface IFlyoutAgent : IFlyoutControl
/// <summary>
/// Event emitted by the Flyout in order to minimize the dialogue.
/// </summary>
// ReSharper disable once EventNeverSubscribedTo.Global
event IFlyoutControlAction ControlMinimize;

/// <summary>
Expand Down Expand Up @@ -65,6 +66,8 @@ public virtual void PushEvent(AdminShellEvents.AasEventMsgEnvelope ev)
/// If the Flyout is executed as Agent, minimized and then closed, the closing
/// action needs to be retained.
/// </summary>
///
// ReSharper disable once UnassignedField.Global
public Action ClosingAction;

/// <summary>
Expand Down
58 changes: 26 additions & 32 deletions src/AasxPackageExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,23 @@ Global
{569B369E-9393-4F57-994E-6B84398FD7CC}.Debug|Any CPU.Build.0 = Debug|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Debug|x64.ActiveCfg = Debug|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Debug|x64.Build.0 = Debug|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.Debug|x86.Build.0 = Debug|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|Any CPU.ActiveCfg = DebugWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|Any CPU.Build.0 = DebugWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x64.ActiveCfg = DebugWithoutCEF|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x64.Build.0 = DebugWithoutCEF|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x86.ActiveCfg = DebugWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x86.Build.0 = DebugWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|Any CPU.Build.0 = Release|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.Debug|x86.ActiveCfg = Debug|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|Any CPU.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|Any CPU.Build.0 = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x64.ActiveCfg = Debug|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x64.Build.0 = Debug|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x86.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.DebugWithoutCEF|x86.Build.0 = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|Any CPU.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|x64.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|x64.Build.0 = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|x86.ActiveCfg = Release|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|x86.Build.0 = Release|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|Any CPU.ActiveCfg = ReleaseWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|Any CPU.Build.0 = ReleaseWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x64.ActiveCfg = ReleaseWithoutCEF|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x64.Build.0 = ReleaseWithoutCEF|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x86.ActiveCfg = ReleaseWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x86.Build.0 = ReleaseWithoutCEF|Any CPU
{569B369E-9393-4F57-994E-6B84398FD7CC}.Release|x86.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|Any CPU.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|Any CPU.Build.0 = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x64.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x64.Build.0 = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x86.ActiveCfg = Release|x64
{569B369E-9393-4F57-994E-6B84398FD7CC}.ReleaseWithoutCEF|x86.Build.0 = Release|x64
{294FC59A-5645-412F-8216-702FB66528C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{294FC59A-5645-412F-8216-702FB66528C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{294FC59A-5645-412F-8216-702FB66528C1}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -569,26 +566,23 @@ Global
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Debug|Any CPU.Build.0 = Debug|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Debug|x64.ActiveCfg = Debug|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Debug|x64.Build.0 = Debug|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Debug|x86.ActiveCfg = Debug|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Debug|x86.Build.0 = Debug|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|Any CPU.ActiveCfg = Debug|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|Any CPU.Build.0 = Debug|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Debug|x86.ActiveCfg = Debug|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|Any CPU.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|Any CPU.Build.0 = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|x64.ActiveCfg = Debug|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|x64.Build.0 = Debug|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|x86.ActiveCfg = Debug|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|x86.Build.0 = Debug|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|Any CPU.Build.0 = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|x86.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.DebugWithoutCEF|x86.Build.0 = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|Any CPU.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|x64.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|x64.Build.0 = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|x86.ActiveCfg = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|x86.Build.0 = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|Any CPU.ActiveCfg = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|Any CPU.Build.0 = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.Release|x86.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|Any CPU.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|Any CPU.Build.0 = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|x64.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|x64.Build.0 = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|x86.ActiveCfg = Release|x64
{AA2A09A7-1E92-4572-9411-249C392ED6A6}.ReleaseWithoutCEF|x86.Build.0 = Release|x64
{B074E5E8-A2D4-4DFB-81C6-4DD5F0ABB8B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B074E5E8-A2D4-4DFB-81C6-4DD5F0ABB8B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B074E5E8-A2D4-4DFB-81C6-4DD5F0ABB8B4}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
111 changes: 111 additions & 0 deletions src/AasxPackageExplorer/MainWindow.CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ private async void CommandBinding_GeneralDispatch(string cmd)
if (cmd == "csvimport")
CommandBinding_CSVImport();

if (cmd == "tdimport")
CommandBinding_TDImport();

if (cmd == "submodeltdexport")
CommandBinding_SubmodelTDExport();

if (cmd == "opcuaimportnodeset")
CommandBinding_OpcUaImportNodeSet();

Expand Down Expand Up @@ -629,6 +635,62 @@ private async void CommandBinding_GeneralDispatch(string cmd)
}
}

public void CommandBinding_TDImport()
{
VisualElementSubmodelRef ve = null;
if (DisplayElements.SelectedItem != null && DisplayElements.SelectedItem is VisualElementSubmodelRef)
ve = DisplayElements.SelectedItem as VisualElementSubmodelRef;

if (ve == null || ve.theSubmodel == null || ve.theEnv == null)
{
MessageBoxFlyoutShow(
"No valid SubModel is selected.", "Unable to import TD JSON LD Document",
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Error);
return;
}

// ok!
if (Options.Curr.UseFlyovers) this.StartFlyover(new EmptyFlyout());

var dlg = new Microsoft.Win32.OpenFileDialog();
dlg.InitialDirectory = DetermineInitialDirectory(_packageCentral.MainItem.Filename);
dlg.Filter = "JSON files (*.JSONLD)|*.jsonld";
if (Options.Curr.UseFlyovers) this.StartFlyover(new EmptyFlyout());
var res = dlg.ShowDialog();
if (res == true)
try
{
// do it
RememberForInitialDirectory(dlg.FileName);
JObject importObject = TDJsonImport.ImportTDJsontoSubModel
(dlg.FileName, ve.theEnv, ve.theSubmodel, ve.theSubmodelRef);
foreach (var temp in (JToken)importObject)
{
JProperty importProperty = (JProperty)temp;
string key = importProperty.Name.ToString();
if (key == "error")
{
MessageBoxFlyoutShow(
"Unable to Import the JSON LD File", "Check the log"
,
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Error);
Log.Singleton.Error(importProperty.Value.ToString(), "When importing the jsonld document");
}
else
{
// redisplay
RedrawAllAasxElements();
RedrawElementView();
}
}
}
catch (Exception ex)
{
Log.Singleton.Error(ex, "When importing the jsonld document");
}

if (Options.Curr.UseFlyovers) this.CloseFlyover();
}
public bool PanelConcurrentCheckIsVisible()
{
return MenuItemWorkspaceEventsShowLog.IsChecked;
Expand Down Expand Up @@ -2363,6 +2425,55 @@ public void CommandBinding_ExportTable()
pi.InvokeAction(actionName, this, ve1.theEnv, ve1.theSubmodel);
}

public void CommandBinding_SubmodelTDExport()
{
VisualElementSubmodelRef ve1 = null;

if (DisplayElements.SelectedItem != null && DisplayElements.SelectedItem is VisualElementSubmodelRef)
ve1 = DisplayElements.SelectedItem as VisualElementSubmodelRef;

if (ve1 == null || ve1.theSubmodel == null || ve1.theEnv == null)
{
MessageBoxFlyoutShow(
"No valid SubModel is selected.", "Unable to create TD JSON LD document",
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Error);
return;
}
var obj = ve1.theSubmodel;

// ok!
if (Options.Curr.UseFlyovers) this.StartFlyover(new EmptyFlyout());

var dlg = new Microsoft.Win32.SaveFileDialog();
dlg.InitialDirectory = DetermineInitialDirectory(_packageCentral.MainItem.Filename);
dlg.FileName = "Submodel_" + obj.idShort + ".jsonld";
dlg.Filter = "JSON files (*.JSONLD)|*.jsonld";
if (Options.Curr.UseFlyovers) this.StartFlyover(new EmptyFlyout());
var res = dlg.ShowDialog();
if (res == true)
{
JObject exportData = TDJsonExport.ExportSMtoJson(ve1.theSubmodel);
if (exportData["status"].ToString() == "success")
{
RememberForInitialDirectory(dlg.FileName);
using (var s = new StreamWriter(dlg.FileName))
{
string output = Newtonsoft.Json.JsonConvert.SerializeObject(exportData["data"],
Newtonsoft.Json.Formatting.Indented);
s.WriteLine(output);
}
}
else
{
MessageBoxFlyoutShow(
"Unable to Import the JSON LD File", exportData["data"].ToString(),
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Error);
}

}
if (Options.Curr.UseFlyovers) this.CloseFlyover();
}

public void CommandBinding_NewSubmodelFromPlugin()
{
// trivial things
Expand Down
7 changes: 7 additions & 0 deletions src/AasxPackageExplorer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<RoutedUICommand x:Key="SubmodelPut" Text="SubmodelPut" />
<RoutedUICommand x:Key="BMEcatImport" Text="BMEcatImport" />
<RoutedUICommand x:Key="CSVImport" Text="CSVImport" />
<RoutedUICommand x:Key="TDImport" Text="TDImport" />
<RoutedUICommand x:Key="SubmodelTDExport" Text="SubmodelTDExport" />
<RoutedUICommand x:Key="ExportAML" Text="ExportAML" />
<RoutedUICommand x:Key="OpcUaImportNodeSet" Text="OpcUaImportNodeSet" />
<RoutedUICommand x:Key="OPCUAi4aasExport" Text="OPCUAi4aasExport" />
Expand Down Expand Up @@ -222,6 +224,8 @@
<CommandBinding Command="{StaticResource SubmodelGet}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource BMEcatImport}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource CSVImport}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource TDImport}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource SubmodelTDExport}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource ExportAML}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource OpcUaImportNodeSet}" Executed="CommandBinding_Executed"/>
<CommandBinding Command="{StaticResource OPCUAi4aasImport}" Executed="CommandBinding_Executed"/>
Expand Down Expand Up @@ -347,6 +351,8 @@
<MenuItem Header="Import Submodel from Dictionary .." Command="{StaticResource ImportSubmodel}"/>
<MenuItem Header="Import Submodel Elements from Dictionary .." Command="{StaticResource ImportSubmodelElements}"/>
<MenuItem Header="Import BMEcat-file into SubModel .." Command="{StaticResource BMEcatImport}"/>
<MenuItem Header="Import Thing Description JSON LD document into SubModel .." Command="{StaticResource TDImport}"/>

<MenuItem Header="Import CSV-file into SubModel .." Command="{StaticResource CSVImport}"/>
<MenuItem Header="Import AAS from i4aas-nodeset .." Command="{StaticResource OPCUAi4aasImport}"/>
<MenuItem Header="Import OPC UA nodeset.xml as Submodel .." Command="{StaticResource OpcUaImportNodeSet}"/>
Expand All @@ -362,6 +368,7 @@
<MenuItem Header="Export Submodel as options for GenericForms .." Command="{StaticResource ExportGenericForms}"/>
<MenuItem Header="Export Submodel as snippet for PredefinedConcepts .." Command="{StaticResource ExportPredefineConcepts}"/>
<MenuItem Header="Export Submodel as table .." Command="{StaticResource ExportTable}"/>
<MenuItem Header="Export Submodel as Thing Description JSON LD document" Command="{StaticResource SubmodelTDExport}"/>
<MenuItem Header="Print Asset as code sheet .." Command="{StaticResource PrintAsset}"/>
<MenuItem Header="Export SMD .." Command="{StaticResource ExportSMD}"/>
</MenuItem>
Expand Down
Loading