]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Issue #660 Move Group is still not implemented
[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_SelectionMgr;
24 class XGUI_Displayer;
25 class XGUI_OperationMgr;
26 class XGUI_SalomeConnector;
27 class XGUI_ObjectsBrowser;
28 class XGUI_ActionsMgr;
29 class XGUI_ErrorDialog;
30 class XGUI_SalomeViewer;
31 class XGUI_ViewerProxy;
32 class XGUI_PropertyPanel;
33 class XGUI_ContextMenuMgr;
34 class XGUI_ModuleConnector;
35 class XGUI_WorkshopListener;
36
37 class ModuleBase_Operation;
38 class ModuleBase_IModule;
39 class ModuleBase_IViewer;
40
41 class QWidget;
42 class QDockWidget;
43 class QMainWindow;
44
45 class QAction;
46
47 /**\class XGUI_Workshop
48  * \ingroup GUI
49  * \brief Class which defines a configuration of the application (Workshop) and launches it.
50  */
51 class XGUI_EXPORT XGUI_Workshop : public QObject
52 {
53 Q_OBJECT
54  public:
55   /// Constructor
56   /// \param theConnector a Salome connector object. 
57   /// Used only if the workshop is launched in Salome environment
58   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
59   virtual ~XGUI_Workshop();
60
61   //! Starting of the application
62   void startApplication();
63
64   // Activates the module controls. Should be called after module creation
65   void activateModule();
66
67   // Deactivates the module controls. Should be called after module creation
68   void deactivateModule();
69
70   //! Returns main window (Desktop) of the application
71   AppElements_MainWindow* mainWindow() const
72   {
73     return myMainWindow;
74   }
75
76   //! Returns selection manager object
77   XGUI_SelectionMgr* selector() const
78   {
79     return mySelector;
80   }
81
82   //! Returns displayer
83   XGUI_Displayer* displayer() const
84   {
85     return myDisplayer;
86   }
87
88   //! ! Returns operation manager.
89   XGUI_OperationMgr* operationMgr() const
90   {
91     return myOperationMgr;
92   }
93
94   //! ! Returns an actions manager
95   XGUI_ActionsMgr* actionsMgr() const
96   {
97     return myActionsMgr;
98   }
99
100   //! Returns property panel widget
101   XGUI_PropertyPanel* propertyPanel() const
102   {
103     return myPropertyPanel;
104   }
105
106   //! Returns context menu manager object
107   XGUI_ContextMenuMgr* contextMenuMgr() const
108   {
109     return myContextMenuMgr;
110   }
111
112   //! Creates and adds a new workbench (menu group) with the given name and returns it
113   AppElements_Workbench* addWorkbench(const QString& theName);
114
115   //! Returns an object which provides interface to Salome Module (LightApp_Module)
116   XGUI_SalomeConnector* salomeConnector() const
117   {
118     return mySalomeConnector;
119   }
120
121   //! Provides an object which provides interface to Salome Viewer
122   ModuleBase_IViewer* salomeViewer() const;
123
124   //! Returns true if the application works as SALOME module
125   bool isSalomeMode() const
126   {
127     return mySalomeConnector != 0;
128   }
129
130   /// Returns true if the loading data process is started and has not been finished yet
131   /// \return boolean result
132   bool isLoadingData() const
133   {
134     return myIsLoadingData;
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 connectory
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   //! Move selected features to be after the current feature
167   void moveObjects();
168
169   //! Returns true if there is at least one selected body/construction/group result
170   //! \return boolean value
171   bool canChangeColor() const;
172
173   //! Change color of the features if it is possible
174   //! The operation is available for construction, body and group results
175   //! theObjects a list of selected objects
176   void changeColor(const QObjectPtrList& theObjects);
177
178   //! Show the given features in 3d Viewer
179   void showObjects(const QObjectPtrList& theList, bool isVisible);
180
181   //! Show the given features in 3d Viewer
182   void showOnlyObjects(const QObjectPtrList& theList);
183
184   /// Set display mode for the given onjects
185   /// \param theList a list of displayed objects
186   /// \param theMode a mode to set (see \ref XGUI_Displayer)
187   void setDisplayMode(const QObjectPtrList& theList, int theMode);
188
189   /// Returns current module
190   ModuleBase_IModule* module() const
191   {
192     return myModule;
193   }
194
195   /// Returns current directory whic contains data files
196   QString currentDataDir() const { return myCurrentDir; }
197
198   /// Returns current directory whic contains data files
199   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
200
201   /**
202   * Save the current document into a directory
203   * \param theName - path to the directory
204   * \param theFileNames - returned file names created in this directory
205   */
206   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
207
208   /**
209    * If there is an active (uncommited) operation shows a prompt to abort it
210    * and performs abortion if user agreed. Returns true if
211    * - operation aborted successfully
212    * - there is no active operation
213    */
214   bool isActiveOperationAborted();
215
216   //! Delete features. Delete the referenced features. There can be a question with a list of referenced
217   //! objects.
218   //! \param theList an objects to be deleted
219   //! \param theIgnoredFeatures a list of features to be ignored during delete
220   //! \param theParent a parent widget for the question message box
221   //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
222   //! objects features appear. If the user chose do not continue, the deletion is not performed
223   //! \return the success of the delete 
224   bool deleteFeatures(const QObjectPtrList& theList,
225                       const std::set<FeaturePtr>& theIgnoredFeatures,
226                       QWidget* theParent = 0,
227                       const bool theAskAboutDeleteReferences = false);
228
229   /// Deactivates the object, if it is active and the module returns that the activation
230   /// of selection for the object is not possible currently(the current operation uses it)
231   /// \param theObject an object
232   /// \param theUpdateViewer a boolean flag to update viewer immediately
233   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
234
235 signals:
236   /// Emitted when selection happens in Salome viewer
237   void salomeViewerSelection();
238
239   /// Emitted when error in applivation happens
240   void errorOccurred(const QString&);
241
242   //! the signal about the workshop actions states are updated.
243   void commandStatusUpdated();
244
245   //! the application is started
246   void applicationStarted();
247
248   //! Signal to update Undo history list
249   void updateUndoHistory(const QList<ActionInfo>&);
250
251   //! Signal to update Redo history list
252   void updateRedoHistory(const QList<ActionInfo>&);
253
254  public slots:
255    /// Update of commands status
256   void updateCommandStatus();
257
258   /// update history list (undo/redo commands)
259   void updateHistory();
260
261   /// Create a new dokument
262   void onNew();
263
264   /// Open document from file
265   void onOpen();
266
267   /// Save current document
268   bool onSave();
269
270   /// Save current document to a file selected by user
271   bool onSaveAs();
272
273   /// Exit application
274   void onExit();
275
276   /// Undo last command
277   void onUndo(int times = 1);
278
279   /// Redo previous command
280   void onRedo(int times = 1);
281
282   /// Rebuild data tree
283   void onRebuild();
284
285   /// Open preferences dialog box
286   void onPreferences();
287
288   /// Show property panel
289   void showPropertyPanel();
290
291   /// Hide property panel
292   void hidePropertyPanel();
293
294   /// Show object Browser
295   void showObjectBrowser();
296
297   /// Hide object Browser
298   void hideObjectBrowser();
299
300   /// Reaction on command call
301   //void onFeatureTriggered();
302
303   /// Close document
304   void closeDocument();
305
306  protected:
307   /// Find the nested features and set them into the operation
308   /// \param theOperation an operation
309   void setNestedFeatures(ModuleBase_Operation* theOperation);
310
311   /// Update the property panel content by the XML description of the operation and set the panel
312   /// into the operation
313   /// \param theOperation an operation
314   void setPropertyPanel(ModuleBase_Operation* theOperation);
315
316   /// Connect to operation signals
317   /// \param theOperation an operation
318   void connectWithOperation(ModuleBase_Operation* theOperation);
319
320 private:
321   /// Display all results
322   //void displayAllResults();
323
324   /// Displau results from document
325   /// \param theDoc a document
326   void displayDocumentResults(DocumentPtr theDoc);
327
328   /// Display results from a group
329   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
330
331  private slots:
332   /// SLOT, that is called after the operation is started. Update workshop state according to
333   /// the started operation, e.g. visualizes the property panel and connect to it.
334   /// \param theOpertion a started operation
335   void onOperationStarted(ModuleBase_Operation* theOperation);
336
337   /// SLOT, that is called after the operation is resumed. Update workshop state according to
338   /// the started operation, e.g. visualizes the property panel and connect to it.
339   /// \param theOpertion a resumed operation
340   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
341
342   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
343   /// hides the property panel and udpate the command status.
344   /// \param theOpertion a stopped operation
345   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
346
347   /// SLOT, that is called after the operation is committed.
348   /// \param theOpertion a commmitted operation
349   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
350
351   /// SLOT, that is called after the operation is aborted.
352   /// \param theOpertion an aborted operation
353   void onOperationAborted(ModuleBase_Operation* theOperation);
354
355   /// Slot, which reacts to the context popup menu call
356   /// \param theId the data value of the clicked action
357   /// \param isChecked a state of toggle if the action is checkable
358   void onContextMenuCommand(const QString& theId, bool isChecked);
359
360   /// Set waiting cursor
361   void onStartWaiting();
362
363  private:
364    /// Init menu
365   void initMenu();
366
367   /// Register validators
368   void registerValidators() const;
369
370   /// Load module from external library
371   /// \param theModule name of the module
372   ModuleBase_IModule* loadModule(const QString& theModule);
373
374   /// Create module
375   bool createModule();
376
377   /// Create object browser widget
378   /// \param theParent a parent of widget
379   QDockWidget* createObjectBrowser(QWidget* theParent);
380
381   /// Create property panel widget
382   /// \param theParent a parent of widget
383   QDockWidget* createPropertyPanel(QWidget* theParent);
384
385   // Creates Dock widgets: Object browser and Property panel
386   void createDockWidgets();
387
388   //! Extends undo/redo toolbutton's with history menu
389   //! \param theObject - in the OpenParts it is a QToolButton by itself,
390   //! in salome mode - QAction that creates a button.
391   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
392   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
393   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
394
395   //! Creates list of actions (commands) by given history list from session
396   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
397
398 private:
399   AppElements_MainWindow* myMainWindow;
400   ModuleBase_IModule* myModule;
401   XGUI_ObjectsBrowser* myObjectBrowser;
402   XGUI_PropertyPanel* myPropertyPanel;
403   XGUI_SelectionMgr* mySelector;
404   XGUI_Displayer* myDisplayer;
405   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
406   XGUI_ActionsMgr* myActionsMgr;
407   XGUI_SalomeConnector* mySalomeConnector;
408   XGUI_ErrorDialog* myErrorDlg;
409   XGUI_ViewerProxy* myViewerProxy;
410   XGUI_ContextMenuMgr* myContextMenuMgr;
411   XGUI_ModuleConnector* myModuleConnector;
412   XGUI_WorkshopListener* myEventsListener;
413
414   QString myCurrentDir;
415
416   /// The flag is true when we loading a document
417   bool myIsLoadingData;
418 };
419
420 #endif