${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
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(
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<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> 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
const std::shared_ptr<GeomAPI_Ax3>& 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
#define GET_CONSTRAINT_PRS(NAME) \
static AISObjectPtr NAME(SketchPlugin_Constraint* theConstraint, \
- const std::shared_ptr<GeomAPI_Ax3>& thePlane); \
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
/**
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<GeomAPI_Shape> 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
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
/// \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;
};
{
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<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> 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);
const std::shared_ptr<GeomAPI_Ax3>& 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
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<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> 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);
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
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Dir.h>
-static const int MyStep = 20;
-
static SketcherPrs_PositionMgr* MyPosMgr = NULL;
}
gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
- Handle(SketcherPrs_SymbolPrs) thePrs)
+ Handle(SketcherPrs_SymbolPrs) thePrs,
+ double theStep)
{
std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(theShape);
gp_Pnt aP; // Central point
}
gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
aShift.Normalize();
- aShift.Multiply(MyStep);
+ aShift.Multiply(theStep);
int aPos = getPositionIndex(theShape, thePrs);
int aM = 1;
if (aPos > 1) {
// Normalize vector along the line
aVec1.Normalize();
- aVec1.Multiply(MyStep);
+ aVec1.Multiply(theStep);
aP.Translate(aVec1.Multiplied(aM));
}
return aP;
/// 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
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<GeomAPI_Ax3>& thePlane)
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<GeomAPI_Shape> 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());
#define SketcherPrs_Rigid_H
#include "SketcherPrs_SymbolPrs.h"
+#include <ModelAPI_Object.h>
class SketchPlugin_Constraint;
class SketchPlugin_Sketch;
Standard_EXPORT SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& 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
#include <GeomAPI_Edge.h>
#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_BndBox4f.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitivePoint.hxx>
+#include <TopLoc_Location.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_Viewer.hxx>
+#include <Prs3d_Root.hxx>
+#include <OpenGl_Element.hxx>
+#include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_View.hxx>
+#include <OpenGl_PointSprite.hxx>
+#include <OpenGl_VertexBuffer.hxx>
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_VertexBufferCompat.hxx>
+#include <OpenGl_GraphicDriver.hxx>
#ifdef WIN32
# define FSEP "\\"
# 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);
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();
}
}
+
#include <Standard_DefineHandle.hxx>
#include <map>
+#include <OpenGl_Workspace.hxx>
+
class SketchPlugin_Constraint;
+class OpenGl_Context;
DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
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,
/// \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;
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<const char*, Handle(Image_AlienPixMap)> myIconsMap;
+ mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
};
#endif
\ No newline at end of file
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<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> 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
/// \param thePlane a coordinate plane of current sketch
Standard_EXPORT SketcherPrs_Tangent(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& 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