Beispiel #1
0
        /// <summary>
        /// Draw the edge on the graph that connects 2 nodes passed, if edge param is null, create a new edge
        /// </summary>
        /// <param name="startNode"></param>
        /// <param name="endNode"></param>
        /// <param name="edge"></param>
        private void DrawEdge(CanvasNode startNode, CanvasNode endNode, CanvasEdge edge = null)
        {
            Point startPoint, endPoint;

            startPoint = new Point(startNode.X, startNode.Y);
            endPoint   = new Point(endNode.X, endNode.Y);

            if (edge == null)
            {
                edge = new CanvasEdge()
                {
                    Stroke = Brushes.DarkGray,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    StrokeThickness     = 3,
                    X1         = startNode.X,
                    Y1         = startNode.Y,
                    X2         = endNode.X,
                    Y2         = endNode.Y,
                    IsDirected = ArcType.SelectedItem == DirectedArc
                };

                // Add attributes to the edge
                foreach (KeyValuePair <string, double> attr in graph.CommonAttributes)
                {
                    if (!edge.Impl.HasNumericAttribute(attr.Key))
                    {
                        edge.Impl.NumericAttributes.Add(attr.Key, attr.Value);
                    }
                }

                graph.Call(graph =>
                {
                    graph.ConnectNodeToWith(startNode.Impl, endNode.Impl, edge.Impl);
                });
                graph[edge.Impl] = edge;
            }
            else
            {
                edge.Stroke = Brushes.DarkGray;
                edge.HorizontalAlignment = HorizontalAlignment.Center;
                edge.VerticalAlignment   = VerticalAlignment.Center;
                edge.StrokeThickness     = 3;
            }


            MainCanvas.Children.Add(edge);
            Canvas.SetZIndex(edge, -1);

            startNode.OutLines.Add(edge);
            endNode.InLines.Add(edge);

            MainCanvas.UpdateLines(startNode);
            MainCanvas.UpdateLines(endNode);
        }
        protected override XElement CreateXElement(IEdge edge)
        {
            XElement   xelement = base.CreateXElement(edge);
            CanvasEdge cedge    = cgraph[edge];
            var        position = new XElement("Position", new XElement("X1", cedge.X1),
                                               new XElement("Y1", cedge.Y1),
                                               new XElement("X2", cedge.X2),
                                               new XElement("Y2", cedge.Y2));

            xelement.Add(position);

            return(xelement);
        }
Beispiel #3
0
        /// <summary>
        /// Draw result edge onto the result graph
        /// </summary>
        /// <param name="resultGraph"></param>
        /// <param name="canvasEdge"></param>
        private void DrawOutputEdge(ResultGraph resultGraph, CanvasEdge canvasEdge)
        {
            resultGraph.ResultCanvas.Children.Add(canvasEdge);
            Canvas.SetZIndex(canvasEdge, -1);

            CanvasNode tempSrcNode  = resultGraph.CGraph[canvasEdge.Impl.From];
            CanvasNode tempDestNode = resultGraph.CGraph[canvasEdge.Impl.To];

            tempSrcNode.OutLines.Add(canvasEdge);
            tempDestNode.InLines.Add(canvasEdge);

            resultGraph.ResultCanvas.UpdateLines(tempSrcNode);
            resultGraph.ResultCanvas.UpdateLines(tempDestNode);
        }
        public void Remove(CanvasEdge edge)
        {
            edgeToCEdge.Remove(edge.Impl);

            INode from = edge.Impl.From;

            nodeToCNode[from].OutLines.Remove(edge);
            from.ConnectOut.Remove(edge.Impl);

            INode to = edge.Impl.To;

            to.ConnectOut.Remove(edge.Impl);
            nodeToCNode[to].InLines.Remove(edge);

            Impl.Remove(edge.Impl);
        }
        protected override FromToThrough <string, IEdge> LoadEdge(XElement xedge)
        {
            var        tuple    = base.LoadEdge(xedge);
            var        position = xedge.Element("Position");
            CanvasEdge cedge    = new CanvasEdge()
            {
                X1   = Convert.ToDouble(position.Element("X1").Value),
                Y1   = Convert.ToDouble(position.Element("Y1").Value),
                X2   = Convert.ToDouble(position.Element("X2").Value),
                Y2   = Convert.ToDouble(position.Element("Y2").Value),
                Impl = tuple.Through
            };

            cgraph[tuple.Through] = cedge;

            return(tuple);
        }
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            this.isDragInProgress = false;

            // Cache the mouse cursor location.
            this.origCursorLocation = e.GetPosition(this);

            // Walk up the visual tree from the element that was clicked,
            // looking for an element that is a direct child of the Canvas.
            this.ElementBeingDragged = this.FindCanvasChild(e.Source as DependencyObject);
            if (this.ElementBeingDragged == null)
            {
                return;
            }

            // Test get new Node
            if (this.elementBeingDragged is CanvasNode)
            {
                this.SelectedNode = (CanvasNode)this.elementBeingDragged;
            }
            else if (this.elementBeingDragged is CanvasEdge)
            {
                this.SelectedEdge = (CanvasEdge)this.elementBeingDragged;
            }

            this.SetMainWindowSidePanel(this.ElementBeingDragged);

            // Get the element's offsets from the four sides of the Canvas.
            double left   = Canvas.GetLeft(this.ElementBeingDragged);
            double right  = Canvas.GetRight(this.ElementBeingDragged);
            double top    = Canvas.GetTop(this.ElementBeingDragged);
            double bottom = Canvas.GetBottom(this.ElementBeingDragged);

            // Calculate the offset deltas and determine for which sides
            // of the Canvas to adjust the offsets.
            this.origHorizOffset = ResolveOffset(left, right, out this.modifyLeftOffset);
            this.origVertOffset  = ResolveOffset(top, bottom, out this.modifyTopOffset);

            // Set the Handled flag so that a control being dragged
            // does not react to the mouse input.
            e.Handled = true;

            this.isDragInProgress = true;
        }
        private void SetMainWindowSidePanel(UIElement elementBeingDragged)
        {
            if (elementBeingDragged is CanvasNode)
            {
                if (this.edge != null)
                {
                    this.edge.IsSelected = false;
                    this.edge            = null;
                }
                this.node.IsSelected = true;
                NetworkObservability.MainWindow.AppWindow.NodePanel.DataContext   = this.node;
                NetworkObservability.MainWindow.AppWindow.SidePanel.SelectedIndex = 0;
            }
            else if (elementBeingDragged is CanvasEdge)
            {
                if (this.node != null)
                {
                    this.node.IsSelected = false;
                    this.node            = null;
                }
                this.edge.IsSelected = true;


                Dictionary <string, double> tempNumAttr  = new Dictionary <string, double>();
                Dictionary <string, string> tempDescAttr = new Dictionary <string, string>();

                foreach (var a in this.edge.Impl.NumericAttributes)
                {
                    tempNumAttr[a.Key] = a.Value;
                }

                foreach (var a in this.edge.Impl.DescriptiveAttributes)
                {
                    tempDescAttr[a.Key] = a.Value;
                }

                NetworkObservability.MainWindow.AppWindow.NumericAttrList.ItemsSource = tempNumAttr;
                NetworkObservability.MainWindow.AppWindow.DescAttrList.ItemsSource    = tempDescAttr;
                NetworkObservability.MainWindow.AppWindow.SidePanel.SelectedIndex     = 1;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Display the attributes on the side panel when a canvas edge is selected
        /// </summary>
        /// <param name="edge"></param>
        public void PopulateAttributesPanel(CanvasEdge edge)
        {
            edgeNumAttrList.Clear();
            edgeDescAttrList.Clear();

            foreach (var a in edge.Impl.NumericAttributes)
            {
                edgeNumAttrList[a.Key] = a.Value;
            }

            foreach (var a in edge.Impl.DescriptiveAttributes)
            {
                edgeDescAttrList[a.Key] = a.Value;
            }

            NumericAttrList.ItemsSource = null;
            NumericAttrList.ItemsSource = edgeNumAttrList;

            DescAttrList.ItemsSource = null;
            DescAttrList.ItemsSource = edgeDescAttrList;
        }
Beispiel #9
0
        /// <summary>
        /// Add result edge onto the result graph
        /// </summary>
        /// <param name="resultGraph"></param>
        /// <param name="srcNode"></param>
        /// <param name="destNode"></param>
        /// <param name="fullyObserved"></param>
        private void AddOutputEdge(ResultGraph resultGraph, CanvasNode srcNode, CanvasNode destNode, bool fullyObserved)
        {
            CanvasEdge edge = new CanvasEdge(isResult: true)
            {
                Stroke = fullyObserved ? Brushes.Green : Brushes.DarkOrange,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                StrokeThickness     = 3,
                X1         = srcNode.X,
                Y1         = srcNode.Y,
                X2         = destNode.X,
                Y2         = destNode.Y,
                IsDirected = ArcType.SelectedItem == DirectedArc,
            };

            resultGraph.CGraph.Call(g =>
            {
                g.ConnectNodeToWith(srcNode.Impl, destNode.Impl, edge.Impl);
            });
            resultGraph.CGraph[edge.Impl] = edge;
        }