Salome HOME
Create help management system
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_WORKSHOP_H
22 #define XGUI_WORKSHOP_H
23
24 #include "XGUI.h"
25
26 #include <ModelAPI_Document.h>
27 #include <ModelAPI_Feature.h>
28
29 #include <ModuleBase_ActionInfo.h>
30 #include <ModuleBase_ActionType.h>
31 #include <ModuleBase_Definitions.h>
32
33 #include <SelectMgr_ListOfFilter.hxx>
34
35 #include <QIcon>
36 #include <QObject>
37 #include <QKeySequence>
38 #include <QMap>
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 directory which contains data files
237   QString currentDataDir() const { return myCurrentDir; }
238
239   /// Returns current directory which contains data files
240   void setCurrentDataDir(const QString& theDir) { myCurrentDir = 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 openDirectory(const QString& theDirectory);
322
323 signals:
324   /// Emitted when selection happens in Salome viewer
325   void salomeViewerSelection();
326
327   /// the signal about the workshop actions states are updated.
328   void commandStatusUpdated();
329
330   /// the application is started
331   void applicationStarted();
332
333   /// Signal to update Undo history list
334   void updateUndoHistory(const QList<ActionInfo>&);
335
336   /// Signal to update Redo history list
337   void updateRedoHistory(const QList<ActionInfo>&);
338
339  public slots:
340    /// Update of commands status
341   void updateCommandStatus();
342
343   /// update history list (undo/redo commands)
344   void updateHistory();
345
346   /// Save current document
347   bool onSave();
348
349   /// Save current document to a file selected by user
350   bool onSaveAs();
351
352   /// Undo last command
353   void onUndo(int times = 1);
354
355   /// Redo previous command
356   void onRedo(int times = 1);
357
358   /// Validates the operation to change the "Apply" button state.
359   /// \param thePreviousState the previous state of the widget
360   void onWidgetStateChanged(int thePreviousState);
361
362   /// Calls activate of the current widget again. It is possible that selection filters are
363   /// differs in the new state of paged container
364   void onValuesChanged();
365
366   /// Listens the corresponded signal of model widget and updates Apply button state by feature
367   void onWidgetObjectUpdated();
368
369   /// Show dock widget panel
370   void showPanel(QDockWidget* theDockWidget);
371
372   /// Hide dock widget panel
373   void hidePanel(QDockWidget* theDockWidget);
374
375   /// Show object Browser
376   void showObjectBrowser();
377
378   /// Hide object Browser
379   void hideObjectBrowser();
380
381   /// Close document
382   void closeDocument();
383
384   /// Open document from file
385   void onOpen();
386
387   /// Create a new document
388   void onNew();
389
390 #ifndef HAVE_SALOME
391   /// Exit application
392   void onExit();
393
394   /// Open preferences dialog box
395   void onPreferences();
396 #endif
397
398   /// Activates/deactivates the trihedron in the viewer AIS context
399   void onTrihedronVisibilityChanged(bool theState);
400
401   /// Apply the current transparency value if preview in transparency dialog is switched on
402   void onTransparencyValueChanged();
403
404   /// Switch on/off preview of transparency change
405   void onPreviewStateChanged();
406
407  protected:
408   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
409   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
410   /// \param theOperation an operation
411    void setGrantedFeatures(ModuleBase_Operation* theOperation);
412
413 private:
414   /// Display results from document
415   /// \param theDoc a document
416   void displayDocumentResults(DocumentPtr theDoc);
417
418   /// Display results from a group
419   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
420
421   /// Insert folder object before currently selected feature
422   void insertFeatureFolder();
423
424   /// Insert an object to a folder above or below
425   void insertToFolder(bool isBefore);
426
427   /// Insert an object to a folder above or below
428   void moveOutFolder(bool isBefore);
429
430  private slots:
431   /// SLOT, that is called after the operation is resumed. Update workshop state according to
432   /// the started operation, e.g. visualizes the property panel and connect to it.
433   /// \param theOpertion a resumed operation
434   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
435
436   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
437   /// hides the property panel and update the command status.
438   /// \param theOpertion a stopped operation
439   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
440
441   /// SLOT, that is called after the operation is committed.
442   /// \param theOpertion a committed operation
443   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
444
445   /// SLOT, that is called after the operation is aborted.
446   /// \param theOpertion an aborted operation
447   void onOperationAborted(ModuleBase_Operation* theOperation);
448
449   /// Slot, which reacts to the context popup menu call
450   /// \param theId the data value of the clicked action
451   /// \param isChecked a state of toggle if the action is checkable
452   void onContextMenuCommand(const QString& theId, bool isChecked);
453
454   /// Set waiting cursor
455   void onStartWaiting();
456
457   /// Called by Ok button clicked in the property panel. Asks the error manager whether
458   /// the operation can be committed and do it if it returns true.
459   void onAcceptActionClicked();
460
461   /// Called by OkPlus button clicked in the property panel. Asks the error manager whether
462   /// the operation can be committed and do it if it returns true.
463   void onAcceptPlusActionClicked();
464
465   /// Called by Preview button clicked in the property panel. Sends signal to model to
466   /// compute preview.
467   void onPreviewActionClicked();
468
469   /// Called on help button clicked in the property panel.
470   void onHelpActionClicked();
471
472  private:
473   /// Init menu
474   void initMenu();
475
476   /// Register validators
477   void registerValidators() const;
478
479   /// Load module from external library
480   /// \param theModule name of the module
481   ModuleBase_IModule* loadModule(const QString& theModule);
482
483   /// Create module
484   bool createModule();
485
486   /// Create object browser widget
487   /// \param theParent a parent of widget
488   QDockWidget* createObjectBrowser(QWidget* theParent);
489
490   // Creates Dock widgets: Object browser and Property panel
491   void createDockWidgets();
492
493   /// Extends undo/redo toolbutton's with history menu
494   /// \param theObject - in the OpenParts it is a QToolButton by itself,
495   /// in salome mode - QAction that creates a button.
496   /// \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
497   /// \param theSlot - onUndo(int) or onRedo(int) SLOT
498   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
499
500   /// Creates list of actions (commands) by given history list from session
501   QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
502
503   /// Pefrom Undo/Redo and necessary workshop updates(viewer, browser, actions state)
504   /// \param theActionType a type of the action (Undo or Redo)
505   /// \param theTimes number of applies the given action
506   void processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes);
507
508 private:
509 #ifndef HAVE_SALOME
510   AppElements_MainWindow* myMainWindow; ///< desktop window
511 #endif
512
513   ModuleBase_IModule* myModule; ///< current module
514   XGUI_ErrorMgr* myErrorMgr; ///< updator of error message
515   XGUI_ObjectsBrowser* myObjectBrowser; ///< data tree widget
516   XGUI_PropertyPanel* myPropertyPanel; ///< container of feature attributes widgets
517   XGUI_FacesPanel* myFacesPanel; ///< panel for hide object faces
518   XGUI_SelectionMgr* mySelector; ///< handler of selection processing
519   XGUI_SelectionActivate* mySelectionActivate; /// manager of selection activating
520   XGUI_Displayer* myDisplayer; ///< handler of objects display
521   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
522   XGUI_ActionsMgr* myActionsMgr; ///< manager of workshop actions
523   XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
524   XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
525   XGUI_SalomeConnector* mySalomeConnector; ///< connector to SALOME module interface
526   XGUI_ErrorDialog* myErrorDlg; ///< dialog to show information of occured error events
527   XGUI_ViewerProxy* myViewerProxy; ///< connector to SALOME viewer interface
528   XGUI_ContextMenuMgr* myContextMenuMgr; ///< manager of context menu build
529   XGUI_ModuleConnector* myModuleConnector; ///< implementation of ModuleBase_IWorkshop
530   XGUI_WorkshopListener* myEventsListener; ///< processing of events
531   QString myCurrentDir; ///< cached the last open directory
532   QIntList myViewerSelMode; ///< selection modes set in the viewer
533   Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
534   XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets
535 };
536
537 #endif