From: vsv Date: Mon, 23 Mar 2015 12:52:34 +0000 (+0300) Subject: Make symbols of constraints with fixed distance X-Git-Tag: V_1.1.0~85^2~9^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ee8227215801cf94dd1d5c03d647b1bf18ea6ffb;p=modules%2Fshaper.git Make symbols of constraints with fixed distance --- diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 5fe8b8437..dca91a3b4 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -38,8 +38,16 @@ SET(PROJECT_LIBRARIES ${CAS_VIEWER} ${CAS_SHAPE} ${CAS_TKTopAlgo} + ${CAS_TKOpenGl} ) +IF(WIN32) + SET(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} opengl32) +ELSE() + SET(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} GL) +ENDIF() + + SET(PROJECT_PICTURES icons/parallel.png icons/perpendicular.png @@ -50,7 +58,7 @@ SET(PROJECT_PICTURES icons/tangent.png ) -ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS}) +ADD_DEFINITIONS(-DSKETCHERPRS_EXPORTS ${CAS_DEFINITIONS}) ADD_LIBRARY(SketcherPrs SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) INCLUDE_DIRECTORIES( diff --git a/src/SketcherPrs/SketcherPrs_Equal.cpp b/src/SketcherPrs/SketcherPrs_Equal.cpp index d6fa639d9..7ba9a3f65 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.cpp +++ b/src/SketcherPrs/SketcherPrs_Equal.cpp @@ -28,32 +28,21 @@ SketcherPrs_Equal::SketcherPrs_Equal(SketchPlugin_Constraint* theConstraint, myPntArray->AddVertex(0., 0., 0.); } -void SketcherPrs_Equal::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) +bool SketcherPrs_Equal::updatePoints(double theStep) const { - prepareAspect(); - ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) + return false; + if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) + return false; - std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); - if (aLine1.get() == NULL) - return; - - std::shared_ptr aLine2 = SketcherPrs_Tools::getShape(aObj2); - if (aLine2.get() == NULL) - return; - SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this); - gp_Pnt aP2 = aMgr->getPosition(aObj2, this); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - aGroup->SetPrimitivesAspect(myAspect); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); + gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); myPntArray->SetVertice(1, aP1); myPntArray->SetVertice(2, aP2); - aGroup->AddPrimitiveArray(myPntArray); + return true; } void SketcherPrs_Equal::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const diff --git a/src/SketcherPrs/SketcherPrs_Equal.h b/src/SketcherPrs/SketcherPrs_Equal.h index 90beb8c04..4bd1a86ab 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.h +++ b/src/SketcherPrs/SketcherPrs_Equal.h @@ -30,13 +30,14 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Equal) protected: - /// Redefinition of virtual function - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); virtual const char* iconName() const { return "equal.png"; } virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h index 1d3f7335d..b6feedebc 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.h +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -16,7 +16,7 @@ class SketchPlugin_Constraint; #define GET_CONSTRAINT_PRS(NAME) \ static AISObjectPtr NAME(SketchPlugin_Constraint* theConstraint, \ - const std::shared_ptr& thePlane); \ + const std::shared_ptr& thePlane); /** diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.cpp b/src/SketcherPrs/SketcherPrs_HVDirection.cpp index 2c0e892dd..5992db2fd 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.cpp +++ b/src/SketcherPrs/SketcherPrs_HVDirection.cpp @@ -29,24 +29,16 @@ SketcherPrs_HVDirection::SketcherPrs_HVDirection(SketchPlugin_Constraint* theCon myPntArray->AddVertex(0., 0., 0.); } -void SketcherPrs_HVDirection::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) +bool SketcherPrs_HVDirection::updatePoints(double theStep) const { - prepareAspect(); - - ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); - if (aLine1.get() == NULL) - return; + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + if (SketcherPrs_Tools::getShape(aObj).get() == NULL) + return false; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - aGroup->SetPrimitivesAspect(myAspect); + gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(1, aP1); - aGroup->AddPrimitiveArray(myPntArray); + return true; } void SketcherPrs_HVDirection::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.h b/src/SketcherPrs/SketcherPrs_HVDirection.h index 84e993b05..96432d230 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.h +++ b/src/SketcherPrs/SketcherPrs_HVDirection.h @@ -32,10 +32,6 @@ public: DEFINE_STANDARD_RTTI(SketcherPrs_HVDirection) protected: - /// Redefinition of virtual function - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); - virtual const char* iconName() const { return myIsHorisontal? "horisontal.png" : "vertical.png"; } /// Redefine this function in order to add additiona lines of constraint base @@ -43,6 +39,10 @@ protected: /// \param theColor a color of additiona lines virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const; + private: bool myIsHorisontal; }; diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index 6b7e07194..71f97ceda 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -26,37 +26,28 @@ SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstrain { myPntArray = new Graphic3d_ArrayOfPoints(2); myPntArray->AddVertex(0., 0., 0.); - myPntArray->AddVertex(0. ,0., 0.); + myPntArray->AddVertex(0., 0., 0.); } -void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) -{ - prepareAspect(); +bool SketcherPrs_Parallel::updatePoints(double theStep) const +{ ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) + return false; + if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) + return false; - std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); - if (aLine1.get() == NULL) - return; - - std::shared_ptr aLine2 = SketcherPrs_Tools::getShape(aObj2); - if (aLine2.get() == NULL) - return; - SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this); - gp_Pnt aP2 = aMgr->getPosition(aObj2, this); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - aGroup->SetPrimitivesAspect(myAspect); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); + gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); myPntArray->SetVertice(1, aP1); myPntArray->SetVertice(2, aP2); - aGroup->AddPrimitiveArray(myPntArray); + return true; } + void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const { Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); diff --git a/src/SketcherPrs/SketcherPrs_Parallel.h b/src/SketcherPrs/SketcherPrs_Parallel.h index 63aa6afc3..d0126d30b 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.h +++ b/src/SketcherPrs/SketcherPrs_Parallel.h @@ -30,13 +30,13 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Parallel) protected: - /// Redefinition of virtual function - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); - virtual const char* iconName() const { return "parallel.png"; } virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index d27cf03e5..e00b23d7d 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -29,34 +29,25 @@ SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* th myPntArray->AddVertex(0., 0., 0.); } -void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) -{ - prepareAspect(); +bool SketcherPrs_Perpendicular::updatePoints(double theStep) const +{ ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - - std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); - if (aLine1.get() == NULL) - return; - - std::shared_ptr aLine2 = SketcherPrs_Tools::getShape(aObj2); - if (aLine2.get() == NULL) - return; + if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) + return false; + if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) + return false; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this); - gp_Pnt aP2 = aMgr->getPosition(aObj2, this); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - aGroup->SetPrimitivesAspect(myAspect); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); + gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); myPntArray->SetVertice(1, aP1); myPntArray->SetVertice(2, aP2); - aGroup->AddPrimitiveArray(myPntArray); + return true; } + void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const { Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.h b/src/SketcherPrs/SketcherPrs_Perpendicular.h index 87a620ab1..c77a09203 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.h +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.h @@ -30,16 +30,16 @@ public: DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular) protected: - /// Redefinition of virtual function - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); - virtual const char* iconName() const { return "perpendicular.png"; } /// Redefine this function in order to add additiona lines of constraint base /// \param thePrs a presentation /// \param theColor a color of additiona lines virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 03fb8a9b2..2e0a66ae4 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -12,8 +12,6 @@ #include #include -static const int MyStep = 20; - static SketcherPrs_PositionMgr* MyPosMgr = NULL; @@ -50,7 +48,8 @@ int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, } gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, - Handle(SketcherPrs_SymbolPrs) thePrs) + Handle(SketcherPrs_SymbolPrs) thePrs, + double theStep) { std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); gp_Pnt aP; // Central point @@ -91,7 +90,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, } gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl()); aShift.Normalize(); - aShift.Multiply(MyStep); + aShift.Multiply(theStep); int aPos = getPositionIndex(theShape, thePrs); int aM = 1; @@ -117,7 +116,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, if (aPos > 1) { // Normalize vector along the line aVec1.Normalize(); - aVec1.Multiply(MyStep); + aVec1.Multiply(theStep); aP.Translate(aVec1.Multiplied(aM)); } return aP; diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.h b/src/SketcherPrs/SketcherPrs_PositionMgr.h index 65a2aa068..fd61fa64f 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.h +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.h @@ -29,7 +29,8 @@ public: /// Returns position of symbol for the given presentation /// \param theLine constrained object /// \param thePrs a presentation of constraint - gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs); + /// \param theStep step between symbols + gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs, double theStep = 20); /// Deletes constraint object from internal structures. Has to be called on constraint delete. /// \param thePrs a constraint presentation diff --git a/src/SketcherPrs/SketcherPrs_Rigid.cpp b/src/SketcherPrs/SketcherPrs_Rigid.cpp index 9c3d812ea..84a36d3c0 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.cpp +++ b/src/SketcherPrs/SketcherPrs_Rigid.cpp @@ -32,7 +32,9 @@ IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs); IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs); -static Handle(Image_AlienPixMap) MyPixMap; +static Handle(Image_AlienPixMap) MyPixMap; + + SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane) @@ -42,26 +44,20 @@ SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint, myPntArray->AddVertex(0., 0., 0.); } -void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) -{ - prepareAspect(); - ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); - if (aLine1.get() == NULL) - return; +bool SketcherPrs_Rigid::updatePoints(double theStep) const +{ + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + if (SketcherPrs_Tools::getShape(aObj).get() == NULL) + return false; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - aGroup->SetPrimitivesAspect(myAspect); + gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(1, aP1); - aGroup->AddPrimitiveArray(myPntArray); + return true; } + void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const { ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); diff --git a/src/SketcherPrs/SketcherPrs_Rigid.h b/src/SketcherPrs/SketcherPrs_Rigid.h index 29ed4544a..532821077 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.h +++ b/src/SketcherPrs/SketcherPrs_Rigid.h @@ -8,6 +8,7 @@ #define SketcherPrs_Rigid_H #include "SketcherPrs_SymbolPrs.h" +#include class SketchPlugin_Constraint; class SketchPlugin_Sketch; @@ -29,18 +30,20 @@ public: Standard_EXPORT SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane); + DEFINE_STANDARD_RTTI(SketcherPrs_Rigid) protected: - /// Redefinition of virtual function - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); - virtual const char* iconName() const { return "anchor.png"; } /// Redefine this function in order to add additiona lines of constraint base /// \param thePrs a presentation /// \param theColor a color of additiona lines virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const; + }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index b953501fa..f7ef9256e 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -10,11 +10,25 @@ #include #include +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef WIN32 # define FSEP "\\" @@ -22,6 +36,182 @@ # define FSEP "/" #endif +/// Step between icons +static const double MyDist = 0.03; + +/// Function to convert opengl data type +GLenum toGlDataType (const Graphic3d_TypeOfData theType, GLint& theNbComp) +{ + switch (theType) { + case Graphic3d_TOD_USHORT: + theNbComp = 1; + return GL_UNSIGNED_SHORT; + case Graphic3d_TOD_UINT: + theNbComp = 1; + return GL_UNSIGNED_INT; + case Graphic3d_TOD_VEC2: + theNbComp = 2; + return GL_FLOAT; + case Graphic3d_TOD_VEC3: + theNbComp = 3; + return GL_FLOAT; + case Graphic3d_TOD_VEC4: + theNbComp = 4; + return GL_FLOAT; + case Graphic3d_TOD_VEC4UB: + theNbComp = 4; + return GL_UNSIGNED_BYTE; + } + theNbComp = 0; + return GL_NONE; +} + + +//******************************************************************* +//! Auxiliary class for Vertex buffer with interleaved attributes. +class SketcherPrs_VertexBuffer : public OpenGl_VertexBuffer +{ + +public: + + //! Create uninitialized VBO.. + SketcherPrs_VertexBuffer (const Graphic3d_Attribute* theAttribs, + const Standard_Integer theStride) + : Stride (theStride), NbAttributes(1) + { + + memcpy (Attribs, theAttribs, sizeof(Graphic3d_Attribute) * NbAttributes); + } + + //! Create uninitialized VBO. + SketcherPrs_VertexBuffer (const Graphic3d_Buffer& theAttribs) + : Stride (theAttribs.Stride), NbAttributes(1) + { + memcpy (Attribs, theAttribs.AttributesArray(), sizeof(Graphic3d_Attribute) * NbAttributes); + } + + virtual bool HasColorAttribute() const + { + for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) { + const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; + if (anAttrib.Id == Graphic3d_TOA_COLOR) { + return true; + } + } + return false; + } + + virtual bool HasNormalAttribute() const + { + for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) { + const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; + if (anAttrib.Id == Graphic3d_TOA_NORM) { + return true; + } + } + return false; + } + + virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const + { + if (!OpenGl_VertexBuffer::IsValid()) { + return; + } + + OpenGl_VertexBuffer::Bind (theGlCtx); + GLint aNbComp; + const GLubyte* anOffset = OpenGl_VertexBuffer::myOffset; + for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) { + const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; + const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp); + if (aDataType == GL_NONE) { + continue; + } else if (anAttrib.Id == Graphic3d_TOA_POS) { + OpenGl_VertexBuffer::bindAttribute (theGlCtx, Graphic3d_TOA_POS, aNbComp, aDataType, Stride, anOffset); + break; + } + + anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType); + } + } + + virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const + { + if (!OpenGl_VertexBuffer::IsValid()) + return; + + OpenGl_VertexBuffer::Bind (theGlCtx); + GLint aNbComp; + const GLubyte* anOffset = OpenGl_VertexBuffer::myOffset; + for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) + { + const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; + const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp); + if (aDataType == GL_NONE) + continue; + + OpenGl_VertexBuffer::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset); + anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType); + } + } + + virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const + { + if (!OpenGl_VertexBuffer::IsValid()) + return; + OpenGl_VertexBuffer::Unbind (theGlCtx); + + for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) { + const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; + OpenGl_VertexBuffer::unbindAttribute (theGlCtx, anAttrib.Id); + } + } + +public: + + Graphic3d_Attribute Attribs[1]; + Standard_Integer Stride; + Standard_Integer NbAttributes; +}; + +//************************************************************** +//! Redefinition of OpenGl_Element +class SketcherPrs_Element: public OpenGl_Element +{ +public: + SketcherPrs_Element(const Handle(SketcherPrs_SymbolPrs)& theObj) : + OpenGl_Element(), myObj(theObj) {} + + virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const + { + if (!myObj.IsNull()) + myObj->Render(theWorkspace); + } + + virtual void Release (OpenGl_Context* theContext) + { + if (!myObj.IsNull()) + myObj->Release(theContext); + } + +private: + Handle(SketcherPrs_SymbolPrs) myObj; +}; + + +//************************************************************** +//! Definition of call back +OpenGl_Element* SymbolPrsCallBack(const CALL_DEF_USERDRAW * theUserDraw) +{ + Handle(SketcherPrs_SymbolPrs) anIObj = (SketcherPrs_SymbolPrs*)theUserDraw->Data; + if (anIObj.IsNull()) { + std::cout << "VUserDrawCallback error: null object passed, the custom scene element will not be rendered" << std::endl; + } + return new SketcherPrs_Element(anIObj); +} + + +//***************************************************************************** IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject); IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject); @@ -111,18 +301,121 @@ void SketcherPrs_SymbolPrs::HilightOwnerWithColor(const Handle(PrsMgr_Presentati thePM->AddToImmediateList(aHilightPrs); } +void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + prepareAspect(); + + Handle(AIS_InteractiveContext) aCtx = GetContext(); + Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(aCtx->CurrentViewer()->Driver()); + if (!aDriver.IsNull()) { + // register the custom element factory function + aDriver->UserDrawCallback() = SymbolPrsCallBack; + } + + if (!updatePoints(20)) + return; + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation); + aGroup->SetPrimitivesAspect(myAspect); + + Graphic3d_BndBox4f& aBnd = aGroup->ChangeBoundingBox(); + gp_Pnt aVert; + 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)); + } + + aGroup->UserDraw(this, true); + //aGroup->AddPrimitiveArray(myPntArray); +} + void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, 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); + } +} + - if (!myPntArray.IsNull()) { - 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); +void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) const +{ + const OpenGl_AspectMarker* anAspectMarker = theWorkspace->AspectMarker(Standard_True); + const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); + Handle(OpenGl_View) aView = theWorkspace->ActiveView(); + + double aScale = aView->Camera()->Scale(); + if (!updatePoints(MyDist * aScale)) + return; + + Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes(); + + if (myVboAttribs.IsNull()) { + myVboAttribs = new SketcherPrs_VertexBuffer(*aAttribs); + } + + if (!myVboAttribs->init(aCtx, 0, aAttribs->NbElements, aAttribs->Data(), GL_NONE, aAttribs->Stride)) { + myVboAttribs->Release (aCtx.operator->()); + myVboAttribs.Nullify(); + return; + } + + Handle(OpenGl_Texture) aTextureBack = theWorkspace->DisableTexture(); + + const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes(aCtx); + + if (!aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) { + const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0; + const Handle(OpenGl_PointSprite)& aSprite = (toHilight && anAspectMarker->SpriteHighlightRes(aCtx)->IsValid()) + ? anAspectMarker->SpriteHighlightRes(aCtx) + : aSpriteNorm; + theWorkspace->EnableTexture (aSprite); + aCtx->ShaderManager()->BindProgram(anAspectMarker, aSprite, Standard_False, Standard_False, anAspectMarker->ShaderProgramRes(aCtx)); + const TEL_COLOUR* aLineColor = &anAspectMarker->Color(); + if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) + aLineColor = theWorkspace->HighlightColor; + + aCtx->SetColor4fv(*(const OpenGl_Vec4* )(aLineColor->rgb)); + + + myVboAttribs->BindAllAttributes(aCtx); + // Textured markers will be drawn with the point sprites + aCtx->SetPointSize (anAspectMarker->MarkerSize()); + aCtx->core11fwd->glEnable (GL_ALPHA_TEST); + aCtx->core11fwd->glAlphaFunc (GL_GEQUAL, 0.1f); + + aCtx->core11fwd->glEnable (GL_BLEND); + aCtx->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + aCtx->core11fwd->glDrawArrays (0, 0, myVboAttribs->GetElemsNb()); + + aCtx->core11fwd->glDisable (GL_BLEND); + aCtx->core11fwd->glDisable (GL_ALPHA_TEST); + aCtx->SetPointSize (1.0f); + } + theWorkspace->EnableTexture (aTextureBack); + aCtx->BindProgram (NULL); +} + + +void SketcherPrs_SymbolPrs::Release (OpenGl_Context* theContext) +{ + if (!myVboAttribs.IsNull()) { + if (theContext) { + theContext->DelayedRelease (myVboAttribs); } + myVboAttribs.Nullify(); } } + diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h index 3fe208699..7a9c37b03 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.h +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -16,7 +16,10 @@ #include #include +#include + class SketchPlugin_Constraint; +class OpenGl_Context; DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject) @@ -52,9 +55,19 @@ public: Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; } + + Handle(Graphic3d_ArrayOfPoints) pointsArray() const { return myPntArray; } + + void Render(const Handle(OpenGl_Workspace)& theWorkspace) const; + + void Release (OpenGl_Context* theContext); + DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs) protected: + /// Redefinition of virtual function + Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); /// Redefinition of virtual function Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, @@ -80,6 +93,10 @@ protected: /// \param theColor a color of additiona lines virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {} + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const { return true; } + protected: /// Constraint feature SketchPlugin_Constraint* myConstraint; @@ -91,12 +108,13 @@ protected: Handle(Graphic3d_AspectMarker3d) myAspect; /// Array of symbols positions - Handle(Graphic3d_ArrayOfPoints) myPntArray; + mutable Handle(Graphic3d_ArrayOfPoints) myPntArray; private: /// Static map to collect constraints icons {IconName : IconPixMap} static std::map myIconsMap; + mutable Handle(OpenGl_VertexBuffer) myVboAttribs; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tangent.cpp b/src/SketcherPrs/SketcherPrs_Tangent.cpp index 88dcd35c3..bbee898f9 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.cpp +++ b/src/SketcherPrs/SketcherPrs_Tangent.cpp @@ -32,32 +32,21 @@ SketcherPrs_Tangent::SketcherPrs_Tangent(SketchPlugin_Constraint* theConstraint, myPntArray->AddVertex(0., 0., 0.); } -void SketcherPrs_Tangent::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) +bool SketcherPrs_Tangent::updatePoints(double theStep) const { - prepareAspect(); - ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) + return false; + if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) + return false; - std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); - if (aLine1.get() == NULL) - return; - - std::shared_ptr aLine2 = SketcherPrs_Tools::getShape(aObj2); - if (aLine2.get() == NULL) - return; - SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this); - gp_Pnt aP2 = aMgr->getPosition(aObj2, this); - - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); - aGroup->SetPrimitivesAspect(myAspect); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); + gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); myPntArray->SetVertice(1, aP1); myPntArray->SetVertice(2, aP2); - aGroup->AddPrimitiveArray(myPntArray); + return true; } void SketcherPrs_Tangent::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const diff --git a/src/SketcherPrs/SketcherPrs_Tangent.h b/src/SketcherPrs/SketcherPrs_Tangent.h index e1faefe21..335006da5 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.h +++ b/src/SketcherPrs/SketcherPrs_Tangent.h @@ -28,15 +28,17 @@ public: /// \param thePlane a coordinate plane of current sketch Standard_EXPORT SketcherPrs_Tangent(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane); + DEFINE_STANDARD_RTTI(SketcherPrs_Tangent) protected: - /// Redefinition of virtual function - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); virtual const char* iconName() const { return "tangent.png"; } virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + + /// Update myPntArray according to presentation positions + /// \return true in case of success + virtual bool updatePoints(double theStep) const; }; #endif \ No newline at end of file