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