]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make symbols of constraints with fixed distance
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 23 Mar 2015 12:52:34 +0000 (15:52 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 23 Mar 2015 12:52:34 +0000 (15:52 +0300)
18 files changed:
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_Equal.cpp
src/SketcherPrs/SketcherPrs_Equal.h
src/SketcherPrs/SketcherPrs_Factory.h
src/SketcherPrs/SketcherPrs_HVDirection.cpp
src/SketcherPrs/SketcherPrs_HVDirection.h
src/SketcherPrs/SketcherPrs_Parallel.cpp
src/SketcherPrs/SketcherPrs_Parallel.h
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_Perpendicular.h
src/SketcherPrs/SketcherPrs_PositionMgr.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.h
src/SketcherPrs/SketcherPrs_Rigid.cpp
src/SketcherPrs/SketcherPrs_Rigid.h
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.h
src/SketcherPrs/SketcherPrs_Tangent.cpp
src/SketcherPrs/SketcherPrs_Tangent.h

index 5fe8b8437c12587826fa5990fada21a98b4d95e7..dca91a3b4aeffa9c5c9498be6b9bee5845c8a231 100644 (file)
@@ -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(
index d6fa639d9aec9d5a010354210e1e7dccaca129b9..7ba9a3f65ab9dddab53078881a589da978d0923a 100644 (file)
@@ -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<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
index 90beb8c048e11c258a345ece1963930f50c9327d..4bd1a86ab53a3ec4937a923d145a7383056dd4a3 100644 (file)
@@ -30,13 +30,14 @@ public:
                                        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
index 1d3f7335d66145c103603ffdf02b106e94f293f4..b6feedebc887265e3cd1a0d789999b8d32d05026 100644 (file)
@@ -16,7 +16,7 @@ class SketchPlugin_Constraint;
 
 #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);
 
 
 /**
index 2c0e892dd0973e70dd28ecab984a2d776c72af9a..5992db2fd4ed128240514a711feb824ea15ec785 100644 (file)
@@ -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<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
index 84e993b05af9fb2ab7e05d38588de1abe40ce71b..96432d23071a59be989deb477bde3205a5333bed 100644 (file)
@@ -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;
 };
index 6b7e071946cb9f67986edadae00d4f49ab2b7965..71f97ceda2329387a90395a3e714b81038f2c1e4 100644 (file)
@@ -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<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);
index 63aa6afc3efb87649cf038240badac9d5d4b1665..d0126d30b0e0e8197cff4c5f669c04ad76901493 100644 (file)
@@ -30,13 +30,13 @@ public:
                                        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
index d27cf03e57cb1b28e4876ec9d52b7c11ac05f67b..e00b23d7df1b38283f920035608c9b48ed0c8d54 100644 (file)
@@ -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<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);
index 87a620ab13d06e4ebfd4499cd1d1ec9acd916ca5..c77a09203bcdb3f0a80ab550f3227845cc301ec4 100644 (file)
@@ -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
index 03fb8a9b2ef333d6c9248baf19e45732e22c2df0..2e0a66ae4f245386e223f2a2976b976518685e36 100644 (file)
@@ -12,8 +12,6 @@
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_Dir.h>
 
-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<GeomAPI_Shape> 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<gp_Dir>());
   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;
index 65a2aa06827c3407fe1e780c5fddb95b70d48f58..fd61fa64ffe90c6e6da3e29e427066ee8b4e7699 100644 (file)
@@ -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
index 9c3d812ea7cb26a15695642e78e66fb9a1946ca3..84a36d3c017943d0afa10f58739fc211261ecc17 100644 (file)
@@ -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<GeomAPI_Ax3>& 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<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());
index 29ed4544a47d8dc0d5190895b021d8bcaf21183c..5328210773228b7eb49ae2d97703f7bc83f675fb 100644 (file)
@@ -8,6 +8,7 @@
 #define SketcherPrs_Rigid_H
 
 #include "SketcherPrs_SymbolPrs.h"
+#include <ModelAPI_Object.h>
 
 class SketchPlugin_Constraint;
 class SketchPlugin_Sketch;
@@ -29,18 +30,20 @@ public:
   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
index b953501fa8b509abe938eb6182df85e9aa36e199..f7ef9256ef03ba9e36697376cd5155972b873d61 100644 (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);
 
@@ -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();
   }
 }
+
index 3fe2086996917b60e2e590adf4e4c99d8e7e7b7b..7a9c37b032529b8b89e16eab40c65eed85c1f407 100644 (file)
 #include <Standard_DefineHandle.hxx>
 #include <map>
 
+#include <OpenGl_Workspace.hxx>
+
 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<const char*, Handle(Image_AlienPixMap)> myIconsMap;
 
+  mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
 };
 
 #endif
\ No newline at end of file
index 88dcd35c3fd45b27b56196ccb1e4f7ad9daef8a6..bbee898f92e735037e25243449d0f4a4991b4497 100644 (file)
@@ -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<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
index e1faefe2175e8085fe4b770bf32142f8de343eb4..335006da59e1cf682ef42b1167390826a387d561 100644 (file)
@@ -28,15 +28,17 @@ public:
   /// \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