public PortConstraintBendHandle(bool sourceEnd, IBend bend, IHandle originalImplementation, WeakDictionaryMapper <IEdge, PortConstraint> portConstraints) : base(originalImplementation) { this.sourceEnd = sourceEnd; this.bend = bend; this.portConstraints = portConstraints; }
private bool FindAnchorTangent(IEdge edge, out double upX, out double upY, out double cx, out double cy) { IEdgeStyle style = edge.Style; if (style != null) { IEdgeStyleRenderer renderer = style.Renderer; IPathGeometry geometry = renderer.GetPathGeometry(edge, style); if (geometry != null) { var t = geometry.GetTangent(ratio); if (t != null) { var tangent = t.Value; upX = -tangent.Vector.Y; upY = tangent.Vector.X; cx = tangent.Point.X; cy = tangent.Point.Y; return(true); } } } double l = 0; var spl = edge.SourcePort.GetLocation(); double x1 = spl.X; double y1 = spl.Y; var tpl = edge.TargetPort.GetLocation(); double x2 = tpl.X; double y2 = tpl.Y; { double lx = x1; double ly = y1; var bends = edge.Bends; for (int i = 0; i < bends.Count; i++) { IBend bend = bends[i]; double bx = bend.Location.X; double by = bend.Location.Y; double dx = bx - lx; double dy = by - ly; l += Math.Sqrt(dx * dx + dy * dy); lx = bx; ly = by; } { double dx = x2 - lx; double dy = y2 - ly; l += Math.Sqrt(dx * dx + dy * dy); } } double tl = ratio * l; if (l == 0) { // no length, no path, no label upX = 0; upY = -1; cx = x1; cy = y1; return(false); } l = 0; { double lx = x1; double ly = y1; var bends = edge.Bends; for (int i = 0; i < bends.Count; i++) { IBend bend = bends[i]; double bx = bend.Location.X; double by = bend.Location.Y; double dx = bx - lx; double dy = by - ly; double sl = Math.Sqrt(dx * dx + dy * dy); if (sl > 0 && l + sl >= tl) { tl -= l; cx = lx + tl * dx / sl; cy = ly + tl * dy / sl; upX = -dy; upY = dx; return(true); } l += sl; lx = bx; ly = by; } { double dx = x2 - lx; double dy = y2 - ly; double sl = Math.Sqrt(dx * dx + dy * dy); if (sl > 0) { tl -= l; cx = lx + tl * dx / sl; cy = ly + tl * dy / sl; upX = -dy; upY = dx; return(true); } else { upX = 0; upY = -1; cx = x1; cy = y1; return(false); } } } }
/// <summary> /// Creates a sample graph and introduces all important graph elements present in /// yFiles WPF. Additionally, this method now overrides the label placement for some specific labels. /// </summary> private void PopulateGraph() { #region Sample Graph creation // Creates two nodes with the default node size // The location is specified for the _center_ INode node1 = Graph.CreateNode(new PointD(50, 50)); INode node2 = Graph.CreateNode(new PointD(150, 50)); // Creates a third node with a different size of 80x40 // In this case, the location of (360,280) describes the _upper left_ // corner of the node bounds INode node3 = Graph.CreateNode(new RectD(260, 180, 80, 40)); // Creates some edges between the nodes IEdge edge1 = Graph.CreateEdge(node1, node2); IEdge edge2 = Graph.CreateEdge(node2, node3); // Creates the first bend for edge2 at (400, 50) IBend bend1 = Graph.AddBend(edge2, new PointD(300, 50)); // Actually, edges connect "ports", not nodes directly. // If necessary, you can manually create ports at nodes // and let the edges connect to these. // Creates a port in the center of the node layout IPort port1AtNode1 = Graph.AddPort(node1, FreeNodePortLocationModel.NodeCenterAnchored); // Creates a port at the middle of the left border // Note to use absolute locations when placing ports using PointD. IPort port1AtNode3 = Graph.AddPort(node3, new PointD(node3.Layout.X, node3.Layout.GetCenter().Y)); // Creates an edge that connects these specific ports IEdge edgeAtPorts = Graph.CreateEdge(port1AtNode1, port1AtNode3); // Adds labels to several graph elements Graph.AddLabel(node1, "Node 1"); Graph.AddLabel(node2, "Node 2"); Graph.AddLabel(node3, "Node 3"); Graph.AddLabel(edgeAtPorts, "Edge at Ports"); // Add some more elements to have a larger graph to edit var n4 = Graph.CreateNode(new PointD(50, -50)); Graph.AddLabel(n4, "Node 4"); var n5 = Graph.CreateNode(new PointD(50, -150)); Graph.AddLabel(n5, "Node 5"); var n6 = Graph.CreateNode(new PointD(-50, -50)); Graph.AddLabel(n6, "Node 6"); var n7 = Graph.CreateNode(new PointD(-50, -150)); Graph.AddLabel(n7, "Node 7"); var n8 = Graph.CreateNode(new PointD(150, -50)); Graph.AddLabel(n8, "Node 8"); Graph.CreateEdge(n4, node1); Graph.CreateEdge(n5, n4); Graph.CreateEdge(n7, n6); var e6_1 = Graph.CreateEdge(n6, node1); Graph.AddBend(e6_1, new PointD(-50, 50), 0); // Creates a group node programmatically which groups the child nodes n4, n5, and n8 var groupNode = CreateGroupNodes(n4, n5, n8); // creates an edge between the group node and node 2 var eg_2 = Graph.CreateEdge(groupNode, node2); Graph.AddBend(eg_2, new PointD(100, 0), 0); Graph.AddBend(eg_2, new PointD(150, 0), 1); #endregion }
/// <summary> /// Creates a sample graph and introduces all important graph elements present in /// yFiles.NET. Additionally, this method now overrides the label placement for some specific labels. /// </summary> private void PopulateGraph() { #region Sample Graph creation //////////// Sample node creation /////////////////// // Creates two nodes with the default node size // The location is specified for the _center_ INode node1 = Graph.CreateNode(new PointD(50, 50)); INode node2 = Graph.CreateNode(new PointD(150, 50)); // Creates a third node with a different size of 80x40 // In this case, the location of (360,380) describes the _upper left_ // corner of the node bounds INode node3 = Graph.CreateNode(new RectD(360, 380, 80, 40)); ///////////////////////////////////////////////////// //////////// Sample edge creation /////////////////// // Creates some edges between the nodes IEdge edge1 = Graph.CreateEdge(node1, node2); IEdge edge2 = Graph.CreateEdge(node2, node3); ///////////////////////////////////////////////////// //////////// Using Bends //////////////////////////// // Creates the first bend for edge2 at (400, 50) IBend bend1 = Graph.AddBend(edge2, new PointD(400, 50)); ///////////////////////////////////////////////////// //////////// Using Ports //////////////////////////// // Actually, edges connect "ports", not nodes directly. // If necessary, you can manually create ports at nodes // and let the edges connect to these. // Creates a port in the center of the node layout IPort port1AtNode1 = Graph.AddPort(node1, FreeNodePortLocationModel.NodeCenterAnchored); // Creates a port at the middle of the left border // Note to use absolute locations when placing ports using PointD. IPort port1AtNode3 = Graph.AddPort(node3, new PointD(node3.Layout.X, node3.Layout.GetCenter().Y)); // Creates an edge that connects these specific ports IEdge edgeAtPorts = Graph.CreateEdge(port1AtNode1, port1AtNode3); ///////////////////////////////////////////////////// //////////// Sample label creation /////////////////// // Adds labels to several graph elements Graph.AddLabel(node1, "N 1"); Graph.AddLabel(node2, "N 2"); Graph.AddLabel(node3, "N 3"); var edgeLabel = Graph.AddLabel(edgeAtPorts, "Edge at Ports"); ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// #endregion ///////////////// New in this Sample ///////////////// // Override default styles // Changes the style for the second node // Creates a new node style, this time a ShapeNodeStyle: ShapeNodeStyle sns = new ShapeNodeStyle { Shape = ShapeNodeShape.Ellipse, Pen = Pens.Black, Brush = Brushes.OrangeRed }; // Sets the node's style property to the new style through its owning graph, // since you can't set the style property of an INode directly // (you'll set most other graph object properties this way as well) Graph.SetStyle(node2, sns); // Creates a different style for the label with black text and a red border // and intransparent white background DefaultLabelStyle sls = new DefaultLabelStyle { Font = new Font("Arial Black", 12), TextBrush = Brushes.Black }; sls.BackgroundPen = Pens.Red; sls.BackgroundBrush = Brushes.White; // And sets the style for the edge label, again through its owning graph. Graph.SetStyle(edgeLabel, sls); // Override the style for the "Edge at Ports" edge: // Uses a dashed red Pen with thickness 2. Pen defaultPen = new Pen(Brushes.Red, 2) { DashStyle = DashStyle.Dash }; // Creates an edge style that will apply the new default pen // to the entire line using PolyLineEdgeStyle, // which draws a polyline determined by the edge's control points (bends) var edgeStyle = new PolylineEdgeStyle { Pen = defaultPen }; // Sets the source and target arrows on the edge style instance // Note that IEdgeStyle itself does not have these properties // also note: by default the arrows have a default brush and pen edgeStyle.SourceArrow = Arrows.Circle; // set color and size to match the thick red line edgeStyle.TargetArrow = new Arrow(Color.Red) { Type = ArrowType.Short, Scale = 2 }; // Sets the style for the "Edge at Ports" edge, again through its owning graph. Graph.SetStyle(edge2, edgeStyle); ////////////////////////////////////////////////////// }
public BendCreationHandler(IBend bend, IGraph graph, BezierCreateBendInputMode bendInputMode) { this.bend = bend; this.graph = graph; this.bendInputMode = bendInputMode; }
/// <summary> /// Creates a sample graph and introduces all important graph elements present in /// yFiles.NET. /// </summary> private void PopulateGraph() { #region Sample Graph creation ///////////////// New in this Sample ///////////////// // Creates a node outside the initial content rectangle INode node4 = Graph.CreateNode(new PointD(-100, -100)); ILabel outsiderLabel = Graph.AddLabel(node4, "Outside Initial Viewport"); ////////////////////////////////////////////////////// //////////// Sample node creation /////////////////// // Creates two nodes with the default node size // The location is specified for the _center_ INode node1 = Graph.CreateNode(new PointD(50, 50)); INode node2 = Graph.CreateNode(new PointD(150, 50)); // Creates a third node with a different size of 80x40 // In this case, the location of (360,380) describes the _upper left_ // corner of the node bounds INode node3 = Graph.CreateNode(new RectD(360, 380, 80, 40)); ///////////////////////////////////////////////////// //////////// Sample edge creation /////////////////// // Creates some edges between the nodes IEdge edge1 = Graph.CreateEdge(node1, node2); IEdge edge2 = Graph.CreateEdge(node2, node3); ///////////////////////////////////////////////////// //////////// Using Bends //////////////////////////// // Creates the first bend for edge2 at (400, 50) IBend bend1 = Graph.AddBend(edge2, new PointD(400, 50)); ///////////////////////////////////////////////////// //////////// Using Ports //////////////////////////// // Actually, edges connect "ports", not nodes directly. // If necessary, you can manually create ports at nodes // and let the edges connect to these. // Creates a port in the center of the node layout IPort port1AtNode1 = Graph.AddPort(node1, FreeNodePortLocationModel.NodeCenterAnchored); // Creates a port at the middle of the left border // Note to use absolute locations when placing ports using PointD. IPort port1AtNode3 = Graph.AddPort(node3, new PointD(node3.Layout.X, node3.Layout.GetCenter().Y)); // Creates an edge that connects these specific ports IEdge edgeAtPorts = Graph.CreateEdge(port1AtNode1, port1AtNode3); ///////////////////////////////////////////////////// //////////// Sample label creation /////////////////// // Adds labels to several graph elements Graph.AddLabel(node1, "N 1"); Graph.AddLabel(node2, "N 2"); Graph.AddLabel(node3, "N 3"); Graph.AddLabel(edgeAtPorts, "Edge at Ports"); ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// #endregion }
/// <summary> /// Creates a sample graph and introduces all important graph elements present in /// yFiles.NET. Additionally, this method now overrides the label placement for some specific labels. /// </summary> private void PopulateGraph() { #region Sample Graph creation //////////// Sample node creation /////////////////// // Creates two nodes with the default node size // The location is specified for the _center_ INode node1 = Graph.CreateNode(new PointD(50, 50)); INode node2 = Graph.CreateNode(new PointD(150, 50)); // Creates a third node with a different size of 80x40 // In this case, the location of (360,380) describes the _upper left_ // corner of the node bounds INode node3 = Graph.CreateNode(new RectD(360, 380, 80, 40)); ///////////////////////////////////////////////////// //////////// Sample edge creation /////////////////// // Creates some edges between the nodes IEdge edge1 = Graph.CreateEdge(node1, node2); IEdge edge2 = Graph.CreateEdge(node2, node3); ///////////////////////////////////////////////////// //////////// Using Bends //////////////////////////// // Creates the first bend for edge2 at (400, 50) IBend bend1 = Graph.AddBend(edge2, new PointD(400, 50)); ///////////////////////////////////////////////////// //////////// Using Ports //////////////////////////// // Actually, edges connect "ports", not nodes directly. // If necessary, you can manually create ports at nodes // and let the edges connect to these. // Creates a port in the center of the node layout IPort port1AtNode1 = Graph.AddPort(node1, FreeNodePortLocationModel.NodeCenterAnchored); // Creates a port at the middle of the left border // Note to use absolute locations when placing ports using PointD. IPort port1AtNode3 = Graph.AddPort(node3, new PointD(node3.Layout.X, node3.Layout.GetCenter().Y)); // Creates an edge that connects these specific ports IEdge edgeAtPorts = Graph.CreateEdge(port1AtNode1, port1AtNode3); ///////////////////////////////////////////////////// //////////// Sample label creation /////////////////// // Adds labels to several graph elements Graph.AddLabel(node1, "N 1"); Graph.AddLabel(node2, "N 2"); var node3Label = Graph.AddLabel(node3, "N 3"); Graph.AddLabel(edgeAtPorts, "Edge at Ports"); ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// #endregion ///////////////// New in this Sample ///////////////// // Override default label placement // For our "special" label, we use a model that describes discrete positions // outside the node bounds ExteriorLabelModel exteriorLabelModel = new ExteriorLabelModel(); // We use some extra insets from the label to the node bounds exteriorLabelModel.Insets = new InsetsD(5); // We assign this label a specific symbolic position out of the eight possible // external locations valid for ExteriorLabelModel Graph.SetLabelLayoutParameter(node3Label, exteriorLabelModel.CreateParameter(ExteriorLabelModel.Position.South)); ///////////////////////////////////////////////////// }
/// <summary> /// Creates a new instance that wraps the original <paramref name="coreHandle"/> for the given <paramref name="bend"/>. /// </summary> public OuterControlPointHandle([NotNull] IHandle coreHandle, [NotNull] IBend bend) { this.coreHandle = coreHandle; this.bend = bend; }