From f17a6aa3e829726cbe870ea4c0f918d229f041e0 Mon Sep 17 00:00:00 2001 From: sbh Date: Tue, 8 Apr 2014 15:38:47 +0400 Subject: [PATCH] Property pannel connected with the model through the ModuelBase dll. --- CMakeLists.txt | 5 +- src/Config/CMakeLists.txt | 4 +- src/Config/Config_Keywords.h | 8 +- src/Config/Config_PointerMessage.cpp | 29 +++ src/Config/Config_PointerMessage.h | 30 +++ src/Config/Config_WidgetAPI.cpp | 5 + src/Config/Config_WidgetAPI.h | 1 + src/Config/Config_WidgetMessage.cpp | 38 --- src/Config/Config_WidgetMessage.h | 31 --- src/ModuleBase/CMakeLists.txt | 36 +++ src/ModuleBase/ModuleBase.h | 18 ++ src/ModuleBase/ModuleBase_Operation.cpp | 330 ++++++++++++++++++++++++ src/ModuleBase/ModuleBase_Operation.h | 136 ++++++++++ src/PartSet/CMakeLists.txt | 11 +- src/PartSet/PartSet_Module.cpp | 18 +- src/PartSet/PartSet_Module.h | 2 +- src/XGUI/CMakeLists.txt | 2 + src/XGUI/XGUI_MainWindow.cpp | 33 ++- src/XGUI/XGUI_MainWindow.h | 4 + src/XGUI/XGUI_WidgetFactory.cpp | 40 ++- src/XGUI/XGUI_WidgetFactory.h | 9 +- src/XGUI/XGUI_Workshop.cpp | 46 +++- src/XGUI/XGUI_Workshop.h | 9 +- 23 files changed, 723 insertions(+), 122 deletions(-) create mode 100644 src/Config/Config_PointerMessage.cpp create mode 100644 src/Config/Config_PointerMessage.h delete mode 100644 src/Config/Config_WidgetMessage.cpp delete mode 100644 src/Config/Config_WidgetMessage.h create mode 100644 src/ModuleBase/CMakeLists.txt create mode 100644 src/ModuleBase/ModuleBase.h create mode 100644 src/ModuleBase/ModuleBase_Operation.cpp create mode 100644 src/ModuleBase/ModuleBase_Operation.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f13e37375..29ee4ab93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,14 @@ INCLUDE(Common) INCLUDE(FindQt5) INCLUDE(FindPython) +ADD_SUBDIRECTORY (src/Config) ADD_SUBDIRECTORY (src/Event) ADD_SUBDIRECTORY (src/Model) ADD_SUBDIRECTORY (src/ModelAPI) -ADD_SUBDIRECTORY (src/Config) +ADD_SUBDIRECTORY (src/ModuleBase) ADD_SUBDIRECTORY (src/PartSet) ADD_SUBDIRECTORY (src/PartSetPlugin) +ADD_SUBDIRECTORY (src/PyConsole) ADD_SUBDIRECTORY (src/PyEvent) ADD_SUBDIRECTORY (src/PyInterp) -ADD_SUBDIRECTORY (src/PyConsole) ADD_SUBDIRECTORY (src/XGUI) diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index 8e6369fa3..159be465c 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -13,7 +13,7 @@ SET(PROJECT_HEADERS Config_FeatureReader.h Config_WidgetAPI.h Config_WidgetReader.h - Config_WidgetMessage.h + Config_PointerMessage.h ) SET(PROJECT_SOURCES @@ -23,7 +23,7 @@ SET(PROJECT_SOURCES Config_FeatureReader.cpp Config_WidgetAPI.cpp Config_WidgetReader.cpp - Config_WidgetMessage.cpp + Config_PointerMessage.cpp ) SET(XML_RESOURCES diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 107ba9ec7..bca951680 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -14,7 +14,7 @@ const static char* NODE_WORKBENCH = "workbench"; const static char* NODE_GROUP = "group"; const static char* NODE_FEATURE = "feature"; -const static char* NODE_WIDGET = "value"; +const static char* NODE_DOUBLE_WDG = "value"; const static char* _ID = "id"; //const static char* WORKBENCH_ID = "id"; @@ -25,6 +25,12 @@ const static char* FEATURE_TOOLTIP = "tooltip"; const static char* FEATURE_ICON = "icon"; const static char* FEATURE_KEYSEQUENCE = "keysequence"; +// doublevalue properties: +const static char* DOUBLE_WDG_MIN = "min"; +const static char* DOUBLE_WDG_MAX = "max"; +const static char* DOUBLE_WDG_STEP = "step"; +const static char* DOUBLE_WDG_DFLT = "default"; + /* * Hardcoded xml entities of plugins.xml */ diff --git a/src/Config/Config_PointerMessage.cpp b/src/Config/Config_PointerMessage.cpp new file mode 100644 index 000000000..cc4b353d5 --- /dev/null +++ b/src/Config/Config_PointerMessage.cpp @@ -0,0 +1,29 @@ +/* + * Config_PointerMessage.cpp + * + * Created on: Mar 21, 2014 + * Author: sbh + */ + +#include + +Config_PointerMessage::Config_PointerMessage(const Event_ID theId, const void* theParent) + : Event_Message(theId, theParent), myPointer(0) +{ + +} + +Config_PointerMessage::~Config_PointerMessage() +{ + +} + +void* Config_PointerMessage::pointer() const +{ + return myPointer; +} + +void Config_PointerMessage::setPointer(void* pointer) +{ + myPointer = pointer; +} diff --git a/src/Config/Config_PointerMessage.h b/src/Config/Config_PointerMessage.h new file mode 100644 index 000000000..e0ac3e440 --- /dev/null +++ b/src/Config/Config_PointerMessage.h @@ -0,0 +1,30 @@ +/* + * Config_PointerMessage.h + * + * Created on: Mar 21, 2014 + * Author: sbh + */ + +#ifndef PARTSET_MESSAGE_H_ +#define PARTSET_MESSAGE_H_ + +#include +#include + +/* + * A general class to pass pointers over the event loop. + */ +class CONFIG_EXPORT Config_PointerMessage: public Event_Message +{ +public: + Config_PointerMessage(const Event_ID theId, const void* theParent = 0); + virtual ~Config_PointerMessage(); + + void* pointer() const; + void setPointer(void* pointer); + +private: + void* myPointer; +}; + +#endif /* PARTSET_MESSAGE_H_ */ diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 14d5fa2aa..65d4b14ca 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -58,6 +58,11 @@ std::string Config_WidgetAPI::getProperty(const char* thePropName) return result; } +std::string Config_WidgetAPI::widgetId() +{ + return getProperty("id"); +} + std::string Config_WidgetAPI::widgetTooltip() { return getProperty("tooltip"); diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index 59f44f2b8..c98888f12 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -37,6 +37,7 @@ public: std::string widgetType(); + std::string widgetId(); std::string widgetIcon(); std::string widgetLabel(); std::string widgetTooltip(); diff --git a/src/Config/Config_WidgetMessage.cpp b/src/Config/Config_WidgetMessage.cpp deleted file mode 100644 index 846359f39..000000000 --- a/src/Config/Config_WidgetMessage.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Config_WidgetMessage.cpp - * - * Created on: Mar 21, 2014 - * Author: sbh - */ - -#include - -Config_WidgetMessage::Config_WidgetMessage(const Event_ID theId, const void* theParent) - : Event_Message(theId, theParent) -{ - -} - -Config_WidgetMessage::~Config_WidgetMessage() -{ -} - -const std::string& Config_WidgetMessage::featureId() const -{ - return myFeatureId; -} - -void Config_WidgetMessage::setFeatureId(const std::string& theFeatureId) -{ - myFeatureId = theFeatureId; -} - -const std::string& Config_WidgetMessage::xmlRepresentation() const -{ - return myXMLRepr; -} - -void Config_WidgetMessage::setXmlRepresentation(const std::string& theXmlRep) -{ - myXMLRepr = theXmlRep; -} diff --git a/src/Config/Config_WidgetMessage.h b/src/Config/Config_WidgetMessage.h deleted file mode 100644 index 1aa00d86d..000000000 --- a/src/Config/Config_WidgetMessage.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Config_WidgetMessage.h - * - * Created on: Mar 21, 2014 - * Author: sbh - */ - -#ifndef PARTSET_MESSAGE_H_ -#define PARTSET_MESSAGE_H_ - -#include - -#include -#include - -class CONFIG_EXPORT Config_WidgetMessage: public Event_Message -{ -public: - Config_WidgetMessage(const Event_ID theId, const void* theParent = 0); - virtual ~Config_WidgetMessage(); - - const std::string& featureId() const; - const std::string& xmlRepresentation() const; - void setFeatureId(const std::string& featureId); - void setXmlRepresentation(const std::string& xmlRepresentation); - - std::string myFeatureId; - std::string myXMLRepr; -}; - -#endif /* PARTSET_MESSAGE_H_ */ diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt new file mode 100644 index 000000000..00adfbb5a --- /dev/null +++ b/src/ModuleBase/CMakeLists.txt @@ -0,0 +1,36 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) + +INCLUDE(Common) +SET(CMAKE_AUTOMOC ON) + +SET(PROJECT_HEADERS + ModuleBase.h + ModuleBase_Operation.h +) + +SET(PROJECT_SOURCES + ModuleBase_Operation.cpp +) + +SET(PROJECT_LIBRARIES + ModelAPI + ${Qt5Widgets_LIBRARIES} +) + +SET(PROJECT_AUTOMOC + ${CMAKE_CURRENT_BINARY_DIR}/ModuleBase_automoc.cpp +) + +#QT5_ADD_RESOURCES(PROJECT_COMPILED_RESOURCES ${PROJECT_RESOURCES}) +#QT5_ADD_TRANSLATION(QM_RESOURCES ${TEXT_RESOURCES}) + +SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES}) +#SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES}) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/ModelAPI) + +ADD_DEFINITIONS(-DMODULEBASE_EXPORTS) +ADD_LIBRARY(ModuleBase SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(ModuleBase ${PROJECT_LIBRARIES}) + +INSTALL(TARGETS ModuleBase DESTINATION bin) diff --git a/src/ModuleBase/ModuleBase.h b/src/ModuleBase/ModuleBase.h new file mode 100644 index 000000000..e4a58e3d7 --- /dev/null +++ b/src/ModuleBase/ModuleBase.h @@ -0,0 +1,18 @@ +#ifndef MODULEBASE_H +#define MODULEBASE_H + +#if defined MODULEBASE_EXPORTS +#if defined WIN32 +#define MODULEBASE_EXPORT __declspec( dllexport ) +#else +#define MODULEBASE_EXPORT +#endif +#else +#if defined WIN32 +#define MODULEBASE_EXPORT __declspec( dllimport ) +#else +#define MODULEBASE_EXPORT +#endif +#endif + +#endif //MODULEBASE_H diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp new file mode 100644 index 000000000..b3250ff01 --- /dev/null +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -0,0 +1,330 @@ +/* + * ModuleBase_Operation.cpp + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + +#include "ModuleBase_Operation.h" + +#include +#include +#include +#include +#include + +/*! + \brief Constructor + \param XGUI_Workshop - workshop for this operation + + Constructs an empty operation. Constructor should work very fast because many + operators may be created after starting workshop but only several from them + may be used. As result this constructor stores given workshop in myApp field + and set Waiting status. + */ +ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* parent) + : QObject(parent), + myFlags(Transaction), + myState(Waiting), + myExecStatus(Rejected), + myOperationId(theId) +{ + myFeature = ModelAPI_PluginManager::get()->createFeature(theId.toStdString()); +} + +/*! + * \brief Destructor + */ +ModuleBase_Operation::~ModuleBase_Operation() +{ + +} + +/*! + * \brief Unique name of the operation + * + * Returns string name of the operation. + */ +QString ModuleBase_Operation::operationId() const +{ + return myOperationId; +} + +/*! + * \brief Gets state of operation + * \return Value from OperationState enumeration + * + * Gets state of operation (see OperationState enumeration) + */ +ModuleBase_Operation::OperationState ModuleBase_Operation::state() const +{ + return myState; +} + +/*! + * \brief Verifies whether operation is an ran one (state()==Running) + * \return TRUE if operation is active, FALSE otherwise + * + * Verifies whether operation is an running. Returns TRUE if state of operator + * is Running + */ +bool ModuleBase_Operation::isRunning() const +{ + return state() == Running; +} + +/*! + * \brief Verifies whether given operator is valid for this one + * \param theOtherOp - other operation + * \return Returns TRUE if the given operator is valid for this one + * + * Verifies whether given operator is valid for this one (i.e. can be started "above" + * this operator) + */ +bool ModuleBase_Operation::isValid(ModuleBase_Operation*) const +{ + return false; +} + +/*! + * \brief Verifies whether this operator can be always started above any already running one + * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this ) + * + * This method must be redefined in derived operation if operation of derived class + * must be always can start above any launched one. Default implementation returns FALSE, + * so it is being checked for IsValid, but some operations may overload IsGranted() + * In this case they will always start, no matter what operation is running. + */ +bool ModuleBase_Operation::isGranted() const +{ + return false; +} + +/* + * Returns pointer to the root document. + */ +std::shared_ptr ModuleBase_Operation::document() const +{ + return ModelAPI_PluginManager::get()->rootDocument(); +} + +/*! + * \brief Sets slot which is called when operation is started + * \param theReceiver - object containing slot + * \param theSlot - slot of theReceiver object + * \return TR if slot was connected successfully, FALSE otherwise + * + * Sets slot which is called when operation is started. There is no point in + * using this method. It would be better to inherit own operator from base + * one and redefine startOperation method + */ +bool ModuleBase_Operation::setSlot(const QObject* theReceiver, const char* theSlot) +{ + return connect(this, SIGNAL(callSlot()), theReceiver, theSlot); +} + +/*! + * \brief Sets the flags of operation + * \param f - flags of operation to be set + * + * Sets flags of operation (see Flags enumeration) + */ +void ModuleBase_Operation::setFlags(const int f) +{ + myFlags = myFlags | f; +} + +/*! + * \brief Clears the flags of operation + * \param f - flags of operation to be cleared + * + * Clears flags of operation (see Flags enumeration) + */ +void ModuleBase_Operation::clearFlags(const int f) +{ + myFlags = myFlags & ~f; +} + +/*! + * \brief Test the flags of operation + * \param f - flags of operation to be tested + * + * Returns TRUE if the specified flags set in the operation (see Flags enumeration) + */ +bool ModuleBase_Operation::testFlags(const int f) const +{ + return (myFlags & f) == f; +} + +/*! + * \brief Gets execution status + * \return Execution status + * + * Gets execution status + */ +int ModuleBase_Operation::execStatus() const +{ + return myExecStatus; +} + +/*! + * \brief Returns XML representation of the operation's widget. + * \return XML QString + * + * Returns XML representation of the operation's widget. + */ +const QString& ModuleBase_Operation::xmlRepresentation() const +{ + return myXmlRepr; +} + +/*! + * \brief Sets XML representation of the operation's widget. + * \param xmlRepr - XML QString + * + * Sets XML representation of the operation's widget. + */ +void ModuleBase_Operation::setXmlRepresentation(const QString& xmlRepr) +{ + myXmlRepr = xmlRepr; +} + +/*! + * \brief Starts operation + * + * Public slot. Verifies whether operation can be started and starts operation. + * This slot is not virtual and cannot be redefined. Redefine startOperation method + * to change behavior of operation. There is no point in using this method. It would + * be better to inherit own operator from base one and redefine startOperation method + * instead. + */ +void ModuleBase_Operation::start() +{ + //document()->start(this); + document()->startOperation(); + + startOperation(); + emit started(); +} + +/*! + * \brief Aborts operation + * + * Public slot. Aborts operation. This slot is not virtual and cannot be redefined. + * Redefine abortOperation method to change behavior of operation instead + */ +void ModuleBase_Operation::abort() +{ + abortOperation(); + myState = Waiting; + emit aborted(); + + stopOperation(); + emit stopped(); + + document()->abortOperation(); +} + +/*! + * \brief Commits operation + * + * Public slot. Commits operation. This slot is not virtual and cannot be redefined. + * Redefine commitOperation method to change behavior of operation instead + */ +void ModuleBase_Operation::commit() +{ + commitOperation(); + myState = Waiting; + emit committed(); + + stopOperation(); + emit stopped(); + + document()->finishOperation(); +} + +/*! + * \brief Stores a real value in model. + * \param theValue - to store + * + * Public slot. Passes theValue into the model. + */ +void ModuleBase_Operation::storeReal(double theValue) +{ + QString anId = sender()->objectName(); + std::shared_ptr aData = myFeature->data(); + std::shared_ptr aReal = aData->real(anId.toStdString()); + aReal->setValue(theValue); +} + +/*! + * \brief Verifies whether operator is ready to start. + * \return TRUE if operation is ready to start + * + * Default implementation returns TRUE. Redefine this method to add own verifications + */ +bool ModuleBase_Operation::isReadyToStart() const +{ + return true; +} + +/*! + * \brief Virtual method called when operation is started + * + * Virtual method called when operation started (see start() method for more description) + * Default implementation calls corresponding slot and commits immediately. + */ +void ModuleBase_Operation::startOperation() +{ + //emit callSlot(); + //commit(); +} + +/*! + * \brief Virtual method called when operation is started + * + * Virtual method called when operation stopped - committed or aborted. + */ +void ModuleBase_Operation::stopOperation() +{ +} + +/*! + * \brief Virtual method called when operation aborted + * + * Virtual method called when operation aborted (see abort() method for more description) + */ +void ModuleBase_Operation::abortOperation() +{ +} + +/*! + * \brief Virtual method called when operation committed + * + * Virtual method called when operation committed (see commit() method for more description) + */ +void ModuleBase_Operation::commitOperation() +{ +} + +/*! + * \brief Sets execution status + * \param theStatus - execution status + * + * Sets myExecStatus to the given value + */ +void ModuleBase_Operation::setExecStatus(const int theVal) +{ + myExecStatus = (ExecStatus) theVal; +} + +/*! + * \brief Sets state of operation + * \param theState - state of operation to be set + * + * Sets state of operation (see OperationState enumeration) + */ +void ModuleBase_Operation::setState(const ModuleBase_Operation::OperationState theState) +{ + myState = theState; +} diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h new file mode 100644 index 000000000..5daf8e6c6 --- /dev/null +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -0,0 +1,136 @@ +/* + * ModuleBase_Operation.h + * + * Created on: Apr 2, 2014 + * Author: sbh + */ + + +#ifndef MODULEBASE_OPERATION_H +#define MODULEBASE_OPERATION_H + +#include + +#include +#include + +#include + +class SUIT_Study; +class XGUI_Workshop; +class ModelAPI_Feature; +class ModelAPI_Document; + +/*! + \class ModuleBase_Operation + * \brief Base class for all operations + * + * Base class for all operations. If you perform an action it is reasonable to create + * operation intended for this. This is a base class for all operations which provides + * mechanism for correct starting operations, starting operations above already started + * ones, committing operations and so on. To create own operation it is reasonable to + * inherit it from this class and redefines virtual methods to provide own behavior + * Main virtual methods are + * - virtual bool isReadyToStart(); + * - virtual void startOperation(); + * - virtual void abortOperation(); + * - virtual void commitOperation(); + */ + +class MODULEBASE_EXPORT ModuleBase_Operation: public QObject +{ +Q_OBJECT + +public: + /*! Enum describes state of operation */ + enum OperationState + { + Waiting, //!< Operation is not used (it is not run or suspended) + Running, //!< Operation is started + }; + + /*! + * Enum describes execution status of operation. Execution status often used after + * ending work of operation which was started from this one. In this case this + * operation can ask previously started operation whether it finished successfully. + */ + enum ExecStatus + { + Rejected, //!< Operation has not performed any action (modification of data model for example) + Accepted //!< Operation has performed an actions and must be stopped + }; + + /*! + * Enum describes setting of the operation. + */ + enum Flags + { + None = 0x00, //!< None options + Transaction = 0x01 //!< Automatically open (commit/abort) transaction during start (commit/abort). + }; + +public: + ModuleBase_Operation(const QString& theId = "", QObject* parent = 0); + virtual ~ModuleBase_Operation(); + + // Operation processing. + virtual QString operationId() const; + + OperationState state() const; + bool isRunning() const; + virtual bool isValid(ModuleBase_Operation* theOtherOp) const; + virtual bool isGranted() const; + + bool setSlot(const QObject* theReceiver, const char* theSlot); + + void setFlags(const int); + void clearFlags(const int); + bool testFlags(const int) const; + + int execStatus() const; + + // Widget processing. + const QString& xmlRepresentation() const; + void setXmlRepresentation(const QString& xmlRepr); + +signals: + void started(); + void aborted(); + void committed(); + void stopped(); //!< operation aborted or committed + + void callSlot(); + +public slots: + void start(); + void abort(); + void commit(); + + // Data model operations. + void storeReal(double); + +protected: + virtual bool isReadyToStart() const; + + virtual void startOperation(); + virtual void stopOperation(); + virtual void abortOperation(); + virtual void commitOperation(); + + void setExecStatus(const int); + void setState(const OperationState); + + std::shared_ptr document() const; + +private: + int myFlags; //!< Operation flags + OperationState myState; //!< Operation state + ExecStatus myExecStatus; //!< Execution status + + //!< Next fields could be extracted into a subclass; + QString myOperationId; + QString myXmlRepr; + std::shared_ptr myFeature; +}; + +#endif diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index bb9960d9a..0fc2e748b 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -21,6 +21,7 @@ SET(TEXT_RESOURCES ) SET(PROJECT_LIBRARIES + ModuleBase Config ${Qt5Widgets_LIBRARIES} ) @@ -35,9 +36,11 @@ QT5_ADD_TRANSLATION(QM_RESOURCES ${TEXT_RESOURCES}) SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES}) SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES}) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/Config) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/Event) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI + ${CMAKE_SOURCE_DIR}/src/Config + ${CMAKE_SOURCE_DIR}/src/Event + ${CMAKE_SOURCE_DIR}/src/ModuleBase +) ADD_DEFINITIONS(-DPARTSET_EXPORTS) ADD_LIBRARY(PartSet SHARED @@ -51,4 +54,6 @@ ADD_LIBRARY(PartSet SHARED # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES}) +ADD_DEPENDENCIES(PartSet ModuleBase) + INSTALL(TARGETS PartSet DESTINATION bin) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index f8e60b9e4..409e38484 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,6 +1,7 @@ #include -#include +#include +#include #include #include #include @@ -40,10 +41,10 @@ void PartSet_Module::createFeatures() void PartSet_Module::featureCreated(XGUI_Command* theFeature) { QString aFtId = theFeature->getId(); - theFeature->connectTo(this, SLOT(onCommandTriggered())); + theFeature->connectTo(this, SLOT(onFeatureTriggered())); } -void PartSet_Module::onCommandTriggered() +void PartSet_Module::onFeatureTriggered() { Config_ModuleReader aModuleReader = Config_ModuleReader(); aModuleReader.readAll(); @@ -52,12 +53,13 @@ void PartSet_Module::onCommandTriggered() Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName); aWdgReader.readAll(); XGUI_Command* aCmd = dynamic_cast(sender()); - std::string aCmdId = aCmd->getId().toStdString(); - std::string aXMLWidgetCfg = aWdgReader.featureWidgetCfg(aCmdId); + QString aCmdId = aCmd->getId(); + std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString()); //TODO(sbh): Implement static method to extract event id [SEID] static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent"); - Config_WidgetMessage aMessage(aModuleEvent, this); - aMessage.setFeatureId(aCmdId); - aMessage.setXmlRepresentation(aXMLWidgetCfg); + Config_PointerMessage aMessage(aModuleEvent, this); + ModuleBase_Operation* aPartSetOp = new ModuleBase_Operation(aCmdId, this); + aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg)); + aMessage.setPointer(aPartSetOp); Event_Loop::loop()->send(aMessage); } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 913616725..f4894e239 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -19,7 +19,7 @@ public: virtual void featureCreated(XGUI_Command* theFeature); public slots: - void onCommandTriggered(); + void onFeatureTriggered(); private: XGUI_Workshop* myWorkshop; diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 713f9b905..c91ec1451 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -67,6 +67,7 @@ SET(PROJECT_LIBRARIES PyInterp PyEvent ModelAPI + ModuleBase ) QT5_ADD_RESOURCES(PROJECT_COMPILED_RESOURCES ${PROJECT_RESOURCES}) @@ -83,6 +84,7 @@ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Event ${PROJECT_SOURCE_DIR}/src/PyInterp ${PROJECT_SOURCE_DIR}/src/PyConsole ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModuleBase ${CAS_INCLUDE_DIRS}) LINK_DIRECTORIES($ENV{PYTHON_LIB_DIR}) diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index c89e0fc0a..9619f1cd6 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -23,12 +23,13 @@ #include #include #include - +#include XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), - myObjectBrowser(0), - myPythonConsole(0) + myObjectBrowser(NULL), + myPythonConsole(NULL), + myPropertyPanelDock(NULL) { setWindowTitle(tr("New Geom")); myMenuBar = new XGUI_MainMenu(this); @@ -91,6 +92,21 @@ void XGUI_MainWindow::hidePythonConsole() myPythonConsole->parentWidget()->hide(); } +void XGUI_MainWindow::showPropertyPanel() +{ + QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); + aViewAct->setEnabled(true); + myPropertyPanelDock->show(); + myPropertyPanelDock->raise(); +} + +void XGUI_MainWindow::hidePropertyPanel() +{ + QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); + aViewAct->setEnabled(false); + myPropertyPanelDock->hide(); +} + /* * Creates dock widgets, places them in corresponding area * and tabifies if necessary. @@ -99,10 +115,11 @@ void XGUI_MainWindow::createDockWidgets() { QDockWidget* aObjDock = createObjectBrowser(); addDockWidget(Qt::LeftDockWidgetArea, aObjDock); - QDockWidget* aPropPanelDock = createPropertyPanel(); - addDockWidget(Qt::LeftDockWidgetArea, aPropPanelDock); + myPropertyPanelDock = createPropertyPanel(); + addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock); + hidePropertyPanel(); //setWidget(aContent); QWidget* aCustomWidget = new QWidget(aContent); - aCustomWidget->setObjectName("PropertyPanelWidget"); + aCustomWidget->setObjectName("property_panel_widget"); aMainLay->addWidget(aCustomWidget); aMainLay->addStretch(1); @@ -133,9 +150,11 @@ QDockWidget* XGUI_MainWindow::createPropertyPanel() aBtnLay->addWidget(aBtn); aBtnLay->addStretch(1); aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); + aBtn->setObjectName("property_panel_ok"); aBtn->setFlat(true); aBtnLay->addWidget(aBtn); aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); + aBtn->setObjectName("property_panel_cancel"); aBtn->setFlat(true); aBtnLay->addWidget(aBtn); diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index e12614a73..5ac18d547 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -37,8 +37,11 @@ public: return myViewer; } +public slots: void showPythonConsole(); void hidePythonConsole(); + void showPropertyPanel(); + void hidePropertyPanel(); private: void createDockWidgets(); @@ -47,6 +50,7 @@ private: XGUI_MainMenu* myMenuBar; XGUI_ObjectsBrowser* myObjectBrowser; + QDockWidget* myPropertyPanelDock; XGUI_Viewer* myViewer; diff --git a/src/XGUI/XGUI_WidgetFactory.cpp b/src/XGUI/XGUI_WidgetFactory.cpp index b2551c62c..eeb6c10cd 100644 --- a/src/XGUI/XGUI_WidgetFactory.cpp +++ b/src/XGUI/XGUI_WidgetFactory.cpp @@ -6,7 +6,9 @@ */ #include +#include +#include #include #include @@ -20,9 +22,11 @@ #include #endif -XGUI_WidgetFactory::XGUI_WidgetFactory(const std::string& theXml) +XGUI_WidgetFactory::XGUI_WidgetFactory(ModuleBase_Operation* theOperation) + : myOperation(theOperation) { - myWidgetApi = new Config_WidgetAPI(theXml); + QString aXml = myOperation->xmlRepresentation(); + myWidgetApi = new Config_WidgetAPI(aXml.toStdString()); } XGUI_WidgetFactory::~XGUI_WidgetFactory() @@ -41,8 +45,8 @@ void XGUI_WidgetFactory::fillWidget(QWidget* theParent) do { std::string aWdgType = myWidgetApi->widgetType(); QWidget* aWidget = NULL; - if (aWdgType == "value") { - aWidget = valueWidget(); + if (aWdgType == NODE_DOUBLE_WDG) { + aWidget = doubleSpinBoxWidget(); } else { #ifdef _DEBUG qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type"; @@ -55,7 +59,7 @@ void XGUI_WidgetFactory::fillWidget(QWidget* theParent) theParent->setLayout(aWidgetLay); } -QWidget* XGUI_WidgetFactory::valueWidget() +QWidget* XGUI_WidgetFactory::doubleSpinBoxWidget() { QWidget* result = new QWidget(); QHBoxLayout* aControlLay = new QHBoxLayout(result); @@ -67,20 +71,26 @@ QWidget* XGUI_WidgetFactory::valueWidget() aControlLay->addWidget(aLabel); QDoubleSpinBox* aBox = new QDoubleSpinBox(result); + QString anObjName = QString::fromStdString(myWidgetApi->widgetId()); + aBox->setObjectName(anObjName); bool isOk = false; - double aMinVal = qs(myWidgetApi->getProperty("min")).toDouble(&isOk); + std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN); + double aMinVal = qs(aProp).toDouble(&isOk); if (isOk) { aBox->setMinimum(aMinVal); } - double aMaxVal = qs(myWidgetApi->getProperty("max")).toDouble(&isOk); + aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX); + double aMaxVal = qs(aProp).toDouble(&isOk); if (isOk) { aBox->setMaximum(aMaxVal); } - double aStepVal = qs(myWidgetApi->getProperty("step")).toDouble(&isOk); + aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP); + double aStepVal = qs(aProp).toDouble(&isOk); if (isOk) { aBox->setSingleStep(aStepVal); } - double aDefVal = qs(myWidgetApi->getProperty("default")).toDouble(&isOk); + aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT); + double aDefVal = qs(aProp).toDouble(&isOk); if (isOk) { aBox->setValue(aDefVal); } @@ -88,8 +98,18 @@ QWidget* XGUI_WidgetFactory::valueWidget() aBox->setToolTip(aTTip); aControlLay->addWidget(aBox); aControlLay->setStretch(1, 1); - result->setLayout(aControlLay); + connectWidget(aBox, NODE_DOUBLE_WDG); + return result; +} + +bool XGUI_WidgetFactory::connectWidget(QWidget* theWidget, const QString& theType) +{ + bool result = false; + if (theType == NODE_DOUBLE_WDG) { + result = QObject::connect(theWidget, SIGNAL(valueChanged(double)), + myOperation, SLOT(storeReal(double))); + } return result; } diff --git a/src/XGUI/XGUI_WidgetFactory.h b/src/XGUI/XGUI_WidgetFactory.h index cd02f6382..474559f48 100644 --- a/src/XGUI/XGUI_WidgetFactory.h +++ b/src/XGUI/XGUI_WidgetFactory.h @@ -9,26 +9,29 @@ #define XGUI_WIDGETFACTORY_H_ #include -#include class QWidget; class Config_WidgetAPI; +class ModuleBase_Operation; class XGUI_WidgetFactory { public: - XGUI_WidgetFactory(const std::string&); + XGUI_WidgetFactory(ModuleBase_Operation*); virtual ~XGUI_WidgetFactory(); void fillWidget(QWidget* theParent); protected: - QWidget* valueWidget(); + QWidget* doubleSpinBoxWidget(); + + bool connectWidget(QWidget*, const QString&); private: QString qs(const std::string& theStdString) const; Config_WidgetAPI* myWidgetApi; + ModuleBase_Operation* myOperation; }; #endif /* XGUI_WIDGETFACTORY_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index ecf852496..526adf0c8 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -8,15 +8,17 @@ #include "XGUI_Workshop.h" #include "XGUI_Viewer.h" #include "XGUI_WidgetFactory.h" +#include "ModuleBase_Operation.h" #include #include -#include +#include #include #include #include #include +#include #ifdef _DEBUG #include @@ -29,10 +31,11 @@ #endif XGUI_Workshop::XGUI_Workshop() - : QObject() + : QObject(), + myCurrentOperation(NULL), + myPartSetModule(NULL) { myMainWindow = new XGUI_MainWindow(); - myPartSetModule = NULL; } //****************************************************** @@ -117,7 +120,8 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage) addFeature(aFeatureMsg); return; } - const Config_WidgetMessage* aPartSetMsg = dynamic_cast(theMessage); + const Config_PointerMessage* aPartSetMsg = + dynamic_cast(theMessage); if (aPartSetMsg) { fillPropertyPanel(aPartSetMsg); return; @@ -168,21 +172,35 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) /* * */ -void XGUI_Workshop::fillPropertyPanel(const Config_WidgetMessage* theMessage) +void XGUI_Workshop::fillPropertyPanel(const Config_PointerMessage* theMessage) { - QWidget* aPropWidget = myMainWindow->findChild("PropertyPanelWidget"); - if (!aPropWidget) { - #ifdef _DEBUG - qDebug() << "XGUI_Workshop::fillPropertyPanel: " << "Unable to find property panel"; - #endif - return; - } + ModuleBase_Operation* anOperation = (ModuleBase_Operation*)(theMessage->pointer()); + connectToPropertyPanel(anOperation); + QWidget* aPropWidget = myMainWindow->findChild("property_panel_widget"); qDeleteAll(aPropWidget->children()); - std::string aXml = theMessage->xmlRepresentation(); - XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aXml); + anOperation->start(); + XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(anOperation); aFactory.fillWidget(aPropWidget); } +void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation) +{ + if(myCurrentOperation) { + //FIXME: Ask user about aborting of current operation? + myCurrentOperation->abort(); + myCurrentOperation->deleteLater(); + } + myCurrentOperation = theOperation; + + QPushButton* aOkBtn = myMainWindow->findChild("property_panel_ok"); + connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit())); + QPushButton* aCancelBtn = myMainWindow->findChild("property_panel_cancel"); + connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort())); + + connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel())); + connect(theOperation, SIGNAL(stopped()), myMainWindow, SLOT(hidePropertyPanel())); +} + //****************************************************** void XGUI_Workshop::onExit() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 68300e96b..aa17e5a9e 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -13,9 +13,10 @@ class XGUI_MainWindow; class XGUI_Command; class XGUI_Module; class XGUI_Workbench; +class ModuleBase_Operation; class Config_FeatureMessage; -class Config_WidgetMessage; +class Config_PointerMessage; class XGUI_Workshop: public QObject, public Event_Listener { @@ -46,7 +47,9 @@ public slots: protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); - void fillPropertyPanel(const Config_WidgetMessage*); + void fillPropertyPanel(const Config_PointerMessage*); + + void connectToPropertyPanel(ModuleBase_Operation* theOperation); private: void initMenu(); @@ -56,6 +59,8 @@ private: XGUI_MainWindow* myMainWindow; XGUI_Module* myPartSetModule; + + ModuleBase_Operation* myCurrentOperation; }; #endif -- 2.39.2