From d48393d6fc34df209585623b7d0d0546d3d6ec25 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 19 Feb 2016 18:49:09 +0300 Subject: [PATCH] #1277 SKETCH : Bad restitution coordinates in the point creation panel --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 25 +++++++++++- src/PartSet/PartSet_WidgetPoint2d.cpp | 49 ++++++++++++++++++----- src/PartSet/PartSet_WidgetPoint2d.h | 11 +++++ 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index a90353845..e0ac58445 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -22,6 +22,8 @@ #include #include +//#define DEBUG_VALUE_STATE + ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) @@ -227,11 +229,32 @@ bool ModuleBase_ModelWidget::storeValue() 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); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 8cfec7f7d..eaa3ec7d1 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -56,7 +56,8 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, 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() @@ -119,14 +120,24 @@ bool PartSet_WidgetPoint2D::resetCustom() 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; } @@ -257,6 +268,24 @@ bool PartSet_WidgetPoint2D::restoreValueCustom() 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 PartSet_WidgetPoint2D::getControls() const { QList aControls; @@ -501,6 +530,8 @@ void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEv 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); diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 77e286ab2..a66e11a92 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -117,8 +117,15 @@ protected: /// \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(); @@ -182,6 +189,10 @@ private: //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 -- 2.39.2