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>
18 #include <Events_InfoMessage.h>
20 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
21 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
22 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
24 //==================================================================================================
25 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
26 const std::list<std::string>& theArguments,
27 Events_InfoMessage& theError) const
29 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
31 AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
32 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
34 GeomShapePtr aLineShape1 = aLineAttribute1->value();
35 ResultPtr aContext1 = aLineAttribute1->context();
36 if(!aContext1.get()) {
37 theError = "One of the attribute not initialized.";
40 if(!aLineShape1.get()) {
41 aLineShape1 = aContext1->shape();
43 if(!aLineShape1->isEdge()) {
44 theError = "One of the selected shapes not an edge.";
48 GeomShapePtr aLineShape2 = aLineAttribute2->value();
49 ResultPtr aContext2 = aLineAttribute2->context();
50 if(!aContext2.get()) {
53 if(!aLineShape2.get()) {
54 aLineShape2 = aContext2->shape();
56 if(!aLineShape2->isEdge()) {
57 theError = "One of the selected shapes not an edge.";
61 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
62 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
64 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
65 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
67 if(!aLine1->isCoplanar(aLine2)) {
68 theError = "Selected lines not coplanar.";
72 if(aLine1->isParallel(aLine2)) {
73 theError = "Selected lines are parallel.";
80 //==================================================================================================
81 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
82 const AttributePtr& theAttribute,
83 const std::list<std::string>& theArguments,
84 Events_InfoMessage& theError) const
86 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
88 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
89 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
91 std::shared_ptr<GeomAPI_Lin> aLin;
92 std::shared_ptr<GeomAPI_Pln> aPln;
94 GeomShapePtr aShape1 = anAttribute1->value();
95 ResultPtr aContext1 = anAttribute1->context();
96 if(!aContext1.get()) {
97 theError = "One of the attribute not initialized.";
101 aShape1 = aContext1->shape();
104 GeomShapePtr aShape2 = anAttribute2->value();
105 ResultPtr aContext2 = anAttribute2->context();
106 if(!aContext2.get()) {
110 aShape2 = aContext2->shape();
113 aLin = getLin(aShape1);
114 aPln = getPln(aShape2);
115 if(!aLin.get() || !aPln.get()) {
116 aLin = getLin(aShape2);
117 aPln = getPln(aShape1);
120 if(!aLin.get() || !aPln.get()) {
121 theError = "Wrong shape types selected.";
125 if(aPln->isParallel(aLin)) {
126 theError = "Plane and line are parallel.";
133 //==================================================================================================
134 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
135 const std::list<std::string>& theArguments,
136 Events_InfoMessage& theError) const
138 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
140 AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
141 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
142 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
144 GeomShapePtr aPointShape1 = aPointAttribute1->value();
145 ResultPtr aContext1 = aPointAttribute1->context();
146 if(!aContext1.get()) {
147 theError = "One of the attribute not initialized.";
150 if(!aPointShape1.get()) {
151 aPointShape1 = aContext1->shape();
153 if(!aPointShape1->isVertex()) {
154 theError = "One of the selected shapes not a vertex.";
158 GeomShapePtr aPointShape2 = aPointAttribute2->value();
159 ResultPtr aContext2 = aPointAttribute2->context();
160 if(!aContext2.get()) {
163 if(!aPointShape2.get()) {
164 aPointShape2 = aContext2->shape();
166 if(!aPointShape2->isVertex()) {
167 theError = "One of the selected shapes not a vertex.";
171 GeomShapePtr aPointShape3 = aPointAttribute3->value();
172 ResultPtr aContext3 = aPointAttribute3->context();
173 if(!aContext3.get()) {
176 if(!aPointShape3.get()) {
177 aPointShape3 = aContext3->shape();
179 if(!aPointShape3->isVertex()) {
180 theError = "One of the selected shapes not a vertex.";
184 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
185 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
186 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
188 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
189 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
190 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
192 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
194 if(aLin->contains(aPnt3)) {
195 theError = "Selected points lie on a line.";
202 //==================================================================================================
203 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
204 const AttributePtr& theAttribute,
205 const std::list<std::string>& theArguments,
206 Events_InfoMessage& theError) const
208 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
210 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
211 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
213 std::shared_ptr<GeomAPI_Lin> aLin;
214 std::shared_ptr<GeomAPI_Pnt> aPnt;
216 GeomShapePtr aShape1 = anAttribute1->value();
217 ResultPtr aContext1 = anAttribute1->context();
218 if(!aContext1.get()) {
219 theError = "One of the attribute not initialized.";
223 aShape1 = aContext1->shape();
226 GeomShapePtr aShape2 = anAttribute2->value();
227 ResultPtr aContext2 = anAttribute2->context();
228 if(!aContext2.get()) {
232 aShape2 = aContext2->shape();
235 aLin = getLin(aShape1);
236 aPnt = getPnt(aShape2);
237 if(!aLin.get() || !aPnt.get()) {
238 aLin = getLin(aShape2);
239 aPnt = getPnt(aShape1);
242 if(!aLin.get() || !aPnt.get()) {
243 theError = "Wrong shape types selected.";
247 if(aLin->contains(aPnt)) {
248 theError = "Point lies on the line.";
255 //==================================================================================================
256 bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
257 const AttributePtr& theAttribute,
258 const std::list<std::string>& theArguments,
259 Events_InfoMessage& theError) const
261 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
263 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
264 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
266 std::shared_ptr<GeomAPI_Pln> aPln1;
267 std::shared_ptr<GeomAPI_Pln> aPln2;
269 GeomShapePtr aShape1 = anAttribute1->value();
270 ResultPtr aContext1 = anAttribute1->context();
271 if(!aContext1.get()) {
272 theError = "One of the attribute not initialized.";
276 aShape1 = aContext1->shape();
279 GeomShapePtr aShape2 = anAttribute2->value();
280 ResultPtr aContext2 = anAttribute2->context();
281 if(!aContext2.get()) {
285 aShape2 = aContext2->shape();
288 aPln1 = getPln(aShape1);
289 aPln2 = getPln(aShape2);
291 if(!aPln1.get() || !aPln2.get()) {
292 theError = "Wrong shape types selected.";
296 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
297 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
299 if(!aDir1->isParallel(aDir2)) {
300 theError = "Planes not parallel.";
307 //==================================================================================================
308 bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
309 const AttributePtr& theAttribute,
310 const std::list<std::string>& theArguments,
311 Events_InfoMessage& theError) const
313 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
315 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
316 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
318 std::shared_ptr<GeomAPI_Pln> aPln1;
319 std::shared_ptr<GeomAPI_Pln> aPln2;
321 GeomShapePtr aShape1 = anAttribute1->value();
322 ResultPtr aContext1 = anAttribute1->context();
323 if(!aContext1.get()) {
324 theError = "One of the attribute not initialized.";
328 aShape1 = aContext1->shape();
331 GeomShapePtr aShape2 = anAttribute2->value();
332 ResultPtr aContext2 = anAttribute2->context();
333 if(!aContext2.get()) {
337 aShape2 = aContext2->shape();
340 aPln1 = getPln(aShape1);
341 aPln2 = getPln(aShape2);
343 if(!aPln1.get() || !aPln2.get()) {
344 theError = "Wrong shape types selected.";
348 std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
349 std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
351 if(aDir1->isParallel(aDir2)) {
352 theError = "Planes are parallel.";
359 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
361 std::shared_ptr<GeomAPI_Lin> aLin;
363 if(!theShape->isEdge()) {
367 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
369 if(!anEdge->isLine()) {
373 aLin = anEdge->line();
378 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
380 std::shared_ptr<GeomAPI_Pln> aPln;
382 if(!theShape->isFace()) {
386 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
388 if(!aFace->isPlanar()) {
392 aPln = aFace->getPlane();
397 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
399 std::shared_ptr<GeomAPI_Pnt> aPnt;
401 if(!theShape->isVertex()) {
405 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
407 aPnt = aVertex->point();