Ejemplo n.º 1
0
        public static void FillCanvasWithAllNodes(Canvas c, Graph g)
        {
            c.Background = new SolidColorBrush(new System.Windows.Media.Color()
            {
                A = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).A,
                R = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).R,
                G = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).G,
                B = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).B,
            });
            // Gett All Names and Sizes
            List <string> allNodeNames = g.GetAllNodeNames().ToList();
            List <Point>  sizes        = new List <Point>();

            foreach (string name in allNodeNames)
            {
                sizes.Add(NodeEllipse.GetEllipseWidthAndHeightBasedOnText(name,
                                                                          out _, g.GetNode(name)));
            }
            //allNodeNames.ForEach(x => Sizes.Add(NodeEllipse.GetEllipseWidthAndHeightBasedOnText(x)));

            // Actually Fill the Canvas
            for (int i = 0; i < allNodeNames.Count; i++)
            {
                Node n = g.GetNode(allNodeNames[i]);
                NodeEllipse.AddNodeEllipse(c, g, n, new Point(n.Position.X, n.Position.Y));
            }
            for (int j = 0; j < c.Children.Count; j++)
            {
                if (c.Children[j] is NodeEllipse nodeEllipse)
                {
                    nodeEllipse.InstantiateConnectionLines();
                }
            }
        }
Ejemplo n.º 2
0
        private static void AddNodeEllipse(Canvas c, Graph g, Node n, Point p)
        {
            NodeEllipse nodeEllipse = new NodeEllipse(c, g, n, p,
                                                      (int)Properties.Settings.Default["MinNodeEllipsePadding"]);

            c.Children.Add(nodeEllipse);
        }
Ejemplo n.º 3
0
        private void AddConnectionLine(Node toNode)
        {
            NodeConnectionLine connectionLine = new NodeConnectionLine(this,
                                                                       NodeEllipse.GetNodeEllipseByName(this._canvas, toNode.Name), this._canvas);

            this._lines.Add(connectionLine);
        }
Ejemplo n.º 4
0
        public NodeConnectionLine(NodeEllipse fromNodeEllipse, NodeEllipse toNodeEllipse, Canvas c)
        {
            this.FromNodeEllipse = fromNodeEllipse;
            this.ToNodeEllipse   = toNodeEllipse;
            this._canvas         = c;

            this._line = new Line()
            {
                Stroke          = System.Windows.Media.Brushes.White,
                StrokeThickness = 5,
            };

            Canvas.SetZIndex(this._line, -1);
            this._canvas.Children.Add(this._line);

            this._directionLines = new List <Line>()
            {
                new Line()
                {
                    Stroke          = System.Windows.Media.Brushes.White,
                    StrokeThickness = 2,
                },
                new Line()
                {
                    Stroke          = System.Windows.Media.Brushes.White,
                    StrokeThickness = 2,
                }
            };
            Canvas.SetZIndex(this._directionLines[0], -1);
            Canvas.SetZIndex(this._directionLines[1], -1);
            this._canvas.Children.Add(this._directionLines[0]);
            this._canvas.Children.Add(this._directionLines[1]);

            this.UpdatePosition();
        }
Ejemplo n.º 5
0
        private void InstantiateContent(Point p, Brush strokeBrush, Brush textBrush, int minDistanceToText = 10, int zIndex = 3)
        {
            Point Size = NodeEllipse.GetEllipseWidthAndHeightBasedOnText(this._node.Name, minDistanceToText);

            this._measurements = new Rect()
            {
                X      = p.X,
                Y      = p.Y,
                Width  = Size.X,
                Height = Size.Y
            };

            // Creating the Ellipse
            this._ellipse = new Ellipse()
            {
                Fill   = this._canvas.Background,
                Stroke = strokeBrush,
                Width  = this._measurements.Width,
                Height = this._measurements.Height
            };

            // Setting the Ellipse's coordinates
            Canvas.SetLeft(this._ellipse, 0);
            Canvas.SetTop(this._ellipse, 0);
            Canvas.SetZIndex(this._ellipse, zIndex);

            // Creating the TextBlock
            this._textBlock = new TextBlock()
            {
                Text          = this._node.Name,
                TextAlignment = TextAlignment.Center,
                Foreground    = textBrush,
                Width         = Size.X - 2 * minDistanceToText,
                Height        = Size.Y - 2 * minDistanceToText
            };

            //// Applying the appropriate width and height of the TextBlock
            //this._textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            //this._textBlock.Arrange(new Rect(this._textBlock.DesiredSize));


            // Setting the Textblock's coordinates
            Canvas.SetLeft(this._textBlock, 0 + minDistanceToText);
            Canvas.SetTop(this._textBlock, 0 + minDistanceToText);
            Canvas.SetZIndex(this._textBlock, zIndex + 1);

            // Drawing
            this.NodeEllipseCanvas.Children.Add(this._ellipse);
            this.NodeEllipseCanvas.Children.Add(this._textBlock);
        }
Ejemplo n.º 6
0
        public NodeConnectionLine(NodeEllipse fromNodeEllipse, NodeEllipse toNodeEllipse, Canvas c)
        {
            this.FromNodeEllipse = fromNodeEllipse;
            this.ToNodeEllipse   = toNodeEllipse;
            this._canvas         = c;

            this._line = new Line()
            {
                Stroke = new SolidColorBrush(new System.Windows.Media.Color {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).B,
                }),
                StrokeThickness = 3,
            };

            Canvas.SetZIndex(this._line, -1);
            this._canvas.Children.Add(this._line);

            this._directionLines = new List <Line>()
            {
                new Line()
                {
                    Stroke = new SolidColorBrush(new System.Windows.Media.Color {
                        A = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).A,
                        R = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).R,
                        G = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).G,
                        B = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).B,
                    }),
                    StrokeThickness = 3,
                },
                new Line()
                {
                    Stroke = new SolidColorBrush(new System.Windows.Media.Color {
                        A = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).A,
                        R = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).R,
                        G = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).G,
                        B = ((System.Drawing.Color)Properties.Settings.Default["NodeConnectionNormalBrushColour"]).B,
                    }),
                    StrokeThickness = 3,
                }
            };
            Canvas.SetZIndex(this._directionLines[0], 2);
            Canvas.SetZIndex(this._directionLines[1], 2);
            this._canvas.Children.Add(this._directionLines[0]);
            this._canvas.Children.Add(this._directionLines[1]);

            this.UpdatePosition();
        }
Ejemplo n.º 7
0
        public void SetCoordinates(Point p)
        {
            // Constrain the X Position
            p.X = Clamp((int)p.X, 0, this._canvas.ActualWidth - this._measurements.Width);

            // Constrain the Y Position
            p.Y = Clamp(p.Y, 0, this._canvas.ActualHeight - this._measurements.Height);

            this._measurements.X = p.X;
            this._measurements.Y = p.Y;

            p.X = Math.Max(0, p.X);
            p.Y = Math.Max(0, p.Y);

            this._node.Position = new System.Drawing.Point((int)p.X, (int)p.Y);

            Canvas.SetLeft(this, p.X);
            Canvas.SetTop(this, p.Y);

            // Fix the OneWayConnectionBug
            foreach (string name in this._graph.GetAllNodeNames())
            {
                if (this._node.Name != name && this._graph.GetNode(name).IsDirectlyConnectedToNode(this._node))
                {
                    NodeEllipse.GetNodeEllipseByName(this._canvas, name).UpdateConnectionCoordinates();
                }
            }

            this.UpdateConnectionCoordinates();
            for (int i = 0; i < this._lines.Count; i++)
            {
                if (this._lines[i].ToNodeEllipse.GetNode().IsDirectlyConnectedToNode(this._node))
                {
                    this._lines[i].ToNodeEllipse.UpdateConnectionCoordinates();
                }
            }
        }
Ejemplo n.º 8
0
        private void InstantiateContent(Point p, int zIndex = 3)
        {
            Point Size = NodeEllipse.GetEllipseWidthAndHeightBasedOnText(this._node.Name, out int minDistanceToText, this._node);

            this._measurements = new Rect()
            {
                X      = p.X,
                Y      = p.Y,
                Width  = Size.X,
                Height = Size.Y
            };

            // Creating the Ellipse
            this._ellipse = new Ellipse()
            {
                Stroke = new SolidColorBrush(
                    new System.Windows.Media.Color()
                {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).B,
                }),
                Fill = new SolidColorBrush(
                    new System.Windows.Media.Color()
                {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).B,
                }),
                Width  = this._measurements.Width,
                Height = this._measurements.Height
            };

            // Setting the Ellipse's coordinates
            Canvas.SetLeft(this._ellipse, 0);
            Canvas.SetTop(this._ellipse, 0);
            Canvas.SetZIndex(this._ellipse, zIndex);

            // Creating the TextBlock
            this._textBlock = new TextBlock()
            {
                Text          = this._node.Name,
                TextAlignment = TextAlignment.Center,
                Foreground    = new SolidColorBrush(
                    new System.Windows.Media.Color()
                {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).B,
                }),
                Width  = Size.X - 2 * minDistanceToText,
                Height = Size.Y - 2 * minDistanceToText
            };

            //// Applying the appropriate width and height of the TextBlock
            //this._textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            //this._textBlock.Arrange(new Rect(this._textBlock.DesiredSize));


            // Setting the Textblock's coordinates
            Canvas.SetLeft(this._textBlock, minDistanceToText);
            Canvas.SetTop(this._textBlock, minDistanceToText);
            Canvas.SetZIndex(this._textBlock, zIndex + 1);

            // Drawing
            this.NodeEllipseCanvas.Children.Add(this._ellipse);
            this.NodeEllipseCanvas.Children.Add(this._textBlock);
        }