X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_PositionMgr.cpp;h=ec7938b89abfd58c7fdf66432b34ca550ae76a9d;hb=8ebc9a7d5f87057b61b174e7568e01e44571549d;hp=5237b18e2b038f8c6d8300320ddbcc02037a6435;hpb=71862c3b2c0e78ef927520985f68c5ffa2916b78;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 5237b18e2..ec7938b89 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -5,10 +5,12 @@ // Author: Vitaly SMETANNIKOV #include "SketcherPrs_PositionMgr.h" +#include "SketcherPrs_Tools.h" #include - -static const int MyStep = 20; +#include +#include +#include static SketcherPrs_PositionMgr* MyPosMgr = NULL; @@ -25,46 +27,72 @@ SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() } -int SketcherPrs_PositionMgr::getPositionIndex(std::shared_ptr theLine, - Handle(SketcherPrs_SymbolPrs) thePrs) +int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, + const SketcherPrs_SymbolPrs* thePrs) { if (myShapes.count(theLine) == 1) { PositionsMap& aPosMap = myShapes[theLine]; - if (aPosMap.count(thePrs.Access()) == 1) { - return aPosMap[thePrs.Access()]; + if (aPosMap.count(thePrs) == 1) { + return aPosMap[thePrs]; } else { int aInd = aPosMap.size(); - aPosMap[thePrs.Access()] = aInd; + aPosMap[thePrs] = aInd; return aInd; } } else { PositionsMap aPosMap; - aPosMap[thePrs.Access()] = 0; + aPosMap[thePrs] = 0; myShapes[theLine] = aPosMap; return 0; } } -gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr theLine, - Handle(SketcherPrs_SymbolPrs) thePrs) +gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, + const SketcherPrs_SymbolPrs* thePrs, + double theStep) { - std::shared_ptr aEdge = - std::shared_ptr(new GeomAPI_Edge(theLine)); + 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); + aShift.Multiply(theStep * 0.8); - int aPos = getPositionIndex(theLine, thePrs); + int aPos = getPositionIndex(theShape, thePrs); int aM = 1; if ((aPos % 2) == 0) { // Even position @@ -79,7 +107,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr theLi // Odd position aP.Translate(-aShift); if (aPos > 1) { - if (aPos % 4 == 0) + if ((aPos - 1) % 4 == 0) aM = (aPos - 1) / 4; else aM = -(aPos + 1) / 4; @@ -88,24 +116,26 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr theLi if (aPos > 1) { // Normalize vector along the line aVec1.Normalize(); - aVec1.Multiply(MyStep); + aVec1.Multiply(theStep); aP.Translate(aVec1.Multiplied(aM)); } return aP; } -void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs) +void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* thePrs) { - std::map, PositionsMap>::iterator aIt; + std::map::iterator aIt; + std::list aToDel; for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { PositionsMap& aPosMap = aIt->second; - if (aPosMap.count(thePrs.Access()) > 0) - aPosMap.erase(aPosMap.find(thePrs.Access())); - } - for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { - if (aIt->second.size() == 0) { - myShapes.erase(aIt); - aIt = myShapes.begin(); + if (aPosMap.count(thePrs) > 0) { + aPosMap.erase(aPosMap.find(thePrs)); + if (aPosMap.size() == 0) + aToDel.push_back(aIt->first); } } + std::list::const_iterator aListIt; + for (aListIt = aToDel.cbegin(); aListIt != aToDel.cend(); ++aListIt) { + myShapes.erase(*aListIt); + } }