Salome HOME
Remove obsolete flag
[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 Object browser
131   XGUI_ObjectsBrowser* objectBrowser() const
132   {
133     return myObjectBrowser;
134   }
135
136   /// This method is called by Salome module when selection is changed
137   void salomeViewerSelectionChanged();
138
139   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
140   XGUI_ViewerProxy* viewer() const
141   {
142     return myViewerProxy;
143   }
144
145   /// Returns the module connectory
146   /// \returns the instance of connector
147   XGUI_ModuleConnector* moduleConnector() const
148   {
149     return myModuleConnector;
150   }
151
152   /// Returns a desktop
153   /// \return a desktop instance
154   QMainWindow* desktop() const;
155
156   //! Delete features
157   void deleteObjects();
158
159   //! Returns true if the selected feature can be moved to the position after the current feature
160   //! \return boolean value
161   bool canMoveFeature();
162
163   //! Move selected features to be after the current feature
164   void moveObjects();
165
166   //! Returns true if there is at least one selected body/construction/group result
167   //! \return boolean value
168   bool canChangeColor() const;
169
170   //! Change color of the features if it is possible
171   //! The operation is available for construction, body and group results
172   //! theObjects a list of selected objects
173   void changeColor(const QObjectPtrList& theObjects);
174
175   //! Show the given features in 3d Viewer
176   void showObjects(const QObjectPtrList& theList, bool isVisible);
177
178   //! Show the given features in 3d Viewer
179   void showOnlyObjects(const QObjectPtrList& theList);
180
181   /// Set display mode for the given onjects
182   /// \param theList a list of displayed objects
183   /// \param theMode a mode to set (see \ref XGUI_Displayer)
184   void setDisplayMode(const QObjectPtrList& theList, int theMode);
185
186   /// Returns current module
187   ModuleBase_IModule* module() const
188   {
189     return myModule;
190   }
191
192   /// Returns current directory whic contains data files
193   QString currentDataDir() const { return myCurrentDir; }
194
195   /// Returns current directory whic contains data files
196   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
197
198   /**
199   * Save the current document into a directory
200   * \param theName - path to the directory
201   * \param theFileNames - returned file names created in this directory
202   */
203   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
204
205   /**
206    * If there is an active (uncommited) operation shows a prompt to abort it
207    * and performs abortion if user agreed. Returns true if
208    * - operation aborted successfully
209    * - there is no active operation
210    */
211   bool isActiveOperationAborted();
212
213   //! Delete features. Delete the referenced features. There can be a question with a list of referenced
214   //! objects.
215   //! \param theList an objects to be deleted
216   //! \param theIgnoredFeatures a list of features to be ignored during delete
217   //! \param theParent a parent widget for the question message box
218   //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
219   //! objects features appear. If the user chose do not continue, the deletion is not performed
220   //! \return the success of the delete 
221   bool deleteFeatures(const QObjectPtrList& theList,
222                       const std::set<FeaturePtr>& theIgnoredFeatures,
223                       QWidget* theParent = 0,
224                       const bool theAskAboutDeleteReferences = false);
225
226   /// Deactivates the object, if it is active and the module returns that the activation
227   /// of selection for the object is not possible currently(the current operation uses it)
228   /// \param theObject an object
229   /// \param theUpdateViewer a boolean flag to update viewer immediately
230   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
231
232 signals:
233   /// Emitted when selection happens in Salome viewer
234   void salomeViewerSelection();
235
236   /// Emitted when error in applivation happens
237   void errorOccurred(const QString&);
238
239   //! the signal about the workshop actions states are updated.
240   void commandStatusUpdated();
241
242   //! the application is started
243   void applicationStarted();
244
245   //! Signal to update Undo history list
246   void updateUndoHistory(const QList<ActionInfo>&);
247
248   //! Signal to update Redo history list
249   void updateRedoHistory(const QList<ActionInfo>&);
250
251  public slots:
252    /// Update of commands status
253   void updateCommandStatus();
254
255   /// update history list (undo/redo commands)
256   void updateHistory();
257
258   /// Create a new dokument
259   void onNew();
260
261   /// Open document from file
262   void onOpen();
263
264   /// Save current document
265   bool onSave();
266
267   /// Save current document to a file selected by user
268   bool onSaveAs();
269
270   /// Exit application
271   void onExit();
272
273   /// Undo last command
274   void onUndo(int times = 1);
275
276   /// Redo previous command
277   void onRedo(int times = 1);
278
279   /// Rebuild data tree
280   void onRebuild();
281
282   /// Open preferences dialog box
283   void onPreferences();
284
285   /// Show property panel
286   void showPropertyPanel();
287
288   /// Hide property panel
289   void hidePropertyPanel();
290
291   /// Show object Browser
292   void showObjectBrowser();
293
294   /// Hide object Browser
295   void hideObjectBrowser();
296
297   /// Reaction on command call
298   //void onFeatureTriggered();
299
300   /// Close document
301   void closeDocument();
302
303  protected:
304   /// Find the nested features and set them into the operation
305   /// \param theOperation an operation
306   void setNestedFeatures(ModuleBase_Operation* theOperation);
307
308   /// Update the property panel content by the XML description of the operation and set the panel
309   /// into the operation
310   /// \param theOperation an operation
311   void setPropertyPanel(ModuleBase_Operation* theOperation);
312
313   /// Connect to operation signals
314   /// \param theOperation an operation
315   void connectWithOperation(ModuleBase_Operation* theOperation);
316
317 private:
318   /// Display all results
319   //void displayAllResults();
320
321   /// Displau results from document
322   /// \param theDoc a document
323   void displayDocumentResults(DocumentPtr theDoc);
324
325   /// Display results from a group
326   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
327
328  private slots:
329   /// SLOT, that is called after the operation is started. Update workshop state according to
330   /// the started operation, e.g. visualizes the property panel and connect to it.
331   /// \param theOpertion a started operation
332   void onOperationStarted(ModuleBase_Operation* theOperation);
333
334   /// SLOT, that is called after the operation is resumed. Update workshop state according to
335   /// the started operation, e.g. visualizes the property panel and connect to it.
336   /// \param theOpertion a resumed operation
337   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
338
339   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
340   /// hides the property panel and udpate the command status.
341   /// \param theOpertion a stopped operation
342   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
343
344   /// SLOT, that is called after the operation is committed.
345   /// \param theOpertion a commmitted operation
346   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
347
348   /// SLOT, that is called after the operation is aborted.
349   /// \param theOpertion an aborted operation
350   void onOperationAborted(ModuleBase_Operation* theOperation);
351
352   /// Slot, which reacts to the context popup menu call
353   /// \param theId the data value of the clicked action
354   /// \param isChecked a state of toggle if the action is checkable
355   void onContextMenuCommand(const QString& theId, bool isChecked);
356
357   /// Set waiting cursor
358   void onStartWaiting();
359
360  private:
361    /// Init menu
362   void initMenu();
363
364   /// Register validators
365   void registerValidators() const;
366
367   /// Load module from external library
368   /// \param theModule name of the module
369   ModuleBase_IModule* loadModule(const QString& theModule);
370
371   /// Create module
372   bool createModule();
373
374   /// Create object browser widget
375   /// \param theParent a parent of widget
376   QDockWidget* createObjectBrowser(QWidget* theParent);
377
378   /// Create property panel widget
379   /// \param theParent a parent of widget
380   QDockWidget* createPropertyPanel(QWidget* theParent);
381
382   // Creates Dock widgets: Object browser and Property panel
383   void createDockWidgets();
384
385   //! Extends undo/redo toolbutton's with history menu
386   //! \param theObject - in the OpenParts it is a QToolButton by itself,
387   //! in salome mode - QAction that creates a button.
388   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
389   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
390   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
391
392   //! Creates list of actions (commands) by given history list from session
393   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
394
395 private:
396   AppElements_MainWindow* myMainWindow;
397   ModuleBase_IModule* myModule;
398   XGUI_ObjectsBrowser* myObjectBrowser;
399   XGUI_PropertyPanel* myPropertyPanel;
400   XGUI_SelectionMgr* mySelector;
401   XGUI_Displayer* myDisplayer;
402   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
403   XGUI_ActionsMgr* myActionsMgr;
404   XGUI_SalomeConnector* mySalomeConnector;
405   XGUI_ErrorDialog* myErrorDlg;
406   XGUI_ViewerProxy* myViewerProxy;
407   XGUI_ContextMenuMgr* myContextMenuMgr;
408   XGUI_ModuleConnector* myModuleConnector;
409   XGUI_WorkshopListener* myEventsListener;
410
411   QString myCurrentDir;
412 };
413
414 #endif