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