1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <Inventor/nodes/SoSeparator.h>
26
# include <QHeaderView>
27
# include <QTextStream>
30
#include "SceneInspector.h"
31
#include "ui_SceneInspector.h"
32
#include "Application.h"
34
#include "View3DInventor.h"
35
#include "View3DInventorViewer.h"
36
#include "ViewProviderDocumentObject.h"
39
using namespace Gui::Dialog;
41
/* TRANSLATOR Gui::Dialog::SceneModel */
43
SceneModel::SceneModel(QObject* parent)
44
: QStandardItemModel(parent)
48
SceneModel::~SceneModel() = default;
50
int SceneModel::columnCount (const QModelIndex & parent) const
56
Qt::ItemFlags SceneModel::flags (const QModelIndex & index) const
58
return QAbstractItemModel::flags(index);
61
QVariant SceneModel::headerData (int section, Qt::Orientation orientation, int role) const
63
if (orientation == Qt::Horizontal) {
64
if (role != Qt::DisplayRole)
67
return tr("Inventor Tree");
68
else if (section == 1)
75
bool SceneModel::setHeaderData (int, Qt::Orientation, const QVariant &, int)
80
void SceneModel::setNode(SoNode* node)
83
this->setHeaderData(0, Qt::Horizontal, tr("Nodes"), Qt::DisplayRole);
85
this->insertColumns(0,2);
86
this->insertRows(0,1);
87
setNode(this->index(0, 0), node);
90
void SceneModel::setNode(QModelIndex index, SoNode* node)
92
this->setData(index, QVariant(QString::fromLatin1(QByteArray(node->getTypeId().getName()))));
93
if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
94
auto group = static_cast<SoGroup*>(node);
95
// insert SoGroup icon
96
this->insertColumns(0,2,index);
97
this->insertRows(0,group->getNumChildren(), index);
98
for (int i=0; i<group->getNumChildren();i++) {
99
SoNode* child = group->getChild(i);
100
setNode(this->index(i, 0, index), child);
102
QHash<SoNode*, QString>::iterator it = nodeNames.find(child);
104
QTextStream stream(&name);
105
stream << child << ", ";
106
if(child->isOfType(SoSwitch::getClassTypeId())) {
107
auto pcSwitch = static_cast<SoSwitch*>(child);
108
stream << pcSwitch->whichChild.getValue() << ", ";
109
} else if (child->isOfType(SoSeparator::getClassTypeId())) {
110
auto pcSeparator = static_cast<SoSeparator*>(child);
111
stream << pcSeparator->renderCaching.getValue() << ", ";
113
if (it != nodeNames.end())
114
stream << it.value();
116
stream << child->getName();
117
this->setData(this->index(i, 1, index), QVariant(name));
123
void SceneModel::setNodeNames(const QHash<SoNode*, QString>& names)
128
// --------------------------------------------------------
130
/* TRANSLATOR Gui::Dialog::DlgInspector */
132
DlgInspector::DlgInspector(QWidget* parent, Qt::WindowFlags fl)
133
: QDialog(parent, fl), ui(new Ui_SceneInspector())
136
connect(ui->refreshButton, &QPushButton::clicked,
137
this, &DlgInspector::onRefreshButtonClicked);
138
setWindowTitle(tr("Scene Inspector"));
140
auto model = new SceneModel(this);
141
ui->treeView->setModel(model);
142
ui->treeView->setRootIsDecorated(true);
146
* Destroys the object and frees any allocated resources
148
DlgInspector::~DlgInspector()
150
// no need to delete child widgets, Qt does it all for us
154
void DlgInspector::setDocument(Gui::Document* doc)
158
auto view = qobject_cast<View3DInventor*>(doc->getActiveView());
160
View3DInventorViewer* viewer = view->getViewer();
161
setNode(viewer->getSceneGraph());
162
ui->treeView->expandToDepth(3);
166
void DlgInspector::setNode(SoNode* node)
168
auto model = static_cast<SceneModel*>(ui->treeView->model());
169
model->setNode(node);
171
QHeaderView* header = ui->treeView->header();
172
header->setSectionResizeMode(0, QHeaderView::Stretch);
173
header->setSectionsMovable(false);
176
void DlgInspector::setNodeNames(Gui::Document* doc)
178
std::vector<Gui::ViewProvider*> vps = doc->getViewProvidersOfType
179
(Gui::ViewProviderDocumentObject::getClassTypeId());
180
QHash<SoNode*, QString> nodeNames;
181
for (const auto & it : vps) {
182
auto vp = static_cast<Gui::ViewProviderDocumentObject*>(it);
183
App::DocumentObject* obj = vp->getObject();
185
QString label = QString::fromUtf8(obj->Label.getValue());
186
nodeNames[vp->getRoot()] = label;
189
std::vector<std::string> modes = vp->getDisplayMaskModes();
190
for (const auto & mode : modes) {
191
SoNode* node = vp->getDisplayMaskMode(mode.c_str());
193
nodeNames[node] = QString::fromStdString(mode);
198
auto model = static_cast<SceneModel*>(ui->treeView->model());
199
model->setNodeNames(nodeNames);
202
void DlgInspector::changeEvent(QEvent *e)
204
if (e->type() == QEvent::LanguageChange) {
205
ui->retranslateUi(this);
206
setWindowTitle(tr("Scene Inspector"));
208
QDialog::changeEvent(e);
211
void DlgInspector::onRefreshButtonClicked()
213
Gui::Document* doc = Application::Instance->activeDocument();
217
auto view = qobject_cast<View3DInventor*>(doc->getActiveView());
219
View3DInventorViewer* viewer = view->getViewer();
220
setNode(viewer->getSceneGraph());
221
ui->treeView->expandToDepth(3);
225
auto model = static_cast<SceneModel*>(ui->treeView->model());
230
#include "moc_SceneInspector.cpp"