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/ShapeView_ItemShape.hxx> |
14bbbdcb |
17 | |
18 | #include <Adaptor3d_Curve.hxx> |
19 | #include <BRep_Tool.hxx> |
20 | #include <BRepAdaptor_Curve.hxx> |
21 | |
22 | #include <GCPnts_AbscissaPoint.hxx> |
23 | #include <Geom_Curve.hxx> |
24 | #include <GeomAdaptor_Curve.hxx> |
25 | |
0cb512c0 |
26 | #include <inspector/ShapeView_ItemRoot.hxx> |
27 | #include <inspector/ShapeView_ItemShape.hxx> |
14bbbdcb |
28 | #include <TCollection_AsciiString.hxx> |
29 | #include <TopoDS.hxx> |
30 | #include <TopoDS_Edge.hxx> |
31 | #include <TopoDS_Iterator.hxx> |
32 | #include <TopoDS_Vertex.hxx> |
33 | |
130eb114 |
34 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
35 | #include <QObject> |
36 | #include <QStringList> |
130eb114 |
37 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
38 | |
39 | // ======================================================================= |
40 | // function : ToString |
41 | // purpose : |
42 | // ======================================================================= |
43 | QString ToString (const Standard_Boolean& theValue) |
44 | { |
45 | return theValue ? "1" : "0"; |
46 | } |
47 | |
48 | // ======================================================================= |
49 | // function : ToString |
50 | // purpose : |
51 | // ======================================================================= |
52 | QString ToString (const gp_Pnt& thePoint) |
53 | { |
54 | return QString ("(%1, %2, %3)").arg (thePoint.X()).arg (thePoint.Y()).arg (thePoint.Z()); |
55 | } |
56 | |
57 | // ======================================================================= |
58 | // function : ToName |
59 | // purpose : |
60 | // ======================================================================= |
61 | QString ToName (const TopAbs_ShapeEnum& theShapeType) |
62 | { |
63 | Standard_SStream aSStream; |
64 | TopAbs::Print (theShapeType, aSStream); |
65 | return QString (aSStream.str().c_str()); |
66 | } |
67 | |
68 | // ======================================================================= |
69 | // function : ToName |
70 | // purpose : |
71 | // ======================================================================= |
72 | QString ToName (const TopAbs_Orientation& theOrientation) |
73 | { |
74 | Standard_SStream aSStream; |
75 | TopAbs::Print(theOrientation, aSStream); |
76 | return QString (aSStream.str().c_str()); |
77 | } |
78 | |
79 | // ======================================================================= |
80 | // function : ToName |
81 | // purpose : |
82 | // ======================================================================= |
83 | QString ToName (const GeomAbs_Shape& theType) |
84 | { |
85 | switch (theType) |
86 | { |
87 | case GeomAbs_C0: return "GeomAbs_C0"; |
88 | case GeomAbs_G1: return "GeomAbs_G1"; |
89 | case GeomAbs_C1: return "GeomAbs_C1"; |
90 | case GeomAbs_G2: return "GeomAbs_G2"; |
91 | case GeomAbs_C2: return "GeomAbs_C2"; |
92 | case GeomAbs_C3: return "GeomAbs_C3"; |
93 | case GeomAbs_CN: return "GeomAbs_CN"; |
94 | default: break; |
95 | } |
96 | return QString(); |
97 | } |
98 | |
99 | // ======================================================================= |
100 | // function : ToFlags |
101 | // purpose : |
102 | // ======================================================================= |
103 | void ToFlags (const TopoDS_Shape& theShape, QVariant& theValue, QVariant& theInfo) |
104 | { |
105 | QStringList aValues; |
106 | aValues << ToString (theShape.Checked()) << ToString (theShape.Closed()) |
107 | << ToString (theShape.Infinite()) << ToString (theShape.Locked()) |
108 | << ToString (theShape.Modified()) << ToString (theShape.Orientable()); |
109 | |
110 | theValue = aValues.join ("/"); |
111 | theInfo = "Checked/Closed/Infinite/Locked/Modified/Orientable"; |
112 | } |
113 | |
114 | // ======================================================================= |
115 | // function : ToOtherInfo |
116 | // purpose : |
117 | // ======================================================================= |
118 | void ToOtherInfo (const TopoDS_Shape& theShape, QVariant& theValue, QVariant& theInfo) |
119 | { |
120 | switch (theShape.ShapeType()) |
121 | { |
122 | case TopAbs_COMPOUND: |
123 | case TopAbs_COMPSOLID: |
124 | case TopAbs_SOLID: |
125 | case TopAbs_SHELL: |
126 | case TopAbs_FACE: |
127 | case TopAbs_WIRE: |
128 | break; |
129 | case TopAbs_EDGE: |
130 | { |
131 | TopoDS_Edge anEdge = TopoDS::Edge(theShape); |
132 | double aFirst, aLast; |
133 | Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast); |
134 | |
135 | GeomAdaptor_Curve aAdaptor(aCurve, aFirst, aLast); |
136 | gp_Pnt aFirstPnt = aAdaptor.Value(aFirst); |
137 | gp_Pnt aLastPnt = aAdaptor.Value(aLast); |
138 | |
139 | BRepAdaptor_Curve aBRepAdaptor = BRepAdaptor_Curve(anEdge); |
140 | Adaptor3d_Curve* anAdaptor3d = &aBRepAdaptor; |
141 | |
142 | QStringList aValues, anInfo; |
143 | aValues.append (QString::number (GCPnts_AbscissaPoint::Length(*anAdaptor3d))); |
144 | anInfo.append ("Length"); |
145 | |
146 | aValues.append (aCurve->DynamicType()->Name()); |
147 | anInfo.append ("DynamicType"); |
148 | |
149 | aValues.append (ToString (aFirstPnt)); |
150 | anInfo.append (QString ("First" + QString::number (aFirst))); |
151 | |
152 | aValues.append (ToString (aLastPnt)); |
153 | anInfo.append (QString ("Last" + QString::number (aLast))); |
154 | |
155 | aValues.append (ToName (aCurve->Continuity())); |
156 | anInfo.append ("Continuity"); |
157 | |
158 | aValues.append (ToString (aCurve->IsClosed())); |
159 | anInfo.append ("IsClosed"); |
160 | |
161 | if (aCurve->IsPeriodic()) { |
162 | aValues.append (QString::number (aCurve->Period())); |
163 | anInfo.append ("IsPeriodic"); |
164 | } |
165 | else |
166 | { |
167 | aValues.append (ToString (aCurve->IsPeriodic())); |
168 | anInfo.append ("IsPeriodic"); |
169 | } |
170 | theValue = aValues.join (" / "); |
171 | theInfo = QString ("%1:\n%2").arg (anInfo.join (" / ")).arg (aValues.join ("\n")); |
172 | break; |
173 | } |
174 | case TopAbs_VERTEX: |
175 | { |
176 | TopoDS_Vertex aVertex = TopoDS::Vertex (theShape); |
177 | gp_Pnt aPoint = BRep_Tool::Pnt (aVertex); |
178 | theValue = ToString (aPoint); |
179 | theInfo = "(X, Y, Z) of gp_Pnt"; |
180 | break; |
181 | } |
182 | case TopAbs_SHAPE: |
183 | default: |
184 | break; |
185 | } |
186 | } |
187 | |
188 | // ======================================================================= |
189 | // function : locationInfo |
190 | // purpose : |
191 | // ======================================================================= |
192 | QString locationInfo (const TopLoc_Location& theLocation) |
193 | { |
194 | QString anInfo; |
195 | |
196 | gp_Trsf aTrsf = theLocation.Transformation(); |
197 | QStringList aValues, aRowValues; |
198 | for (int aRowId = 1; aRowId <= 3; aRowId++) |
199 | { |
200 | aRowValues.clear(); |
201 | for (int aColumnId = 1; aColumnId <= 4; aColumnId++) |
202 | aRowValues.append (QString::number (aTrsf.Value(aRowId, aColumnId))); |
203 | aValues.append (aRowValues.join (",")); |
204 | } |
205 | anInfo.append (aValues.join (" ")); |
206 | return anInfo; |
207 | } |
208 | |
209 | // ======================================================================= |
210 | // function : GetShape |
211 | // purpose : |
212 | // ======================================================================= |
213 | TopoDS_Shape ShapeView_ItemShape::GetShape (const int theRowId) const |
214 | { |
215 | TopoDS_Iterator aSubShapeIt (myShape); |
216 | for (int aCurrentIndex = 0; aSubShapeIt.More(); aSubShapeIt.Next(), aCurrentIndex++) |
217 | { |
218 | if (aCurrentIndex != theRowId) |
219 | continue; |
220 | break; |
221 | } |
222 | return aSubShapeIt.Value(); |
223 | } |
224 | |
225 | // ======================================================================= |
226 | // function : initValue |
227 | // purpose : |
228 | // ======================================================================= |
229 | QVariant ShapeView_ItemShape::initValue(const int theRole) const |
230 | { |
231 | TopoDS_Shape aShape = getShape(); |
232 | if (aShape.IsNull()) |
233 | return QVariant(); |
234 | |
235 | if (theRole != Qt::DisplayRole && theRole != Qt::ToolTipRole) |
236 | return QVariant(); |
237 | |
238 | bool isDisplayRole = theRole == Qt::DisplayRole; |
239 | switch (Column()) |
240 | { |
241 | case 0: return isDisplayRole ? ToName (aShape.ShapeType()) : "ShapeType"; |
242 | case 1: return isDisplayRole ? (rowCount() > 0 ? QVariant (rowCount()) : QVariant()) |
243 | : QVariant ("Number of sub shapes"); |
244 | case 2: return isDisplayRole ? TShapePointer().ToCString() : "TShape pointer"; |
245 | case 3: return isDisplayRole ? ToName(aShape.Orientation()) : "Orientation"; |
246 | case 4: return isDisplayRole ? locationInfo(aShape.Location()) : "Location"; |
247 | case 5: |
248 | case 6: |
249 | case 7: |
250 | { |
251 | QVariant aDataInfo, aTooTipInfo; |
252 | if (Column() == 5) |
253 | ToFlags(aShape, aDataInfo, aTooTipInfo); |
254 | else if (Column() == 6) |
255 | ToOtherInfo(aShape, aDataInfo, aTooTipInfo); |
256 | return isDisplayRole ? aDataInfo : aTooTipInfo; |
257 | } |
258 | default: break; |
259 | } |
260 | return QVariant(); |
261 | } |
262 | |
263 | // ======================================================================= |
264 | // function : initRowCount |
265 | // purpose : |
266 | // ======================================================================= |
267 | int ShapeView_ItemShape::initRowCount() const |
268 | { |
269 | TopoDS_Shape aShape = getShape(); |
270 | if (aShape.IsNull()) |
271 | return 0; |
272 | |
273 | int aRowsCount = 0; |
274 | for (TopoDS_Iterator aSubShapeIt(aShape); aSubShapeIt.More(); aSubShapeIt.Next()) |
275 | aRowsCount++; |
276 | return aRowsCount; |
277 | } |
278 | |
279 | // ======================================================================= |
280 | // function : createChild |
281 | // purpose : |
282 | // ======================================================================= |
283 | TreeModel_ItemBasePtr ShapeView_ItemShape::createChild (int theRow, int theColumn) |
284 | { |
285 | return ShapeView_ItemShape::CreateItem (currentItem(), theRow, theColumn); |
286 | } |
287 | |
288 | // ======================================================================= |
289 | // function : Init |
290 | // purpose : |
291 | // ======================================================================= |
292 | void ShapeView_ItemShape::Init() |
293 | { |
294 | ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot> (Parent()); |
295 | ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape> (Parent()); |
296 | myShape = aRootItem ? aRootItem->GetShape (Row()) : aShapeItem->GetShape (Row()); |
297 | } |
298 | |
299 | // ======================================================================= |
300 | // function : getShape |
301 | // purpose : |
302 | // ======================================================================= |
303 | TopoDS_Shape ShapeView_ItemShape::getShape() const |
304 | { |
305 | initItem(); |
306 | return myShape; |
307 | } |
308 | |
309 | // ======================================================================= |
310 | // function : getPointerInfo |
311 | // purpose : |
312 | // ======================================================================= |
313 | TCollection_AsciiString ShapeView_ItemShape::getPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) |
314 | { |
315 | std::ostringstream aPtrStr; |
316 | aPtrStr << thePointer.operator->(); |
317 | if (!isShortInfo) |
318 | return aPtrStr.str().c_str(); |
319 | |
320 | TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str()); |
321 | for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++) |
322 | { |
323 | if (anInfoPtr.Value(aSymbolId) != '0') |
324 | { |
325 | anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); |
326 | anInfoPtr.Prepend("0x"); |
327 | return anInfoPtr; |
328 | } |
329 | } |
330 | return aPtrStr.str().c_str(); |
331 | } |
332 | |
333 | // ======================================================================= |
334 | // function : Reset |
335 | // purpose : |
336 | // ======================================================================= |
337 | void ShapeView_ItemShape::Reset() |
338 | { |
339 | myFileName = QString(); |
340 | |
341 | ShapeView_ItemBase::Reset(); |
342 | } |
343 | |
344 | // ======================================================================= |
345 | // function : initItem |
346 | // purpose : |
347 | // ======================================================================= |
348 | void ShapeView_ItemShape::initItem() const |
349 | { |
350 | if (IsInitialized()) |
351 | return; |
352 | const_cast<ShapeView_ItemShape*>(this)->Init(); |
353 | } |
354 | |