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;
45 class ModelAPI_ObjectUpdatedMessage;
46 class ModelAPI_ObjectDeletedMessage;
47 class ModelAPI_ResultPart;
50 /**\class XGUI_Workshop
52 * \brief Class which defines a configuration of the application (Workshop) and launches it.
54 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
59 /// \param theConnector a Salome connector object.
60 /// Used only if the workshop is launched in Salome environment
61 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
62 virtual ~XGUI_Workshop();
64 //! Starting of the application
65 void startApplication();
67 //! Returns main window (Desktop) of the application
68 AppElements_MainWindow* mainWindow() const
73 //! Returns selection manager object
74 XGUI_SelectionMgr* selector() const
80 XGUI_Displayer* displayer() const
85 //! ! Returns operation manager.
86 XGUI_OperationMgr* operationMgr() const
88 return myOperationMgr;
91 //! ! Returns an actions manager
92 XGUI_ActionsMgr* actionsMgr() const
97 //! Returns property panel widget
98 XGUI_PropertyPanel* propertyPanel() const
100 return myPropertyPanel;
103 //! Returns context menu manager object
104 XGUI_ContextMenuMgr* contextMenuMgr() const
106 return myContextMenuMgr;
109 //! Creates and adds a new workbench (menu group) with the given name and returns it
110 AppElements_Workbench* addWorkbench(const QString& theName);
112 //! Redefinition of Events_Listener method
113 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
115 //! Returns an object which provides interface to Salome Module (LightApp_Module)
116 XGUI_SalomeConnector* salomeConnector() const
118 return mySalomeConnector;
121 //! Provides an object which provides interface to Salome Viewer
122 ModuleBase_IViewer* salomeViewer() const;
124 //! Returns true if the application works as SALOME module
125 bool isSalomeMode() const
127 return mySalomeConnector != 0;
130 //! Returns Object browser
131 XGUI_ObjectsBrowser* objectBrowser() const
133 return myObjectBrowser;
136 /// This method is called by Salome module when selection is changed
137 void salomeViewerSelectionChanged();
139 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
140 XGUI_ViewerProxy* viewer() const
142 return myViewerProxy;
145 /// Returns the module connectory
146 /// \returns the instance of connector
147 XGUI_ModuleConnector* moduleConnector() const
149 return myModuleConnector;
152 //! Returns icon name according to feature
153 static QIcon featureIcon(const FeaturePtr& theFeature);
155 //! Activates or deactivates a part
156 //! If PartPtr is Null pointer then PartSet will be activated
157 void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
160 void deleteObjects(const QObjectPtrList& theList);
162 //! Show the given features in 3d Viewer
163 void showObjects(const QObjectPtrList& theList, bool isVisible);
165 //! Show the given features in 3d Viewer
166 void showOnlyObjects(const QObjectPtrList& theList);
168 /// Set display mode for the given onjects
169 /// \param theList a list of displayed objects
170 /// \param theMode a mode to set (see \ref XGUI_Displayer)
171 void setDisplayMode(const QObjectPtrList& theList, int theMode);
173 /// Returns current module
174 ModuleBase_IModule* module() const
179 /// Returns current directory whic contains data files
180 QString currentDataDir() const { return myCurrentDir; }
182 /// Returns current directory whic contains data files
183 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
186 * Save the current document into a directory
187 * \param theName - path to the directory
188 * \param theFileNames - returned file names created in this directory
190 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
193 * If there is an active (uncommited) operation shows a prompt to abort it
194 * and performs abortion if user agreed. Returns true if
195 * - operation aborted successfully
196 * - there is no active operation
198 bool isActiveOperationAborted();
201 /// Emitted when selection happens in Salome viewer
202 void salomeViewerSelection();
204 /// Emitted when error in applivation happens
205 void errorOccurred(const QString&);
207 //! the signal about the workshop actions states are updated.
208 void commandStatusUpdated();
210 //! the application is started
211 void applicationStarted();
214 /// Update of commands status
215 void updateCommandStatus();
217 /// Create a new dokument
220 /// Open document from file
223 /// Save current document
226 /// Save current document to a file selected by user
232 /// Undo last command
235 /// Redo previous command
238 /// Rebuild data tree
241 /// Open preferences dialog box
242 void onPreferences();
244 /// Show property panel
245 void showPropertyPanel();
247 /// Hide property panel
248 void hidePropertyPanel();
250 /// Show object Browser
251 void showObjectBrowser();
253 /// Hide object Browser
254 void hideObjectBrowser();
256 /// Reaction on command call
257 void onFeatureTriggered();
259 /// Change active document
260 /// \param theObj a part object. If it is NULL then active document is a main document
261 void changeCurrentDocument(ObjectPtr theObj);
263 //void activateLastPart();
266 void closeDocument();
269 /// Find the nested features and set them into the operation
270 /// \param theOperation an operation
271 void setNestedFeatures(ModuleBase_Operation* theOperation);
273 /// Update the property panel content by the XML description of the operation and set the panel
274 /// into the operation
275 /// \param theOperation an operation
276 void setPropertyPanel(ModuleBase_Operation* theOperation);
278 /// Procedure to process postponed events
279 bool event(QEvent * theEvent);
281 //Event-loop processing methods:
283 /// Process event "Add a feature"
284 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
286 /// Connect to operation signals
287 /// \param theOperation an operation
288 void connectWithOperation(ModuleBase_Operation* theOperation);
290 /// Process feature update message
291 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
293 ///Process feature created message
294 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
296 /// Process feature redisplay message
297 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
299 /// Process feature delete message
300 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
302 /// Display all results
303 void displayAllResults();
305 /// Displau results from document
306 /// \param theDoc a document
307 void displayDocumentResults(DocumentPtr theDoc);
309 /// Display results from a group
310 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
313 /// SLOT, that is called after the operation is started. Update workshop state according to
314 /// the started operation, e.g. visualizes the property panel and connect to it.
315 /// \param theOpertion a started operation
316 void onOperationStarted(ModuleBase_Operation* theOperation);
318 /// SLOT, that is called after the operation is resumed. Update workshop state according to
319 /// the started operation, e.g. visualizes the property panel and connect to it.
320 /// \param theOpertion a resumed operation
321 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
323 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
324 /// hides the property panel and udpate the command status.
325 /// \param theOpertion a stopped operation
326 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
328 /// SLOT, that is called after the operation is committed.
329 /// \param theOpertion a commmitted operation
330 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
332 /// SLOT, that is called after the operation is aborted.
333 /// \param theOpertion an aborted operation
334 void onOperationAborted(ModuleBase_Operation* theOperation);
336 /// Process context menu command
337 /// \param theId id of the command
338 /// \param isChecked is checked flag
339 void onContextMenuCommand(const QString& theId, bool isChecked);
341 /// Processing of values changed in model widget
342 void onWidgetValuesChanged();
344 /// Set waiting cursor
345 void onStartWaiting();
351 /// Register validators
352 void registerValidators() const;
354 /// Load module from external library
355 /// \param theModule name of the module
356 ModuleBase_IModule* loadModule(const QString& theModule);
359 bool activateModule();
361 /// Create object browser widget
362 /// \param theParent a parent of widget
363 QDockWidget* createObjectBrowser(QWidget* theParent);
365 /// Create property panel widget
366 /// \param theParent a parent of widget
367 QDockWidget* createPropertyPanel(QWidget* theParent);
369 // Creates Dock widgets: Object browser and Property panel
370 void createDockWidgets();
372 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
373 void displayObject(ObjectPtr theObj);
376 AppElements_MainWindow* myMainWindow;
377 ModuleBase_IModule* myModule;
378 XGUI_ObjectsBrowser* myObjectBrowser;
379 XGUI_PropertyPanel* myPropertyPanel;
380 XGUI_SelectionMgr* mySelector;
381 XGUI_Displayer* myDisplayer;
382 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
383 XGUI_ActionsMgr* myActionsMgr;
384 XGUI_SalomeConnector* mySalomeConnector;
385 XGUI_ErrorDialog* myErrorDlg;
386 XGUI_ViewerProxy* myViewerProxy;
387 XGUI_ContextMenuMgr* myContextMenuMgr;
388 XGUI_ModuleConnector* myModuleConnector;
390 QString myCurrentDir;
391 static QMap<QString, QString> myIcons;
395 // Flag to check that part document is in process of activating
396 bool myPartActivating;