--Author Manel Fredj-CEA LIST
library HelpersEdge;
import GeneralMappingsandHelpers;
import StateDiagVisualIDs;
modeltype di2 uses 'http://www.papyrusuml.org/di2';
modeltype notation uses 'http://www.eclipse.org/gmf/runtime/1.0.2/notation';
modeltype uml uses 'http://www.eclipse.org/uml2/2.1.0/UML';
mapping di2::GraphEdge::stateDiagEdge2Edge() : notation::Connector inherits di2::GraphEdge::edge2Connector
{
-----------------------------------------------------------------------
--under an Edge "association"
-----------------------------------------------------------------------
--In the case that we have an association we will have:
--1 edge with a xmi:type:="notation:Connector", a geneerated Id, type= "4001", a target and a source that includes:
-- 6 "children" typed with decoration nodes
-- 1 "styles
-- 1 element
-- 1 bendpoints
--1 sourceAnchor
--1targetAnchor
-----------------------------------------------------------------------
--setting the type and children
if (self.getElement() != null) then {
if (self.getElement().oclIsTypeOf(uml::Transition)) then {
type := VisualId_Edge_Transition;
--adding children
children := setChildrenForTransition();
} endif;
}
else {
--type := VisualId_Edge_Link;
--adding children
} endif;
--setting the source and target Anchors
var anchors : OrderedSet (di2::GraphConnector) := self.anchor;
anchors->forEach (gc) {
--log("the anchor is "+ gc.graphElement.repr());
gc.graphElement;
};
source := anchors->first().graphElement.oclAsType(di2::GraphNode).late resolveone(notation::Shape);
target := anchors->last().graphElement.oclAsType(di2::GraphNode).late resolveone(notation::Shape);
--adding style
styles := setStyleForEdge();
--adding element: already done in View
--adding the bend points
bendpoints := setBendpointsForEdge();
--adding the source and target Anchor
sourceAnchor := setSourceAnchor();
targetAnchor := setTargetAnchor();
}
--Helpers related to an Edge
--------------------------------
--generic helper for an edge with two children
--takes as input the visual ids of the the two children
helper setChildrenForEdge2Children(in VisualId1: String, in VisualId2: String): OrderedSet(notation::Node)
{
var child1 := object notation::DecorationNode {
--the id is set automatically
type := VisualId1;
layoutConstraint := object notation::Location {
y := 40;
};
};
--second child
var child2 :=object notation::DecorationNode {
--the id is set automatically
type := VisualId2;
layoutConstraint := object notation::Location {
y := 60;
};
};
return OrderedSet {child1,child2};
}
helper setChildrenForTransition(): OrderedSet(notation::Node)
{
--
--
--
var child1 := object notation::DecorationNode {
--the id is set automatically
--type := VisualId_DecoNodeGeneralization;
type := VisualId_Edge_Transition_DecoNode1;
layoutConstraint := object notation::Location {
y := 10;
};
};
var child2 := object notation::DecorationNode {
--the id is set automatically
--type := VisualId_DecoNodeGeneralization;
type := VisualId_Edge_Transition_DecoNode2;
layoutConstraint := object notation::Location {
y := 20;
};
};
var child3 := object notation::DecorationNode {
--the id is set automatically
--type := VisualId_DecoNodeGeneralization;
type := VisualId_Edge_Transition_DecoNode3;
layoutConstraint := object notation::Location {
y := 20;
};
};
return OrderedSet {
child1, child2, child3
};
}
helper setStyleForEdge() : OrderedSet(notation::Style)
{
--
var style := object notation::FontStyle {
--the id is set automatically
--fontName="Sans Serif";
};
return OrderedSet{style};
}
helper setSourceAnchor() : notation::Anchor
{
return object notation::IdentityAnchor { };
}
helper setTargetAnchor():notation::Anchor
{
return object notation::IdentityAnchor { };
}
helper setBendpointsForEdge():notation::RelativeBendpoints
{
--
// var pts : notation::RelativeBendpointList;
// var bendpoints:=object notation::RelativeBendpoints { };
var bendpoints := createBendpoints().oclAsType (notation::RelativeBendpoints);
return bendpoints;
}