Esempio n. 1
0
        /// <summary>
        /// Collapse all children (outgoing nodes) for the target node
        /// </summary>
        /// <param name="targetNode"></param>
        private void CollapseNode(NodeViewModelBase targetNode)
        {
            List <INode>             childNodes       = new List <INode>();
            List <IEdgeViewModel>    edgesToBeRemoved = new List <IEdgeViewModel>();
            List <IEdgeViewModel>    edgesToBeAdded   = new List <IEdgeViewModel>();
            List <NodeViewModelBase> nodesToBeRemoved = new List <NodeViewModelBase>();

            graph = Data.GraphManager.Instance.GetGraphComponents(targetNode.Scope);

            // Get all the chidren for the target node
            childNodes = GetChildren(targetNode.ParentNode);

            // Ensure we have any child nodes before continuing
            if (childNodes.Count > 0)
            {
                foreach (INode childNode in childNodes)
                {
                    NodeViewModelBase nodeVM = graph.GetNodeViewModel(childNode) as NodeViewModelBase;

                    foreach (IEdge edge in graph.GetEdges(childNode))
                    {
                        IEdgeViewModel edgeVM = graph.GetEdgeViewModel(edge);

                        // Determine if this is an incoming edge
                        if (edge.Target == childNode)
                        {
                            // Existing incoming edges need to be removed
                            // and new ones need to be added
                            edgesToBeRemoved.Add(edgeVM);

                            // Determine if this edge's source node is inside
                            // of the child nodes being collapsed
                            if (!childNodes.Contains(edge.Source) && edge.Source != targetNode.ParentNode)
                            {
                                IEdgeViewModel newEdgeVM = (edgeVM as EdgeViewModelBase).Copy(edge.Source, targetNode.ParentNode);

                                edgesToBeAdded.Add(newEdgeVM);
                            }
                        }
                        else // Handle the outgoing edges
                        {
                            // Outgoing edges need to be saved and removed
                            edgesToBeRemoved.Add(edgeVM);
                        }
                    }

                    // Remove (hide) the node
                    //nodeVM.IsHidden = true;
                    nodesToBeRemoved.Add(nodeVM);
                }

                graph.RemoveNodeViewModels(nodesToBeRemoved);

                // Remove (hide) the edges
                RemoveEdges(edgesToBeRemoved, targetNode);

                // Add new edges
                AddEdges(edgesToBeAdded, targetNode);
            }
        }
Esempio n. 2
0
        public IEdge ConnectNodes(IEdgeViewModel <TEdge> connection, TVertex vertex1Object, TVertex vertex2Object, bool isDirected)
        {
            var vertex1 = Graph.Vertices.Single(v => v.Object.Object.Equals(vertex1Object));
            var vertex2 = Graph.Vertices.Single(v => v.Object.Object.Equals(vertex2Object));

            return(ConnectNodes(connection, vertex1.Id, vertex2.Id, isDirected));
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the NodeLoaded event which indicates that a node
        /// has been loaded onto the graph
        /// </summary>
        /// <param name="sender">The object that fired the event</param>
        /// <param name="e">The arguments for the event</param>
        private void nodeViewModel_NodeLoaded(object sender, System.EventArgs e)
        {
            // Obtain an instance to the node's view model
            NodeViewModelBase nodeViewModel = sender as NodeViewModelBase;

            // Get a reference to all edges associated with this node
            foreach (IEdge edge in graphData.Edges(nodeViewModel.ParentNode))
            {
                // Get the EdgeViewModel for this edge
                if (!edgeToEdgeViewModel.ContainsKey(edge))
                {
                    continue;
                }

                // Obtain an instance to this edge's view model
                IEdgeViewModel edgeViewModel = edgeToEdgeViewModel[edge];

                // Check if the current node is the source or target
                // so that we know which part of the edge line to
                // update.  Our rule of thumb is that we draw the line
                // from source to target.
                if (edge.Source.Equals(nodeViewModel.ParentNode))
                {
                    // Update the edge line properties
                    edgeViewModel.X1 = nodeViewModel.CenterPoint.X;
                    edgeViewModel.Y1 = nodeViewModel.CenterPoint.Y;
                }
                else
                {
                    // Update the edge line properties
                    edgeViewModel.X2 = nodeViewModel.CenterPoint.X;
                    edgeViewModel.Y2 = nodeViewModel.CenterPoint.Y;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns the view model for the provided Edge
        /// </summary>
        /// <param name="node">The Edge whose view model is being
        /// requested</param>
        /// <returns>the view model for the provided edge</returns>
        public IEdgeViewModel GetEdgeViewModel(IEdge edge)
        {
            IEdgeViewModel edgeVM = null;

            if (this.edgeToEdgeViewModel.TryGetValue(edge, out edgeVM))
            {
                return(edgeVM);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Removes the edge view model for the given edge (and the edge
        /// itself)
        /// </summary>
        /// <param name="edge">The edge whose view model should be removed</param>
        public void RemoveEdgeViewModel(IEdge edge)
        {
            IEdgeViewModel edgeVM = null;

            // Try and get the edge view model for the provided edge
            if (this.edgeToEdgeViewModel.TryGetValue(edge, out edgeVM))
            {
                // Remove the edge view model for this edge
                RemoveEdgeViewModel(edgeVM);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns a new IEdgeViewModel that is a copy of the current
        /// edge view model but with the specified source and target
        /// nodes
        /// </summary>
        /// <param name="source">The source Node for this edge</param>
        /// <param name="target">The target Node for this edge</param>
        /// <returns>an edge view model</returns>
        public virtual IEdgeViewModel Copy(INode source, INode target)
        {
            // Create a copy of the parent edgeLine
            IEdge newEdge = this.ParentEdge.Copy(source, target);

            // Create a new edge view model based on the the type
            // of the new edge that was just created
            //EdgeViewModelBase oldEdgeVM = GetEdgeViewModel(newEdge);
            IEdgeViewModel newEdgeVM = null;

            //TODO: TRY AND UPDATE TO USE GENERICS

            if (this is SimilarityEdgeViewModel)
            {
                newEdgeVM = new SimilarityEdgeViewModel(newEdge as SimilarityDataEdge, this.Scope)
                {
                    Visibility = this.Visibility,
                    EdgeLine   = new EdgeLine(ParentEdge.Type)
                    {
                        Opacity              = this.EdgeLine.Opacity,
                        Color                = this.EdgeLine.Color,
                        Thickness            = this.EdgeLine.Thickness,
                        LabelForegroundColor = this.EdgeLine.LabelForegroundColor,
                        LabelBackgroundColor = this.EdgeLine.LabelBackgroundColor,
                        LabelFontStyle       = this.EdgeLine.LabelFontStyle,
                        LabelFontWeight      = this.EdgeLine.LabelFontWeight,
                        LabelTextUnderline   = this.EdgeLine.LabelTextUnderline,
                        LabelFont            = this.EdgeLine.LabelFont
                    }
                };
            }
            else
            {
                newEdgeVM = new StandardEdgeViewModel(newEdge, this.Scope)
                {
                    Visibility = this.Visibility,
                    EdgeLine   = new EdgeLine(ParentEdge.Type)
                    {
                        Opacity              = this.EdgeLine.Opacity,
                        Color                = this.EdgeLine.Color,
                        Thickness            = this.EdgeLine.Thickness,
                        LabelForegroundColor = this.EdgeLine.LabelForegroundColor,
                        LabelBackgroundColor = this.EdgeLine.LabelBackgroundColor,
                        LabelFontStyle       = this.EdgeLine.LabelFontStyle,
                        LabelFontWeight      = this.EdgeLine.LabelFontWeight,
                        LabelTextUnderline   = this.EdgeLine.LabelTextUnderline,
                        LabelFont            = this.EdgeLine.LabelFont
                    }
                };
            }

            return(newEdgeVM);
        }
Esempio n. 7
0
        /// <summary>
        /// Removes the edge view model from the graph
        /// </summary>
        /// <param name="edgeVM">The edge view model to be removed</param>
        public void RemoveEdgeViewModel(IEdgeViewModel edgeVM)
        {
            // Remove the parent edge
            this.graphData.RemoveEdge(edgeVM.ParentEdge);

            // Ensure that the provided edge view model exists
            if (this.edgeToEdgeViewModel.ContainsKey(edgeVM.ParentEdge))
            {
                // Remove the edge view model from the collection
                this.edgeToEdgeViewModel.Remove(edgeVM.ParentEdge);

                // Fire the EdgeViewModelRemoved event
                OnEdgeViewModelRemoved(new EdgeViewModelEventArgs(edgeVM, this.scope));
            }
        }
Esempio n. 8
0
        public IEdge ConnectNodes(IEdgeViewModel <TEdge> connection, uint vertex1Id, uint vertex2Id, bool isDirected)
        {
            var edge = new Edge <IEdgeViewModel <TEdge> >(
                Graph.GetUnusedEdgeId(),
                vertex1Id,
                vertex2Id)
            {
                IsDirected = isDirected,
                Object     = connection
            };

            Graph.AddEdge(edge);
            Edges.Add(connection);
            RearrangeGraph();
            return(edge);
        }
Esempio n. 9
0
        /// <summary>
        /// Adds the provided edgeviewmodel (and it's parent edge)
        /// to the graph
        /// </summary>
        /// <param name="edgeVMs">The edge view model to be added to the graph</param>
        public void AddEdgeViewModel(IEdgeViewModel edgeVM)
        {
            // Add the ParentEdge for this view model.  The AddEdge method
            // will check if the edge already exists.
            this.graphData.AddEdge(edgeVM.ParentEdge);

            // Check if the edge view model already exists
            if (!this.edgeToEdgeViewModel.ContainsKey(edgeVM.ParentEdge))
            {
                if (graphData.OrphanEdges.Contains(edgeVM.ParentEdge))
                {
                    _orphanEdgeViewModels.Add(edgeVM);
                }
                else
                {
                    // Get the viewmodels for the source and target nodes
                    INodeShape sourceNodeVM = GetNodeViewModel(edgeVM.ParentEdge.Source);
                    INodeShape targetNodeVM = GetNodeViewModel(edgeVM.ParentEdge.Target);

                    // Ensure the edge is attached to its source
                    if (sourceNodeVM != null)
                    {
                        edgeVM.X1 = sourceNodeVM.CenterPoint.X;
                        edgeVM.Y1 = sourceNodeVM.CenterPoint.Y;
                    }

                    // Ensure the edge is attached to its target
                    if (targetNodeVM != null)
                    {
                        edgeVM.X2 = targetNodeVM.CenterPoint.X;
                        edgeVM.Y2 = targetNodeVM.CenterPoint.Y;
                    }

                    // Now we need to update the edge to edgeviewmodels collection
                    edgeToEdgeViewModel.Add(edgeVM.ParentEdge, edgeVM);

                    // Fire the EdgeViewModelAdded event
                    OnEdgeViewModelAdded(new EdgeViewModelEventArgs(edgeVM, this.scope));
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Remove an edge view (physical edge line)
 /// </summary>
 /// <param name="edgeViewModel">The view model for the edge view to be removed</param>
 private void RemoveEdgeView(IEdgeViewModel edgeViewModel)
 {
     // Remove the physical edge (the line) from the graph surface
     edgeViewModel.EraseEdgeLine(graphSurface);
 }
Esempio n. 11
0
        //public void ScaleBy(double scaleChange)
        //{
        //    double MIN_SCALE = 0.01;
        //    double MAX_SCALE = 4;
        //    double newScale = this.currentScale + (this.currentScale * scaleChange);
        //    //double newScale = this.scale * scaleChange;

        //    //if (newScale < MIN_SCALE)
        //    //{
        //    //    proposedScale = MIN_SCALE / this.currentScale;
        //    //    newScale = this.currentScale * proposedScale;
        //    //    scaleChange = MIN_SCALE;
        //    //}
        //   // else if (newScale > MAX_SCALE)
        //    //{
        //    //    proposedScale = MAX_SCALE / this.currentScale;
        //    //    newScale = this.currentScale * proposedScale;
        //    //    scaleChange = MAX_SCALE;
        //    //}

        //    if (newScale < MIN_SCALE)
        //        return;

        //    if (newScale > MAX_SCALE)
        //        return;

        //    // Set the scale transform
        //    //this.Scale += proposedScale;
        //    this.Scale = newScale;
        //    this.currentScale = newScale;

        //    currentTranslation.X += (GraphSurfaceWidth / currentScale - GraphSurfaceWidth / (currentScale / scaleChange)) / 2;
        //    currentTranslation.Y += (GraphSurfaceHeight / currentScale - GraphSurfaceHeight / (currentScale / scaleChange)) / 2;
        //}

        /// <summary>
        /// Add an edge view (physical edge line)
        /// </summary>
        /// <param name="edgeViewModel">The view model for the edge view to be created</param>
        private void AddEdgeView(IEdgeViewModel edgeViewModel)
        {
            // Draw the physical edge (the line) on the graph surface
            edgeViewModel.DrawEdgeLine(graphSurface);
        }
Esempio n. 12
0
 /// <summary>
 /// Creates a new instance of the Berico.SnagL.Events.
 /// EdgeViewModelMouseEventArgs class using the provided
 /// IEdgeViewModel and MouseEventArgs.
 /// </summary>
 /// <param name="_nodeVM">The view model class for the node involved
 /// in the event</param>
 /// <param name="_args">The mouse arguments related to the event</param>
 /// <param name="_sourceID">The ID for graph that this object belongs to</param>
 public EdgeViewModelMouseEventArgs(IEdgeViewModel _edgeVM, T _args, string _scope)
     : base(_edgeVM, _scope)
 {
     MouseArgs = _args;
 }
Esempio n. 13
0
        /// <summary>
        /// Adds the specificed edge
        /// </summary>
        /// <param name="graphComponents">The Graph that data is being imported into</param>
        /// <param name="creationType">The specified CreationType</param>
        /// <param name="objEdge">Edge to be added</param>
        public static void AddEdge(GraphComponents graphComponents, CreationType creationType, EdgeMapData objEdge)
        {
            INode uiSourceNode = graphComponents.Data.GetNode(objEdge.Source);

            if (uiSourceNode == null && creationType == CreationType.Imported)
            {
                throw new Exception("Missing Source Node");
            }
            else if (uiSourceNode == null)// && creationType == CreationType.Live
            {
                uiSourceNode = new GhostNode(objEdge.Source);
            }

            INode uiTargetNode = graphComponents.Data.GetNode(objEdge.Target);

            if (uiTargetNode == null && creationType == CreationType.Imported)
            {
                throw new Exception("Missing Target Node");
            }
            else if (uiTargetNode == null)// && creationType == CreationType.Live
            {
                uiTargetNode = new GhostNode(objEdge.Target);
            }

            if (string.IsNullOrEmpty(objEdge.Label) && objEdge.Attributes.Count == 0)
            {
                Berico.SnagL.Model.Edge uiEdge = new Berico.SnagL.Model.Edge(uiSourceNode, uiTargetNode);
                uiEdge.SourceMechanism = creationType;

                // Properties
                uiEdge.Type = objEdge.Type;

                // the EdgeViewModel must be created after uiEdge has had a Type specified
                IEdgeViewModel uiEdgeVM = EdgeViewModelBase.GetEdgeViewModel(uiEdge, graphComponents.Scope);
                graphComponents.AddEdgeViewModel(uiEdgeVM);
            }
            else
            {
                DataEdge uiEdge = new DataEdge(uiSourceNode, uiTargetNode);
                uiEdge.SourceMechanism = creationType;

                // Properties
                uiEdge.Type         = objEdge.Type;
                uiEdge.DisplayValue = objEdge.Label;

                // the EdgeViewModel must be created after uiEdge has had a Type specified
                IEdgeViewModel uiEdgeVM = EdgeViewModelBase.GetEdgeViewModel(uiEdge, graphComponents.Scope);
                graphComponents.AddEdgeViewModel(uiEdgeVM);

                uiEdgeVM.Thickness     = objEdge.Thickness;
                uiEdgeVM.Color         = new SolidColorBrush(objEdge.Color);
                uiEdgeVM.EdgeLine.Text = objEdge.Label;
                uiEdgeVM.EdgeLine.LabelTextUnderline   = objEdge.IsLabelTextUnderlined;
                uiEdgeVM.EdgeLine.LabelBackgroundColor = new SolidColorBrush(objEdge.LabelBackgroundColor);
                uiEdgeVM.EdgeLine.LabelForegroundColor = new SolidColorBrush(objEdge.LabelForegroundColor);
                uiEdgeVM.EdgeLine.LabelFontStyle       = objEdge.LabelFontStyle;
                uiEdgeVM.EdgeLine.LabelFontWeight      = objEdge.LabelFontWeight;
                if (objEdge.LabelFont != null)
                {
                    uiEdgeVM.EdgeLine.LabelFont = objEdge.LabelFont;
                }

                // Attributes
                foreach (KeyValuePair <string, AttributeMapData> objEdgeAttrKVP in objEdge.Attributes)
                {
                    Attributes.Attribute uiEdgeAttribute      = new Attributes.Attribute(objEdgeAttrKVP.Value.Name);
                    AttributeValue       uiEdgeAttributeValue = new AttributeValue(objEdgeAttrKVP.Value.Value);

                    uiEdge.Attributes.Add(uiEdgeAttribute.Name, uiEdgeAttributeValue);
                    //GlobalAttributeCollection.GetInstance(graphComponents.Scope).Add(uiEdgeAttribute, uiEdgeAttributeValue);

                    uiEdgeAttribute.SemanticType = objEdgeAttrKVP.Value.SemanticType;
                    uiEdgeAttribute.PreferredSimilarityMeasure = objEdgeAttrKVP.Value.SimilarityMeasure;
                    uiEdgeAttribute.Visible = !objEdgeAttrKVP.Value.IsHidden;
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Creates a new instance of the Berico.SnagL.Events.
 /// EdgeViewModelEventArgs class using the provided
 /// EdgeViewModelBase
 /// </summary>
 /// <param name="_edgeVM">The view model class for the edge involved
 /// in the event</param>
 /// <param name="_sourceID">The ID for graph that this object belongs to</param>
 public EdgeViewModelEventArgs(IEdgeViewModel _edgeVM, string _scope)
 {
     EdgeViewModel = _edgeVM;
     Scope         = _scope;
 }