Esempio 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);
     }
 }
Esempio n. 2
0
        public static UMLGeneralization CreateNew(
			UMLDiagram ownerDiagram,
			UMLElement fromElement,
			UMLElement toElement )
        {
            UMLGeneralization generalization = 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 Generalization in the model
                UML.Generalization generalizModel = UML.Create.Generalization ();
                generalizModel.General = toModelElement;
                generalizModel.Specific = fromModelElement;
                fromModelElement.Generalization.Add(generalizModel);
                // creates the graphical representation of the new Generalization
                DI.GraphEdge generalizGE = new DI.GraphEdge ();
                //    model bridge to the UML model element (Actor)
                Uml2SemanticModelBridge bridge = new Uml2SemanticModelBridge ();
                bridge.Element = generalizModel;
                generalizGE.SemanticModel = bridge;
                // adds anchors and anchorages
                DI.GraphConnector cnn;
                cnn = new DI.GraphConnector ();
                cnn.GraphElement = fromGE;
                fromGE.Position.CopyTo (cnn.Position);
                fromGE.Anchorage.Add (cnn);
                generalizGE.Anchor.Add (cnn);
                cnn = new DI.GraphConnector ();
                cnn.GraphElement = toGE;
                toGE.Position.CopyTo (cnn.Position);
                toGE.Anchorage.Add (cnn);
                generalizGE.Anchor.Add (cnn);
                // 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 ());
                generalizGE.Waypoints.Add (f);
                generalizGE.Waypoints.Add (t);
                // adds the generalization to the diagram
                ownerDiagram.DIDiagram.Contained.Add (generalizGE);
                generalization = new UMLGeneralization (ownerDiagram, generalizGE, generalizModel);
                ownerDiagram.UMLCanvas.AddElement (generalization);
                Hub.Instance.Broadcaster.BroadcastElementChange(fromModelElement);
            }
            return generalization;
        }