Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_Validators.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 PartSet_Validators_H
21 #define PartSet_Validators_H
22
23 #include "PartSet.h"
24
25 #include <ModuleBase_SelectionValidator.h>
26 #include <ModuleBase_ISelection.h>
27 #include <ModelAPI_AttributeValidator.h>
28
29 class GeomDataAPI_Point2D;
30
31 /*
32  * Selector validators
33  */
34
35
36 //! \ingroup Validators
37 //! A class to validate a selection for Distance constraint operation
38 class PartSet_DistanceSelection : public ModuleBase_SelectionValidator
39 {
40 public:
41   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
42                                       ModuleBase_Operation* theOperation) const;
43 };
44
45 //! \ingroup Validators
46 //! A class to validate a selection for Length constraint operation
47 class PartSet_LengthSelection : public ModuleBase_SelectionValidator
48 {
49 public:
50   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
51                                       ModuleBase_Operation* theOperation) const;
52 };
53
54 //! \ingroup Validators
55 //! A class to validate a selection for Perpendicular constraint operation
56 class PartSet_PerpendicularSelection : public ModuleBase_SelectionValidator
57 {
58 public:
59   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
60                                       ModuleBase_Operation* theOperation) const;
61 };
62
63 //! \ingroup Validators
64 //! A class to validate a selection for Parallel constraint operation
65 class PartSet_ParallelSelection : public ModuleBase_SelectionValidator
66 {
67 public:
68   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
69                                       ModuleBase_Operation* theOperation) const;
70 };
71
72 //! \ingroup Validators
73 //! A class to validate a selection for Radius constraint operation
74 class PartSet_RadiusSelection : public ModuleBase_SelectionValidator
75 {
76 public:
77   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
78                                       ModuleBase_Operation* theOperation) const;
79 };
80
81 //! \ingroup Validators
82 //! A class to validate a selection for Rigid constraint operation
83 class PartSet_RigidSelection : public ModuleBase_SelectionValidator
84 {
85 public:
86   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
87                                       ModuleBase_Operation* theOperation) const;
88 };
89
90
91 //! \ingroup Validators
92 //! A class to validate a selection for coincedence constraint operation
93 class PartSet_CoincidentSelection : public ModuleBase_SelectionValidator
94 {
95 public:
96   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
97                                       ModuleBase_Operation* theOperation) const;
98 };
99
100 //! \ingroup Validators
101 //! A class to validate a selection for Horizontal and Vertical constraints operation
102 class PartSet_HVDirSelection : public ModuleBase_SelectionValidator
103 {
104 public:
105   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
106                                       ModuleBase_Operation* theOperation) const;
107 };
108
109 //! \ingroup Validators
110 //! A class to validate a selection for Tangential constraints operation
111 class PartSet_TangentSelection : public ModuleBase_SelectionValidator
112 {
113 public:
114   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
115                                       ModuleBase_Operation* theOperation) const;
116 };
117
118 //! \ingroup Validators
119 //! A class to validate a selection for Fillet constraints operation
120 class PartSet_FilletSelection : public ModuleBase_SelectionValidator
121 {
122 public:
123   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
124                                       ModuleBase_Operation* theOperation) const;
125 };
126
127 //! \ingroup Validators
128 //! A class to validate a selection for Angle constraints operation
129 class PartSet_AngleSelection : public ModuleBase_SelectionValidator
130 {
131 public:
132   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
133                                       ModuleBase_Operation* theOperation) const;
134 };
135
136 //! \ingroup Validators
137 //! A class to validate a selection for Equal constraints operation
138 class PartSet_EqualSelection : public ModuleBase_SelectionValidator
139 {
140 public:
141   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
142                                       ModuleBase_Operation* theOperation) const;
143 };
144
145 //! \ingroup Validators
146 //! A class to validate a selection for Collinear constraints operation
147 class PartSet_CollinearSelection : public ModuleBase_SelectionValidator
148 {
149 public:
150   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
151                                       ModuleBase_Operation* theOperation) const;
152 };
153
154 //! \ingroup Validators
155 //! A class to validate a selection for Middle point constraints operation
156 class PartSet_MiddlePointSelection : public ModuleBase_SelectionValidator
157 {
158 public:
159   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
160                                       ModuleBase_Operation* theOperation) const;
161 };
162
163 //! \ingroup Validators
164 //! A class to validate a selection for Middle point constraints operation
165 class PartSet_MultyTranslationSelection : public ModuleBase_SelectionValidator
166 {
167 public:
168   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
169                                       ModuleBase_Operation* theOperation) const;
170 };
171
172 //! \ingroup Validators
173 //! A class to validate a selection for Middle point constraints operation
174 class PartSet_SplitSelection : public ModuleBase_SelectionValidator
175 {
176 public:
177   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
178                                       ModuleBase_Operation* theOperation) const;
179 };
180
181 //! \ingroup Validators
182 //! A class to validate a selection for Middle point constraints operation
183 class PartSet_ProjectionSelection : public ModuleBase_SelectionValidator
184 {
185 public:
186   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
187                                       ModuleBase_Operation* theOperation) const;
188 };
189
190 //! \ingroup Validators
191 //! A class to validate a selection for intersection operation
192 class PartSet_IntersectionSelection : public ModuleBase_SelectionValidator
193 {
194 public:
195   PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection,
196                                       ModuleBase_Operation* theOperation) const;
197 };
198
199 ////////////// Attribute validators ////////////////
200
201
202 /**
203 * \ingroup Validators
204 * A validator which checks that objects selected for feature attributes are different (not the same)
205 */
206 class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
207 {
208   //! Validator possible error types
209   enum ErrorType {
210     EqualObjects,
211     EqualAttributes,
212     EqualShapes,
213     EmptyShapes
214   };
215  public:
216   //! Returns true if the attribute is good for the feature attribute
217   //! \param theAttribute an attribute
218   //! \param theArguments a list of arguments (names of attributes to check)
219   //! \param theError an output error string
220   virtual bool isValid(const AttributePtr& theAttribute,
221                        const std::list<std::string>& theArguments,
222                        Events_InfoMessage& theError) const;
223 private:
224   //! Returns error message for the error type
225   //! \param theType a type of error
226   //! \param thEqualObjectInfo an
227   std::string errorMessage(const PartSet_DifferentObjectsValidator::ErrorType& theType,
228                            const std::string& thEqualObject, const std::string& theFirstAttribute,
229                            const std::string& theSecondAttribute) const;
230
231 };
232
233 /**
234 * \ingroup Validators
235 * A validator which checks that Point2D selected for feature attributes are different (not the same)
236 * It iterates by the feature ModelAPI_AttributeRefAttr attributes, finds GeomDataAPI_Point2D attribute in
237 * value or attribute of the attributes and if the point of the given attribute is geometrical equal to
238 * a point of another attribute, returns false
239 */
240 class PartSet_DifferentPointsValidator : public ModelAPI_AttributeValidator
241 {
242  public:
243   //! Returns true if the attribute is good for the feature attribute
244   //! \param theAttribute an attribute
245   //! \param theArguments a list of arguments (names of attributes to check)
246   //! \param theError an output error string
247   virtual bool isValid(const AttributePtr& theAttribute,
248                        const std::list<std::string>& theArguments,
249                        Events_InfoMessage& theError) const;
250 private:
251   //! Finds Point2D attribute by reference attribute. It might be:
252   //! - COORD_ID attribute of SketchPlugin_Point if object
253   //! - Attribute casted to point if attribute
254   //! \param theAttribute an attribute
255   //! \return point 2d attribute or NULL
256   std::shared_ptr<GeomDataAPI_Point2D> getRefPointAttribute
257                       (const AttributePtr& theAttribute) const;
258 };
259
260
261 /**\class PartSet_CoincidentAttr
262  * \ingroup Validators
263  * \brief Validator to check whether there is a coincident constraint between
264  * the attribute and attribute of argument.
265  */
266 class PartSet_CoincidentAttr : public ModelAPI_AttributeValidator
267 {
268  public:
269   //! returns true if attribute is valid
270   //! \param theAttribute the checked attribute
271   //! \param theArguments arguments of the attribute
272   //! \param theError an output error string
273   virtual bool isValid(const AttributePtr& theAttribute,
274                        const std::list<std::string>& theArguments,
275                        Events_InfoMessage& theError) const;
276 };
277
278
279 #endif