Salome HOME
Issue #660 Move Group is still not implemented
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_WORKSHOP_H
4 #define XGUI_WORKSHOP_H
5
6 #include "XGUI.h"
7 //#include "XGUI_Constants.h"
8 #include <ModuleBase_Definitions.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Feature.h>
11
12 #include <ModuleBase_ActionInfo.h>
13
14 #include <QObject>
15 #include <QMap>
16 #include <QKeySequence>
17 #include <QIcon>
18
19 class AppElements_MainWindow;
20 class AppElements_Command;
21 class AppElements_Workbench;
22
23 class XGUI_SelectionMgr;
24 class XGUI_Displayer;
25 class XGUI_OperationMgr;
26 class XGUI_SalomeConnector;
27 class XGUI_ObjectsBrowser;
28 class XGUI_ActionsMgr;
29 class XGUI_ErrorDialog;
30 class XGUI_SalomeViewer;
31 class XGUI_ViewerProxy;
32 class XGUI_PropertyPanel;
33 class XGUI_ContextMenuMgr;
34 class XGUI_ModuleConnector;
35 class XGUI_WorkshopListener;
36
37 class ModuleBase_Operation;
38 class ModuleBase_IModule;
39 class ModuleBase_IViewer;
40
41 class QWidget;
42 class QDockWidget;
43 class QMainWindow;
44
45 class QAction;
46
47 /**\class XGUI_Workshop
48  * \ingroup GUI
49  * \brief Class which defines a configuration of the application (Workshop) and launches it.
50  */
51 class XGUI_EXPORT XGUI_Workshop : public QObject
52 {
53 Q_OBJECT
54  public:
55   /// Constructor
56   /// \param theConnector a Salome connector object. 
57   /// Used only if the workshop is launched in Salome environment
58   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
59   virtual ~XGUI_Workshop();
60
61   //! Starting of the application
62   void startApplication();
63
64   // Activates the module controls. Should be called after module creation
65   void activateModule();
66
67   // Deactivates the module controls. Should be called after module creation
68   void deactivateModule();
69
70   //! Returns main window (Desktop) of the application
71   AppElements_MainWindow* mainWindow() const
72   {
73     return myMainWindow;
74   }
75
76   //! Returns selection manager object
77   XGUI_SelectionMgr* selector() const
78   {
79     return mySelector;
80   }
81
82   //! Returns displayer
83   XGUI_Displayer* displayer() const
84   {
85     return myDisplayer;
86   }
87
88   //! ! Returns operation manager.
89   XGUI_OperationMgr* operationMgr() const
90   {
91     return myOperationMgr;
92   }
93
94   //! ! Returns an actions manager
95   XGUI_ActionsMgr* actionsMgr() const
96   {
97     return myActionsMgr;
98   }
99
100   //! Returns property panel widget
101   XGUI_PropertyPanel* propertyPanel() const
102   {
103     return myPropertyPanel;
104   }
105
106   //! Returns context menu manager object
107   XGUI_ContextMenuMgr* contextMenuMgr() const
108   {
109     return myContextMenuMgr;
110   }
111
112   //! Creates and adds a new workbench (menu group) with the given name and returns it
113   AppElements_Workbench* addWorkbench(const QString& theName);
114
115   //! Returns an object which provides interface to Salome Module (LightApp_Module)
116   XGUI_SalomeConnector* salomeConnector() const
117   {
118     return mySalomeConnector;
119   }
120
121   //! Provides an object which provides interface to Salome Viewer
122   ModuleBase_IViewer* salomeViewer() const;
123
124   //! Returns true if the application works as SALOME module
125   bool isSalomeMode() const
126   {
127     return mySalomeConnector != 0;
128   }
129
130   /// Returns true if the loading data process is started and has not been finished yet
131   /// \return boolean result
132   bool isLoadingData() const
133   {
134     return myIsLoadingData;
135   };
136
137   //! Returns Object browser
138   XGUI_ObjectsBrowser* objectBrowser() const
139   {
140     return myObjectBrowser;
141   }
142
143   /// This method is called by Salome module when selection is changed
144   void salomeViewerSelectionChanged();
145
146   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
147   XGUI_ViewerProxy* viewer() const
148   {
149     return myViewerProxy;
150   }
151
152   /// Returns the module connectory
153   /// \returns the instance of connector
154   XGUI_ModuleConnector* moduleConnector() const
155   {
156     return myModuleConnector;
157   }
158
159   /// Returns a desktop
160   /// \return a desktop instance
161   QMainWindow* desktop() const;
162
163   //! Delete features
164   void deleteObjects();
165
166   //! Returns true if the selected feature can be moved to the position after the current feature
167   //! \return boolean value
168   bool canMoveFeature();
169
170   //! Move selected features to be after the current feature
171   void moveObjects();
172
173   //! Returns true if there is at least one selected body/construction/group result
174   //! \return boolean value
175   bool canChangeColor() const;
176
177   //! Change color of the features if it is possible
178   //! The operation is available for construction, body and group results
179   //! theObjects a list of selected objects
180   void changeColor(const QObjectPtrList& theObjects);
181
182   //! Show the given features in 3d Viewer
183   void showObjects(const QObjectPtrList& theList, bool isVisible);
184
185   //! Show the given features in 3d Viewer
186   void showOnlyObjects(const QObjectPtrList& theList);
187
188   /// Set display mode for the given onjects
189   /// \param theList a list of displayed objects
190   /// \param theMode a mode to set (see \ref XGUI_Displayer)
191   void setDisplayMode(const QObjectPtrList& theList, int theMode);
192
193   /// Returns current module
194   ModuleBase_IModule* module() const
195   {
196     return myModule;
197   }
198
199   /// Returns current directory whic contains data files
200   QString currentDataDir() const { return myCurrentDir; }
201
202   /// Returns current directory whic contains data files
203   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
204
205   /**
206   * Save the current document into a directory
207   * \param theName - path to the directory
208   * \param theFileNames - returned file names created in this directory
209   */
210   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
211
212   /**
213    * If there is an active (uncommited) operation shows a prompt to abort it
214    * and performs abortion if user agreed. Returns true if
215    * - operation aborted successfully
216    * - there is no active operation
217    */
218   bool isActiveOperationAborted();
219
220   //! Delete features. Delete the referenced features. There can be a question with a list of referenced
221   //! objects.
222   //! \param theList an objects to be deleted
223   //! \param theIgnoredFeatures a list of features to be ignored during delete
224   //! \param theParent a parent widget for the question message box
225   //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
226   //! objects features appear. If the user chose do not continue, the deletion is not performed
227   //! \return the success of the delete 
228   bool deleteFeatures(const QObjectPtrList& theList,
229                       const std::set<FeaturePtr>& theIgnoredFeatures,
230                       QWidget* theParent = 0,
231                       const bool theAskAboutDeleteReferences = false);
232
233   /// Deactivates the object, if it is active and the module returns that the activation
234   /// of selection for the object is not possible currently(the current operation uses it)
235   /// \param theObject an object
236   /// \param theUpdateViewer a boolean flag to update viewer immediately
237   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
238
239 signals:
240   /// Emitted when selection happens in Salome viewer
241   void salomeViewerSelection();
242
243   /// Emitted when error in applivation happens
244   void errorOccurred(const QString&);
245
246   //! the signal about the workshop actions states are updated.
247   void commandStatusUpdated();
248
249   //! the application is started
250   void applicationStarted();
251
252   //! Signal to update Undo history list
253   void updateUndoHistory(const QList<ActionInfo>&);
254
255   //! Signal to update Redo history list
256   void updateRedoHistory(const QList<ActionInfo>&);
257
258  public slots:
259    /// Update of commands status
260   void updateCommandStatus();
261
262   /// update history list (undo/redo commands)
263   void updateHistory();
264
265   /// Create a new dokument
266   void onNew();
267
268   /// Open document from file
269   void onOpen();
270
271   /// Save current document
272   bool onSave();
273
274   /// Save current document to a file selected by user
275   bool onSaveAs();
276
277   /// Exit application
278   void onExit();
279
280   /// Undo last command
281   void onUndo(int times = 1);
282
283   /// Redo previous command
284   void onRedo(int times = 1);
285
286   /// Rebuild data tree
287   void onRebuild();
288
289   /// Open preferences dialog box
290   void onPreferences();
291
292   /// Show property panel
293   void showPropertyPanel();
294
295   /// Hide property panel
296   void hidePropertyPanel();
297
298   /// Show object Browser
299   void showObjectBrowser();
300
301   /// Hide object Browser
302   void hideObjectBrowser();
303
304   /// Reaction on command call
305   //void onFeatureTriggered();
306
307   /// Close document
308   void closeDocument();
309
310  protected:
311   /// Find the nested features and set them into the operation
312   /// \param theOperation an operation
313   void setNestedFeatures(ModuleBase_Operation* theOperation);
314
315   /// Update the property panel content by the XML description of the operation and set the panel
316   /// into the operation
317   /// \param theOperation an operation
318   void setPropertyPanel(ModuleBase_Operation* theOperation);
319
320   /// Connect to operation signals
321   /// \param theOperation an operation
322   void connectWithOperation(ModuleBase_Operation* theOperation);
323
324 private:
325   /// Display all results
326   //void displayAllResults();
327
328   /// Displau results from document
329   /// \param theDoc a document
330   void displayDocumentResults(DocumentPtr theDoc);
331
332   /// Display results from a group
333   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
334
335  private slots:
336   /// SLOT, that is called after the operation is started. Update workshop state according to
337   /// the started operation, e.g. visualizes the property panel and connect to it.
338   /// \param theOpertion a started operation
339   void onOperationStarted(ModuleBase_Operation* theOperation);
340
341   /// SLOT, that is called after the operation is resumed. Update workshop state according to
342   /// the started operation, e.g. visualizes the property panel and connect to it.
343   /// \param theOpertion a resumed operation
344   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
345
346   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
347   /// hides the property panel and udpate the command status.
348   /// \param theOpertion a stopped operation
349   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
350
351   /// SLOT, that is called after the operation is committed.
352   /// \param theOpertion a commmitted operation
353   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
354
355   /// SLOT, that is called after the operation is aborted.
356   /// \param theOpertion an aborted operation
357   void onOperationAborted(ModuleBase_Operation* theOperation);
358
359   /// Slot, which reacts to the context popup menu call
360   /// \param theId the data value of the clicked action
361   /// \param isChecked a state of toggle if the action is checkable
362   void onContextMenuCommand(const QString& theId, bool isChecked);
363
364   /// Set waiting cursor
365   void onStartWaiting();
366
367  private:
368    /// Init menu
369   void initMenu();
370
371   /// Register validators
372   void registerValidators() const;
373
374   /// Load module from external library
375   /// \param theModule name of the module
376   ModuleBase_IModule* loadModule(const QString& theModule);
377
378   /// Create module
379   bool createModule();
380
381   /// Create object browser widget
382   /// \param theParent a parent of widget
383   QDockWidget* createObjectBrowser(QWidget* theParent);
384
385   /// Create property panel widget
386   /// \param theParent a parent of widget
387   QDockWidget* createPropertyPanel(QWidget* theParent);
388
389   // Creates Dock widgets: Object browser and Property panel
390   void createDockWidgets();
391
392   //! Extends undo/redo toolbutton's with history menu
393   //! \param theObject - in the OpenParts it is a QToolButton by itself,
394   //! in salome mode - QAction that creates a button.
395   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
396   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
397   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
398
399   //! Creates list of actions (commands) by given history list from session
400   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
401
402 private:
403   AppElements_MainWindow* myMainWindow;
404   ModuleBase_IModule* myModule;
405   XGUI_ObjectsBrowser* myObjectBrowser;
406   XGUI_PropertyPanel* myPropertyPanel;
407   XGUI_SelectionMgr* mySelector;
408   XGUI_Displayer* myDisplayer;
409   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
410   XGUI_ActionsMgr* myActionsMgr;
411   XGUI_SalomeConnector* mySalomeConnector;
412   XGUI_ErrorDialog* myErrorDlg;
413   XGUI_ViewerProxy* myViewerProxy;
414   XGUI_ContextMenuMgr* myContextMenuMgr;
415   XGUI_ModuleConnector* myModuleConnector;
416   XGUI_WorkshopListener* myEventsListener;
417
418   QString myCurrentDir;
419
420   /// The flag is true when we loading a document
421   bool myIsLoadingData;
422 };
423
424 #endif