Salome HOME
Property pannel connected with the model through the ModuelBase dll.
authorsbh <sergey.belash@opencascade.com>
Tue, 8 Apr 2014 11:38:47 +0000 (15:38 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 8 Apr 2014 11:38:47 +0000 (15:38 +0400)
23 files changed:
CMakeLists.txt
src/Config/CMakeLists.txt
src/Config/Config_Keywords.h
src/Config/Config_PointerMessage.cpp [new file with mode: 0644]
src/Config/Config_PointerMessage.h [new file with mode: 0644]
src/Config/Config_WidgetAPI.cpp
src/Config/Config_WidgetAPI.h
src/Config/Config_WidgetMessage.cpp [deleted file]
src/Config/Config_WidgetMessage.h [deleted file]
src/ModuleBase/CMakeLists.txt [new file with mode: 0644]
src/ModuleBase/ModuleBase.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_Operation.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_Operation.h [new file with mode: 0644]
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_WidgetFactory.cpp
src/XGUI/XGUI_WidgetFactory.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index f13e37375395277ad7d5135a8cc57b0797eedbd2..29ee4ab93208cac3be39df2f7ad0bffd776b1a80 100644 (file)
@@ -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)
index 8e6369fa3c329aae86f959c32d8a458c03050a9a..159be465ca1bd23c221dabbe9d5840ce1cd58a92 100644 (file)
@@ -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
index 107ba9ec7460ddf42765222318f7b0ee51af150b..bca951680913fdc4efe8b2b12b14d2ee29de58e2 100644 (file)
@@ -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 (file)
index 0000000..cc4b353
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Config_PointerMessage.cpp
+ *
+ *  Created on: Mar 21, 2014
+ *      Author: sbh
+ */
+
+#include <Config_PointerMessage.h>
+
+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 (file)
index 0000000..e0ac3e4
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Config_PointerMessage.h
+ *
+ *  Created on: Mar 21, 2014
+ *      Author: sbh
+ */
+
+#ifndef PARTSET_MESSAGE_H_
+#define PARTSET_MESSAGE_H_
+
+#include <Config.h>
+#include <Event_Message.h>
+
+/*
+ * 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_ */
index 14d5fa2aa9b18323806403b393f6de708c78580a..65d4b14cad33bd13191fd5730a56ffd6b1405234 100644 (file)
@@ -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");
index 59f44f2b89642cf8b84a576c241a2495518058a8..c98888f12339d66b223378151118d86268d4e099 100644 (file)
@@ -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 (file)
index 846359f..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Config_WidgetMessage.cpp
- *
- *  Created on: Mar 21, 2014
- *      Author: sbh
- */
-
-#include <Config_WidgetMessage.h>
-
-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 (file)
index 1aa00d8..0000000
+++ /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 <Config.h>
-
-#include <Event_Message.h>
-#include <string>
-
-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 (file)
index 0000000..00adfbb
--- /dev/null
@@ -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 (file)
index 0000000..e4a58e3
--- /dev/null
@@ -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 (file)
index 0000000..b3250ff
--- /dev/null
@@ -0,0 +1,330 @@
+/*
+ * ModuleBase_Operation.cpp
+ *
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
+ */
+
+#include "ModuleBase_Operation.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_PluginManager.h>
+
+/*!
+ \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<ModelAPI_Document> 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<ModelAPI_Object> aData = myFeature->data();
+  std::shared_ptr<ModelAPI_AttributeDouble> 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 (file)
index 0000000..5daf8e6
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * ModuleBase_Operation.h
+ *
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
+ */
+
+
+#ifndef MODULEBASE_OPERATION_H
+#define MODULEBASE_OPERATION_H
+
+#include <ModuleBase.h>
+
+#include <QObject>
+#include <QString>
+
+#include <memory>
+
+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<ModelAPI_Document> 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<ModelAPI_Feature> myFeature;
+};
+
+#endif
index bb9960d9a646660448531b0e102b76cedf3739ab..0fc2e748b4e5e968e7f182b9a15ad1f0989f7826 100644 (file)
@@ -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)
index f8e60b9e4c75e2efcf2642093c53ef5d1eacf2a0..409e38484871b43be35dd85042f6c838a0fc099f 100644 (file)
@@ -1,6 +1,7 @@
 #include <PartSet_Module.h>
-#include <Config_WidgetMessage.h>
+#include <ModuleBase_Operation.h>
 
+#include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
 #include <Config_WidgetReader.h>
 #include <Event_Loop.h>
@@ -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<XGUI_Command*>(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);
 }
index 9136167253166db81dc25f1d3fab1388488365d6..f4894e239868544517f7f7d0695b5d28065d3f21 100644 (file)
@@ -19,7 +19,7 @@ public:
   virtual void featureCreated(XGUI_Command* theFeature);
 
 public slots:
-  void onCommandTriggered();
+  void onFeatureTriggered();
 
 private:
   XGUI_Workshop* myWorkshop;
index 713f9b9051c88c731b4c2e11939b3de5963ae311..c91ec14515326358a55805e8e60e7918ad1c0deb 100644 (file)
@@ -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})
index c89e0fc0a1224586ceb3059717e6a4ef724db155..9619f1cd6d416b7642b80126a9d5fc850ea537e0 100644 (file)
 #include <QPushButton>
 #include <QScrollArea>
 #include <QComboBox>
-
+#include <QAction>
 
 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(); //<! Invisible by default
 
-  tabifyDockWidget(aPropPanelDock, aObjDock);
+  tabifyDockWidget(aObjDock, myPropertyPanelDock);
 }
 
 
@@ -117,7 +134,7 @@ QDockWidget* XGUI_MainWindow::createPropertyPanel()
   aPropPanel->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);
 
index e12614a7380fa6ac38040960acd193fe5f683cbe..5ac18d5470b30cefe13f8f2ecca8c4c59612eb42 100644 (file)
@@ -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;
 
index b2551c62c667dd59a15d3c20ab2c5f6b960d7a2a..eeb6c10cde969231a91c81b772ac563ba28c4ff1 100644 (file)
@@ -6,7 +6,9 @@
  */
 
 #include <XGUI_WidgetFactory.h>
+#include <ModuleBase_Operation.h>
 
+#include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 
 #include <QWidget>
 #include <QDebug>
 #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;
 }
 
index cd02f6382e461655ebb1b25733706a470783660e..474559f4825d5181abe9ddbc374c6ab1e2ddaaa3 100644 (file)
@@ -9,26 +9,29 @@
 #define XGUI_WIDGETFACTORY_H_
 
 #include <QString>
-#include <string>
 
 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_ */
index ecf8524964668aba6387a308a8393c947c2c479e..526adf0c899ccb5725f410d88b17f0944ae03167 100644 (file)
@@ -8,15 +8,17 @@
 #include "XGUI_Workshop.h"
 #include "XGUI_Viewer.h"
 #include "XGUI_WidgetFactory.h"
+#include "ModuleBase_Operation.h"
 
 #include <Event_Loop.h>
 #include <Config_FeatureMessage.h>
-#include <Config_WidgetMessage.h>
+#include <Config_PointerMessage.h>
 
 #include <QApplication>
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QMdiSubWindow>
+#include <QPushButton>
 
 #ifdef _DEBUG
 #include <QDebug>
 #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<const Config_WidgetMessage*>(theMessage);
+  const Config_PointerMessage* aPartSetMsg =
+      dynamic_cast<const Config_PointerMessage*>(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<QWidget*>("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<QWidget*>("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<QPushButton*>("property_panel_ok");
+  connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit()));
+  QPushButton* aCancelBtn = myMainWindow->findChild<QPushButton*>("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()
 {
index 68300e96bde568391335d49c97793d96c25aa069..aa17e5a9e84886b67f14b5abb1894dd096118f4b 100644 (file)
@@ -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