Esempio n. 1
0
        private void OptionFilterRadioButton_ChangeFilter(FilterMode filterMode)
        {
            if (requestHandler.FilterBy == filterMode)
            {
                return;
            }

            switch (filterMode)
            {
            case FilterMode.Project:
                requestHandler.FilterByProject();
                break;

            case FilterMode.View:
                requestHandler.FilterByView();
                break;

            case FilterMode.Selection:
                requestHandler.FilterBySelection();
                break;

            default:
                throw new InvalidEnumArgumentException("Error: filterMode is not Project, View, or Selection in this.optionController.GetFilterState()");
            }
        }
Esempio n. 2
0
        public bool SetSubSet(FilterMode mode, bool force = false)
        {
            if ((this.currentMode == mode) &&
                (this.currentMode != FilterMode.View) &&
                (!force))
            {
                return(false);
            }

            switch (mode)
            {
            case FilterMode.Project:
                this.subSet = new HashSet <ElementId>(this.setTree.Set);
                break;

            case FilterMode.View:
                List <ViewType> types = new List <ViewType>()
                {
                    ViewType.EngineeringPlan,
                    ViewType.FloorPlan,
                    ViewType.CeilingPlan,
                    ViewType.ThreeD,
                    ViewType.Elevation
                };

                View view = this.doc.ActiveView;

                if (!types.Contains(view.ViewType))
                {
                    return(false);
                }

                FilteredElementCollector collection = new FilteredElementCollector(this.doc, view.Id).WhereElementIsNotElementType();

                this.subSet.Clear();

                foreach (ElementId id in collection.ToElementIds())
                {
                    this.subSet.Add(id);
                }

                if (this.hiddenNodes.ContainsKey(view.Id))
                {
                    this.subSet.UnionWith(this.hiddenNodes[view.Id]);
                }

                break;

            case FilterMode.Selection:
                this.subSet = new HashSet <ElementId>(this.SelectedNodes);
                break;

            default:
                break;
            }

            this.currentMode = mode;

            return(true);
        }
Esempio n. 3
0
        private void OptionFilterRadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            this.haltIdlingHandler = true;

            FilterMode filterMode = optionController.GetFilterState();

            OptionFilterRadioButton_ChangeFilter(filterMode);

            this.haltIdlingHandler = false;
        }
Esempio n. 4
0
        public TreeStructure(Document doc)
        {
            this.doc = doc;

            this.elementIdNodes = new Dictionary <ElementId, TreeNode>();

            this.setTree      = new ElementSet();
            this.setTree.Name = "All";

            this.currentMode = FilterMode.Invalid;

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

            this.HiddenNodes   = new Dictionary <ElementId, HashSet <ElementId> >();
            this.SelectedNodes = new HashSet <ElementId>();
        }
Esempio n. 5
0
        /// <summary>
        /// Get the state of the filters
        /// </summary>
        /// <returns></returns>
        public FilterMode GetFilterState()
        {
            FilterMode output = FilterMode.Invalid;

            if (this.selectionRadioButton.Checked)
            {
                output = FilterMode.Selection;
            }
            else if (this.viewRadioButton.Checked)
            {
                output = FilterMode.View;
            }
            else if (this.projectRadioButton.Checked)
            {
                output = FilterMode.Project;
            }

            return(output);
        }
Esempio n. 6
0
        public List <ElementId> GetAllElementIds(FilterMode filter)
        {
            List <ElementId> output = null;

            switch (filter)
            {
            case FilterMode.Selection:
                output = GetElementIdsFromSelection();
                break;

            case FilterMode.View:
                output = GetElementIdsFromView();
                break;

            case FilterMode.Project:
                output = GetElementIdsFromDocument();
                break;

            default:
                break;
            }

            return(output);
        }
Esempio n. 7
0
        /// <summary>
        /// Handles the form's request to execute instructions within a revit API context
        /// </summary>
        private void HandleRequest_IdlingHandler(Request request)
        {
            FilterMode filter = requestHandler.FilterBy;

            switch (request)
            {
            case Request.UpdateTreeView:

                // debug.printText(dataController.SelElementIds, "SelElementIds Before", 1);

                // Step 1: Update all viewable elements for the current view
                bool changed = dataController.SetMode(filter);

                changed = true;
                // Step 1.1: Exit if dataController doesn't detect a change in viewable elements
                if (!changed)
                {
                    return;
                }

                Dictionary <Common.Depth, HashSet <string> > blackList;
                HashSet <string> bl = new HashSet <string>();

                blackList = filterController.FieldBlackList;
                bl.Clear();
                if (blackList.ContainsKey(Common.Depth.CategoryType))
                {
                    bl.UnionWith(blackList[Common.Depth.CategoryType]);
                }
                debug.printText(bl, "CategoryType temporary", 1);

                blackList = filterController.PersistentBlackList;
                bl.Clear();
                if (blackList.ContainsKey(Common.Depth.CategoryType))
                {
                    bl.UnionWith(blackList[Common.Depth.CategoryType]);
                }
                debug.printText(bl, "CategoryType persistent", 2);

                // Get the new elements by filtering all the elements reported by dataController
                HashSet <ElementId> newElementIds = filterController.FilterS(dataController.AllElements);
                // Get the old elements obtaining all the elements reported by selectionController
                HashSet <ElementId> oldElementIds = selectionController.AllElementIds;

                // Make a LINQ statement for addList
                var addList
                    = from ElementId id in newElementIds
                      where (!oldElementIds.Contains(id))
                      select id;
                // Make a LINQ statement for delList
                var delList
                    = from ElementId id in oldElementIds
                      where (!newElementIds.Contains(id))
                      select id;

                // Set nodes to add and nodes to delete
                selectionController.NodesToAdd = addList.ToList();
                selectionController.NodesToDel = delList.ToList();

                // Step 2: Update the treeView element outside of the API context
                this.BeginInvoke(new Action(() =>
                {
                    // Commit the changes to the TreeView
                    selectionController.CommitTree(dataController.ElementTree);
                    // selectionController.CommitTree(dataController.ElementTree, newElementIds);
                    // Refresh all node counters since the TreeView's nodes are mostly going to be changed
                    selectionController.RefreshAllNodeCounters(dataController);
                    // Update the selection counter label
                    selectionController.UpdateSelectionCounter();

                    // Update the HideNodeList
                    this.optionController.UpdateHideNodeList(dataController.ElementTree.SetTree, this.filterController);
                }));

                // Step 3: Update visibility state of the view
                Autodesk.Revit.DB.View view   = dataController.View;
                HashSet <ElementId>    hidden = new HashSet <ElementId>();
                if (optionController.GetVisibilityState())
                {
                    // Step 3.1a: Get hidden elements by the formula: hidden = AllElements - SelElements
                    hidden = new HashSet <ElementId>(dataController.AllElements.Except(dataController.SelElementIds));
                }
                else
                {
                    // Step 3.1b: To show all elements, we need to remove the previously hidden ids from the records (if there is any)
                    if (dataController.ElementTree.HiddenNodes.ContainsKey(view.Id))
                    {
                        dataController.ElementTree.HiddenNodes.Remove(view.Id);
                    }
                }

                // Step 4: Set dataController's ids to hide with hidden
                dataController.IdsToHide = hidden;

                // Step 5: Request ChangeElementVisibility
                requestHandler.AddRequest(Request.ChangeElementVisibility);

                requestHandler.AddRequest(Request.UpdateTreeViewSelection);

                break;

            case Request.UpdateTreeViewSelection:
                // Step 1: Update dataController's select element list
                HashSet <ElementId> newSelection = new HashSet <ElementId>(revitController.GetElementIdsFromSelection());
                // newSelection.IntersectWith(dataController.AllElements);
                newSelection.IntersectWith(selectionController.AllElementIds);
                HashSet <ElementId> oldSelection = dataController.SelElementIds;
                oldSelection.IntersectWith(selectionController.AllElementIds);
                // Step 2: Construct add and remove hashsets
                HashSet <ElementId> addSelection = new HashSet <ElementId>(newSelection.Except(oldSelection));
                HashSet <ElementId> remSelection = new HashSet <ElementId>(oldSelection.Except(newSelection));

                // DEBUG: Print out addSelection
                //StringBuilder sb = new StringBuilder();
                //sb.AppendLine("RemSelection");
                //foreach (ElementId id in remSelection)
                //{
                //    sb.AppendLine(id.ToString());
                //}
                //MessageBox.Show(sb.ToString());

                // Branch nodes to update


                // Step 3: Update selection by 'adding' and 'removing' selected treeNodes by checking and unchecking them
                this.BeginInvoke(new Action(() =>
                {
                    selectionController.UpdateSelectionByElementId(addSelection, true);
                    selectionController.UpdateSelectionByElementId(remSelection, false);
                    // selectionController.RefreshAllNodeCounters(dataController);
                    selectionController.UpdateAffectedCounter(addSelection.Union(remSelection), dataController);
                    selectionController.UpdateSelectionCounter();
                }));
                // Step 4: Update dataController efficiently
                // Mathematical visualization: SelElements = (currentSelection ^ revitSelection) U additionalSelection
                dataController.SelElementIds.IntersectWith(newSelection);
                dataController.SelElementIds.UnionWith(addSelection);

                // Step 3: (OPTIONAL) Hide the remaining elementIds
                if (optionController.GetVisibilityState())
                {
                    // Step 3.1: Get selected and all elemnts from dataController
                    HashSet <ElementId> sel = dataController.SelElementIds;
                    HashSet <ElementId> all = dataController.AllElements;
                    // Step 3.2: Get the elementIds that are supposed to be hidden by (hid = all - sel)
                    HashSet <ElementId> hid = new HashSet <ElementId>(all.Except(sel));
                    // Step 3.3: Set dataController's requested ids to hide (NOT ACTUAL HIDDEN ELEMENTIDS) to hid
                    dataController.IdsToHide = hid;
                    // Step 3.4: Immediately override the next request by Requesting ChangeElementVisibility
                    requestHandler.ImmediateRequest(Request.ChangeElementVisibility);
                }
                break;

            case Request.SelectElementIds:
                // Step 1: Make a new selection in Revit
                revitController.MakeNewSelection(dataController.SelElementIds.ToList());
                // Step 2: Update the selection's counter
                this.BeginInvoke(new Action(() =>
                {
                    // selectionController.RefreshAllNodeCounters(dataController);
                    selectionController.UpdateSelectionCounter();
                }));

                // Step 2: (OPTIONAL) Hide the remaining elementIds
                if (optionController.GetVisibilityState())
                {
                    // Step 2.1: Get selected and all elemnts from dataController
                    HashSet <ElementId> sel = dataController.SelElementIds;
                    HashSet <ElementId> all = dataController.AllElements;
                    // Step 2.2: Get the elementIds that are supposed to be hidden by (hid = all - sel)
                    HashSet <ElementId> hid = new HashSet <ElementId>(all.Except(sel));
                    // Step 2.3: Set dataController's requested ids to hide (NOT ACTUAL HIDDEN ELEMENTIDS) to hid
                    dataController.IdsToHide = hid;
                    // Step 2.4: Immediately override the next request by Requesting ChangeElementVisibility
                    requestHandler.ImmediateRequest(Request.ChangeElementVisibility);
                }
                break;

            case Request.ChangeElementVisibility:

                // Step 1: Get the previously hidden ids
                HashSet <ElementId>    prevHidden = new HashSet <ElementId>();
                Autodesk.Revit.DB.View v          = dataController.View;
                if (v != null)
                {
                    if (dataController.ElementTree.HiddenNodes.ContainsKey(v.Id))
                    {
                        prevHidden.UnionWith(dataController.ElementTree.HiddenNodes[v.Id]);
                    }
                }

                // Step 2: Get ids to Hide and Show
                // idsToHide = IdsToHide
                HashSet <ElementId> idsToHide = dataController.IdsToHide;
                // idsToShow = AllElements - prevHidden
                HashSet <ElementId> idsToShow = new HashSet <ElementId>(dataController.AllElements.Union(prevHidden));

                // Step 3: idsToShow = idsToShow - idsToHide
                idsToShow.ExceptWith(idsToHide);

                // Step 4: Hide elements if there is any
                if (idsToHide.Count != 0)
                {
                    revitController.HideElementIds(idsToHide, dataController.ElementTree);
                }

                // Step 5: Show elements if there is any
                if (idsToShow.Count != 0)
                {
                    revitController.ShowElementIds(idsToShow, dataController.ElementTree);
                }

                break;

            case Request.ShiftElements:
                // Step 1: Get all the needed information within dataController
                List <ElementId> idsToMove    = revitController.GetMovableElementIds(dataController.IdsToMove.ToList());
                List <int>       coords       = dataController.Coords;
                bool             copyAndShift = dataController.CopyAndShift;

                if (idsToMove.Count == 0)
                {
                    this.actionController.PromptNotValidElements();
                }

                // Step 2: Copy and move the elements via the Revit Controller using the given information and get back the affected elementIds
                // revitController.CopyAndMoveElements(idsToMove, coords, copyAndShift);
                List <ElementId> elementsAffected = revitController.CopyAndShiftElements(idsToMove, coords, copyAndShift);

                if (copyAndShift)
                {
                    this.dataController.AddToAllElements(elementsAffected);

                    this.selectionController.NodesToAdd = elementsAffected;
                    requestHandler.ImmediateRequest(Request.UpdateTreeView);
                }

                break;

            case Request.Nothing:
                if (RevitSelectionChanged())
                {
                    requestHandler.AddRequest(Request.UpdateTreeViewSelection);
                }

                break;

            default:
                break;
            }
        }
Esempio n. 8
0
        private void ModelessForm_Load(object sender, EventArgs e)
        {
            // Stop IdlingHandler from executing during initialization
            this.haltIdlingHandler = true;

            this.filterController.ClearAllFilters();

            this.requestHandler.ResetAll();

            this.requestHandler.AddRequest(Request.UpdateTreeView);

            this.requestHandler.AddRequest(Request.UpdateTreeViewSelection);

            // Set up Options
            List <System.EventHandler> visibilityHandler = new List <System.EventHandler>()
            {
                OptionVisibilityCheckBox_CheckedChanged
            };
            List <System.EventHandler> filterHandler = new List <System.EventHandler>()
            {
                OptionFilterRadioButton0_CheckedChanged,
                OptionFilterRadioButton1_CheckedChanged,
                OptionFilterRadioButton2_CheckedChanged
            };

            this.optionController.Reset(visibilityHandler, filterHandler);

            // Initialize action conditions
            bool hideUnselected = this.optionController.GetVisibilityState();

            if (hideUnselected)
            {
                requestHandler.HideUnselected(true);
            }
            else
            {
                requestHandler.ShowAll(true);
            }

            FilterMode filterMode = this.optionController.GetFilterState();

            switch (filterMode)
            {
            case FilterMode.Project:
                requestHandler.FilterByProject();
                break;

            case FilterMode.View:
                requestHandler.FilterByView();
                break;

            case FilterMode.Selection:
                requestHandler.FilterBySelection();
                break;

            default:
                throw new InvalidEnumArgumentException("Error: filterMode is not Project, View, or Selection in this.optionController.GetFilterState()");
            }

            // Begin first start up loop (where TreeStructure gets all its elements from the document)
            this.firstStartup = true;

            // Set up actionController
            this.actionController.Reset();

            // Resume IdlingHandler
            this.haltIdlingHandler = false;
        }
Esempio n. 9
0
 public bool SetMode(FilterMode mode, bool force = false)
 {
     return(this.elementTree.SetSubSet(mode, force));
 }