1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ConstructionPlugin_Validators.h"
23 #include <GeomAPI_Dir.h>
24 #include <GeomAPI_Edge.h>
25 #include <GeomAPI_Face.h>
26 #include <GeomAPI_Lin.h>
27 #include <GeomAPI_Pln.h>
28 #include <GeomAPI_Vertex.h>
30 #include <ModelAPI_AttributeSelection.h>
31 #include <ModelAPI_AttributeBoolean.h>
33 #include <Events_InfoMessage.h>
35 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
36 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
37 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
39 //==================================================================================================
40 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
41 const std::list<std::string>& theArguments,
42 Events_InfoMessage& theError) const
44 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
46 AttributeSelectionPtr aLineAttribute1 =
47 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
48 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
50 GeomShapePtr aLineShape1 = aLineAttribute1->value();
51 ResultPtr aContext1 = aLineAttribute1->context();
52 if(!aContext1.get()) {
53 theError = "One of the attribute not initialized.";
56 if(!aLineShape1.get()) {
57 aLineShape1 = aContext1->shape();
59 if(!aLineShape1->isEdge()) {
60 theError = "One of the selected shapes not an edge.";
64 GeomShapePtr aLineShape2 = aLineAttribute2->value();
65 ResultPtr aContext2 = aLineAttribute2->context();
66 if(!aContext2.get()) {
69 if(!aLineShape2.get()) {
70 aLineShape2 = aContext2->shape();
72 if(!aLineShape2->isEdge()) {
73 theError = "One of the selected shapes not an edge.";
77 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
78 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
80 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
81 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
83 if(!aLine1->isCoplanar(aLine2)) {
84 theError = "Selected lines not coplanar.";
88 if(aLine1->isParallel(aLine2)) {
89 theError = "Selected lines are parallel.";
96 //==================================================================================================
97 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
98 const AttributePtr& theAttribute,
99 const std::list<std::string>& theArguments,
100 Events_InfoMessage& theError) const
102 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
104 AttributeSelectionPtr anAttribute1 =
105 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
106 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
108 std::shared_ptr<GeomAPI_Lin> aLin;
109 std::shared_ptr<GeomAPI_Pln> aPln;
111 GeomShapePtr aShape1 = anAttribute1->value();
112 ResultPtr aContext1 = anAttribute1->context();
113 if(!aContext1.get()) {
114 theError = "One of the attribute not initialized.";
118 aShape1 = aContext1->shape();
121 GeomShapePtr aShape2 = anAttribute2->value();
122 ResultPtr aContext2 = anAttribute2->context();
123 if(!aContext2.get()) {
127 aShape2 = aContext2->shape();
130 aLin = getLin(aShape1);
131 aPln = getPln(aShape2);
132 if(!aLin.get() || !aPln.get()) {
133 aLin = getLin(aShape2);
134 aPln = getPln(aShape1);
137 if(!aLin.get() || !aPln.get()) {
138 theError = "Wrong shape types selected.";
142 if(aPln->isParallel(aLin)) {
143 theError = "Plane and line are parallel.";
150 //==================================================================================================
151 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
152 const std::list<std::string>& theArguments,
153 Events_InfoMessage& theError) const
155 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
157 AttributeSelectionPtr aPointAttribute1 =
158 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
159 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
160 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
162 GeomShapePtr aPointShape1 = aPointAttribute1->value();
163 ResultPtr aContext1 = aPointAttribute1->context();
164 if(!aContext1.get()) {
165 theError = "One of the attribute not initialized.";
168 if(!aPointShape1.get()) {
169 aPointShape1 = aContext1->shape();
171 if(!aPointShape1->isVertex()) {
172 theError = "One of the selected shapes not a vertex.";
176 GeomShapePtr aPointShape2 = aPointAttribute2->value();
177 ResultPtr aContext2 = aPointAttribute2->context();
178 if(!aContext2.get()) {
181 if(!aPointShape2.get()) {
182 aPointShape2 = aContext2->shape();
184 if(!aPointShape2->isVertex()) {
185 theError = "One of the selected shapes not a vertex.";
189 GeomShapePtr aPointShape3 = aPointAttribute3->value();
190 ResultPtr aContext3 = aPointAttribute3->context();
191 if(!aContext3.get()) {
194 if(!aPointShape3.get()) {
195 aPointShape3 = aContext3->shape();
197 if(!aPointShape3->isVertex()) {
198 theError = "One of the selected shapes not a vertex.";
202 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
203 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
204 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
206 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
207 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
208 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
210 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
212 if(aLin->contains(aPnt3)) {
213 theError = "Selected points lie on a line.";
220 //==================================================================================================
221 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
222 const AttributePtr& theAttribute,
223 const std::list<std::string>& theArguments,
224 Events_InfoMessage& theError) const
226 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
228 AttributeSelectionPtr anAttribute1 =
229 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
230 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
232 std::shared_ptr<GeomAPI_Lin> aLin;
233 std::shared_ptr<GeomAPI_Pnt> aPnt;
235 GeomShapePtr aShape1 = anAttribute1->value();
236 ResultPtr aContext1 = anAttribute1->context();
237 if(!aContext1.get()) {
238 theError = "One of the attribute not initialized.";
242 aShape1 = aContext1->shape();
245 GeomShapePtr aShape2 = anAttribute2->value();
246 ResultPtr aContext2 = anAttribute2->context();
247 if(!aContext2.get()) {
251 aShape2 = aContext2->shape();
254 aLin = getLin(aShape1);
255 aPnt = getPnt(aShape2);
256 if(!aLin.get() || !aPnt.get()) {
257 aLin = getLin(aShape2);
258 aPnt = getPnt(aShape1);
261 if(!aLin.get() || !aPnt.get()) {
262 theError = "Wrong shape types selected.";
266 // line should not contain point only for not-prependicular case
267 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
268 if (aBoolAttr.get() && !aBoolAttr->value()) {
269 if(aLin->contains(aPnt)) {
270 theError = "Point lies on the line.";
278 //==================================================================================================
279 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
280 const AttributePtr& theAttribute,
281 const std::list<std::string>& theArguments,
282 Events_InfoMessage& theError) const
284 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
286 AttributeSelectionPtr anAttribute1 =
287 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
288 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
290 std::shared_ptr<GeomAPI_Pln> aPln1;
291 std::shared_ptr<GeomAPI_Pln> aPln2;
293 GeomShapePtr aShape1 = anAttribute1->value();
294 ResultPtr aContext1 = anAttribute1->context();
295 if(!aContext1.get()) {
296 theError = "One of the attribute not initialized.";
300 aShape1 = aContext1->shape();
303 GeomShapePtr aShape2 = anAttribute2->value();
304 ResultPtr aContext2 = anAttribute2->context();
305 if(!aContext2.get()) {
309 aShape2 = aContext2->shape();
312 aPln1 = getPln(aShape1);
313 aPln2 = getPln(aShape2);
315 if(!aPln1.get() || !aPln2.get()) {
316 theError = "Wrong shape types selected.";
320 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
321 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
323 if(!aDir1->isParallel(aDir2)) {
324 theError = "Planes not parallel.";
331 //==================================================================================================
332 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
333 const AttributePtr& theAttribute,
334 const std::list<std::string>& theArguments,
335 Events_InfoMessage& theError) const
337 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
339 AttributeSelectionPtr anAttribute1 =
340 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
341 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
343 std::shared_ptr<GeomAPI_Pln> aPln1;
344 std::shared_ptr<GeomAPI_Pln> aPln2;
346 GeomShapePtr aShape1 = anAttribute1->value();
347 ResultPtr aContext1 = anAttribute1->context();
348 if(!aContext1.get()) {
349 theError = "One of the attribute not initialized.";
353 aShape1 = aContext1->shape();
356 GeomShapePtr aShape2 = anAttribute2->value();
357 ResultPtr aContext2 = anAttribute2->context();
358 if(!aContext2.get()) {
362 aShape2 = aContext2->shape();
365 aPln1 = getPln(aShape1);
366 aPln2 = getPln(aShape2);
368 if(!aPln1.get() || !aPln2.get()) {
369 theError = "Wrong shape types selected.";
373 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
374 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
376 if(aDir1->isParallel(aDir2)) {
377 theError = "Planes are parallel.";
384 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
386 std::shared_ptr<GeomAPI_Lin> aLin;
388 if(!theShape->isEdge()) {
392 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
394 if(!anEdge->isLine()) {
398 aLin = anEdge->line();
403 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
405 std::shared_ptr<GeomAPI_Pln> aPln;
407 if(!theShape->isFace()) {
411 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
413 if(!aFace->isPlanar()) {
417 aPln = aFace->getPlane();
422 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
424 std::shared_ptr<GeomAPI_Pnt> aPnt;
426 if(!theShape->isVertex()) {
430 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
432 aPnt = aVertex->point();