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 //! Returns true if there is at least one selected body/construction/group result
170 //! \return boolean value
171 bool canChangeColor() const;
173 //! Change color of the features if it is possible
174 //! The operation is available for construction, body and group results
175 //! theObjects a list of selected objects
176 void changeColor(const QObjectPtrList& theObjects);
178 //! Show the given features in 3d Viewer
179 void showObjects(const QObjectPtrList& theList, bool isVisible);
181 //! Show the given features in 3d Viewer
182 void showOnlyObjects(const QObjectPtrList& theList);
184 /// Set display mode for the given onjects
185 /// \param theList a list of displayed objects
186 /// \param theMode a mode to set (see \ref XGUI_Displayer)
187 void setDisplayMode(const QObjectPtrList& theList, int theMode);
189 /// Returns current module
190 ModuleBase_IModule* module() const
195 /// Returns current directory whic contains data files
196 QString currentDataDir() const { return myCurrentDir; }
198 /// Returns current directory whic contains data files
199 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
202 * Save the current document into a directory
203 * \param theName - path to the directory
204 * \param theFileNames - returned file names created in this directory
206 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
209 * If there is an active (uncommited) operation shows a prompt to abort it
210 * and performs abortion if user agreed. Returns true if
211 * - operation aborted successfully
212 * - there is no active operation
214 bool isActiveOperationAborted();
217 /// Emitted when selection happens in Salome viewer
218 void salomeViewerSelection();
220 /// Emitted when error in applivation happens
221 void errorOccurred(const QString&);
223 //! the signal about the workshop actions states are updated.
224 void commandStatusUpdated();
226 //! the application is started
227 void applicationStarted();
229 //! Signal to update Undo history list
230 void updateUndoHistory(const QList<ActionInfo>&);
231 //! Signal to update Redo history list
232 void updateRedoHistory(const QList<ActionInfo>&);
235 /// Update of commands status
236 void updateCommandStatus();
238 /// update history list (undo/redo commands)
239 void updateHistory();
241 /// Create a new dokument
244 /// Open document from file
247 /// Save current document
250 /// Save current document to a file selected by user
256 /// Undo last command
257 void onUndo(int times = 1);
259 /// Redo previous command
260 void onRedo(int times = 1);
262 /// Rebuild data tree
265 /// Open preferences dialog box
266 void onPreferences();
268 /// Show property panel
269 void showPropertyPanel();
271 /// Hide property panel
272 void hidePropertyPanel();
274 /// Show object Browser
275 void showObjectBrowser();
277 /// Hide object Browser
278 void hideObjectBrowser();
280 /// Reaction on command call
281 void onFeatureTriggered();
283 /// Change active document
284 /// \param theObj a part object. If it is NULL then active document is a main document
285 void changeCurrentDocument(ObjectPtr theObj);
287 //void activateLastPart();
290 void closeDocument();
293 /// Find the nested features and set them into the operation
294 /// \param theOperation an operation
295 void setNestedFeatures(ModuleBase_Operation* theOperation);
297 /// Update the property panel content by the XML description of the operation and set the panel
298 /// into the operation
299 /// \param theOperation an operation
300 void setPropertyPanel(ModuleBase_Operation* theOperation);
302 /// Procedure to process postponed events
303 bool event(QEvent * theEvent);
305 //Event-loop processing methods:
307 /// Process event "Add a feature"
308 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
310 /// Connect to operation signals
311 /// \param theOperation an operation
312 void connectWithOperation(ModuleBase_Operation* theOperation);
314 /// Process feature update message
315 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
317 ///Process feature created message
318 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
320 /// Process feature redisplay message
321 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
323 /// Process feature delete message
324 void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
326 /// Display all results
327 void displayAllResults();
329 /// Displau results from document
330 /// \param theDoc a document
331 void displayDocumentResults(DocumentPtr theDoc);
333 /// Display results from a group
334 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
337 /// SLOT, that is called after the operation is started. Update workshop state according to
338 /// the started operation, e.g. visualizes the property panel and connect to it.
339 /// \param theOpertion a started operation
340 void onOperationStarted(ModuleBase_Operation* theOperation);
342 /// SLOT, that is called after the operation is resumed. Update workshop state according to
343 /// the started operation, e.g. visualizes the property panel and connect to it.
344 /// \param theOpertion a resumed operation
345 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
347 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
348 /// hides the property panel and udpate the command status.
349 /// \param theOpertion a stopped operation
350 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
352 /// SLOT, that is called after the operation is committed.
353 /// \param theOpertion a commmitted operation
354 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
356 /// SLOT, that is called after the operation is aborted.
357 /// \param theOpertion an aborted operation
358 void onOperationAborted(ModuleBase_Operation* theOperation);
360 /// Slot, which reacts to the context popup menu call
361 /// \param theId the data value of the clicked action
362 /// \param isChecked a state of toggle if the action is checkable
363 void onContextMenuCommand(const QString& theId, bool isChecked);
365 /// Set waiting cursor
366 void onStartWaiting();
372 /// Register validators
373 void registerValidators() const;
375 /// Load module from external library
376 /// \param theModule name of the module
377 ModuleBase_IModule* loadModule(const QString& theModule);
380 bool activateModule();
382 /// Create object browser widget
383 /// \param theParent a parent of widget
384 QDockWidget* createObjectBrowser(QWidget* theParent);
386 /// Create property panel widget
387 /// \param theParent a parent of widget
388 QDockWidget* createPropertyPanel(QWidget* theParent);
390 // Creates Dock widgets: Object browser and Property panel
391 void createDockWidgets();
393 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
394 void displayObject(ObjectPtr theObj);
396 //! Extends undo/redo toolbutton's with history menu
397 //! \param theObject - in the OpenParts it is a QToolButton by itself,
398 //! in salome mode - QAction that creates a button.
399 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
400 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
401 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
403 //! Creates list of actions (commands) by given history list from session
404 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
407 AppElements_MainWindow* myMainWindow;
408 ModuleBase_IModule* myModule;
409 XGUI_ObjectsBrowser* myObjectBrowser;
410 XGUI_PropertyPanel* myPropertyPanel;
411 XGUI_SelectionMgr* mySelector;
412 XGUI_Displayer* myDisplayer;
413 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
414 XGUI_ActionsMgr* myActionsMgr;
415 XGUI_SalomeConnector* mySalomeConnector;
416 XGUI_ErrorDialog* myErrorDlg;
417 XGUI_ViewerProxy* myViewerProxy;
418 XGUI_ContextMenuMgr* myContextMenuMgr;
419 XGUI_ModuleConnector* myModuleConnector;
421 QString myCurrentDir;
422 static QMap<QString, QString> myIcons;
426 // Flag to check that part document is in process of activating
427 bool myPartActivating;