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