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_Edge.h>
10 #include <GeomAPI_Face.h>
11 #include <GeomAPI_Lin.h>
12 #include <GeomAPI_Pln.h>
13 #include <GeomAPI_Vertex.h>
15 #include <ModelAPI_AttributeSelection.h>
17 #include <Events_InfoMessage.h>
19 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
20 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
21 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
23 //==================================================================================================
24 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
25 const std::list<std::string>& theArguments,
26 Events_InfoMessage& theError) const
28 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
30 AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
31 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
33 GeomShapePtr aLineShape1 = aLineAttribute1->value();
34 ResultPtr aContext1 = aLineAttribute1->context();
35 if(!aContext1.get()) {
36 theError = "One of the attribute not initialized.";
39 if(!aLineShape1.get()) {
40 aLineShape1 = aContext1->shape();
42 if(!aLineShape1->isEdge()) {
43 theError = "One of the selected shapes not an edge.";
47 GeomShapePtr aLineShape2 = aLineAttribute2->value();
48 ResultPtr aContext2 = aLineAttribute2->context();
49 if(!aContext2.get()) {
52 if(!aLineShape2.get()) {
53 aLineShape2 = aContext2->shape();
55 if(!aLineShape2->isEdge()) {
56 theError = "One of the selected shapes not an edge.";
60 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
61 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
63 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
64 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
66 if(!aLine1->isCoplanar(aLine2)) {
67 theError = "Selected lines not coplanar.";
71 if(aLine1->isParallel(aLine2)) {
72 theError = "Selected lines are parallel.";
79 //==================================================================================================
80 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
81 const AttributePtr& theAttribute,
82 const std::list<std::string>& theArguments,
83 Events_InfoMessage& theError) const
85 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
87 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
88 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
90 std::shared_ptr<GeomAPI_Lin> aLin;
91 std::shared_ptr<GeomAPI_Pln> aPln;
93 GeomShapePtr aShape1 = anAttribute1->value();
94 ResultPtr aContext1 = anAttribute1->context();
95 if(!aContext1.get()) {
96 theError = "One of the attribute not initialized.";
100 aShape1 = aContext1->shape();
103 GeomShapePtr aShape2 = anAttribute2->value();
104 ResultPtr aContext2 = anAttribute2->context();
105 if(!aContext2.get()) {
109 aShape2 = aContext2->shape();
112 aLin = getLin(aShape1);
113 aPln = getPln(aShape2);
114 if(!aLin.get() || !aPln.get()) {
115 aLin = getLin(aShape2);
116 aPln = getPln(aShape1);
119 if(!aLin.get() || !aPln.get()) {
120 theError = "Wrong shape types selected.";
124 if(aPln->isParallel(aLin)) {
125 theError = "Plane and line are parallel.";
132 //==================================================================================================
133 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
134 const std::list<std::string>& theArguments,
135 Events_InfoMessage& theError) const
137 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
139 AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
140 AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
141 AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
143 GeomShapePtr aPointShape1 = aPointAttribute1->value();
144 ResultPtr aContext1 = aPointAttribute1->context();
145 if(!aContext1.get()) {
146 theError = "One of the attribute not initialized.";
149 if(!aPointShape1.get()) {
150 aPointShape1 = aContext1->shape();
152 if(!aPointShape1->isVertex()) {
153 theError = "One of the selected shapes not a vertex.";
157 GeomShapePtr aPointShape2 = aPointAttribute2->value();
158 ResultPtr aContext2 = aPointAttribute2->context();
159 if(!aContext2.get()) {
162 if(!aPointShape2.get()) {
163 aPointShape2 = aContext2->shape();
165 if(!aPointShape2->isVertex()) {
166 theError = "One of the selected shapes not a vertex.";
170 GeomShapePtr aPointShape3 = aPointAttribute3->value();
171 ResultPtr aContext3 = aPointAttribute3->context();
172 if(!aContext3.get()) {
175 if(!aPointShape3.get()) {
176 aPointShape3 = aContext3->shape();
178 if(!aPointShape3->isVertex()) {
179 theError = "One of the selected shapes not a vertex.";
183 std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
184 std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
185 std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
187 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
188 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
189 std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
191 std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
193 if(aLin->contains(aPnt3)) {
194 theError = "Selected points lie on a line.";
201 //==================================================================================================
202 bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
203 const AttributePtr& theAttribute,
204 const std::list<std::string>& theArguments,
205 Events_InfoMessage& theError) const
207 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
209 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
210 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
212 std::shared_ptr<GeomAPI_Lin> aLin;
213 std::shared_ptr<GeomAPI_Pnt> aPnt;
215 GeomShapePtr aShape1 = anAttribute1->value();
216 ResultPtr aContext1 = anAttribute1->context();
217 if(!aContext1.get()) {
218 theError = "One of the attribute not initialized.";
222 aShape1 = aContext1->shape();
225 GeomShapePtr aShape2 = anAttribute2->value();
226 ResultPtr aContext2 = anAttribute2->context();
227 if(!aContext2.get()) {
231 aShape2 = aContext2->shape();
234 aLin = getLin(aShape1);
235 aPnt = getPnt(aShape2);
236 if(!aLin.get() || !aPnt.get()) {
237 aLin = getLin(aShape2);
238 aPnt = getPnt(aShape1);
241 if(!aLin.get() || !aPnt.get()) {
242 theError = "Wrong shape types selected.";
246 if(aLin->contains(aPnt)) {
247 theError = "Point lies on the line.";
254 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
256 std::shared_ptr<GeomAPI_Lin> aLin;
258 if(!theShape->isEdge()) {
262 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
264 if(!anEdge->isLine()) {
268 aLin = anEdge->line();
273 std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
275 std::shared_ptr<GeomAPI_Pln> aPln;
277 if(!theShape->isFace()) {
281 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
283 if(!aFace->isPlanar()) {
287 aPln = aFace->getPlane();
292 std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
294 std::shared_ptr<GeomAPI_Pnt> aPnt;
296 if(!theShape->isVertex()) {
300 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
302 aPnt = aVertex->point();