1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef SketcherPrs_PositionMgr_H
21 #define SketcherPrs_PositionMgr_H
23 #include "SketcherPrs.h"
24 #include "SketcherPrs_SymbolPrs.h"
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_Pnt.h>
29 #include <ModelAPI_Object.h>
36 * A class Position Manager which manages position of constraints symbols along a source object line.
37 * it expects that symbol icons have size 16x16 px
39 class SketcherPrs_PositionMgr
42 /// Returns current instance of position manager
43 SKETCHERPRS_EXPORT static SketcherPrs_PositionMgr* get();
45 /// Returns position of symbol for the given presentation
46 /// \param theLine constrained object
47 /// \param thePrs a presentation of constraint
48 /// \param theStep step between symbols
49 SKETCHERPRS_EXPORT gp_Pnt getPosition(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs,
50 double theStep = 20, GeomPointPtr thePnt = GeomPointPtr());
52 /// Deletes constraint object from internal structures. Has to be called on constraint delete.
53 /// \param thePrs a constraint presentation
54 SKETCHERPRS_EXPORT void deleteConstraint(const SketcherPrs_SymbolPrs* thePrs);
56 /// Cleares all stored positions for all constraints
57 void clearAll() { myShapes.clear(); myPntShapes.clear(); }
61 SketcherPrs_PositionMgr();
63 /// Returns position index of the given constraint
64 /// \param theLine constrained object
65 /// \param thePrs a presentation of constraint
66 int getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs);
68 /// Returns position index of the given constraint around a point
69 /// \param theLine constrained object
70 /// \param thePrs a presentation of constraint
71 const std::array<int, 2>& getPositionIndex(GeomPointPtr thePos,
72 const SketcherPrs_SymbolPrs* thePrs);
74 /// Returns position of a constraint around a point
75 /// \param theLine a base object of the constraint
76 /// \param thePrs a presentation of the constraint symbol
77 /// \param theStep step from base point
78 /// \param thePnt a base point
79 gp_Pnt getPointPosition(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs,
80 double theStep, GeomPointPtr thePnt);
82 static bool isPntConstraint(const std::string& theName);
85 typedef std::map<const SketcherPrs_SymbolPrs*, int> PositionsMap;
86 typedef std::map<const ModelAPI_Feature*, std::array<int, 2>> FeaturesMap;
88 /// The map contains position index
89 std::map<ObjectPtr, PositionsMap> myShapes;
91 /// The map contains position of index for constraints around a point
92 FeaturesMap myPntShapes;