Salome HOME
Simplification of the code: it removes focusNextPrevChild processing.
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
index 1ffc4f4d234d66faf4fdb60b76450309d01eefec..66a67efc418a917d2d4085aa1e9ad7452db47f02 100644 (file)
@@ -7,7 +7,6 @@
 #include "PartSet_WidgetPoint2d.h"
 #include <PartSet_Tools.h>
 #include <PartSet_Module.h>
-#include <PartSet_LockApplyMgr.h>
 
 #include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_Tools.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Point.h>
 
 #include <QGroupBox>
 #include <QGridLayout>
@@ -46,6 +49,7 @@
 
 const double MaxCoordinate = 1e12;
 
+static QStringList MyFeaturesForCoincedence;
 
 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, 
                                              ModuleBase_IWorkshop* theWorkshop,
@@ -53,7 +57,12 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
                                              const std::string& theParentId)
  : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop)
 {
-  myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop);
+  if (MyFeaturesForCoincedence.isEmpty()) {
+    MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
+      << SketchPlugin_Arc::ID().c_str()
+      << SketchPlugin_Point::ID().c_str()
+      << SketchPlugin_Circle::ID().c_str();
+  }
 
   // the control should accept the focus, so the boolen flag is corrected to be true
   myIsObligatory = true;
@@ -77,7 +86,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
     myXSpin->setToolTip(tr("X"));
     aGroupLay->addWidget(myXSpin, 0, 1);
 
-    connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SLOT(onValuesChanged()));
+    connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
   }
   {
     QLabel* aLabel = new QLabel(myGroupBox);
@@ -90,7 +99,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
     myYSpin->setToolTip(tr("Y"));
     aGroupLay->addWidget(myYSpin, 1, 1);
 
-    connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SLOT(onValuesChanged()));
+    connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
   }
   QVBoxLayout* aLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
@@ -98,7 +107,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
   setLayout(aLayout);
 }
 
-bool PartSet_WidgetPoint2D::reset()
+bool PartSet_WidgetPoint2D::resetCustom()
 {
   bool aDone = false;
   if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) {
@@ -160,7 +169,7 @@ bool PartSet_WidgetPoint2D::storeValueCustom() const
     return false;
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
-  
+
   PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
   bool isBlocked = that->blockSignals(true);
   bool isImmutable = aPoint->setImmutable(true);
@@ -239,12 +248,11 @@ void PartSet_WidgetPoint2D::activateCustom()
   aModes << TopAbs_VERTEX;
   aModes << TopAbs_EDGE;
   myWorkshop->activateSubShapesSelection(aModes);
-
-  myLockApplyMgr->activate();
 }
 
 void PartSet_WidgetPoint2D::deactivate()
 {
+  ModuleBase_ModelWidget::deactivate();
   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
   disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
              this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
@@ -252,8 +260,6 @@ void PartSet_WidgetPoint2D::deactivate()
              this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
 
   myWorkshop->deactivateSubShapesSelection();
-
-  myLockApplyMgr->deactivate();
 }
 
 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, 
@@ -328,6 +334,8 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
           setPoint(aX, aY);
         }
         else {
+          if (getPoint2d(aView, aShape, aX, aY))
+            setPoint(aX, aY);
           setConstraintWith(aObject);
           emit vertexSelected();
           emit focusOutWidget(this);
@@ -346,11 +354,14 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
         // do not set a coincidence constraint in the attribute if the feature contains a point
         // with the same coordinates. It is important for line creation in order to do not set
         // the same constraints for the same points, oterwise the result line has zero length.
-        if (getPoint2d(aView, aShape, aX, aY))
+        if (getPoint2d(aView, aShape, aX, aY)) {
+          setPoint(aX, aY);
           PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
-        else if (aShape.ShapeType() == TopAbs_EDGE)
-          setConstraintWith(aObject);
-
+        }
+        else if (aShape.ShapeType() == TopAbs_EDGE) {
+          if (MyFeaturesForCoincedence.contains(myFeature->getKind().c_str()))
+            setConstraintWith(aObject);
+        }
         // it is important to perform updateObject() in order to the current value is 
         // processed by Sketch Solver. Test case: line is created from a previous point
         // to some distance, but in the area of the highlighting of the point. Constraint
@@ -403,7 +414,11 @@ void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEv
 
   double aX, anY;
   PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
+  // we need to block the value state change 
+  bool isBlocked = blockValueState(true);
   setPoint(aX, anY);
+  blockValueState(isBlocked);
+  setValueState(ModifiedInViewer);
 }
 
 double PartSet_WidgetPoint2D::x() const
@@ -428,20 +443,36 @@ bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
   std::list<AttributePtr> anAttributes =
                                 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
   std::list<AttributePtr>::iterator anIter = anAttributes.begin();
-  for(; anIter != anAttributes.end(); anIter++) {
+  for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
     AttributePoint2DPtr aPoint2DAttribute =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
     if (aPoint2DAttribute == aWidgetAttribute)
       continue;
-    if (aPoint2DAttribute.get()) {
+    if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
       aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
     }
   }
   return aPointIsFound;
 }
 
-void PartSet_WidgetPoint2D::onValuesChanged()
+/*void PartSet_WidgetPoint2D::onValuesChanged()
 {
-  myLockApplyMgr->valuesChanged();
   emit valuesChanged();
+}*/
+
+bool PartSet_WidgetPoint2D::processEnter()
+{
+  bool isModified = myXSpin->isModified() || myYSpin->isModified();
+  if (isModified) {
+    bool isXModified = myXSpin->isModified();
+    emit valuesChanged();
+    //onValuesChanged();
+    myXSpin->clearModified();
+    myYSpin->clearModified();
+    if (isXModified)
+      myXSpin->selectAll();
+    else
+      myYSpin->selectAll();
+  }
+  return isModified;
 }