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>
32 // =======================================================================
35 // =======================================================================
36 void DFBrowser_ThreadItemSearch::Run()
38 DFBrowser_TreeModel* aModel = dynamic_cast<DFBrowser_TreeModel*> (mySearchLine->GetModule()->GetOCAFViewModel());
39 Handle(TDocStd_Application) anApplication = aModel->GetTDocStdApplication();
40 if (anApplication.IsNull())
43 myDocumentValues.clear();
44 myDocumentInfoValues.clear();
46 QMap<QString, DFBrowser_SearchItemInfo> anAdditionalValues;
47 QStringList anInfoValues;
48 QStringList aCurrentPath;
49 for (Standard_Integer aDocId = 1, aNbDoc = anApplication->NbDocuments(); aDocId <= aNbDoc; aDocId++)
51 Handle(TDocStd_Document) aDocument;
52 anApplication->GetDocument (aDocId, aDocument);
53 if (aDocument.IsNull())
56 anAdditionalValues.clear();
59 getLabelLines (aDocument->Main().Root(), aCurrentPath, anAdditionalValues, anInfoValues);
61 myDocumentValues[aDocId] = anAdditionalValues;
62 myDocumentInfoValues[aDocId] = anInfoValues;
66 // =======================================================================
67 // function : ApplyValues
69 // =======================================================================
70 void DFBrowser_ThreadItemSearch::ApplyValues()
72 mySearchLine->SetValues (myDocumentValues, myDocumentInfoValues);
75 // =======================================================================
76 // function : ClearValues
78 // =======================================================================
79 void DFBrowser_ThreadItemSearch::ClearValues (DFBrowser_SearchLine* theSearchLine)
81 theSearchLine->ClearValues();
84 // =======================================================================
85 // function : getLabelLines
87 // =======================================================================
88 void DFBrowser_ThreadItemSearch::getLabelLines (const TDF_Label& theLabel, QStringList& theCurrentPath,
89 QMap<QString, DFBrowser_SearchItemInfo >& theValues,
90 QStringList& theInfoValues)
92 addLabel (theLabel, theCurrentPath, theValues, theInfoValues);
93 theCurrentPath.append (DFBrowserPane_Tools::GetEntry (theLabel).ToCString());
96 for (TDF_AttributeIterator anAttrIt (theLabel); anAttrIt.More(); anAttrIt.Next(), anId++)
97 addAttribute(anAttrIt.Value(), theCurrentPath, theValues, theInfoValues);
99 for (TDF_ChildIterator aChildIt (theLabel); aChildIt.More(); aChildIt.Next())
100 getLabelLines(aChildIt.Value(), theCurrentPath, theValues, theInfoValues);
102 theCurrentPath.removeLast();
105 // =======================================================================
106 // function : addLabel
108 // =======================================================================
109 void DFBrowser_ThreadItemSearch::addLabel (const TDF_Label& theLabel, const QStringList& theCurrentPath,
110 QMap<QString, DFBrowser_SearchItemInfo>& theValues,
111 QStringList& theInfoValues)
113 QString anEntry = DFBrowserPane_Tools::GetEntry (theLabel).ToCString();
114 if (!theValues.contains (anEntry))
116 theInfoValues.append (anEntry);
117 theValues[anEntry] = DFBrowser_SearchItemInfo ("40x40_label_icon", anEntry, theCurrentPath, QDir::separator());
121 // =======================================================================
122 // function : addAttribute
124 // =======================================================================
125 void DFBrowser_ThreadItemSearch::addAttribute (const Handle(TDF_Attribute)& theAttribute,
126 const QStringList& theCurrentPath,
127 QMap<QString, DFBrowser_SearchItemInfo >& theValues,
128 QStringList& theInfoValues)
130 Standard_CString anAttributeKind = theAttribute->DynamicType()->Name();
131 // add element of attribute kind
132 QString anAttributeName = QString ("%1%2%3").arg (anAttributeKind)
133 .arg (DFBrowser_SearchLineModel::SplitSeparator())
134 .arg (DFBrowserPane_Tools::GetEntry (theAttribute->Label()).ToCString());
136 if (!theInfoValues.contains (anAttributeName))
138 theInfoValues.append (anAttributeName);
139 theValues[anAttributeName] = DFBrowser_SearchItemInfo (QVariant(), anAttributeName, theCurrentPath,
143 // add element of attribute value, e.g. Name or Comment string
144 QString anAttributeValue;
145 if (anAttributeKind == STANDARD_TYPE (TDataStd_Name)->Name())
147 Handle(TDataStd_Name) anAttribute = Handle(TDataStd_Name)::DownCast (theAttribute);
148 anAttributeValue = DFBrowserPane_Tools::ToString (anAttribute->Get());
150 else if (anAttributeKind == STANDARD_TYPE (TDataStd_Comment)->Name())
152 Handle(TDataStd_Comment) anAttribute = Handle(TDataStd_Comment)::DownCast (theAttribute);
153 anAttributeValue = DFBrowserPane_Tools::ToString (anAttribute->Get());
158 if (anAttributeValue == "")
161 // using attribute value in the name
162 QString anAttributeValueExt = QString ("%1%2%3").arg (anAttributeValue)
163 .arg (DFBrowser_SearchLineModel::SplitSeparator())
164 .arg (DFBrowserPane_Tools::GetEntry (theAttribute->Label()).ToCString());
165 if (!theInfoValues.contains (anAttributeValueExt))
167 theInfoValues.append (anAttributeValueExt);
168 theValues[anAttributeValueExt] = DFBrowser_SearchItemInfo (QVariant(), anAttributeValueExt,
169 theCurrentPath, QDir::separator());