Salome HOME
Abort operation correction, Cases are: 1. Deselect feature button in ToolBar, 2....
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
index 2805b712a9d582df0fa57d5d1371958cd58ba3e8..510ee796d5d9e8863a007aaecc7460b37880379a 100644 (file)
@@ -1,66 +1,75 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
 #ifndef XGUI_WORKSHOP_H
 #define XGUI_WORKSHOP_H
 
 #include "XGUI.h"
-#include "XGUI_Constants.h"
-#include <Events_Listener.h>
+//#include "XGUI_Constants.h"
 #include <ModuleBase_Definitions.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 
+#include <ModuleBase_ActionInfo.h>
+
 #include <QObject>
 #include <QMap>
 #include <QKeySequence>
 #include <QIcon>
 
-class XGUI_MainWindow;
-class XGUI_Command;
-class XGUI_Workbench;
-class XGUI_SelectionMgr;
+class AppElements_MainWindow;
+class AppElements_Command;
+class AppElements_Workbench;
+
+class XGUI_ActionsMgr;
+class XGUI_ContextMenuMgr;
 class XGUI_Displayer;
+class XGUI_ErrorDialog;
+class XGUI_ErrorMgr;
+class XGUI_ModuleConnector;
+class XGUI_ObjectsBrowser;
 class XGUI_OperationMgr;
+class XGUI_PropertyPanel;
 class XGUI_SalomeConnector;
-class XGUI_ObjectsBrowser;
-class XGUI_ActionsMgr;
-class XGUI_ErrorDialog;
 class XGUI_SalomeViewer;
+class XGUI_SelectionMgr;
 class XGUI_ViewerProxy;
-class XGUI_PropertyPanel;
-class XGUI_ContextMenuMgr;
-class XGUI_ModuleConnector;
+class XGUI_WorkshopListener;
 
-class ModuleBase_Operation;
 class ModuleBase_IModule;
 class ModuleBase_IViewer;
-
-class Config_FeatureMessage;
-class Config_PointerMessage;
+class ModuleBase_Operation;
 
 class QWidget;
 class QDockWidget;
+class QMainWindow;
 
-class ModelAPI_ObjectUpdatedMessage;
-class ModelAPI_ObjectDeletedMessage;
-class ModelAPI_ResultPart;
 class QAction;
 
 /**\class XGUI_Workshop
  * \ingroup GUI
  * \brief Class which defines a configuration of the application (Workshop) and launches it.
  */
-class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
+class XGUI_EXPORT XGUI_Workshop : public QObject
 {
 Q_OBJECT
  public:
-
+  /// Constructor
+  /// \param theConnector a Salome connector object. 
+  /// Used only if the workshop is launched in Salome environment
   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
   virtual ~XGUI_Workshop();
 
   //! Starting of the application
   void startApplication();
 
+  // Activates the module controls. Should be called after module creation
+  void activateModule();
+
+  // Deactivates the module controls. Should be called after module creation
+  void deactivateModule();
+
   //! Returns main window (Desktop) of the application
-  XGUI_MainWindow* mainWindow() const
+  AppElements_MainWindow* mainWindow() const
   {
     return myMainWindow;
   }
@@ -88,7 +97,6 @@ Q_OBJECT
   {
     return myActionsMgr;
   }
-  ;
 
   //! Returns property panel widget
   XGUI_PropertyPanel* propertyPanel() const
@@ -103,10 +111,7 @@ Q_OBJECT
   }
 
   //! Creates and adds a new workbench (menu group) with the given name and returns it
-  XGUI_Workbench* addWorkbench(const QString& theName);
-
-  //! Redefinition of Events_Listener method
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  AppElements_Workbench* addWorkbench(const QString& theName);
 
   //! Returns an object which provides interface to Salome Module (LightApp_Module)
   XGUI_SalomeConnector* salomeConnector() const
@@ -129,8 +134,10 @@ Q_OBJECT
     return myObjectBrowser;
   }
 
+  /// This method is called by Salome module when selection is changed
   void salomeViewerSelectionChanged();
 
+  /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
   XGUI_ViewerProxy* viewer() const
   {
     return myViewerProxy;
@@ -143,15 +150,33 @@ Q_OBJECT
     return myModuleConnector;
   }
 
-  //! Returns icon name according to feature
-  static QIcon featureIcon(const FeaturePtr& theFeature);
-
-  //! Activates or deactivates a part
-  //! If PartPtr is Null pointer then PartSet will be activated
-  void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
+  /// Returns a desktop
+  /// \return a desktop instance
+  QMainWindow* desktop() const;
 
   //! Delete features
-  void deleteObjects(const QObjectPtrList& theList);
+  void deleteObjects();
+
+  //! Returns true if the selected feature can be moved to the position after the current feature
+  //! \return boolean value
+  bool canMoveFeature();
+
+  //! Move selected features to be after the current feature
+  void moveObjects();
+
+  //! Returns true if the object can be shaded. If the object is a compsolid result, the method
+  //! checks subobjects of the result
+  //! \return boolean value
+  bool canBeShaded(const ObjectPtr& theObject) const;
+
+  //! Returns true if there is at least one selected body/construction/group result
+  //! \return boolean value
+  bool canChangeColor() const;
+
+  //! Change color of the features if it is possible
+  //! The operation is available for construction, body and group results
+  //! theObjects a list of selected objects
+  void changeColor(const QObjectPtrList& theObjects);
 
   //! Show the given features in 3d Viewer
   void showObjects(const QObjectPtrList& theList, bool isVisible);
@@ -159,8 +184,12 @@ Q_OBJECT
   //! Show the given features in 3d Viewer
   void showOnlyObjects(const QObjectPtrList& theList);
 
+  /// Set display mode for the given onjects
+  /// \param theList a list of displayed objects
+  /// \param theMode a mode to set (see \ref XGUI_Displayer)
   void setDisplayMode(const QObjectPtrList& theList, int theMode);
 
+  /// Returns current module
   ModuleBase_IModule* module() const
   {
     return myModule;
@@ -179,7 +208,7 @@ Q_OBJECT
   */
   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
 
-  /*
+  /**
    * If there is an active (uncommited) operation shows a prompt to abort it
    * and performs abortion if user agreed. Returns true if
    * - operation aborted successfully
@@ -187,87 +216,189 @@ Q_OBJECT
    */
   bool isActiveOperationAborted();
 
+  //! Delete features. Delete the referenced features. There can be a question with a list of referenced
+  //! objects.
+  //! \param theList an objects to be deleted
+  //! \param theIgnoredFeatures a list of features to be ignored during delete
+  //! \param theParent a parent widget for the question message box
+  //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
+  //! objects features appear. If the user chose do not continue, the deletion is not performed
+  //! \return the success of the delete 
+  bool deleteFeatures(const QObjectPtrList& theList,
+                      const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
+                      QWidget* theParent = 0,
+                      const bool theAskAboutDeleteReferences = false);
+
+  /// Deactivates the object, if it is active and the module returns that the activation
+  /// of selection for the object is not possible currently(the current operation uses it)
+  /// \param theObject an object
+  /// \param theUpdateViewer a boolean flag to update viewer immediately
+  void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
+
 signals:
+  /// Emitted when selection happens in Salome viewer
   void salomeViewerSelection();
+
+  /// Emitted when error in applivation happens
   void errorOccurred(const QString&);
 
+  //! the signal about the workshop actions states are updated.
+  void commandStatusUpdated();
+
+  //! the application is started
+  void applicationStarted();
+
+  //! Signal to update Undo history list
+  void updateUndoHistory(const QList<ActionInfo>&);
+
+  //! Signal to update Redo history list
+  void updateRedoHistory(const QList<ActionInfo>&);
+
  public slots:
+   /// Update of commands status
   void updateCommandStatus();
-  void updateCommandsOnViewSelection();
 
+  // Update enable state of accept all button. It is enabled if the the parent operation is
+  // valid and there are modifications in sesstion(undo can be performed).
+  void updateCompositeActionState();
+
+  /// update history list (undo/redo commands)
+  void updateHistory();
+
+  /// Create a new dokument
   void onNew();
+
+  /// Open document from file
   void onOpen();
+
+  /// Save current document
   bool onSave();
+
+  /// Save current document to a file selected by user
   bool onSaveAs();
+
+  /// Exit application
   void onExit();
-  void onUndo();
-  void onRedo();
+
+  /// Undo last command
+  void onUndo(int times = 1);
+
+  /// Redo previous command
+  void onRedo(int times = 1);
+
+  /// Rebuild data tree
   void onRebuild();
+
+  /// Open preferences dialog box
   void onPreferences();
 
+  /// Show property panel
   void showPropertyPanel();
+
+  /// Hide property panel
   void hidePropertyPanel();
-  void showObjectBrowser();
-  void hideObjectBrowser();
 
-  void onFeatureTriggered();
-  void changeCurrentDocument(ObjectPtr theObj);
+  /// Show object Browser
+  void showObjectBrowser();
 
-  void activateLastPart();
+  /// Hide object Browser
+  void hideObjectBrowser();
 
+  /// Close document
   void closeDocument();
 
  protected:
-  bool event(QEvent * theEvent);
-  //Event-loop processing methods:
-  void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
-  void connectWithOperation(ModuleBase_Operation* theOperation);
-
-  void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
-  void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
-  void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
-  void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
+  /// Find the nested features and set them into the operation
+  /// \param theOperation an operation
+  void setNestedFeatures(ModuleBase_Operation* theOperation);
 
-  void validateOperation(const QString& theOperationId);
+  /// Update the property panel content by the XML description of the operation and set the panel
+  /// into the operation
+  /// \param theOperation an operation
+  void setPropertyPanel(ModuleBase_Operation* theOperation);
 
-  QList<QAction*> getModuleCommands() const;
+private:
+  /// Display all results
+  //void displayAllResults();
 
-  void displayAllResults();
+  /// Displau results from document
+  /// \param theDoc a document
   void displayDocumentResults(DocumentPtr theDoc);
+
+  /// Display results from a group
   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
 
  private slots:
   /// SLOT, that is called after the operation is started. Update workshop state according to
   /// the started operation, e.g. visualizes the property panel and connect to it.
-  void onOperationStarted();
+  /// \param theOpertion a started operation
+  void onOperationStarted(ModuleBase_Operation* theOperation);
+
+  /// SLOT, that is called after the operation is resumed. Update workshop state according to
+  /// the started operation, e.g. visualizes the property panel and connect to it.
+  /// \param theOpertion a resumed operation
+  virtual void onOperationResumed(ModuleBase_Operation* theOperation);
 
   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
   /// hides the property panel and udpate the command status.
   /// \param theOpertion a stopped operation
-  void onOperationStopped(ModuleBase_Operation* theOperation);
+  virtual void onOperationStopped(ModuleBase_Operation* theOperation);
 
-  void onContextMenuCommand(const QString& theId, bool isChecked);
+  /// SLOT, that is called after the operation is committed.
+  /// \param theOpertion a commmitted operation
+  virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
 
-  void onWidgetValuesChanged();
+  /// SLOT, that is called after the operation is aborted.
+  /// \param theOpertion an aborted operation
+  void onOperationAborted(ModuleBase_Operation* theOperation);
 
+  /// Slot, which reacts to the context popup menu call
+  /// \param theId the data value of the clicked action
+  /// \param isChecked a state of toggle if the action is checkable
+  void onContextMenuCommand(const QString& theId, bool isChecked);
+
+  /// Set waiting cursor
   void onStartWaiting();
 
  private:
+   /// Init menu
   void initMenu();
 
+  /// Register validators
   void registerValidators() const;
 
+  /// Load module from external library
+  /// \param theModule name of the module
   ModuleBase_IModule* loadModule(const QString& theModule);
-  bool activateModule();
 
+  /// Create module
+  bool createModule();
+
+  /// Create object browser widget
+  /// \param theParent a parent of widget
   QDockWidget* createObjectBrowser(QWidget* theParent);
+
+  /// Create property panel widget
+  /// \param theParent a parent of widget
   QDockWidget* createPropertyPanel(QWidget* theParent);
 
   // Creates Dock widgets: Object browser and Property panel
   void createDockWidgets();
 
-  XGUI_MainWindow* myMainWindow;
+  //! Extends undo/redo toolbutton's with history menu
+  //! \param theObject - in the OpenParts it is a QToolButton by itself,
+  //! in salome mode - QAction that creates a button.
+  //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
+  //! \param theSlot - onUndo(int) or onRedo(int) SLOT
+  void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
+
+  //! Creates list of actions (commands) by given history list from session
+  QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
+
+private:
+  AppElements_MainWindow* myMainWindow;
   ModuleBase_IModule* myModule;
+  XGUI_ErrorMgr* myErrorMgr;
   XGUI_ObjectsBrowser* myObjectBrowser;
   XGUI_PropertyPanel* myPropertyPanel;
   XGUI_SelectionMgr* mySelector;
@@ -279,14 +410,9 @@ signals:
   XGUI_ViewerProxy* myViewerProxy;
   XGUI_ContextMenuMgr* myContextMenuMgr;
   XGUI_ModuleConnector* myModuleConnector;
+  XGUI_WorkshopListener* myEventsListener;
 
   QString myCurrentDir;
-  static QMap<QString, QString> myIcons;
-
-  bool myUpdatePrefs;
-
-  // Flag to check that part document is in process of activating
-  bool myPartActivating;
 };
 
 #endif