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 <GeomAlgoAPI_ShapeTools.h>
31 #include <ModelAPI_AttributeSelection.h>
32 #include <ModelAPI_AttributeBoolean.h>
34 #include <Events_InfoMessage.h>
36 static std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape);
37 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
38 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
39 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
41 //==================================================================================================
42 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
43 const std::list<std::string>& theArguments,
44 Events_InfoMessage& theError) const
46 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
48 AttributeSelectionPtr aLineAttribute1 =
49 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
50 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
52 GeomShapePtr aLineShape1 = aLineAttribute1->value();
53 ResultPtr aContext1 = aLineAttribute1->context();
54 if(!aContext1.get()) {
55 theError = "One of the attribute not initialized.";
58 if(!aLineShape1.get()) {
59 aLineShape1 = aContext1->shape();
61 if(!aLineShape1->isEdge()) {
62 theError = "One of the selected shapes not an edge.";
66 GeomShapePtr aLineShape2 = aLineAttribute2->value();
67 ResultPtr aContext2 = aLineAttribute2->context();
68 if(!aContext2.get()) {
71 if(!aLineShape2.get()) {
72 aLineShape2 = aContext2->shape();
74 if(!aLineShape2->isEdge()) {
75 theError = "One of the selected shapes not an edge.";
79 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
80 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
82 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
83 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
85 if(!aLine1->isCoplanar(aLine2)) {
86 theError = "Selected lines not coplanar.";
90 if(aLine1->isParallel(aLine2)) {
91 theError = "Selected lines are parallel.";
98 //==================================================================================================
99 bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
100 const AttributePtr& theAttribute,
101 const std::list<std::string>& theArguments,
102 Events_InfoMessage& theError) const
104 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
106 AttributeSelectionPtr anAttribute1 =
107 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
108 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
110 std::shared_ptr<GeomAPI_Edge> anEdge;
111 std::shared_ptr<GeomAPI_Pln> aPln;
113 GeomShapePtr aShape1 = anAttribute1->value();
114 ResultPtr aContext1 = anAttribute1->context();
115 if(!aContext1.get()) {
116 theError = "One of the attribute not initialized.";
120 aShape1 = aContext1->shape();
123 GeomShapePtr aShape2 = anAttribute2->value();
124 ResultPtr aContext2 = anAttribute2->context();
125 if(!aContext2.get()) {
129 aShape2 = aContext2->shape();
132 bool isPlaneFirst = false;
133 anEdge = getEdge(aShape1);
134 aPln = getPln(aShape2);
135 if(!anEdge.get() || !aPln.get()) {
136 anEdge = getEdge(aShape2);
137 aPln = getPln(aShape1);
141 if(!anEdge.get() || !aPln.get()) {
142 theError = "Wrong shape types selected.";
146 std::shared_ptr<GeomAPI_Face> aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2));
147 if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) {
148 theError = "Plane and edge are parallel.";
155 //==================================================================================================
156 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
157 const std::list<std::string>& theArguments,
158 Events_InfoMessage& theError) const
160 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
162 AttributeSelectionPtr aPointAttribute1 =
163 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
164 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
165 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
167 GeomShapePtr aPointShape1 = aPointAttribute1->value();
168 ResultPtr aContext1 = aPointAttribute1->context();
169 if(!aContext1.get()) {
170 theError = "One of the attribute not initialized.";
173 if(!aPointShape1.get()) {
174 aPointShape1 = aContext1->shape();
176 if(!aPointShape1->isVertex()) {
177 theError = "One of the selected shapes not a vertex.";
181 GeomShapePtr aPointShape2 = aPointAttribute2->value();
182 ResultPtr aContext2 = aPointAttribute2->context();
183 if(!aContext2.get()) {
186 if(!aPointShape2.get()) {
187 aPointShape2 = aContext2->shape();
189 if(!aPointShape2->isVertex()) {
190 theError = "One of the selected shapes not a vertex.";
194 GeomShapePtr aPointShape3 = aPointAttribute3->value();
195 ResultPtr aContext3 = aPointAttribute3->context();
196 if(!aContext3.get()) {
199 if(!aPointShape3.get()) {
200 aPointShape3 = aContext3->shape();
202 if(!aPointShape3->isVertex()) {
203 theError = "One of the selected shapes not a vertex.";
207 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
208 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
209 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
211 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
212 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
213 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
215 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
217 if(aLin->contains(aPnt3)) {
218 theError = "Selected points lie on a line.";
225 //==================================================================================================
226 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
227 const AttributePtr& theAttribute,
228 const std::list<std::string>& theArguments,
229 Events_InfoMessage& theError) const
231 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
233 AttributeSelectionPtr anAttribute1 =
234 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
235 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
237 std::shared_ptr<GeomAPI_Lin> aLin;
238 std::shared_ptr<GeomAPI_Pnt> aPnt;
240 GeomShapePtr aShape1 = anAttribute1->value();
241 ResultPtr aContext1 = anAttribute1->context();
242 if(!aContext1.get()) {
243 theError = "One of the attribute not initialized.";
247 aShape1 = aContext1->shape();
250 GeomShapePtr aShape2 = anAttribute2->value();
251 ResultPtr aContext2 = anAttribute2->context();
252 if(!aContext2.get()) {
256 aShape2 = aContext2->shape();
259 aLin = getLin(aShape1);
260 aPnt = getPnt(aShape2);
261 if(!aLin.get() || !aPnt.get()) {
262 aLin = getLin(aShape2);
263 aPnt = getPnt(aShape1);
266 if(!aLin.get() || !aPnt.get()) {
267 theError = "Wrong shape types selected.";
271 // line should not contain point only for not-prependicular case
272 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
273 if (aBoolAttr.get() && !aBoolAttr->value()) {
274 if(aLin->contains(aPnt)) {
275 theError = "Point lies on the line.";
283 //==================================================================================================
284 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
285 const AttributePtr& theAttribute,
286 const std::list<std::string>& theArguments,
287 Events_InfoMessage& theError) const
289 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
291 AttributeSelectionPtr anAttribute1 =
292 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
293 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
295 std::shared_ptr<GeomAPI_Pln> aPln1;
296 std::shared_ptr<GeomAPI_Pln> aPln2;
298 GeomShapePtr aShape1 = anAttribute1->value();
299 ResultPtr aContext1 = anAttribute1->context();
300 if(!aContext1.get()) {
301 theError = "One of the attribute not initialized.";
305 aShape1 = aContext1->shape();
308 GeomShapePtr aShape2 = anAttribute2->value();
309 ResultPtr aContext2 = anAttribute2->context();
310 if(!aContext2.get()) {
314 aShape2 = aContext2->shape();
317 aPln1 = getPln(aShape1);
318 aPln2 = getPln(aShape2);
320 if(!aPln1.get() || !aPln2.get()) {
321 theError = "Wrong shape types selected.";
325 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
326 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
328 if(!aDir1->isParallel(aDir2)) {
329 theError = "Planes not parallel.";
336 //==================================================================================================
337 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
338 const AttributePtr& theAttribute,
339 const std::list<std::string>& theArguments,
340 Events_InfoMessage& theError) const
342 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
344 AttributeSelectionPtr anAttribute1 =
345 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
346 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
348 std::shared_ptr<GeomAPI_Pln> aPln1;
349 std::shared_ptr<GeomAPI_Pln> aPln2;
351 GeomShapePtr aShape1 = anAttribute1->value();
352 ResultPtr aContext1 = anAttribute1->context();
353 if(!aContext1.get()) {
354 theError = "One of the attribute not initialized.";
358 aShape1 = aContext1->shape();
361 GeomShapePtr aShape2 = anAttribute2->value();
362 ResultPtr aContext2 = anAttribute2->context();
363 if(!aContext2.get()) {
367 aShape2 = aContext2->shape();
370 aPln1 = getPln(aShape1);
371 aPln2 = getPln(aShape2);
373 if(!aPln1.get() || !aPln2.get()) {
374 theError = "Wrong shape types selected.";
378 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
379 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
381 if(aDir1->isParallel(aDir2)) {
382 theError = "Planes are parallel.";
389 std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
391 if(!theShape->isEdge()) {
392 return std::shared_ptr<GeomAPI_Edge>();
395 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
400 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
402 std::shared_ptr<GeomAPI_Lin> aLin;
404 if(!theShape->isEdge()) {
408 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
410 if(!anEdge->isLine()) {
414 aLin = anEdge->line();
419 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
421 std::shared_ptr<GeomAPI_Pln> aPln;
423 if(!theShape->isFace()) {
427 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
429 if(!aFace->isPlanar()) {
433 aPln = aFace->getPlane();
438 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
440 std::shared_ptr<GeomAPI_Pnt> aPnt;
442 if(!theShape->isVertex()) {
446 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
448 aPnt = aVertex->point();