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"
9 #include <GeomAPI_Edge.h>
11 static const int MyStep = 20;
13 static SketcherPrs_PositionMgr* MyPosMgr = NULL;
16 SketcherPrs_PositionMgr* SketcherPrs_PositionMgr::get()
19 MyPosMgr = new SketcherPrs_PositionMgr();
23 SketcherPrs_PositionMgr::SketcherPrs_PositionMgr()
28 int SketcherPrs_PositionMgr::getPositionIndex(std::shared_ptr<GeomAPI_Shape> theLine,
29 Handle(SketcherPrs_SymbolPrs) thePrs)
31 if (myShapes.count(theLine) == 1) {
32 PositionsMap& aPosMap = myShapes[theLine];
33 if (aPosMap.count(thePrs.Access()) == 1) {
34 return aPosMap[thePrs.Access()];
36 int aInd = aPosMap.size();
37 aPosMap[thePrs.Access()] = aInd;
42 aPosMap[thePrs.Access()] = 0;
43 myShapes[theLine] = aPosMap;
48 gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr<GeomAPI_Shape> theLine,
49 Handle(SketcherPrs_SymbolPrs) thePrs)
51 std::shared_ptr<GeomAPI_Edge> aEdge =
52 std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(theLine));
54 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
55 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
57 // Find the middle point
58 gp_Pnt aP((aPnt1->x() + aPnt2->x())/2.,
59 (aPnt1->y() + aPnt2->y())/2.,
60 (aPnt1->z() + aPnt2->z())/2.);
62 gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
63 gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
65 aShift.Multiply(MyStep);
67 int aPos = getPositionIndex(theLine, thePrs);
69 if ((aPos % 2) == 0) {
80 aP.Translate(-aShift);
89 // Normalize vector along the line
91 aVec1.Multiply(MyStep);
92 aP.Translate(aVec1.Multiplied(aM));
97 void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs)
99 std::map<std::shared_ptr<GeomAPI_Shape>, PositionsMap>::iterator aIt;
100 for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) {
101 PositionsMap& aPosMap = aIt->second;
102 if (aPosMap.count(thePrs.Access()) > 0)
103 aPosMap.erase(aPosMap.find(thePrs.Access()));
105 for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) {
106 if (aIt->second.size() == 0) {
108 aIt = myShapes.begin();