/// <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; } } }
/// <summary> /// Removes the provided node view model (and its parent node) from the graph /// </summary> /// <param name="nodeVM">The node view model to be removed from the graph</param> public void RemoveNodeViewModel(INodeShape nodeVM) { // Validate the provided nodeVM if (nodeVM == null) { throw new System.ArgumentNullException("NodeVM", "Invalid node view model provided"); } // Make sure the node view model even exists before going // through the motions to remove it if (this.nodeViewModels.Contains(nodeVM)) { // Ensure we are not dealing with a partition nodeVM if (!(nodeVM is PartitionNode)) { NodeViewModelBase targetNodeVM = nodeVM as NodeViewModelBase; // Remove the parent node from the graph this.graphData.RemoveNode(targetNodeVM.ParentNode); // Remove event handlers for this node VM targetNodeVM.NodeMoved -= new System.EventHandler <System.EventArgs>(nodeViewModel_NodeMoved); targetNodeVM.NodeLoaded -= new System.EventHandler <System.EventArgs>(nodeViewModel_NodeLoaded); // Remove the view model from the internal collections nodeToNodeViewModel.Remove(targetNodeVM.ParentNode); } else { this.graphData.RemoveNode(nodeVM as PartitionNode); } nodeViewModels.Remove(nodeVM); } }
/// <summary> /// /// </summary> /// <param name="nodeVM"></param> public void Hide(NodeViewModelBase nodeVM) { // Validate the node view model list if (nodeVM == null) { return; } if (hiddenNodes.Contains(nodeVM)) { return; } this.hiddenNodes.Add(nodeVM); // Get the edges for this node this.hiddenEdges.AddRange(GraphManager.Instance.DefaultGraphComponentsInstance.GetEdgeViewModels(nodeVM.ParentNode)); // Now we need to remove the nodes and edges // that were effected by the filter GraphManager.Instance.DefaultGraphComponentsInstance.RemoveNodeViewModels(this.hiddenNodes); GraphManager.Instance.DefaultGraphComponentsInstance.RemoveEdgeViewModels(this.hiddenEdges); if (this.hiddenNodes.Count > 0) { this.isActive = true; } else { this.isActive = false; } }
private void AddEdges(List<IEdgeViewModel> edges, NodeViewModelBase parentNode) { // Record the new edges addedEdges.Add(parentNode, edges); // Add the edges to the graph graph.AddEdgeViewModels(edges); }
/// <summary> /// Unselect the provided node /// </summary> /// <param name="nodeVM">The view model of the node to be selected</param> public void Unselect(NodeViewModelBase nodeVM) { // Remove the view model from our selected collection selectedNodes.Remove(nodeVM); // Set the state of the node view model to Selected nodeVM.CurrentState = NodeStates.Unselected; }
/// <summary> /// Visualizes the target node's importance by altering it's size /// </summary> /// <param name="target">The node that is the target for this visualization</param> /// <param name="importance">A value that indicates how important the target /// is. This value affects the visualization functionality.</param> public void Visualize(NodeViewModelBase target, double importance) { if (importance == 0) target.Scale = 0.75; else if (importance == 1) target.Scale = 3; else target.Scale = 1.0 + importance; }
/// <summary> /// Selects the provided node. If the node is already /// selected, it is unselectedf /// </summary> /// <param name="nodeVM">The view model of the node to be selected</param> public void Select(NodeViewModelBase nodeVM) { // Only select the node if it isn't already selected if (!this.selectedNodes.Contains(nodeVM)) { // Keep track of the selected node viewmodels selectedNodes.Add(nodeVM); // Set the state of the node view model to Selected nodeVM.CurrentState = NodeStates.Selected; } else { Unselect(nodeVM); } }
/// <summary> /// Handles the MouseRightButtonDown event for the Node /// </summary> /// <param name="args">Arguments for the event</param> public void NodeMouseRightButtonDownEventHandler(NodeViewModelMouseEventArgs <MouseButtonEventArgs> args) { // Ensure that the context menu has not already been initialized if (nodeContextMenu == null) { nodeContextMenu = new ContextMenu(); nodeContextMenu.ItemsSource = nodeMenuItems; nodeContextMenu.Opening += new RoutedEventHandler(NodeContextMenuOpeningHandler); nodeContextMenu.Closed += new RoutedEventHandler(NodeContextMenuClosedHandler); } // Save the NodeViewModel that the right click was on targetNodeVM = args.NodeViewModel; // Open the Node's ContextMenu nodeContextMenu.OpenPopup(args.MouseArgs.GetPosition(null)); }
/// <summary> /// Adds the provided node view model (and its ParentNode) to the graph /// </summary> /// <param name="nodeVM">The node view model that should be added to the graph</param> public void AddNodeViewModel(INodeShape nodeVM) { // Validate the provided nodeVM if (nodeVM == null) { throw new ArgumentNullException("NodeVM", "Invalid node view model provided"); } // Skip the current view model if it already exists if (this.nodeViewModels.Contains(nodeVM)) { return; } // Determine if this is a PartitionNode if (!(nodeVM is PartitionNode)) { NodeViewModelBase targetNode = nodeVM as NodeViewModelBase; INode parentNode = targetNode.ParentNode; if (nodeToNodeViewModel.ContainsKey(targetNode.ParentNode)) { return; } else { this.graphData.AddNode(parentNode); // Process the orphan edges ProcessOrphanEdges(parentNode); // Setup event handlers for this node VM targetNode.NodeMoved += new System.EventHandler <System.EventArgs>(nodeViewModel_NodeMoved); targetNode.NodeLoaded += new System.EventHandler <System.EventArgs>(nodeViewModel_NodeLoaded); nodeToNodeViewModel.Add(targetNode.ParentNode, nodeVM); } } else { this.graphData.AddNode(nodeVM as PartitionNode); } nodeViewModels.Add(nodeVM); }
/// <summary> /// Creates a NodeViewModel, for the provided Node, and adds it to the nodes /// view model collection. The NodesViewModel collection is bound to the Graph /// control and displays and handles creating appropriate node views for each /// view model. /// </summary> /// <param name="node">The Node instance to create the NodeVIewModel for</param> private void CreateNodeViewModel(Node node, string imagePath) { // Ensure that the node view model doesn't already exist if (nodeToNodeViewModel.ContainsKey(node)) { return; } // Create new NodeViewModel for this node NodeViewModelBase nodeViewModel = NodeViewModelBase.GetNodeViewModel(this.nodeType, node, this.scope); // Setup the event handler to catch when a node's position has changed nodeViewModel.NodeMoved += new System.EventHandler <System.EventArgs>(nodeViewModel_NodeMoved); nodeViewModel.NodeLoaded += new System.EventHandler <System.EventArgs>(nodeViewModel_NodeLoaded); if (!string.IsNullOrEmpty(imagePath) && this.nodeType == NodeTypes.Icon) { (nodeViewModel as IconNodeViewModel).ImageSource = imagePath; } nodeToNodeViewModel.Add(node, nodeViewModel); nodeViewModels.Add(nodeViewModel); }
/// <summary> /// Unselect the provided node /// </summary> /// <param name="nodeVM">The view model of the node to be selected</param> public void Unselect(NodeViewModelBase nodeVM) { // Remove the view model from our selected collection selectedNodes.Remove(nodeVM); // Set the state of the node view model to Selected nodeVM.CurrentState = NodeStates.Unselected; }
/// <summary> /// Selects the provided node. If the node is already /// selected, it is unselectedf /// </summary> /// <param name="nodeVM">The view model of the node to be selected</param> public void Select(NodeViewModelBase nodeVM) { // Only select the node if it isn't already selected if (!this.selectedNodes.Contains(nodeVM)) { // Keep track of the selected node viewmodels selectedNodes.Add(nodeVM); // Set the state of the node view model to Selected nodeVM.CurrentState = NodeStates.Selected; } else Unselect(nodeVM); }
private void RemoveEdges(List<IEdgeViewModel> edges, NodeViewModelBase parentNode) { // Save the edges savedEdges.Add(parentNode, edges); graph.RemoveEdgeViewModels(edges); // Loop over all the edge view models that were provided // that need to be removed //foreach (IEdgeViewModel edgeVM in edges) //{ // edgeVM.Visibility = Visibility.Collapsed; //} }
/// <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); } }
/// <summary> /// Handles the MouseRightButtonDown event for the Node /// </summary> /// <param name="args">Arguments for the event</param> public void NodeMouseRightButtonDownEventHandler(NodeViewModelMouseEventArgs<MouseButtonEventArgs> args) { // Ensure that the context menu has not already been initialized if (nodeContextMenu == null) { nodeContextMenu = new ContextMenu(); nodeContextMenu.ItemsSource = nodeMenuItems; nodeContextMenu.Opening += new RoutedEventHandler(NodeContextMenuOpeningHandler); nodeContextMenu.Closed += new RoutedEventHandler(NodeContextMenuClosedHandler); } // Save the NodeViewModel that the right click was on targetNodeVM = args.NodeViewModel; // Open the Node's ContextMenu nodeContextMenu.OpenPopup(args.MouseArgs.GetPosition(null)); }
public static NodeMapData GetNode(NodeViewModelBase uiNodeVM) { NodeMapData objNode; if (uiNodeVM.GetType().Equals(typeof(IconNodeViewModel))) { objNode = new IconNodeMapData(uiNodeVM.ParentNode.ID); // Property IconNodeViewModel iconNodeVM = (IconNodeViewModel)uiNodeVM; if (iconNodeVM.ImageSource != null) { ((IconNodeMapData)objNode).ImageSource = new System.Uri(iconNodeVM.ImageSource, UriKind.Relative); } } else { objNode = new TextNodeMapData(uiNodeVM.ParentNode.ID); } // Properties objNode.Description = uiNodeVM.Description; objNode.Label = uiNodeVM.DisplayValue; Size dimension = new Size(uiNodeVM.Width, uiNodeVM.Height); objNode.Dimension = dimension; objNode.Position = uiNodeVM.Position; objNode.IsHidden = uiNodeVM.IsHidden; objNode.BackgroundColor = uiNodeVM.BackgroundColor.Color; objNode.SelectionColor = uiNodeVM.SelectionColor.Color; // Attributes foreach (KeyValuePair<string, AttributeValue> uiNodeVMAttrKVP in uiNodeVM.ParentNode.Attributes) { Attributes.Attribute uiNodeVMAttribute = GlobalAttributeCollection.GetInstance(uiNodeVM.Scope).GetAttribute(uiNodeVMAttrKVP.Key); AttributeMapData objNodeAttribute = new AttributeMapData(uiNodeVMAttrKVP.Key, uiNodeVMAttrKVP.Value.Value); objNode.Attributes.Add(objNodeAttribute.Name, objNodeAttribute); objNodeAttribute.SemanticType = uiNodeVMAttribute.SemanticType; objNodeAttribute.SimilarityMeasure = uiNodeVMAttribute.PreferredSimilarityMeasure; objNodeAttribute.IsHidden = !uiNodeVMAttribute.Visible; } return objNode; }
/// <summary> /// Removes the color visualization from the target node /// </summary> /// <param name="target">The node whose visualization is to be removed</param> public void ClearVisualization(NodeViewModelBase target) { target.BackgroundColor = _storedColors.ContainsKey(target.ParentNode.ID) ? new SolidColorBrush(_storedColors[target.ParentNode.ID]) : new SolidColorBrush(Colors.Transparent); }
/// <summary> /// Creates a new instance of the NodePositionAnimator class using /// the provided target node and target position /// </summary> /// <param name="_targetNode">The node being animated</param> /// <param name="_targetPosition">The position the node should be /// moved to</param> /// <param name="_duration">The duration of the animation</param> public NodePositionAnimator(NodeViewModelBase _targetNode, Point _targetPosition, int _duration) : this(_targetNode, _targetPosition, _duration, 0) { }
/// <summary> /// Determines which operation (Collapse or Expand) is most appropriate /// and executes it /// </summary> /// <param name="targetNode">The node view model that is being collapsed or expanded</param> private void CollapseOrExpandNode(NodeViewModelBase targetNode) { //TODO: check collection to determine if this node has already been collapsed CollapseNode(targetNode); }
/// <summary> /// Removes the scale visualization from the target node /// </summary> /// <param name="target">The node whose visualization is to be removed</param> public void ClearVisualization(NodeViewModelBase target) { target.Scale = 1.0; }
/// <summary> /// Visualizes the target node's importance by altering it's color /// </summary> /// <param name="target">The node that is the target for this visualization</param> /// <param name="importance">A value that indicates how important the target /// is. This value affects the target visualization.</param> public void Visualize(NodeViewModelBase target, double importance) { // Compute the color that should be used Color computedColor = new Color { A = 255, R = (byte)(_delta.R * importance / _range + _lowerColor.R), G = (byte)(_delta.G * importance / _range + _lowerColor.G), B = (byte)(_delta.B * importance / _range + _lowerColor.B) }; // Check if the current background color is Transparent //if (target.BackgroundColor.Color != Colors.Transparent) //{ // Check if the color for this node has already // been saved if (!_storedColors.ContainsKey(target.ParentNode.ID)) { // Save the color for this node _storedColors.Add(target.ParentNode.ID, target.BackgroundColor.Color); } //} // Set the node's background color target.BackgroundColor = new SolidColorBrush(computedColor); }
/// <summary> /// Redraws the graph with the specified layout type /// </summary> /// <param name="layout">Type of graph layout</param> /// <param name="isAnimated">Specifies whether or not to animate the graph when it's laid out</param> /// <param name="scope">Specifies the default graph scope</param> /// <param name="rootNode">Specifies the root node for layouts that require one</param> public void LayoutGraph(LayoutBase layout, bool isAnimated, string scope, NodeViewModelBase rootNode) { LayoutManager flyweight = LayoutManager.Instance; // Make sure we have a scope if (String.IsNullOrWhiteSpace(scope)) { scope = this.defaultComponentInstanceScope; } // Get the graph as a GraphMapData object GraphMapData graphMapData = GetGraphComponents(scope).ExportGraph(); // Execute the layout DispatcherHelper.UIDispatcher.BeginInvoke(() => { if (rootNode != null) { layout.CalculateLayout(graphMapData, rootNode.ParentNode); } else { layout.CalculateLayout(graphMapData); } System.Diagnostics.Debug.WriteLine(""); foreach (Delegate d in ContextMenuManager.Instance.GetContextMenuOpeningInvocationList()) { System.Diagnostics.Debug.WriteLine((d.Target as GraphComponents).Scope); } layout.PositionNodes(isAnimated, graphMapData); }); }
/// <summary> /// /// </summary> /// <param name="nodeVM"></param> public void AddNode(NodeViewModelBase nodeVM) { // Check and make sure that the provided node view // model is not already part of this partition node if (nodes.Contains(nodeVM)) return; // Add the node to the partition nodes.Add(nodeVM); // Create a temporary edge collection List<Edge> tempEdgeList = new List<Edge>(); // Analyze the collection of existing external connections foreach (Edge edge in externalConnections) { // Check if the current node is this edge's // Target node if (edge.Target.Equals(nodeVM.ParentNode)) { // Add this edge to our temporary edge // collection tempEdgeList.Add(edge); } // Check if the node is this edge's Source node else if (edge.Source.Equals(nodeVM.ParentNode)) { // Since this node is the source node for this // edge, and the node is part of the Partition, // it needs to be removed from the external // incomming connections collection. externalIncommingConnections.Remove(edge); } } // Remove all the edges in the temporary collection // from the external edges collection. foreach (Edge edge in tempEdgeList) externalConnections.Remove(edge); tempEdgeList.Clear(); // Analyze the collection of existing external incomming // connections foreach (Edge edge in externalIncommingConnections) { // Check if the current node is this edge's // Source node if (edge.Source.Equals(nodeVM.ParentNode)) { // Add this edge to our temporary edge // collection tempEdgeList.Add(edge); } else if (edge.Target.Equals(nodeVM.ParentNode)) { externalConnections.Remove(edge); } } // Remove all the edges in the temporary collection // from the external incomming edges collection. foreach (Edge edge in tempEdgeList) externalIncommingConnections.Remove(edge); //TODO: VALIDATE GRAPHMANAGER CALL RESULTS BEFORE USING VALUES // Loop over all the edges for this nodes foreach (Edge edge in GraphManager.Instance.GetGraphComponents(nodeVM.Scope).Data.Edges(nodeVM.ParentNode)) { NodeViewModelBase targetNodeVM = (GraphManager.Instance.GetGraphComponents(nodeVM.Scope).GetNodeViewModel(edge.Target)) as NodeViewModelBase; NodeViewModelBase sourceNodeVM = (GraphManager.Instance.GetGraphComponents(nodeVM.Scope).GetNodeViewModel(edge.Source)) as NodeViewModelBase; // Check if the current node is this edge's // Target node if (edge.Target != nodeVM.ParentNode && !nodes.Contains(targetNodeVM)) { // If we are here, this edge is an outgoing edge // whose target is not part of this PartionNode externalConnections.Add(edge); } else if (edge.Source != nodeVM.ParentNode && !nodes.Contains(sourceNodeVM)) { // If we are here, this edge is an incomming edge // whose source is not part of this PartitionNode externalIncommingConnections.Add(edge); } } }
/// <summary> /// /// </summary> /// <param name="nodeVM"></param> public void Hide(NodeViewModelBase nodeVM) { // Validate the node view model list if (nodeVM == null) return; if (hiddenNodes.Contains(nodeVM)) return; this.hiddenNodes.Add(nodeVM); // Get the edges for this node this.hiddenEdges.AddRange(GraphManager.Instance.DefaultGraphComponentsInstance.GetEdgeViewModels(nodeVM.ParentNode)); // Now we need to remove the nodes and edges // that were effected by the filter GraphManager.Instance.DefaultGraphComponentsInstance.RemoveNodeViewModels(this.hiddenNodes); GraphManager.Instance.DefaultGraphComponentsInstance.RemoveEdgeViewModels(this.hiddenEdges); if (this.hiddenNodes.Count > 0) this.isActive = true; else this.isActive = false; }
/// <summary> /// Creates a new instance of the NodePositionAnimator class using /// the provided target node and target position /// </summary> /// <param name="_targetNode">The node being animated</param> /// <param name="_targetPosition">The position the node should be /// moved to</param> /// <param name="_duration">The duration of the animation</param> /// <param name="_frameRate">The frame rate of the animation</param> public NodePositionAnimator(NodeViewModelBase _targetNode, Point _targetPosition, int _duration, int _frameRate) : base(_duration, _frameRate) { this.targetNode = _targetNode; this.targetPosition = _targetPosition; }