Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_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 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   //! returns true if attribute is a good point for fillet
214   //! \param theAttribute the checked point attribute
215   //! \param theError error message
216   //! \param theEdge1 adjacent edge feature
217   //! \param theEdge2 adjacent edge feature
218   static bool isValidVertex(const AttributePtr& theAttribute,
219                             Events_InfoMessage& theError,
220                             FeaturePtr&         theEdge1,
221                             FeaturePtr&         theEdge2);
222 };
223
224
225 /**\class SketchPlugin_MiddlePointAttrValidator
226  * \ingroup Validators
227  * \brief Validator for the middle point constraint input.
228  *
229  * It checks that attributes of the Middle point constraint are correct.
230  */
231 class SketchPlugin_MiddlePointAttrValidator : public ModelAPI_AttributeValidator
232 {
233  public:
234   //! returns true if attribute is valid
235   //! \param theAttribute the checked attribute
236   //! \param theArguments arguments of the attribute (not used)
237   //! \param theError error message
238   virtual bool isValid(const AttributePtr& theAttribute,
239                        const std::list<std::string>& theArguments,
240                        Events_InfoMessage& theError) const;
241 };
242
243
244 /**\class SketchPlugin_ArcTangentPointValidator
245  * \ingroup Validators
246  * \brief Validator for the point where the tangent arc is building.
247  *
248  * Checks that the point is a start or end point just on line or arc.
249  */
250 class SketchPlugin_ArcTangentPointValidator : public ModelAPI_AttributeValidator
251 {
252  public:
253   //! returns true if attribute is valid
254   //! \param theAttribute the checked attribute
255   //! \param theArguments arguments of the attribute
256   //! \param theError error message
257   virtual bool isValid(const AttributePtr& theAttribute,
258                        const std::list<std::string>& theArguments,
259                        Events_InfoMessage& theError) const;
260 };
261
262 /**\class SketchPlugin_ArcTransversalPointValidator
263  * \ingroup Validators
264  * \brief Validator for the point where the transversal arc is building.
265  *
266  * Checks that the point is a start or end point just on line or arc.
267  */
268 class SketchPlugin_ArcTransversalPointValidator : public ModelAPI_AttributeValidator
269 {
270  public:
271   //! returns true if attribute is valid
272   //! \param theAttribute the checked attribute
273   //! \param theArguments arguments of the attribute
274   //! \param theError error message
275   virtual bool isValid(const AttributePtr& theAttribute,
276                        const std::list<std::string>& theArguments,
277                        Events_InfoMessage& theError) const;
278 };
279
280
281 /**\class SketchPlugin_SplitValidator
282  * \ingroup Validators
283  * \brief Validator for the entity of the following type:
284  * - Linear segment with point(s) coinident to this line
285  * - Arc with point(s) coincident to the arc
286  * - Circle with at least 2 split-points on this circle
287  *
288  * Checks that there are coincident point on selected feature.
289  */
290 class SketchPlugin_SplitValidator : public ModelAPI_AttributeValidator
291 {
292  public:
293   //! returns true if attribute is valid
294   //! \param theAttribute the checked attribute
295   //! \param theArguments arguments of the attribute
296   //! \param theError error message
297   virtual bool isValid(const AttributePtr& theAttribute,
298                        const std::list<std::string>& theArguments,
299                        Events_InfoMessage& theError) const;
300 };
301
302 /**\class SketchPlugin_TrimValidator
303  * \ingroup Validators
304  * \brief Validator for the entity of the following type:
305  * - Linear segment with point(s) coinident to this line or intersected it
306  * - Arc with point(s) coincident to the arc or intersected it
307  * - Circle with at least 2 split-points on this circle or intersected it
308  *
309  * Checks that there are coincident point on selected feature.
310  */
311 class SketchPlugin_TrimValidator : public ModelAPI_AttributeValidator
312 {
313  public:
314   //! returns true if attribute is valid
315   //! \param theAttribute the checked attribute
316   //! \param theArguments arguments of the attribute
317   //! \param theError error message
318   virtual bool isValid(const AttributePtr& theAttribute,
319                        const std::list<std::string>& theArguments,
320                        Events_InfoMessage& theError) const;
321 };
322
323 /**\class SketchPlugin_IntersectionValidator
324  * \ingroup Validators
325  * \brief Validator for the attribute to be intersected with the sketch plane.
326  */
327 class SketchPlugin_IntersectionValidator : public ModelAPI_AttributeValidator
328 {
329  public:
330   //! returns true if attribute is valid
331   //! \param theAttribute the checked attribute
332   //! \param theArguments arguments of the attribute
333   //! \param theError error message
334   virtual bool isValid(const AttributePtr& theAttribute,
335                        const std::list<std::string>& theArguments,
336                        Events_InfoMessage& theError) const;
337 };
338
339 /**\class SketchPlugin_ProjectionValidator
340  * \ingroup Validators
341  * \brief Validator for the attribute to be projected onto the sketch plane.
342  */
343 class SketchPlugin_ProjectionValidator : public ModelAPI_AttributeValidator
344 {
345  public:
346   //! returns true if attribute is valid
347   //! \param theAttribute the checked attribute
348   //! \param theArguments arguments of the attribute
349   //! \param theError error message
350   virtual bool isValid(const AttributePtr& theAttribute,
351                        const std::list<std::string>& theArguments,
352                        Events_InfoMessage& theError) const;
353 };
354
355 /**\class SketchPlugin_DifferentReferenceValidator
356  * \ingroup Validators
357  * \brief Validator for attributes of a sketch feature.
358  *
359  * It checks that at least one of specified attributes
360  * refers to another feature in respect to each other.
361  */
362 class SketchPlugin_DifferentReferenceValidator : public ModelAPI_AttributeValidator
363 {
364  public:
365   //! returns true if attribute is valid
366   //! \param theAttribute the checked attribute
367   //! \param theArguments arguments of the attribute
368   //! \param theError error message
369   virtual bool isValid(const AttributePtr& theAttribute,
370                        const std::list<std::string>& theArguments,
371                        Events_InfoMessage& theError) const;
372 };
373
374 /**\class SketchPlugin_DifferentPointReferenceValidator
375  * \ingroup Validators
376  * \brief Validator for attributes of a sketch feature.
377  *
378  * It checks that at least two of specified attributes refer to different points.
379  */
380 class SketchPlugin_DifferentPointReferenceValidator : public ModelAPI_AttributeValidator
381 {
382  public:
383   //! returns true if attribute is valid
384   //! \param theAttribute the checked attribute
385   //! \param theArguments arguments of the attribute
386   //! \param theError error message
387   virtual bool isValid(const AttributePtr& theAttribute,
388                        const std::list<std::string>& theArguments,
389                        Events_InfoMessage& theError) const;
390 };
391
392 /**\class SketchPlugin_CirclePassedPointValidator
393  * \ingroup Validators
394  * \brief Validator for passed point of MacroCircle feature.
395  *
396  * Checks that passed point does not refer to the feature, the center is coincident to.
397  */
398 class SketchPlugin_CirclePassedPointValidator : public ModelAPI_AttributeValidator
399 {
400  public:
401   //! returns true if attribute is valid
402   //! \param theAttribute the checked attribute
403   //! \param theArguments arguments of the attribute
404   //! \param theError error message
405   virtual bool isValid(const AttributePtr& theAttribute,
406                        const std::list<std::string>&,
407                        Events_InfoMessage& theError) const;
408 };
409
410 /**\class SketchPlugin_ThirdPointValidator
411  * \ingroup Validators
412  * \brief Validator for the third point of MacroCircle feature.
413  *
414  * Checks that third point does not lie on a line passed through the first two points.
415  * Checks that third point does not refer to feature lying between the first two points.
416  */
417 class SketchPlugin_ThirdPointValidator : public ModelAPI_AttributeValidator
418 {
419  public:
420   //! returns true if attribute is valid
421   //! \param theAttribute the checked attribute
422   //! \param theArguments arguments of the attribute
423   //! \param theError error message
424   virtual bool isValid(const AttributePtr& theAttribute,
425                        const std::list<std::string>& theArguments,
426                        Events_InfoMessage& theError) const;
427
428 private:
429   //! returns true if three points have not been placed on the same line
430   bool arePointsNotOnLine(const FeaturePtr& theMacroFeature,
431                           Events_InfoMessage& theError) const;
432
433   //! returns true if the first two points have not been separated
434   //! by a feature referred by thrid point
435   bool arePointsNotSeparated(const FeaturePtr& theMacroFeature,
436                              const std::list<std::string>& theArguments,
437                              Events_InfoMessage& theError) const;
438 };
439
440 /**\class SketchPlugin_ArcEndPointValidator
441  * \ingroup Validators
442  * \brief Validator for the end point of MacroArc feature.
443  *
444  * Checks that third point does not lie on a point.
445  */
446 class SketchPlugin_ArcEndPointValidator: public ModelAPI_AttributeValidator
447 {
448  public:
449   //! returns true if attribute is valid
450   //! \param theAttribute the checked attribute
451   //! \param theArguments arguments of the attribute
452   //! \param theError error message
453   virtual bool isValid(const AttributePtr& theAttribute,
454                        const std::list<std::string>& theArguments,
455                        Events_InfoMessage& theError) const;
456 };
457
458 /**\class SketchPlugin_ArcEndPointIntersectionValidator
459  * \ingroup Validators
460  * \brief Validator for the end point of MacroArc feature.
461  *
462  * Checks that third point does lie on edge which intersects arc.
463  */
464 class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeValidator
465 {
466  public:
467   //! returns true if attribute is valid
468   //! \param theAttribute the checked attribute
469   //! \param theArguments arguments of the attribute
470   //! \param theError error message
471   virtual bool isValid(const AttributePtr& theAttribute,
472                        const std::list<std::string>& theArguments,
473                        Events_InfoMessage& theError) const;
474 };
475
476 /**\class SketchPlugin_HasNoConstraint
477  * \ingroup Validators
478  * \brief Validator for checking whether the feature has constraint.
479  *
480  * Checks that feature of the attribute does not have constraint with some kinds.
481  * The kinds of constraints should be described in parameters of the validator
482  * Validator processes the ModelAPI_AttributeRefAttr attribute kind
483  */
484 class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator
485 {
486  public:
487   //! returns true if attribute is valid
488   //! \param theAttribute the checked attribute
489   //! \param theArguments arguments of the attribute
490   //! \param theError error message
491   virtual bool isValid(const AttributePtr& theAttribute,
492                        const std::list<std::string>& theArguments,
493                        Events_InfoMessage& theError) const;
494 };
495
496 /**\class SketchPlugin_ReplicationReferenceValidator
497  * \ingroup Validators
498  * \brief Validator checking that the replications features (Mirror,
499  *        Multi-Rotation, Mutli-Translation) do not refer to the shapes they produce.
500  */
501 class SketchPlugin_ReplicationReferenceValidator: public ModelAPI_AttributeValidator
502 {
503  public:
504   //! returns true if attribute is valid
505   //! \param theAttribute the checked attribute
506   //! \param theArguments arguments of the attribute
507   //! \param theError error message
508   virtual bool isValid(const AttributePtr& theAttribute,
509                        const std::list<std::string>& theArguments,
510                        Events_InfoMessage& theError) const;
511 };
512
513 /**\class SketchPlugin_SketchFeatureValidator
514  * \ingroup Validators
515  * \brief Validator for checking whether the feature referred by attribute is a sketch feature.
516  */
517 class SketchPlugin_SketchFeatureValidator: public ModelAPI_AttributeValidator
518 {
519  public:
520   //! returns true if attribute is valid
521   //! \param theAttribute the checked attribute
522   //! \param theArguments arguments of the attribute
523   //! \param theError error message
524   virtual bool isValid(const AttributePtr& theAttribute,
525                        const std::list<std::string>& theArguments,
526                        Events_InfoMessage& theError) const;
527 };
528
529 /**\class SketchPlugin_MultiRotationAngleValidator
530  * \ingroup Validators
531  * \brief Validator for checking whether the angle of MultiRotation is in range [0, 360].
532  */
533 class SketchPlugin_MultiRotationAngleValidator : public ModelAPI_AttributeValidator
534 {
535   //! returns true if attribute is valid
536   //! \param theAttribute the checked attribute
537   //! \param theArguments arguments of the attribute
538   //! \param theError error message
539   virtual bool isValid(const AttributePtr& theAttribute,
540                        const std::list<std::string>& theArguments,
541                        Events_InfoMessage& theError) const;
542 };
543
544 /**\class SketchPlugin_BSplineValidator
545  * \ingroup Validators
546  * \brief Validator for checking poles/weights of B-spline curve.
547  */
548 class SketchPlugin_BSplineValidator : public ModelAPI_AttributeValidator
549 {
550   //! returns true if attribute is valid
551   //! \param theAttribute the checked attribute
552   //! \param theArguments arguments of the attribute
553   //! \param theError error message
554   virtual bool isValid(const AttributePtr& theAttribute,
555                        const std::list<std::string>& theArguments,
556                        Events_InfoMessage& theError) const;
557 };
558
559 /**\class SketchPlugin_CurveFittingValidator
560  * \ingroup Validators
561  * \brief Validator for the selected vertices for the curve fitting feature.
562  */
563 class SketchPlugin_CurveFittingValidator : public ModelAPI_FeatureValidator
564 {
565 public:
566   //! returns true if number of selected points is greater than the minimal value
567   //! \param theAttribute the checked attribute
568   //! \param theArguments arguments of the attribute
569   //! \param theError error message
570   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
571                        const std::list<std::string>& theArguments,
572                        Events_InfoMessage& theError) const;
573 };
574
575 #endif