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