Salome HOME
Switch to the newer compiled Linux SALOME environment.
[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 ////////////// Attribute validators ////////////////
192
193
194 /**
195 * \ingroup Validators
196 * A validator which checks that objects selected for feature attributes are different (not the same)
197 */
198 class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
199 {
200   //! Validator possible error types
201   enum ErrorType {
202     EqualObjects,
203     EqualAttributes,
204     EqualShapes,
205     EmptyShapes
206   };
207  public:
208   //! Returns true if the attribute is good for the feature attribute
209   //! \param theAttribute an attribute
210   //! \param theArguments a list of arguments (names of attributes to check)
211   //! \param theError an output error string
212   virtual bool isValid(const AttributePtr& theAttribute,
213                        const std::list<std::string>& theArguments,
214                        Events_InfoMessage& theError) const;
215 private:
216   //! Returns error message for the error type
217   //! \param theType a type of error
218   //! \param thEqualObjectInfo an
219   std::string errorMessage(const PartSet_DifferentObjectsValidator::ErrorType& theType,
220                            const std::string& thEqualObject, const std::string& theFirstAttribute,
221                            const std::string& theSecondAttribute) const;
222
223 };
224
225 /**
226 * \ingroup Validators
227 * A validator which checks that Point2D selected for feature attributes are different (not the same)
228 * It iterates by the feature ModelAPI_AttributeRefAttr attributes, finds GeomDataAPI_Point2D attribute in
229 * value or attribute of the attributes and if the point of the given attribute is geometrical equal to
230 * a point of another attribute, returns false
231 */
232 class PartSet_DifferentPointsValidator : public ModelAPI_AttributeValidator
233 {
234  public:
235   //! Returns true if the attribute is good for the feature attribute
236   //! \param theAttribute an attribute
237   //! \param theArguments a list of arguments (names of attributes to check)
238   //! \param theError an output error string
239   virtual bool isValid(const AttributePtr& theAttribute,
240                        const std::list<std::string>& theArguments,
241                        Events_InfoMessage& theError) const;
242 private:
243   //! Finds Point2D attribute by reference attribute. It might be:
244   //! - COORD_ID attribute of SketchPlugin_Point if object
245   //! - Attribute casted to point if attribute
246   //! \param theAttribute an attribute
247   //! \return point 2d attribute or NULL
248   std::shared_ptr<GeomDataAPI_Point2D> getRefPointAttribute
249                       (const AttributePtr& theAttribute) const;
250 };
251
252
253 /**\class PartSet_CoincidentAttr
254  * \ingroup Validators
255  * \brief Validator to check whether there is a coincident constraint between
256  * the attribute and attribute of argument.
257  */
258 class PartSet_CoincidentAttr : 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 an output error string
265   virtual bool isValid(const AttributePtr& theAttribute,
266                        const std::list<std::string>& theArguments,
267                        Events_InfoMessage& theError) const;
268 };
269
270
271 #endif