Salome HOME
Issue #1660: Ability to change the deflection coefficient
[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 results 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   //! Returns true if there is at least one selected body/construction/group result
205   //! \return boolean value
206   bool canChangeDeflection() const;
207
208   //! Change deflection of the results if it is possible
209   //! The operation is available for construction, body and group results
210   //! theObjects a list of selected objects
211   void changeDeflection(const QObjectPtrList& theObjects);
212
213   //! Show the given features in 3d Viewer
214   void showObjects(const QObjectPtrList& theList, bool isVisible);
215
216   //! Show the given features in 3d Viewer
217   void showOnlyObjects(const QObjectPtrList& theList);
218
219   /// Set display mode for the given objects
220   /// \param theList a list of displayed objects
221   /// \param theMode a mode to set (see \ref XGUI_Displayer)
222   void setDisplayMode(const QObjectPtrList& theList, int theMode);
223
224   /// Set selection mode in viewer. If theMode=-1 then activate default mode
225   /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
226   void setViewerSelectionMode(int theMode);
227
228   /// Activates current selection mode for the given list of objects
229   void activateObjectsSelection(const QObjectPtrList& theList);
230
231   /// Returns current module
232   ModuleBase_IModule* module() const
233   {
234     return myModule;
235   }
236
237   /// Returns current directory which contains data files
238   QString currentDataDir() const { return myCurrentDir; }
239
240   /// Returns current directory which contains data files
241   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
242
243   /**
244   * Save the current document into a directory
245   * \param theName - path to the directory
246   * \param theFileNames - returned file names created in this directory
247   */
248   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
249
250   /**
251    * If there is an active (uncommitted) operation shows a prompt to abort it
252    * and performs abortion if user agreed. Returns true if
253    * - operation aborted successfully
254    * - there is no active operation
255    */
256   bool abortAllOperations();
257
258   /// Updates workshop state according to the started operation, e.g. visualizes the property panel
259   /// and connect to it.
260   /// \param theOpertion a started operation
261   void operationStarted(ModuleBase_Operation* theOperation);
262
263
264   //! Delete features. Delete the referenced features. There can be a question with a list of
265   //! referenced objects.
266   //! \param theFeatures a list of objects to be deleted
267   bool deleteFeatures(const QObjectPtrList& theFeatures);
268
269   /// Deactivates the object, if it is active and the module returns that the activation
270   /// of selection for the object is not possible currently(the current operation uses it)
271   /// \param theObject an object
272   /// \param theUpdateViewer a boolean flag to update viewer immediately
273   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
274
275   /// Returns true if the action of the feature is created to contain Accept/Cancel button
276   /// \param theFeature a feature
277   bool isFeatureOfNested(const FeaturePtr& theFeature);
278
279   //! Shows the message in the status bar
280   //! \param theMessage a message
281   void setStatusBarMessage(const QString& theMessage);
282
283   /// Has to be called in order to display objects with visibility status = true
284   void synchronizeViewer();
285
286   /// Has to be called in order to display objects from a cpecifed group with visibility status = true
287   /// \param theDoc the document for objects synchronisation
288   /// \param theGroup the group name
289   /// \param theUpdateViewer update viewer flag
290   void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
291
292   /// Update the property panel content by the XML description of the operation and set the panel
293   /// into the operation
294   /// \param theOperation an operation
295   void fillPropertyPanel(ModuleBase_Operation* theOperation);
296
297   /// Connects or disconnects to the value changed signal of the property panel widgets
298   /// \param isToConnect a boolean value whether connect or disconnect
299   void connectToPropertyPanel(const bool isToConnect);
300
301   /// Returns defailt selection mode in 3d viewer
302   QIntList viewerSelectionModes() const { return myViewerSelMode; }
303
304   /// Highlights result objects in Object Browser according to
305   /// features found in the given list
306   void highlightResults(const QObjectPtrList& theObjects);
307
308   /// Highlights feature objects in Object Browser according to
309   /// features found in the given list
310   void highlightFeature(const QObjectPtrList& theObjects);
311
312   /// Returns Data Model XML reader which contains information about 
313   /// Data structure configuration
314   const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
315
316   /// A constant string used for "Move to end" command definition
317   /// It is used for specific processing of Undo/Redo for this command.
318   static QString MOVE_TO_END_COMMAND;
319
320   //! Closes all in the current session and load the directory
321   //! \param theDirectory a path to directory
322   void openDirectory(const QString& theDirectory);
323
324 signals:
325   /// Emitted when selection happens in Salome viewer
326   void salomeViewerSelection();
327
328   //! the signal about the workshop actions states are updated.
329   void commandStatusUpdated();
330
331   //! the application is started
332   void applicationStarted();
333
334   //! Signal to update Undo history list
335   void updateUndoHistory(const QList<ActionInfo>&);
336
337   //! Signal to update Redo history list
338   void updateRedoHistory(const QList<ActionInfo>&);
339
340  public slots:
341    /// Update of commands status
342   void updateCommandStatus();
343
344   /// update history list (undo/redo commands)
345   void updateHistory();
346
347   /// Save current document
348   bool onSave();
349
350   /// Save current document to a file selected by user
351   bool onSaveAs();
352
353   /// Undo last command
354   void onUndo(int times = 1);
355
356   /// Redo previous command
357   void onRedo(int times = 1);
358
359   // Rebuild data tree
360   //void onRebuild();
361
362   /// Validates the operation to change the "Apply" button state.
363   /// \param thePreviousState the previous state of the widget
364   void onWidgetStateChanged(int thePreviousState);
365
366   /// Calls activate of the current widget again. It is possible that selection filters are
367   /// differs in the new state of paged container
368   void onValuesChanged();
369
370   /// Listens the corresponded signal of model widget and updates Apply button state by feature
371   void onWidgetObjectUpdated();
372
373   /// Show property panel
374   void showPropertyPanel();
375
376   /// Hide property panel
377   void hidePropertyPanel();
378
379   /// Show object Browser
380   void showObjectBrowser();
381
382   /// Hide object Browser
383   void hideObjectBrowser();
384
385   /// Close document
386   void closeDocument();
387
388   /// Open document from file
389   void onOpen();
390
391   /// Create a new document
392   void onNew();
393
394 #ifndef HAVE_SALOME
395   /// Exit application
396   void onExit();
397
398   /// Open preferences dialog box
399   void onPreferences();
400 #endif
401
402   /// Activates/deactivates the trihedron in the viewer AIS context
403   void onTrihedronVisibilityChanged(bool theState);
404
405
406  protected:
407   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
408   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
409   /// \param theOperation an operation
410    void setGrantedFeatures(ModuleBase_Operation* theOperation);
411
412 private:
413   /// Display all results
414   //void displayAllResults();
415
416   /// Display results from document
417   /// \param theDoc a document
418   void displayDocumentResults(DocumentPtr theDoc);
419
420   /// Display results from a group
421   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
422
423  private slots:
424   /// SLOT, that is called after the operation is started. Update workshop state according to
425   /// the started operation, e.g. visualizes the property panel and connect to it.
426   /// \param theOpertion a started operation
427   // void onOperationStarted(ModuleBase_Operation* theOperation);
428
429   /// SLOT, that is called after the operation is resumed. Update workshop state according to
430   /// the started operation, e.g. visualizes the property panel and connect to it.
431   /// \param theOpertion a resumed operation
432   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
433
434   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
435   /// hides the property panel and update the command status.
436   /// \param theOpertion a stopped operation
437   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
438
439   /// SLOT, that is called after the operation is committed.
440   /// \param theOpertion a committed operation
441   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
442
443   /// SLOT, that is called after the operation is aborted.
444   /// \param theOpertion an aborted operation
445   void onOperationAborted(ModuleBase_Operation* theOperation);
446
447   /// Slot, which reacts to the context popup menu call
448   /// \param theId the data value of the clicked action
449   /// \param isChecked a state of toggle if the action is checkable
450   void onContextMenuCommand(const QString& theId, bool isChecked);
451
452   /// Set waiting cursor
453   void onStartWaiting();
454
455   /// Called by Ok button clicked in the property panel. Asks the error manager whether
456   /// the operation can be committed and do it if it returns true.
457   void onAcceptActionClicked();
458
459   /// Called by Preview button clicked in the property panel. Sends signal to model to
460   /// compute preview.
461   void onPreviewActionClicked();
462
463  private:
464    /// Init menu
465   void initMenu();
466
467   /// Register validators
468   void registerValidators() const;
469
470   /// Load module from external library
471   /// \param theModule name of the module
472   ModuleBase_IModule* loadModule(const QString& theModule);
473
474   /// Create module
475   bool createModule();
476
477   /// Create object browser widget
478   /// \param theParent a parent of widget
479   QDockWidget* createObjectBrowser(QWidget* theParent);
480
481   /// Create property panel widget
482   /// \param theParent a parent of widget
483   QDockWidget* createPropertyPanel(QWidget* theParent);
484
485   // Creates Dock widgets: Object browser and Property panel
486   void createDockWidgets();
487
488   //! Extends undo/redo toolbutton's with history menu
489   //! \param theObject - in the OpenParts it is a QToolButton by itself,
490   //! in salome mode - QAction that creates a button.
491   //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
492   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
493   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
494
495   //! Creates list of actions (commands) by given history list from session
496   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
497
498 private:
499 #ifndef HAVE_SALOME
500   AppElements_MainWindow* myMainWindow;
501 #endif
502
503   ModuleBase_IModule* myModule;
504   XGUI_ErrorMgr* myErrorMgr;
505   XGUI_ObjectsBrowser* myObjectBrowser;
506   XGUI_PropertyPanel* myPropertyPanel;
507   XGUI_SelectionMgr* mySelector;
508   XGUI_Displayer* myDisplayer;
509   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
510   XGUI_ActionsMgr* myActionsMgr;
511   XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
512   XGUI_SalomeConnector* mySalomeConnector;
513   XGUI_ErrorDialog* myErrorDlg;
514   XGUI_ViewerProxy* myViewerProxy;
515   XGUI_ContextMenuMgr* myContextMenuMgr;
516   XGUI_ModuleConnector* myModuleConnector;
517   XGUI_WorkshopListener* myEventsListener;
518
519   QString myCurrentDir;
520
521   QIntList myViewerSelMode;
522
523   Config_DataModelReader* myDataModelXMLReader;
524 };
525
526 #endif