Skip to content

Commit

Permalink
Properties of the corresponding class are now also automatically adde…
Browse files Browse the repository at this point in the history
…d if the instance specificiation does not define these properties.
  • Loading branch information
thomasfruehwirth committed Dec 3, 2020
1 parent 1418a92 commit 72da5ef
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 33 deletions.
58 changes: 57 additions & 1 deletion QvtoTransformationRules/transforms/ClassDiagram/Instances.qvto
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ mapping UML::InstanceSpecification::instanceSpecification2OPCUAObject(inout node
browseName := self.createBrowseName();
nodeId := self.createNodeId();
displayName := (object OPCUA::LocalizedText {value := browseName})->asOrderedSet();

var classifier := self.classifier->any(true); // should only have one classifier

// transform property slots of the Instance
nodeset.uAVariable += self.ownedElement->selectByType(UML::Slot)->select(slot | slot.definingFeature.oclIsTypeOf(UML::Property))->map transformPropertySlot2UAVariable(result);

// TODO: transform properties of the class that are not defined as slot
log("number of slots not defined in the instance: " + classifier.ownedElement->selectByType(UML::Property)->select(p | self.slot.definingFeature->excludes(p))->size().toString());
nodeset.uAVariable += classifier.ownedElement->selectByType(UML::Property)->select(p | self.slot.definingFeature->excludes(p))->map transformClassifierProperty2UAVariable(result);

assert warning (self.classifier->size() <= 1) with log("Element specifies more than one classifier. Only the first value is used");
_references := object OPCUA::ListOfReferences{};
_references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("HasTypeDefinition"); value := self.classifier->any(true).createNodeId()}; // should only have one classifier
_references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("HasTypeDefinition"); value := classifier.createNodeId()};
_references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("Organizes"); value := getIdOrAlias("ObjectsFolder"); isForward := false};
}

Expand Down Expand Up @@ -116,6 +120,58 @@ mapping UML::Slot::transformPropertySlot2UAVariable(inout parent : OPCUA::UANode

}

mapping UML::Property::transformClassifierProperty2UAVariable(inout parent : OPCUA::UANode) : OPCUA::UAVariable {
log("transformClassifierProperty2UAVariable for UML element " + self.name);

// set attributs of the OPCUA::UAVariable
nodeId := self.createNodeId(false);
browseName := self.createBrowseName();
displayName := object OPCUA::LocalizedText{value := browseName};

// 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 or self.type.toString().find("Double") > 0 or 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
parent._references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("HasComponent"); value := nodeId};
parentNodeId := parent.nodeId;

// add references
_references := object OPCUA::ListOfReferences{};
_references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("HasTypeDefinition"); value := getIdOrAlias("BaseDataVariableType")};
_references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("HasModellingRule"); value := getIdOrAlias("ModellingRule_Mandatory")}; // TODO replace with correct modelling rule
_references.reference += object OPCUA::Reference{referenceType := getIdOrAlias("HasComponent"); value := parent.nodeId; isForward := false};

}
/*
helper UML::Slot::transformPropertySlot2UAVariable(inout nodeset: OPCUA::UANodeSetType) : OPCUA::UAVariable{
log("transformPropertySlot for UML element " + self.toString());
Expand Down
7 changes: 4 additions & 3 deletions Uml2OpcuaTransformationTests/InstanceWithSlots.uml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?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="Instance">
<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="InstanceWithSlots">
<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="Class5">
<packagedElement xmi:type="uml:Class" xmi:id="_punesMdPEeqBwPQ5-6UCwg" name="Robot">
<ownedAttribute xmi:type="uml:Property" xmi:id="_Q-UhQDPhEeusqo4eorF9lg" name="Manufacturer">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/EcorePrimitiveTypes.library.uml#EString"/>
<defaultValue xmi:type="uml:LiteralString" xmi:id="_5jal4DS4EeuvtL-cjTXdxg" value="ABB"/>
</ownedAttribute>
<ownedAttribute xmi:type="uml:Property" xmi:id="_FevlsDSIEeuvtL-cjTXdxg" name="Axes">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
<defaultValue xmi:type="uml:LiteralInteger" xmi:id="_gtf6IDVFEeuvtL-cjTXdxg" value="6"/>
</ownedAttribute>
<ownedAttribute xmi:type="uml:Property" xmi:id="_RlIvwDSIEeuvtL-cjTXdxg" name="SN">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
Expand All @@ -19,7 +20,7 @@
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:InstanceSpecification" xmi:id="_KYJegDPhEeusqo4eorF9lg" name="Class5Instance" classifier="_punesMdPEeqBwPQ5-6UCwg">
<packagedElement xmi:type="uml:InstanceSpecification" xmi:id="_KYJegDPhEeusqo4eorF9lg" name="MyRobotInstance" classifier="_punesMdPEeqBwPQ5-6UCwg">
<slot xmi:type="uml:Slot" xmi:id="_J7neEDPiEeusqo4eorF9lg" definingFeature="_Q-UhQDPhEeusqo4eorF9lg"/>
<slot xmi:type="uml:Slot" xmi:id="_XqlEADSIEeuvtL-cjTXdxg" definingFeature="_RlIvwDSIEeuvtL-cjTXdxg">
<value xmi:type="uml:LiteralString" xmi:id="_bvo04DSIEeuvtL-cjTXdxg" value="#005001"/>
Expand Down
72 changes: 43 additions & 29 deletions Uml2OpcuaTransformationTests/InstanceWithSlots.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<?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>Instance</Uri>
<Uri>InstanceWithSlots</Uri>
</NamespaceUris>
<Aliases>
<Alias Alias="Int32">i=6</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="ObjectsFolder">i=85</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="ModellingRule_Mandatory">i=78</Alias>
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="BaseObjectType">i=58</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasModellingRule">i=37</Alias>
<Alias Alias="BaseDataVariableType">i=63</Alias>
<Alias Alias="BaseObjectType">i=58</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="HasModellingRule">i=37</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="Int32">i=6</Alias>
</Aliases>
<UAVariable BrowseName="Axes" NodeId="ns=1;i=1002" ParentNodeId="ns=1;i=1000" DataType="Int32">
<DisplayName>Axes</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1000</Reference>
</References>
</UAVariable>
<UAVariable BrowseName="SN" NodeId="ns=1;i=1004" ParentNodeId="ns=1;i=1000" DataType="String">
<UAVariable BrowseName="SN" NodeId="ns=1;i=1002" ParentNodeId="ns=1;i=1000" DataType="String">
<DisplayName>SN</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
Expand All @@ -35,7 +27,7 @@
<types:String>#000000</types:String>
</Value>
</UAVariable>
<UAVariable BrowseName="Manufacturer" NodeId="ns=1;i=1001" ParentNodeId="ns=1;i=1000" DataType="String">
<UAVariable BrowseName="Manufacturer" NodeId="ns=1;i=1003" ParentNodeId="ns=1;i=1000" DataType="String">
<DisplayName>Manufacturer</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
Expand All @@ -46,16 +38,27 @@
<types:String>ABB</types:String>
</Value>
</UAVariable>
<UAVariable BrowseName="Description" NodeId="ns=1;i=1003" ParentNodeId="ns=1;i=1000" DataType="String">
<UAVariable BrowseName="Description" NodeId="ns=1;i=1001" ParentNodeId="ns=1;i=1000" DataType="String">
<DisplayName>Description</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1000</Reference>
</References>
</UAVariable>
<UAObjectType BrowseName="Class5Type" NodeId="ns=1;i=1000">
<DisplayName>Class5Type</DisplayName>
<UAVariable BrowseName="Axes" NodeId="ns=1;i=1004" ParentNodeId="ns=1;i=1000" DataType="Int32">
<DisplayName>Axes</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1000</Reference>
</References>
<Value>
<types:Int32>6</types:Int32>
</Value>
</UAVariable>
<UAObjectType BrowseName="RobotType" NodeId="ns=1;i=1000">
<DisplayName>RobotType</DisplayName>
<References>
<Reference IsForward="false" ReferenceType="HasSubtype">BaseObjectType</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1001</Reference>
Expand All @@ -64,38 +67,49 @@
<Reference ReferenceType="HasComponent">ns=1;i=1004</Reference>
</References>
</UAObjectType>
<UAVariable BrowseName="Description" NodeId="ns=1;i=1007" ParentNodeId="ns=1;i=1005" DataType="String">
<UAVariable BrowseName="Manufacturer" NodeId="ns=1;i=1006" ParentNodeId="ns=1;i=1005" DataType="String">
<DisplayName>Manufacturer</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1005</Reference>
</References>
<Value>
<types:String>ABB</types:String>
</Value>
</UAVariable>
<UAVariable BrowseName="Description" NodeId="ns=1;i=1008" ParentNodeId="ns=1;i=1005" DataType="String">
<DisplayName>Description</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1005</Reference>
</References>
</UAVariable>
<UAVariable BrowseName="Manufacturer" NodeId="ns=1;i=1008" ParentNodeId="ns=1;i=1005" DataType="String">
<DisplayName>Manufacturer</DisplayName>
<UAVariable BrowseName="SN" NodeId="ns=1;i=1007" ParentNodeId="ns=1;i=1005" DataType="String">
<DisplayName>SN</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1005</Reference>
</References>
<Value>
<types:String>ABB</types:String>
<types:String>#005001</types:String>
</Value>
</UAVariable>
<UAVariable BrowseName="SN" NodeId="ns=1;i=1006" ParentNodeId="ns=1;i=1005" DataType="String">
<DisplayName>SN</DisplayName>
<UAVariable BrowseName="Axes" NodeId="ns=1;i=1009" ParentNodeId="ns=1;i=1005" DataType="Int32">
<DisplayName>Axes</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">BaseDataVariableType</Reference>
<Reference ReferenceType="HasModellingRule">ModellingRule_Mandatory</Reference>
<Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=1005</Reference>
</References>
<Value>
<types:String>#005001</types:String>
<types:Int32>6</types:Int32>
</Value>
</UAVariable>
<UAObject BrowseName="Class5Instance" NodeId="ns=1;i=1005">
<DisplayName>Class5Instance</DisplayName>
<UAObject BrowseName="MyRobotInstance" NodeId="ns=1;i=1005">
<DisplayName>MyRobotInstance</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=1000</Reference>
<Reference IsForward="false" ReferenceType="Organizes">ObjectsFolder</Reference>
Expand Down

0 comments on commit 72da5ef

Please sign in to comment.