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 <inspector/TInspectorAPI_PluginParameters.hxx>
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>
28 #include <Standard_WarningsDisable.hxx>
30 #include <QItemSelection>
31 #include <QMainWindow>
32 #include <QModelIndexList>
33 #include <Standard_WarningsRestore.hxx>
35 class DFBrowser_DumpView;
36 class DFBrowser_Module;
37 class DFBrowser_PropertyPanel;
38 class DFBrowser_Thread;
39 class DFBrowser_TreeLevelLine;
41 class ViewControl_MessageDialog;
46 class QAbstractItemModel;
51 //! \class DFBrowser_Window
52 //! Window that unites all DFBrowser controls.
53 //! External functionality : it processes plugin parameters, updates controls content and places itself in parent layout.
54 //! It Synchronizes controls content depending on current selection.
55 //! It shows context popup menu for OCAF tree view.
56 class DFBrowser_Window : public QObject
62 Standard_EXPORT DFBrowser_Window();
65 Standard_EXPORT virtual ~DFBrowser_Window() Standard_OVERRIDE;
67 //! Appends main window into layout of the parent if the parent is child of QWidget
68 //! \param theParent a parent class
69 Standard_EXPORT void SetParent (void* theParent);
71 //! Sets parameters container, it should be used when the plugin is initialized or in update content
72 //! \param theParameters a parameters container
73 void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
75 //! Provide container for actions available in inspector on general level
76 //! \param theMenu if Qt implementation, it is QMenu object
77 Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
79 //! Returns plugin preferences: dock widgets state, tree view columns.
80 //! \param theItem container of preference elements
81 Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
83 //! Applies plugin preferences
84 //! \param theItem container of preference elements
85 Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
87 //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
88 Standard_EXPORT void UpdateContent();
90 //! Fills controls of the plugin by parameters:
91 //! - Find TDocStd_Application and fills OCAF tree model if it differs from the current application
92 //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
93 //! - If it is the first call, it creates module, start thread to cache application information, fills selection models
94 //! \param theParameters a parameters container
95 Standard_EXPORT void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
97 //! Opens application by the name, it may be either OCAF document or STEP file.
98 //! Before opening it cleans tree view history, current selections, stop threads(if it was started),
99 //! reset OCAF tree view model. After opening document, it fills all controls by the created application.
100 //! \param theFileName a file name to be opened
101 Standard_EXPORT void OpenFile (const TCollection_AsciiString& theFileName);
103 //! Returns main control
104 QWidget* GetMainWindow() const { return myMainWindow; }
106 //! Returns the current module
107 DFBrowser_Module* GetModule() const { return myModule; }
109 //! Clears thread cache
110 Standard_EXPORT void ClearThreadCache();
112 //! Returns tree level line control
113 DFBrowser_TreeLevelLine* GetTreeLevelLine() const { return myTreeLevelLine; }
115 //! Returns temporary directory defined by environment variables TEMP or TMP
116 //! \return string value
117 Standard_EXPORT static TCollection_AsciiString TmpDirectory();
121 //! Cleans history in tree level line, clears cache of thread processing, starts threads for application
122 void onBeforeUpdateTreeModel();
124 //! Shows context menu for tree view selected item. It contains clear view or BREP operations items
125 //! \param thePosition a clicked point
126 void onTreeViewContextMenuRequested (const QPoint& thePosition);
128 //! Expand two next levels for all selected item
131 //! Expand all levels for all selected items
134 //! Collapse all levels for all selected items
135 void onCollapseAll();
137 //! Udpates all controls by changed selection in OCAF tree view
138 //! \param theSelected list of selected tree view items
139 //! \param theDeselected list of deselected tree view items
140 void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
142 //! Changes attribute pane stack content depending on search control text
143 void onSearchActivated();
145 //! Processes selection change in attribute pane. Depending on selection kind, it will:
146 //! - export to shape viewer
147 //! - display presentation of the pane
148 //! - display references
149 void onPaneSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected,
150 QItemSelectionModel* theModel);
152 //! Selects the item in OCAF tree view
153 //! \param theIndex OCAF tree view index
154 void onTreeLevelLineSelected (const QModelIndex& theIndex);
156 //! Updates OCAF tree model
157 void onUpdateClicked();
159 //! Higlights OCAF tree model item
160 //! \param thePath a container of entries to the item
161 //! \param theValue a label entry or attribute name
162 void onSearchPathSelected (const QStringList& thePath, const QString& theValue);
164 //! Selects OCAF tree model item
165 //! \param thePath a container of entries to the item
166 //! \param theValue a label entry or attribute name
167 void onSearchPathDoubleClicked (const QStringList& thePath, const QString& theValue);
169 //! Higlights OCAF tree model item
170 //! \param theIndex an OCAF tree model index
171 void onLevelSelected (const QModelIndex& theIndex);
173 //! Selects OCAF tree model item
174 //! \param theIndex an OCAF tree model index
175 void onLevelDoubleClicked (const QModelIndex& theIndex);
179 //! Inits OCAF tree view with the given model
180 //! \param theModel a model
181 void setOCAFModel (QAbstractItemModel* theModel);
183 //! Sets expanded levels in OCAF tree view. Do recursive expand of items.
184 //! \param theTreeView an OCAF tree view
185 //! \param theParentIndex an index which children should be expanded
186 //! \param theLevels a number of levels to be expanded, or -1 for all levels
187 static void setExpandedLevels (QTreeView* theTreeView, const QModelIndex& theParentIndex, const int theLevels);
189 //! Marks items highlighted in OCAF tree view model and move view scroll to the first item
190 //! \param theIndices a container of OCAF tree view model indices
191 void highlightIndices (const QModelIndexList& theIndices);
193 //! Returns candidate to be the window title. It is either name of opened STEP file or the application path
194 //! \return string value
195 QString getWindowTitle() const;
199 //! Returns presentation for the OCAF tree model index. To do this, it uses attribute pane for this item
200 //! \param theIndex a model index
201 //! \return presentation or NULL
202 Handle(AIS_InteractiveObject) findPresentation (const QModelIndex& theIndex);
204 //! Returns presentations for the OCAF tree model indices. To do this, it uses attribute pane for this items
205 //! \param theIndex a model index
206 //! \return container of presentations or NULL
207 void findPresentations (const QModelIndexList& theIndices, AIS_ListOfInteractive& thePresentations);
209 //! Recursive items expanding in tree view staring from the index
210 //! \param theTreeView an OCAF tree view
211 //! \param theParentIndex an index which children should be expanded
212 //! \param isExpanded a boolean state if the item should be expanded or collapsed
213 //! \param theLevels a number of levels to be expanded, or -1 for all levels
214 static void setExpanded (QTreeView* theTreeView, const QModelIndex& theParentIndex, const bool isExpanded, int& theLevels);
218 DFBrowser_Module* myModule; //!< current module
219 QWidget* myParent; //!< widget, comes when Init window, the window control lays in the layout, updates window title
220 QMainWindow* myMainWindow; //!< main control for all components
221 DFBrowser_TreeLevelLine* myTreeLevelLine; //!< navigate line of tree levels to the selected item
222 QTreeView* myTreeView; //!< OCAF tree view
223 DFBrowser_PropertyPanel* myPropertyPanel; //!< property panel shows full information about attribute or search view
224 View_Window* myViewWindow; //!< V3d view to visualize presentations/references if it can be build for a selected item
225 DFBrowser_DumpView* myDumpView; //!< Text editor where "Dump" method output is shown
226 DFBrowser_Thread* myThread; //!< Threads manipulator, starting thread items, listens finalizing
227 ViewControl_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
228 Handle(TInspectorAPI_PluginParameters) myParameters; //!< contains application, context, files that should be opened