Пример #1
0
        /// <summary>
        /// Creates new node in the model
        /// </summary>
        /// <param name="__description">The description.</param>
        /// <param name="type">The type.</param>
        /// <param name="__name">The name.</param>
        /// <returns></returns>
        public diagramNode AddNode(string __description, diagramNodeShapeEnum type, string __name = "", string __hash = "", ILogBuilder logger = null)
        {
            diagramNode output = new diagramNode();

            output.description = __description;
            output.shapeType   = type;

            if (!isNodeNameAcceptable(__name))
            {
                __name = __name + getUID(output, true, false);
            }

            output.name   = __name;
            output.parent = this;

            nodes.Add(output.name, output);
            if (!__hash.isNullOrEmpty())
            {
                if (linkByHash.ContainsKey(__hash))
                {
                    if (logger != null)
                    {
                        logger.log("AddNode() failed :: " + __hash);
                    }
                }
                else
                {
                    nodeByHash.Add(__hash, output);
                }
            }

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Adds the link.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <returns></returns>
        public diagramLink AddLink(diagramNode from, diagramNode to, diagramLinkTypeEnum type, string description = "", string __hash = "", ILogBuilder logger = null)
        {
            diagramLink output = new diagramLink();

            output.from        = from;
            output.to          = to;
            output.type        = type;
            output.name        = getUID(output);
            output.description = description;
            links.Add(output);
            output.parent = this;

            if (!__hash.isNullOrEmpty())
            {
                if (linkByHash.ContainsKey(__hash))
                {
                    if (logger != null)
                    {
                        logger.log("AddLink() failed :: " + __hash);
                    }
                }
                else
                {
                    linkByHash.Add(__hash, output);
                }
            }
            return(output);
        }
        /// <summary>
        /// Builds the children and returns newly built nodes
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="source">The source.</param>
        /// <param name="defShapeType">Type of the definition shape.</param>
        /// <param name="defLinkType">Type of the definition link.</param>
        /// <param name="doDegradeImportance">if set to <c>true</c> [do degrade importance].</param>
        /// <returns></returns>
        public List <diagramNode> buildChildren(diagramModel model, diagramNode parent, IEnumerable source, diagramNodeShapeEnum defShapeType = diagramNodeShapeEnum.normal, diagramLinkTypeEnum defLinkType = diagramLinkTypeEnum.normal, bool doDegradeImportance = true)
        {
            List <diagramNode> childNodes = new List <diagramNode>();

            if (source == null)
            {
                return(childNodes);
            }

            foreach (IObjectWithPathAndChildSelector child in source)
            {
                diagramNode node = buildNode(model, child);
                node.shapeType = getShapeTypeEnum(child, defShapeType);
                //node.relatedObject = child;
                childNodes.Add(node);
                if (doDegradeImportance)
                {
                    node.importance = parent.importance - 1;
                }
                node.color = getColor(node);
            }

            foreach (diagramNode child in childNodes)
            {
                diagramLink link = model.AddLink(parent, child, diagramLinkTypeEnum.normal);
                link.type        = getLinkTypeEnum(child, defLinkType);
                link.description = getLinkDescription(link, "");
            }
            return(childNodes);
        }
        //public virtual

        /// <summary>
        /// Builds a node.
        /// </summary>
        /// <param name="model">The diagram model.</param>
        /// <param name="source">The source object to build from</param>
        /// <returns></returns>
        public override diagramNode buildNode(diagramModel model, IObjectWithPathAndChildSelector source)
        {
            string      name        = getNodeName(source, "NaN");
            string      description = getNodeDescription(source, name);
            diagramNode node        = model.AddNode(description, diagramNodeShapeEnum.normal, name);

            node.relatedObject = source;

            return(node);
        }
        /// <summary>
        /// Gets the node declaration.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public override string getNodeDeclaration(diagramNode node)
        {
            string output = "";
            string name   = "N" + node.name;
            string insert = "";

            if (!node.description.isNullOrEmpty())
            {
                insert = "\"" + node.description + "\"";
            }
            else
            {
                insert = "\"" + node.name + "\"";
            }

            switch (node.shapeType)
            {
            case diagramNodeShapeEnum.circle:
                insert = "((" + insert + "))";
                break;

            case diagramNodeShapeEnum.flagToLeft:
                insert = "[" + insert + "<";
                break;

            case diagramNodeShapeEnum.flagToRight:
                insert = ">" + insert + "]";
                break;

            default:
            case diagramNodeShapeEnum.normal:
                insert = "[" + insert + "]";
                break;

            case diagramNodeShapeEnum.rhombus:
                insert = "{" + insert + "}";
                break;

            case diagramNodeShapeEnum.rounded:
                insert = "(" + insert + ")";
                break;
            }

            output = name + insert;
            return("    " + output + ";");
        }
        /// <summary>
        /// Builds the diagram model from an object with children
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public override diagramModel buildModel(diagramModel output, IObjectWithPathAndChildSelector source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("can-t build model :: source is null" + "Diagram = source is null");
            }
            if (output == null)
            {
                output = new diagramModel("", "", diagramDirectionEnum.LR);
                if (source is IObjectWithNameAndDescription)
                {
                    IObjectWithNameAndDescription source_IObjectWithNameAndDescription = (IObjectWithNameAndDescription)source;
                    output.name        = source_IObjectWithNameAndDescription.name;
                    output.description = source_IObjectWithNameAndDescription.description;
                }
            }

            diagramNode parent = buildNode(output, source);
            //parent.relatedObject = source;

            List <diagramNode> childNodes = new List <diagramNode>();

            childNodes = buildChildren(output, parent, source, diagramNodeShapeEnum.normal, diagramLinkTypeEnum.normal, true);
            int c = 1;

            while (childNodes.Any())
            {
                c++;
                if (c > childDepthLimit)
                {
                    break;
                }
                List <diagramNode> newChildNodes = new List <diagramNode>();
                foreach (diagramNode childNode in childNodes)
                {
                    if (childNode.relatedObject is IEnumerable)
                    {
                        newChildNodes.AddRange(buildChildren(output, childNode, childNode.relatedObject as IEnumerable, diagramNodeShapeEnum.normal, diagramLinkTypeEnum.normal, true));
                    }
                }

                childNodes = newChildNodes;
            }

            return(output);
        }
 public override diagramLinkTypeEnum getLinkTypeEnum(diagramNode child, diagramLinkTypeEnum defType = diagramLinkTypeEnum.normal)
 {
     if (child.relatedObject is IContentBlock)
     {
         return(diagramLinkTypeEnum.thick);
     }
     if (child.relatedObject is IContentParagraph)
     {
         return(diagramLinkTypeEnum.normal);
     }
     if (child.relatedObject is IContentSentence)
     {
         return(diagramLinkTypeEnum.normal);
     }
     if (child.relatedObject is IContentToken)
     {
         return(diagramLinkTypeEnum.dotted);
     }
     return(defType);
 }
 public override int getColor(diagramNode child, int defColor = 1)
 {
     if (child.relatedObject is IContentBlock)
     {
         return(1);
     }
     if (child.relatedObject is IContentParagraph)
     {
         return(2);
     }
     if (child.relatedObject is IContentSentence)
     {
         return(3);
     }
     if (child.relatedObject is IContentToken)
     {
         return(4);
     }
     return(5);
 }
Пример #9
0
 public virtual diagramLinkTypeEnum getLinkTypeEnum(diagramNode child, diagramLinkTypeEnum defType = diagramLinkTypeEnum.normal)
 {
     return(defType);
 }
Пример #10
0
 public virtual int getColor(diagramNode child, int defColor = 1)
 {
     return(defColor);
 }
        //public abstract String getLinkType(diagramLinkTypeEnum type);

        public abstract string getNodeDeclaration(diagramNode node);