1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "ConstructionPlugin_Validators.h"
22 #include <GeomAPI_Dir.h>
23 #include <GeomAPI_Edge.h>
24 #include <GeomAPI_Face.h>
25 #include <GeomAPI_Lin.h>
26 #include <GeomAPI_Pln.h>
27 #include <GeomAPI_Vertex.h>
28 #include <GeomAPI_Pnt.h>
29 #include <GeomAPI_ShapeIterator.h>
30 #include <GeomAlgoAPI_ShapeTools.h>
32 #include <ModelAPI_AttributeSelection.h>
33 #include <ModelAPI_AttributeBoolean.h>
35 #include <Events_InfoMessage.h>
37 static std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape);
38 static std::shared_ptr<GeomAPI_Face> getFace(const GeomShapePtr theShape);
39 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
40 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
41 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
43 //==================================================================================================
44 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
45 const std::list<std::string>& theArguments,
46 Events_InfoMessage& theError) const
48 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
50 AttributeSelectionPtr aLineAttribute1 =
51 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
52 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
54 GeomShapePtr aLineShape1 = aLineAttribute1->value();
55 ResultPtr aContext1 = aLineAttribute1->context();
56 if(!aContext1.get()) {
57 theError = "One of the attribute not initialized.";
60 if(!aLineShape1.get()) {
61 aLineShape1 = aContext1->shape();
63 if(!aLineShape1->isEdge()) {
64 theError = "One of the selected shapes not an edge.";
68 GeomShapePtr aLineShape2 = aLineAttribute2->value();
69 ResultPtr aContext2 = aLineAttribute2->context();
70 if(!aContext2.get()) {
73 if(!aLineShape2.get()) {
74 aLineShape2 = aContext2->shape();
76 if(!aLineShape2->isEdge()) {
77 theError = "One of the selected shapes not an edge.";
81 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
82 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
84 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
85 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
87 if (!aLine1.get() || !aLine2.get()) {
88 theError = "Selected edge is not a line.";
92 if(!aLine1->isCoplanar(aLine2)) {
93 theError = "Selected lines not coplanar.";
97 if(aLine1->isParallel(aLine2)) {
98 theError = "Selected lines are parallel.";
105 //==================================================================================================
106 bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
107 const AttributePtr& theAttribute,
108 const std::list<std::string>& theArguments,
109 Events_InfoMessage& theError) const
111 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
113 AttributeSelectionPtr anAttribute1 =
114 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
115 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
117 std::shared_ptr<GeomAPI_Edge> anEdge;
118 std::shared_ptr<GeomAPI_Face> aFace;
120 GeomShapePtr aShape1 = anAttribute1->value();
121 ResultPtr aContext1 = anAttribute1->context();
122 if(!aContext1.get()) {
123 theError = "One of the attribute not initialized.";
127 aShape1 = aContext1->shape();
130 GeomShapePtr aShape2 = anAttribute2->value();
131 ResultPtr aContext2 = anAttribute2->context();
132 if(!aContext2.get()) {
136 aShape2 = aContext2->shape();
139 bool isPlaneFirst = false;
140 anEdge = getEdge(aShape1);
142 aFace = getFace(aShape2);
143 if(!anEdge.get() || !aFace.get()) {
144 anEdge = getEdge(aShape2);
145 aFace = getFace(aShape1);
149 if(!anEdge.get() || !aFace.get()) {
150 theError = "Wrong shape types selected.";
154 if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aFace)) {
155 theError = "Plane and edge are parallel.";
162 //==================================================================================================
163 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
164 const std::list<std::string>& theArguments,
165 Events_InfoMessage& theError) const
167 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
169 AttributeSelectionPtr aPointAttribute1 =
170 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
171 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
172 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
174 GeomShapePtr aPointShape1 = aPointAttribute1->value();
175 ResultPtr aContext1 = aPointAttribute1->context();
176 if(!aContext1.get()) {
177 theError = "One of the attribute not initialized.";
180 if(!aPointShape1.get()) {
181 aPointShape1 = aContext1->shape();
183 if(!aPointShape1->isVertex()) {
184 theError = "One of the selected shapes not a vertex.";
188 GeomShapePtr aPointShape2 = aPointAttribute2->value();
189 ResultPtr aContext2 = aPointAttribute2->context();
190 if(!aContext2.get()) {
193 if(!aPointShape2.get()) {
194 aPointShape2 = aContext2->shape();
196 if(!aPointShape2->isVertex()) {
197 theError = "One of the selected shapes not a vertex.";
201 GeomShapePtr aPointShape3 = aPointAttribute3->value();
202 ResultPtr aContext3 = aPointAttribute3->context();
203 if(!aContext3.get()) {
206 if(!aPointShape3.get()) {
207 aPointShape3 = aContext3->shape();
209 if(!aPointShape3->isVertex()) {
210 theError = "One of the selected shapes not a vertex.";
214 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
215 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
216 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
218 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
219 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
220 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
222 if (aPnt1->isEqual(aPnt2)) {
223 theError = "Selected points are equal";
227 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
229 if(aLin->contains(aPnt3)) {
230 theError = "Selected points lie on a line.";
237 //==================================================================================================
238 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
239 const AttributePtr& theAttribute,
240 const std::list<std::string>& theArguments,
241 Events_InfoMessage& theError) const
243 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
245 AttributeSelectionPtr anAttribute1 =
246 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
247 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
249 std::shared_ptr<GeomAPI_Lin> aLin;
250 std::shared_ptr<GeomAPI_Pnt> aPnt;
252 GeomShapePtr aShape1 = anAttribute1->value();
253 ResultPtr aContext1 = anAttribute1->context();
254 if(!aContext1.get()) {
255 theError = "One of the attribute not initialized.";
259 aShape1 = aContext1->shape();
262 GeomShapePtr aShape2 = anAttribute2->value();
263 ResultPtr aContext2 = anAttribute2->context();
264 if(!aContext2.get()) {
268 aShape2 = aContext2->shape();
271 aLin = getLin(aShape1);
272 aPnt = getPnt(aShape2);
273 if(!aLin.get() || !aPnt.get()) {
274 aLin = getLin(aShape2);
275 aPnt = getPnt(aShape1);
278 if(!aLin.get() || !aPnt.get()) {
279 theError = "Wrong shape types selected.";
283 // line should not contain point only for not-prependicular case
284 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
285 if (aBoolAttr.get() && !aBoolAttr->value()) {
286 if(aLin->contains(aPnt)) {
287 theError = "Point lies on the line.";
295 //==================================================================================================
296 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
297 const AttributePtr& theAttribute,
298 const std::list<std::string>& theArguments,
299 Events_InfoMessage& theError) const
301 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
303 AttributeSelectionPtr anAttribute1 =
304 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
305 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
307 std::shared_ptr<GeomAPI_Pln> aPln1;
308 std::shared_ptr<GeomAPI_Pln> aPln2;
310 GeomShapePtr aShape1 = anAttribute1->value();
311 ResultPtr aContext1 = anAttribute1->context();
312 if(!aContext1.get()) {
313 theError = "One of the attribute not initialized.";
317 aShape1 = aContext1->shape();
320 GeomShapePtr aShape2 = anAttribute2->value();
321 ResultPtr aContext2 = anAttribute2->context();
322 if(!aContext2.get()) {
326 aShape2 = aContext2->shape();
329 aPln1 = getPln(aShape1);
330 aPln2 = getPln(aShape2);
332 if(!aPln1.get() || !aPln2.get()) {
333 theError = "Wrong shape types selected.";
337 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
338 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
340 if(!aDir1->isParallel(aDir2)) {
341 theError = "Planes not parallel.";
348 //==================================================================================================
349 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
350 const AttributePtr& theAttribute,
351 const std::list<std::string>& theArguments,
352 Events_InfoMessage& theError) const
354 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
356 AttributeSelectionPtr anAttribute1 =
357 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
358 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
360 std::shared_ptr<GeomAPI_Pln> aPln1;
361 std::shared_ptr<GeomAPI_Pln> aPln2;
363 GeomShapePtr aShape1 = anAttribute1->value();
364 ResultPtr aContext1 = anAttribute1->context();
365 if(!aContext1.get()) {
366 theError = "One of the attribute not initialized.";
370 aShape1 = aContext1->shape();
373 GeomShapePtr aShape2 = anAttribute2->value();
374 ResultPtr aContext2 = anAttribute2->context();
375 if(!aContext2.get()) {
379 aShape2 = aContext2->shape();
382 aPln1 = getPln(aShape1);
383 aPln2 = getPln(aShape2);
385 if(!aPln1.get() || !aPln2.get()) {
386 theError = "Wrong shape types selected.";
390 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
391 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
393 if(aDir1->isParallel(aDir2)) {
394 theError = "Planes are parallel.";
401 //==================================================================================================
402 bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid(
403 const AttributePtr& theAttribute,
404 const std::list<std::string>& theArguments,
405 Events_InfoMessage& theError) const
407 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
409 AttributeSelectionPtr anAttribute1 =
410 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
411 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
412 AttributeSelectionPtr anAttribute3 = aFeature->selection(theArguments.back());
414 GeomShapePtr aShape1 = anAttribute1->value();
415 ResultPtr aContext1 = anAttribute1->context();
416 if (!aContext1.get()) {
417 theError = "One of the attribute not initialized.";
420 if (!aShape1.get()) {
421 aShape1 = aContext1->shape();
424 std::shared_ptr<GeomAPI_Pln> aPln1 = getPln(aShape1);
426 theError = "Wrong shape types selected.";
429 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
431 if (anAttribute2.get()) {
432 GeomShapePtr aShape2 = anAttribute2->value();
433 ResultPtr aContext2 = anAttribute2->context();
434 if (!aShape2.get() && aContext2.get()) {
435 aShape2 = aContext2->shape();
439 std::shared_ptr<GeomAPI_Pln> aPln2 = getPln(aShape2);
441 theError = "Wrong shape types selected.";
444 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
445 if (aDir1->isParallel(aDir2)) {
446 theError = "Planes are parallel.";
452 if (anAttribute3.get()) {
453 GeomShapePtr aShape3 = anAttribute3->value();
454 ResultPtr aContext3 = anAttribute3->context();
455 if (!aShape3.get() && aContext3.get()) {
456 aShape3 = aContext3->shape();
460 std::shared_ptr<GeomAPI_Pln> aPln3 = getPln(aShape3);
462 theError = "Wrong shape types selected.";
465 std::shared_ptr<GeomAPI_Dir> aDir3 = aPln3->direction();
466 if (aDir1->isParallel(aDir3)) {
467 theError = "Planes are parallel.";
476 std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
480 if(theShape->isEdge()) {
481 anEdge = theShape->edge();
483 else if (theShape->isCompound()) {
484 GeomAPI_ShapeIterator anIt(theShape);
485 anEdge = anIt.current()->edge();
491 GeomFacePtr getFace(const GeomShapePtr theShape)
495 if (theShape->isFace()) {
496 aFace = theShape->face();
498 else if (theShape->isCompound()) {
499 GeomAPI_ShapeIterator anIt(theShape);
500 aFace = anIt.current()->face();
506 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
508 std::shared_ptr<GeomAPI_Lin> aLin;
512 if (theShape->isEdge()) {
513 anEdge = theShape->edge();
515 else if (theShape->isCompound()) {
516 GeomAPI_ShapeIterator anIt(theShape);
517 anEdge = anIt.current()->edge();
523 if(!anEdge->isLine()) {
527 aLin = anEdge->line();
532 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
534 std::shared_ptr<GeomAPI_Pln> aPln;
538 if(theShape->isFace()) {
539 aFace = theShape->face();
541 else if (theShape->isCompound()) {
542 GeomAPI_ShapeIterator anIt(theShape);
543 aFace = anIt.current()->face();
549 if(!aFace || !aFace->isPlanar()) {
553 aPln = aFace->getPlane();
558 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
560 std::shared_ptr<GeomAPI_Pnt> aPnt;
562 if(!theShape->isVertex()) {
566 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
568 aPnt = aVertex->point();