From 02974a19c63611f77e62712b77cc8484dce1658d Mon Sep 17 00:00:00 2001 From: kgv Date: Sat, 3 Sep 2016 12:23:55 +0300 Subject: [PATCH] 0027805: Visualization - AIS_InteractiveContext::FitSelected() is broken for global selection AIS_Selection class has been cleaned up: - SelectMgr_EntityOwner is now used in interface instead of Standard_Transient. - Method ::Select() has been renamed to ::Clear() for clarity. - Dropped unused class fields. - Owners without Selectable are not added to the list (should never happen). SelectMgr_SelectableObject::BndBoxOfSelected() has been modified to properly compute bounding box of ALL selection Entities for specified Owner (only first Entity has been used before the patch). Methods of AIS_InteractiveContext::DisplaySelected(), ::SetSelectedAspect(), ::FitSelected(), ::SubIntensityOff() have been fixed (wrong DownCast). AIS_InteractiveContext::AddSelect() now handles properly AIS_InteractiveObject as argument. --- src/AIS/AIS_InteractiveContext.cxx | 46 ++- src/AIS/AIS_InteractiveContext.hxx | 8 +- src/AIS/AIS_InteractiveContext_1.cxx | 123 +++---- src/AIS/AIS_InteractiveContext_2.cxx | 2 +- src/AIS/AIS_LocalContext.cxx | 10 +- src/AIS/AIS_LocalContext.hxx | 2 +- src/AIS/AIS_LocalContext_1.cxx | 301 ++++++++---------- ...aMapOfTransientIteratorOfListTransient.hxx | 25 -- src/AIS/AIS_NListIteratorOfListTransient.hxx | 23 -- ...ansient.hxx => AIS_NListOfEntityOwner.hxx} | 4 +- src/AIS/AIS_Selection.cxx | 177 +++++----- src/AIS/AIS_Selection.hxx | 95 +++--- src/AIS/AIS_Selection.lxx | 50 --- src/AIS/FILES | 5 +- src/SelectMgr/SelectMgr_SelectableObject.cxx | 26 +- src/SelectMgr/SelectMgr_SelectableObject.hxx | 2 +- tests/bugs/vis/bug27805 | 26 ++ 17 files changed, 364 insertions(+), 561 deletions(-) delete mode 100644 src/AIS/AIS_NDataMapOfTransientIteratorOfListTransient.hxx delete mode 100644 src/AIS/AIS_NListIteratorOfListTransient.hxx rename src/AIS/{AIS_NListTransient.hxx => AIS_NListOfEntityOwner.hxx} (87%) delete mode 100644 src/AIS/AIS_Selection.lxx create mode 100644 tests/bugs/vis/bug27805 diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index 6400689f8b..a55caec2b5 100644 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -104,7 +104,7 @@ myIsAutoActivateSelMode(Standard_True) void AIS_InteractiveContext::Delete() const { // clear the current selection - mySelection->Select(); + mySelection->Clear(); // let's remove one reference explicitly. this operation's supposed to // be performed when mgrSelector will be destroyed but anyway... @@ -645,7 +645,7 @@ void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdate Standard_Boolean isFound = Standard_False; for (mySelection->Init(); mySelection->More(); mySelection->Next()) { - Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()); + Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable()); Display (anObj, Standard_False); isFound = Standard_True; } @@ -671,7 +671,7 @@ void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateVi mySelection->Init(); while (mySelection->More()) { - Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); + Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value(); Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); Erase (anObj, Standard_False); @@ -2198,10 +2198,10 @@ void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& } Standard_Boolean isFound = Standard_False; - for (mySelection->Init(); mySelection->More(); mySelection->Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { isFound = Standard_True; - Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()); + Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable()); anObj->SetAspect (theAspect); } @@ -2399,21 +2399,18 @@ void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& t //======================================================================= void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject) { - mySelection->Init(); - while (mySelection->More()) + SelectMgr_SequenceOfOwner aSeq; + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (anOwner->Selectable() == theObject) + if (aSelIter.Value()->Selectable() == theObject + && aSelIter.Value()->IsSelected()) { - if (anOwner->IsSelected()) - { - AddOrRemoveSelected (anOwner, Standard_False); - mySelection->Init(); - continue; - } + aSeq.Append (aSelIter.Value()); } - mySelection->Next(); + } + for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next()) + { + AddOrRemoveSelected (aDelIter.Value(), Standard_False); } } @@ -2889,22 +2886,21 @@ void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView, AIS_MapOfObjectOwners anObjectOwnerMap; for (aSelection->Init(); aSelection->More(); aSelection->Next()) { - Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value())); - if (!anObj.IsNull()) + const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value(); + Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); + if (anObj->IsInfinite()) { - if (anObj->IsInfinite()) - continue; + continue; + } + if (anOwner == anObj->GlobalSelOwner()) + { Bnd_Box aTmpBnd; anObj->BoundingBox (aTmpBnd); aBndSelected.Add (aTmpBnd); } else { - Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value())); - if (anOwner.IsNull()) - continue; - Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap; if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap)) { diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 73a2446cef..148ec6a467 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -881,7 +881,13 @@ public: Standard_EXPORT Standard_Integer HilightPreviousDetected (const Handle(V3d_View)& theView, const Standard_Boolean theToRedrawImmediate = Standard_True); //! Adds object in the selection. - Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(Standard_Transient)& theObject); + Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(SelectMgr_EntityOwner)& theObject); + + //! Adds object in the selection. + AIS_StatusOfPick AddSelect (const Handle(AIS_InteractiveObject)& theObject) + { + return AddSelect (theObject->GlobalSelOwner()); + } //! Selects everything found in the bounding rectangle //! defined by the pixel minima and maxima, XPMin, diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 7a1ce9ae75..56d77b7510 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -94,13 +94,12 @@ void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwn if (!theOwner->IsAutoHilight()) { SelectMgr_SequenceOfOwner aSeq; - for (mySelection->Init(); mySelection->More(); mySelection->Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - const Handle(SelectMgr_EntityOwner) aSelOwnr = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (aSelOwnr->Selectable() != anObj) - continue; - aSeq.Append (aSelOwnr); + if (aSelIter.Value()->Selectable() == anObj) + { + aSeq.Append (aSelIter.Value()); + } } anObj->HilightSelected (myMainPM, aSeq); } @@ -117,15 +116,10 @@ void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwn void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity) { NCollection_IndexedMap anObjToClear; - for (mySelection->Init(); mySelection->More(); mySelection->Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (anOwner.IsNull() || !anOwner->HasSelectable()) - continue; - - const Handle(AIS_InteractiveObject) anInteractive = - Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); + const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); + const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); if (anOwner->IsAutoHilight()) { const Standard_Integer aHiMode = anInteractive->HasHilightMode() ? anInteractive->HilightMode() : 0; @@ -313,7 +307,7 @@ AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer th //function : AddSelect //purpose : //======================================================================= -AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(Standard_Transient)& theObject) +AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject) { if (HasOpenedContext()) { @@ -461,7 +455,7 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdate { unhighlightSelected (Standard_True); - mySelection->Select(); + mySelection->Clear(); if (toUpdateViewer && myWasLastMain) { UpdateCurrentViewer(); @@ -768,41 +762,36 @@ void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdate // In case of selection without using local context myMainPM->ClearImmediateDraw(); AIS_MapOfObjSelectedOwners anObjOwnerMap; - for (mySelection->Init(); mySelection->More(); mySelection->Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (!anOwner.IsNull() && anOwner->HasSelectable()) + const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); + const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); + if (anOwner == anObj->GlobalSelOwner()) { - const Handle(AIS_InteractiveObject) anObj = - Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - if (anOwner == anObj->GlobalSelOwner()) - { - Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObj); - aState->SetHilightStatus (Standard_True); - aState->SetHilightColor (mySelectionColor); - } - anOwner->State (1); - if (!anOwner->IsAutoHilight()) + Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObj); + aState->SetHilightStatus (Standard_True); + aState->SetHilightColor (mySelectionColor); + } + anOwner->State (1); + if (!anOwner->IsAutoHilight()) + { + NCollection_Handle aSeq; + if (anObjOwnerMap.Find (anObj, aSeq)) { - NCollection_Handle aSeq; - if (anObjOwnerMap.Find (anObj, aSeq)) - { - aSeq->Append (anOwner); - } - else - { - aSeq = new SelectMgr_SequenceOfOwner(); - aSeq->Append (anOwner); - anObjOwnerMap.Bind (anObj, aSeq); - } + aSeq->Append (anOwner); } else { - const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0; - anOwner->HilightWithColor (myMainPM, mySelectionColor, aHiMode); + aSeq = new SelectMgr_SequenceOfOwner(); + aSeq->Append (anOwner); + anObjOwnerMap.Bind (anObj, aSeq); } } + else + { + const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HilightMode() : 0; + anOwner->HilightWithColor (myMainPM, mySelectionColor, aHiMode); + } } if (!anObjOwnerMap.IsEmpty()) @@ -829,22 +818,18 @@ void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpda return myLocalContexts (myCurLocalIndex)->UnhilightPicked (theToUpdateViewer); } - for (mySelection->Init(); mySelection->More(); mySelection->Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (!anOwner.IsNull() && anOwner->HasSelectable()) + const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); + const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); + if (anOwner == anObj->GlobalSelOwner()) { - const Handle(AIS_InteractiveObject) anObj = - Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); - if (anOwner == anObj->GlobalSelOwner()) - { - myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); - } - anOwner->State (0); - const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HasHilightMode() : 0; - anOwner->Unhilight (myMainPM, aHiMode); + myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False); } + + anOwner->State (0); + const Standard_Integer aHiMode = anObj->HasHilightMode() ? anObj->HasHilightMode() : 0; + anOwner->Unhilight (myMainPM, aHiMode); } if (theToUpdateViewer) @@ -866,7 +851,7 @@ void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateVi unhighlightSelected(); - mySelection->Select(); + mySelection->Clear(); myMainPM->ClearImmediateDraw(); if (theToUpdateViewer) @@ -922,10 +907,11 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t for (mySelection->Init(); mySelection->More(); mySelection->Next()) { - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner)) + const Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value(); + if (!myFilters->IsOk (anOwner)) + { continue; + } Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); @@ -1199,7 +1185,6 @@ void AIS_InteractiveContext::NextSelected() if(HasOpenedContext()) { return myLocalContexts (myCurLocalIndex)->NextSelected(); - return; } mySelection->Next(); @@ -1231,7 +1216,7 @@ TopoDS_Shape AIS_InteractiveContext::SelectedShape() const return myLocalContexts (myCurLocalIndex)->SelectedShape(); } - if (mySelection->Extent() == 0) + if (!mySelection->More()) return TopoDS_Shape(); const Handle(StdSelect_BRepOwner) anOwner = @@ -1253,12 +1238,9 @@ Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() cons return myLocalContexts(myCurLocalIndex)->SelectedInteractive(); } - const Handle(SelectMgr_EntityOwner) anOwner = - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()); - if (anOwner.IsNull() || !anOwner->HasSelectable()) - return NULL; - - return Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); + return !mySelection->More() + ? Handle(AIS_InteractiveObject)() + : Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable()); } //======================================================================= //function : SelectedOwner @@ -1271,8 +1253,9 @@ Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const return myLocalContexts(myCurLocalIndex)->SelectedOwner(); } - return mySelection->Extent() > 0 ? - Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value()) : NULL; + return !mySelection->More() + ? Handle(SelectMgr_EntityOwner)() + : mySelection->Value(); } //======================================================================= diff --git a/src/AIS/AIS_InteractiveContext_2.cxx b/src/AIS/AIS_InteractiveContext_2.cxx index a993c16b05..442b39d323 100644 --- a/src/AIS/AIS_InteractiveContext_2.cxx +++ b/src/AIS/AIS_InteractiveContext_2.cxx @@ -413,7 +413,7 @@ SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj, Standard_Integer DM,HM,SM; GetDefModes(anIObj,DM,HM,SM); - if(mySelection->IsSelected(anIObj)) + if(IsSelected(anIObj)) myMainPM->Highlight(anIObj,HM); if(updateviewer){ diff --git a/src/AIS/AIS_LocalContext.cxx b/src/AIS/AIS_LocalContext.cxx index d5eb7656f1..7c4f7dedac 100644 --- a/src/AIS/AIS_LocalContext.cxx +++ b/src/AIS/AIS_LocalContext.cxx @@ -612,13 +612,11 @@ void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate) // clear the selector... myMainVS->Clear(); - Handle(Standard_Transient) Tr; - for (mySelection->Init(); mySelection->More(); mySelection->Next()){ - Tr = mySelection->Value(); - Handle(SelectMgr_EntityOwner)::DownCast (Tr)->SetSelected (Standard_False); + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + { + aSelIter.Value()->SetSelected (Standard_False); } - - mySelection->Select(); + mySelection->Clear(); Handle(V3d_View) aDummyView; myMainVS->ClearSensitive (aDummyView); diff --git a/src/AIS/AIS_LocalContext.hxx b/src/AIS/AIS_LocalContext.hxx index 26d7b328ec..c8c648b205 100644 --- a/src/AIS/AIS_LocalContext.hxx +++ b/src/AIS/AIS_LocalContext.hxx @@ -167,7 +167,7 @@ public: Standard_EXPORT Standard_Boolean UnhilightLastDetected (const Handle(V3d_View)& aView); //! returns the number of selected - Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(Standard_Transient)& theObject); + Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(SelectMgr_EntityOwner)& theObject); Standard_EXPORT AIS_StatusOfPick Select (const Standard_Boolean updateviewer = Standard_True); diff --git a/src/AIS/AIS_LocalContext_1.cxx b/src/AIS/AIS_LocalContext_1.cxx index c1b3765dfb..5a866baacc 100644 --- a/src/AIS/AIS_LocalContext_1.cxx +++ b/src/AIS/AIS_LocalContext_1.cxx @@ -143,7 +143,7 @@ AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix, //function : AddSelect //purpose : //======================================================================= -AIS_StatusOfPick AIS_LocalContext::AddSelect (const Handle(Standard_Transient)& theObject) +AIS_StatusOfPick AIS_LocalContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject) { mySelection->AddSelect (theObject); @@ -168,7 +168,7 @@ AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer if (aDetIndex <= 0) { ClearSelected (toUpdateViewer); - return (mySelection->Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed; + return mySelection->IsEmpty() ? AIS_SOP_NothingSelected : AIS_SOP_Removed; } const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner->FindKey (aDetIndex); @@ -514,103 +514,92 @@ void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner, //======================================================================= //function : HilightPicked -//purpose : +//purpose : //======================================================================= -void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer) +void AIS_LocalContext::HilightPicked (const Standard_Boolean theToUpdateviewer) { - if( mySelection.IsNull() ) return; + if (mySelection.IsNull()) + { + return; + } - typedef NCollection_DataMap > SelectMgr_DataMapOfObjectOwners; + typedef NCollection_Shared SelectMgr_HSequenceOfOwner; + typedef NCollection_DataMap SelectMgr_DataMapOfObjectOwners; SelectMgr_DataMapOfObjectOwners aMap; - Handle (PrsMgr_PresentationManager3d) PM = myMainPM; - // to avoid problems when there is a loop searching for selected objects... - const AIS_NListTransient& Obj = mySelection->Objects(); - AIS_NListTransient::Iterator anIter( Obj ); - for(; anIter.More(); anIter.Next()) + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - const Handle(Standard_Transient)& Tr = anIter.Value(); - if(!Tr.IsNull()){ - const Handle(SelectMgr_EntityOwner)& Ownr = - *((const Handle(SelectMgr_EntityOwner)*) &Tr); - Handle(AIS_InteractiveObject) IO; - if(Ownr->HasSelectable()){ - Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); - if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ - Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); - IO = Handle(AIS_InteractiveObject)::DownCast (SO); - } - } - Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); - Standard_Integer HM = GetHiMod(Handle(AIS_InteractiveObject)::DownCast (SO)); - if ( Ownr->IsAutoHilight() ) - Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM); - else if ( aMap.IsBound (SO) ) - aMap(SO)->Append ( Ownr ); - else { - NCollection_Handle aSeq = new SelectMgr_SequenceOfOwner; - aSeq->Append ( Ownr ); - aMap.Bind ( SO, aSeq ); - } + const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value(); + Handle(SelectMgr_SelectableObject) aSelObj = anOwner->Selectable(); + if (anOwner->IsAutoHilight()) + { + Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(aSelObj); + const Standard_Integer aHighMode = GetHiMod (anIO); + anOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHighMode); + continue; + } + + Handle(SelectMgr_HSequenceOfOwner) aSeq; + if (aMap.Find (aSelObj, aSeq)) + { + aSeq->Append (anOwner); + } + else + { + aSeq = new SelectMgr_HSequenceOfOwner(); + aSeq->Append (anOwner); + aMap.Bind (aSelObj, aSeq); } } - for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap); - aMapIter.More(); aMapIter.Next() ) + for (SelectMgr_DataMapOfObjectOwners::Iterator aMapIter (aMap); aMapIter.More(); aMapIter.Next()) { aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value()); } - if (updateviewer) + if (theToUpdateviewer) { myCTX->CurrentViewer()->Update(); } } //================================================== -// Function: +// Function: UnhilightPicked // Purpose : //================================================== -void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer) +void AIS_LocalContext::UnhilightPicked (const Standard_Boolean theToUpdateViewer) { myMainPM->ClearImmediateDraw(); + if (mySelection.IsNull()) + { + return; + } - if( mySelection.IsNull() ) return; - Handle (PrsMgr_PresentationManager3d) PM = myMainPM; NCollection_Map anObjMap; - - const AIS_NListTransient& Obj = mySelection->Objects(); - AIS_NListTransient::Iterator anIter( Obj ); - for(; anIter.More(); anIter.Next()){ - const Handle(Standard_Transient)& Tr = anIter.Value(); - if(!Tr.IsNull()){ - const Handle(SelectMgr_EntityOwner)& Ownr = - *((const Handle(SelectMgr_EntityOwner)*) &Tr); - Standard_Integer HM(0); - if(Ownr->HasSelectable()){ - Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); - Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (SO); - anObjMap.Add (IO); - - HM = GetHiMod(IO); - Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); - if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ - } - } - Ownr->Unhilight(PM,HM); - } + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + { + const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value(); + Handle(SelectMgr_SelectableObject) aSelObj = anOwner->Selectable(); + Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aSelObj); + anObjMap.Add (aSelObj); + Standard_Integer aHighMode = GetHiMod (anIO); + anOwner->Unhilight (myMainPM, aHighMode); } - - for (NCollection_Map::Iterator anIter1 ( anObjMap ); - anIter1.More(); anIter1.Next() ) + + for (NCollection_Map::Iterator aMapIter (anObjMap); + aMapIter.More(); aMapIter.Next()) { - if ( !anIter1.Key()->IsAutoHilight() ) - anIter1.Key()->ClearSelected(); + if (!aMapIter.Key()->IsAutoHilight()) + { + aMapIter.Key()->ClearSelected(); + } } - if(updateviewer) + if (theToUpdateViewer) + { myCTX->CurrentViewer()->Update(); + } } //======================================================================= @@ -663,20 +652,20 @@ NextSelected() } //================================================== -// Function: +// Function: HasShape // Purpose : //================================================== -Standard_Boolean AIS_LocalContext:: -HasShape() const +Standard_Boolean AIS_LocalContext::HasShape() const { - Handle(Standard_Transient) Tr = mySelection->Value(); - if( Tr.IsNull() ) return Standard_False; - Handle(SelectMgr_EntityOwner) EO = Handle(SelectMgr_EntityOwner)::DownCast (Tr); - Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); - if(BRO.IsNull()) return Standard_False; - Standard_Boolean hasshape = BRO->HasShape(); - Standard_Boolean comes = BRO->ComesFromDecomposition(); - return (hasshape&&comes); + if (!mySelection->More()) + { + return Standard_False; + } + + Handle(StdSelect_BRepOwner) aBROwner = Handle(StdSelect_BRepOwner)::DownCast(mySelection->Value()); + return !aBROwner.IsNull() + && aBROwner->HasShape() + && aBROwner->ComesFromDecomposition(); } //================================================================ @@ -685,32 +674,29 @@ HasShape() const //================================================================ Standard_Boolean AIS_LocalContext::HasSelectedShape() const { - if (mySelection->Extent() == 0) - return Standard_False; - - Handle(Standard_Transient) aCurSelection = mySelection->Value(); - if (aCurSelection.IsNull()) - return Standard_False; - - Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSelection); - Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner); - if (aBrepOwner.IsNull()) + if (!mySelection->More()) { return Standard_False; } - return aBrepOwner->HasShape(); + + Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value()); + return !aBrepOwner.IsNull() + && aBrepOwner->HasShape(); } //================================================== -// Function: +// Function: SelectedShape // Purpose : //================================================== TopoDS_Shape AIS_LocalContext::SelectedShape() const { - Handle(Standard_Transient) aTr = mySelection->Value(); - Handle(SelectMgr_EntityOwner) anEO = Handle(SelectMgr_EntityOwner)::DownCast (aTr); - Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(anEO); - if( aBRO.IsNull() ) + if (!mySelection->More()) + { + return TopoDS_Shape(); + } + + Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(mySelection->Value()); + if (aBRO.IsNull()) { return TopoDS_Shape(); } @@ -719,48 +705,36 @@ TopoDS_Shape AIS_LocalContext::SelectedShape() const } //================================================== -// Function: +// Function: SelectedInteractive // Purpose : //================================================== -Handle(AIS_InteractiveObject) AIS_LocalContext:: -SelectedInteractive() const +Handle(AIS_InteractiveObject) AIS_LocalContext::SelectedInteractive() const { - Handle(AIS_InteractiveObject) IO; - Handle(Standard_Transient) Tr = mySelection->Value(); - if( !Tr.IsNull() ) { - Handle(SelectMgr_EntityOwner) EO = Handle(SelectMgr_EntityOwner)::DownCast (Tr); - Handle(SelectMgr_SelectableObject) SO; - if(EO->HasSelectable()){ - SO = EO->Selectable(); - IO = Handle(AIS_InteractiveObject)::DownCast (SO); - } - } - return IO; + return !mySelection->More() + ? Handle(AIS_InteractiveObject)() + : Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable()); } + //================================================== -// Function: +// Function: SelectedOwner // Purpose : //================================================== -Handle(SelectMgr_EntityOwner) AIS_LocalContext:: -SelectedOwner() const +Handle(SelectMgr_EntityOwner) AIS_LocalContext::SelectedOwner() const { - Handle(SelectMgr_EntityOwner) EO; - Handle(Standard_Transient) Tr = mySelection->Value(); - if( !Tr.IsNull() ) - EO = Handle(SelectMgr_EntityOwner)::DownCast (Tr); - return EO; + return !mySelection->More() + ? Handle(SelectMgr_EntityOwner)() + : mySelection->Value(); } //================================================== // Function: // Purpose : //================================================== -Standard_Boolean AIS_LocalContext:: -HasApplicative() const +Standard_Boolean AIS_LocalContext::HasApplicative() const { - Handle(AIS_InteractiveObject) IO = SelectedInteractive(); - if( IO.IsNull() ) return Standard_False; - return IO->HasOwner(); + Handle(AIS_InteractiveObject) anIO = SelectedInteractive(); + return !anIO.IsNull() + && anIO->HasOwner(); } //================================================== @@ -797,11 +771,12 @@ void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj return; SelectMgr_SequenceOfOwner aSeq; - for (mySelection->Init(); mySelection->More(); mySelection->Next() ){ - Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(mySelection->Value()); - - if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj ) - aSeq.Append( aOwner ); + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + { + if (aSelIter.Value()->Selectable() == anobj) + { + aSeq.Append (aSelIter.Value()); + } } if ( aSeq.Length() ) @@ -821,17 +796,11 @@ void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer) { UnhilightPicked(updateviewer); - - const AIS_NListTransient& Obj = mySelection->Objects(); - AIS_NListTransient::Iterator anIter( Obj ); - for(; anIter.More(); anIter.Next()){ - const Handle(Standard_Transient)& Tr = anIter.Value(); - if(!Tr.IsNull()) - { - (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False); - } + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + { + aSelIter.Value()->SetSelected (Standard_False); } - mySelection->Select(); + mySelection->Clear(); mylastindex = 0; } @@ -912,12 +881,11 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec // 3. AIS_Selection : remove entity owners from AIS_Selection const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); - AIS_NListTransient::Iterator anIter (mySelection->Objects()); - AIS_NListTransient aRemoveEntites; - for (; anIter.More(); anIter.Next()) + NCollection_List aRemoveEntites; + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) { - Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anIter.Value()); - if (anOwner.IsNull() || anOwner->Selectable() != theIO) + Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value(); + if (anOwner->Selectable() != theIO) { continue; } @@ -936,8 +904,9 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec } } } - AIS_NListTransient::Iterator anIterRemove (aRemoveEntites); - for (; anIterRemove.More(); anIterRemove.Next()) + + for (NCollection_List::Iterator anIterRemove (aRemoveEntites); + anIterRemove.More(); anIterRemove.Next()) { mySelection->Select (anIterRemove.Value()); } @@ -1038,7 +1007,6 @@ void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj, //1st case, owner already as owner // and not separated is found... - Handle(Standard_Transient) Tr; Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj); if(EO.IsNull()){ //check if in selection number 0 there is an owner that can be triturated... @@ -1427,35 +1395,30 @@ Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View) //function : FindSelectedOwnerFromIO //purpose : it is checked if one of the selected owners really presents IObj //======================================================================= -Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO - (const Handle(AIS_InteractiveObject)& anIObj) const +Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO (const Handle(AIS_InteractiveObject)& theObj) const { Handle(SelectMgr_EntityOwner) EO,bid; - if (anIObj.IsNull()) return EO; - - if(mySelection.IsNull()) { - return EO; + if (theObj.IsNull() + || mySelection.IsNull()) + { + return Handle(SelectMgr_EntityOwner)(); } - Standard_Boolean found(Standard_False); - const AIS_NListTransient& Obj = mySelection->Objects(); - AIS_NListTransient::Iterator anIter( Obj ); - for(; anIter.More(); anIter.Next()){ - const Handle(Standard_Transient)& Tr = anIter.Value(); - if(!Tr.IsNull()){ - EO = Handle(SelectMgr_EntityOwner)::DownCast (Tr); - if(EO->HasSelectable()){ - Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); - if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ - if (anIObj == EO->Selectable()){ - found =Standard_True; - break; - } - } - } + + for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next()) + { + if (theObj != aSelIter.Value()->Selectable()) + { + continue; + } + + Handle(StdSelect_BRepOwner) aBROwner = Handle(StdSelect_BRepOwner)::DownCast(aSelIter.Value()); + if (aBROwner.IsNull() + || !aBROwner->ComesFromDecomposition()) + { + return aSelIter.Value(); } } - if(found) return EO; - return bid; + return Handle(SelectMgr_EntityOwner)(); } //======================================================================= diff --git a/src/AIS/AIS_NDataMapOfTransientIteratorOfListTransient.hxx b/src/AIS/AIS_NDataMapOfTransientIteratorOfListTransient.hxx deleted file mode 100644 index d2ebf0f54c..0000000000 --- a/src/AIS/AIS_NDataMapOfTransientIteratorOfListTransient.hxx +++ /dev/null @@ -1,25 +0,0 @@ -// Created on: 2003-05-04 -// Created by: Alexander Grigoriev (a-grigoriev@opencascade.com) -// Copyright (c) 2003-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _AIS_NDataMapOfTransientIteratorOfListTransient_HeaderFile -#define _AIS_NDataMapOfTransientIteratorOfListTransient_HeaderFile - -#include -#include - -typedef NCollection_DataMap - AIS_NDataMapOfTransientIteratorOfListTransient; - -#endif diff --git a/src/AIS/AIS_NListIteratorOfListTransient.hxx b/src/AIS/AIS_NListIteratorOfListTransient.hxx deleted file mode 100644 index d3333728d4..0000000000 --- a/src/AIS/AIS_NListIteratorOfListTransient.hxx +++ /dev/null @@ -1,23 +0,0 @@ -// Created on: 2003-05-04 -// Created by: Alexander Grigoriev (a-grigoriev@opencascade.com) -// Copyright (c) 2003-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _AIS_NListIteratorOfListTransient_HeaderFile -#define _AIS_NListIteratorOfListTransient_HeaderFile - -#include - -typedef AIS_NListTransient::Iterator AIS_NListIteratorOfListTransient; - -#endif diff --git a/src/AIS/AIS_NListTransient.hxx b/src/AIS/AIS_NListOfEntityOwner.hxx similarity index 87% rename from src/AIS/AIS_NListTransient.hxx rename to src/AIS/AIS_NListOfEntityOwner.hxx index e30159bde5..140c85cdda 100644 --- a/src/AIS/AIS_NListTransient.hxx +++ b/src/AIS/AIS_NListOfEntityOwner.hxx @@ -16,9 +16,9 @@ #ifndef _AIS_NListTransient_HeaderFile #define _AIS_NListTransient_HeaderFile -#include +#include #include -typedef NCollection_List AIS_NListTransient; +typedef NCollection_List AIS_NListOfEntityOwner; #endif diff --git a/src/AIS/AIS_Selection.cxx b/src/AIS/AIS_Selection.cxx index ea2c849304..b03e76eb31 100644 --- a/src/AIS/AIS_Selection.cxx +++ b/src/AIS/AIS_Selection.cxx @@ -12,143 +12,112 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include -#include -#include -#include -#include -#include -#include -#include -IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection,MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection, Standard_Transient) -#define MaxSizeOfResult 100000 +namespace +{ + static const Standard_Integer THE_MaxSizeOfResult = 100000; +} //======================================================================= //function : AIS_Selection -//purpose : +//purpose : //======================================================================= -AIS_Selection::AIS_Selection() : -myNb(0) +AIS_Selection::AIS_Selection() { - myResultMap.ReSize( MaxSizeOfResult ); // for maximum performnace on medium selections ( < 100000 objects ) + // for maximum performance on medium selections (< 100000 objects) + myResultMap.ReSize (THE_MaxSizeOfResult); } //======================================================================= -//function : Select -//purpose : +//function : Clear +//purpose : //======================================================================= -void AIS_Selection::Select() +void AIS_Selection::Clear() { - myNb=0; myresult.Clear(); myResultMap.Clear(); } //======================================================================= //function : Select -//purpose : +//purpose : //======================================================================= -AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObject) +AIS_SelectStatus AIS_Selection::Select (const Handle(SelectMgr_EntityOwner)& theObject) { - Handle(AIS_InteractiveObject) anAISObj; - Handle(SelectMgr_EntityOwner) owner = Handle(SelectMgr_EntityOwner)::DownCast( anObject ); - if ( owner.IsNull() ) - anAISObj = Handle(AIS_InteractiveObject)::DownCast( anObject ); - if ( myResultMap.IsBound( anObject ) ){ - AIS_NListTransient::Iterator aListIter = myResultMap.Find( anObject ); -//skt----------------------------------------------------------------- - if( myIterator == aListIter ) { - if( myIterator.More() ) - myIterator.Next(); - else - myIterator = AIS_NListTransient::Iterator(); - } -//-------------------------------------------------------------------- - // 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( !anAISObj.IsNull() || ( !owner.IsNull() && !owner->IsForcedHilight() ) ) + if (theObject.IsNull() + || !theObject->HasSelectable()) + { + return AIS_SS_NotDone; + } + + if (!myResultMap.IsBound (theObject)) + { + AIS_NListOfEntityOwner::Iterator aListIter; + myresult.Append (theObject, aListIter); + myResultMap.Bind (theObject, aListIter); + return AIS_SS_Added; + } + + AIS_NListOfEntityOwner::Iterator aListIter = myResultMap.Find (theObject); + if (myIterator == aListIter) + { + if (myIterator.More()) { - myresult.Remove( aListIter ); - myResultMap.UnBind( anObject ); - - // update list iterator for next object in list if any - if ( aListIter.More() ){ - const Handle(Standard_Transient)& aNextObject = aListIter.Value(); - if ( myResultMap.IsBound( aNextObject ) ) - myResultMap( aNextObject ) = aListIter; - else - myResultMap.Bind( aNextObject, aListIter ); - } - return AIS_SS_Removed; + myIterator.Next(); } else - return AIS_SS_Added; + { + myIterator = AIS_NListOfEntityOwner::Iterator(); + } } - - AIS_NListTransient::Iterator aListIter; - myresult.Append( anObject, aListIter ); - myResultMap.Bind( anObject, aListIter ); - return AIS_SS_Added; -} - -//======================================================================= -//function : AddSelect -//purpose : Always add int the selection -//======================================================================= -AIS_SelectStatus AIS_Selection::AddSelect(const Handle(Standard_Transient)& anObject) -{ - if ( myResultMap.IsBound( anObject ) ) - return AIS_SS_NotDone; - - AIS_NListTransient::Iterator aListIter; - myresult.Append( anObject, aListIter ); - myResultMap.Bind( anObject, aListIter ); - return AIS_SS_Added; -} + // 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()) + { + return AIS_SS_Added; + } -//======================================================================= -//function : ClearAndSelect -//purpose : -//======================================================================= + myresult.Remove (aListIter); + myResultMap.UnBind (theObject); -void AIS_Selection::ClearAndSelect(const Handle(Standard_Transient)& anObject) -{ - Select(); - Select(anObject); + // update list iterator for next object in list if any + if (aListIter.More()) + { + const Handle(SelectMgr_EntityOwner)& aNextObject = aListIter.Value(); + if (myResultMap.IsBound (aNextObject)) + { + myResultMap (aNextObject) = aListIter; + } + else + { + myResultMap.Bind (aNextObject, aListIter); + } + } + return AIS_SS_Removed; } - //======================================================================= -//function : Extent -//purpose : +//function : AddSelect +//purpose : //======================================================================= -Standard_Integer AIS_Selection::Extent() const +AIS_SelectStatus AIS_Selection::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject) { - return myresult.Extent(); -} + if (theObject.IsNull() + || !theObject->HasSelectable() + || myResultMap.IsBound (theObject)) + { + return AIS_SS_NotDone; + } -//======================================================================= -//function : Single -//purpose : -//======================================================================= -Handle(Standard_Transient) AIS_Selection::Single() -{ - Init(); - return Value(); -} -//======================================================================= -//function : IsSelected -//purpose : -//======================================================================= -Standard_Boolean AIS_Selection::IsSelected(const Handle(Standard_Transient)& anObject) const -{ - return myResultMap.IsBound( anObject ); + AIS_NListOfEntityOwner::Iterator aListIter; + myresult.Append (theObject, aListIter); + myResultMap.Bind (theObject, aListIter); + return AIS_SS_Added; } - - diff --git a/src/AIS/AIS_Selection.hxx b/src/AIS/AIS_Selection.hxx index 2da7936a78..92f2e0b8fb 100644 --- a/src/AIS/AIS_Selection.hxx +++ b/src/AIS/AIS_Selection.hxx @@ -17,95 +17,72 @@ #ifndef _AIS_Selection_HeaderFile #define _AIS_Selection_HeaderFile +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -class Standard_NoSuchObject; -class Standard_MultiplyDefined; -class Standard_TypeMismatch; -class Standard_Transient; - - -class AIS_Selection; -DEFINE_STANDARD_HANDLE(AIS_Selection, MMgt_TShared) - - -class AIS_Selection : public MMgt_TShared +//! Class holding the list of selected owners. +class AIS_Selection : public Standard_Transient { - + DEFINE_STANDARD_RTTIEXT(AIS_Selection, Standard_Transient) public: - //! creates a new selection. - Standard_EXPORT AIS_Selection(); //! removes all the object of the selection. - Standard_EXPORT void Select(); + Standard_EXPORT 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 AIS_SelectStatus Select (const Handle(Standard_Transient)& anObject); + Standard_EXPORT AIS_SelectStatus Select (const Handle(SelectMgr_EntityOwner)& theObject); //! the object is always add int the selection. //! faster when the number of objects selected is great. - Standard_EXPORT AIS_SelectStatus AddSelect (const Handle(Standard_Transient)& anObject); - + Standard_EXPORT AIS_SelectStatus AddSelect (const Handle(SelectMgr_EntityOwner)& theObject); + //! clears the selection and adds the object in the selection. - Standard_EXPORT void ClearAndSelect (const Handle(Standard_Transient)& anObject); + void ClearAndSelect (const Handle(SelectMgr_EntityOwner)& theObject) + { + Clear(); + Select (theObject); + } //! checks if the object is in the selection. - Standard_EXPORT Standard_Boolean IsSelected (const Handle(Standard_Transient)& anObject) const; - - //! returns the number of objects selected. - Standard_EXPORT Standard_Integer Extent() const; - - //! returns the single object selected. - //! Warning: raises TypeMismatch from Standard if Extent is not equal to 1. - Standard_EXPORT Handle(Standard_Transient) Single(); - - void Init(); - - Standard_Boolean More() const; - - void Next(); - - const Handle(Standard_Transient)& Value() const; - - Standard_Integer NbStored() const; - - const AIS_NListTransient& Objects() const; - - DEFINE_STANDARD_RTTIEXT(AIS_Selection,MMgt_TShared) - -protected: + Standard_Boolean IsSelected (const Handle(SelectMgr_EntityOwner)& theObject) const { return myResultMap.IsBound (theObject); } + //! Return the list of selected objects. + const AIS_NListOfEntityOwner& Objects() const { return myresult; } + //! Return the number of selected objects. + Standard_Integer Extent() const { return myresult.Size(); } + //! Return true if list of selected objects is empty. + Standard_Boolean IsEmpty() const { return myresult.IsEmpty(); } -private: - - AIS_NListTransient myresult; - AIS_NListIteratorOfListTransient myIterator; - AIS_NDataMapOfTransientIteratorOfListTransient myResultMap; - Standard_Integer myNb; +public: + //! Start iteration through selected objects. + void Init() { myIterator = AIS_NListOfEntityOwner::Iterator(myresult); } -}; + //! Return true if iterator points to selected object. + Standard_Boolean More() const { return myIterator.More(); } + //! Continue iteration through selected objects. + void Next() { myIterator.Next(); } -#include + //! Return selected object at iterator position. + const Handle(SelectMgr_EntityOwner)& Value() const { return myIterator.Value(); } +private: + AIS_NListOfEntityOwner myresult; + AIS_NListOfEntityOwner::Iterator myIterator; + NCollection_DataMap myResultMap; +}; +DEFINE_STANDARD_HANDLE(AIS_Selection, Standard_Transient) #endif // _AIS_Selection_HeaderFile diff --git a/src/AIS/AIS_Selection.lxx b/src/AIS/AIS_Selection.lxx deleted file mode 100644 index f783a1d073..0000000000 --- a/src/AIS/AIS_Selection.lxx +++ /dev/null @@ -1,50 +0,0 @@ -// Created on: 1998-06-23 -// Created by: Robert COUBLANC -// Copyright (c) 1998-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -//SAV: 18/03/02 array was replaced with list. -//san : 18/04/03 USE_MAP - additional datamap is used to speed up access -//to certain owners in list - -#include -#include - -inline const AIS_NListTransient& AIS_Selection::Objects() const -{ - return myresult; -} - -inline void AIS_Selection::Init() -{ - myIterator = AIS_NListTransient::Iterator ( myresult ); -} - -inline Standard_Boolean AIS_Selection::More() const -{ - return myIterator.More(); -} -inline void AIS_Selection::Next () -{ - myIterator.Next(); -} -inline const Handle(Standard_Transient)& AIS_Selection::Value() const -{ - return myIterator.Value(); -} - -inline Standard_Integer AIS_Selection::NbStored() const -{ - return myresult.Extent(); -} diff --git a/src/AIS/FILES b/src/AIS/FILES index 9a4bae746f..dd9f93a7a5 100644 --- a/src/AIS/FILES +++ b/src/AIS/FILES @@ -117,9 +117,7 @@ AIS_MinRadiusDimension.hxx AIS_MultipleConnectedInteractive.cxx AIS_MultipleConnectedInteractive.hxx AIS_MultipleConnectedInteractive.lxx -AIS_NDataMapOfTransientIteratorOfListTransient.hxx -AIS_NListIteratorOfListTransient.hxx -AIS_NListTransient.hxx +AIS_NListOfEntityOwner.hxx AIS_OffsetDimension.cxx AIS_OffsetDimension.hxx AIS_OffsetDimension.lxx @@ -149,7 +147,6 @@ AIS_RubberBand.hxx AIS_RubberBand.cxx AIS_Selection.cxx AIS_Selection.hxx -AIS_Selection.lxx AIS_SelectStatus.hxx AIS_SequenceOfDimension.hxx AIS_SequenceOfInteractive.hxx diff --git a/src/SelectMgr/SelectMgr_SelectableObject.cxx b/src/SelectMgr/SelectMgr_SelectableObject.cxx index f0d3e831d3..c7af451374 100644 --- a/src/SelectMgr/SelectMgr_SelectableObject.cxx +++ b/src/SelectMgr/SelectMgr_SelectableObject.cxx @@ -602,16 +602,14 @@ const Handle(SelectMgr_EntityOwner)& SelectMgr_SelectableObject::GetAssemblyOwne //======================================================================= //function : BndBoxOfSelected -//purpose : Returns a bounding box of sensitive entities with the owners given -// if they are a part of activated selection +//purpose : //======================================================================= -Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (Handle(SelectMgr_IndexedMapOfOwner)& theOwners) +Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (const Handle(SelectMgr_IndexedMapOfOwner)& theOwners) { - Bnd_Box aBnd; - if (theOwners->IsEmpty()) - return aBnd; + return Bnd_Box(); + Bnd_Box aBnd; for (Init(); More(); Next()) { const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); @@ -625,20 +623,8 @@ Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (Handle(SelectMgr_IndexedMa if (theOwners->Contains (anOwner)) { Select3D_BndBox3d aBox = aSel->Sensitive()->BaseSensitive()->BoundingBox(); - Bnd_Box aTmpBnd; - aTmpBnd.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), - aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); - aBnd.Add (aTmpBnd); - - Standard_Integer anOwnerIdx = theOwners->FindIndex (anOwner); - if (theOwners->Size() != anOwnerIdx) - { - theOwners->Swap (anOwnerIdx, theOwners->Size()); - } - theOwners->RemoveLast(); - - if (theOwners->IsEmpty()) - return aBnd; + aBnd.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), + aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); } } } diff --git a/src/SelectMgr/SelectMgr_SelectableObject.hxx b/src/SelectMgr/SelectMgr_SelectableObject.hxx index ebb26b3ff3..3ce3d8ac92 100644 --- a/src/SelectMgr/SelectMgr_SelectableObject.hxx +++ b/src/SelectMgr/SelectMgr_SelectableObject.hxx @@ -210,7 +210,7 @@ public: //! Returns a bounding box of sensitive entities with the owners given //! if they are a part of activated selection - Standard_EXPORT Bnd_Box BndBoxOfSelected (Handle(SelectMgr_IndexedMapOfOwner)& theOwners); + Standard_EXPORT Bnd_Box BndBoxOfSelected (const Handle(SelectMgr_IndexedMapOfOwner)& theOwners); //! Returns the mode for selection of object as a whole Standard_Integer GlobalSelectionMode() const diff --git a/tests/bugs/vis/bug27805 b/tests/bugs/vis/bug27805 new file mode 100644 index 0000000000..63c7ddc041 --- /dev/null +++ b/tests/bugs/vis/bug27805 @@ -0,0 +1,26 @@ +puts "============" +puts "CR27805" +puts "AIS_InteractiveContext::FitSelected() is broken for global selection" +puts "============" +puts "" + +set anImgFitAll $imagedir/${casename}_fitall.png +set anImgFitSel $imagedir/${casename}_fitsel.png +set anImgDiff $imagedir/${casename}_diff.png + +pload MODELING VISUALIZATION +box b 1 2 3 +vclear +vinit View1 +vaxo +vdisplay -dispMode 1 b +vfit +vselect 200 200 +vdump $anImgFitAll +vfit -selected +vdump $anImgFitSel + +set aDiffRes [diffimage $anImgFitSel $anImgFitAll 0.0 0 0 $anImgDiff] +if {$aDiffRes != 0} { + puts "Error: FitSelected() does not match FitAll() for single object" +} -- 2.20.1