Ejemplo n.º 1
0
 protected override void DrawElement(DI.GraphEdge edge)
 {
     Uml2SemanticModelBridge bridge = edge.SemanticModel as Uml2SemanticModelBridge;
     UML.Element umlElement = bridge.Element;
     if (umlElement is UML.Association)
     {
         UMLAssociation association = new UMLAssociation (this, edge);
         _canvas.AddElement (association);
     }
     else if (umlElement is UML.Generalization)
     {
         UMLGeneralization generalization = new UMLGeneralization (this, edge);
         _canvas.AddElement (generalization);
     }
     else
     {
         base.DrawElement(edge);
     }
 }
Ejemplo n.º 2
0
        public static UMLAssociation CreateNew(
			UMLDiagram ownerDiagram,
			UMLElement fromElement,
			UMLElement toElement )
        {
            UMLAssociation association = null;
            DI.GraphElement fromGE = fromElement.GraphElement;
            DI.GraphElement toGE = toElement.GraphElement;
            UML.Classifier fromModelElement = MonoUML.Widgets.Helper.GetSemanticElement (fromGE) as UML.Classifier;
            UML.Classifier toModelElement = MonoUML.Widgets.Helper.GetSemanticElement (toGE) as UML.Classifier;
            if (fromModelElement != null && toModelElement != null)
            {
                // creates the new Association in the model
                UML.Association assocModel = UML.Create.Association ();
                UML.Property end0 = UML.Create.Property ();
                // the first end aims at the "TO" end
                end0.Type = toModelElement;
                assocModel.OwnedEnd.Add (end0);
                end0.OwningAssociation = assocModel;
                // the second (and last) end aims at the "FROM" end
                UML.Property end1 = UML.Create.Property ();
                end1.Type = fromModelElement;
                assocModel.OwnedEnd.Add (end1);
                end1.OwningAssociation = assocModel;
                // creates the graphical representation of the new Association
                DI.GraphEdge assocGE = new DI.GraphEdge ();
                //    graphical properties
                //    model bridge to the UML model element (Actor)
                Uml2SemanticModelBridge bridge = new Uml2SemanticModelBridge ();
                bridge.Element = assocModel;
                assocGE.SemanticModel = bridge;
                // adds anchors and anchorages
                DI.GraphConnector cnn;
                cnn = new DI.GraphConnector ();
                cnn.GraphElement = fromGE;
                fromGE.Anchorage.Add (cnn);
                fromGE.Position.CopyTo (cnn.Position);
                assocGE.Anchor.Add (cnn);
                cnn.GraphEdge.Add (assocGE);
                cnn = new DI.GraphConnector ();
                cnn.GraphElement = toGE;
                toGE.Anchorage.Add (cnn);
                toGE.Position.CopyTo (cnn.Position);
                assocGE.Anchor.Add (cnn);
                cnn.GraphEdge.Add (assocGE);
                // adds waypoints
                DI.GraphNode gn = fromGE as DI.GraphNode;
                DI.Point f = (gn != null ? gn.Center : toGE.Position.Clone ());
                gn = toGE as DI.GraphNode;
                DI.Point t = (gn != null ? gn.Center : toGE.Position.Clone ());
                assocGE.Waypoints.Add (f);
                assocGE.Waypoints.Add (t);
                // adds the name compartment
                DI.SimpleSemanticModelElement simpleBridge;
                DI.GraphNode nameCompartmentGN = new DI.GraphNode ();
                simpleBridge = new DI.SimpleSemanticModelElement ();
                simpleBridge.TypeInfo = "DirectedName";
                nameCompartmentGN.SemanticModel = simpleBridge;
                assocGE.Contained.Add (nameCompartmentGN);
                nameCompartmentGN.Container = assocGE;
                DI.Point.GetHalfWayPoint (fromGE.Position, toGE.Position).CopyTo (nameCompartmentGN.Position);
                DI.GraphNode keywordMetaclassGN = new DI.GraphNode ();
                simpleBridge = new DI.SimpleSemanticModelElement ();
                simpleBridge.TypeInfo = "Name";
                keywordMetaclassGN.SemanticModel = simpleBridge;
                nameCompartmentGN.Contained.Add (keywordMetaclassGN);
                keywordMetaclassGN.Container = nameCompartmentGN;
                // adds the association ends compartments
                DI.GraphNode endCompartment0 = UMLAssociationEnd.CreateNewGraphNode (end0);
                assocGE.Contained.Add (endCompartment0);
                endCompartment0.Container = assocGE;
                DI.GraphNode endCompartment1 = UMLAssociationEnd.CreateNewGraphNode (end1);
                assocGE.Contained.Add (endCompartment1);
                endCompartment1.Container = assocGE;
                // adds the association to the diagram
                ownerDiagram.DIDiagram.Contained.Add (assocGE);
                assocGE.Container = ownerDiagram.DIDiagram;
                association = new UMLAssociation (ownerDiagram, assocGE, assocModel);
                association._assocEnd0.SetPosition ((DI.Point) association._graphEdge.Waypoints [0]);
                association._assocEnd1.SetPosition ((DI.Point) association._graphEdge.Waypoints [1]);
                ownerDiagram.AddNewClassifier (association, assocModel);
            }
            return association;
        }