SceneInspector.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <Inventor/nodes/SoGroup.h>
00027 # include <QHeaderView>
00028 #endif
00029 
00030 #include "SceneInspector.h"
00031 #include "ui_SceneInspector.h"
00032 #include "MainWindow.h"
00033 #include "View3DInventor.h"
00034 #include "View3DInventorViewer.h"
00035 
00036 using namespace Gui::Dialog;
00037 
00038 /* TRANSLATOR Gui::Dialog::SceneModel */
00039 
00040 SceneModel::SceneModel(QObject* parent)
00041     : QStandardItemModel(parent)
00042 {
00043 }
00044 
00045 SceneModel::~SceneModel()
00046 {
00047 }
00048 
00049 int SceneModel::columnCount (const QModelIndex & parent) const
00050 {
00051     return 1;
00052 }
00053 
00054 Qt::ItemFlags SceneModel::flags (const QModelIndex & index) const
00055 {
00056     return QAbstractItemModel::flags(index);
00057 }
00058 
00059 QVariant SceneModel::headerData (int section, Qt::Orientation orientation, int role) const
00060 {
00061     if (orientation == Qt::Horizontal) {
00062         if (role != Qt::DisplayRole)
00063             return QVariant();
00064         if (section == 0)
00065             return tr("Inventor Tree");
00066     }
00067 
00068     return QVariant();
00069 }
00070 
00071 bool SceneModel::setHeaderData (int, Qt::Orientation, const QVariant &, int)
00072 {
00073     return false;
00074 }
00075 
00076 void SceneModel::setNode(SoNode* node)
00077 {
00078     this->clear();
00079     this->setHeaderData(0, Qt::Horizontal, tr("Nodes"), Qt::DisplayRole);
00080 
00081     this->insertColumns(0,1);
00082     this->insertRows(0,1);
00083     setNode(this->index(0, 0),node);
00084 }
00085 
00086 void SceneModel::setNode(QModelIndex index, SoNode* node)
00087 {
00088     this->setData(index, QVariant(QString::fromAscii(node->getTypeId().getName())));
00089     if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
00090         SoGroup *group = static_cast<SoGroup*>(node);
00091         // insert SoGroup icon
00092         this->insertColumns(0,1,index);
00093         this->insertRows(0,group->getNumChildren(), index);
00094         for (int i=0; i<group->getNumChildren();i++) {
00095             SoNode* child = group->getChild(i);
00096             setNode(this->index(i, 0, index), child);
00097         }
00098     }
00099     // insert icon
00100 }
00101 
00102 // --------------------------------------------------------
00103 
00104 /* TRANSLATOR Gui::Dialog::DlgInspector */
00105 
00106 DlgInspector::DlgInspector(QWidget* parent, Qt::WFlags fl)
00107   : QDialog(parent, fl), ui(new Ui_SceneInspector())
00108 {
00109     ui->setupUi(this);
00110     setWindowTitle(tr("Scene Inspector"));
00111 
00112     SceneModel* model = new SceneModel(this);
00113     ui->treeView->setModel(model);
00114     ui->treeView->setRootIsDecorated(true);
00115 }
00116 
00117 /*  
00118  *  Destroys the object and frees any allocated resources
00119  */
00120 DlgInspector::~DlgInspector()
00121 {
00122     // no need to delete child widgets, Qt does it all for us
00123     delete ui;
00124 }
00125 
00126 void DlgInspector::setNode(SoNode* node)
00127 {
00128     SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
00129     model->setNode(node);
00130     
00131     QHeaderView* header = ui->treeView->header();
00132     header->setResizeMode(0, QHeaderView::Stretch);
00133     header->setMovable(false);
00134 }
00135 
00136 void DlgInspector::changeEvent(QEvent *e)
00137 {
00138     if (e->type() == QEvent::LanguageChange) {
00139         ui->retranslateUi(this);
00140         setWindowTitle(tr("Scene Inspector"));
00141     }
00142     QDialog::changeEvent(e);
00143 }
00144 
00145 void DlgInspector::on_refreshButton_clicked()
00146 {
00147     View3DInventor* child = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
00148     if (child) {
00149         View3DInventorViewer* viewer = child->getViewer();
00150         setNode(viewer->getSceneGraph());
00151         ui->treeView->expandToDepth(3);
00152     }
00153     else {
00154         SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
00155         model->clear();
00156     }
00157 }
00158 
00159 #include "moc_SceneInspector.cpp"

Generated on Wed Nov 23 19:00:36 2011 for FreeCAD by  doxygen 1.6.1