Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new SimilarityEdgeViewModel or retrieves
        /// an existing one from the cache
        /// </summary>
        /// <param name="sourceNode">The source node</param>
        /// <param name="targetNode">The target node</param>
        /// <param name="similarityValue">The similarity value for the provided source and target node</param>
        /// <returns>a new (or cached) SimilarityEdgeViewModel</returns>
        private void GenerateSimilarityEdgeVM(SimilarityDataEdge similarityEdge)
        {
            List <SimilarityEdgeViewModel> nodeSimilarityEdges;
            SimilarityEdgeViewModel        newEdgeVM = null;

            //TODO:  WE NEED TO CLEAR THE CACHE AT SOME POINT IN TIME

            // Get the cache list of edges for the source node
            if (attributeEdgeCache.TryGetValue(similarityEdge.Source, out nodeSimilarityEdges))
            {
                // Loop over all the edges to try and find if we already have one
                // for the given source and target nodes
                foreach (SimilarityEdgeViewModel currentEdgeVM in nodeSimilarityEdges)
                {
                    if (currentEdgeVM.ParentEdge.Target == similarityEdge.Target)
                    {
                        // The edge was previously cached
                        newEdgeVM = currentEdgeVM;
                        break;
                    }
                }
            }
            else
            {
                // Initialize the edge cache list
                attributeEdgeCache[similarityEdge.Target] = new List <SimilarityEdgeViewModel>();
            }

            // If we found an edge, we should return it
            if (newEdgeVM != null)
            {
                GraphManager.Instance.DefaultGraphComponentsInstance.AddEdgeViewModel(newEdgeVM);
            }

            // If we are here, we need to create a brand new edge
            newEdgeVM = new SimilarityEdgeViewModel(similarityEdge, this.scope);

            GraphManager.Instance.DefaultGraphComponentsInstance.AddEdgeViewModel(newEdgeVM);
        }