}
}
+//=======================================================================
+//function : isDetected
+//purpose :
+//=======================================================================
+Standard_Boolean AIS_InteractiveContext::isDetected (const Handle(AIS_InteractiveObject)& theObject)
+{
+ for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper(); aDetIter++)
+ {
+ Handle(SelectMgr_EntityOwner) aPicked = MainSelector()->Picked(myDetectedSeq(aDetIter));
+ Handle(AIS_InteractiveObject) anObj;
+ if (!aPicked.IsNull())
+ {
+ anObj = Handle(AIS_InteractiveObject)::DownCast(aPicked->Selectable());
+ }
+
+ if (!anObj.IsNull()
+ && anObj == theObject)
+ {
+ return Standard_True;
+ }
+ }
+ return Standard_False;
+}
+
//=======================================================================
//function : SetSelected
//purpose : Sets the whole object as selected and highlights it with selection color
}
// added to avoid untimely viewer update...
- mySelection->ClearAndSelect (anOwner);
+ const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
+ mySelection->ClearAndSelect (anOwner, myFilters, isDetected (anObj));
if (myAutoHilight)
{
unhighlightSelected();
}
- mySelection->ClearAndSelect (theOwner);
+ mySelection->ClearAndSelect (theOwner, myFilters, isDetected (anObject));
if (myAutoHilight)
{
Handle(Prs3d_Drawer) aCustomStyle;
return;
}
- if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
+ if (!myFilters->IsOk (theOwner) && !theOwner->IsSelected())
{
return;
}
- mySelection->Select (theOwner);
+ AIS_SelectionScheme aSelScheme = theOwner->IsSelected() ? AIS_SelectionScheme_Remove : AIS_SelectionScheme_Add;
+ const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
+ mySelection->Select (theOwner, myFilters, aSelScheme, isDetected (anObj));
if (myAutoHilight)
{
- const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
if (!aStatusPtr)
{
}
else
{
- const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
+ const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(theEntity->Selectable());
+ const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity, myFilters, AIS_SelectionScheme_Remove, isDetected (anObj));
theEntity->SetSelected (false);
return aSelStatus == AIS_SS_Removed;
}
Standard_EXPORT AIS_StatusOfDetection moveTo (const Handle(V3d_View)& theView,
const Standard_Boolean theToRedrawOnUpdate);
+ //! Returns True if the object is detected.
+ Standard_EXPORT Standard_Boolean isDetected (const Handle(AIS_InteractiveObject)& theObject);
+
//! Helper function to unhighlight all entity owners currently highlighted with seleciton color.
Standard_EXPORT void unselectOwners (const Handle(AIS_InteractiveObject)& theObject);
//function : Select
//purpose :
//=======================================================================
-AIS_SelectStatus AIS_Selection::Select (const Handle(SelectMgr_EntityOwner)& theObject)
+AIS_SelectStatus AIS_Selection::Select (const Handle(SelectMgr_EntityOwner)& theOwner,
+ const Handle(SelectMgr_Filter)& theFilter,
+ const AIS_SelectionScheme theSelScheme,
+ const Standard_Boolean theIsDetected)
{
- if (theObject.IsNull()
- || !theObject->HasSelectable())
+ if (theOwner.IsNull()
+ || !theOwner->HasSelectable())
{
return AIS_SS_NotDone;
}
- if (!myResultMap.IsBound (theObject))
+ const Standard_Boolean isDetected = theIsDetected
+ && (theFilter.IsNull() || theFilter->IsOk (theOwner));
+
+ const Standard_Boolean wasSelected = theOwner->IsSelected();
+ const Standard_Boolean toSelect = theOwner->Select (theSelScheme, isDetected);
+
+ if (toSelect && !wasSelected)
{
AIS_NListOfEntityOwner::Iterator aListIter;
- myresult.Append (theObject, aListIter);
- myResultMap.Bind (theObject, aListIter);
- theObject->SetSelected (Standard_True);
+ myresult.Append (theOwner, aListIter);
+ myResultMap.Bind (theOwner, aListIter);
+ theOwner->SetSelected (Standard_True);
return AIS_SS_Added;
}
- AIS_NListOfEntityOwner::Iterator aListIter = myResultMap.Find (theObject);
+ if (!toSelect && !wasSelected)
+ {
+ return AIS_SS_NotDone;
+ }
+
+ AIS_NListOfEntityOwner::Iterator aListIter = myResultMap.Find (theOwner);
if (myIterator == aListIter)
{
if (myIterator.More())
// In the mode of advanced mesh selection only one owner is created for all selection modes.
// It is necessary to check the current detected entity
// and remove the owner from map only if the detected entity is the same as previous selected (IsForcedHilight call)
- if (theObject->IsForcedHilight())
+ if (theOwner->IsForcedHilight())
{
return AIS_SS_Added;
}
myresult.Remove (aListIter);
- myResultMap.UnBind (theObject);
- theObject->SetSelected (Standard_False);
+ myResultMap.UnBind (theOwner);
+ theOwner->SetSelected (Standard_False);
// update list iterator for next object in <myresult> list if any
if (aListIter.More())
const Standard_Boolean theToAllowSelOverlap,
const Handle(SelectMgr_Filter)& theFilter)
{
- (void )theToAllowSelOverlap;
- switch (theSelScheme)
- {
- case AIS_SelectionScheme_UNKNOWN:
- {
- return;
- }
- case AIS_SelectionScheme_ReplaceExtra:
- {
- // If picked owners is equivalent to the selected then just clear selected
- // Else go to AIS_SelectionScheme_Replace
- if (thePickedOwners.Size() == myresult.Size())
- {
- Standard_Boolean isTheSame = Standard_True;
- for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
- {
- if (!myResultMap.IsBound (aSelIter.Value()))
- {
- isTheSame = Standard_False;
- break;
- }
- }
- if (isTheSame)
- {
- Clear();
- return;
- }
- }
- }
- Standard_FALLTHROUGH
- case AIS_SelectionScheme_Replace:
- {
- Clear();
- for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
- {
- appendOwner (aSelIter.Value(), theFilter);
- }
+ (void)theToAllowSelOverlap;
- return;
- }
- case AIS_SelectionScheme_Add:
- {
- for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
- {
- appendOwner (aSelIter.Value(), theFilter);
- }
- return;
- }
- case AIS_SelectionScheme_Remove:
- {
- for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
- {
- if (myResultMap.IsBound (aSelIter.Value()))
- {
- Select (aSelIter.Value());
- }
- }
- return;
- }
- case AIS_SelectionScheme_XOR:
+ if (theSelScheme == AIS_SelectionScheme_ReplaceExtra
+ && thePickedOwners.Size() == myresult.Size())
+ {
+ // If picked owners is equivalent to the selected then just clear selected.
+ Standard_Boolean isTheSame = Standard_True;
+ for (AIS_NArray1OfEntityOwner::Iterator aPickedIter (thePickedOwners); aPickedIter.More(); aPickedIter.Next())
{
- for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
+ if (!myResultMap.IsBound (aPickedIter.Value()))
{
- const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
- if (anOwner.IsNull()
- || !anOwner->HasSelectable()
- || !theFilter->IsOk (anOwner))
- {
- continue;
- }
-
- Select (anOwner);
+ isTheSame = Standard_False;
+ break;
}
- return;
}
- case AIS_SelectionScheme_Clear:
+ if (isTheSame)
{
- Clear();
- return;
+ Clear();
+ return;
}
}
+
+ if (theSelScheme == AIS_SelectionScheme_Replace
+ || theSelScheme == AIS_SelectionScheme_ReplaceExtra
+ || theSelScheme == AIS_SelectionScheme_Clear)
+ {
+ Clear();
+ }
+
+ for (AIS_NArray1OfEntityOwner::Iterator aPickedIter (thePickedOwners); aPickedIter.More(); aPickedIter.Next())
+ {
+ const Handle(SelectMgr_EntityOwner)& anOwner = aPickedIter.Value();
+ Select (anOwner, theFilter, theSelScheme, true);
+ }
}
//=======================================================================
//! creates a new selection.
Standard_EXPORT AIS_Selection();
-
+
//! removes all the object of the selection.
Standard_EXPORT virtual void Clear();
-
+
//! if the object is not yet in the selection, it will be added.
//! if the object is already in the selection, it will be removed.
- Standard_EXPORT virtual AIS_SelectStatus Select (const Handle(SelectMgr_EntityOwner)& theObject);
-
+ //! @param[in] theOwner element to change selection state
+ //! @param[in] theFilter context filter
+ //! @param[in] theSelScheme selection scheme
+ //! @param[in] theIsDetected flag of object detection
+ //! @return result of selection
+ Standard_EXPORT virtual AIS_SelectStatus Select (const Handle(SelectMgr_EntityOwner)& theOwner,
+ const Handle(SelectMgr_Filter)& theFilter,
+ const AIS_SelectionScheme theSelScheme,
+ const Standard_Boolean theIsDetected);
+
//! the object is always add int the selection.
//! faster when the number of objects selected is great.
Standard_EXPORT virtual AIS_SelectStatus AddSelect (const Handle(SelectMgr_EntityOwner)& theObject);
//! clears the selection and adds the object in the selection.
- virtual void ClearAndSelect (const Handle(SelectMgr_EntityOwner)& theObject)
+ //! @param[in] theObject element to change selection state
+ //! @param[in] theFilter context filter
+ //! @param[in] theIsDetected flag of object detection
+ virtual void ClearAndSelect (const Handle(SelectMgr_EntityOwner)& theObject,
+ const Handle(SelectMgr_Filter)& theFilter,
+ const Standard_Boolean theIsDetected)
{
Clear();
- Select (theObject);
+ Select (theObject, theFilter, AIS_SelectionScheme_Add, theIsDetected);
}
//! checks if the object is in the selection.
}
}
+// =======================================================================
+// function : Select
+// purpose :
+// =======================================================================
+Standard_Boolean SelectMgr_EntityOwner::Select (const AIS_SelectionScheme theSelScheme,
+ const Standard_Boolean theIsDetected) const
+{
+ switch (theSelScheme)
+ {
+ case AIS_SelectionScheme_UNKNOWN:
+ {
+ return myIsSelected;
+ }
+ case AIS_SelectionScheme_Replace:
+ {
+ return theIsDetected;
+ }
+ case AIS_SelectionScheme_Add:
+ {
+ return !myIsSelected || theIsDetected || IsForcedHilight();
+ }
+ case AIS_SelectionScheme_Remove:
+ {
+ return myIsSelected && !theIsDetected;
+ }
+ case AIS_SelectionScheme_XOR:
+ {
+ if (theIsDetected)
+ {
+ return !myIsSelected && !IsForcedHilight();
+ }
+ return myIsSelected;
+ }
+ case AIS_SelectionScheme_Clear:
+ {
+ return Standard_False;
+ }
+ case AIS_SelectionScheme_ReplaceExtra:
+ {
+ return theIsDetected;
+ }
+ }
+ return Standard_False;
+}
+
// =======================================================================
// function : DumpJson
// purpose :
#ifndef _SelectMgr_EntityOwner_HeaderFile
#define _SelectMgr_EntityOwner_HeaderFile
+#include <AIS_SelectionScheme.hxx>
#include <Aspect_VKey.hxx>
#include <PrsMgr_PresentationManager.hxx>
#include <SelectMgr_SelectableObject.hxx>
//! @param theIsSelected [in] shows if owner is selected.
void SetSelected (const Standard_Boolean theIsSelected) { myIsSelected = theIsSelected; }
+ //! If the object needs to be selected, it returns true.
+ //! @param[in] theSelScheme selection scheme
+ //! @param[in] theIsDetected flag of object detection
+ Standard_EXPORT Standard_Boolean Select (const AIS_SelectionScheme theSelScheme,
+ const Standard_Boolean theIsDetected) const;
+
//! Returns selection state.
Standard_DEPRECATED ("Deprecated method - IsSelected() should be used instead")
Standard_Integer State() const { return myIsSelected ? 1 : 0; }