0029559: Samples - wrong copyright statement in FuncDemo
[occt.git] / tools / VInspector / VInspector_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 VInspector_Window_H
17 #define VInspector_Window_H
18
19 #include <AIS_InteractiveContext.hxx>
20 #include <NCollection_List.hxx>
21 #include <SelectBasics_EntityOwner.hxx>
22 #include <Standard.hxx>
23 #include <inspector/TInspectorAPI_PluginParameters.hxx>
24 #include <inspector/VInspector_CallBack.hxx>
25
26 #include <QObject>
27 #include <QItemSelection>
28 #include <QMainWindow>
29
30 class TreeModel_MessageDialog;
31
32 class VInspector_ToolBar;
33 class View_Window;
34
35 class QAbstractItemModel;
36 class QAction;
37 class QMainWindow;
38 class QTreeView;
39 class QWidget;
40
41 //! \class VInspector_Window
42 //! Window that unites all VInspector controls.
43 class VInspector_Window : public QObject
44 {
45   Q_OBJECT
46
47 public:
48
49   //! Constructor
50   Standard_EXPORT VInspector_Window();
51
52   //! Destructor
53   virtual ~VInspector_Window() Standard_OVERRIDE {}
54
55   //! Provides the container with a parent where this container should be inserted.
56   //! If Qt implementation, it should be QWidget with QLayout set inside
57   //! \param theParent a parent class
58   Standard_EXPORT void SetParent (void* theParent);
59
60   //! Sets parameters container, it should be used when the plugin is initialized or in update content
61   //! \param theParameters a parameters container
62   void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
63
64   //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
65   Standard_EXPORT void UpdateContent();
66
67   //! Returns main control
68   QWidget* GetMainWindow() const { return myMainWindow; }
69
70 private:
71
72   //! Fills controls of the plugin by parameters:
73   //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
74   //! \param theParameters a parameters container
75   void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
76
77   //! Read BREP file, creates AIS presentation for the shape and visualize it in the current context
78   //! \param theFileName a name of BREP file
79   void OpenFile (const TCollection_AsciiString& theFileName);
80
81 private slots:
82
83   //! Shows context menu for tree view selected item. It contains clear view or BREP operations items
84   //! \param thePosition a clicked point
85   void onTreeViewContextMenuRequested(const QPoint& thePosition);
86
87   //! Performs the functionality of the clicked action
88   //! \param theActionId an action identifier in tool bar
89   void onToolBarActionClicked (const int theActionId);
90
91   //! Synchronization selection between history and tree view. Selection by history view
92   //! \param theSelected a selected items
93   //! \param theDeselected a deselected items
94   void onHistoryViewSelectionChanged (const QItemSelection& theSelected,
95                                       const QItemSelection& theDeselected);
96
97   //! Processes selection in tree view: make presentation or owner selected in the context if corresponding
98   //! check box is checked
99   //! \param theSelected a selected items
100   //! \param theDeselected a deselected items
101   void onSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
102
103   //! Exports the first selected shape into ShapeViewer plugin.
104   void onExportToShapeView();
105
106   //! Shows selected presentation if it is not shown yet
107   void onShow();
108
109   //! Erase selected presentation if it is shown
110   void onHide();
111
112 private:
113
114   //! Inits the window content by the given context
115   //! \param theContext a context
116   void SetContext (const Handle(AIS_InteractiveContext)& theContext);
117
118   //! Updates tree model
119   void UpdateTreeModel();
120
121   //! Creates an action with the given text connected to the slot
122   //! \param theText an action text value
123   //! \param theSlot a listener of triggered signal of the new action
124   //! \return a new action
125   QAction* createAction(const QString& theText, const char* theSlot);
126
127   //! Set selected in tree view presentations displayed or erased in the current context. Note that erased presentations
128   //! still belongs to the current context until Remove is called.
129   //! \param theToDisplay if true, presentation is displayed otherwise erased
130   void displaySelectedPresentations (const bool theToDisplay);
131
132   //! Creates an istance of 3D view to initialize context.
133   //! \return a context of created view.
134   Handle(AIS_InteractiveContext) createView();
135
136 private:
137
138   QWidget* myParent; //!< widget, comes when Init window, the window control lays in the layout, updates window title
139
140   QMainWindow* myMainWindow; //!< main control
141   VInspector_ToolBar* myToolBar; //!< tool bar actions
142   QTreeView* myTreeView; //!< tree view of AIS content
143   QTreeView* myHistoryView; //!< history of AIS context calls
144   Handle(VInspector_CallBack) myCallBack; //!< AIS context call back, if set
145
146   TreeModel_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
147   View_Window* myViewWindow; //!< temporary view window, it is created if Open is called but context is still NULL
148
149   Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
150 };
151
152 #endif