private void AssignEdgesOfNodeToEdgeDragSets(GeomNode node) { foreach (GeomEdge edge in node.SelfEdges) { objectsToDrag.Insert(edge); } foreach (GeomEdge edge in node.InEdges) { if (objectsToDrag.Contains(edge.Source)) { objectsToDrag.Insert(edge); } else { this.edgesDraggedForTheTarget.Insert(edge); } } foreach (GeomEdge edge in node.OutEdges) { if (objectsToDrag.Contains(edge.Target)) { objectsToDrag.Insert(edge); } else { this.edgesDraggedForTheSource.Insert(edge); } } }
private static void ProcessPhyloEdges(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { foreach (Edge e in graph.Edges) { Microsoft.Msagl.Node sourceNode = msaglGraph.FindNode(e.Source); Microsoft.Msagl.Node targetNode = msaglGraph.FindNode(e.Target); if (sourceNode == null) { sourceNode = CreateGeometryNode(msaglGraph, graph.FindNode(e.Source) as Node, Connection.Connected); } if (targetNode == null) { targetNode = CreateGeometryNode(msaglGraph, graph.FindNode(e.Target) as Node, Connection.Connected); } Microsoft.Msagl.Edge msaglEdge = new Microsoft.Msagl.PhyloEdge(sourceNode, targetNode); msaglEdge.Weight = e.Attr.Weight; msaglEdge.Separation = e.Attr.Separation; msaglEdge.ArrowheadAtSource = e.Attr.ArrowAtSource; msaglEdge.ArrowheadAtTarget = e.Attr.ArrowAtTarget; msaglGraph.AddEdge(msaglEdge); msaglEdge.UserData = e; msaglEdge.ArrowheadLength = e.Attr.ArrowheadLength; msaglEdge.LineWidth = e.Attr.LineWidth; } }
private static void ProcessEdges(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { foreach (Edge drawingEdge in graph.Edges) { Microsoft.Msagl.Node sourceNode = msaglGraph.FindNode(drawingEdge.Source); Microsoft.Msagl.Node targetNode = msaglGraph.FindNode(drawingEdge.Target); if (sourceNode == null) { sourceNode = CreateGeometryNode(msaglGraph, graph.FindNode(drawingEdge.Source) as Node, Connection.Connected); } if (targetNode == null) { targetNode = CreateGeometryNode(msaglGraph, graph.FindNode(drawingEdge.Target) as Node, Connection.Connected); } Microsoft.Msagl.Edge msaglEdge = new Microsoft.Msagl.Edge(sourceNode, targetNode); if (drawingEdge.Label != null && graph.LayoutAlgorithmSettings is SugiyamaLayoutSettings) { msaglEdge.Label = drawingEdge.Label.GeometryLabel; msaglEdge.Label.Parent = msaglEdge; } msaglEdge.Weight = drawingEdge.Attr.Weight; msaglEdge.Length = drawingEdge.Attr.Length; msaglEdge.Separation = drawingEdge.Attr.Separation; msaglEdge.ArrowheadAtSource = drawingEdge.Attr.ArrowAtSource; msaglEdge.ArrowheadAtTarget = drawingEdge.Attr.ArrowAtTarget; msaglGraph.AddEdge(msaglEdge); msaglEdge.UserData = drawingEdge; msaglEdge.ArrowheadLength = drawingEdge.Attr.ArrowheadLength; msaglEdge.LineWidth = drawingEdge.Attr.LineWidth; } }
private void CalculateDragSetsForEdges() { foreach (GeometryObject geomObj in objectsToDrag.Clone()) { GeomNode node = geomObj as GeomNode; if (node != null) { AssignEdgesOfNodeToEdgeDragSets(node); } } }
private static void ProcessNodes(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { foreach (Node n in graph.NodeMap.Values) { Microsoft.Msagl.Node msaglNode = msaglGraph.FindNode(n.Id); if (msaglNode == null) { msaglNode = CreateGeometryNode(msaglGraph, n, Connection.Connected); } else { msaglGraph.NodeMap[msaglNode.Id] = msaglNode; } } }
/// <summary> /// drags elements by the delta /// </summary> /// <param name="delta"></param> public void Drag(Point delta) { GraphBoundingBoxGetsExtended = false; if (delta.X != 0 || delta.Y != 0) { if (EditedEdge == null) { foreach (GeometryObject geomObj in objectsToDrag) { GeomNode node = geomObj as GeomNode; if (node != null) { DragNode(node, delta, CurrentUndoAction.GetRestoreData(node) as NodeRestoreData); } else { GeomEdge edge = geomObj as GeomEdge; if (edge != null) { TranslateEdge(edge, delta, CurrentUndoAction.GetRestoreData(edge) as EdgeRestoreData); } else { GeomLabel label = geomObj as GeomLabel; if (label != null) { DragLabel(label, delta, (CurrentUndoAction.GetRestoreData(label) as LabelRestoreData).Center); } else { throw new NotImplementedException(); } } } UpdateGraphBoundingBoxWithCheck(geomObj); } DragEdgesWithSource(delta); DragEdgesWithTarget(delta); } else if (EditedEdge != null) { DragEdgeEdit(delta); UpdateGraphBoundingBoxWithCheck(EditedEdge); } } }
/// <summary> /// redoes the editing /// </summary> public override void Redo() { base.Redo(); foreach (GeometryObject geomObj in movedObjects) { GeomNode node = geomObj as GeomNode; if (node != null) { GeometryGraphEditor.DragNode(node, Delta, GetRestoreData(node) as NodeRestoreData); foreach (GeomEdge edge in node.OutEdges) { GeometryGraphEditor.DragEdgeWithSource(Delta, edge, GetRestoreData(edge) as EdgeRestoreData); } foreach (GeomEdge edge in node.InEdges) { GeometryGraphEditor.DragEdgeWithTarget(Delta, edge, GetRestoreData(edge) as EdgeRestoreData); } foreach (GeomEdge edge in node.SelfEdges) { GeometryGraphEditor.DragEdge(Delta, edge, GetRestoreData(edge) as EdgeRestoreData, movedObjects); } } else { GeomEdge edge = geomObj as GeomEdge; if (edge != null) { GeometryGraphEditor.DragEdge(Delta, edge, GetRestoreData(edge) as EdgeRestoreData, movedObjects); } else { GeomLabel label = geomObj as GeomLabel; if (label != null) { GeometryGraphEditor.DragLabel(label, Delta, (GetRestoreData(label) as LabelRestoreData).Center); } else { throw new System.NotImplementedException(); } } } } }
/// <summary> /// a helper function creating a geometry node /// </summary> /// <param name="graph"></param> /// <param name="node"></param> /// <param name="connection">controls if the node is connected to the graph</param> /// <returns></returns> public static Microsoft.Msagl.Node CreateGeometryNode(Microsoft.Msagl.GeometryGraph graph, Node node, Connection connection) { Microsoft.Msagl.Node geomNode = new Microsoft.Msagl.Node(node.Id, null); if (connection == Connection.Connected) { graph.AddNode(geomNode); } if (node.Label != null) { geomNode.Label = node.Label.GeometryLabel; if (geomNode.Label != null) { geomNode.Label.Parent = geomNode; } } geomNode.UserData = node; geomNode.Padding = node.Attr.Padding; return(geomNode); }
/// <summary> /// Undoes the editing /// </summary> public override void Undo() { base.Undo(); Point point = new Point(); foreach (GeometryObject geomObj in movedObjects) { GeomNode node = geomObj as GeomNode; if (node != null) { GeometryGraphEditor.DragNode(node, point, GetRestoreData(node) as NodeRestoreData); foreach (GeomEdge edge in node.Edges) { RestoreEdge(edge); } } else { GeomEdge edge = geomObj as GeomEdge; if (edge != null) { GeometryGraphEditor.DragEdge(point, edge, GetRestoreData(edge) as EdgeRestoreData, movedObjects); } else { GeomLabel label = geomObj as GeomLabel; if (label != null) { GeometryGraphEditor.DragLabel(label, point, (GetRestoreData(label) as LabelRestoreData).Center); } else { throw new System.NotImplementedException(); } } } } }
static internal void DragNode(GeomNode node, Point delta, NodeRestoreData restoreData) { node.BoundaryCurve = restoreData.BoundaryCurve.Translate(delta); node.Center = restoreData.Center + delta; }
private IEnumerable <GeometryObject> ChangedElements() { if (this.EditedEdge == null) { foreach (GeometryObject obj in ObjectsToDrag) { GeomNode node = obj as GeomNode; if (node != null) { yield return(node); foreach (GeomEdge e in node.OutEdges) { yield return(e); } foreach (GeomEdge e in node.SelfEdges) { yield return(e); } foreach (GeomEdge e in node.InEdges) { yield return(e); } } else { GeomEdge edge = obj as GeomEdge; if (edge != null) { yield return(edge); yield return(edge.Source); foreach (GeomEdge e in edge.Source.Edges) { yield return(e); } yield return(edge.Target); foreach (GeomEdge e in edge.Target.Edges) { yield return(e); } } else { GeomLabel label = obj as GeomLabel; if (label != null) { yield return(label); } else { throw new NotImplementedException(); } } } } } else { yield return(this.EditedEdge); } }
private static bool CustomDrawNode(Microsoft.Msagl.Drawing.Node node, object graphics, NodeTypes nodeType) { try { double width = 110; double height = 40; Microsoft.Msagl.GeometryGraph geomGraph = new Microsoft.Msagl.GeometryGraph(); GeomNode geomCreek = new Microsoft.Msagl.Node(node.Id, Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center)); node.Attr.GeometryNode.BoundaryCurve = Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center); Graphics g = (Graphics)graphics; MemoryStream ms = new MemoryStream(); switch (nodeType) { case NodeTypes.Normal: CxViewerResources.NormalNode.Save(ms, ImageFormat.Png); break; case NodeTypes.NormalSelected: CxViewerResources.NormalSelected.Save(ms, ImageFormat.Png); break; case NodeTypes.MultiRelaitions: CxViewerResources.MultiRelaitions.Save(ms, ImageFormat.Png); break; case NodeTypes.MultiRelaitionsSelected: CxViewerResources.MultiRelaitionsSelected.Save(ms, ImageFormat.Png); break; } System.Drawing.Image image = System.Drawing.Image.FromStream(ms); //flip the image around its center using (System.Drawing.Drawing2D.Matrix m = g.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { float c = (float)node.Attr.GeometryNode.Center.Y; using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c)) m.Multiply(m2); g.Transform = m; g.SetClip(FillTheGraphicsPath(node.Attr.GeometryNode.BoundaryCurve)); g.DrawImage(image, new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2))); Font myFont = new System.Drawing.Font("Helvetica", 10, System.Drawing.FontStyle.Italic); System.Drawing.Brush myBrush = new SolidBrush(System.Drawing.Color.Blue); Rectangle rectString = new Rectangle(Convert.ToInt32(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), Convert.ToInt32(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2), Convert.ToInt32(width), Convert.ToInt32(height)); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; g.DrawString(node.Label.Text, myFont, myBrush, rectString, stringFormat // new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - 5)) ); g.Transform = saveM; } } } catch (Exception err) { Common.Logger.Create().Error(err.ToString()); } return(true);//returning false would enable the default rendering }