From: vsv Date: Thu, 23 Aug 2018 13:44:53 +0000 (+0300) Subject: Issue #2581: Initialize attributes if they are not initialized. It can be in case... X-Git-Tag: SHAPER_V9_1_0RC1~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=db456cfe240d462c3b9f1d0a4a5d2f9cc10fdf3f;p=modules%2Fshaper.git Issue #2581: Initialize attributes if they are not initialized. It can be in case of creation by Python script --- diff --git a/src/ModuleBase/ModuleBase_PagedContainer.cpp b/src/ModuleBase/ModuleBase_PagedContainer.cpp index f98710943..b02d23b47 100644 --- a/src/ModuleBase/ModuleBase_PagedContainer.cpp +++ b/src/ModuleBase/ModuleBase_PagedContainer.cpp @@ -101,16 +101,25 @@ bool ModuleBase_PagedContainer::restoreValueCustom() DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); QString aCaseId; - if (myIsEditing) - aCaseId = QString::fromStdString(aStringAttr->value()); - else - aCaseId = QString::fromStdString(aDefVal.empty()? aStringAttr->value() : aDefVal); - - myIsFirst = false; - int idx = myCaseIds.indexOf(aCaseId); - if (idx == -1) - idx = currentPageIndex(); - setCurrentPageIndex(idx); + if (aStringAttr->isInitialized()) { + if (myIsEditing) + aCaseId = QString::fromStdString(aStringAttr->value()); + else + aCaseId = QString::fromStdString(aDefVal.empty() ? aStringAttr->value() : aDefVal); + myIsFirst = false; + int idx = myCaseIds.indexOf(aCaseId); + if (idx == -1) + idx = currentPageIndex(); + setCurrentPageIndex(idx); + } + else { + // It is added because if user edits the feature created from Python + // and switches his choice + // it will not be stored in the attribute while apply not pressed. + // But this button will be disabled because of not initialized attribute + aStringAttr->setValue(myCaseIds.at(0).toStdString()); + setCurrentPageIndex(0); + } return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index a36aa614b..d06de842b 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -40,11 +40,11 @@ ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, { QString aText = translate(theData->widgetLabel()); QString aToolTip = translate(theData->widgetTooltip()); - bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false); + myDefVal = theData->getBooleanAttribute(ATTR_DEFAULT, false); myCheckBox = new QCheckBox(aText, this); myCheckBox->setToolTip(aToolTip); - myCheckBox->setChecked(isChecked); + myCheckBox->setChecked(myDefVal); QVBoxLayout* aMainLayout = new QVBoxLayout(this); ModuleBase_Tools::adjustMargins(aMainLayout); @@ -73,9 +73,14 @@ bool ModuleBase_WidgetBoolValue::restoreValueCustom() std::shared_ptr aRef = aData->boolean(attributeID()); bool isBlocked = myCheckBox->blockSignals(true); - myCheckBox->setChecked(aRef->value()); + if (aRef->isInitialized()) { + myCheckBox->setChecked(aRef->value()); + } + else { + myCheckBox->setChecked(myDefVal); + aRef->setValue(myDefVal); + } myCheckBox->blockSignals(isBlocked); - return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 121fae5ff..36b3b62ef 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -59,6 +59,8 @@ protected: private: /// The check box QCheckBox* myCheckBox; + + bool myDefVal; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 90e44ba7c..7afe07635 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -101,10 +101,11 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, mySpinBox->setSingleStep(aStepVal); } - double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk); - if (isOk) { - mySpinBox->setValue(aDefVal); - } + myDefaultVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk); + if (isOk) + mySpinBox->setValue(myDefaultVal); + else + myDefaultVal = 0; QString aTTip = translate(theData->widgetTooltip()); mySpinBox->setToolTip(aTTip); @@ -210,12 +211,15 @@ bool ModuleBase_WidgetDoubleValue::restoreValueCustom() // aText += aExprAttr->value().c_str(); //} ModuleBase_Tools::setSpinText(mySpinBox, aText); - } else { - ModuleBase_Tools::setSpinValue(mySpinBox, aRef->isInitialized() ? aRef->value() : 0); + } + else { + ModuleBase_Tools::setSpinValue(mySpinBox, aRef->isInitialized() ? aRef->value() : myDefaultVal); if (aRef->isInitialized() && aRef->expressionInvalid()) { aRef->setExpressionError(""); aRef->setExpressionInvalid(false); } + if (!aRef->isInitialized()) + aRef->setValue(myDefaultVal); } return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 4cdae391d..8e9055ab7 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -88,6 +88,8 @@ protected: ModuleBase_ParamSpinBox* mySpinBox; FeaturePtr myParameter; + + double myDefaultVal; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp index 72622070a..12931a997 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp @@ -91,10 +91,11 @@ ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent, mySpinBox->setSingleStep(aStepVal); } - int aDefVal = QString::fromStdString(getDefaultValue()).toInt(&isOk); - if (isOk) { - mySpinBox->setValue(aDefVal); - } + myDefVal = QString::fromStdString(getDefaultValue()).toInt(&isOk); + if (isOk) + mySpinBox->setValue(myDefVal); + else + myDefVal = 0; QString aTTip = translate(theData->widgetTooltip()); mySpinBox->setToolTip(aTTip); @@ -205,6 +206,8 @@ bool ModuleBase_WidgetIntValue::restoreValueCustom() anAttribute->setExpressionError(""); anAttribute->setExpressionInvalid(false); } + if (!anAttribute->isInitialized()) + anAttribute->setValue(myDefVal); } return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetIntValue.h b/src/ModuleBase/ModuleBase_WidgetIntValue.h index bcd45d4b1..3d6030844 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.h +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.h @@ -83,6 +83,8 @@ protected: ModuleBase_ParamSpinBox* mySpinBox; FeaturePtr myParameter; + + int myDefVal; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp index 29265d26c..9b225ef78 100644 --- a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp @@ -126,24 +126,35 @@ bool ModuleBase_WidgetPointInput::storeValueCustom() bool ModuleBase_WidgetPointInput::restoreValueCustom() { AttributePointPtr aAttr = std::dynamic_pointer_cast(attribute()); - if (aAttr.get() && aAttr->isInitialized()) { - std::string aXText = aAttr->textX(); - if (aXText.empty()) { - myXSpin->setValue(aAttr->x()); - } else { - myXSpin->setText(aXText.c_str()); - } - std::string aYText = aAttr->textY(); - if (aYText.empty()) { - myYSpin->setValue(aAttr->y()); - } else { - myYSpin->setText(aYText.c_str()); + if (aAttr.get()) { + if (aAttr->isInitialized()) { + std::string aXText = aAttr->textX(); + if (aXText.empty()) { + myXSpin->setValue(aAttr->x()); + } + else { + myXSpin->setText(aXText.c_str()); + } + std::string aYText = aAttr->textY(); + if (aYText.empty()) { + myYSpin->setValue(aAttr->y()); + } + else { + myYSpin->setText(aYText.c_str()); + } + std::string aZText = aAttr->textZ(); + if (aZText.empty()) { + myZSpin->setValue(aAttr->z()); + } + else { + myZSpin->setText(aZText.c_str()); + } } - std::string aZText = aAttr->textZ(); - if (aZText.empty()) { - myZSpin->setValue(aAttr->z()); - } else { - myZSpin->setText(aZText.c_str()); + else { + aAttr->setValue(myDefaultValue[0], myDefaultValue[1], myDefaultValue[2]); + myXSpin->setValue(myDefaultValue[0]); + myYSpin->setValue(myDefaultValue[1]); + myZSpin->setValue(myDefaultValue[2]); } return true; }