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