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