示例#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 if (umlElement is UML.InterfaceRealization)
     {
         UMLInterfaceRealization interfaceRealization = new UMLInterfaceRealization (this, edge);
         _canvas.AddElement (interfaceRealization);
     }
     else
     {
         base.DrawElement(edge);
     }
 }
        public static UMLInterfaceRealization CreateNew(
			UMLDiagram ownerDiagram,
			UMLElement fromElement,
			UMLElement toElement )
        {
            UMLInterfaceRealization interfaceRealization = null;
            DI.GraphElement fromGE = fromElement.GraphElement;
            DI.GraphElement toGE = toElement.GraphElement;
            UML.BehavioredClassifier fromModelElement = MonoUML.Widgets.Helper.GetSemanticElement (fromGE) as UML.BehavioredClassifier;
            UML.Interface toModelElement = MonoUML.Widgets.Helper.GetSemanticElement (toGE) as UML.Interface;
            if (fromModelElement != null && toModelElement != null)
            {
                // creates the new InterfaceRealization in the model
                UML.InterfaceRealization interfaceRealizationModel = UML.Create.InterfaceRealization ();
                interfaceRealizationModel.Contract = toModelElement;
                interfaceRealizationModel.ImplementingClassifier = fromModelElement;
                fromModelElement.InterfaceRealization.Add(interfaceRealizationModel);
                // creates the graphical representation of the new InterfaceRealization
                DI.GraphEdge interfaceRealizationGE = new DI.GraphEdge ();
                //    model bridge to the UML model element (Actor)
                Uml2SemanticModelBridge bridge = new Uml2SemanticModelBridge ();
                bridge.Element = interfaceRealizationModel;
                interfaceRealizationGE.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);
                interfaceRealizationGE.Anchor.Add (cnn);
                cnn = new DI.GraphConnector ();
                cnn.GraphElement = toGE;
                toGE.Position.CopyTo (cnn.Position);
                toGE.Anchorage.Add (cnn);
                interfaceRealizationGE.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 ());
                interfaceRealizationGE.Waypoints.Add (f);
                interfaceRealizationGE.Waypoints.Add (t);
                // adds the interfaceRealization to the diagram
                ownerDiagram.DIDiagram.Contained.Add (interfaceRealizationGE);
                interfaceRealization = new UMLInterfaceRealization (ownerDiagram, interfaceRealizationGE, interfaceRealizationModel);
                ownerDiagram.UMLCanvas.AddElement (interfaceRealization);
                Hub.Instance.Broadcaster.BroadcastElementChange(fromModelElement);
            }
            return interfaceRealization;
        }