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