a5162275 |
1 | // Created on: 2020-02-10 |
2 | // Created by: Natalia ERMOLAEVA |
3 | // Copyright (c) 2020 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 | |
16 | #include <inspector/VInspector_ItemV3dViewer.hxx> |
17 | |
18 | #include <AIS.hxx> |
19 | #include <AIS_InteractiveContext.hxx> |
20 | #include <inspector/VInspector_ItemContext.hxx> |
21 | #include <inspector/VInspector_ItemContextProperties.hxx> |
22 | |
23 | // ======================================================================= |
24 | // function : initRowCount |
25 | // purpose : |
26 | // ======================================================================= |
27 | int VInspector_ItemV3dViewer::initRowCount() const |
28 | { |
29 | return 0; |
30 | } |
31 | |
32 | // ======================================================================= |
33 | // function : initValue |
34 | // purpose : |
35 | // ======================================================================= |
36 | QVariant VInspector_ItemV3dViewer::initValue (const int theItemRole) const |
37 | { |
38 | QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); |
39 | if (aParentValue.isValid()) |
40 | return aParentValue; |
41 | |
42 | if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) |
43 | return QVariant(); |
44 | |
45 | if (GetViewer().IsNull()) |
46 | return Column() == 0 ? "Empty viewer" : ""; |
47 | |
48 | return Column() == 0 ? GetViewer()->DynamicType()->Name() : QVariant(); |
49 | } |
50 | |
51 | // ======================================================================= |
52 | // function : Init |
53 | // purpose : |
54 | // ======================================================================= |
55 | void VInspector_ItemV3dViewer::Init() |
56 | { |
57 | VInspector_ItemContextPropertiesPtr aParentItem = itemDynamicCast<VInspector_ItemContextProperties>(Parent()); |
58 | Handle(V3d_Viewer) aViewer; |
59 | if (aParentItem) |
60 | { |
61 | VInspector_ItemContextPtr aParentContextItem = itemDynamicCast<VInspector_ItemContext>(aParentItem->Parent()); |
62 | if (aParentContextItem) |
63 | { |
64 | Handle(AIS_InteractiveContext) aContext = aParentContextItem->GetContext(); |
65 | aViewer = aContext->CurrentViewer(); |
66 | } |
67 | } |
68 | myViewer = aViewer; |
69 | TreeModel_ItemBase::Init(); |
70 | } |
71 | |
72 | // ======================================================================= |
73 | // function : Reset |
74 | // purpose : |
75 | // ======================================================================= |
76 | void VInspector_ItemV3dViewer::Reset() |
77 | { |
78 | VInspector_ItemBase::Reset(); |
79 | |
80 | myViewer = NULL; |
81 | } |
82 | |
83 | // ======================================================================= |
84 | // function : initItem |
85 | // purpose : |
86 | // ======================================================================= |
87 | void VInspector_ItemV3dViewer::initItem() const |
88 | { |
89 | if (IsInitialized()) |
90 | return; |
91 | const_cast<VInspector_ItemV3dViewer*>(this)->Init(); |
92 | } |
93 | |
94 | // ======================================================================= |
95 | // function : initStream |
96 | // purpose : |
97 | // ======================================================================= |
98 | void VInspector_ItemV3dViewer::initStream (Standard_OStream& theOStream) const |
99 | { |
100 | Handle(V3d_Viewer) aViewer = GetViewer(); |
101 | if (aViewer.IsNull()) |
102 | return; |
103 | |
104 | aViewer->DumpJson (theOStream); |
105 | } |