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