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