#include <QLabel>
#include <QFocusEvent>
+//#define DEBUG_VALUE_STATE
+
ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
const Config_WidgetAPI* theData,
const std::string& theParentId)
return isDone;
}
+#ifdef DEBUG_VALUE_STATE
+std::string getDebugInfo(const ModuleBase_ModelWidget::ValueState& theState)
+{
+ std::string anInfo;
+ switch (theState) {
+ case ModuleBase_ModelWidget::Stored: anInfo = "Stored "; break;
+ case ModuleBase_ModelWidget::ModifiedInPP: anInfo = "ModifiedInPP "; break;
+ case ModuleBase_ModelWidget::ModifiedInViewer: anInfo = "ModifiedInViewer"; break;
+ case ModuleBase_ModelWidget::Reset: anInfo = "Reset "; break;
+ default: break;
+ }
+ return anInfo;
+}
-ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState(const ModuleBase_ModelWidget::ValueState& theState)
+#endif
+ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState
+ (const ModuleBase_ModelWidget::ValueState& theState)
{
ValueState aState = myState;
+
if (myState != theState && !myIsValueStateBlocked) {
+#ifdef DEBUG_VALUE_STATE
+ qDebug(QString("setValueState: previous state = %1,\t new state = %2")
+ .arg(getDebugInfo(myState).c_str())
+ .arg(getDebugInfo(theState).c_str()).toStdString().c_str());
+#endif
myState = theState;
emit valueStateChanged(aState);
}
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop)
+: ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop),
+ myValueIsCashed(false), myXValueInCash(0), myYValueInCash(0)
{
if (MyFeaturesForCoincedence.isEmpty()) {
MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
aDone = false;
}
else {
- bool isOk;
- double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
- // it is important to block the spin box control in order to do not through out the
- // locking of the validating state.
- ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
- ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
- storeValueCustom();
- aDone = true;
+ if (myValueIsCashed) {
+ // fill the control widgets by the cashed value
+ restoreCurentValue();
+ // store value to the model
+ storeValueCustom();
+ setValueState(Stored);
+ aDone = false;
+ }
+ else {
+ bool isOk;
+ double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+ // it is important to block the spin box control in order to do not through out the
+ // locking of the validating state.
+ ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
+ ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
+ storeValueCustom();
+ aDone = true;
+ }
}
return aDone;
}
return true;
}
+void PartSet_WidgetPoint2D::storeCurentValue()
+{
+ // do not use cash if a variable is used
+ if (myXSpin->hasVariable() || myYSpin->hasVariable())
+ return;
+
+ myValueIsCashed = true;
+ myXValueInCash = myXSpin->value();
+ myYValueInCash = myYSpin->value();
+}
+
+void PartSet_WidgetPoint2D::restoreCurentValue()
+{
+ myValueIsCashed = false;
+ ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash);
+ ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash);
+}
+
QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
{
QList<QWidget*> aControls;
double aX, anY;
PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
+ if (myState != ModifiedInViewer)
+ storeCurentValue();
// we need to block the value state change
bool isBlocked = blockValueState(true);
setPoint(aX, anY);
/// \return True in success
virtual bool storeValueCustom() const;
+ /// Restore value from attribute data to the widget's control
virtual bool restoreValueCustom();
+ /// Store current value in cashed value
+ void storeCurentValue();
+
+ /// Restore cashed value in the model attribute
+ void restoreCurentValue();
+
/// Fills the widget with default values
/// \return true if the widget current value is reset
virtual bool resetCustom();
//std::string myOptionParam; /// Parameter name which has to be taken from previous feature
CompositeFeaturePtr mySketch;
+
+ bool myValueIsCashed; /// boolean state if the value is cashed during value state change
+ double myXValueInCash; /// the cashed X value during value state change
+ double myYValueInCash; /// the cashed Y value during value state change
};
#endif