1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: ConstructionPlugin_Validators.cpp
4 // Created: 04 July 2016
5 // Author: Dmitry Bobylev
7 #include "ConstructionPlugin_Validators.h"
9 #include <GeomAPI_Dir.h>
10 #include <GeomAPI_Edge.h>
11 #include <GeomAPI_Face.h>
12 #include <GeomAPI_Lin.h>
13 #include <GeomAPI_Pln.h>
14 #include <GeomAPI_Vertex.h>
16 #include <ModelAPI_AttributeSelection.h>
17 #include <ModelAPI_AttributeBoolean.h>
19 #include <Events_InfoMessage.h>
21 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
22 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
23 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
25 //==================================================================================================
26 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
27 const std::list<std::string>& theArguments,
28 Events_InfoMessage& theError) const
30 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
32 AttributeSelectionPtr aLineAttribute1 =
33 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
34 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
36 GeomShapePtr aLineShape1 = aLineAttribute1->value();
37 ResultPtr aContext1 = aLineAttribute1->context();
38 if(!aContext1.get()) {
39 theError = "One of the attribute not initialized.";
42 if(!aLineShape1.get()) {
43 aLineShape1 = aContext1->shape();
45 if(!aLineShape1->isEdge()) {
46 theError = "One of the selected shapes not an edge.";
50 GeomShapePtr aLineShape2 = aLineAttribute2->value();
51 ResultPtr aContext2 = aLineAttribute2->context();
52 if(!aContext2.get()) {
55 if(!aLineShape2.get()) {
56 aLineShape2 = aContext2->shape();
58 if(!aLineShape2->isEdge()) {
59 theError = "One of the selected shapes not an edge.";
63 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
64 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
66 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
67 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
69 if(!aLine1->isCoplanar(aLine2)) {
70 theError = "Selected lines not coplanar.";
74 if(aLine1->isParallel(aLine2)) {
75 theError = "Selected lines are parallel.";
82 //==================================================================================================
83 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
84 const AttributePtr& theAttribute,
85 const std::list<std::string>& theArguments,
86 Events_InfoMessage& theError) const
88 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
90 AttributeSelectionPtr anAttribute1 =
91 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
92 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
94 std::shared_ptr<GeomAPI_Lin> aLin;
95 std::shared_ptr<GeomAPI_Pln> aPln;
97 GeomShapePtr aShape1 = anAttribute1->value();
98 ResultPtr aContext1 = anAttribute1->context();
99 if(!aContext1.get()) {
100 theError = "One of the attribute not initialized.";
104 aShape1 = aContext1->shape();
107 GeomShapePtr aShape2 = anAttribute2->value();
108 ResultPtr aContext2 = anAttribute2->context();
109 if(!aContext2.get()) {
113 aShape2 = aContext2->shape();
116 aLin = getLin(aShape1);
117 aPln = getPln(aShape2);
118 if(!aLin.get() || !aPln.get()) {
119 aLin = getLin(aShape2);
120 aPln = getPln(aShape1);
123 if(!aLin.get() || !aPln.get()) {
124 theError = "Wrong shape types selected.";
128 if(aPln->isParallel(aLin)) {
129 theError = "Plane and line are parallel.";
136 //==================================================================================================
137 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
138 const std::list<std::string>& theArguments,
139 Events_InfoMessage& theError) const
141 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
143 AttributeSelectionPtr aPointAttribute1 =
144 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
145 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
146 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
148 GeomShapePtr aPointShape1 = aPointAttribute1->value();
149 ResultPtr aContext1 = aPointAttribute1->context();
150 if(!aContext1.get()) {
151 theError = "One of the attribute not initialized.";
154 if(!aPointShape1.get()) {
155 aPointShape1 = aContext1->shape();
157 if(!aPointShape1->isVertex()) {
158 theError = "One of the selected shapes not a vertex.";
162 GeomShapePtr aPointShape2 = aPointAttribute2->value();
163 ResultPtr aContext2 = aPointAttribute2->context();
164 if(!aContext2.get()) {
167 if(!aPointShape2.get()) {
168 aPointShape2 = aContext2->shape();
170 if(!aPointShape2->isVertex()) {
171 theError = "One of the selected shapes not a vertex.";
175 GeomShapePtr aPointShape3 = aPointAttribute3->value();
176 ResultPtr aContext3 = aPointAttribute3->context();
177 if(!aContext3.get()) {
180 if(!aPointShape3.get()) {
181 aPointShape3 = aContext3->shape();
183 if(!aPointShape3->isVertex()) {
184 theError = "One of the selected shapes not a vertex.";
188 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
189 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
190 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
192 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
193 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
194 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
196 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
198 if(aLin->contains(aPnt3)) {
199 theError = "Selected points lie on a line.";
206 //==================================================================================================
207 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
208 const AttributePtr& theAttribute,
209 const std::list<std::string>& theArguments,
210 Events_InfoMessage& theError) const
212 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
214 AttributeSelectionPtr anAttribute1 =
215 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
216 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
218 std::shared_ptr<GeomAPI_Lin> aLin;
219 std::shared_ptr<GeomAPI_Pnt> aPnt;
221 GeomShapePtr aShape1 = anAttribute1->value();
222 ResultPtr aContext1 = anAttribute1->context();
223 if(!aContext1.get()) {
224 theError = "One of the attribute not initialized.";
228 aShape1 = aContext1->shape();
231 GeomShapePtr aShape2 = anAttribute2->value();
232 ResultPtr aContext2 = anAttribute2->context();
233 if(!aContext2.get()) {
237 aShape2 = aContext2->shape();
240 aLin = getLin(aShape1);
241 aPnt = getPnt(aShape2);
242 if(!aLin.get() || !aPnt.get()) {
243 aLin = getLin(aShape2);
244 aPnt = getPnt(aShape1);
247 if(!aLin.get() || !aPnt.get()) {
248 theError = "Wrong shape types selected.";
252 // line should not contain point only for not-prependicular case
253 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
254 if (aBoolAttr.get() && !aBoolAttr->value()) {
255 if(aLin->contains(aPnt)) {
256 theError = "Point lies on the line.";
264 //==================================================================================================
265 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
266 const AttributePtr& theAttribute,
267 const std::list<std::string>& theArguments,
268 Events_InfoMessage& theError) const
270 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
272 AttributeSelectionPtr anAttribute1 =
273 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
274 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
276 std::shared_ptr<GeomAPI_Pln> aPln1;
277 std::shared_ptr<GeomAPI_Pln> aPln2;
279 GeomShapePtr aShape1 = anAttribute1->value();
280 ResultPtr aContext1 = anAttribute1->context();
281 if(!aContext1.get()) {
282 theError = "One of the attribute not initialized.";
286 aShape1 = aContext1->shape();
289 GeomShapePtr aShape2 = anAttribute2->value();
290 ResultPtr aContext2 = anAttribute2->context();
291 if(!aContext2.get()) {
295 aShape2 = aContext2->shape();
298 aPln1 = getPln(aShape1);
299 aPln2 = getPln(aShape2);
301 if(!aPln1.get() || !aPln2.get()) {
302 theError = "Wrong shape types selected.";
306 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
307 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
309 if(!aDir1->isParallel(aDir2)) {
310 theError = "Planes not parallel.";
317 //==================================================================================================
318 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
319 const AttributePtr& theAttribute,
320 const std::list<std::string>& theArguments,
321 Events_InfoMessage& theError) const
323 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
325 AttributeSelectionPtr anAttribute1 =
326 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
327 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
329 std::shared_ptr<GeomAPI_Pln> aPln1;
330 std::shared_ptr<GeomAPI_Pln> aPln2;
332 GeomShapePtr aShape1 = anAttribute1->value();
333 ResultPtr aContext1 = anAttribute1->context();
334 if(!aContext1.get()) {
335 theError = "One of the attribute not initialized.";
339 aShape1 = aContext1->shape();
342 GeomShapePtr aShape2 = anAttribute2->value();
343 ResultPtr aContext2 = anAttribute2->context();
344 if(!aContext2.get()) {
348 aShape2 = aContext2->shape();
351 aPln1 = getPln(aShape1);
352 aPln2 = getPln(aShape2);
354 if(!aPln1.get() || !aPln2.get()) {
355 theError = "Wrong shape types selected.";
359 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
360 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
362 if(aDir1->isParallel(aDir2)) {
363 theError = "Planes are parallel.";
370 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
372 std::shared_ptr<GeomAPI_Lin> aLin;
374 if(!theShape->isEdge()) {
378 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
380 if(!anEdge->isLine()) {
384 aLin = anEdge->line();
389 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
391 std::shared_ptr<GeomAPI_Pln> aPln;
393 if(!theShape->isFace()) {
397 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
399 if(!aFace->isPlanar()) {
403 aPln = aFace->getPlane();
408 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
410 std::shared_ptr<GeomAPI_Pnt> aPnt;
412 if(!theShape->isVertex()) {
416 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
418 aPnt = aVertex->point();