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 <ModuleBase_Definitions.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Feature.h>
12 #include <ModuleBase_ActionInfo.h>
16 #include <QKeySequence>
20 class AppElements_MainWindow;
21 class AppElements_Command;
22 class AppElements_Workbench;
25 class XGUI_ActionsMgr;
26 class XGUI_ContextMenuMgr;
28 class XGUI_ErrorDialog;
30 class XGUI_ModuleConnector;
31 class XGUI_ObjectsBrowser;
32 class XGUI_OperationMgr;
33 class XGUI_PropertyPanel;
34 class XGUI_SalomeConnector;
35 class XGUI_SalomeViewer;
36 class XGUI_SelectionMgr;
37 class XGUI_ViewerProxy;
38 class XGUI_WorkshopListener;
40 class ModuleBase_IModule;
41 class ModuleBase_IViewer;
42 class ModuleBase_Operation;
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
59 /// \param theConnector a Salome connector object.
60 /// Used only if the workshop is launched in Salome environment
61 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
62 virtual ~XGUI_Workshop();
64 //! Starting of the application
65 void startApplication();
67 /// Activates the module controls. Should be called after module creation
68 void activateModule();
70 /// Deactivates the module controls. Should be called after module creation
71 void deactivateModule();
74 //! Returns main window (Desktop) of the application
75 AppElements_MainWindow* mainWindow() const
80 //! Creates and adds a new workbench (menu group) with the given name and returns it
81 AppElements_Workbench* addWorkbench(const QString& theName);
84 //! Returns selection manager object
85 XGUI_SelectionMgr* selector() const
91 XGUI_Displayer* displayer() const
96 //! ! Returns operation manager.
97 XGUI_OperationMgr* operationMgr() const
99 return myOperationMgr;
102 //! ! Returns error manager.
103 XGUI_ErrorMgr* errorMgr() const
108 //! ! Returns an actions manager
109 XGUI_ActionsMgr* actionsMgr() const
114 //! Returns property panel widget
115 XGUI_PropertyPanel* propertyPanel() const
117 return myPropertyPanel;
120 //! Returns context menu manager object
121 XGUI_ContextMenuMgr* contextMenuMgr() const
123 return myContextMenuMgr;
126 //! Returns an object which provides interface to Salome Module (LightApp_Module)
127 XGUI_SalomeConnector* salomeConnector() const
129 return mySalomeConnector;
132 //! Provides an object which provides interface to Salome Viewer
133 ModuleBase_IViewer* salomeViewer() const;
135 //! Returns true if the application works as SALOME module
136 bool isSalomeMode() const
138 return mySalomeConnector != 0;
141 //! Returns Object browser
142 XGUI_ObjectsBrowser* objectBrowser() const
144 return myObjectBrowser;
147 /// This method is called by Salome module when selection is changed
148 void salomeViewerSelectionChanged();
150 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
151 XGUI_ViewerProxy* viewer() const
153 return myViewerProxy;
156 /// Returns the module connector
157 /// \returns the instance of connector
158 XGUI_ModuleConnector* moduleConnector() const
160 return myModuleConnector;
163 /// Returns a desktop
164 /// \return a desktop instance
165 QMainWindow* desktop() const;
168 void deleteObjects();
170 //! Returns true if the selected feature can be moved to the position after the current feature
171 //! \return boolean value
172 bool canMoveFeature();
174 //! Move selected features to be after the current feature
177 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
178 //! checks subobjects of the result
179 //! \return boolean value
180 bool canBeShaded(const ObjectPtr& theObject) const;
182 //! Returns true if there is at least one selected body/construction/group result
183 //! \return boolean value
184 bool canChangeColor() const;
186 //! Change color of the features if it is possible
187 //! The operation is available for construction, body and group results
188 //! theObjects a list of selected objects
189 void changeColor(const QObjectPtrList& theObjects);
191 //! Show the given features in 3d Viewer
192 void showObjects(const QObjectPtrList& theList, bool isVisible);
194 //! Show the given features in 3d Viewer
195 void showOnlyObjects(const QObjectPtrList& theList);
197 /// Set display mode for the given objects
198 /// \param theList a list of displayed objects
199 /// \param theMode a mode to set (see \ref XGUI_Displayer)
200 void setDisplayMode(const QObjectPtrList& theList, int theMode);
202 /// Returns current module
203 ModuleBase_IModule* module() const
208 /// Returns current directory which contains data files
209 QString currentDataDir() const { return myCurrentDir; }
211 /// Returns current directory which contains data files
212 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
215 * Save the current document into a directory
216 * \param theName - path to the directory
217 * \param theFileNames - returned file names created in this directory
219 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
222 * If there is an active (uncommitted) operation shows a prompt to abort it
223 * and performs abortion if user agreed. Returns true if
224 * - operation aborted successfully
225 * - there is no active operation
227 bool abortAllOperations();
229 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
231 //! \param theList an objects to be deleted
232 //! \param theIgnoredFeatures a list of features to be ignored during delete
233 //! \param theParent a parent widget for the question message box
234 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
235 //! objects features appear. If the user chose do not continue, the deletion is not performed
236 //! \return the success of the delete
237 bool deleteFeatures(const QObjectPtrList& theList,
238 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
239 QWidget* theParent = 0,
240 const bool theAskAboutDeleteReferences = false);
242 /// Deactivates the object, if it is active and the module returns that the activation
243 /// of selection for the object is not possible currently(the current operation uses it)
244 /// \param theObject an object
245 /// \param theUpdateViewer a boolean flag to update viewer immediately
246 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
248 /// Returns true if the action of the feature is created to contain Accept/Cancel button
249 /// \param theFeature a feature
250 bool isFeatureOfNested(const FeaturePtr& theFeature);
252 /// Has to be called in order to display objects with visibility status = true
253 void synchronizeViewer();
255 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
256 /// \param theDoc the document for objects synchronisation
257 /// \param theGroup the group name
258 /// \param theUpdateViewer update viewer flag
259 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
262 /// Emitted when selection happens in Salome viewer
263 void salomeViewerSelection();
265 /// Emitted when error in application happens
266 void errorOccurred(const QString&);
268 //! the signal about the workshop actions states are updated.
269 void commandStatusUpdated();
271 //! the application is started
272 void applicationStarted();
274 //! Signal to update Undo history list
275 void updateUndoHistory(const QList<ActionInfo>&);
277 //! Signal to update Redo history list
278 void updateRedoHistory(const QList<ActionInfo>&);
281 /// Update of commands status
282 void updateCommandStatus();
284 /// update history list (undo/redo commands)
285 void updateHistory();
287 /// Save current document
290 /// Save current document to a file selected by user
293 /// Undo last command
294 void onUndo(int times = 1);
296 /// Redo previous command
297 void onRedo(int times = 1);
299 /// Rebuild data tree
302 /// Validates the operation to change the "Apply" button state.
303 /// \param thePreviousState the previous state of the widget
304 void onWidgetStateChanged(int thePreviousState);
306 /// Show property panel
307 void showPropertyPanel();
309 /// Hide property panel
310 void hidePropertyPanel();
312 /// Show object Browser
313 void showObjectBrowser();
315 /// Hide object Browser
316 void hideObjectBrowser();
319 void closeDocument();
321 /// Open document from file
324 /// Create a new document
331 /// Open preferences dialog box
332 void onPreferences();
336 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
337 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
338 /// \param theOperation an operation
339 void setGrantedFeatures(ModuleBase_Operation* theOperation);
341 /// Update the property panel content by the XML description of the operation and set the panel
342 /// into the operation
343 /// \param theOperation an operation
344 void setPropertyPanel(ModuleBase_Operation* theOperation);
346 /// Connects or disconnects to the value changed signal of the property panel widgets
347 /// \param isToConnect a boolean value whether connect or disconnect
348 void connectToPropertyPanel(const bool isToConnect);
351 /// Display all results
352 //void displayAllResults();
354 /// Display results from document
355 /// \param theDoc a document
356 void displayDocumentResults(DocumentPtr theDoc);
358 /// Display results from a group
359 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
362 /// SLOT, that is called after the operation is started. Update workshop state according to
363 /// the started operation, e.g. visualizes the property panel and connect to it.
364 /// \param theOpertion a started operation
365 void onOperationStarted(ModuleBase_Operation* theOperation);
367 /// SLOT, that is called after the operation is resumed. Update workshop state according to
368 /// the started operation, e.g. visualizes the property panel and connect to it.
369 /// \param theOpertion a resumed operation
370 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
372 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
373 /// hides the property panel and update the command status.
374 /// \param theOpertion a stopped operation
375 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
377 /// SLOT, that is called after the operation is committed.
378 /// \param theOpertion a committed operation
379 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
381 /// SLOT, that is called after the operation is aborted.
382 /// \param theOpertion an aborted operation
383 void onOperationAborted(ModuleBase_Operation* theOperation);
385 /// Slot, which reacts to the context popup menu call
386 /// \param theId the data value of the clicked action
387 /// \param isChecked a state of toggle if the action is checkable
388 void onContextMenuCommand(const QString& theId, bool isChecked);
390 /// Set waiting cursor
391 void onStartWaiting();
393 /// Called by Ok button clicked in the property panel. Asks the error manager whether
394 /// the operation can be committed and do it if it returns true.
395 void onAcceptActionClicked();
397 /// Listens the corresponded signal from operation manager and send it with the Ok
398 /// action to operation manager.
399 /// \param theEnabled an enabled state for the action
400 //void onValidationStateChanged(bool theEnabled);
402 //connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
403 // aOkAct, SLOT(setEnabled(bool)));
410 /// Register validators
411 void registerValidators() const;
413 /// Load module from external library
414 /// \param theModule name of the module
415 ModuleBase_IModule* loadModule(const QString& theModule);
420 /// Create object browser widget
421 /// \param theParent a parent of widget
422 QDockWidget* createObjectBrowser(QWidget* theParent);
424 /// Create property panel widget
425 /// \param theParent a parent of widget
426 QDockWidget* createPropertyPanel(QWidget* theParent);
428 // Creates Dock widgets: Object browser and Property panel
429 void createDockWidgets();
431 //! Extends undo/redo toolbutton's with history menu
432 //! \param theObject - in the OpenParts it is a QToolButton by itself,
433 //! in salome mode - QAction that creates a button.
434 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
435 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
436 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
438 //! Creates list of actions (commands) by given history list from session
439 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
443 AppElements_MainWindow* myMainWindow;
446 ModuleBase_IModule* myModule;
447 XGUI_ErrorMgr* myErrorMgr;
448 XGUI_ObjectsBrowser* myObjectBrowser;
449 XGUI_PropertyPanel* myPropertyPanel;
450 XGUI_SelectionMgr* mySelector;
451 XGUI_Displayer* myDisplayer;
452 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
453 XGUI_ActionsMgr* myActionsMgr;
454 XGUI_SalomeConnector* mySalomeConnector;
455 XGUI_ErrorDialog* myErrorDlg;
456 XGUI_ViewerProxy* myViewerProxy;
457 XGUI_ContextMenuMgr* myContextMenuMgr;
458 XGUI_ModuleConnector* myModuleConnector;
459 XGUI_WorkshopListener* myEventsListener;
461 QString myCurrentDir;