X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_PositionMgr.cpp;h=03fb8a9b2ef333d6c9248baf19e45732e22c2df0;hb=68420e410a9846ec7dcb2f4645030455bc374288;hp=36c5a72b2da20374062eda77e6f1bc53f76b9512;hpb=e7f1ac7ab6a29efa09daecae84b2add0ff630c8d;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 36c5a72b2..03fb8a9b2 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -8,6 +8,9 @@ #include "SketcherPrs_Tools.h" #include +#include +#include +#include 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 aShape = SketcherPrs_Tools::getLine(theLine); - std::shared_ptr aEdge = - std::shared_ptr(new GeomAPI_Edge(aShape)); + std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); + gp_Pnt aP; // Central point + gp_Vec aVec1; // main vector + if (aShape->isEdge()) { + std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(aShape)); + std::shared_ptr aPnt1; // Start point of main vector + std::shared_ptr aPnt2; // End point of main vector + if (aCurve->isLine()) { + std::shared_ptr aEdge = + std::shared_ptr(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 aPnt1 = aEdge->firstPoint(); - std::shared_ptr aPnt2 = aEdge->lastPoint(); + } else { + double aMidParam = (aCurve->startParam() + aCurve->endParam()) / 2.; + std::shared_ptr aPnt = aCurve->getPoint(aMidParam); + aP = aPnt->impl(); - // 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(), aPnt2->impl()); + } else { + // This is a point + std::shared_ptr aVertex = std::shared_ptr(new GeomAPI_Vertex(aShape)); + std::shared_ptr aPnt = aVertex->point(); + aP = aPnt->impl(); - gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); + std::shared_ptr aDir = thePrs->plane()->dirX(); + aVec1 = gp_Vec(aDir->impl()); + } gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl()); aShift.Normalize(); aShift.Multiply(MyStep); - int aPos = getPositionIndex(theLine, thePrs); + int aPos = getPositionIndex(theShape, thePrs); int aM = 1; if ((aPos % 2) == 0) { // Even position