]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
Issue #1489 Multi-rotation problem if there is a reference to copied objects
[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_MenuMgr;
31 class XGUI_ModuleConnector;
32 class XGUI_ObjectsBrowser;
33 class XGUI_OperationMgr;
34 class XGUI_PropertyPanel;
35 class XGUI_SalomeConnector;
36 class XGUI_SalomeViewer;
37 class XGUI_SelectionMgr;
38 class XGUI_ViewerProxy;
39 class XGUI_WorkshopListener;
40
41 class ModuleBase_IModule;
42 class ModuleBase_IViewer;
43 class ModuleBase_Operation;
44
45 class QWidget;
46 class QDockWidget;
47 class QMainWindow;
48
49 class QAction;
50 class Config_DataModelReader;
51
52 /**\class XGUI_Workshop
53  * \ingroup GUI
54  * \brief Class which defines a configuration of the application (Workshop) and launches it.
55  */
56 class XGUI_EXPORT XGUI_Workshop : public QObject
57 {
58 Q_OBJECT
59  public:
60   /// Constructor
61   /// \param theConnector a Salome connector object. 
62   /// Used only if the workshop is launched in Salome environment
63   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
64   virtual ~XGUI_Workshop();
65
66   //! Starting of the application
67   void startApplication();
68
69   /// Activates the module controls. Should be called after module creation
70   void activateModule();
71
72   /// Deactivates the module controls. Should be called after module creation
73   void deactivateModule();
74
75 #ifndef HAVE_SALOME
76   //! Returns main window (Desktop) of the application
77   AppElements_MainWindow* mainWindow() const
78   {
79     return myMainWindow;
80   }
81
82   //! Creates and adds a new workbench (menu group) with the given name and returns it
83   AppElements_Workbench* addWorkbench(const QString& theName);
84 #endif
85
86   //! Returns selection manager object
87   XGUI_SelectionMgr* selector() const
88   {
89     return mySelector;
90   }
91
92   //! Returns displayer
93   XGUI_Displayer* displayer() const
94   {
95     return myDisplayer;
96   }
97
98   //! ! Returns operation manager.
99   XGUI_OperationMgr* operationMgr() const
100   {
101     return myOperationMgr;
102   }
103
104   //! ! Returns error manager.
105   XGUI_ErrorMgr* errorMgr() const
106   {
107     return myErrorMgr;
108   }
109
110   //! ! Returns an actions manager
111   XGUI_ActionsMgr* actionsMgr() const
112   {
113     return myActionsMgr;
114   }
115
116   //! ! Returns an actions manager
117   XGUI_MenuMgr* menuMgr() const
118   {
119     return myMenuMgr;
120   }
121
122   //! Returns property panel widget
123   XGUI_PropertyPanel* propertyPanel() const
124   {
125     return myPropertyPanel;
126   }
127
128   //! Returns context menu manager object
129   XGUI_ContextMenuMgr* contextMenuMgr() const
130   {
131     return myContextMenuMgr;
132   }
133
134   //! Returns an object which provides interface to Salome Module (LightApp_Module)
135   XGUI_SalomeConnector* salomeConnector() const
136   {
137     return mySalomeConnector;
138   }
139
140   //! Provides an object which provides interface to Salome Viewer
141   ModuleBase_IViewer* salomeViewer() const;
142
143   //! Returns true if the application works as SALOME module
144   bool isSalomeMode() const
145   {
146     return mySalomeConnector != 0;
147   }
148
149   //! Returns Object browser
150   XGUI_ObjectsBrowser* objectBrowser() const
151   {
152     return myObjectBrowser;
153   }
154
155   /// This method is called by Salome module when selection is changed
156   void salomeViewerSelectionChanged();
157
158   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
159   XGUI_ViewerProxy* viewer() const
160   {
161     return myViewerProxy;
162   }
163
164   /// Returns the module connector
165   /// \returns the instance of connector
166   XGUI_ModuleConnector* moduleConnector() const
167   {
168     return myModuleConnector;
169   }
170
171   /// Returns a desktop
172   /// \return a desktop instance
173   QMainWindow* desktop() const;
174
175   //! Delete features
176   void deleteObjects();
177
178   //! Searches for selected features unused in other (not selected) features. If one or several
179   //! selected features are found, a warning message proposes to delete them. It contains 
180   //! the list of features to be deleted.
181   void cleanHistory();
182
183   //! Returns true if the selected feature can be moved to the position after the current feature
184   //! \return boolean value
185   bool canMoveFeature();
186
187   //! Move selected features to be after the current feature
188   void moveObjects();
189
190   //! Returns true if the object can be shaded. If the object is a compsolid result, the method
191   //! checks subobjects of the result
192   //! \return boolean value
193   bool canBeShaded(const ObjectPtr& theObject) const;
194
195   //! Returns true if there is at least one selected body/construction/group result
196   //! \return boolean value
197   bool canChangeColor() const;
198
199   //! Change color of the features if it is possible
200   //! The operation is available for construction, body and group results
201   //! theObjects a list of selected objects
202   void changeColor(const QObjectPtrList& theObjects);
203
204   //! Show the given features in 3d Viewer
205   void showObjects(const QObjectPtrList& theList, bool isVisible);
206
207   //! Show the given features in 3d Viewer
208   void showOnlyObjects(const QObjectPtrList& theList);
209
210   /// Set display mode for the given objects
211   /// \param theList a list of displayed objects
212   /// \param theMode a mode to set (see \ref XGUI_Displayer)
213   void setDisplayMode(const QObjectPtrList& theList, int theMode);
214
215   /// Set selection mode in viewer. If theMode=-1 then activate default mode
216   /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
217   void setViewerSelectionMode(int theMode);
218
219   /// Activates current selection mode for the given list of objects
220   void activateObjectsSelection(const QObjectPtrList& theList);
221
222   /// Returns current module
223   ModuleBase_IModule* module() const
224   {
225     return myModule;
226   }
227
228   /// Returns current directory which contains data files
229   QString currentDataDir() const { return myCurrentDir; }
230
231   /// Returns current directory which contains data files
232   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
233
234   /**
235   * Save the current document into a directory
236   * \param theName - path to the directory
237   * \param theFileNames - returned file names created in this directory
238   */
239   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
240
241   /**
242    * If there is an active (uncommitted) operation shows a prompt to abort it
243    * and performs abortion if user agreed. Returns true if
244    * - operation aborted successfully
245    * - there is no active operation
246    */
247   bool abortAllOperations();
248
249   //! Delete features. Delete the referenced features. There can be a question with a list of
250   //! referenced objects.
251   //! \param theFeatures a list of objects to be deleted
252   bool deleteFeatures(const QObjectPtrList& theFeatures);
253
254   /// Deactivates the object, if it is active and the module returns that the activation
255   /// of selection for the object is not possible currently(the current operation uses it)
256   /// \param theObject an object
257   /// \param theUpdateViewer a boolean flag to update viewer immediately
258   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
259
260   /// Returns true if the action of the feature is created to contain Accept/Cancel button
261   /// \param theFeature a feature
262   bool isFeatureOfNested(const FeaturePtr& theFeature);
263
264   /// Has to be called in order to display objects with visibility status = true
265   void synchronizeViewer();
266
267   /// Has to be called in order to display objects from a cpecifed group with visibility status = true
268   /// \param theDoc the document for objects synchronisation
269   /// \param theGroup the group name
270   /// \param theUpdateViewer update viewer flag
271   void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
272
273   /// Update the property panel content by the XML description of the operation and set the panel
274   /// into the operation
275   /// \param theOperation an operation
276   void setPropertyPanel(ModuleBase_Operation* theOperation);
277
278   /// Connects or disconnects to the value changed signal of the property panel widgets
279   /// \param isToConnect a boolean value whether connect or disconnect
280   void connectToPropertyPanel(const bool isToConnect);
281
282   /// Returns defailt selection mode in 3d viewer
283   QIntList viewerSelectionModes() const { return myViewerSelMode; }
284
285   /// Highlights result objects in Object Browser according to
286   /// features found in the given list
287   void highlightResults(const QObjectPtrList& theObjects);
288
289   /// Highlights feature objects in Object Browser according to
290   /// features found in the given list
291   void highlightFeature(const QObjectPtrList& theObjects);
292
293   /// Returns Data Model XML reader which contains information about 
294   /// Data structure configuration
295   const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
296
297   /// A constant string used for "Move to end" command definition
298   /// It is used for specific processing of Undo/Redo for this command.
299   static QString MOVE_TO_END_COMMAND;
300
301 signals:
302   /// Emitted when selection happens in Salome viewer
303   void salomeViewerSelection();
304
305   /// Emitted when error in application happens
306   void errorOccurred(const QString&);
307
308   //! the signal about the workshop actions states are updated.
309   void commandStatusUpdated();
310
311   //! the application is started
312   void applicationStarted();
313
314   //! Signal to update Undo history list
315   void updateUndoHistory(const QList<ActionInfo>&);
316
317   //! Signal to update Redo history list
318   void updateRedoHistory(const QList<ActionInfo>&);
319
320  public slots:
321    /// Update of commands status
322   void updateCommandStatus();
323
324   /// update history list (undo/redo commands)
325   void updateHistory();
326
327   /// Save current document
328   bool onSave();
329
330   /// Save current document to a file selected by user
331   bool onSaveAs();
332
333   /// Undo last command
334   void onUndo(int times = 1);
335
336   /// Redo previous command
337   void onRedo(int times = 1);
338
339   // Rebuild data tree
340   //void onRebuild();
341
342   /// Validates the operation to change the "Apply" button state.
343   /// \param thePreviousState the previous state of the widget
344   void onWidgetStateChanged(int thePreviousState);
345
346   /// Calls activate of the current widget again. It is possible that selection filters are
347   /// differs in the new state of paged container
348   void onValuesChanged();
349
350   /// Listens the corresponded signal of model widget and updates Apply button state by feature
351   void onWidgetObjectUpdated();
352
353   /// Show property panel
354   void showPropertyPanel();
355
356   /// Hide property panel
357   void hidePropertyPanel();
358
359   /// Show object Browser
360   void showObjectBrowser();
361
362   /// Hide object Browser
363   void hideObjectBrowser();
364
365   /// Close document
366   void closeDocument();
367
368   /// Open document from file
369   void onOpen();
370
371   /// Create a new document
372   void onNew();
373
374 #ifndef HAVE_SALOME
375   /// Exit application
376   void onExit();
377
378   /// Open preferences dialog box
379   void onPreferences();
380 #endif
381
382   /// Activates/deactivates the trihedron in the viewer AIS context
383   void onTrihedronVisibilityChanged(bool theState);
384
385
386  protected:
387   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
388   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
389   /// \param theOperation an operation
390    void setGrantedFeatures(ModuleBase_Operation* theOperation);
391
392 private:
393   /// Display all results
394   //void displayAllResults();
395
396   /// Display results from document
397   /// \param theDoc a document
398   void displayDocumentResults(DocumentPtr theDoc);
399
400   /// Display results from a group
401   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
402
403  private slots:
404   /// SLOT, that is called after the operation is started. Update workshop state according to
405   /// the started operation, e.g. visualizes the property panel and connect to it.
406   /// \param theOpertion a started operation
407   void onOperationStarted(ModuleBase_Operation* theOperation);
408
409   /// SLOT, that is called after the operation is resumed. Update workshop state according to
410   /// the started operation, e.g. visualizes the property panel and connect to it.
411   /// \param theOpertion a resumed operation
412   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
413
414   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
415   /// hides the property panel and update the command status.
416   /// \param theOpertion a stopped operation
417   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
418
419   /// SLOT, that is called after the operation is committed.
420   /// \param theOpertion a committed operation
421   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
422
423   /// SLOT, that is called after the operation is aborted.
424   /// \param theOpertion an aborted operation
425   void onOperationAborted(ModuleBase_Operation* theOperation);
426
427   /// Slot, which reacts to the context popup menu call
428   /// \param theId the data value of the clicked action
429   /// \param isChecked a state of toggle if the action is checkable
430   void onContextMenuCommand(const QString& theId, bool isChecked);
431
432   /// Set waiting cursor
433   void onStartWaiting();
434
435   /// Called by Ok button clicked in the property panel. Asks the error manager whether
436   /// the operation can be committed and do it if it returns true.
437   void onAcceptActionClicked();
438
439   /// Called by Preview button clicked in the property panel. Sends signal to model to
440   /// compute preview.
441   void onPreviewActionClicked();
442
443  private:
444    /// Init menu
445   void initMenu();
446
447   /// Register validators
448   void registerValidators() const;
449
450   /// Load module from external library
451   /// \param theModule name of the module
452   ModuleBase_IModule* loadModule(const QString& theModule);
453
454   /// Create module
455   bool createModule();
456
457   /// Create object browser widget
458   /// \param theParent a parent of widget
459   QDockWidget* createObjectBrowser(QWidget* theParent);
460
461   /// Create property panel widget
462   /// \param theParent a parent of widget
463   QDockWidget* createPropertyPanel(QWidget* theParent);
464
465   // Creates Dock widgets: Object browser and Property panel
466   void createDockWidgets();
467
468   //! Extends undo/redo toolbutton's with history menu
469   //! \param theObject - in the OpenParts it is a QToolButton by itself,
470   //! in salome mode - QAction that creates a button.
471   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
472   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
473   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
474
475   //! Creates list of actions (commands) by given history list from session
476   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
477
478 private:
479 #ifndef HAVE_SALOME
480   AppElements_MainWindow* myMainWindow;
481 #endif
482
483   ModuleBase_IModule* myModule;
484   XGUI_ErrorMgr* myErrorMgr;
485   XGUI_ObjectsBrowser* myObjectBrowser;
486   XGUI_PropertyPanel* myPropertyPanel;
487   XGUI_SelectionMgr* mySelector;
488   XGUI_Displayer* myDisplayer;
489   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
490   XGUI_ActionsMgr* myActionsMgr;
491   XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
492   XGUI_SalomeConnector* mySalomeConnector;
493   XGUI_ErrorDialog* myErrorDlg;
494   XGUI_ViewerProxy* myViewerProxy;
495   XGUI_ContextMenuMgr* myContextMenuMgr;
496   XGUI_ModuleConnector* myModuleConnector;
497   XGUI_WorkshopListener* myEventsListener;
498
499   QString myCurrentDir;
500
501   QIntList myViewerSelMode;
502
503   Config_DataModelReader* myDataModelXMLReader;
504 };
505
506 #endif