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

Commit

Permalink
AID Plugin First Version
Browse files Browse the repository at this point in the history
  • Loading branch information
hapakala committed Jan 30, 2024
1 parent a5bba3f commit 010e614
Show file tree
Hide file tree
Showing 21 changed files with 3,747 additions and 9 deletions.
90 changes: 89 additions & 1 deletion src/AasxIntegrationBase/AasForms/FormDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class FormDescReferable : FormDescBase
/// Preset for Referable.description
/// </summary>
[JsonProperty(Order = 7)]
public List<Aas.ILangStringTextType> PresetDescription = null;
public List<Aas.ILangStringTextType> PresetDescription = new List<ILangStringTextType>();

/// <summary>
/// SemanticId of the SubmodelElement. Always required.
Expand Down Expand Up @@ -591,6 +591,94 @@ public Aas.Property GenerateDefault()
}
}


[DisplayName("FormRange")]
public class FormDescRange : FormDescSubmodelElement
{
[JsonProperty(Order = 20)]
public string[] allowedValueTypes = new string[] { "string" };

/// <summary>
/// Pre-set the editable Property value with this value.
/// </summary>
[JsonProperty(Order = 21)]
public string presetMin = "";

[JsonProperty(Order = 22)]
public string presetMax = "";

// Constructors
//=============

public FormDescRange() { }

public FormDescRange(
string formText, FormMultiplicity multiplicity, Aas.Key smeSemanticId,
string presetIdShort, string formInfo = null, bool isReadOnly = false, string valueType = null,
string presetMin = null, string presetMax = null)
: base(formText, multiplicity, smeSemanticId, presetIdShort, formInfo, isReadOnly)
{
// init
if (valueType != null)
this.allowedValueTypes = new[] { valueType };
if (presetMin != null)
this.presetMin = presetMin;
if (presetMax != null)
this.presetMax = presetMax;

}

public FormDescRange(FormDescRange other)
: base(other)
{
// this part == static, therefore only shallow copy
this.allowedValueTypes = other.allowedValueTypes;
this.presetMin = other.presetMin;
this.presetMax = other.presetMax;
}

#if !DoNotUseAasxCompatibilityModels
public FormDescRange(AasxCompatibilityModels.AasxIntegrationBase.AasForms.FormDescRangeV20 other)
: base(other)
{
// this part == static, therefore only shallow copy
this.allowedValueTypes = other.allowedValueTypes;
this.presetMin = other.presetMin;
this.presetMax = other.presetMax;
}
#endif

public override FormDescSubmodelElement Clone()
{
return new FormDescRange(this);
}

/// <summary>
/// Build a new instance, based on the description data
/// </summary>
public override FormInstanceSubmodelElement CreateInstance(
FormInstanceListOfSame parentInstance, Aas.ISubmodelElement source = null)
{
return new FormInstanceRange(parentInstance, this, source);
}

public Aas.Range GenerateDefault()
{
var res = new Aas.Range(Aas.DataTypeDefXsd.String);
this.InitSme(res);
if (this.presetMin != null)
res.Min = this.presetMin;
if (this.presetMax != null)
res.Max = this.presetMax;
if (this.allowedValueTypes.Length == 1)
{
res.ValueType = Aas.Stringification.DataTypeDefXsdFromString(this.allowedValueTypes[0])
?? Aas.DataTypeDefXsd.String;
}
return res;
}
}

[DisplayName("FormMultiLangProp")]
public class FormDescMultiLangProp : FormDescSubmodelElement
{
Expand Down
159 changes: 158 additions & 1 deletion src/AasxIntegrationBase/AasForms/FormInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,6 @@ public override void RenderAnyUi(AnyUiStackPanel view, AnyUiSmallWidgetToolkit u
}
}
}

public class FormInstanceProperty : FormInstanceSubmodelElement
{
public FormInstanceProperty(
Expand Down Expand Up @@ -1569,6 +1568,164 @@ public override void RenderAnyUi(AnyUiStackPanel view, AnyUiSmallWidgetToolkit u
}
}

public class FormInstanceRange : FormInstanceSubmodelElement
{
public FormInstanceRange(
FormInstanceListOfSame parentInstance, FormDescRange parentDesc,
Aas.ISubmodelElement source = null, bool deepCopy = false)
{
// way back to description
this.parentInstance = parentInstance;
this.desc = parentDesc;

// initialize Referable
var p = new Aas.Range(Aas.DataTypeDefXsd.String);
this.sme = p;
InitReferable(parentDesc, source);

// check, if a source is present
this.sourceSme = source;
var pSource = this.sourceSme as Aas.Range;
if (pSource != null)
{
// take over
p.ValueType = pSource.ValueType;
p.Min = pSource.Min;
p.Max = pSource.Max;
}
else
{
// some more preferences
if (parentDesc.allowedValueTypes != null && parentDesc.allowedValueTypes.Length >= 1)
p.ValueType = Aas.Stringification.DataTypeDefXsdFromString(parentDesc.allowedValueTypes[0])
?? Aas.DataTypeDefXsd.String;

if (parentDesc.presetMin != null && parentDesc.presetMax != null)
{
p.Min = parentDesc.presetMin;
p.Max = parentDesc.presetMax;
// immediately set touched in order to have this value saved
this.Touch();
}
}

// create user control
#if USE_WPF
if (createSubControls)
{
this.subControl = new FormSubControlProperty();
this.subControl.DataContext = this;
}
#endif
}

/// <summary>
/// Before rendering the SME into a list of new elements, process the SME.
/// If <c>Touched</c>, <c>sourceSme</c> and <c>editSource</c> is set,
/// this function shall write back the new values instead of
/// producing a new element. Returns True, if a new element shall be rendered.
/// </summary>
public override bool ProcessSmeForRender(
AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false, bool editSource = false)
{
// refer to base (SME) function, but not caring about result
base.ProcessSmeForRender(packageEnv, addFilesToPackage, editSource);

var p = this.sme as Aas.Range;
var pSource = this.sourceSme as Aas.Range;
if (p != null && Touched && pSource != null && editSource)
{
pSource.ValueType = p.ValueType;
pSource.Min = p.Min;
pSource.Max = p.Max;
return false;
}
return true;
}

/// <summary>
/// Event was raised from master because matching slave.
/// </summary>
public override void OnSlaveEvent(
FormDescSubmodelElement masterDesc, FormInstanceSubmodelElement masterInst, int index)
{
// access to master
var pMasterInst = masterInst as FormInstanceRange;
var pMaster = pMasterInst?.sme as Aas.Range;
if (pMaster?.Min == null || pMaster.Max == null)
return;

// accues to this
var pThis = this.sme as Aas.Range;
if (pThis == null)
return;

// refresh
#if USE_WPF
if (this.subControl != null && this.subControl is FormSubControlRange scr)
scr.UpdateDisplay();
#endif
if (MainControl is AnyUiTextBox mtb)
{
mtb.Text = pThis.Min + ".." + pThis.Max;
mtb.Touch();
}

if (MainControl is AnyUiComboBox mcb && mcb.IsEditable == true)
{
mcb.Text = pThis.Min + ".." + pThis.Max;
mcb.Touch();
}
}

/// <summary>
/// Render the AnyUI representation of the current instance data structure
/// </summary>
public override void RenderAnyUi(AnyUiStackPanel view, AnyUiSmallWidgetToolkit uitk,
PluginOperationContextBase opctx)
{
// access
var prop = sme as Aas.Range;
var pDesc = desc as FormDescRange;
if (prop == null || pDesc == null)
return;

// Intended layout
// Grid
// Index
// TextBox | ComboBox

var g = view.Add(
uitk.AddSmallGrid(rows: 2, cols: 3, colWidths: new[] { "2:", "*", "2:" }));


MainControl = AnyUiUIElement.RegisterControl(
uitk.AddSmallTextBoxTo(g, 0, 1,
margin: new AnyUiThickness(0, 2, 0, 2),
text: "" + prop.Min),
(o) =>
{
if (o is string os)
prop.Min = os;
Touch();
return new AnyUiLambdaActionNone();
});


MainControl = AnyUiUIElement.RegisterControl(
uitk.AddSmallTextBoxTo(g, 1, 1,
margin: new AnyUiThickness(0, 2, 0, 2),
text: "" + prop.Max),
(o) =>
{
if (o is string os)
prop.Max = os;
Touch();
return new AnyUiLambdaActionNone();
});
}
}

public class FormInstanceMultiLangProp : FormInstanceSubmodelElement
{
public FormInstanceMultiLangProp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ public class FormDescPropertyV20 : FormDescSubmodelElementV20

}

[DisplayName("FormRange_V20")]
public class FormDescRangeV20 : FormDescSubmodelElementV20
{
/// <summary>
/// Pre-set the Property with this valueType. Right now, only one item (and this shall be "string") is allowed!
/// </summary>
[JsonProperty(Order = 20)]
public string[] allowedValueTypes = new string[] { "string" };

/// <summary>
/// Pre-set the editable Range Min with this value.
/// </summary>
[JsonProperty(Order = 21)]
public string presetMin = "";

/// <summary>
/// Pre-set the editable Range Max with this value.
/// </summary>
[JsonProperty(Order = 22)]
public string presetMax = "";
}

[DisplayName("FormMultiLangProp_V20")]
public class FormDescMultiLangPropV20 : FormDescSubmodelElementV20
{
Expand Down
38 changes: 33 additions & 5 deletions src/AasxPackageExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxPluginDigitalNameplate"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxPluginContactInformation", "AasxPluginContactInformation\AasxPluginContactInformation.csproj", "{938BB137-DC45-4A84-B0C9-AC46DA321FDB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxPluginAID", "AasxPluginAID\AasxPluginAID.csproj", "{B481FE2E-20B0-49AD-88DE-930A992DF49F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -268,7 +270,6 @@ Global
{EBAE658A-3ECE-4C98-89BC-F79809AB4A5E}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{EBAE658A-3ECE-4C98-89BC-F79809AB4A5E}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{967E60E3-D668-42A3-AA0B-1A031C20D871}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{967E60E3-D668-42A3-AA0B-1A031C20D871}.Debug|Any CPU.Build.0 = Debug|Any CPU
{967E60E3-D668-42A3-AA0B-1A031C20D871}.Debug|x64.ActiveCfg = Debug|Any CPU
{967E60E3-D668-42A3-AA0B-1A031C20D871}.Debug|x64.Build.0 = Debug|Any CPU
{967E60E3-D668-42A3-AA0B-1A031C20D871}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -298,7 +299,6 @@ Global
{967E60E3-D668-42A3-AA0B-1A031C20D871}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{967E60E3-D668-42A3-AA0B-1A031C20D871}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{6C45112D-B7F0-4463-BE6D-A8A2B5A547BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C45112D-B7F0-4463-BE6D-A8A2B5A547BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C45112D-B7F0-4463-BE6D-A8A2B5A547BF}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C45112D-B7F0-4463-BE6D-A8A2B5A547BF}.Debug|x64.Build.0 = Debug|Any CPU
{6C45112D-B7F0-4463-BE6D-A8A2B5A547BF}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -836,7 +836,6 @@ Global
{7788AC2B-7F97-4755-B343-C4196FA90198}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{7788AC2B-7F97-4755-B343-C4196FA90198}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{2F21FEFF-F0EF-40B5-BA05-09FC9F499AE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F21FEFF-F0EF-40B5-BA05-09FC9F499AE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F21FEFF-F0EF-40B5-BA05-09FC9F499AE9}.Debug|x64.ActiveCfg = Debug|Any CPU
{2F21FEFF-F0EF-40B5-BA05-09FC9F499AE9}.Debug|x64.Build.0 = Debug|Any CPU
{2F21FEFF-F0EF-40B5-BA05-09FC9F499AE9}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1436,7 +1435,6 @@ Global
{E9AC7B0F-58FC-4BD8-A1C9-97BBB34A4E99}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{E9AC7B0F-58FC-4BD8-A1C9-97BBB34A4E99}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{BCE9B9F3-35CD-4CEA-8C88-68B0FD48DFD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCE9B9F3-35CD-4CEA-8C88-68B0FD48DFD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCE9B9F3-35CD-4CEA-8C88-68B0FD48DFD5}.Debug|x64.ActiveCfg = Debug|Any CPU
{BCE9B9F3-35CD-4CEA-8C88-68B0FD48DFD5}.Debug|x64.Build.0 = Debug|Any CPU
{BCE9B9F3-35CD-4CEA-8C88-68B0FD48DFD5}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1760,7 +1758,6 @@ Global
{4EB64F40-1A01-46BB-BEED-D1A75313C7F8}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{4EB64F40-1A01-46BB-BEED-D1A75313C7F8}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{BE68E42C-28CB-4298-9F34-A18AF92FC4DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE68E42C-28CB-4298-9F34-A18AF92FC4DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE68E42C-28CB-4298-9F34-A18AF92FC4DE}.Debug|x64.ActiveCfg = Debug|Any CPU
{BE68E42C-28CB-4298-9F34-A18AF92FC4DE}.Debug|x64.Build.0 = Debug|Any CPU
{BE68E42C-28CB-4298-9F34-A18AF92FC4DE}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1939,6 +1936,36 @@ Global
{938BB137-DC45-4A84-B0C9-AC46DA321FDB}.ReleaseWithoutCEF|x64.Build.0 = Release|Any CPU
{938BB137-DC45-4A84-B0C9-AC46DA321FDB}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{938BB137-DC45-4A84-B0C9-AC46DA321FDB}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Debug|x64.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Debug|x64.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Debug|x86.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugSlow|Any CPU.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugSlow|Any CPU.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugSlow|x64.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugSlow|x64.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugSlow|x86.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugSlow|x86.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugWithoutCEF|Any CPU.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugWithoutCEF|Any CPU.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugWithoutCEF|x64.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugWithoutCEF|x64.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugWithoutCEF|x86.ActiveCfg = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.DebugWithoutCEF|x86.Build.0 = Debug|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Release|Any CPU.Build.0 = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Release|x64.ActiveCfg = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Release|x64.Build.0 = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Release|x86.ActiveCfg = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.Release|x86.Build.0 = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.ReleaseWithoutCEF|Any CPU.ActiveCfg = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.ReleaseWithoutCEF|Any CPU.Build.0 = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.ReleaseWithoutCEF|x64.ActiveCfg = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.ReleaseWithoutCEF|x64.Build.0 = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.ReleaseWithoutCEF|x86.ActiveCfg = Release|Any CPU
{B481FE2E-20B0-49AD-88DE-930A992DF49F}.ReleaseWithoutCEF|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2002,6 +2029,7 @@ Global
{D39BC0A4-64EA-4C7B-B72C-BF0A80FF29FE} = {DDA9C372-F8ED-4099-A53C-01B9333FD985}
{DA75828B-E5AC-4E9D-AE1F-398F8FF5AE25} = {66D730EB-B9D7-4C3A-8954-0F86240AD612}
{938BB137-DC45-4A84-B0C9-AC46DA321FDB} = {66D730EB-B9D7-4C3A-8954-0F86240AD612}
{B481FE2E-20B0-49AD-88DE-930A992DF49F} = {66D730EB-B9D7-4C3A-8954-0F86240AD612}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1AE21162-9541-4B98-A49C-A63B6AD03998}
Expand Down
Loading

0 comments on commit 010e614

Please sign in to comment.