X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_PositionMgr.cpp;h=7aacd2002093c332c992a444deaac12f75898e03;hb=c02fae5493cc6d56c9a1db3bdcf6d872f88fea07;hp=85aa05217cbe08cfe9473e4fef71f228f08d6174;hpb=3c46eaaf05cee455691f51a8555f1e7a9540bfdb;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 85aa05217..7aacd2002 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,30 +12,31 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SketcherPrs_PositionMgr.h" #include "SketcherPrs_Tools.h" -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include +#include #include -#include -#include #include -#include +#include +#include +#include #include +#include #include #include @@ -61,7 +62,6 @@ SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() { } - int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs) { @@ -152,14 +152,17 @@ const std::array& SketcherPrs_PositionMgr::getPositionIndex(GeomPointPtr if (aUseFeature) { DataPtr aData = aFeature->data(); AttributeRefAttrPtr aObjRef = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); - FeaturePtr aObj = ModelAPI_Feature::feature(aObjRef->object()); + FeaturePtr aObj; + if (aObjRef) + aObj = ModelAPI_Feature::feature(aObjRef->object()); bool aContains = false; - if (containsPoint(aObj, aPnt2d, thePos)) { + if (aObj && containsPoint(aObj, aPnt2d, thePos)) { aContains = true; } else { aObjRef = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); - aObj = ModelAPI_Feature::feature(aObjRef->object()); - if (containsPoint(aObj, aPnt2d, thePos)) { + if (aObjRef) + aObj = ModelAPI_Feature::feature(aObjRef->object()); + if (aObj && containsPoint(aObj, aPnt2d, thePos)) { aContains = true; } } @@ -188,12 +191,26 @@ gp_Vec getVector(ObjectPtr theShape, GeomDirPtr theDir, gp_Pnt theP) std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(aShape)); - if (aCurve->isCircle()) { + if (aCurve->isCircle() || aCurve->isEllipse()) { Handle(Geom_Curve) aCurv = aCurve->impl(); GeomAPI_ProjectPointOnCurve anExtr(theP, aCurv); double aParam = anExtr.LowerDistanceParameter(); gp_Pnt aP; aCurv->D1(aParam, aP, aVec); + // 2458: check correct orientation of the vector + if (aVec.SquareMagnitude() > Precision::Confusion()) { + std::shared_ptr aCircEdge(new GeomAPI_Edge(aShape)); + double aFirstParam, aLastParam; + aCircEdge->getRange(aFirstParam, aLastParam); + // if parameter is near the LastParam, make the vector go inside (reverse) + double aDelta = aLastParam - aParam; + while (aDelta < -Precision::Confusion()) + aDelta += 2. * M_PI; + while (aDelta > 2. * M_PI - Precision::Confusion()) + aDelta -= 2. * M_PI; + if (fabs(aDelta) < Precision::Confusion()) + aVec.Reverse(); + } } else { GeomPointPtr aPnt1 = aCurve->getPoint(aCurve->endParam()); GeomPointPtr aPnt2 = aCurve->getPoint(aCurve->startParam()); @@ -288,8 +305,8 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym int aNbSubs = aOwner->numberOfSubs(); for (int i = 0; i < aNbSubs; i++) { FeaturePtr aFeature = aOwner->subFeature(i); - if (!aFeature->firstResult().get()) // There is no result - continue; + if (!aFeature->firstResult().get() || aFeature->firstResult()->isDisabled()) + continue; // There is no result if (aFeature->getKind() == SketchPlugin_Line::ID()) { AttributePoint2DPtr aSPnt1 = std::dynamic_pointer_cast( @@ -313,8 +330,7 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym if (aDist <= Precision::Confusion()) aList.push_back(aFeature->firstResult()); } - } else if ((aFeature->getKind() == SketchPlugin_Circle::ID()) || - (aFeature->getKind() == SketchPlugin_Arc::ID())) { + } else { GeomCurvePtr aCurve; ObjectPtr aResObj; std::list aResults = aFeature->results(); @@ -328,11 +344,17 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym } } if (aCurve.get()) { - double aStart = aCurve->startParam(); - double aEnd = aCurve->endParam(); - GeomCirclePtr aCircle = GeomCirclePtr(new GeomAPI_Circ(aCurve)); - GeomPointPtr aProjPnt = aCircle->project(thePnt); - if (thePnt->distance(aProjPnt) <= Precision::Confusion()) + GeomPointPtr aProjPnt; + if (aFeature->getKind() == SketchPlugin_Circle::ID() || + aFeature->getKind() == SketchPlugin_Arc::ID()) { + GeomCirclePtr aCircle = GeomCirclePtr(new GeomAPI_Circ(aCurve)); + aProjPnt = aCircle->project(thePnt); + } + else if (aFeature->getKind() == SketchPlugin_Ellipse::ID()) { + GeomEllipsePtr anEllipse = GeomEllipsePtr(new GeomAPI_Ellipse(aCurve)); + aProjPnt = anEllipse->project(thePnt); + } + if (aProjPnt && thePnt->distance(aProjPnt) <= Precision::Confusion()) aList.push_back(aResObj); } } @@ -346,6 +368,8 @@ gp_Pnt SketcherPrs_PositionMgr::getPointPosition( double theStep, GeomPointPtr thePnt) { gp_Pnt aP = thePnt->impl(); + if (!thePrs->plane().get()) + return aP; GeomDirPtr aNormal = thePrs->plane()->normal(); gp_Dir aNormDir = aNormal->impl();