From: sbh Date: Mon, 5 May 2014 15:09:32 +0000 (+0400) Subject: Updating property pannel on sketch editing (refs #31) X-Git-Tag: V_0.2~89^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5bc7e60d4b6c59c9e05f0aa6acfab22cced99e5e;p=modules%2Fshaper.git Updating property pannel on sketch editing (refs #31) --- diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index 5c526db97..ba0b7ea34 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -13,11 +13,11 @@ class ModelAPI_Feature; class ModelAPI_Document; -/// Event ID that feature is created (comes with ModelAPI_FeatureUpdatedMessage) +/// Event ID that feature is created (comes with Model_FeatureUpdatedMessage) static const char * EVENT_FEATURE_CREATED = "FeatureCreated"; -/// Event ID that data of feature is updated (comes with ModelAPI_FeatureUpdatedMessage) +/// Event ID that data of feature is updated (comes with Model_FeatureUpdatedMessage) static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated"; -/// Event ID that data of feature is deleted (comes with ModelAPI_FeatureDeletedMessage) +/// Event ID that data of feature is deleted (comes with Model_FeatureDeletedMessage) static const char * EVENT_FEATURE_DELETED = "FeatureDeleted"; /// Message that feature was changed (used for Object Browser update) diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 02d8d3ef9..2e706ecb9 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -7,11 +7,10 @@ SET(PROJECT_HEADERS ModuleBase_Operation.h ModuleBase_OperationDescription.h ModuleBase_PropPanelOperation.h - ModuleBase_WidgetCustom.h + ModuleBase_ModelWidget.h ModuleBase_WidgetFactory.h ModuleBase_WidgetPoint2D.h ModuleBase_WidgetSwitch.h - ModuleBase_IModelWidget.h ModuleBase_MetaWidget.h ) diff --git a/src/ModuleBase/ModuleBase_IModelWidget.h b/src/ModuleBase/ModuleBase_IModelWidget.h deleted file mode 100644 index e128dc690..000000000 --- a/src/ModuleBase/ModuleBase_IModelWidget.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ModuleBase_IModelWidget.h - * - * Created on: Apr 30, 2014 - * Author: sbh - */ - -#ifndef MODULEBASE_IMODELWIDGET_H_ -#define MODULEBASE_IMODELWIDGET_H_ - -#include -#include -#include - -/* - * Common interface for widgets in the property panel. - * Every widget are able to save/restore data from the - * model and/or to contain other widgets. - * - * Also, there are some methods to simplify and accelerate - * searching of children. - */ -class ModuleBase_IModelWidget -{ -public: - //! Interface for saving widget's data into the data model - MODULEBASE_EXPORT virtual bool storeValue() = 0; - //! Interface for loading widget's data from the data model - MODULEBASE_EXPORT virtual bool restoreValue() = 0; -}; - -#endif /* MODULEBASE_IMODELWIDGET_H_ */ diff --git a/src/ModuleBase/ModuleBase_MetaWidget.cpp b/src/ModuleBase/ModuleBase_MetaWidget.cpp index 442be7dae..308cc3065 100644 --- a/src/ModuleBase/ModuleBase_MetaWidget.cpp +++ b/src/ModuleBase/ModuleBase_MetaWidget.cpp @@ -9,10 +9,9 @@ #include #endif -ModuleBase_MetaWidget::ModuleBase_MetaWidget(const QString& theId, - QWidget* theWrapped, - boost::shared_ptr theFeature) - : myId(theId), myWrappedWidget(theWrapped), myFeature(theFeature) +ModuleBase_MetaWidget::ModuleBase_MetaWidget(QWidget* theWrapped) + : ModuleBase_ModelWidget(theWrapped->parent()), + myWrappedWidget(theWrapped) { } @@ -22,7 +21,7 @@ ModuleBase_MetaWidget::~ModuleBase_MetaWidget() } -bool ModuleBase_MetaWidget::storeValue() +bool ModuleBase_MetaWidget::storeValue(boost::shared_ptr theFeature) { #ifdef _DEBUG std::cout << "ModuleBase_MetaWidget::storeValue" @@ -31,7 +30,7 @@ bool ModuleBase_MetaWidget::storeValue() return true; } -bool ModuleBase_MetaWidget::restoreValue() +bool ModuleBase_MetaWidget::restoreValue(boost::shared_ptr theFeature) { #ifdef _DEBUG std::cout << "ModuleBase_MetaWidget::restoreValue" diff --git a/src/ModuleBase/ModuleBase_MetaWidget.h b/src/ModuleBase/ModuleBase_MetaWidget.h index c81efee13..2899374c5 100644 --- a/src/ModuleBase/ModuleBase_MetaWidget.h +++ b/src/ModuleBase/ModuleBase_MetaWidget.h @@ -1,42 +1,34 @@ /* - * ModuleBase_IModelWidget.h * - * Created on: Apr 30, 2014 - * Author: sbh */ #ifndef MODULEBASE_METAWIDGET_H_ #define MODULEBASE_METAWIDGET_H_ -#include #include +#include #include #include -#include #include /* * */ -class ModuleBase_MetaWidget : public ModuleBase_IModelWidget +class ModuleBase_MetaWidget : public ModuleBase_ModelWidget { public: - MODULEBASE_EXPORT ModuleBase_MetaWidget(const QString& theId, - QWidget* theWrapped, - boost::shared_ptr); + MODULEBASE_EXPORT ModuleBase_MetaWidget(QWidget* theWrapped); virtual ~ModuleBase_MetaWidget(); //! Interface for saving widget's data into the data model - MODULEBASE_EXPORT virtual bool storeValue(); + MODULEBASE_EXPORT virtual bool storeValue(boost::shared_ptr theFeature); //! Interface for loading widget's data from the data model - MODULEBASE_EXPORT virtual bool restoreValue(); + MODULEBASE_EXPORT virtual bool restoreValue(boost::shared_ptr theFeature); private: - QString myId; QWidget* myWrappedWidget; - boost::shared_ptr myFeature; }; #endif /* MODULEBASE_METAWIDGET_H_ */ diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h new file mode 100644 index 000000000..a684515a3 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -0,0 +1,46 @@ +// File: ModuleBase_ModelWidget.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_ModelWidget_H +#define ModuleBase_ModelWidget_H + +#include + +#include + +#include + +class ModelAPI_Feature; + +/**\class ModuleBase_ModelWidget + * \brief An abstract custom widget class. This class realization is assumed to create some controls. + * The controls values modification should send signal about values change. + * + * Common interface for widgets in the property panel. + * Every widget are able to save/restore data from the model and/or to contain other widgets. + * + */ +class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject +{ + Q_OBJECT +public: + /// Constructor + /// \theParent the parent object + ModuleBase_ModelWidget(QObject* theParent) :QObject(theParent) {}; + /// Destructor + virtual ~ModuleBase_ModelWidget() {}; + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(boost::shared_ptr theFeature) = 0; + + virtual bool restoreValue(boost::shared_ptr theFeature) = 0; + + +signals: + /// The signal about widget values changed + void valuesChanged(); +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 8c2f4a274..087413377 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -8,7 +8,7 @@ #include "ModuleBase_Operation.h" #include "ModuleBase_OperationDescription.h" -#include "ModuleBase_WidgetCustom.h" +#include "ModuleBase_ModelWidget.h" #include #include @@ -60,9 +60,9 @@ void ModuleBase_Operation::storeCustomValue() return; } - ModuleBase_WidgetCustom* aCustom = dynamic_cast(sender()); + ModuleBase_ModelWidget* aCustom = dynamic_cast(sender()); if (aCustom) - aCustom->store(myFeature); + aCustom->storeValue(myFeature); } void ModuleBase_Operation::startOperation() diff --git a/src/ModuleBase/ModuleBase_WidgetCustom.h b/src/ModuleBase/ModuleBase_WidgetCustom.h deleted file mode 100644 index 37716f31d..000000000 --- a/src/ModuleBase/ModuleBase_WidgetCustom.h +++ /dev/null @@ -1,42 +0,0 @@ -// File: ModuleBase_WidgetCustom.h -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_WidgetCustom_H -#define ModuleBase_WidgetCustom_H - -#include -#include - -#include - -#include - -class ModelAPI_Feature; - -/**\class ModuleBase_WidgetCustom - * \ingroup GUI - * \brief An abstract custom widget class. This class realization is assumed to create some controls. - * The controls values modification should send signal about values change. Method store is used to fill - * the feature with the - */ -class MODULEBASE_EXPORT ModuleBase_WidgetCustom : public QObject -{ - Q_OBJECT -public: - /// Constructor - /// \theParent the parent object - ModuleBase_WidgetCustom(QObject* theParent) :QObject(theParent) {}; - /// Destructor - virtual ~ModuleBase_WidgetCustom() {}; - - /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual void store(boost::shared_ptr theFeature) = 0; - -signals: - /// The signal about widget values changed - void valuesChanged(); -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index d89f27de4..ab27df2df 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -185,17 +185,16 @@ QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl() aControlLay->setStretch(1, 1); result->setLayout(aControlLay); connectWidget(aBox, WDG_DOUBLEVALUE); - ModuleBase_MetaWidget* aWrappedWdg = - new ModuleBase_MetaWidget(anObjName, aBox, myOperation->feature()); - myWidgets.append(aWrappedWdg); return result; } QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) { ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, - qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)), myWidgetApi->widgetId()); + qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)), + myWidgetApi->widgetId()); connectWidget(aWidget, WDG_POINT_SELECTOR); + myModelWidgets.append(aWidget); return aWidget->getControl(); } @@ -207,8 +206,7 @@ bool ModuleBase_WidgetFactory::connectWidget(QObject* theWidget, const QString& myOperation, SLOT(storeReal(double))); } if (theType == WDG_POINT_SELECTOR) { - ModuleBase_WidgetCustom* aCustom = dynamic_cast(theWidget); - result = QObject::connect(aCustom, SIGNAL(valuesChanged()), + result = QObject::connect(theWidget, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue())); } return result; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index c5b8ef598..bf765824f 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -9,7 +9,7 @@ #define ModuleBase_WidgetFactory_H_ #include -#include +#include #include #include @@ -27,9 +27,9 @@ public: void createWidget(QWidget* theParent); - QList getWrappedWidgets() const + QList getModelWidgets() const { - return myWidgets; + return myModelWidgets; } protected: @@ -47,7 +47,7 @@ private: Config_WidgetAPI* myWidgetApi; ModuleBase_Operation* myOperation; - QList myWidgets; + QList myModelWidgets; }; #endif /* ModuleBase_WidgetFactory_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 5ca2eb98d..35c91813d 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -20,7 +20,7 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle, const std::string& theFeatureAttributeID) -: ModuleBase_WidgetCustom(theParent), myFeatureAttributeID(theFeatureAttributeID) +: ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID) { myGroupBox = new QGroupBox(theTitle, theParent); QGridLayout* aGroupLay = new QGridLayout(myGroupBox); @@ -60,13 +60,27 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() { } -void ModuleBase_WidgetPoint2D::store(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr theFeature) { boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); aPoint->setValue(myXSpin->value(), myYSpin->value()); + return true; +} + +bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr theFeature) +{ + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(aPoint->x()); + myYSpin->setValue(aPoint->y()); + this->blockSignals(isBlocked); + return true; } QWidget* ModuleBase_WidgetPoint2D::getControl() const diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index a973ef693..cd52779dc 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -6,7 +6,7 @@ #define ModuleBase_WidgetPoint2D_H #include -#include "ModuleBase_WidgetCustom.h" +#include "ModuleBase_ModelWidget.h" #include @@ -19,7 +19,7 @@ class QDoubleSpinBox; * \ingroup GUI * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls */ -class MODULEBASE_EXPORT ModuleBase_WidgetPoint2D : public ModuleBase_WidgetCustom +class MODULEBASE_EXPORT ModuleBase_WidgetPoint2D : public ModuleBase_ModelWidget { Q_OBJECT public: @@ -34,7 +34,9 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual void store(boost::shared_ptr theFeature); + virtual bool storeValue(boost::shared_ptr theFeature); + + virtual bool restoreValue(boost::shared_ptr theFeature); /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 0bab9abba..4f4caf21c 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -22,6 +22,11 @@ ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const return myOperations.count() > 0 ? myOperations.last() : 0; } +bool XGUI_OperationMgr::hasOperation() const +{ + return (myOperations.count() > 0) && (myOperations.last() != NULL); +} + bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) { if (!canStartOperation(theOperation)) diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 2e74ab0b1..e3f653cca 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -34,6 +34,8 @@ public: /// Returns the current operation or NULL /// \return the current operation ModuleBase_Operation* currentOperation() const; + /// Returns true is operation manager has at least one non-null operation. + bool hasOperation() const; /// Start the operation and append it to the stack of operations /// \param theOperation the started operation /// \return the state whether the current operation is started diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 202be90fc..09a6c727e 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -61,7 +61,7 @@ XGUI_PropertyPanel::~XGUI_PropertyPanel() { } -void XGUI_PropertyPanel::setModelWidgets(const QList& theWidgets) +void XGUI_PropertyPanel::setModelWidgets(const QList& theWidgets) { myWidgets = theWidgets; } @@ -71,9 +71,9 @@ QWidget* XGUI_PropertyPanel::contentWidget() return myCustomWidget; } -void XGUI_PropertyPanel::updateContentWidget() +void XGUI_PropertyPanel::updateContentWidget(boost::shared_ptr theFeature) { - foreach(ModuleBase_IModelWidget* eachWidget, myWidgets) { - eachWidget->restoreValue(); + foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) { + eachWidget->restoreValue(theFeature); } } diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 92de955c1..9229b8756 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -8,7 +8,7 @@ #ifndef XGUI_PROPERTYPANEL_H_ #define XGUI_PROPERTYPANEL_H_ -#include +#include #include #include @@ -21,15 +21,15 @@ public: virtual ~XGUI_PropertyPanel(); QWidget* contentWidget(); - void setModelWidgets(const QList& theWidgets); + void setModelWidgets(const QList& theWidgets); public slots: - void updateContentWidget(); + void updateContentWidget(boost::shared_ptr theFeature); private: QWidget* myCustomWidget; - QList myWidgets; + QList myWidgets; }; #endif /* XGUI_PROPERTYPANEL_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index c80c8a7ae..a956d0487 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -177,17 +177,27 @@ XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName) //****************************************************** void XGUI_Workshop::processEvent(const Events_Message* theMessage) { + //A message to start feature creation received. static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED); if (theMessage->eventID() == aFeatureLoadedId) { const Config_FeatureMessage* aFeatureMsg = dynamic_cast(theMessage); addFeature(aFeatureMsg); return; } + //Update property panel on corresponding message. If there is no current operation (no + //property panel), or received message has different feature to the current - do nothing. static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED); - if (theMessage->eventID() == aFeatureUpdatedId) + if (theMessage->eventID() == aFeatureUpdatedId && myOperationMgr->hasOperation()) { - myPropertyPanel->updateContentWidget(); + const Model_FeatureUpdatedMessage* anUpdateMsg = + dynamic_cast(theMessage); + boost::shared_ptr aNewFeature = anUpdateMsg->feature(); + boost::shared_ptr aCurrentFeature = myOperationMgr->currentOperation()->feature(); + if(aNewFeature == aCurrentFeature) { + myPropertyPanel->updateContentWidget(aCurrentFeature); + } } + //An operation passed by message. Start it, process and commit. const Config_PointerMessage* aPartSetMsg = dynamic_cast(theMessage); if (aPartSetMsg) { ModuleBase_Operation* anOperation = @@ -201,6 +211,7 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } return; } + //Show error dialog if error message received. const Events_Error* anAppError = dynamic_cast(theMessage); if (anAppError) { emit errorOccurred(QString::fromLatin1(anAppError->description())); @@ -222,8 +233,10 @@ void XGUI_Workshop::onOperationStarted() showPropertyPanel(); ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation); - aFactory.createWidget(myPropertyPanel->contentWidget()); - myPropertyPanel->setModelWidgets(aFactory.getWrappedWidgets()); + QWidget* aContent = myPropertyPanel->contentWidget(); + qDeleteAll(aContent->children()); + aFactory.createWidget(aContent); + myPropertyPanel->setModelWidgets(aFactory.getModelWidgets()); myPropertyPanel->setWindowTitle(aOperation->getDescription()->description()); } }