示例#1
0
        /// <summary>
        /// Adds new leaves into the treeView and contructs the branches to get there by recursion
        /// </summary>
        /// <param name="elementIds"></param>
        /// <param name="treeNodes"></param>
        /// <param name="tree"></param>
        /// <param name="depth"></param>
        /// <param name="lowestDepth"></param>
        private void AddNodesToTree(
            List <ElementId> elementIds,
            TreeNodeCollection treeNodes,
            TreeStructure tree,
            Depth depth,
            Depth lowestDepth = Depth.Instance)
        {
            // If the method currently is at the lowestDepth...
            if (depth == lowestDepth)
            {
                // For every elementId...
                TreeNode node;
                foreach (ElementId id in elementIds)
                {
                    // Get a clone of the tree's cached node
                    node = CloneTreeNode(tree.ElementIdNodes[id]);
                    // Add the node into the treeNode
                    treeNodes.Add(node);
                    // Record the elementId and node to keep track of it and for easy access
                    this.curElementIds.Add(id);
                    this.leafNodes.Add(id, node);
                }
                // Exit out immediately
                return;
            }

            Depth nextDepth;
            SortedDictionary <string, List <ElementId> > grouping;

            // Get the next depth
            nextDepth = GetNextDepth(depth, lowestDepth);
            // Get the next grouping
            grouping = GetNextGrouping(elementIds, tree.ElementIdNodes, depth.ToString());

            // Sort the dictionary in alphebetical order
            grouping.OrderBy(key => key.Key);

            List <TreeNode> branches;

            foreach (KeyValuePair <string, List <ElementId> > kvp in grouping)
            {
                branches = treeNodes.Find(kvp.Key, false).ToList();

                if (branches.Count == 0)
                {
                    TreeNode brnch = new TreeNode();
                    brnch.Name = kvp.Key;
                    brnch.Text = kvp.Key;
                    // Put it into treeView
                    treeNodes.Add(brnch);
                    // Add it into branches
                    branches.Add(brnch);
                }

                foreach (TreeNode brnch in branches)
                {
                    AddNodesToTree(kvp.Value, brnch.Nodes, tree, nextDepth);
                }
            }
        }
示例#2
0
        public void ShowElementIds(HashSet <ElementId> elementIds, TreeStructure tree)
        {
            View view = this.View;

            if (view == null)
            {
                return;
            }

            // Get all the elementIds to show
            IEnumerable <Element> elements
                = from ElementId id in elementIds
                  select this.doc.GetElement(id);

            IEnumerable <ElementId> elementIdsToShow
                = from Element e in elements
                  where e.IsHidden(view)
                  select e.Id;

            if (elementIdsToShow.Count <ElementId>() == 0)
            {
                return;
            }

            // Update treeStructure of what the current hidden elementIds are
            foreach (ElementId id in elementIdsToShow)
            {
                if (!tree.HiddenNodes.ContainsKey(view.Id))
                {
                    continue;
                }

                tree.HiddenNodes[view.Id].Remove(id);

                if (tree.HiddenNodes[view.Id].Count == 0)
                {
                    tree.HiddenNodes.Remove(view.Id);
                }
            }

            using (Transaction tran = new Transaction(this.doc, "Show Elements"))
            {
                tran.Start();

                view.UnhideElements(elementIdsToShow.ToList());

                tran.Commit();
            }
        }
示例#3
0
        /// <summary>
        /// Commit the changes requested from the object's NodesToDel and NodesToAdd parameters
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="keepChangeLists"></param>
        public void CommitChanges(TreeStructure tree, bool keepChangeLists = false)
        {
            // Remove and add elementIds
            Remove(this.NodesToDel, this.leafNodes);
            Append(this.NodesToAdd, tree);

            this.treeView.Sort();

            // If the argument specifies to not keep the change lists, reset it by passing null to the lists
            if (!keepChangeLists)
            {
                this.NodesToDel = null;
                this.NodesToAdd = null;
            }
        }
示例#4
0
        /// <summary>
        /// Append the given elementIds into the treeView
        /// </summary>
        /// <param name="elementIds"></param>
        /// <param name="tree"></param>
        public void Append(
            List <ElementId> elementIds,
            TreeStructure tree
            )
        {
            // If there are no elementIds, then exit out
            if (elementIds.Count == 0)
            {
                return;
            }

            lock (treeLock)
            {
                // Call a method that will add treeNodes corresponding to the elementIds into treeView
                AddNodesToTree(elementIds, this.treeView.Nodes, tree, Depth.CategoryType);
            }
        }
示例#5
0
        public void HideElementIds(HashSet <ElementId> elementIds, TreeStructure tree)
        {
            View view = this.View;

            if (view == null)
            {
                return;
            }

            // Get all the elementIds to hide
            IEnumerable <Element> elements
                = from ElementId id in elementIds
                  select this.doc.GetElement(id);

            IEnumerable <ElementId> elementIdsToHide
                = from Element e in elements
                  where (e as View == null) &&
                  (e.CanBeHidden(view)) &&
                  (!e.IsHidden(view))
                  select e.Id;

            if (elementIdsToHide.Count <ElementId>() == 0)
            {
                return;
            }

            // Update treeStructure of what the current hidden elementIds are
            foreach (ElementId id in elementIdsToHide)
            {
                if (!tree.HiddenNodes.ContainsKey(view.Id))
                {
                    tree.HiddenNodes.Add(view.Id, new HashSet <ElementId>());
                }
                tree.HiddenNodes[view.Id].Add(id);
            }

            using (Transaction tran = new Transaction(this.doc, "Hide Elements"))
            {
                tran.Start();

                view.HideElements(elementIdsToHide.ToList());

                tran.Commit();
            }
        }
示例#6
0
        public DataController(Document doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException();
            }

            this.allElements = new List <ElementId>();
            this.selElements = new List <ElementId>();
            // Fields related to movement
            this.movElements = new List <ElementId>();

            this.idsToHide = new HashSet <ElementId>();

            this.copyAndShift = true;
            this.coords       = new List <int>()
            {
                0, 0, 0
            };

            this.elementTree = new TreeStructure(doc);
        }
示例#7
0
        /// <summary>
        /// Updates the treeView's structure
        /// </summary>
        /// <param name="rCon"></param>
        public void CommitTree(
            TreeStructure tree,
            HashSet <ElementId> newElementIds = null
            )
        {
            // This method absolutely requires TreeStructure to work, throw an argument if no TreeStructure exists
            if (tree == null)
            {
                throw new ArgumentNullException();
            }

            // Modify the change lists if the corresponding argument isn't null
            if (newElementIds != null)
            {
                // Get the 'old' selected elementIds
                HashSet <ElementId> oldElementIds = this.treeController.CurElementIds;

                // Get all the elementIds from newElementIds that are NOT from oldElementIds to be added
                IEnumerable <ElementId> addList
                    = from ElementId id in newElementIds
                      where (!oldElementIds.Contains(id))
                      select id;
                // Get all the elementIds from oldElementIds that are NOT from newElementIds to be deleted
                IEnumerable <ElementId> delList
                    = from ElementId id in oldElementIds
                      where (!newElementIds.Contains(id))
                      select id;

                // Set the treeController's change lists so that it can be used when treeController.CommitChanges is called
                this.treeController.NodesToAdd = addList.ToList();
                this.treeController.NodesToDel = delList.ToList();
            }

            // Commit the following changes
            this.treeController.CommitChanges(tree);

            return;
        }