Salome HOME
3cb49701fed6bbc61b0584856d79893572982978
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.h
1 // Copyright (C) 2014-2021  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_Validators_H
21 #define SketchPlugin_Validators_H
22
23 #include "SketchPlugin.h"
24 #include <ModelAPI_AttributeValidator.h>
25 #include <ModelAPI_FeatureValidator.h>
26
27 /**\class SketchPlugin_DistanceAttrValidator
28  * \ingroup Validators
29  * \brief Validator for the distance input.
30  *
31  * It just checks that distance is greater than zero.
32  */
33 class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
34 {
35  public:
36   //! returns true if attribute is valid
37   //! \param theAttribute the checked attribute
38   //! \param theArguments arguments of the attribute
39   //! \param theError error message
40   virtual bool isValid(const AttributePtr& theAttribute,
41                        const std::list<std::string>& theArguments,
42                        Events_InfoMessage& theError) const;
43 };
44
45 /**\class SketchPlugin_TangentAttrValidator
46  * \ingroup Validators
47  * \brief Validator for the tangent constraint input.
48  *
49  * It just checks that distance is greater than zero.
50  */
51 class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator
52 {
53  public:
54   //! returns true if attribute is valid
55   //! \param theAttribute the checked attribute
56   //! \param theArguments arguments of the attribute
57   //! \param theError error message
58   virtual bool isValid(const AttributePtr& theAttribute,
59                        const std::list<std::string>& theArguments,
60                        Events_InfoMessage& theError) const;
61 };
62
63 /**\class SketchPlugin_PerpendicularAttrValidator
64  * \ingroup Validators
65  * \brief Validator for the perpendicular constraint input.
66  *
67  * Checks that two arcs are not selected for perpendicular.
68  */
69 class SketchPlugin_PerpendicularAttrValidator : public ModelAPI_AttributeValidator
70 {
71  public:
72   //! returns true if attribute is valid
73   //! \param theAttribute the checked attribute
74   //! \param theArguments arguments of the attribute
75   //! \param theError error message
76   virtual bool isValid(const AttributePtr& theAttribute,
77                        const std::list<std::string>& theArguments,
78                        Events_InfoMessage& theError) const;
79 };
80
81
82 /**\class SketchPlugin_NotFixedValidator
83  * \ingroup Validators
84  * \brief Validator for the rigid constraint input.
85  *
86  * It just checks there is no rigid constraint for the current feature.
87  */
88 class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator
89 {
90  public:
91   //! returns true if attribute is not used in another rigid constraint
92   //! \param theAttribute the checked attribute
93   //! \param theArguments arguments of the attribute
94   //! \param theError error message
95   virtual bool isValid(const AttributePtr& theAttribute,
96                        const std::list<std::string>& theArguments,
97                        Events_InfoMessage& theError) const;
98 };
99
100 /**\class SketchPlugin_EqualAttrValidator
101  * \ingroup Validators
102  * \brief Validator for the equal constraint input.
103  *
104  * It checks that attributes of the Equal constraint are correct.
105  */
106 class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator
107 {
108  public:
109   //! returns true if attribute is valid
110   //! \param theAttribute the checked attribute
111   //! \param theArguments arguments of the attribute
112   //! \param theError error message
113   virtual bool isValid(const AttributePtr& theAttribute,
114                        const std::list<std::string>& theArguments,
115                        Events_InfoMessage& theError) const;
116 };
117
118 /**\class SketchPlugin_MirrorAttrValidator
119  * \ingroup Validators
120  * \brief Validator for the mirror constraint input.
121  *
122  * It checks that attributes of the Mirror constraint are correct.
123  */
124 class SketchPlugin_MirrorAttrValidator : public ModelAPI_AttributeValidator
125 {
126  public:
127   //! returns true if attribute is valid
128   //! \param theAttribute the checked attribute
129   //! \param theArguments arguments of the attribute (not used)
130   //! \param theError error message
131   virtual bool isValid(const AttributePtr& theAttribute,
132                        const std::list<std::string>& theArguments,
133                        Events_InfoMessage& theError) const;
134 };
135
136
137 /**\class SketchPlugin_CoincidenceAttrValidator
138  * \ingroup Validators
139  * \brief Validator for the coincidence constraint input.
140  *
141  * It checks that attributes of the Coincidence constraint are correct.
142  */
143 class SketchPlugin_CoincidenceAttrValidator : public ModelAPI_AttributeValidator
144 {
145  public:
146   //! returns true if attribute is valid
147   //! \param theAttribute the checked attribute
148   //! \param theArguments arguments of the attribute (not used)
149   //! \param theError error message
150   virtual bool isValid(const AttributePtr& theAttribute,
151                        const std::list<std::string>& theArguments,
152                        Events_InfoMessage& theError) const;
153 };
154
155
156 /**\class SketchPlugin_CopyValidator
157  * \ingroup Validators
158  * \brief Validator for the constraints which create features.
159  *
160  * Applicable only for features, which creates another features. It verifies the produced
161  * features of current constraint don't become into the list of initial features
162  */
163 class SketchPlugin_CopyValidator : public ModelAPI_AttributeValidator
164 {
165  public:
166   //! returns true if attribute is valid
167   //! \param theAttribute the checked attribute
168   //! \param theArguments arguments of the attribute (not used)
169   //! \param theError error message
170   virtual bool isValid(const AttributePtr& theAttribute,
171                        const std::list<std::string>& theArguments,
172                        Events_InfoMessage& theError) const;
173 };
174
175 /**\class SketchPlugin_SolverErrorValidator
176  * \ingroup Validators
177  * \brief Validator for the solver error.
178  *
179  * Simply checks that solver error attribute is empty. Returns the attribute value as an error.
180  */
181 class SketchPlugin_SolverErrorValidator : public ModelAPI_FeatureValidator
182 {
183  public:
184   //! returns true if there are no solver errors
185   //! \param theFeature the checked feature
186   //! \param theArguments arguments of the feature (not used)
187   //! \param theError error message
188   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
189                        const std::list<std::string>& theArguments,
190                        Events_InfoMessage& theError) const;
191
192   /// Returns true if the attribute in feature is not obligatory for the feature execution
193   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
194 };
195
196 /**\class SketchPlugin_FilletVertexValidator
197  * \ingroup Validators
198  * \brief Validator for the point for fillet creation.
199  *
200  * Checks that selected point have exactly two coincident lines.
201  */
202 class SketchPlugin_FilletVertexValidator : public ModelAPI_AttributeValidator
203 {
204 public:
205   //! returns true if attribute is valid
206   //! \param theAttribute the checked attribute
207   //! \param theArguments arguments of the attribute (not used)
208   //! \param theError error message
209   virtual bool isValid(const AttributePtr& theAttribute,
210                        const std::list<std::string>& theArguments,
211                        Events_InfoMessage& theError) const;
212 };
213
214
215 /**\class SketchPlugin_MiddlePointAttrValidator
216  * \ingroup Validators
217  * \brief Validator for the middle point constraint input.
218  *
219  * It checks that attributes of the Middle point constraint are correct.
220  */
221 class SketchPlugin_MiddlePointAttrValidator : public ModelAPI_AttributeValidator
222 {
223  public:
224   //! returns true if attribute is valid
225   //! \param theAttribute the checked attribute
226   //! \param theArguments arguments of the attribute (not used)
227   //! \param theError error message
228   virtual bool isValid(const AttributePtr& theAttribute,
229                        const std::list<std::string>& theArguments,
230                        Events_InfoMessage& theError) const;
231 };
232
233
234 /**\class SketchPlugin_ArcTangentPointValidator
235  * \ingroup Validators
236  * \brief Validator for the point where the tangent arc is building.
237  *
238  * Checks that the point is a start or end point just on line or arc.
239  */
240 class SketchPlugin_ArcTangentPointValidator : public ModelAPI_AttributeValidator
241 {
242  public:
243   //! returns true if attribute is valid
244   //! \param theAttribute the checked attribute
245   //! \param theArguments arguments of the attribute
246   //! \param theError error message
247   virtual bool isValid(const AttributePtr& theAttribute,
248                        const std::list<std::string>& theArguments,
249                        Events_InfoMessage& theError) const;
250 };
251
252 /**\class SketchPlugin_ArcTransversalPointValidator
253  * \ingroup Validators
254  * \brief Validator for the point where the transversal arc is building.
255  *
256  * Checks that the point is a start or end point just on line or arc.
257  */
258 class SketchPlugin_ArcTransversalPointValidator : public ModelAPI_AttributeValidator
259 {
260  public:
261   //! returns true if attribute is valid
262   //! \param theAttribute the checked attribute
263   //! \param theArguments arguments of the attribute
264   //! \param theError error message
265   virtual bool isValid(const AttributePtr& theAttribute,
266                        const std::list<std::string>& theArguments,
267                        Events_InfoMessage& theError) const;
268 };
269
270
271 /**\class SketchPlugin_SplitValidator
272  * \ingroup Validators
273  * \brief Validator for the entity of the following type:
274  * - Linear segment with point(s) coinident to this line
275  * - Arc with point(s) coincident to the arc
276  * - Circle with at least 2 split-points on this circle
277  *
278  * Checks that there are coincident point on selected feature.
279  */
280 class SketchPlugin_SplitValidator : public ModelAPI_AttributeValidator
281 {
282  public:
283   //! returns true if attribute is valid
284   //! \param theAttribute the checked attribute
285   //! \param theArguments arguments of the attribute
286   //! \param theError error message
287   virtual bool isValid(const AttributePtr& theAttribute,
288                        const std::list<std::string>& theArguments,
289                        Events_InfoMessage& theError) const;
290 };
291
292 /**\class SketchPlugin_TrimValidator
293  * \ingroup Validators
294  * \brief Validator for the entity of the following type:
295  * - Linear segment with point(s) coinident to this line or intersected it
296  * - Arc with point(s) coincident to the arc or intersected it
297  * - Circle with at least 2 split-points on this circle or intersected it
298  *
299  * Checks that there are coincident point on selected feature.
300  */
301 class SketchPlugin_TrimValidator : public ModelAPI_AttributeValidator
302 {
303  public:
304   //! returns true if attribute is valid
305   //! \param theAttribute the checked attribute
306   //! \param theArguments arguments of the attribute
307   //! \param theError error message
308   virtual bool isValid(const AttributePtr& theAttribute,
309                        const std::list<std::string>& theArguments,
310                        Events_InfoMessage& theError) const;
311 };
312
313 /**\class SketchPlugin_IntersectionValidator
314  * \ingroup Validators
315  * \brief Validator for the attribute to be intersected with the sketch plane.
316  */
317 class SketchPlugin_IntersectionValidator : public ModelAPI_AttributeValidator
318 {
319  public:
320   //! returns true if attribute is valid
321   //! \param theAttribute the checked attribute
322   //! \param theArguments arguments of the attribute
323   //! \param theError error message
324   virtual bool isValid(const AttributePtr& theAttribute,
325                        const std::list<std::string>& theArguments,
326                        Events_InfoMessage& theError) const;
327 };
328
329 /**\class SketchPlugin_ProjectionValidator
330  * \ingroup Validators
331  * \brief Validator for the attribute to be projected onto the sketch plane.
332  */
333 class SketchPlugin_ProjectionValidator : public ModelAPI_AttributeValidator
334 {
335  public:
336   //! returns true if attribute is valid
337   //! \param theAttribute the checked attribute
338   //! \param theArguments arguments of the attribute
339   //! \param theError error message
340   virtual bool isValid(const AttributePtr& theAttribute,
341                        const std::list<std::string>& theArguments,
342                        Events_InfoMessage& theError) const;
343 };
344
345 /**\class SketchPlugin_DifferentReferenceValidator
346  * \ingroup Validators
347  * \brief Validator for attributes of a sketch feature.
348  *
349  * It checks that at least one of specified attributes
350  * refers to another feature in respect to each other.
351  */
352 class SketchPlugin_DifferentReferenceValidator : 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>& theArguments,
361                        Events_InfoMessage& theError) const;
362 };
363
364 /**\class SketchPlugin_DifferentPointReferenceValidator
365  * \ingroup Validators
366  * \brief Validator for attributes of a sketch feature.
367  *
368  * It checks that at least two of specified attributes refer to different points.
369  */
370 class SketchPlugin_DifferentPointReferenceValidator : public ModelAPI_AttributeValidator
371 {
372  public:
373   //! returns true if attribute is valid
374   //! \param theAttribute the checked attribute
375   //! \param theArguments arguments of the attribute
376   //! \param theError error message
377   virtual bool isValid(const AttributePtr& theAttribute,
378                        const std::list<std::string>& theArguments,
379                        Events_InfoMessage& theError) const;
380 };
381
382 /**\class SketchPlugin_CirclePassedPointValidator
383  * \ingroup Validators
384  * \brief Validator for passed point of MacroCircle feature.
385  *
386  * Checks that passed point does not refer to the feature, the center is coincident to.
387  */
388 class SketchPlugin_CirclePassedPointValidator : public ModelAPI_AttributeValidator
389 {
390  public:
391   //! returns true if attribute is valid
392   //! \param theAttribute the checked attribute
393   //! \param theArguments arguments of the attribute
394   //! \param theError error message
395   virtual bool isValid(const AttributePtr& theAttribute,
396                        const std::list<std::string>&,
397                        Events_InfoMessage& theError) const;
398 };
399
400 /**\class SketchPlugin_ThirdPointValidator
401  * \ingroup Validators
402  * \brief Validator for the third point of MacroCircle feature.
403  *
404  * Checks that third point does not lie on a line passed through the first two points.
405  * Checks that third point does not refer to feature lying between the first two points.
406  */
407 class SketchPlugin_ThirdPointValidator : public ModelAPI_AttributeValidator
408 {
409  public:
410   //! returns true if attribute is valid
411   //! \param theAttribute the checked attribute
412   //! \param theArguments arguments of the attribute
413   //! \param theError error message
414   virtual bool isValid(const AttributePtr& theAttribute,
415                        const std::list<std::string>& theArguments,
416                        Events_InfoMessage& theError) const;
417
418 private:
419   //! returns true if three points have not been placed on the same line
420   bool arePointsNotOnLine(const FeaturePtr& theMacroFeature,
421                           Events_InfoMessage& theError) const;
422
423   //! returns true if the first two points have not been separated
424   //! by a feature referred by thrid point
425   bool arePointsNotSeparated(const FeaturePtr& theMacroFeature,
426                              const std::list<std::string>& theArguments,
427                              Events_InfoMessage& theError) const;
428 };
429
430 /**\class SketchPlugin_ArcEndPointValidator
431  * \ingroup Validators
432  * \brief Validator for the end point of MacroArc feature.
433  *
434  * Checks that third point does not lie on a point.
435  */
436 class SketchPlugin_ArcEndPointValidator: public ModelAPI_AttributeValidator
437 {
438  public:
439   //! returns true if attribute is valid
440   //! \param theAttribute the checked attribute
441   //! \param theArguments arguments of the attribute
442   //! \param theError error message
443   virtual bool isValid(const AttributePtr& theAttribute,
444                        const std::list<std::string>& theArguments,
445                        Events_InfoMessage& theError) const;
446 };
447
448 /**\class SketchPlugin_ArcEndPointIntersectionValidator
449  * \ingroup Validators
450  * \brief Validator for the end point of MacroArc feature.
451  *
452  * Checks that third point does lie on edge which intersects arc.
453  */
454 class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeValidator
455 {
456  public:
457   //! returns true if attribute is valid
458   //! \param theAttribute the checked attribute
459   //! \param theArguments arguments of the attribute
460   //! \param theError error message
461   virtual bool isValid(const AttributePtr& theAttribute,
462                        const std::list<std::string>& theArguments,
463                        Events_InfoMessage& theError) const;
464 };
465
466 /**\class SketchPlugin_HasNoConstraint
467  * \ingroup Validators
468  * \brief Validator for checking whether the feature has constraint.
469  *
470  * Checks that feature of the attribute does not have constraint with some kinds.
471  * The kinds of constraints should be described in parameters of the validator
472  * Validator processes the ModelAPI_AttributeRefAttr attribute kind
473  */
474 class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator
475 {
476  public:
477   //! returns true if attribute is valid
478   //! \param theAttribute the checked attribute
479   //! \param theArguments arguments of the attribute
480   //! \param theError error message
481   virtual bool isValid(const AttributePtr& theAttribute,
482                        const std::list<std::string>& theArguments,
483                        Events_InfoMessage& theError) const;
484 };
485
486 /**\class SketchPlugin_ReplicationReferenceValidator
487  * \ingroup Validators
488  * \brief Validator checking that the replications features (Mirror,
489  *        Multi-Rotation, Mutli-Translation) do not refer to the shapes they produce.
490  */
491 class SketchPlugin_ReplicationReferenceValidator: public ModelAPI_AttributeValidator
492 {
493  public:
494   //! returns true if attribute is valid
495   //! \param theAttribute the checked attribute
496   //! \param theArguments arguments of the attribute
497   //! \param theError error message
498   virtual bool isValid(const AttributePtr& theAttribute,
499                        const std::list<std::string>& theArguments,
500                        Events_InfoMessage& theError) const;
501 };
502
503 /**\class SketchPlugin_SketchFeatureValidator
504  * \ingroup Validators
505  * \brief Validator for checking whether the feature referred by attribute is a sketch feature.
506  */
507 class SketchPlugin_SketchFeatureValidator: public ModelAPI_AttributeValidator
508 {
509  public:
510   //! returns true if attribute is valid
511   //! \param theAttribute the checked attribute
512   //! \param theArguments arguments of the attribute
513   //! \param theError error message
514   virtual bool isValid(const AttributePtr& theAttribute,
515                        const std::list<std::string>& theArguments,
516                        Events_InfoMessage& theError) const;
517 };
518
519 /**\class SketchPlugin_MultiRotationAngleValidator
520  * \ingroup Validators
521  * \brief Validator for checking whether the angle of MultiRotation is in range [0, 360].
522  */
523 class SketchPlugin_MultiRotationAngleValidator : public ModelAPI_AttributeValidator
524 {
525   //! returns true if attribute is valid
526   //! \param theAttribute the checked attribute
527   //! \param theArguments arguments of the attribute
528   //! \param theError error message
529   virtual bool isValid(const AttributePtr& theAttribute,
530                        const std::list<std::string>& theArguments,
531                        Events_InfoMessage& theError) const;
532 };
533
534 /**\class SketchPlugin_BSplineValidator
535  * \ingroup Validators
536  * \brief Validator for checking poles/weights of B-spline curve.
537  */
538 class SketchPlugin_BSplineValidator : public ModelAPI_AttributeValidator
539 {
540   //! returns true if attribute is valid
541   //! \param theAttribute the checked attribute
542   //! \param theArguments arguments of the attribute
543   //! \param theError error message
544   virtual bool isValid(const AttributePtr& theAttribute,
545                        const std::list<std::string>& theArguments,
546                        Events_InfoMessage& theError) const;
547 };
548
549 /**\class SketchPlugin_CurveFittingValidator
550  * \ingroup Validators
551  * \brief Validator for the selected vertices for the curve fitting feature.
552  */
553 class SketchPlugin_CurveFittingValidator : public ModelAPI_FeatureValidator
554 {
555 public:
556   //! returns true if number of selected points is greater than the minimal value
557   //! \param theAttribute the checked attribute
558   //! \param theArguments arguments of the attribute
559   //! \param theError error message
560   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
561                        const std::list<std::string>& theArguments,
562                        Events_InfoMessage& theError) const;
563 };
564
565 #endif