]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.h
Salome HOME
80aa6d2f8358d405b313f1a48f18a8b770feae1f
[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 class QMainWindow;
45
46 class ModelAPI_ObjectUpdatedMessage;
47 class ModelAPI_ObjectDeletedMessage;
48 class ModelAPI_ResultPart;
49 class QAction;
50
51 /**\class XGUI_Workshop
52  * \ingroup GUI
53  * \brief Class which defines a configuration of the application (Workshop) and launches it.
54  */
55 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
56 {
57 Q_OBJECT
58  public:
59   /// Constructor
60   /// \param theConnector a Salome connector object. 
61   /// Used only if the workshop is launched in Salome environment
62   XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
63   virtual ~XGUI_Workshop();
64
65   //! Starting of the application
66   void startApplication();
67
68   //! Returns main window (Desktop) of the application
69   AppElements_MainWindow* mainWindow() const
70   {
71     return myMainWindow;
72   }
73
74   //! Returns selection manager object
75   XGUI_SelectionMgr* selector() const
76   {
77     return mySelector;
78   }
79
80   //! Returns displayer
81   XGUI_Displayer* displayer() const
82   {
83     return myDisplayer;
84   }
85
86   //! ! Returns operation manager.
87   XGUI_OperationMgr* operationMgr() const
88   {
89     return myOperationMgr;
90   }
91
92   //! ! Returns an actions manager
93   XGUI_ActionsMgr* actionsMgr() const
94   {
95     return myActionsMgr;
96   }
97
98   //! Returns property panel widget
99   XGUI_PropertyPanel* propertyPanel() const
100   {
101     return myPropertyPanel;
102   }
103
104   //! Returns context menu manager object
105   XGUI_ContextMenuMgr* contextMenuMgr() const
106   {
107     return myContextMenuMgr;
108   }
109
110   //! Creates and adds a new workbench (menu group) with the given name and returns it
111   AppElements_Workbench* addWorkbench(const QString& theName);
112
113   //! Redefinition of Events_Listener method
114   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
115
116   //! Returns an object which provides interface to Salome Module (LightApp_Module)
117   XGUI_SalomeConnector* salomeConnector() const
118   {
119     return mySalomeConnector;
120   }
121
122   //! Provides an object which provides interface to Salome Viewer
123   ModuleBase_IViewer* salomeViewer() const;
124
125   //! Returns true if the application works as SALOME module
126   bool isSalomeMode() const
127   {
128     return mySalomeConnector != 0;
129   }
130
131   //! Returns Object browser
132   XGUI_ObjectsBrowser* objectBrowser() const
133   {
134     return myObjectBrowser;
135   }
136
137   /// This method is called by Salome module when selection is changed
138   void salomeViewerSelectionChanged();
139
140   /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
141   XGUI_ViewerProxy* viewer() const
142   {
143     return myViewerProxy;
144   }
145
146   /// Returns the module connectory
147   /// \returns the instance of connector
148   XGUI_ModuleConnector* moduleConnector() const
149   {
150     return myModuleConnector;
151   }
152
153   /// Returns a desktop
154   /// \return a desktop instance
155   QMainWindow* desktop() const;
156
157   //! Returns icon name according to feature
158   static QIcon featureIcon(const FeaturePtr& theFeature);
159
160   //! Activates or deactivates a part
161   //! If PartPtr is Null pointer then PartSet will be activated
162   void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
163
164   //! Delete features
165   void deleteObjects(const QObjectPtrList& theList);
166
167   //! Show the given features in 3d Viewer
168   void showObjects(const QObjectPtrList& theList, bool isVisible);
169
170   //! Show the given features in 3d Viewer
171   void showOnlyObjects(const QObjectPtrList& theList);
172
173   /// Set display mode for the given onjects
174   /// \param theList a list of displayed objects
175   /// \param theMode a mode to set (see \ref XGUI_Displayer)
176   void setDisplayMode(const QObjectPtrList& theList, int theMode);
177
178   /// Returns current module
179   ModuleBase_IModule* module() const
180   {
181     return myModule;
182   }
183
184   /// Returns current directory whic contains data files
185   QString currentDataDir() const { return myCurrentDir; }
186
187   /// Returns current directory whic contains data files
188   void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
189
190   /**
191   * Save the current document into a directory
192   * \param theName - path to the directory
193   * \param theFileNames - returned file names created in this directory
194   */
195   void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
196
197   /**
198    * If there is an active (uncommited) operation shows a prompt to abort it
199    * and performs abortion if user agreed. Returns true if
200    * - operation aborted successfully
201    * - there is no active operation
202    */
203   bool isActiveOperationAborted();
204
205 signals:
206   /// Emitted when selection happens in Salome viewer
207   void salomeViewerSelection();
208
209   /// Emitted when error in applivation happens
210   void errorOccurred(const QString&);
211
212   //! the signal about the workshop actions states are updated.
213   void commandStatusUpdated();
214
215   //! the application is started
216   void applicationStarted();
217
218  public slots:
219    /// Update of commands status
220   void updateCommandStatus();
221
222   /// Create a new dokument
223   void onNew();
224
225   /// Open document from file
226   void onOpen();
227
228   /// Save current document
229   bool onSave();
230
231   /// Save current document to a file selected by user
232   bool onSaveAs();
233
234   /// Exit application
235   void onExit();
236
237   /// Undo last command
238   void onUndo();
239
240   /// Redo previous command
241   void onRedo();
242
243   /// Rebuild data tree
244   void onRebuild();
245
246   /// Open preferences dialog box
247   void onPreferences();
248
249   /// Show property panel
250   void showPropertyPanel();
251
252   /// Hide property panel
253   void hidePropertyPanel();
254
255   /// Show object Browser
256   void showObjectBrowser();
257
258   /// Hide object Browser
259   void hideObjectBrowser();
260
261   /// Reaction on command call
262   void onFeatureTriggered();
263
264   /// Change active document
265   /// \param theObj a part object. If it is NULL then active document is a main document
266   void changeCurrentDocument(ObjectPtr theObj);
267
268   //void activateLastPart();
269
270   /// Close document
271   void closeDocument();
272
273  protected:
274   /// Find the nested features and set them into the operation
275   /// \param theOperation an operation
276   void setNestedFeatures(ModuleBase_Operation* theOperation);
277
278   /// Update the property panel content by the XML description of the operation and set the panel
279   /// into the operation
280   /// \param theOperation an operation
281   void setPropertyPanel(ModuleBase_Operation* theOperation);
282
283   /// Procedure to process postponed events
284   bool event(QEvent * theEvent);
285
286   //Event-loop processing methods:
287
288   /// Process event "Add a feature"
289   void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
290
291   /// Connect to operation signals
292   /// \param theOperation an operation
293   void connectWithOperation(ModuleBase_Operation* theOperation);
294
295   /// Process feature update message
296   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
297
298   ///Process feature created message
299   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
300
301   /// Process feature redisplay message
302   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
303
304   /// Process feature delete message
305   void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
306
307   /// Display all results
308   void displayAllResults();
309
310   /// Displau results from document
311   /// \param theDoc a document
312   void displayDocumentResults(DocumentPtr theDoc);
313
314   /// Display results from a group
315   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
316
317  private slots:
318   /// SLOT, that is called after the operation is started. Update workshop state according to
319   /// the started operation, e.g. visualizes the property panel and connect to it.
320   /// \param theOpertion a started operation
321   void onOperationStarted(ModuleBase_Operation* theOperation);
322
323   /// SLOT, that is called after the operation is resumed. Update workshop state according to
324   /// the started operation, e.g. visualizes the property panel and connect to it.
325   /// \param theOpertion a resumed operation
326   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
327
328   /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
329   /// hides the property panel and udpate the command status.
330   /// \param theOpertion a stopped operation
331   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
332
333   /// SLOT, that is called after the operation is committed.
334   /// \param theOpertion a commmitted operation
335   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
336
337   /// SLOT, that is called after the operation is aborted.
338   /// \param theOpertion an aborted operation
339   void onOperationAborted(ModuleBase_Operation* theOperation);
340
341   /// Slot, which reacts to the context popup menu call
342   /// \param theId the data value of the clicked action
343   /// \param isChecked a state of toggle if the action is checkable
344   void onContextMenuCommand(const QString& theId, bool isChecked);
345
346   /// Processing of values changed in model widget
347   void onWidgetValuesChanged();
348
349   /// Set waiting cursor
350   void onStartWaiting();
351
352  private:
353    /// Init menu
354   void initMenu();
355
356   /// Register validators
357   void registerValidators() const;
358
359   /// Load module from external library
360   /// \param theModule name of the module
361   ModuleBase_IModule* loadModule(const QString& theModule);
362
363   /// Activate module
364   bool activateModule();
365
366   /// Create object browser widget
367   /// \param theParent a parent of widget
368   QDockWidget* createObjectBrowser(QWidget* theParent);
369
370   /// Create property panel widget
371   /// \param theParent a parent of widget
372   QDockWidget* createPropertyPanel(QWidget* theParent);
373
374   // Creates Dock widgets: Object browser and Property panel
375   void createDockWidgets();
376
377   /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
378   void displayObject(ObjectPtr theObj);
379
380 private:
381   AppElements_MainWindow* myMainWindow;
382   ModuleBase_IModule* myModule;
383   XGUI_ObjectsBrowser* myObjectBrowser;
384   XGUI_PropertyPanel* myPropertyPanel;
385   XGUI_SelectionMgr* mySelector;
386   XGUI_Displayer* myDisplayer;
387   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
388   XGUI_ActionsMgr* myActionsMgr;
389   XGUI_SalomeConnector* mySalomeConnector;
390   XGUI_ErrorDialog* myErrorDlg;
391   XGUI_ViewerProxy* myViewerProxy;
392   XGUI_ContextMenuMgr* myContextMenuMgr;
393   XGUI_ModuleConnector* myModuleConnector;
394
395   QString myCurrentDir;
396   static QMap<QString, QString> myIcons;
397
398   bool myUpdatePrefs;
399
400   // Flag to check that part document is in process of activating
401   bool myPartActivating;
402 };
403
404 #endif