From 158ec45192170772d7299e674be1769ede59ea7f Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 27 May 2015 10:28:24 +0300 Subject: [PATCH] Make possible to input formula to Point2d widget --- src/ModuleBase/ModuleBase_Tools.cpp | 7 ++++ src/ModuleBase/ModuleBase_Tools.h | 5 +++ src/PartSet/PartSet_WidgetPoint2d.cpp | 50 ++++++++++++++------------- src/PartSet/PartSet_WidgetPoint2d.h | 6 ++-- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 449dd2d3f..2deb05c7c 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -125,6 +125,13 @@ void setSpinValue(QDoubleSpinBox* theSpin, double theValue) theSpin->blockSignals(isBlocked); } +void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue) +{ + bool isBlocked = theSpin->blockSignals(true); + theSpin->setValue(theValue); + theSpin->blockSignals(isBlocked); +} + QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo) { QString aFeatureStr = "feature"; diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 410f01de2..0bb3e68ee 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -62,6 +62,11 @@ MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterVa /// \param theValue a new value MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue); +/// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged) +/// \param theSpin an X or Y coordinate widget +/// \param theValue a new value +MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue); + /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged) /// \param theSpin an ModuleBase_ParamSpinBox that accepts text /// \param theText a new value diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index add40ce6a..df7aab9dc 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include @@ -72,13 +72,13 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aLabel->setPixmap(QPixmap(":pictures/x_point.png")); aGroupLay->addWidget(aLabel, 0, 0); - myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox); + myXSpin = new ModuleBase_ParamSpinBox(myGroupBox); myXSpin->setMinimum(-DBL_MAX); myXSpin->setMaximum(DBL_MAX); myXSpin->setToolTip(tr("X")); aGroupLay->addWidget(myXSpin, 0, 1); - connect(myXSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); + connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SLOT(onValuesChanged())); } { QLabel* aLabel = new QLabel(myGroupBox); @@ -86,13 +86,13 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aLabel->setPixmap(QPixmap(":pictures/y_point.png")); aGroupLay->addWidget(aLabel, 1, 0); - myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox); + myYSpin = new ModuleBase_ParamSpinBox(myGroupBox); myYSpin->setMinimum(-DBL_MAX); myYSpin->setMaximum(DBL_MAX); myYSpin->setToolTip(tr("Y")); aGroupLay->addWidget(myYSpin, 1, 1); - connect(myYSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); + connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SLOT(onValuesChanged())); } QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -105,10 +105,10 @@ void PartSet_WidgetPoint2D::reset() if (!isUseReset()) return; - if (isComputedDefault()) { - //return; - if (myFeature->compute(myAttributeID)) - restoreValue(); + if (isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) { + return; + //if (myFeature->compute(myAttributeID)) + // restoreValue(); } else { bool isOk; @@ -167,12 +167,13 @@ bool PartSet_WidgetPoint2D::storeValueCustom() const PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this; bool isBlocked = that->blockSignals(true); bool isImmutable = aPoint->setImmutable(true); -#ifdef _DEBUG - std::string _attr_name = myAttributeID; - double _X = myXSpin->value(); - double _Y = myYSpin->value(); -#endif - aPoint->setValue(myXSpin->value(), myYSpin->value()); + + if (myXSpin->hasVariable() || myYSpin->hasVariable()) { + aPoint->setText(myXSpin->text().toStdString(), myYSpin->text().toStdString()); + } else { + aPoint->setValue(myXSpin->value(), myYSpin->value()); + aPoint->setText("", ""); + } // after movement the solver will call the update event: optimization moveObject(myFeature); aPoint->setImmutable(isImmutable); @@ -186,15 +187,16 @@ bool PartSet_WidgetPoint2D::restoreValue() std::shared_ptr aData = myFeature->data(); std::shared_ptr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); - -#ifdef _DEBUG - std::string _attr_name = myAttributeID; - double _X = aPoint->x(); - double _Y = aPoint->y(); -#endif - - ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x()); - ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y()); + std::string aTextX = aPoint->textX(); + std::string aTextY = aPoint->textY(); + if (aTextX.empty() || aTextY.empty()) { + double aX = aPoint->x(); + ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x()); + ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y()); + } else { + ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX)); + ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY)); + } return true; } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index dc47f2d7a..75c617ca0 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -18,7 +18,7 @@ class ModelAPI_Feature; class ModuleBase_IWorkshop; -class ModuleBase_DoubleSpinBox; +class ModuleBase_ParamSpinBox; class ModuleBase_IViewWindow; class GeomAPI_Pnt2d; class XGUI_Workshop; @@ -136,8 +136,8 @@ private slots: XGUI_Workshop* myWorkshop; QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets - ModuleBase_DoubleSpinBox* myXSpin; ///< the spin box for the X coordinate - ModuleBase_DoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate + ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate + ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate //std::string myOptionParam; /// Parameter name which has to be taken from previous feature -- 2.39.2