From 3c9825482f501e26d453a03157c8e5d73bd1fe2f Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 26 Mar 2012 19:50:04 +0400 Subject: [PATCH] 0023012: Detection gives incorrect results --- src/AIS/AIS_InteractiveContext.cdl | 22 +++++- src/AIS/AIS_InteractiveContext.cxx | 76 +++++++++++++++----- src/AIS/AIS_LocalContext.cdl | 22 +++++- src/AIS/AIS_LocalContext.cxx | 26 +++++-- src/SelectMgr/SelectMgr_ViewerSelector.cdl | 5 ++ src/SelectMgr/SelectMgr_ViewerSelector.lxx | 5 ++ src/StdSelect/StdSelect.cdl | 5 ++ src/StdSelect/StdSelect_ViewerSelector3d.cdl | 24 ++++++- src/StdSelect/StdSelect_ViewerSelector3d.cxx | 44 ++++++++---- src/StdSelect/StdSelect_ViewerSelector3d.lxx | 10 +++ src/ViewerTest/ViewerTest.cxx | 61 ++++++++++++++++ 11 files changed, 258 insertions(+), 42 deletions(-) diff --git a/src/AIS/AIS_InteractiveContext.cdl b/src/AIS/AIS_InteractiveContext.cdl index 80518485a4..bab1ae87b5 100755 --- a/src/AIS/AIS_InteractiveContext.cdl +++ b/src/AIS/AIS_InteractiveContext.cdl @@ -114,6 +114,7 @@ uses SelectionManager from SelectMgr, PresentationManager3d from PrsMgr, ViewerSelector3d from StdSelect, + SensitivityMode from StdSelect, MapOfInteractive from AIS, InteractiveObject from AIS, DisplayMode from AIS, @@ -525,6 +526,17 @@ is -- Removes selection mode from Interactive Objects. -- aMode provides the selection mode index of the entity aniobj. + SetSensitivityMode(me : mutable; + aMode : SensitivityMode from StdSelect) is static; + ---Level: Public + ---Purpose: Sets the selection sensitivity mode. SM_WINDOW mode + -- uses the specified pixel tolerance to compute the sensitivity + -- value, SM_VIEW mode allows to define the sensitivity manually. + + SensitivityMode(me) returns SensitivityMode from StdSelect; + ---Level: Public + ---Purpose: Returns the selection sensitivity mode. + SetSensitivity(me:mutable; aPrecision: Real from Standard); ---Level: Public @@ -537,7 +549,11 @@ is -- When a local context is open, the defined sensitivity applies to -- this local context instead of the main context. - SetSensitivity(me:mutable; + Sensitivity (me) returns Real from Standard; + ---Level: Public + ---Purpose: Returns the selection sensitivity value. + + SetPixelTolerance(me:mutable; aPrecision: Integer from Standard = 4); ---Level: Public ---Purpose: Define the current selection pixel sensitivity @@ -545,6 +561,10 @@ is -- Warning: When a local context is open the sensitivity is apply on it -- instead on the main context. + PixelTolerance(me) returns Integer from Standard; + ---Level: Public + ---Purpose: Returns the pixel tolerance. + ---Category: put locations on objects.... -- diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index a58952283f..d3b7eab094 100755 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -188,12 +188,7 @@ myIsAutoActivateSelMode( Standard_True ) { InitAttributes(); mgrSelector->Add(myCollectorSel); -#ifdef BUC60688 - SetSensitivity(); -#else - myCollectorSel->Set(4); -#endif - + SetPixelTolerance(); } void AIS_InteractiveContext::Delete() const @@ -2977,7 +2972,33 @@ void AIS_InteractiveContext::UnsetSelectionMode(const Handle_AIS_InteractiveObje { } -#ifdef BUC60688 +//======================================================================= +//function : SetSensitivityMode +//purpose : +//======================================================================= + +void AIS_InteractiveContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) { + + if( HasOpenedContext() ) + myLocalContexts(myCurLocalIndex)->SetSensitivityMode(aMode); + else { + myMainSel->SetSensitivityMode(aMode); + if( !myCollectorSel.IsNull() ) myCollectorSel->SetSensitivityMode(aMode); + } +} + +//======================================================================= +//function : SensitivityMode +//purpose : +//======================================================================= + +StdSelect_SensitivityMode AIS_InteractiveContext::SensitivityMode() const { + + if( HasOpenedContext() ) + return myLocalContexts(myCurLocalIndex)->SensitivityMode(); + return myMainSel->SensitivityMode(); +} + //======================================================================= //function : SetSensitivity //purpose : @@ -2994,20 +3015,43 @@ void AIS_InteractiveContext::SetSensitivity(const Standard_Real aPrecision) { } //======================================================================= -//function : SetSensitivity +//function : Sensitivity //purpose : //======================================================================= -void AIS_InteractiveContext::SetSensitivity(const Standard_Integer aPrecision) { +Standard_Real AIS_InteractiveContext::Sensitivity() const { if( HasOpenedContext() ) - myLocalContexts(myCurLocalIndex)->SetSensitivity(aPrecision); + return myLocalContexts(myCurLocalIndex)->Sensitivity(); + return myMainSel->Sensitivity(); +} + +//======================================================================= +//function : SetPixelTolerance +//purpose : +//======================================================================= + +void AIS_InteractiveContext::SetPixelTolerance(const Standard_Integer aPrecision) { + + if( HasOpenedContext() ) + myLocalContexts(myCurLocalIndex)->SetPixelTolerance(aPrecision); else { - myMainSel->Set(aPrecision); - if( !myCollectorSel.IsNull() ) myCollectorSel->Set(aPrecision); + myMainSel->SetPixelTolerance(aPrecision); + if( !myCollectorSel.IsNull() ) myCollectorSel->SetPixelTolerance(aPrecision); } } -#endif + +//======================================================================= +//function : PixelTolerance +//purpose : +//======================================================================= + +Standard_Integer AIS_InteractiveContext::PixelTolerance() const { + + if( HasOpenedContext() ) + return myLocalContexts(myCurLocalIndex)->PixelTolerance(); + return myMainSel->PixelTolerance(); +} //======================================================================= //function : IsInLocal @@ -3063,11 +3107,7 @@ void AIS_InteractiveContext::InitAttributes() HLA->SetTypeOfLine(Aspect_TOL_DASH); // tolerance to 4 pixels... -#ifdef BUC60688 - SetSensitivity(); -#else - myMainSel->Set(4); -#endif + SetPixelTolerance(); // Customizing the drawer for trihedrons and planes... diff --git a/src/AIS/AIS_LocalContext.cdl b/src/AIS/AIS_LocalContext.cdl index 02a39462c5..074d766ff3 100755 --- a/src/AIS/AIS_LocalContext.cdl +++ b/src/AIS/AIS_LocalContext.cdl @@ -72,6 +72,7 @@ uses ListOfFilter from SelectMgr, BRepOwner from StdSelect, ViewerSelector3d from StdSelect, + SensitivityMode from StdSelect, InteractiveContext from AIS, ClearMode from AIS, InteractiveObject from AIS, @@ -443,18 +444,37 @@ is HiCol : out NameOfColor from Quantity) returns Boolean from Standard; + SetSensitivityMode(me : mutable; + aMode : SensitivityMode from StdSelect) is static; + ---Level: Public + ---Purpose: Sets the selection sensitivity mode. SM_WINDOW mode + -- uses the specified pixel tolerance to compute the sensitivity + -- value, SM_VIEW mode allows to define the sensitivity manually. + + SensitivityMode(me) returns SensitivityMode from StdSelect; + ---Level: Public + ---Purpose: Returns the selection sensitivity mode. + SetSensitivity(me:mutable; aPrecision: Real from Standard); ---Level: Public ---Purpose: Define the current selection sensitivity for -- this local context according to the view size. - SetSensitivity(me:mutable; + Sensitivity (me) returns Real from Standard; + ---Level: Public + ---Purpose: Returns the selection sensitivity value. + + SetPixelTolerance(me:mutable; aPrecision: Integer from Standard = 2); ---Level: Public ---Purpose: Define the current selection sensitivity for -- this local context according to the view size. + PixelTolerance(me) returns Integer from Standard; + ---Level: Public + ---Purpose: Returns the pixel tolerance. + ---Category: IMMEDIATE MODE diff --git a/src/AIS/AIS_LocalContext.cxx b/src/AIS/AIS_LocalContext.cxx index f604eef36d..07c494be71 100755 --- a/src/AIS/AIS_LocalContext.cxx +++ b/src/AIS/AIS_LocalContext.cxx @@ -1224,17 +1224,35 @@ Standard_Boolean AIS_LocalContext::EndImmediateDraw(const Handle(V3d_View)& aVie Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const {return myMainPM->IsImmediateModeOn();} -#ifdef BUC60688 +void AIS_LocalContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) { + + myMainVS->SetSensitivityMode(aMode); +} + +StdSelect_SensitivityMode AIS_LocalContext::SensitivityMode() const { + + return myMainVS->SensitivityMode(); +} + void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) { myMainVS->SetSensitivity(aPrecision); } -void AIS_LocalContext::SetSensitivity(const Standard_Integer aPrecision) { +Standard_Real AIS_LocalContext::Sensitivity() const { - myMainVS->Set(aPrecision); + return myMainVS->Sensitivity(); +} + +void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) { + + myMainVS->SetPixelTolerance(aPrecision); +} + +Standard_Integer AIS_LocalContext::PixelTolerance() const { + + return myMainVS->PixelTolerance(); } -#endif //======================================================================= //function : SetZLayer diff --git a/src/SelectMgr/SelectMgr_ViewerSelector.cdl b/src/SelectMgr/SelectMgr_ViewerSelector.cdl index ee63c57f58..69e1054894 100755 --- a/src/SelectMgr/SelectMgr_ViewerSelector.cdl +++ b/src/SelectMgr/SelectMgr_ViewerSelector.cdl @@ -154,6 +154,11 @@ is ---Purpose: changes the Sensitivity of picking -- Input value is Real. + Sensitivity (me) returns Real from Standard; + ---Level: Public + ---Purpose: returns the Sensitivity of picking + ---C++: inline + SetClipping(me:mutable ; Xc,Yc,Height,Width:Real) is static; ---Level: Public ---Purpose: sets the clipping limits of dynamic picking diff --git a/src/SelectMgr/SelectMgr_ViewerSelector.lxx b/src/SelectMgr/SelectMgr_ViewerSelector.lxx index 7f5da839f0..274fd4016c 100755 --- a/src/SelectMgr/SelectMgr_ViewerSelector.lxx +++ b/src/SelectMgr/SelectMgr_ViewerSelector.lxx @@ -19,6 +19,11 @@ #define OCC9026 //AEL Additional method to optimize performance //of the FindSelectedOwnerFromShape() method. +inline Standard_Real SelectMgr_ViewerSelector::Sensitivity() const +{ + return mytolerance; +} + inline void SelectMgr_ViewerSelector::Init() { myCurRank = 1; diff --git a/src/StdSelect/StdSelect.cdl b/src/StdSelect/StdSelect.cdl index 93b15e9f03..fcbf263c2b 100755 --- a/src/StdSelect/StdSelect.cdl +++ b/src/StdSelect/StdSelect.cdl @@ -90,6 +90,11 @@ is ---Purpose: Provides values for different types of edges. These -- values are used to filter edges in frameworks -- inheriting StdSelect_EdgeFilter. + + enumeration SensitivityMode is SM_WINDOW, SM_VIEW; + ---Purpose: Selection sensitivity mode. SM_WINDOW mode uses the + -- specified pixel tolerance to compute the sensitivity value, + -- SM_VIEW mode allows to define the sensitivity manually. class ViewerSelector3d; diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cdl b/src/StdSelect/StdSelect_ViewerSelector3d.cdl index f614ef1e68..832ff86957 100755 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cdl +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cdl @@ -34,7 +34,8 @@ uses Group from Graphic3d, Structure from Graphic3d, Array1OfReal from TColStd, - Array1OfPnt2d from TColgp + Array1OfPnt2d from TColgp, + SensitivityMode from StdSelect is @@ -50,12 +51,28 @@ is -- in the active view ; to be done before the selection action... - Set(me:mutable; aSensitivity : Integer) is static; - ---Purpose: Sets the sensitivity aSensitivity. Set(me:mutable; aProj: Projector from Select3D) is static; ---Purpose: Sets the new projector aProj to replace the one used at construction time. + SetSensitivityMode(me : mutable; + aMode : SensitivityMode from StdSelect) is static; + ---Purpose: Sets the selection sensitivity mode. SM_WINDOW mode + -- uses the specified pixel tolerance to compute the sensitivity + -- value, SM_VIEW mode allows to define the sensitivity manually. + + SensitivityMode(me) returns SensitivityMode from StdSelect; + ---C++: inline + ---Purpose: Returns the selection sensitivity mode. + + SetPixelTolerance(me : mutable; + aTolerance : Integer) is static; + ---Purpose: Sets the pixel tolerance aTolerance. + + PixelTolerance(me) returns Integer from Standard; + ---C++: inline + ---Purpose: Returns the pixel tolerance. + Pick (me : mutable;XPix,YPix:Integer; aView : View from V3d) is static; @@ -147,6 +164,7 @@ fields mycenter : Real from Standard[2]; myprevcenter : Real from Standard[2]; mylastzoom : Real from Standard; + mysensmode : SensitivityMode from StdSelect; mypixtol : Integer ; myupdatetol : Boolean; diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cxx b/src/StdSelect/StdSelect_ViewerSelector3d.cxx index 2aa6e94a83..257110da56 100755 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cxx @@ -101,6 +101,7 @@ StdSelect_ViewerSelector3d ::StdSelect_ViewerSelector3d(): myprj(new Select3D_Projector()), mylastzoom(0.0), +mysensmode(StdSelect_SM_WINDOW), mypixtol(2), myupdatetol(Standard_True) { @@ -118,6 +119,7 @@ StdSelect_ViewerSelector3d ::StdSelect_ViewerSelector3d(const Handle(Select3D_Projector)& aProj): myprj(aProj), mylastzoom(0.0), +mysensmode(StdSelect_SM_WINDOW), mypixtol(2), myupdatetol(Standard_True) { @@ -149,25 +151,37 @@ void StdSelect_ViewerSelector3d::Convert(const Handle(SelectMgr_Selection)& aSel //================================================== void StdSelect_ViewerSelector3d -::Set(const Standard_Integer PixelTolerance) +::Set(const Handle(Select3D_Projector)& aProj) { - if(mypixtol!=PixelTolerance) - { - mypixtol = PixelTolerance; - myupdatetol = Standard_True; - } + myprj = aProj; + toupdate=Standard_True; } //================================================== -// Function: Set +// Function: SetSensitivityMode // Purpose : //================================================== void StdSelect_ViewerSelector3d -::Set(const Handle(Select3D_Projector)& aProj) +::SetSensitivityMode(const StdSelect_SensitivityMode aMode) { - myprj = aProj; - toupdate=Standard_True; + mysensmode = aMode; + toupdate = Standard_True; +} + +//================================================== +// Function: SetPixelTolerance +// Purpose : +//================================================== + +void StdSelect_ViewerSelector3d +::SetPixelTolerance(const Standard_Integer aTolerance) +{ + if(mypixtol!=aTolerance) + { + mypixtol = aTolerance; + myupdatetol = Standard_True; + } } //================================================== @@ -247,7 +261,7 @@ void StdSelect_ViewerSelector3d const Standard_Integer YPMax, const Handle(V3d_View)& aView) { - if (myupdatetol) + if (myupdatetol && SensitivityMode() == StdSelect_SM_WINDOW) { SetSensitivity (aView->Convert (mypixtol)); myupdatetol = Standard_False; @@ -276,7 +290,7 @@ void StdSelect_ViewerSelector3d ::Pick(const TColgp_Array1OfPnt2d& aPolyline, const Handle(V3d_View)& aView) { - if (myupdatetol) + if (myupdatetol && SensitivityMode() == StdSelect_SM_WINDOW) { SetSensitivity (aView->Convert (mypixtol)); myupdatetol = Standard_False; @@ -317,7 +331,7 @@ void StdSelect_ViewerSelector3d void StdSelect_ViewerSelector3d:: DisplayAreas(const Handle(V3d_View)& aView) { - if (myupdatetol) + if (myupdatetol && SensitivityMode() == StdSelect_SM_WINDOW) { SetSensitivity (aView->Convert (mypixtol)); myupdatetol = Standard_False; @@ -500,7 +514,7 @@ UpdateProj(const Handle(V3d_View)& aView) mylastzoom = aView->Scale(); } - if (myupdatetol) + if (myupdatetol && SensitivityMode() == StdSelect_SM_WINDOW) { SetSensitivity (aView->Convert (mypixtol)); myupdatetol = Standard_False; @@ -519,7 +533,7 @@ UpdateProj(const Handle(V3d_View)& aView) //============================= void StdSelect_ViewerSelector3d::DisplaySensitive(const Handle(V3d_View)& aViou) { - if (myupdatetol) + if (myupdatetol && SensitivityMode() == StdSelect_SM_WINDOW) { SetSensitivity (aViou->Convert (mypixtol)); myupdatetol = Standard_False; diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.lxx b/src/StdSelect/StdSelect_ViewerSelector3d.lxx index aee24acfc1..5a20a4a84a 100755 --- a/src/StdSelect/StdSelect_ViewerSelector3d.lxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.lxx @@ -16,6 +16,16 @@ // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. +inline StdSelect_SensitivityMode StdSelect_ViewerSelector3d::SensitivityMode() const +{ + return mysensmode; +} + +inline Standard_Integer StdSelect_ViewerSelector3d::PixelTolerance() const +{ + return mypixtol; +} + inline const Handle(Select3D_Projector)& StdSelect_ViewerSelector3d::Projector() const { return myprj; diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index b0bc67110c..bfcfaa354c 100755 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -754,6 +754,63 @@ static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** ) return 0; } +//============================================================================== +//function : VSelPrecision +//purpose : To set the selection precision mode and tolerance value +//Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance +// value (integer number of pixel for window mode, double value of +// sensitivity for view mode). Without arguments the function just +// prints the current precision mode and the corresponding tolerance. +//============================================================================== +static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if( argc > 3 ) + { + di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n"; + return 1; + } + + Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); + if( aContext.IsNull() ) + return 1; + + if( argc == 1 ) + { + StdSelect_SensitivityMode aMode = aContext->SensitivityMode(); + if( aMode == StdSelect_SM_WINDOW ) + { + Standard_Integer aPixelTolerance = aContext->PixelTolerance(); + di << "Precision mode : 0 (window)\n"; + di << "Pixel tolerance : " << aPixelTolerance << "\n"; + } + else if( aMode == StdSelect_SM_VIEW ) + { + Standard_Real aSensitivity = aContext->Sensitivity(); + di << "Precision mode : 1 (view)\n"; + di << "Sensitivity : " << aSensitivity << "\n"; + } + } + else if( argc > 1 ) + { + StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] ); + aContext->SetSensitivityMode( aMode ); + if( argc > 2 ) + { + if( aMode == StdSelect_SM_WINDOW ) + { + Standard_Integer aPixelTolerance = atoi( argv[2] ); + aContext->SetPixelTolerance( aPixelTolerance ); + } + else if( aMode == StdSelect_SM_VIEW ) + { + Standard_Real aSensitivity = atof( argv[2] ); + aContext->SetSensitivity( aSensitivity ); + } + } + } + return 0; +} + //============================================================================== //function : VDump //purpose : To dump the active view snapshot to image file @@ -3482,6 +3539,10 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) "vardisp : erase active entities", __FILE__,VClearSensi,group); + theCommands.Add("vselprecision", + "vselprecision : vselprecision [precision_mode [tolerance_value]]", + __FILE__,VSelPrecision,group); + theCommands.Add("vperf", "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)", __FILE__,VPerf,group); -- 2.20.1