]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_MacroRectangle.h
Salome HOME
move rectangle plugin from python addons to C++.
[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,  public GeomAPI_IPresentable
34 {
35 public:
36   /// Rectangle feature kind
37   inline static const std::string& ID()
38   {
39     static const std::string ID("SketchMacroRectangle");
40     return ID;
41   }
42
43   inline static const std::string& TYPE_ID()
44   {
45     static const std::string ID("rectangle_type");
46     return ID;
47   }
48
49   inline static const std::string& EDIT_TYPE_ID()
50   {
51     static const std::string ID("edit_rectangle_type");
52     return ID;
53   }
54
55   inline static const std::string& START_END_POINT_TYPE_ID()
56   {
57     static const std::string ID("rectangle_type_by_start_and_end_points");
58     return ID;
59   }
60
61   inline static const std::string& START_CENTER_POINT_TYPE_ID()
62   {
63     static const std::string ID("rectangle_type_by_start_and_center_points");
64     return ID;
65   }
66
67   /// 2D point - start point of the Rectangle
68   inline static const std::string& START1_ID()
69   {
70     static const std::string ID("rectangle_start_point1");
71     return ID;
72   } 
73   /// 2D point - end point of the Rectangle
74   inline static const std::string& END1_ID()
75   {
76     static const std::string ID("rectangle_end_point1");
77     return ID;
78   }
79   /// 2D point - start point of the second Rectangle type
80   inline static const std::string& START2_ID()
81   {
82     static const std::string ID("rectangle_start_point2");
83     return ID;
84   }
85
86    /// 2D point - center point of the second Rectangle type
87   inline static const std::string& CENTER_ID()
88   {
89     static const std::string ID("rectangle_center_point");
90     return ID;
91   } 
92
93   /// Returns the kind of a feature
94   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
95   {
96     static std::string MY_KIND = SketchPlugin_MacroRectangle::ID();
97     return MY_KIND;
98   }
99
100    /// Called on change of any argument-attribute of this object
101   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
102
103   /// Creates a new part document if needed
104   SKETCHPLUGIN_EXPORT virtual void execute();
105
106   /// Use plugin manager for features creation
107   SketchPlugin_MacroRectangle();
108
109   SKETCHPLUGIN_EXPORT virtual bool isMacro() const
110   {return true;}
111
112   SKETCHPLUGIN_EXPORT virtual void initAttributes();
113
114   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;}
115
116   /// Returns the AIS preview
117   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
118
119 private:
120
121   std::shared_ptr<GeomAPI_Pnt2d> myStartPoint;
122   std::shared_ptr<GeomAPI_Pnt2d> myEndPoint;
123
124   void startPoint();
125   void endPoint();
126   FeaturePtr createRectangle();
127 };
128
129 #endif