///Returns an element that includes tasks and parameters for target object recursively
        public static Hierarchy.Element GetTaskAndParametersStructureInTarget(object obj)
        {
            var parentElement = new Hierarchy.Element(obj);
            var resultObjects = new List <object>();

            if (obj is ITaskAssignable && (obj as ITaskAssignable).task != null)
            {
                resultObjects.Add((obj as ITaskAssignable).task);
            }
            if (obj is ISubTasksContainer)
            {
                var subs = (obj as ISubTasksContainer).GetSubTasks();
                if (subs != null)
                {
                    resultObjects.AddRange(subs);
                }
            }

            //this also handles ISubParametersContainer
            resultObjects.AddRange(BBParameter.GetObjectBBParameters(obj).ToArray());

            //recurse
            for (var i = 0; i < resultObjects.Count; i++)
            {
                parentElement.AddChild(GetTaskAndParametersStructureInTarget(resultObjects[i]));
            }

            return(parentElement);
        }
        ///Returns a structure of the graphs that includes Nodes, Connections, Tasks and BBParameters,
        ///but where node elements are parent to their respetive connections. Only possible for tree-like graphs.
        public Hierarchy.Element GetFullGraphHierarchy()
        {
            var root   = new Hierarchy.Element(this);
            int lastID = 0;

            if (primeNode != null)
            {
                root.AddChild(GetTreeNodeElement(primeNode, true, ref lastID));
            }
            for (var i = 0; i < allNodes.Count; i++)
            {
                var node = allNodes[i];
                if (node.ID > lastID && node.inConnections.Count == 0)
                {
                    root.AddChild(GetTreeNodeElement(node, true, ref lastID));
                }
            }
            return(root);
        }
        ///----------------------------------------------------------------------------------------------

        ///Returns a structure of the graphs that includes Nodes, Connections, Tasks and BBParameters,
        ///but with nodes elements all being root to the graph (instead of respective parent connections).
        virtual public Hierarchy.Element GetFlatGraphHierarchy()
        {
            var root   = new Hierarchy.Element(this);
            int lastID = 0;

            for (var i = 0; i < allNodes.Count; i++)
            {
                root.AddChild(GetTreeNodeElement(allNodes[i], false, ref lastID));
            }
            return(root);
        }