public Render ( System.Windows.Controls.Canvas _parent, System.Windows.Controls.Canvas _childCanvas, double xx, double yy, double padsize, int tagid, string name ) : void | ||
_parent | System.Windows.Controls.Canvas | |
_childCanvas | System.Windows.Controls.Canvas | |
xx | double | |
yy | double | |
padsize | double | |
tagid | int | |
name | string | |
Résultat | void |
private void Draw_Universe(string netid) { string SQL; string NodeName; int NodeID, FromID, ToID, EdgeID; double xx2, yy2, size, xx, yy; double px, py; int comments; Random rnd = new Random(); Graph oGraph = new Graph(GraphDirectedness.Directed); IVertexCollection oVertices = oGraph.Vertices; IEdgeCollection oEdges = oGraph.Edges; // Nuke the Display UniverseBackground.Children.Clear(); // Add the Whiskers Programmatically Add_Whiskers(); SQL = "select id, nodename,x,y from nodes where networkid = '" + netid + "'"; OleDbCommand aCommand = new OleDbCommand(SQL, localengine.RepositoryConnection); try { //create the datareader object to connect to table OleDbDataReader aReader = aCommand.ExecuteReader(); //Iterate throuth the database while (aReader.Read()) { NodeID = aReader.GetInt32(0); NodeName = aReader.GetString(1); ListBoxItem li = new ListBoxItem(); li.Content = NodeName; li.Tag = NodeID.ToString(); NodeList.Items.Add(li); px = (double)aReader.GetInt32(2); py = (double)aReader.GetInt32(3); UniversePadPoint p2 = new UniversePadPoint(); p2.PadName = NodeName; xx2 = px; yy2 = py; xx2 = xx2 + 0; yy2 = yy2 + 0; // BUG p2.WhiskX = XWhisker; // BUG p2.WhiskY = YWhisker; size = (double)10; p2.SetDrillFeature(DrillDetailLabel, DrillDetailList, localengine.RepositoryConnection); p2.Render(UniverseBackground, FieldBackground, xx2, yy2, size, (int)NodeID, NodeName); Ellipse re = new Ellipse(); re.Width = rnd.NextDouble() * 80; re.Height = re.Width; re.Opacity = 0.25; re.Tag = "METRIC"; re.Fill = new SolidColorBrush(Colors.Blue); UniverseBackground.Children.Add(re); Canvas.SetLeft(re, xx2 - (re.Width / 2) + 5); Canvas.SetTop(re, yy2 - (re.Width / 2) + 5); } aReader.Close(); } catch (Exception e) { MessageBox.Show(e.Message); } // Connect the edges SQL = "SELECT e.edgeid, e.fromid, n1.x, n1.y, e.toid, n2.x, n2.y "; SQL = SQL + "FROM Edges e, Nodes n1, Nodes n2 "; SQL = SQL + "where e.networkid = '" + netid + "' and n1.networkid = '" + netid + "' and n2.networkid = '" + netid + "' "; SQL = SQL + " and n1.id = e.fromid and n2.id = e.toid "; aCommandEdge = new OleDbCommand(SQL, localengine.RepositoryConnection); try { //create the datareader object to connect to table aReaderEdge = aCommandEdge.ExecuteReader(); //Iterate throuth the database while (aReaderEdge.Read()) { EdgeID = aReaderEdge.GetInt32(0); FromID = aReaderEdge.GetInt32(1); ToID = aReaderEdge.GetInt32(4); xx = aReaderEdge.GetInt32(2); yy = aReaderEdge.GetInt32(3); xx2 = aReaderEdge.GetInt32(5); yy2 = aReaderEdge.GetInt32(6); Line l = new Line(); l.X1 = xx + 5; l.Y1 = yy + 5; l.X2 = xx2 + 5; l.Y2 = yy2 + 5; l.Tag = "EDGE(" + FromID.ToString() + ":" + ToID.ToString() + ")"; l.ToolTip = l.Tag; l.Stroke = new SolidColorBrush(Colors.Gray); UniverseBackground.Children.Add(l); } //aReaderEdge.Close(); } catch (Exception eEdgedDraw) { MessageBox.Show(eEdgedDraw.Message); } }
private void Build_Universe_Network(string layoutmethod, string netid) { string SQL; string NodeName; int NodeID, FromID, ToID, EdgeID; double xx2, yy2, size, xx,yy; double px, py; int comments; Random rnd = new Random(); Graph oGraph = new Graph(GraphDirectedness.Directed); IVertexCollection oVertices = oGraph.Vertices; IEdgeCollection oEdges = oGraph.Edges; // Nuke the Display UniverseBackground.Children.Clear(); // Add the Whiskers Programmatically Add_Whiskers(); SQL = "select id, nodename,x,y from nodes where networkid = '" + netid + "'"; OleDbCommand aCommand = new OleDbCommand(SQL, localengine.RepositoryConnection); try { //create the datareader object to connect to table OleDbDataReader aReader = aCommand.ExecuteReader(); //Iterate throuth the database while (aReader.Read()) { NodeID = aReader.GetInt32(0); NodeName = aReader.GetString(1); ListBoxItem li = new ListBoxItem(); li.Content = NodeName; li.Tag = NodeID.ToString(); NodeList.Items.Add(li); px = (double)aReader.GetInt32(2); py = (double)aReader.GetInt32(3); IVertex oVertexA = oVertices.Add(); oVertexA.Name = NodeName; oVertexA.Tag = NodeID; } aReader.Close(); } catch (Exception e) { MessageBox.Show(e.Message); } // Connect the edges SQL = "select edgeid, fromid, toid from edges where networkid='" + netid + "'"; aCommandEdge = new OleDbCommand(SQL, localengine.RepositoryConnection); try { //create the datareader object to connect to table aReaderEdge = aCommandEdge.ExecuteReader(); //Iterate throuth the database while (aReaderEdge.Read()) { EdgeID = aReaderEdge.GetInt32(0); FromID = aReaderEdge.GetInt32(1); ToID = aReaderEdge.GetInt32(2); xx = Getx(FromID); yy = Gety(FromID); xx2 = Getx(ToID); yy2 = Gety(ToID); Line l = new Line(); l.X1 = xx+5; l.Y1 = yy+5; l.X2 = xx2+5; l.Y2 = yy2+5; l.Tag = "EDGE(" + FromID.ToString() + ":" + ToID.ToString() + ")"; l.ToolTip = l.Tag; l.Stroke = new SolidColorBrush(Colors.Gray); UniverseBackground.Children.Add(l); IVertex oFrom=null; IVertex oTo=null; foreach (IVertex oVertex in oVertices) { if (oVertex.Tag.ToString() == FromID.ToString()) { oFrom = oVertex; } if (oVertex.Tag.ToString() == ToID.ToString()) { oTo = oVertex; } } IEdge oEdge1 = oEdges.Add(oFrom, oTo, true); } //aReaderEdge.Close(); } catch (Exception eEdge) { MessageBox.Show(eEdge.Message); } // Apply Layout // ================================================================== switch(layoutmethod) { case "Circular Layout": ILayout oLayout_cir = new CircleLayout(); LayoutContext oLayoutContext_cir = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_cir.LayOutGraph(oGraph, oLayoutContext_cir); break; case "Random Layout": ILayout oLayout_rand = new RandomLayout(); LayoutContext oLayoutContext_rand = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_rand.LayOutGraph(oGraph, oLayoutContext_rand); break; case "Sugiyama Layout": ILayout oLayout_Sugi = new SugiyamaLayout(); LayoutContext oLayoutContext_Sugi = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_Sugi.LayOutGraph(oGraph, oLayoutContext_Sugi); break; case "Grid Layout": ILayout oLayout_grid = new GridLayout(); LayoutContext oLayoutContext_grid = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_grid.LayOutGraph(oGraph, oLayoutContext_grid); break; case "Spiral Layout": ILayout oLayout_spiral = new SpiralLayout(); LayoutContext oLayoutContext_spiral = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_spiral.LayOutGraph(oGraph, oLayoutContext_spiral); break; case "Fruchterman/Reingold Layout": ILayout oLayout_Fruch = new FruchtermanReingoldLayout(); LayoutContext oLayoutContext_Fruch = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_Fruch.LayOutGraph(oGraph, oLayoutContext_Fruch); break; case "Sinusoid H Layout": ILayout oLayout_SinH = new SinusoidHorizontalLayout(); LayoutContext oLayoutContext_SinH = new LayoutContext(new System.Drawing.Rectangle(0, 0, 5000, 5000)); oLayout_SinH.LayOutGraph(oGraph, oLayoutContext_SinH); break; case "Sinusoid V Layout": ILayout oLayout_SinV = new SinusoidVerticalLayout(); LayoutContext oLayoutContext_SinV = new LayoutContext(new System.Drawing.Rectangle(0, 0, 500, 500)); oLayout_SinV.LayOutGraph(oGraph, oLayoutContext_SinV); break; } // List the results. int xoffset=0; int yoffset=0; Random rc = new Random(); Random rx = new Random(); Random ry = new Random(); Random coin = new Random(); foreach (IVertex oVertex in oVertices) { UniversePadPoint p2 = new UniversePadPoint(); p2.PadName = oVertex.Name; xx2 = oVertex.Location.X; yy2 = oVertex.Location.Y; xx2 = xx2 + xoffset; yy2 = yy2 + yoffset; // BUG p2.WhiskX = XWhisker; // BUG p2.WhiskY = YWhisker; size = (double)10; p2.Render(UniverseBackground, FieldBackground, xx2, yy2, size, (int)oVertex.Tag, oVertex.Name); Ellipse re = new Ellipse(); re.Width = rnd.NextDouble() * 80; re.Height = re.Width; re.Opacity = 0.25; re.Tag = "METRIC"; re.Fill = new SolidColorBrush(Colors.Blue); UniverseBackground.Children.Add(re); Canvas.SetLeft(re, xx2-(re.Width/2)+5); Canvas.SetTop(re, yy2 - (re.Width / 2)+5); } foreach (IEdge e2 in oEdges) { IVertex f1 = e2.BackVertex; IVertex t2 = e2.FrontVertex; xx = f1.Location.X; yy = f1.Location.Y; xx2 = t2.Location.X; yy2 = t2.Location.Y; xx = xx + xoffset; yy = yy + yoffset; xx2 = xx2 + xoffset; yy2 = yy2 + yoffset; Line l = new Line(); l.X1 = xx + 5; l.Y1 = yy + 5; l.X2 = xx2 + 5; l.Y2 = yy2 + 5; l.Tag = "EDGE(" + f1.Tag.ToString() + ":" + t2.Tag.ToString() + ")"; l.ToolTip = l.Tag; l.Stroke = new SolidColorBrush(Colors.Gray); UniverseBackground.Children.Add(l); } }