/// <summary> /// Desenha o grafo atual. /// </summary> private void DrawGraph(EDA.Graph graphToDraw, EDA.Node[] highlightedNodes) { List <EDA.Edge> edges = new List <EDA.Edge>(); Glee.Graph drawingGraph = new Glee.Graph("Grafo - EDA2"); // Adiciona nós ao grafo.. foreach (EDA.Node node in graphToDraw.Nodes) { Glee.Node drawingNode = drawingGraph.AddNode(node.Name); drawingNode.Attr.Shape = Glee.Shape.Circle; if (highlightedNodes != null && Array.IndexOf(highlightedNodes, node) >= 0) { drawingNode.Attr.Color = Glee.Color.Red; } // Consolida os arcos.. edges.AddRange(node.Edges); } foreach (EDA.Edge edge in edges) { Glee.Edge drawingEdge = drawingGraph.AddEdge(edge.From.Name, edge.To.Name); drawingEdge.Attr.Label = String.Format("{0:F4}", edge.Cost); } // Gera controle de desenho.. GleeUI.GViewer viewer = new GleeUI.GViewer(); viewer.NavigationVisible = false; viewer.OutsideAreaBrush = Brushes.White; viewer.RemoveToolbar(); viewer.Graph = drawingGraph; viewer.Dock = System.Windows.Forms.DockStyle.Fill; pnlGraph.Controls.Clear(); pnlGraph.Controls.Add(viewer); }
private GD.Graph CreateGraph() { GD.Graph result = new GD.Graph(_id); // Hang onto the name of the active item for SetGraph. if (_activeItem != null) { result.UserData = _activeItem.Name; } result.GraphAttr.NodeAttr.FontName = "Microsoft Sans Serif"; result.GraphAttr.NodeAttr.Fontsize = 8; result.GraphAttr.NodeAttr.Shape = GD.Shape.Box; result.GraphAttr.NodeAttr.Fillcolor = GD.Color.WhiteSmoke; result.GraphAttr.EdgeAttr.FontName = "Tahoma"; result.GraphAttr.EdgeAttr.Fontsize = 8; result.GraphAttr.AspectRatio = _ratio; if (_options.LeftToRight) { result.GraphAttr.LayerDirection = GD.LayerDirection.LR; } else { result.GraphAttr.LayerDirection = GD.LayerDirection.TB; } return(result); }
public static void printDirectGraph(int[][] graphMatrix, int[][] basicGraph, int numberOfVertics) { Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); for (int i = 0; i < numberOfVertics; i++) { for (int j = 0; j < i; j++) { if ((basicGraph[j][i] > 0) && graphMatrix[i][j] > 0) { Edge e = graph.AddEdge("Node" + (j + 1), "Node" + (i + 1)); e.EdgeAttr.Label = graphMatrix[i][j].ToString() + "/" + basicGraph[j][i]; e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Green; } } } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form maxFlowform.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; maxFlowform.Controls.Add(viewer); maxFlowform.ResumeLayout(); //show the form maxFlowform.Show(); }
public static Microsoft.Glee.Drawing.Graph clacuMst(int[][] graphMatrix, int minNode, Microsoft.Glee.Drawing.Graph graph1) { //create a graph object // Microsoft.Glee.Drawing.Graph graph = graph1; Node n1 = tempGraph.FindNode("Node" + (minNode + 1)); foreach (Edge e in n1.OutEdges) { e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Green; } //bind the graph to the viewer viewer.Graph = tempGraph; //associate the viewer with the form mstForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; mstForm.Controls.Add(viewer); mstForm.ResumeLayout(); //show the form mstForm.Show(); return(tempGraph); }
// ketika button 'Generate' diklik, membangun graf dari hasil bacaan file private void button2_Click(object sender, EventArgs e) { // membuat objek graf Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); // membuat isi graf int numberOfNodes = Convert.ToInt32(richTextBox1.Lines[0]); _n = numberOfNodes; Init(_n); // inisialisasi graf string[] edge; for (int i = 1; i < _n; i++) // baca input graf dari richTextBox1 { edge = richTextBox1.Lines[i].Split(' '); _x = Convert.ToInt32(edge[0]); _y = Convert.ToInt32(edge[1]); // membangun sisi graph.AddEdge(edge[0], edge[1]); Node node = graph.FindNode(edge[0]); // graf berbentuk lingkaran node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle; node = graph.FindNode(edge[1]); // membuat adjecent list Ukuran[_x] += 1; L[_x].Add(_y); // graf berbentuk lingkaran node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle; // menghilangkan panah graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None; } ; // graf dimasukkan ke viewer gViewer1.Graph = graph; }
public static void printGraph(int[][] graphMatrix, int numberOfVertex, Form form) { //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); for (int i = 0; i < numberOfVertex; i++) { for (int j = 0; j < numberOfVertex; j++) { if (graphMatrix[i][j] > 0) { Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1)); e.EdgeAttr.Label = graphMatrix[i][j].ToString(); } } } //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(); //show the form form.Show(); }
private void primsButton_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Do Not Close The Window Of Solution to solve Many Graph"); mst = new MST(graph_matrix, VerticsNum); mstForm = new MstViewer(mst); MainWindow.tempGraph = new Graph("graph"); MainWindow.tempGraph = mstPrintGraph(graph_matrix, mst.numberOfVertics); int i = 1; }
public void Draw() { UndirectedGraph <Vertex, QuickGraph.Edge <Vertex> > mG = new UndirectedGraph <Vertex, QuickGraph.Edge <Vertex> >(); List <Vertex> .Enumerator etV = mGraph.mVertices.GetEnumerator(); while (etV.MoveNext()) { mG.AddVertex(etV.Current); } List <Edge> .Enumerator etE = mGraph.mEdges.GetEnumerator(); while (etE.MoveNext()) { QuickGraph.Edge <Vertex> e = new Edge <Vertex>(etE.Current.mVertexA, etE.Current.mVertexB); mG.AddEdge(e); } Console.WriteLine("QUICK GRAPH FORMAT:"); Console.WriteLine(mG.VertexCount); Console.WriteLine(mG.EdgeCount); /* * var graphviz = new GraphvizAlgorithm<Vertex, Edge<Vertex>>(mG); * string output = graphviz.Generate(new FileDotEngine(), "graph"); * * Console.WriteLine("OUTPUT"); * Console.WriteLine(output); * * // Process drawProcess = new Process(); * Process.Start("dot","-Tpng graph.dot > graph.png"); */ var populator = GleeGraphUtility.Create <Vertex, Edge <Vertex> >(mG); populator.Compute(); Microsoft.Glee.Drawing.Graph gleeG = populator.GleeGraph; //create a viewer object Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); //create a form System.Windows.Forms.Form form = new System.Windows.Forms.Form(); //bind the graph to the viewer viewer.Graph = gleeG; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.ShowDialog(); }
public static Microsoft.Glee.Drawing.Graph Create(IEnumerable <Edge> edges, IEnumerable <State> highlightedStates = null) { var graph = new Microsoft.Glee.Drawing.Graph("graph"); graph.AddEdges(edges); if (highlightedStates != null) { graph.AddHighlightedStates(highlightedStates); } return(graph); }
public static void printAugmentedPath(int[][] graphMatrix, int numberOfVertex, int[] parent) { Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); for (int i = 0; i < numberOfVertex; i++) { for (int j = 0; j < numberOfVertex; j++) { if (graphMatrix[i][j] > 0) { Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1)); e.EdgeAttr.Label = graphMatrix[i][j].ToString(); } } } int u; try { for (int v = numberOfVertex - 1; v != 0; v = parent[v]) { u = parent[v]; Node n1 = graph.FindNode("Node" + (u + 1)); Node n2 = graph.FindNode("Node" + (v + 1)); n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red; n2.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red; // Edge e = graph.AddEdge("Node" + u, "Node" + v); // e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Red; } } catch (Exception e) { MessageBox.Show("Your graph is incorrect \nGraph should be directed with source and sink"); } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form // form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; maxFlowform.Controls.Add(viewer); maxFlowform.ResumeLayout(); //show the form maxFlowform.Show(); }
static void buatMap(string mapLoc) //Membuat representasi peta dalam graf dan linkedlist { //Inisialisasi Graph //create a form //create a viewer object viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); //create a graph object graph = new Microsoft.Glee.Drawing.Graph("graph"); //Inisialisasi variable static file = new System.IO.StreamReader(@mapLoc); N = Convert.ToInt32(file.ReadLine()); nodeVal = new int[N + 1]; visited = new bool[N + 1]; pathArr = new int[N + 1]; //ALGORITMA //inisialiasi ketetanggaan seluruh node dan nilai visited myList = new LinkedList <int> [N + 1]; for (int i = 1; i <= N; i++) { visited[i] = false; myList[i] = new LinkedList <int>(); } //Input string[] inp = new string[2]; int temp1, temp2; for (int i = 0; i < N - 1; i++) { inp = file.ReadLine().Split(); temp1 = int.Parse(inp[0]); temp2 = int.Parse(inp[1]); //Mengisi ketetanggaan kedua node myList[temp1].AddLast(temp2); myList[temp2].AddLast(temp1); //Membuat Graph string tempst1 = temp1.ToString(); string tempst2 = temp2.ToString(); graph.AddEdge(tempst1, tempst2); } //Inisialisasi nilai awal simpul dengan nol for (int i = 1; i <= N; i++) { nodeVal[i] = 0; } giveNodeValue(1, 0); }
public static Microsoft.Glee.Drawing.Graph printMinNode(int[][] graphMatrix, int numberOfVertex, int[] distance, int minNode) { //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); for (int i = 0; i < numberOfVertex; i++) { for (int j = 0; j < numberOfVertex; j++) { if (graphMatrix[i][j] > 0) { Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1)); e.EdgeAttr.Label = graphMatrix[i][j].ToString(); } } } for (int i = 0; i < numberOfVertex; i++) { Node n = graph.FindNode("Node" + (i + 1)); if (distance[i] == Int32.MaxValue) { n.Attr.Label += "\n(" + "infinity" + ")"; } else { n.Attr.Label += "\n(" + distance[i].ToString() + ")"; } } Node n1 = graph.FindNode("Node" + (minNode + 1)); n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red; //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form dijkstraForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; dijkstraForm.Controls.Add(viewer); dijkstraForm.ResumeLayout(); //show the form dijkstraForm.Show(); return(graph); }
//отрисовка графа private void DrawGraph(int currentTop) { this.GraphPanel.Controls.Clear(); Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); viewer.AsyncLayout = false; viewer.AutoScroll = true; nodes = new string[nodesCount]; for (int i = 0; i < nodesCount; ++i) { nodes[i] = (i + 1).ToString(); } graph = new Microsoft.Glee.Drawing.Graph("Graph"); for (int i = 0; i < nodesCount; ++i) { for (int j = 0; j < nodesCount; ++j) { if (adjancyMatrix[i, j] != 0) { graph.AddEdge(nodes[i], "" /*adjancyMatrix[i, j].ToString()*/, nodes[j]); } } } for (int i = 0; i < nodesCount; ++i) { Microsoft.Glee.Drawing.Node currentNode = graph.FindNode(nodes[i]); if (i == currentTop) { currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Green; } else { currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; } currentNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.DoubleCircle; } Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Glee.GraphViewerGdi.GraphRenderer(graph); viewer.Graph = graph; this.GraphPanel.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.GraphPanel.Controls.Add(viewer); this.GraphPanel.ResumeLayout(); //Bitmap graphImage = new Bitmap(GraphPanel.Width, GraphPanel.Height); //renderer.Render(graphImage); //GraphPanel.Image = graphImage; }
protected override void InternalCompute() { this.gleeGraph = new Microsoft.Glee.Drawing.Graph(""); foreach (var v in this.VisitedGraph.Vertices) { Node node = this.AddNode(v); node.UserData = v; this.OnNodeAdded(new GleeVertexEventArgs <TVertex>(v, node)); } foreach (var e in this.VisitedGraph.Edges) { Microsoft.Glee.Drawing.Edge edge = this.AddEdge(e); edge.UserData = e; this.OnEdgeAdded(new GleeEdgeEventArgs <TVertex, TEdge>(e, edge)); } }
public static void main() { //create a form System.Windows.Forms.Form form = new System.Windows.Forms.Form(); form.BackColor = System.Drawing.Color.Black; form.Size = new System.Drawing.Size(1000, 600); //create a viewer object Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.LavenderBlush; //create the graph content CoursePlan coursePlan = new CoursePlan(filename); coursePlan.Print(); foreach (KeyValuePair <string, Subject> entry in coursePlan.subjects) { Subject subject = entry.Value; foreach (string element in subject.preq_of) { graph.AddEdge(subject.name, element); } } //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(); //show the form form.ShowDialog(); // print to console //DFS resultDFS = new DFS(coursePlan.subjects); //resultDFS.Print(); }
// FUNCTION TO DO LOAD GRAPH AND RUN DFS: public static void runDFS(Form1 f1) { defaultG = new Graph("graph"); if (graphForm.IsDisposed) { Console.WriteLine(graphForm == null); graphForm = new Form(); viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); } StreamReader sr = new StreamReader(@f1.getFileURL()); string Rumah = sr.ReadLine(); jmlRumah = Int32.Parse(Rumah); buildTree(ref sr, jmlRumah); // DFS arrive = new long[jmlRumah + 1]; leave = new long[jmlRumah + 1]; visited = new bool[jmlRumah + 1]; DFS(1, ref tree); // COLOR THE ROOT (1) WITH SEAGREEN COLOR Microsoft.Glee.Drawing.Node n1 = defaultG.FindNode("1"); n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.SeaGreen; // Make Root a double-circled vertex just for emphasis, hehe: n1.Attr.Shape = Microsoft.Glee.Drawing.Shape.DoubleCircle; // SHOWING THE GRAPH: // Bind the graph to the viewer viewer.Graph = defaultG; // Associate the viewer with the created form graphForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; graphForm.Controls.Add(viewer); graphForm.ResumeLayout(); graphForm.Refresh(); // Show the form as a new window, BUT not locked there! graphForm.Show(); }
public static void printCalcDistance(int[][] graphMatrix, int numberOfVertex, int[] distance, int minNode, Microsoft.Glee.Drawing.Graph graph1) { //create a graph object Microsoft.Glee.Drawing.Graph graph = graph1; Node n1 = graph.FindNode("Node" + (minNode + 1)); foreach (var i in n1.OutEdges) { i.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Green; i.EdgeAttr.Fontcolor = Microsoft.Glee.Drawing.Color.Green; } for (int i = 0; i < numberOfVertex; i++) { Node n = graph.FindNode("Node" + (i + 1)); if (distance[i] != Int32.MaxValue) { n.Attr.Label += "->\n(" + distance[i].ToString() + ")"; } } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form dijkstraForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; dijkstraForm.Controls.Add(viewer); dijkstraForm.ResumeLayout(); //show the form dijkstraForm.Show(); }
public static Microsoft.Glee.Drawing.Graph printMstMinNode(int[][] graphMatrix, int numberOfVertex, int minNode, int[] parent, Microsoft.Glee.Drawing.Graph graph1) { //create a graph object // Microsoft.Glee.Drawing.Graph graph = graph1; Node n1 = tempGraph.FindNode("Node" + (minNode + 1)); //n1.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red; n1.Attr.Color = Microsoft.Glee.Drawing.Color.Red; if (minNode != 0) { Node n0 = tempGraph.FindNode("Node" + (parent[minNode] + 1)); foreach (Edge e in n0.OutEdges) { if (e.TargetNode == n1) { e.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Red; } } } //bind the graph to the viewer viewer.Graph = tempGraph; //associate the viewer with the form mstForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; mstForm.Controls.Add(viewer); mstForm.ResumeLayout(); //show the form mstForm.Show(); return(tempGraph); }
// ketika isi dari listBox diklik dan mengalami perubahan indeks private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { // jika input secara langsung, bukan file eksternal if (_direct) { // ambil indeks item list int idx = listBox1.SelectedIndex; string[] passed_path = _arrPath[idx].Split(' '); bool found = false; // membangun objek graf Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); // membuat isi graf int numberOfNodes = Convert.ToInt32(richTextBox1.Lines[0]); string[] edge; for (int i = 1; i < numberOfNodes; i++) { edge = richTextBox1.Lines[i].Split(' '); graph.AddEdge(edge[0], edge[1]); Node node = graph.FindNode(edge[0]); // mencari node yang ada pada path yang ditemukan for (int j = 0; j < passed_path.Length; j++) { if (passed_path[j] == edge[0]) { found = true; } } if (found) { // ubah tampilan node yang ditemukan untuk menandakan jalur node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond; node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; found = false; } else { // seperti bentuk node pada graf awal node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle; } node = graph.FindNode(edge[1]); // mencari node yang ada pada path yang ditemukan for (int j = 0; j < passed_path.Length; j++) { if (passed_path[j] == edge[1]) { found = true; } } if (found) { // ubah tampilan node yang ditemukan untuk menandakan jalur node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond; node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; found = false; } else { // seperti bentuk node pada graf awal node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle; } graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None; } ; // masukkan graf ke dalam viewer gViewer1.Graph = graph; } else // jika input dari file eksternal { // ambil indeks item list int idx = listBox1.SelectedIndex - 1; string[] passed_path = _arrPath[idx].Split(' '); bool found = false; // membangun objek graf Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); // membuat isi graf int numberOfNodes = Convert.ToInt32(richTextBox1.Lines[0]); string[] edge; for (int i = 1; i < numberOfNodes; i++) { edge = richTextBox1.Lines[i].Split(' '); graph.AddEdge(edge[0], edge[1]); Node node = graph.FindNode(edge[0]); // mencari node yang ada pada path yang ditemukan for (int j = 0; j < passed_path.Length; j++) { if (passed_path[j] == edge[0]) { found = true; } } if (found) { // ubah tampilan node yang ditemukan untuk menandakan jalur node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond; node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; found = false; } else { // seperti bentuk node pada graf awal node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle; } node = graph.FindNode(edge[1]); for (int j = 0; j < passed_path.Length; j++) { if (passed_path[j] == edge[1]) { found = true; } } if (found) { // ubah tampilan node yang ditemukan untuk menandakan jalu node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond; node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; found = false; } else { // seperti bentuk node pada graf awal node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle; } graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = ArrowStyle.None; } ; // memasukkan graf ke dalam viewer gViewer1.Graph = graph; } }
public void RefreshDisplay() { var obj = this.DBObject; //impersonation toolStripComboBox_exec_grid_as_user.Items.Clear(); toolStripComboBox_exec_grid_as_user.Items.Add(DBObject.Connection.User); toolStripComboBox_exec_grid_as_user.SelectedItem = DBObject.Connection.User; toolStripComboBox_exec_grid_as_user.Items.AddRange(obj.Connection.GetDataTable(Util.GetSql("get_impersonation")).AsEnumerable().Select(x => x["impersonated"].ToString() ).ToList().ToArray()); if (!(obj is IContainsColumns)) { if (tabControl1.TabPages.Contains(tabPage_design)) { tabControl1.TabPages.Remove(tabPage_design); } } var sql = ""; var sql_select = ""; var db_obj = (obj as DBSchemaObject); if (db_obj != null) { sql = db_obj.GetSQL(); if (db_obj.Schema != null && db_obj.State != DBObject.DBObjectState.New) { //properties grid dataGridView_properties.DataSource = new BindingSource(db_obj.Properties, null); } //columns if (obj is IContainsColumns) { var tbl = obj as IContainsColumns; var cols = string.Join("\r\n\t,", tbl.Columns.Select(x => x.FullName).ToList()); sql_select = string.Format("if object_id('{1}') is not null select top 100 \r\n\t{0} \r\nfrom \r\n\t{1}", cols, db_obj.FullName); this.FillGrid(sql_select); //current table as default source toolStripComboBox_source.Items.Clear(); toolStripComboBox_source.Items.Add(obj); toolStripComboBox_source.SelectedItem = obj; //bind the columns to the grid BindingSource cols_source = new BindingSource(tbl is DBTable ? (tbl as DBTable).CombinedColumns : tbl.Columns, null); dataGridView_design.AutoGenerateColumns = false; dataGridView_design.Columns.Clear(); dataGridView_design.Columns.AddRange(new DataGridViewColumn[] { new DataGridViewTextBoxColumn() { Name = "Owner", HeaderText = "Owner", DataPropertyName = "OwnerName", ReadOnly = true }, new DataGridViewTextBoxColumn() { Name = "DisplayOrder", HeaderText = "DisplayOrder", DataPropertyName = "DisplayOrder" }, new DataGridViewTextBoxColumn() { Name = "Name", HeaderText = "Name", DataPropertyName = "Name" }, new DataGridViewTextBoxColumn() { Name = "Title", HeaderText = "Title", DataPropertyName = "Title" }, new DataGridViewTextBoxColumn() { Name = "DataType", HeaderText = "DataType", DataPropertyName = "DataType", ReadOnly = true }, new DataGridViewTextBoxColumn() { Name = "Length", HeaderText = "Length", DataPropertyName = "Length" }, new DataGridViewTextBoxColumn() { Name = "CustomDataType", HeaderText = "CustomDataType", DataPropertyName = "CustomDataType", ReadOnly = true }, new DataGridViewCheckBoxColumn() { Name = "Nullable", HeaderText = "Nullable", DataPropertyName = "Nullable" }, new DataGridViewTextBoxColumn() { Name = "Default", HeaderText = "Default", DataPropertyName = "Default" } }); dataGridView_design.DataSource = cols_source; //sources if (db_obj is DBTable) { toolStripComboBox_source.Items.AddRange((db_obj as DBTable).Extensions.ToArray()); } } else if (obj is DBColumn) { var db_column = (obj as DBColumn); sql_select = string.Format("select top 100 {0} from {1}", db_column.FullName, db_column.Parent.FullName); this.FillGrid(sql_select); } } syntaxEditor1.Text = string.IsNullOrEmpty(sql_select) ? sql : sql_select; syntaxEditor2.Text = sql; //glee //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph") { Directed = true, BuildNodeHierarchy = true, Cluster = true }; graph.GraphAttr.AspectRatio = 2; graph.GraphAttr.LayerDirection = LayerDirection.TB; graph.GraphAttr.OptimizeLabelPositions = true; graph.GraphAttr.Orientation = Microsoft.Glee.Drawing.Orientation.Landscape; // graph.GraphAttr.LayerSep = 1; //graph.GraphAttr.NodeSep = 1; DBObject.DrawGraph(graph, null); //reshape foreach (DictionaryEntry node in graph.NodeMap) { ((Microsoft.Glee.Drawing.Node)node.Value).Attr.Shape = Microsoft.Glee.Drawing.Shape.Box; ((Microsoft.Glee.Drawing.Node)node.Value).Attr.Fontsize = 8; ((Microsoft.Glee.Drawing.Node)node.Value).Attr.LabelMargin = 10; ((Microsoft.Glee.Drawing.Node)node.Value).Attr.FontName = "Lucida Console"; } gViewer1.Graph = graph; }
public static string filename;// = "../../../../" + "Daftar Kuliah.txt"; public static void main() { //create a form System.Windows.Forms.Form form = new System.Windows.Forms.Form(); form.Size = new System.Drawing.Size(1000, 600); //create a viewer object Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); viewer.OutsideAreaBrush = Brushes.LightCoral; //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.LightCoral; //create the graph content CoursePlan coursePlan = new CoursePlan(filename); Subject tempSub = new Subject(); BFS bfsResult = new BFS(coursePlan.subjects); CoursePlan tempCourse = new CoursePlan(filename); string temp = "1. " + bfsResult.result[1][0]; List <string> convert = new List <string>(); foreach (KeyValuePair <int, List <string> > entry in bfsResult.result) { foreach (string x in entry.Value) { convert.Add(x); } } for (int i = 0; i < convert.Count - 1; i++) { tempSub = tempCourse.subjects[convert[i]]; foreach (string x in tempSub.preq_of) { int index = convert.IndexOf(x) + 1; graph.AddEdge(((i + 1).ToString() + ". " + convert[i]), (index.ToString() + ". " + x)); } } int j = 1; foreach (KeyValuePair <int, List <string> > entry in bfsResult.result) { foreach (string tempp in entry.Value) { Microsoft.Glee.Drawing.Node n = graph.FindNode(j.ToString() + ". " + tempp); switch (entry.Key % 5) { case 1: { n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MidnightBlue; n.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.LavenderBlush; break; } case 2: { n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MediumBlue; n.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.LavenderBlush; break; } case 3: { n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.RoyalBlue; break; } case 4: { n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.DodgerBlue; break; } default: { n.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.SkyBlue; break; } } j++; } } //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(); //show the form form.ShowDialog(); }
public static void printDijkstraPath(int[][] graphMatrix, int numberOfVertex, int[] distance, int[] path, int distination) { //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); for (int i = 0; i < numberOfVertex; i++) { for (int j = 0; j < numberOfVertex; j++) { if (graphMatrix[i][j] > 0) { Edge e = graph.AddEdge("Node" + (i + 1), "Node" + (j + 1)); e.EdgeAttr.Label = graphMatrix[i][j].ToString(); } } } for (int i = 0; i < numberOfVertex; i++) { Node n = graph.FindNode("Node" + (i + 1)); if (distance[i] == Int32.MaxValue) { n.Attr.Label += "\n(" + "infinity" + ")"; } else { n.Attr.Label += "\n(" + distance[i].ToString() + ")"; } } int iTemp = distination; int jTemp = 0; while (iTemp != (-1)) { jTemp = path[iTemp]; if (iTemp != 0) { Node nsource = graph.FindNode("Node" + (jTemp + 1)); Node ntarget = graph.FindNode("Node" + (iTemp + 1)); foreach (var edge in nsource.OutEdges) { if (edge.TargetNode == ntarget) { edge.EdgeAttr.Color = Microsoft.Glee.Drawing.Color.Red; } } } iTemp = jTemp; } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form dijkstraForm.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; dijkstraForm.Controls.Add(viewer); dijkstraForm.ResumeLayout(); //show the form dijkstraForm.Show(); }
private GD.Graph CreateGraph() { GD.Graph result = new GD.Graph(_id); // Hang onto the name of the active item for SetGraph. if (_activeItem != null) { result.UserData = _activeItem.Name; } result.GraphAttr.NodeAttr.FontName = "Microsoft Sans Serif"; result.GraphAttr.NodeAttr.Fontsize = 8; result.GraphAttr.NodeAttr.Shape = GD.Shape.Box; result.GraphAttr.NodeAttr.Fillcolor = GD.Color.WhiteSmoke; result.GraphAttr.EdgeAttr.FontName = "Tahoma"; result.GraphAttr.EdgeAttr.Fontsize = 8; result.GraphAttr.AspectRatio = _ratio; if (_options.LeftToRight) { result.GraphAttr.LayerDirection = GD.LayerDirection.LR; } else { result.GraphAttr.LayerDirection = GD.LayerDirection.TB; } return result; }
private void BuildGraph() { // The only way I can see to do this is to create another graph, and // copy what we want to the new graph, which is slow. Grim, we need // to rebuild addedNodes and edges as well. // Considering options, it's easier to do this each time anyway, // and don't build the initial graph at all. TODO, split this. GD.Graph newGraph = CreateGraph(); Dictionary<string, object> newAddedNodes = new Dictionary<string, object>(); Dictionary<string, List<object>> newAddedEdges = new Dictionary<string, List<object>>(); newGraph.GraphAttr.AspectRatio = _options.AspectRatio; newGraph.GraphAttr.NodeSep = _options.NodeSep; foreach (KeyValuePair<string, object> pair in _addedNodes) { GD.Node node = pair.Value as GD.Node; if (!_options.ShowOrphans && !_notOrphans.ContainsKey(pair.Key)) continue; GD.Node newNode = newGraph.AddNode(node.Id); newNode.Attr = node.Attr.Clone(); newNode.Attr.LabelMargin = _options.TextSpacing; newNode.Attr.Fontsize = _options.FontSize; newNode.UserData = node.UserData; newAddedNodes.Add(node.Id, newNode); } foreach (KeyValuePair<string, List<object>> pair in _addedEdges) { if (pair.Value.Count == 0) return; string idFrom = (pair.Value[0] as GD.Edge).Source; string idTo = (pair.Value[0] as GD.Edge).Target; if (_options.MultipleEdges) { int count = _addedEdges[pair.Key].Count; // Perhaps thicken edges. if (_options.ThickenEdges) { // Interesting, but any greater than 2 looks bad. int thickness = 1; if (count > 1) thickness = 2; // Create a thickened edge. Take the properties of the first one. GD.Edge edge = pair.Value[0] as GD.Edge; GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo); newEdge.Attr = edge.Attr.Clone(); newEdge.Attr.LineWidth = thickness; newAddedEdges.Add(pair.Key, new List<object>() { newEdge } ); } else { // Show multiple edges. newAddedEdges.Add(pair.Key, new List<object>()); foreach (GD.Edge edge in pair.Value) { GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo); newEdge.Attr = edge.Attr.Clone(); newAddedEdges[pair.Key].Add(newEdge); } } } else { // Show single edges. Take the properties of the first one. GD.Edge edge = pair.Value[0] as GD.Edge; GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo); newEdge.Attr = edge.Attr.Clone(); newAddedEdges.Add(pair.Key, new List<object> { newEdge }); } } _hasOrphans = _notOrphans.Count < _addedNodes.Count; _graph = newGraph; _addedEdges = newAddedEdges; _addedNodes = newAddedNodes; }
//отрисовка графа private void DrawGraph(int currentTop) { this.GraphPanel.Controls.Clear(); Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); viewer.AsyncLayout = false; viewer.AutoScroll = true; nodes = new string[nodesCount]; for (int i = 0; i < nodesCount; ++i) { nodes[i] = (i + 1).ToString(); } graph = new Microsoft.Glee.Drawing.Graph("Graph"); for (int i = 0; i < nodesCount; ++i) { for (int j = 0; j < nodesCount; ++j) { if (adjancyMatrix[i, j] != 0) { graph.AddEdge(nodes[i], ""/*adjancyMatrix[i, j].ToString()*/, nodes[j]); } } } for (int i = 0; i < nodesCount; ++i) { Microsoft.Glee.Drawing.Node currentNode = graph.FindNode(nodes[i]); if (i == currentTop) { currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Green; } else { currentNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; } currentNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.DoubleCircle; } Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Glee.GraphViewerGdi.GraphRenderer(graph); viewer.Graph = graph; this.GraphPanel.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.GraphPanel.Controls.Add(viewer); this.GraphPanel.ResumeLayout(); //Bitmap graphImage = new Bitmap(GraphPanel.Width, GraphPanel.Height); //renderer.Render(graphImage); //GraphPanel.Image = graphImage; }
private void BuildGraph() { // The only way I can see to do this is to create another graph, and // copy what we want to the new graph, which is slow. Grim, we need // to rebuild addedNodes and edges as well. // Considering options, it's easier to do this each time anyway, // and don't build the initial graph at all. TODO, split this. GD.Graph newGraph = CreateGraph(); Dictionary <string, object> newAddedNodes = new Dictionary <string, object>(); Dictionary <string, List <object> > newAddedEdges = new Dictionary <string, List <object> >(); newGraph.GraphAttr.AspectRatio = _options.AspectRatio; newGraph.GraphAttr.NodeSep = _options.NodeSep; foreach (KeyValuePair <string, object> pair in _addedNodes) { GD.Node node = pair.Value as GD.Node; if (!_options.ShowOrphans && !_notOrphans.ContainsKey(pair.Key)) { continue; } GD.Node newNode = newGraph.AddNode(node.Id); newNode.Attr = node.Attr.Clone(); newNode.Attr.LabelMargin = _options.TextSpacing; newNode.Attr.Fontsize = _options.FontSize; newNode.UserData = node.UserData; newAddedNodes.Add(node.Id, newNode); } foreach (KeyValuePair <string, List <object> > pair in _addedEdges) { if (pair.Value.Count == 0) { return; } string idFrom = (pair.Value[0] as GD.Edge).Source; string idTo = (pair.Value[0] as GD.Edge).Target; if (_options.MultipleEdges) { int count = _addedEdges[pair.Key].Count; // Perhaps thicken edges. if (_options.ThickenEdges) { // Interesting, but any greater than 2 looks bad. int thickness = 1; if (count > 1) { thickness = 2; } // Create a thickened edge. Take the properties of the first one. GD.Edge edge = pair.Value[0] as GD.Edge; GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo); newEdge.Attr = edge.Attr.Clone(); newEdge.Attr.LineWidth = thickness; newAddedEdges.Add(pair.Key, new List <object>() { newEdge }); } else { // Show multiple edges. newAddedEdges.Add(pair.Key, new List <object>()); foreach (GD.Edge edge in pair.Value) { GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo); newEdge.Attr = edge.Attr.Clone(); newAddedEdges[pair.Key].Add(newEdge); } } } else { // Show single edges. Take the properties of the first one. GD.Edge edge = pair.Value[0] as GD.Edge; GD.Edge newEdge = newGraph.AddEdge(idFrom, idTo); newEdge.Attr = edge.Attr.Clone(); newAddedEdges.Add(pair.Key, new List <object> { newEdge }); } } _hasOrphans = _notOrphans.Count < _addedNodes.Count; _graph = newGraph; _addedEdges = newAddedEdges; _addedNodes = newAddedNodes; }
public static void main() { //create a form System.Windows.Forms.Form form = new System.Windows.Forms.Form(); //create a viewer object Microsoft.Glee.GraphViewerGdi.GViewer viewer = new Microsoft.Glee.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph"); //create the graph content CoursePlan coursePlan = new CoursePlan("Daftar Kuliah.txt"); coursePlan.Print(); foreach (KeyValuePair <string, Subject> entry in coursePlan.subjects) { Subject subject = entry.Value; foreach (string element in subject.preq_of) { graph.AddEdge(subject.name, element); } } DFS resultDFS = new DFS(coursePlan.subjects); resultDFS.Print(); Console.WriteLine(); BFS resultBFS = new BFS(coursePlan.subjects); resultBFS.Print(); /*string strNode1 = "Circle"; * string strNode2 = "Home"; * string strNode3 = "Diamond"; * string strNode4 = "Standard"; * * graph.AddEdge(strNode1, strNode2); * graph.AddEdge(strNode2, strNode1); * graph.AddEdge(strNode2, strNode2); * graph.AddEdge(strNode1, strNode3); * graph.AddEdge(strNode1, strNode4); * graph.AddEdge(strNode4, strNode1);*/ //graph.AddEdge(strNode2, "Node 0"); //for (int i = 0; i & lt; 3; i++) graph.AddEdge("Node " + i.ToString(), "Node " + (i + 1).ToString()); //for (int i = 0; i & lt; 3; i++) graph.AddEdge("Node " + (i + 1).ToString(), "Node " + i.ToString()); //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(); //show the form form.ShowDialog(); }
private void SetGraph(GD.Graph graph) { try { string activeItemName = graph.UserData as string; // Can't work out how to set the caption, without also setting // the tab text, which we do not want. This at least tells us. lblCaption.Text = activeItemName; this.ToolTipText = string.Format("{0} [{1}]", GetID(), activeItemName); // This can fail with 'trim a spline' error. _viewer.Graph = graph; _viewer.Visible = true; _viewer.ZoomFraction = 0.1; //_viewer.ZoomMode // Heuristic adjustment. _defaultZoom = 1.0f; if (graph.NodeCount <= 1) { _defaultZoom = 0.35f; } else if (graph.NodeCount <= 2) { _defaultZoom = 0.45f; } else if (graph.NodeCount <= 3) { _defaultZoom = 0.6f; } else if (graph.NodeCount <= 4) { _defaultZoom = 0.8f; } if (oldnodecount == graph.NodeCount) { _defaultZoom = olddefaultzoom; } _viewer.ZoomF = _defaultZoom; if (1 == 1) { olddefaultzoom = (float)_viewer.ZoomF; oldnodecount = _viewer.Graph.NodeCount; } } catch (InvalidOperationException) { _logView.LogStr("GLEE Layout error, try again with different aspect ratio"); _failed = true; } // Show these, incase we've failed. Will be hidden if all ok. if (_failed) { lblPleaseWait.Text = "Layout failed"; btnRefresh.Visible = true; } }