]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Apply button to be disabled during value modification for any operation, not only...
[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   /// Validates the operation. Apply button is disabled if the widget value is in Modified state
303   void onValueStateChanged();
304
305   /// Show property panel
306   void showPropertyPanel();
307
308   /// Hide property panel
309   void hidePropertyPanel();
310
311   /// Show object Browser
312   void showObjectBrowser();
313
314   /// Hide object Browser
315   void hideObjectBrowser();
316
317   /// Close document
318   void closeDocument();
319
320   /// Open document from file
321   void onOpen();
322
323   /// Create a new document
324   void onNew();
325
326 #ifndef HAVE_SALOME
327   /// Exit application
328   void onExit();
329
330   /// Open preferences dialog box
331   void onPreferences();
332 #endif
333
334  protected:
335   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
336   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
337   /// \param theOperation an operation
338    void setGrantedFeatures(ModuleBase_Operation* theOperation);
339
340   /// Update the property panel content by the XML description of the operation and set the panel
341   /// into the operation
342   /// \param theOperation an operation
343   void setPropertyPanel(ModuleBase_Operation* theOperation);
344
345   /// Connects or disconnects to the value changed signal of the property panel widgets
346   /// \param isToConnect a boolean value whether connect or disconnect
347   void connectToPropertyPanel(const bool isToConnect);
348
349 private:
350   /// Display all results
351   //void displayAllResults();
352
353   /// Display results from document
354   /// \param theDoc a document
355   void displayDocumentResults(DocumentPtr theDoc);
356
357   /// Display results from a group
358   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
359
360  private slots:
361   /// SLOT, that is called after the operation is started. Update workshop state according to
362   /// the started operation, e.g. visualizes the property panel and connect to it.
363   /// \param theOpertion a started operation
364   void onOperationStarted(ModuleBase_Operation* theOperation);
365
366   /// SLOT, that is called after the operation is resumed. Update workshop state according to
367   /// the started operation, e.g. visualizes the property panel and connect to it.
368   /// \param theOpertion a resumed operation
369   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
370
371   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
372   /// hides the property panel and update the command status.
373   /// \param theOpertion a stopped operation
374   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
375
376   /// SLOT, that is called after the operation is committed.
377   /// \param theOpertion a committed operation
378   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
379
380   /// SLOT, that is called after the operation is aborted.
381   /// \param theOpertion an aborted operation
382   void onOperationAborted(ModuleBase_Operation* theOperation);
383
384   /// Slot, which reacts to the context popup menu call
385   /// \param theId the data value of the clicked action
386   /// \param isChecked a state of toggle if the action is checkable
387   void onContextMenuCommand(const QString& theId, bool isChecked);
388
389   /// Set waiting cursor
390   void onStartWaiting();
391
392   /// Called by Ok button clicked in the property panel. Asks the error manager whether
393   /// the operation can be committed and do it if it returns true.
394   void onAcceptActionClicked();
395
396   /// Listens the corresponded signal from operation manager and send it with the Ok
397   /// action to operation manager.
398   /// \param theEnabled an enabled state for the action
399   //void onValidationStateChanged(bool theEnabled);
400
401   //connect(myOperationMgr,  SIGNAL(validationStateChanged(bool)),
402   //        aOkAct,          SLOT(setEnabled(bool)));
403
404
405  private:
406    /// Init menu
407   void initMenu();
408
409   /// Register validators
410   void registerValidators() const;
411
412   /// Load module from external library
413   /// \param theModule name of the module
414   ModuleBase_IModule* loadModule(const QString& theModule);
415
416   /// Create module
417   bool createModule();
418
419   /// Create object browser widget
420   /// \param theParent a parent of widget
421   QDockWidget* createObjectBrowser(QWidget* theParent);
422
423   /// Create property panel widget
424   /// \param theParent a parent of widget
425   QDockWidget* createPropertyPanel(QWidget* theParent);
426
427   // Creates Dock widgets: Object browser and Property panel
428   void createDockWidgets();
429
430   //! Extends undo/redo toolbutton's with history menu
431   //! \param theObject - in the OpenParts it is a QToolButton by itself,
432   //! in salome mode - QAction that creates a button.
433   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
434   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
435   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
436
437   //! Creates list of actions (commands) by given history list from session
438   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
439
440 private:
441 #ifndef HAVE_SALOME
442   AppElements_MainWindow* myMainWindow;
443 #endif
444
445   ModuleBase_IModule* myModule;
446   XGUI_ErrorMgr* myErrorMgr;
447   XGUI_ObjectsBrowser* myObjectBrowser;
448   XGUI_PropertyPanel* myPropertyPanel;
449   XGUI_SelectionMgr* mySelector;
450   XGUI_Displayer* myDisplayer;
451   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
452   XGUI_ActionsMgr* myActionsMgr;
453   XGUI_SalomeConnector* mySalomeConnector;
454   XGUI_ErrorDialog* myErrorDlg;
455   XGUI_ViewerProxy* myViewerProxy;
456   XGUI_ContextMenuMgr* myContextMenuMgr;
457   XGUI_ModuleConnector* myModuleConnector;
458   XGUI_WorkshopListener* myEventsListener;
459
460   QString myCurrentDir;
461 };
462
463 #endif