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;
51 /**\class XGUI_Workshop
53 * \brief Class which defines a configuration of the application (Workshop) and launches it.
55 class XGUI_EXPORT XGUI_Workshop : public QObject
60 /// \param theConnector a Salome connector object.
61 /// Used only if the workshop is launched in Salome environment
62 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
63 virtual ~XGUI_Workshop();
65 //! Starting of the application
66 void startApplication();
68 /// Activates the module controls. Should be called after module creation
69 void activateModule();
71 /// Deactivates the module controls. Should be called after module creation
72 void deactivateModule();
75 //! Returns main window (Desktop) of the application
76 AppElements_MainWindow* mainWindow() const
81 //! Creates and adds a new workbench (menu group) with the given name and returns it
82 AppElements_Workbench* addWorkbench(const QString& theName);
85 //! Returns selection manager object
86 XGUI_SelectionMgr* selector() const
92 XGUI_Displayer* displayer() const
97 //! ! Returns operation manager.
98 XGUI_OperationMgr* operationMgr() const
100 return myOperationMgr;
103 //! ! Returns error manager.
104 XGUI_ErrorMgr* errorMgr() const
109 //! ! Returns an actions manager
110 XGUI_ActionsMgr* actionsMgr() const
115 //! Returns property panel widget
116 XGUI_PropertyPanel* propertyPanel() const
118 return myPropertyPanel;
121 //! Returns context menu manager object
122 XGUI_ContextMenuMgr* contextMenuMgr() const
124 return myContextMenuMgr;
127 //! Returns an object which provides interface to Salome Module (LightApp_Module)
128 XGUI_SalomeConnector* salomeConnector() const
130 return mySalomeConnector;
133 //! Provides an object which provides interface to Salome Viewer
134 ModuleBase_IViewer* salomeViewer() const;
136 //! Returns true if the application works as SALOME module
137 bool isSalomeMode() const
139 return mySalomeConnector != 0;
142 //! Returns Object browser
143 XGUI_ObjectsBrowser* objectBrowser() const
145 return myObjectBrowser;
148 /// This method is called by Salome module when selection is changed
149 void salomeViewerSelectionChanged();
151 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
152 XGUI_ViewerProxy* viewer() const
154 return myViewerProxy;
157 /// Returns the module connector
158 /// \returns the instance of connector
159 XGUI_ModuleConnector* moduleConnector() const
161 return myModuleConnector;
164 /// Returns a desktop
165 /// \return a desktop instance
166 QMainWindow* desktop() const;
169 void deleteObjects();
171 //! Returns true if the selected feature can be moved to the position after the current feature
172 //! \return boolean value
173 bool canMoveFeature();
175 //! Move selected features to be after the current feature
178 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
179 //! checks subobjects of the result
180 //! \return boolean value
181 bool canBeShaded(const ObjectPtr& theObject) const;
183 //! Returns true if there is at least one selected body/construction/group result
184 //! \return boolean value
185 bool canChangeColor() const;
187 //! Change color of the features if it is possible
188 //! The operation is available for construction, body and group results
189 //! theObjects a list of selected objects
190 void changeColor(const QObjectPtrList& theObjects);
192 //! Show the given features in 3d Viewer
193 void showObjects(const QObjectPtrList& theList, bool isVisible);
195 //! Show the given features in 3d Viewer
196 void showOnlyObjects(const QObjectPtrList& theList);
198 /// Set display mode for the given objects
199 /// \param theList a list of displayed objects
200 /// \param theMode a mode to set (see \ref XGUI_Displayer)
201 void setDisplayMode(const QObjectPtrList& theList, int theMode);
203 /// Returns current module
204 ModuleBase_IModule* module() const
209 /// Returns current directory which contains data files
210 QString currentDataDir() const { return myCurrentDir; }
212 /// Returns current directory which contains data files
213 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
216 * Save the current document into a directory
217 * \param theName - path to the directory
218 * \param theFileNames - returned file names created in this directory
220 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
223 * If there is an active (uncommitted) operation shows a prompt to abort it
224 * and performs abortion if user agreed. Returns true if
225 * - operation aborted successfully
226 * - there is no active operation
228 bool abortAllOperations();
230 //! Delete features. Delete the referenced features. There can be a question with a list of referenced
232 //! \param theList an objects to be deleted
233 //! \param theIgnoredFeatures a list of features to be ignored during delete
234 //! \param theParent a parent widget for the question message box
235 //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
236 //! objects features appear. If the user chose do not continue, the deletion is not performed
237 //! \return the success of the delete
238 bool deleteFeatures(const QObjectPtrList& theList,
239 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
240 QWidget* theParent = 0,
241 const bool theAskAboutDeleteReferences = false);
243 /// Deactivates the object, if it is active and the module returns that the activation
244 /// of selection for the object is not possible currently(the current operation uses it)
245 /// \param theObject an object
246 /// \param theUpdateViewer a boolean flag to update viewer immediately
247 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
249 /// Returns true if the action of the feature is created to contain Accept/Cancel button
250 /// \param theFeature a feature
251 bool isFeatureOfNested(const FeaturePtr& theFeature);
253 /// Has to be called in order to display objects with visibility status = true
254 void synchronizeViewer();
256 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
257 /// \param theDoc the document for objects synchronisation
258 /// \param theGroup the group name
259 /// \param theUpdateViewer update viewer flag
260 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
262 /// A constant string used for "Move to end" command definition
263 /// It is used for specific processing of Undo/Redo for this command.
264 static QString MOVE_TO_END_COMMAND;
267 /// Emitted when selection happens in Salome viewer
268 void salomeViewerSelection();
270 /// Emitted when error in application happens
271 void errorOccurred(const QString&);
273 //! the signal about the workshop actions states are updated.
274 void commandStatusUpdated();
276 //! the application is started
277 void applicationStarted();
279 //! Signal to update Undo history list
280 void updateUndoHistory(const QList<ActionInfo>&);
282 //! Signal to update Redo history list
283 void updateRedoHistory(const QList<ActionInfo>&);
286 /// Update of commands status
287 void updateCommandStatus();
289 /// update history list (undo/redo commands)
290 void updateHistory();
292 /// Save current document
295 /// Save current document to a file selected by user
298 /// Undo last command
299 void onUndo(int times = 1);
301 /// Redo previous command
302 void onRedo(int times = 1);
307 /// Validates the operation to change the "Apply" button state.
308 /// \param thePreviousState the previous state of the widget
309 void onWidgetStateChanged(int thePreviousState);
311 /// Show property panel
312 void showPropertyPanel();
314 /// Hide property panel
315 void hidePropertyPanel();
317 /// Show object Browser
318 void showObjectBrowser();
320 /// Hide object Browser
321 void hideObjectBrowser();
324 void closeDocument();
326 /// Open document from file
329 /// Create a new document
336 /// Open preferences dialog box
337 void onPreferences();
340 /// Activates/deactivates the trihedron in the viewer AIS context
341 void onTrihedronVisibilityChanged(bool theState);
344 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
345 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
346 /// \param theOperation an operation
347 void setGrantedFeatures(ModuleBase_Operation* theOperation);
349 /// Update the property panel content by the XML description of the operation and set the panel
350 /// into the operation
351 /// \param theOperation an operation
352 void setPropertyPanel(ModuleBase_Operation* theOperation);
354 /// Connects or disconnects to the value changed signal of the property panel widgets
355 /// \param isToConnect a boolean value whether connect or disconnect
356 void connectToPropertyPanel(const bool isToConnect);
359 /// Display all results
360 //void displayAllResults();
362 /// Display results from document
363 /// \param theDoc a document
364 void displayDocumentResults(DocumentPtr theDoc);
366 /// Display results from a group
367 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
370 /// SLOT, that is called after the operation is started. Update workshop state according to
371 /// the started operation, e.g. visualizes the property panel and connect to it.
372 /// \param theOpertion a started operation
373 void onOperationStarted(ModuleBase_Operation* theOperation);
375 /// SLOT, that is called after the operation is resumed. Update workshop state according to
376 /// the started operation, e.g. visualizes the property panel and connect to it.
377 /// \param theOpertion a resumed operation
378 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
380 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
381 /// hides the property panel and update the command status.
382 /// \param theOpertion a stopped operation
383 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
385 /// SLOT, that is called after the operation is committed.
386 /// \param theOpertion a committed operation
387 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
389 /// SLOT, that is called after the operation is aborted.
390 /// \param theOpertion an aborted operation
391 void onOperationAborted(ModuleBase_Operation* theOperation);
393 /// Slot, which reacts to the context popup menu call
394 /// \param theId the data value of the clicked action
395 /// \param isChecked a state of toggle if the action is checkable
396 void onContextMenuCommand(const QString& theId, bool isChecked);
398 /// Set waiting cursor
399 void onStartWaiting();
401 /// Called by Ok button clicked in the property panel. Asks the error manager whether
402 /// the operation can be committed and do it if it returns true.
403 void onAcceptActionClicked();
409 /// Register validators
410 void registerValidators() const;
412 /// Load module from external library
413 /// \param theModule name of the module
414 ModuleBase_IModule* loadModule(const QString& theModule);
419 /// Create object browser widget
420 /// \param theParent a parent of widget
421 QDockWidget* createObjectBrowser(QWidget* theParent);
423 /// Create property panel widget
424 /// \param theParent a parent of widget
425 QDockWidget* createPropertyPanel(QWidget* theParent);
427 // Creates Dock widgets: Object browser and Property panel
428 void createDockWidgets();
430 //! Extends undo/redo toolbutton's with history menu
431 //! \param theObject - in the OpenParts it is a QToolButton by itself,
432 //! in salome mode - QAction that creates a button.
433 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
434 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
435 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
437 //! Creates list of actions (commands) by given history list from session
438 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
442 AppElements_MainWindow* myMainWindow;
445 ModuleBase_IModule* myModule;
446 XGUI_ErrorMgr* myErrorMgr;
447 XGUI_ObjectsBrowser* myObjectBrowser;
448 XGUI_PropertyPanel* myPropertyPanel;
449 XGUI_SelectionMgr* mySelector;
450 XGUI_Displayer* myDisplayer;
451 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
452 XGUI_ActionsMgr* myActionsMgr;
453 XGUI_SalomeConnector* mySalomeConnector;
454 XGUI_ErrorDialog* myErrorDlg;
455 XGUI_ViewerProxy* myViewerProxy;
456 XGUI_ContextMenuMgr* myContextMenuMgr;
457 XGUI_ModuleConnector* myModuleConnector;
458 XGUI_WorkshopListener* myEventsListener;
460 QString myCurrentDir;