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 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
60 virtual ~XGUI_Workshop();
62 //! Starting of the application
63 void startApplication();
65 //! Returns main window (Desktop) of the application
66 AppElements_MainWindow* mainWindow() const
71 //! Returns selection manager object
72 XGUI_SelectionMgr* selector() const
78 XGUI_Displayer* displayer() const
83 //! ! Returns operation manager.
84 XGUI_OperationMgr* operationMgr() const
86 return myOperationMgr;
89 //! ! Returns an actions manager
90 XGUI_ActionsMgr* actionsMgr() const
95 //! Returns property panel widget
96 XGUI_PropertyPanel* propertyPanel() const
98 return myPropertyPanel;
101 //! Returns context menu manager object
102 XGUI_ContextMenuMgr* contextMenuMgr() const
104 return myContextMenuMgr;
107 //! Creates and adds a new workbench (menu group) with the given name and returns it
108 AppElements_Workbench* addWorkbench(const QString& theName);
110 //! Redefinition of Events_Listener method
111 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
113 //! Returns an object which provides interface to Salome Module (LightApp_Module)
114 XGUI_SalomeConnector* salomeConnector() const
116 return mySalomeConnector;
119 //! Provides an object which provides interface to Salome Viewer
120 ModuleBase_IViewer* salomeViewer() const;
122 //! Returns true if the application works as SALOME module
123 bool isSalomeMode() const
125 return mySalomeConnector != 0;
128 //! Returns Object browser
129 XGUI_ObjectsBrowser* objectBrowser() const
131 return myObjectBrowser;
134 void salomeViewerSelectionChanged();
136 XGUI_ViewerProxy* viewer() const
138 return myViewerProxy;
141 /// Returns the module connectory
142 /// \returns the instance of connector
143 XGUI_ModuleConnector* moduleConnector() const
145 return myModuleConnector;
148 //! Returns icon name according to feature
149 static QIcon featureIcon(const FeaturePtr& theFeature);
151 //! Activates or deactivates a part
152 //! If PartPtr is Null pointer then PartSet will be activated
153 void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
156 void deleteObjects(const QObjectPtrList& theList);
158 //! Show the given features in 3d Viewer
159 void showObjects(const QObjectPtrList& theList, bool isVisible);
161 //! Show the given features in 3d Viewer
162 void showOnlyObjects(const QObjectPtrList& theList);
164 void setDisplayMode(const QObjectPtrList& theList, int theMode);
166 ModuleBase_IModule* module() const
171 /// Returns current directory whic contains data files
172 QString currentDataDir() const { return myCurrentDir; }
174 /// Returns current directory whic contains data files
175 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
178 * Save the current document into a directory
179 * \param theName - path to the directory
180 * \param theFileNames - returned file names created in this directory
182 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
185 * If there is an active (uncommited) operation shows a prompt to abort it
186 * and performs abortion if user agreed. Returns true if
187 * - operation aborted successfully
188 * - there is no active operation
190 bool isActiveOperationAborted();
193 void salomeViewerSelection();
194 void errorOccurred(const QString&);
195 //! the signal about the workshop actions states are updated.
196 void commandStatusUpdated();
198 //! the application is started
199 void applicationStarted();
202 void updateCommandStatus();
212 void onPreferences();
214 void showPropertyPanel();
215 void hidePropertyPanel();
216 void showObjectBrowser();
217 void hideObjectBrowser();
219 void onFeatureTriggered();
220 void changeCurrentDocument(ObjectPtr theObj);
222 void activateLastPart();
224 void closeDocument();
227 // Find the nested features and set them into the operation
228 // \param theOperation an operation
229 void setNestedFeatures(ModuleBase_Operation* theOperation);
230 // Update the property panel content by the XML description of the operation and set the panel
231 // into the operation
232 // \param theOperation an operation
233 void setPropertyPanel(ModuleBase_Operation* theOperation);
235 bool event(QEvent * theEvent);
236 //Event-loop processing methods:
237 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
238 void connectWithOperation(ModuleBase_Operation* theOperation);
240 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
241 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
242 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
243 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
245 void validateOperation(const QString& theOperationId);
247 void displayAllResults();
248 void displayDocumentResults(DocumentPtr theDoc);
249 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
252 /// SLOT, that is called after the operation is started. Update workshop state according to
253 /// the started operation, e.g. visualizes the property panel and connect to it.
254 /// \param theOpertion a started operation
255 void onOperationStarted(ModuleBase_Operation* theOperation);
257 /// SLOT, that is called after the operation is resumed. Update workshop state according to
258 /// the started operation, e.g. visualizes the property panel and connect to it.
259 /// \param theOpertion a resumed operation
260 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
262 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
263 /// hides the property panel and udpate the command status.
264 /// \param theOpertion a stopped operation
265 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
267 /// SLOT, that is called after the operation is committed.
268 /// \param theOpertion a commmitted operation
269 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
271 /// SLOT, that is called after the operation is aborted.
272 /// \param theOpertion an aborted operation
273 void onOperationAborted(ModuleBase_Operation* theOperation);
275 void onContextMenuCommand(const QString& theId, bool isChecked);
277 void onWidgetValuesChanged();
279 void onStartWaiting();
284 void registerValidators() const;
286 ModuleBase_IModule* loadModule(const QString& theModule);
287 bool activateModule();
289 QDockWidget* createObjectBrowser(QWidget* theParent);
290 QDockWidget* createPropertyPanel(QWidget* theParent);
292 // Creates Dock widgets: Object browser and Property panel
293 void createDockWidgets();
295 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
296 void displayObject(ObjectPtr theObj);
299 AppElements_MainWindow* myMainWindow;
300 ModuleBase_IModule* myModule;
301 XGUI_ObjectsBrowser* myObjectBrowser;
302 XGUI_PropertyPanel* myPropertyPanel;
303 XGUI_SelectionMgr* mySelector;
304 XGUI_Displayer* myDisplayer;
305 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
306 XGUI_ActionsMgr* myActionsMgr;
307 XGUI_SalomeConnector* mySalomeConnector;
308 XGUI_ErrorDialog* myErrorDlg;
309 XGUI_ViewerProxy* myViewerProxy;
310 XGUI_ContextMenuMgr* myContextMenuMgr;
311 XGUI_ModuleConnector* myModuleConnector;
313 QString myCurrentDir;
314 static QMap<QString, QString> myIcons;
318 // Flag to check that part document is in process of activating
319 bool myPartActivating;