0029807: [Regression to 7.0.0] Impossible to cut cone from prism
[occt.git] / tools / VInspector / VInspector_ItemSelection.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_ItemSelection.hxx>
14bbbdcb 17
18#include <AIS_ListOfInteractive.hxx>
19#include <SelectMgr_EntityOwner.hxx>
20#include <SelectMgr_Selection.hxx>
21#include <SelectMgr_SensitiveEntity.hxx>
6822a3be 22#include <Standard_Version.hxx>
0cb512c0 23#include <inspector/VInspector_ItemContext.hxx>
24#include <inspector/VInspector_ItemPresentableObject.hxx>
25#include <inspector/VInspector_ItemSensitiveEntity.hxx>
26#include <inspector/VInspector_Tools.hxx>
14bbbdcb 27
130eb114 28#include <Standard_WarningsDisable.hxx>
130eb114 29#include <QStringList>
6822a3be 30
31#include <QColor>
130eb114 32#include <Standard_WarningsRestore.hxx>
14bbbdcb 33
34// =======================================================================
35// function : getSelection
36// purpose :
37// =======================================================================
38Handle(SelectMgr_Selection) VInspector_ItemSelection::getSelection() const
39{
40 initItem();
41 return mySelection;
42}
43
44// =======================================================================
45// function : initRowCount
46// purpose :
47// =======================================================================
48int VInspector_ItemSelection::initRowCount() const
49{
14bbbdcb 50 Handle(SelectMgr_Selection) aSelection = getSelection();
6822a3be 51#if OCC_VERSION_HEX < 0x070201
52 int aRows = 0;
53 for (aSelection->Init(); aSelection->More(); aSelection->Next())
54 aRows++;
55 return aRows;
56#else
b5cce1ab 57 return aSelection->Entities().Size();
6822a3be 58#endif
14bbbdcb 59}
60
61// =======================================================================
62// function : initValue
63// purpose :
64// =======================================================================
65QVariant VInspector_ItemSelection::initValue (int theItemRole) const
66{
67 switch (theItemRole)
68 {
69 case Qt::DisplayRole:
70 case Qt::EditRole:
71 case Qt::ToolTipRole:
72 {
73 switch (Column())
74 {
75 case 0: return getSelection()->DynamicType()->Name();
76 case 1: return rowCount();
77 case 3:
78 {
79 if (theItemRole == Qt::ToolTipRole)
80 return "Mode";
81 else
82 {
83 VInspector_ItemPresentableObjectPtr aParentItem = itemDynamicCast<VInspector_ItemPresentableObject>(Parent());
84 return VInspector_Tools::SelectionModeToName(getSelection()->Mode(), aParentItem->GetInteractiveObject()).ToCString();
85 }
86 }
87 case 4:
88 {
89 if (theItemRole == Qt::ToolTipRole)
90 return "SelectMgr_StateOfSelection";
91 else {
92 int aNbSelected = 0;
93 SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
94 if (aState == SelectMgr_SOS_Activated || aState == SelectMgr_SOS_Any)
95 {
96 Handle(AIS_InteractiveContext) aContext = GetContext();
6822a3be 97#if OCC_VERSION_HEX < 0x070201
98 for (mySelection->Init(); mySelection->More(); mySelection->Next())
99 {
100 const Handle(SelectBasics_EntityOwner)& anOwner = mySelection->Sensitive()->BaseSensitive()->OwnerId();
101#else
b5cce1ab 102 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (mySelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
14bbbdcb 103 {
b5cce1ab 104 const Handle(SelectBasics_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId();
6822a3be 105#endif
14bbbdcb 106 if (VInspector_Tools::IsOwnerSelected(aContext, anOwner))
107 aNbSelected++;
108 }
109 }
6822a3be 110 return aNbSelected > 0 ? QString::number (aNbSelected) : "";
14bbbdcb 111 }
112 }
6822a3be 113 case 9:
14bbbdcb 114 {
6822a3be 115 SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
116 return VInspector_Tools::ToName (VInspector_SelectionType_StateOfSelection, aState).ToCString();
14bbbdcb 117 }
6822a3be 118 case 10: return QString::number (getSelection()->Sensitivity());
119 case 11:
120 return VInspector_Tools::ToName (VInspector_SelectionType_TypeOfUpdate,
121 getSelection()->UpdateStatus()).ToCString();
122 case 12:
123 return VInspector_Tools::ToName (VInspector_SelectionType_TypeOfBVHUpdate,
124 getSelection()->BVHUpdateStatus()).ToCString();
14bbbdcb 125 default:
126 break;
127 }
128 break;
129 }
130 case Qt::ForegroundRole:
131 {
132 SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
133 return QVariant (aState == SelectMgr_SOS_Activated ? QColor (Qt::black) : QColor (Qt::darkGray));
134 }
135 }
136 return QVariant();
137}
138
139// =======================================================================
140// function : createChild
141// purpose :
142// =======================================================================
143TreeModel_ItemBasePtr VInspector_ItemSelection::createChild (int theRow, int theColumn)
144{
145 return VInspector_ItemSensitiveEntity::CreateItem (currentItem(), theRow, theColumn);
146}
147
148// =======================================================================
149// function : Init
150// purpose :
151// =======================================================================
152void VInspector_ItemSelection::Init()
153{
154 VInspector_ItemPresentableObjectPtr aParentItem = itemDynamicCast<VInspector_ItemPresentableObject>(Parent());
155
156 Handle(AIS_InteractiveObject) anIO = aParentItem->GetInteractiveObject();
157
158 int aRowId = Row();
159 int aCurrentId = 0;
6822a3be 160#if OCC_VERSION_HEX < 0x070201
161 for (anIO->Init(); anIO->More(); anIO->Next(), aCurrentId++)
162#else
b5cce1ab 163 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anIO->Selections()); aSelIter.More(); aSelIter.Next(), aCurrentId++)
6822a3be 164#endif
14bbbdcb 165 {
166 if (aCurrentId != aRowId)
167 continue;
6822a3be 168#if OCC_VERSION_HEX < 0x070201
169 mySelection = anIO->CurrentSelection();
170#else
b5cce1ab 171 mySelection = aSelIter.Value();
6822a3be 172#endif
14bbbdcb 173 break;
174 }
175 TreeModel_ItemBase::Init();
176}
177
178// =======================================================================
179// function : Reset
180// purpose :
181// =======================================================================
182void VInspector_ItemSelection::Reset()
183{
184 // an empty method to don't clear the main label, otherwise the model will be empty
185 TreeModel_ItemBase::Reset();
186
187 mySelection = NULL;
188}
189
190// =======================================================================
191// function : initItem
192// purpose :
193// =======================================================================
194void VInspector_ItemSelection::initItem() const
195{
196 if (IsInitialized())
197 return;
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()
200}