Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 05:39:17 +0000 (09:39 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 05:39:17 +0000 (09:39 +0400)
Union of the stopped(), started() signals processing of the operation.

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index f82eee4b2249fe239766cb03c221710028381f39..99bd4c85ba788cf32592e49af916dd5d068bc7ac 100644 (file)
@@ -34,7 +34,9 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
   myWorkshop = theWshop;
   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
 
-  connect(anOperationMgr, SIGNAL(beforeOperationStart()), this, SLOT(onBeforeOperationStart()));
+  connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
+  connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
+          this, SLOT(onOperationStopped(ModuleBase_Operation*)));
 }
 
 PartSet_Module::~PartSet_Module()
@@ -110,22 +112,21 @@ void PartSet_Module::onVisualizePreview(bool isDisplay)
     myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
 }
 
-void PartSet_Module::onBeforeOperationStart()
+void PartSet_Module::onOperationStarted()
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
 
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
-    connect(anOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
     connect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
     connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
             aPreviewOp, SLOT(onViewSelectionChanged()));
   }
 }
 
-void PartSet_Module::onOperationStopped()
+void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
 {
-  ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(sender());
+  ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
   if (!anOperation)
     return;
 
index dc22f1f440137b4a13912da4ca494081584acf26..e343e4373ace6aa18bad89931116c3f22ea91469 100644 (file)
@@ -22,8 +22,8 @@ public:
 
 public slots:
   void onFeatureTriggered();
-  void onBeforeOperationStart();
-  void onOperationStopped();
+  void onOperationStarted();
+  void onOperationStopped(ModuleBase_Operation* theOperation);
   void onVisualizePreview(bool isDisplay);
 
 private:
index ae5aeb04732b065d042ee57b34a82ad61e128894..bca019e31da01b8eea4ad02e56cd8d7a0e266416 100644 (file)
@@ -4,46 +4,31 @@
 
 #include <QMessageBox>
 
-/*!
- \brief Constructor
- */
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
 : QObject(theParent)
 {
 }
 
-/*!
- \brief Destructor
- */
 XGUI_OperationMgr::~XGUI_OperationMgr()
 {
 }
 
-/*!
- \brief Returns the current operation or NULL
- * \return the current operation
- */
 ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
 {
   return myOperations.count() > 0 ? myOperations.last() : 0;
 }
 
-/*!
- \brief Sets the current operation or NULL
- * \return the current operation
- */
 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
 {
   if (!canStartOperation(theOperation))
     return false;
 
   myOperations.append(theOperation);
-  emit beforeOperationStart();
 
   connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
-  theOperation->start();
+  connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
 
-  emit afterOperationStart();
+  theOperation->start();
   return true;
 }
 
@@ -80,7 +65,10 @@ void XGUI_OperationMgr::onOperationStopped()
   if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
     return;
 
+  emit operationStopped(anOperation);
+
   myOperations.removeAll(anOperation);
+  anOperation->deleteLater();
 
   // get last operation which can be resumed
   ModuleBase_Operation* aResultOp = 0;
index 4fabac82118e340dbf2c05d223a7a71716969e06..b45b84d3c9163162024cf75c94bcec9a411301fd 100644 (file)
 /**\class XGUI_OperationMgr
  * \ingroup GUI
  * \brief Operation manager. Servers to manupulate to the workshop operations. Contains a stack
- *   of started operations and uses the upper one as a current.
+ * of started operations. In simple case, if only one operration is started, the stack contains
+ * one operation. It is possible for some kind of operations to start them above already
+ * started one. In that case, the previous active operation becames suspended, a new one - active.
+ * The new operation is added to the top of the stack. Then it is finished, it is removed from
+ * the stack and the previous operation is activated.
  */
 class XGUI_EXPORT XGUI_OperationMgr : public QObject
 {
   Q_OBJECT
 public:
+  /// Constructor
+  /// \param theParent the parent
   XGUI_OperationMgr(QObject* theParent);
+  /// Destructor
   virtual ~XGUI_OperationMgr();
 
+  /// Returns the current operation or NULL
+  /// \return the current operation
   ModuleBase_Operation* currentOperation() const;
+  /// Sets the current operation or NULL
+  /// \return the current operation
   bool startOperation(ModuleBase_Operation* theOperation);
 
   void commitCurrentOperation();
 
 signals:
-  void beforeOperationStart();
-  void afterOperationStart();
+  void operationStarted();
+  void operationStopped(ModuleBase_Operation* theOperation);
 
 protected:
   bool canStartOperation(ModuleBase_Operation* theOperation);
@@ -36,8 +47,9 @@ protected slots:
   void onOperationStopped();
 
 private:
-  typedef QList<ModuleBase_Operation*> Operations;
-  Operations myOperations;
+  typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
+  Operations myOperations; ///< a stack of started operations. The active operation is on top,
+                           // others are suspended and started by the active is finished
 };
 
 #endif
index f606615a7b4eed8787ef791d5433bcb4fd070608..6a2bb4f1351910562d560f91089b20432b4beaea 100644 (file)
@@ -50,8 +50,9 @@ XGUI_Workshop::XGUI_Workshop()
   mySelector = new XGUI_SelectionMgr(this);
   myDisplayer = new XGUI_Displayer(myMainWindow->viewer());
   myOperationMgr = new XGUI_OperationMgr(this);
-  connect(myOperationMgr, SIGNAL(beforeOperationStart()), this, SLOT(onBeforeOperationStart()));
-  connect(myOperationMgr, SIGNAL(afterOperationStart()),  this, SLOT(onAfterOperationStart()));
+  connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
+  connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
+          this, SLOT(onOperationStopped(ModuleBase_Operation*)));
 }
 
 //******************************************************
@@ -156,33 +157,11 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage)
     ModuleBase_PropPanelOperation* anOperation =
         (ModuleBase_PropPanelOperation*)(aPartSetMsg->pointer());
 
-    if (myOperationMgr->startOperation(anOperation))
-    {
-      if (anOperation->isPerformedImmediately())
-      {
+    if (myOperationMgr->startOperation(anOperation)) {
+      if (anOperation->isPerformedImmediately()) {
         myOperationMgr->commitCurrentOperation();
         updateCommandStatus();
       }
-      /*if(anOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
-        //connectToPropertyPanel(anOperation);
-
-        anOperation->start();
-
-        if (anOperation->isPerformedImmediately()) {
-          anOperation->commit();
-          updateCommandStatus();
-        }
-      } else {
-        connectToPropertyPanel(anOperation);
-        QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
-        qDeleteAll(aPropWidget->children());
-
-        anOperation->start();
-        
-        XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(anOperation);
-        aFactory.createWidget(aPropWidget);
-        myMainWindow->setPropertyPannelTitle(anOperation->description());
-      }*/
     }
     return;
   }
@@ -194,34 +173,37 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage)
 
 }
 
-void XGUI_Workshop::onBeforeOperationStart()
+void XGUI_Workshop::onOperationStarted()
 {
   ModuleBase_PropPanelOperation* aOperation =
         (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation());
 
   if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
-    //myPartSetModule->connectToPropertyPanel(aOperation);
   } else {
     connectWithOperation(aOperation);
     QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
     qDeleteAll(aPropWidget->children());
-  }
-}
 
-void XGUI_Workshop::onAfterOperationStart()
-{
-  ModuleBase_PropPanelOperation* aOperation =
-        (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation());
+    myMainWindow->showPropertyPanel();
 
-  if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
-  } else {
     XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aOperation);
-    QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
     aFactory.createWidget(aPropWidget);
     myMainWindow->setPropertyPannelTitle(aOperation->description());
   }
 }
 
+/**
+ *
+ */
+void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
+{
+  myMainWindow->hidePropertyPanel();
+  updateCommandStatus();
+
+  XGUI_MainMenu* aMenu = myMainWindow->menuObject();
+  aMenu->restoreCommandState();
+}
+
 /*
  *
  */
@@ -259,20 +241,6 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
   myPartSetModule->featureCreated(aCommand);
 }
 
-/*
- *
- */
-/*void XGUI_Workshop::fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation)
-{
-  connectWithOperation(theOperation);
-  QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
-  qDeleteAll(aPropWidget->children());
-  theOperation->start();
-  XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(theOperation);
-  aFactory.createWidget(aPropWidget);
-  myMainWindow->setPropertyPannelTitle(theOperation->description());
-}*/
-
 /*
  * Makes a signal/slot connections between Property Panel
  * and given operation. The given operation becomes a
@@ -286,13 +254,7 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
   QPushButton* aCancelBtn = aPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
   connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort()));
 
-  connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel()));
-  connect(theOperation, SIGNAL(stopped()), myMainWindow, SLOT(hidePropertyPanel()));
-  connect(theOperation, SIGNAL(stopped()), this, SLOT(updateCommandStatus()));
-
   XGUI_MainMenu* aMenu = myMainWindow->menuObject();
-  connect(theOperation, SIGNAL(stopped()), aMenu, SLOT(restoreCommandState()));
-
   XGUI_Command* aCommand = aMenu->feature(theOperation->operationId());
   //Abort operation on uncheck the command
   connect(aCommand, SIGNAL(toggled(bool)), theOperation, SLOT(setRunning(bool)));
index a1c79c0b3ece2d859c9be45fde0d430ab48a3c46..68b961589f764b4fda42a4c246b24f6c18ca8b26 100644 (file)
@@ -75,8 +75,8 @@ protected:
   void connectWithOperation(ModuleBase_Operation* theOperation);
 
 protected slots:
-  void onBeforeOperationStart();
-  void onAfterOperationStart();
+  void onOperationStarted();
+  void onOperationStopped(ModuleBase_Operation* theOperation);
 
 private:
   void initMenu();
@@ -90,7 +90,7 @@ private:
   XGUI_SelectionMgr* mySelector;
   XGUI_Displayer* myDisplayer;
 
-  XGUI_OperationMgr* myOperationMgr;
+  XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
 };
 
 #endif