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 #include <DFBrowser_Module.hxx>
18 #include <DFBrowser_Item.hxx>
19 #include <DFBrowser_ItemApplication.hxx>
20 #include <DFBrowser_ItemBase.hxx>
21 #include <DFBrowser_ItemRole.hxx>
22 #include <DFBrowser_Tools.hxx>
23 #include <DFBrowser_TreeModel.hxx>
25 #include <DFBrowserPane_AttributePane.hxx>
26 #include <DFBrowserPane_AttributePaneCreator.hxx>
27 #include <DFBrowserPane_ItemRole.hxx>
28 #include <DFBrowserPane_Tools.hxx>
30 #include <DFBrowserPaneXDE_AttributePaneCreator.hxx>
31 #include <DFBrowserPaneXDE_Tools.hxx>
33 #include <XCAFApp_Application.hxx>
35 #include <QItemSelectionModel>
36 #include <QMessageBox>
38 // =======================================================================
39 // function : Constructor
41 // =======================================================================
42 DFBrowser_Module::DFBrowser_Module()
45 RegisterPaneCreator (new DFBrowserPane_AttributePaneCreator());
48 // =======================================================================
49 // function : CreateViewModel
51 // =======================================================================
52 void DFBrowser_Module::CreateViewModel (void* theParent)
54 myOCAFViewModel = new DFBrowser_TreeModel ((QWidget*)theParent, this);
57 // =======================================================================
58 // function : SetApplication
60 // =======================================================================
61 void DFBrowser_Module::SetApplication (const Handle(TDocStd_Application)& theApplication)
63 myOCAFViewModel->Init (theApplication);
65 myPaneCreators.clear();
66 RegisterPaneCreator (new DFBrowserPane_AttributePaneCreator());
67 if (!theApplication.IsNull() && DFBrowserPaneXDE_Tools::IsXDEApplication (theApplication))
68 RegisterPaneCreator (new DFBrowserPaneXDE_AttributePaneCreator (myPaneCreators[0]));
71 // =======================================================================
72 // function : SetExternalContext
74 // =======================================================================
75 void DFBrowser_Module::SetExternalContext (const Handle(Standard_Transient)& theContext)
77 myExternalContext = Handle(AIS_InteractiveContext)::DownCast (theContext);
80 // =======================================================================
81 // function : GetTDocStdApplication
83 // =======================================================================
84 Handle(TDocStd_Application) DFBrowser_Module::GetTDocStdApplication() const
86 return myOCAFViewModel->GetTDocStdApplication();
89 // =======================================================================
90 // function : UpdateTreeModel
92 // =======================================================================
93 void DFBrowser_Module::UpdateTreeModel()
95 QAbstractItemModel* aModel = GetOCAFViewModel();
96 QItemSelectionModel* aSelectionModel = GetOCAFViewSelectionModel();
97 if (!aModel || !aSelectionModel)
99 aSelectionModel->clearSelection();
101 emit beforeUpdateTreeModel();
102 myOCAFViewModel->Reset();
103 myOCAFViewModel->EmitLayoutChanged();
105 SetInitialTreeViewSelection();
108 // =======================================================================
109 // function : SetInitialTreeViewSelection
111 // =======================================================================
112 void DFBrowser_Module::SetInitialTreeViewSelection()
114 QAbstractItemModel* aModel = GetOCAFViewModel();
115 QItemSelectionModel* aSelectionModel = GetOCAFViewSelectionModel();
116 if (!aModel || !aSelectionModel)
119 // select a parent(aplication) item
120 aSelectionModel->select (aModel->index (0, 0), QItemSelectionModel::ClearAndSelect);
123 // =======================================================================
124 // function : FindAttribute
126 // =======================================================================
127 Handle(TDF_Attribute) DFBrowser_Module::FindAttribute (const QModelIndex& theIndex)
129 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theIndex);
131 return Handle(TDF_Attribute)();
133 DFBrowser_ItemPtr anItem = itemDynamicCast<DFBrowser_Item> (anItemBase);
134 return (anItem && anItem->HasAttribute()) ? anItem->GetAttribute() : Handle(TDF_Attribute)();
137 // =======================================================================
138 // function : GetAttributePane
140 // =======================================================================
141 DFBrowserPane_AttributePaneAPI* DFBrowser_Module::GetAttributePane (Handle(TDF_Attribute) theAttribute)
143 DFBrowserPane_AttributePaneAPI* aPane = 0;
144 if (theAttribute.IsNull())
146 return GetAttributePane (theAttribute->DynamicType()->Name());
149 // =======================================================================
150 // function : GetAttributePane
152 // =======================================================================
153 DFBrowserPane_AttributePaneAPI* DFBrowser_Module::GetAttributePane (const Standard_CString& theAttributeName)
155 DFBrowserPane_AttributePaneAPI* aPane = 0;
157 if (!myAttributeTypes.contains (theAttributeName))
159 aPane = CreateAttributePane (theAttributeName);
161 myAttributeTypes[theAttributeName] = aPane;
164 aPane = myAttributeTypes[theAttributeName];
169 // =======================================================================
170 // function : GetAttributeInfo
172 // =======================================================================
173 QVariant DFBrowser_Module::GetAttributeInfo (Handle(TDF_Attribute) theAttribute, DFBrowser_Module* theModule,
174 int theRole, int theColumnId)
176 DFBrowserPane_AttributePane* anAttributePane = 0;
177 if (!theAttribute.IsNull())
179 DFBrowserPane_AttributePaneAPI* anAPIPane = theModule->GetAttributePane (theAttribute);
181 anAttributePane = dynamic_cast<DFBrowserPane_AttributePane*> (anAPIPane);
186 aValue = anAttributePane->GetAttributeInfo (theAttribute,
187 theRole == DFBrowser_ItemRole_AdditionalInfo ? DFBrowserPane_ItemRole_ShortInfo : theRole,
190 aValue = DFBrowserPane_AttributePane::GetAttributeInfoByType (theAttribute->DynamicType()->Name(), theRole, theColumnId);
194 // =======================================================================
195 // function : GetAttributeInfo
197 // =======================================================================
198 QVariant DFBrowser_Module::GetAttributeInfo (const Standard_CString& theAttributeName, DFBrowser_Module* theModule,
199 int theRole, int theColumnId)
201 DFBrowserPane_AttributePane* anAttributePane = 0;
202 DFBrowserPane_AttributePaneAPI* anAPIPane = theModule->GetAttributePane (theAttributeName);
204 anAttributePane = dynamic_cast<DFBrowserPane_AttributePane*> (anAPIPane);
209 Handle(TDF_Attribute) anAttribute;
210 aValue = anAttributePane->GetAttributeInfo (anAttribute,
211 theRole == DFBrowser_ItemRole_AdditionalInfo ? DFBrowserPane_ItemRole_ShortInfo : theRole, theColumnId);
214 aValue = DFBrowserPane_AttributePane::GetAttributeInfoByType (theAttributeName, theRole, theColumnId);
219 // =======================================================================
220 // function : CreateAttributePane
222 // =======================================================================
223 DFBrowserPane_AttributePaneAPI* DFBrowser_Module::CreateAttributePane (const Standard_CString& theAttributeName)
225 DFBrowserPane_AttributePaneAPI* aPane = 0;
226 // iteration should be performed from the tail of the list, as latest added creator has
228 for (int aPaneCreatorId = myPaneCreators.size()-1; aPaneCreatorId >= 0 && !aPane; aPaneCreatorId--)
229 aPane = myPaneCreators[aPaneCreatorId]->CreateAttributePane (theAttributeName);