]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve rigid constraint presentation
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 17 Mar 2015 09:47:40 +0000 (12:47 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 17 Mar 2015 09:47:40 +0000 (12:47 +0300)
src/GeomAPI/GeomAPI_Curve.cpp
src/GeomAPI/GeomAPI_Curve.h
src/SketcherPrs/SketcherPrs_HVDirection.cpp
src/SketcherPrs/SketcherPrs_Parallel.cpp
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.cpp
src/SketcherPrs/SketcherPrs_Rigid.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
src/SketcherPrs/SketcherPrs_Tools.cpp
src/SketcherPrs/SketcherPrs_Tools.h

index 9b4f4e26d8e8869945df7aa7a5b24ef34bb93ff5..46a1ea19f663732398053c879e03682ce95514e7 100644 (file)
@@ -5,6 +5,7 @@
 // Author:      Mikhail PONIKAROV
 
 #include<GeomAPI_Curve.h>
+#include<GeomAPI_Pnt.h>
 
 #include <TopoDS_Shape.hxx>
 #include <Geom_Curve.hxx>
 #include <BRep_Tool.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS.hxx>
+#include <GeomAdaptor_Curve.hxx>
 
 #define MY_CURVE (*(static_cast<Handle_Geom_Curve*>(myImpl)))
 
 GeomAPI_Curve::GeomAPI_Curve()
-    : GeomAPI_Interface(new Handle_Geom_Curve())
+    : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
 {
 }
 
@@ -27,8 +29,7 @@ GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
   TopoDS_Edge anEdge = TopoDS::Edge(aShape);
   if (!anEdge.IsNull()) {
-    Standard_Real aStart, anEnd;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd);
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
     if (!aCurve.IsNull()) {
       setImpl(new Handle(Geom_Curve)(aCurve));
     }
@@ -49,3 +50,10 @@ bool GeomAPI_Curve::isCircle() const
 {
   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
 }
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
+{
+  GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
+  gp_Pnt aPnt = aAdaptor.Value(theParam);
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+}
index f09654a8c941328b2f0554a6ccf9035589ec09d4..20e0f0a46ee46b6044b3a1a969cb9da165a2d167 100644 (file)
@@ -10,6 +10,8 @@
 #include <GeomAPI_Shape.h>
 #include <memory>
 
+class GeomAPI_Pnt;
+
 /**\class GeomAPI_Curve
  * \ingroup DataModel
  * \brief Interface to the generic curve object
@@ -33,6 +35,19 @@ class GEOMAPI_EXPORT GeomAPI_Curve : public GeomAPI_Interface
   /// Returns whether the curve is circular
   virtual bool isCircle() const;
 
+  /// Returns start parameter of the curve
+  double startParam() const { return myStart; }
+
+  /// Returns end parameter of the curve
+  double endParam() const { return myEnd; }
+
+  /// Returns point on the curve by parameter
+  /// \param theParam parameter on the curve
+  std::shared_ptr<GeomAPI_Pnt> getPoint(double theParam);
+
+private:
+  double myStart;
+  double myEnd;
 };
 
 #endif
index 0ad7c1f15db5c9b9c888e2a6dee2b3b5fd4ed294..13b3def6ed7db543ecdbc8f6a1c9c6037ef07799 100644 (file)
@@ -57,7 +57,7 @@ void SketcherPrs_HVDirection::Compute(const Handle(PrsMgr_PresentationManager3d)
   prepareAspect();
 
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(aObj1);
+  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
   if (aLine1.get() == NULL)
     return;
 
index 09aebca45e48f0bf4b916e7682f154c09796e119..b3bd0ffa96f68b0c6069a0c2bef14e338d1a3fb3 100644 (file)
@@ -59,11 +59,11 @@ void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   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::getLine(aObj1);
+  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
   if (aLine1.get() == NULL)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(aObj2);
+  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
   if (aLine2.get() == NULL)
     return;
   
index 287c5fe69dc13f916334038927d0fb46b323d897..303daffeb4ca3a487541f26c674f8832d75e9a93 100644 (file)
@@ -54,11 +54,11 @@ void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3
   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::getLine(aObj1);
+  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
   if (aLine1.get() == NULL)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(aObj2);
+  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
   if (aLine2.get() == NULL)
     return;
 
index 36c5a72b2da20374062eda77e6f1bc53f76b9512..03fb8a9b2ef333d6c9248baf19e45732e22c2df0 100644 (file)
@@ -8,6 +8,9 @@
 #include "SketcherPrs_Tools.h"
 
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Curve.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Dir.h>
 
 static const int MyStep = 20;
 
@@ -46,27 +49,51 @@ int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine,
   }
 }
 
-gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theLine, 
+gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, 
                                             Handle(SketcherPrs_SymbolPrs) thePrs)
 {
-  std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getLine(theLine);
-  std::shared_ptr<GeomAPI_Edge> aEdge = 
-    std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
+  std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(theShape);
+  gp_Pnt aP; // Central point
+  gp_Vec aVec1; // main vector
+  if (aShape->isEdge()) {
+    std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
+    std::shared_ptr<GeomAPI_Pnt> aPnt1; // Start point of main vector
+    std::shared_ptr<GeomAPI_Pnt> aPnt2; // End point of main vector
+    if (aCurve->isLine()) {
+      std::shared_ptr<GeomAPI_Edge> aEdge = 
+        std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
+
+      aPnt1 = aEdge->firstPoint();
+      aPnt2 = aEdge->lastPoint();
+
+      // Find the middle point
+      aP = gp_Pnt((aPnt1->x() + aPnt2->x())/2.,
+                  (aPnt1->y() + aPnt2->y())/2.,
+                  (aPnt1->z() + aPnt2->z())/2.);
 
-  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
-  std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
+    } else {
+      double aMidParam = (aCurve->startParam() + aCurve->endParam()) / 2.;
+      std::shared_ptr<GeomAPI_Pnt> aPnt = aCurve->getPoint(aMidParam);
+      aP = aPnt->impl<gp_Pnt>();
 
-  // Find the middle point
-  gp_Pnt aP((aPnt1->x() + aPnt2->x())/2.,
-            (aPnt1->y() + aPnt2->y())/2.,
-            (aPnt1->z() + aPnt2->z())/2.);
+      aPnt1 = aCurve->getPoint((aMidParam + aCurve->endParam()) / 2.);
+      aPnt2 = aCurve->getPoint((aMidParam + aCurve->startParam()) / 2.);
+    }
+    aVec1 = gp_Vec(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+  } else {
+    // This is a point
+    std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
+    std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+    aP = aPnt->impl<gp_Pnt>();
 
-  gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+    std::shared_ptr<GeomAPI_Dir> aDir = thePrs->plane()->dirX();
+    aVec1 = gp_Vec(aDir->impl<gp_Dir>());
+  }
   gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
   aShift.Normalize();
   aShift.Multiply(MyStep);
 
-  int aPos = getPositionIndex(theLine, thePrs);
+  int aPos = getPositionIndex(theShape, thePrs);
   int aM = 1;
   if ((aPos % 2) == 0) {
     // Even position
index 099096c202c60ef6f2d4962b6a35fbd319409351..c436e586acb5e8add2cb989cebcde831197ea507 100644 (file)
@@ -9,6 +9,9 @@
 #include "SketcherPrs_PositionMgr.h"
 
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Curve.h>
+#include <GeomAPI_Vertex.h>
 
 #include <SketchPlugin_Constraint.h>
 
 #include <SelectMgr_Selection.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 
+#include <GeomAdaptor_Curve.hxx>
+#include <BRep_Tool.hxx>
+#include <StdPrs_DeflectionCurve.hxx>
+#include <StdPrs_Point.hxx>
+#include <Geom_CartesianPoint.hxx>
+
 
 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
                                                       const std::string& theAttribute);
@@ -56,7 +65,7 @@ void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& theP
   prepareAspect();
 
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(aObj1);
+  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
   if (aLine1.get() == NULL)
     return;
 
@@ -71,11 +80,31 @@ void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& theP
 
 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
 {
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
-
-  Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
-  aGroup->SetPrimitivesAspect(aLineAspect);
+  ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+  if (aShape.get() == NULL)
+    return;
 
-  addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+  Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
+  if (aShape->isEdge()) {
+    Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
+    aGroup->SetPrimitivesAspect(aLineAspect);
+    std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
+    if (aCurve->isLine()) {
+      addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+    } else {
+      GeomAdaptor_Curve aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
+      StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
+    }
+  } else {
+    // This is a point
+    Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
+    myDrawer->SetPointAspect(aPntAspect);
+
+    std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
+    std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+    Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
+    StdPrs_Point::Add(thePrs, aPoint, myDrawer);
+  }
 }
 
index 9e051971af61cd2853c8e0ea2b05a2d2ea50719c..b953501fa8b509abe938eb6182df85e9aa36e199 100644 (file)
@@ -71,7 +71,7 @@ void SketcherPrs_SymbolPrs::prepareAspect()
 void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const
 {
   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, theAttrName);
-  std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getLine(aObj);
+  std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
   if (aLine.get() == NULL)
     return;
   std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
index e92283e42c13fdaf130bbce827c7d5c189e7e128..9f845f57fc0d2ff8b160fb1174206ca0bf5662c0 100644 (file)
@@ -27,7 +27,7 @@ ObjectPtr getResult(SketchPlugin_Constraint* theFeature, const std::string& theA
 }
 
 
-std::shared_ptr<GeomAPI_Shape> getLine(ObjectPtr theObject)
+std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject)
 {
   ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
   if (aRes.get() != NULL) {
index e913a2fd696f11464e5243e7c04a17b4aee87996..3cde3ea2a6e32dd95337a71b97b30baaff23fa39 100644 (file)
@@ -20,7 +20,7 @@ namespace SketcherPrs_Tools {
   ObjectPtr getResult(SketchPlugin_Constraint* theFeature,
                       const std::string& theAttrName);
 
-  std::shared_ptr<GeomAPI_Shape> getLine(ObjectPtr theObject);
+  std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
 
   std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
                                           const std::string& theAttrName);