--- /dev/null
+// 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 <Select3D_Projector.hxx>
+#include <Bnd_Box2d.hxx>
+#include <CSLib_Class2d.hxx>
+#include <ElCLib.hxx>
+#include <TopLoc_Location.hxx>
+#include <SelectBasics_ListOfBox2d.hxx>
+
+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"<<endl;
+
+ S<<"\t\t P3d [ "<<aPnt.X()<<" , "<<aPnt.Y()<<" , "<<aPnt.Z()<<" ]"<<endl;
+ S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
+}
+
+Standard_Real SketcherPrs_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
+{
+ return ElCLib::Parameter(EyeLine, Point());
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_SensitivePoint.h
+// Created: 24 March 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_SensitivePoint_H
+#define SketcherPrs_SensitivePoint_H
+
+#include <Select3D_SensitiveEntity.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Select3D_Pnt2d.hxx>
+#include <Standard_DefineHandle.hxx>
+
+
+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 <aProjector> ; this method is called by the selection Manager.
+ Standard_EXPORT void Project (const Handle(Select3D_Projector)& aProjector) ;
+
+ //! stores in <aresult> 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
#include <Graphic3d_BndBox4f.hxx>
#include <SelectMgr_Selection.hxx>
-#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitivePoint.hxx>
#include <TopLoc_Location.hxx>
#include <AIS_InteractiveContext.hxx>
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);
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);
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));
}
}
theWorkspace->EnableTexture (aTextureBack);
aCtx->BindProgram (NULL);
+
+ // Update selection position
+ GetContext()->RecomputeSelectionOnly(this);
}
#ifndef SketcherPrs_SymbolPrs_H
#define SketcherPrs_SymbolPrs_H
+#include "SketcherPrs_SensitivePoint.h"
+
#include <AIS_InteractiveObject.hxx>
#include <GeomAPI_Ax3.h>
#include <Graphic3d_ArrayOfPoints.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Image_AlienPixMap.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <Select3D_SensitiveEntitySequence.hxx>
#include <Standard_DefineHandle.hxx>
#include <map>
/// 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<const char*, Handle(Image_AlienPixMap)> myIconsMap;
mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
+
+ Select3D_SensitiveEntitySequence mySPoints;
};
#endif
\ No newline at end of file