Salome HOME
Delete key regression corrections: in previous implementation sketch entities did...
[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   //! Searches for selected features unused in other (not selected) features. If one or several
172   //! selected features are found, a warning message proposes to delete them. It contains 
173   //! the list of features to be deleted.
174   void cleanHistory();
175
176   //! Returns true if the selected feature can be moved to the position after the current feature
177   //! \return boolean value
178   bool canMoveFeature();
179
180   //! Move selected features to be after the current feature
181   void moveObjects();
182
183   //! Returns true if the object can be shaded. If the object is a compsolid result, the method
184   //! checks subobjects of the result
185   //! \return boolean value
186   bool canBeShaded(const ObjectPtr& theObject) const;
187
188   //! Returns true if there is at least one selected body/construction/group result
189   //! \return boolean value
190   bool canChangeColor() const;
191
192   //! Change color of the features if it is possible
193   //! The operation is available for construction, body and group results
194   //! theObjects a list of selected objects
195   void changeColor(const QObjectPtrList& theObjects);
196
197   //! Show the given features in 3d Viewer
198   void showObjects(const QObjectPtrList& theList, bool isVisible);
199
200   //! Show the given features in 3d Viewer
201   void showOnlyObjects(const QObjectPtrList& theList);
202
203   /// Set display mode for the given objects
204   /// \param theList a list of displayed objects
205   /// \param theMode a mode to set (see \ref XGUI_Displayer)
206   void setDisplayMode(const QObjectPtrList& theList, int theMode);
207
208   /// Returns current module
209   ModuleBase_IModule* module() const
210   {
211     return myModule;
212   }
213
214   /// Returns current directory which contains data files
215   QString currentDataDir() const { return myCurrentDir; }
216
217   /// Returns current directory which contains data files
218   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
219
220   /**
221   * Save the current document into a directory
222   * \param theName - path to the directory
223   * \param theFileNames - returned file names created in this directory
224   */
225   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
226
227   /**
228    * If there is an active (uncommitted) operation shows a prompt to abort it
229    * and performs abortion if user agreed. Returns true if
230    * - operation aborted successfully
231    * - there is no active operation
232    */
233   bool abortAllOperations();
234
235   //! Delete features. Delete the referenced features. There can be a question with a list of referenced
236   //! objects.
237   //! \param theList an objects to be deleted
238   //! \param theIgnoredFeatures a list of features to be ignored during delete
239   //! \param theParent a parent widget for the question message box
240   //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
241   //! objects features appear. If the user chose do not continue, the deletion is not performed
242   //! \return the success of the delete 
243   bool deleteFeatures(const QObjectPtrList& theList,
244                       const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
245                       QWidget* theParent = 0,
246                       const bool theAskAboutDeleteReferences = false);
247
248   /// Deactivates the object, if it is active and the module returns that the activation
249   /// of selection for the object is not possible currently(the current operation uses it)
250   /// \param theObject an object
251   /// \param theUpdateViewer a boolean flag to update viewer immediately
252   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
253
254   /// Returns true if the action of the feature is created to contain Accept/Cancel button
255   /// \param theFeature a feature
256   bool isFeatureOfNested(const FeaturePtr& theFeature);
257
258   /// Has to be called in order to display objects with visibility status = true
259   void synchronizeViewer();
260
261   /// Has to be called in order to display objects from a cpecifed group with visibility status = true
262   /// \param theDoc the document for objects synchronisation
263   /// \param theGroup the group name
264   /// \param theUpdateViewer update viewer flag
265   void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
266
267   /// A constant string used for "Move to end" command definition
268   /// It is used for specific processing of Undo/Redo for this command.
269   static QString MOVE_TO_END_COMMAND;
270
271 signals:
272   /// Emitted when selection happens in Salome viewer
273   void salomeViewerSelection();
274
275   /// Emitted when error in application happens
276   void errorOccurred(const QString&);
277
278   //! the signal about the workshop actions states are updated.
279   void commandStatusUpdated();
280
281   //! the application is started
282   void applicationStarted();
283
284   //! Signal to update Undo history list
285   void updateUndoHistory(const QList<ActionInfo>&);
286
287   //! Signal to update Redo history list
288   void updateRedoHistory(const QList<ActionInfo>&);
289
290  public slots:
291    /// Update of commands status
292   void updateCommandStatus();
293
294   /// update history list (undo/redo commands)
295   void updateHistory();
296
297   /// Save current document
298   bool onSave();
299
300   /// Save current document to a file selected by user
301   bool onSaveAs();
302
303   /// Undo last command
304   void onUndo(int times = 1);
305
306   /// Redo previous command
307   void onRedo(int times = 1);
308
309   // Rebuild data tree
310   //void onRebuild();
311
312   /// Validates the operation to change the "Apply" button state.
313   /// \param thePreviousState the previous state of the widget
314   void onWidgetStateChanged(int thePreviousState);
315
316   /// Show property panel
317   void showPropertyPanel();
318
319   /// Hide property panel
320   void hidePropertyPanel();
321
322   /// Show object Browser
323   void showObjectBrowser();
324
325   /// Hide object Browser
326   void hideObjectBrowser();
327
328   /// Close document
329   void closeDocument();
330
331   /// Open document from file
332   void onOpen();
333
334   /// Create a new document
335   void onNew();
336
337 #ifndef HAVE_SALOME
338   /// Exit application
339   void onExit();
340
341   /// Open preferences dialog box
342   void onPreferences();
343 #endif
344
345   /// Activates/deactivates the trihedron in the viewer AIS context
346   void onTrihedronVisibilityChanged(bool theState);
347
348  protected:
349   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
350   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
351   /// \param theOperation an operation
352    void setGrantedFeatures(ModuleBase_Operation* theOperation);
353
354   /// Update the property panel content by the XML description of the operation and set the panel
355   /// into the operation
356   /// \param theOperation an operation
357   void setPropertyPanel(ModuleBase_Operation* theOperation);
358
359   /// Connects or disconnects to the value changed signal of the property panel widgets
360   /// \param isToConnect a boolean value whether connect or disconnect
361   void connectToPropertyPanel(const bool isToConnect);
362
363 private:
364   /// Display all results
365   //void displayAllResults();
366
367   /// Display results from document
368   /// \param theDoc a document
369   void displayDocumentResults(DocumentPtr theDoc);
370
371   /// Display results from a group
372   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
373
374  private slots:
375   /// SLOT, that is called after the operation is started. Update workshop state according to
376   /// the started operation, e.g. visualizes the property panel and connect to it.
377   /// \param theOpertion a started operation
378   void onOperationStarted(ModuleBase_Operation* theOperation);
379
380   /// SLOT, that is called after the operation is resumed. Update workshop state according to
381   /// the started operation, e.g. visualizes the property panel and connect to it.
382   /// \param theOpertion a resumed operation
383   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
384
385   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
386   /// hides the property panel and update the command status.
387   /// \param theOpertion a stopped operation
388   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
389
390   /// SLOT, that is called after the operation is committed.
391   /// \param theOpertion a committed operation
392   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
393
394   /// SLOT, that is called after the operation is aborted.
395   /// \param theOpertion an aborted operation
396   void onOperationAborted(ModuleBase_Operation* theOperation);
397
398   /// Slot, which reacts to the context popup menu call
399   /// \param theId the data value of the clicked action
400   /// \param isChecked a state of toggle if the action is checkable
401   void onContextMenuCommand(const QString& theId, bool isChecked);
402
403   /// Set waiting cursor
404   void onStartWaiting();
405
406   /// Called by Ok button clicked in the property panel. Asks the error manager whether
407   /// the operation can be committed and do it if it returns true.
408   void onAcceptActionClicked();
409
410  private:
411    /// Init menu
412   void initMenu();
413
414   /// Register validators
415   void registerValidators() const;
416
417   /// Load module from external library
418   /// \param theModule name of the module
419   ModuleBase_IModule* loadModule(const QString& theModule);
420
421   /// Create module
422   bool createModule();
423
424   /// Create object browser widget
425   /// \param theParent a parent of widget
426   QDockWidget* createObjectBrowser(QWidget* theParent);
427
428   /// Create property panel widget
429   /// \param theParent a parent of widget
430   QDockWidget* createPropertyPanel(QWidget* theParent);
431
432   // Creates Dock widgets: Object browser and Property panel
433   void createDockWidgets();
434
435   //! Extends undo/redo toolbutton's with history menu
436   //! \param theObject - in the OpenParts it is a QToolButton by itself,
437   //! in salome mode - QAction that creates a button.
438   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
439   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
440   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
441
442
443   /// Calls removeFeature of the document for each object in the list
444   //! \param theList an objects to be deleted
445   //! \param theIgnoredFeatures a list of features to be ignored during delete
446   //! \param theActionId an action command key to find context menu object types enabled for remove
447   bool removeFeatures(const QObjectPtrList& theList,
448                       const std::set<FeaturePtr>& theIgnoredFeatures,
449                       const QString& theActionId);
450
451   //! Creates list of actions (commands) by given history list from session
452   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
453
454 private:
455 #ifndef HAVE_SALOME
456   AppElements_MainWindow* myMainWindow;
457 #endif
458
459   ModuleBase_IModule* myModule;
460   XGUI_ErrorMgr* myErrorMgr;
461   XGUI_ObjectsBrowser* myObjectBrowser;
462   XGUI_PropertyPanel* myPropertyPanel;
463   XGUI_SelectionMgr* mySelector;
464   XGUI_Displayer* myDisplayer;
465   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
466   XGUI_ActionsMgr* myActionsMgr;
467   XGUI_SalomeConnector* mySalomeConnector;
468   XGUI_ErrorDialog* myErrorDlg;
469   XGUI_ViewerProxy* myViewerProxy;
470   XGUI_ContextMenuMgr* myContextMenuMgr;
471   XGUI_ModuleConnector* myModuleConnector;
472   XGUI_WorkshopListener* myEventsListener;
473
474   QString myCurrentDir;
475 };
476
477 #endif