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)
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
)
+++ /dev/null
-/*
- * ModuleBase_IModelWidget.h
- *
- * Created on: Apr 30, 2014
- * Author: sbh
- */
-
-#ifndef MODULEBASE_IMODELWIDGET_H_
-#define MODULEBASE_IMODELWIDGET_H_
-
-#include <ModuleBase.h>
-#include <QWidget>
-#include <QString>
-
-/*
- * 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_ */
#include <iostream>
#endif
-ModuleBase_MetaWidget::ModuleBase_MetaWidget(const QString& theId,
- QWidget* theWrapped,
- boost::shared_ptr<ModelAPI_Feature> theFeature)
- : myId(theId), myWrappedWidget(theWrapped), myFeature(theFeature)
+ModuleBase_MetaWidget::ModuleBase_MetaWidget(QWidget* theWrapped)
+ : ModuleBase_ModelWidget(theWrapped->parent()),
+ myWrappedWidget(theWrapped)
{
}
}
-bool ModuleBase_MetaWidget::storeValue()
+bool ModuleBase_MetaWidget::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
#ifdef _DEBUG
std::cout << "ModuleBase_MetaWidget::storeValue"
return true;
}
-bool ModuleBase_MetaWidget::restoreValue()
+bool ModuleBase_MetaWidget::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
#ifdef _DEBUG
std::cout << "ModuleBase_MetaWidget::restoreValue"
/*
- * ModuleBase_IModelWidget.h
*
- * Created on: Apr 30, 2014
- * Author: sbh
*/
#ifndef MODULEBASE_METAWIDGET_H_
#define MODULEBASE_METAWIDGET_H_
-#include <ModuleBase_IModelWidget.h>
#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
#include <ModelAPI_Feature.h>
#include <QWidget>
-#include <QString>
#include <boost/shared_ptr.hpp>
/*
*
*/
-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<ModelAPI_Feature>);
+ 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<ModelAPI_Feature> theFeature);
//! Interface for loading widget's data from the data model
- MODULEBASE_EXPORT virtual bool restoreValue();
+ MODULEBASE_EXPORT virtual bool restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
private:
- QString myId;
QWidget* myWrappedWidget;
- boost::shared_ptr<ModelAPI_Feature> myFeature;
};
#endif /* MODULEBASE_METAWIDGET_H_ */
--- /dev/null
+// File: ModuleBase_ModelWidget.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_ModelWidget_H
+#define ModuleBase_ModelWidget_H
+
+#include <ModuleBase.h>
+
+#include <QObject>
+
+#include <boost/shared_ptr.hpp>
+
+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<ModelAPI_Feature> theFeature) = 0;
+
+ virtual bool restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+
+
+signals:
+ /// The signal about widget values changed
+ void valuesChanged();
+};
+
+#endif
#include "ModuleBase_Operation.h"
#include "ModuleBase_OperationDescription.h"
-#include "ModuleBase_WidgetCustom.h"
+#include "ModuleBase_ModelWidget.h"
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Document.h>
return;
}
- ModuleBase_WidgetCustom* aCustom = dynamic_cast<ModuleBase_WidgetCustom*>(sender());
+ ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
if (aCustom)
- aCustom->store(myFeature);
+ aCustom->storeValue(myFeature);
}
void ModuleBase_Operation::startOperation()
+++ /dev/null
-// File: ModuleBase_WidgetCustom.h
-// Created: 25 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_WidgetCustom_H
-#define ModuleBase_WidgetCustom_H
-
-#include <ModuleBase.h>
-#include <ModuleBase_IModelWidget.h>
-
-#include <QObject>
-
-#include <boost/shared_ptr.hpp>
-
-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<ModelAPI_Feature> theFeature) = 0;
-
-signals:
- /// The signal about widget values changed
- void valuesChanged();
-};
-
-#endif
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();
}
myOperation, SLOT(storeReal(double)));
}
if (theType == WDG_POINT_SELECTOR) {
- ModuleBase_WidgetCustom* aCustom = dynamic_cast<ModuleBase_WidgetCustom*>(theWidget);
- result = QObject::connect(aCustom, SIGNAL(valuesChanged()),
+ result = QObject::connect(theWidget, SIGNAL(valuesChanged()),
myOperation, SLOT(storeCustomValue()));
}
return result;
#define ModuleBase_WidgetFactory_H_
#include <ModuleBase.h>
-#include <ModuleBase_IModelWidget.h>
+#include <ModuleBase_ModelWidget.h>
#include <QString>
#include <QList>
void createWidget(QWidget* theParent);
- QList<ModuleBase_IModelWidget*> getWrappedWidgets() const
+ QList<ModuleBase_ModelWidget*> getModelWidgets() const
{
- return myWidgets;
+ return myModelWidgets;
}
protected:
Config_WidgetAPI* myWidgetApi;
ModuleBase_Operation* myOperation;
- QList<ModuleBase_IModelWidget*> myWidgets;
+ QList<ModuleBase_ModelWidget*> myModelWidgets;
};
#endif /* ModuleBase_WidgetFactory_H_ */
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);
{
}
-void ModuleBase_WidgetPoint2D::store(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
aPoint->setValue(myXSpin->value(), myYSpin->value());
+ return true;
+}
+
+bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(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
#define ModuleBase_WidgetPoint2D_H
#include <ModuleBase.h>
-#include "ModuleBase_WidgetCustom.h"
+#include "ModuleBase_ModelWidget.h"
#include <QObject>
* \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:
/// Saves the internal parameters to the given feature
/// \param theFeature a model feature to be changed
- virtual void store(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ virtual bool storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+ virtual bool restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
/// Returns the internal parent wiget control, that can be shown anywhere
/// \returns the widget
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))
/// 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
{
}
-void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_IModelWidget*>& theWidgets)
+void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
{
myWidgets = theWidgets;
}
return myCustomWidget;
}
-void XGUI_PropertyPanel::updateContentWidget()
+void XGUI_PropertyPanel::updateContentWidget(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
- foreach(ModuleBase_IModelWidget* eachWidget, myWidgets) {
- eachWidget->restoreValue();
+ foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
+ eachWidget->restoreValue(theFeature);
}
}
#ifndef XGUI_PROPERTYPANEL_H_
#define XGUI_PROPERTYPANEL_H_
-#include <ModuleBase_IModelWidget.h>
+#include <ModuleBase_ModelWidget.h>
#include <QDockWidget>
#include <QList>
virtual ~XGUI_PropertyPanel();
QWidget* contentWidget();
- void setModelWidgets(const QList<ModuleBase_IModelWidget*>& theWidgets);
+ void setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets);
public slots:
- void updateContentWidget();
+ void updateContentWidget(boost::shared_ptr<ModelAPI_Feature> theFeature);
private:
QWidget* myCustomWidget;
- QList<ModuleBase_IModelWidget*> myWidgets;
+ QList<ModuleBase_ModelWidget*> myWidgets;
};
#endif /* XGUI_PROPERTYPANEL_H_ */
//******************************************************
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<const Config_FeatureMessage*>(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<const Model_FeatureUpdatedMessage*>(theMessage);
+ boost::shared_ptr<ModelAPI_Feature> aNewFeature = anUpdateMsg->feature();
+ boost::shared_ptr<ModelAPI_Feature> 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<const Config_PointerMessage*>(theMessage);
if (aPartSetMsg) {
ModuleBase_Operation* anOperation =
}
return;
}
+ //Show error dialog if error message received.
const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
if (anAppError) {
emit errorOccurred(QString::fromLatin1(anAppError->description()));
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());
}
}