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/VInspector_ItemContext.hxx>
18 #include <AIS_ListOfInteractive.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <inspector/VInspector_ItemPresentableObject.hxx>
21 #include <inspector/VInspector_Tools.hxx>
23 #include <QStringList>
25 //#define DEBUG_FREE_OWNERS
27 // =======================================================================
28 // function : initRowCount
30 // =======================================================================
31 int VInspector_ItemContext::initRowCount() const
36 int aNbPresentations = 0;
37 if (!GetContext().IsNull())
39 AIS_ListOfInteractive aListOfIO;
40 GetContext()->DisplayedObjects (aListOfIO);
41 GetContext()->ErasedObjects(aListOfIO);
42 aNbPresentations = aListOfIO.Extent();
44 // owners without Presentation
45 #ifdef DEBUG_FREE_OWNERS
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);
53 Handle(SelectMgr_EntityOwner) anOwner;
54 for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(anActiveOwners);
55 anOwnersIt.More(); anOwnersIt.Next())
57 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
60 Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
61 if (anAISObj.IsNull())
66 // owners in Global Context
67 if (!aContext.IsNull())
69 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
70 aContext->MainSelector()->ActiveOwners(anActiveOwners);
73 aNbPresentations += aRows;
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;
82 return aNbPresentations;
85 // =======================================================================
86 // function : initValue
88 // =======================================================================
89 QVariant VInspector_ItemContext::initValue (const int theItemRole) const
91 if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
96 case 0: return GetContext()->DynamicType()->Name();
97 case 1: return rowCount();
100 if (theItemRole == Qt::ToolTipRole)
101 return "Selected Owners";
104 Handle(AIS_InteractiveObject) anEmptyIO;
105 int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false);
106 return aSelectedCount > 0 ? QString::number (aSelectedCount) : "";
111 if (theItemRole == Qt::ToolTipRole)
112 return QString ("All Owners/Active Owners");
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);
125 if (theItemRole == Qt::ToolTipRole)
126 return QString ("DeviationCoefficient");
128 return GetContext()->DeviationCoefficient();
136 // =======================================================================
137 // function : createChild
139 // =======================================================================
140 TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn)
142 return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);