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->isCoplanar(aLine2)) {
87 theError = "Selected lines not coplanar.";
91 if(aLine1->isParallel(aLine2)) {
92 theError = "Selected lines are parallel.";
99 //==================================================================================================
100 bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
101 const AttributePtr& theAttribute,
102 const std::list<std::string>& theArguments,
103 Events_InfoMessage& theError) const
105 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
107 AttributeSelectionPtr anAttribute1 =
108 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
109 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
111 std::shared_ptr<GeomAPI_Edge> anEdge;
112 std::shared_ptr<GeomAPI_Pln> aPln;
114 GeomShapePtr aShape1 = anAttribute1->value();
115 ResultPtr aContext1 = anAttribute1->context();
116 if(!aContext1.get()) {
117 theError = "One of the attribute not initialized.";
121 aShape1 = aContext1->shape();
124 GeomShapePtr aShape2 = anAttribute2->value();
125 ResultPtr aContext2 = anAttribute2->context();
126 if(!aContext2.get()) {
130 aShape2 = aContext2->shape();
133 bool isPlaneFirst = false;
134 anEdge = getEdge(aShape1);
135 aPln = getPln(aShape2);
136 if(!anEdge.get() || !aPln.get()) {
137 anEdge = getEdge(aShape2);
138 aPln = getPln(aShape1);
142 if(!anEdge.get() || !aPln.get()) {
143 theError = "Wrong shape types selected.";
147 std::shared_ptr<GeomAPI_Face> aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2));
148 if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) {
149 theError = "Plane and edge are parallel.";
156 //==================================================================================================
157 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
158 const std::list<std::string>& theArguments,
159 Events_InfoMessage& theError) const
161 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
163 AttributeSelectionPtr aPointAttribute1 =
164 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
165 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
166 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
168 GeomShapePtr aPointShape1 = aPointAttribute1->value();
169 ResultPtr aContext1 = aPointAttribute1->context();
170 if(!aContext1.get()) {
171 theError = "One of the attribute not initialized.";
174 if(!aPointShape1.get()) {
175 aPointShape1 = aContext1->shape();
177 if(!aPointShape1->isVertex()) {
178 theError = "One of the selected shapes not a vertex.";
182 GeomShapePtr aPointShape2 = aPointAttribute2->value();
183 ResultPtr aContext2 = aPointAttribute2->context();
184 if(!aContext2.get()) {
187 if(!aPointShape2.get()) {
188 aPointShape2 = aContext2->shape();
190 if(!aPointShape2->isVertex()) {
191 theError = "One of the selected shapes not a vertex.";
195 GeomShapePtr aPointShape3 = aPointAttribute3->value();
196 ResultPtr aContext3 = aPointAttribute3->context();
197 if(!aContext3.get()) {
200 if(!aPointShape3.get()) {
201 aPointShape3 = aContext3->shape();
203 if(!aPointShape3->isVertex()) {
204 theError = "One of the selected shapes not a vertex.";
208 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
209 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
210 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
212 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
213 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
214 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
216 if (aPnt1->isEqual(aPnt2)) {
217 theError = "Selected points are equal";
221 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
223 if(aLin->contains(aPnt3)) {
224 theError = "Selected points lie on a line.";
231 //==================================================================================================
232 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
233 const AttributePtr& theAttribute,
234 const std::list<std::string>& theArguments,
235 Events_InfoMessage& theError) const
237 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
239 AttributeSelectionPtr anAttribute1 =
240 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
241 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
243 std::shared_ptr<GeomAPI_Lin> aLin;
244 std::shared_ptr<GeomAPI_Pnt> aPnt;
246 GeomShapePtr aShape1 = anAttribute1->value();
247 ResultPtr aContext1 = anAttribute1->context();
248 if(!aContext1.get()) {
249 theError = "One of the attribute not initialized.";
253 aShape1 = aContext1->shape();
256 GeomShapePtr aShape2 = anAttribute2->value();
257 ResultPtr aContext2 = anAttribute2->context();
258 if(!aContext2.get()) {
262 aShape2 = aContext2->shape();
265 aLin = getLin(aShape1);
266 aPnt = getPnt(aShape2);
267 if(!aLin.get() || !aPnt.get()) {
268 aLin = getLin(aShape2);
269 aPnt = getPnt(aShape1);
272 if(!aLin.get() || !aPnt.get()) {
273 theError = "Wrong shape types selected.";
277 // line should not contain point only for not-prependicular case
278 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
279 if (aBoolAttr.get() && !aBoolAttr->value()) {
280 if(aLin->contains(aPnt)) {
281 theError = "Point lies on the line.";
289 //==================================================================================================
290 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
291 const AttributePtr& theAttribute,
292 const std::list<std::string>& theArguments,
293 Events_InfoMessage& theError) const
295 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
297 AttributeSelectionPtr anAttribute1 =
298 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
299 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
301 std::shared_ptr<GeomAPI_Pln> aPln1;
302 std::shared_ptr<GeomAPI_Pln> aPln2;
304 GeomShapePtr aShape1 = anAttribute1->value();
305 ResultPtr aContext1 = anAttribute1->context();
306 if(!aContext1.get()) {
307 theError = "One of the attribute not initialized.";
311 aShape1 = aContext1->shape();
314 GeomShapePtr aShape2 = anAttribute2->value();
315 ResultPtr aContext2 = anAttribute2->context();
316 if(!aContext2.get()) {
320 aShape2 = aContext2->shape();
323 aPln1 = getPln(aShape1);
324 aPln2 = getPln(aShape2);
326 if(!aPln1.get() || !aPln2.get()) {
327 theError = "Wrong shape types selected.";
331 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
332 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
334 if(!aDir1->isParallel(aDir2)) {
335 theError = "Planes not parallel.";
342 //==================================================================================================
343 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
344 const AttributePtr& theAttribute,
345 const std::list<std::string>& theArguments,
346 Events_InfoMessage& theError) const
348 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
350 AttributeSelectionPtr anAttribute1 =
351 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
352 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
354 std::shared_ptr<GeomAPI_Pln> aPln1;
355 std::shared_ptr<GeomAPI_Pln> aPln2;
357 GeomShapePtr aShape1 = anAttribute1->value();
358 ResultPtr aContext1 = anAttribute1->context();
359 if(!aContext1.get()) {
360 theError = "One of the attribute not initialized.";
364 aShape1 = aContext1->shape();
367 GeomShapePtr aShape2 = anAttribute2->value();
368 ResultPtr aContext2 = anAttribute2->context();
369 if(!aContext2.get()) {
373 aShape2 = aContext2->shape();
376 aPln1 = getPln(aShape1);
377 aPln2 = getPln(aShape2);
379 if(!aPln1.get() || !aPln2.get()) {
380 theError = "Wrong shape types selected.";
384 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
385 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
387 if(aDir1->isParallel(aDir2)) {
388 theError = "Planes are parallel.";
395 std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
397 if(!theShape->isEdge()) {
398 return std::shared_ptr<GeomAPI_Edge>();
401 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
406 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
408 std::shared_ptr<GeomAPI_Lin> aLin;
410 if(!theShape->isEdge()) {
414 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
416 if(!anEdge->isLine()) {
420 aLin = anEdge->line();
425 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
427 std::shared_ptr<GeomAPI_Pln> aPln;
429 if(!theShape->isFace()) {
433 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
435 if(!aFace->isPlanar()) {
439 aPln = aFace->getPlane();
444 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
446 std::shared_ptr<GeomAPI_Pnt> aPnt;
448 if(!theShape->isVertex()) {
452 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
454 aPnt = aVertex->point();