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_ContextMenuMgr;
46 class XGUI_ErrorDialog;
49 class XGUI_ModuleConnector;
50 class XGUI_ObjectsBrowser;
51 class XGUI_OperationMgr;
52 class XGUI_PropertyPanel;
53 class XGUI_SalomeConnector;
54 class XGUI_SalomeViewer;
55 class XGUI_SelectionMgr;
56 class XGUI_ViewerProxy;
57 class XGUI_WorkshopListener;
59 class ModuleBase_IModule;
60 class ModuleBase_IViewer;
61 class ModuleBase_Operation;
68 class Config_DataModelReader;
70 /**\class XGUI_Workshop
72 * \brief Class which defines a configuration of the application (Workshop) and launches it.
74 class XGUI_EXPORT XGUI_Workshop : public QObject
79 /// \param theConnector a Salome connector object.
80 /// Used only if the workshop is launched in Salome environment
81 XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0);
82 virtual ~XGUI_Workshop();
84 //! Starting of the application
85 void startApplication();
87 /// Activates the module controls. Should be called after module creation
88 void activateModule();
90 /// Deactivates the module controls. Should be called after module creation
91 void deactivateModule();
94 //! Returns main window (Desktop) of the application
95 AppElements_MainWindow* mainWindow() const
100 //! Creates and adds a new workbench (menu group) with the given name and returns it
101 AppElements_Workbench* addWorkbench(const QString& theName);
104 //! Returns selection manager object
105 XGUI_SelectionMgr* selector() const
110 //! Returns displayer
111 XGUI_Displayer* displayer() const
116 //! ! Returns operation manager.
117 XGUI_OperationMgr* operationMgr() const
119 return myOperationMgr;
122 //! ! Returns error manager.
123 XGUI_ErrorMgr* errorMgr() const
128 //! ! Returns an actions manager
129 XGUI_ActionsMgr* actionsMgr() const
134 //! ! Returns an actions manager
135 XGUI_MenuMgr* menuMgr() const
140 //! Returns property panel widget
141 XGUI_PropertyPanel* propertyPanel() const
143 return myPropertyPanel;
146 //! Returns context menu manager object
147 XGUI_ContextMenuMgr* contextMenuMgr() const
149 return myContextMenuMgr;
152 //! Returns an object which provides interface to Salome Module (LightApp_Module)
153 XGUI_SalomeConnector* salomeConnector() const
155 return mySalomeConnector;
158 //! Provides an object which provides interface to Salome Viewer
159 ModuleBase_IViewer* salomeViewer() const;
161 //! Returns true if the application works as SALOME module
162 bool isSalomeMode() const
164 return mySalomeConnector != 0;
167 //! Returns Object browser
168 XGUI_ObjectsBrowser* objectBrowser() const
170 return myObjectBrowser;
173 /// This method is called by Salome module when selection is changed
174 void salomeViewerSelectionChanged();
176 /// Returns viewer which unifies access as to Salome viewer as to standalone viewer
177 XGUI_ViewerProxy* viewer() const
179 return myViewerProxy;
182 /// Returns the module connector
183 /// \returns the instance of connector
184 XGUI_ModuleConnector* moduleConnector() const
186 return myModuleConnector;
189 /// Returns a desktop
190 /// \return a desktop instance
191 QMainWindow* desktop() const;
194 void deleteObjects();
196 //! Searches for selected features unused in other (not selected) features. If one or several
197 //! selected features are found, a warning message proposes to delete them. It contains
198 //! the list of features to be deleted.
201 //! Returns true if the selected feature can be moved to the position after the current feature
202 //! \return boolean value
203 bool canMoveFeature();
205 //! Move selected features to be after the current feature
208 //! Returns true if the object can be shaded. If the object is a compsolid result, the method
209 //! checks subobjects of the result
210 //! \return boolean value
211 bool canBeShaded(const ObjectPtr& theObject) const;
213 //! Returns true if there is at least one selected body/construction/group result
214 //! \return boolean value
215 bool canChangeColor() const;
217 //! Change color of the results if it is possible
218 //! The operation is available for construction, body and group results
219 //! theObjects a list of selected objects
220 void changeColor(const QObjectPtrList& theObjects);
222 //! Returns true if there is at least one selected body/construction/group result
223 //! \return boolean value
224 bool canChangeDeflection() const;
226 //! Change deflection of the results if it is possible
227 //! The operation is available for construction, body and group results
228 //! theObjects a list of selected objects
229 void changeDeflection(const QObjectPtrList& theObjects);
231 //! Show the given features in 3d Viewer
232 void showObjects(const QObjectPtrList& theList, bool isVisible);
234 //! Show the given features in 3d Viewer
235 void showOnlyObjects(const QObjectPtrList& theList);
237 /// Set display mode for the given objects
238 /// \param theList a list of displayed objects
239 /// \param theMode a mode to set (see \ref XGUI_Displayer)
240 void setDisplayMode(const QObjectPtrList& theList, int theMode);
242 /// Set selection mode in viewer. If theMode=-1 then activate default mode
243 /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
244 void setViewerSelectionMode(int theMode);
246 /// Activates current selection mode for the given list of objects
247 void activateObjectsSelection(const QObjectPtrList& theList);
249 /// Returns current module
250 ModuleBase_IModule* module() const
255 /// Returns current directory which contains data files
256 QString currentDataDir() const { return myCurrentDir; }
258 /// Returns current directory which contains data files
259 void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; }
262 * Save the current document into a directory
263 * \param theName - path to the directory
264 * \param theFileNames - returned file names created in this directory
266 void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
269 * If there is an active (uncommitted) operation shows a prompt to abort it
270 * and performs abortion if user agreed. Returns true if
271 * - operation aborted successfully
272 * - there is no active operation
274 bool abortAllOperations();
276 /// Updates workshop state according to the started operation, e.g. visualizes the property panel
277 /// and connect to it.
278 /// \param theOpertion a started operation
279 void operationStarted(ModuleBase_Operation* theOperation);
282 //! Delete features. Delete the referenced features. There can be a question with a list of
283 //! referenced objects.
284 //! \param theFeatures a list of objects to be deleted
285 bool deleteFeatures(const QObjectPtrList& theFeatures);
287 /// Deactivates the object, if it is active and the module returns that the activation
288 /// of selection for the object is not possible currently(the current operation uses it)
289 /// \param theObject an object
290 /// \param theUpdateViewer a boolean flag to update viewer immediately
291 void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
293 /// Returns true if the action of the feature is created to contain Accept/Cancel button
294 /// \param theFeature a feature
295 bool isFeatureOfNested(const FeaturePtr& theFeature);
297 //! Shows the message in the status bar
298 //! \param theMessage a message
299 void setStatusBarMessage(const QString& theMessage);
301 /// Has to be called in order to display objects with visibility status = true
302 void synchronizeViewer();
304 /// Has to be called in order to display objects from a specifed group
305 /// with visibility status = true
306 /// \param theDoc the document for objects synchronisation
307 /// \param theGroup the group name
308 /// \param theUpdateViewer update viewer flag
309 void synchronizeGroupInViewer(const DocumentPtr& theDoc,
310 const std::string& theGroup,
311 bool theUpdateViewer);
313 /// Update the property panel content by the XML description of the operation and set the panel
314 /// into the operation
315 /// \param theOperation an operation
316 void fillPropertyPanel(ModuleBase_Operation* theOperation);
318 /// Connects or disconnects to the value changed signal of the property panel widgets
319 /// \param isToConnect a boolean value whether connect or disconnect
320 void connectToPropertyPanel(const bool isToConnect);
322 /// Returns defailt selection mode in 3d viewer
323 QIntList viewerSelectionModes() const { return myViewerSelMode; }
325 /// Highlights result objects in Object Browser according to
326 /// features found in the given list
327 void highlightResults(const QObjectPtrList& theObjects);
329 /// Highlights feature objects in Object Browser according to
330 /// features found in the given list
331 void highlightFeature(const QObjectPtrList& theObjects);
333 /// Returns Data Model XML reader which contains information about
334 /// Data structure configuration
335 const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
337 /// A constant string used for "Move to end" command definition
338 /// It is used for specific processing of Undo/Redo for this command.
339 static QString MOVE_TO_END_COMMAND;
341 //! Closes all in the current session and load the directory
342 //! \param theDirectory a path to directory
343 void openDirectory(const QString& theDirectory);
346 /// Emitted when selection happens in Salome viewer
347 void salomeViewerSelection();
349 //! the signal about the workshop actions states are updated.
350 void commandStatusUpdated();
352 //! the application is started
353 void applicationStarted();
355 //! Signal to update Undo history list
356 void updateUndoHistory(const QList<ActionInfo>&);
358 //! Signal to update Redo history list
359 void updateRedoHistory(const QList<ActionInfo>&);
362 /// Update of commands status
363 void updateCommandStatus();
365 /// update history list (undo/redo commands)
366 void updateHistory();
368 /// Save current document
371 /// Save current document to a file selected by user
374 /// Undo last command
375 void onUndo(int times = 1);
377 /// Redo previous command
378 void onRedo(int times = 1);
383 /// Validates the operation to change the "Apply" button state.
384 /// \param thePreviousState the previous state of the widget
385 void onWidgetStateChanged(int thePreviousState);
387 /// Calls activate of the current widget again. It is possible that selection filters are
388 /// differs in the new state of paged container
389 void onValuesChanged();
391 /// Listens the corresponded signal of model widget and updates Apply button state by feature
392 void onWidgetObjectUpdated();
394 /// Show property panel
395 void showPropertyPanel();
397 /// Hide property panel
398 void hidePropertyPanel();
400 /// Show object Browser
401 void showObjectBrowser();
403 /// Hide object Browser
404 void hideObjectBrowser();
407 void closeDocument();
409 /// Open document from file
412 /// Create a new document
419 /// Open preferences dialog box
420 void onPreferences();
423 /// Activates/deactivates the trihedron in the viewer AIS context
424 void onTrihedronVisibilityChanged(bool theState);
428 /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
429 /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
430 /// \param theOperation an operation
431 void setGrantedFeatures(ModuleBase_Operation* theOperation);
434 /// Display all results
435 //void displayAllResults();
437 /// Display results from document
438 /// \param theDoc a document
439 void displayDocumentResults(DocumentPtr theDoc);
441 /// Display results from a group
442 void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
445 /// SLOT, that is called after the operation is started. Update workshop state according to
446 /// the started operation, e.g. visualizes the property panel and connect to it.
447 /// \param theOpertion a started operation
448 // void onOperationStarted(ModuleBase_Operation* theOperation);
450 /// SLOT, that is called after the operation is resumed. Update workshop state according to
451 /// the started operation, e.g. visualizes the property panel and connect to it.
452 /// \param theOpertion a resumed operation
453 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
455 /// SLOT, that is called after the operation is stopped. Update workshop state, e.g.
456 /// hides the property panel and update the command status.
457 /// \param theOpertion a stopped operation
458 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
460 /// SLOT, that is called after the operation is committed.
461 /// \param theOpertion a committed operation
462 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
464 /// SLOT, that is called after the operation is aborted.
465 /// \param theOpertion an aborted operation
466 void onOperationAborted(ModuleBase_Operation* theOperation);
468 /// Slot, which reacts to the context popup menu call
469 /// \param theId the data value of the clicked action
470 /// \param isChecked a state of toggle if the action is checkable
471 void onContextMenuCommand(const QString& theId, bool isChecked);
473 /// Set waiting cursor
474 void onStartWaiting();
476 /// Called by Ok button clicked in the property panel. Asks the error manager whether
477 /// the operation can be committed and do it if it returns true.
478 void onAcceptActionClicked();
480 /// Called by Preview button clicked in the property panel. Sends signal to model to
482 void onPreviewActionClicked();
488 /// Register validators
489 void registerValidators() const;
491 /// Load module from external library
492 /// \param theModule name of the module
493 ModuleBase_IModule* loadModule(const QString& theModule);
498 /// Create object browser widget
499 /// \param theParent a parent of widget
500 QDockWidget* createObjectBrowser(QWidget* theParent);
502 /// Create property panel widget
503 /// \param theParent a parent of widget
504 QDockWidget* createPropertyPanel(QWidget* theParent);
506 // Creates Dock widgets: Object browser and Property panel
507 void createDockWidgets();
509 //! Extends undo/redo toolbutton's with history menu
510 //! \param theObject - in the OpenParts it is a QToolButton by itself,
511 //! in salome mode - QAction that creates a button.
512 //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
513 //! \param theSlot - onUndo(int) or onRedo(int) SLOT
514 void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
516 //! Creates list of actions (commands) by given history list from session
517 QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
521 AppElements_MainWindow* myMainWindow;
524 ModuleBase_IModule* myModule;
525 XGUI_ErrorMgr* myErrorMgr;
526 XGUI_ObjectsBrowser* myObjectBrowser;
527 XGUI_PropertyPanel* myPropertyPanel;
528 XGUI_SelectionMgr* mySelector;
529 XGUI_Displayer* myDisplayer;
530 XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
531 XGUI_ActionsMgr* myActionsMgr;
532 XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
533 XGUI_SalomeConnector* mySalomeConnector;
534 XGUI_ErrorDialog* myErrorDlg;
535 XGUI_ViewerProxy* myViewerProxy;
536 XGUI_ContextMenuMgr* myContextMenuMgr;
537 XGUI_ModuleConnector* myModuleConnector;
538 XGUI_WorkshopListener* myEventsListener;
540 QString myCurrentDir;
542 QIntList myViewerSelMode;
544 Config_DataModelReader* myDataModelXMLReader;