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_ItemPresentableObject.hxx> |
14bbbdcb |
17 | |
7e1c1e48 |
18 | #include <AIS.hxx> |
14bbbdcb |
19 | #include <AIS_Shape.hxx> |
20 | #include <AIS_ListOfInteractive.hxx> |
21 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
7e1c1e48 |
22 | |
0cb512c0 |
23 | #include <inspector/VInspector_ItemContext.hxx> |
0cb512c0 |
24 | #include <inspector/VInspector_Tools.hxx> |
25 | #include <inspector/VInspector_ViewModel.hxx> |
14bbbdcb |
26 | |
7e1c1e48 |
27 | #include <inspector/ViewControl_Table.hxx> |
28 | #include <inspector/ViewControl_Tools.hxx> |
29 | |
14bbbdcb |
30 | #include <NCollection_List.hxx> |
31 | #include <Prs3d.hxx> |
32 | #include <Prs3d_Drawer.hxx> |
bbd92927 |
33 | #include <SelectMgr_EntityOwner.hxx> |
14bbbdcb |
34 | #include <StdSelect_BRepOwner.hxx> |
14bbbdcb |
35 | |
130eb114 |
36 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
37 | #include <QColor> |
38 | #include <QItemSelectionModel> |
130eb114 |
39 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
40 | |
41 | // ======================================================================= |
42 | // function : initValue |
43 | // purpose : |
44 | // ======================================================================= |
45 | QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const |
46 | { |
7e1c1e48 |
47 | QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); |
48 | if (aParentValue.isValid()) |
49 | return aParentValue; |
6822a3be |
50 | |
14bbbdcb |
51 | if (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole) |
52 | { |
53 | Handle(AIS_InteractiveObject) anIO = GetInteractiveObject(); |
54 | bool aNullIO = anIO.IsNull(); |
55 | switch (Column()) |
56 | { |
57 | case 0: |
58 | { |
59 | if (aNullIO) |
60 | return theItemRole == Qt::ToolTipRole ? QVariant ("Owners where Selectable is empty") |
61 | : QVariant ("Free Owners"); |
62 | else |
63 | return theItemRole == Qt::ToolTipRole ? QVariant ("") |
64 | : QVariant (anIO->DynamicType()->Name()); |
65 | } |
14bbbdcb |
66 | case 4: |
67 | { |
6822a3be |
68 | int aNbSelected = VInspector_Tools::SelectedOwners (GetContext(), anIO, false); |
69 | return aNbSelected > 0 ? QString::number (aNbSelected) : ""; |
70 | } |
6822a3be |
71 | case 6: |
72 | { |
73 | double aDeviationCoefficient = 0; |
74 | Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO); |
75 | if (!anAISShape.IsNull()) |
76 | { |
77 | Standard_Real aPreviousCoefficient; |
78 | anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient); |
79 | } |
80 | return QString::number(aDeviationCoefficient); |
81 | } |
14bbbdcb |
82 | case 8: |
83 | { |
6822a3be |
84 | double aDeviationCoefficient = 0; |
85 | Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO); |
86 | if (!anAISShape.IsNull()) |
14bbbdcb |
87 | { |
6822a3be |
88 | Standard_Real aPreviousCoefficient; |
89 | anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient); |
14bbbdcb |
90 | } |
6822a3be |
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"); |
94 | } |
14bbbdcb |
95 | default: break; |
96 | } |
97 | } |
98 | if (theItemRole == Qt::BackgroundRole || theItemRole == Qt::ForegroundRole) |
99 | { |
100 | Handle(AIS_InteractiveContext) aContext = GetContext(); |
101 | if (Column() == 2 && VInspector_Tools::SelectedOwners(aContext, GetInteractiveObject(), false) > 0) |
102 | { |
103 | return (theItemRole == Qt::BackgroundRole) ? QColor(Qt::darkBlue) : QColor(Qt::white); |
104 | } |
105 | else if (theItemRole == Qt::ForegroundRole) |
106 | { |
107 | Handle(AIS_InteractiveObject) anIO = GetInteractiveObject(); |
108 | if (anIO.IsNull()) |
109 | return QVariant(); |
110 | |
111 | AIS_ListOfInteractive aListOfIO; |
112 | GetContext()->ErasedObjects(aListOfIO); |
113 | for (AIS_ListIteratorOfListOfInteractive anIOIt(aListOfIO); anIOIt.More(); anIOIt.Next()) |
114 | { |
115 | if (anIO == anIOIt.Value()) |
116 | return QColor(Qt::darkGray); |
117 | } |
118 | return QColor(Qt::black); |
119 | } |
120 | } |
121 | return QVariant(); |
122 | } |
123 | |
124 | // ======================================================================= |
125 | // function : initRowCount |
126 | // purpose : |
127 | // ======================================================================= |
128 | int VInspector_ItemPresentableObject::initRowCount() const |
129 | { |
7e1c1e48 |
130 | return 0; |
14bbbdcb |
131 | } |
132 | |
133 | // ======================================================================= |
134 | // function : Init |
135 | // purpose : |
136 | // ======================================================================= |
137 | void VInspector_ItemPresentableObject::Init() |
138 | { |
139 | VInspector_ItemContextPtr aParentItem = itemDynamicCast<VInspector_ItemContext>(Parent()); |
140 | Handle(AIS_InteractiveContext) aContext = aParentItem->GetContext(); |
141 | SetContext (aContext); |
142 | |
143 | Handle(AIS_InteractiveObject) anIO; |
144 | if (!GetContext().IsNull()) |
145 | { |
146 | int aRowId = Row(); |
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 |
7e1c1e48 |
150 | |
151 | std::vector<Handle(AIS_InteractiveObject)> aListOfIOSorted; |
152 | aListOfIOSorted.reserve (aListOfIO.Size()); |
153 | for (AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); anIOIt.More(); anIOIt.Next()) |
154 | { |
155 | aListOfIOSorted.push_back (anIOIt.Value()); |
156 | } |
157 | std::sort (aListOfIOSorted.begin(), aListOfIOSorted.end()); |
158 | |
6b63dc83 |
159 | int aCurrentIndex = 1; /* Properties item of context*/ |
7e1c1e48 |
160 | for (std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIOIt = aListOfIOSorted.begin(); anIOIt != aListOfIOSorted.end(); anIOIt++, aCurrentIndex++) |
14bbbdcb |
161 | { |
7e1c1e48 |
162 | if (aCurrentIndex != aRowId) |
14bbbdcb |
163 | continue; |
7e1c1e48 |
164 | anIO = *anIOIt; |
14bbbdcb |
165 | break; |
166 | } |
167 | } |
168 | |
169 | setInteractiveObject (anIO); |
7e1c1e48 |
170 | myTransformPersistence = !anIO.IsNull() ? anIO->TransformPersistence() : NULL; |
171 | UpdatePresentationShape(); |
14bbbdcb |
172 | TreeModel_ItemBase::Init(); // to use getIO() without circling initialization |
173 | } |
174 | |
175 | // ======================================================================= |
176 | // function : Reset |
177 | // purpose : |
178 | // ======================================================================= |
179 | void VInspector_ItemPresentableObject::Reset() |
180 | { |
181 | VInspector_ItemBase::Reset(); |
182 | |
183 | SetContext (NULL); |
184 | setInteractiveObject (NULL); |
7e1c1e48 |
185 | myTransformPersistence = NULL; |
14bbbdcb |
186 | } |
187 | |
188 | // ======================================================================= |
189 | // function : initItem |
190 | // purpose : |
191 | // ======================================================================= |
192 | void VInspector_ItemPresentableObject::initItem() const |
193 | { |
194 | if (IsInitialized()) |
195 | return; |
196 | const_cast<VInspector_ItemPresentableObject*>(this)->Init(); |
197 | } |
198 | |
199 | // ======================================================================= |
7e1c1e48 |
200 | // function : buildPresentationShape |
14bbbdcb |
201 | // purpose : |
202 | // ======================================================================= |
7e1c1e48 |
203 | TopoDS_Shape VInspector_ItemPresentableObject::buildPresentationShape() |
14bbbdcb |
204 | { |
7e1c1e48 |
205 | Handle(AIS_InteractiveObject) aPrs = myIO; |
206 | if (aPrs.IsNull()) |
207 | return TopoDS_Shape(); |
208 | |
209 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs); |
210 | if (!aShapePrs.IsNull()) |
211 | return aShapePrs->Shape(); |
212 | |
213 | return TopoDS_Shape(); |
14bbbdcb |
214 | } |
215 | |
216 | // ======================================================================= |
217 | // function : PointerInfo |
218 | // purpose : |
219 | // ======================================================================= |
220 | QString VInspector_ItemPresentableObject::PointerInfo() const |
221 | { |
7e1c1e48 |
222 | return Standard_Dump::GetPointerInfo (GetInteractiveObject(), true).ToCString(); |
14bbbdcb |
223 | } |
224 | |
225 | // ======================================================================= |
7e1c1e48 |
226 | // function : Presentations |
14bbbdcb |
227 | // purpose : |
228 | // ======================================================================= |
7e1c1e48 |
229 | void VInspector_ItemPresentableObject::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations) |
14bbbdcb |
230 | { |
6b63dc83 |
231 | TreeModel_ItemBase::Presentations (thePresentations); |
232 | |
7e1c1e48 |
233 | if (Column() != 0) |
234 | return; |
7e1c1e48 |
235 | thePresentations.Append (GetInteractiveObject()); |
236 | } |
237 | |
238 | // ======================================================================= |
239 | // function : initStream |
240 | // purpose : |
241 | // ======================================================================= |
242 | void VInspector_ItemPresentableObject::initStream (Standard_OStream& theOStream) const |
243 | { |
244 | Handle(AIS_InteractiveObject) anIO = GetInteractiveObject(); |
245 | if (anIO.IsNull()) |
246 | return; |
247 | |
248 | anIO->DumpJson (theOStream); |
14bbbdcb |
249 | } |
7e1c1e48 |
250 | |