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