]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetPoint2d.cpp
Salome HOME
9e380d4319bd1727ccfea37a2a66de7a2e09e3d7
[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 and use it
363   if (aShapes.Extent() > 0 && useSelectedShapes()) {
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           (aSPFeature.get() && aSPFeature->isExternal())) {
373         anExternal = true;
374         ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
375         if (!aFixedObject.get())
376           aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
377
378         double aX, aY;
379         if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
380           // do not create a constraint to the point, which already used by the feature
381           // if the feature contains the point, focus is not switched
382           setPoint(aX, aY);
383         }
384         else {
385           if (getPoint2d(aView, aShape, aX, aY))
386             setPoint(aX, aY);
387           else
388             setValueState(Stored); // in case of edge selection, Apply state should also be updated
389           bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
390                                isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
391           if (anExternal) {
392             anOrphanPoint = true; // we should not stop reentrant operation on external objects because
393             // they are not participate in the contour creation excepting external vertices
394             if (aShape.ShapeType() == TopAbs_VERTEX) {
395               FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
396               if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
397                 anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY, true);
398               }
399             }
400           }
401
402           setConstraintWith(aFixedObject);
403           // fignal updated should be flushed in order to visualize possible created external objects
404           // e.g. selection of trihedron axis when input end arc point
405           updateObject(feature());
406
407           if (!anOrphanPoint)
408             emit vertexSelected(); // it stops the reentrant operation
409
410           emit focusOutWidget(this);
411         }
412       }
413     if (!anExternal) {
414       double aX, aY;
415       bool isProcessed = false;
416       if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
417         // when the point is selected, the coordinates of the point should be set into the attribute
418         // if the feature contains the point, focus is not switched
419         setPoint(aX, aY);
420       }
421       else {
422         bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
423         // do not set a coincidence constraint in the attribute if the feature contains a point
424         // with the same coordinates. It is important for line creation in order to do not set
425         // the same constraints for the same points, oterwise the result line has zero length.
426         if (getPoint2d(aView, aShape, aX, aY)) {
427           setPoint(aX, aY);
428           PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
429         }
430         else if (aShape.ShapeType() == TopAbs_EDGE) {
431           if (MyFeaturesForCoincedence.contains(myFeature->getKind().c_str())) {
432             setConstraintWith(aObject);
433             setValueState(Stored); // in case of edge selection, Apply state should also be updated
434           }
435         }
436         // it is important to perform updateObject() in order to the current value is 
437         // processed by Sketch Solver. Test case: line is created from a previous point
438         // to some distance, but in the area of the highlighting of the point. Constraint
439         // coincidence is created, after the solver is performed, the distance between the
440         // points of the line becomes less than the tolerance. Validator of the line returns
441         // false, the line will be aborted, but sketch stays valid.
442         updateObject(feature());
443         if (!anOrphanPoint && !anExternal)
444           emit vertexSelected();
445         emit focusOutWidget(this);
446       }
447     }
448   }
449   // End of Bug dependent fragment
450   else {
451     // A case when point is taken from mouse event
452     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
453     double aX, anY;
454     PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
455
456     // if the feature contains the point, focus is not switched
457     if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
458       return;
459
460     /// Start alternative code
461     //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
462     //    GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
463     //QList<FeaturePtr> aIgnore;
464     //aIgnore.append(feature());
465
466     //double aTolerance = aView->Convert(7);
467     //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
468     //  PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
469     //if (aAttrPnt.get() != NULL) {
470     //  aFeaturePoint->setValue(aAttrPnt->pnt());
471     //  PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
472     //  emit vertexSelected();
473     //}
474     /// End alternative code
475     emit focusOutWidget(this);
476   }
477 }
478
479
480 void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
481 {
482   if (isEditingMode())
483     return;
484
485   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
486
487   double aX, anY;
488   PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
489   // we need to block the value state change 
490   bool isBlocked = blockValueState(true);
491   setPoint(aX, anY);
492   blockValueState(isBlocked);
493   setValueState(ModifiedInViewer);
494 }
495
496 double PartSet_WidgetPoint2D::x() const
497 {
498   return myXSpin->value();
499 }
500
501 double PartSet_WidgetPoint2D::y() const
502 {
503   return myYSpin->value();
504 }
505
506
507 bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
508                                                    double theX, double theY)
509 {
510   bool aPointIsFound = false;
511
512   if (feature()->getKind() != SketchPlugin_Line::ID())
513     return aPointIsFound;
514
515   AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
516
517   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
518                                     std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
519   std::list<AttributePtr> anAttributes =
520                                 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
521   std::list<AttributePtr>::iterator anIter = anAttributes.begin();
522   for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
523     AttributePoint2DPtr aPoint2DAttribute =
524       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
525     if (aPoint2DAttribute == aWidgetAttribute)
526       continue;
527     if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
528       aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
529     }
530   }
531   return aPointIsFound;
532 }
533
534 void PartSet_WidgetPoint2D::initializeValueByActivate()
535 {
536 }
537
538 /*void PartSet_WidgetPoint2D::onValuesChanged()
539 {
540   emit valuesChanged();
541 }*/
542
543 bool PartSet_WidgetPoint2D::processEnter()
544 {
545   bool isModified = getValueState() == ModifiedInPP;
546   if (isModified) {
547     bool isXModified = myXSpin->hasFocus();
548     emit valuesChanged();
549     if (isXModified)
550       myXSpin->selectAll();
551     else
552       myYSpin->selectAll();
553   }
554   return isModified;
555 }
556
557 bool PartSet_WidgetPoint2D::useSelectedShapes() const
558 {
559   return true;
560 }
561
562 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
563                                           const CompositeFeaturePtr& theSketch,
564                                           double theX, double theY, const bool theSearchInResults)
565 {
566   bool anOrphanPoint = false;
567   if (theFeature.get()) {
568     std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
569     std::string aFeatureKind = theFeature->getKind();
570     if (aFeatureKind == SketchPlugin_Point::ID())
571       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
572                                        theFeature->attribute(SketchPlugin_Point::COORD_ID()));
573     else if (aFeatureKind == SketchPlugin_Circle::ID())
574       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
575                                        theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
576
577     else if (aFeatureKind == SketchPlugin_Arc::ID())
578       aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
579                                        theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
580
581     /// check that the geometry point with the given coordinates is the checked point
582     /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
583     /// means that this point is not an orphant one.
584     if (aPointAttr.get()) {
585       std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
586                                                     new GeomAPI_Pnt2d(theX, theY));
587       if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
588         return anOrphanPoint;
589     }
590
591     if (aPointAttr.get()) {
592       std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
593       // we need to find coincidence features in results also, because external object(point)
594       // uses refs to me in another feature.
595       FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint, theSearchInResults);
596       anOrphanPoint = true;
597       // if there is at least one concident line to the point, the point is not an orphant
598       if (aCoincidence.get()) {
599         QList<FeaturePtr> aCoinsideLines;
600         PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
601                                         SketchPlugin_ConstraintCoincidence::ENTITY_A());
602         PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
603                                         SketchPlugin_ConstraintCoincidence::ENTITY_B());
604         QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
605                                           aLast = aCoinsideLines.end();
606         for (; anIt != aLast && anOrphanPoint; anIt++) {
607           anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
608         }
609       }
610     }
611   }
612   return anOrphanPoint;
613 }