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 //! Searches for selected features unused in other (not selected) features. If one or several
172 //! selected features are found, a warning message proposes to delete them. It contains
173 //! the list of features to be deleted.
176 //! Returns true if the selected feature can be moved to the position after the current feature
177 //! \return boolean value
178 bool canMoveFeature();
180 //! Move selected features to be after the current feature
183 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
184 //! checks subobjects of the result
185 //! \return boolean value
186 bool canBeShaded(const ObjectPtr& theObject) const;
188 //! Returns true if there is at least one selected body/construction/group result
189 //! \return boolean value
190 bool canChangeColor() const;
192 //! Change color of the features if it is possible
193 //! The operation is available for construction, body and group results
194 //! theObjects a list of selected objects
195 void changeColor(const QObjectPtrList& theObjects);
197 //! Show the given features in 3d Viewer
198 void showObjects(const QObjectPtrList& theList, bool isVisible);
200 //! Show the given features in 3d Viewer
201 void showOnlyObjects(const QObjectPtrList& theList);
203 /// Set display mode for the given objects
204 /// \param theList a list of displayed objects
205 /// \param theMode a mode to set (see \ref XGUI_Displayer)
206 void setDisplayMode(const QObjectPtrList& theList, int theMode);
208 /// Set selection mode in viewer. If theMode=-1 then activate default mode
209 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
210 void setViewerSelectionMode(int theMode);
212 /// Activates current selection mode for the given list of objects
213 void activateObjectsSelection(const QObjectPtrList& theList);
215 /// Returns current module
216 ModuleBase_IModule* module() const
221 /// Returns current directory which contains data files
222 QString currentDataDir() const { return myCurrentDir; }
224 /// Returns current directory which contains data files
225 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
228 * Save the current document into a directory
229 * \param theName - path to the directory
230 * \param theFileNames - returned file names created in this directory
232 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
235 * If there is an active (uncommitted) operation shows a prompt to abort it
236 * and performs abortion if user agreed. Returns true if
237 * - operation aborted successfully
238 * - there is no active operation
240 bool abortAllOperations();
242 //! Delete features. Delete the referenced features. There can be a question with a list of
243 //! referenced objects.
244 //! \param theList an objects to be deleted
245 //! \param theIgnoredFeatures a list of features to be ignored during delete
246 bool deleteFeatures(const QObjectPtrList& theFeatures,
247 const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>());
249 /// Deactivates the object, if it is active and the module returns that the activation
250 /// of selection for the object is not possible currently(the current operation uses it)
251 /// \param theObject an object
252 /// \param theUpdateViewer a boolean flag to update viewer immediately
253 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
255 /// Returns true if the action of the feature is created to contain Accept/Cancel button
256 /// \param theFeature a feature
257 bool isFeatureOfNested(const FeaturePtr& theFeature);
259 /// Has to be called in order to display objects with visibility status = true
260 void synchronizeViewer();
262 /// Has to be called in order to display objects from a cpecifed group with visibility status = true
263 /// \param theDoc the document for objects synchronisation
264 /// \param theGroup the group name
265 /// \param theUpdateViewer update viewer flag
266 void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
268 /// Update the property panel content by the XML description of the operation and set the panel
269 /// into the operation
270 /// \param theOperation an operation
271 void setPropertyPanel(ModuleBase_Operation* theOperation);
273 /// Connects or disconnects to the value changed signal of the property panel widgets
274 /// \param isToConnect a boolean value whether connect or disconnect
275 void connectToPropertyPanel(const bool isToConnect);
277 /// A constant string used for "Move to end" command definition
278 /// It is used for specific processing of Undo/Redo for this command.
279 static QString MOVE_TO_END_COMMAND;
282 /// Emitted when selection happens in Salome viewer
283 void salomeViewerSelection();
285 /// Emitted when error in application happens
286 void errorOccurred(const QString&);
288 //! the signal about the workshop actions states are updated.
289 void commandStatusUpdated();
291 //! the application is started
292 void applicationStarted();
294 //! Signal to update Undo history list
295 void updateUndoHistory(const QList<ActionInfo>&);
297 //! Signal to update Redo history list
298 void updateRedoHistory(const QList<ActionInfo>&);
301 /// Update of commands status
302 void updateCommandStatus();
304 /// update history list (undo/redo commands)
305 void updateHistory();
307 /// Save current document
310 /// Save current document to a file selected by user
313 /// Undo last command
314 void onUndo(int times = 1);
316 /// Redo previous command
317 void onRedo(int times = 1);
322 /// Validates the operation to change the "Apply" button state.
323 /// \param thePreviousState the previous state of the widget
324 void onWidgetStateChanged(int thePreviousState);
326 /// Calls activate of the current widget again. It is possible that selection filters are
327 /// differs in the new state of paged container
328 void onValuesChanged();
330 /// Show property panel
331 void showPropertyPanel();
333 /// Hide property panel
334 void hidePropertyPanel();
336 /// Show object Browser
337 void showObjectBrowser();
339 /// Hide object Browser
340 void hideObjectBrowser();
343 void closeDocument();
345 /// Open document from file
348 /// Create a new document
355 /// Open preferences dialog box
356 void onPreferences();
359 /// Activates/deactivates the trihedron in the viewer AIS context
360 void onTrihedronVisibilityChanged(bool theState);
362 /// Returns defailt selection mode in 3d viewer
363 int viewerSelectionMode() const { return myViewerSelMode; }
367 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
368 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
369 /// \param theOperation an operation
370 void setGrantedFeatures(ModuleBase_Operation* theOperation);
372 //! Find all referenced features. Return direct and indirect lists of referenced object
373 //! \param theList an objects to be checked
374 //! \param aDirectRefFeatures a list of direct reference features
375 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
376 void findReferences(const QObjectPtrList& theList,
377 std::set<FeaturePtr>& aDirectRefFeatures,
378 std::set<FeaturePtr>& aIndirectRefFeatures);
380 //! Shows a dialog box about references. Ask whether they should be also removed.
381 //! \param theList an objects to be checked
382 //! \param aDirectRefFeatures a list of direct reference features
383 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
384 //! \param theParent a parent widget for the question message box
385 //! \param doDeleteReferences if there are parameters between features, ask if they should be
386 //! replaced to their meaning without corresponded features remove
387 //! \return true if in message box answer is Yes
388 bool isDeleteFeatureWithReferences(const QObjectPtrList& theList,
389 const std::set<FeaturePtr>& aDirectRefFeatures,
390 const std::set<FeaturePtr>& aIndirectRefFeatures,
392 bool& doDeleteReferences);
394 //! \param theIgnoredFeatures a list of features to be ignored during delete
395 //! \param theList an objects to be checked
396 //! \param aDirectRefFeatures a list of direct reference features
397 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
398 //! \param doDeleteReferences flag if referenced features should be removed also
399 bool deleteFeaturesInternal(const QObjectPtrList& theList,
400 const std::set<FeaturePtr>& aDirectRefFeatures,
401 const std::set<FeaturePtr>& aIndirectRefFeatures,
402 const std::set<FeaturePtr>& theIgnoredFeatures,
403 const bool doDeleteReferences = true);
406 /// Display all results
407 //void displayAllResults();
409 /// Display results from document
410 /// \param theDoc a document
411 void displayDocumentResults(DocumentPtr theDoc);
413 /// Display results from a group
414 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
417 /// SLOT, that is called after the operation is started. Update workshop state according to
418 /// the started operation, e.g. visualizes the property panel and connect to it.
419 /// \param theOpertion a started operation
420 void onOperationStarted(ModuleBase_Operation* theOperation);
422 /// SLOT, that is called after the operation is resumed. Update workshop state according to
423 /// the started operation, e.g. visualizes the property panel and connect to it.
424 /// \param theOpertion a resumed operation
425 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
427 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
428 /// hides the property panel and update the command status.
429 /// \param theOpertion a stopped operation
430 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
432 /// SLOT, that is called after the operation is committed.
433 /// \param theOpertion a committed operation
434 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
436 /// SLOT, that is called after the operation is aborted.
437 /// \param theOpertion an aborted operation
438 void onOperationAborted(ModuleBase_Operation* theOperation);
440 /// Slot, which reacts to the context popup menu call
441 /// \param theId the data value of the clicked action
442 /// \param isChecked a state of toggle if the action is checkable
443 void onContextMenuCommand(const QString& theId, bool isChecked);
445 /// Set waiting cursor
446 void onStartWaiting();
448 /// Called by Ok button clicked in the property panel. Asks the error manager whether
449 /// the operation can be committed and do it if it returns true.
450 void onAcceptActionClicked();
456 /// Register validators
457 void registerValidators() const;
459 /// Load module from external library
460 /// \param theModule name of the module
461 ModuleBase_IModule* loadModule(const QString& theModule);
466 /// Create object browser widget
467 /// \param theParent a parent of widget
468 QDockWidget* createObjectBrowser(QWidget* theParent);
470 /// Create property panel widget
471 /// \param theParent a parent of widget
472 QDockWidget* createPropertyPanel(QWidget* theParent);
474 // Creates Dock widgets: Object browser and Property panel
475 void createDockWidgets();
477 //! Extends undo/redo toolbutton's with history menu
478 //! \param theObject - in the OpenParts it is a QToolButton by itself,
479 //! in salome mode - QAction that creates a button.
480 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
481 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
482 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
485 /// Calls removeFeature of the document for each object in the list
486 //! \param theList an objects to be deleted
487 //! \param theIgnoredFeatures a list of features to be ignored during delete
488 //! \param theActionId an action command key to find context menu object types enabled for remove
489 bool removeFeatures(const QObjectPtrList& theList,
490 const std::set<FeaturePtr>& theIgnoredFeatures,
491 const QString& theActionId);
493 //! Creates list of actions (commands) by given history list from session
494 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
498 AppElements_MainWindow* myMainWindow;
501 ModuleBase_IModule* myModule;
502 XGUI_ErrorMgr* myErrorMgr;
503 XGUI_ObjectsBrowser* myObjectBrowser;
504 XGUI_PropertyPanel* myPropertyPanel;
505 XGUI_SelectionMgr* mySelector;
506 XGUI_Displayer* myDisplayer;
507 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
508 XGUI_ActionsMgr* myActionsMgr;
509 XGUI_SalomeConnector* mySalomeConnector;
510 XGUI_ErrorDialog* myErrorDlg;
511 XGUI_ViewerProxy* myViewerProxy;
512 XGUI_ContextMenuMgr* myContextMenuMgr;
513 XGUI_ModuleConnector* myModuleConnector;
514 XGUI_WorkshopListener* myEventsListener;
516 QString myCurrentDir;