1 #ifndef XGUI_WORKSHOP_H
2 #define XGUI_WORKSHOP_H
5 #include "XGUI_Constants.h"
6 #include <Events_Listener.h>
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_Document.h>
9 #include <ModelAPI_Feature.h>
13 #include <QKeySequence>
16 class XGUI_MainWindow;
19 class XGUI_SelectionMgr;
21 class XGUI_OperationMgr;
22 class XGUI_SalomeConnector;
23 class XGUI_ObjectsBrowser;
24 class XGUI_ActionsMgr;
25 class XGUI_ErrorDialog;
26 class XGUI_SalomeViewer;
27 class XGUI_ViewerProxy;
28 class XGUI_PropertyPanel;
29 class XGUI_ContextMenuMgr;
30 class XGUI_ModuleConnector;
32 class ModuleBase_Operation;
33 class ModuleBase_IModule;
34 class ModuleBase_IViewer;
36 class Config_FeatureMessage;
37 class Config_PointerMessage;
42 class ModelAPI_ObjectUpdatedMessage;
43 class ModelAPI_ObjectDeletedMessage;
44 class ModelAPI_ResultPart;
47 /**\class XGUI_Workshop
49 * \brief Class which defines a configuration of the application (Workshop) and launches it.
51 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
56 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
57 virtual ~XGUI_Workshop();
59 //! Starting of the application
60 void startApplication();
62 //! Returns main window (Desktop) of the application
63 XGUI_MainWindow* mainWindow() const
68 //! Returns selection manager object
69 XGUI_SelectionMgr* selector() const
75 XGUI_Displayer* displayer() const
80 //! ! Returns operation manager.
81 XGUI_OperationMgr* operationMgr() const
83 return myOperationMgr;
86 //! ! Returns an actions manager
87 XGUI_ActionsMgr* actionsMgr() const
93 //! Returns property panel widget
94 XGUI_PropertyPanel* propertyPanel() const
96 return myPropertyPanel;
99 //! Returns context menu manager object
100 XGUI_ContextMenuMgr* contextMenuMgr() const
102 return myContextMenuMgr;
105 //! Creates and adds a new workbench (menu group) with the given name and returns it
106 XGUI_Workbench* addWorkbench(const QString& theName);
108 //! Redefinition of Events_Listener method
109 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
111 //! Returns an object which provides interface to Salome Module (LightApp_Module)
112 XGUI_SalomeConnector* salomeConnector() const
114 return mySalomeConnector;
117 //! Provides an object which provides interface to Salome Viewer
118 ModuleBase_IViewer* salomeViewer() const;
120 //! Returns true if the application works as SALOME module
121 bool isSalomeMode() const
123 return mySalomeConnector != 0;
126 //! Returns Object browser
127 XGUI_ObjectsBrowser* objectBrowser() const
129 return myObjectBrowser;
132 void salomeViewerSelectionChanged();
134 XGUI_ViewerProxy* viewer() const
136 return myViewerProxy;
139 /// Returns the module connectory
140 /// \returns the instance of connector
141 XGUI_ModuleConnector* moduleConnector() const
143 return myModuleConnector;
146 //! Returns icon name according to feature Id
147 static QPixmap featureIcon(const FeaturePtr& theFeature);
149 //! Activates or deactivates a part
150 //! If PartPtr is Null pointer then PartSet will be activated
151 void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
154 void deleteObjects(const QObjectPtrList& theList);
156 //! Show the given features in 3d Viewer
157 void showObjects(const QObjectPtrList& theList, bool isVisible);
159 //! Show the given features in 3d Viewer
160 void showOnlyObjects(const QObjectPtrList& theList);
162 void setDisplayMode(const QObjectPtrList& theList, int theMode);
164 ModuleBase_IModule* module() const
169 /// Returns current directory whic contains data files
170 QString currentDataDir() const { return myCurrentDir; }
172 /// Returns current directory whic contains data files
173 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
176 * Save the current document into a directory
177 * \param theName - path to the directory
178 * \param theFileNames - returned file names created in this directory
180 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
183 * If there is an active (uncommited) operation shows a prompt to abort it
184 * and performs abortion if user agreed. Returns true if
185 * - operation aborted successfully
186 * - there is no active operation
188 bool isActiveOperationAborted();
191 void salomeViewerSelection();
192 void errorOccurred(const QString&);
195 void updateCommandStatus();
196 void updateCommandsOnViewSelection();
206 void onPreferences();
208 void showPropertyPanel();
209 void hidePropertyPanel();
210 void showObjectBrowser();
211 void hideObjectBrowser();
213 void onFeatureTriggered();
214 void changeCurrentDocument(ObjectPtr theObj);
216 void activateLastPart();
218 void closeDocument();
221 bool event(QEvent * theEvent);
222 //Event-loop processing methods:
223 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
224 void connectWithOperation(ModuleBase_Operation* theOperation);
226 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
227 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
228 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
229 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg);
231 void validateOperation(const QString& theOperationId);
233 QList<QAction*> getModuleCommands() const;
235 void displayAllResults();
236 void displayDocumentResults(DocumentPtr theDoc);
237 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
240 /// SLOT, that is called after the operation is started. Update workshop state according to
241 /// the started operation, e.g. visualizes the property panel and connect to it.
242 void onOperationStarted();
244 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
245 /// hides the property panel and udpate the command status.
246 /// \param theOpertion a stopped operation
247 void onOperationStopped(ModuleBase_Operation* theOperation);
249 void onContextMenuCommand(const QString& theId, bool isChecked);
251 void onWidgetValuesChanged();
253 void onStartWaiting();
258 void registerValidators() const;
260 ModuleBase_IModule* loadModule(const QString& theModule);
261 bool activateModule();
263 QDockWidget* createObjectBrowser(QWidget* theParent);
264 QDockWidget* createPropertyPanel(QWidget* theParent);
266 // Creates Dock widgets: Object browser and Property panel
267 void createDockWidgets();
269 XGUI_MainWindow* myMainWindow;
270 ModuleBase_IModule* myModule;
271 XGUI_ObjectsBrowser* myObjectBrowser;
272 XGUI_PropertyPanel* myPropertyPanel;
273 XGUI_SelectionMgr* mySelector;
274 XGUI_Displayer* myDisplayer;
275 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
276 XGUI_ActionsMgr* myActionsMgr;
277 XGUI_SalomeConnector* mySalomeConnector;
278 XGUI_ErrorDialog* myErrorDlg;
279 XGUI_ViewerProxy* myViewerProxy;
280 XGUI_ContextMenuMgr* myContextMenuMgr;
281 XGUI_ModuleConnector* myModuleConnector;
283 QString myCurrentDir;
284 static QMap<QString, QString> myIcons;
288 // Flag to check that part document is in process of activating
289 bool myPartActivating;