0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[occt.git] / tools / VInspector / VInspector_Window.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef VInspector_Window_H
17 #define VInspector_Window_H
18
19 #include <AIS_InteractiveContext.hxx>
20 #include <NCollection_List.hxx>
21 #include <SelectBasics_EntityOwner.hxx>
22 #include <Standard.hxx>
23 #include <TInspectorAPI_PluginParameters.hxx>
24 #include <VInspector_CallBack.hxx>
25
26 #include <QObject>
27 #include <QItemSelection>
28 #include <QMainWindow>
29
30 class VInspector_ToolBar;
31
32 class QAbstractItemModel;
33 class QAction;
34 class QMainWindow;
35 class QTreeView;
36 class QWidget;
37
38 //! \class VInspector_Window
39 //! Window that unites all VInspector controls.
40 class VInspector_Window : public QObject
41 {
42   Q_OBJECT
43
44 public:
45
46   //! Constructor
47   Standard_EXPORT VInspector_Window();
48
49   //! Destructor
50   virtual ~VInspector_Window() Standard_OVERRIDE {}
51
52   //! Provides the container with a parent where this container should be inserted.
53   //! If Qt implementation, it should be QWidget with QLayout set inside
54   //! \param theParent a parent class
55   Standard_EXPORT void SetParent (void* theParent);
56
57   //! Sets parameters container, it should be used when the plugin is initialized or in update content
58   //! \param theParameters a parameters container
59   void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
60
61   //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
62   Standard_EXPORT void UpdateContent();
63
64   //! Returns main control
65   QWidget* GetMainWindow() const { return myMainWindow; }
66
67 private:
68
69   //! Fills controls of the plugin by parameters:
70   //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
71   //! \param theParameters a parameters container
72   void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
73
74   //! Read BREP file, creates AIS presentation for the shape and visualize it in the current context
75   //! \param theFileName a name of BREP file
76   void OpenFile (const TCollection_AsciiString& theFileName);
77
78 private slots:
79
80   //! Shows context menu for tree view selected item. It contains clear view or BREP operations items
81   //! \param thePosition a clicked point
82   void onTreeViewContextMenuRequested(const QPoint& thePosition);
83
84   //! Performs the functionality of the clicked action
85   //! \param theActionId an action identifier in tool bar
86   void onToolBarActionClicked (const int theActionId);
87
88   //! Synchronization selection between history and tree view. Selection by history view
89   //! \param theSelected a selected items
90   //! \param theDeselected a deselected items
91   void onHistoryViewSelectionChanged (const QItemSelection& theSelected,
92                                       const QItemSelection& theDeselected);
93
94   //! Processes selection in tree view: make presentation or owner selected in the context if corresponding
95   //! check box is checked
96   //! \param theSelected a selected items
97   //! \param theDeselected a deselected items
98   void onSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
99
100   //! Exports the first selected shape into ShapeViewer plugin.
101   void onExportToShapeView();
102
103   //! Shows selected presentation if it is not shown yet
104   void onShow();
105
106   //! Erase selected presentation if it is shown
107   void onHide();
108
109 private:
110
111   //! Inits the window content by the given context
112   //! \param theContext a context
113   void SetContext (const Handle(AIS_InteractiveContext)& theContext);
114
115   //! Updates tree model
116   void UpdateTreeModel();
117
118   //! Creates an action with the given text connected to the slot
119   //! \param theText an action text value
120   //! \param theSlot a listener of triggered signal of the new action
121   //! \return a new action
122   QAction* createAction(const QString& theText, const char* theSlot);
123
124   //! Set selected in tree view presentations displayed or erased in the current context. Note that erased presentations
125   //! still belongs to the current context until Remove is called.
126   //! \param theToDisplay if true, presentation is displayed otherwise erased
127   void displaySelectedPresentations (const bool theToDisplay);
128
129 private:
130
131   QMainWindow* myMainWindow; //!< main control
132   VInspector_ToolBar* myToolBar; //!< tool bar actions
133   QTreeView* myTreeView; //!< tree view of AIS content
134   QTreeView* myHistoryView; //!< history of AIS context calls
135   Handle(VInspector_CallBack) myCallBack; //!< AIS context call back, if set
136
137   Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
138 };
139
140 #endif