0030687: Visualization - remove redundant interfaces SelectBasics_EntityOwner and...
[occt.git] / tools / VInspector / VInspector_ViewModel.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_ViewModel.hxx>
14bbbdcb 17
6822a3be 18#include <inspector/TreeModel_Tools.hxx>
0cb512c0 19#include <inspector/VInspector_ItemContext.hxx>
20#include <inspector/VInspector_ItemEntityOwner.hxx>
21#include <inspector/VInspector_ItemPresentableObject.hxx>
22#include <inspector/VInspector_ItemSensitiveEntity.hxx>
0ef04197 23#include <SelectMgr_EntityOwner.hxx>
14bbbdcb 24
130eb114 25#include <Standard_WarningsDisable.hxx>
14bbbdcb 26#include <QItemSelectionModel>
27#include <QStringList>
130eb114 28#include <Standard_WarningsRestore.hxx>
14bbbdcb 29
6822a3be 30const int COLUMN_NAME_WIDTH = 260;
31const int COLUMN_SIZE_WIDTH = 30;
32const int COLUMN_POINTER_WIDTH = 70;
33const int COLUMN_SHAPE_TYPE_WIDTH = 75;
34
14bbbdcb 35// =======================================================================
36// function : Constructor
37// purpose :
38// =======================================================================
39VInspector_ViewModel::VInspector_ViewModel (QObject* theParent)
40 : TreeModel_ModelBase (theParent)
41{
6822a3be 42 SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
43 SetHeaderItem (1, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH));
44 SetHeaderItem (2, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH));
45 SetHeaderItem (3, TreeModel_HeaderSection ("ShapeType", COLUMN_SHAPE_TYPE_WIDTH)); // ItemPresentableObject, ItemSelection
46 SetHeaderItem (4, TreeModel_HeaderSection ("SelectedOwners", -1)); // ItemContext, ItemPresentableObject, ItemSelection
47 SetHeaderItem (5, TreeModel_HeaderSection ("ActivatedModes", -1)); // ItemPresentableObject
48 SetHeaderItem (6, TreeModel_HeaderSection ("DeviationCoefficient", -1, true)); // ItemContext, ItemPresentableObject
49 SetHeaderItem (7, TreeModel_HeaderSection ("Deflection", -1, true)); // ItemPresentableObject
50 SetHeaderItem (8, TreeModel_HeaderSection ("IsAutoTriangulation", -1, true)); // ItemPresentableObject
51
52 SetHeaderItem (9, TreeModel_HeaderSection ("SelectionState", -1)); // ItemSelection
53 SetHeaderItem (10, TreeModel_HeaderSection ("Sensitivity", -1, true)); // ItemSelection
54 SetHeaderItem (11, TreeModel_HeaderSection ("UpdateStatus", -1, true)); // ItemSelection
55 SetHeaderItem (12, TreeModel_HeaderSection ("BVHUpdateStatus", -1, true)); // ItemSelection
56
57 SetHeaderItem (13, TreeModel_HeaderSection ("IsActiveForSelection", -1, true)); // ItemSensitiveEntity
58 SetHeaderItem (14, TreeModel_HeaderSection ("SensitivityFactor", -1, true)); // ItemSensitiveEntity
59 SetHeaderItem (15, TreeModel_HeaderSection ("NbSubElements", -1, true)); // ItemSensitiveEntity
60 SetHeaderItem (16, TreeModel_HeaderSection ("Priority", -1, true)); // ItemSensitiveEntity
61
62 SetHeaderItem (17, TreeModel_HeaderSection ("TShape", COLUMN_POINTER_WIDTH, true)); // ItemEntityOwner
63 SetHeaderItem (18, TreeModel_HeaderSection ("Orientation", -1, true)); // ItemEntityOwner
64 SetHeaderItem (19, TreeModel_HeaderSection ("Location", -1, true)); // ItemEntityOwner
14bbbdcb 65
6822a3be 66 SetHeaderItem (20, TreeModel_HeaderSection ("Color", -1)); // ItemPresentableObject
67}
68
69// =======================================================================
70// function : createRootItem
71// purpose :
72// =======================================================================
73void VInspector_ViewModel::createRootItem (const int theColumnId)
74{
75 myRootItems.insert (theColumnId, VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId));
76 if (theColumnId == 0)
77 m_pRootItem = myRootItems[0];
14bbbdcb 78}
79
80// =======================================================================
81// function : GetContext
82// purpose :
83// =======================================================================
6822a3be 84Handle(AIS_InteractiveContext) VInspector_ViewModel::GetContext() const
14bbbdcb 85{
6822a3be 86 return itemDynamicCast<VInspector_ItemContext> (RootItem (0))->GetContext();
14bbbdcb 87}
88
89// =======================================================================
90// function : SetContext
91// purpose :
92// =======================================================================
93void VInspector_ViewModel::SetContext (const Handle(AIS_InteractiveContext)& theContext)
94{
95 // fill root item by the application
96 for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
97 itemDynamicCast<VInspector_ItemContext>(myRootItems[aColId])->SetContext (theContext);
98 EmitLayoutChanged();
99}
100
101// =======================================================================
102// function : FindPointers
103// purpose :
104// =======================================================================
105QModelIndexList VInspector_ViewModel::FindPointers (const QStringList& thePointers)
106{
107 QModelIndexList anIndices;
108 QModelIndex aParentIndex = index (0, 0);
109 TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // context item
110 for (int aRowId = 0, aCount = aParentItem->rowCount(); aRowId < aCount; aRowId++)
111 {
112 QModelIndex anIndex = index (aRowId, 0, aParentIndex);
113 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
114 VInspector_ItemPresentableObjectPtr anItemPrs = itemDynamicCast<VInspector_ItemPresentableObject>(anItemBase);
115 if (!anItemPrs)
116 continue;
117 if (thePointers.contains (anItemPrs->PointerInfo()))
118 anIndices.append (anIndex);
119 }
120 return anIndices;
121}
122
0cb512c0 123// =======================================================================
124// function : FindIndex
125// purpose :
126// =======================================================================
127QModelIndex VInspector_ViewModel::FindIndex (const Handle(AIS_InteractiveObject)& thePresentation) const
128{
129 QModelIndex aParentIndex = index (0, 0);
130 TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // context item
131 for (int aRowId = 0, aCount = aParentItem->rowCount(); aRowId < aCount; aRowId++)
132 {
133 QModelIndex anIndex = index (aRowId, 0, aParentIndex);
134 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
135 VInspector_ItemPresentableObjectPtr anItemPrs = itemDynamicCast<VInspector_ItemPresentableObject>(anItemBase);
136 if (!anItemPrs)
137 continue;
138 if (anItemPrs->GetInteractiveObject() == thePresentation)
139 return anIndex;
140 }
141 return QModelIndex();
142}
143
14bbbdcb 144// =======================================================================
145// function : GetSelectedOwners
146// purpose :
147// =======================================================================
148void VInspector_ViewModel::GetSelectedOwners (QItemSelectionModel* theSelectionModel,
0ef04197 149 NCollection_List<Handle(SelectMgr_EntityOwner)>& theOwners)
14bbbdcb 150{
151 if (!theSelectionModel)
152 return;
153 QList<TreeModel_ItemBasePtr> anItems;
154
155 QModelIndexList anIndices = theSelectionModel->selectedIndexes();
156 for (QModelIndexList::const_iterator anIndicesIt = anIndices.begin(); anIndicesIt != anIndices.end(); anIndicesIt++)
157 {
158 TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt);
159 if (!anItem || anItems.contains (anItem))
160 continue;
161 anItems.append (anItem);
162 }
163
164 QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
165 for (QList<TreeModel_ItemBasePtr>::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); anItemIt++)
166 {
167 TreeModel_ItemBasePtr anItem = *anItemIt;
0ef04197 168 Handle(SelectMgr_EntityOwner) anEntityOwner;
14bbbdcb 169 if (VInspector_ItemEntityOwnerPtr anOwnerItem = itemDynamicCast<VInspector_ItemEntityOwner>(anItem))
170 {
171 anEntityOwner = anOwnerItem->EntityOwner();
172 }
173 else if (VInspector_ItemSensitiveEntityPtr aSensItem = itemDynamicCast<VInspector_ItemSensitiveEntity>(anItem))
174 {
175 anEntityOwner = aSensItem->GetSensitiveEntity()->BaseSensitive()->OwnerId();
176 }
177 if (anEntityOwner.IsNull())
178 continue;
179 if (aSelectedIds.contains ((size_t)anEntityOwner.operator->()))
180 continue;
181 aSelectedIds.append ((size_t)anEntityOwner.operator->());
182 if (!anEntityOwner.IsNull())
183 theOwners.Append (anEntityOwner);
184 }
185}
6822a3be 186
187// =======================================================================
188// function : UpdateTreeModel
189// purpose :
190// =======================================================================
191void VInspector_ViewModel::UpdateTreeModel()
192{
193 Reset();
194 EmitLayoutChanged();
195}