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