1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_PositionMgr.cpp
4 // Created: 13 March 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_PositionMgr.h"
8 #include "SketcherPrs_Tools.h"
10 #include <GeomAPI_Edge.h>
12 static const int MyStep = 20;
14 static SketcherPrs_PositionMgr* MyPosMgr = NULL;
17 SketcherPrs_PositionMgr* SketcherPrs_PositionMgr::get()
20 MyPosMgr = new SketcherPrs_PositionMgr();
24 SketcherPrs_PositionMgr::SketcherPrs_PositionMgr()
29 int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine,
30 Handle(SketcherPrs_SymbolPrs) thePrs)
32 if (myShapes.count(theLine) == 1) {
33 PositionsMap& aPosMap = myShapes[theLine];
34 if (aPosMap.count(thePrs.Access()) == 1) {
35 return aPosMap[thePrs.Access()];
37 int aInd = aPosMap.size();
38 aPosMap[thePrs.Access()] = aInd;
43 aPosMap[thePrs.Access()] = 0;
44 myShapes[theLine] = aPosMap;
49 gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theLine,
50 Handle(SketcherPrs_SymbolPrs) thePrs)
52 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getLine(theLine);
53 std::shared_ptr<GeomAPI_Edge> aEdge =
54 std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
56 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
57 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
59 // Find the middle point
60 gp_Pnt aP((aPnt1->x() + aPnt2->x())/2.,
61 (aPnt1->y() + aPnt2->y())/2.,
62 (aPnt1->z() + aPnt2->z())/2.);
64 gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
65 gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
67 aShift.Multiply(MyStep);
69 int aPos = getPositionIndex(theLine, thePrs);
71 if ((aPos % 2) == 0) {
82 aP.Translate(-aShift);
91 // Normalize vector along the line
93 aVec1.Multiply(MyStep);
94 aP.Translate(aVec1.Multiplied(aM));
99 void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs)
101 std::map<ObjectPtr, PositionsMap>::iterator aIt;
102 for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) {
103 PositionsMap& aPosMap = aIt->second;
104 if (aPosMap.count(thePrs.Access()) > 0)
105 aPosMap.erase(aPosMap.find(thePrs.Access()));
107 for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) {
108 if (aIt->second.size() == 0) {
110 aIt = myShapes.begin();