Beispiel #1
0
        /// <summary>
        /// Converts the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="depthLimit">The depth limit.</param>
        /// <returns></returns>
        public override freeGraph Convert(T source, Int32 depthLimit = 500, IEnumerable <T> rootNodes = null)
        {
            freeGraph output = new freeGraph();

            output.DisableCheck = true;
            output.Id           = source.name;
            output.description  = "FreeGraph built from " + source.GetType().Name + ":GraphNodeBase graph";

            var nodes = source.getAllChildren(null, false, false, 1, depthLimit, true);

            Dictionary <T, freeGraphNodeBase> nodeDict = new Dictionary <T, freeGraphNodeBase>();

            foreach (var ch in nodes)
            {
                T   child = (T)ch;
                var node  = output.AddNewNode(GetNodeName(child), GetNodeWeight(child), GetNodeType(child));
                nodeDict.Add(child, node);
            }

            foreach (var ch in nodes)
            {
                if (ch.parent != null)
                {
                    T parent = (T)ch.parent;
                    T child  = (T)ch;
                    if ((parent != null) && (child != null))
                    {
                        freeGraphNodeBase gParent = nodeDict[parent];
                        freeGraphNodeBase gChild  = nodeDict[child];
                        var lnk = output.AddLink(gParent.name, gChild.name, GetLinkWeight(parent, child), GetLinkType(parent, child));
                        lnk.linkLabel = GetLinkLabel(parent, child);
                    }
                }
            }
            output.DisableCheck = false;
            output.RebuildIndex();
            return(output);
        }