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 <inspector/DFBrowser_ThreadItemSearch.hxx>
18 #include <inspector/DFBrowser_Module.hxx>
19 #include <inspector/DFBrowser_Tools.hxx>
20 #include <inspector/DFBrowser_TreeModel.hxx>
21 #include <inspector/DFBrowser_SearchLine.hxx>
22 #include <inspector/DFBrowserPane_Tools.hxx>
24 #include <TDataStd_Comment.hxx>
25 #include <TDataStd_Name.hxx>
26 #include <TDataStd_UAttribute.hxx>
27 #include <TDF_AttributeIterator.hxx>
28 #include <TDF_ChildIterator.hxx>
30 #include <Standard_WarningsDisable.hxx>
32 #include <Standard_WarningsRestore.hxx>
34 // =======================================================================
37 // =======================================================================
38 void DFBrowser_ThreadItemSearch::Run()
40 DFBrowser_TreeModel* aModel = dynamic_cast<DFBrowser_TreeModel*> (mySearchLine->GetModule()->GetOCAFViewModel());
41 Handle(TDocStd_Application) anApplication = aModel->GetTDocStdApplication();
42 if (anApplication.IsNull())
45 myDocumentValues.clear();
46 myDocumentInfoValues.clear();
48 QMap<QString, DFBrowser_SearchItemInfo> anAdditionalValues;
49 QStringList anInfoValues;
50 QStringList aCurrentPath;
51 for (Standard_Integer aDocId = 1, aNbDoc = anApplication->NbDocuments(); aDocId <= aNbDoc; aDocId++)
53 Handle(TDocStd_Document) aDocument;
54 anApplication->GetDocument (aDocId, aDocument);
55 if (aDocument.IsNull())
58 anAdditionalValues.clear();
61 getLabelLines (aDocument->Main().Root(), aCurrentPath, anAdditionalValues, anInfoValues);
63 myDocumentValues[aDocId] = anAdditionalValues;
64 myDocumentInfoValues[aDocId] = anInfoValues;
68 // =======================================================================
69 // function : ApplyValues
71 // =======================================================================
72 void DFBrowser_ThreadItemSearch::ApplyValues()
74 mySearchLine->SetValues (myDocumentValues, myDocumentInfoValues);
77 // =======================================================================
78 // function : ClearValues
80 // =======================================================================
81 void DFBrowser_ThreadItemSearch::ClearValues (DFBrowser_SearchLine* theSearchLine)
83 theSearchLine->ClearValues();
86 // =======================================================================
87 // function : getLabelLines
89 // =======================================================================
90 void DFBrowser_ThreadItemSearch::getLabelLines (const TDF_Label& theLabel, QStringList& theCurrentPath,
91 QMap<QString, DFBrowser_SearchItemInfo >& theValues,
92 QStringList& theInfoValues)
94 addLabel (theLabel, theCurrentPath, theValues, theInfoValues);
95 theCurrentPath.append (DFBrowserPane_Tools::GetEntry (theLabel).ToCString());
98 for (TDF_AttributeIterator anAttrIt (theLabel); anAttrIt.More(); anAttrIt.Next(), anId++)
99 addAttribute(anAttrIt.Value(), theCurrentPath, theValues, theInfoValues);
101 for (TDF_ChildIterator aChildIt (theLabel); aChildIt.More(); aChildIt.Next())
102 getLabelLines(aChildIt.Value(), theCurrentPath, theValues, theInfoValues);
104 theCurrentPath.removeLast();
107 // =======================================================================
108 // function : addLabel
110 // =======================================================================
111 void DFBrowser_ThreadItemSearch::addLabel (const TDF_Label& theLabel, const QStringList& theCurrentPath,
112 QMap<QString, DFBrowser_SearchItemInfo>& theValues,
113 QStringList& theInfoValues)
115 QString anEntry = DFBrowserPane_Tools::GetEntry (theLabel).ToCString();
116 if (!theValues.contains (anEntry))
118 theInfoValues.append (anEntry);
119 theValues[anEntry] = DFBrowser_SearchItemInfo ("40x40_label_icon", anEntry, theCurrentPath, QDir::separator());
123 // =======================================================================
124 // function : addAttribute
126 // =======================================================================
127 void DFBrowser_ThreadItemSearch::addAttribute (const Handle(TDF_Attribute)& theAttribute,
128 const QStringList& theCurrentPath,
129 QMap<QString, DFBrowser_SearchItemInfo >& theValues,
130 QStringList& theInfoValues)
132 Standard_CString anAttributeKind = theAttribute->DynamicType()->Name();
133 // add element of attribute kind
134 QString anAttributeName = QString ("%1%2%3").arg (anAttributeKind)
135 .arg (DFBrowser_SearchLineModel::SplitSeparator())
136 .arg (DFBrowserPane_Tools::GetEntry (theAttribute->Label()).ToCString());
138 if (!theInfoValues.contains (anAttributeName))
140 theInfoValues.append (anAttributeName);
141 theValues[anAttributeName] = DFBrowser_SearchItemInfo (QVariant(), anAttributeName, theCurrentPath,
145 // add element of attribute value, e.g. Name or Comment string
146 QString anAttributeValue;
147 if (anAttributeKind == STANDARD_TYPE (TDataStd_Name)->Name())
149 Handle(TDataStd_Name) anAttribute = Handle(TDataStd_Name)::DownCast (theAttribute);
150 anAttributeValue = DFBrowserPane_Tools::ToString (anAttribute->Get());
152 else if (anAttributeKind == STANDARD_TYPE (TDataStd_Comment)->Name())
154 Handle(TDataStd_Comment) anAttribute = Handle(TDataStd_Comment)::DownCast (theAttribute);
155 anAttributeValue = DFBrowserPane_Tools::ToString (anAttribute->Get());
160 if (anAttributeValue == "")
163 // using attribute value in the name
164 QString anAttributeValueExt = QString ("%1%2%3").arg (anAttributeValue)
165 .arg (DFBrowser_SearchLineModel::SplitSeparator())
166 .arg (DFBrowserPane_Tools::GetEntry (theAttribute->Label()).ToCString());
167 if (!theInfoValues.contains (anAttributeValueExt))
169 theInfoValues.append (anAttributeValueExt);
170 theValues[anAttributeValueExt] = DFBrowser_SearchItemInfo (QVariant(), anAttributeValueExt,
171 theCurrentPath, QDir::separator());