Salome HOME
Merge branch 'V9_2_2_BR'
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef XGUI_WORKSHOP_H
21 #define XGUI_WORKSHOP_H
22
23 #include "XGUI.h"
24
25 #include <ModelAPI_Document.h>
26 #include <ModelAPI_Feature.h>
27
28 #include <ModuleBase_ActionInfo.h>
29 #include <ModuleBase_ActionType.h>
30 #include <ModuleBase_Definitions.h>
31
32 #include <SelectMgr_ListOfFilter.hxx>
33
34 #include <QIcon>
35 #include <QObject>
36 #include <QKeySequence>
37 #include <QMap>
38 #include <QTemporaryDir>
39
40 #ifndef HAVE_SALOME
41 class AppElements_Command;
42 class AppElements_MainWindow;
43 class AppElements_Workbench;
44 #endif
45
46 class Config_DataModelReader;
47
48 class XGUI_ActionsMgr;
49 class XGUI_ActiveControlMgr;
50 class XGUI_ContextMenuMgr;
51 class XGUI_Displayer;
52 class XGUI_ErrorDialog;
53 class XGUI_ErrorMgr;
54 class XGUI_FacesPanel;
55 class XGUI_MenuMgr;
56 class XGUI_ModuleConnector;
57 class XGUI_ObjectsBrowser;
58 class XGUI_OperationMgr;
59 class XGUI_PropertyPanel;
60 class XGUI_SalomeConnector;
61 class XGUI_SalomeViewer;
62 class XGUI_SelectionActivate;
63 class XGUI_SelectionMgr;
64 class XGUI_ViewerProxy;
65 class XGUI_WorkshopListener;
66 class XGUI_InspectionPanel;
67
68 class ModuleBase_IModule;
69 class ModuleBase_IViewer;
70 class ModuleBase_Operation;
71
72 class QAction;
73 class QDockWidget;
74 class QMainWindow;
75 class QWidget;
76
77 /// \class XGUI_Workshop
78 /// \ingroup GUI
79 /// \brief Class which defines a configuration of the application (Workshop) and launches it.
80 class XGUI_EXPORT XGUI_Workshop : public QObject
81 {
82 Q_OBJECT
83  public:
84   /// Constructor
85   /// \param theConnector a Salome connector object.
86   /// Used only if the workshop is launched in Salome environment
87   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
88   virtual ~XGUI_Workshop();
89
90   /// Starting of the application
91   void startApplication();
92
93   /// Activates the module controls. Should be called after module creation
94   void activateModule();
95
96   /// Deactivates the module controls. Should be called after module creation
97   void deactivateModule();
98
99 #ifndef HAVE_SALOME
100   /// Returns main window (Desktop) of the application
101   AppElements_MainWindow* mainWindow() const { return myMainWindow; }
102
103   /// Creates and adds a new workbench (menu group) with the given name and returns it
104   AppElements_Workbench* addWorkbench(const QString& theName);
105 #endif
106
107   /// Returns selection manager object
108   XGUI_SelectionMgr* selector() const { return mySelector; }
109
110   /// Returns selection activating object
111   XGUI_SelectionActivate* selectionActivate() const { return mySelectionActivate; }
112
113   /// Returns displayer
114   XGUI_Displayer* displayer() const { return myDisplayer; }
115
116   /// Returns operation manager.
117   XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
118
119   /// Returns error manager.
120   XGUI_ErrorMgr* errorMgr() const { return myErrorMgr; }
121
122   /// Returns an actions manager
123   XGUI_ActionsMgr* actionsMgr() const { return myActionsMgr; }
124
125   /// Returns an active control manager
126   XGUI_ActiveControlMgr* activeControlMgr() const { return myActiveControlMgr; }
127
128   /// Returns an actions manager
129   XGUI_MenuMgr* menuMgr() const { return myMenuMgr; }
130
131   /// Returns property panel widget
132   XGUI_PropertyPanel* propertyPanel() const { return myPropertyPanel; }
133
134   /// Returns property panel widget
135   XGUI_InspectionPanel* inspectionPanel() const { return myInspectionPanel; }
136
137   /// Returns panel for hide object faces
138   XGUI_FacesPanel* facesPanel() const { return myFacesPanel; }
139
140   /// Returns context menu manager object
141   XGUI_ContextMenuMgr* contextMenuMgr() const { return myContextMenuMgr; }
142
143   /// Returns an object which provides interface to Salome Module (LightApp_Module)
144   XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; }
145
146   /// Provides an object which provides interface to Salome Viewer
147   ModuleBase_IViewer* salomeViewer() const;
148
149   /// Returns true if the application works as SALOME module
150   bool isSalomeMode() const { return mySalomeConnector != 0; }
151
152   /// Returns Object browser
153   XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; }
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 { return myViewerProxy; }
160
161   /// Returns the module connector
162   /// \returns the instance of connector
163   XGUI_ModuleConnector* moduleConnector() const { return myModuleConnector; }
164
165   /// Returns a desktop
166   /// \return a desktop instance
167   QMainWindow* desktop() const;
168
169   /// If faces panel made the object hidden, show message box whether the object should be
170   /// restored (removed from the panel) and displayed, if answer is No, returns false
171   /// \param theObject a model object
172   /// \return boolean state if the object should not be displayed
173   virtual bool prepareForDisplay(const std::set<ObjectPtr>& theObjects) 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   /// \param theActionName text of the checked action
197   /// \return boolean value
198   bool canChangeProperty(const QString& theActionName) const;
199
200   /// Change color of the results if it is possible
201   /// The operation is available for construction, body and group results
202   /// theObjects a list of selected objects
203   void changeColor(const QObjectPtrList& theObjects);
204
205   /// Change deflection of the results if it is possible
206   /// The operation is available for construction, body and group results
207   /// theObjects a list of selected objects
208   void changeDeflection(const QObjectPtrList& theObjects);
209
210   /// Change transparency of the results if it is possible
211   /// The operation is available for construction, body and group results
212   /// theObjects a list of selected objects
213   void changeTransparency(const QObjectPtrList& theObjects);
214
215   /// Show the given features in 3d Viewer
216   void showObjects(const QObjectPtrList& theList, bool isVisible);
217
218   /// Show the given features in 3d Viewer
219   void showOnlyObjects(const QObjectPtrList& theList);
220
221   /// Set display mode for the given objects
222   /// \param theList a list of displayed objects
223   /// \param theMode a mode to set (see \ref XGUI_Displayer)
224   void setDisplayMode(const QObjectPtrList& theList, int theMode);
225
226   /// Set selection mode in viewer. If theMode=-1 then activate default mode
227   /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
228   void setViewerSelectionMode(int theMode);
229
230   /// Activates current selection mode for the given list of objects
231   void activateObjectsSelection(const QObjectPtrList& theList);
232
233   /// Returns current module
234   ModuleBase_IModule* module() const { return myModule; }
235
236   /// Returns current file
237   QString currentDataFile() const { return myCurrentFile; }
238
239   /// Returns current file
240   void setCurrentDataFile(const QString& theDir) { myCurrentFile = theDir; }
241
242   /// Save the current document into a directory
243   /// \param theName - path to the directory
244   /// \param theFileNames - returned file names created in this directory
245   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
246
247   /// If there is an active (uncommitted) operation shows a prompt to abort it
248   /// and performs abortion if user agreed. Returns true if
249   /// - operation aborted successfully
250   /// - there is no active operation
251   bool abortAllOperations();
252
253   /// Updates workshop state according to the started operation, e.g. visualizes the property panel
254   /// and connect to it.
255   /// \param theOpertion a started operation
256   void operationStarted(ModuleBase_Operation* theOperation);
257
258   /// Delete features. Delete the referenced features. There can be a question with a list of
259   /// referenced objects.
260   /// \param theFeatures a list of objects to be deleted
261   bool deleteFeatures(const QObjectPtrList& theFeatures);
262
263   /// Deactivates the object, if it is active and the module returns that the activation
264   /// of selection for the object is not possible currently(the current operation uses it)
265   /// \param theObject an object
266   /// \param theUpdateViewer a boolean flag to update viewer immediately
267   void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
268
269   /// Returns true if the action of the feature is created to contain Accept/Cancel button
270   /// \param theFeature a feature
271   bool isFeatureOfNested(const FeaturePtr& theFeature);
272
273   /// Shows the message in the status bar
274   /// \param theMessage a message
275   void setStatusBarMessage(const QString& theMessage);
276
277 #ifdef HAVE_SALOME
278   /// Has to be called in order to display objects with visibility status = true
279   void synchronizeViewer();
280
281   /// Has to be called in order to display objects from a specifed group
282   /// with visibility status = true
283   /// \param theDoc the document for objects synchronisation
284   /// \param theGroup the group name
285   /// \param theUpdateViewer update viewer flag
286   void synchronizeGroupInViewer(const DocumentPtr& theDoc,
287                                 const std::string& theGroup,
288                                 bool theUpdateViewer);
289
290 #endif
291   /// Update the property panel content by the XML description of the operation and set the panel
292   /// into the operation
293   /// \param theOperation an operation
294   void fillPropertyPanel(ModuleBase_Operation* theOperation);
295
296   /// Connects or disconnects to the value changed signal of the property panel widgets
297   /// \param isToConnect a boolean value whether connect or disconnect
298   void connectToPropertyPanel(const bool isToConnect);
299
300   /// Returns defailt selection mode in 3d viewer
301   QIntList viewerSelectionModes() const { return myViewerSelMode; }
302
303   /// Highlights result objects in Object Browser according to
304   /// features found in the given list
305   void highlightResults(const QObjectPtrList& theObjects);
306
307   /// Highlights feature objects in Object Browser according to
308   /// features found in the given list
309   void highlightFeature(const QObjectPtrList& theObjects);
310
311   /// Returns Data Model XML reader which contains information about
312   /// Data structure configuration
313   const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
314
315   /// A constant string used for "Move to end" command definition
316   /// It is used for specific processing of Undo/Redo for this command.
317   static QString MOVE_TO_END_COMMAND;
318
319   /// Closes all in the current session and load the directory
320   /// \param theDirectory a path to directory
321   void openFile(const QString& theDirectory);
322
323   void updateAutoComputeState();
324
325 signals:
326   /// Emitted when selection happens in Salome viewer
327   void salomeViewerSelection();
328
329   /// the signal about the workshop actions states are updated.
330   void commandStatusUpdated();
331
332   /// the application is started
333   void applicationStarted();
334
335   /// Signal to update Undo history list
336   void updateUndoHistory(const QList<ActionInfo>&);
337
338   /// Signal to update Redo history list
339   void updateRedoHistory(const QList<ActionInfo>&);
340
341  public slots:
342    /// Update of commands status
343   void updateCommandStatus();
344
345   /// update history list (undo/redo commands)
346   void updateHistory();
347
348   /// Save current document
349   bool onSave();
350
351   /// Save current document to a file selected by user
352   bool onSaveAs();
353
354   /// Undo last command
355   void onUndo(int times = 1);
356
357   /// Redo previous command
358   void onRedo(int times = 1);
359
360   /// Validates the operation to change the "Apply" button state.
361   /// \param thePreviousState the previous state of the widget
362   void onWidgetStateChanged(int thePreviousState);
363
364   /// Calls activate of the current widget again. It is possible that selection filters are
365   /// differs in the new state of paged container
366   void onValuesChanged();
367
368   /// Listens the corresponded signal of model widget and updates Apply button state by feature
369   void onWidgetObjectUpdated();
370
371   /// Show dock widget panel
372   void showPanel(QDockWidget* theDockWidget);
373
374   /// Hide dock widget panel
375   void hidePanel(QDockWidget* theDockWidget);
376
377   /// Show object Browser
378   void showObjectBrowser();
379
380   /// Hide object Browser
381   void hideObjectBrowser();
382
383   /// Close document
384   void closeDocument();
385
386   /// Open document from file
387   void onOpen();
388
389   /// Create a new document
390   void onNew();
391
392 #ifndef HAVE_SALOME
393   /// Exit application
394   void onExit();
395
396   /// Open preferences dialog box
397   void onPreferences();
398 #endif
399
400   /// A slot calleon toggle of auto-compute button
401   void onAutoApply();
402
403   /// Activates/deactivates the trihedron in the viewer AIS context
404   void onTrihedronVisibilityChanged(bool theState);
405
406   /// Apply the current transparency value if preview in transparency dialog is switched on
407   void onTransparencyValueChanged();
408
409   /// Switch on/off preview of transparency change
410   void onPreviewStateChanged();
411
412  protected:
413   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
414   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
415   /// \param theOperation an operation
416    void setGrantedFeatures(ModuleBase_Operation* theOperation);
417
418 private:
419   /// Display results from document
420   /// \param theDoc a document
421   void displayDocumentResults(DocumentPtr theDoc);
422
423   /// Display results from a group
424   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
425
426   /// Insert folder object before currently selected feature
427   void insertFeatureFolder();
428
429   /// Insert an object to a folder above or below
430   void insertToFolder(bool isBefore);
431
432   /// Insert an object to a folder above or below
433   void moveOutFolder(bool isBefore);
434
435  private slots:
436   /// SLOT, that is called after the operation is resumed. Update workshop state according to
437   /// the started operation, e.g. visualizes the property panel and connect to it.
438   /// \param theOpertion a resumed operation
439   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
440
441   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
442   /// hides the property panel and update the command status.
443   /// \param theOpertion a stopped operation
444   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
445
446   /// SLOT, that is called after the operation is committed.
447   /// \param theOpertion a committed operation
448   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
449
450   /// SLOT, that is called after the operation is aborted.
451   /// \param theOpertion an aborted operation
452   void onOperationAborted(ModuleBase_Operation* theOperation);
453
454   /// Slot, which reacts to the context popup menu call
455   /// \param theId the data value of the clicked action
456   /// \param isChecked a state of toggle if the action is checkable
457   void onContextMenuCommand(const QString& theId, bool isChecked);
458
459   /// Set waiting cursor
460   void onStartWaiting();
461
462   /// Called by Ok button clicked in the property panel. Asks the error manager whether
463   /// the operation can be committed and do it if it returns true.
464   void onAcceptActionClicked();
465
466   /// Called by OkPlus button clicked in the property panel. Asks the error manager whether
467   /// the operation can be committed and do it if it returns true.
468   void onAcceptPlusActionClicked();
469
470   /// Called by Preview button clicked in the property panel. Sends signal to model to
471   /// compute preview.
472   void onPreviewActionClicked();
473
474   /// Called on help button clicked in the property panel.
475   void onHelpActionClicked();
476
477  private:
478   /// Init menu
479   void initMenu();
480
481   /// Register validators
482   void registerValidators() const;
483
484   /// Load module from external library
485   /// \param theModule name of the module
486   ModuleBase_IModule* loadModule(const QString& theModule);
487
488   /// Create module
489   bool createModule();
490
491   /// Create object browser widget
492   /// \param theParent a parent of widget
493   QDockWidget* createObjectBrowser(QWidget* theParent);
494
495   // Creates Dock widgets: Object browser and Property panel
496   void createDockWidgets();
497
498   /// Extends undo/redo toolbutton's with history menu
499   /// \param theObject - in the OpenParts it is a QToolButton by itself,
500   /// in salome mode - QAction that creates a button.
501   /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
502   /// \param theSlot - onUndo(int) or onRedo(int) SLOT
503   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
504
505   /// Creates list of actions (commands) by given history list from session
506   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
507
508   /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
509   /// \param theActionType a type of the action (Undo or Redo)
510   /// \param theTimes number of applies the given action
511   void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
512
513   /// Clear content of temporary directory
514   void clearTemporaryDir();
515
516 private:
517 #ifndef HAVE_SALOME
518   AppElements_MainWindow* myMainWindow; ///< desktop window
519 #endif
520
521   ModuleBase_IModule* myModule; ///< current module
522   XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
523   XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
524   XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
525   XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
526   XGUI_SelectionMgr* mySelector; ///< handler of selection processing
527   XGUI_SelectionActivate* mySelectionActivate; /// manager of selection activating
528   XGUI_Displayer* myDisplayer; ///< handler of objects display
529   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
530   XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
531   XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
532   XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
533   XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
534   XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
535   XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
536   XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
537   XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
538   XGUI_WorkshopListener* myEventsListener; ///< processing of events
539   QString myCurrentFile; ///< cached the last open directory
540   QIntList myViewerSelMode; ///< selection modes set in the viewer
541   Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
542   XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets
543   QTemporaryDir myTmpDir; ///< a direcory for uncompressed files
544 };
545
546 #endif