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.
18 #include <OSD_Environment.hxx>
19 #include <SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors.hxx>
20 #include <SelectMgr_SelectableObject.hxx>
21 #include <SelectMgr_Selection.hxx>
22 #include <SelectMgr_SelectionManager.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,MMgt_TShared)
33 static Standard_Integer FindIndex (const SelectMgr_SequenceOfSelector& theSelectorsSeq,
34 const Handle(SelectMgr_ViewerSelector)& theSelector)
36 Standard_Integer aFoundIdx = 0;
38 for (Standard_Integer anIdx = 1; anIdx <= theSelectorsSeq.Length() && aFoundIdx==0; anIdx++)
40 if (theSelector == theSelectorsSeq.Value (anIdx))
47 //==================================================
50 //==================================================
51 SelectMgr_SelectionManager::SelectMgr_SelectionManager() {}
53 //==================================================
56 //==================================================
57 void SelectMgr_SelectionManager::Add (const Handle(SelectMgr_ViewerSelector)& theSelector)
59 mySelectors.Add (theSelector);
62 //==================================================
65 //==================================================
66 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_ViewerSelector)& theSelector)
68 for (SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors aSelIter (myLocal); aSelIter.More(); aSelIter.Next())
70 SelectMgr_SequenceOfSelector& theSelectors = myLocal.ChangeFind (aSelIter.Key());
71 Standard_Integer aRank = FindIndex (theSelectors, theSelector);
72 if (aRank != 0 && aRank <= theSelectors.Length())
73 theSelectors.Remove (aRank);
76 if (mySelectors.Contains (theSelector))
77 mySelectors.Remove (theSelector);
80 //==================================================
83 //==================================================
84 Standard_Boolean SelectMgr_SelectionManager::Contains (const Handle(SelectMgr_ViewerSelector)& theSelector) const
86 return mySelectors.Contains (theSelector);
89 //==================================================
92 //==================================================
93 Standard_Boolean SelectMgr_SelectionManager::Contains (const Handle(SelectMgr_SelectableObject)& theObject) const
95 if (myGlobal.Contains (theObject))
98 if (myLocal.IsBound (theObject))
101 return Standard_False;
104 //==================================================
107 //==================================================
108 void SelectMgr_SelectionManager::Load (const Handle(SelectMgr_SelectableObject)& theObject,
109 const Standard_Integer theMode)
111 if (myGlobal.Contains(theObject))
114 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
116 Load (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode);
119 if (!theObject->HasOwnPresentations())
122 myGlobal.Add(theObject);
123 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
125 Handle(SelectMgr_ViewerSelector) aSelector =
126 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
127 if (!aSelector->Contains (theObject) && theObject->HasOwnPresentations())
129 aSelector->AddSelectableObject (theObject);
133 loadMode (theObject, theMode);
137 //==================================================
140 //==================================================
141 void SelectMgr_SelectionManager::Load (const Handle(SelectMgr_SelectableObject)& theObject,
142 const Handle(SelectMgr_ViewerSelector)& theSelector,
143 const Standard_Integer theMode)
145 if (!mySelectors.Contains (theSelector))
147 mySelectors.Add (theSelector);
151 loadMode (theObject, theMode, theSelector);
153 if (theObject->HasOwnPresentations())
154 theSelector->AddSelectableObject (theObject);
156 if (myLocal.IsBound (theObject))
158 SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
159 if (FindIndex (aSelectors, theSelector) == 0)
161 aSelectors.Append (theSelector);
166 if (!myGlobal.Contains (theObject))
168 if (theObject->HasOwnPresentations())
170 SelectMgr_SequenceOfSelector aSelectors;
171 aSelectors.Append (theSelector);
172 myLocal.Bind (theObject, aSelectors);
176 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
178 Load (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector, theMode);
186 //==================================================
189 //==================================================
190 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject)
192 if (myGlobal.Contains (theObject))
194 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
196 Handle(SelectMgr_ViewerSelector) aCurSelector =
197 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
199 if (!aCurSelector->Contains (theObject))
202 for (theObject->Init(); theObject->More(); theObject->Next())
204 aCurSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
205 theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
207 aCurSelector->RemoveSelectableObject (theObject);
210 myGlobal.Remove (theObject);
212 else if (myLocal.IsBound (theObject))
214 SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
215 for (Standard_Integer aSelectorsIdx = 1; aSelectorsIdx <= aSelectors.Length(); aSelectorsIdx++)
217 Handle(SelectMgr_ViewerSelector) aCurSelector = aSelectors (aSelectorsIdx);
218 if (!aCurSelector->Contains (theObject))
221 for (theObject->Init(); theObject->More(); theObject->Next())
223 aCurSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
224 theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
226 aCurSelector->RemoveSelectableObject (theObject);
229 myLocal.UnBind (theObject);
231 else if (!theObject->HasOwnPresentations())
233 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
235 Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()));
239 theObject->ClearSelections();
242 //==================================================
245 //==================================================
246 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject,
247 const Handle(SelectMgr_ViewerSelector)& theSelector)
249 if (!theSelector->Contains (theObject))
252 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
254 Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector);
257 if (!theObject->HasOwnPresentations())
260 for (theObject->Init(); theObject->More(); theObject->Next())
262 theSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
263 theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
266 theSelector->RemoveSelectableObject (theObject);
268 if (myLocal.IsBound (theObject))
270 SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
271 for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= aSelectors.Length(); aSelectorIdx++)
273 if (aSelectors (aSelectorIdx) == theSelector)
275 aSelectors.Remove (aSelectorIdx);
280 if (aSelectors.IsEmpty())
282 myLocal.UnBind (theObject);
287 //==================================================
288 // Function: Activate
290 //==================================================
291 void SelectMgr_SelectionManager::Activate (const Handle(SelectMgr_SelectableObject)& theObject,
292 const Standard_Integer theMode,
293 const Handle(SelectMgr_ViewerSelector)& theSelector)
298 if (!theSelector.IsNull() && !mySelectors.Contains (theSelector))
301 if (!theObject->HasOwnPresentations())
303 for (PrsMgr_ListOfPresentableObjectsIter anChildIter (theObject->Children()); anChildIter.More(); anChildIter.Next())
305 Activate (Handle(SelectMgr_SelectableObject)::DownCast (anChildIter.Value()), theMode, theSelector);
311 Standard_Boolean isComputed = Standard_False;
312 if (theObject->HasSelection (theMode))
314 isComputed = theObject->Selection (theMode)->IsEmpty() ? 0 : 1;
318 loadMode (theObject, theMode);
320 if (theSelector.IsNull())
322 if (myGlobal.Contains (theObject))
324 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
326 Handle(SelectMgr_ViewerSelector) aCurSelector =
327 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
328 Activate (theObject, theMode, aCurSelector);
331 else if (myLocal.IsBound (theObject))
333 SelectMgr_SequenceOfSelector& theSelectors = myLocal.ChangeFind (theObject);
334 for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= theSelectors.Length(); aSelectorIdx++)
336 Handle(SelectMgr_ViewerSelector) aCurSelector = theSelectors (aSelectorIdx);
337 Activate (theObject, theMode, aCurSelector);
342 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
344 switch (aSelection->UpdateStatus())
346 case SelectMgr_TOU_Full:
347 if (theObject->HasSelection (theMode))
348 theSelector->RemoveSelectionOfObject (theObject, aSelection);
349 theObject->RecomputePrimitives (theMode);
350 case SelectMgr_TOU_Partial:
351 if(theObject->HasTransformation())
352 theObject->UpdateTransformations (aSelection);
353 theSelector->RebuildObjectsTree();
358 aSelection->UpdateStatus(SelectMgr_TOU_None);
360 switch (aSelection->BVHUpdateStatus())
362 case SelectMgr_TBU_Add:
363 case SelectMgr_TBU_Renew:
364 theSelector->AddSelectionToObject (theObject, aSelection);
366 case SelectMgr_TBU_Remove:
367 if (aSelection->GetSelectionState() == SelectMgr_SOS_Deactivated)
368 theSelector->AddSelectionToObject (theObject, aSelection);
373 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
375 if (myGlobal.Contains (theObject))
377 if (theMode != 0 && theSelector->IsActive (theObject, 0))
379 theSelector->Deactivate (theObject->Selection (0));
381 theSelector->Activate (theObject->Selection (theMode));
385 if (myLocal.IsBound (theObject))
387 if (FindIndex (myLocal.Find (theObject), theSelector) == 0)
388 (myLocal.ChangeFind (theObject)).Append (theSelector);
389 theSelector->Activate (theObject->Selection (theMode));
394 //==================================================
395 // Function: Deactivate
397 //==================================================
398 void SelectMgr_SelectionManager::Deactivate (const Handle(SelectMgr_SelectableObject)& theObject,
399 const Standard_Integer theMode,
400 const Handle(SelectMgr_ViewerSelector)& theSelector)
403 if (!theObject->HasOwnPresentations())
405 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
407 Deactivate (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
413 Standard_Boolean isInGlobal = myGlobal.Contains (theObject);
414 Standard_Boolean hasSelection = theMode == -1 ? Standard_True : theObject->HasSelection (theMode);
416 if (theSelector.IsNull())
418 Handle(SelectMgr_ViewerSelector) aSelector;
419 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
421 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
422 if (isInGlobal || myLocal.IsBound (theObject))
426 for (theObject->Init(); theObject->More(); theObject->Next())
428 aSelector->Deactivate (theObject->CurrentSelection());
434 aSelector->Deactivate (theObject->Selection (theMode));
443 for (theObject->Init(); theObject->More(); theObject->Next())
445 theSelector->Deactivate (theObject->CurrentSelection());
450 theSelector->Deactivate (theObject->Selection (theMode));
454 //=======================================================================
455 //function : IsActivated
457 //=======================================================================
458 Standard_Boolean SelectMgr_SelectionManager::IsActivated (const Handle(SelectMgr_SelectableObject)& theObject,
459 const Standard_Integer theMode,
460 const Handle(SelectMgr_ViewerSelector)& theSelector) const
462 if (!theObject->HasOwnPresentations())
464 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
466 if (IsActivated (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector))
467 return Standard_True;
470 return Standard_False;
473 if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
474 return Standard_False;
476 if (theMode == -1 && theSelector.IsNull())
478 for (theObject->Init(); theObject->More(); theObject->Next())
480 if (IsActivated (theObject, theObject->CurrentSelection()->Mode()))
481 return Standard_True;
484 return Standard_False;
487 if (!theObject->HasSelection (theMode))
488 return Standard_False;
490 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
491 if (theSelector.IsNull())
493 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
495 Handle(SelectMgr_ViewerSelector) aSelector (Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key()));
496 if (aSelector->Status (aSelection) == SelectMgr_SOS_Activated)
497 return Standard_True;
502 return theSelector->Status (aSelection) == SelectMgr_SOS_Activated;
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())
526 if (theSelector.IsNull())
528 if (!(myGlobal.Contains (theObj) || myLocal.IsBound(theObj)))
531 TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors);
532 Handle(SelectMgr_ViewerSelector) aSelector;
533 for( ; aSelectorsIter.More(); aSelectorsIter.Next())
535 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
536 ClearSelectionStructures (theObj, theMode, aSelector);
541 if (!(myGlobal.Contains (theObj) || myLocal.IsBound (theObj)))
546 if (theObj->HasSelection (theMode))
548 const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode);
549 if (theObj->HasSelection (theMode))
551 theSelector->RemoveSelectionOfObject (theObj, aSelection);
552 aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
558 for (theObj->Init(); theObj->More(); theObj->Next())
560 const Handle(SelectMgr_Selection)& aSelection = theObj->CurrentSelection();
561 theSelector->RemoveSelectionOfObject (theObj, aSelection);
562 aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
565 theSelector->RebuildObjectsTree();
569 //=======================================================================
570 //function : RestoreSelectionStructuress
571 //purpose : Re-adds newely calculated sensitive entities of recomputed selection
572 // defined by mode theMode to all viewer selectors contained that selection.
573 //=======================================================================
574 void SelectMgr_SelectionManager::RestoreSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
575 const Standard_Integer theMode,
576 const Handle(SelectMgr_ViewerSelector)& theSelector)
578 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
580 RestoreSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
583 if (!theObj->HasOwnPresentations())
586 if (theSelector.IsNull())
588 if (!(myGlobal.Contains (theObj) || myLocal.IsBound(theObj)))
591 TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors);
592 Handle(SelectMgr_ViewerSelector) aSelector;
593 for( ; aSelectorsIter.More(); aSelectorsIter.Next())
595 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
596 RestoreSelectionStructures (theObj, theMode, aSelector);
601 if (!(myGlobal.Contains (theObj) || myLocal.IsBound (theObj)))
606 if (theObj->HasSelection (theMode))
608 const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode);
609 if (theObj->HasSelection (theMode))
611 theSelector->AddSelectionToObject (theObj, aSelection);
612 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
618 for (theObj->Init(); theObj->More(); theObj->Next())
620 const Handle(SelectMgr_Selection)& aSelection = theObj->CurrentSelection();
621 theSelector->AddSelectionToObject (theObj, aSelection);
622 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
625 theSelector->RebuildObjectsTree();
629 //=======================================================================
630 //function : rebuildSelectionStructures
631 //purpose : Internal function that marks 1st level BVH of object theObj
633 //=======================================================================
634 void SelectMgr_SelectionManager::rebuildSelectionStructures (const Handle(SelectMgr_ViewerSelector)& theSelector)
636 if (theSelector.IsNull())
638 Handle(SelectMgr_ViewerSelector) aSelector;
639 for(TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
641 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
642 rebuildSelectionStructures (aSelector);
647 theSelector->RebuildObjectsTree();
651 //==================================================
652 // Function: recomputeSelectionMode
654 //==================================================
655 void SelectMgr_SelectionManager::recomputeSelectionMode (const Handle(SelectMgr_SelectableObject)& theObject,
656 const Handle(SelectMgr_Selection)& theSelection,
657 const Standard_Integer theMode)
659 theSelection->UpdateStatus (SelectMgr_TOU_Full);
661 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
663 Handle(SelectMgr_ViewerSelector) aCurSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
665 ClearSelectionStructures (theObject, theMode, aCurSelector);
666 theObject->RecomputePrimitives (theMode);
667 RestoreSelectionStructures (theObject, theMode, aCurSelector);
668 theSelection->UpdateStatus (SelectMgr_TOU_None);
669 theSelection->UpdateBVHStatus (SelectMgr_TBU_None);
673 //==================================================
676 //==================================================
677 void SelectMgr_SelectionManager::RecomputeSelection (const Handle(SelectMgr_SelectableObject)& theObject,
678 const Standard_Boolean theIsForce,
679 const Standard_Integer theMode)
685 ClearSelectionStructures (theObject);
686 theObject->RecomputePrimitives();
687 theObject->UpdateTransformation();
688 RestoreSelectionStructures (theObject);
690 else if (theObject->HasSelection (theMode))
692 ClearSelectionStructures (theObject, theMode);
693 theObject->RecomputePrimitives (theMode);
694 theObject->UpdateTransformation();
695 RestoreSelectionStructures (theObject, theMode);
700 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
702 RecomputeSelection (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theIsForce, theMode);
705 if (!theObject->HasOwnPresentations())
708 if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
713 for (theObject->Init(); theObject->More(); theObject->Next())
715 const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
716 Standard_Integer aSelMode = aSelection->Mode();
717 recomputeSelectionMode (theObject, aSelection, aSelMode);
722 if (!theObject->HasSelection (theMode))
725 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
726 recomputeSelectionMode (theObject, aSelection, theMode);
730 //=======================================================================
732 //purpose : Selections are recalculated if they are flagged
733 // "TO RECALCULATE" and activated in one of selectors.
734 // If ForceUpdate = True, and they are "TO RECALCULATE"
735 // This is done without caring for the state of activation.
736 //=======================================================================
737 void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
738 const Standard_Boolean theIsForce)
740 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
742 Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theIsForce);
745 if (!theObject->HasOwnPresentations())
748 for (theObject->Init(); theObject->More(); theObject->Next())
750 const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
753 switch (aSelection->UpdateStatus())
755 case SelectMgr_TOU_Full:
756 ClearSelectionStructures (theObject, aSelection->Mode());
757 theObject->RecomputePrimitives (aSelection->Mode()); // no break on purpose...
758 RestoreSelectionStructures (theObject, aSelection->Mode());
759 case SelectMgr_TOU_Partial:
760 theObject->UpdateTransformations (aSelection);
761 rebuildSelectionStructures();
766 aSelection->UpdateStatus (SelectMgr_TOU_None);
767 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
770 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
772 Handle(SelectMgr_ViewerSelector) aSelector (Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key()));
773 Update (theObject, aSelector, Standard_False);
778 //==================================================
780 // Purpose : Attention, it is required to know what is done...
781 //==================================================
782 void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
783 const Handle(SelectMgr_ViewerSelector)& theSelector,
784 const Standard_Boolean theIsForce)
786 if (!mySelectors.Contains (theSelector))
789 Standard_Boolean isKnown = myGlobal.Contains (theObject);
791 isKnown = (myLocal.IsBound (theObject) && (FindIndex (myLocal.Find (theObject), theSelector) != 0));
795 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
797 Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theSelector, theIsForce);
800 if (!theObject->HasOwnPresentations())
803 for (theObject->Init(); theObject->More(); theObject->Next())
805 const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
808 switch (aSelection->UpdateStatus())
810 case SelectMgr_TOU_Full:
811 ClearSelectionStructures (theObject, aSelection->Mode());
812 theObject->RecomputePrimitives (aSelection->Mode());
813 RestoreSelectionStructures (theObject, aSelection->Mode());
814 case SelectMgr_TOU_Partial:
815 theObject->UpdateTransformations (aSelection);
816 rebuildSelectionStructures();
821 aSelection->UpdateStatus (SelectMgr_TOU_None);
822 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
825 if (theSelector->Status (aSelection) == SelectMgr_SOS_Activated)
827 switch (aSelection->UpdateStatus())
829 case SelectMgr_TOU_Full:
830 ClearSelectionStructures (theObject, aSelection->Mode(), theSelector);
831 theObject->RecomputePrimitives (aSelection->Mode());
832 RestoreSelectionStructures (theObject, aSelection->Mode(), theSelector);
833 case SelectMgr_TOU_Partial:
834 if (theObject->HasTransformation())
836 theObject->UpdateTransformations (aSelection);
837 theSelector->RebuildObjectsTree();
844 aSelection->UpdateStatus(SelectMgr_TOU_None);
845 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
850 //==================================================
851 // Function: loadMode
852 // Purpose : Private Method
853 //==================================================
854 void SelectMgr_SelectionManager::loadMode (const Handle(SelectMgr_SelectableObject)& theObject,
855 const Standard_Integer theMode,
856 const Handle(SelectMgr_ViewerSelector)& theSelector)
861 if (!theObject->HasSelection (theMode))
863 Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
864 theObject->AddSelection (aNewSel, theMode);
865 if (theSelector.IsNull())
867 if (myGlobal.Contains (theObject))
869 TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors);
870 for ( ; aSelectorIter.More(); aSelectorIter.Next())
872 Handle(SelectMgr_ViewerSelector) aSelector =
873 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
874 aSelector->AddSelectionToObject (theObject, aNewSel);
875 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
878 else if (myLocal.IsBound (theObject))
880 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
881 for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= aSelectors.Length(); ++aSelectorIdx)
883 aSelectors (aSelectorIdx)->AddSelectionToObject (theObject, aNewSel);
884 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
890 theSelector->AddSelectionToObject (theObject, aNewSel);
891 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
894 else if (theObject->Selection (theMode)->IsEmpty())
896 if (theObject->Selection (theMode)->BVHUpdateStatus() == SelectMgr_TBU_Remove)
898 Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
899 theObject->AddSelection (aNewSel, theMode);
900 theObject->Selection (theMode)->UpdateBVHStatus (SelectMgr_TBU_Remove);
901 theObject->Selection (theMode)->SetSelectionState (SelectMgr_SOS_Deactivated);
906 //=======================================================================
907 //function : SetUpdateMode
909 //=======================================================================
910 void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
911 const SelectMgr_TypeOfUpdate theType)
913 for (theObject->Init(); theObject->More(); theObject->Next())
914 theObject->CurrentSelection()->UpdateStatus (theType);
917 //=======================================================================
918 //function : SetUpdateMode
920 //=======================================================================
921 void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
922 const Standard_Integer theMode,
923 const SelectMgr_TypeOfUpdate theType)
925 if (theObject->HasSelection (theMode))
926 theObject->Selection (theMode)->UpdateStatus (theType);
929 //=======================================================================
930 //function : SetSelectionSensitivity
931 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject and
932 // changes previous sensitivity value of all sensitive entities in selection with theMode
933 // to the given theNewSensitivity.
934 //=======================================================================
935 void SelectMgr_SelectionManager::SetSelectionSensitivity (const Handle(SelectMgr_SelectableObject)& theObject,
936 const Standard_Integer theMode,
937 const Standard_Integer theNewSens)
939 Standard_ASSERT_RAISE (theNewSens > 0,
940 "Error! Selection sensitivity have positive value.");
942 if (theObject.IsNull() || !theObject->HasSelection (theMode))
945 Handle(SelectMgr_Selection) aSel = theObject->Selection (theMode);
946 const Standard_Integer aPrevSens = aSel->Sensitivity();
947 aSel->SetSensitivity (theNewSens);
949 if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
952 if (myGlobal.Contains (theObject))
954 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
956 Handle(SelectMgr_ViewerSelector) aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
957 if (aSelector->Contains (theObject))
959 aSelector->myTolerances.Decrement (aPrevSens);
960 aSelector->myTolerances.Add (theNewSens);
961 aSelector->myToUpdateTolerance = Standard_True;
965 if (myLocal.IsBound (theObject))
967 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
968 for (SelectMgr_SequenceOfSelector::Iterator aLocalIter (aSelectors); aLocalIter.More(); aLocalIter.Next())
970 Handle(SelectMgr_ViewerSelector)& aCurSel = aLocalIter.ChangeValue();
971 aCurSel->myTolerances.Decrement (aPrevSens);
972 aCurSel->myTolerances.Add (theNewSens);
973 aCurSel->myToUpdateTolerance = Standard_True;