Salome HOME
Dump with geometrical selection
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Tangent.cpp
index 74ee2ed6910eb2b0978f1ceb9624cce8972e05a5..bf998d8120b5e8fe1c17ed3d932ab56567ee012c 100644 (file)
@@ -23,6 +23,9 @@
 #include "SketcherPrs_PositionMgr.h"
 
 #include <GeomAPI_Curve.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_Vertex.h>
 
 #include <SketchPlugin_Constraint.h>
 
@@ -37,8 +40,9 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Tangent, SketcherPrs_SymbolPrs);
 static Handle(Image_AlienPixMap) MyPixMap;
 
 SketcherPrs_Tangent::SketcherPrs_Tangent(ModelAPI_Feature* theConstraint,
+                                         ModelAPI_CompositeFeature* theSketcher,
                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane)
- : SketcherPrs_SymbolPrs(theConstraint, thePlane)
+ : SketcherPrs_SymbolPrs(theConstraint, theSketcher, thePlane)
 {
 }
 
@@ -74,23 +78,27 @@ 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());
-
   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;
+  GeomShapePtr aIntPnt = aShp1->intersect(aShp2);
+  if (aIntPnt.get() && aIntPnt->isVertex()) {
+    GeomVertexPtr aVetrex(new GeomAPI_Vertex(aIntPnt));
+    aPnt = aVetrex->point();
+  }
 
   // Compute points coordinates
-  SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep, aPnt);
-  myPntArray = new Graphic3d_ArrayOfPoints(1, withColor);
-  myPntArray->AddVertex(aP1);
+  if (aPnt.get()) {
+    SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
+    gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep, aPnt);
+    myPntArray = new Graphic3d_ArrayOfPoints(1, withColor);
+    myPntArray->AddVertex(aP1);
+  } else {
+    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);
+    myPntArray->AddVertex(aP1);
+    myPntArray->AddVertex(aP2);
+  }
   return true;
 }