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 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
33 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
35 GeomShapePtr aLineShape1 = aLineAttribute1->value();
36 ResultPtr aContext1 = aLineAttribute1->context();
37 if(!aContext1.get()) {
38 theError = "One of the attribute not initialized.";
41 if(!aLineShape1.get()) {
42 aLineShape1 = aContext1->shape();
44 if(!aLineShape1->isEdge()) {
45 theError = "One of the selected shapes not an edge.";
49 GeomShapePtr aLineShape2 = aLineAttribute2->value();
50 ResultPtr aContext2 = aLineAttribute2->context();
51 if(!aContext2.get()) {
54 if(!aLineShape2.get()) {
55 aLineShape2 = aContext2->shape();
57 if(!aLineShape2->isEdge()) {
58 theError = "One of the selected shapes not an edge.";
62 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
63 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
65 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
66 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
68 if(!aLine1->isCoplanar(aLine2)) {
69 theError = "Selected lines not coplanar.";
73 if(aLine1->isParallel(aLine2)) {
74 theError = "Selected lines are parallel.";
81 //==================================================================================================
82 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
83 const AttributePtr& theAttribute,
84 const std::list<std::string>& theArguments,
85 Events_InfoMessage& theError) const
87 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
89 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
90 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
92 std::shared_ptr<GeomAPI_Lin> aLin;
93 std::shared_ptr<GeomAPI_Pln> aPln;
95 GeomShapePtr aShape1 = anAttribute1->value();
96 ResultPtr aContext1 = anAttribute1->context();
97 if(!aContext1.get()) {
98 theError = "One of the attribute not initialized.";
102 aShape1 = aContext1->shape();
105 GeomShapePtr aShape2 = anAttribute2->value();
106 ResultPtr aContext2 = anAttribute2->context();
107 if(!aContext2.get()) {
111 aShape2 = aContext2->shape();
114 aLin = getLin(aShape1);
115 aPln = getPln(aShape2);
116 if(!aLin.get() || !aPln.get()) {
117 aLin = getLin(aShape2);
118 aPln = getPln(aShape1);
121 if(!aLin.get() || !aPln.get()) {
122 theError = "Wrong shape types selected.";
126 if(aPln->isParallel(aLin)) {
127 theError = "Plane and line are parallel.";
134 //==================================================================================================
135 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
136 const std::list<std::string>& theArguments,
137 Events_InfoMessage& theError) const
139 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
141 AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
142 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
143 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
145 GeomShapePtr aPointShape1 = aPointAttribute1->value();
146 ResultPtr aContext1 = aPointAttribute1->context();
147 if(!aContext1.get()) {
148 theError = "One of the attribute not initialized.";
151 if(!aPointShape1.get()) {
152 aPointShape1 = aContext1->shape();
154 if(!aPointShape1->isVertex()) {
155 theError = "One of the selected shapes not a vertex.";
159 GeomShapePtr aPointShape2 = aPointAttribute2->value();
160 ResultPtr aContext2 = aPointAttribute2->context();
161 if(!aContext2.get()) {
164 if(!aPointShape2.get()) {
165 aPointShape2 = aContext2->shape();
167 if(!aPointShape2->isVertex()) {
168 theError = "One of the selected shapes not a vertex.";
172 GeomShapePtr aPointShape3 = aPointAttribute3->value();
173 ResultPtr aContext3 = aPointAttribute3->context();
174 if(!aContext3.get()) {
177 if(!aPointShape3.get()) {
178 aPointShape3 = aContext3->shape();
180 if(!aPointShape3->isVertex()) {
181 theError = "One of the selected shapes not a vertex.";
185 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
186 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
187 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
189 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
190 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
191 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
193 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
195 if(aLin->contains(aPnt3)) {
196 theError = "Selected points lie on a line.";
203 //==================================================================================================
204 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
205 const AttributePtr& theAttribute,
206 const std::list<std::string>& theArguments,
207 Events_InfoMessage& theError) const
209 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
211 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
212 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
214 std::shared_ptr<GeomAPI_Lin> aLin;
215 std::shared_ptr<GeomAPI_Pnt> aPnt;
217 GeomShapePtr aShape1 = anAttribute1->value();
218 ResultPtr aContext1 = anAttribute1->context();
219 if(!aContext1.get()) {
220 theError = "One of the attribute not initialized.";
224 aShape1 = aContext1->shape();
227 GeomShapePtr aShape2 = anAttribute2->value();
228 ResultPtr aContext2 = anAttribute2->context();
229 if(!aContext2.get()) {
233 aShape2 = aContext2->shape();
236 aLin = getLin(aShape1);
237 aPnt = getPnt(aShape2);
238 if(!aLin.get() || !aPnt.get()) {
239 aLin = getLin(aShape2);
240 aPnt = getPnt(aShape1);
243 if(!aLin.get() || !aPnt.get()) {
244 theError = "Wrong shape types selected.";
248 // line should not contain point only for not-prependicular case
249 AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
250 if (aBoolAttr.get() && !aBoolAttr->value()) {
251 if(aLin->contains(aPnt)) {
252 theError = "Point lies on the line.";
260 //==================================================================================================
261 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
262 const AttributePtr& theAttribute,
263 const std::list<std::string>& theArguments,
264 Events_InfoMessage& theError) const
266 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
268 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
269 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
271 std::shared_ptr<GeomAPI_Pln> aPln1;
272 std::shared_ptr<GeomAPI_Pln> aPln2;
274 GeomShapePtr aShape1 = anAttribute1->value();
275 ResultPtr aContext1 = anAttribute1->context();
276 if(!aContext1.get()) {
277 theError = "One of the attribute not initialized.";
281 aShape1 = aContext1->shape();
284 GeomShapePtr aShape2 = anAttribute2->value();
285 ResultPtr aContext2 = anAttribute2->context();
286 if(!aContext2.get()) {
290 aShape2 = aContext2->shape();
293 aPln1 = getPln(aShape1);
294 aPln2 = getPln(aShape2);
296 if(!aPln1.get() || !aPln2.get()) {
297 theError = "Wrong shape types selected.";
301 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
302 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
304 if(!aDir1->isParallel(aDir2)) {
305 theError = "Planes not parallel.";
312 //==================================================================================================
313 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
314 const AttributePtr& theAttribute,
315 const std::list<std::string>& theArguments,
316 Events_InfoMessage& theError) const
318 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
320 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
321 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
323 std::shared_ptr<GeomAPI_Pln> aPln1;
324 std::shared_ptr<GeomAPI_Pln> aPln2;
326 GeomShapePtr aShape1 = anAttribute1->value();
327 ResultPtr aContext1 = anAttribute1->context();
328 if(!aContext1.get()) {
329 theError = "One of the attribute not initialized.";
333 aShape1 = aContext1->shape();
336 GeomShapePtr aShape2 = anAttribute2->value();
337 ResultPtr aContext2 = anAttribute2->context();
338 if(!aContext2.get()) {
342 aShape2 = aContext2->shape();
345 aPln1 = getPln(aShape1);
346 aPln2 = getPln(aShape2);
348 if(!aPln1.get() || !aPln2.get()) {
349 theError = "Wrong shape types selected.";
353 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
354 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
356 if(aDir1->isParallel(aDir2)) {
357 theError = "Planes are parallel.";
364 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
366 std::shared_ptr<GeomAPI_Lin> aLin;
368 if(!theShape->isEdge()) {
372 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
374 if(!anEdge->isLine()) {
378 aLin = anEdge->line();
383 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
385 std::shared_ptr<GeomAPI_Pln> aPln;
387 if(!theShape->isFace()) {
391 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
393 if(!aFace->isPlanar()) {
397 aPln = aFace->getPlane();
402 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
404 std::shared_ptr<GeomAPI_Pnt> aPnt;
406 if(!theShape->isVertex()) {
410 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
412 aPnt = aVertex->point();