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>
29 #include <GeomAPI_Pnt.h>
30 #include <GeomAPI_ShapeIterator.h>
31 #include <GeomAlgoAPI_ShapeTools.h>
33 #include <ModelAPI_AttributeSelection.h>
34 #include <ModelAPI_AttributeBoolean.h>
36 #include <Events_InfoMessage.h>
38 static std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape);
39 static std::shared_ptr<GeomAPI_Face> getFace(const GeomShapePtr theShape);
40 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
41 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
42 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
44 //==================================================================================================
45 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
46 const std::list<std::string>& theArguments,
47 Events_InfoMessage& theError) const
49 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
51 AttributeSelectionPtr aLineAttribute1 =
52 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
53 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
55 GeomShapePtr aLineShape1 = aLineAttribute1->value();
56 ResultPtr aContext1 = aLineAttribute1->context();
57 if(!aContext1.get()) {
58 theError = "One of the attribute not initialized.";
61 if(!aLineShape1.get()) {
62 aLineShape1 = aContext1->shape();
64 if(!aLineShape1->isEdge()) {
65 theError = "One of the selected shapes not an edge.";
69 GeomShapePtr aLineShape2 = aLineAttribute2->value();
70 ResultPtr aContext2 = aLineAttribute2->context();
71 if(!aContext2.get()) {
74 if(!aLineShape2.get()) {
75 aLineShape2 = aContext2->shape();
77 if(!aLineShape2->isEdge()) {
78 theError = "One of the selected shapes not an edge.";
82 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
83 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
85 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
86 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
88 if (!aLine1.get() || !aLine2.get()) {
89 theError = "Selected edge is not a line.";
93 if(!aLine1->isCoplanar(aLine2)) {
94 theError = "Selected lines not coplanar.";
98 if(aLine1->isParallel(aLine2)) {
99 theError = "Selected lines are parallel.";
106 //==================================================================================================
107 bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
108 const AttributePtr& theAttribute,
109 const std::list<std::string>& theArguments,
110 Events_InfoMessage& theError) const
112 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
114 AttributeSelectionPtr anAttribute1 =
115 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
116 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
118 std::shared_ptr<GeomAPI_Edge> anEdge;
119 std::shared_ptr<GeomAPI_Face> aFace;
121 GeomShapePtr aShape1 = anAttribute1->value();
122 ResultPtr aContext1 = anAttribute1->context();
123 if(!aContext1.get()) {
124 theError = "One of the attribute not initialized.";
128 aShape1 = aContext1->shape();
131 GeomShapePtr aShape2 = anAttribute2->value();
132 ResultPtr aContext2 = anAttribute2->context();
133 if(!aContext2.get()) {
137 aShape2 = aContext2->shape();
140 bool isPlaneFirst = false;
141 anEdge = getEdge(aShape1);
143 aFace = getFace(aShape2);
144 if(!anEdge.get() || !aFace.get()) {
145 anEdge = getEdge(aShape2);
146 aFace = getFace(aShape1);
150 if(!anEdge.get() || !aFace.get()) {
151 theError = "Wrong shape types selected.";
155 if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aFace)) {
156 theError = "Plane and edge are parallel.";
163 //==================================================================================================
164 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
165 const std::list<std::string>& theArguments,
166 Events_InfoMessage& theError) const
168 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
170 AttributeSelectionPtr aPointAttribute1 =
171 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
172 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
173 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
175 GeomShapePtr aPointShape1 = aPointAttribute1->value();
176 ResultPtr aContext1 = aPointAttribute1->context();
177 if(!aContext1.get()) {
178 theError = "One of the attribute not initialized.";
181 if(!aPointShape1.get()) {
182 aPointShape1 = aContext1->shape();
184 if(!aPointShape1->isVertex()) {
185 theError = "One of the selected shapes not a vertex.";
189 GeomShapePtr aPointShape2 = aPointAttribute2->value();
190 ResultPtr aContext2 = aPointAttribute2->context();
191 if(!aContext2.get()) {
194 if(!aPointShape2.get()) {
195 aPointShape2 = aContext2->shape();
197 if(!aPointShape2->isVertex()) {
198 theError = "One of the selected shapes not a vertex.";
202 GeomShapePtr aPointShape3 = aPointAttribute3->value();
203 ResultPtr aContext3 = aPointAttribute3->context();
204 if(!aContext3.get()) {
207 if(!aPointShape3.get()) {
208 aPointShape3 = aContext3->shape();
210 if(!aPointShape3->isVertex()) {
211 theError = "One of the selected shapes not a vertex.";
215 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
216 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
217 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
219 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
220 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
221 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
223 if (aPnt1->isEqual(aPnt2)) {
224 theError = "Selected points are equal";
228 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
230 if(aLin->contains(aPnt3)) {
231 theError = "Selected points lie on a line.";
238 //==================================================================================================
239 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
240 const AttributePtr& theAttribute,
241 const std::list<std::string>& theArguments,
242 Events_InfoMessage& theError) const
244 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
246 AttributeSelectionPtr anAttribute1 =
247 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
248 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
250 std::shared_ptr<GeomAPI_Lin> aLin;
251 std::shared_ptr<GeomAPI_Pnt> aPnt;
253 GeomShapePtr aShape1 = anAttribute1->value();
254 ResultPtr aContext1 = anAttribute1->context();
255 if(!aContext1.get()) {
256 theError = "One of the attribute not initialized.";
260 aShape1 = aContext1->shape();
263 GeomShapePtr aShape2 = anAttribute2->value();
264 ResultPtr aContext2 = anAttribute2->context();
265 if(!aContext2.get()) {
269 aShape2 = aContext2->shape();
272 aLin = getLin(aShape1);
273 aPnt = getPnt(aShape2);
274 if(!aLin.get() || !aPnt.get()) {
275 aLin = getLin(aShape2);
276 aPnt = getPnt(aShape1);
279 if(!aLin.get() || !aPnt.get()) {
280 theError = "Wrong shape types selected.";
284 // line should not contain point only for not-prependicular case
285 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
286 if (aBoolAttr.get() && !aBoolAttr->value()) {
287 if(aLin->contains(aPnt)) {
288 theError = "Point lies on the line.";
296 //==================================================================================================
297 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
298 const AttributePtr& theAttribute,
299 const std::list<std::string>& theArguments,
300 Events_InfoMessage& theError) const
302 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
304 AttributeSelectionPtr anAttribute1 =
305 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
306 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
308 std::shared_ptr<GeomAPI_Pln> aPln1;
309 std::shared_ptr<GeomAPI_Pln> aPln2;
311 GeomShapePtr aShape1 = anAttribute1->value();
312 ResultPtr aContext1 = anAttribute1->context();
313 if(!aContext1.get()) {
314 theError = "One of the attribute not initialized.";
318 aShape1 = aContext1->shape();
321 GeomShapePtr aShape2 = anAttribute2->value();
322 ResultPtr aContext2 = anAttribute2->context();
323 if(!aContext2.get()) {
327 aShape2 = aContext2->shape();
330 aPln1 = getPln(aShape1);
331 aPln2 = getPln(aShape2);
333 if(!aPln1.get() || !aPln2.get()) {
334 theError = "Wrong shape types selected.";
338 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
339 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
341 if(!aDir1->isParallel(aDir2)) {
342 theError = "Planes not parallel.";
349 //==================================================================================================
350 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
351 const AttributePtr& theAttribute,
352 const std::list<std::string>& theArguments,
353 Events_InfoMessage& theError) const
355 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
357 AttributeSelectionPtr anAttribute1 =
358 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
359 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
361 std::shared_ptr<GeomAPI_Pln> aPln1;
362 std::shared_ptr<GeomAPI_Pln> aPln2;
364 GeomShapePtr aShape1 = anAttribute1->value();
365 ResultPtr aContext1 = anAttribute1->context();
366 if(!aContext1.get()) {
367 theError = "One of the attribute not initialized.";
371 aShape1 = aContext1->shape();
374 GeomShapePtr aShape2 = anAttribute2->value();
375 ResultPtr aContext2 = anAttribute2->context();
376 if(!aContext2.get()) {
380 aShape2 = aContext2->shape();
383 aPln1 = getPln(aShape1);
384 aPln2 = getPln(aShape2);
386 if(!aPln1.get() || !aPln2.get()) {
387 theError = "Wrong shape types selected.";
391 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
392 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
394 if(aDir1->isParallel(aDir2)) {
395 theError = "Planes are parallel.";
402 //==================================================================================================
403 bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid(
404 const AttributePtr& theAttribute,
405 const std::list<std::string>& theArguments,
406 Events_InfoMessage& theError) const
408 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
410 AttributeSelectionPtr anAttribute1 =
411 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
412 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
413 AttributeSelectionPtr anAttribute3 = aFeature->selection(theArguments.back());
415 GeomShapePtr aShape1 = anAttribute1->value();
416 ResultPtr aContext1 = anAttribute1->context();
417 if (!aContext1.get()) {
418 theError = "One of the attribute not initialized.";
421 if (!aShape1.get()) {
422 aShape1 = aContext1->shape();
425 std::shared_ptr<GeomAPI_Pln> aPln1 = getPln(aShape1);
427 theError = "Wrong shape types selected.";
430 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
432 if (anAttribute2.get()) {
433 GeomShapePtr aShape2 = anAttribute2->value();
434 ResultPtr aContext2 = anAttribute2->context();
435 if (!aShape2.get() && aContext2.get()) {
436 aShape2 = aContext2->shape();
440 std::shared_ptr<GeomAPI_Pln> aPln2 = getPln(aShape2);
442 theError = "Wrong shape types selected.";
445 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
446 if (aDir1->isParallel(aDir2)) {
447 theError = "Planes are parallel.";
453 if (anAttribute3.get()) {
454 GeomShapePtr aShape3 = anAttribute3->value();
455 ResultPtr aContext3 = anAttribute3->context();
456 if (!aShape3.get() && aContext3.get()) {
457 aShape3 = aContext3->shape();
461 std::shared_ptr<GeomAPI_Pln> aPln3 = getPln(aShape3);
463 theError = "Wrong shape types selected.";
466 std::shared_ptr<GeomAPI_Dir> aDir3 = aPln3->direction();
467 if (aDir1->isParallel(aDir3)) {
468 theError = "Planes are parallel.";
477 std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
481 if(theShape->isEdge()) {
482 anEdge = theShape->edge();
484 else if (theShape->isCompound()) {
485 GeomAPI_ShapeIterator anIt(theShape);
486 anEdge = anIt.current()->edge();
492 GeomFacePtr getFace(const GeomShapePtr theShape)
496 if (theShape->isFace()) {
497 aFace = theShape->face();
499 else if (theShape->isCompound()) {
500 GeomAPI_ShapeIterator anIt(theShape);
501 aFace = anIt.current()->face();
507 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
509 std::shared_ptr<GeomAPI_Lin> aLin;
513 if (theShape->isEdge()) {
514 anEdge = theShape->edge();
516 else if (theShape->isCompound()) {
517 GeomAPI_ShapeIterator anIt(theShape);
518 anEdge = anIt.current()->edge();
524 if(!anEdge->isLine()) {
528 aLin = anEdge->line();
533 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
535 std::shared_ptr<GeomAPI_Pln> aPln;
539 if(theShape->isFace()) {
540 aFace = theShape->face();
542 else if (theShape->isCompound()) {
543 GeomAPI_ShapeIterator anIt(theShape);
544 aFace = anIt.current()->face();
550 if(!aFace || !aFace->isPlanar()) {
554 aPln = aFace->getPlane();
559 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
561 std::shared_ptr<GeomAPI_Pnt> aPnt;
563 if(!theShape->isVertex()) {
567 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
569 aPnt = aVertex->point();