From: vsv Date: Tue, 18 Jul 2017 15:21:17 +0000 (+0300) Subject: Issue #2208: positioning of tangent and perpendicular symbols X-Git-Tag: V_2.9.0~23^2~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f34ed4488b454d0f9d2cb4281eafdea7daf0f91c;p=modules%2Fshaper.git Issue #2208: positioning of tangent and perpendicular symbols --- diff --git a/src/GeomAPI/GeomAPI_Circ.cpp b/src/GeomAPI/GeomAPI_Circ.cpp index 63743cc7d..87662f275 100644 --- a/src/GeomAPI/GeomAPI_Circ.cpp +++ b/src/GeomAPI/GeomAPI_Circ.cpp @@ -56,6 +56,16 @@ GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr& theCenter, { } +//================================================================================================= +GeomAPI_Circ::GeomAPI_Circ(const GeomCurvePtr& theCurve) +{ + Handle(Geom_Curve) aCurve = theCurve->impl(); + 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_Circ::center() const { diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h index 6f4215965..4fe0c8240 100644 --- a/src/GeomAPI/GeomAPI_Circ.h +++ b/src/GeomAPI/GeomAPI_Circ.h @@ -22,6 +22,7 @@ #define GeomAPI_Circ_H_ #include +#include #include class GeomAPI_Ax2; @@ -51,6 +52,9 @@ class GeomAPI_Circ : public GeomAPI_Interface GEOMAPI_EXPORT GeomAPI_Circ(const std::shared_ptr& theCenter, const std::shared_ptr& 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 center() const; diff --git a/src/GeomAPI/GeomAPI_Lin.h b/src/GeomAPI/GeomAPI_Lin.h index bff2d17e4..e8c91e2e4 100644 --- a/src/GeomAPI/GeomAPI_Lin.h +++ b/src/GeomAPI/GeomAPI_Lin.h @@ -84,5 +84,8 @@ class GeomAPI_Lin : public GeomAPI_Interface bool isCoplanar(const std::shared_ptr theLin) const; }; +//! Pointer on the object +typedef std::shared_ptr GeomLinePtr; + #endif diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index bce82ffba..0dcb01edf 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -27,6 +27,9 @@ #include #include +#include +#include +#include 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 aLin1 = aEdge1->line(); + std::shared_ptr aLin2 = aEdge2->line(); + + std::shared_ptr 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; } diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 51771dcfa..b57344d71 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -120,7 +120,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, gp_Pnt aP; // Central point if (thePnt.get()) { - aP = thePnt->impl(); + return getPointPosition(theShape, thePrs, theStep, thePnt); } else { if (aShape->isEdge()) { std::shared_ptr 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()); 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_Vec aVec1 = getVector(theLine, thePrs->plane()->dirX(), aP); + + // Compute shifting vector for a one symbol + gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl()); + aShift.Normalize(); + aShift.Multiply(theStep * 1.5); + aP.Translate(aShift); + return aP; +} + + void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* thePrs) { std::map::iterator aIt; diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.h b/src/SketcherPrs/SketcherPrs_PositionMgr.h index 8de0204b4..272092989 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.h +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.h @@ -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 PositionsMap; diff --git a/src/SketcherPrs/SketcherPrs_Tangent.cpp b/src/SketcherPrs/SketcherPrs_Tangent.cpp index 74ee2ed69..8358b07e6 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.cpp +++ b/src/SketcherPrs/SketcherPrs_Tangent.cpp @@ -23,6 +23,8 @@ #include "SketcherPrs_PositionMgr.h" #include +#include +#include #include @@ -74,17 +76,24 @@ bool SketcherPrs_Tangent::updateIfReadyToDisplay(double theStep, bool withColor) GeomCurvePtr aCurv1 = std::shared_ptr(new GeomAPI_Curve(aShp1)); GeomCurvePtr aCurv2 = std::shared_ptr(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();