Salome HOME
Set default value for point input widget
authorvsv <vsv@opencascade.com>
Wed, 11 Jul 2018 14:49:39 +0000 (17:49 +0300)
committervsv <vsv@opencascade.com>
Wed, 11 Jul 2018 14:49:56 +0000 (17:49 +0300)
src/ConstructionPlugin/point_widget.xml
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ModuleBase/ModuleBase_WidgetPointInput.cpp
src/ModuleBase/ModuleBase_WidgetPointInput.h

index d82ab6c45f78eeff6da38dbac4aa1ec1aa661fee..43b3262ef733bf15055088c5e68637e4c924bc17 100644 (file)
@@ -25,7 +25,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
          title="By X, Y, Z"
          tooltip="Point at a given distance from the origin."
          icon="icons/Construction/point_by_xyz_32x32.png">
-      <point_input id="point3d"/>
+      <point_input id="point3d" default="0;0;0"/>
     </box>
     <box id="by_distance_on_edge"
          title="By distance on edge"
index 9f784ef6e33a47d80acedf0cea680326f43d6fa8..aa6eaca7cdb27409af911c41519fbf92de2bcee0 100644 (file)
@@ -49,7 +49,7 @@ ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrec
   myIsEquation(false),
   myAcceptVariables(true),
   mySingleStep(1),
-  myMinimum(DBL_MIN),
+  myMinimum(-DBL_MAX),
   myMaximum(DBL_MAX)
 {
   myCompleter = new QCompleter(this);
index 199960a5e4fca91715408ae3dcf9cab64c7f3acb..29265d26cdb86288fedd2c82ad34be24a6678b42 100644 (file)
@@ -39,15 +39,27 @@ ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
   const Config_WidgetAPI* theData)
   : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
 {
+  myDefaultValue[0] = 0;
+  myDefaultValue[1] = 0;
+  myDefaultValue[2] = 0;
   bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
 
+  std::string aDefValuesStr = theData->getProperty(ATTR_DEFAULT);
+  if (!aDefValuesStr.empty()) {
+    QString aDefVal(aDefValuesStr.c_str());
+    QStringList aStrArray = aDefVal.split(';', QString::SkipEmptyParts);
+    if (aStrArray.length() == 3) {
+      for (int i = 0; i < 3; i++)
+        myDefaultValue[i] = aStrArray.at(i).toDouble();
+    }
+  }
   QFormLayout* aMainlayout = new QFormLayout(this);
   ModuleBase_Tools::adjustMargins(aMainlayout);
 
   myXSpin = new ModuleBase_ParamSpinBox(this);
   myXSpin->setAcceptVariables(aAcceptVariables);
   myXSpin->setToolTip("X coordinate");
-  myXSpin->setValue(0);
+  myXSpin->setValue(myDefaultValue[0]);
   QLabel* aXLbl = new QLabel(this);
   aXLbl->setPixmap(QPixmap(":pictures/x_size.png"));
   aMainlayout->addRow(aXLbl, myXSpin);
@@ -55,7 +67,7 @@ ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
   myYSpin = new ModuleBase_ParamSpinBox(this);
   myYSpin->setAcceptVariables(aAcceptVariables);
   myYSpin->setToolTip("Y coordinate");
-  myYSpin->setValue(0);
+  myYSpin->setValue(myDefaultValue[1]);
   QLabel* aYLbl = new QLabel(this);
   aYLbl->setPixmap(QPixmap(":pictures/y_size.png"));
   aMainlayout->addRow(aYLbl, myYSpin);
@@ -63,10 +75,14 @@ ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
   myZSpin = new ModuleBase_ParamSpinBox(this);
   myZSpin->setAcceptVariables(aAcceptVariables);
   myZSpin->setToolTip("Z coordinate");
-  myZSpin->setValue(0);
+  myZSpin->setValue(myDefaultValue[2]);
   QLabel* aZLbl = new QLabel(this);
   aZLbl->setPixmap(QPixmap(":pictures/z_size.png"));
   aMainlayout->addRow(aZLbl, myZSpin);
+
+  connect(myXSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
+  connect(myYSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
+  connect(myZSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
 }
 
 ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput()
@@ -90,12 +106,17 @@ bool ModuleBase_WidgetPointInput::storeValueCustom()
 {
   AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
   if (aAttr.get()) {
-    if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
-      aAttr->setText(myXSpin->text().toStdString(),
-        myYSpin->text().toStdString(), myZSpin->text().toStdString());
+    if (aAttr->isInitialized()) {
+      if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
+        aAttr->setText(myXSpin->text().toStdString(),
+          myYSpin->text().toStdString(), myZSpin->text().toStdString());
+      } else {
+        aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
+      }
     } else {
-      aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
+      aAttr->setValue(myDefaultValue[0], myDefaultValue[1], myDefaultValue[2]);
     }
+    updateObject(myFeature);
     return true;
   }
   return false;
@@ -105,7 +126,7 @@ bool ModuleBase_WidgetPointInput::storeValueCustom()
 bool ModuleBase_WidgetPointInput::restoreValueCustom()
 {
   AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
-  if (aAttr.get()) {
+  if (aAttr.get() && aAttr->isInitialized()) {
     std::string aXText = aAttr->textX();
     if (aXText.empty()) {
       myXSpin->setValue(aAttr->x());
index e9cd0f3e1bcf513210daed9160c03b61652852d1..d0e9c790d3cb259038f6ad881d60d923a033ca4b 100644 (file)
@@ -72,6 +72,8 @@ protected:
   ModuleBase_ParamSpinBox* myXSpin;
   ModuleBase_ParamSpinBox* myYSpin;
   ModuleBase_ParamSpinBox* myZSpin;
+
+  double myDefaultValue[3];
 };