0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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 <inspector/TInspectorAPI_PluginParameters.hxx>
20
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>
27
28 #include <Standard_WarningsDisable.hxx>
29 #include <QObject>
30 #include <QItemSelection>
31 #include <QMainWindow>
32 #include <QModelIndexList>
33 #include <Standard_WarningsRestore.hxx>
34
35 class DFBrowser_DumpView;
36 class DFBrowser_Module;
37 class DFBrowser_PropertyPanel;
38 class DFBrowser_TreeLevelLine;
39
40 class ViewControl_MessageDialog;
41 class ViewControl_PropertyView;
42
43 class View_ToolBar;
44 class View_Window;
45
46 class QAbstractItemModel;
47 class QAction;
48 class QDockWidget;
49 class QTreeView;
50 class QWidget;
51
52 //! \class DFBrowser_Window
53 //! Window that unites all DFBrowser controls.
54 //! External functionality : it processes plugin parameters, updates controls content and places itself in parent layout.
55 //! It Synchronizes controls content depending on current selection.
56 //! It shows context popup menu for OCAF tree view.
57 class DFBrowser_Window : public QObject
58 {
59   Q_OBJECT
60 public:
61
62   //! Constructor
63   Standard_EXPORT DFBrowser_Window();
64
65   //! Destructor
66   Standard_EXPORT virtual ~DFBrowser_Window();
67
68   //! Appends main window into layout of the parent if the parent is child of QWidget
69   //! \param theParent a parent class
70   Standard_EXPORT void SetParent (void* theParent);
71
72   //! Sets parameters container, it should be used when the plugin is initialized or in update content
73   //! \param theParameters a parameters container
74   void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
75
76   //! Provides container for actions available in inspector on general level
77   //! \param theMenu if Qt implementation, it is QMenu object
78   Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
79
80   //! Returns plugin preferences: dock widgets state, tree view columns.
81   //! \param theItem container of preference elements
82   Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
83
84   //! Applies plugin preferences
85   //! \param theItem container of preference elements
86   Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
87
88   //! Applies parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
89   Standard_EXPORT void UpdateContent();
90
91   //! Fills controls of the plugin by parameters:
92   //! - Find TDocStd_Application and fills OCAF tree model if it differs from the current application
93   //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
94   //! - If it is the first call, it creates module, fills selection models
95   //! \param theParameters a parameters container
96   Standard_EXPORT void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
97
98   //! Opens application by the name, it may be either OCAF document or STEP file.
99   //! Before opening it cleans tree view history, current selections,
100   //! reset OCAF tree view model. After opening document, it fills all controls by the created application.
101   //! \param theFileName a file name to be opened
102   Standard_EXPORT void OpenFile (const TCollection_AsciiString& theFileName);
103
104   //! Returns main control
105   QWidget* GetMainWindow() const { return myMainWindow; }
106
107   //! Returns the current module
108   DFBrowser_Module* GetModule() const { return myModule; }
109
110   //! Returns tree level line control
111   DFBrowser_TreeLevelLine* GetTreeLevelLine() const { return myTreeLevelLine; }
112
113   //! Returns temporary directory defined by environment variables TEMP or TMP
114   //! \return string value
115   Standard_EXPORT static TCollection_AsciiString TmpDirectory();
116
117   //! Sets whether DumpJson is used when the tree view is generated
118   Standard_EXPORT static void SetUseDumpJson(const Standard_Boolean theValue);
119
120   //! Returns whether DumpJson is used when the tree view is generated
121   Standard_EXPORT static Standard_Boolean IsUseDumpJson();
122
123 private slots:
124
125   //! Cleans history in tree level line
126   void onBeforeUpdateTreeModel();
127
128   //! Shows context menu for tree view selected item. It contains clear view or BREP operations items
129   //! \param thePosition a clicked point
130   void onTreeViewContextMenuRequested (const QPoint& thePosition);
131
132   //! Expands two next levels for all selected item
133   void onExpand();
134
135   //! Expands all levels for all selected items
136   void onExpandAll();
137
138   //! Collapses all levels for all selected items
139   void onCollapseAll();
140
141   //! Setting flag whether DumpJSon should be applied to build tree model items structure 
142   void onUseDumpJson();
143
144   //! Updates all controls by changed selection in OCAF tree view
145   //! \param theSelected list of selected tree view items
146   //! \param theDeselected list of deselected tree view items
147   void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
148
149   //! Changes attribute pane stack content depending on search control text
150   void onSearchActivated();
151
152   //! Processes selection change in attribute pane. Depending on selection kind, it will:
153   //! - export to shape viewer
154   //! - display presentation of the pane
155   //! - display references
156   void onPaneSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected,
157                                QItemSelectionModel* theModel);
158
159   //! Selects the item in OCAF tree view
160   //! \param theIndex OCAF tree view index
161   void onTreeLevelLineSelected (const QModelIndex& theIndex);
162
163   //! Updates OCAF tree model
164   void onUpdateClicked();
165
166   //! Highlights 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 onSearchPathSelected (const QStringList& thePath, const QString& theValue);
170
171   //! Selects OCAF tree model item
172   //! \param thePath a container of entries to the item
173   //! \param theValue a label entry or attribute name
174   void onSearchPathDoubleClicked (const QStringList& thePath, const QString& theValue);
175
176   //! Highlights OCAF tree model item
177   //! \param theIndex an OCAF tree model index
178   void onLevelSelected (const QModelIndex& theIndex);
179
180   //! Selects OCAF tree model item
181   //! \param theIndex an OCAF tree model index
182   void onLevelDoubleClicked (const QModelIndex& theIndex);
183
184 private:
185
186   //! Inits OCAF tree view with the given model
187   //! \param theModel a model
188   void setOCAFModel (QAbstractItemModel* theModel);
189
190   //! Sets expanded levels in OCAF tree view. Do recursive expand of items.
191   //! \param theTreeView an OCAF tree view
192   //! \param theParentIndex an index which children should be expanded
193   //! \param theLevels a number of levels to be expanded, or -1 for all levels
194   static void setExpandedLevels (QTreeView* theTreeView, const QModelIndex& theParentIndex, const int theLevels);
195
196   //! Marks items highlighted in OCAF tree view model and move view scroll to the first item
197   //! \param theIndices a container of OCAF tree view model indices
198   void highlightIndices (const QModelIndexList& theIndices);
199
200   //! Returns candidate to be the window title. It is either name of opened STEP file or the application path
201   //! \return string value
202   QString getWindowTitle() const;
203
204 protected:
205
206   //! Returns presentation for the OCAF tree model index. To do this, it uses attribute pane for this item
207   //! \param theIndex a model index
208   //! \return presentation or NULL
209   Handle(AIS_InteractiveObject) findPresentation (const QModelIndex& theIndex);
210
211   //! Returns presentations for the OCAF tree model indices. To do this, it uses attribute pane for this items
212   //! \param theIndex a model index
213   //! \return container of presentations or NULL
214   void findPresentations (const QModelIndexList& theIndices, AIS_ListOfInteractive& thePresentations);
215
216   //! Updates content of Property Panel dock widget. It contains button to activate DumpJson or view with content of it.
217   void updatePropertyPanelWidget();
218
219 private:
220
221   DFBrowser_Module* myModule; //!< current module
222   QWidget* myParent; //!< widget, comes when Init window, the window control lays in the layout, updates window title
223   QMainWindow* myMainWindow; //!< main control for all components
224   DFBrowser_TreeLevelLine* myTreeLevelLine; //!< navigate line of tree levels to the selected item
225   QTreeView* myTreeView; //!< OCAF tree view
226   QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget
227   QWidget* myUseDumpJson; //!< button to activate/deactivate using of DumpJson
228   DFBrowser_PropertyPanel* myPropertyPanel; //!< property panel shows full information about attribute or search view
229   ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist
230   View_Window* myViewWindow; //!< V3d view to visualize presentations/references if it can be build for a selected item
231   DFBrowser_DumpView* myDumpView; //!< Text editor where "Dump" method output is shown
232   ViewControl_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
233   Handle(TInspectorAPI_PluginParameters) myParameters; //!< contains application, context, files that should be opened
234   QString myOpenedFileName; //!< cached name of opened file between parent is set, apply it by parent setting and nullify
235 };
236
237 #endif