示例#1
0
 // Draws the given edge.
 // Derived classes are supposed to try to draw the given edge,
 // and if they fail, call this default implementation.
 protected virtual void DrawElement(DI.GraphEdge edge)
 {
     Uml2SemanticModelBridge bridge = edge.SemanticModel as Uml2SemanticModelBridge;
     UML.Element umlElement = bridge.Element;
     // if the element is any kind of binary relationship, represent
     // it as an edge.
     UML.Relationship umlRelation = umlElement as UML.Relationship;
     if (umlRelation != null && umlRelation.RelatedElement.Count == 2)
     {
         System.Console.WriteLine ("UMLDiagram.DrawElement> Adding a generic UMLEdge to the canvas for element: " + umlElement.ToString());
         UMLStereotypedEdge umlEdge = new UMLStereotypedEdge (this, edge);
         _canvas.AddElement (umlEdge);
     }
 }
        public static UMLStereotypedEdge CreateNewAndAdd(
			UMLDiagram owningDiagram,
			UML.Relationship stereotypedEdgeModel,
			DI.GraphElement fromGE,
			DI.GraphElement toGE
		)
        {
            // creates the graphical representation of the new Stereotyped Edge
            DI.GraphEdge stereotypedEdgeGE = new DI.GraphEdge ();
            // model semanticModelBridge to the UML model element
            Uml2SemanticModelBridge semanticModelBridge = new Uml2SemanticModelBridge ();
            semanticModelBridge.Element = stereotypedEdgeModel;
            stereotypedEdgeGE.SemanticModel = semanticModelBridge;
            // adds anchors and anchorages
            DI.GraphConnector cnn;

            cnn = new DI.GraphConnector ();
            cnn.GraphElement = fromGE;
            fromGE.Position.CopyTo (cnn.Position);
            fromGE.Anchorage.Add (cnn);
            stereotypedEdgeGE.Anchor.Add (cnn);
            cnn.GraphEdge.Add(stereotypedEdgeGE);

            cnn = new DI.GraphConnector ();
            cnn.GraphElement = toGE;
            toGE.Position.CopyTo (cnn.Position);
            toGE.Anchorage.Add (cnn);
            stereotypedEdgeGE.Anchor.Add (cnn);
            cnn.GraphEdge.Add(stereotypedEdgeGE);
            // adds waypoints
            DI.GraphNode gn = fromGE as DI.GraphNode;
            DI.Point f = (gn != null ? gn.Center : fromGE.Position.Clone ());
            gn = toGE as DI.GraphNode;
            DI.Point t = (gn != null ? gn.Center : toGE.Position.Clone ());
            stereotypedEdgeGE.Waypoints.Add (f);
            stereotypedEdgeGE.Waypoints.Add (t);
            // adds the stereotype compartment
            DI.SimpleSemanticModelElement bridge;
            DI.GraphNode stCompartmentGN = new DI.GraphNode ();
            bridge = new DI.SimpleSemanticModelElement ();
            bridge.TypeInfo = "StereotypeCompartment";
            stCompartmentGN.SemanticModel = bridge;
            stereotypedEdgeGE.Contained.Add (stCompartmentGN);
            stCompartmentGN.Container = stereotypedEdgeGE;
            DI.Point.GetHalfWayPoint (fromGE.Position, toGE.Position).CopyTo (stCompartmentGN.Position);
            DI.GraphNode keywordMetaclassGN = new DI.GraphNode ();
            bridge = new DI.SimpleSemanticModelElement ();
            bridge.TypeInfo = "KeywordMetaclass";
            keywordMetaclassGN.SemanticModel = bridge;
            stCompartmentGN.Contained.Add (keywordMetaclassGN);
            keywordMetaclassGN.Container = stCompartmentGN;
            // adds the stereotypedEdge to the diagram
            owningDiagram.DIDiagram.Contained.Add (stereotypedEdgeGE);
            stereotypedEdgeGE.Container = owningDiagram.DIDiagram;
            UMLStereotypedEdge stereotypedEdge = new UMLStereotypedEdge (owningDiagram, stereotypedEdgeGE, stereotypedEdgeModel);
            owningDiagram.UMLCanvas.AddElement (stereotypedEdge);
            return stereotypedEdge;
        }