From b05d0edf992d5f35dcbda636f6ca821a32792114 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 24 Mar 2015 18:45:50 +0300 Subject: [PATCH] Provide zoom independent selection of symbols --- .../SketcherPrs_SensitivePoint.cpp | 124 ++++++++++++++++++ src/SketcherPrs/SketcherPrs_SensitivePoint.h | 61 +++++++++ src/SketcherPrs/SketcherPrs_SymbolPrs.cpp | 25 ++-- src/SketcherPrs/SketcherPrs_SymbolPrs.h | 8 ++ 4 files changed, 208 insertions(+), 10 deletions(-) create mode 100644 src/SketcherPrs/SketcherPrs_SensitivePoint.cpp create mode 100644 src/SketcherPrs/SketcherPrs_SensitivePoint.h diff --git a/src/SketcherPrs/SketcherPrs_SensitivePoint.cpp b/src/SketcherPrs/SketcherPrs_SensitivePoint.cpp new file mode 100644 index 000000000..ac89d78a6 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_SensitivePoint.cpp @@ -0,0 +1,124 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_SensitivePoint.cpp +// Created: 24 March 2015 +// Author: Vitaly SMETANNIKOV + + +#include "SketcherPrs_SensitivePoint.h" + +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity); + +SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner, + const Handle(Graphic3d_ArrayOfPoints)& thePntArray, + int theId) +:Select3D_SensitiveEntity(anOwner), myId(theId), myPntArray(thePntArray) +{ + SetSensitivityFactor(4.); +} + +void SketcherPrs_SensitivePoint::Project (const Handle(Select3D_Projector)& aProj) +{ + gp_Pnt2d aPoint2d; + gp_Pnt aPnt = Point(); + if(!HasLocation()) + aProj->Project(aPnt, aPoint2d); + else + { + gp_Pnt aP(aPnt.X(), aPnt.Y(), aPnt.Z()); + aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d); + } + myprojpt = aPoint2d; +} + +void SketcherPrs_SensitivePoint::Areas(SelectBasics_ListOfBox2d& boxes) +{ + Bnd_Box2d abox; + abox.Set(myprojpt); + boxes.Append(abox); +} + +Standard_Boolean SketcherPrs_SensitivePoint::Matches(const SelectBasics_PickArgs& thePickArgs, + Standard_Real& theMatchDMin, + Standard_Real& theMatchDepth) +{ + // check coordinate matching + Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt); + if (aDist > thePickArgs.Tolerance() * SensitivityFactor()) + { + return Standard_False; + } + + Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine()); + if (thePickArgs.IsClipped (aDepth)) + { + return Standard_False; + } + + theMatchDMin = aDist; + theMatchDepth = aDepth; + return Standard_True; +} + +Standard_Boolean SketcherPrs_SensitivePoint::Matches(const Standard_Real XMin, + const Standard_Real YMin, + const Standard_Real XMax, + const Standard_Real YMax, + const Standard_Real aTol) +{ + Bnd_Box2d B; + B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax)); + B.Enlarge(aTol); + return !B.IsOut(myprojpt); +} + +Standard_Boolean SketcherPrs_SensitivePoint::Matches(const TColgp_Array1OfPnt2d& aPoly, + const Bnd_Box2d& aBox, + const Standard_Real aTol) +{ + Standard_Real Umin,Vmin,Umax,Vmax; + aBox.Get(Umin,Vmin,Umax,Vmax); + CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); + + Standard_Integer RES = aClassifier2d.SiDans(myprojpt); + if(RES==1) return Standard_True; + + return Standard_False; +} + +gp_Pnt SketcherPrs_SensitivePoint::Point() const +{ + return myPntArray->Vertice(myId); +} + +Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected(const TopLoc_Location& aLoc) +{ + Handle(SketcherPrs_SensitivePoint) NiouEnt = new SketcherPrs_SensitivePoint(myOwnerId,myPntArray,myId); + if(HasLocation()) NiouEnt->SetLocation(Location()); + NiouEnt->UpdateLocation(aLoc); + return NiouEnt; +} + +void SketcherPrs_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const +{ + gp_Pnt aPnt = Point(); + S<<"\tSensitivePoint 3D :"; + if(HasLocation()) + S<<"\t\tExisting Location"< +#include +#include +#include + + +DEFINE_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity) + +class SketcherPrs_SensitivePoint : public Select3D_SensitiveEntity +{ +public: + //! Constructs a sensitive point object defined by the + //! owner OwnerId and the point Point. + Standard_EXPORT SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& OwnerId, + const Handle(Graphic3d_ArrayOfPoints)& thePntArray, int theId); + + //! Converts the stored 3D point into a 2D point according + //! to ; this method is called by the selection Manager. + Standard_EXPORT void Project (const Handle(Select3D_Projector)& aProjector) ; + + //! stores in the 2D sensitive box which represents + //! the point area in the selection process. + Standard_EXPORT void Areas (SelectBasics_ListOfBox2d& aresult) ; + + Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected (const TopLoc_Location& aLocation) ; + + //! Checks whether the sensitive entity matches the picking + //! detection area (close to the picking line). + //! For details please refer to base class declaration. + Standard_EXPORT Standard_Boolean Matches (const SelectBasics_PickArgs& thePickArgs, Standard_Real& theMatchDMin, Standard_Real& theMatchDepth) ; + + Standard_EXPORT Standard_Boolean Matches (const Standard_Real XMin, const Standard_Real YMin, const Standard_Real XMax, const Standard_Real YMax, const Standard_Real aTol) ; + + Standard_EXPORT virtual Standard_Boolean Matches (const TColgp_Array1OfPnt2d& Polyline, const Bnd_Box2d& aBox, const Standard_Real aTol) ; + + Standard_EXPORT Standard_Real ComputeDepth (const gp_Lin& EyeLine) const; + + //! Returns the point used at the time of construction. + Standard_EXPORT gp_Pnt Point() const; + + Standard_EXPORT virtual void Dump (Standard_OStream& S, const Standard_Boolean FullDump = Standard_True) const; + + DEFINE_STANDARD_RTTI(SketcherPrs_SensitivePoint) + +private: + int myId; + Handle(Graphic3d_ArrayOfPoints) myPntArray; + Select3D_Pnt2d myprojpt; +}; + + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index f7ef9256e..699bbab1f 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -317,6 +316,15 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& if (!updatePoints(20)) return; + int aNbVertex = myPntArray->VertexNumber(); + if (myOwner.IsNull()) { + myOwner = new SelectMgr_EntityOwner(this); + for (int i = 1; i <= aNbVertex; i++) { + Handle(SketcherPrs_SensitivePoint) aSP = new SketcherPrs_SensitivePoint(myOwner, myPntArray, i); + mySPoints.Append(aSP); + } + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); aGroup->SetPrimitivesAspect(myAspect); @@ -325,7 +333,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& aBnd.Clear(); for (int i = 1; i <= myPntArray->ItemNumber(); i++) { aVert = myPntArray->Vertice(i); - aBnd.Add (Graphic3d_Vec4 (aVert.X(), aVert.Y(), aVert.Z(), 1.0f)); + aBnd.Add (Graphic3d_Vec4((float)aVert.X(), (float)aVert.Y(), (float)aVert.Z(), 1.0f)); } aGroup->UserDraw(this, true); @@ -338,14 +346,8 @@ void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& const Standard_Integer aMode) { ClearSelected(); - //if (!updatePoints(20)) - // return; - - Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this); - for (int i = 1; i <= myPntArray->VertexNumber(); i++) { - Handle(Select3D_SensitivePoint) aSP = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(i)); - aSelection->Add(aSP); - } + for (int i = 1; i <= mySPoints.Length(); i++) + aSelection->Add(mySPoints.Value(i)); } @@ -406,6 +408,9 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) } theWorkspace->EnableTexture (aTextureBack); aCtx->BindProgram (NULL); + + // Update selection position + GetContext()->RecomputeSelectionOnly(this); } diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h index 7a9c37b03..c087ff6ba 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.h +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -7,11 +7,15 @@ #ifndef SketcherPrs_SymbolPrs_H #define SketcherPrs_SymbolPrs_H +#include "SketcherPrs_SensitivePoint.h" + #include #include #include #include #include +#include +#include #include #include @@ -110,11 +114,15 @@ protected: /// Array of symbols positions mutable Handle(Graphic3d_ArrayOfPoints) myPntArray; + Handle(SelectMgr_EntityOwner) myOwner; + private: /// Static map to collect constraints icons {IconName : IconPixMap} static std::map myIconsMap; mutable Handle(OpenGl_VertexBuffer) myVboAttribs; + + Select3D_SensitiveEntitySequence mySPoints; }; #endif \ No newline at end of file -- 2.39.2