Salome HOME
1. Manage color of construction point using preferences dialog box.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroRectangle.h
1 // Copyright (C) 2014-2020  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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchPlugin_MacroRectangle_H_
21 #define SketchPlugin_MacroRectangle_H_
22
23 #include "SketchPlugin.h"
24 #include <SketchPlugin_SketchEntity.h>
25 #include <GeomAPI_IPresentable.h>
26
27 class GeomAPI_Pnt2d;
28
29 /**\class SketchPlugin_MacroRectangle
30  * \ingroup Plugins
31  * \brief Feature for creation of the new Rectangle in Sketch.
32  */
33 class SketchPlugin_MacroRectangle: public SketchPlugin_SketchEntity,
34     public GeomAPI_IPresentable
35 {
36 public:
37   /// Rectangle feature kind
38   inline static const std::string& ID()
39   {
40     static const std::string ID("SketchMacroRectangle");
41     return ID;
42   }
43
44   inline static const std::string& RECTANGLE_TYPE_ID()
45   {
46     static const std::string ID("rectangle_type");
47     return ID;
48   }
49
50   inline static const std::string& EDIT_RECTANGLE_TYPE_ID()
51   {
52     static const std::string ID("edit_rectangle_type");
53     return ID;
54   }
55
56   inline static const std::string& START_END_POINT_TYPE_ID()
57   {
58     static const std::string ID("rectangle_type_by_start_and_end_points");
59     return ID;
60   }
61
62   inline static const std::string& CENTER_END_POINT_TYPE_ID()
63   {
64     static const std::string ID("rectangle_type_by_center_and_end_points");
65     return ID;
66   }
67
68   /// 2D point - start point of the Rectangle
69   inline static const std::string& START1_ID()
70   {
71     static const std::string ID("rectangle_start_point1");
72     return ID;
73   }
74
75   inline static const std::string& START1_REF_ID()
76   {
77     static const std::string ID("rectangle_start_point1_ref");
78     return ID;
79   }
80
81   /// 2D point - end point of the Rectangle
82   inline static const std::string& END1_ID()
83   {
84     static const std::string ID("rectangle_end_point1");
85     return ID;
86   }
87
88   inline static const std::string& END1_REF_ID()
89   {
90     static const std::string ID("rectangle_end_point1_ref");
91     return ID;
92   }
93
94   /// 2D point - start point of the second Rectangle type
95   inline static const std::string& END2_ID()
96   {
97     static const std::string ID("rectangle_end_point2");
98     return ID;
99   }
100
101   inline static const std::string& END2_REF_ID()
102   {
103     static const std::string ID("rectangle_end_point2_ref");
104     return ID;
105   }
106
107   /// 2D point - center point of the second Rectangle type
108   inline static const std::string& CENTER_ID()
109   {
110     static const std::string ID("rectangle_center_point");
111     return ID;
112   }
113   /// Reference for center point selection.
114   inline static const std::string& CENTER_REF_ID()
115   {
116     static const std::string ID("rectangle_center_point_ref");
117     return ID;
118   }
119
120   /// Returns the kind of a feature
121   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
122   {
123     static std::string MY_KIND = SketchPlugin_MacroRectangle::ID();
124     return MY_KIND;
125   }
126
127   /// Called on change of any argument-attribute of this object
128   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
129
130   /// Creates a new part document if needed
131   SKETCHPLUGIN_EXPORT virtual void execute();
132
133   /// Use plugin manager for features creation
134   SketchPlugin_MacroRectangle();
135
136   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
137   {return true;}
138
139   SKETCHPLUGIN_EXPORT virtual void initAttributes();
140
141   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;}
142
143   /// Returns the AIS preview
144   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
145
146 private:
147
148   std::shared_ptr<GeomAPI_Pnt2d> myStartPoint;
149   std::shared_ptr<GeomAPI_Pnt2d> myEndPoint;
150   std::shared_ptr<GeomAPI_Pnt2d> myCenterPoint;
151   bool myHasCenterPoint;
152   void startPoint();
153   void endPoint();
154   FeaturePtr createRectangle();
155 };
156
157 #endif