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