1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_WORKSHOP_H
22 #define XGUI_WORKSHOP_H
25 //#include "XGUI_Constants.h"
26 #include <ModuleBase_Definitions.h>
27 #include <ModelAPI_Document.h>
28 #include <ModelAPI_Feature.h>
30 #include <ModuleBase_ActionInfo.h>
34 #include <QKeySequence>
38 class AppElements_MainWindow;
39 class AppElements_Command;
40 class AppElements_Workbench;
43 class XGUI_ActionsMgr;
44 class XGUI_ActiveControlMgr;
45 class XGUI_ContextMenuMgr;
47 class XGUI_ErrorDialog;
49 class XGUI_FacesPanel;
51 class XGUI_ModuleConnector;
52 class XGUI_ObjectsBrowser;
53 class XGUI_OperationMgr;
54 class XGUI_PropertyPanel;
55 class XGUI_SalomeConnector;
56 class XGUI_SalomeViewer;
57 class XGUI_SelectionMgr;
58 class XGUI_ViewerProxy;
59 class XGUI_WorkshopListener;
61 class ModuleBase_IModule;
62 class ModuleBase_IViewer;
63 class ModuleBase_Operation;
70 class Config_DataModelReader;
72 /**\class XGUI_Workshop
74 * \brief Class which defines a configuration of the application (Workshop) and launches it.
76 class XGUI_EXPORT XGUI_Workshop : public QObject
81 /// \param theConnector a Salome connector object.
82 /// Used only if the workshop is launched in Salome environment
83 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
84 virtual ~XGUI_Workshop();
86 //! Starting of the application
87 void startApplication();
89 /// Activates the module controls. Should be called after module creation
90 void activateModule();
92 /// Deactivates the module controls. Should be called after module creation
93 void deactivateModule();
96 //! Returns main window (Desktop) of the application
97 AppElements_MainWindow* mainWindow() const
102 //! Creates and adds a new workbench (menu group) with the given name and returns it
103 AppElements_Workbench* addWorkbench(const QString& theName);
106 //! Returns selection manager object
107 XGUI_SelectionMgr* selector() const
112 //! Returns displayer
113 XGUI_Displayer* displayer() const
118 //! ! Returns operation manager.
119 XGUI_OperationMgr* operationMgr() const
121 return myOperationMgr;
124 //! ! Returns error manager.
125 XGUI_ErrorMgr* errorMgr() const
130 //! ! Returns an actions manager
131 XGUI_ActionsMgr* actionsMgr() const
136 //! ! Returns an active control manager
137 XGUI_ActiveControlMgr* activeControlMgr() const
139 return myActiveControlMgr;
142 //! ! Returns an actions manager
143 XGUI_MenuMgr* menuMgr() const
148 //! Returns property panel widget
149 XGUI_PropertyPanel* propertyPanel() const
151 return myPropertyPanel;
154 //! Returns panel for hide object faces
155 XGUI_FacesPanel* facesPanel() const
160 //! Returns context menu manager object
161 XGUI_ContextMenuMgr* contextMenuMgr() const
163 return myContextMenuMgr;
166 //! Returns an object which provides interface to Salome Module (LightApp_Module)
167 XGUI_SalomeConnector* salomeConnector() const
169 return mySalomeConnector;
172 //! Provides an object which provides interface to Salome Viewer
173 ModuleBase_IViewer* salomeViewer() const;
175 //! Returns true if the application works as SALOME module
176 bool isSalomeMode() const
178 return mySalomeConnector != 0;
181 //! Returns Object browser
182 XGUI_ObjectsBrowser* objectBrowser() const
184 return myObjectBrowser;
187 /// This method is called by Salome module when selection is changed
188 void salomeViewerSelectionChanged();
190 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
191 XGUI_ViewerProxy* viewer() const
193 return myViewerProxy;
196 /// Returns the module connector
197 /// \returns the instance of connector
198 XGUI_ModuleConnector* moduleConnector() const
200 return myModuleConnector;
203 /// Returns a desktop
204 /// \return a desktop instance
205 QMainWindow* desktop() const;
207 /// If faces panel made the object hidden, show message box whether the object should be
208 /// restored (removed from the panel) and displayed, if answer is No, returns false
209 /// \param theObject a model object
210 /// \return boolean state if the object should not be displayed
211 virtual bool prepareForDisplay(const std::set<ObjectPtr>& theObjects) const;
214 void deleteObjects();
216 //! Searches for selected features unused in other (not selected) features. If one or several
217 //! selected features are found, a warning message proposes to delete them. It contains
218 //! the list of features to be deleted.
221 //! Returns true if the selected feature can be moved to the position after the current feature
222 //! \return boolean value
223 bool canMoveFeature();
225 //! Move selected features to be after the current feature
228 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
229 //! checks subobjects of the result
230 //! \return boolean value
231 bool canBeShaded(const ObjectPtr& theObject) const;
233 //! Returns true if there is at least one selected body/construction/group result
234 //! \param theActionName text of the checked action
235 //! \return boolean value
236 bool canChangeProperty(const QString& theActionName) const;
238 //! Change color of the results if it is possible
239 //! The operation is available for construction, body and group results
240 //! theObjects a list of selected objects
241 void changeColor(const QObjectPtrList& theObjects);
243 //! Change deflection of the results if it is possible
244 //! The operation is available for construction, body and group results
245 //! theObjects a list of selected objects
246 void changeDeflection(const QObjectPtrList& theObjects);
248 //! Change transparency of the results if it is possible
249 //! The operation is available for construction, body and group results
250 //! theObjects a list of selected objects
251 void changeTransparency(const QObjectPtrList& theObjects);
253 //! Show the given features in 3d Viewer
254 void showObjects(const QObjectPtrList& theList, bool isVisible);
256 //! Show the given features in 3d Viewer
257 void showOnlyObjects(const QObjectPtrList& theList);
259 /// Set display mode for the given objects
260 /// \param theList a list of displayed objects
261 /// \param theMode a mode to set (see \ref XGUI_Displayer)
262 void setDisplayMode(const QObjectPtrList& theList, int theMode);
264 /// Set selection mode in viewer. If theMode=-1 then activate default mode
265 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
266 void setViewerSelectionMode(int theMode);
268 /// Activates current selection mode for the given list of objects
269 void activateObjectsSelection(const QObjectPtrList& theList);
271 /// Returns current module
272 ModuleBase_IModule* module() const
277 /// Returns current directory which contains data files
278 QString currentDataDir() const { return myCurrentDir; }
280 /// Returns current directory which contains data files
281 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
284 * Save the current document into a directory
285 * \param theName - path to the directory
286 * \param theFileNames - returned file names created in this directory
288 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
291 * If there is an active (uncommitted) operation shows a prompt to abort it
292 * and performs abortion if user agreed. Returns true if
293 * - operation aborted successfully
294 * - there is no active operation
296 bool abortAllOperations();
298 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
299 /// and connect to it.
300 /// \param theOpertion a started operation
301 void operationStarted(ModuleBase_Operation* theOperation);
304 //! Delete features. Delete the referenced features. There can be a question with a list of
305 //! referenced objects.
306 //! \param theFeatures a list of objects to be deleted
307 bool deleteFeatures(const QObjectPtrList& theFeatures);
309 /// Deactivates the object, if it is active and the module returns that the activation
310 /// of selection for the object is not possible currently(the current operation uses it)
311 /// \param theObject an object
312 /// \param theUpdateViewer a boolean flag to update viewer immediately
313 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
315 /// Returns true if the action of the feature is created to contain Accept/Cancel button
316 /// \param theFeature a feature
317 bool isFeatureOfNested(const FeaturePtr& theFeature);
319 //! Shows the message in the status bar
320 //! \param theMessage a message
321 void setStatusBarMessage(const QString& theMessage);
323 /// Has to be called in order to display objects with visibility status = true
324 void synchronizeViewer();
326 /// Has to be called in order to display objects from a specifed group
327 /// with visibility status = true
328 /// \param theDoc the document for objects synchronisation
329 /// \param theGroup the group name
330 /// \param theUpdateViewer update viewer flag
331 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
332 const std::string& theGroup,
333 bool theUpdateViewer);
335 /// Update the property panel content by the XML description of the operation and set the panel
336 /// into the operation
337 /// \param theOperation an operation
338 void fillPropertyPanel(ModuleBase_Operation* theOperation);
340 /// Connects or disconnects to the value changed signal of the property panel widgets
341 /// \param isToConnect a boolean value whether connect or disconnect
342 void connectToPropertyPanel(const bool isToConnect);
344 /// Returns defailt selection mode in 3d viewer
345 QIntList viewerSelectionModes() const { return myViewerSelMode; }
347 /// Highlights result objects in Object Browser according to
348 /// features found in the given list
349 void highlightResults(const QObjectPtrList& theObjects);
351 /// Highlights feature objects in Object Browser according to
352 /// features found in the given list
353 void highlightFeature(const QObjectPtrList& theObjects);
355 /// Returns Data Model XML reader which contains information about
356 /// Data structure configuration
357 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
359 /// A constant string used for "Move to end" command definition
360 /// It is used for specific processing of Undo/Redo for this command.
361 static QString MOVE_TO_END_COMMAND;
363 //! Closes all in the current session and load the directory
364 //! \param theDirectory a path to directory
365 void openDirectory(const QString& theDirectory);
368 /// Emitted when selection happens in Salome viewer
369 void salomeViewerSelection();
371 //! the signal about the workshop actions states are updated.
372 void commandStatusUpdated();
374 //! the application is started
375 void applicationStarted();
377 //! Signal to update Undo history list
378 void updateUndoHistory(const QList<ActionInfo>&);
380 //! Signal to update Redo history list
381 void updateRedoHistory(const QList<ActionInfo>&);
384 /// Update of commands status
385 void updateCommandStatus();
387 /// update history list (undo/redo commands)
388 void updateHistory();
390 /// Save current document
393 /// Save current document to a file selected by user
396 /// Undo last command
397 void onUndo(int times = 1);
399 /// Redo previous command
400 void onRedo(int times = 1);
402 /// Validates the operation to change the "Apply" button state.
403 /// \param thePreviousState the previous state of the widget
404 void onWidgetStateChanged(int thePreviousState);
406 /// Calls activate of the current widget again. It is possible that selection filters are
407 /// differs in the new state of paged container
408 void onValuesChanged();
410 /// Listens the corresponded signal of model widget and updates Apply button state by feature
411 void onWidgetObjectUpdated();
413 /// Show dock widget panel
414 void showPanel(QDockWidget* theDockWidget);
416 /// Hide dock widget panel
417 void hidePanel(QDockWidget* theDockWidget);
419 /// Show object Browser
420 void showObjectBrowser();
422 /// Hide object Browser
423 void hideObjectBrowser();
426 void closeDocument();
428 /// Open document from file
431 /// Create a new document
438 /// Open preferences dialog box
439 void onPreferences();
442 /// Activates/deactivates the trihedron in the viewer AIS context
443 void onTrihedronVisibilityChanged(bool theState);
445 /// Apply the current transparency value if preview in transparency dialog is switched on
446 void onTransparencyValueChanged();
448 /// Switch on/off preview of transparency change
449 void onPreviewStateChanged();
452 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
453 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
454 /// \param theOperation an operation
455 void setGrantedFeatures(ModuleBase_Operation* theOperation);
458 /// Display all results
459 //void displayAllResults();
461 /// Display results from document
462 /// \param theDoc a document
463 void displayDocumentResults(DocumentPtr theDoc);
465 /// Display results from a group
466 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
468 /// Insert folder object before currently selected feature
469 void insertFeatureFolder();
471 /// Insert an object to a folder above or below
472 void insertToFolder(bool isBefore);
474 /// Insert an object to a folder above or below
475 void moveOutFolder(bool isBefore);
478 /// SLOT, that is called after the operation is started. Update workshop state according to
479 /// the started operation, e.g. visualizes the property panel and connect to it.
480 /// \param theOpertion a started operation
481 // void onOperationStarted(ModuleBase_Operation* theOperation);
483 /// SLOT, that is called after the operation is resumed. Update workshop state according to
484 /// the started operation, e.g. visualizes the property panel and connect to it.
485 /// \param theOpertion a resumed operation
486 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
488 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
489 /// hides the property panel and update the command status.
490 /// \param theOpertion a stopped operation
491 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
493 /// SLOT, that is called after the operation is committed.
494 /// \param theOpertion a committed operation
495 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
497 /// SLOT, that is called after the operation is aborted.
498 /// \param theOpertion an aborted operation
499 void onOperationAborted(ModuleBase_Operation* theOperation);
501 /// Slot, which reacts to the context popup menu call
502 /// \param theId the data value of the clicked action
503 /// \param isChecked a state of toggle if the action is checkable
504 void onContextMenuCommand(const QString& theId, bool isChecked);
506 /// Set waiting cursor
507 void onStartWaiting();
509 /// Called by Ok button clicked in the property panel. Asks the error manager whether
510 /// the operation can be committed and do it if it returns true.
511 void onAcceptActionClicked();
513 /// Called by Preview button clicked in the property panel. Sends signal to model to
515 void onPreviewActionClicked();
521 /// Register validators
522 void registerValidators() const;
524 /// Load module from external library
525 /// \param theModule name of the module
526 ModuleBase_IModule* loadModule(const QString& theModule);
531 /// Create object browser widget
532 /// \param theParent a parent of widget
533 QDockWidget* createObjectBrowser(QWidget* theParent);
535 /// Create property panel widget
536 /// \param theParent a parent of widget
537 QDockWidget* createPropertyPanel(QWidget* theParent);
539 // Creates Dock widgets: Object browser and Property panel
540 void createDockWidgets();
542 //! Extends undo/redo toolbutton's with history menu
543 //! \param theObject - in the OpenParts it is a QToolButton by itself,
544 //! in salome mode - QAction that creates a button.
545 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
546 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
547 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
549 //! Creates list of actions (commands) by given history list from session
550 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
554 AppElements_MainWindow* myMainWindow;
557 ModuleBase_IModule* myModule;
558 XGUI_ErrorMgr* myErrorMgr;
559 XGUI_ObjectsBrowser* myObjectBrowser;
560 XGUI_PropertyPanel* myPropertyPanel;
561 XGUI_FacesPanel* myFacesPanel; //< panel for hide object faces
562 XGUI_SelectionMgr* mySelector;
563 XGUI_Displayer* myDisplayer;
564 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
565 XGUI_ActionsMgr* myActionsMgr;
566 XGUI_ActiveControlMgr* myActiveControlMgr; ///< manager to have none or one active control
567 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
568 XGUI_SalomeConnector* mySalomeConnector;
569 XGUI_ErrorDialog* myErrorDlg;
570 XGUI_ViewerProxy* myViewerProxy;
571 XGUI_ContextMenuMgr* myContextMenuMgr;
572 XGUI_ModuleConnector* myModuleConnector;
573 XGUI_WorkshopListener* myEventsListener;
575 QString myCurrentDir;
577 QIntList myViewerSelMode;
579 Config_DataModelReader* myDataModelXMLReader;