Exemple #1
0
        /// <summary>
        /// Prepares a node
        /// </summary>
        /// <param name="nodeId">Unique ID of the node for which to create</param>
        /// <param name="ghostNode">Indicates whether or not a GhostNode should be created</param>
        /// <returns>An INode object with the given specifications</returns>
        private static INode PrepareNode(string nodeId, bool ghostNode)
        {
            INode node;

            if (ghostNode)
            {
                node = new GhostNode(nodeId);
            }
            else
            {
                node = new Node(nodeId);
            }

            node.SourceMechanism = CreationType.Live;

            return node;
        }
Exemple #2
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;
                }
            }
        }