0030268: Inspectors - improvements in VInspector plugin
[occt.git] / tools / DFBrowser / DFBrowser_Module.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_Module_H
17 #define DFBrowser_Module_H
18
19 #include <inspector/DFBrowser_TreeModel.hxx>
20 #include <inspector/TreeModel_ItemBase.hxx>
21
22 #include <AIS_InteractiveContext.hxx>
23 #include <NCollection_Map.hxx>
24 #include <Standard.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TDF_Attribute.hxx>
27 #include <TDocStd_Application.hxx>
28 #include <TopoDS_Shape.hxx>
29
30 #include <Standard_WarningsDisable.hxx>
31 #include <QObject>
32 #include <Standard_WarningsRestore.hxx>
33
34 class DFBrowserPane_AttributePaneAPI;
35 class DFBrowserPane_AttributePaneCreatorAPI;
36
37 class QAbstractItemModel;
38 class QItemSelectionModel;
39
40 //! \class DFBrowser_Module
41 //! The class is a container of current components of DFBrowser:
42 //! - OCAF view model
43 //! - OCAF selection model
44 //! - container of attribute panes into attribute name
45 //! - acceptable attribute pane creators
46 //! - external AIS interactive context
47 //! It has general attribute pane creator, if the application is XDE, it uses XDE attribute pane creator.
48 //! It fills container of created attribute pane.
49 class DFBrowser_Module : public QObject
50 {
51   Q_OBJECT
52 public:
53
54   //! Constructor
55   Standard_EXPORT DFBrowser_Module();
56
57   //! Destructor
58   virtual ~DFBrowser_Module() {}
59
60   //! Creates tree model for OCAF application
61   Standard_EXPORT void CreateViewModel (void* theParent);
62
63   //! Fills tree model by the application and register pane creator
64   //! \param theApplication a current application
65   Standard_EXPORT void SetApplication (const Handle(TDocStd_Application)& theApplication);
66
67   //! Fills viewer by the context
68   //! \param theContext a current context where presentations should be visualized
69   Standard_EXPORT void SetExternalContext (const Handle(Standard_Transient)& theContext);
70
71   //! Returns external context or NULL
72   const Handle(AIS_InteractiveContext)& GetExternalContext() const { return myExternalContext; }
73
74   //! Returns a view model with the OCAF structure content
75   QAbstractItemModel* GetOCAFViewModel() { return myOCAFViewModel; }
76
77   //! Sets selection model of tree view
78   void SetOCAFViewSelectionModel(QItemSelectionModel* theSelectionModel)
79   { myOCAFViewSelectionModel = theSelectionModel; }
80
81   //! Returns selection model of tree view
82   QItemSelectionModel* GetOCAFViewSelectionModel() const { return myOCAFViewSelectionModel; }
83
84   //! Returns an OCAF application or NULL
85   //! \return an application instance
86   Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const;
87
88   //! Rebuilds an OCAF tree view model
89   Standard_EXPORT void UpdateTreeModel();
90
91   //! Sets initial selection in OCAF tree view, it is an application(root) item
92   Standard_EXPORT void SetInitialTreeViewSelection();
93
94   //! Returns attibute placed on the parameter index in the OCAF tree view or NULL
95   //! \param theIndex an index in OCAF tree view.
96   //! \return an attribute
97   Standard_EXPORT Handle(TDF_Attribute) FindAttribute (const QModelIndex& theIndex);
98
99   //! Appends creator of a pane by attribute type
100   //! \param thePaneCreator
101   void RegisterPaneCreator (DFBrowserPane_AttributePaneCreatorAPI* thePaneCreator)
102   { myPaneCreators.append (thePaneCreator); }
103
104   //! Returns an attribute pane for the attribute: create a new if it is not exist in
105   //! internal map and the module processes this kind of attribute
106   //! \param theAttributeGUID an attribute key
107   //! \return attribute pane
108   Standard_EXPORT DFBrowserPane_AttributePaneAPI* GetAttributePane (Handle(TDF_Attribute) theAttribute);
109
110   //! Returns an attribute pane for the attribute GUID: create a new if it is not exist in
111   //! internal map and the module processes this kind of attribute
112   //! \param theAttributeGUID an attribute key
113   //! \return attribute pane
114   Standard_EXPORT DFBrowserPane_AttributePaneAPI* GetAttributePane (Standard_CString theAttributeName);
115
116   //! Finds the attribute pane according to the give attribute and returns its information
117   //! \param theAttribute a source attribute
118   //! \param theModule to provide a map of attribute id to attribute pane
119   //! \param theRole an attribute role in the tree view, includes: text, icon, color roles
120   //! \param theColumnId a column index
121   Standard_EXPORT static QVariant GetAttributeInfo (Handle(TDF_Attribute) theAttribute, DFBrowser_Module* theModule,
122                                                     int theRole, int theColumnId);
123
124   //! Returns information for the given attribute type name
125   //! \param theAttributeName a current attribute type name
126   //! \param theModule a current module
127   //! \param theRole a role of information, used by tree model (e.g. DisplayRole, icon, background and so on)
128   //! \param theColumnId a tree model column
129   //! \return value, interpreted by tree model depending on the role
130   Standard_EXPORT static QVariant GetAttributeInfo (Standard_CString theAttributeName, DFBrowser_Module* theModule,
131                                                     int theRole, int theColumnId);
132 signals:
133
134   //! Emits signal about updating tree model
135   void beforeUpdateTreeModel();
136
137 protected:
138
139   //! Tries to create attribute pane for the attribute name using registered attribute pane creators
140   //! \param theAttributeName a source attribute
141   //! \return attribute pane or NULL
142   DFBrowserPane_AttributePaneAPI* CreateAttributePane (Standard_CString theAttributeName);
143
144 private:
145
146   DFBrowser_TreeModel* myOCAFViewModel; //!< the tree view abstract model
147   QItemSelectionModel* myOCAFViewSelectionModel; //!< selection model over OCAF tree view
148   QMap<TCollection_AsciiString, DFBrowserPane_AttributePaneAPI*> myAttributeTypes; //!< container of created panes
149   QList<DFBrowserPane_AttributePaneCreatorAPI*> myPaneCreators; //!< pane creators
150   Handle(AIS_InteractiveContext) myExternalContext; //!< context that comes in initialize parameters
151 };
152
153 #endif