Salome HOME
History for undo and redo commands
[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 <Events_Listener.h>
9 #include <ModuleBase_Definitions.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Feature.h>
12
13 #include <QObject>
14 #include <QMap>
15 #include <QKeySequence>
16 #include <QIcon>
17
18 class AppElements_MainWindow;
19 class AppElements_Command;
20 class AppElements_Workbench;
21
22 class XGUI_SelectionMgr;
23 class XGUI_Displayer;
24 class XGUI_OperationMgr;
25 class XGUI_SalomeConnector;
26 class XGUI_ObjectsBrowser;
27 class XGUI_ActionsMgr;
28 class XGUI_ErrorDialog;
29 class XGUI_SalomeViewer;
30 class XGUI_ViewerProxy;
31 class XGUI_PropertyPanel;
32 class XGUI_ContextMenuMgr;
33 class XGUI_ModuleConnector;
34
35 class ModuleBase_Operation;
36 class ModuleBase_IModule;
37 class ModuleBase_IViewer;
38
39 class Config_FeatureMessage;
40 class Config_PointerMessage;
41
42 class QWidget;
43 class QDockWidget;
44 class QMainWindow;
45
46 class ModelAPI_ObjectUpdatedMessage;
47 class ModelAPI_ObjectDeletedMessage;
48 class ModelAPI_ResultPart;
49 class QAction;
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, public Events_Listener
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   //! Returns main window (Desktop) of the application
69   AppElements_MainWindow* mainWindow() const
70   {
71     return myMainWindow;
72   }
73
74   //! Returns selection manager object
75   XGUI_SelectionMgr* selector() const
76   {
77     return mySelector;
78   }
79
80   //! Returns displayer
81   XGUI_Displayer* displayer() const
82   {
83     return myDisplayer;
84   }
85
86   //! ! Returns operation manager.
87   XGUI_OperationMgr* operationMgr() const
88   {
89     return myOperationMgr;
90   }
91
92   //! ! Returns an actions manager
93   XGUI_ActionsMgr* actionsMgr() const
94   {
95     return myActionsMgr;
96   }
97
98   //! Returns property panel widget
99   XGUI_PropertyPanel* propertyPanel() const
100   {
101     return myPropertyPanel;
102   }
103
104   //! Returns context menu manager object
105   XGUI_ContextMenuMgr* contextMenuMgr() const
106   {
107     return myContextMenuMgr;
108   }
109
110   //! Creates and adds a new workbench (menu group) with the given name and returns it
111   AppElements_Workbench* addWorkbench(const QString& theName);
112
113   //! Redefinition of Events_Listener method
114   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
115
116   //! Returns an object which provides interface to Salome Module (LightApp_Module)
117   XGUI_SalomeConnector* salomeConnector() const
118   {
119     return mySalomeConnector;
120   }
121
122   //! Provides an object which provides interface to Salome Viewer
123   ModuleBase_IViewer* salomeViewer() const;
124
125   //! Returns true if the application works as SALOME module
126   bool isSalomeMode() const
127   {
128     return mySalomeConnector != 0;
129   }
130
131   //! Returns Object browser
132   XGUI_ObjectsBrowser* objectBrowser() const
133   {
134     return myObjectBrowser;
135   }
136
137   /// This method is called by Salome module when selection is changed
138   void salomeViewerSelectionChanged();
139
140   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
141   XGUI_ViewerProxy* viewer() const
142   {
143     return myViewerProxy;
144   }
145
146   /// Returns the module connectory
147   /// \returns the instance of connector
148   XGUI_ModuleConnector* moduleConnector() const
149   {
150     return myModuleConnector;
151   }
152
153   /// Returns a desktop
154   /// \return a desktop instance
155   QMainWindow* desktop() const;
156
157   //! Returns icon name according to feature
158   static QIcon featureIcon(const FeaturePtr& theFeature);
159
160   //! Activates or deactivates a part
161   //! If PartPtr is Null pointer then PartSet will be activated
162   void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
163
164   //! Delete features
165   void deleteObjects(const QObjectPtrList& theList);
166
167   //! Show the given features in 3d Viewer
168   void showObjects(const QObjectPtrList& theList, bool isVisible);
169
170   //! Show the given features in 3d Viewer
171   void showOnlyObjects(const QObjectPtrList& theList);
172
173   /// Set display mode for the given onjects
174   /// \param theList a list of displayed objects
175   /// \param theMode a mode to set (see \ref XGUI_Displayer)
176   void setDisplayMode(const QObjectPtrList& theList, int theMode);
177
178   /// Returns current module
179   ModuleBase_IModule* module() const
180   {
181     return myModule;
182   }
183
184   /// Returns current directory whic contains data files
185   QString currentDataDir() const { return myCurrentDir; }
186
187   /// Returns current directory whic contains data files
188   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
189
190   /**
191   * Save the current document into a directory
192   * \param theName - path to the directory
193   * \param theFileNames - returned file names created in this directory
194   */
195   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
196
197   /**
198    * If there is an active (uncommited) operation shows a prompt to abort it
199    * and performs abortion if user agreed. Returns true if
200    * - operation aborted successfully
201    * - there is no active operation
202    */
203   bool isActiveOperationAborted();
204
205 signals:
206   /// Emitted when selection happens in Salome viewer
207   void salomeViewerSelection();
208
209   /// Emitted when error in applivation happens
210   void errorOccurred(const QString&);
211
212   //! the signal about the workshop actions states are updated.
213   void commandStatusUpdated();
214
215   //! the application is started
216   void applicationStarted();
217
218   void updateUndoHistory(const QList<QAction*>&);
219   void updateRedoHistory(const QList<QAction*>&);
220
221  public slots:
222    /// Update of commands status
223   void updateCommandStatus();
224
225   /// update history list (undo/redo commands)
226   void updateHistory();
227
228   /// Create a new dokument
229   void onNew();
230
231   /// Open document from file
232   void onOpen();
233
234   /// Save current document
235   bool onSave();
236
237   /// Save current document to a file selected by user
238   bool onSaveAs();
239
240   /// Exit application
241   void onExit();
242
243   /// Undo last command
244   void onUndo(int times = 1);
245
246   /// Redo previous command
247   void onRedo(int times = 1);
248
249   /// Rebuild data tree
250   void onRebuild();
251
252   /// Open preferences dialog box
253   void onPreferences();
254
255   /// Show property panel
256   void showPropertyPanel();
257
258   /// Hide property panel
259   void hidePropertyPanel();
260
261   /// Show object Browser
262   void showObjectBrowser();
263
264   /// Hide object Browser
265   void hideObjectBrowser();
266
267   /// Reaction on command call
268   void onFeatureTriggered();
269
270   /// Change active document
271   /// \param theObj a part object. If it is NULL then active document is a main document
272   void changeCurrentDocument(ObjectPtr theObj);
273
274   //void activateLastPart();
275
276   /// Close document
277   void closeDocument();
278
279  protected:
280   /// Find the nested features and set them into the operation
281   /// \param theOperation an operation
282   void setNestedFeatures(ModuleBase_Operation* theOperation);
283
284   /// Update the property panel content by the XML description of the operation and set the panel
285   /// into the operation
286   /// \param theOperation an operation
287   void setPropertyPanel(ModuleBase_Operation* theOperation);
288
289   /// Procedure to process postponed events
290   bool event(QEvent * theEvent);
291
292   //Event-loop processing methods:
293
294   /// Process event "Add a feature"
295   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
296
297   /// Connect to operation signals
298   /// \param theOperation an operation
299   void connectWithOperation(ModuleBase_Operation* theOperation);
300
301   /// Process feature update message
302   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
303
304   ///Process feature created message
305   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
306
307   /// Process feature redisplay message
308   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
309
310   /// Process feature delete message
311   void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
312
313   /// Display all results
314   void displayAllResults();
315
316   /// Displau results from document
317   /// \param theDoc a document
318   void displayDocumentResults(DocumentPtr theDoc);
319
320   /// Display results from a group
321   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
322
323  private slots:
324   /// SLOT, that is called after the operation is started. Update workshop state according to
325   /// the started operation, e.g. visualizes the property panel and connect to it.
326   /// \param theOpertion a started operation
327   void onOperationStarted(ModuleBase_Operation* theOperation);
328
329   /// SLOT, that is called after the operation is resumed. Update workshop state according to
330   /// the started operation, e.g. visualizes the property panel and connect to it.
331   /// \param theOpertion a resumed operation
332   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
333
334   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
335   /// hides the property panel and udpate the command status.
336   /// \param theOpertion a stopped operation
337   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
338
339   /// SLOT, that is called after the operation is committed.
340   /// \param theOpertion a commmitted operation
341   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
342
343   /// SLOT, that is called after the operation is aborted.
344   /// \param theOpertion an aborted operation
345   void onOperationAborted(ModuleBase_Operation* theOperation);
346
347   /// Slot, which reacts to the context popup menu call
348   /// \param theId the data value of the clicked action
349   /// \param isChecked a state of toggle if the action is checkable
350   void onContextMenuCommand(const QString& theId, bool isChecked);
351
352   /// Processing of values changed in model widget
353   void onWidgetValuesChanged();
354
355   /// Set waiting cursor
356   void onStartWaiting();
357
358  private:
359    /// Init menu
360   void initMenu();
361
362   /// Register validators
363   void registerValidators() const;
364
365   /// Load module from external library
366   /// \param theModule name of the module
367   ModuleBase_IModule* loadModule(const QString& theModule);
368
369   /// Activate module
370   bool activateModule();
371
372   /// Create object browser widget
373   /// \param theParent a parent of widget
374   QDockWidget* createObjectBrowser(QWidget* theParent);
375
376   /// Create property panel widget
377   /// \param theParent a parent of widget
378   QDockWidget* createPropertyPanel(QWidget* theParent);
379
380   // Creates Dock widgets: Object browser and Property panel
381   void createDockWidgets();
382
383   /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
384   void displayObject(ObjectPtr theObj);
385
386 private:
387   AppElements_MainWindow* myMainWindow;
388   ModuleBase_IModule* myModule;
389   XGUI_ObjectsBrowser* myObjectBrowser;
390   XGUI_PropertyPanel* myPropertyPanel;
391   XGUI_SelectionMgr* mySelector;
392   XGUI_Displayer* myDisplayer;
393   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
394   XGUI_ActionsMgr* myActionsMgr;
395   XGUI_SalomeConnector* mySalomeConnector;
396   XGUI_ErrorDialog* myErrorDlg;
397   XGUI_ViewerProxy* myViewerProxy;
398   XGUI_ContextMenuMgr* myContextMenuMgr;
399   XGUI_ModuleConnector* myModuleConnector;
400
401   QString myCurrentDir;
402   static QMap<QString, QString> myIcons;
403
404   bool myUpdatePrefs;
405
406   // Flag to check that part document is in process of activating
407   bool myPartActivating;
408 };
409
410 #endif