0029674: Improvements in Inspector tool
[occt.git] / tools / VInspector / VInspector_ItemContext.cxx
CommitLineData
14bbbdcb 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
0cb512c0 16#include <inspector/VInspector_ItemContext.hxx>
14bbbdcb 17
18#include <AIS_ListOfInteractive.hxx>
19#include <SelectMgr_EntityOwner.hxx>
6822a3be 20#include <inspector/VInspector_ItemFolderObject.hxx>
0cb512c0 21#include <inspector/VInspector_ItemPresentableObject.hxx>
22#include <inspector/VInspector_Tools.hxx>
14bbbdcb 23
6822a3be 24#include <Standard_WarningsDisable.hxx>
25#include <QStringList>
26#include <Standard_WarningsRestore.hxx>
27
14bbbdcb 28//#define DEBUG_FREE_OWNERS
29
30// =======================================================================
31// function : initRowCount
32// purpose :
33// =======================================================================
34int VInspector_ItemContext::initRowCount() const
35{
36 if (Column() != 0)
37 return 0;
38
6822a3be 39 int aNbProperties = 1; // item to visualize Filters/Drawer information of context
40
14bbbdcb 41 int aNbPresentations = 0;
6822a3be 42 Handle(AIS_InteractiveContext) aContext = GetContext();
43 if (aContext.IsNull())
44 return 0;
45
46 AIS_ListOfInteractive aListOfIO;
47 aContext->DisplayedObjects (aListOfIO);
48 aContext->ErasedObjects(aListOfIO);
49 aNbPresentations = aListOfIO.Extent();
50
14bbbdcb 51 // owners without Presentation
52#ifdef DEBUG_FREE_OWNERS
53 int aRows = 0;
54 // only local context is processed: TODO for global context
6822a3be 55 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
56 aContext->MainSelector()->ActiveOwners(anActiveOwners);
14bbbdcb 57
6822a3be 58 Handle(SelectMgr_EntityOwner) anOwner;
59 for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(anActiveOwners);
60 anOwnersIt.More(); anOwnersIt.Next())
14bbbdcb 61 {
6822a3be 62 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
63 if (anOwner.IsNull())
64 continue;
65 Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
66 if (anAISObj.IsNull())
67 aRows++;
14bbbdcb 68 }
6822a3be 69 // owners in Global Context
70 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
71 aContext->MainSelector()->ActiveOwners(anActiveOwners);
14bbbdcb 72 if (aRows > 0)
73 aNbPresentations += aRows;
14bbbdcb 74 NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
75 NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
6822a3be 76 VInspector_Tools::ActiveOwners (aContext, anEmptySelectableOwners);
14bbbdcb 77 if (anEmptySelectableOwners.Size() > 0)
78 aNbPresentations += 1;
79#endif
6822a3be 80 return aNbProperties + aNbPresentations;
14bbbdcb 81}
82
83// =======================================================================
84// function : initValue
85// purpose :
86// =======================================================================
87QVariant VInspector_ItemContext::initValue (const int theItemRole) const
88{
89 if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
90 return QVariant();
91
6822a3be 92 if (GetContext().IsNull())
93 return Column() == 0 ? "Empty context" : "";
94
14bbbdcb 95 switch (Column())
96 {
97 case 0: return GetContext()->DynamicType()->Name();
98 case 1: return rowCount();
99 case 4:
100 {
6822a3be 101 Handle(AIS_InteractiveObject) anEmptyIO;
102 int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false);
103 return aSelectedCount > 0 ? QString::number (aSelectedCount) : "";
14bbbdcb 104 }
6822a3be 105 case 6: return GetContext()->DeviationCoefficient();
14bbbdcb 106 default:
107 break;
108 }
109 return QVariant();
110}
111
112// =======================================================================
113// function : createChild
114// purpose :
115// =======================================================================
116TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn)
117{
6822a3be 118 if (theRow == 0)
119 return VInspector_ItemFolderObject::CreateItem (currentItem(), theRow, theColumn);
120 else
121 return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);
14bbbdcb 122}