Salome HOME
d03cc141bcc3c9b447c566a5d60efcff3723e1de
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Symmetry.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 FEATURESPLUGIN_SYMMETRY_H_
22 #define FEATURESPLUGIN_SYMMETRY_H_
23
24 #include <FeaturesPlugin.h>
25
26 #include <ModelAPI_Feature.h>
27
28 #include <GeomAlgoAPI_Symmetry.h>
29 #include <GeomAlgoAPI_MakeShapeList.h>
30
31 class GeomAPI_Trsf;
32
33 /** \class FeaturesPlugin_Symmetry
34  *  \ingroup Plugins
35  *  \brief Feature that performs reflection with respect to a point, axis, or plane.
36  */
37 class FeaturesPlugin_Symmetry : public ModelAPI_Feature
38 {
39  public:
40   /// Symmetry kind.
41   inline static const std::string& ID()
42   {
43     static const std::string MY_SYMMETRY_ID("Symmetry");
44     return MY_SYMMETRY_ID;
45   }
46
47   /// Attribute name for creation method.
48   inline static const std::string& CREATION_METHOD()
49   {
50     static const std::string MY_CREATION_METHOD_ID("CreationMethod");
51     return MY_CREATION_METHOD_ID;
52   }
53
54   /// Attribute name for creation method "ByPoint".
55   inline static const std::string& CREATION_METHOD_BY_POINT()
56   {
57     static const std::string MY_CREATION_METHOD_ID("ByPoint");
58     return MY_CREATION_METHOD_ID;
59   }
60
61   /// Attribute name for creation method "ByAxis".
62   inline static const std::string& CREATION_METHOD_BY_AXIS()
63   {
64     static const std::string MY_CREATION_METHOD_ID("ByAxis");
65     return MY_CREATION_METHOD_ID;
66   }
67
68   /// Attribute name for creation method "ByPlane".
69   inline static const std::string& CREATION_METHOD_BY_PLANE()
70   {
71     static const std::string MY_CREATION_METHOD_ID("ByPlane");
72     return MY_CREATION_METHOD_ID;
73   }
74
75   /// Attribute name of referenced objects.
76   inline static const std::string& OBJECTS_LIST_ID()
77   {
78     static const std::string MY_OBJECTS_LIST_ID("main_objects");
79     return MY_OBJECTS_LIST_ID;
80   }
81
82   /// Attribute name of a point.
83   inline static const std::string& POINT_OBJECT_ID()
84   {
85     static const std::string MY_POINT_OBJECT_ID("point_object");
86     return MY_POINT_OBJECT_ID;
87   }
88
89   /// Attribute name of an axis.
90   inline static const std::string& AXIS_OBJECT_ID()
91   {
92     static const std::string MY_AXIS_OBJECT_ID("axis_object");
93     return MY_AXIS_OBJECT_ID;
94   }
95
96   /// Attribute name of a plane.
97   inline static const std::string& PLANE_OBJECT_ID()
98   {
99     static const std::string MY_PLANE_OBJECT_ID("plane_object");
100     return MY_PLANE_OBJECT_ID;
101   }
102
103   /// Attribute name of keeping original shape.
104   inline static const std::string& KEEP_ORIGINAL_RESULT()
105   {
106     static const std::string MY_KEEP_ORIGINAL_RESULT_ID("keep_original");
107     return MY_KEEP_ORIGINAL_RESULT_ID;
108   }
109
110   /// \return the kind of a feature.
111   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
112   {
113     static std::string MY_KIND = FeaturesPlugin_Symmetry::ID();
114     return MY_KIND;
115   }
116
117   /// Creates a new part document if needed.
118   FEATURESPLUGIN_EXPORT virtual void execute();
119
120   /// Request for initialization of data model of the feature: adding all attributes.
121   FEATURESPLUGIN_EXPORT virtual void initAttributes();
122
123   /// Use plugin manager for features creation.
124   FeaturesPlugin_Symmetry();
125
126 private:
127   /// Obtain list of source objects of the mirror
128   bool collectSourceObjects(ListOfShape& theSourceShapes,
129                             std::list<std::shared_ptr<ModelAPI_Result>>& theSourceResults);
130
131   /// Perform symmetry with respect to a point.
132   void performSymmetryByPoint();
133
134   /// Perform symmetry with respect to an axis.
135   void performSymmetryByAxis();
136
137   /// Perform symmetry with respect to a plane.
138   void performSymmetryByPlane();
139
140   /// Create new result on given shapes and the index of result
141   void buildResult(std::shared_ptr<GeomAlgoAPI_Symmetry>& theSymmetryAlgo,
142                    std::shared_ptr<GeomAPI_Shape> theBaseShape,
143                    int theResultIndex);
144
145   /// Create new result for the given part and transformation
146   void buildResult(std::shared_ptr<ModelAPI_ResultPart> theOriginal,
147                    std::shared_ptr<GeomAPI_Trsf> theTrsf,
148                    int& theResultIndex);
149 };
150
151 #endif // FEATURESPLUGIN_SYMMETRY_H_