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