import org.omg.eclipse.sysml.UMLUtils; import modelicaQVTUtils.ModelicaUtils; modeltype UML uses 'http://www.eclipse.org/uml2/3.0.0/UML'; modeltype AlgorithmItem uses 'http://www.openmodelica.org/openmodelica.unparsed/AlgorithmItem'; modeltype AlgorithmStatement uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/AlgorithmStatement'; modeltype Annotation uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Annotation'; modeltype ArrayDim uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ArrayDim'; modeltype Class uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Class'; modeltype ClassDef uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ClassDef'; modeltype ClassPart uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ClassPart'; modeltype Comment uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Comment'; modeltype Component uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Component'; modeltype ComponentCondition uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ComponentCondition'; modeltype ComponentItem uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ComponentItem'; modeltype ComponentRef uses 'http://www.openmodelica.org/openmodelica.unparsed/ComponentRef'; modeltype ConstrainClass uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ConstrainClass'; modeltype Direction uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Direction'; modeltype Each uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Each'; modeltype Element uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Element'; modeltype ElementArg uses 'http://www.openmodelica.org/openmodelica.unparsed/ElementArg'; modeltype ElementAttributes uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ElementAttributes'; modeltype ElementItem uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ElementItem'; modeltype ElementSpec uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ElementSpec'; modeltype EnumDef uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/EnumDef'; modeltype EnumLiteral uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/EnumLiteral'; modeltype Equation uses 'http://www.openmodelica.org/openmodelica.unparsed/Equation'; modeltype EquationItem uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/EquationItem'; modeltype Exp uses 'http://www.openmodelica.org/openmodelica.unparsed/Exp'; modeltype ExternalDecl uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/ExternalDecl'; modeltype FunctionArgs uses 'http://www.openmodelica.org/openmodelica.unparsed/FunctionArgs'; modeltype Import uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Import'; modeltype InnerOuter uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/InnerOuter'; modeltype Iterators uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Iterators'; modeltype Modifications uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Modifications'; modeltype NamedArg uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/NamedArg'; modeltype Operator uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Operator'; modeltype Path uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Path'; modeltype Program uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Program'; modeltype RedeclareKeywords uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/RedeclareKeywords'; modeltype Restriction uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Restriction'; modeltype Subscript uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Subscript'; modeltype TypeSpec uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/TypeSpec'; modeltype Variability uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Variability'; modeltype Within uses 'http://www.openmodelica.org/openmodelica.abstract.syntax/Within'; transformation SysML2ModelicaUnparsed(in sysmlModel:UML, in sysml4ModelicaProfile:UML, out modelicaModel:Program); property sysml4Modelica_profile:UML::Profile = sysml4ModelicaProfile.rootObjects()![UML::Profile]; property ModelicaClassDefinition_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaClassDefinition"]; property ModelicaClass_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaClass"]; property ModelicaModel_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaModel"]; property ModelicaRecord_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaRecord"]; property ModelicaBlock_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaBlock"]; property ModelicaConnector_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaConnector"]; property ModelicaType_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaType"]; property ModelicaPackage_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaPackage"]; property ModelicaFunction_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaFunction"]; property ModelicaExtends_stereotype : UML::Stereotype = sysml4Modelica_profile.ownedStereotype![name = "ModelicaExtends"]; property ModelicaFunctionParameter_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaFunctionParameter")->any(true); property ModelicaPart_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaPart")->any(true); property ModelicaPort_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaPort")->any(true); property ModelicaValueProperty_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaValueProperty")->any(true); property ModelicaAlgorithm_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaAlgorithm")->any(true); property ModelicaConnection_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaConnection")->any(true); property ModelicaEquation_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaEquation")->any(true); property ModelicaAnnotation_stereotype : UML::Stereotype = sysml4Modelica_profile.subobjects()[UML::Stereotype] ->select(name = "ModelicaAnnotation")->any(true); property modelicaTypesClass : UML::Type = sysml4Modelica_profile.nestedPackage![name = "Types"] .ownedType![name = "ModelicaPredefinedTypes"]; property modelicaRealType : UML::Type = modelicaTypesClass.subobjects()[UML::DataType] ->select(name = "ModelicaReal")->any(true); property modelicaIntegerType : UML::Type = modelicaTypesClass.subobjects()[UML::DataType] ->select(name = "ModelicaInteger")->any(true); property modelicaBooleanType : UML::Type = modelicaTypesClass.subobjects()[UML::DataType] ->select(name = "ModelicaBoolean")->any(true); property modelicaStringType : UML::Type = modelicaTypesClass.subobjects()[UML::DataType] ->select(name = "ModelicaString")->any(true); property modelicaStateSelectKind : UML::Enumeration = modelicaTypesClass.subobjects()[UML::Enumeration] ->select(name = "ModelicaStateSelect")->any(true); property modelicaDefaultKind : UML::EnumerationLiteral = modelicaStateSelectKind.subobjects()[UML::EnumerationLiteral] ->select(name = "default")->any(true); property modelicaAlwaysKind : UML::EnumerationLiteral = modelicaStateSelectKind.subobjects()[UML::EnumerationLiteral] ->select(name = "always")->any(true); property modelicaNeverKind : UML::EnumerationLiteral = modelicaStateSelectKind.subobjects()[UML::EnumerationLiteral] ->select(name = "never")->any(true); property modelicaPreferKind : UML::EnumerationLiteral = modelicaStateSelectKind.subobjects()[UML::EnumerationLiteral] ->select(name = "prefer")->any(true); property modelicaAvoidKind : UML::EnumerationLiteral = modelicaStateSelectKind.subobjects()[UML::EnumerationLiteral] ->select(name = "avoid")->any(true); property modelicaScopeKind : UML::Enumeration = sysml4Modelica_profile.nestedPackage![name = "Types"].subobjects()[UML::Enumeration] ->select(name = "ModelicaScopeKind")->any(true); property modelicaInnerKind : UML::EnumerationLiteral = modelicaScopeKind.subobjects()[UML::EnumerationLiteral] ->select(name = "inner")->any(true); property modelicaOuterKind : UML::EnumerationLiteral = modelicaScopeKind.subobjects()[UML::EnumerationLiteral] ->select(name = "outer")->any(true); property modelicaCausalityKind : UML::Enumeration = sysml4Modelica_profile.nestedPackage![name = "Types"].subobjects()[UML::Enumeration] ->select(name = "ModelicaCausalityKind")->any(true); property modelicaInputKind : UML::EnumerationLiteral = modelicaCausalityKind.subobjects()[UML::EnumerationLiteral] ->select(name = "input")->any(true); property modelicaOutputKind : UML::EnumerationLiteral = modelicaCausalityKind.subobjects()[UML::EnumerationLiteral] ->select(name = "output")->any(true); property modelicaVariabilityKind : UML::Enumeration = sysml4Modelica_profile.nestedPackage![name = "Types"].subobjects()[UML::Enumeration] ->select(name = "ModelicaVariabilityKind")->any(true); property modelicaConstantKind : UML::EnumerationLiteral = modelicaVariabilityKind.subobjects()[UML::EnumerationLiteral] ->select(name = "constant")->any(true); property modelicaContinuousKind : UML::EnumerationLiteral = modelicaVariabilityKind.subobjects()[UML::EnumerationLiteral] ->select(name = "continuous")->any(true); property modelicaDiscreteKind : UML::EnumerationLiteral = modelicaVariabilityKind.subobjects()[UML::EnumerationLiteral] ->select(name = "discrete")->any(true); property modelicaParameterKind : UML::EnumerationLiteral = modelicaVariabilityKind.subobjects()[UML::EnumerationLiteral] ->select(name = "parameter")->any(true); property modelicaFlowFlagKind : UML::Enumeration = sysml4Modelica_profile.nestedPackage![name = "Types"].subobjects()[UML::Enumeration] ->select(name = "ModelicaFlowFlagKind")->any(true); property modelicaFlowKind : UML::EnumerationLiteral = modelicaFlowFlagKind.subobjects()[UML::EnumerationLiteral] ->select(name = "flow")->any(true); property modelicaStreamKind : UML::EnumerationLiteral = modelicaFlowFlagKind.subobjects()[UML::EnumerationLiteral] ->select(name = "stream")->any(true); // use Tuple property undefinedGeneralizations : Sequence(UML::Generalization)= Sequence{}; property generalizedClassNames : Sequence(String)= Sequence{}; main() { var model : UML::Package = sysmlModel.rootObjects()![UML::Package]; if(model.oclIsKindOf(UML::Model))then{ model := sysmlModel.rootObjects()![UML::Model].nestedPackage![UML::Package]; }endif; model.map toModelica(); log("Transformation SysML2ModelicaUnparsed finished"); } mapping UML::Package::toModelica() : Program::PROGRAM { self.packagedElement[UML::Classifier]->asOrderedSet()->sortedBy(qualifiedName) -> forEach (packagedElement){ packagedElement.map toModelicaSpecializedClass(result); }; } // *********************************** CLASS DEFINITION *********************************** // ****** Mapping Rule 16.1 ****** mapping UML::Classifier::toModelicaSpecializedClass (inout owningElement : OclAny) : Class::CLASS disjuncts UML::Class::toModelicaClass, // Mapping Rule 16.1.2 UML::Class::toModelicaModel, // Mapping Rule 16.1.3 UML::Class::toModelicaRecord, // Mapping Rule 16.1.4 UML::Class::toModelicaBlock, // Mapping Rule 16.1.5 UML::Class::toModelicaConnector, // Mapping Rule 16.1.6 UML::DataType::toModelicaType, // Mapping Rule 16.1.7 UML::Enumeration::toModelicaEnum, UML::Class::toModelicaPackage, // Mapping Rule 16.1.8 UML::FunctionBehavior::toModelicaFunction{} // Mapping Rule 16.1.9 // ****** Mapping Rule 16.2 ****** mapping UML::Class::toModelicaClass (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations, UML::Class::setModelicaAlgorithms, UML::Class::setModelicaConnections when{self.isStereotypeApplied(ModelicaClass_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_CLASS{}; } // ****** Mapping Rule 16.2 ****** mapping UML::Class::toModelicaModel (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations, UML::Class::setModelicaAlgorithms, UML::Class::setModelicaConnections when{self.isStereotypeApplied(ModelicaModel_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_MODEL{}; } // ****** Mapping Rule 16.2 ****** mapping UML::Class::toModelicaRecord (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations, UML::Class::setModelicaAlgorithms, UML::Class::setModelicaConnections when{self.isStereotypeApplied(ModelicaRecord_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_RECORD{}; } // ****** Mapping Rule 16.2 ****** mapping UML::Class::toModelicaBlock (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations, UML::Class::setModelicaAlgorithms, UML::Class::setModelicaConnections when{self.isStereotypeApplied(ModelicaBlock_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_BLOCK{}; } // ****** Mapping Rule 16.2 ****** mapping UML::Class::toModelicaConnector (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations, UML::Class::setModelicaAlgorithms, UML::Class::setModelicaConnections when{self.isStereotypeApplied(ModelicaConnector_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_CONNECTOR{}; } // ****** Mapping Rule 16.2 ****** mapping UML::DataType::toModelicaType (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations //UML::Class::setModelicaAlgorithms, //UML::Classifier::setModelicaConnections when{self.isStereotypeApplied(ModelicaType_stereotype)and(not self.oclIsKindOf(UML::Enumeration))} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_TYPE{}; } // ****** Mapping Rule 16.2 ****** mapping UML::Enumeration::toModelicaEnum (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Enumeration::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations //UML::Class::setModelicaAlgorithms, //UML::Classifier::setModelicaConnections when{self.isStereotypeApplied(ModelicaType_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_TYPE{}; } // ****** Mapping Rule 16.2 ****** mapping UML::Class::toModelicaPackage (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.2.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.2.3 UML::Classifier::setModelicaEquations, UML::Class::setModelicaAlgorithms, UML::Class::setModelicaConnections when{self.isStereotypeApplied(ModelicaPackage_stereotype);} // //restriction.oclIsKindOf(Restriction::R_CLASS) { //safeApplyStereotype(result, ModelicaClass_stereotype); // Mapping Rule 16.2.2 result.restriction := object Restriction::R_PACKAGE{}; } // ****** Mapping Rule 16.9 ****** mapping UML::FunctionBehavior ::toModelicaFunction (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 16.9.1 inherits UML::Classifier::setOwner merges UML::Classifier::toModelicaClassDefinition, // Mapping Rule 16.9.9 UML::Class::setModelicaAlgorithms when{self.isStereotypeApplied(ModelicaFunction_stereotype);} { //safeApplyStereotype(result, ModelicaFunction_stereotype); // Mapping Rule 16.9.2 result.restriction := object Restriction::R_FUNCTION{}; } // ****** Mapping Rule 16.1.10 ****** mapping UML::Classifier::toModelicaClassDefinition (inout owningElement2 : OclAny) : Class::CLASS { init{ if(not self.getStereotypeApplications()->isEmpty())then{ result.finalPrefix := self.getValue(self.getAppliedStereotypes() ->any(true), "isFinal").oclAsType(Boolean); // Mapping Rule 16.1.11 result.encapsulatedPrefix := self.getValue(self.getAppliedStereotypes() ->any(true), "isModelicaEncapsulated").oclAsType(Boolean); // Mapping Rule 16.1.12 result.partialPrefix := self.getValue(self.getAppliedStereotypes() ->any(true), "isPartial").oclAsType(Boolean); // Mapping Rule 16.1.13 }endif; if(self.name.equalsIgnoreCase("FirstOrder"))then{ log("stop"); }endif; if(self.oclIsTypeOf(UML::FunctionBehavior))then{ var functionBehavior : UML::FunctionBehavior = self.oclAsType(UML::FunctionBehavior); functionBehavior.ownedParameter->map toModelicaComponent(result); }else { if(self.oclIsTypeOf(UML::Class))then{ //self.oclAsType(UML::Class).ownedAttribute->map toModelicaComponent(result); // start commenting here -> self.oclAsType(UML::Class).ownedAttribute->forEach(attrib) { var attribElement : Element::ELEMENT = attrib.map toModelicaComponent(result); var newElementItem = object ElementItem::ELEMENTITEM{element := attribElement;}; var owningElementBodyClassPart : ClassPart::PUBLIC = result.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC]; owningElementBodyClassPart.contents += newElementItem; }; result.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents[ElementItem::ELEMENTITEM]->forEach(elementItem){ log(elementItem.element![Element::ELEMENT].specification![ElementSpec::COMPONENTS].components![ComponentItem::COMPONENTITEM].component![Component::COMPONENT].name); }; }else{ if(self.oclIsTypeOf(UML::Enumeration))then{ self.oclAsType(UML::Enumeration).ownedLiteral->map toModelicaEnumLiteral(result); }endif; }endif; }endif; } if(self.isStereotypeApplied(ModelicaType_stereotype))then{ if(not self.generalization.ownedComment->isEmpty())then{ self.generalization->map toGeneralization2(result); } else{ self.generalization->map toGeneralization(result); }endif; } else{ self.generalization->map toGeneralization(result); }endif; self.ownedMember[UML::Classifier]->asOrderedSet()->sortedBy(qualifiedName) -> forEach (ownedClassifier){ ownedClassifier.map toModelicaSpecializedClass(result); }; self.ownedComment[body.startsWith("import ")]->forEach(comment){ comment.map toModelicaPackageImport(result); } } mapping UML::Comment ::toModelicaPackageImport (inout class_ : Class::CLASS) : ElementSpec::IMPORT { var body = class_.body![ClassDef::PARTS]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::PARTS{}; class_.body := newBody; } endif; var classParts = class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC]; if(classParts = null) then{ var newClassParts : ClassPart::PUBLIC = object ClassPart::PUBLIC{}; class_.body![ClassDef::PARTS].classParts += newClassParts; } endif; var elementItem = class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents![ElementItem::ELEMENTITEM]; if(elementItem = null) then{ var newElementItem : ElementItem::ELEMENTITEM = object ElementItem::ELEMENTITEM{}; class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents += newElementItem; } endif; var namedImportObject : Import::NAMED_IMPORT = object Import::NAMED_IMPORT{name:= self.body}; result.import_:= namedImportObject; var element = class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents![ElementItem::ELEMENTITEM].element![Element::ELEMENT]; if(element = null) then{ element := object Element::ELEMENT{}; class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents![ElementItem::ELEMENTITEM].element := element; } endif; element.specification := result; } mapping UML::Comment ::toModelicaAnnotation (inout class_ : Class::CLASS) : ElementArg::MODIFICATION when{(self.isStereotypeApplied(ModelicaAnnotation_stereotype)) and (self.body <> null)} { var commentString = self.body; var body = class_.body![ClassDef::PARTS]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::PARTS{}; class_.body := newBody; } endif; var classParts = class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC]; if(classParts = null) then{ var newClassParts : ClassPart::PUBLIC = object ClassPart::PUBLIC{}; class_.body![ClassDef::PARTS].classParts += newClassParts; } endif; var annotationItem = class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents![ElementItem::ANNOTATIONITEM]; if(annotationItem = null) then{ var newAnnotationItem : ElementItem::ANNOTATIONITEM = object ElementItem::ANNOTATIONITEM{}; class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents += newAnnotationItem; } endif; var annotation = class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents![ElementItem::ANNOTATIONITEM].annotation_![Annotation::ANNOTATION]; if(annotation = null) then{ annotation := object Annotation::ANNOTATION{}; class_.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents![ElementItem::ANNOTATIONITEM].annotation_ := annotation; //annotationItem.annotation_ := newAnnotation; } endif; result.unparsedElementArg := commentString; annotation.elementArgs += result; } mapping UML::Classifier::setOwner(inout owningElement2 : OclAny) : Class::CLASS { if(owningElement2.oclIsKindOf(Class::CLASS))then{ var owningElement : Class::CLASS = owningElement2.oclAsType(Class::CLASS); var body = owningElement.body![ClassDef::PARTS]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::PARTS{}; owningElement.body := newBody; } endif; var classParts = owningElement.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC]; if(classParts = null) then{ var newClassParts : ClassPart::PUBLIC = object ClassPart::PUBLIC{}; owningElement.body![ClassDef::PARTS].classParts += newClassParts; } endif; var newSpecification = object ElementSpec::CLASSDEF{class_ := result}; var newElement = object Element::ELEMENT{specification := newSpecification}; var newElementItem = object ElementItem::ELEMENTITEM{element := newElement;}; owningElement.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents += newElementItem; result.name := self.name; } endif; if(owningElement2.oclIsKindOf(Program::PROGRAM))then{ var owningElement : Program::PROGRAM = owningElement2.oclAsType(Program::PROGRAM); owningElement.classes += result; result.name := self.name; }endif; } mapping UML::Enumeration::setOwner(inout owningElement2 : OclAny) : Class::CLASS { if(owningElement2.oclIsKindOf(Class::CLASS))then{ var owningElement : Class::CLASS = owningElement2.oclAsType(Class::CLASS); var body = result.body![ClassDef::ENUMERATION]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::ENUMERATION{}; result.body := newBody; } endif; var enumLiterals : EnumDef::ENUMLITERALS = body.enumLiterals![EnumDef::ENUMLITERALS]; if(enumLiterals = null)then{ var newEnumLiterals = object EnumDef::ENUMLITERALS{}; result.body![ClassDef::ENUMERATION].enumLiterals := newEnumLiterals; } endif; var newSpecification = object ElementSpec::CLASSDEF{class_ := result}; var newElement = object Element::ELEMENT{specification := newSpecification}; var newElementItem = object ElementItem::ELEMENTITEM{element := newElement;}; owningElement.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC].contents += newElementItem; result.name := self.name; }endif; } // ******************************** COMPONENT DECLARATIONS ******************************** // ****** Mapping Rule 18.1 ****** mapping UML::TypedElement ::toModelicaComponent (inout class_ : Class::CLASS) : Element::ELEMENT disjuncts UML::Property::toModelicaPart , // Mapping Rule 18.1.1 UML::Port::toModelicaPort, // Mapping Rule 18.1.2 UML::Property::toModelicaValueProperty, // Mapping Rule 18.1.3 UML::Parameter::toModelicaFunctionParameter{}; // Mapping Rule 18.1.4 // ****** Mapping Rule 18.2 ****** mapping UML::Property::toModelicaPart // Mapping Rule 18.2.1 (inout owningElement : Class::CLASS) : Element::ELEMENT inherits UML::TypedElement::setModelicaComponentTypeAndName // Mapping Rule 18.2.6 merges UML::TypedElement::setModelicaComponentCommonValues, // Mapping Rule 18.2.9 // Mapping Rule 18.2.10 // Mapping Rule 18.2.11 // Mapping Rule 18.2.12 UML::TypedElement::setModelicaComponentScopeValue, // Mapping Rule 18.2.7 UML::TypedElement :: setModelicaComponentConditionalExpressionValue // Mapping Rule 18.2.8 when{self.isStereotypeApplied(ModelicaPart_stereotype);} { } // ****** Mapping Rule 18.3 ****** mapping UML::Port ::toModelicaPort // Mapping Rule 18.3.1 (inout owningElement : Class::CLASS) : Element::ELEMENT inherits UML::TypedElement::setModelicaComponentTypeAndName // Mapping Rule 18.3.6 merges UML::TypedElement ::setModelicaComponentCommonValues, // Mapping Rule 18.3.9 // Mapping Rule 18.3.10 // Mapping Rule 18.3.11 // Mapping Rule 18.3.12 UML::TypedElement ::setModelicaComponentConditionalExpressionValue, // Mapping Rule 18.3.8 UML::TypedElement ::setModelicaComponentCausalityValue // Mapping Rule 18.3.7 when{self.isStereotypeApplied(ModelicaPort_stereotype)} // Mapping Rule 18.3.3 // java.lang.NullPointerException { } // ****** Mapping Rule 18.4 ****** mapping UML::Property::toModelicaValueProperty // Mapping Rule 18.4.1 (inout owningElement : Class::CLASS) : Element::ELEMENT inherits UML::TypedElement::setModelicaComponentTypeAndName // Mapping Rule 18.4.7 merges UML::TypedElement ::setModelicaComponentCommonValues, // Mapping Rule 18.4.14 // Mapping Rule 18.4.15 // Mapping Rule 18.4.17 // Mapping Rule 18.4.18 UML::TypedElement:: setModelicaComponentDeclarationEquationValue, // Mapping Rule 18.4.16 UML::TypedElement ::setModelicaComponentCausalityValue, // Mapping Rule 18.4.9 UML::TypedElement ::setModelicaComponentVariabilityValue, // Mapping Rule 18.4.10 UML::TypedElement // Mapping Rule 18.4.13 ::setModelicaComponentConditionalExpressionValue, UML::TypedElement ::setModelicaComponentScopeValue, // Mapping Rule 18.4.12 UML::TypedElement ::setModelicaComponentFlowFlagValue // Mapping Rule 18.4.11 when{self.isStereotypeApplied(ModelicaValueProperty_stereotype)} // Mapping Rule 18.4.3 // java.lang.NullPointerException { } // ****** Mapping Rule 18.5 ****** mapping UML::Parameter::toModelicaFunctionParameter // Mapping Rule 18.5.1 (inout owningElement : Class::CLASS) : Element::ELEMENT inherits UML::TypedElement::setModelicaComponentTypeAndName // Mapping Rule 18.5.8 merges UML::TypedElement ::setModelicaComponentCommonValues, // Mapping Rule 18.4.11 // Mapping Rule 18.5.12 // Mapping Rule 18.5.13 // Mapping Rule 18.4.15 UML::TypedElement:: setModelicaComponentDeclarationEquationValue, // Mapping Rule 18.5.14 UML::TypedElement ::setModelicaComponentCausalityValue, // Mapping Rule 18.5.9 UML::TypedElement ::setModelicaComponentVariabilityValue // Mapping Rule 18.5.10 when{self.isStereotypeApplied(ModelicaFunctionParameter_stereotype);} // Mapping Rule 18.5.4 { } mapping UML::EnumerationLiteral::toModelicaEnumLiteral (inout owningElement : Class::CLASS) : EnumLiteral::ENUMLITERAL { var enumerationBody : ClassDef::ENUMERATION = owningElement.body![ClassDef::ENUMERATION]; enumerationBody.enumLiterals![EnumDef::ENUMLITERALS].enumLiterals += result; result._literal := self.name; } mapping UML::TypedElement ::setModelicaComponentCommonValues (inout owningElement : Class::CLASS) : Element::ELEMENT { // modifications var modifications : Collection(String) = OrderedSet{}; var element : UML::Element = self.oclAsType(UML::Element); if(self.getAppliedStereotypes() [name = "ModelicaValueProperty" or name = "ModelicaFunctionParameter" or name = "ModelicaPart" or name = "ModelicaPort"] ->any(true) != null)then{ element.collectStereotypeStringValues(modifications, self.getAppliedStereotypes() [name = "ModelicaValueProperty" or name = "ModelicaFunctionParameter" or name = "ModelicaPart" or name = "ModelicaPort"] ->any(true), "modification"); var spec : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(spec = null)then{ spec := object ElementSpec::COMPONENTS{}; result.specification := spec; }endif; var componentItem : ComponentItem::COMPONENTITEM = spec.components![ComponentItem::COMPONENTITEM]; if(componentItem = null)then{ componentItem := object ComponentItem::COMPONENTITEM{}; spec.components := componentItem; }endif; var component : Component::COMPONENT = componentItem.component![Component::COMPONENT]; if(component = null)then{ component := object Component::COMPONENT{}; componentItem.component := component; }endif; var modification : Modifications::CLASSMOD = component.modification![Modifications::CLASSMOD]; if(modification = null)then{ modification := object Modifications::CLASSMOD{}; component.modification := modification; }endif; modifications->forEach(mod){ var modString : String = mod.oclAsType(String); var newMODIFICATION : ElementArg::MODIFICATION = object ElementArg::MODIFICATION{}; newMODIFICATION.unparsedElementArg := modString; modification.elementArgLst += newMODIFICATION; }; }endif; // isReplaceable var isReplaceable : Boolean = self.getValue(self.getAppliedStereotypes() ->any(true) , "isReplaceable").oclAsType(Boolean); if(isReplaceable)then{ result.redeclareKeywords := object RedeclareKeywords::REPLACEABLE{}; }endif; // annotation self.ownedComment-> forEach (comment){ //log(self.getAppliedStereotypes()->any(true).repr()); if(comment.getAppliedStereotypes() [name = "ModelicaAnnotation"] ->any(true) != null)then{ var commentString = comment.body; var spec : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(spec = null)then{ spec := object ElementSpec::COMPONENTS{}; result.specification := spec; }endif; var componentItem : ComponentItem::COMPONENTITEM = spec.components![ComponentItem::COMPONENTITEM]; if(componentItem = null)then{ componentItem := object ComponentItem::COMPONENTITEM{}; spec.components := componentItem; }endif; var mod : ElementArg::MODIFICATION = object ElementArg::MODIFICATION{unparsedElementArg := commentString}; var annotation : Annotation::ANNOTATION = object Annotation::ANNOTATION{elementArgs += mod}; componentItem.comment := object Comment::COMMENT{annotation_ := annotation}; }endif; }; } mapping UML::TypedElement ::setModelicaComponentDeclarationEquationValue (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ var declarationEquation : String = self.getValue(self.getAppliedStereotypes() [name = "ModelicaValueProperty" or name = "ModelicaFunctionParameter"] ->any(true) , "declarationEquation").oclAsType(String); var spec : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(spec = null)then{ spec := object ElementSpec::COMPONENTS{}; result.specification := spec; }endif; var componentItem : ComponentItem::COMPONENTITEM = spec.components![ComponentItem::COMPONENTITEM]; if(componentItem = null)then{ componentItem := object ComponentItem::COMPONENTITEM{}; spec.components := componentItem; }endif; var component : Component::COMPONENT = componentItem.component![Component::COMPONENT]; if(component = null)then{ component := object Component::COMPONENT{}; componentItem.component := component; }endif; var modification : Modifications::CLASSMOD = component.modification![Modifications::CLASSMOD]; if(modification = null)then{ modification := object Modifications::CLASSMOD{}; component.modification := modification; }endif; var expression : Exp::uExp = modification.expOption; if(expression = null)then{ expression := object Exp::uExp{}; modification.expOption := expression; }endif; expression.unparsedExp := declarationEquation; } } mapping UML::TypedElement ::setModelicaComponentScopeValue (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ var scope : UML::EnumerationLiteral = self.getValue(self.getAppliedStereotypes() ->any(true), "scope").oclAsType(UML::EnumerationLiteral); if(scope = modelicaInnerKind)then{ result.innerOuter := object InnerOuter::INNER{}; }endif; if(scope = modelicaOuterKind)then{ result.innerOuter := object InnerOuter::OUTER{}; }endif; } } mapping UML::TypedElement ::setModelicaComponentConditionalExpressionValue (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ var expression : String = self.getValue(self.getAppliedStereotypes() ->any(true), "conditionalExpression").oclAsType(String); var spec : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(spec = null)then{ spec := object ElementSpec::COMPONENTS{}; result.specification := spec; }endif; var componentItem : ComponentItem::COMPONENTITEM = spec.components![ComponentItem::COMPONENTITEM]; if(componentItem = null)then{ componentItem := object ComponentItem::COMPONENTITEM{}; spec.components := componentItem; }endif; var exp : Exp::uExp = componentItem.condition; if(exp = null)then{ exp := object Exp::uExp{}; componentItem.condition := exp; }endif; exp.unparsedExp := expression; } } mapping UML::TypedElement ::setModelicaComponentCausalityValue (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ var direction : UML::EnumerationLiteral = self.getValue(self.getAppliedStereotypes() ->any(true), "causality").oclAsType(UML::EnumerationLiteral); var components : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(components = null)then{ components := object ElementSpec::COMPONENTS{}; result.specification := components; }endif; var attr : ElementAttributes::ATTR = components.attributes![ElementAttributes::ATTR]; if(attr = null)then{ attr := object ElementAttributes::ATTR{}; components.attributes := attr; }endif; if(direction = modelicaInputKind) then{ attr.direction := object Direction::INPUT{}; }endif; if(direction = modelicaOutputKind) then{ attr.direction := object Direction::OUTPUT{}; }endif; } } mapping UML::TypedElement ::setModelicaComponentVariabilityValue (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ var variability : UML::EnumerationLiteral = self.getValue(self.getAppliedStereotypes() ->any(true), "variability").oclAsType(UML::EnumerationLiteral); var components : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(components = null)then{ components := object ElementSpec::COMPONENTS{}; result.specification := components; }endif; var attr : ElementAttributes::ATTR = components.attributes![ElementAttributes::ATTR]; if(attr = null)then{ attr := object ElementAttributes::ATTR{}; components.attributes := attr; }endif; if(variability = modelicaConstantKind) then{ attr.variability := object Variability::CONST{}; }endif; if(variability = modelicaContinuousKind) then{ attr.variability := object Variability::VAR{}; }endif; if(variability = modelicaDiscreteKind) then{ attr.variability := object Variability::DISCRETE{}; }endif; if(variability = modelicaParameterKind) then{ attr.variability := object Variability::PARAM{}; }endif; } } mapping UML::TypedElement ::setModelicaComponentFlowFlagValue (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ var flowFlag : EnumerationLiteral = self.getValue(self.getAppliedStereotypes() ->any(true), "flowFlag").oclAsType(UML::EnumerationLiteral); var components : ElementSpec::COMPONENTS = result.specification![ElementSpec::COMPONENTS]; if(components = null)then{ components := object ElementSpec::COMPONENTS{}; result.specification := components; }endif; var attr : ElementAttributes::ATTR = components.attributes![ElementAttributes::ATTR]; if(attr = null)then{ attr := object ElementAttributes::ATTR{}; components.attributes := attr; }endif; attr.flowPrefix := false; attr.streamPrefix := false; if(flowFlag = modelicaFlowKind) then{ attr.flowPrefix := true; }else{ if(flowFlag = modelicaStreamKind)then{ attr.streamPrefix := true; }endif; }endif; //attr.flowPrefix := isFlow; } } mapping UML::TypedElement::setModelicaComponentTypeAndName (inout owningElement : Class::CLASS) : Element::ELEMENT { init{ //result.type := getSysML$PropertyType(getModelicaComponentTypeName(self)); if (null = owningElement.body) then { owningElement.body := object ClassDef::PARTS{ classParts := OrderedSet{}; }; } endif; assert fatal (owningElement.body.oclIsKindOf(ClassDef::PARTS)); var owningElementBody := owningElement.body![ClassDef::PARTS]; if (owningElementBody.classParts[ClassPart::PUBLIC]->isEmpty()) then owningElementBody.classParts += object ClassPart::PUBLIC{} endif; var owningElementBodyClassPartPUBLIC := owningElementBody.classParts![ClassPart::PUBLIC]; // set component type var componentTypeName = self.type.name; if(componentTypeName = "ModelicaReal")then { componentTypeName := "Real"; }else{ if(componentTypeName = "ModelicaReal") then { componentTypeName := "Real"; } else{ if(componentTypeName = "ModelicaInteger")then { componentTypeName := "Integer"; } else{ if(componentTypeName = "ModelicaBoolean") then { componentTypeName := "Boolean"; } else{ if(componentTypeName = "ModelicaString")then { componentTypeName := "String"; } else{ if(componentTypeName = "ModelicaStateSelect")then { componentTypeName := "StateSelect"; } else{ componentTypeName := self.type.qualifiedName; var modelName : String = componentTypeName.substringBefore("::"); componentTypeName := componentTypeName.replace(modelName + "::", ""); componentTypeName := componentTypeName.replace("::", "."); }endif; }endif; }endif; }endif; }endif; }endif; var newIdent = object Path::IDENT{name := componentTypeName}; var newTPath = object TypeSpec::TPATH{path := newIdent}; // set component name var newComponent = object Component::COMPONENT{name := self.name}; var newComponentItem = object ComponentItem::COMPONENTITEM{component := newComponent}; //var newComponents : ElementSpec::COMPONENTS = object ElementSpec::COMPONENTS{components += newComponentItem; typeSpec := newTPath}; var newComponents : ElementSpec::COMPONENTS = object ElementSpec::COMPONENTS{components := OrderedSet{newComponentItem}; typeSpec := newTPath}; result.specification := newComponents; } } // ****** Mapping Rule 16.10 ****** mapping UML::Generalization ::toGeneralization (inout owningElement : Class::CLASS) : ElementSpec::EXTENDS // Mapping Rule 16.10.1 { if(self.isStereotypeApplied(ModelicaExtends_stereotype))then{ var body = owningElement.body![ClassDef::PARTS]; if(body = null) then{ body := object ClassDef::PARTS{}; owningElement.body := body; }endif; var classParts : ClassPart::PUBLIC = owningElement.body![ClassDef::PARTS].classParts![ClassPart::PUBLIC]; if(classParts = null)then{ classParts := object ClassPart::PUBLIC{}; owningElement.body![ClassDef::PARTS].classParts += classParts; }endif; var pathName : String = self.general.qualifiedName; var modelName : String = pathName.substringBefore("::"); pathName := pathName.replace(modelName + "::", ""); pathName := pathName.replace("::", "."); if(matchRegex(pathName, "ModelicaReal"))then{ pathName := "Real"; }endif; if(matchRegex(pathName, "ModelicaInteger"))then{ pathName := "Integer"; }endif; if(matchRegex(pathName, "ModelicaBoolean"))then{ pathName := "Boolean"; }endif; if(matchRegex(pathName, "ModelicaString"))then{ pathName := "String"; }endif; if(matchRegex(pathName, "ModelicaStateSelect"))then{ pathName := "StateSelect"; }endif; var ident : Path::IDENT = object Path::IDENT{name:= pathName}; result.path := ident; var newElement : Element::ELEMENT = object Element::ELEMENT{specification:= result}; var elementItem : ElementItem::ELEMENTITEM = object ElementItem::ELEMENTITEM{element:= newElement}; classParts.contents += elementItem; // modifications // Mapping Rule 16.10.4 var modifications : Collection(String) = OrderedSet{}; var element : UML::Element = self.oclAsType(UML::Element); element.collectStereotypeStringValues(modifications, self.getAppliedStereotypes() [name = "ModelicaExtends"] ->any(true), "modification"); modifications->forEach(mod){ var modString : String = mod.oclAsType(String); var newMODIFICATION : ElementArg::MODIFICATION = object ElementArg::MODIFICATION{}; newMODIFICATION.unparsedElementArg := modString; result.elementArg += newMODIFICATION; }; // Mapping Rule 16.10.5: visibility attribute - to be implemented // Mapping Rule 16.10.6: arraysize attribute - to be implemented }endif; } mapping UML::Generalization ::toGeneralization2 (inout owningElement : Class::CLASS) : ClassDef::DERIVED // Mapping Rule 16.10.1 { if(self.isStereotypeApplied(ModelicaExtends_stereotype))then{ owningElement.body := result; var pathName : String = self.general.qualifiedName; var modelName : String = pathName.substringBefore("::"); pathName := pathName.replace(modelName + "::", ""); pathName := pathName.replace("::", "."); if(matchRegex(pathName, "ModelicaReal"))then{ pathName := "Real"; }endif; if(matchRegex(pathName, "ModelicaInteger"))then{ pathName := "Integer"; }endif; if(matchRegex(pathName, "ModelicaBoolean"))then{ pathName := "Boolean"; }endif; if(matchRegex(pathName, "ModelicaString"))then{ pathName := "String"; }endif; if(matchRegex(pathName, "ModelicaStateSelect"))then{ pathName := "StateSelect"; }endif; //var ident : Path::IDENT := object Path::IDENT{name:= self.general.name}; var ident : Path::IDENT = object Path::IDENT{name:= pathName}; var typeSpec : TypeSpec::TPATH = object TypeSpec::TPATH{path:= ident}; result.typeSpec := typeSpec; // modifications // Mapping Rule 16.10.4 var modifications : Collection(String) = OrderedSet{}; var element : UML::Element = self.oclAsType(UML::Element); element.collectStereotypeStringValues(modifications, self.getAppliedStereotypes() [name = "ModelicaExtends"] ->any(true), "modification"); modifications->forEach(mod){ //log("Modification found for: " + self.oclAsType(UML::NamedElement).name); var modString : String = mod.oclAsType(String); //log(modString); var newMODIFICATION : ElementArg::MODIFICATION = object ElementArg::MODIFICATION{}; newMODIFICATION.unparsedElementArg := modString; result.arguments += newMODIFICATION; }; // arraySize var arraySize : Collection(String) = OrderedSet{}; element.collectStereotypeStringValues(arraySize, self.getAppliedStereotypes() [name = "ModelicaExtends"] ->any(true), "arraySize"); arraySize->forEach(arraySizeItem){ var arraySizeItemString : String = arraySizeItem.oclAsType(String); var newExp : Exp::uExp = object Exp::uExp{unparsedExp := arraySizeItemString}; var newSubscript : Subscript::SUBSCRIPT = object Subscript::SUBSCRIPT{subScript:= newExp}; var newArrayDim : ArrayDim::ArrayDim = object ArrayDim::ArrayDim{subscripts += newSubscript}; typeSpec.arrayDim := newArrayDim; }; }endif; } // **************************** EQUATION AND ALGORITHM SECTION **************************** mapping UML::Classifier::setModelicaEquations // Mapping Rule 19.2.1 (inout owningElement : Class::CLASS) : Class::CLASS { // mapping to constraints self.ownedRule->forEach( rule ){ if(rule.isStereotypeApplied(ModelicaEquation_stereotype))then{ var isInitial : Boolean = rule.getValue(ModelicaEquation_stereotype, "isInitial").oclAsType(Boolean); rule->map toModelicaEquation(result, isInitial); }endif; }; } mapping UML::Constraint::toModelicaEquation (inout owningElement : Class::CLASS, in isInitial : Boolean) : Equation::uEquation { var opaqueExpression : UML::OpaqueExpression = self.specification.oclAsType(UML::OpaqueExpression); var equationString : String = opaqueExpression.body->any(true); result.unparsedEquation := equationString; var body = owningElement.body![ClassDef::PARTS]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::PARTS{}; owningElement.body := newBody; }endif; var equationItem = object EquationItem::EQUATIONITEM{equation_ := result;}; if(isInitial)then{ var newClassParts : ClassPart::INITIALEQUATIONS = object ClassPart::INITIALEQUATIONS{contents += equationItem}; owningElement.body![ClassDef::PARTS].classParts += newClassParts; } else{ var newClassParts : ClassPart::EQUATIONS = object ClassPart::EQUATIONS{contents += equationItem}; owningElement.body![ClassDef::PARTS].classParts += newClassParts; }endif; } // ****** Mapping Rule 19.4 ****** mapping UML::Class::setModelicaConnections (inout owningElement : Class::CLASS) : Class::CLASS // Mapping Rule 19.4.1 { self.ownedConnector->forEach( connector ){ if(connector.isStereotypeApplied(ModelicaConnection_stereotype))then{ connector->map toModelicaConnection(result); }endif; }; } mapping UML::Connector::toModelicaConnection (inout owningElement : Class::CLASS) : Equation::EQ_CONNECT { var connectorEnd1 : UML::ConnectorEnd = self._end->at(1); var connectorEnd2 : UML::ConnectorEnd = self._end->at(2); var part1 = connectorEnd1.partWithPort; var part2 = connectorEnd2.partWithPort; var port1 = connectorEnd1.role; var port2 = connectorEnd2.role; var string1 = part1.name + "." + port1.name; var string2 = part1.name + "." + port1.name; //result.unparsedEquation := "connect (" + string1 + " , " + string2 + ")"; result.unparsedEquation := self.name; var body = owningElement.body![ClassDef::PARTS]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::PARTS{}; owningElement.body := newBody; }endif; var equations = owningElement.body![ClassDef::PARTS].classParts[ClassPart::EQUATIONS]; if(equations = null) then{ var newEquations : ClassPart::EQUATIONS = object ClassPart::EQUATIONS{}; owningElement.body![ClassDef::PARTS].classParts := newEquations; }endif; var equationItem = object EquationItem::EQUATIONITEM{equation_ := result;}; var newClassParts : ClassPart::EQUATIONS = object ClassPart::EQUATIONS{contents += equationItem}; owningElement.body![ClassDef::PARTS].classParts += newClassParts; } // ****** Mapping Rule 19.3 ****** mapping UML::Class::setModelicaAlgorithms // Mapping Rule 19.3.1 (inout owningElement : Class::CLASS) : Class::CLASS { self.ownedBehavior->forEach( behavior ){ if(behavior.isStereotypeApplied(ModelicaAlgorithm_stereotype))then{ var isInitial : Boolean = behavior.getValue(ModelicaAlgorithm_stereotype, "isInitial").oclAsType(Boolean); behavior.oclAsType(UML::OpaqueBehavior)-> map toModelicaAlgorithm(result, isInitial); }endif; }; } mapping UML::OpaqueBehavior::toModelicaAlgorithm (inout owningElement : Class::CLASS, in isInitial : Boolean) : AlgorithmItem::uAlgorithmItem { result.unparsedAlgorithmItem := self.body->any(true); var body = owningElement.body![ClassDef::PARTS]; if(body = null) then{ var newBody :ClassDef::uClassDef = object ClassDef::PARTS{}; owningElement.body := newBody; }endif; if(isInitial)then{ var newClassParts : ClassPart::INITIALALGORITHMS = object ClassPart::INITIALALGORITHMS{contents += result}; owningElement.body![ClassDef::PARTS].classParts += newClassParts; } else{ var newClassParts : ClassPart::ALGORITHMS = object ClassPart::ALGORITHMS{contents += result}; owningElement.body![ClassDef::PARTS].classParts += newClassParts; }endif; } // ****** Mapping Rule 16.11 ****** : ModelicaDer - to be implemented // ****** Mapping Rule 16.12 ****** : ConstrainedBy - to be implemented