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_ItemSelection.hxx>
18 #include <AIS_ListOfInteractive.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <SelectMgr_Selection.hxx>
21 #include <SelectMgr_SensitiveEntity.hxx>
22 #include <Standard_Version.hxx>
23 #include <inspector/VInspector_ItemContext.hxx>
24 #include <inspector/VInspector_ItemPresentableObject.hxx>
25 #include <inspector/VInspector_ItemSensitiveEntity.hxx>
26 #include <inspector/VInspector_Tools.hxx>
28 #include <Standard_WarningsDisable.hxx>
29 #include <QStringList>
32 #include <Standard_WarningsRestore.hxx>
34 // =======================================================================
35 // function : getSelection
37 // =======================================================================
38 Handle(SelectMgr_Selection) VInspector_ItemSelection::getSelection() const
44 // =======================================================================
45 // function : initRowCount
47 // =======================================================================
48 int VInspector_ItemSelection::initRowCount() const
50 Handle(SelectMgr_Selection) aSelection = getSelection();
51 #if OCC_VERSION_HEX < 0x070201
53 for (aSelection->Init(); aSelection->More(); aSelection->Next())
57 return aSelection->Entities().Size();
61 // =======================================================================
62 // function : initValue
64 // =======================================================================
65 QVariant VInspector_ItemSelection::initValue (int theItemRole) const
75 case 0: return getSelection()->DynamicType()->Name();
76 case 1: return rowCount();
79 if (theItemRole == Qt::ToolTipRole)
83 VInspector_ItemPresentableObjectPtr aParentItem = itemDynamicCast<VInspector_ItemPresentableObject>(Parent());
84 return VInspector_Tools::SelectionModeToName(getSelection()->Mode(), aParentItem->GetInteractiveObject()).ToCString();
89 if (theItemRole == Qt::ToolTipRole)
90 return "SelectMgr_StateOfSelection";
93 SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
94 if (aState == SelectMgr_SOS_Activated || aState == SelectMgr_SOS_Any)
96 Handle(AIS_InteractiveContext) aContext = GetContext();
97 #if OCC_VERSION_HEX < 0x070201
98 for (mySelection->Init(); mySelection->More(); mySelection->Next())
100 const Handle(SelectBasics_EntityOwner)& anOwner = mySelection->Sensitive()->BaseSensitive()->OwnerId();
102 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (mySelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
104 const Handle(SelectBasics_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId();
106 if (VInspector_Tools::IsOwnerSelected(aContext, anOwner))
110 return aNbSelected > 0 ? QString::number (aNbSelected) : "";
115 SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
116 return VInspector_Tools::ToName (VInspector_SelectionType_StateOfSelection, aState).ToCString();
118 case 10: return QString::number (getSelection()->Sensitivity());
120 return VInspector_Tools::ToName (VInspector_SelectionType_TypeOfUpdate,
121 getSelection()->UpdateStatus()).ToCString();
123 return VInspector_Tools::ToName (VInspector_SelectionType_TypeOfBVHUpdate,
124 getSelection()->BVHUpdateStatus()).ToCString();
130 case Qt::ForegroundRole:
132 SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
133 return QVariant (aState == SelectMgr_SOS_Activated ? QColor (Qt::black) : QColor (Qt::darkGray));
139 // =======================================================================
140 // function : createChild
142 // =======================================================================
143 TreeModel_ItemBasePtr VInspector_ItemSelection::createChild (int theRow, int theColumn)
145 return VInspector_ItemSensitiveEntity::CreateItem (currentItem(), theRow, theColumn);
148 // =======================================================================
151 // =======================================================================
152 void VInspector_ItemSelection::Init()
154 VInspector_ItemPresentableObjectPtr aParentItem = itemDynamicCast<VInspector_ItemPresentableObject>(Parent());
156 Handle(AIS_InteractiveObject) anIO = aParentItem->GetInteractiveObject();
160 #if OCC_VERSION_HEX < 0x070201
161 for (anIO->Init(); anIO->More(); anIO->Next(), aCurrentId++)
163 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anIO->Selections()); aSelIter.More(); aSelIter.Next(), aCurrentId++)
166 if (aCurrentId != aRowId)
168 #if OCC_VERSION_HEX < 0x070201
169 mySelection = anIO->CurrentSelection();
171 mySelection = aSelIter.Value();
175 TreeModel_ItemBase::Init();
178 // =======================================================================
181 // =======================================================================
182 void VInspector_ItemSelection::Reset()
184 // an empty method to don't clear the main label, otherwise the model will be empty
185 TreeModel_ItemBase::Reset();
190 // =======================================================================
191 // function : initItem
193 // =======================================================================
194 void VInspector_ItemSelection::initItem() const
198 const_cast<VInspector_ItemSelection*>(this)->Init();
199 // an empty method to don't initialize the main label, as it was not cleared in Reset()