static void BindTheGraphs(Graph drawingGraph, GeometryGraph geomGraph) { drawingGraph.GeometryGraph = geomGraph; foreach (KeyValuePair <string, Microsoft.Msagl.Node> kv in geomGraph.NodeMap) { Microsoft.Msagl.Drawing.Node drawingNode = drawingGraph.NodeMap[kv.Key] as Microsoft.Msagl.Drawing.Node; drawingNode.Attr.GeometryNode = kv.Value; if (drawingNode.Label != null) { drawingNode.Label.GeometryLabel = kv.Value.Label; } } //geom edges have to appear in the same order as drawing edges IEnumerator <Edge> edgeEnum = drawingGraph.Edges.GetEnumerator(); IEnumerator <Microsoft.Msagl.Edge> geomEdgeEnum = geomGraph.Edges.GetEnumerator(); while (edgeEnum.MoveNext()) { geomEdgeEnum.MoveNext(); edgeEnum.Current.Attr.GeometryEdge = geomEdgeEnum.Current; if (edgeEnum.Current.Label != null) { edgeEnum.Current.Label.GeometryLabel = geomEdgeEnum.Current.Label; } } drawingGraph.LayoutAlgorithmSettings = geomGraph.LayoutAlgorithmSettings; }
void RefreshDisplay() { foreach (cCellType item in Parent.ListCellTypes) { Microsoft.Msagl.Drawing.Node NewNode = new Microsoft.Msagl.Drawing.Node(item.Name); NewNode.Label.FontColor = new Microsoft.Msagl.Drawing.Color(item.TypeColor.R, item.TypeColor.G, item.TypeColor.B); NewNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.DimGray; NewNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Ellipse; graph.AddNode(NewNode); } foreach (cCellType item in Parent.ListCellTypes) { foreach (cTransitionValue Transitions in item.ListInitialTransitions) { if (Transitions.Value == 0) continue; Microsoft.Msagl.Drawing.Edge Currentedge = new Microsoft.Msagl.Drawing.Edge(item.Name, Transitions.Value.ToString(), Transitions.DestType.Name); //Currentedge.Label.FontSize = Transitions.Value; //Currentedge.LabelText = ; graph.Edges.Add(Currentedge); } } GraphView.Graph = graph; GraphView.Dock = System.Windows.Forms.DockStyle.Fill; this.panel.Controls.Add(GraphView); }
static public void dfagraph(List <DFAState> list) { System.Windows.Forms.Form form = new System.Windows.Forms.Form(); Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); for (int i = 0; i < list.Count; i++) { for (int j = 0; j < list[i].transitions.Count; j += 2) { if (list[i].transitions[j].input != "") { graph.AddEdge(list[i].name, list[i].transitions[j].input, list[i].transitions[j].nextState.name); } if (list[i].isFinalState == true) { Microsoft.Msagl.Drawing.Node c = graph.FindNode(list[i].name); c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; } } } viewer.Graph = graph; form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); form.ShowDialog(); }
private void gViewer_MouseUp(object sender, MouseEventArgs e) { if (InteractiveMode == InteractiveMode.NonInteractive) { return; } if (mouseDownPosition == e.Location) { if (gViewer.SelectedObject is Microsoft.Msagl.Drawing.Node) { if (InteractiveMode == InteractiveMode.OnlyEdges) { return; } Microsoft.Msagl.Drawing.Node node = gViewer.SelectedObject as Microsoft.Msagl.Drawing.Node; int vertexIndex = int.Parse(node.Id) - 1; VertexSelectedEvent?.Invoke(Graph.Vertices[vertexIndex]); } else if (gViewer.SelectedObject is Microsoft.Msagl.Drawing.Edge) { if (InteractiveMode == InteractiveMode.OnlyVertices) { return; } Microsoft.Msagl.Drawing.Edge edge = gViewer.SelectedObject as Microsoft.Msagl.Drawing.Edge; int sourceIndex = int.Parse(edge.Source) - 1; int targetIndex = int.Parse(edge.Target) - 1; EdgeSelectedEvent?.Invoke(Graph.GetEdge(sourceIndex, targetIndex)); } } mouseDownPosition = Point.Empty; }
public static void Main() { //create a form System.Windows.Forms.Form form = new System.Windows.Forms.Form(); //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content graph.AddEdge("A", "B"); graph.AddEdge("B", "C"); graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); viewer.MouseUp += Viewer_MouseUp; //show the form form.ShowDialog(); }
/** * Metode untuk mewarnai sebuah simpul */ private void ColorNode(String node, Color color) { MSAGLNode Copy = G.FindNode(node); Copy.Attr.FillColor = color; this.gViewer.Graph = G; }
public static Path Update(this Path nodeBoundary, DrawingNode drawingNode) { switch (drawingNode.Attr.Shape) { case DrawingShape.Box: case DrawingShape.House: case DrawingShape.InvHouse: case DrawingShape.Diamond: case DrawingShape.Octagon: case DrawingShape.Hexagon: nodeBoundary.Data = ConvertMsaglCurveToPathGeometry(drawingNode.GeometryNode.BoundaryCurve); break; case DrawingShape.DoubleCircle: nodeBoundary.Data = ConvertMsaglRectangleToDoubleCirclePathGeometry(drawingNode.BoundingBox); break; default: nodeBoundary.Data = ConvertMsaglRectangleToEllipseGeometry(drawingNode.BoundingBox); break; } nodeBoundary.Stroke = drawingNode.Attr.Color.ToWpf(); nodeBoundary.Fill = drawingNode.Attr.FillColor.ToWpf(); return(nodeBoundary); }
private void show_path_animate(object sender, EventArgs e) { if (isAnim && path.Count > 0) { Microsoft.Msagl.Drawing.Node tempNode = viewer.Graph.FindNode(path[0].getID().ToString()); tempNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; tempNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Cyan; if (path.Count > 1) { Tuple <int, int> key = new Tuple <int, int>(path[0].getID() - 1, path[1].getID() - 1); Tuple <int, int> keyInv = new Tuple <int, int>(key.Item2, key.Item1); if (dictEdge.ContainsKey(key)) { dictEdge[key].Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { if (dictEdge.ContainsKey(keyInv)) { dictEdge[keyInv].Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } } path.RemoveAt(0); } else { path.Clear(); isAnim = false; } } this.Refresh(); }
private void reset_color_path() { //Ganti semua shape path hasil query sebelumnya jadi normal lagi for (int i = 0; i < lastPath.Count; i++) { Microsoft.Msagl.Drawing.Node tempNode = viewer.Graph.FindNode(lastPath[i].getID().ToString()); tempNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; tempNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Transparent; if (i < lastPath.Count - 1) { Tuple <int, int> key = new Tuple <int, int>(lastPath[i].getID() - 1, lastPath[i + 1].getID() - 1); Tuple <int, int> keyInv = new Tuple <int, int>(key.Item2, key.Item1); if (dictEdge.ContainsKey(key)) { dictEdge[key].Attr.Color = Microsoft.Msagl.Drawing.Color.Black; } else { if (dictEdge.ContainsKey(keyInv)) { dictEdge[keyInv].Attr.Color = Microsoft.Msagl.Drawing.Color.Black; } } } } lastPath.Clear(); this.Refresh(); }
private void Form1_Load(object sender, EventArgs e) { viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); viewer.CurrentLayoutMethod = Microsoft.Msagl.GraphViewerGdi.LayoutMethod.UseSettingsOfTheGraph; Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); graph.LayoutAlgorithmSettings = new Microsoft.Msagl.Layout.MDS.MdsLayoutSettings(); foreach (Edge E in G.allEdge) { graph.AddEdge((E.getFrom() + 1).ToString(), (E.getTo() + 1).ToString()); } viewer.Graph = graph; foreach (var E in viewer.Graph.Edges) { Tuple <int, int> key = new Tuple <int, int>(Int32.Parse(E.Source) - 1, Int32.Parse(E.Target) - 1); dictEdge.Add(key, E); E.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; } viewer.ToolBarIsVisible = false; viewer.PanButtonPressed = true; Microsoft.Msagl.Drawing.Node nodeRaja = viewer.Graph.FindNode("1"); if (nodeRaja != null) { nodeRaja.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; nodeRaja.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Fuchsia; } viewer.Size = new Size(780, 500); viewer.Location = new Point(0, 0); this.Controls.Add(viewer); foreach (Command C in LC) { this.query_file_list.Items.Add(C.getApproach().ToString() + " " + C.getX().ToString() + " " + C.getY().ToString()); } }
private Microsoft.Msagl.Drawing.Graph BFSHandler() { string[] testspek = File.ReadAllLines(textBox1.Text); List <string> filenodes = BacaFile.getNodes(testspek); bool[,] adjMatrix = BacaFile.getAdjMatrix(testspek, filenodes); List <string> BFSpath = BFS.FindPathBFS(filenodes, adjMatrix, comboBox1.Text, comboBox2.Text); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); graph = getPlainGraph(BFSpath); Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); for (int i = 0; i < BFSpath.Count - 1; i++) { Microsoft.Msagl.Drawing.Node source = graph.FindNode(BFSpath[i]); Microsoft.Msagl.Drawing.Node target = graph.FindNode(BFSpath[i + 1]); source.Attr.FillColor = Microsoft.Msagl.Drawing.Color.GreenYellow; var edge = graph.AddEdge(BFSpath[i], BFSpath[i + 1]); edge.Attr.Color = Microsoft.Msagl.Drawing.Color.GreenYellow; edge.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; if (i == BFSpath.Count - 2) { target.Attr.FillColor = Microsoft.Msagl.Drawing.Color.GreenYellow; } } return(graph); }
private void stage_1_Entities_Identification_Click(object sender, EventArgs e) { Form form = new System.Windows.Forms.Form(); form.Text = "Stage-1 Reverse Engineer : Entities"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content foreach (Relation rel in _masterListRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(rel.relationName); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; graph.AddNode(newNode); } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.Size = new Size(500, 500); form.ResumeLayout(); //show the form form.Show(); }
/// <summary> /// Adds a graph layout constraint /// </summary> /// <param name="n1">id node 1</param> /// <param name="n2">id node 2</param> /// <param name="node1">node object 1</param> /// <param name="node2">node object 2</param> /// <param name="graph">graph object</param> /// <param name="useCase">use case object</param> private void AddLayerConstraint(int n1, int n2, Microsoft.Msagl.Drawing.Node node1, Microsoft.Msagl.Drawing.Node node2, Microsoft.Msagl.Drawing.Graph graph, UseCase useCase) { if (useCase.Nodes[n1].Identifier.Id == useCase.Nodes[n2].Identifier.Id && useCase.Nodes[n1].Identifier.Type == FlowType.Basic && useCase.Nodes[n2].Identifier.Type == FlowType.Basic && n1 < n2) { graph.LayerConstraints.AddSequenceOfUpDownVerticalConstraint(node1, node2); } }
/// <summary> /// Displays the edge condition /// </summary> /// <param name="n1">id node 1</param> /// <param name="n2">id node 2</param> /// <param name="node1">node object 1</param> /// <param name="node2">node object 2</param> /// <param name="edge">edge object</param> /// <param name="useCase">use case object</param> private void DisplayEdgeCondition(int n1, int n2, Microsoft.Msagl.Drawing.Node node1, Microsoft.Msagl.Drawing.Node node2, Microsoft.Msagl.Drawing.Edge edge, UseCase useCase) { UseCaseCore.UcIntern.Condition condition = useCase.ConditionMatrix[n1, n2] ?? new UseCaseCore.UcIntern.Condition(); if (this.displayGraphConditions && condition.ConditionText != null) { edge.LabelText = condition.ConditionText + " is " + condition.ConditionState; edge.Label.FontSize = node1.Label.FontSize / 2; edge.Label.FontColor = node1.Attr.FillColor; } }
private Microsoft.Msagl.Drawing.Graph CreateGraph( AdminShellPackageEnv env, AdminShell.Submodel sm, GenericBomCreatorOptions options) { // access if (env == null || sm == null || options == null) { return(null); } //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("BOM-graph"); #if FALSE //create the graph content graph.AddEdge("A", "B"); var e1 = graph.AddEdge("B", "C"); // e1.LabelText = "Dumpf!"; e1.LabelText = "hbhbjhbjhb"; // e1.Label = new Microsoft.Msagl.Drawing.Label("Dumpf!!"); graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); graph.FindNode("B").LabelText = "HalliHallo"; c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; c.Label.FontSize = 28; #else var creator = new GenericBomCreator( env?.AasEnv, _bomRecords, options); using (var tw = new StreamWriter("bomgraph.log")) { creator.RecurseOnLayout(1, graph, null, sm.submodelElements, 1, tw); creator.RecurseOnLayout(2, graph, null, sm.submodelElements, 1, tw); creator.RecurseOnLayout(3, graph, null, sm.submodelElements, 1, tw); } // make default or (already) preferred settings var settings = GivePresetSettings(options.LayoutIndex); if (this.preferredPresetIndex != null && this.preferredPresetIndex.ContainsKey(sm)) { settings = GivePresetSettings(this.preferredPresetIndex[sm]); } if (settings != null) { graph.LayoutAlgorithmSettings = settings; } #endif return(graph); }
public static TextBlock UpdateFrom(this TextBlock textBlock, DrawingNode drawingNode) { Debug.Assert(textBlock.Dispatcher.CheckAccess()); var tmp = textBlock.UpdateFrom(drawingNode.Label); tmp.Width = drawingNode.Width; tmp.Height = drawingNode.Height; tmp.Margin = new Thickness(drawingNode.Attr.LabelMargin); return(textBlock); }
/// <summary> /// Set the style of a graph node /// </summary> /// <param name="node">the microsoft drawing node</param> /// <param name="nodeTitle">the node title</param> /// <param name="flowId">the flow id</param> private static void SetNodeStyle(Microsoft.Msagl.Drawing.Node node, string nodeTitle, int flowId) { var backgroundColor = GetNodeColor(nodeTitle, flowId); var backgroundHex = MaterialDesignColors.MsaglColorToHex(backgroundColor); var foregroundHex = MaterialDesignColors.GetForegroundColor(backgroundHex); var foregroundColor = MaterialDesignColors.MsaglColorFromHex(foregroundHex); node.Attr.FillColor = backgroundColor; node.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; node.Attr.Color = MaterialDesignColors.MsaglColorFromHex(MaterialDesignColors.White); node.Label.FontColor = foregroundColor; node.Label.FontSize = 10; }
private static void SetNodeBoundary(Microsoft.Msagl.Drawing.Node drawingNode) { var font = new System.Drawing.Font(drawingNode.Label.FontName, (float)drawingNode.Label.FontSize); StringMeasure.MeasureWithFont(drawingNode.LabelText, font, out double width, out double height); drawingNode.Label.GeometryLabel = new Microsoft.Msagl.Core.Layout.Label(); drawingNode.Label.GeometryLabel.Width = width; drawingNode.Label.GeometryLabel.Height = width; drawingNode.Label.Width = width; drawingNode.Label.Height = height; int r = drawingNode.Attr.LabelMargin; drawingNode.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(width + r * 2, height + r * 2, r, r, new Point()); }
private void ArchitectureGraphRefresh() { foreach (string nodeName in ArchitectureGraphAccessor.nodeList) { architectureGraph.RemoveNode(architectureGraph.FindNode(nodeName)); } //foreach (string key in simulator.LayerList.Keys) //{ // architectureGraph.AddEdge(simulator.LayerList[key].Name + "Bias", simulator.LayerList[key].Name); // Microsoft.Msagl.Drawing.Node biasNode = architectureGraph.FindNode(simulator.LayerList[key].Name + "Bias"); // biasNode.LabelText = ""; //} foreach (string key in simulator.BundleList.Keys) { architectureGraph.AddEdge(simulator.BundleList[key].SendLayer.Name, simulator.BundleList[key].ReceiveLayer.Name); ArchitectureGraphAccessor.nodeList.Add(simulator.BundleList[key].SendLayer.Name); ArchitectureGraphAccessor.nodeList.Add(simulator.BundleList[key].ReceiveLayer.Name); Microsoft.Msagl.Drawing.Node sendLayerNode = architectureGraph.FindNode(simulator.BundleList[key].SendLayer.Name); sendLayerNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; sendLayerNode.Attr.LabelMargin = 10; Microsoft.Msagl.Drawing.Node receiveLayerNode = architectureGraph.FindNode(simulator.BundleList[key].ReceiveLayer.Name); receiveLayerNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; receiveLayerNode.Attr.LabelMargin = 10; } foreach (string key in simulator.LayerList.Keys) { if (simulator.LayerList[key].LayerType == LayerType.BPTTLayer) { BPTTLayer selectedBPTTLayer = (BPTTLayer)simulator.LayerList[key]; //Microsoft.Msagl.Drawing.Edge TickInEdge = architectureGraph.AddEdge(selectedBPTTLayer.Name, selectedBPTTLayer.Name + " 0 Tick"); for (int i = 0; i < selectedBPTTLayer.Tick; i++) { architectureGraph.AddEdge(selectedBPTTLayer.Name, selectedBPTTLayer.Name + " " + i.ToString() + " Tick").Attr.AddStyle(Microsoft.Msagl.Drawing.Style.Dotted); architectureGraph.AddEdge(selectedBPTTLayer.Name + " " + i.ToString() + " Tick", selectedBPTTLayer.Name + " " + (i + 1).ToString() + " Tick"); ArchitectureGraphAccessor.nodeList.Add(selectedBPTTLayer.Name); ArchitectureGraphAccessor.nodeList.Add(selectedBPTTLayer.Name + " " + i.ToString() + " Tick"); ArchitectureGraphAccessor.nodeList.Add(selectedBPTTLayer.Name + " " + (i + 1).ToString() + " Tick"); } Microsoft.Msagl.Drawing.Edge TickOutEdge = architectureGraph.AddEdge(selectedBPTTLayer.Name + " " + selectedBPTTLayer.Tick.ToString() + " Tick", selectedBPTTLayer.Name); //TickInEdge.Attr.AddStyle(Microsoft.Msagl.Drawing.Style.Dotted); TickOutEdge.Attr.AddStyle(Microsoft.Msagl.Drawing.Style.Dotted); } } ArchitectureGraphAccessor.architectureGraphViewer.Graph = ArchitectureGraphAccessor.architectureGraph; }
private void Viewer_Click(object sender, EventArgs e) { Microsoft.Msagl.GraphViewerGdi.GViewer viewer = sender as Microsoft.Msagl.GraphViewerGdi.GViewer; if (viewer.SelectedObject is Microsoft.Msagl.Drawing.Node) { Microsoft.Msagl.Drawing.Node node = viewer.SelectedObject as Microsoft.Msagl.Drawing.Node; MessageBox.Show($"Это вершина {node.Attr.Id}"); } else if (viewer.SelectedObject is Microsoft.Msagl.Drawing.Edge) { Microsoft.Msagl.Drawing.Edge edge = viewer.SelectedObject as Microsoft.Msagl.Drawing.Edge; MessageBox.Show($"Это дуга {edge.Source}-{edge.Target}"); } }
private void AddFileInfoGraphNodes(FileInfo fileInfo, Microsoft.Msagl.Drawing.Graph graph, List <FileInfo> PrevNodes) { if (PrevNodes.Contains(fileInfo)) { return; } if (fileInfo.Imports.Count != 0) { foreach (DGFileImport import in fileInfo.Imports) { Microsoft.Msagl.Drawing.Node n = graph.FindNode(fileInfo.FileName); bool addEdge = true; if (n != null) { foreach (Microsoft.Msagl.Drawing.Edge e in n.OutEdges) { if (e.Target == import.File.FileName) { addEdge = false; } } } if (addEdge) { graph.AddEdge(fileInfo.FileName, import.File.FileName); } List <FileInfo> NewPrevNodes = new List <FileInfo>(PrevNodes); NewPrevNodes.Add(fileInfo); AddFileInfoGraphNodes(import.File, graph, NewPrevNodes); } } else { graph.AddNode(fileInfo.FileName); } Microsoft.Msagl.Drawing.Color c = Microsoft.Msagl.Drawing.Color.White; switch (System.IO.Path.GetExtension(fileInfo.FileName).ToLower()) { case ".dll": c = Microsoft.Msagl.Drawing.Color.LightBlue; break; case ".exe": c = Microsoft.Msagl.Drawing.Color.LightGreen; break; } graph.FindNode(fileInfo.FileName).Attr.FillColor = c; }
private void DrawWeakEntities() { Form form = new Form(); form.Text = "Stage-3 Reverse Engineer : Foreign_Keys"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content // Draw all the entitites foreach (Relation rel in _masterListRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(rel.relationName); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; //Add it to the graph graph.AddNode(newNode); } //Draw all the weak Entities foreach (Tuple <string, string> weakEnt in weakEntities) { graph.AddNode(weakEnt.Item1).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Ellipse; graph.AddEdge(weakEnt.Item1, weakEnt.Item2); } //Draw all the other relations foreach (Tuple <string, string> rel in foreignKeyRelations) { Tuple <string, string> find = weakEntities.Find(obj => (obj.Item1 == rel.Item1 && obj.Item2 == rel.Item2) || (obj.Item2 == rel.Item1 && obj.Item1 == rel.Item2)); if (find == null) { graph.AddEdge(rel.Item1, rel.Item2); } } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.Show(); }
// Menampilkan visualisasi graph pada gviewer MSAGL private void visualizeGraph() { g1 = new GraphOfRelation(); listNode = new HashSet <string>(); // Algoritma Membaca Text File string line; List <string[]> lisString = new List <string[]>(); using (StringReader reader = new StringReader(txt_box_isi_file.Text)) { line = reader.ReadLine(); // SKip Line 1 while ((line = reader.ReadLine()) != null) { if (!line.Equals("")) { lisString.Add(line.Split(' ')); } } } //create a graph object Microsoft.Msagl.Drawing.Graph graph2 = new Microsoft.Msagl.Drawing.Graph("graph"); // Mengassign Graph dari Text (lisString) foreach (var str in lisString) { g1.addRelation(str); graph2.AddEdge(str[0], str[1]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; listNode.Add(str[0]); listNode.Add(str[1]); } // Mengubah design visualiasi graph foreach (var node in listNode) { if (!comboBox1.Items.Contains(node)) { comboBox1.Items.Add(node); } Microsoft.Msagl.Drawing.Node temp = graph2.FindNode(node); temp.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Ellipse; temp.Attr.FillColor = Microsoft.Msagl.Drawing.Color.SteelBlue; temp.Label.FontColor = Microsoft.Msagl.Drawing.Color.White; } // Menampilkan Graph MSAGL gViewer1.Graph = graph2; }
public static void visualExplore(Graph G, List <string> path) { // Membuat objek graf Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); // Membuat isi graf foreach (Node person in G.persons) { foreach (string friend in person.friends) { // Karena graf tidak punya arah maka a berteman dengan b , lalu b juga berteman dengan a // Untuk mencegah duplikasi edge, maka print edge dari graf yang namanya < nama temannnya if (String.CompareOrdinal(person.name, friend) < 0) { var edge = graph.AddEdge(person.name, friend); // Hilangkan panah pada graf edge.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; edge.Attr.ArrowheadAtSource = Microsoft.Msagl.Drawing.ArrowStyle.None; if (path.Contains(friend) && path.Contains(person.name)) { // Cek apakah edge yang sedang dibuat merupakan salah satu path untuk explore friend // Jika iya maka tambahkan beberapa properti ke edge dan node yang bersangkutan if (Math.Abs(path.IndexOf(person.name) - path.IndexOf(friend)) == 1) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Crimson; edge.Attr.LineWidth = 2; Microsoft.Msagl.Drawing.Node p1 = graph.FindNode(person.name); Microsoft.Msagl.Drawing.Node p2 = graph.FindNode(friend); p1.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Crimson; p2.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Crimson; p1.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Octagon; p2.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Octagon; p1.Attr.LineWidth = 2; p2.Attr.LineWidth = 2; } } } } } // Memasukkan graf ke viewer ExploreGraph.Graph = graph; ExploreGraph.Dock = System.Windows.Forms.DockStyle.Fill; }
public GraphTestForm() { InitializeComponent(); Microsoft.Msagl.Drawing.Graph g1 = new Microsoft.Msagl.Drawing.Graph("g1"); g1.AddNode("elo"); g1.AddNode("gitara"); g1.AddNode("siema"); g1.AddEdge("elo", "0", "gitara"); g1.AddEdge("gitara", "0", "siema"); Microsoft.Msagl.Drawing.Node n = g1.FindNode("siema"); n.Attr.FillColor = Color.Blue; Microsoft.Msagl.Drawing.Graph g2 = new Microsoft.Msagl.Drawing.Graph("g2"); foreach (var node in g1.Nodes) { g2.AddNode(node); } gViewer1.Graph = g2; }
public MainForm() { // Из NuGet подтянуть: // Microsoft.Msagl // Microsoft.Msagl.GraphViewerGDI InitializeComponent(); // ПРИМЕР 1 //create a viewer object viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //viewer.ToolBarIsVisible = false; //create a graph object graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content graph.Directed = false; graph.Attr.BackgroundColor = Microsoft.Msagl.Drawing.Color.Green; graph.AddEdge("A", "B").Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; graph.AddEdge("B", "C").LabelText = "Я метка!"; graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; graph.FindNode("A").Attr.Color = Microsoft.Msagl.Drawing.Color.BlueViolet; graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; //c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; foreach (var node in graph.Nodes) { node.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form this.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; tableLayoutPanel1.Controls.Add(viewer, 0, 0); this.ResumeLayout(); viewer.Click += Viewer_Click; //viewer.ObjectUnderMouseCursorChanged += Viewer_Click; }
private void DrawForeignKeys() { Form form = new Form(); form.Text = "Stage-2 Reverse Engineer : Foreign_Keys"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content foreach (Tuple <string, string> tup in foreignKeyRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(tup.Item1); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; graph.AddNode(newNode); Microsoft.Msagl.Drawing.Node newNode2 = new Microsoft.Msagl.Drawing.Node(tup.Item2); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; graph.AddNode(newNode2); graph.AddEdge(tup.Item1, tup.Item2); } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.Show(); }
Microsoft.Msagl.Drawing.Graph ComputeAndDisplayGraph(string DotString, bool IsCellular) { int CurrentPos = 0; int NextReturnPos = CurrentPos; List<int> ListNodeId = new List<int>(); string TmpDotString = DotString; Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); while (NextReturnPos != -1) { int NextBracket = DotString.IndexOf("["); string StringToProcess = DotString.Remove(NextBracket - 1); string StringToProcess1 = StringToProcess.Remove(0, 1); if (StringToProcess1.Contains("N") == false) { int Id = Convert.ToInt32(StringToProcess1); Microsoft.Msagl.Drawing.Node Currentnode = new Microsoft.Msagl.Drawing.Node(Id.ToString()); Currentnode.Label.FontColor = Microsoft.Msagl.Drawing.Color.Red; int LabelPos = DotString.IndexOf("label=\""); string LabelString = DotString.Remove(0, LabelPos + 7); LabelPos = LabelString.IndexOf("\""); string FinalLabel = LabelString.Remove(LabelPos); Currentnode.LabelText = FinalLabel; if (IsCellular && (FinalLabel[FinalLabel.Length - 1] == ')') && (FinalLabel.Contains('('))) // that's a leaf { int LastBracket = FinalLabel.LastIndexOf('('); string LeafName = FinalLabel.Remove(LastBracket - 1); cCellularPhenotype CP = cGlobalInfo.ListCellularPhenotypes.FindFromName(LeafName); if (CP != null) { Currentnode.Attr.FillColor = new Microsoft.Msagl.Drawing.Color(CP.ColourForDisplay.R, CP.ColourForDisplay.G, CP.ColourForDisplay.B); } } graph.AddNode(Currentnode); } NextReturnPos = DotString.IndexOf("\n"); if (NextReturnPos != -1) { string TmpString = DotString.Remove(0, NextReturnPos + 1); DotString = TmpString; } } DotString = TmpDotString; NextReturnPos = 0; while (NextReturnPos != -1) { int NextBracket = DotString.IndexOf("["); string StringToProcess = DotString.Remove(NextBracket - 1); string StringToProcess1 = StringToProcess.Remove(0, 1); if (StringToProcess1.Contains("N")) { string stringNodeIdxStart = StringToProcess1.Remove(StringToProcess1.IndexOf("-")); int NodeIdxStart = Convert.ToInt32(stringNodeIdxStart); string stringNodeIdxEnd = StringToProcess1.Remove(0, StringToProcess1.IndexOf("N") + 1); int NodeIdxSEnd = Convert.ToInt32(stringNodeIdxEnd); int LabelPos = DotString.IndexOf("label="); LabelPos += 7; string CurrLabelString = DotString.Remove(0, LabelPos); Microsoft.Msagl.Drawing.Edge Currentedge = new Microsoft.Msagl.Drawing.Edge(stringNodeIdxStart, ""/*NodeIdx.ToString()*/, stringNodeIdxEnd); Currentedge.LabelText = CurrLabelString.Remove(CurrLabelString.IndexOf("]") - 1); graph.Edges.Add(Currentedge); } NextReturnPos = DotString.IndexOf("\n"); if (NextReturnPos != -1) { string TmpString = DotString.Remove(0, NextReturnPos + 1); DotString = TmpString; } } return graph; }
private void stage_1_Entities_Identification_Click(object sender, EventArgs e) { Form form = new System.Windows.Forms.Form(); form.Text = "Stage-1 Reverse Engineer : Entities"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content foreach(Relation rel in _masterListRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(rel.relationName); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; graph.AddNode(newNode); } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.Size = new Size(500, 500); form.ResumeLayout(); //show the form form.Show(); }
private void DrawRelations() { Form form = new Form(); form.Text = "Stage-4 Reverse Engineer : Relations"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content // Draw all the entitites foreach (Relation rel in _masterListRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(rel.relationName); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; //Add it to the graph graph.AddNode(newNode); } //Draw all the weak Entities foreach (Tuple<string, string> weakEnt in weakEntities) { graph.AddNode(weakEnt.Item1).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Ellipse; graph.AddEdge(weakEnt.Item1, weakEnt.Item2); } int relIndex = 1; //Draw all the other relations foreach (Tuple<string, string> rel in foreignKeyRelations) { Tuple<string, string> find = weakEntities.Find(obj => (obj.Item1 == rel.Item1 && obj.Item2 == rel.Item2) || (obj.Item2 == rel.Item1 && obj.Item1 == rel.Item2)); if (find == null) { string intermediateRel = "R" + relIndex; graph.AddNode(intermediateRel); graph.AddNode(intermediateRel).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; graph.AddEdge(rel.Item1, intermediateRel); graph.AddEdge(intermediateRel, rel.Item2); relIndex++; } } //Draw the relations as Diamonds foreach(Tuple<string, List<string>> tup in relations) { graph.AddNode(tup.Item1).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; } foreach(string s in multiValuedAttr) { graph.AddNode(s).Attr.Shape = Microsoft.Msagl.Drawing.Shape.DoubleCircle; } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.Show(); }
private void DrawWeakEntities() { Form form = new Form(); form.Text = "Stage-3 Reverse Engineer : Foreign_Keys"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content // Draw all the entitites foreach(Relation rel in _masterListRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(rel.relationName); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; //Add it to the graph graph.AddNode(newNode); } //Draw all the weak Entities foreach(Tuple<string, string> weakEnt in weakEntities) { graph.AddNode(weakEnt.Item1).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Ellipse; graph.AddEdge(weakEnt.Item1, weakEnt.Item2); } //Draw all the other relations foreach(Tuple<string, string> rel in foreignKeyRelations) { Tuple<string, string> find = weakEntities.Find(obj => (obj.Item1 == rel.Item1 && obj.Item2 == rel.Item2) || (obj.Item2 == rel.Item1 && obj.Item1 == rel.Item2)); if(find == null) { graph.AddEdge(rel.Item1, rel.Item2); } } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.Show(); }
private void DrawForeignKeys() { Form form = new Form(); form.Text = "Stage-2 Reverse Engineer : Foreign_Keys"; //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content foreach (Tuple<string,string> tup in foreignKeyRelations) { Microsoft.Msagl.Drawing.Node newNode = new Microsoft.Msagl.Drawing.Node(tup.Item1); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; graph.AddNode(newNode); Microsoft.Msagl.Drawing.Node newNode2 = new Microsoft.Msagl.Drawing.Node(tup.Item2); newNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; graph.AddNode(newNode2); graph.AddEdge(tup.Item1, tup.Item2); } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.Show(); }
void EditNodeNormal(Microsoft.Msagl.Drawing.Graph graphs, string name) // Mengubah atribut sebuah simpul untuk menjadi simpul normal { Microsoft.Msagl.Drawing.Node find = graphs.FindNode(name); find.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; find.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; }
void EditNodeAccount(Microsoft.Msagl.Drawing.Graph graphs, string name) // Mengubah atribut sebuah simpul untuk menunjukkan akun saat ini { Microsoft.Msagl.Drawing.Node find = graphs.FindNode(name); find.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Yellow; find.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; }
void EditNodeFind(Microsoft.Msagl.Drawing.Graph graphs, string name) // Mengubah atribut sebuah simpul untuk menunjukkan simpul tujuan { Microsoft.Msagl.Drawing.Node find = graphs.FindNode(name); find.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; find.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; }
void EditNodeConnection(Microsoft.Msagl.Drawing.Graph graphs, string name) // Mengubah atribut sebuah simpul untuk menunjukkan menambahkan koneksi { Microsoft.Msagl.Drawing.Node find = graphs.FindNode(name); find.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGreen; find.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; }
private Microsoft.Msagl.Drawing.Graph ComputeAndDisplayGraph(string DotString) { int CurrentPos = 0; int NextReturnPos = CurrentPos; List<int> ListNodeId = new List<int>(); string TmpDotString = DotString; Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); while (NextReturnPos != -1) { int NextBracket = DotString.IndexOf("["); string StringToProcess = DotString.Remove(NextBracket - 1); string StringToProcess1 = StringToProcess.Remove(0, 1); if (StringToProcess1.Contains("N") == false) { int Id = Convert.ToInt32(StringToProcess1); Microsoft.Msagl.Drawing.Node Currentnode = new Microsoft.Msagl.Drawing.Node(Id.ToString()); Currentnode.Label.FontColor = Microsoft.Msagl.Drawing.Color.Red; int LabelPos = DotString.IndexOf("label=\""); string LabelString = DotString.Remove(0, LabelPos + 7); LabelPos = LabelString.IndexOf("\""); string FinalLabel = LabelString.Remove(LabelPos); Currentnode.LabelText = FinalLabel; graph.AddNode(Currentnode); } NextReturnPos = DotString.IndexOf("\n"); if (NextReturnPos != -1) { string TmpString = DotString.Remove(0, NextReturnPos + 1); DotString = TmpString; } } DotString = TmpDotString; NextReturnPos = 0; while (NextReturnPos != -1) { int NextBracket = DotString.IndexOf("["); string StringToProcess = DotString.Remove(NextBracket - 1); string StringToProcess1 = StringToProcess.Remove(0, 1); if (StringToProcess1.Contains("N")) { string stringNodeIdxStart = StringToProcess1.Remove(StringToProcess1.IndexOf("-")); int NodeIdxStart = Convert.ToInt32(stringNodeIdxStart); string stringNodeIdxEnd = StringToProcess1.Remove(0, StringToProcess1.IndexOf("N") + 1); int NodeIdxSEnd = Convert.ToInt32(stringNodeIdxEnd); int LabelPos = DotString.IndexOf("label="); LabelPos += 7; string CurrLabelString = DotString.Remove(0, LabelPos); Microsoft.Msagl.Drawing.Edge Currentedge = new Microsoft.Msagl.Drawing.Edge(stringNodeIdxStart, ""/*NodeIdx.ToString()*/, stringNodeIdxEnd); Currentedge.LabelText = CurrLabelString.Remove(CurrLabelString.IndexOf("]") - 1); graph.Edges.Add(Currentedge); } NextReturnPos = DotString.IndexOf("\n"); if (NextReturnPos != -1) { string TmpString = DotString.Remove(0, NextReturnPos + 1); DotString = TmpString; } } return graph; }