Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[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 <Events_Listener.h>
9 #include <ModuleBase_Definitions.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Feature.h>
12
13 #include <QObject>
14 #include <QMap>
15 #include <QKeySequence>
16 #include <QIcon>
17
18 class AppElements_MainWindow;
19 class AppElements_Command;
20 class AppElements_Workbench;
21
22 class XGUI_SelectionMgr;
23 class XGUI_Displayer;
24 class XGUI_OperationMgr;
25 class XGUI_SalomeConnector;
26 class XGUI_ObjectsBrowser;
27 class XGUI_ActionsMgr;
28 class XGUI_ErrorDialog;
29 class XGUI_SalomeViewer;
30 class XGUI_ViewerProxy;
31 class XGUI_PropertyPanel;
32 class XGUI_ContextMenuMgr;
33 class XGUI_ModuleConnector;
34
35 class ModuleBase_Operation;
36 class ModuleBase_IModule;
37 class ModuleBase_IViewer;
38
39 class Config_FeatureMessage;
40 class Config_PointerMessage;
41
42 class QWidget;
43 class QDockWidget;
44
45 class ModelAPI_ObjectUpdatedMessage;
46 class ModelAPI_ObjectDeletedMessage;
47 class ModelAPI_ResultPart;
48 class QAction;
49
50 /**\class XGUI_Workshop
51  * \ingroup GUI
52  * \brief Class which defines a configuration of the application (Workshop) and launches it.
53  */
54 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
55 {
56 Q_OBJECT
57  public:
58
59   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
60   virtual ~XGUI_Workshop();
61
62   //! Starting of the application
63   void startApplication();
64
65   //! Returns main window (Desktop) of the application
66   AppElements_MainWindow* mainWindow() const
67   {
68     return myMainWindow;
69   }
70
71   //! Returns selection manager object
72   XGUI_SelectionMgr* selector() const
73   {
74     return mySelector;
75   }
76
77   //! Returns displayer
78   XGUI_Displayer* displayer() const
79   {
80     return myDisplayer;
81   }
82
83   //! ! Returns operation manager.
84   XGUI_OperationMgr* operationMgr() const
85   {
86     return myOperationMgr;
87   }
88
89   //! ! Returns an actions manager
90   XGUI_ActionsMgr* actionsMgr() const
91   {
92     return myActionsMgr;
93   }
94   ;
95
96   //! Returns property panel widget
97   XGUI_PropertyPanel* propertyPanel() const
98   {
99     return myPropertyPanel;
100   }
101
102   //! Returns context menu manager object
103   XGUI_ContextMenuMgr* contextMenuMgr() const
104   {
105     return myContextMenuMgr;
106   }
107
108   //! Creates and adds a new workbench (menu group) with the given name and returns it
109   AppElements_Workbench* addWorkbench(const QString& theName);
110
111   //! Redefinition of Events_Listener method
112   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
113
114   //! Returns an object which provides interface to Salome Module (LightApp_Module)
115   XGUI_SalomeConnector* salomeConnector() const
116   {
117     return mySalomeConnector;
118   }
119
120   //! Provides an object which provides interface to Salome Viewer
121   ModuleBase_IViewer* salomeViewer() const;
122
123   //! Returns true if the application works as SALOME module
124   bool isSalomeMode() const
125   {
126     return mySalomeConnector != 0;
127   }
128
129   //! Returns Object browser
130   XGUI_ObjectsBrowser* objectBrowser() const
131   {
132     return myObjectBrowser;
133   }
134
135   void salomeViewerSelectionChanged();
136
137   XGUI_ViewerProxy* viewer() const
138   {
139     return myViewerProxy;
140   }
141
142   /// Returns the module connectory
143   /// \returns the instance of connector
144   XGUI_ModuleConnector* moduleConnector() const
145   {
146     return myModuleConnector;
147   }
148
149   //! Returns icon name according to feature
150   static QIcon featureIcon(const FeaturePtr& theFeature);
151
152   //! Activates or deactivates a part
153   //! If PartPtr is Null pointer then PartSet will be activated
154   void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
155
156   //! Delete features
157   void deleteObjects(const QObjectPtrList& theList);
158
159   //! Show the given features in 3d Viewer
160   void showObjects(const QObjectPtrList& theList, bool isVisible);
161
162   //! Show the given features in 3d Viewer
163   void showOnlyObjects(const QObjectPtrList& theList);
164
165   void setDisplayMode(const QObjectPtrList& theList, int theMode);
166
167   ModuleBase_IModule* module() const
168   {
169     return myModule;
170   }
171
172   /// Returns current directory whic contains data files
173   QString currentDataDir() const { return myCurrentDir; }
174
175   /// Returns current directory whic contains data files
176   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
177
178   /**
179   * Save the current document into a directory
180   * \param theName - path to the directory
181   * \param theFileNames - returned file names created in this directory
182   */
183   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
184
185   /*
186    * If there is an active (uncommited) operation shows a prompt to abort it
187    * and performs abortion if user agreed. Returns true if
188    * - operation aborted successfully
189    * - there is no active operation
190    */
191   bool isActiveOperationAborted();
192
193 signals:
194   void salomeViewerSelection();
195   void errorOccurred(const QString&);
196
197  public slots:
198   void updateCommandStatus();
199   void updateCommandsOnViewSelection();
200
201   void onNew();
202   void onOpen();
203   bool onSave();
204   bool onSaveAs();
205   void onExit();
206   void onUndo();
207   void onRedo();
208   void onRebuild();
209   void onPreferences();
210
211   void showPropertyPanel();
212   void hidePropertyPanel();
213   void showObjectBrowser();
214   void hideObjectBrowser();
215
216   void onFeatureTriggered();
217   void changeCurrentDocument(ObjectPtr theObj);
218
219   void activateLastPart();
220
221   void closeDocument();
222
223  protected:
224   // Find the nested features and set them into the operation
225   // \param theOperation an operation
226   void setNestedFeatures(ModuleBase_Operation* theOperation);
227   // Update the property panel content by the XML description of the operation and set the panel
228   // into the operation
229   // \param theOperation an operation
230   void setPropertyPanel(ModuleBase_Operation* theOperation);
231
232   bool event(QEvent * theEvent);
233   //Event-loop processing methods:
234   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
235   void connectWithOperation(ModuleBase_Operation* theOperation);
236
237   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
238   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
239   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
240   void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
241
242   void validateOperation(const QString& theOperationId);
243
244   QList<QAction*> getModuleCommands() const;
245
246   void displayAllResults();
247   void displayDocumentResults(DocumentPtr theDoc);
248   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
249
250  private slots:
251   /// SLOT, that is called after the operation is started. Update workshop state according to
252   /// the started operation, e.g. visualizes the property panel and connect to it.
253   /// \param theOpertion a started operation
254   void onOperationStarted(ModuleBase_Operation* theOperation);
255
256   /// SLOT, that is called after the operation is resumed. Update workshop state according to
257   /// the started operation, e.g. visualizes the property panel and connect to it.
258   /// \param theOpertion a resumed operation
259   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
260
261   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
262   /// hides the property panel and udpate the command status.
263   /// \param theOpertion a stopped operation
264   void onOperationStopped(ModuleBase_Operation* theOperation);
265
266   void onContextMenuCommand(const QString& theId, bool isChecked);
267
268   void onWidgetValuesChanged();
269
270   void onStartWaiting();
271
272  private:
273   void initMenu();
274
275   void registerValidators() const;
276
277   ModuleBase_IModule* loadModule(const QString& theModule);
278   bool activateModule();
279
280   QDockWidget* createObjectBrowser(QWidget* theParent);
281   QDockWidget* createPropertyPanel(QWidget* theParent);
282
283   // Creates Dock widgets: Object browser and Property panel
284   void createDockWidgets();
285
286   AppElements_MainWindow* myMainWindow;
287   ModuleBase_IModule* myModule;
288   XGUI_ObjectsBrowser* myObjectBrowser;
289   XGUI_PropertyPanel* myPropertyPanel;
290   XGUI_SelectionMgr* mySelector;
291   XGUI_Displayer* myDisplayer;
292   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
293   XGUI_ActionsMgr* myActionsMgr;
294   XGUI_SalomeConnector* mySalomeConnector;
295   XGUI_ErrorDialog* myErrorDlg;
296   XGUI_ViewerProxy* myViewerProxy;
297   XGUI_ContextMenuMgr* myContextMenuMgr;
298   XGUI_ModuleConnector* myModuleConnector;
299
300   QString myCurrentDir;
301   static QMap<QString, QString> myIcons;
302
303   bool myUpdatePrefs;
304
305   // Flag to check that part document is in process of activating
306   bool myPartActivating;
307 };
308
309 #endif