0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[occt.git] / tools / DFBrowser / DFBrowser_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 DFBrowser_Window_H
17 #define DFBrowser_Window_H
18
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_ListOfInteractive.hxx>
21 #include <NCollection_List.hxx>
22 #include <Standard.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <TDF_Label.hxx>
25 #include <TInspectorAPI_PluginParameters.hxx>
26
27 #ifdef _MSC_VER
28 #pragma warning(disable : 4127) // conditional expression is constant
29 #endif
30 #include <QObject>
31 #include <QItemSelection>
32 #include <QMainWindow>
33 #include <QModelIndexList>
34
35 class DFBrowser_DumpView;
36 class DFBrowser_Module;
37 class DFBrowser_PropertyPanel;
38 class DFBrowser_Shortcut;
39 class DFBrowser_Thread;
40 class DFBrowser_TreeLevelLine;
41
42 class View_ToolBar;
43 class View_Window;
44
45 class QAbstractItemModel;
46 class QAction;
47 class QTreeView;
48 class QWidget;
49
50 //! \class DFBrowser_Window
51 //! Window that unites all DFBrowser controls.
52 //! External functionality : it processes plugin parameters, updates controls content and places itself in parent layout.
53 //! It Synchronizes controls content depending on current selection.
54 //! It shows context popup menu for OCAF tree view.
55 class DFBrowser_Window : public QObject
56 {
57   Q_OBJECT
58 public:
59
60   //! Constructor
61   Standard_EXPORT DFBrowser_Window();
62
63   //! Destructor
64   Standard_EXPORT virtual ~DFBrowser_Window() Standard_OVERRIDE;
65
66   //! Appends main window into layout of the parent if the parent is child of QWidget
67   //! \param theParent a parent class
68   Standard_EXPORT void SetParent (void* theParent);
69
70   //! Sets parameters container, it should be used when the plugin is initialized or in update content
71   //! \param theParameters a parameters container
72   void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
73
74   //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
75   Standard_EXPORT void UpdateContent();
76
77   //! Fills controls of the plugin by parameters:
78   //! - Find TDocStd_Application and fills OCAF tree model if it differs from the current application
79   //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
80   //! - If it is the first call, it creates module, start thread to cache application information, fills selection models
81   //! \param theParameters a parameters container
82   Standard_EXPORT void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
83
84   //! Opens application by the name, it may be either OCAF document or STEP file.
85   //! Before opening it cleans tree view history, current selections, stop threads(if it was started),
86   //! reset OCAF tree view model. After opening document, it fills all controls by the created application.
87   //! \param theFileName a file name to be opened
88   Standard_EXPORT void OpenFile (const TCollection_AsciiString& theFileName);
89
90   //! Returns main control
91   QWidget* GetMainWindow() const { return myMainWindow; }
92
93   //! Returns the current module
94   DFBrowser_Module* GetModule() const { return myModule; }
95
96   //! Clears thread cache
97   Standard_EXPORT void ClearThreadCache();
98
99   //! Returns tree level line control
100   DFBrowser_TreeLevelLine* GetTreeLevelLine() const { return myTreeLevelLine; }
101
102   //! Change palette of the widget to have white foreground
103   //! \param theControl a widget to be modified
104   Standard_EXPORT static void SetWhiteBackground (QWidget* theControl);
105
106   //! Returns temporary directory defined by environment variables TEMP or TMP
107   //! \return string value
108   Standard_EXPORT static TCollection_AsciiString TmpDirectory();
109
110   //! Returns light highlight color
111   //! \returns Qt color
112   static QColor LightHighlightColor() { return QColor (229, 243, 255); }
113
114   //! Returns single selected item in the cell of given orientation. If the orientation is Horizontal,
115   //! in the cell id colum, one row should be selected.
116   //! \param theIndices a container of selected indices
117   //! \param theCellId column index if orientation is horizontal, row index otherwise
118   //! \param theOrientation an orientation to apply the cell index
119   //! \return model index from the list
120   Standard_EXPORT static QModelIndex SingleSelected (const QModelIndexList& theIndices, const int theCellId,
121                                                      const Qt::Orientation theOrientation = Qt::Horizontal);
122 private slots:
123
124   //! Cleans history in tree level line, clears cache of thread processing, starts threads for application
125   void onBeforeUpdateTreeModel();
126
127   //! Shows context menu for tree view selected item. It contains clear view or BREP operations items
128   //! \param thePosition a clicked point
129   void onTreeViewContextMenuRequested (const QPoint& thePosition);
130
131   //! Expand two next levels for all selected item
132   void onExpand();
133
134   //! Expand all levels for all selected items
135   void onExpandAll();
136
137   //! Collapse all levels for all selected items
138   void onCollapseAll();
139
140   //! Udpates all controls by changed selection in OCAF tree view
141   //! \param theSelected list of selected tree view items
142   //! \param theDeselected list of deselected tree view items
143   void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
144
145   //! Changes attribute pane stack content depending on search control text
146   void onSearchActivated();
147
148   //! Processes selection change in attribute pane. Depending on selection kind, it will:
149   //! - export to shape viewer
150   //! - display presentation of the pane
151   //! - display references
152   void onPaneSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected,
153                                QItemSelectionModel* theModel);
154
155   //! Selects the item in OCAF tree view
156   //! \param theIndex OCAF tree view index
157   void onTreeLevelLineSelected (const QModelIndex& theIndex);
158
159   //! Updates OCAF tree model
160   void onUpdateClicked();
161
162   //! Higlights OCAF tree model item
163   //! \param thePath a container of entries to the item
164   //! \param theValue a label entry or attribute name
165   void onSearchPathSelected (const QStringList& thePath, const QString& theValue);
166
167   //! Selects OCAF tree model item
168   //! \param thePath a container of entries to the item
169   //! \param theValue a label entry or attribute name
170   void onSearchPathDoubleClicked (const QStringList& thePath, const QString& theValue);
171
172   //! Higlights OCAF tree model item
173   //! \param theIndex an OCAF tree model index
174   void onLevelSelected (const QModelIndex& theIndex);
175
176   //! Selects OCAF tree model item
177   //! \param theIndex an OCAF tree model index
178   void onLevelDoubleClicked (const QModelIndex& theIndex);
179
180 private:
181
182   //! Inits OCAF tree view with the given model
183   //! \param theModel a model
184   void setOCAFModel (QAbstractItemModel* theModel);
185
186   //! Sets expanded levels in OCAF tree view. Do recursive expand of items.
187   //! \param theTreeView an OCAF tree view
188   //! \param theParentIndex an index which children should be expanded
189   //! \param theLevels a number of levels to be expanded, or -1 for all levels
190   static void setExpandedLevels (QTreeView* theTreeView, const QModelIndex& theParentIndex, const int theLevels);
191
192   //! Marks items highlighted in OCAF tree view model and move view scroll to the first item
193   //! \param theIndices a container of OCAF tree view model indices
194   void highlightIndices (const QModelIndexList& theIndices);
195
196   //! Creates an action with the given text connected to the slot
197   //! \param theText an action text value
198   //! \param theSlot a listener of triggered signal of the new action
199   //! \return a new action
200   QAction* createAction (const QString& theText, const char* theSlot);
201
202   //! Returns candidate to be the window title. It is either name of opened STEP file or the application path
203   //! \return string value
204   QString getWindowTitle() const;
205
206 protected:
207
208   //! Returns presentation for the OCAF tree model index. To do this, it uses attribute pane for this item
209   //! \param theIndex a model index
210   //! \return presentation or NULL
211   Handle(AIS_InteractiveObject) findPresentation (const QModelIndex& theIndex);
212
213   //! Returns presentations for the OCAF tree model indices. To do this, it uses attribute pane for this items
214   //! \param theIndex a model index
215   //! \return container of presentations or NULL
216   void findPresentations (const QModelIndexList& theIndices, AIS_ListOfInteractive& thePresentations);
217
218   //! Recursive items expanding in tree view staring from the index
219   //! \param theTreeView an OCAF tree view
220   //! \param theParentIndex an index which children should be expanded
221   //! \param isExpanded a boolean state if the item should be expanded or collapsed
222   //! \param theLevels a number of levels to be expanded, or -1 for all levels
223   static void setExpanded (QTreeView* theTreeView, const QModelIndex& theParentIndex, const bool isExpanded, int& theLevels);
224
225 private:
226
227   DFBrowser_Module* myModule; //!< current module
228   QWidget* myParent; //!< widget, comes when Init window, the window control lays in the layout, updates window title
229   QMainWindow* myMainWindow; //!< main control for all components
230   DFBrowser_TreeLevelLine* myTreeLevelLine; //!< navigate line of tree levels to the selected item
231   QTreeView* myTreeView; //!< OCAF tree view
232   DFBrowser_PropertyPanel* myPropertyPanel; //!< property panel shows full information about attribute or search view
233   View_Window* myViewWindow; //!< V3d view to visualize presentations/references if it can be build for a selected item
234   DFBrowser_DumpView* myDumpView; //!< Text editor where "Dump" method output is shown
235   DFBrowser_Thread* myThread; //!< Threads manipulator, starting thread items, listens finalizing
236   DFBrowser_Shortcut* myShortcut; //!< Short cut processor, F5 - updates OCAF view model content
237   Handle(TInspectorAPI_PluginParameters) myParameters; //!< contains application, context, files that should be opened
238 };
239
240 #endif