Salome HOME
e8555daed568bdede8f07571dcff437dc0255852
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetPoint2D.cpp
4 // Created:     25 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include "PartSet_WidgetPoint2d.h"
8 #include <PartSet_Tools.h>
9 #include <PartSet_Module.h>
10
11 #include <ModuleBase_ParamSpinBox.h>
12 #include <ModuleBase_Tools.h>
13 #include <ModuleBase_IViewer.h>
14 #include <ModuleBase_IViewWindow.h>
15 #include <ModuleBase_ISelection.h>
16
17 #include <Config_Keywords.h>
18 #include <Config_WidgetAPI.h>
19
20 #include <Events_Loop.h>
21 #include <ModelAPI_Events.h>
22
23 #include <ModelAPI_Feature.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Object.h>
26 #include <GeomDataAPI_Point2D.h>
27 #include <GeomAPI_Pnt2d.h>
28
29 #include <SketchPlugin_Feature.h>
30 #include <SketchPlugin_ConstraintCoincidence.h>
31 #include <SketchPlugin_Line.h>
32 #include <SketchPlugin_Arc.h>
33 #include <SketchPlugin_Circle.h>
34 #include <SketchPlugin_Point.h>
35
36 #include <QGroupBox>
37 #include <QGridLayout>
38 #include <QLabel>
39 #include <QEvent>
40 #include <QMouseEvent>
41 #include <QApplication>
42
43 #include <TopoDS.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <BRep_Tool.hxx>
46
47 #include <cfloat>
48 #include <climits>
49
50 const double MaxCoordinate = 1e12;
51
52 static QStringList MyFeaturesForCoincedence;
53
54 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, 
55                                              ModuleBase_IWorkshop* theWorkshop,
56                                              const Config_WidgetAPI* theData,
57                                              const std::string& theParentId)
58  : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop)
59 {
60   if (MyFeaturesForCoincedence.isEmpty()) {
61     MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
62       << SketchPlugin_Arc::ID().c_str()
63       << SketchPlugin_Point::ID().c_str()
64       << SketchPlugin_Circle::ID().c_str();
65   }
66
67   // the control should accept the focus, so the boolean flag is corrected to be true
68   myIsObligatory = true;
69   //myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
70   QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
71   myGroupBox = new QGroupBox(aPageName, theParent);
72   myGroupBox->setFlat(false);
73
74   bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
75
76   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
77   ModuleBase_Tools::adjustMargins(aGroupLay);
78   aGroupLay->setSpacing(2);
79   aGroupLay->setColumnStretch(1, 1);
80   {
81     QLabel* aLabel = new QLabel(myGroupBox);
82     aLabel->setText(tr("X "));
83     aGroupLay->addWidget(aLabel, 0, 0);
84
85     myXSpin = new ModuleBase_ParamSpinBox(myGroupBox);
86     myXSpin->setAcceptVariables(aAcceptVariables);
87     myXSpin->setMinimum(-DBL_MAX);
88     myXSpin->setMaximum(DBL_MAX);
89     myXSpin->setToolTip(tr("X"));
90     aGroupLay->addWidget(myXSpin, 0, 1);
91
92     connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
93   }
94   {
95     QLabel* aLabel = new QLabel(myGroupBox);
96     aLabel->setText(tr("Y "));
97     aGroupLay->addWidget(aLabel, 1, 0);
98
99     myYSpin = new ModuleBase_ParamSpinBox(myGroupBox);
100     myYSpin->setAcceptVariables(aAcceptVariables);
101     myYSpin->setMinimum(-DBL_MAX);
102     myYSpin->setMaximum(DBL_MAX);
103     myYSpin->setToolTip(tr("Y"));
104     aGroupLay->addWidget(myYSpin, 1, 1);
105
106     connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
107   }
108   QVBoxLayout* aLayout = new QVBoxLayout(this);
109   ModuleBase_Tools::zeroMargins(aLayout);
110   aLayout->addWidget(myGroupBox);
111   setLayout(aLayout);
112 }
113
114 bool PartSet_WidgetPoint2D::resetCustom()
115 {
116   bool aDone = false;
117   if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) {
118     aDone = false;
119   }
120   else {
121     bool isOk;
122     double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
123     // it is important to block the spin box control in order to do not through out the
124     // locking of the validating state.
125     ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
126     ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
127     storeValueCustom();
128     aDone = true;
129   }
130   return aDone;
131 }
132
133 PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
134 {
135 }
136
137 bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
138                                          const bool theToValidate)
139 {
140   bool isDone = false;
141   if (theValues.empty())
142     return isDone;
143
144   ModuleBase_ViewerPrs aValue = theValues.takeFirst();
145   TopoDS_Shape aShape = aValue.shape();
146   if (!aShape.IsNull()) {
147     Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
148     double aX, aY;
149     if (getPoint2d(aView, aShape, aX, aY)) {
150       isDone = setPoint(aX, aY);
151       PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
152     }
153   }
154   else if (canBeActivatedByMove()) {
155     if (feature()->getKind() == SketchPlugin_Line::ID()) {
156       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aValue.object());
157       // Initialize new line with first point equal to end of previous
158       if (aFeature.get()) {
159         std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
160         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
161           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
162                                        aData->attribute(SketchPlugin_Line::END_ID()));
163         if (aPoint) {
164           setPoint(aPoint->x(), aPoint->y());
165           PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aPoint->x(),
166                                         aPoint->y());
167           isDone = true;
168         }
169       }
170     }
171   }
172   return isDone;
173 }
174
175 void PartSet_WidgetPoint2D::selectContent()
176 {
177   myXSpin->selectAll();
178 }
179
180 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
181 {
182   if (fabs(theX) >= MaxCoordinate)
183     return false;
184   if (fabs(theY) >= MaxCoordinate)
185     return false;
186
187   ModuleBase_Tools::setSpinValue(myXSpin, theX);
188   ModuleBase_Tools::setSpinValue(myYSpin, theY);
189
190   storeValue();
191   return true;
192 }
193
194 bool PartSet_WidgetPoint2D::storeValueCustom() const
195 {
196   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
197   if (!aData) // can be on abort of sketcher element
198     return false;
199   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
200       aData->attribute(attributeID()));
201
202   PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
203   bool isBlocked = that->blockSignals(true);
204   bool isImmutable = aPoint->setImmutable(true);
205
206   // if text is not empty then setValue will be ignored
207   // so we should set the text at first
208   aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "",
209                   myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
210   aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
211                    !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
212
213   // after movement the solver will call the update event: optimization
214   moveObject(myFeature);
215   aPoint->setImmutable(isImmutable);
216   that->blockSignals(isBlocked);
217
218   return true;
219 }
220
221 bool PartSet_WidgetPoint2D::restoreValueCustom()
222 {
223   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
224   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
225       aData->attribute(attributeID()));
226   QString aTextX = QString::fromStdString(aPoint->textX());
227   QString aTextY = QString::fromStdString(aPoint->textY());
228
229   bool isDouble = false;
230   double aVal = 0;
231   if (aTextX.isEmpty()) {
232     ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
233   } else {
234     aVal = aTextX.toDouble(&isDouble);
235     if (isDouble)
236       ModuleBase_Tools::setSpinValue(myXSpin, aVal);
237     else
238       ModuleBase_Tools::setSpinText(myXSpin, aTextX);
239   }
240   if (aTextY.isEmpty()) {
241     ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
242   } else {
243     aVal = aTextY.toDouble(&isDouble);
244     if (isDouble)
245       ModuleBase_Tools::setSpinValue(myYSpin, aVal);
246     else
247       ModuleBase_Tools::setSpinText(myYSpin, aTextY);
248   }
249   //if (aTextX.empty() || aTextY.empty()) {
250   //  ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
251   //  ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
252   //} else {
253   //  ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
254   //  ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
255   //}
256   return true;
257 }
258
259 QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
260 {
261   QList<QWidget*> aControls;
262   aControls.append(myXSpin);
263   aControls.append(myYSpin);
264   return aControls;
265 }
266
267
268 void PartSet_WidgetPoint2D::activateCustom()
269 {
270   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
271   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), 
272           this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
273   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
274           this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
275
276   QIntList aModes;
277   aModes << TopAbs_VERTEX;
278   aModes << TopAbs_EDGE;
279   myWorkshop->activateSubShapesSelection(aModes);
280 }
281
282 bool PartSet_WidgetPoint2D::canBeActivatedByMove()
283 {
284   bool aCanBeActivated = false;
285   if (feature()->getKind() == SketchPlugin_Line::ID() &&
286       attributeID() == SketchPlugin_Line::START_ID())
287     aCanBeActivated = true;
288
289   return aCanBeActivated;
290 }
291
292 void PartSet_WidgetPoint2D::deactivate()
293 {
294   // the value of the control should be stored to model if it was not
295   // initialized yet. It is important when we leave this control by Tab key.
296   // It should not be performed by the widget activation as the preview
297   // is visualized with default value. Line point is moved to origin.
298   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
299   if (anAttribute && !anAttribute->isInitialized())
300     storeValue();
301
302   ModuleBase_ModelWidget::deactivate();
303   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
304   disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
305              this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
306   disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
307              this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
308
309   myWorkshop->deactivateSubShapesSelection();
310 }
311
312 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, 
313                                        const TopoDS_Shape& theShape, 
314                                        double& theX, double& theY) const
315 {
316   if (!theShape.IsNull()) {
317     if (theShape.ShapeType() == TopAbs_VERTEX) {
318       const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
319       if (!aVertex.IsNull()) {
320         // A case when point is taken from existing vertex
321         gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
322         PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY);
323         return true;
324       }
325     }
326   }
327   return false;
328 }
329
330 void PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
331 {
332   // Create point-edge coincedence
333   FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
334   std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
335
336   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
337       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
338   AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
339   std::shared_ptr<GeomDataAPI_Point2D> aThisPoint = 
340     std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
341   aRef1->setAttr(aThisPoint);
342
343   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
344       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
345   aRef2->setObject(theObject);
346
347   aFeature->execute();
348 }
349
350 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
351 {
352   // the contex menu release by the right button should not be processed by this widget
353   if (theEvent->button() != Qt::LeftButton)
354     return;
355
356   ModuleBase_ISelection* aSelection = myWorkshop->selection();
357   Handle(V3d_View) aView = theWnd->v3dView();
358   // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
359   NCollection_List<TopoDS_Shape> aShapes;
360   std::list<ObjectPtr> aObjects;
361   aSelection->selectedShapes(aShapes, aObjects);
362   // if we have selection
363   if (aShapes.Extent() > 0) {
364     TopoDS_Shape aShape = aShapes.First();
365     ObjectPtr aObject = aObjects.front();
366     FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
367     bool anExternal = false;
368       std::shared_ptr<SketchPlugin_Feature> aSPFeature;
369       if (aSelectedFeature.get() != NULL)
370         aSPFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
371       if ((!aSPFeature) && (!aShape.IsNull())) {
372         anExternal = true;
373         ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
374         if (!aFixedObject.get())
375           aObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
376
377         double aX, aY;
378         if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
379           // do not create a constraint to the point, which already used by the feature
380           // if the feature contains the point, focus is not switched
381           setPoint(aX, aY);
382         }
383         else {
384           if (getPoint2d(aView, aShape, aX, aY))
385             setPoint(aX, aY);
386           else
387             setValueState(Stored); // in case of edge selection, Apply state should also be updated
388           bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
389                                isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
390           setConstraintWith(aObject);
391           // fignal updated should be flushed in order to visualize possible created external objects
392           // e.g. selection of trihedron axis when input end arc point
393           updateObject(feature());
394           if (!anOrphanPoint && !anExternal)
395             emit vertexSelected();
396
397           emit focusOutWidget(this);
398         }
399       }
400     if (!anExternal) {
401       double aX, aY;
402       bool isProcessed = false;
403       if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
404         // when the point is selected, the coordinates of the point should be set into the attribute
405         // if the feature contains the point, focus is not switched
406         setPoint(aX, aY);
407       }
408       else {
409         bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
410         // do not set a coincidence constraint in the attribute if the feature contains a point
411         // with the same coordinates. It is important for line creation in order to do not set
412         // the same constraints for the same points, oterwise the result line has zero length.
413         if (getPoint2d(aView, aShape, aX, aY)) {
414           setPoint(aX, aY);
415           PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
416         }
417         else if (aShape.ShapeType() == TopAbs_EDGE) {
418           if (MyFeaturesForCoincedence.contains(myFeature->getKind().c_str())) {
419             setConstraintWith(aObject);
420             setValueState(Stored); // in case of edge selection, Apply state should also be updated
421           }
422         }
423         // it is important to perform updateObject() in order to the current value is 
424         // processed by Sketch Solver. Test case: line is created from a previous point
425         // to some distance, but in the area of the highlighting of the point. Constraint
426         // coincidence is created, after the solver is performed, the distance between the
427         // points of the line becomes less than the tolerance. Validator of the line returns
428         // false, the line will be aborted, but sketch stays valid.
429         updateObject(feature());
430         if (!anOrphanPoint && !anExternal)
431           emit vertexSelected();
432         emit focusOutWidget(this);
433       }
434     }
435   }
436   // End of Bug dependent fragment
437   else {
438     // A case when point is taken from mouse event
439     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
440     double aX, anY;
441     PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
442
443     // if the feature contains the point, focus is not switched
444     if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
445       return;
446
447     /// Start alternative code
448     //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
449     //    GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
450     //QList<FeaturePtr> aIgnore;
451     //aIgnore.append(feature());
452
453     //double aTolerance = aView->Convert(7);
454     //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
455     //  PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
456     //if (aAttrPnt.get() != NULL) {
457     //  aFeaturePoint->setValue(aAttrPnt->pnt());
458     //  PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
459     //  emit vertexSelected();
460     //}
461     /// End alternative code
462     emit focusOutWidget(this);
463   }
464 }
465
466
467 void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
468 {
469   if (isEditingMode())
470     return;
471
472   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
473
474   double aX, anY;
475   PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
476   // we need to block the value state change 
477   bool isBlocked = blockValueState(true);
478   setPoint(aX, anY);
479   blockValueState(isBlocked);
480   setValueState(ModifiedInViewer);
481 }
482
483 double PartSet_WidgetPoint2D::x() const
484 {
485   return myXSpin->value();
486 }
487
488 double PartSet_WidgetPoint2D::y() const
489 {
490   return myYSpin->value();
491 }
492
493
494 bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
495                                                    double theX, double theY)
496 {
497   bool aPointIsFound = false;
498
499   if (feature()->getKind() != SketchPlugin_Line::ID())
500     return aPointIsFound;
501
502   AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
503
504   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
505                                     std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
506   std::list<AttributePtr> anAttributes =
507                                 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
508   std::list<AttributePtr>::iterator anIter = anAttributes.begin();
509   for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
510     AttributePoint2DPtr aPoint2DAttribute =
511       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
512     if (aPoint2DAttribute == aWidgetAttribute)
513       continue;
514     if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
515       aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
516     }
517   }
518   return aPointIsFound;
519 }
520
521 void PartSet_WidgetPoint2D::initializeValueByActivate()
522 {
523 }
524
525 /*void PartSet_WidgetPoint2D::onValuesChanged()
526 {
527   emit valuesChanged();
528 }*/
529
530 bool PartSet_WidgetPoint2D::processEnter()
531 {
532   bool isModified = getValueState() == ModifiedInPP;
533   if (isModified) {
534     bool isXModified = myXSpin->hasFocus();
535     emit valuesChanged();
536     if (isXModified)
537       myXSpin->selectAll();
538     else
539       myYSpin->selectAll();
540   }
541   return isModified;
542 }
543
544 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
545                                           const CompositeFeaturePtr& theSketch,
546                                           double theX, double theY)
547 {
548   bool anOrphanPoint = false;
549   if (theFeature.get()) {
550     std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
551     std::string aFeatureKind = theFeature->getKind();
552     if (aFeatureKind == SketchPlugin_Point::ID())
553       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
554                                        theFeature->attribute(SketchPlugin_Point::COORD_ID()));
555     else if (aFeatureKind == SketchPlugin_Circle::ID())
556       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
557                                        theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
558
559     else if (aFeatureKind == SketchPlugin_Arc::ID())
560       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
561                                        theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
562
563     /// check that the geometry point with the given coordinates is the checked point
564     /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
565     /// means that this point is not an orphant one.
566     if (aPointAttr.get()) {
567       std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
568                                                     new GeomAPI_Pnt2d(theX, theY));
569       if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
570         return anOrphanPoint;
571     }
572
573     if (aPointAttr.get()) {
574       std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
575       FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint);
576       anOrphanPoint = true;
577       // if there is at least one concident line to the point, the point is not an orphant
578       if (aCoincidence.get()) {
579         QList<FeaturePtr> aCoinsideLines;
580         PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
581                                         SketchPlugin_ConstraintCoincidence::ENTITY_A());
582         PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
583                                         SketchPlugin_ConstraintCoincidence::ENTITY_B());
584         QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
585                                           aLast = aCoinsideLines.end();
586         for (; anIt != aLast && anOrphanPoint; anIt++) {
587           anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
588         }
589       }
590     }
591   }
592   return anOrphanPoint;
593 }