1 // Created on: 1995-02-13
2 // Created by: Mister rmi
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <SelectMgr_SelectionManager.hxx>
19 #include <OSD_Environment.hxx>
20 #include <SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors.hxx>
21 #include <SelectMgr_SelectableObject.hxx>
22 #include <SelectMgr_Selection.hxx>
23 #include <SelectMgr_SequenceOfSelector.hxx>
24 #include <SelectMgr_ViewerSelector.hxx>
25 #include <Standard_Type.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TColStd_ListIteratorOfListOfInteger.hxx>
28 #include <TColStd_ListOfInteger.hxx>
29 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
31 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SelectionManager,Standard_Transient)
35 static bool containsSelector (const SelectMgr_SequenceOfSelector& theSelectorsSeq,
36 const Handle(SelectMgr_ViewerSelector)& theSelector)
38 for (SelectMgr_SequenceOfSelector::Iterator aSelectorIter (theSelectorsSeq); aSelectorIter.More(); aSelectorIter.Next())
40 if (aSelectorIter.Value() == theSelector)
49 //==================================================
52 //==================================================
53 SelectMgr_SelectionManager::SelectMgr_SelectionManager()
58 //==================================================
61 //==================================================
62 void SelectMgr_SelectionManager::Add (const Handle(SelectMgr_ViewerSelector)& theSelector)
64 mySelectors.Add (theSelector);
67 //==================================================
70 //==================================================
71 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_ViewerSelector)& theSelector)
73 for (SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors aSelIter (myLocal); aSelIter.More(); aSelIter.Next())
75 SelectMgr_SequenceOfSelector& theSelectors = myLocal.ChangeFind (aSelIter.Key());
76 for (SelectMgr_SequenceOfSelector::Iterator aSelectorIter (theSelectors); aSelectorIter.More(); aSelectorIter.Next())
78 if (aSelectorIter.Value() == theSelector)
80 theSelectors.Remove (aSelectorIter);
86 mySelectors.Remove (theSelector);
89 //==================================================
92 //==================================================
93 Standard_Boolean SelectMgr_SelectionManager::Contains (const Handle(SelectMgr_ViewerSelector)& theSelector) const
95 return mySelectors.Contains (theSelector);
98 //==================================================
101 //==================================================
102 Standard_Boolean SelectMgr_SelectionManager::Contains (const Handle(SelectMgr_SelectableObject)& theObject) const
104 return myGlobal.Contains (theObject)
105 || myLocal.IsBound (theObject);
108 //==================================================
111 //==================================================
112 void SelectMgr_SelectionManager::Load (const Handle(SelectMgr_SelectableObject)& theObject,
113 const Standard_Integer theMode)
115 if (myGlobal.Contains(theObject))
118 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
120 Load (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode);
123 if (!theObject->HasOwnPresentations())
126 myGlobal.Add(theObject);
127 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
129 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.Key();
130 if (!aSelector->Contains (theObject) && theObject->HasOwnPresentations())
132 aSelector->AddSelectableObject (theObject);
136 loadMode (theObject, theMode);
140 //==================================================
143 //==================================================
144 void SelectMgr_SelectionManager::Load (const Handle(SelectMgr_SelectableObject)& theObject,
145 const Handle(SelectMgr_ViewerSelector)& theSelector,
146 const Standard_Integer theMode)
148 mySelectors.Add (theSelector);
151 loadMode (theObject, theMode, theSelector);
154 if (theObject->HasOwnPresentations())
156 theSelector->AddSelectableObject (theObject);
159 if (SelectMgr_SequenceOfSelector* aSelectors = myLocal.ChangeSeek (theObject))
161 if (!containsSelector (*aSelectors, theSelector))
163 aSelectors->Append (theSelector);
168 if (!myGlobal.Contains (theObject))
170 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
172 Load (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector, theMode);
174 if (!theObject->HasOwnPresentations())
177 SelectMgr_SequenceOfSelector aGlobSelectors;
178 aGlobSelectors.Append (theSelector);
179 myLocal.Bind (theObject, aGlobSelectors);
184 //==================================================
187 //==================================================
188 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject)
190 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
192 Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()));
195 if (!theObject->HasOwnPresentations())
198 if (myGlobal.Contains (theObject))
200 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
202 const Handle(SelectMgr_ViewerSelector)& aCurSelector = aSelectorsIter.Key();
203 if (!aCurSelector->Contains (theObject))
208 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
210 aCurSelector->RemoveSelectionOfObject (theObject, aSelIter.Value());
211 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Remove);
213 aCurSelector->RemoveSelectableObject (theObject);
216 myGlobal.Remove (theObject);
218 else if (SelectMgr_SequenceOfSelector* aSelectors = myLocal.ChangeSeek (theObject))
220 for (SelectMgr_SequenceOfSelector::Iterator aSelectorIter (*aSelectors); aSelectorIter.More(); aSelectorIter.Next())
222 const Handle(SelectMgr_ViewerSelector)& aCurSelector = aSelectorIter.Value();
223 if (!aCurSelector->Contains (theObject))
226 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
228 aCurSelector->RemoveSelectionOfObject (theObject, aSelIter.Value());
229 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Remove);
231 aCurSelector->RemoveSelectableObject (theObject);
234 myLocal.UnBind (theObject);
237 theObject->ClearSelections();
240 //==================================================
243 //==================================================
244 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject,
245 const Handle(SelectMgr_ViewerSelector)& theSelector)
247 if (!theSelector->Contains (theObject))
250 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
252 Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector);
254 if (!theObject->HasOwnPresentations())
257 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
259 theSelector->RemoveSelectionOfObject (theObject, aSelIter.Value());
260 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Remove);
262 theSelector->RemoveSelectableObject (theObject);
264 if (SelectMgr_SequenceOfSelector* aSelectors = myLocal.ChangeSeek (theObject))
266 for (SelectMgr_SequenceOfSelector::Iterator aSelectorIter (*aSelectors); aSelectorIter.More(); aSelectorIter.Next())
268 if (aSelectorIter.Value() == theSelector)
270 aSelectors->Remove (aSelectorIter);
275 if (aSelectors->IsEmpty())
277 myLocal.UnBind (theObject);
282 //==================================================
283 // Function: Activate
285 //==================================================
286 void SelectMgr_SelectionManager::Activate (const Handle(SelectMgr_SelectableObject)& theObject,
287 const Standard_Integer theMode,
288 const Handle(SelectMgr_ViewerSelector)& theSelector)
293 if (!theSelector.IsNull() && !mySelectors.Contains (theSelector))
296 for (PrsMgr_ListOfPresentableObjectsIter anChildIter (theObject->Children()); anChildIter.More(); anChildIter.Next())
298 Activate (Handle(SelectMgr_SelectableObject)::DownCast (anChildIter.Value()), theMode, theSelector);
300 if (!theObject->HasOwnPresentations())
303 Standard_Boolean isComputed = Standard_False;
304 if (const Handle(SelectMgr_Selection)& aSelOld = theObject->Selection (theMode))
306 isComputed = !aSelOld->IsEmpty();
310 loadMode (theObject, theMode);
313 if (theSelector.IsNull())
315 if (myGlobal.Contains (theObject))
317 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
319 const Handle(SelectMgr_ViewerSelector)& aCurSelector = aSelectorsIter.Key();
320 Activate (theObject, theMode, aCurSelector);
323 else if (SelectMgr_SequenceOfSelector* aSelectors = myLocal.ChangeSeek (theObject))
325 for (SelectMgr_SequenceOfSelector::Iterator aSelectorIter (*aSelectors); aSelectorIter.More(); aSelectorIter.Next())
327 Handle(SelectMgr_ViewerSelector) aCurSelector = aSelectorIter.Value();
328 Activate (theObject, theMode, aCurSelector);
333 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
334 switch (aSelection->UpdateStatus())
336 case SelectMgr_TOU_Full:
338 if (theObject->HasSelection (theMode))
340 theSelector->RemoveSelectionOfObject (theObject, aSelection);
342 theObject->RecomputePrimitives (theMode);
343 // pass through SelectMgr_TOU_Partial
346 case SelectMgr_TOU_Partial:
348 theObject->UpdateTransformations (aSelection);
349 theSelector->RebuildObjectsTree();
355 aSelection->UpdateStatus(SelectMgr_TOU_None);
357 switch (aSelection->BVHUpdateStatus())
359 case SelectMgr_TBU_Add:
360 case SelectMgr_TBU_Renew:
362 theSelector->AddSelectionToObject (theObject, aSelection);
365 case SelectMgr_TBU_Remove:
367 if (aSelection->GetSelectionState() == SelectMgr_SOS_Deactivated)
369 theSelector->AddSelectionToObject (theObject, aSelection);
376 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
378 if (myGlobal.Contains (theObject))
380 theSelector->Activate (theObject->Selection (theMode));
384 if (SelectMgr_SequenceOfSelector* aSelectors = myLocal.ChangeSeek (theObject))
386 if (!containsSelector (*aSelectors, theSelector))
388 aSelectors->Append (theSelector);
390 theSelector->Activate (theObject->Selection (theMode));
395 //==================================================
396 // Function: Deactivate
398 //==================================================
399 void SelectMgr_SelectionManager::Deactivate (const Handle(SelectMgr_SelectableObject)& theObject,
400 const Standard_Integer theMode,
401 const Handle(SelectMgr_ViewerSelector)& theSelector)
403 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
405 Deactivate (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
407 if (!theObject->HasOwnPresentations())
411 if (!myGlobal.Contains(theObject)
412 && !myLocal.IsBound (theObject))
417 const Handle(SelectMgr_Selection)& aSel = theObject->Selection (theMode);
418 if (!theSelector.IsNull())
422 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
424 theSelector->Deactivate (aSelIter.Value());
427 else if (!aSel.IsNull())
429 theSelector->Deactivate (aSel);
434 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
436 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorIter.Key();
439 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
441 aSelector->Deactivate (aSelIter.Value());
444 else if (!aSel.IsNull())
446 aSelector->Deactivate (aSel);
451 //=======================================================================
452 //function : IsActivated
454 //=======================================================================
455 Standard_Boolean SelectMgr_SelectionManager::IsActivated (const Handle(SelectMgr_SelectableObject)& theObject,
456 const Standard_Integer theMode,
457 const Handle(SelectMgr_ViewerSelector)& theSelector) const
459 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
461 if (IsActivated (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector))
462 return Standard_True;
464 if (!theObject->HasOwnPresentations())
466 return Standard_False;
468 if (!myGlobal.Contains(theObject)
469 && !myLocal.IsBound (theObject))
471 return Standard_False;
474 if (theMode == -1 && theSelector.IsNull())
476 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
478 if (IsActivated (theObject, aSelIter.Value()->Mode()))
480 return Standard_True;
483 return Standard_False;
486 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
487 if (aSelection.IsNull())
489 return Standard_False;
492 if (!theSelector.IsNull())
494 return theSelector->Status (aSelection) == SelectMgr_SOS_Activated;
497 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
499 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorIter.Key();
500 if (aSelector->Status (aSelection) == SelectMgr_SOS_Activated)
502 return Standard_True;
505 return Standard_False;
508 //=======================================================================
509 //function : ClearSelectionStructures
510 //purpose : Removes sensitive entities from all viewer selectors
511 // after method Clear() was called to the selection they belonged to
512 // or it was recomputed somehow
513 //=======================================================================
514 void SelectMgr_SelectionManager::ClearSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
515 const Standard_Integer theMode,
516 const Handle(SelectMgr_ViewerSelector)& theSelector)
518 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
520 ClearSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
523 if (!theObj->HasOwnPresentations())
527 if (!myGlobal.Contains(theObj)
528 && !myLocal.IsBound (theObj))
533 if (theSelector.IsNull())
535 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
537 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.Key();
538 ClearSelectionStructures (theObj, theMode, aSelector);
545 if (const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode))
547 theSelector->RemoveSelectionOfObject (theObj, aSelection);
548 aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
553 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObj->Selections()); aSelIter.More(); aSelIter.Next())
555 const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
556 theSelector->RemoveSelectionOfObject (theObj, aSelection);
557 aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
560 theSelector->RebuildObjectsTree();
563 //=======================================================================
564 //function : RestoreSelectionStructuress
565 //purpose : Re-adds newely calculated sensitive entities of recomputed selection
566 // defined by mode theMode to all viewer selectors contained that selection.
567 //=======================================================================
568 void SelectMgr_SelectionManager::RestoreSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
569 const Standard_Integer theMode,
570 const Handle(SelectMgr_ViewerSelector)& theSelector)
572 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
574 RestoreSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
576 if (!theObj->HasOwnPresentations())
580 if (!myGlobal.Contains(theObj)
581 && !myLocal.IsBound (theObj))
586 if (theSelector.IsNull())
588 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
590 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.Key();
591 RestoreSelectionStructures (theObj, theMode, aSelector);
598 if (const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode))
600 theSelector->AddSelectionToObject (theObj, aSelection);
601 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
606 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObj->Selections()); aSelIter.More(); aSelIter.Next())
608 const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
609 theSelector->AddSelectionToObject (theObj, aSelection);
610 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
613 theSelector->RebuildObjectsTree();
616 //=======================================================================
617 //function : rebuildSelectionStructures
618 //purpose : Internal function that marks 1st level BVH of object theObj
620 //=======================================================================
621 void SelectMgr_SelectionManager::rebuildSelectionStructures (const Handle(SelectMgr_ViewerSelector)& theSelector)
623 if (!theSelector.IsNull())
625 theSelector->RebuildObjectsTree();
629 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
631 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.Key();
632 rebuildSelectionStructures (aSelector);
636 //==================================================
637 // Function: recomputeSelectionMode
639 //==================================================
640 void SelectMgr_SelectionManager::recomputeSelectionMode (const Handle(SelectMgr_SelectableObject)& theObject,
641 const Handle(SelectMgr_Selection)& theSelection,
642 const Standard_Integer theMode)
644 theSelection->UpdateStatus (SelectMgr_TOU_Full);
646 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
648 const Handle(SelectMgr_ViewerSelector)& aCurSelector = aSelectorIter.Key();
650 ClearSelectionStructures (theObject, theMode, aCurSelector);
651 theObject->RecomputePrimitives (theMode);
652 RestoreSelectionStructures (theObject, theMode, aCurSelector);
653 theSelection->UpdateStatus (SelectMgr_TOU_None);
654 theSelection->UpdateBVHStatus (SelectMgr_TBU_None);
658 //==================================================
661 //==================================================
662 void SelectMgr_SelectionManager::RecomputeSelection (const Handle(SelectMgr_SelectableObject)& theObject,
663 const Standard_Boolean theIsForce,
664 const Standard_Integer theMode)
670 ClearSelectionStructures (theObject);
671 theObject->RecomputePrimitives();
672 theObject->UpdateTransformation();
673 RestoreSelectionStructures (theObject);
675 else if (theObject->HasSelection (theMode))
677 ClearSelectionStructures (theObject, theMode);
678 theObject->RecomputePrimitives (theMode);
679 theObject->UpdateTransformation();
680 RestoreSelectionStructures (theObject, theMode);
685 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
687 RecomputeSelection (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theIsForce, theMode);
689 if (!theObject->HasOwnPresentations())
693 if (!myGlobal.Contains (theObject)
694 && !myLocal.IsBound (theObject))
701 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
703 const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
704 const Standard_Integer aSelMode = aSelection->Mode();
705 recomputeSelectionMode (theObject, aSelection, aSelMode);
710 if (const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode))
712 recomputeSelectionMode (theObject, aSelection, theMode);
717 //=======================================================================
719 //purpose : Selections are recalculated if they are flagged
720 // "TO RECALCULATE" and activated in one of selectors.
721 // If ForceUpdate = True, and they are "TO RECALCULATE"
722 // This is done without caring for the state of activation.
723 //=======================================================================
724 void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
725 const Standard_Boolean theIsForce)
727 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
729 Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theIsForce);
731 if (!theObject->HasOwnPresentations())
736 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
738 const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
741 switch (aSelection->UpdateStatus())
743 case SelectMgr_TOU_Full:
745 ClearSelectionStructures (theObject, aSelection->Mode());
746 theObject->RecomputePrimitives (aSelection->Mode()); // no break on purpose...
747 RestoreSelectionStructures (theObject, aSelection->Mode());
748 // pass through SelectMgr_TOU_Partial
751 case SelectMgr_TOU_Partial:
753 theObject->UpdateTransformations (aSelection);
754 rebuildSelectionStructures();
760 aSelection->UpdateStatus (SelectMgr_TOU_None);
761 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
764 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
766 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorIter.Key();
767 Update (theObject, aSelector, Standard_False);
772 //==================================================
774 // Purpose : Attention, it is required to know what is done...
775 //==================================================
776 void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
777 const Handle(SelectMgr_ViewerSelector)& theSelector,
778 const Standard_Boolean theIsForce)
780 if (!mySelectors.Contains (theSelector))
785 if (!myGlobal.Contains (theObject))
787 const SelectMgr_SequenceOfSelector* aSelectors = myLocal.Seek (theObject);
788 if (aSelectors == NULL
789 || !containsSelector (*aSelectors, theSelector))
795 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
797 Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theSelector, theIsForce);
799 if (!theObject->HasOwnPresentations())
804 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
806 const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
809 switch (aSelection->UpdateStatus())
811 case SelectMgr_TOU_Full:
813 ClearSelectionStructures (theObject, aSelection->Mode());
814 theObject->RecomputePrimitives (aSelection->Mode());
815 RestoreSelectionStructures (theObject, aSelection->Mode());
816 // pass through SelectMgr_TOU_Partial
819 case SelectMgr_TOU_Partial:
821 theObject->UpdateTransformations (aSelection);
822 rebuildSelectionStructures();
828 aSelection->UpdateStatus (SelectMgr_TOU_None);
829 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
832 if (theSelector->Status (aSelection) == SelectMgr_SOS_Activated)
834 switch (aSelection->UpdateStatus())
836 case SelectMgr_TOU_Full:
838 ClearSelectionStructures (theObject, aSelection->Mode(), theSelector);
839 theObject->RecomputePrimitives (aSelection->Mode());
840 RestoreSelectionStructures (theObject, aSelection->Mode(), theSelector);
841 // pass through SelectMgr_TOU_Partial
844 case SelectMgr_TOU_Partial:
846 theObject->UpdateTransformations (aSelection);
847 theSelector->RebuildObjectsTree();
854 aSelection->UpdateStatus (SelectMgr_TOU_None);
855 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
860 //==================================================
861 // Function: loadMode
862 // Purpose : Private Method
863 //==================================================
864 void SelectMgr_SelectionManager::loadMode (const Handle(SelectMgr_SelectableObject)& theObject,
865 const Standard_Integer theMode,
866 const Handle(SelectMgr_ViewerSelector)& theSelector)
873 if (const Handle(SelectMgr_Selection)& aSelOld = theObject->Selection (theMode))
875 if (aSelOld->IsEmpty())
877 if (aSelOld->BVHUpdateStatus() == SelectMgr_TBU_Remove)
879 Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
880 theObject->AddSelection (aNewSel, theMode);
881 aNewSel->UpdateBVHStatus (SelectMgr_TBU_Remove);
882 aNewSel->SetSelectionState (SelectMgr_SOS_Deactivated);
888 Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
889 theObject->AddSelection (aNewSel, theMode);
890 if (!theSelector.IsNull())
892 theSelector->AddSelectionToObject (theObject, aNewSel);
893 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
897 if (myGlobal.Contains (theObject))
899 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
901 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorIter.Key();
902 aSelector->AddSelectionToObject (theObject, aNewSel);
903 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
906 else if (SelectMgr_SequenceOfSelector* aSelectors = myLocal.ChangeSeek (theObject))
908 for (SelectMgr_SequenceOfSelector::Iterator aSelectorIter (*aSelectors); aSelectorIter.More(); aSelectorIter.Next())
910 aSelectorIter.Value()->AddSelectionToObject (theObject, aNewSel);
911 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
916 //=======================================================================
917 //function : SetUpdateMode
919 //=======================================================================
920 void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
921 const SelectMgr_TypeOfUpdate theType)
923 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
925 aSelIter.Value()->UpdateStatus (theType);
929 //=======================================================================
930 //function : SetUpdateMode
932 //=======================================================================
933 void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
934 const Standard_Integer theMode,
935 const SelectMgr_TypeOfUpdate theType)
937 if (const Handle(SelectMgr_Selection)& aSel = theObject->Selection (theMode))
939 aSel->UpdateStatus (theType);
943 //=======================================================================
944 //function : SetSelectionSensitivity
945 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject and
946 // changes previous sensitivity value of all sensitive entities in selection with theMode
947 // to the given theNewSensitivity.
948 //=======================================================================
949 void SelectMgr_SelectionManager::SetSelectionSensitivity (const Handle(SelectMgr_SelectableObject)& theObject,
950 const Standard_Integer theMode,
951 const Standard_Integer theNewSens)
953 Standard_ASSERT_RAISE (theNewSens > 0, "Error! Selection sensitivity have positive value.");
954 if (theObject.IsNull())
959 const Handle(SelectMgr_Selection)& aSel = theObject->Selection (theMode);
960 if (theObject.IsNull())
965 const Standard_Integer aPrevSens = aSel->Sensitivity();
966 aSel->SetSensitivity (theNewSens);
967 if (myGlobal.Contains (theObject))
969 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
971 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.Key();
972 if (aSelector->Contains (theObject))
974 aSelector->myTolerances.Decrement (aPrevSens);
975 aSelector->myTolerances.Add (theNewSens);
976 aSelector->myToUpdateTolerance = Standard_True;
980 if (myLocal.IsBound (theObject))
982 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
983 for (SelectMgr_SequenceOfSelector::Iterator aLocalIter (aSelectors); aLocalIter.More(); aLocalIter.Next())
985 Handle(SelectMgr_ViewerSelector)& aCurSel = aLocalIter.ChangeValue();
986 aCurSel->myTolerances.Decrement (aPrevSens);
987 aCurSel->myTolerances.Add (theNewSens);
988 aCurSel->myToUpdateTolerance = Standard_True;
993 //=======================================================================
994 //function : UpdateSelection
996 //=======================================================================
997 void SelectMgr_SelectionManager::UpdateSelection (const Handle(SelectMgr_SelectableObject)& theObject)
999 if (myGlobal.Contains (theObject))
1001 for (NCollection_Map<Handle(SelectMgr_ViewerSelector)>::Iterator aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
1003 const Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.Key();
1004 if (aSelector->Contains (theObject))
1006 aSelector->MoveSelectableObject (theObject);
1011 if (myLocal.IsBound (theObject))
1013 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
1014 for (SelectMgr_SequenceOfSelector::Iterator aSelectorsIter (aSelectors); aSelectorsIter.More(); aSelectorsIter.Next())
1016 Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.ChangeValue();
1017 if (aSelector->Contains (theObject))
1019 aSelector->MoveSelectableObject (theObject);