Salome HOME
Issue #2208: positioning of tangent and perpendicular symbols
authorvsv <vsv@opencascade.com>
Tue, 18 Jul 2017 15:21:17 +0000 (18:21 +0300)
committervsv <vsv@opencascade.com>
Tue, 18 Jul 2017 15:21:17 +0000 (18:21 +0300)
src/GeomAPI/GeomAPI_Circ.cpp
src/GeomAPI/GeomAPI_Circ.h
src/GeomAPI/GeomAPI_Lin.h
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.h
src/SketcherPrs/SketcherPrs_Tangent.cpp

index 63743cc7d06caaa327758599ccf7f7953ad6f019..87662f275a42cdc2e18a4510c50b4bb8ed2621d9 100644 (file)
@@ -56,6 +56,16 @@ GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
 {
 }
 
+//=================================================================================================
+GeomAPI_Circ::GeomAPI_Circ(const GeomCurvePtr& theCurve)
+{
+  Handle(Geom_Curve) aCurve = theCurve->impl<Handle(Geom_Curve)>();
+  Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
+  if (aCirc.IsNull())
+    throw Standard_ConstructionError("GeomAPI_Circ: Curve is not a circle");
+  setImpl(new gp_Circ(aCirc->Circ()));
+}
+
 //=================================================================================================
 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::center() const
 {
index 6f4215965ca75da375b1548f217c13fbbe9d7a4d..4fe0c82407f4a8d2e4dcd52e005dff5551a1238f 100644 (file)
@@ -22,6 +22,7 @@
 #define GeomAPI_Circ_H_
 
 #include <GeomAPI_Interface.h>
+#include <GeomAPI_Curve.h>
 #include <memory>
 
 class GeomAPI_Ax2;
@@ -51,6 +52,9 @@ class GeomAPI_Circ : public GeomAPI_Interface
   GEOMAPI_EXPORT GeomAPI_Circ(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
                const std::shared_ptr<GeomAPI_Dir>& theDir, double theRadius);
 
+  /// Creation of circle defined by a curve
+  GEOMAPI_EXPORT GeomAPI_Circ(const GeomCurvePtr& theCurve);
+
   /// Return center of the circle
   GEOMAPI_EXPORT const std::shared_ptr<GeomAPI_Pnt> center() const;
 
index bff2d17e4994aa328516a277786ba5ea251c9595..e8c91e2e4d17495481cf7226066ba496a026030f 100644 (file)
@@ -84,5 +84,8 @@ class GeomAPI_Lin : public GeomAPI_Interface
   bool isCoplanar(const std::shared_ptr<GeomAPI_Lin> theLin) const;
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Lin> GeomLinePtr;
+
 #endif
 
index bce82ffbaa8fce3b49fc5e0c35e910c7d78adf01..0dcb01edf49a21bac46993bfad0c282e3a6b7d7d 100644 (file)
@@ -27,6 +27,9 @@
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Prs3d_Root.hxx>
 
+#include <GeomAPI_Curve.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
 
 
 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
@@ -64,13 +67,24 @@ bool SketcherPrs_Perpendicular::updateIfReadyToDisplay(double theStep, bool with
   ObjectPtr aObj2 =
     SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
 
+  GeomShapePtr aShp1 = SketcherPrs_Tools::getShape(aObj1);
+  GeomShapePtr aShp2 = SketcherPrs_Tools::getShape(aObj2);
+
+  GeomEdgePtr aEdge1(new GeomAPI_Edge(aShp1));
+  GeomEdgePtr aEdge2(new GeomAPI_Edge(aShp2));
+
+  std::shared_ptr<GeomAPI_Lin> aLin1 = aEdge1->line();
+  std::shared_ptr<GeomAPI_Lin> aLin2 = aEdge2->line();
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
+
   // Compute position of symbols
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
-  gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
-  myPntArray = new Graphic3d_ArrayOfPoints(2, withColor);
+  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep, aPnt);
+  //gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
+  myPntArray = new Graphic3d_ArrayOfPoints(1, withColor);
   myPntArray->AddVertex(aP1);
-  myPntArray->AddVertex(aP2);
+  //myPntArray->AddVertex(aP2);
   return true;
 }
 
index 51771dcfab9b6b01852e5c56e0ea5e3ff60fc4b2..b57344d712d5be8cf88d19ed41c6658f2902ebcc 100644 (file)
@@ -120,7 +120,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
   gp_Pnt aP; // Central point
 
   if (thePnt.get()) {
-    aP = thePnt->impl<gp_Pnt>();
+    return getPointPosition(theShape, thePrs, theStep, thePnt);
   } else {
     if (aShape->isEdge()) {
       std::shared_ptr<GeomAPI_Curve> aCurve =
@@ -143,8 +143,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
   // Compute shifting vector for a one symbol
   gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl<gp_Dir>());
   aShift.Normalize();
-  // For point based symbols step = 1.2, for line based = 0.8
-  aShift.Multiply(theStep * (thePnt.get()? 1.2 : 0.8));
+  aShift.Multiply(theStep * 0.8);
 
   // Shift the position coordinate according to position index
   int aPos = getPositionIndex(theShape, thePrs);
@@ -177,6 +176,22 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
   return aP;
 }
 
+gp_Pnt SketcherPrs_PositionMgr::getPointPosition(
+  ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs,
+  double theStep, GeomPointPtr thePnt)
+{
+  gp_Pnt aP = thePnt->impl<gp_Pnt>();
+  gp_Vec aVec1 = getVector(theLine, thePrs->plane()->dirX(), aP);
+
+  // Compute shifting vector for a one symbol
+  gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl<gp_Dir>());
+  aShift.Normalize();
+  aShift.Multiply(theStep * 1.5);
+  aP.Translate(aShift);
+  return aP;
+}
+
+
 void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* thePrs)
 {
   std::map<ObjectPtr, PositionsMap>::iterator aIt;
index 8de0204b44bbd09f1d0e733f11c48360deffa756..272092989524c4d9a8f032035e257bcd51ae3b54 100644 (file)
@@ -61,6 +61,9 @@ private:
   /// \param thePrs a presentation of constraint
   int getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs);
 
+  gp_Pnt getPointPosition(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs,
+                          double theStep, GeomPointPtr thePnt);
+
 private:
   typedef std::map<const SketcherPrs_SymbolPrs*, int> PositionsMap;
 
index 74ee2ed6910eb2b0978f1ceb9624cce8972e05a5..8358b07e6f5e703938dd766cb45bcbd0eb44f444 100644 (file)
@@ -23,6 +23,8 @@
 #include "SketcherPrs_PositionMgr.h"
 
 #include <GeomAPI_Curve.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Lin.h>
 
 #include <SketchPlugin_Constraint.h>
 
@@ -74,17 +76,24 @@ bool SketcherPrs_Tangent::updateIfReadyToDisplay(double theStep, bool withColor)
   GeomCurvePtr aCurv1 = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShp1));
   GeomCurvePtr aCurv2 = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShp2));
 
-  GeomPointPtr aPnt1_1 = aCurv1->getPoint(aCurv1->startParam());
-  GeomPointPtr aPnt1_2 = aCurv1->getPoint(aCurv1->endParam());
-
-  GeomPointPtr aPnt2_1 = aCurv2->getPoint(aCurv2->startParam());
-  GeomPointPtr aPnt2_2 = aCurv2->getPoint(aCurv2->endParam());
-
+  GeomCurvePtr aLine;
+  GeomCirclePtr aCircle;
+  if (aCurv1->isLine()) {
+    aLine = aCurv1;
+    aCircle = GeomCirclePtr(new GeomAPI_Circ(aCurv2));
+  } else {
+    aLine = aCurv2;
+    aCircle = GeomCirclePtr(new GeomAPI_Circ(aCurv1));
+  }
+
+  GeomPointPtr aPnt1 = aLine->getPoint(aLine->startParam());
+  GeomPointPtr aPnt2 = aLine->getPoint(aLine->endParam());
+  double aParam;
   GeomPointPtr aPnt;
-  if (aPnt1_1->isEqual(aPnt2_1) || aPnt1_1->isEqual(aPnt2_2))
-    aPnt = aPnt1_1;
-  else if (aPnt1_2->isEqual(aPnt2_1) || aPnt1_2->isEqual(aPnt2_2))
-    aPnt = aPnt1_2;
+  if (aCircle->parameter(aPnt1, 1.e-4, aParam))
+    aPnt = aPnt1;
+  else
+    aPnt = aPnt2;
 
   // Compute points coordinates
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();