// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#include <SelectMgr_SelectionManager.hxx>
-#include <OSD_Environment.hxx>
-#include <SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors.hxx>
#include <SelectMgr_SelectableObject.hxx>
#include <SelectMgr_Selection.hxx>
-#include <SelectMgr_SelectionManager.hxx>
-#include <SelectMgr_SequenceOfSelector.hxx>
-#include <SelectMgr_ViewerSelector.hxx>
-#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_ListOfInteger.hxx>
-#include <TColStd_MapIteratorOfMapOfTransient.hxx>
-
-IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SelectionManager,MMgt_TShared)
-static Standard_Integer FindIndex (const SelectMgr_SequenceOfSelector& theSelectorsSeq,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
-{
- Standard_Integer aFoundIdx = 0;
-
- for (Standard_Integer anIdx = 1; anIdx <= theSelectorsSeq.Length() && aFoundIdx==0; anIdx++)
- {
- if (theSelector == theSelectorsSeq.Value (anIdx))
- aFoundIdx = anIdx;
- }
-
- return aFoundIdx;
-}
+IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SelectionManager,Standard_Transient)
//==================================================
// Function: Create
// Purpose :
//==================================================
-SelectMgr_SelectionManager::SelectMgr_SelectionManager() {}
-
-//==================================================
-// Function: Add
-// Purpose :
-//==================================================
-void SelectMgr_SelectionManager::Add (const Handle(SelectMgr_ViewerSelector)& theSelector)
-{
- mySelectors.Add (theSelector);
-}
-
-//==================================================
-// Function: Remove
-// Purpose :
-//==================================================
-void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_ViewerSelector)& theSelector)
-{
- for (SelectMgr_DataMapIteratorOfDataMapOfObjectSelectors aSelIter (myLocal); aSelIter.More(); aSelIter.Next())
- {
- SelectMgr_SequenceOfSelector& theSelectors = myLocal.ChangeFind (aSelIter.Key());
- Standard_Integer aRank = FindIndex (theSelectors, theSelector);
- if (aRank != 0 && aRank <= theSelectors.Length())
- theSelectors.Remove (aRank);
- }
-
- if (mySelectors.Contains (theSelector))
- mySelectors.Remove (theSelector);
-}
-
-//==================================================
-// Function: Contains
-// Purpose :
-//==================================================
-Standard_Boolean SelectMgr_SelectionManager::Contains (const Handle(SelectMgr_ViewerSelector)& theSelector) const
+SelectMgr_SelectionManager::SelectMgr_SelectionManager (const Handle(SelectMgr_ViewerSelector)& theSelector)
+: mySelector (theSelector)
{
- return mySelectors.Contains (theSelector);
+ //
}
//==================================================
//==================================================
Standard_Boolean SelectMgr_SelectionManager::Contains (const Handle(SelectMgr_SelectableObject)& theObject) const
{
- if (myGlobal.Contains (theObject))
- return Standard_True;
-
- if (myLocal.IsBound (theObject))
- return Standard_True;
-
- return Standard_False;
+ return myGlobal.Contains (theObject);
}
//==================================================
return;
myGlobal.Add(theObject);
- for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
+ if (!mySelector->Contains (theObject) && theObject->HasOwnPresentations())
{
- Handle(SelectMgr_ViewerSelector) aSelector =
- Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- if (!aSelector->Contains (theObject) && theObject->HasOwnPresentations())
- {
- aSelector->AddSelectableObject (theObject);
- }
+ mySelector->AddSelectableObject (theObject);
}
if (theMode != -1)
loadMode (theObject, theMode);
}
-
-//==================================================
-// Function: Load
-// Purpose :
-//==================================================
-void SelectMgr_SelectionManager::Load (const Handle(SelectMgr_SelectableObject)& theObject,
- const Handle(SelectMgr_ViewerSelector)& theSelector,
- const Standard_Integer theMode)
-{
- if (!mySelectors.Contains (theSelector))
- {
- mySelectors.Add (theSelector);
- }
-
- if (theMode != -1)
- loadMode (theObject, theMode, theSelector);
-
- if (theObject->HasOwnPresentations())
- theSelector->AddSelectableObject (theObject);
-
- if (myLocal.IsBound (theObject))
- {
- SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
- if (FindIndex (aSelectors, theSelector) == 0)
- {
- aSelectors.Append (theSelector);
- }
- }
- else
- {
- if (!myGlobal.Contains (theObject))
- {
- if (theObject->HasOwnPresentations())
- {
- SelectMgr_SequenceOfSelector aSelectors;
- aSelectors.Append (theSelector);
- myLocal.Bind (theObject, aSelectors);
- }
- else
- {
- for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
- {
- Load (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector, theMode);
- }
- }
- }
- }
-}
-
-
//==================================================
// Function: Remove
// Purpose :
//==================================================
void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject)
{
- if (myGlobal.Contains (theObject))
- {
- for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aCurSelector =
- Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
-
- if (!aCurSelector->Contains (theObject))
- continue;
-
- for (theObject->Init(); theObject->More(); theObject->Next())
- {
- aCurSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
- theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
- }
- aCurSelector->RemoveSelectableObject (theObject);
- }
-
- myGlobal.Remove (theObject);
- }
- else if (myLocal.IsBound (theObject))
- {
- SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
- for (Standard_Integer aSelectorsIdx = 1; aSelectorsIdx <= aSelectors.Length(); aSelectorsIdx++)
- {
- Handle(SelectMgr_ViewerSelector) aCurSelector = aSelectors (aSelectorsIdx);
- if (!aCurSelector->Contains (theObject))
- continue;
-
- for (theObject->Init(); theObject->More(); theObject->Next())
- {
- aCurSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
- theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
- }
- aCurSelector->RemoveSelectableObject (theObject);
- }
-
- myLocal.UnBind (theObject);
- }
- else if (!theObject->HasOwnPresentations())
- {
- for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
- {
- Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()));
- }
- }
-
- theObject->ClearSelections();
-}
-
-//==================================================
-// Function: Remove
-// Purpose :
-//==================================================
-void SelectMgr_SelectionManager::Remove (const Handle(SelectMgr_SelectableObject)& theObject,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
-{
- if (!theSelector->Contains (theObject))
- return;
-
for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
{
- Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theSelector);
+ Remove (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()));
}
if (!theObject->HasOwnPresentations())
return;
- for (theObject->Init(); theObject->More(); theObject->Next())
- {
- theSelector->RemoveSelectionOfObject (theObject, theObject->CurrentSelection());
- theObject->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Remove);
- }
-
- theSelector->RemoveSelectableObject (theObject);
-
- if (myLocal.IsBound (theObject))
+ if (myGlobal.Contains (theObject))
{
- SelectMgr_SequenceOfSelector& aSelectors = myLocal.ChangeFind (theObject);
- for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= aSelectors.Length(); aSelectorIdx++)
+ if (mySelector->Contains (theObject))
{
- if (aSelectors (aSelectorIdx) == theSelector)
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
{
- aSelectors.Remove (aSelectorIdx);
- break;
+ mySelector->RemoveSelectionOfObject (theObject, aSelIter.Value());
+ aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Remove);
+ mySelector->Deactivate (aSelIter.Value());
}
+ mySelector->RemoveSelectableObject (theObject);
}
-
- if (aSelectors.IsEmpty())
- {
- myLocal.UnBind (theObject);
- }
+ myGlobal.Remove (theObject);
}
+
+ theObject->ClearSelections();
}
//==================================================
// Purpose :
//==================================================
void SelectMgr_SelectionManager::Activate (const Handle(SelectMgr_SelectableObject)& theObject,
- const Standard_Integer theMode,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
+ const Standard_Integer theMode)
{
if (theMode == -1)
return;
- if (!theSelector.IsNull() && !mySelectors.Contains (theSelector))
- return;
-
- if (!theObject->HasOwnPresentations())
+ for (PrsMgr_ListOfPresentableObjectsIter anChildIter (theObject->Children()); anChildIter.More(); anChildIter.Next())
{
- for (PrsMgr_ListOfPresentableObjectsIter anChildIter (theObject->Children()); anChildIter.More(); anChildIter.Next())
- {
- Activate (Handle(SelectMgr_SelectableObject)::DownCast (anChildIter.Value()), theMode, theSelector);
- }
-
- return;
+ Activate (Handle(SelectMgr_SelectableObject)::DownCast (anChildIter.Value()), theMode);
}
+ if (!theObject->HasOwnPresentations())
+ return;
Standard_Boolean isComputed = Standard_False;
- if (theObject->HasSelection (theMode))
+ if (const Handle(SelectMgr_Selection)& aSelOld = theObject->Selection (theMode))
{
- isComputed = theObject->Selection (theMode)->IsEmpty() ? 0 : 1;
+ isComputed = !aSelOld->IsEmpty();
}
-
if (!isComputed)
+ {
loadMode (theObject, theMode);
+ }
- if (theSelector.IsNull())
+ const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
+ switch (aSelection->UpdateStatus())
{
- if (myGlobal.Contains (theObject))
+ case SelectMgr_TOU_Full:
{
- for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
+ if (theObject->HasSelection (theMode))
{
- Handle(SelectMgr_ViewerSelector) aCurSelector =
- Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- Activate (theObject, theMode, aCurSelector);
+ mySelector->RemoveSelectionOfObject (theObject, aSelection);
}
+ theObject->RecomputePrimitives (theMode);
+ // pass through SelectMgr_TOU_Partial
}
- else if (myLocal.IsBound (theObject))
+ Standard_FALLTHROUGH
+ case SelectMgr_TOU_Partial:
{
- SelectMgr_SequenceOfSelector& theSelectors = myLocal.ChangeFind (theObject);
- for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= theSelectors.Length(); aSelectorIdx++)
- {
- Handle(SelectMgr_ViewerSelector) aCurSelector = theSelectors (aSelectorIdx);
- Activate (theObject, theMode, aCurSelector);
- }
- }
- }
-
- const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
-
- switch (aSelection->UpdateStatus())
- {
- case SelectMgr_TOU_Full:
- if (theObject->HasSelection (theMode))
- theSelector->RemoveSelectionOfObject (theObject, aSelection);
- theObject->RecomputePrimitives (theMode);
- case SelectMgr_TOU_Partial:
- if(theObject->HasTransformation())
theObject->UpdateTransformations (aSelection);
- theSelector->RebuildObjectsTree();
- break;
- default:
- break;
+ mySelector->RebuildObjectsTree();
+ break;
+ }
+ default:
+ break;
}
aSelection->UpdateStatus(SelectMgr_TOU_None);
switch (aSelection->BVHUpdateStatus())
{
- case SelectMgr_TBU_Add:
- case SelectMgr_TBU_Renew:
- theSelector->AddSelectionToObject (theObject, aSelection);
- break;
- case SelectMgr_TBU_Remove:
- if (aSelection->GetSelectionState() == SelectMgr_SOS_Deactivated)
- theSelector->AddSelectionToObject (theObject, aSelection);
- break;
- default:
- break;
+ case SelectMgr_TBU_Add:
+ case SelectMgr_TBU_Renew:
+ {
+ mySelector->AddSelectionToObject (theObject, aSelection);
+ break;
+ }
+ case SelectMgr_TBU_Remove:
+ {
+ if (aSelection->GetSelectionState() == SelectMgr_SOS_Deactivated)
+ {
+ mySelector->AddSelectionToObject (theObject, aSelection);
+ }
+ break;
+ }
+ default:
+ break;
}
aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
if (myGlobal.Contains (theObject))
{
- if (theMode != 0 && theSelector->IsActive (theObject, 0))
- {
- theSelector->Deactivate (theObject->Selection (0));
- }
- theSelector->Activate (theObject->Selection (theMode));
- }
- else
- {
- if (myLocal.IsBound (theObject))
- {
- if (FindIndex (myLocal.Find (theObject), theSelector) == 0)
- (myLocal.ChangeFind (theObject)).Append (theSelector);
- theSelector->Activate (theObject->Selection (theMode));
- }
+ mySelector->Activate (theObject->Selection (theMode));
}
}
// Purpose :
//==================================================
void SelectMgr_SelectionManager::Deactivate (const Handle(SelectMgr_SelectableObject)& theObject,
- const Standard_Integer theMode,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
+ const Standard_Integer theMode)
{
-
+ for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
+ {
+ Deactivate (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode);
+ }
if (!theObject->HasOwnPresentations())
{
- for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
- {
- Deactivate (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
- }
-
+ return;
+ }
+ if (!myGlobal.Contains(theObject))
+ {
return;
}
- Standard_Boolean isInGlobal = myGlobal.Contains (theObject);
- Standard_Boolean hasSelection = theMode == -1 ? Standard_True : theObject->HasSelection (theMode);
-
- if (theSelector.IsNull())
+ const Handle(SelectMgr_Selection)& aSel = theObject->Selection (theMode);
+ if (theMode == -1)
{
- Handle(SelectMgr_ViewerSelector) aSelector;
- for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
{
- aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
- if (isInGlobal || myLocal.IsBound (theObject))
- {
- if (theMode == -1)
- {
- for (theObject->Init(); theObject->More(); theObject->Next())
- {
- aSelector->Deactivate (theObject->CurrentSelection());
- }
- }
- else
- {
- if (hasSelection)
- aSelector->Deactivate (theObject->Selection (theMode));
- }
- }
+ mySelector->Deactivate (aSelIter.Value());
}
}
- else
+ else if (!aSel.IsNull())
{
- if (theMode == -1)
- {
- for (theObject->Init(); theObject->More(); theObject->Next())
- {
- theSelector->Deactivate (theObject->CurrentSelection());
- }
- }
- else
- if (hasSelection)
- theSelector->Deactivate (theObject->Selection (theMode));
+ mySelector->Deactivate (aSel);
}
}
//purpose :
//=======================================================================
Standard_Boolean SelectMgr_SelectionManager::IsActivated (const Handle(SelectMgr_SelectableObject)& theObject,
- const Standard_Integer theMode,
- const Handle(SelectMgr_ViewerSelector)& theSelector) const
+ const Standard_Integer theMode) const
{
+ for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
+ {
+ if (IsActivated (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode))
+ return Standard_True;
+ }
if (!theObject->HasOwnPresentations())
{
- for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObject->Children()); anChildrenIter.More(); anChildrenIter.Next())
- {
- if (IsActivated (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector))
- return Standard_True;
- }
-
return Standard_False;
}
-
- if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
+ if (!myGlobal.Contains(theObject))
+ {
return Standard_False;
+ }
- if (theMode == -1 && theSelector.IsNull())
+ if (theMode == -1)
{
- for (theObject->Init(); theObject->More(); theObject->Next())
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
{
- if (IsActivated (theObject, theObject->CurrentSelection()->Mode()))
+ if (mySelector->Status (aSelIter.Value()) == SelectMgr_SOS_Activated)
+ {
return Standard_True;
+ }
}
-
return Standard_False;
}
- if (!theObject->HasSelection (theMode))
- return Standard_False;
-
const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
- if (theSelector.IsNull())
- {
- for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aSelector (Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key()));
- if (aSelector->Status (aSelection) == SelectMgr_SOS_Activated)
- return Standard_True;
- }
- }
- else
+ if (aSelection.IsNull())
{
- return theSelector->Status (aSelection) == SelectMgr_SOS_Activated;
+ return Standard_False;
}
-
- return Standard_False;
+ return !aSelection.IsNull()
+ && mySelector->Status (aSelection) == SelectMgr_SOS_Activated;
}
//=======================================================================
// or it was recomputed somehow
//=======================================================================
void SelectMgr_SelectionManager::ClearSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
- const Standard_Integer theMode,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
+ const Standard_Integer theMode)
{
for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
{
- ClearSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
+ ClearSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode);
}
if (!theObj->HasOwnPresentations())
+ {
return;
-
- if (theSelector.IsNull())
+ }
+ if (!myGlobal.Contains(theObj))
{
- if (!(myGlobal.Contains (theObj) || myLocal.IsBound(theObj)))
- return;
+ return;
+ }
- TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors);
- Handle(SelectMgr_ViewerSelector) aSelector;
- for( ; aSelectorsIter.More(); aSelectorsIter.Next())
+ if (theMode != -1)
+ {
+ if (const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode))
{
- aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- ClearSelectionStructures (theObj, theMode, aSelector);
+ mySelector->RemoveSelectionOfObject (theObj, aSelection);
+ aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
}
}
else
{
- if (!(myGlobal.Contains (theObj) || myLocal.IsBound (theObj)))
- return;
-
- if (theMode != -1)
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObj->Selections()); aSelIter.More(); aSelIter.Next())
{
- if (theObj->HasSelection (theMode))
- {
- const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode);
- if (theObj->HasSelection (theMode))
- {
- theSelector->RemoveSelectionOfObject (theObj, aSelection);
- aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
- }
- }
+ const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
+ mySelector->RemoveSelectionOfObject (theObj, aSelection);
+ aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
}
- else
- {
- for (theObj->Init(); theObj->More(); theObj->Next())
- {
- const Handle(SelectMgr_Selection)& aSelection = theObj->CurrentSelection();
- theSelector->RemoveSelectionOfObject (theObj, aSelection);
- aSelection->UpdateBVHStatus (SelectMgr_TBU_Add);
- }
- }
- theSelector->RebuildObjectsTree();
}
+ mySelector->RebuildObjectsTree();
}
//=======================================================================
// defined by mode theMode to all viewer selectors contained that selection.
//=======================================================================
void SelectMgr_SelectionManager::RestoreSelectionStructures (const Handle(SelectMgr_SelectableObject)& theObj,
- const Standard_Integer theMode,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
+ const Standard_Integer theMode)
{
for (PrsMgr_ListOfPresentableObjectsIter anChildrenIter (theObj->Children()); anChildrenIter.More(); anChildrenIter.Next())
{
- RestoreSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode, theSelector);
+ RestoreSelectionStructures (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theMode);
}
-
if (!theObj->HasOwnPresentations())
- return;
-
- if (theSelector.IsNull())
{
- if (!(myGlobal.Contains (theObj) || myLocal.IsBound(theObj)))
- return;
-
- TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors);
- Handle(SelectMgr_ViewerSelector) aSelector;
- for( ; aSelectorsIter.More(); aSelectorsIter.Next())
- {
- aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- RestoreSelectionStructures (theObj, theMode, aSelector);
- }
+ return;
}
- else
+ if (!myGlobal.Contains(theObj))
{
- if (!(myGlobal.Contains (theObj) || myLocal.IsBound (theObj)))
- return;
-
- if (theMode != -1)
- {
- if (theObj->HasSelection (theMode))
- {
- const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode);
- if (theObj->HasSelection (theMode))
- {
- theSelector->AddSelectionToObject (theObj, aSelection);
- aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
- }
- }
- }
- else
- {
- for (theObj->Init(); theObj->More(); theObj->Next())
- {
- const Handle(SelectMgr_Selection)& aSelection = theObj->CurrentSelection();
- theSelector->AddSelectionToObject (theObj, aSelection);
- aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
- }
- }
- theSelector->RebuildObjectsTree();
+ return;
}
-}
-//=======================================================================
-//function : rebuildSelectionStructures
-//purpose : Internal function that marks 1st level BVH of object theObj
-// as outdated
-//=======================================================================
-void SelectMgr_SelectionManager::rebuildSelectionStructures (const Handle(SelectMgr_ViewerSelector)& theSelector)
-{
- if (theSelector.IsNull())
+ if (theMode != -1)
{
- Handle(SelectMgr_ViewerSelector) aSelector;
- for(TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
+ if (const Handle(SelectMgr_Selection)& aSelection = theObj->Selection (theMode))
{
- aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- rebuildSelectionStructures (aSelector);
+ mySelector->AddSelectionToObject (theObj, aSelection);
+ aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
}
}
else
{
- theSelector->RebuildObjectsTree();
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObj->Selections()); aSelIter.More(); aSelIter.Next())
+ {
+ const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
+ mySelector->AddSelectionToObject (theObj, aSelection);
+ aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
+ }
}
+ mySelector->RebuildObjectsTree();
}
//==================================================
{
theSelection->UpdateStatus (SelectMgr_TOU_Full);
- for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aCurSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
-
- ClearSelectionStructures (theObject, theMode, aCurSelector);
- theObject->RecomputePrimitives (theMode);
- RestoreSelectionStructures (theObject, theMode, aCurSelector);
- theSelection->UpdateStatus (SelectMgr_TOU_None);
- theSelection->UpdateBVHStatus (SelectMgr_TBU_None);
- }
+ ClearSelectionStructures (theObject, theMode);
+ theObject->RecomputePrimitives (theMode);
+ RestoreSelectionStructures (theObject, theMode);
+ theSelection->UpdateStatus (SelectMgr_TOU_None);
+ theSelection->UpdateBVHStatus (SelectMgr_TBU_None);
}
//==================================================
{
RecomputeSelection (Handle(SelectMgr_SelectableObject)::DownCast (anChildrenIter.Value()), theIsForce, theMode);
}
-
if (!theObject->HasOwnPresentations())
+ {
return;
-
- if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
+ }
+ if (!myGlobal.Contains (theObject))
+ {
return;
+ }
if (theMode == -1)
{
- for (theObject->Init(); theObject->More(); theObject->Next())
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
{
- const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
- Standard_Integer aSelMode = aSelection->Mode();
+ const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
+ const Standard_Integer aSelMode = aSelection->Mode();
recomputeSelectionMode (theObject, aSelection, aSelMode);
}
}
else
{
- if (!theObject->HasSelection (theMode))
- return;
-
- const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode);
- recomputeSelectionMode (theObject, aSelection, theMode);
+ if (const Handle(SelectMgr_Selection)& aSelection = theObject->Selection (theMode))
+ {
+ recomputeSelectionMode (theObject, aSelection, theMode);
+ }
}
}
{
Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theIsForce);
}
-
if (!theObject->HasOwnPresentations())
- return;
-
- for (theObject->Init(); theObject->More(); theObject->Next())
{
- const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
- if (theIsForce)
- {
- switch (aSelection->UpdateStatus())
- {
- case SelectMgr_TOU_Full:
- ClearSelectionStructures (theObject, aSelection->Mode());
- theObject->RecomputePrimitives (aSelection->Mode()); // no break on purpose...
- RestoreSelectionStructures (theObject, aSelection->Mode());
- case SelectMgr_TOU_Partial:
- theObject->UpdateTransformations (aSelection);
- rebuildSelectionStructures();
- break;
- default:
- break;
- }
- aSelection->UpdateStatus (SelectMgr_TOU_None);
- aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
- }
-
- for (TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors); aSelectorIter.More(); aSelectorIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aSelector (Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key()));
- Update (theObject, aSelector, Standard_False);
- }
- }
-}
-
-//==================================================
-// Function: Update
-// Purpose : Attention, it is required to know what is done...
-//==================================================
-void SelectMgr_SelectionManager::Update (const Handle(SelectMgr_SelectableObject)& theObject,
- const Handle(SelectMgr_ViewerSelector)& theSelector,
- const Standard_Boolean theIsForce)
-{
- if (!mySelectors.Contains (theSelector))
- return;
-
- Standard_Boolean isKnown = myGlobal.Contains (theObject);
- if (!isKnown)
- isKnown = (myLocal.IsBound (theObject) && (FindIndex (myLocal.Find (theObject), theSelector) != 0));
- if (!isKnown)
return;
-
- for (PrsMgr_ListOfPresentableObjectsIter aChildIter (theObject->Children()); aChildIter.More(); aChildIter.Next())
- {
- Update (Handle(SelectMgr_SelectableObject)::DownCast (aChildIter.Value()), theSelector, theIsForce);
}
- if (!theObject->HasOwnPresentations())
- return;
-
- for (theObject->Init(); theObject->More(); theObject->Next())
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
{
- const Handle(SelectMgr_Selection)& aSelection = theObject->CurrentSelection();
- if (theIsForce)
+ const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
+ if (theIsForce || mySelector->Status (aSelection) == SelectMgr_SOS_Activated)
{
switch (aSelection->UpdateStatus())
{
- case SelectMgr_TOU_Full:
- ClearSelectionStructures (theObject, aSelection->Mode());
- theObject->RecomputePrimitives (aSelection->Mode());
- RestoreSelectionStructures (theObject, aSelection->Mode());
- case SelectMgr_TOU_Partial:
- theObject->UpdateTransformations (aSelection);
- rebuildSelectionStructures();
- break;
- default:
- break;
- }
- aSelection->UpdateStatus (SelectMgr_TOU_None);
- aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
- }
-
- if (theSelector->Status (aSelection) == SelectMgr_SOS_Activated)
- {
- switch (aSelection->UpdateStatus())
- {
- case SelectMgr_TOU_Full:
- ClearSelectionStructures (theObject, aSelection->Mode(), theSelector);
- theObject->RecomputePrimitives (aSelection->Mode());
- RestoreSelectionStructures (theObject, aSelection->Mode(), theSelector);
- case SelectMgr_TOU_Partial:
- if (theObject->HasTransformation())
+ case SelectMgr_TOU_Full:
+ {
+ ClearSelectionStructures (theObject, aSelection->Mode());
+ theObject->RecomputePrimitives (aSelection->Mode()); // no break on purpose...
+ RestoreSelectionStructures (theObject, aSelection->Mode());
+ // pass through SelectMgr_TOU_Partial
+ }
+ Standard_FALLTHROUGH
+ case SelectMgr_TOU_Partial:
{
theObject->UpdateTransformations (aSelection);
- theSelector->RebuildObjectsTree();
+ mySelector->RebuildObjectsTree();
+ break;
}
- break;
- default:
- break;
+ default:
+ break;
}
-
- aSelection->UpdateStatus(SelectMgr_TOU_None);
+ aSelection->UpdateStatus (SelectMgr_TOU_None);
aSelection->UpdateBVHStatus (SelectMgr_TBU_None);
}
}
// Purpose : Private Method
//==================================================
void SelectMgr_SelectionManager::loadMode (const Handle(SelectMgr_SelectableObject)& theObject,
- const Standard_Integer theMode,
- const Handle(SelectMgr_ViewerSelector)& theSelector)
+ const Standard_Integer theMode)
{
if (theMode == -1)
+ {
return;
+ }
- if (!theObject->HasSelection (theMode))
+ if (const Handle(SelectMgr_Selection)& aSelOld = theObject->Selection (theMode))
{
- Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
- theObject->AddSelection (aNewSel, theMode);
- if (theSelector.IsNull())
+ if (aSelOld->IsEmpty())
{
- if (myGlobal.Contains (theObject))
- {
- TColStd_MapIteratorOfMapOfTransient aSelectorIter (mySelectors);
- for ( ; aSelectorIter.More(); aSelectorIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aSelector =
- Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorIter.Key());
- aSelector->AddSelectionToObject (theObject, aNewSel);
- aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
- }
- }
- else if (myLocal.IsBound (theObject))
+ if (aSelOld->BVHUpdateStatus() == SelectMgr_TBU_Remove)
{
- const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
- for (Standard_Integer aSelectorIdx = 1; aSelectorIdx <= aSelectors.Length(); ++aSelectorIdx)
- {
- aSelectors (aSelectorIdx)->AddSelectionToObject (theObject, aNewSel);
- aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
- }
+ Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
+ theObject->AddSelection (aNewSel, theMode);
+ aNewSel->UpdateBVHStatus (SelectMgr_TBU_Remove);
+ aNewSel->SetSelectionState (SelectMgr_SOS_Deactivated);
}
}
- else
- {
- theSelector->AddSelectionToObject (theObject, aNewSel);
- aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
- }
+ return;
}
- else if (theObject->Selection (theMode)->IsEmpty())
+
+ Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
+ theObject->AddSelection (aNewSel, theMode);
+ if (myGlobal.Contains (theObject))
{
- if (theObject->Selection (theMode)->BVHUpdateStatus() == SelectMgr_TBU_Remove)
- {
- Handle(SelectMgr_Selection) aNewSel = new SelectMgr_Selection (theMode);
- theObject->AddSelection (aNewSel, theMode);
- theObject->Selection (theMode)->UpdateBVHStatus (SelectMgr_TBU_Remove);
- theObject->Selection (theMode)->SetSelectionState (SelectMgr_SOS_Deactivated);
- }
+ mySelector->AddSelectionToObject (theObject, aNewSel);
+ aNewSel->UpdateBVHStatus (SelectMgr_TBU_None);
}
}
void SelectMgr_SelectionManager::SetUpdateMode (const Handle(SelectMgr_SelectableObject)& theObject,
const SelectMgr_TypeOfUpdate theType)
{
- for (theObject->Init(); theObject->More(); theObject->Next())
- theObject->CurrentSelection()->UpdateStatus (theType);
+ for (SelectMgr_SequenceOfSelection::Iterator aSelIter (theObject->Selections()); aSelIter.More(); aSelIter.Next())
+ {
+ aSelIter.Value()->UpdateStatus (theType);
+ }
}
//=======================================================================
const Standard_Integer theMode,
const SelectMgr_TypeOfUpdate theType)
{
- if (theObject->HasSelection (theMode))
- theObject->Selection (theMode)->UpdateStatus (theType);
+ if (const Handle(SelectMgr_Selection)& aSel = theObject->Selection (theMode))
+ {
+ aSel->UpdateStatus (theType);
+ }
}
//=======================================================================
const Standard_Integer theMode,
const Standard_Integer theNewSens)
{
- Standard_ASSERT_RAISE (theNewSens > 0,
- "Error! Selection sensitivity have positive value.");
+ Standard_ASSERT_RAISE (theNewSens > 0, "Error! Selection sensitivity have positive value.");
+ if (theObject.IsNull())
+ {
+ return;
+ }
- if (theObject.IsNull() || !theObject->HasSelection (theMode))
+ const Handle(SelectMgr_Selection)& aSel = theObject->Selection (theMode);
+ if (aSel.IsNull())
+ {
return;
+ }
- Handle(SelectMgr_Selection) aSel = theObject->Selection (theMode);
const Standard_Integer aPrevSens = aSel->Sensitivity();
aSel->SetSensitivity (theNewSens);
-
- if (!(myGlobal.Contains (theObject) || myLocal.IsBound (theObject)))
- return;
-
- if (myGlobal.Contains (theObject))
+ if (myGlobal.Contains (theObject)
+ && mySelector->Contains (theObject))
{
- for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- if (aSelector->Contains (theObject))
- {
- aSelector->myTolerances.Decrement (aPrevSens);
- aSelector->myTolerances.Add (theNewSens);
- aSelector->myToUpdateTolerance = Standard_True;
- }
- }
- }
- if (myLocal.IsBound (theObject))
- {
- const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
- for (SelectMgr_SequenceOfSelector::Iterator aLocalIter (aSelectors); aLocalIter.More(); aLocalIter.Next())
- {
- Handle(SelectMgr_ViewerSelector)& aCurSel = aLocalIter.ChangeValue();
- aCurSel->myTolerances.Decrement (aPrevSens);
- aCurSel->myTolerances.Add (theNewSens);
- aCurSel->myToUpdateTolerance = Standard_True;
- }
+ mySelector->myTolerances.Decrement (aPrevSens);
+ mySelector->myTolerances.Add (theNewSens);
+ mySelector->myToUpdateTolerance = Standard_True;
}
}
//=======================================================================
void SelectMgr_SelectionManager::UpdateSelection (const Handle(SelectMgr_SelectableObject)& theObject)
{
- if (myGlobal.Contains (theObject))
+ if (myGlobal.Contains (theObject)
+ && mySelector->Contains (theObject))
{
- for (TColStd_MapIteratorOfMapOfTransient aSelectorsIter (mySelectors); aSelectorsIter.More(); aSelectorsIter.Next())
- {
- Handle(SelectMgr_ViewerSelector) aSelector = Handle(SelectMgr_ViewerSelector)::DownCast (aSelectorsIter.Key());
- if (aSelector->Contains (theObject))
- {
- aSelector->MoveSelectableObject (theObject);
- }
- }
- }
-
- if (myLocal.IsBound (theObject))
- {
- const SelectMgr_SequenceOfSelector& aSelectors = myLocal (theObject);
- for (SelectMgr_SequenceOfSelector::Iterator aSelectorsIter (aSelectors); aSelectorsIter.More(); aSelectorsIter.Next())
- {
- Handle(SelectMgr_ViewerSelector)& aSelector = aSelectorsIter.ChangeValue();
- if (aSelector->Contains (theObject))
- {
- aSelector->MoveSelectableObject (theObject);
- }
- }
+ mySelector->MoveSelectableObject (theObject);
}
}