Exemple #1
0
        /// <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);
            });
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
        }
Exemple #4
0
        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);
        }
 private void AddNewRow(TableModel model, NodeViewModelBase itemToRemove)
 {
     if (model.IsCollapsed)
         model.IsCollapsed = false;
     if (itemToRemove == null)
         model.AddItem(new RowModel() { ColumnName = "NewRow", DataType = DataType.String });
     else
         model.AddItem(itemToRemove);
 }
Exemple #6
0
 /// <summary>
 /// Handles the MouseLeftButtonDown event
 /// </summary>
 /// <param name="args">The arguments for the event</param>
 public void NodeMouseLeftButtonDownEventHandler(NodeViewModelMouseEventArgs <MouseButtonEventArgs> args)
 {
     // Turn on node dragging if we are in node selection mode
     if (!isPanMode)
     {
         isLeftButtonDown   = true;
         dragTargetNode     = args.NodeViewModel;
         isMouseDownHandled = true;
     }
 }
        private void RemoveRow(TableModel model, NodeViewModelBase itemToRemove)
        {
            var dc = this.DataContext as TablesGraphSource;
            if (dc != null && model != null && itemToRemove != null)
            {
                if (model.IsCollapsed)
                    model.IsCollapsed = false;
                dc.RemoveItem(itemToRemove);
            }

            CommandManager.InvalidateRequerySuggested();
        }
Exemple #8
0
        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;
            //}
        }
Exemple #9
0
        /// <summary>
        /// Returns a PartitionNode instance for the next connected
        /// component contained in the provided list.  The collection
        /// provided is altered and should not be changed between calls
        /// to this method.
        /// </summary>
        /// <param name="nodeVMs">The collection of node view models to be processed</param>
        /// <param name="partitionGraphScope">The scope for the paritioned graph</param>
        /// <param name="originalScope">The scope for the original graph</param>
        /// <returns>a PartitionNode containing a set of connected nodes</returns>
        private PartitionNode GetNextConnectedComponent(IList <NodeViewModelBase> nodeVMs, string scope)
        {
            // Make sure node view models were provided
            if (nodeVMs.Count == 0)
            {
                return(null);
            }

            // Create a new partition node to hold these components
            PartitionNode partitionNode = new PartitionNode(scope, "PN-" + nodeVMs.Count);

            // Start at the first nodeVMs
            List <NodeViewModelBase> visitedNodes = new List <NodeViewModelBase>();
            List <NodeViewModelBase> rootNodes    = new List <NodeViewModelBase>();

            // Add the first node view model to the root and visited lists
            rootNodes.Add(nodeVMs[0]);
            visitedNodes.Add(nodeVMs[0]);

            // Itterate over the root nodes
            while (rootNodes.Count > 0)
            {
                int currentNodeIndex = 0;

                // Add the current node view model to the
                // current PartitionNode
                partitionNode.AddNode(rootNodes[currentNodeIndex]);

                // Itterate over the node's neighbors
                foreach (Model.INode node in GetGraphComponents(rootNodes[currentNodeIndex].Scope).Data.Neighbors(rootNodes[currentNodeIndex].ParentNode))
                {
                    // Get the nodeVM for this node
                    NodeViewModelBase nodeVM = GetGraphComponents(rootNodes[currentNodeIndex].Scope).GetNodeViewModel(node) as NodeViewModelBase;

                    // Check if this node has already been visisted
                    if (!visitedNodes.Contains(nodeVM))
                    {
                        // Add this node to our two holder collections
                        rootNodes.Add(nodeVM);
                        visitedNodes.Add(nodeVM);
                    }
                }

                // Remove the current node since it has been processed
                nodeVMs.Remove(rootNodes[currentNodeIndex]);
                rootNodes.RemoveAt(currentNodeIndex);
            }

            return(partitionNode);
        }
Exemple #10
0
 /// <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;
     }
 }
        private void RemoveRow(TableModel model, NodeViewModelBase itemToRemove)
        {
            var dc = this.DataContext as TablesGraphSource;

            if (dc != null && model != null && itemToRemove != null)
            {
                if (model.IsCollapsed)
                {
                    model.IsCollapsed = false;
                }
                dc.RemoveItem(itemToRemove);
            }

            CommandManager.InvalidateRequerySuggested();
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        /// <summary>
        /// Executes the JavaScript function specified by <paramref name="callbackName"/>
        /// </summary>
        /// <param name="sender">The NodeViewModel that raised the event</param>
        /// <param name="callbackName">The name of the JavaScript function to execute</param>
        private static void ExecuteNodeJSCallback(object sender, string callbackName)
        {
            //TODO:  VALIDATE CALLBACK
            try
            {
                NodeViewModelBase     nodeVM                = (NodeViewModelBase)sender;
                NodeMapData           nodeMapData           = MappingExtensions.GetNode(nodeVM);
                ScriptableNodeMapData scriptableNodeMapData = ScriptableMapper.GetNode(nodeMapData);

                HtmlPage.Window.Invoke(callbackName, scriptableNodeMapData);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Unable to find the '" + callbackName + "' method in the host application", "Unknown callback", MessageBoxButton.OK);
                // Swallow error for now
                //TODO:  LOG THIS CASE
            }
        }
 private void AddNewRow(TableModel model, NodeViewModelBase itemToRemove)
 {
     if (model.IsCollapsed)
     {
         model.IsCollapsed = false;
     }
     if (itemToRemove == null)
     {
         model.AddItem(new RowModel()
         {
             ColumnName = "NewRow", DataType = DataType.String
         });
     }
     else
     {
         model.AddItem(itemToRemove);
     }
 }
Exemple #15
0
        public void SetPlayingVideo(NodeViewModelBase video)
        {
            var node      = Items.FirstOrDefault(n => n.Id == video.Id);
            var videoItem = node as VideoItemViewModel;

            if (videoItem == null)
            {
                return;
            }

            var nowPlaying = GetNowPlayingVideo();

            if (nowPlaying == null)
            {
                return;
            }

            nowPlaying.IsNowPlaying = false;
            videoItem.IsNowPlaying  = true;
        }
Exemple #16
0
        /// <summary>
        /// Handles the ToolbarItemClicked event
        /// </summary>
        /// <param name="args">The arguments for the event</param>
        public void ToolbarItemClickedEventHandler(ToolBarItemEventArgs args)
        {
            NodeViewModelBase rootNode = GetGraphComponents(args.Scope).NodeSelector.SelectedNode;

            // TODO: USE CONSTANT FOR ITEM NAME
            // TODO: Controls should control their own behavior
            if (args.ToolBarItem.Name == "GENERATOR")
            {
                CreateRandomGraph(args.Scope);
            }
            else if (args.ToolBarItem.Name.EndsWith("_LAYOUT"))
            {
                LayoutBase layout = InitializeLayout(args.ToolBarItem.Name, args.Scope);

                // Perform the layout
                LayoutGraph(layout, false, args.Scope, rootNode);
            }
            else if (args.ToolBarItem.Name == "IMPORT")
            {
                PerformImport(args.Scope, new GraphMLGraphDataFormat());     // TODO: Determine which type at runtime
            }
            else if (args.ToolBarItem.Name == "EXPORT")
            {
                PerformExport(args.Scope);
            }
            else if (args.ToolBarItem.Name == "GRAPH_TO_IMAGE")
            {
                SaveGraphAsImage();
            }
            else if (args.ToolBarItem.Name == "PRINT_GRAPH")
            {
                PrintGraph();
            }
            else if (args.ToolBarItem.Name == "RESIZE")
            {
                UI.GraphViewModel graphVM = UI.ViewModelLocator.GraphDataStatic;
                graphVM.ResizeToFit();

                //TODO:  THIS SHOULD BE DECOUPLED
            }
        }
        private void RadDiagram_PreviewDrop(object sender, System.Windows.DragEventArgs e)
        {
            var droppedRow = e.Data.GetData(typeof(GridViewRow));
            var employee   = (droppedRow as GridViewRow).DataContext as Employee;

            NodeViewModelBase node = new NodeViewModelBase();

            node.Position = e.GetPosition(this.xDiagram);
            node.Content  = employee.FirstName + " " + employee.LastName;

            var droppedUIElement = e.OriginalSource as UIElement;

            var droppedInsideContainer = droppedUIElement.ParentOfType <RadDiagramContainerShape>();

            if (droppedInsideContainer != null)
            {
                var division = droppedInsideContainer.DataContext as Division;
                node.Position = this.InsertAtPositionOfDroppedContainer(droppedInsideContainer);
                division.AddItem(node);
            }

            (this.DataContext as MainViewModel).EmployeeGraphSource.AddNode(node);
            (this.DataContext as MainViewModel).EmployeeData.Remove(employee);
        }
Exemple #18
0
 /// <summary>
 /// Creates a new instance of the Berico.SnagL.Events.
 /// NodeEventArgs class using the provided NodeViewModelBase
 /// 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 NodeViewModelMouseEventArgs(NodeViewModelBase _nodeVM, T _args, string _scope)
     : base(_nodeVM, _scope)
 {
     MouseArgs = _args;
 }
Exemple #19
0
        private void RankingCompletedHandler(object sender, RankingEventArgs e)
        {
            // Remove event handler for currently selected ranker
            SelectedRanker.RankingCompleted -= RankingCompletedHandler;

            GraphComponents    graph = GraphManager.Instance.DefaultGraphComponentsInstance;
            List <RankingData> data  = new List <RankingData>();

            if (_colorVisualizer == null)
            {
                _colorVisualizer = new ColorVisualizer(e.Results.Values.Min(), e.Results.Values.Max());
            }
            else
            {
                _colorVisualizer.Reset(e.Results.Values.Min(), e.Results.Values.Max());
            }

            _scaleVisualizer = new ScaleVisualizer();

            foreach (INode node in e.Results.Keys)
            {
                RankingData rankingData = new RankingData {
                    Score = e.Results[node], NodeCount = 1
                };

                if (data.Contains(rankingData))
                {
                    data[data.IndexOf(rankingData)].NodeCount += 1;
                }
                else
                {
                    data.Add(rankingData);
                }

                NodeViewModelBase nodeVM = graph.GetNodeViewModel(node) as NodeViewModelBase;

                if (nodeVM != null)
                {
                    if ((VisualizationOption & VisualizationOptions.Color) == VisualizationOptions.Color)
                    {
                        _colorVisualizer.Visualize(nodeVM, e.Results[node]);
                    }
                    else
                    {
                        _colorVisualizer.ClearVisualization(nodeVM);
                    }

                    if ((VisualizationOption & VisualizationOptions.Scale) == VisualizationOptions.Scale)
                    {
                        _scaleVisualizer.Visualize(nodeVM, e.Results[node]);
                    }
                    else
                    {
                        _scaleVisualizer.ClearVisualization(nodeVM);
                    }
                }
            }

            Scores   = new ObservableCollection <RankingData>(data.OrderBy(rankData => rankData.Score));
            IsActive = true;
        }
        /// <summary>
        ///     Event raised while the user is dragging a node.
        /// </summary>
        private void NodeItem_Dragging(object source, NodeDraggingEventArgs e)
        {
            e.Handled = true;

            //
            // Cache the NodeItem for each selected node whilst dragging is in progress.
            //
            if (this.cachedSelectedNodeItems == null)
            {
                this.cachedSelectedNodeItems = new List <Node>();

                foreach (var selectedNode in this.SelectedNodes)
                {
                    Node nodeItem = FindAssociatedNodeItem(selectedNode);
                    if (nodeItem == null)
                    {
                        throw new ApplicationException("Unexpected code path!");
                    }

                    this.cachedSelectedNodeItems.Add(nodeItem);
                }
            }

            //
            // Update the position of the node within the Canvas.
            //
            foreach (var nodeItem in this.cachedSelectedNodeItems)
            {
                nodeItem.X += e.HorizontalChange;
                nodeItem.Y += e.VerticalChange;
                NodeViewModelBase vm = nodeItem.Content as NodeViewModelBase;
                if (vm != null)
                {
                    vm.Left.X  += e.HorizontalChange;
                    vm.Left.Y  += e.VerticalChange;
                    vm.Right.X += e.HorizontalChange;
                    vm.Right.Y += e.VerticalChange;
                }
            }

            //Detect Selected node insert operation
            Point         p          = Mouse.GetPosition(this);
            List <object> unselected = new List <object>();

            foreach (var node in Nodes)
            {
                if (!SelectedNodes.Contains(node))
                {
                    unselected.Add(node);
                }
            }
            foreach (var node in unselected)
            {
                Node nodeItem        = FindAssociatedNodeItem(node);
                NodeViewModelBase vm = nodeItem.Content as NodeViewModelBase;
                if (vm == null)
                {
                    throw new NotSupportedException("Node Control contents must inherit from NodeViewModelBase.");
                }
                var targetRect = new Rect(new Point(vm.Left.X, vm.Left.Y), new Size(vm.Left.Width, vm.Left.Height));
            }


            var eventArgs = new NodeDraggingEventArgs(NodeDraggingEvent, this, this.SelectedNodes, e.HorizontalChange, e.VerticalChange);

            RaiseEvent(eventArgs);
        }
Exemple #21
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);
        }
Exemple #22
0
 /// <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)
 {
 }
Exemple #23
0
 /// <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;
 }
Exemple #24
0
 /// <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;
 }
Exemple #25
0
 public NavigationObject(NodeViewModelBase nodeViewModel, Page page)
 {
     ViewModel         = nodeViewModel;
     NavigationService = page.NavigationService;
 }
Exemple #26
0
        /// <summary>
        /// Handles the MouseLeftButtonUp event
        /// </summary>
        /// <param name="args">The arguments for the event</param>
        public void NodeMouseLeftButtonUpEventHandler(NodeViewModelMouseEventArgs <MouseButtonEventArgs> args)
        {
            // Only allow node manipulation if we are not in pan mode
            if (!isPanMode)
            {
                NodeSelector nodeSelector = GraphManager.Instance.DefaultGraphComponentsInstance.NodeSelector;

                // Check if we were dragging the node
                if (isNodeDragging)
                {
                    // Turn off node dragging
                    isNodeDragging = false;
                    dragTargetNode = null;
                }
                else
                {
                    // Check if any nodes are currently selected
                    if (nodeSelector.AreAnyNodesSelected)
                    {
                        // Check if Control is pressed
                        if ((Keyboard.Modifiers & ModifierKeys.Alt) > 0)
                        {
                            nodeSelector.InvertSelection();
                        }
                        else
                        {
                            // Check if multiple nodes are selected
                            if (nodeSelector.AreMultipleNodesSelected)
                            {
                                // Check if target node is already selected
                                if (nodeSelector.SelectedNodes.Contains(args.NodeViewModel))
                                {
                                    // Check if Control is pressed
                                    if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
                                    {
                                        nodeSelector.Unselect(args.NodeViewModel);
                                        return;
                                    }
                                    else
                                    {
                                        nodeSelector.UnselectAll();
                                    }
                                }
                                else     // Target node is not selected
                                {
                                    // Check if Control is pressed
                                    if ((Keyboard.Modifiers & ModifierKeys.Control) == 0)
                                    {
                                        nodeSelector.UnselectAll();
                                    }
                                }
                            }
                            else     // Only one node is selected
                            {
                                // Check if the target node is already selected
                                if (nodeSelector.SelectedNode.Equals(args.NodeViewModel))
                                {
                                    nodeSelector.Unselect(nodeSelector.SelectedNode);
                                    return;
                                }
                                else     // Target node is not selected
                                {
                                    // Check if Control is pressed
                                    if ((Keyboard.Modifiers & ModifierKeys.Control) == 0)
                                    {
                                        nodeSelector.Unselect(nodeSelector.SelectedNode);
                                    }
                                }
                            }
                        }
                    }

                    // Set the SELECTED state of the clicked node
                    nodeSelector.Select(args.NodeViewModel);
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Adds the specificed node
        /// </summary>
        /// <param name="graphComponents">The Graph that data is being imported into</param>
        /// <param name="creationType">The specified CreationType</param>
        /// <param name="objNode">Node to be added</param>
        public static void AddNode(GraphComponents graphComponents, CreationType creationType, NodeMapData objNode)
        {
            // Create new node
            Node uiNode = new Node(objNode.Id);

            uiNode.SourceMechanism = creationType;

            // TODO as NodeMapData types expands, this needs to be adjusted
            NodeTypes uiNodeType = NodeTypes.Simple;

            if (objNode is IconNodeMapData)
            {
                uiNodeType = NodeTypes.Icon;
            }
            else if (objNode is TextNodeMapData)
            {
                uiNodeType = NodeTypes.Text;
            }

            NodeViewModelBase uiNodeVM = NodeViewModelBase.GetNodeViewModel(uiNodeType, uiNode, graphComponents.Scope);

            // Properties
            if (uiNodeType == NodeTypes.Icon)
            {
                IconNodeMapData objIconNode = (IconNodeMapData)objNode;
                if (objIconNode.ImageSource != null)
                {
                    ((IconNodeViewModel)uiNodeVM).ImageSource = objIconNode.ImageSource.ToString();
                }
            }

            uiNodeVM.Description  = objNode.Description;
            uiNodeVM.DisplayValue = objNode.Label;
            uiNodeVM.Width        = objNode.Dimension.Width;
            uiNodeVM.Height       = objNode.Dimension.Height;
            uiNodeVM.Position     = objNode.Position;
            uiNodeVM.IsHidden     = objNode.IsHidden;

            SolidColorBrush uiBackgroundColorBrush = new SolidColorBrush(objNode.BackgroundColor);

            uiNodeVM.BackgroundColor = uiBackgroundColorBrush;

            SolidColorBrush uiSelectionColorBrush = new SolidColorBrush(objNode.SelectionColor);

            uiNodeVM.SelectionColor = uiSelectionColorBrush;

            if (uiNodeVM.Height == 0)
            {
                uiNodeVM.Height = 45;
            }

            if (uiNodeVM.Width == 0)
            {
                uiNodeVM.Width = 45;
            }

            // Add the node to the graph
            graphComponents.AddNodeViewModel(uiNodeVM);

            // Attributes
            foreach (KeyValuePair <string, AttributeMapData> objNodeAttrKVP in objNode.Attributes)
            {
                Attributes.Attribute uiNodeAttribute      = new Attributes.Attribute(objNodeAttrKVP.Value.Name);
                AttributeValue       uiNodeAttributeValue = new AttributeValue(objNodeAttrKVP.Value.Value);

                uiNode.Attributes.Add(uiNodeAttribute.Name, uiNodeAttributeValue);
                GlobalAttributeCollection.GetInstance(graphComponents.Scope).Add(uiNodeAttribute, uiNodeAttributeValue);

                uiNodeAttribute.SemanticType = objNodeAttrKVP.Value.SemanticType;
                uiNodeAttribute.PreferredSimilarityMeasure = objNodeAttrKVP.Value.SimilarityMeasure;
                uiNodeAttribute.Visible = !objNodeAttrKVP.Value.IsHidden;
            }
        }
Exemple #28
0
        /// <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);
                }
            }
        }
Exemple #29
0
 /// <summary>
 /// Creates a new instance of the Berico.SnagL.Events.
 /// NodeEventArgs class using the provided NodeViewModelBase
 /// and MouseEventArgs.
 /// </summary>
 /// <param name="_nodeVM">The view model class for the node involved
 /// in the event</param>
 /// <param name="_sourceID">The ID for graph that this object belongs to</param>
 public NodeViewModelEventArgs(NodeViewModelBase _nodeVM, string _scope)
 {
     NodeViewModel = _nodeVM;
     Scope         = _scope;
 }
Exemple #30
0
 /// <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);
 }