]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Delete action modification: selection is lost even if we answer that we do not wish...
[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
236   //! referenced objects.
237   //! \param theList an objects to be deleted
238   //! \param theIgnoredFeatures a list of features to be ignored during delete
239   bool deleteFeatures(const QObjectPtrList& theFeatures,
240                       const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>());
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   /// A constant string used for "Move to end" command definition
262   /// It is used for specific processing of Undo/Redo for this command.
263   static QString MOVE_TO_END_COMMAND;
264
265 signals:
266   /// Emitted when selection happens in Salome viewer
267   void salomeViewerSelection();
268
269   /// Emitted when error in application happens
270   void errorOccurred(const QString&);
271
272   //! the signal about the workshop actions states are updated.
273   void commandStatusUpdated();
274
275   //! the application is started
276   void applicationStarted();
277
278   //! Signal to update Undo history list
279   void updateUndoHistory(const QList<ActionInfo>&);
280
281   //! Signal to update Redo history list
282   void updateRedoHistory(const QList<ActionInfo>&);
283
284  public slots:
285    /// Update of commands status
286   void updateCommandStatus();
287
288   /// update history list (undo/redo commands)
289   void updateHistory();
290
291   /// Save current document
292   bool onSave();
293
294   /// Save current document to a file selected by user
295   bool onSaveAs();
296
297   /// Undo last command
298   void onUndo(int times = 1);
299
300   /// Redo previous command
301   void onRedo(int times = 1);
302
303   // Rebuild data tree
304   //void onRebuild();
305
306   /// Validates the operation to change the "Apply" button state.
307   /// \param thePreviousState the previous state of the widget
308   void onWidgetStateChanged(int thePreviousState);
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   /// Open document from file
326   void onOpen();
327
328   /// Create a new document
329   void onNew();
330
331 #ifndef HAVE_SALOME
332   /// Exit application
333   void onExit();
334
335   /// Open preferences dialog box
336   void onPreferences();
337 #endif
338
339   /// Activates/deactivates the trihedron in the viewer AIS context
340   void onTrihedronVisibilityChanged(bool theState);
341
342  protected:
343   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
344   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
345   /// \param theOperation an operation
346    void setGrantedFeatures(ModuleBase_Operation* theOperation);
347
348   /// Update the property panel content by the XML description of the operation and set the panel
349   /// into the operation
350   /// \param theOperation an operation
351   void setPropertyPanel(ModuleBase_Operation* theOperation);
352
353   /// Connects or disconnects to the value changed signal of the property panel widgets
354   /// \param isToConnect a boolean value whether connect or disconnect
355   void connectToPropertyPanel(const bool isToConnect);
356
357   //! Find all referenced features. Return direct and indirect lists of referenced object
358   //! \param theList an objects to be checked
359   //! \param aDirectRefFeatures a list of direct reference features
360   //! \param aIndirectRefFeatures a list of features which depend on the feature through others
361   void findReferences(const QObjectPtrList& theList,
362                       std::set<FeaturePtr>& aDirectRefFeatures,
363                       std::set<FeaturePtr>& aIndirectRefFeatures);
364
365   //! Shows a dialog box about references. Ask whether they should be also removed.
366   //! \param theList an objects to be checked
367   //! \param aDirectRefFeatures a list of direct reference features
368   //! \param aIndirectRefFeatures a list of features which depend on the feature through others
369   //! \param theParent a parent widget for the question message box
370   //! \param doDeleteReferences if there are parameters between features, ask if they should be
371   //! replaced to their meaning without corresponded features remove
372   //! \return true if in message box answer is Yes
373   bool isDeleteFeatureWithReferences(const QObjectPtrList& theList,
374                                      const std::set<FeaturePtr>& aDirectRefFeatures,
375                                      const std::set<FeaturePtr>& aIndirectRefFeatures,
376                                      QWidget* theParent,
377                                      bool& doDeleteReferences);
378
379   //! \param theIgnoredFeatures a list of features to be ignored during delete
380   //! \param theList an objects to be checked
381   //! \param aDirectRefFeatures a list of direct reference features
382   //! \param aIndirectRefFeatures a list of features which depend on the feature through others
383   //! \param doDeleteReferences flag if referenced features should be removed also
384   bool deleteFeaturesInternal(const QObjectPtrList& theList,
385                               const std::set<FeaturePtr>& aDirectRefFeatures,
386                               const std::set<FeaturePtr>& aIndirectRefFeatures,
387                               const std::set<FeaturePtr>& theIgnoredFeatures,
388                               const bool doDeleteReferences = true);
389
390 private:
391   /// Display all results
392   //void displayAllResults();
393
394   /// Display results from document
395   /// \param theDoc a document
396   void displayDocumentResults(DocumentPtr theDoc);
397
398   /// Display results from a group
399   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
400
401  private slots:
402   /// SLOT, that is called after the operation is started. Update workshop state according to
403   /// the started operation, e.g. visualizes the property panel and connect to it.
404   /// \param theOpertion a started operation
405   void onOperationStarted(ModuleBase_Operation* theOperation);
406
407   /// SLOT, that is called after the operation is resumed. Update workshop state according to
408   /// the started operation, e.g. visualizes the property panel and connect to it.
409   /// \param theOpertion a resumed operation
410   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
411
412   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
413   /// hides the property panel and update the command status.
414   /// \param theOpertion a stopped operation
415   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
416
417   /// SLOT, that is called after the operation is committed.
418   /// \param theOpertion a committed operation
419   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
420
421   /// SLOT, that is called after the operation is aborted.
422   /// \param theOpertion an aborted operation
423   void onOperationAborted(ModuleBase_Operation* theOperation);
424
425   /// Slot, which reacts to the context popup menu call
426   /// \param theId the data value of the clicked action
427   /// \param isChecked a state of toggle if the action is checkable
428   void onContextMenuCommand(const QString& theId, bool isChecked);
429
430   /// Set waiting cursor
431   void onStartWaiting();
432
433   /// Called by Ok button clicked in the property panel. Asks the error manager whether
434   /// the operation can be committed and do it if it returns true.
435   void onAcceptActionClicked();
436
437  private:
438    /// Init menu
439   void initMenu();
440
441   /// Register validators
442   void registerValidators() const;
443
444   /// Load module from external library
445   /// \param theModule name of the module
446   ModuleBase_IModule* loadModule(const QString& theModule);
447
448   /// Create module
449   bool createModule();
450
451   /// Create object browser widget
452   /// \param theParent a parent of widget
453   QDockWidget* createObjectBrowser(QWidget* theParent);
454
455   /// Create property panel widget
456   /// \param theParent a parent of widget
457   QDockWidget* createPropertyPanel(QWidget* theParent);
458
459   // Creates Dock widgets: Object browser and Property panel
460   void createDockWidgets();
461
462   //! Extends undo/redo toolbutton's with history menu
463   //! \param theObject - in the OpenParts it is a QToolButton by itself,
464   //! in salome mode - QAction that creates a button.
465   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
466   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
467   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
468
469
470   /// Calls removeFeature of the document for each object in the list
471   //! \param theList an objects to be deleted
472   //! \param theIgnoredFeatures a list of features to be ignored during delete
473   //! \param theActionId an action command key to find context menu object types enabled for remove
474   bool removeFeatures(const QObjectPtrList& theList,
475                       const std::set<FeaturePtr>& theIgnoredFeatures,
476                       const QString& theActionId);
477
478   //! Creates list of actions (commands) by given history list from session
479   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
480
481 private:
482 #ifndef HAVE_SALOME
483   AppElements_MainWindow* myMainWindow;
484 #endif
485
486   ModuleBase_IModule* myModule;
487   XGUI_ErrorMgr* myErrorMgr;
488   XGUI_ObjectsBrowser* myObjectBrowser;
489   XGUI_PropertyPanel* myPropertyPanel;
490   XGUI_SelectionMgr* mySelector;
491   XGUI_Displayer* myDisplayer;
492   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
493   XGUI_ActionsMgr* myActionsMgr;
494   XGUI_SalomeConnector* mySalomeConnector;
495   XGUI_ErrorDialog* myErrorDlg;
496   XGUI_ViewerProxy* myViewerProxy;
497   XGUI_ContextMenuMgr* myContextMenuMgr;
498   XGUI_ModuleConnector* myModuleConnector;
499   XGUI_WorkshopListener* myEventsListener;
500
501   QString myCurrentDir;
502 };
503
504 #endif