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