X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_PositionMgr.cpp;h=1eb15216c24f051af4d2e9eed72d8857f84f9f5d;hb=497397f795254cb5adf0d727f5858d5aeb16eaf3;hp=2e0a66ae4f245386e223f2a2976b976518685e36;hpb=ad777acf40828575ffa8a9ba6db103a7cc17dd71;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 2e0a66ae4..1eb15216c 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -14,7 +14,7 @@ static SketcherPrs_PositionMgr* MyPosMgr = NULL; - +// The class is implemented as a singlton SketcherPrs_PositionMgr* SketcherPrs_PositionMgr::get() { if (MyPosMgr == NULL) @@ -28,27 +28,31 @@ SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, - Handle(SketcherPrs_SymbolPrs) thePrs) + const SketcherPrs_SymbolPrs* thePrs) { if (myShapes.count(theLine) == 1) { + // Find the map and add new [Presentation - Index] pair PositionsMap& aPosMap = myShapes[theLine]; - if (aPosMap.count(thePrs.Access()) == 1) { - return aPosMap[thePrs.Access()]; + if (aPosMap.count(thePrs) == 1) { + // return existing index + return aPosMap[thePrs]; } else { + // Add a new [Presentation - Index] pair int aInd = aPosMap.size(); - aPosMap[thePrs.Access()] = aInd; + aPosMap[thePrs] = aInd; return aInd; } } else { + // Create a new map with initial index PositionsMap aPosMap; - aPosMap[thePrs.Access()] = 0; + aPosMap[thePrs] = 0; myShapes[theLine] = aPosMap; return 0; } } gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, - Handle(SketcherPrs_SymbolPrs) thePrs, + const SketcherPrs_SymbolPrs* thePrs, double theStep) { std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); @@ -71,6 +75,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, (aPnt1->z() + aPnt2->z())/2.); } else { + // this is a circle or arc double aMidParam = (aCurve->startParam() + aCurve->endParam()) / 2.; std::shared_ptr aPnt = aCurve->getPoint(aMidParam); aP = aPnt->impl(); @@ -88,10 +93,12 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, std::shared_ptr aDir = thePrs->plane()->dirX(); aVec1 = gp_Vec(aDir->impl()); } - gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl()); + // Compute shifting vector for a one symbol + gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl()); aShift.Normalize(); - aShift.Multiply(theStep); + aShift.Multiply(theStep * 0.8); + // Shift the position coordinate according to position index int aPos = getPositionIndex(theShape, thePrs); int aM = 1; if ((aPos % 2) == 0) { @@ -107,7 +114,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, // 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; @@ -122,18 +129,30 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, return aP; } -void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs) +void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* thePrs) { std::map::iterator aIt; + std::list aToDel; + // Clear map for deleted presentation 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) { + // Erase index + aPosMap.erase(aPosMap.find(thePrs)); + if (aPosMap.size() == 0) + // Delete the map + aToDel.push_back(aIt->first); + else { + // Reindex objects positions in order to avoid spaces + PositionsMap::iterator aIt; + int i = 0; + for (aIt = aPosMap.begin(); aIt != aPosMap.end(); aIt++, i++) + aIt->second = i; + } } } + std::list::const_iterator aListIt; + for (aListIt = aToDel.cbegin(); aListIt != aToDel.cend(); ++aListIt) { + myShapes.erase(*aListIt); + } }