0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / VInspector / VInspector_ItemContext.cxx
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 #include <inspector/VInspector_ItemContext.hxx>
17
18 #include <AIS_ListOfInteractive.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <inspector/VInspector_ItemPresentableObject.hxx>
21 #include <inspector/VInspector_Tools.hxx>
22
23 #include <QStringList>
24
25 //#define DEBUG_FREE_OWNERS
26
27 // =======================================================================
28 // function : initRowCount
29 // purpose :
30 // =======================================================================
31 int VInspector_ItemContext::initRowCount() const
32 {
33   if (Column() != 0)
34     return 0;
35
36   int aNbPresentations = 0;
37   if (!GetContext().IsNull())
38   {
39     AIS_ListOfInteractive aListOfIO;
40     GetContext()->DisplayedObjects (aListOfIO);
41     GetContext()->ErasedObjects(aListOfIO);
42     aNbPresentations = aListOfIO.Extent();
43   }
44   // owners without Presentation
45 #ifdef DEBUG_FREE_OWNERS
46   int aRows = 0;
47   // only local context is processed: TODO for global context
48   Handle(AIS_InteractiveContext) aContext = GetContext();
49   if (!aContext.IsNull()) {
50     NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
51     aContext->MainSelector()->ActiveOwners(anActiveOwners);
52
53     Handle(SelectMgr_EntityOwner) anOwner;
54     for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(anActiveOwners);
55       anOwnersIt.More(); anOwnersIt.Next())
56     {
57       anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
58       if (anOwner.IsNull())
59         continue;
60       Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
61       if (anAISObj.IsNull())
62         aRows++;
63     }
64   }
65
66   // owners in Global Context
67   if (!aContext.IsNull())
68   {
69     NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
70     aContext->MainSelector()->ActiveOwners(anActiveOwners);
71   }
72   if (aRows > 0)
73     aNbPresentations += aRows;
74 #endif
75 #ifdef DEBUG_FREE_OWNERS
76   NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
77   NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
78     VInspector_Tools::ActiveOwners (GetContext(), anEmptySelectableOwners);
79   if (anEmptySelectableOwners.Size() > 0)
80     aNbPresentations += 1;
81 #endif
82   return aNbPresentations;
83 }
84
85 // =======================================================================
86 // function : initValue
87 // purpose :
88 // =======================================================================
89 QVariant VInspector_ItemContext::initValue (const int theItemRole) const
90 {
91   if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
92     return QVariant();
93
94   switch (Column())
95   {
96     case 0: return GetContext()->DynamicType()->Name();
97     case 1: return rowCount();
98     case 4:
99     {
100       if (theItemRole == Qt::ToolTipRole)
101         return "Selected Owners";
102       else
103       {
104         Handle(AIS_InteractiveObject) anEmptyIO;
105         int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false);
106         return aSelectedCount > 0 ? QString::number (aSelectedCount) : "";
107       }
108     }
109     case 7:
110     {
111       if (theItemRole == Qt::ToolTipRole)
112         return QString ("All Owners/Active Owners");
113       else
114       {
115         NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
116         NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
117                  VInspector_Tools::ActiveOwners (GetContext(), anEmptySelectableOwners);
118         int anActiveOwners = anOwners.Size();
119         anOwners = VInspector_Tools::ContextOwners (GetContext());
120         return QString ("%1 / %2").arg (anOwners.Size()).arg (anActiveOwners);
121       }
122     }
123     case 8:
124     {
125       if (theItemRole == Qt::ToolTipRole)
126         return QString ("DeviationCoefficient");
127       else
128         return GetContext()->DeviationCoefficient();
129     }
130     default:
131       break;
132   }
133   return QVariant();
134 }
135
136 // =======================================================================
137 // function : createChild
138 // purpose :
139 // =======================================================================
140 TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn)
141 {
142   return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);
143 }