Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
[modules/shaper.git] / src / XGUI / XGUI_Workshop.h
1 #ifndef XGUI_WORKSHOP_H
2 #define XGUI_WORKSHOP_H
3
4 #include "XGUI.h"
5 #include "XGUI_Constants.h"
6 #include <Events_Listener.h>
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_Document.h>
9 #include <ModelAPI_Feature.h>
10
11 #include <QObject>
12 #include <QMap>
13 #include <QKeySequence>
14 #include <QIcon>
15
16 class XGUI_MainWindow;
17 class XGUI_Command;
18 class XGUI_Workbench;
19 class XGUI_SelectionMgr;
20 class XGUI_Displayer;
21 class XGUI_OperationMgr;
22 class XGUI_SalomeConnector;
23 class XGUI_ObjectsBrowser;
24 class XGUI_ActionsMgr;
25 class XGUI_ErrorDialog;
26 class XGUI_SalomeViewer;
27 class XGUI_ViewerProxy;
28 class XGUI_PropertyPanel;
29 class XGUI_ContextMenuMgr;
30 class XGUI_ModuleConnector;
31
32 class ModuleBase_Operation;
33 class ModuleBase_IModule;
34 class ModuleBase_IViewer;
35
36 class Config_FeatureMessage;
37 class Config_PointerMessage;
38
39 class QWidget;
40 class QDockWidget;
41
42 class ModelAPI_ObjectUpdatedMessage;
43 class ModelAPI_ObjectDeletedMessage;
44 class ModelAPI_ResultPart;
45 class QAction;
46
47 /**\class XGUI_Workshop
48  * \ingroup GUI
49  * \brief Class which defines a configuration of the application (Workshop) and launches it.
50  */
51 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
52 {
53 Q_OBJECT
54  public:
55
56   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
57   virtual ~XGUI_Workshop();
58
59   //! Starting of the application
60   void startApplication();
61
62   //! Returns main window (Desktop) of the application
63   XGUI_MainWindow* mainWindow() const
64   {
65     return myMainWindow;
66   }
67
68   //! Returns selection manager object
69   XGUI_SelectionMgr* selector() const
70   {
71     return mySelector;
72   }
73
74   //! Returns displayer
75   XGUI_Displayer* displayer() const
76   {
77     return myDisplayer;
78   }
79
80   //! ! Returns operation manager.
81   XGUI_OperationMgr* operationMgr() const
82   {
83     return myOperationMgr;
84   }
85
86   //! ! Returns an actions manager
87   XGUI_ActionsMgr* actionsMgr() const
88   {
89     return myActionsMgr;
90   }
91   ;
92
93   //! Returns property panel widget
94   XGUI_PropertyPanel* propertyPanel() const
95   {
96     return myPropertyPanel;
97   }
98
99   //! Returns context menu manager object
100   XGUI_ContextMenuMgr* contextMenuMgr() const
101   {
102     return myContextMenuMgr;
103   }
104
105   //! Creates and adds a new workbench (menu group) with the given name and returns it
106   XGUI_Workbench* addWorkbench(const QString& theName);
107
108   //! Redefinition of Events_Listener method
109   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
110
111   //! Returns an object which provides interface to Salome Module (LightApp_Module)
112   XGUI_SalomeConnector* salomeConnector() const
113   {
114     return mySalomeConnector;
115   }
116
117   //! Provides an object which provides interface to Salome Viewer
118   ModuleBase_IViewer* salomeViewer() const;
119
120   //! Returns true if the application works as SALOME module
121   bool isSalomeMode() const
122   {
123     return mySalomeConnector != 0;
124   }
125
126   //! Returns Object browser
127   XGUI_ObjectsBrowser* objectBrowser() const
128   {
129     return myObjectBrowser;
130   }
131
132   void salomeViewerSelectionChanged();
133
134   XGUI_ViewerProxy* viewer() const
135   {
136     return myViewerProxy;
137   }
138
139   /// Returns the module connectory
140   /// \returns the instance of connector
141   XGUI_ModuleConnector* moduleConnector() const
142   {
143     return myModuleConnector;
144   }
145
146   //! Returns icon name according to feature
147   static QIcon featureIcon(const FeaturePtr& theFeature);
148
149   //! Returns icon name according to feature
150   static std::string featureIconStr(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   bool event(QEvent * theEvent);
225   //Event-loop processing methods:
226   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
227   void connectWithOperation(ModuleBase_Operation* theOperation);
228
229   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
230   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
231   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
232   void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
233
234   void validateOperation(const QString& theOperationId);
235
236   QList<QAction*> getModuleCommands() const;
237
238   void displayAllResults();
239   void displayDocumentResults(DocumentPtr theDoc);
240   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
241
242  private slots:
243   /// SLOT, that is called after the operation is started. Update workshop state according to
244   /// the started operation, e.g. visualizes the property panel and connect to it.
245   void onOperationStarted();
246
247   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
248   /// hides the property panel and udpate the command status.
249   /// \param theOpertion a stopped operation
250   void onOperationStopped(ModuleBase_Operation* theOperation);
251
252   void onContextMenuCommand(const QString& theId, bool isChecked);
253
254   void onWidgetValuesChanged();
255
256   void onStartWaiting();
257
258  private:
259   void initMenu();
260
261   void registerValidators() const;
262
263   ModuleBase_IModule* loadModule(const QString& theModule);
264   bool activateModule();
265
266   QDockWidget* createObjectBrowser(QWidget* theParent);
267   QDockWidget* createPropertyPanel(QWidget* theParent);
268
269   // Creates Dock widgets: Object browser and Property panel
270   void createDockWidgets();
271
272   XGUI_MainWindow* myMainWindow;
273   ModuleBase_IModule* myModule;
274   XGUI_ObjectsBrowser* myObjectBrowser;
275   XGUI_PropertyPanel* myPropertyPanel;
276   XGUI_SelectionMgr* mySelector;
277   XGUI_Displayer* myDisplayer;
278   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
279   XGUI_ActionsMgr* myActionsMgr;
280   XGUI_SalomeConnector* mySalomeConnector;
281   XGUI_ErrorDialog* myErrorDlg;
282   XGUI_ViewerProxy* myViewerProxy;
283   XGUI_ContextMenuMgr* myContextMenuMgr;
284   XGUI_ModuleConnector* myModuleConnector;
285
286   QString myCurrentDir;
287   static QMap<QString, QString> myIcons;
288
289   bool myUpdatePrefs;
290
291   // Flag to check that part document is in process of activating
292   bool myPartActivating;
293 };
294
295 #endif