Salome HOME
4a7bd052576a7952bb799ef1c3169c1a83e380c5
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.h
1 // Copyright (C) 2014-2019  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
64 /**\class SketchPlugin_NotFixedValidator
65  * \ingroup Validators
66  * \brief Validator for the rigid constraint input.
67  *
68  * It just checks there is no rigid constraint for the current feature.
69  */
70 class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator
71 {
72  public:
73   //! returns true if attribute is not used in another rigid constraint
74   //! \param theAttribute the checked attribute
75   //! \param theArguments arguments of the attribute
76   //! \param theError error message
77   virtual bool isValid(const AttributePtr& theAttribute,
78                        const std::list<std::string>& theArguments,
79                        Events_InfoMessage& theError) const;
80 };
81
82 /**\class SketchPlugin_EqualAttrValidator
83  * \ingroup Validators
84  * \brief Validator for the equal constraint input.
85  *
86  * It checks that attributes of the Equal constraint are correct.
87  */
88 class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator
89 {
90  public:
91   //! returns true if attribute is valid
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_MirrorAttrValidator
101  * \ingroup Validators
102  * \brief Validator for the mirror constraint input.
103  *
104  * It checks that attributes of the Mirror constraint are correct.
105  */
106 class SketchPlugin_MirrorAttrValidator : 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 (not used)
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
119 /**\class SketchPlugin_CoincidenceAttrValidator
120  * \ingroup Validators
121  * \brief Validator for the coincidence constraint input.
122  *
123  * It checks that attributes of the Coincidence constraint are correct.
124  */
125 class SketchPlugin_CoincidenceAttrValidator : public ModelAPI_AttributeValidator
126 {
127  public:
128   //! returns true if attribute is valid
129   //! \param theAttribute the checked attribute
130   //! \param theArguments arguments of the attribute (not used)
131   //! \param theError error message
132   virtual bool isValid(const AttributePtr& theAttribute,
133                        const std::list<std::string>& theArguments,
134                        Events_InfoMessage& theError) const;
135 };
136
137
138 /**\class SketchPlugin_CopyValidator
139  * \ingroup Validators
140  * \brief Validator for the constraints which create features.
141  *
142  * Applicable only for features, which creates another features. It verifies the produced
143  * features of current constraint don't become into the list of initial features
144  */
145 class SketchPlugin_CopyValidator : public ModelAPI_AttributeValidator
146 {
147  public:
148   //! returns true if attribute is valid
149   //! \param theAttribute the checked attribute
150   //! \param theArguments arguments of the attribute (not used)
151   //! \param theError error message
152   virtual bool isValid(const AttributePtr& theAttribute,
153                        const std::list<std::string>& theArguments,
154                        Events_InfoMessage& theError) const;
155 };
156
157 /**\class SketchPlugin_SolverErrorValidator
158  * \ingroup Validators
159  * \brief Validator for the solver error.
160  *
161  * Simply checks that solver error attribute is empty. Returns the attribute value as an error.
162  */
163 class SketchPlugin_SolverErrorValidator : public ModelAPI_FeatureValidator
164 {
165  public:
166   //! returns true if there are no solver errors
167   //! \param theFeature the checked feature
168   //! \param theArguments arguments of the feature (not used)
169   //! \param theError error message
170   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
171                        const std::list<std::string>& theArguments,
172                        Events_InfoMessage& theError) const;
173
174   /// Returns true if the attribute in feature is not obligatory for the feature execution
175   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
176 };
177
178 /**\class SketchPlugin_FilletVertexValidator
179  * \ingroup Validators
180  * \brief Validator for the point for fillet creation.
181  *
182  * Checks that selected point have exactly two coincident lines.
183  */
184 class SketchPlugin_FilletVertexValidator : public ModelAPI_AttributeValidator
185 {
186 public:
187   //! returns true if attribute is valid
188   //! \param theAttribute the checked attribute
189   //! \param theArguments arguments of the attribute (not used)
190   //! \param theError error message
191   virtual bool isValid(const AttributePtr& theAttribute,
192                        const std::list<std::string>& theArguments,
193                        Events_InfoMessage& theError) const;
194 };
195
196
197 /**\class SketchPlugin_MiddlePointAttrValidator
198  * \ingroup Validators
199  * \brief Validator for the middle point constraint input.
200  *
201  * It checks that attributes of the Middle point constraint are correct.
202  */
203 class SketchPlugin_MiddlePointAttrValidator : public ModelAPI_AttributeValidator
204 {
205  public:
206   //! returns true if attribute is valid
207   //! \param theAttribute the checked attribute
208   //! \param theArguments arguments of the attribute (not used)
209   //! \param theError error message
210   virtual bool isValid(const AttributePtr& theAttribute,
211                        const std::list<std::string>& theArguments,
212                        Events_InfoMessage& theError) const;
213 };
214
215
216 /**\class SketchPlugin_ArcTangentPointValidator
217  * \ingroup Validators
218  * \brief Validator for the point where the tangent arc is building.
219  *
220  * Checks that the point is a start or end point just on line or arc.
221  */
222 class SketchPlugin_ArcTangentPointValidator : public ModelAPI_AttributeValidator
223 {
224  public:
225   //! returns true if attribute is valid
226   //! \param theAttribute the checked attribute
227   //! \param theArguments arguments of the attribute
228   //! \param theError error message
229   virtual bool isValid(const AttributePtr& theAttribute,
230                        const std::list<std::string>& theArguments,
231                        Events_InfoMessage& theError) const;
232 };
233
234 /**\class SketchPlugin_SplitValidator
235  * \ingroup Validators
236  * \brief Validator for the entity of the following type:
237  * - Linear segment with point(s) coinident to this line
238  * - Arc with point(s) coincident to the arc
239  * - Circle with at least 2 split-points on this circle
240  *
241  * Checks that there are coincident point on selected feature.
242  */
243 class SketchPlugin_SplitValidator : public ModelAPI_AttributeValidator
244 {
245  public:
246   //! returns true if attribute is valid
247   //! \param theAttribute the checked attribute
248   //! \param theArguments arguments of the attribute
249   //! \param theError error message
250   virtual bool isValid(const AttributePtr& theAttribute,
251                        const std::list<std::string>& theArguments,
252                        Events_InfoMessage& theError) const;
253 };
254
255 /**\class SketchPlugin_TrimValidator
256  * \ingroup Validators
257  * \brief Validator for the entity of the following type:
258  * - Linear segment with point(s) coinident to this line or intersected it
259  * - Arc with point(s) coincident to the arc or intersected it
260  * - Circle with at least 2 split-points on this circle or intersected it
261  *
262  * Checks that there are coincident point on selected feature.
263  */
264 class SketchPlugin_TrimValidator : public ModelAPI_AttributeValidator
265 {
266  public:
267   //! returns true if attribute is valid
268   //! \param theAttribute the checked attribute
269   //! \param theArguments arguments of the attribute
270   //! \param theError error message
271   virtual bool isValid(const AttributePtr& theAttribute,
272                        const std::list<std::string>& theArguments,
273                        Events_InfoMessage& theError) const;
274 };
275
276 /**\class SketchPlugin_IntersectionValidator
277  * \ingroup Validators
278  * \brief Validator for the attribute to be intersected with the sketch plane.
279  */
280 class SketchPlugin_IntersectionValidator : 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_ProjectionValidator
293  * \ingroup Validators
294  * \brief Validator for the attribute to be projected onto the sketch plane.
295  */
296 class SketchPlugin_ProjectionValidator : public ModelAPI_AttributeValidator
297 {
298  public:
299   //! returns true if attribute is valid
300   //! \param theAttribute the checked attribute
301   //! \param theArguments arguments of the attribute
302   //! \param theError error message
303   virtual bool isValid(const AttributePtr& theAttribute,
304                        const std::list<std::string>& theArguments,
305                        Events_InfoMessage& theError) const;
306 };
307
308 /**\class SketchPlugin_DifferentReferenceValidator
309  * \ingroup Validators
310  * \brief Validator for attributes of a sketch feature.
311  *
312  * It checks that at least one of specified attributes
313  * refers to another feature in respect to each other.
314  */
315 class SketchPlugin_DifferentReferenceValidator : public ModelAPI_AttributeValidator
316 {
317  public:
318   //! returns true if attribute is valid
319   //! \param theAttribute the checked attribute
320   //! \param theArguments arguments of the attribute
321   //! \param theError error message
322   virtual bool isValid(const AttributePtr& theAttribute,
323                        const std::list<std::string>& theArguments,
324                        Events_InfoMessage& theError) const;
325 };
326
327 /**\class SketchPlugin_DifferentPointReferenceValidator
328  * \ingroup Validators
329  * \brief Validator for attributes of a sketch feature.
330  *
331  * It checks that at least two of specified attributes refer to different points.
332  */
333 class SketchPlugin_DifferentPointReferenceValidator : 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_CirclePassedPointValidator
346  * \ingroup Validators
347  * \brief Validator for passed point of MacroCircle feature.
348  *
349  * Checks that passed point does not refer to the feature, the center is coincident to.
350  */
351 class SketchPlugin_CirclePassedPointValidator : public ModelAPI_AttributeValidator
352 {
353  public:
354   //! returns true if attribute is valid
355   //! \param theAttribute the checked attribute
356   //! \param theArguments arguments of the attribute
357   //! \param theError error message
358   virtual bool isValid(const AttributePtr& theAttribute,
359                        const std::list<std::string>&,
360                        Events_InfoMessage& theError) const;
361 };
362
363 /**\class SketchPlugin_ThirdPointValidator
364  * \ingroup Validators
365  * \brief Validator for the third point of MacroCircle feature.
366  *
367  * Checks that third point does not lie on a line passed through the first two points.
368  * Checks that third point does not refer to feature lying between the first two points.
369  */
370 class SketchPlugin_ThirdPointValidator : 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 private:
382   //! returns true if three points have not been placed on the same line
383   bool arePointsNotOnLine(const FeaturePtr& theMacroFeature,
384                           Events_InfoMessage& theError) const;
385
386   //! returns true if the first two points have not been separated
387   //! by a feature referred by thrid point
388   bool arePointsNotSeparated(const FeaturePtr& theMacroFeature,
389                              const std::list<std::string>& theArguments,
390                              Events_InfoMessage& theError) const;
391 };
392
393 /**\class SketchPlugin_ArcEndPointValidator
394  * \ingroup Validators
395  * \brief Validator for the end point of MacroArc feature.
396  *
397  * Checks that third point does not lie on a point.
398  */
399 class SketchPlugin_ArcEndPointValidator: public ModelAPI_AttributeValidator
400 {
401  public:
402   //! returns true if attribute is valid
403   //! \param theAttribute the checked attribute
404   //! \param theArguments arguments of the attribute
405   //! \param theError error message
406   virtual bool isValid(const AttributePtr& theAttribute,
407                        const std::list<std::string>& theArguments,
408                        Events_InfoMessage& theError) const;
409 };
410
411 /**\class SketchPlugin_ArcEndPointIntersectionValidator
412  * \ingroup Validators
413  * \brief Validator for the end point of MacroArc feature.
414  *
415  * Checks that third point does lie on edge which intersects arc.
416  */
417 class SketchPlugin_ArcEndPointIntersectionValidator: 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
429 /**\class SketchPlugin_HasNoConstraint
430  * \ingroup Validators
431  * \brief Validator for checking whether the feature has constraint.
432  *
433  * Checks that feature of the attribute does not have constraint with some kinds.
434  * The kinds of constraints should be described in parameters of the validator
435  * Validator processes the ModelAPI_AttributeRefAttr attribute kind
436  */
437 class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator
438 {
439  public:
440   //! returns true if attribute is valid
441   //! \param theAttribute the checked attribute
442   //! \param theArguments arguments of the attribute
443   //! \param theError error message
444   virtual bool isValid(const AttributePtr& theAttribute,
445                        const std::list<std::string>& theArguments,
446                        Events_InfoMessage& theError) const;
447 };
448
449 /**\class SketchPlugin_ReplicationReferenceValidator
450  * \ingroup Validators
451  * \brief Validator checking that the replications features (Mirror,
452  *        Multi-Rotation, Mutli-Translation) do not refer to the shapes they produce.
453  */
454 class SketchPlugin_ReplicationReferenceValidator: 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_SketchFeatureValidator
467  * \ingroup Validators
468  * \brief Validator for checking whether the feature referred by attribute is a sketch feature.
469  */
470 class SketchPlugin_SketchFeatureValidator: public ModelAPI_AttributeValidator
471 {
472  public:
473   //! returns true if attribute is valid
474   //! \param theAttribute the checked attribute
475   //! \param theArguments arguments of the attribute
476   //! \param theError error message
477   virtual bool isValid(const AttributePtr& theAttribute,
478                        const std::list<std::string>& theArguments,
479                        Events_InfoMessage& theError) const;
480 };
481
482 /**\class SketchPlugin_MultiRotationAngleValidator
483  * \ingroup Validators
484  * \brief Validator for checking whether the angle of MultiRotation is in range [0, 360].
485  */
486 class SketchPlugin_MultiRotationAngleValidator : public ModelAPI_AttributeValidator
487 {
488   //! returns true if attribute is valid
489   //! \param theAttribute the checked attribute
490   //! \param theArguments arguments of the attribute
491   //! \param theError error message
492   virtual bool isValid(const AttributePtr& theAttribute,
493                        const std::list<std::string>& theArguments,
494                        Events_InfoMessage& theError) const;
495 };
496
497 #endif