use names directly from document to set them in scene inspector
This commit is contained in:
parent
fc4a1c6081
commit
321ca984c9
|
@ -2519,13 +2519,12 @@ StdCmdSceneInspector::StdCmdSceneInspector()
|
|||
void StdCmdSceneInspector::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
View3DInventor* child = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
|
||||
if (child) {
|
||||
View3DInventorViewer* viewer = child->getViewer();
|
||||
Gui::Document* doc = Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
static QPointer<Gui::Dialog::DlgInspector> dlg = 0;
|
||||
if (!dlg)
|
||||
dlg = new Gui::Dialog::DlgInspector(getMainWindow());
|
||||
dlg->setNode(viewer->getSceneGraph());
|
||||
dlg->setDocument(doc);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->show();
|
||||
}
|
||||
|
|
|
@ -29,9 +29,12 @@
|
|||
|
||||
#include "SceneInspector.h"
|
||||
#include "ui_SceneInspector.h"
|
||||
#include "MainWindow.h"
|
||||
#include "View3DInventor.h"
|
||||
#include "View3DInventorViewer.h"
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
#include "Document.h"
|
||||
#include "Application.h"
|
||||
#include <App/Document.h>
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
|
||||
|
@ -97,15 +100,21 @@ void SceneModel::setNode(QModelIndex index, SoNode* node)
|
|||
for (int i=0; i<group->getNumChildren();i++) {
|
||||
SoNode* child = group->getChild(i);
|
||||
setNode(this->index(i, 0, index), child);
|
||||
// See ViewProviderDocumentObject::updateData
|
||||
QByteArray name(child->getName());
|
||||
name = QByteArray::fromPercentEncoding(name);
|
||||
this->setData(this->index(i, 1, index), QVariant(QString::fromUtf8(name)));
|
||||
|
||||
QMap<SoNode*, QString>::iterator it = nodeNames.find(child);
|
||||
if (it != nodeNames.end()) {
|
||||
this->setData(this->index(i, 1, index), QVariant(it.value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// insert icon
|
||||
}
|
||||
|
||||
void SceneModel::setNodeNames(const QMap<SoNode*, QString>& names)
|
||||
{
|
||||
nodeNames = names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
/* TRANSLATOR Gui::Dialog::DlgInspector */
|
||||
|
@ -130,6 +139,18 @@ DlgInspector::~DlgInspector()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void DlgInspector::setDocument(Gui::Document* doc)
|
||||
{
|
||||
setNodeNames(doc);
|
||||
|
||||
View3DInventor* view = qobject_cast<View3DInventor*>(doc->getActiveView());
|
||||
if (view) {
|
||||
View3DInventorViewer* viewer = view->getViewer();
|
||||
setNode(viewer->getSceneGraph());
|
||||
ui->treeView->expandToDepth(3);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgInspector::setNode(SoNode* node)
|
||||
{
|
||||
SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
|
||||
|
@ -145,6 +166,32 @@ void DlgInspector::setNode(SoNode* node)
|
|||
#endif
|
||||
}
|
||||
|
||||
void DlgInspector::setNodeNames(Gui::Document* doc)
|
||||
{
|
||||
std::vector<Gui::ViewProvider*> vps = doc->getViewProvidersOfType
|
||||
(Gui::ViewProviderDocumentObject::getClassTypeId());
|
||||
QMap<SoNode*, QString> nodeNames;
|
||||
for (std::vector<Gui::ViewProvider*>::iterator it = vps.begin(); it != vps.end(); ++it) {
|
||||
Gui::ViewProviderDocumentObject* vp = static_cast<Gui::ViewProviderDocumentObject*>(*it);
|
||||
App::DocumentObject* obj = vp->getObject();
|
||||
if (obj) {
|
||||
QString label = QString::fromUtf8(obj->Label.getValue());
|
||||
nodeNames[vp->getRoot()] = label;
|
||||
}
|
||||
|
||||
std::vector<std::string> modes = vp->getDisplayMaskModes();
|
||||
for (std::vector<std::string>::iterator jt = modes.begin(); jt != modes.end(); ++jt) {
|
||||
SoNode* node = vp->getDisplayMaskMode(jt->c_str());
|
||||
if (node) {
|
||||
nodeNames[node] = QString::fromStdString(*jt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
|
||||
model->setNodeNames(nodeNames);
|
||||
}
|
||||
|
||||
void DlgInspector::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
|
@ -156,11 +203,16 @@ void DlgInspector::changeEvent(QEvent *e)
|
|||
|
||||
void DlgInspector::on_refreshButton_clicked()
|
||||
{
|
||||
View3DInventor* child = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
|
||||
if (child) {
|
||||
View3DInventorViewer* viewer = child->getViewer();
|
||||
setNode(viewer->getSceneGraph());
|
||||
ui->treeView->expandToDepth(3);
|
||||
Gui::Document* doc = Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
setNodeNames(doc);
|
||||
|
||||
View3DInventor* view = qobject_cast<View3DInventor*>(doc->getActiveView());
|
||||
if (view) {
|
||||
View3DInventorViewer* viewer = view->getViewer();
|
||||
setNode(viewer->getSceneGraph());
|
||||
ui->treeView->expandToDepth(3);
|
||||
}
|
||||
}
|
||||
else {
|
||||
SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
|
||||
|
|
|
@ -25,10 +25,12 @@
|
|||
|
||||
#include <QStandardItemModel>
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
|
||||
class SoNode;
|
||||
|
||||
namespace Gui {
|
||||
class Document;
|
||||
namespace Dialog {
|
||||
|
||||
class Ui_SceneInspector;
|
||||
|
@ -53,11 +55,14 @@ public:
|
|||
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole);
|
||||
/// insert the first node in tree
|
||||
void setNode(SoNode* node);
|
||||
/// set names per node
|
||||
void setNodeNames(const QMap<SoNode*, QString>& names);
|
||||
/// returns standard parent's flags
|
||||
Qt::ItemFlags flags (const QModelIndex & index) const;
|
||||
|
||||
private:
|
||||
void setNode(QModelIndex, SoNode*);
|
||||
QMap<SoNode*, QString> nodeNames;
|
||||
};
|
||||
|
||||
/// Dialog window to display scenegraph model as a tree
|
||||
|
@ -69,13 +74,15 @@ public:
|
|||
DlgInspector(QWidget* parent = 0, Qt::WindowFlags fl = 0);
|
||||
~DlgInspector();
|
||||
|
||||
void setNode(SoNode* node);
|
||||
void setDocument(Gui::Document* doc);
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_refreshButton_clicked();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
void setNode(SoNode* node);
|
||||
void setNodeNames(Gui::Document*);
|
||||
|
||||
private:
|
||||
Ui_SceneInspector* ui;
|
||||
|
|
|
@ -275,21 +275,6 @@ SbMatrix ViewProvider::convert(const Base::Matrix4D &rcMatrix) const
|
|||
|
||||
void ViewProvider::addDisplayMaskMode(SoNode *node, const char* type)
|
||||
{
|
||||
if (type) {
|
||||
std::string name = type;
|
||||
for (std::string::iterator it = name.begin(); it != name.end(); ++it) {
|
||||
if (it == name.begin()) {
|
||||
if (!SbName::isBaseNameStartChar(*it))
|
||||
*it = '_';
|
||||
}
|
||||
else {
|
||||
if (!SbName::isBaseNameChar(*it))
|
||||
*it = '_';
|
||||
}
|
||||
}
|
||||
node->setName(name.c_str());
|
||||
}
|
||||
|
||||
_sDisplayMaskModes[type] = pcModeSwitch->getNumChildren();
|
||||
pcModeSwitch->addChild(node);
|
||||
}
|
||||
|
|
|
@ -190,14 +190,6 @@ void ViewProviderDocumentObject::attach(App::DocumentObject *pcObj)
|
|||
|
||||
void ViewProviderDocumentObject::updateData(const App::Property* prop)
|
||||
{
|
||||
if (pcObject && prop == &pcObject->Label) {
|
||||
// SoBase::setName() replaces characters that according to the
|
||||
// VRML standard are invalid. To avoid the replacement we use
|
||||
// the percent encoding.
|
||||
QByteArray ba(pcObject->Label.getValue());
|
||||
QByteArray name = ba.toPercentEncoding();
|
||||
pcRoot->setName(name.constData());
|
||||
}
|
||||
ViewProvider::updateData(prop);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user