Salome HOME
1. ExtrusionCut: Apply Sketch button(in tool bar) should be applyed only to the sketc...
[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   // Update enable state of accept all button. It is enabled if the the parent operation is
283   // valid and there are modifications in sesstion(undo can be performed).
284   void updateCompositeActionState();
285
286   /// Open preferences dialog box
287   void onPreferences();
288
289   /// Show property panel
290   void showPropertyPanel();
291
292   /// Hide property panel
293   void hidePropertyPanel();
294
295   /// Show object Browser
296   void showObjectBrowser();
297
298   /// Hide object Browser
299   void hideObjectBrowser();
300
301   /// Reaction on command call
302   //void onFeatureTriggered();
303
304   /// Close document
305   void closeDocument();
306
307  protected:
308   /// Find the nested features and set them into the operation
309   /// \param theOperation an operation
310   void setNestedFeatures(ModuleBase_Operation* theOperation);
311
312   /// Update the property panel content by the XML description of the operation and set the panel
313   /// into the operation
314   /// \param theOperation an operation
315   void setPropertyPanel(ModuleBase_Operation* theOperation);
316
317   /// Connect to operation signals
318   /// \param theOperation an operation
319   void connectWithOperation(ModuleBase_Operation* theOperation);
320
321 private:
322   /// Display all results
323   //void displayAllResults();
324
325   /// Displau results from document
326   /// \param theDoc a document
327   void displayDocumentResults(DocumentPtr theDoc);
328
329   /// Display results from a group
330   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
331
332  private slots:
333   /// SLOT, that is called after the operation is started. Update workshop state according to
334   /// the started operation, e.g. visualizes the property panel and connect to it.
335   /// \param theOpertion a started operation
336   void onOperationStarted(ModuleBase_Operation* theOperation);
337
338   /// SLOT, that is called after the operation is resumed. Update workshop state according to
339   /// the started operation, e.g. visualizes the property panel and connect to it.
340   /// \param theOpertion a resumed operation
341   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
342
343   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
344   /// hides the property panel and udpate the command status.
345   /// \param theOpertion a stopped operation
346   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
347
348   /// SLOT, that is called after the operation is committed.
349   /// \param theOpertion a commmitted operation
350   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
351
352   /// SLOT, that is called after the operation is aborted.
353   /// \param theOpertion an aborted operation
354   void onOperationAborted(ModuleBase_Operation* theOperation);
355
356   /// Slot, which reacts to the context popup menu call
357   /// \param theId the data value of the clicked action
358   /// \param isChecked a state of toggle if the action is checkable
359   void onContextMenuCommand(const QString& theId, bool isChecked);
360
361   /// Set waiting cursor
362   void onStartWaiting();
363
364  private:
365    /// Init menu
366   void initMenu();
367
368   /// Register validators
369   void registerValidators() const;
370
371   /// Load module from external library
372   /// \param theModule name of the module
373   ModuleBase_IModule* loadModule(const QString& theModule);
374
375   /// Create module
376   bool createModule();
377
378   /// Create object browser widget
379   /// \param theParent a parent of widget
380   QDockWidget* createObjectBrowser(QWidget* theParent);
381
382   /// Create property panel widget
383   /// \param theParent a parent of widget
384   QDockWidget* createPropertyPanel(QWidget* theParent);
385
386   // Creates Dock widgets: Object browser and Property panel
387   void createDockWidgets();
388
389   //! Extends undo/redo toolbutton's with history menu
390   //! \param theObject - in the OpenParts it is a QToolButton by itself,
391   //! in salome mode - QAction that creates a button.
392   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
393   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
394   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
395
396   //! Creates list of actions (commands) by given history list from session
397   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
398
399 private:
400   AppElements_MainWindow* myMainWindow;
401   ModuleBase_IModule* myModule;
402   XGUI_ObjectsBrowser* myObjectBrowser;
403   XGUI_PropertyPanel* myPropertyPanel;
404   XGUI_SelectionMgr* mySelector;
405   XGUI_Displayer* myDisplayer;
406   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
407   XGUI_ActionsMgr* myActionsMgr;
408   XGUI_SalomeConnector* mySalomeConnector;
409   XGUI_ErrorDialog* myErrorDlg;
410   XGUI_ViewerProxy* myViewerProxy;
411   XGUI_ContextMenuMgr* myContextMenuMgr;
412   XGUI_ModuleConnector* myModuleConnector;
413   XGUI_WorkshopListener* myEventsListener;
414
415   QString myCurrentDir;
416 };
417
418 #endif