1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef XGUI_WORKSHOP_H
4 #define XGUI_WORKSHOP_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>
15 #include <QKeySequence>
18 class AppElements_MainWindow;
19 class AppElements_Command;
20 class AppElements_Workbench;
22 class XGUI_SelectionMgr;
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;
35 class ModuleBase_Operation;
36 class ModuleBase_IModule;
37 class ModuleBase_IViewer;
39 class Config_FeatureMessage;
40 class Config_PointerMessage;
46 class ModelAPI_ObjectUpdatedMessage;
47 class ModelAPI_ObjectDeletedMessage;
48 class ModelAPI_ResultPart;
51 /**\class XGUI_Workshop
53 * \brief Class which defines a configuration of the application (Workshop) and launches it.
55 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
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();
65 //! Starting of the application
66 void startApplication();
68 //! Returns main window (Desktop) of the application
69 AppElements_MainWindow* mainWindow() const
74 //! Returns selection manager object
75 XGUI_SelectionMgr* selector() const
81 XGUI_Displayer* displayer() const
86 //! ! Returns operation manager.
87 XGUI_OperationMgr* operationMgr() const
89 return myOperationMgr;
92 //! ! Returns an actions manager
93 XGUI_ActionsMgr* actionsMgr() const
98 //! Returns property panel widget
99 XGUI_PropertyPanel* propertyPanel() const
101 return myPropertyPanel;
104 //! Returns context menu manager object
105 XGUI_ContextMenuMgr* contextMenuMgr() const
107 return myContextMenuMgr;
110 //! Creates and adds a new workbench (menu group) with the given name and returns it
111 AppElements_Workbench* addWorkbench(const QString& theName);
113 //! Redefinition of Events_Listener method
114 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
116 //! Returns an object which provides interface to Salome Module (LightApp_Module)
117 XGUI_SalomeConnector* salomeConnector() const
119 return mySalomeConnector;
122 //! Provides an object which provides interface to Salome Viewer
123 ModuleBase_IViewer* salomeViewer() const;
125 //! Returns true if the application works as SALOME module
126 bool isSalomeMode() const
128 return mySalomeConnector != 0;
131 //! Returns Object browser
132 XGUI_ObjectsBrowser* objectBrowser() const
134 return myObjectBrowser;
137 /// This method is called by Salome module when selection is changed
138 void salomeViewerSelectionChanged();
140 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
141 XGUI_ViewerProxy* viewer() const
143 return myViewerProxy;
146 /// Returns the module connectory
147 /// \returns the instance of connector
148 XGUI_ModuleConnector* moduleConnector() const
150 return myModuleConnector;
153 /// Returns a desktop
154 /// \return a desktop instance
155 QMainWindow* desktop() const;
157 //! Returns icon name according to feature
158 static QIcon featureIcon(const FeaturePtr& theFeature);
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);
165 void deleteObjects(const QObjectPtrList& theList);
167 //! Show the given features in 3d Viewer
168 void showObjects(const QObjectPtrList& theList, bool isVisible);
170 //! Show the given features in 3d Viewer
171 void showOnlyObjects(const QObjectPtrList& theList);
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);
178 /// Returns current module
179 ModuleBase_IModule* module() const
184 /// Returns current directory whic contains data files
185 QString currentDataDir() const { return myCurrentDir; }
187 /// Returns current directory whic contains data files
188 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
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
195 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
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
203 bool isActiveOperationAborted();
206 /// Emitted when selection happens in Salome viewer
207 void salomeViewerSelection();
209 /// Emitted when error in applivation happens
210 void errorOccurred(const QString&);
212 //! the signal about the workshop actions states are updated.
213 void commandStatusUpdated();
215 //! the application is started
216 void applicationStarted();
218 void updateUndoHistory(const QList<QAction*>&);
219 void updateRedoHistory(const QList<QAction*>&);
222 /// Update of commands status
223 void updateCommandStatus();
225 /// update history list (undo/redo commands)
226 void updateHistory();
228 /// Create a new dokument
231 /// Open document from file
234 /// Save current document
237 /// Save current document to a file selected by user
243 /// Undo last command
244 void onUndo(int times = 1);
246 /// Redo previous command
247 void onRedo(int times = 1);
249 /// Rebuild data tree
252 /// Open preferences dialog box
253 void onPreferences();
255 /// Show property panel
256 void showPropertyPanel();
258 /// Hide property panel
259 void hidePropertyPanel();
261 /// Show object Browser
262 void showObjectBrowser();
264 /// Hide object Browser
265 void hideObjectBrowser();
267 /// Reaction on command call
268 void onFeatureTriggered();
270 /// Change active document
271 /// \param theObj a part object. If it is NULL then active document is a main document
272 void changeCurrentDocument(ObjectPtr theObj);
274 //void activateLastPart();
277 void closeDocument();
280 /// Find the nested features and set them into the operation
281 /// \param theOperation an operation
282 void setNestedFeatures(ModuleBase_Operation* theOperation);
284 /// Update the property panel content by the XML description of the operation and set the panel
285 /// into the operation
286 /// \param theOperation an operation
287 void setPropertyPanel(ModuleBase_Operation* theOperation);
289 /// Procedure to process postponed events
290 bool event(QEvent * theEvent);
292 //Event-loop processing methods:
294 /// Process event "Add a feature"
295 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
297 /// Connect to operation signals
298 /// \param theOperation an operation
299 void connectWithOperation(ModuleBase_Operation* theOperation);
301 /// Process feature update message
302 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
304 ///Process feature created message
305 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
307 /// Process feature redisplay message
308 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
310 /// Process feature delete message
311 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
313 /// Display all results
314 void displayAllResults();
316 /// Displau results from document
317 /// \param theDoc a document
318 void displayDocumentResults(DocumentPtr theDoc);
320 /// Display results from a group
321 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
324 /// SLOT, that is called after the operation is started. Update workshop state according to
325 /// the started operation, e.g. visualizes the property panel and connect to it.
326 /// \param theOpertion a started operation
327 void onOperationStarted(ModuleBase_Operation* theOperation);
329 /// SLOT, that is called after the operation is resumed. Update workshop state according to
330 /// the started operation, e.g. visualizes the property panel and connect to it.
331 /// \param theOpertion a resumed operation
332 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
334 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
335 /// hides the property panel and udpate the command status.
336 /// \param theOpertion a stopped operation
337 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
339 /// SLOT, that is called after the operation is committed.
340 /// \param theOpertion a commmitted operation
341 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
343 /// SLOT, that is called after the operation is aborted.
344 /// \param theOpertion an aborted operation
345 void onOperationAborted(ModuleBase_Operation* theOperation);
347 /// Slot, which reacts to the context popup menu call
348 /// \param theId the data value of the clicked action
349 /// \param isChecked a state of toggle if the action is checkable
350 void onContextMenuCommand(const QString& theId, bool isChecked);
352 /// Processing of values changed in model widget
353 void onWidgetValuesChanged();
355 /// Set waiting cursor
356 void onStartWaiting();
362 /// Register validators
363 void registerValidators() const;
365 /// Load module from external library
366 /// \param theModule name of the module
367 ModuleBase_IModule* loadModule(const QString& theModule);
370 bool activateModule();
372 /// Create object browser widget
373 /// \param theParent a parent of widget
374 QDockWidget* createObjectBrowser(QWidget* theParent);
376 /// Create property panel widget
377 /// \param theParent a parent of widget
378 QDockWidget* createPropertyPanel(QWidget* theParent);
380 // Creates Dock widgets: Object browser and Property panel
381 void createDockWidgets();
383 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
384 void displayObject(ObjectPtr theObj);
387 AppElements_MainWindow* myMainWindow;
388 ModuleBase_IModule* myModule;
389 XGUI_ObjectsBrowser* myObjectBrowser;
390 XGUI_PropertyPanel* myPropertyPanel;
391 XGUI_SelectionMgr* mySelector;
392 XGUI_Displayer* myDisplayer;
393 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
394 XGUI_ActionsMgr* myActionsMgr;
395 XGUI_SalomeConnector* mySalomeConnector;
396 XGUI_ErrorDialog* myErrorDlg;
397 XGUI_ViewerProxy* myViewerProxy;
398 XGUI_ContextMenuMgr* myContextMenuMgr;
399 XGUI_ModuleConnector* myModuleConnector;
401 QString myCurrentDir;
402 static QMap<QString, QString> myIcons;
406 // Flag to check that part document is in process of activating
407 bool myPartActivating;