d3635891b754429919ea09945971b9ab1a137fb0
[occt.git] / tools / DFBrowser / DFBrowser_ThreadItemUsedShapesMap.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_ThreadItemUsedShapesMap_H
17 #define DFBROWSER_ThreadItemUsedShapesMap_H
18
19 #include <DFBrowser_ThreadItem.hxx>
20 #include <NCollection_DataMap.hxx>
21 #include <Standard.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TDF_Attribute.hxx>
24
25 #ifdef _MSC_VER
26 #pragma warning(disable : 4127) // conditional expression is constant
27 #endif
28 #include <QStringList>
29 #include <QPair>
30
31 class DFBrowser_Module;
32
33 //! \class DFBrowser_ThreadItemUsedShapesMap
34 //! Collects and sorts map values of TNaming_UsedShape attributes. Applies values to the OCAF tree view model
35 class DFBrowser_ThreadItemUsedShapesMap : public DFBrowser_ThreadItem
36 {
37 public:
38
39   //! Constructor
40   DFBrowser_ThreadItemUsedShapesMap() : myModule (0) {}
41
42   //! Destructor
43   virtual ~DFBrowser_ThreadItemUsedShapesMap() {}
44
45   //! Sets the current module
46   void SetModule (DFBrowser_Module* theModule) { myModule = theModule; }
47
48   //! Iterates by application documents and for TNaming_UsedShape attribute collects container of sorted values.
49   Standard_EXPORT virtual void Run() Standard_OVERRIDE;
50
51   //! Initialize tree view model of OCAF by internal container of sorted values.
52   Standard_EXPORT virtual void ApplyValues() Standard_OVERRIDE;
53
54   //! Set empty cache into tree view model of OCAF. Calls Init of these item by usual values (not sorted)
55   Standard_EXPORT static void ClearSortedReferences (DFBrowser_Module* theModule);
56
57 private:
58
59   //! Collects sorted values of the attribute if the attribute has TNaming_UsedShape type
60   //! \param theAttribute a processed attribute
61   //! \param theReferences a output container of sorted references
62   void findReferences (Handle(TDF_Attribute) theAttribute, std::list<TCollection_AsciiString>& theReferences);
63
64   //! Checks whether the left path is less than the right path
65   //! \param theLeft path to label
66   //! \param theRight path to label
67   //! \returns true if the left path is less(not equal) than right path
68   static bool isLessThan (const QStringList& theLeft, const QStringList& theRight);
69
70   //! Insert entry into container of entries using sorting. It is split by ":" separator to perform soring
71   //! \param theEntry a label entry
72   //! \param theEntries a result container
73   void addValue (const TCollection_AsciiString& theEntry, QList<QPair<TCollection_AsciiString, QStringList > >& theEntries);
74
75 private:
76
77   DFBrowser_Module* myModule; //!< the current module
78   NCollection_DataMap<Handle(TDF_Attribute), std::list<TCollection_AsciiString> > myAttributeRefs; //!< sorted references
79 };
80
81 #endif