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