Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.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 SketchPlugin_Validators_H
22 #define SketchPlugin_Validators_H
23
24 #include "SketchPlugin.h"
25 #include <ModelAPI_AttributeValidator.h>
26 #include <ModelAPI_FeatureValidator.h>
27
28 /**\class SketchPlugin_DistanceAttrValidator
29  * \ingroup Validators
30  * \brief Validator for the distance input.
31  *
32  * It just checks that distance is greater than zero.
33  */
34 class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
35 {
36  public:
37   //! returns true if attribute is valid
38   //! \param theAttribute the checked attribute
39   //! \param theArguments arguments of the attribute
40   //! \param theError error message
41   virtual bool isValid(const AttributePtr& theAttribute,
42                        const std::list<std::string>& theArguments,
43                        Events_InfoMessage& theError) const;
44 };
45
46 /**\class SketchPlugin_TangentAttrValidator
47  * \ingroup Validators
48  * \brief Validator for the tangent constraint input.
49  *
50  * It just checks that distance is greater than zero.
51  */
52 class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator
53 {
54  public:
55   //! returns true if attribute is valid
56   //! \param theAttribute the checked attribute
57   //! \param theArguments arguments of the attribute
58   //! \param theError error message
59   virtual bool isValid(const AttributePtr& theAttribute,
60                        const std::list<std::string>& theArguments,
61                        Events_InfoMessage& theError) const;
62 };
63
64
65 /**\class SketchPlugin_NotFixedValidator
66  * \ingroup Validators
67  * \brief Validator for the rigid constraint input.
68  *
69  * It just checks there is no rigid constraint for the current feature.
70  */
71 class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator
72 {
73  public:
74   //! returns true if attribute is not used in another rigid constraint
75   //! \param theAttribute the checked attribute
76   //! \param theArguments arguments of the attribute
77   //! \param theError error message
78   virtual bool isValid(const AttributePtr& theAttribute,
79                        const std::list<std::string>& theArguments,
80                        Events_InfoMessage& theError) const;
81 };
82
83 /**\class SketchPlugin_EqualAttrValidator
84  * \ingroup Validators
85  * \brief Validator for the equal constraint input.
86  *
87  * It checks that attributes of the Equal constraint are correct.
88  */
89 class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator
90 {
91  public:
92   //! returns true if attribute is valid
93   //! \param theAttribute the checked attribute
94   //! \param theArguments arguments of the attribute
95   //! \param theError error message
96   virtual bool isValid(const AttributePtr& theAttribute,
97                        const std::list<std::string>& theArguments,
98                        Events_InfoMessage& theError) const;
99 };
100
101 /**\class SketchPlugin_MirrorAttrValidator
102  * \ingroup Validators
103  * \brief Validator for the mirror constraint input.
104  *
105  * It checks that attributes of the Mirror constraint are correct.
106  */
107 class SketchPlugin_MirrorAttrValidator : public ModelAPI_AttributeValidator
108 {
109  public:
110   //! returns true if attribute is valid
111   //! \param theAttribute the checked attribute
112   //! \param theArguments arguments of the attribute (not used)
113   //! \param theError error message
114   virtual bool isValid(const AttributePtr& theAttribute,
115                        const std::list<std::string>& theArguments,
116                        Events_InfoMessage& theError) const;
117 };
118
119
120 /**\class SketchPlugin_CoincidenceAttrValidator
121  * \ingroup Validators
122  * \brief Validator for the coincidence constraint input.
123  *
124  * It checks that attributes of the Coincidence constraint are correct.
125  */
126 class SketchPlugin_CoincidenceAttrValidator : public ModelAPI_AttributeValidator
127 {
128  public:
129   //! returns true if attribute is valid
130   //! \param theAttribute the checked attribute
131   //! \param theArguments arguments of the attribute (not used)
132   //! \param theError error message
133   virtual bool isValid(const AttributePtr& theAttribute,
134                        const std::list<std::string>& theArguments,
135                        Events_InfoMessage& theError) const;
136 };
137
138
139 /**\class SketchPlugin_CopyValidator
140  * \ingroup Validators
141  * \brief Validator for the constraints which create features.
142  *
143  * Applicable only for features, which creates another features. It verifies the produced
144  * features of current constraint don't become into the list of initial features
145  */
146 class SketchPlugin_CopyValidator : public ModelAPI_AttributeValidator
147 {
148  public:
149   //! returns true if attribute is valid
150   //! \param theAttribute the checked attribute
151   //! \param theArguments arguments of the attribute (not used)
152   //! \param theError error message
153   virtual bool isValid(const AttributePtr& theAttribute,
154                        const std::list<std::string>& theArguments,
155                        Events_InfoMessage& theError) const;
156 };
157
158 /**\class SketchPlugin_SolverErrorValidator
159  * \ingroup Validators
160  * \brief Validator for the solver error.
161  *
162  * Simply checks that solver error attribute is empty. Returns the attribute value as an error.
163  */
164 class SketchPlugin_SolverErrorValidator : public ModelAPI_FeatureValidator
165 {
166  public:
167   //! returns true if there are no solver errors
168   //! \param theFeature the checked feature
169   //! \param theArguments arguments of the feature (not used)
170   //! \param theError error message
171   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
172                        const std::list<std::string>& theArguments,
173                        Events_InfoMessage& theError) const;
174
175   /// Returns true if the attribute in feature is not obligatory for the feature execution
176   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
177 };
178
179 /**\class SketchPlugin_FilletVertexValidator
180  * \ingroup Validators
181  * \brief Validator for the point for fillet creation.
182  *
183  * Checks that selected point have exactly two coincident lines.
184  */
185 class SketchPlugin_FilletVertexValidator : public ModelAPI_AttributeValidator
186 {
187 public:
188   //! returns true if attribute is valid
189   //! \param theAttribute the checked attribute
190   //! \param theArguments arguments of the attribute (not used)
191   //! \param theError error message
192   virtual bool isValid(const AttributePtr& theAttribute,
193                        const std::list<std::string>& theArguments,
194                        Events_InfoMessage& theError) const;
195 };
196
197
198 /**\class SketchPlugin_MiddlePointAttrValidator
199  * \ingroup Validators
200  * \brief Validator for the middle point constraint input.
201  *
202  * It checks that attributes of the Middle point constraint are correct.
203  */
204 class SketchPlugin_MiddlePointAttrValidator : public ModelAPI_AttributeValidator
205 {
206  public:
207   //! returns true if attribute is valid
208   //! \param theAttribute the checked attribute
209   //! \param theArguments arguments of the attribute (not used)
210   //! \param theError error message
211   virtual bool isValid(const AttributePtr& theAttribute,
212                        const std::list<std::string>& theArguments,
213                        Events_InfoMessage& theError) const;
214 };
215
216
217 /**\class SketchPlugin_ArcTangentPointValidator
218  * \ingroup Validators
219  * \brief Validator for the point where the tangent arc is building.
220  *
221  * Checks that the point is a start or end point just on line or arc.
222  */
223 class SketchPlugin_ArcTangentPointValidator : public ModelAPI_AttributeValidator
224 {
225  public:
226   //! returns true if attribute is valid
227   //! \param theAttribute the checked attribute
228   //! \param theArguments arguments of the attribute
229   //! \param theError error message
230   virtual bool isValid(const AttributePtr& theAttribute,
231                        const std::list<std::string>& theArguments,
232                        Events_InfoMessage& theError) const;
233 };
234
235 /**\class SketchPlugin_SplitValidator
236  * \ingroup Validators
237  * \brief Validator for the entity of the following type:
238  * - Linear segment with point(s) coinident to this line
239  * - Arc with point(s) coincident to the arc
240  * - Circle with at least 2 split-points on this circle
241  *
242  * Checks that there are coincident point on selected feature.
243  */
244 class SketchPlugin_SplitValidator : public ModelAPI_AttributeValidator
245 {
246  public:
247   //! returns true if attribute is valid
248   //! \param theAttribute the checked attribute
249   //! \param theArguments arguments of the attribute
250   //! \param theError error message
251   virtual bool isValid(const AttributePtr& theAttribute,
252                        const std::list<std::string>& theArguments,
253                        Events_InfoMessage& theError) const;
254 };
255
256 /**\class SketchPlugin_TrimValidator
257  * \ingroup Validators
258  * \brief Validator for the entity of the following type:
259  * - Linear segment with point(s) coinident to this line or intersected it
260  * - Arc with point(s) coincident to the arc or intersected it
261  * - Circle with at least 2 split-points on this circle or intersected it
262  *
263  * Checks that there are coincident point on selected feature.
264  */
265 class SketchPlugin_TrimValidator : public ModelAPI_AttributeValidator
266 {
267  public:
268   //! returns true if attribute is valid
269   //! \param theAttribute the checked attribute
270   //! \param theArguments arguments of the attribute
271   //! \param theError error message
272   virtual bool isValid(const AttributePtr& theAttribute,
273                        const std::list<std::string>& theArguments,
274                        Events_InfoMessage& theError) const;
275 };
276
277 /**\class SketchPlugin_IntersectionValidator
278  * \ingroup Validators
279  * \brief Validator for the attribute to be intersected with the sketch plane.
280  */
281 class SketchPlugin_IntersectionValidator : public ModelAPI_AttributeValidator
282 {
283  public:
284   //! returns true if attribute is valid
285   //! \param theAttribute the checked attribute
286   //! \param theArguments arguments of the attribute
287   //! \param theError error message
288   virtual bool isValid(const AttributePtr& theAttribute,
289                        const std::list<std::string>& theArguments,
290                        Events_InfoMessage& theError) const;
291 };
292
293 /**\class SketchPlugin_ProjectionValidator
294  * \ingroup Validators
295  * \brief Validator for the attribute to be projected onto the sketch plane.
296  */
297 class SketchPlugin_ProjectionValidator : public ModelAPI_AttributeValidator
298 {
299  public:
300   //! returns true if attribute is valid
301   //! \param theAttribute the checked attribute
302   //! \param theArguments arguments of the attribute
303   //! \param theError error message
304   virtual bool isValid(const AttributePtr& theAttribute,
305                        const std::list<std::string>& theArguments,
306                        Events_InfoMessage& theError) const;
307 };
308
309 /**\class SketchPlugin_DifferentReferenceValidator
310  * \ingroup Validators
311  * \brief Validator for attributes of a sketch feature.
312  *
313  * It checks that at least one of specified attributes
314  * refers to another feature in respect to each other.
315  */
316 class SketchPlugin_DifferentReferenceValidator : public ModelAPI_AttributeValidator
317 {
318  public:
319   //! returns true if attribute is valid
320   //! \param theAttribute the checked attribute
321   //! \param theArguments arguments of the attribute
322   //! \param theError error message
323   virtual bool isValid(const AttributePtr& theAttribute,
324                        const std::list<std::string>& theArguments,
325                        Events_InfoMessage& theError) const;
326 };
327
328 /**\class SketchPlugin_DifferentPointReferenceValidator
329  * \ingroup Validators
330  * \brief Validator for attributes of a sketch feature.
331  *
332  * It checks that at least two of specified attributes refer to different points.
333  */
334 class SketchPlugin_DifferentPointReferenceValidator : public ModelAPI_AttributeValidator
335 {
336  public:
337   //! returns true if attribute is valid
338   //! \param theAttribute the checked attribute
339   //! \param theArguments arguments of the attribute
340   //! \param theError error message
341   virtual bool isValid(const AttributePtr& theAttribute,
342                        const std::list<std::string>& theArguments,
343                        Events_InfoMessage& theError) const;
344 };
345
346 /**\class SketchPlugin_CirclePassedPointValidator
347  * \ingroup Validators
348  * \brief Validator for passed point of MacroCircle feature.
349  *
350  * Checks that passed point does not refer to the feature, the center is coincident to.
351  */
352 class SketchPlugin_CirclePassedPointValidator : public ModelAPI_AttributeValidator
353 {
354  public:
355   //! returns true if attribute is valid
356   //! \param theAttribute the checked attribute
357   //! \param theArguments arguments of the attribute
358   //! \param theError error message
359   virtual bool isValid(const AttributePtr& theAttribute,
360                        const std::list<std::string>&,
361                        Events_InfoMessage& theError) const;
362 };
363
364 /**\class SketchPlugin_ThirdPointValidator
365  * \ingroup Validators
366  * \brief Validator for the third point of MacroCircle feature.
367  *
368  * Checks that third point does not lie on a line passed through the first two points.
369  * Checks that third point does not refer to feature lying between the first two points.
370  */
371 class SketchPlugin_ThirdPointValidator : public ModelAPI_AttributeValidator
372 {
373  public:
374   //! returns true if attribute is valid
375   //! \param theAttribute the checked attribute
376   //! \param theArguments arguments of the attribute
377   //! \param theError error message
378   virtual bool isValid(const AttributePtr& theAttribute,
379                        const std::list<std::string>& theArguments,
380                        Events_InfoMessage& theError) const;
381
382 private:
383   //! returns true if three points have not been placed on the same line
384   bool arePointsNotOnLine(const FeaturePtr& theMacroFeature,
385                           Events_InfoMessage& theError) const;
386
387   //! returns true if the first two points have not been separated
388   //! by a feature referred by thrid point
389   bool arePointsNotSeparated(const FeaturePtr& theMacroFeature,
390                              const std::list<std::string>& theArguments,
391                              Events_InfoMessage& theError) const;
392 };
393
394 /**\class SketchPlugin_ArcEndPointValidator
395  * \ingroup Validators
396  * \brief Validator for the end point of MacroArc feature.
397  *
398  * Checks that third point does not lie on a point.
399  */
400 class SketchPlugin_ArcEndPointValidator: public ModelAPI_AttributeValidator
401 {
402  public:
403   //! returns true if attribute is valid
404   //! \param theAttribute the checked attribute
405   //! \param theArguments arguments of the attribute
406   //! \param theError error message
407   virtual bool isValid(const AttributePtr& theAttribute,
408                        const std::list<std::string>& theArguments,
409                        Events_InfoMessage& theError) const;
410 };
411
412 /**\class SketchPlugin_ArcEndPointIntersectionValidator
413  * \ingroup Validators
414  * \brief Validator for the end point of MacroArc feature.
415  *
416  * Checks that third point does lie on edge which intersects arc.
417  */
418 class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeValidator
419 {
420  public:
421   //! returns true if attribute is valid
422   //! \param theAttribute the checked attribute
423   //! \param theArguments arguments of the attribute
424   //! \param theError error message
425   virtual bool isValid(const AttributePtr& theAttribute,
426                        const std::list<std::string>& theArguments,
427                        Events_InfoMessage& theError) const;
428 };
429
430 /**\class SketchPlugin_HasNoConstraint
431  * \ingroup Validators
432  * \brief Validator for checking whether the feature has constraint.
433  *
434  * Checks that feature of the attribute does not have constraint with some kinds.
435  * The kinds of constraints should be described in parameters of the validator
436  * Validator processes the ModelAPI_AttributeRefAttr attribute kind
437  */
438 class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator
439 {
440  public:
441   //! returns true if attribute is valid
442   //! \param theAttribute the checked attribute
443   //! \param theArguments arguments of the attribute
444   //! \param theError error message
445   virtual bool isValid(const AttributePtr& theAttribute,
446                        const std::list<std::string>& theArguments,
447                        Events_InfoMessage& theError) const;
448 };
449
450 #endif