1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef DFBrowser_Window_H
17 #define DFBrowser_Window_H
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>
28 #pragma warning(disable : 4127) // conditional expression is constant
31 #include <QItemSelection>
32 #include <QMainWindow>
33 #include <QModelIndexList>
35 class DFBrowser_DumpView;
36 class DFBrowser_Module;
37 class DFBrowser_PropertyPanel;
38 class DFBrowser_Shortcut;
39 class DFBrowser_Thread;
40 class DFBrowser_TreeLevelLine;
45 class QAbstractItemModel;
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
61 Standard_EXPORT DFBrowser_Window();
64 Standard_EXPORT virtual ~DFBrowser_Window() Standard_OVERRIDE;
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);
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; }
74 //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
75 Standard_EXPORT void UpdateContent();
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);
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);
90 //! Returns main control
91 QWidget* GetMainWindow() const { return myMainWindow; }
93 //! Returns the current module
94 DFBrowser_Module* GetModule() const { return myModule; }
96 //! Clears thread cache
97 Standard_EXPORT void ClearThreadCache();
99 //! Returns tree level line control
100 DFBrowser_TreeLevelLine* GetTreeLevelLine() const { return myTreeLevelLine; }
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);
106 //! Returns temporary directory defined by environment variables TEMP or TMP
107 //! \return string value
108 Standard_EXPORT static TCollection_AsciiString TmpDirectory();
110 //! Returns light highlight color
111 //! \returns Qt color
112 static QColor LightHighlightColor() { return QColor (229, 243, 255); }
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);
124 //! Cleans history in tree level line, clears cache of thread processing, starts threads for application
125 void onBeforeUpdateTreeModel();
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);
131 //! Expand two next levels for all selected item
134 //! Expand all levels for all selected items
137 //! Collapse all levels for all selected items
138 void onCollapseAll();
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);
145 //! Changes attribute pane stack content depending on search control text
146 void onSearchActivated();
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);
155 //! Selects the item in OCAF tree view
156 //! \param theIndex OCAF tree view index
157 void onTreeLevelLineSelected (const QModelIndex& theIndex);
159 //! Updates OCAF tree model
160 void onUpdateClicked();
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);
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);
172 //! Higlights OCAF tree model item
173 //! \param theIndex an OCAF tree model index
174 void onLevelSelected (const QModelIndex& theIndex);
176 //! Selects OCAF tree model item
177 //! \param theIndex an OCAF tree model index
178 void onLevelDoubleClicked (const QModelIndex& theIndex);
182 //! Inits OCAF tree view with the given model
183 //! \param theModel a model
184 void setOCAFModel (QAbstractItemModel* theModel);
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);
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);
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);
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;
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);
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);
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);
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