X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetPointInput.cpp;h=8b8d85e3e224cbbaf98bb1a663fd9255a2b5d29e;hb=63d86e00e1e6a482fcad527ae0b883deccceed11;hp=7917a909ac9c7fc49144e258ce9e249671b8da78;hpb=3264b4a29ab742384af02f661e289633f8d7234e;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp index 7917a909a..8b8d85e3e 100644 --- a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "ModuleBase_WidgetPointInput.h" @@ -34,6 +33,9 @@ #include #include + +#define ERR_STRING "ERROR" + ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) @@ -58,7 +60,7 @@ ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, myXSpin = new ModuleBase_ParamSpinBox(this); myXSpin->setAcceptVariables(aAcceptVariables); - myXSpin->setToolTip("X coordinate"); + myXSpin->setToolTip(tr("X coordinate")); myXSpin->setValue(myDefaultValue[0]); QLabel* aXLbl = new QLabel(this); aXLbl->setPixmap(QPixmap(":pictures/x_size.png")); @@ -66,7 +68,7 @@ ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, myYSpin = new ModuleBase_ParamSpinBox(this); myYSpin->setAcceptVariables(aAcceptVariables); - myYSpin->setToolTip("Y coordinate"); + myYSpin->setToolTip(tr("Y coordinate")); myYSpin->setValue(myDefaultValue[1]); QLabel* aYLbl = new QLabel(this); aYLbl->setPixmap(QPixmap(":pictures/y_size.png")); @@ -74,7 +76,7 @@ ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, myZSpin = new ModuleBase_ParamSpinBox(this); myZSpin->setAcceptVariables(aAcceptVariables); - myZSpin->setToolTip("Z coordinate"); + myZSpin->setToolTip(tr("Z coordinate")); myZSpin->setValue(myDefaultValue[2]); QLabel* aZLbl = new QLabel(this); aZLbl->setPixmap(QPixmap(":pictures/z_size.png")); @@ -101,6 +103,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,9 +128,30 @@ 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->setText("", "", ""); aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value()); } } else { @@ -156,6 +197,7 @@ bool ModuleBase_WidgetPointInput::restoreValueCustom() myYSpin->setValue(myDefaultValue[1]); myZSpin->setValue(myDefaultValue[2]); } + setValueState(Stored); return true; } return false; @@ -178,16 +220,19 @@ QIntList ModuleBase_WidgetPointInput::shapeTypes() const //******************************************************************** bool ModuleBase_WidgetPointInput -::setSelectionCustom(const std::shared_ptr& thePrs) +::setSelection(QList>& theValues, + const bool theToValidate) { - GeomShapePtr aShape = thePrs->shape(); - if (aShape->isVertex()) { - GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape)); - GeomPointPtr aPnt = aVertex->point(); - myXSpin->setValue(aPnt->x()); - myYSpin->setValue(aPnt->y()); - myZSpin->setValue(aPnt->z()); - return true; + if (theValues.size() == 1) { + GeomShapePtr aShape = theValues.first()->shape(); + if (aShape.get() && aShape->isVertex()) { + GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape)); + GeomPointPtr aPnt = aVertex->point(); + myXSpin->setValue(aPnt->x()); + myYSpin->setValue(aPnt->y()); + myZSpin->setValue(aPnt->z()); + return true; + } } return false; }