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 email : webmaster.salome@opencascade.com<mailto: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>
29 #include <ModelAPI_AttributeSelection.h>
30 #include <ModelAPI_AttributeBoolean.h>
32 #include <Events_InfoMessage.h>
34 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
35 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
36 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
38 //==================================================================================================
39 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
40 const std::list<std::string>& theArguments,
41 Events_InfoMessage& theError) const
43 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
45 AttributeSelectionPtr aLineAttribute1 =
46 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
47 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
49 GeomShapePtr aLineShape1 = aLineAttribute1->value();
50 ResultPtr aContext1 = aLineAttribute1->context();
51 if(!aContext1.get()) {
52 theError = "One of the attribute not initialized.";
55 if(!aLineShape1.get()) {
56 aLineShape1 = aContext1->shape();
58 if(!aLineShape1->isEdge()) {
59 theError = "One of the selected shapes not an edge.";
63 GeomShapePtr aLineShape2 = aLineAttribute2->value();
64 ResultPtr aContext2 = aLineAttribute2->context();
65 if(!aContext2.get()) {
68 if(!aLineShape2.get()) {
69 aLineShape2 = aContext2->shape();
71 if(!aLineShape2->isEdge()) {
72 theError = "One of the selected shapes not an edge.";
76 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
77 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
79 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
80 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
82 if(!aLine1->isCoplanar(aLine2)) {
83 theError = "Selected lines not coplanar.";
87 if(aLine1->isParallel(aLine2)) {
88 theError = "Selected lines are parallel.";
95 //==================================================================================================
96 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
97 const AttributePtr& theAttribute,
98 const std::list<std::string>& theArguments,
99 Events_InfoMessage& theError) const
101 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
103 AttributeSelectionPtr anAttribute1 =
104 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
105 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
107 std::shared_ptr<GeomAPI_Lin> aLin;
108 std::shared_ptr<GeomAPI_Pln> aPln;
110 GeomShapePtr aShape1 = anAttribute1->value();
111 ResultPtr aContext1 = anAttribute1->context();
112 if(!aContext1.get()) {
113 theError = "One of the attribute not initialized.";
117 aShape1 = aContext1->shape();
120 GeomShapePtr aShape2 = anAttribute2->value();
121 ResultPtr aContext2 = anAttribute2->context();
122 if(!aContext2.get()) {
126 aShape2 = aContext2->shape();
129 aLin = getLin(aShape1);
130 aPln = getPln(aShape2);
131 if(!aLin.get() || !aPln.get()) {
132 aLin = getLin(aShape2);
133 aPln = getPln(aShape1);
136 if(!aLin.get() || !aPln.get()) {
137 theError = "Wrong shape types selected.";
141 if(aPln->isParallel(aLin)) {
142 theError = "Plane and line are parallel.";
149 //==================================================================================================
150 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
151 const std::list<std::string>& theArguments,
152 Events_InfoMessage& theError) const
154 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
156 AttributeSelectionPtr aPointAttribute1 =
157 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
158 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
159 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
161 GeomShapePtr aPointShape1 = aPointAttribute1->value();
162 ResultPtr aContext1 = aPointAttribute1->context();
163 if(!aContext1.get()) {
164 theError = "One of the attribute not initialized.";
167 if(!aPointShape1.get()) {
168 aPointShape1 = aContext1->shape();
170 if(!aPointShape1->isVertex()) {
171 theError = "One of the selected shapes not a vertex.";
175 GeomShapePtr aPointShape2 = aPointAttribute2->value();
176 ResultPtr aContext2 = aPointAttribute2->context();
177 if(!aContext2.get()) {
180 if(!aPointShape2.get()) {
181 aPointShape2 = aContext2->shape();
183 if(!aPointShape2->isVertex()) {
184 theError = "One of the selected shapes not a vertex.";
188 GeomShapePtr aPointShape3 = aPointAttribute3->value();
189 ResultPtr aContext3 = aPointAttribute3->context();
190 if(!aContext3.get()) {
193 if(!aPointShape3.get()) {
194 aPointShape3 = aContext3->shape();
196 if(!aPointShape3->isVertex()) {
197 theError = "One of the selected shapes not a vertex.";
201 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
202 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
203 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
205 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
206 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
207 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
209 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
211 if(aLin->contains(aPnt3)) {
212 theError = "Selected points lie on a line.";
219 //==================================================================================================
220 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
221 const AttributePtr& theAttribute,
222 const std::list<std::string>& theArguments,
223 Events_InfoMessage& theError) const
225 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
227 AttributeSelectionPtr anAttribute1 =
228 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
229 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
231 std::shared_ptr<GeomAPI_Lin> aLin;
232 std::shared_ptr<GeomAPI_Pnt> aPnt;
234 GeomShapePtr aShape1 = anAttribute1->value();
235 ResultPtr aContext1 = anAttribute1->context();
236 if(!aContext1.get()) {
237 theError = "One of the attribute not initialized.";
241 aShape1 = aContext1->shape();
244 GeomShapePtr aShape2 = anAttribute2->value();
245 ResultPtr aContext2 = anAttribute2->context();
246 if(!aContext2.get()) {
250 aShape2 = aContext2->shape();
253 aLin = getLin(aShape1);
254 aPnt = getPnt(aShape2);
255 if(!aLin.get() || !aPnt.get()) {
256 aLin = getLin(aShape2);
257 aPnt = getPnt(aShape1);
260 if(!aLin.get() || !aPnt.get()) {
261 theError = "Wrong shape types selected.";
265 // line should not contain point only for not-prependicular case
266 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
267 if (aBoolAttr.get() && !aBoolAttr->value()) {
268 if(aLin->contains(aPnt)) {
269 theError = "Point lies on the line.";
277 //==================================================================================================
278 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
279 const AttributePtr& theAttribute,
280 const std::list<std::string>& theArguments,
281 Events_InfoMessage& theError) const
283 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
285 AttributeSelectionPtr anAttribute1 =
286 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
287 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
289 std::shared_ptr<GeomAPI_Pln> aPln1;
290 std::shared_ptr<GeomAPI_Pln> aPln2;
292 GeomShapePtr aShape1 = anAttribute1->value();
293 ResultPtr aContext1 = anAttribute1->context();
294 if(!aContext1.get()) {
295 theError = "One of the attribute not initialized.";
299 aShape1 = aContext1->shape();
302 GeomShapePtr aShape2 = anAttribute2->value();
303 ResultPtr aContext2 = anAttribute2->context();
304 if(!aContext2.get()) {
308 aShape2 = aContext2->shape();
311 aPln1 = getPln(aShape1);
312 aPln2 = getPln(aShape2);
314 if(!aPln1.get() || !aPln2.get()) {
315 theError = "Wrong shape types selected.";
319 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
320 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
322 if(!aDir1->isParallel(aDir2)) {
323 theError = "Planes not parallel.";
330 //==================================================================================================
331 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
332 const AttributePtr& theAttribute,
333 const std::list<std::string>& theArguments,
334 Events_InfoMessage& theError) const
336 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
338 AttributeSelectionPtr anAttribute1 =
339 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
340 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
342 std::shared_ptr<GeomAPI_Pln> aPln1;
343 std::shared_ptr<GeomAPI_Pln> aPln2;
345 GeomShapePtr aShape1 = anAttribute1->value();
346 ResultPtr aContext1 = anAttribute1->context();
347 if(!aContext1.get()) {
348 theError = "One of the attribute not initialized.";
352 aShape1 = aContext1->shape();
355 GeomShapePtr aShape2 = anAttribute2->value();
356 ResultPtr aContext2 = anAttribute2->context();
357 if(!aContext2.get()) {
361 aShape2 = aContext2->shape();
364 aPln1 = getPln(aShape1);
365 aPln2 = getPln(aShape2);
367 if(!aPln1.get() || !aPln2.get()) {
368 theError = "Wrong shape types selected.";
372 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
373 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
375 if(aDir1->isParallel(aDir2)) {
376 theError = "Planes are parallel.";
383 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
385 std::shared_ptr<GeomAPI_Lin> aLin;
387 if(!theShape->isEdge()) {
391 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
393 if(!anEdge->isLine()) {
397 aLin = anEdge->line();
402 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
404 std::shared_ptr<GeomAPI_Pln> aPln;
406 if(!theShape->isFace()) {
410 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
412 if(!aFace->isPlanar()) {
416 aPln = aFace->getPlane();
421 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
423 std::shared_ptr<GeomAPI_Pnt> aPnt;
425 if(!theShape->isVertex()) {
429 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
431 aPnt = aVertex->point();