Salome HOME
Merge remote-tracking branch 'remotes/origin/2018_Lot1_Tasks'
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_PositionMgr.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef SketcherPrs_PositionMgr_H
22 #define SketcherPrs_PositionMgr_H
23
24 #include "SketcherPrs.h"
25 #include "SketcherPrs_SymbolPrs.h"
26
27 #include <GeomAPI_Shape.h>
28 #include <GeomAPI_Pnt.h>
29 #include <gp_Pnt.hxx>
30 #include <ModelAPI_Object.h>
31
32 #include <map>
33 #include <array>
34
35 /**
36 * \ingroup GUI
37 * A class Position Manager which manages position of constraints symbols along a source object line.
38 * it expects that symbol icons have size 16x16 px
39 */
40 class SKETCHERPRS_EXPORT SketcherPrs_PositionMgr
41 {
42 public:
43   /// Returns current instance of position manager
44   static SketcherPrs_PositionMgr* get();
45
46   /// Returns position of symbol for the given presentation
47   /// \param theLine constrained object
48   /// \param thePrs a presentation of constraint
49   /// \param theStep step between symbols
50   gp_Pnt getPosition(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs,
51                      double theStep = 20, GeomPointPtr thePnt = GeomPointPtr());
52
53   /// Deletes constraint object from internal structures. Has to be called on constraint delete.
54   /// \param thePrs a constraint presentation
55   void deleteConstraint(const SketcherPrs_SymbolPrs* thePrs);
56
57   /// Cleares all stored positions for all constraints
58   void clearAll()  { myShapes.clear(); myPntShapes.clear(); }
59
60 private:
61   /// Constructor
62   SketcherPrs_PositionMgr();
63
64   /// Returns position index of the given constraint
65   /// \param theLine constrained object
66   /// \param thePrs a presentation of constraint
67   int getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs);
68
69   /// Returns position index of the given constraint around a point
70   /// \param theLine constrained object
71   /// \param thePrs a presentation of constraint
72   const std::array<int, 2>& getPositionIndex(GeomPointPtr thePos,
73                                       const SketcherPrs_SymbolPrs* thePrs);
74
75   /// Returns position of a constraint around a point
76   /// \param theLine a base object of the constraint
77   /// \param thePrs a presentation of the constraint symbol
78   /// \param theStep step from base point
79   /// \param thePnt a base point
80   gp_Pnt getPointPosition(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs,
81                           double theStep, GeomPointPtr thePnt);
82
83   static bool isPntConstraint(const std::string& theName);
84
85 private:
86   typedef std::map<const SketcherPrs_SymbolPrs*, int> PositionsMap;
87   typedef std::map<const ModelAPI_Feature*, std::array<int, 2>> FeaturesMap;
88
89   /// The map contains position index
90   std::map<ObjectPtr, PositionsMap> myShapes;
91
92   /// The map contains position of index for constraints around a point
93   FeaturesMap myPntShapes;
94 };
95
96 #endif