Skip to content

Commit

Permalink
Added support for default values for primitive data types
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasfruehwirth committed Dec 1, 2020
1 parent c53b923 commit a4be52c
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 20 deletions.
66 changes: 46 additions & 20 deletions QvtoTransformationRules/transforms/ClassDiagram/Classes.qvto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ClassDiagram.Operations;

modeltype UML uses 'http://www.eclipse.org/uml2/5.0.0/UML';
modeltype OPCUA uses set('http://opcfoundation.org/UA/2011/03/UANodeSet.xsd');
modeltype TYPES uses types('http://opcfoundation.org/UA/2008/02/Types.xsd');
modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');

mapping UML::Class::class2OPCUAObjectType(inout nodeset : OPCUA::UANodeSetType) : OPCUA::UAObjectType {
Expand Down Expand Up @@ -44,26 +45,51 @@ mapping UML::Property::property2UAVariable(inout parent : OPCUA::UANode) : OPCUA
browseName := self.createBrowseName();
displayName := object OPCUA::LocalizedText{value := browseName};

// set the datatype of the UA::Variable
switch {
case (self.type.toString().find("Integer") > 0) {
dataType := getIdOrAlias("Int32"); // do not use getIdentifier here
}
case (self.type.toString().find("String") > 0) {
dataType := getIdOrAlias("String"); // do not use getIdentifier here
}
case (self.type.toString().find("Real") > 0) {
dataType := getIdOrAlias("Double"); // do not use getIdentifier here
}
case (self.type.toString().find("Float") > 0) {
dataType := getIdOrAlias("Double"); // do not use getIdentifier here
}
case (self.type.toString().find("Boolean") > 0) {
dataType := getIdOrAlias("Boolean"); // do not use getIdentifier here
}
else {
raise Exception("Unkown datatype for parameter " + self.name + ": " + self.type.toString());
}
// set the datatype and maybe the value of the UA::Variable
if(self.type.toString().find("Int") > 0) {
dataType := getIdOrAlias("Int32");
if(self.defaultValue <> null) {
var feature := TYPES::DocumentRoot.oclAsType(EClass).getEStructuralFeature("int32");
value := object OPCUA::ValueType1{};
value.oclAsType(EObject).eSet(feature, self.defaultValue.oclAsType(UML::LiteralInteger).value);
};
} else if (self.type.toString().find("String") > 0) {
dataType := getIdOrAlias("String");
if(self.defaultValue <> null) {
var feature := TYPES::DocumentRoot.oclAsType(EClass).getEStructuralFeature("string");
value := object OPCUA::ValueType1{};
value.oclAsType(EObject).eSet(feature, self.defaultValue.oclAsType(UML::LiteralString).value);
};
} else if (self.type.toString().find("Real") > 0) {
dataType := getIdOrAlias("Double");
if(self.defaultValue <> null) {
var feature := TYPES::DocumentRoot.oclAsType(EClass).getEStructuralFeature("double");
value := object OPCUA::ValueType1{};
value.oclAsType(EObject).eSet(feature, self.defaultValue.oclAsType(UML::LiteralReal).value);
};
} else if (self.type.toString().find("Double") > 0) {
dataType := getIdOrAlias("Double");
if(self.defaultValue <> null) {
var feature := TYPES::DocumentRoot.oclAsType(EClass).getEStructuralFeature("double");
value := object OPCUA::ValueType1{};
value.oclAsType(EObject).eSet(feature, self.defaultValue.oclAsType(UML::LiteralReal).value);
};
} else if (self.type.toString().find("Float") > 0) {
dataType := getIdOrAlias("Double");
if(self.defaultValue <> null) {
var feature := TYPES::DocumentRoot.oclAsType(EClass).getEStructuralFeature("double");
value := object OPCUA::ValueType1{};
value.oclAsType(EObject).eSet(feature, self.defaultValue.oclAsType(UML::LiteralReal).value);
};
} else if (self.type.toString().find("Boolean") > 0) {
dataType := getIdOrAlias("Boolean");
if(self.defaultValue <> null) {
var feature := TYPES::DocumentRoot.oclAsType(EClass).getEStructuralFeature("boolean");
value := object OPCUA::ValueType1{};
value.oclAsType(EObject).eSet(feature, self.defaultValue.oclAsType(UML::LiteralBoolean).value);
};
} else {
raise Exception("Unkown datatype for parameter " + self.name + ": " + self.type.toString());
};

// link the OPCUA::UAVariable to the parent via a HasComponent reference
Expand Down
2 changes: 2 additions & 0 deletions Uml2OpcuaTransformationTests/PropertyDefaultValue.di
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<architecture:ArchitectureDescription xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" contextId="org.eclipse.papyrus.infra.services.edit.TypeContext"/>
45 changes: 45 additions & 0 deletions Uml2OpcuaTransformationTests/PropertyDefaultValue.notation
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.3/notation" xmlns:style="http://www.eclipse.org/papyrus/infra/gmfdiag/style" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_n9rskMdPEeqBwPQ5-6UCwg" type="PapyrusUMLClassDiagram" name="Class Diagram" measurementUnit="Pixel">
<children xmi:type="notation:Shape" xmi:id="_pu7AsMdPEeqBwPQ5-6UCwg" type="Class_Shape">
<children xmi:type="notation:DecorationNode" xmi:id="_pvEKoMdPEeqBwPQ5-6UCwg" type="Class_NameLabel">
<element xmi:type="uml:Class" href="PropertyDefaultValue.uml#_punesMdPEeqBwPQ5-6UCwg"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_pvEKocdPEeqBwPQ5-6UCwg" type="Class_FloatingNameLabel">
<element xmi:type="uml:Class" href="PropertyDefaultValue.uml#_punesMdPEeqBwPQ5-6UCwg"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_pvEKosdPEeqBwPQ5-6UCwg" y="15"/>
</children>
<children xmi:type="notation:BasicCompartment" xmi:id="_pvN7oMdPEeqBwPQ5-6UCwg" type="Class_AttributeCompartment">
<children xmi:type="notation:Shape" xmi:id="_yDoo4MdPEeqBwPQ5-6UCwg" type="Property_ClassAttributeLabel">
<element xmi:type="uml:Property" href="PropertyDefaultValue.uml#_yDe34MdPEeqBwPQ5-6UCwg"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_yDoo4cdPEeqBwPQ5-6UCwg"/>
</children>
<styles xmi:type="notation:TitleStyle" xmi:id="_pvN7ocdPEeqBwPQ5-6UCwg"/>
<styles xmi:type="notation:SortingStyle" xmi:id="_pvN7osdPEeqBwPQ5-6UCwg"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_pvN7o8dPEeqBwPQ5-6UCwg"/>
<element xmi:type="uml:Class" href="PropertyDefaultValue.uml#_punesMdPEeqBwPQ5-6UCwg"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_pvN7pMdPEeqBwPQ5-6UCwg"/>
</children>
<children xmi:type="notation:BasicCompartment" xmi:id="_pvN7pcdPEeqBwPQ5-6UCwg" type="Class_OperationCompartment">
<styles xmi:type="notation:TitleStyle" xmi:id="_pvN7psdPEeqBwPQ5-6UCwg"/>
<styles xmi:type="notation:SortingStyle" xmi:id="_pvN7p8dPEeqBwPQ5-6UCwg"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_pvN7qMdPEeqBwPQ5-6UCwg"/>
<element xmi:type="uml:Class" href="PropertyDefaultValue.uml#_punesMdPEeqBwPQ5-6UCwg"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_pvN7qcdPEeqBwPQ5-6UCwg"/>
</children>
<children xmi:type="notation:BasicCompartment" xmi:id="_pvN7qsdPEeqBwPQ5-6UCwg" type="Class_NestedClassifierCompartment">
<styles xmi:type="notation:TitleStyle" xmi:id="_pvN7q8dPEeqBwPQ5-6UCwg"/>
<styles xmi:type="notation:SortingStyle" xmi:id="_pvN7rMdPEeqBwPQ5-6UCwg"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_pvN7rcdPEeqBwPQ5-6UCwg"/>
<element xmi:type="uml:Class" href="PropertyDefaultValue.uml#_punesMdPEeqBwPQ5-6UCwg"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_pvN7rsdPEeqBwPQ5-6UCwg"/>
</children>
<element xmi:type="uml:Class" href="PropertyDefaultValue.uml#_punesMdPEeqBwPQ5-6UCwg"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_pu7AscdPEeqBwPQ5-6UCwg" x="677" y="276"/>
</children>
<styles xmi:type="notation:StringValueStyle" xmi:id="_n9rskcdPEeqBwPQ5-6UCwg" name="diagram_compatibility_version" stringValue="1.4.0"/>
<styles xmi:type="notation:DiagramStyle" xmi:id="_n9rsksdPEeqBwPQ5-6UCwg"/>
<styles xmi:type="style:PapyrusDiagramStyle" xmi:id="_n9rsk8dPEeqBwPQ5-6UCwg" diagramKindId="org.eclipse.papyrus.uml.diagram.class">
<owner xmi:type="uml:Model" href="PropertyDefaultValue.uml#_n7J9AMdPEeqBwPQ5-6UCwg"/>
</styles>
<element xmi:type="uml:Model" href="PropertyDefaultValue.uml#_n7J9AMdPEeqBwPQ5-6UCwg"/>
</notation:Diagram>
12 changes: 12 additions & 0 deletions Uml2OpcuaTransformationTests/PropertyDefaultValue.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_n7J9AMdPEeqBwPQ5-6UCwg" name="PropertyString">
<packageImport xmi:type="uml:PackageImport" xmi:id="_oCcQwMdPEeqBwPQ5-6UCwg">
<importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Class" xmi:id="_punesMdPEeqBwPQ5-6UCwg" name="Robot">
<ownedAttribute xmi:type="uml:Property" xmi:id="_yDe34MdPEeqBwPQ5-6UCwg" name="myProperty">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
<defaultValue xmi:type="uml:LiteralString" xmi:id="_oFZFUDPzEeusqo4eorF9lg" value="SomeDefaultValueString"/>
</ownedAttribute>
</packagedElement>
</uml:Model>
34 changes: 34 additions & 0 deletions Uml2OpcuaTransformationTests/PropertyDefaultValue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:types="http://opcfoundation.org/UA/2008/02/Types.xsd">
<NamespaceUris>
<Uri>PropertyString</Uri>
</NamespaceUris>
<Aliases>
<Alias Alias="String">i=12</Alias>
<Alias Alias="HasModellingRule">i=37</Alias>
<Alias Alias="BaseDataVariableType">i=63</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="BaseObjectType">i=58</Alias>
<Alias Alias="ModellingRule_Mandatory">i=78</Alias>
</Aliases>
<UAVariable BrowseName="myProperty" NodeId="ns=1;s=myProperty" ParentNodeId="ns=1;s=RobotType" DataType="String">
<DisplayName>myProperty</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;s=RobotType</Reference>
</References>
<Value>
<types:String>SomeDefaultValueString</types:String>
</Value>
</UAVariable>
<UAObjectType BrowseName="RobotType" NodeId="ns=1;s=RobotType">
<DisplayName>RobotType</DisplayName>
<References>
<Reference IsForward="false" ReferenceType="HasSubtype">BaseObjectType</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=myProperty</Reference>
</References>
</UAObjectType>
</UANodeSet>

0 comments on commit a4be52c

Please sign in to comment.