X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ModelWidget.cpp;h=cf67219928e96d3c8113dece3d4b4e8c584ddead;hb=397bec888031ab3d5d0578d3094e01f9a052222f;hp=fc7beb3e2760b206dd786e1b333459758bdb28de;hpb=5bb399c88a1cefa30c03754e57b6c684ce733018;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index fc7beb3e2..cf6721992 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -5,7 +5,9 @@ // Author: Natalia ERMOLAEVA #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_ViewerPrs.h" #include "ModuleBase_Tools.h" +#include "ModuleBase_WidgetValidator.h" #include #include @@ -22,15 +24,19 @@ #include #include +//#define DEBUG_VALUE_STATE + ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) + const Config_WidgetAPI* theData) : QWidget(theParent), - myParentId(theParentId), myIsEditing(false), myState(Stored), - myIsValueStateBlocked(false) + myIsValueStateBlocked(false), + myFlushUpdateBlocked(false), + myWidgetValidator(0) { + myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false); + myDefaultValue = theData->getProperty(ATTR_DEFAULT); myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true); myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED; @@ -133,11 +139,16 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted) } } -void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue) +void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue, + const bool isUpdateFlushed) { + /// it is possible to give this flag as parameter in storeValue/storeCustomValue + /// after debug, it may be corrected + myFlushUpdateBlocked = !isUpdateFlushed; myFeature = theFeature; if (theToStoreValue) storeValue(); + myFlushUpdateBlocked = false; } bool ModuleBase_ModelWidget::focusTo() @@ -165,15 +176,22 @@ void ModuleBase_ModelWidget::activate() if (anAttribute.get() != NULL && !anAttribute->isInitialized()) initializeValueByActivate(); } + + if (myWidgetValidator) + myWidgetValidator->activateFilters(true); + activateCustom(); } void ModuleBase_ModelWidget::deactivate() { myIsValueStateBlocked = false; - if (myState == ModifiedInPP) + if (myState == ModifiedInPP || myState == ModifiedInViewer) storeValue(); myState = Stored; + + if (myWidgetValidator) + myWidgetValidator->activateFilters(false); } void ModuleBase_ModelWidget::initializeValueByActivate() @@ -225,11 +243,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); } @@ -252,13 +291,12 @@ bool ModuleBase_ModelWidget::restoreValue() return isDone; } -void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) +void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject) { - blockUpdateViewer(true); - - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - - blockUpdateViewer(false); + if (!myFlushUpdateBlocked) { + ModuleBase_Tools::flushUpdated(theObject); + emit objectUpdated(); + } } void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) @@ -277,6 +315,13 @@ bool ModuleBase_ModelWidget::processEnter() return false; } +bool ModuleBase_ModelWidget::processDelete() +{ + // we consider that model objects eats delete key in order to + // do nothing by for example symbol delete in line edit or spin box + return true; +} + bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); @@ -298,8 +343,11 @@ bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) aReason == Qt::TabFocusReason || aReason == Qt::BacktabFocusReason || aReason == Qt::OtherFocusReason; // to process widget->setFocus() - if (aMouseOrKey && getControls().contains(aWidget) && getValueState() == ModifiedInPP) - storeValue(); + if (aMouseOrKey && getControls().contains(aWidget)) { + if (getValueState() == ModifiedInPP) { + storeValue(); + } + } } // pass the event on to the parent class @@ -317,23 +365,3 @@ void ModuleBase_ModelWidget::onWidgetValuesModified() { setValueState(ModifiedInPP); } - -//************************************************************** -void ModuleBase_ModelWidget::blockUpdateViewer(const bool theValue) -{ - // the viewer update should be blocked in order to avoid the temporary feature content - // when the solver processes the feature, the redisplay message can be flushed - // what caused the display in the viewer preliminary states of object - // e.g. fillet feature, angle value change - std::shared_ptr aMsg; - if (theValue) { - aMsg = std::shared_ptr( - new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED))); - } - else { - // the viewer update should be unblocked - aMsg = std::shared_ptr( - new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED))); - } - Events_Loop::loop()->send(aMsg); -}