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 // Activates the module controls. Should be called after module creation
71 void activateModule();
73 // Deactivates the module controls. Should be called after module creation
74 void deactivateModule();
76 //! Returns main window (Desktop) of the application
77 AppElements_MainWindow* mainWindow() const
82 //! Returns selection manager object
83 XGUI_SelectionMgr* selector() const
89 XGUI_Displayer* displayer() const
94 //! ! Returns operation manager.
95 XGUI_OperationMgr* operationMgr() const
97 return myOperationMgr;
100 //! ! Returns an actions manager
101 XGUI_ActionsMgr* actionsMgr() const
106 //! Returns property panel widget
107 XGUI_PropertyPanel* propertyPanel() const
109 return myPropertyPanel;
112 //! Returns context menu manager object
113 XGUI_ContextMenuMgr* contextMenuMgr() const
115 return myContextMenuMgr;
118 //! Creates and adds a new workbench (menu group) with the given name and returns it
119 AppElements_Workbench* addWorkbench(const QString& theName);
121 //! Redefinition of Events_Listener method
122 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
124 //! Returns an object which provides interface to Salome Module (LightApp_Module)
125 XGUI_SalomeConnector* salomeConnector() const
127 return mySalomeConnector;
130 //! Provides an object which provides interface to Salome Viewer
131 ModuleBase_IViewer* salomeViewer() const;
133 //! Returns true if the application works as SALOME module
134 bool isSalomeMode() const
136 return mySalomeConnector != 0;
139 //! Returns Object browser
140 XGUI_ObjectsBrowser* objectBrowser() const
142 return myObjectBrowser;
145 /// This method is called by Salome module when selection is changed
146 void salomeViewerSelectionChanged();
148 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
149 XGUI_ViewerProxy* viewer() const
151 return myViewerProxy;
154 /// Returns the module connectory
155 /// \returns the instance of connector
156 XGUI_ModuleConnector* moduleConnector() const
158 return myModuleConnector;
161 /// Returns a desktop
162 /// \return a desktop instance
163 QMainWindow* desktop() const;
166 void deleteObjects();
168 //! Returns true if there is at least one selected body/construction/group result
169 //! \return boolean value
170 bool canChangeColor() const;
172 //! Change color of the features if it is possible
173 //! The operation is available for construction, body and group results
174 //! theObjects a list of selected objects
175 void changeColor(const QObjectPtrList& theObjects);
177 //! Show the given features in 3d Viewer
178 void showObjects(const QObjectPtrList& theList, bool isVisible);
180 //! Show the given features in 3d Viewer
181 void showOnlyObjects(const QObjectPtrList& theList);
183 /// Set display mode for the given onjects
184 /// \param theList a list of displayed objects
185 /// \param theMode a mode to set (see \ref XGUI_Displayer)
186 void setDisplayMode(const QObjectPtrList& theList, int theMode);
188 /// Returns current module
189 ModuleBase_IModule* module() const
194 /// Returns current directory whic contains data files
195 QString currentDataDir() const { return myCurrentDir; }
197 /// Returns current directory whic contains data files
198 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
201 * Save the current document into a directory
202 * \param theName - path to the directory
203 * \param theFileNames - returned file names created in this directory
205 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
208 * If there is an active (uncommited) operation shows a prompt to abort it
209 * and performs abortion if user agreed. Returns true if
210 * - operation aborted successfully
211 * - there is no active operation
213 bool isActiveOperationAborted();
215 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
217 //! \param theList an objects to be deleted
218 //! \param theIgnoredFeatures a list of features to be ignored during delete
219 //! \param theParent a parent widget for the question message box
220 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
221 //! objects features appear. If the user chose do not continue, the deletion is not performed
222 //! \return the success of the delete
223 static bool deleteFeatures(const QObjectPtrList& theList,
224 std::set<FeaturePtr> theIgnoredFeatures = std::set<FeaturePtr>(),
225 QWidget* theParent = 0,
226 const bool theAskAboutDeleteReferences = false);
229 /// Emitted when selection happens in Salome viewer
230 void salomeViewerSelection();
232 /// Emitted when error in applivation happens
233 void errorOccurred(const QString&);
235 //! the signal about the workshop actions states are updated.
236 void commandStatusUpdated();
238 //! the application is started
239 void applicationStarted();
241 //! Signal to update Undo history list
242 void updateUndoHistory(const QList<ActionInfo>&);
244 //! Signal to update Redo history list
245 void updateRedoHistory(const QList<ActionInfo>&);
248 /// Update of commands status
249 void updateCommandStatus();
251 /// update history list (undo/redo commands)
252 void updateHistory();
254 /// Create a new dokument
257 /// Open document from file
260 /// Save current document
263 /// Save current document to a file selected by user
269 /// Undo last command
270 void onUndo(int times = 1);
272 /// Redo previous command
273 void onRedo(int times = 1);
275 /// Rebuild data tree
278 /// Open preferences dialog box
279 void onPreferences();
281 /// Show property panel
282 void showPropertyPanel();
284 /// Hide property panel
285 void hidePropertyPanel();
287 /// Show object Browser
288 void showObjectBrowser();
290 /// Hide object Browser
291 void hideObjectBrowser();
293 /// Reaction on command call
294 //void onFeatureTriggered();
297 void closeDocument();
300 /// Find the nested features and set them into the operation
301 /// \param theOperation an operation
302 void setNestedFeatures(ModuleBase_Operation* theOperation);
304 /// Update the property panel content by the XML description of the operation and set the panel
305 /// into the operation
306 /// \param theOperation an operation
307 void setPropertyPanel(ModuleBase_Operation* theOperation);
309 /// Procedure to process postponed events
310 bool event(QEvent * theEvent);
312 //Event-loop processing methods:
314 /// Process event "Add a feature"
315 void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
317 /// Connect to operation signals
318 /// \param theOperation an operation
319 void connectWithOperation(ModuleBase_Operation* theOperation);
321 /// Process feature update message
322 void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
324 /// Process feature created message
325 void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
327 /// Process feature redisplay message
328 void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
330 /// Deactivates the object, if it is active and the module returns that the activation
331 /// of selection for the object is not possible currently(the current operation uses it)
332 /// \param theObject an object
333 /// \param theUpdateViewer a boolean flag to update viewer immediately
334 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
336 /// Display all results
337 //void displayAllResults();
339 /// Displau results from document
340 /// \param theDoc a document
341 void displayDocumentResults(DocumentPtr theDoc);
343 /// Display results from a group
344 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
347 /// SLOT, that is called after the operation is started. Update workshop state according to
348 /// the started operation, e.g. visualizes the property panel and connect to it.
349 /// \param theOpertion a started operation
350 void onOperationStarted(ModuleBase_Operation* theOperation);
352 /// SLOT, that is called after the operation is resumed. Update workshop state according to
353 /// the started operation, e.g. visualizes the property panel and connect to it.
354 /// \param theOpertion a resumed operation
355 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
357 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
358 /// hides the property panel and udpate the command status.
359 /// \param theOpertion a stopped operation
360 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
362 /// SLOT, that is called after the operation is committed.
363 /// \param theOpertion a commmitted operation
364 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
366 /// SLOT, that is called after the operation is aborted.
367 /// \param theOpertion an aborted operation
368 void onOperationAborted(ModuleBase_Operation* theOperation);
370 /// Slot, which reacts to the context popup menu call
371 /// \param theId the data value of the clicked action
372 /// \param isChecked a state of toggle if the action is checkable
373 void onContextMenuCommand(const QString& theId, bool isChecked);
375 /// Set waiting cursor
376 void onStartWaiting();
382 /// Register validators
383 void registerValidators() const;
385 /// Load module from external library
386 /// \param theModule name of the module
387 ModuleBase_IModule* loadModule(const QString& theModule);
392 /// Create object browser widget
393 /// \param theParent a parent of widget
394 QDockWidget* createObjectBrowser(QWidget* theParent);
396 /// Create property panel widget
397 /// \param theParent a parent of widget
398 QDockWidget* createPropertyPanel(QWidget* theParent);
400 // Creates Dock widgets: Object browser and Property panel
401 void createDockWidgets();
403 /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
404 /// Asks the module whether the object can be displayed
405 /// \param theObj an object
406 /// \return true if the object is displayed
407 bool displayObject(ObjectPtr theObj);
409 //! Extends undo/redo toolbutton's with history menu
410 //! \param theObject - in the OpenParts it is a QToolButton by itself,
411 //! in salome mode - QAction that creates a button.
412 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
413 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
414 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
416 //! Creates list of actions (commands) by given history list from session
417 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
420 AppElements_MainWindow* myMainWindow;
421 ModuleBase_IModule* myModule;
422 XGUI_ObjectsBrowser* myObjectBrowser;
423 XGUI_PropertyPanel* myPropertyPanel;
424 XGUI_SelectionMgr* mySelector;
425 XGUI_Displayer* myDisplayer;
426 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
427 XGUI_ActionsMgr* myActionsMgr;
428 XGUI_SalomeConnector* mySalomeConnector;
429 XGUI_ErrorDialog* myErrorDlg;
430 XGUI_ViewerProxy* myViewerProxy;
431 XGUI_ContextMenuMgr* myContextMenuMgr;
432 XGUI_ModuleConnector* myModuleConnector;
434 QString myCurrentDir;
438 // Flag to check that part document is in process of activating
439 bool myPartActivating;
441 /// The flag is true when we loading a document
442 bool myIsLoadingData;