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 //#define DEBUG_FREE_OWNERS
25 // =======================================================================
26 // function : initRowCount
28 // =======================================================================
29 int VInspector_ItemContext::initRowCount() const
34 int aNbPresentations = 0;
35 if (!GetContext().IsNull())
37 AIS_ListOfInteractive aListOfIO;
38 GetContext()->DisplayedObjects (aListOfIO);
39 GetContext()->ErasedObjects(aListOfIO);
40 aNbPresentations = aListOfIO.Extent();
42 // owners without Presentation
43 #ifdef DEBUG_FREE_OWNERS
45 // only local context is processed: TODO for global context
46 Handle(AIS_InteractiveContext) aContext = GetContext();
47 if (!aContext.IsNull()) {
48 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
49 aContext->MainSelector()->ActiveOwners(anActiveOwners);
51 Handle(SelectMgr_EntityOwner) anOwner;
52 for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(anActiveOwners);
53 anOwnersIt.More(); anOwnersIt.Next())
55 anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
58 Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
59 if (anAISObj.IsNull())
64 // owners in Global Context
65 if (!aContext.IsNull())
67 NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
68 aContext->MainSelector()->ActiveOwners(anActiveOwners);
71 aNbPresentations += aRows;
73 #ifdef DEBUG_FREE_OWNERS
74 NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
75 NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
76 VInspector_Tools::ActiveOwners (GetContext(), anEmptySelectableOwners);
77 if (anEmptySelectableOwners.Size() > 0)
78 aNbPresentations += 1;
80 return aNbPresentations;
83 // =======================================================================
84 // function : initValue
86 // =======================================================================
87 QVariant VInspector_ItemContext::initValue (const int theItemRole) const
89 if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
94 case 0: return GetContext()->DynamicType()->Name();
95 case 1: return rowCount();
98 if (theItemRole == Qt::ToolTipRole)
99 return "Selected Owners";
102 Handle(AIS_InteractiveObject) anEmptyIO;
103 int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false);
104 return aSelectedCount > 0 ? QString::number (aSelectedCount) : "";
109 if (theItemRole == Qt::ToolTipRole)
110 return QString ("All Owners/Active Owners");
113 NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
114 NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
115 VInspector_Tools::ActiveOwners (GetContext(), anEmptySelectableOwners);
116 int anActiveOwners = anOwners.Size();
117 anOwners = VInspector_Tools::ContextOwners (GetContext());
118 return QString ("%1 / %2").arg (anOwners.Size()).arg (anActiveOwners);
123 if (theItemRole == Qt::ToolTipRole)
124 return QString ("DeviationCoefficient");
126 return GetContext()->DeviationCoefficient();
134 // =======================================================================
135 // function : createChild
137 // =======================================================================
138 TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn)
140 return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);