| /** |
| * Copyright (c) 2014 CEA LIST. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * CEA LIST - Initial API and implementation |
| */ |
| import UmlUtilities; |
| |
| modeltype DC uses "http://www.omg.org/spec/DD/20110901/DC"; |
| modeltype DG uses "http://www.omg.org/spec/DD/20110901/DG"; |
| modeltype DI uses "http://www.omg.org/spec/DD/20110901/DI"; |
| modeltype UMLDI uses "http://www.omg.org/spec/UML/20131001/UMLDI"; |
| modeltype UML uses "http://www.eclipse.org/uml2/4.0.0/UML"; |
| |
| library UmlCompartments; |
| |
| mapping UML::Activity::compartmentToGraphicalElement(compartment : UMLDI::UmlCompartment) : DG::GraphicalElement { |
| init { |
| if not compartment.owningUmlDiagramElement.oclAsType(UMLDI::ClassifierShape).useClassifierNotation and |
| (compartment.oclIsKindOf(UMLDI::ActivityNodeCompartment) or compartment.oclIsKindOf(UMLDI::OwnedBehaviorCompartment)) then |
| result := object DG::Group {} |
| else |
| result := self.map compartmentToDefault(compartment) |
| endif; |
| } |
| } |
| |
| mapping UML::Element::compartmentToGraphicalElement(compartment : UMLDI::UmlCompartment) : DG::GraphicalElement { |
| init { |
| if compartment.oclIsKindOf(TemplateParameterCompartment) then |
| result := self.map templateParameterCompartmentToGraphicalElement(compartment.oclAsType(TemplateParameterCompartment)) |
| else if compartment.oclIsKindOf(RegionCompartment) then |
| result := self.map regionCompartmentToGraphicalElement(compartment.oclAsType(RegionCompartment)) |
| else if compartment.oclIsKindOf(SubpartitionCompartment) then |
| result := self.map subpartitionCompartmentToGraphicalElement(compartment.oclAsType(SubpartitionCompartment)) |
| else if compartment.oclIsKindOf(StereotypeCompartment) then |
| result := self.map stereotypeCompartmentToGraphicalElement(compartment.oclAsType(StereotypeCompartment)) |
| else |
| result := self.map compartmentToDefault(compartment) |
| endif endif endif endif; |
| } |
| } |
| |
| mapping UML::Element::compartmentToDefault(compartment : UMLDI::UmlCompartment) : DG::GraphicalElement { |
| init { |
| if self.hasNoSeparator(compartment) then |
| result := object DG::Group {} |
| else |
| result := compartmentSeparator(compartment) |
| endif; |
| } |
| } |
| |
| mapping UML::Element::templateParameterCompartmentToGraphicalElement(compartment : UMLDI::TemplateParameterCompartment) : DG::GraphicalElement { |
| init { |
| result := object DG::Rectangle { |
| bounds := compartment.bounds.clone().oclAsType(DC::Bounds); |
| _class := "dashed"; |
| } |
| } |
| } |
| |
| mapping UML::Element::regionCompartmentToGraphicalElement(compartment : UMLDI::RegionCompartment) : DG::GraphicalElement { |
| init { |
| result := if compartment.topUmlDiagramElement->size() > 1 then |
| compartmentSeparator(compartment) |
| else |
| object DG::Group {} |
| endif; |
| } |
| } |
| |
| mapping UML::Element::subpartitionCompartmentToGraphicalElement(compartment : UMLDI::SubpartitionCompartment) : DG::GraphicalElement { |
| init { |
| result := if compartment.owningUmlDiagramElement.umlModelElement.oclAsType(UML::ActivityPartition).isDimension then |
| object DG::Group {} |
| else if compartment.owningUmlDiagramElement.oclAsType(UMLDI::ActivityPartitionShape).isVertical then |
| compartmentSeparator(compartment) |
| else |
| compartmentSeparatorVertical(compartment) |
| endif endif; |
| } |
| } |
| |
| mapping UML::Element::stereotypeCompartmentToGraphicalElement(compartment : UMLDI::StereotypeCompartment) : DG::GraphicalElement { |
| init { |
| var stereotype := self.oclAsType(UML::Stereotype); |
| result := object DG::Group { |
| member += compartmentSeparator(compartment); |
| member += object DG::Text { |
| data := replace('', stereotype.name, '«<n>»'); |
| anchor := DG::TextAnchor::middle; |
| bounds := compartment.bounds; |
| }; |
| }; |
| } |
| } |
| |
| |
| query UML::Element::hasNoSeparator(compartment : UMLDI::UmlCompartment) : Boolean { |
| return compartment.oclIsKindOf(UMLDI::SubvertexCompartment) or |
| compartment.oclIsKindOf(UMLDI::ParameterCompartment) or |
| compartment.oclIsKindOf(UMLDI::PreConditionCompartment) or |
| compartment.oclIsKindOf(UMLDI::PostConditionCompartment) or |
| compartment.oclIsKindOf(UMLDI::ActivityNodeCompartment) or |
| compartment.oclIsKindOf(UMLDI::SubfragmentCompartment); |
| } |
| |
| helper compartmentSeparator(compartment : UMLDI::UmlCompartment) : DG::GraphicalElement { |
| var b := compartment.bounds; |
| return object DG::Line { |
| start := object DC::Point { x := b.x; y := b.y; }; |
| _end := object DC::Point { x := b.x + b.width; y := b.y; }; |
| } |
| } |
| |
| helper compartmentSeparatorVertical(compartment : UMLDI::UmlCompartment) : DG::GraphicalElement { |
| var b := compartment.bounds; |
| return object DG::Line { |
| start := object DC::Point { x := b.x; y := b.y; }; |
| _end := object DC::Point { x := b.x; y := b.y + b.height; }; |
| } |
| } |
| |