--Author Manel Fredj-CEA LIST
library HelpersEdge;
import GeneralMappingsandHelpers;
import NotationQueries;
import ClassAndProfileDiagEdgeVisualIDs;
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';
--class and profile have identical visual IDs for relationships
--Since the profile diagram has been developed starting with a class diagram. This
--is not the case for other diagram types
mapping di2::GraphEdge::classAndProfileDiagEdge2Edge() : notation::Connector inherits di2::GraphEdge::edge2Connector
{
--setting the type and children
if (self.getElement() != null) then {
if (self.getElement().isGeneralization()) then {
type := VisualId_Edge_Generalization;
--adding children
children := setChildrenForGeneralization();
} endif;
if (self.getElement().oclIsTypeOf(uml::Extension)) then {
type := VisualId_Edge_Extension;
--adding children
// children := setChildrenForExtension();
} else {
// extension is also an association, use "else" (else if is unfortunatley not supported in QVTO)
if (self.getElement().isAssociation()) then {
type := VisualId_Edge_Association;
children := setChildrenForAssociation();
} endif;
} endif;
if (self.getElement().oclIsTypeOf(uml::PackageImport)) then {
type := VisualId_Edge_PackageImport;
children := setChildrenForPackageImport();
} endif;
if (self.getElement().isDependency()) then {
type := VisualId_Edge_Dependency;
--adding children
children := setChildrenForDependency();
} endif;
if (self.getElement().isRealization()) then {
type := VisualId_Edge_Realization;
--adding children
children := setChildrenForRealization();
} endif;
}
else {
--it is a link
var diagType : String = self.getDiagramtype ();
if (diagType = ClassDiagram_P2) then {
type := VisualId_CEdge_Link;
}
else {
if (diagType = ProfileDiagram_P2) then {
type := VisualId_PEdge_Link;
} endif;
} endif;
element := null;
} 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 setChildrenForRealization(): OrderedSet(notation::Node)
{
return setChildrenForEdge2Children(VisualId_Edge_Realization_DecoNode1, VisualId_Edge_Realization_DecoNode2);
}
helper setChildrenForDependency(): OrderedSet(notation::Node)
{
--
--
--
--
--
--
return setChildrenForEdge2Children(VisualId_Edge_Dependency_DecoNode1, VisualId_Edge_Dependency_DecoNode2);
}
helper setChildrenForGeneralization(): OrderedSet(notation::Node)
{
--
--
--
var child1 := object notation::DecorationNode {
--the id is set automatically
--type := VisualId_DecoNodeGeneralization;
type := VisualId_Edge_Generalization_DecoNode;
layoutConstraint := object notation::Location {
y := 40;
};
};
return OrderedSet {child1};
}
helper setChildrenForAssociation(): OrderedSet(notation::Node)
{
----------------------------------------------------------------------
--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
-- 1 targetAnchor
-----------------------------------------------------------------------
--first child
var child1 := object notation::DecorationNode {
--the id is set automatically
type := VisualId_Edge_Association_DecoNode1;
layoutConstraint := object notation::Location {
y := -20;
};
};
--second child
var child2 :=object notation::DecorationNode {
--association label
type := VisualId_Edge_Association_DecoNode2;
layoutConstraint := object notation::Location {
y := 20;
};
// make label of association itself (not its endpoints) non visible by default
visible := false;
};
--third child
var child3 := object notation::DecorationNode {
--label first association end
type := VisualId_Edge_Association_DecoNode3;
layoutConstraint := object notation::Location {
y := -20;
};
eAnnotations += noTypeEAnnotation();
};
--fourth child
var child4 := object notation::DecorationNode {
--label 2nd association end
type := VisualId_Edge_Association_DecoNode4;
layoutConstraint := object notation::Location {
y := 20;
};
eAnnotations += noTypeEAnnotation();
};
--fifth child
var child5 := object notation::DecorationNode {
--multiplicity first association end
type := VisualId_Edge_Association_DecoNode5;
visible := false;
--layoutConstraint := object notation::Location{
--y := 20;
--x := 20;
--};
};
--sixth child
var child6 := object notation::DecorationNode {
--the id is set automatically
--multiplicity 2nd association end
type := VisualId_Edge_Association_DecoNode6;
visible := false;
--layoutConstraint := object notation::Location {
--y := -20;
--x := -20;
--};
};
--add the set of children to the node
return OrderedSet {
child1, child2, child3, child4, child5, child6
};
}
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;
}
helper setChildrenForPackageImport(): OrderedSet(notation::Node)
{
var child1 := object notation::DecorationNode {
--the id is set automatically
--type := VisualId_DecoNodeGeneralization;
type := VisualId_Edge_PackageImport_DecoNode;
};
return OrderedSet {child1};
}