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>
19 #include <AIS_Shape.hxx>
20 #include <AIS_ListOfInteractive.hxx>
21 #include <AIS_ListIteratorOfListOfInteractive.hxx>
23 #include <inspector/VInspector_ItemContext.hxx>
24 #include <inspector/VInspector_Tools.hxx>
25 #include <inspector/VInspector_ViewModel.hxx>
27 #include <inspector/ViewControl_Table.hxx>
28 #include <inspector/ViewControl_Tools.hxx>
30 #include <NCollection_List.hxx>
32 #include <Prs3d_Drawer.hxx>
33 #include <SelectBasics_EntityOwner.hxx>
34 #include <StdSelect_BRepOwner.hxx>
36 #include <Standard_WarningsDisable.hxx>
38 #include <QItemSelectionModel>
39 #include <Standard_WarningsRestore.hxx>
41 // =======================================================================
42 // function : initValue
44 // =======================================================================
45 QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const
47 QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole);
48 if (aParentValue.isValid())
51 if (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole)
53 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
54 bool aNullIO = anIO.IsNull();
60 return theItemRole == Qt::ToolTipRole ? QVariant ("Owners where Selectable is empty")
61 : QVariant ("Free Owners");
63 return theItemRole == Qt::ToolTipRole ? QVariant ("")
64 : QVariant (anIO->DynamicType()->Name());
68 int aNbSelected = VInspector_Tools::SelectedOwners (GetContext(), anIO, false);
69 return aNbSelected > 0 ? QString::number (aNbSelected) : "";
73 double aDeviationCoefficient = 0;
74 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
75 if (!anAISShape.IsNull())
77 Standard_Real aPreviousCoefficient;
78 anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
80 return QString::number(aDeviationCoefficient);
84 double aDeviationCoefficient = 0;
85 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
86 if (!anAISShape.IsNull())
88 Standard_Real aPreviousCoefficient;
89 anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
91 Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
92 bool anIsAutoTriangulation = aNullIO ? false : anIO->Attributes()->IsAutoTriangulation();
93 return anIsAutoTriangulation ? QString ("true") : QString ("false");
98 if (theItemRole == Qt::BackgroundRole || theItemRole == Qt::ForegroundRole)
100 Handle(AIS_InteractiveContext) aContext = GetContext();
101 if (Column() == 2 && VInspector_Tools::SelectedOwners(aContext, GetInteractiveObject(), false) > 0)
103 return (theItemRole == Qt::BackgroundRole) ? QColor(Qt::darkBlue) : QColor(Qt::white);
105 else if (theItemRole == Qt::ForegroundRole)
107 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
111 AIS_ListOfInteractive aListOfIO;
112 GetContext()->ErasedObjects(aListOfIO);
113 for (AIS_ListIteratorOfListOfInteractive anIOIt(aListOfIO); anIOIt.More(); anIOIt.Next())
115 if (anIO == anIOIt.Value())
116 return QColor(Qt::darkGray);
118 return QColor(Qt::black);
124 // =======================================================================
125 // function : initRowCount
127 // =======================================================================
128 int VInspector_ItemPresentableObject::initRowCount() const
133 // =======================================================================
136 // =======================================================================
137 void VInspector_ItemPresentableObject::Init()
139 VInspector_ItemContextPtr aParentItem = itemDynamicCast<VInspector_ItemContext>(Parent());
140 Handle(AIS_InteractiveContext) aContext = aParentItem->GetContext();
141 SetContext (aContext);
143 Handle(AIS_InteractiveObject) anIO;
144 if (!GetContext().IsNull())
147 AIS_ListOfInteractive aListOfIO;
148 GetContext()->DisplayedObjects (aListOfIO); // the presentation is in displayed objects of Context
149 GetContext()->ErasedObjects (aListOfIO); // the presentation is in erased objects of Context
151 std::vector<Handle(AIS_InteractiveObject)> aListOfIOSorted;
152 aListOfIOSorted.reserve (aListOfIO.Size());
153 for (AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); anIOIt.More(); anIOIt.Next())
155 aListOfIOSorted.push_back (anIOIt.Value());
157 std::sort (aListOfIOSorted.begin(), aListOfIOSorted.end());
159 int aCurrentIndex = 1; /* Properties item of context*/
160 for (std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIOIt = aListOfIOSorted.begin(); anIOIt != aListOfIOSorted.end(); anIOIt++, aCurrentIndex++)
162 if (aCurrentIndex != aRowId)
169 setInteractiveObject (anIO);
170 myTransformPersistence = !anIO.IsNull() ? anIO->TransformPersistence() : NULL;
171 UpdatePresentationShape();
172 TreeModel_ItemBase::Init(); // to use getIO() without circling initialization
175 // =======================================================================
178 // =======================================================================
179 void VInspector_ItemPresentableObject::Reset()
181 VInspector_ItemBase::Reset();
184 setInteractiveObject (NULL);
185 myTransformPersistence = NULL;
188 // =======================================================================
189 // function : initItem
191 // =======================================================================
192 void VInspector_ItemPresentableObject::initItem() const
196 const_cast<VInspector_ItemPresentableObject*>(this)->Init();
199 // =======================================================================
200 // function : buildPresentationShape
202 // =======================================================================
203 TopoDS_Shape VInspector_ItemPresentableObject::buildPresentationShape()
205 Handle(AIS_InteractiveObject) aPrs = myIO;
207 return TopoDS_Shape();
209 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
210 if (!aShapePrs.IsNull())
211 return aShapePrs->Shape();
213 return TopoDS_Shape();
216 // =======================================================================
217 // function : PointerInfo
219 // =======================================================================
220 QString VInspector_ItemPresentableObject::PointerInfo() const
222 return Standard_Dump::GetPointerInfo (GetInteractiveObject(), true).ToCString();
225 // =======================================================================
226 // function : Presentations
228 // =======================================================================
229 void VInspector_ItemPresentableObject::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
231 TreeModel_ItemBase::Presentations (thePresentations);
235 thePresentations.Append (GetInteractiveObject());
238 // =======================================================================
239 // function : initStream
241 // =======================================================================
242 void VInspector_ItemPresentableObject::initStream (Standard_OStream& theOStream) const
244 Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
248 anIO->DumpJson (theOStream);