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;
42 class ViewControl_PropertyView;
47 class QAbstractItemModel;
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.
58 class DFBrowser_Window : public QObject
64 Standard_EXPORT DFBrowser_Window();
67 Standard_EXPORT virtual ~DFBrowser_Window();
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);
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; }
77 //! Provides container for actions available in inspector on general level
78 //! \param theMenu if Qt implementation, it is QMenu object
79 Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
81 //! Returns plugin preferences: dock widgets state, tree view columns.
82 //! \param theItem container of preference elements
83 Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
85 //! Applies plugin preferences
86 //! \param theItem container of preference elements
87 Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
89 //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
90 Standard_EXPORT void UpdateContent();
92 //! Fills controls of the plugin by parameters:
93 //! - Find TDocStd_Application and fills OCAF tree model if it differs from the current application
94 //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
95 //! - If it is the first call, it creates module, start thread to cache application information, fills selection models
96 //! \param theParameters a parameters container
97 Standard_EXPORT void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
99 //! Opens application by the name, it may be either OCAF document or STEP file.
100 //! Before opening it cleans tree view history, current selections, stop threads(if it was started),
101 //! reset OCAF tree view model. After opening document, it fills all controls by the created application.
102 //! \param theFileName a file name to be opened
103 Standard_EXPORT void OpenFile (const TCollection_AsciiString& theFileName);
105 //! Returns main control
106 QWidget* GetMainWindow() const { return myMainWindow; }
108 //! Returns the current module
109 DFBrowser_Module* GetModule() const { return myModule; }
111 //! Clears thread cache
112 Standard_EXPORT void ClearThreadCache();
114 //! Returns tree level line control
115 DFBrowser_TreeLevelLine* GetTreeLevelLine() const { return myTreeLevelLine; }
117 //! Returns temporary directory defined by environment variables TEMP or TMP
118 //! \return string value
119 Standard_EXPORT static TCollection_AsciiString TmpDirectory();
123 //! Cleans history in tree level line, clears cache of thread processing, starts threads for application
124 void onBeforeUpdateTreeModel();
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);
130 //! Expands two next levels for all selected item
133 //! Expands all levels for all selected items
136 //! Collapses all levels for all selected items
137 void onCollapseAll();
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);
144 //! Changes attribute pane stack content depending on search control text
145 void onSearchActivated();
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);
154 //! Selects the item in OCAF tree view
155 //! \param theIndex OCAF tree view index
156 void onTreeLevelLineSelected (const QModelIndex& theIndex);
158 //! Updates OCAF tree model
159 void onUpdateClicked();
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);
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);
171 //! Higlights OCAF tree model item
172 //! \param theIndex an OCAF tree model index
173 void onLevelSelected (const QModelIndex& theIndex);
175 //! Selects OCAF tree model item
176 //! \param theIndex an OCAF tree model index
177 void onLevelDoubleClicked (const QModelIndex& theIndex);
181 //! Inits OCAF tree view with the given model
182 //! \param theModel a model
183 void setOCAFModel (QAbstractItemModel* theModel);
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);
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);
195 //! Returns candidate to be the window title. It is either name of opened STEP file or the application path
196 //! \return string value
197 QString getWindowTitle() const;
201 //! Returns presentation for the OCAF tree model index. To do this, it uses attribute pane for this item
202 //! \param theIndex a model index
203 //! \return presentation or NULL
204 Handle(AIS_InteractiveObject) findPresentation (const QModelIndex& theIndex);
206 //! Returns presentations for the OCAF tree model indices. To do this, it uses attribute pane for this items
207 //! \param theIndex a model index
208 //! \return container of presentations or NULL
209 void findPresentations (const QModelIndexList& theIndices, AIS_ListOfInteractive& thePresentations);
213 DFBrowser_Module* myModule; //!< current module
214 QWidget* myParent; //!< widget, comes when Init window, the window control lays in the layout, updates window title
215 QMainWindow* myMainWindow; //!< main control for all components
216 DFBrowser_TreeLevelLine* myTreeLevelLine; //!< navigate line of tree levels to the selected item
217 QTreeView* myTreeView; //!< OCAF tree view
218 QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget
219 DFBrowser_PropertyPanel* myPropertyPanel; //!< property panel shows full information about attribute or search view
220 ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist
221 View_Window* myViewWindow; //!< V3d view to visualize presentations/references if it can be build for a selected item
222 DFBrowser_DumpView* myDumpView; //!< Text editor where "Dump" method output is shown
223 DFBrowser_Thread* myThread; //!< Threads manipulator, starting thread items, listens finalizing
224 ViewControl_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
225 Handle(TInspectorAPI_PluginParameters) myParameters; //!< contains application, context, files that should be opened
226 QString myOpenedFileName; //!< cached name of opened file between parent is set, apply it by parent setting and nullify