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 <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_Lin> getLin(const GeomShapePtr theShape);
39 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
40 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
42 //==================================================================================================
43 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
44 const std::list<std::string>& theArguments,
45 Events_InfoMessage& theError) const
47 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
49 AttributeSelectionPtr aLineAttribute1 =
50 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
51 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
53 GeomShapePtr aLineShape1 = aLineAttribute1->value();
54 ResultPtr aContext1 = aLineAttribute1->context();
55 if(!aContext1.get()) {
56 theError = "One of the attribute not initialized.";
59 if(!aLineShape1.get()) {
60 aLineShape1 = aContext1->shape();
62 if(!aLineShape1->isEdge()) {
63 theError = "One of the selected shapes not an edge.";
67 GeomShapePtr aLineShape2 = aLineAttribute2->value();
68 ResultPtr aContext2 = aLineAttribute2->context();
69 if(!aContext2.get()) {
72 if(!aLineShape2.get()) {
73 aLineShape2 = aContext2->shape();
75 if(!aLineShape2->isEdge()) {
76 theError = "One of the selected shapes not an edge.";
80 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
81 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
83 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
84 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
86 if (!aLine1.get() || !aLine2.get()) {
87 theError = "Selected edge is not a line.";
91 if(!aLine1->isCoplanar(aLine2)) {
92 theError = "Selected lines not coplanar.";
96 if(aLine1->isParallel(aLine2)) {
97 theError = "Selected lines are parallel.";
104 //==================================================================================================
105 bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
106 const AttributePtr& theAttribute,
107 const std::list<std::string>& theArguments,
108 Events_InfoMessage& theError) const
110 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
112 AttributeSelectionPtr anAttribute1 =
113 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
114 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
116 std::shared_ptr<GeomAPI_Edge> anEdge;
117 std::shared_ptr<GeomAPI_Pln> aPln;
119 GeomShapePtr aShape1 = anAttribute1->value();
120 ResultPtr aContext1 = anAttribute1->context();
121 if(!aContext1.get()) {
122 theError = "One of the attribute not initialized.";
126 aShape1 = aContext1->shape();
129 GeomShapePtr aShape2 = anAttribute2->value();
130 ResultPtr aContext2 = anAttribute2->context();
131 if(!aContext2.get()) {
135 aShape2 = aContext2->shape();
138 bool isPlaneFirst = false;
139 anEdge = getEdge(aShape1);
140 aPln = getPln(aShape2);
141 if(!anEdge.get() || !aPln.get()) {
142 anEdge = getEdge(aShape2);
143 aPln = getPln(aShape1);
147 if(!anEdge.get() || !aPln.get()) {
148 theError = "Wrong shape types selected.";
152 std::shared_ptr<GeomAPI_Face> aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2));
153 if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) {
154 theError = "Plane and edge are parallel.";
161 //==================================================================================================
162 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
163 const std::list<std::string>& theArguments,
164 Events_InfoMessage& theError) const
166 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
168 AttributeSelectionPtr aPointAttribute1 =
169 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
170 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
171 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
173 GeomShapePtr aPointShape1 = aPointAttribute1->value();
174 ResultPtr aContext1 = aPointAttribute1->context();
175 if(!aContext1.get()) {
176 theError = "One of the attribute not initialized.";
179 if(!aPointShape1.get()) {
180 aPointShape1 = aContext1->shape();
182 if(!aPointShape1->isVertex()) {
183 theError = "One of the selected shapes not a vertex.";
187 GeomShapePtr aPointShape2 = aPointAttribute2->value();
188 ResultPtr aContext2 = aPointAttribute2->context();
189 if(!aContext2.get()) {
192 if(!aPointShape2.get()) {
193 aPointShape2 = aContext2->shape();
195 if(!aPointShape2->isVertex()) {
196 theError = "One of the selected shapes not a vertex.";
200 GeomShapePtr aPointShape3 = aPointAttribute3->value();
201 ResultPtr aContext3 = aPointAttribute3->context();
202 if(!aContext3.get()) {
205 if(!aPointShape3.get()) {
206 aPointShape3 = aContext3->shape();
208 if(!aPointShape3->isVertex()) {
209 theError = "One of the selected shapes not a vertex.";
213 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
214 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
215 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
217 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
218 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
219 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
221 if (aPnt1->isEqual(aPnt2)) {
222 theError = "Selected points are equal";
226 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
228 if(aLin->contains(aPnt3)) {
229 theError = "Selected points lie on a line.";
236 //==================================================================================================
237 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
238 const AttributePtr& theAttribute,
239 const std::list<std::string>& theArguments,
240 Events_InfoMessage& theError) const
242 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
244 AttributeSelectionPtr anAttribute1 =
245 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
246 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
248 std::shared_ptr<GeomAPI_Lin> aLin;
249 std::shared_ptr<GeomAPI_Pnt> aPnt;
251 GeomShapePtr aShape1 = anAttribute1->value();
252 ResultPtr aContext1 = anAttribute1->context();
253 if(!aContext1.get()) {
254 theError = "One of the attribute not initialized.";
258 aShape1 = aContext1->shape();
261 GeomShapePtr aShape2 = anAttribute2->value();
262 ResultPtr aContext2 = anAttribute2->context();
263 if(!aContext2.get()) {
267 aShape2 = aContext2->shape();
270 aLin = getLin(aShape1);
271 aPnt = getPnt(aShape2);
272 if(!aLin.get() || !aPnt.get()) {
273 aLin = getLin(aShape2);
274 aPnt = getPnt(aShape1);
277 if(!aLin.get() || !aPnt.get()) {
278 theError = "Wrong shape types selected.";
282 // line should not contain point only for not-prependicular case
283 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
284 if (aBoolAttr.get() && !aBoolAttr->value()) {
285 if(aLin->contains(aPnt)) {
286 theError = "Point lies on the line.";
294 //==================================================================================================
295 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
296 const AttributePtr& theAttribute,
297 const std::list<std::string>& theArguments,
298 Events_InfoMessage& theError) const
300 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
302 AttributeSelectionPtr anAttribute1 =
303 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
304 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
306 std::shared_ptr<GeomAPI_Pln> aPln1;
307 std::shared_ptr<GeomAPI_Pln> aPln2;
309 GeomShapePtr aShape1 = anAttribute1->value();
310 ResultPtr aContext1 = anAttribute1->context();
311 if(!aContext1.get()) {
312 theError = "One of the attribute not initialized.";
316 aShape1 = aContext1->shape();
319 GeomShapePtr aShape2 = anAttribute2->value();
320 ResultPtr aContext2 = anAttribute2->context();
321 if(!aContext2.get()) {
325 aShape2 = aContext2->shape();
328 aPln1 = getPln(aShape1);
329 aPln2 = getPln(aShape2);
331 if(!aPln1.get() || !aPln2.get()) {
332 theError = "Wrong shape types selected.";
336 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
337 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
339 if(!aDir1->isParallel(aDir2)) {
340 theError = "Planes not parallel.";
347 //==================================================================================================
348 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
349 const AttributePtr& theAttribute,
350 const std::list<std::string>& theArguments,
351 Events_InfoMessage& theError) const
353 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
355 AttributeSelectionPtr anAttribute1 =
356 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
357 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
359 std::shared_ptr<GeomAPI_Pln> aPln1;
360 std::shared_ptr<GeomAPI_Pln> aPln2;
362 GeomShapePtr aShape1 = anAttribute1->value();
363 ResultPtr aContext1 = anAttribute1->context();
364 if(!aContext1.get()) {
365 theError = "One of the attribute not initialized.";
369 aShape1 = aContext1->shape();
372 GeomShapePtr aShape2 = anAttribute2->value();
373 ResultPtr aContext2 = anAttribute2->context();
374 if(!aContext2.get()) {
378 aShape2 = aContext2->shape();
381 aPln1 = getPln(aShape1);
382 aPln2 = getPln(aShape2);
384 if(!aPln1.get() || !aPln2.get()) {
385 theError = "Wrong shape types selected.";
389 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
390 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
392 if(aDir1->isParallel(aDir2)) {
393 theError = "Planes are parallel.";
400 //==================================================================================================
401 bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid(
402 const AttributePtr& theAttribute,
403 const std::list<std::string>& theArguments,
404 Events_InfoMessage& theError) const
406 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
408 AttributeSelectionPtr anAttribute1 =
409 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
410 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
411 AttributeSelectionPtr anAttribute3 = aFeature->selection(theArguments.back());
413 GeomShapePtr aShape1 = anAttribute1->value();
414 ResultPtr aContext1 = anAttribute1->context();
415 if (!aContext1.get()) {
416 theError = "One of the attribute not initialized.";
419 if (!aShape1.get()) {
420 aShape1 = aContext1->shape();
423 std::shared_ptr<GeomAPI_Pln> aPln1 = getPln(aShape1);
425 theError = "Wrong shape types selected.";
428 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
430 if (anAttribute2.get()) {
431 GeomShapePtr aShape2 = anAttribute2->value();
432 ResultPtr aContext2 = anAttribute2->context();
433 if (!aShape2.get() && aContext2.get()) {
434 aShape2 = aContext2->shape();
438 std::shared_ptr<GeomAPI_Pln> aPln2 = getPln(aShape2);
440 theError = "Wrong shape types selected.";
443 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
444 if (aDir1->isParallel(aDir2)) {
445 theError = "Planes are parallel.";
451 if (anAttribute3.get()) {
452 GeomShapePtr aShape3 = anAttribute3->value();
453 ResultPtr aContext3 = anAttribute3->context();
454 if (!aShape3.get() && aContext3.get()) {
455 aShape3 = aContext3->shape();
459 std::shared_ptr<GeomAPI_Pln> aPln3 = getPln(aShape3);
461 theError = "Wrong shape types selected.";
464 std::shared_ptr<GeomAPI_Dir> aDir3 = aPln3->direction();
465 if (aDir1->isParallel(aDir3)) {
466 theError = "Planes are parallel.";
475 std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
477 if(!theShape->isEdge()) {
478 return std::shared_ptr<GeomAPI_Edge>();
481 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
486 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
488 std::shared_ptr<GeomAPI_Lin> aLin;
490 if(!theShape->isEdge()) {
494 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
496 if(!anEdge->isLine()) {
500 aLin = anEdge->line();
505 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
507 std::shared_ptr<GeomAPI_Pln> aPln;
509 if(!theShape->isFace()) {
513 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
515 if(!aFace->isPlanar()) {
519 aPln = aFace->getPlane();
524 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
526 std::shared_ptr<GeomAPI_Pnt> aPnt;
528 if(!theShape->isVertex()) {
532 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
534 aPnt = aVertex->point();