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();
219 /// Update of commands status
220 void updateCommandStatus();
222 /// Create a new dokument
225 /// Open document from file
228 /// Save current document
231 /// Save current document to a file selected by user
237 /// Undo last command
240 /// Redo previous command
243 /// Rebuild data tree
246 /// Open preferences dialog box
247 void onPreferences();
249 /// Show property panel
250 void showPropertyPanel();
252 /// Hide property panel
253 void hidePropertyPanel();
255 /// Show object Browser
256 void showObjectBrowser();
258 /// Hide object Browser
259 void hideObjectBrowser();
261 /// Reaction on command call
262 void onFeatureTriggered();
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);
268 //void activateLastPart();
271 void closeDocument();
274 /// Find the nested features and set them into the operation
275 /// \param theOperation an operation
276 void setNestedFeatures(ModuleBase_Operation* theOperation);
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);
283 /// Procedure to process postponed events
284 bool event(QEvent * theEvent);
286 //Event-loop processing methods:
288 /// Process event "Add a feature"
289 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
291 /// Connect to operation signals
292 /// \param theOperation an operation
293 void connectWithOperation(ModuleBase_Operation* theOperation);
295 /// Process feature update message
296 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
298 ///Process feature created message
299 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
301 /// Process feature redisplay message
302 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
304 /// Process feature delete message
305 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
307 /// Display all results
308 void displayAllResults();
310 /// Displau results from document
311 /// \param theDoc a document
312 void displayDocumentResults(DocumentPtr theDoc);
314 /// Display results from a group
315 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
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);
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);
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);
333 /// SLOT, that is called after the operation is committed.
334 /// \param theOpertion a commmitted operation
335 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
337 /// SLOT, that is called after the operation is aborted.
338 /// \param theOpertion an aborted operation
339 void onOperationAborted(ModuleBase_Operation* theOperation);
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);
346 /// Processing of values changed in model widget
347 void onWidgetValuesChanged();
349 /// Set waiting cursor
350 void onStartWaiting();
356 /// Register validators
357 void registerValidators() const;
359 /// Load module from external library
360 /// \param theModule name of the module
361 ModuleBase_IModule* loadModule(const QString& theModule);
364 bool activateModule();
366 /// Create object browser widget
367 /// \param theParent a parent of widget
368 QDockWidget* createObjectBrowser(QWidget* theParent);
370 /// Create property panel widget
371 /// \param theParent a parent of widget
372 QDockWidget* createPropertyPanel(QWidget* theParent);
374 // Creates Dock widgets: Object browser and Property panel
375 void createDockWidgets();
377 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
378 void displayObject(ObjectPtr theObj);
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;
395 QString myCurrentDir;
396 static QMap<QString, QString> myIcons;
400 // Flag to check that part document is in process of activating
401 bool myPartActivating;