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>
13 #include <ModuleBase_ActionInfo.h>
17 #include <QKeySequence>
20 class AppElements_MainWindow;
21 class AppElements_Command;
22 class AppElements_Workbench;
24 class XGUI_SelectionMgr;
26 class XGUI_OperationMgr;
27 class XGUI_SalomeConnector;
28 class XGUI_ObjectsBrowser;
29 class XGUI_ActionsMgr;
30 class XGUI_ErrorDialog;
31 class XGUI_SalomeViewer;
32 class XGUI_ViewerProxy;
33 class XGUI_PropertyPanel;
34 class XGUI_ContextMenuMgr;
35 class XGUI_ModuleConnector;
37 class ModuleBase_Operation;
38 class ModuleBase_IModule;
39 class ModuleBase_IViewer;
41 class Config_FeatureMessage;
42 class Config_PointerMessage;
48 class ModelAPI_ObjectUpdatedMessage;
49 class ModelAPI_ObjectDeletedMessage;
50 class ModelAPI_ResultPart;
53 /**\class XGUI_Workshop
55 * \brief Class which defines a configuration of the application (Workshop) and launches it.
57 class XGUI_EXPORT XGUI_Workshop : public QObject, public Events_Listener
62 /// \param theConnector a Salome connector object.
63 /// Used only if the workshop is launched in Salome environment
64 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
65 virtual ~XGUI_Workshop();
67 //! Starting of the application
68 void startApplication();
70 //! Returns main window (Desktop) of the application
71 AppElements_MainWindow* mainWindow() const
76 //! Returns selection manager object
77 XGUI_SelectionMgr* selector() const
83 XGUI_Displayer* displayer() const
88 //! ! Returns operation manager.
89 XGUI_OperationMgr* operationMgr() const
91 return myOperationMgr;
94 //! ! Returns an actions manager
95 XGUI_ActionsMgr* actionsMgr() const
100 //! Returns property panel widget
101 XGUI_PropertyPanel* propertyPanel() const
103 return myPropertyPanel;
106 //! Returns context menu manager object
107 XGUI_ContextMenuMgr* contextMenuMgr() const
109 return myContextMenuMgr;
112 //! Creates and adds a new workbench (menu group) with the given name and returns it
113 AppElements_Workbench* addWorkbench(const QString& theName);
115 //! Redefinition of Events_Listener method
116 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
118 //! Returns an object which provides interface to Salome Module (LightApp_Module)
119 XGUI_SalomeConnector* salomeConnector() const
121 return mySalomeConnector;
124 //! Provides an object which provides interface to Salome Viewer
125 ModuleBase_IViewer* salomeViewer() const;
127 //! Returns true if the application works as SALOME module
128 bool isSalomeMode() const
130 return mySalomeConnector != 0;
133 //! Returns Object browser
134 XGUI_ObjectsBrowser* objectBrowser() const
136 return myObjectBrowser;
139 /// This method is called by Salome module when selection is changed
140 void salomeViewerSelectionChanged();
142 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
143 XGUI_ViewerProxy* viewer() const
145 return myViewerProxy;
148 /// Returns the module connectory
149 /// \returns the instance of connector
150 XGUI_ModuleConnector* moduleConnector() const
152 return myModuleConnector;
155 /// Returns a desktop
156 /// \return a desktop instance
157 QMainWindow* desktop() const;
159 //! Returns icon name according to feature
160 static QIcon featureIcon(const FeaturePtr& theFeature);
162 //! Activates or deactivates a part
163 //! If PartPtr is Null pointer then PartSet will be activated
164 void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
167 void deleteObjects(const QObjectPtrList& theList);
169 //! Show the given features in 3d Viewer
170 void showObjects(const QObjectPtrList& theList, bool isVisible);
172 //! Show the given features in 3d Viewer
173 void showOnlyObjects(const QObjectPtrList& theList);
175 /// Set display mode for the given onjects
176 /// \param theList a list of displayed objects
177 /// \param theMode a mode to set (see \ref XGUI_Displayer)
178 void setDisplayMode(const QObjectPtrList& theList, int theMode);
180 /// Returns current module
181 ModuleBase_IModule* module() const
186 /// Returns current directory whic contains data files
187 QString currentDataDir() const { return myCurrentDir; }
189 /// Returns current directory whic contains data files
190 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
193 * Save the current document into a directory
194 * \param theName - path to the directory
195 * \param theFileNames - returned file names created in this directory
197 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
200 * If there is an active (uncommited) operation shows a prompt to abort it
201 * and performs abortion if user agreed. Returns true if
202 * - operation aborted successfully
203 * - there is no active operation
205 bool isActiveOperationAborted();
208 /// Emitted when selection happens in Salome viewer
209 void salomeViewerSelection();
211 /// Emitted when error in applivation happens
212 void errorOccurred(const QString&);
214 //! the signal about the workshop actions states are updated.
215 void commandStatusUpdated();
217 //! the application is started
218 void applicationStarted();
220 //! Signal to update Undo history list
221 void updateUndoHistory(const QList<ActionInfo>&);
222 //! Signal to update Redo history list
223 void updateRedoHistory(const QList<ActionInfo>&);
226 /// Update of commands status
227 void updateCommandStatus();
229 /// update history list (undo/redo commands)
230 void updateHistory();
232 /// Create a new dokument
235 /// Open document from file
238 /// Save current document
241 /// Save current document to a file selected by user
247 /// Undo last command
248 void onUndo(int times = 1);
250 /// Redo previous command
251 void onRedo(int times = 1);
253 /// Rebuild data tree
256 /// Open preferences dialog box
257 void onPreferences();
259 /// Show property panel
260 void showPropertyPanel();
262 /// Hide property panel
263 void hidePropertyPanel();
265 /// Show object Browser
266 void showObjectBrowser();
268 /// Hide object Browser
269 void hideObjectBrowser();
271 /// Reaction on command call
272 void onFeatureTriggered();
274 /// Change active document
275 /// \param theObj a part object. If it is NULL then active document is a main document
276 void changeCurrentDocument(ObjectPtr theObj);
278 //void activateLastPart();
281 void closeDocument();
284 /// Find the nested features and set them into the operation
285 /// \param theOperation an operation
286 void setNestedFeatures(ModuleBase_Operation* theOperation);
288 /// Update the property panel content by the XML description of the operation and set the panel
289 /// into the operation
290 /// \param theOperation an operation
291 void setPropertyPanel(ModuleBase_Operation* theOperation);
293 /// Procedure to process postponed events
294 bool event(QEvent * theEvent);
296 //Event-loop processing methods:
298 /// Process event "Add a feature"
299 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
301 /// Connect to operation signals
302 /// \param theOperation an operation
303 void connectWithOperation(ModuleBase_Operation* theOperation);
305 /// Process feature update message
306 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
308 ///Process feature created message
309 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
311 /// Process feature redisplay message
312 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
314 /// Process feature delete message
315 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
317 /// Display all results
318 void displayAllResults();
320 /// Displau results from document
321 /// \param theDoc a document
322 void displayDocumentResults(DocumentPtr theDoc);
324 /// Display results from a group
325 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
328 /// SLOT, that is called after the operation is started. Update workshop state according to
329 /// the started operation, e.g. visualizes the property panel and connect to it.
330 /// \param theOpertion a started operation
331 void onOperationStarted(ModuleBase_Operation* theOperation);
333 /// SLOT, that is called after the operation is resumed. Update workshop state according to
334 /// the started operation, e.g. visualizes the property panel and connect to it.
335 /// \param theOpertion a resumed operation
336 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
338 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
339 /// hides the property panel and udpate the command status.
340 /// \param theOpertion a stopped operation
341 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
343 /// SLOT, that is called after the operation is committed.
344 /// \param theOpertion a commmitted operation
345 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
347 /// SLOT, that is called after the operation is aborted.
348 /// \param theOpertion an aborted operation
349 void onOperationAborted(ModuleBase_Operation* theOperation);
351 /// Slot, which reacts to the context popup menu call
352 /// \param theId the data value of the clicked action
353 /// \param isChecked a state of toggle if the action is checkable
354 void onContextMenuCommand(const QString& theId, bool isChecked);
356 /// Set waiting cursor
357 void onStartWaiting();
363 /// Register validators
364 void registerValidators() const;
366 /// Load module from external library
367 /// \param theModule name of the module
368 ModuleBase_IModule* loadModule(const QString& theModule);
371 bool activateModule();
373 /// Create object browser widget
374 /// \param theParent a parent of widget
375 QDockWidget* createObjectBrowser(QWidget* theParent);
377 /// Create property panel widget
378 /// \param theParent a parent of widget
379 QDockWidget* createPropertyPanel(QWidget* theParent);
381 // Creates Dock widgets: Object browser and Property panel
382 void createDockWidgets();
384 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
385 void displayObject(ObjectPtr theObj);
387 //! Extends undo/redo toolbutton's with history menu
388 //! \param theObject - in the OpenParts it is a QToolButton by itself,
389 //! in salome mode - QAction that creates a button.
390 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
391 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
392 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
394 //! Creates list of actions (commands) by given history list from session
395 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
398 AppElements_MainWindow* myMainWindow;
399 ModuleBase_IModule* myModule;
400 XGUI_ObjectsBrowser* myObjectBrowser;
401 XGUI_PropertyPanel* myPropertyPanel;
402 XGUI_SelectionMgr* mySelector;
403 XGUI_Displayer* myDisplayer;
404 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
405 XGUI_ActionsMgr* myActionsMgr;
406 XGUI_SalomeConnector* mySalomeConnector;
407 XGUI_ErrorDialog* myErrorDlg;
408 XGUI_ViewerProxy* myViewerProxy;
409 XGUI_ContextMenuMgr* myContextMenuMgr;
410 XGUI_ModuleConnector* myModuleConnector;
412 QString myCurrentDir;
413 static QMap<QString, QString> myIcons;
417 // Flag to check that part document is in process of activating
418 bool myPartActivating;