From: vsv Date: Mon, 1 Oct 2018 14:42:53 +0000 (+0300) Subject: Issue #2666: Create parameter on parametrical point control input X-Git-Tag: CEA_2018-2~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bfc21d599161eb7789ca4134ebcc7be4aeee25b2;p=modules%2Fshaper.git Issue #2666: Create parameter on parametrical point control input --- diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index aa6eaca7c..941a2e2cf 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -177,6 +177,12 @@ void ModuleBase_ParamSpinBox::setText(const QString& value) lineEdit()->setText(value); emit textChanged(value); } + else { + bool isConv = false; + double aVal = value.toDouble(&isConv); + if (isConv) + setValue(aVal); + } } /*! diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp index 7917a909a..7d8596556 100644 --- a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp @@ -34,6 +34,9 @@ #include #include + +#define ERR_STRING "ERROR" + ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) @@ -101,6 +104,24 @@ QList ModuleBase_WidgetPointInput::getControls() const return aList; } +std::string getParmText(ModuleBase_ParamSpinBox* theSpin, FeaturePtr& theParam) +{ + QString aText = theSpin->text(); + if (aText.contains('=')) { + if (!theParam.get()) { + theParam = ModuleBase_Tools::createParameter(aText); + if (!theParam.get()) { + return ERR_STRING; + } + } + else { + ModuleBase_Tools::editParameter(theParam, aText); + } + aText = aText.split('=').at(0); + } + return aText.toStdString(); +} + //******************************************************************** bool ModuleBase_WidgetPointInput::storeValueCustom() { @@ -108,8 +129,28 @@ bool ModuleBase_WidgetPointInput::storeValueCustom() if (aAttr.get()) { if (aAttr->isInitialized()) { if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) { - aAttr->setText(myXSpin->text().toStdString(), - myYSpin->text().toStdString(), myZSpin->text().toStdString()); + std::string aXText = getParmText(myXSpin, myXParam); + if (aXText == ERR_STRING) { + aAttr->setExpressionError(0, "Parameter cannot be created"); + aAttr->setExpressionInvalid(0, true); + updateObject(myFeature); + return false; + } + std::string aYText = getParmText(myYSpin, myYParam); + if (aYText == ERR_STRING) { + aAttr->setExpressionError(1, "Parameter cannot be created"); + aAttr->setExpressionInvalid(1, true); + updateObject(myFeature); + return false; + } + std::string aZText = getParmText(myZSpin, myZParam); + if (aZText == ERR_STRING) { + aAttr->setExpressionError(2, "Parameter cannot be created"); + aAttr->setExpressionInvalid(2, true); + updateObject(myFeature); + return false; + } + aAttr->setText(aXText, aYText, aZText); } else { aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value()); } diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.h b/src/ModuleBase/ModuleBase_WidgetPointInput.h index 7b6ec3b59..bae10d61a 100644 --- a/src/ModuleBase/ModuleBase_WidgetPointInput.h +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.h @@ -76,6 +76,10 @@ protected: ModuleBase_ParamSpinBox* myYSpin; ModuleBase_ParamSpinBox* myZSpin; + FeaturePtr myXParam; + FeaturePtr myYParam; + FeaturePtr myZParam; + double myDefaultValue[3]; };