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