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