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_ItemPresentableObject.hxx>
18 #include <AIS_Shape.hxx>
19 #include <AIS_ListOfInteractive.hxx>
20 #include <AIS_ListIteratorOfListOfInteractive.hxx>
21 #include <inspector/VInspector_ItemContext.hxx>
22 #include <inspector/VInspector_ItemEntityOwner.hxx>
23 #include <inspector/VInspector_ItemSelection.hxx>
24 #include <inspector/VInspector_Tools.hxx>
25 #include <inspector/VInspector_ViewModel.hxx>
27 #include <NCollection_List.hxx>
29 #include <Prs3d_Drawer.hxx>
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <StdSelect_BRepOwner.hxx>
32 #include <Standard_Version.hxx>
34 #include <Standard_WarningsDisable.hxx>
36 #include <QItemSelectionModel>
37 #include <Standard_WarningsRestore.hxx>
39 // =======================================================================
40 // function : initValue
42 // =======================================================================
43 QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const
45 if (Column() == 20 && theItemRole == Qt::BackgroundRole) {
46 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
47 if (!anIO.IsNull() && anIO->HasColor())
49 Quantity_Color aColor;
51 return QColor ((int)(aColor.Red()*255.), (int)(aColor.Green()*255.), (int)(aColor.Blue()*255.));
55 if (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole)
57 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
58 bool aNullIO = anIO.IsNull();
64 return theItemRole == Qt::ToolTipRole ? QVariant ("Owners where Selectable is empty")
65 : QVariant ("Free Owners");
67 return theItemRole == Qt::ToolTipRole ? QVariant ("")
68 : QVariant (anIO->DynamicType()->Name());
75 return VInspector_Tools::GetPointerInfo (anIO, true).ToCString();
80 Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
81 if (!aShapeIO.IsNull())
83 const TopoDS_Shape& aShape = aShapeIO->Shape();
85 return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
91 int aNbSelected = VInspector_Tools::SelectedOwners (GetContext(), anIO, false);
92 return aNbSelected > 0 ? QString::number (aNbSelected) : "";
96 TColStd_ListOfInteger aModes;
97 Handle(AIS_InteractiveContext) aContext = GetContext();
98 aContext->ActivatedModes(anIO, aModes);
99 TCollection_AsciiString aModesInfo;
100 for (TColStd_ListIteratorOfListOfInteger itr (aModes); itr.More(); itr.Next())
102 if (!aModesInfo.IsEmpty())
104 aModesInfo += VInspector_Tools::GetShapeTypeInfo (AIS_Shape::SelectionType(itr.Value()));
106 return aModesInfo.ToCString();
111 double aDeviationCoefficient = 0;
112 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
113 if (!anAISShape.IsNull())
115 Standard_Real aPreviousCoefficient;
116 anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
118 return QString::number(aDeviationCoefficient);
122 double aShapeDeflection = 0;
123 Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
124 if (!aShapeIO.IsNull())
126 const TopoDS_Shape& aShape = aShapeIO->Shape();
127 if (!aShape.IsNull())
128 aShapeDeflection = Prs3d::GetDeflection(aShape, anIO->Attributes());
130 return QString::number (aShapeDeflection);
134 double aDeviationCoefficient = 0;
135 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
136 if (!anAISShape.IsNull())
138 Standard_Real aPreviousCoefficient;
139 anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
141 Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
142 bool anIsAutoTriangulation = aNullIO ? false : anIO->Attributes()->IsAutoTriangulation();
143 return anIsAutoTriangulation ? QString ("true") : QString ("false");
149 Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
150 if (aShapeIO.IsNull())
152 const TopoDS_Shape& aShape = aShapeIO->Shape();
156 return Column() == 17 ? VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString()
157 : Column() == 18 ? VInspector_Tools::OrientationToName (aShape.Orientation()).ToCString()
158 : /*19*/ VInspector_Tools::LocationToName (aShape.Location()).ToCString();
163 if (theItemRole == Qt::BackgroundRole || theItemRole == Qt::ForegroundRole)
165 Handle(AIS_InteractiveContext) aContext = GetContext();
166 if (Column() == 2 && VInspector_Tools::SelectedOwners(aContext, GetInteractiveObject(), false) > 0)
168 return (theItemRole == Qt::BackgroundRole) ? QColor(Qt::darkBlue) : QColor(Qt::white);
170 else if (theItemRole == Qt::ForegroundRole)
172 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
176 AIS_ListOfInteractive aListOfIO;
177 GetContext()->ErasedObjects(aListOfIO);
178 for (AIS_ListIteratorOfListOfInteractive anIOIt(aListOfIO); anIOIt.More(); anIOIt.Next())
180 if (anIO == anIOIt.Value())
181 return QColor(Qt::darkGray);
183 return QColor(Qt::black);
189 // =======================================================================
190 // function : initRowCount
192 // =======================================================================
193 int VInspector_ItemPresentableObject::initRowCount() const
195 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
196 #if OCC_VERSION_HEX < 0x070201
200 // iteration through sensitive privitives
201 for (anIO->Init(); anIO->More(); anIO->Next())
205 return !anIO.IsNull()
206 ? anIO->Selections().Size()
211 // =======================================================================
212 // function : createChild
214 // =======================================================================
215 TreeModel_ItemBasePtr VInspector_ItemPresentableObject::createChild (int theRow, int theColumn)
217 return VInspector_ItemSelection::CreateItem(currentItem(), theRow, theColumn);
220 // =======================================================================
223 // =======================================================================
224 void VInspector_ItemPresentableObject::Init()
226 VInspector_ItemContextPtr aParentItem = itemDynamicCast<VInspector_ItemContext>(Parent());
227 Handle(AIS_InteractiveContext) aContext = aParentItem->GetContext();
228 SetContext (aContext);
230 Handle(AIS_InteractiveObject) anIO;
231 if (!GetContext().IsNull())
234 AIS_ListOfInteractive aListOfIO;
235 GetContext()->DisplayedObjects (aListOfIO); // the presentation is in displayed objects of Context
236 GetContext()->ErasedObjects (aListOfIO); // the presentation is in erased objects of Context
237 int aDeltaIndex = 1; // properties item
238 int aCurrentIndex = 0;
239 for (AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); anIOIt.More(); anIOIt.Next(), aCurrentIndex++)
241 if (aCurrentIndex != aRowId - aDeltaIndex)
243 anIO = anIOIt.Value();
248 setInteractiveObject (anIO);
249 TreeModel_ItemBase::Init(); // to use getIO() without circling initialization
252 // =======================================================================
255 // =======================================================================
256 void VInspector_ItemPresentableObject::Reset()
258 VInspector_ItemBase::Reset();
261 setInteractiveObject (NULL);
264 // =======================================================================
265 // function : initItem
267 // =======================================================================
268 void VInspector_ItemPresentableObject::initItem() const
272 const_cast<VInspector_ItemPresentableObject*>(this)->Init();
275 // =======================================================================
276 // function : GetInteractiveObject
278 // =======================================================================
279 Handle(AIS_InteractiveObject) VInspector_ItemPresentableObject::GetInteractiveObject() const
285 // =======================================================================
286 // function : PointerInfo
288 // =======================================================================
289 QString VInspector_ItemPresentableObject::PointerInfo() const
291 return VInspector_Tools::GetPointerInfo (GetInteractiveObject(), true).ToCString();
294 // =======================================================================
295 // function : GetSelectedPresentations
297 // =======================================================================
298 NCollection_List<Handle(AIS_InteractiveObject)> VInspector_ItemPresentableObject::GetSelectedPresentations
299 (QItemSelectionModel* theSelectionModel)
301 NCollection_List<Handle(AIS_InteractiveObject)> aResultList;
302 if (!theSelectionModel)
305 QList<TreeModel_ItemBasePtr> anItems;
307 QModelIndexList anIndices = theSelectionModel->selectedIndexes();
308 for (QModelIndexList::const_iterator anIndicesIt = anIndices.begin(); anIndicesIt != anIndices.end(); anIndicesIt++)
310 TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt);
311 if (!anItem || anItems.contains (anItem))
313 anItems.append (anItem);
316 QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
317 for (QList<TreeModel_ItemBasePtr>::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); anItemIt++)
319 TreeModel_ItemBasePtr anItem = *anItemIt;
320 VInspector_ItemPresentableObjectPtr aPrsItem = itemDynamicCast<VInspector_ItemPresentableObject>(anItem);
323 Handle(AIS_InteractiveObject) aPresentation = aPrsItem->GetInteractiveObject();
324 if (aSelectedIds.contains ((size_t)aPresentation.operator->()))
326 aSelectedIds.append ((size_t)aPresentation.operator->());
327 if (!aPresentation.IsNull())
328 aResultList.Append (aPresentation);