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 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
170 Load (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector, theMode);
172 if (!theObject->HasOwnPresentations())
175 SelectMgr_SequenceOfSelector aSelectors;
176 aSelectors.Append (theSelector);
177 myLocal.Bind (theObject, aSelectors);
183 //==================================================
186 //==================================================
187 void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject)
189 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
191 Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()));
194 if (!theObject->HasOwnPresentations())
197 if (myGlobal.Contains (theObject))
199 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
201 Handle(SelectMgr_ViewerSelector) aCurSelector =
202 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
204 if (!aCurSelector->Contains (theObject))
207 for (theObject->Init(); theObject->More(); theObject->Next())
209 aCurSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
210 theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
212 aCurSelector->RemoveSelectableObject (theObject);
215 myGlobal.Remove (theObject);
217 else if (myLocal.IsBound (theObject))
219 SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
220 for (Standard_Integer aSelectorsIdx = 1; aSelectorsIdx <= aSelectors.Length(); aSelectorsIdx++)
222 Handle(SelectMgr_ViewerSelector) aCurSelector = aSelectors (aSelectorsIdx);
223 if (!aCurSelector->Contains (theObject))
226 for (theObject->Init(); theObject->More(); theObject->Next())
228 aCurSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
229 theObject->CurrentSelection()->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);
255 if (!theObject->HasOwnPresentations())
258 for (theObject->Init(); theObject->More(); theObject->Next())
260 theSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
261 theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
264 theSelector->RemoveSelectableObject (theObject);
266 if (myLocal.IsBound (theObject))
268 SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
269 for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= aSelectors.Length(); aSelectorIdx++)
271 if (aSelectors (aSelectorIdx) == theSelector)
273 aSelectors.Remove (aSelectorIdx);
278 if (aSelectors.IsEmpty())
280 myLocal.UnBind (theObject);
285 //==================================================
286 // Function: Activate
288 //==================================================
289 void SelectMgr_SelectionManager::Activate (const Handle(SelectMgr_SelectableObject)& theObject,
290 const Standard_Integer theMode,
291 const Handle(SelectMgr_ViewerSelector)& theSelector)
296 if (!theSelector.IsNull() && !mySelectors.Contains (theSelector))
299 for (PrsMgr_ListOfPresentableObjectsIter anChildIter (theObject->Children()); anChildIter.More(); anChildIter.Next())
301 Activate (Handle(SelectMgr_SelectableObject)::DownCast (anChildIter.Value()), theMode, theSelector);
304 if (!theObject->HasOwnPresentations())
307 Standard_Boolean isComputed = Standard_False;
308 if (theObject->HasSelection (theMode))
310 isComputed = theObject->Selection (theMode)->IsEmpty() ? 0 : 1;
314 loadMode (theObject, theMode);
316 if (theSelector.IsNull())
318 if (myGlobal.Contains (theObject))
320 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
322 Handle(SelectMgr_ViewerSelector) aCurSelector =
323 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
324 Activate (theObject, theMode, aCurSelector);
327 else if (myLocal.IsBound (theObject))
329 SelectMgr_SequenceOfSelector& theSelectors = myLocal.ChangeFind (theObject);
330 for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= theSelectors.Length(); aSelectorIdx++)
332 Handle(SelectMgr_ViewerSelector) aCurSelector = theSelectors (aSelectorIdx);
333 Activate (theObject, theMode, aCurSelector);
338 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
340 switch (aSelection->UpdateStatus())
342 case SelectMgr_TOU_Full:
343 if (theObject->HasSelection (theMode))
344 theSelector->RemoveSelectionOfObject (theObject, aSelection);
345 theObject->RecomputePrimitives (theMode);
346 case SelectMgr_TOU_Partial:
347 if(theObject->HasTransformation())
348 theObject->UpdateTransformations (aSelection);
349 theSelector->RebuildObjectsTree();
354 aSelection->UpdateStatus(SelectMgr_TOU_None);
356 switch (aSelection->BVHUpdateStatus())
358 case SelectMgr_TBU_Add:
359 case SelectMgr_TBU_Renew:
360 theSelector->AddSelectionToObject (theObject, aSelection);
362 case SelectMgr_TBU_Remove:
363 if (aSelection->GetSelectionState() == SelectMgr_SOS_Deactivated)
364 theSelector->AddSelectionToObject (theObject, aSelection);
369 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
371 if (myGlobal.Contains (theObject))
373 const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode();
374 if (theMode != aGlobalSelMode && theSelector->IsActive (theObject, aGlobalSelMode))
376 theSelector->Deactivate (theObject->Selection (aGlobalSelMode));
378 theSelector->Activate (theObject->Selection (theMode));
382 if (myLocal.IsBound (theObject))
384 if (FindIndex (myLocal.Find (theObject), theSelector) == 0)
385 (myLocal.ChangeFind (theObject)).Append (theSelector);
386 theSelector->Activate (theObject->Selection (theMode));
391 //==================================================
392 // Function: Deactivate
394 //==================================================
395 void SelectMgr_SelectionManager::Deactivate (const Handle(SelectMgr_SelectableObject)& theObject,
396 const Standard_Integer theMode,
397 const Handle(SelectMgr_ViewerSelector)& theSelector)
399 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
401 Deactivate (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
404 if (!theObject->HasOwnPresentations())
407 Standard_Boolean isInGlobal = myGlobal.Contains (theObject);
408 Standard_Boolean hasSelection = theMode == -1 ? Standard_True : theObject->HasSelection (theMode);
410 if (theSelector.IsNull())
412 Handle(SelectMgr_ViewerSelector) aSelector;
413 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
415 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
416 if (isInGlobal || myLocal.IsBound (theObject))
420 for (theObject->Init(); theObject->More(); theObject->Next())
422 aSelector->Deactivate (theObject->CurrentSelection());
428 aSelector->Deactivate (theObject->Selection (theMode));
437 for (theObject->Init(); theObject->More(); theObject->Next())
439 theSelector->Deactivate (theObject->CurrentSelection());
444 theSelector->Deactivate (theObject->Selection (theMode));
448 //=======================================================================
449 //function : IsActivated
451 //=======================================================================
452 Standard_Boolean SelectMgr_SelectionManager::IsActivated (const Handle(SelectMgr_SelectableObject)& theObject,
453 const Standard_Integer theMode,
454 const Handle(SelectMgr_ViewerSelector)& theSelector) const
456 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
458 if (IsActivated (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector))
459 return Standard_True;
462 if (!theObject->HasOwnPresentations())
463 return Standard_False;
465 if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
466 return Standard_False;
468 if (theMode == -1 && theSelector.IsNull())
470 for (theObject->Init(); theObject->More(); theObject->Next())
472 if (IsActivated (theObject, theObject->CurrentSelection()->Mode()))
473 return Standard_True;
476 return Standard_False;
479 if (!theObject->HasSelection (theMode))
480 return Standard_False;
482 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
483 if (theSelector.IsNull())
485 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
487 Handle(SelectMgr_ViewerSelector) aSelector (Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key()));
488 if (aSelector->Status (aSelection) == SelectMgr_SOS_Activated)
489 return Standard_True;
494 return theSelector->Status (aSelection) == SelectMgr_SOS_Activated;
497 return Standard_False;
500 //=======================================================================
501 //function : ClearSelectionStructures
502 //purpose : Removes sensitive entities from all viewer selectors
503 // after method Clear() was called to the selection they belonged to
504 // or it was recomputed somehow
505 //=======================================================================
506 void SelectMgr_SelectionManager::ClearSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
507 const Standard_Integer theMode,
508 const Handle(SelectMgr_ViewerSelector)& theSelector)
510 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
512 ClearSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
515 if (!theObj->HasOwnPresentations())
518 if (theSelector.IsNull())
520 if (!(myGlobal.Contains (theObj) || myLocal.IsBound(theObj)))
523 TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors);
524 Handle(SelectMgr_ViewerSelector) aSelector;
525 for( ; aSelectorsIter.More(); aSelectorsIter.Next())
527 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
528 ClearSelectionStructures (theObj, theMode, aSelector);
533 if (!(myGlobal.Contains (theObj) || myLocal.IsBound (theObj)))
538 if (theObj->HasSelection (theMode))
540 const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode);
541 if (theObj->HasSelection (theMode))
543 theSelector->RemoveSelectionOfObject (theObj, aSelection);
544 aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
550 for (theObj->Init(); theObj->More(); theObj->Next())
552 const Handle(SelectMgr_Selection)& aSelection = theObj->CurrentSelection();
553 theSelector->RemoveSelectionOfObject (theObj, aSelection);
554 aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
557 theSelector->RebuildObjectsTree();
561 //=======================================================================
562 //function : RestoreSelectionStructuress
563 //purpose : Re-adds newely calculated sensitive entities of recomputed selection
564 // defined by mode theMode to all viewer selectors contained that selection.
565 //=======================================================================
566 void SelectMgr_SelectionManager::RestoreSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
567 const Standard_Integer theMode,
568 const Handle(SelectMgr_ViewerSelector)& theSelector)
570 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
572 RestoreSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
575 if (!theObj->HasOwnPresentations())
578 if (theSelector.IsNull())
580 if (!(myGlobal.Contains (theObj) || myLocal.IsBound(theObj)))
583 TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors);
584 Handle(SelectMgr_ViewerSelector) aSelector;
585 for( ; aSelectorsIter.More(); aSelectorsIter.Next())
587 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
588 RestoreSelectionStructures (theObj, theMode, aSelector);
593 if (!(myGlobal.Contains (theObj) || myLocal.IsBound (theObj)))
598 if (theObj->HasSelection (theMode))
600 const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode);
601 if (theObj->HasSelection (theMode))
603 theSelector->AddSelectionToObject (theObj, aSelection);
604 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
610 for (theObj->Init(); theObj->More(); theObj->Next())
612 const Handle(SelectMgr_Selection)& aSelection = theObj->CurrentSelection();
613 theSelector->AddSelectionToObject (theObj, aSelection);
614 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
617 theSelector->RebuildObjectsTree();
621 //=======================================================================
622 //function : rebuildSelectionStructures
623 //purpose : Internal function that marks 1st level BVH of object theObj
625 //=======================================================================
626 void SelectMgr_SelectionManager::rebuildSelectionStructures (const Handle(SelectMgr_ViewerSelector)& theSelector)
628 if (theSelector.IsNull())
630 Handle(SelectMgr_ViewerSelector) aSelector;
631 for(TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
633 aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
634 rebuildSelectionStructures (aSelector);
639 theSelector->RebuildObjectsTree();
643 //==================================================
644 // Function: recomputeSelectionMode
646 //==================================================
647 void SelectMgr_SelectionManager::recomputeSelectionMode (const Handle(SelectMgr_SelectableObject)& theObject,
648 const Handle(SelectMgr_Selection)& theSelection,
649 const Standard_Integer theMode)
651 theSelection->UpdateStatus (SelectMgr_TOU_Full);
653 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
655 Handle(SelectMgr_ViewerSelector) aCurSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
657 ClearSelectionStructures (theObject, theMode, aCurSelector);
658 theObject->RecomputePrimitives (theMode);
659 RestoreSelectionStructures (theObject, theMode, aCurSelector);
660 theSelection->UpdateStatus (SelectMgr_TOU_None);
661 theSelection->UpdateBVHStatus (SelectMgr_TBU_None);
665 //==================================================
668 //==================================================
669 void SelectMgr_SelectionManager::RecomputeSelection (const Handle(SelectMgr_SelectableObject)& theObject,
670 const Standard_Boolean theIsForce,
671 const Standard_Integer theMode)
677 ClearSelectionStructures (theObject);
678 theObject->RecomputePrimitives();
679 theObject->UpdateTransformation();
680 RestoreSelectionStructures (theObject);
682 else if (theObject->HasSelection (theMode))
684 ClearSelectionStructures (theObject, theMode);
685 theObject->RecomputePrimitives (theMode);
686 theObject->UpdateTransformation();
687 RestoreSelectionStructures (theObject, theMode);
692 for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
694 RecomputeSelection (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theIsForce, theMode);
697 if (!theObject->HasOwnPresentations())
700 if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
705 for (theObject->Init(); theObject->More(); theObject->Next())
707 const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
708 Standard_Integer aSelMode = aSelection->Mode();
709 recomputeSelectionMode (theObject, aSelection, aSelMode);
714 if (!theObject->HasSelection (theMode))
717 const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
718 recomputeSelectionMode (theObject, aSelection, theMode);
722 //=======================================================================
724 //purpose : Selections are recalculated if they are flagged
725 // "TO RECALCULATE" and activated in one of selectors.
726 // If ForceUpdate = True, and they are "TO RECALCULATE"
727 // This is done without caring for the state of activation.
728 //=======================================================================
729 void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
730 const Standard_Boolean theIsForce)
732 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
734 Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theIsForce);
737 if (!theObject->HasOwnPresentations())
740 for (theObject->Init(); theObject->More(); theObject->Next())
742 const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
745 switch (aSelection->UpdateStatus())
747 case SelectMgr_TOU_Full:
748 ClearSelectionStructures (theObject, aSelection->Mode());
749 theObject->RecomputePrimitives (aSelection->Mode()); // no break on purpose...
750 RestoreSelectionStructures (theObject, aSelection->Mode());
751 case SelectMgr_TOU_Partial:
752 theObject->UpdateTransformations (aSelection);
753 rebuildSelectionStructures();
758 aSelection->UpdateStatus (SelectMgr_TOU_None);
759 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
762 for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
764 Handle(SelectMgr_ViewerSelector) aSelector (Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key()));
765 Update (theObject, aSelector, Standard_False);
770 //==================================================
772 // Purpose : Attention, it is required to know what is done...
773 //==================================================
774 void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
775 const Handle(SelectMgr_ViewerSelector)& theSelector,
776 const Standard_Boolean theIsForce)
778 if (!mySelectors.Contains (theSelector))
781 Standard_Boolean isKnown = myGlobal.Contains (theObject);
783 isKnown = (myLocal.IsBound (theObject) && (FindIndex (myLocal.Find (theObject), theSelector) != 0));
787 for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
789 Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theSelector, theIsForce);
792 if (!theObject->HasOwnPresentations())
795 for (theObject->Init(); theObject->More(); theObject->Next())
797 const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
800 switch (aSelection->UpdateStatus())
802 case SelectMgr_TOU_Full:
803 ClearSelectionStructures (theObject, aSelection->Mode());
804 theObject->RecomputePrimitives (aSelection->Mode());
805 RestoreSelectionStructures (theObject, aSelection->Mode());
806 case SelectMgr_TOU_Partial:
807 theObject->UpdateTransformations (aSelection);
808 rebuildSelectionStructures();
813 aSelection->UpdateStatus (SelectMgr_TOU_None);
814 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
817 if (theSelector->Status (aSelection) == SelectMgr_SOS_Activated)
819 switch (aSelection->UpdateStatus())
821 case SelectMgr_TOU_Full:
822 ClearSelectionStructures (theObject, aSelection->Mode(), theSelector);
823 theObject->RecomputePrimitives (aSelection->Mode());
824 RestoreSelectionStructures (theObject, aSelection->Mode(), theSelector);
825 case SelectMgr_TOU_Partial:
826 if (theObject->HasTransformation())
828 theObject->UpdateTransformations (aSelection);
829 theSelector->RebuildObjectsTree();
836 aSelection->UpdateStatus(SelectMgr_TOU_None);
837 aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
842 //==================================================
843 // Function: loadMode
844 // Purpose : Private Method
845 //==================================================
846 void SelectMgr_SelectionManager::loadMode (const Handle(SelectMgr_SelectableObject)& theObject,
847 const Standard_Integer theMode,
848 const Handle(SelectMgr_ViewerSelector)& theSelector)
853 if (!theObject->HasSelection (theMode))
855 Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
856 theObject->AddSelection (aNewSel, theMode);
857 if (theSelector.IsNull())
859 if (myGlobal.Contains (theObject))
861 TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors);
862 for ( ; aSelectorIter.More(); aSelectorIter.Next())
864 Handle(SelectMgr_ViewerSelector) aSelector =
865 Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
866 aSelector->AddSelectionToObject (theObject, aNewSel);
867 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
870 else if (myLocal.IsBound (theObject))
872 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
873 for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= aSelectors.Length(); ++aSelectorIdx)
875 aSelectors (aSelectorIdx)->AddSelectionToObject (theObject, aNewSel);
876 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
882 theSelector->AddSelectionToObject (theObject, aNewSel);
883 aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
886 else if (theObject->Selection (theMode)->IsEmpty())
888 if (theObject->Selection (theMode)->BVHUpdateStatus() == SelectMgr_TBU_Remove)
890 Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
891 theObject->AddSelection (aNewSel, theMode);
892 theObject->Selection (theMode)->UpdateBVHStatus (SelectMgr_TBU_Remove);
893 theObject->Selection (theMode)->SetSelectionState (SelectMgr_SOS_Deactivated);
898 //=======================================================================
899 //function : SetUpdateMode
901 //=======================================================================
902 void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
903 const SelectMgr_TypeOfUpdate theType)
905 for (theObject->Init(); theObject->More(); theObject->Next())
906 theObject->CurrentSelection()->UpdateStatus (theType);
909 //=======================================================================
910 //function : SetUpdateMode
912 //=======================================================================
913 void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
914 const Standard_Integer theMode,
915 const SelectMgr_TypeOfUpdate theType)
917 if (theObject->HasSelection (theMode))
918 theObject->Selection (theMode)->UpdateStatus (theType);
921 //=======================================================================
922 //function : SetSelectionSensitivity
923 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject and
924 // changes previous sensitivity value of all sensitive entities in selection with theMode
925 // to the given theNewSensitivity.
926 //=======================================================================
927 void SelectMgr_SelectionManager::SetSelectionSensitivity (const Handle(SelectMgr_SelectableObject)& theObject,
928 const Standard_Integer theMode,
929 const Standard_Integer theNewSens)
931 Standard_ASSERT_RAISE (theNewSens > 0,
932 "Error! Selection sensitivity have positive value.");
934 if (theObject.IsNull() || !theObject->HasSelection (theMode))
937 Handle(SelectMgr_Selection) aSel = theObject->Selection (theMode);
938 const Standard_Integer aPrevSens = aSel->Sensitivity();
939 aSel->SetSensitivity (theNewSens);
941 if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
944 if (myGlobal.Contains (theObject))
946 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
948 Handle(SelectMgr_ViewerSelector) aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
949 if (aSelector->Contains (theObject))
951 aSelector->myTolerances.Decrement (aPrevSens);
952 aSelector->myTolerances.Add (theNewSens);
953 aSelector->myToUpdateTolerance = Standard_True;
957 if (myLocal.IsBound (theObject))
959 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
960 for (SelectMgr_SequenceOfSelector::Iterator aLocalIter (aSelectors); aLocalIter.More(); aLocalIter.Next())
962 Handle(SelectMgr_ViewerSelector)& aCurSel = aLocalIter.ChangeValue();
963 aCurSel->myTolerances.Decrement (aPrevSens);
964 aCurSel->myTolerances.Add (theNewSens);
965 aCurSel->myToUpdateTolerance = Standard_True;
970 //=======================================================================
971 //function : UpdateSelection
973 //=======================================================================
974 void SelectMgr_SelectionManager::UpdateSelection (const Handle(SelectMgr_SelectableObject)& theObject)
976 if (myGlobal.Contains (theObject))
978 for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
980 Handle(SelectMgr_ViewerSelector) aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
981 if (aSelector->Contains (theObject))
983 aSelector->MoveSelectableObject (theObject);
988 if (myLocal.IsBound (theObject))
990 const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
991 for (SelectMgr_SequenceOfSelector::Iterator aSelectorsIter (aSelectors); aSelectorsIter.More(); aSelectorsIter.Next())
993 Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.ChangeValue();
994 if (aSelector->Contains (theObject))
996 aSelector->MoveSelectableObject (theObject);