Salome HOME
Point should be initialized on start.
[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   if (!isEditingMode()) {
282     FeaturePtr aFeature = feature();
283     if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID())
284       storeValue();
285   }
286 }
287
288 bool PartSet_WidgetPoint2D::canBeActivatedByMove()
289 {
290   bool aCanBeActivated = false;
291   if (feature()->getKind() == SketchPlugin_Line::ID() &&
292       attributeID() == SketchPlugin_Line::START_ID())
293     aCanBeActivated = true;
294
295   return aCanBeActivated;
296 }
297
298 void PartSet_WidgetPoint2D::deactivate()
299 {
300   // the value of the control should be stored to model if it was not
301   // initialized yet. It is important when we leave this control by Tab key.
302   // It should not be performed by the widget activation as the preview
303   // is visualized with default value. Line point is moved to origin.
304   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
305   if (anAttribute && !anAttribute->isInitialized())
306     storeValue();
307
308   ModuleBase_ModelWidget::deactivate();
309   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
310   disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
311              this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
312   disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
313              this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
314
315   myWorkshop->deactivateSubShapesSelection();
316 }
317
318 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, 
319                                        const TopoDS_Shape& theShape, 
320                                        double& theX, double& theY) const
321 {
322   if (!theShape.IsNull()) {
323     if (theShape.ShapeType() == TopAbs_VERTEX) {
324       const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
325       if (!aVertex.IsNull()) {
326         // A case when point is taken from existing vertex
327         gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
328         PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY);
329         return true;
330       }
331     }
332   }
333   return false;
334 }
335
336 void PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
337 {
338   // Create point-edge coincedence
339   FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
340   std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
341
342   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
343       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
344   AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
345   std::shared_ptr<GeomDataAPI_Point2D> aThisPoint = 
346     std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
347   aRef1->setAttr(aThisPoint);
348
349   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
350       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
351   aRef2->setObject(theObject);
352
353   aFeature->execute();
354 }
355
356 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
357 {
358   // the contex menu release by the right button should not be processed by this widget
359   if (theEvent->button() != Qt::LeftButton)
360     return;
361
362   ModuleBase_ISelection* aSelection = myWorkshop->selection();
363   Handle(V3d_View) aView = theWnd->v3dView();
364   // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
365   NCollection_List<TopoDS_Shape> aShapes;
366   std::list<ObjectPtr> aObjects;
367   aSelection->selectedShapes(aShapes, aObjects);
368   // if we have selection and use it
369   if (aShapes.Extent() > 0 && useSelectedShapes()) {
370     TopoDS_Shape aShape = aShapes.First();
371     ObjectPtr aObject = aObjects.front();
372     FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
373     bool anExternal = false;
374     std::shared_ptr<SketchPlugin_Feature> aSPFeature;
375     if (aSelectedFeature.get() != NULL)
376       aSPFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
377       if ((!aSPFeature && !aShape.IsNull()) ||
378           (aSPFeature.get() && aSPFeature->isExternal())) {
379         anExternal = true;
380         ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
381         if (!aFixedObject.get())
382           aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
383
384         double aX, aY;
385         if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
386           // do not create a constraint to the point, which already used by the feature
387           // if the feature contains the point, focus is not switched
388           setPoint(aX, aY);
389         }
390         else {
391           if (getPoint2d(aView, aShape, aX, aY))
392             setPoint(aX, aY);
393           else
394             setValueState(Stored); // in case of edge selection, Apply state should also be updated
395           bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
396                                isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
397           if (anExternal) {
398             anOrphanPoint = true; // we should not stop reentrant operation on external objects because
399             // they are not participate in the contour creation excepting external vertices
400             if (aShape.ShapeType() == TopAbs_VERTEX) {
401               FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
402               if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
403                 anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY, true);
404               }
405             }
406           }
407
408           setConstraintWith(aFixedObject);
409           // fignal updated should be flushed in order to visualize possible created external objects
410           // e.g. selection of trihedron axis when input end arc point
411           updateObject(feature());
412
413           if (!anOrphanPoint)
414             emit vertexSelected(); // it stops the reentrant operation
415
416           emit focusOutWidget(this);
417         }
418       }
419     if (!anExternal) {
420       double aX, aY;
421       bool isProcessed = false;
422       if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
423         // when the point is selected, the coordinates of the point should be set into the attribute
424         // if the feature contains the point, focus is not switched
425         setPoint(aX, aY);
426       }
427       else {
428         bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
429         // do not set a coincidence constraint in the attribute if the feature contains a point
430         // with the same coordinates. It is important for line creation in order to do not set
431         // the same constraints for the same points, oterwise the result line has zero length.
432         if (getPoint2d(aView, aShape, aX, aY)) {
433           setPoint(aX, aY);
434           PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
435         }
436         else if (aShape.ShapeType() == TopAbs_EDGE) {
437           if (MyFeaturesForCoincedence.contains(myFeature->getKind().c_str())) {
438             setConstraintWith(aObject);
439             setValueState(Stored); // in case of edge selection, Apply state should also be updated
440           }
441         }
442         // it is important to perform updateObject() in order to the current value is 
443         // processed by Sketch Solver. Test case: line is created from a previous point
444         // to some distance, but in the area of the highlighting of the point. Constraint
445         // coincidence is created, after the solver is performed, the distance between the
446         // points of the line becomes less than the tolerance. Validator of the line returns
447         // false, the line will be aborted, but sketch stays valid.
448         updateObject(feature());
449         if (!anOrphanPoint && !anExternal)
450           emit vertexSelected();
451         emit focusOutWidget(this);
452       }
453     }
454   }
455   // End of Bug dependent fragment
456   else {
457     // A case when point is taken from mouse event
458     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
459     double aX, anY;
460     PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
461
462     // if the feature contains the point, focus is not switched
463     if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
464       return;
465
466     /// Start alternative code
467     //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
468     //    GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
469     //QList<FeaturePtr> aIgnore;
470     //aIgnore.append(feature());
471
472     //double aTolerance = aView->Convert(7);
473     //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
474     //  PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
475     //if (aAttrPnt.get() != NULL) {
476     //  aFeaturePoint->setValue(aAttrPnt->pnt());
477     //  PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
478     //  emit vertexSelected();
479     //}
480     /// End alternative code
481     emit focusOutWidget(this);
482   }
483 }
484
485
486 void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
487 {
488   if (isEditingMode())
489     return;
490
491   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
492
493   double aX, anY;
494   PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
495   // we need to block the value state change 
496   bool isBlocked = blockValueState(true);
497   setPoint(aX, anY);
498   blockValueState(isBlocked);
499   setValueState(ModifiedInViewer);
500 }
501
502 double PartSet_WidgetPoint2D::x() const
503 {
504   return myXSpin->value();
505 }
506
507 double PartSet_WidgetPoint2D::y() const
508 {
509   return myYSpin->value();
510 }
511
512
513 bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
514                                                    double theX, double theY)
515 {
516   bool aPointIsFound = false;
517
518   if (feature()->getKind() != SketchPlugin_Line::ID())
519     return aPointIsFound;
520
521   AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
522
523   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
524                                     std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
525   std::list<AttributePtr> anAttributes =
526                                 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
527   std::list<AttributePtr>::iterator anIter = anAttributes.begin();
528   for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
529     AttributePoint2DPtr aPoint2DAttribute =
530       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
531     if (aPoint2DAttribute == aWidgetAttribute)
532       continue;
533     if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
534       aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
535     }
536   }
537   return aPointIsFound;
538 }
539
540 void PartSet_WidgetPoint2D::initializeValueByActivate()
541 {
542 }
543
544 /*void PartSet_WidgetPoint2D::onValuesChanged()
545 {
546   emit valuesChanged();
547 }*/
548
549 bool PartSet_WidgetPoint2D::processEnter()
550 {
551   bool isModified = getValueState() == ModifiedInPP;
552   if (isModified) {
553     bool isXModified = myXSpin->hasFocus();
554     emit valuesChanged();
555     if (isXModified)
556       myXSpin->selectAll();
557     else
558       myYSpin->selectAll();
559   }
560   return isModified;
561 }
562
563 bool PartSet_WidgetPoint2D::useSelectedShapes() const
564 {
565   return true;
566 }
567
568 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
569                                           const CompositeFeaturePtr& theSketch,
570                                           double theX, double theY, const bool theSearchInResults)
571 {
572   bool anOrphanPoint = false;
573   if (theFeature.get()) {
574     std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
575     std::string aFeatureKind = theFeature->getKind();
576     if (aFeatureKind == SketchPlugin_Point::ID())
577       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
578                                        theFeature->attribute(SketchPlugin_Point::COORD_ID()));
579     else if (aFeatureKind == SketchPlugin_Circle::ID())
580       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
581                                        theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
582
583     else if (aFeatureKind == SketchPlugin_Arc::ID())
584       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
585                                        theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
586
587     /// check that the geometry point with the given coordinates is the checked point
588     /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
589     /// means that this point is not an orphant one.
590     if (aPointAttr.get()) {
591       std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
592                                                     new GeomAPI_Pnt2d(theX, theY));
593       if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
594         return anOrphanPoint;
595     }
596
597     if (aPointAttr.get()) {
598       std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
599       // we need to find coincidence features in results also, because external object(point)
600       // uses refs to me in another feature.
601       FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint, theSearchInResults);
602       anOrphanPoint = true;
603       // if there is at least one concident line to the point, the point is not an orphant
604       if (aCoincidence.get()) {
605         QList<FeaturePtr> aCoinsideLines;
606         PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
607                                         SketchPlugin_ConstraintCoincidence::ENTITY_A());
608         PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
609                                         SketchPlugin_ConstraintCoincidence::ENTITY_B());
610         QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
611                                           aLast = aCoinsideLines.end();
612         for (; anIt != aLast && anOrphanPoint; anIt++) {
613           anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
614         }
615       }
616     }
617   }
618   return anOrphanPoint;
619 }