]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Tools.cpp
Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
1 // File:        PartSet_Tools.h
2 // Created:     28 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_Tools.h>
6
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_AttributeDouble.h>
9 #include <ModelAPI_AttributeRefList.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_ResultConstruction.h>
13
14 #include <GeomDataAPI_Point.h>
15 #include <GeomDataAPI_Dir.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <GeomAPI_Pln.h>
18 #include <GeomAPI_Pnt2d.h>
19 #include <GeomAPI_Pnt.h>
20 #include <GeomAPI_Edge.h>
21
22 #include <GeomAPI_Dir.h>
23 #include <GeomAPI_XYZ.h>
24
25 #include <SketchPlugin_Feature.h>
26 #include <SketchPlugin_Sketch.h>
27 #include <SketchPlugin_ConstraintCoincidence.h>
28 #include <SketchPlugin_ConstraintDistance.h>
29 #include <SketchPlugin_ConstraintLength.h>
30 #include <SketchPlugin_ConstraintRadius.h>
31 #include <SketchPlugin_ConstraintRigid.h>
32 #include <SketchPlugin_Constraint.h>
33 #include <SketchPlugin_Circle.h>
34 #include <SketchPlugin_Arc.h>
35 #include <SketchPlugin_Line.h>
36
37 #include <ModuleBase_ViewerPrs.h>
38
39 #include <V3d_View.hxx>
40 #include <gp_Pln.hxx>
41 #include <gp_Circ.hxx>
42 #include <ProjLib.hxx>
43 #include <ElSLib.hxx>
44 #include <Geom_Line.hxx>
45 #include <GeomAPI_ProjectPointOnCurve.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopoDS.hxx>
48 #include <TopoDS_Edge.hxx>
49
50 #ifdef _DEBUG
51 #include <QDebug>
52 #endif
53
54 const double PRECISION_TOLERANCE = 0.000001;
55
56 gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
57 {
58   if (theView.IsNull())
59     return gp_Pnt();
60
61   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
62   theView->Eye(XEye, YEye, ZEye);
63
64   theView->At(XAt, YAt, ZAt);
65   gp_Pnt EyePoint(XEye, YEye, ZEye);
66   gp_Pnt AtPoint(XAt, YAt, ZAt);
67
68   gp_Vec EyeVector(EyePoint, AtPoint);
69   gp_Dir EyeDir(EyeVector);
70
71   gp_Pln PlaneOfTheView = gp_Pln(AtPoint, EyeDir);
72   Standard_Real X, Y, Z;
73   theView->Convert(thePoint.x(), thePoint.y(), X, Y, Z);
74   gp_Pnt ConvertedPoint(X, Y, Z);
75
76   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
77   gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(),
78                                      PlaneOfTheView);
79   return ResultPoint;
80 }
81
82 void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
83 Handle(V3d_View) theView,
84                                 double& theX, double& theY)
85 {
86   if (!theSketch)
87     return;
88
89   AttributeDoublePtr anAttr;
90   boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
91
92   boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
93       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
94
95   boost::shared_ptr<GeomDataAPI_Dir> aX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
96       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
97   boost::shared_ptr<GeomDataAPI_Dir> anY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
98       aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
99
100   gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
101   gp_Vec aVec(anOriginPnt, thePoint);
102
103   if (!theView.IsNull()) {
104     V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
105     theView->Eye(XEye, YEye, ZEye);
106
107     theView->At(XAt, YAt, ZAt);
108     gp_Pnt EyePoint(XEye, YEye, ZEye);
109     gp_Pnt AtPoint(XAt, YAt, ZAt);
110
111     gp_Vec anEyeVec(EyePoint, AtPoint);
112     anEyeVec.Normalize();
113
114     boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
115         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
116     gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
117
118     double aDen = anEyeVec * aNormalVec;
119     double aLVec = aDen != 0 ? aVec * aNormalVec / aDen : DBL_MAX;
120
121     gp_Vec aDeltaVec = anEyeVec * aLVec;
122     aVec = aVec - aDeltaVec;
123   }
124   theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
125   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
126 }
127
128 void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
129                                 gp_Pnt& thePoint)
130 {
131   if (!theSketch)
132     return;
133
134   boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
135
136   boost::shared_ptr<GeomDataAPI_Point> aC = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
137       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
138   boost::shared_ptr<GeomDataAPI_Dir> aX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
139       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
140   boost::shared_ptr<GeomDataAPI_Dir> aY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
141       aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
142
143   boost::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
144       ->added(aY->dir()->xyz()->multiplied(theY));
145
146   boost::shared_ptr<GeomAPI_Pnt> aPoint = boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
147   thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
148 }
149
150 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
151                                         FeaturePtr theSketch,
152                                         const QList<ModuleBase_ViewerPrs>& theSelected,
153                                         const QList<ModuleBase_ViewerPrs>& theHighlighted)
154 {
155   ObjectPtr aDeltaObject;
156   // 1. find the object in the highlighted list
157   if (theHighlighted.size() > 0) {
158     aDeltaObject = theHighlighted.first().object();
159   }
160   // 2. find it in the selected list by the selected point
161   if (!aDeltaObject) {
162     double aX, anY;
163     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
164     PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
165
166     FeaturePtr aFeature;
167     double aMinDelta = -1;
168     ModuleBase_ViewerPrs aPrs;
169     foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
170       if (!aPrs.object())
171         continue;
172       FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
173       boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
174           SketchPlugin_Feature>(aFeature);
175       if (!aSketchFeature)
176         continue;
177
178       double aDelta = aSketchFeature->distanceToPoint(
179           boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
180       if (aMinDelta < 0 || aMinDelta > aDelta) {
181         aMinDelta = aDelta;
182         // TODO aDeltaObject = aPrs.result();
183       }
184     }
185   }
186   // 3. if the object is not found, returns the first selected one
187   if (!aDeltaObject && theSelected.size() > 0)
188     aDeltaObject = theSelected.first().object();
189
190   return aDeltaObject;
191 }
192
193 boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
194 {
195   return ModelAPI_Session::get()->moduleDocument();
196 }
197
198 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr theFeature,
199                                                                       double theX, double theY)
200 {
201   boost::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = boost::shared_ptr<GeomAPI_Pnt2d>(
202                                                                  new GeomAPI_Pnt2d(theX, theY));
203   std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes =
204                                     theFeature->data()->attributes(GeomDataAPI_Point2D::type());
205   std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
206                                                                     aLast = anAttiributes.end();
207   boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
208   for (; anIt != aLast && !aFPoint; anIt++) {
209     boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint = boost::dynamic_pointer_cast<
210         GeomDataAPI_Point2D>(*anIt);
211     if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
212       aFPoint = aCurPoint;
213   }
214
215   return aFPoint;
216 }
217
218 void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
219                                     const std::string& theAttribute)
220 {
221   if (!theFeature)
222     return;
223   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
224   AttributeDoublePtr anAttribute = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
225       aData->attribute(theAttribute));
226   if (anAttribute)
227     anAttribute->setValue(theValue);
228 }
229
230 double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
231                                    bool& isValid)
232 {
233   isValid = false;
234   double aValue = 0;
235   if (theFeature) {
236     boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
237     AttributeDoublePtr anAttribute = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
238         aData->attribute(theAttribute));
239     if (anAttribute) {
240       aValue = anAttribute->value();
241       isValid = true;
242     }
243   }
244   return aValue;
245 }
246
247 FeaturePtr PartSet_Tools::feature(FeaturePtr theFeature, const std::string& theAttribute,
248                                   const std::string& theKind)
249 {
250   FeaturePtr aFeature;
251   if (!theFeature)
252     return aFeature;
253
254   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
255   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
256       ModelAPI_AttributeRefAttr>(aData->attribute(theAttribute));
257   if (anAttr) {
258     aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
259     if (!theKind.empty() && aFeature && aFeature->getKind() != theKind) {
260       aFeature = FeaturePtr();
261     }
262   }
263   return aFeature;
264 }
265
266 void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
267                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
268                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
269 {
270   FeaturePtr aFeature;
271   if (theSketch) {
272     aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
273   } else {
274     boost::shared_ptr<ModelAPI_Document> aDoc = document();
275     aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
276   }
277
278   boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
279
280   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = boost::dynamic_pointer_cast<
281       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
282   aRef1->setAttr(thePoint1);
283
284   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = boost::dynamic_pointer_cast<
285       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
286   aRef2->setAttr(thePoint2);
287
288   if (aFeature)  // TODO: generate an error if feature was not created
289     aFeature->execute();
290 }
291
292 void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
293                                    const std::string& theAttribute, double theClickedX,
294                                    double theClickedY)
295 {
296   // find a feature point by the selection mode
297   //boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
298   boost::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = boost::dynamic_pointer_cast<
299       GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
300   if (!aFeaturePoint)
301     return;
302
303   // get all sketch features. If the point with the given coordinates belong to any sketch feature,
304   // the constraint is created between the feature point and the found sketch point
305   boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
306   boost::shared_ptr<ModelAPI_AttributeRefList> aRefList = boost::dynamic_pointer_cast<
307       ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
308
309   std::list<ObjectPtr> aFeatures = aRefList->list();
310   std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
311   std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes;
312   boost::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = boost::shared_ptr<GeomAPI_Pnt2d>(
313       new GeomAPI_Pnt2d(theClickedX, theClickedY));
314   for (; anIt != aLast; anIt++) {
315     FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
316     // find the given point in the feature attributes
317     anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
318     std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
319         aLast = anAttiributes.end();
320     boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
321     for (; anIt != aLast && !aFPoint; anIt++) {
322       boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint = boost::dynamic_pointer_cast<
323           GeomDataAPI_Point2D>(*anIt);
324       if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
325         aFPoint = aCurPoint;
326     }
327     if (aFPoint)
328       PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
329   }
330 }
331
332 boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
333 {
334   boost::shared_ptr<GeomAPI_Pln> aPlane;
335   double aA, aB, aC, aD;
336
337   boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
338   boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
339       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
340   boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
341       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
342   aA = aNormal->x();
343   aB = aNormal->y();
344   aC = aNormal->z();
345   aD = 0;
346
347   aPlane = boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
348   return aPlane;
349 }
350
351 boost::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
352                                                       CompositeFeaturePtr theSketch)
353 {
354   boost::shared_ptr<GeomAPI_Pnt> aPoint;
355   if (!theSketch || !thePoint2D)
356     return aPoint;
357
358   boost::shared_ptr<GeomDataAPI_Point> aC = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
359       theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
360   boost::shared_ptr<GeomDataAPI_Dir> aX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
361       theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
362   boost::shared_ptr<GeomDataAPI_Dir> aY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
363       theSketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
364
365   return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
366 }
367
368 bool PartSet_Tools::isConstraintFeature(const std::string& theKind)
369 {
370   return theKind == SketchPlugin_ConstraintDistance::ID()
371       || theKind == SketchPlugin_ConstraintLength::ID()
372       || theKind == SketchPlugin_ConstraintRadius::ID()
373       || theKind == SketchPlugin_ConstraintRigid::ID();
374 }
375
376 ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch)
377 {
378   TopoDS_Shape aShape = thePrs.shape();
379   if (aShape.ShapeType() != TopAbs_EDGE)
380     return ResultPtr();
381
382   // Check that we already have such external edge
383   boost::shared_ptr<GeomAPI_Edge> aInEdge = boost::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
384   aInEdge->setImpl(new TopoDS_Shape(aShape));
385   ResultPtr aResult = findExternalEdge(theSketch, aInEdge);
386   if (aResult)
387     return aResult;
388
389   // If not found then we have to create new
390   Standard_Real aStart, aEnd;
391   Handle(V3d_View) aNullView;
392   FeaturePtr aMyFeature;
393
394   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aStart, aEnd);
395   GeomAdaptor_Curve aAdaptor(aCurve);
396   if (aAdaptor.GetType() == GeomAbs_Line) {
397     // Create line
398     aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
399
400     //DataPtr aData = myFeature->data();
401     //boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
402     //  boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
403
404     //double aX, aY;
405     //gp_Pnt Pnt1 = aAdaptor.Value(aStart);
406     //convertTo2D(Pnt1, theSketch, aNullView, aX, aY);
407     //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Line::START_ID());
408
409     //gp_Pnt Pnt2 = aAdaptor.Value(aEnd);
410     //convertTo2D(Pnt2, theSketch, aNullView, aX, aY);
411     //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Line::END_ID());
412   } else if (aAdaptor.GetType() == GeomAbs_Circle) {
413     if (aAdaptor.IsClosed()) {
414       // Create circle
415       aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
416       //gp_Circ aCirc = aAdaptor.Circle();
417       //gp_Pnt aCenter = aCirc.Location();
418
419       //double aX, aY;
420       //convertTo2D(aCenter, theSketch, aNullView, aX, aY);
421       //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Circle::CENTER_ID());
422       //setFeatureValue(myFeature, aCirc.Radius(), SketchPlugin_Circle::RADIUS_ID());
423     } else {
424       // Create arc
425       aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
426     }
427   }
428   if (aMyFeature) {
429     DataPtr aData = aMyFeature->data();
430     AttributeSelectionPtr anAttr = 
431       boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>
432       (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
433
434     ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
435     if (anAttr && aRes) {
436       boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
437       anEdge->setImpl(new TopoDS_Shape(aShape));
438
439       anAttr->setValue(aRes, anEdge);
440
441       aMyFeature->execute();
442
443       // fix this edge
444       FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
445       aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
446         setObject(aMyFeature->lastResult());
447
448       return aMyFeature->lastResult();
449     }
450   }
451   return ResultPtr();
452 }
453
454 bool PartSet_Tools::isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
455                                           const ModuleBase_ViewerPrs& thePrs)
456 {
457   foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
458     if (aPrs.object() == thePrs.object())
459       return true;
460   }
461   return false;
462 }
463
464 ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge)
465 {
466   for (int i = 0; i < theSketch->numberOfSubs(); i++) {
467     FeaturePtr aFeature = theSketch->subFeature(i);
468     boost::shared_ptr<SketchPlugin_Feature> aSketchFea = 
469       boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
470     if (aSketchFea) {
471       if (aSketchFea->isExternal()) {
472         std::list<ResultPtr> aResults = aSketchFea->results();
473         std::list<ResultPtr>::const_iterator aIt;
474         for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
475           ResultConstructionPtr aRes = 
476             boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
477           if (aRes) {
478             boost::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
479             if (aShape) {
480               if (theEdge->isEqual(aShape))
481                 return aRes;
482             }
483           }
484         }
485       }
486     }
487   }
488   return ResultPtr();
489 }