23
#include "PreCompiled.h"
26
# include <Inventor/SoDB.h>
27
# include <Inventor/SoInput.h>
28
# include <Inventor/nodes/SoSeparator.h>
29
# include <Inventor/nodes/SoTransform.h>
33
#include <App/Document.h>
34
#include <App/InventorObject.h>
36
#include "ViewProviderInventorObject.h"
37
#include "SoFCSelection.h"
42
PROPERTY_SOURCE(Gui::ViewProviderInventorObject, Gui::ViewProviderDocumentObject)
44
ViewProviderInventorObject::ViewProviderInventorObject()
46
pcBuffer = new SoSeparator();
48
pcFile = new SoSeparator();
52
ViewProviderInventorObject::~ViewProviderInventorObject()
58
void ViewProviderInventorObject::attach(App::DocumentObject *pcObj)
60
ViewProviderDocumentObject::attach(pcObj);
61
auto pcFileBuf = new SoGroup();
62
pcFileBuf->addChild(pcBuffer);
63
pcFileBuf->addChild(pcFile);
64
addDisplayMaskMode(pcFileBuf, "FileBuffer");
65
addDisplayMaskMode(pcBuffer, "Buffer");
66
addDisplayMaskMode(pcFile, "File");
69
void ViewProviderInventorObject::setDisplayMode(const char* ModeName)
71
if (strcmp("File+Buffer",ModeName)==0)
72
setDisplayMaskMode("FileBuffer");
73
else if (strcmp("Buffer",ModeName)==0)
74
setDisplayMaskMode("Buffer");
75
else if (strcmp("File",ModeName)==0)
76
setDisplayMaskMode("File");
77
ViewProviderDocumentObject::setDisplayMode(ModeName);
80
std::vector<std::string> ViewProviderInventorObject::getDisplayModes() const
82
std::vector<std::string> StrList;
83
StrList.emplace_back("File+Buffer");
84
StrList.emplace_back("Buffer");
85
StrList.emplace_back("File");
89
void ViewProviderInventorObject::updateData(const App::Property* prop)
91
auto ivObj = static_cast<App::InventorObject*>(pcObject);
92
if (prop == &ivObj->Buffer) {
95
std::string buffer = ivObj->Buffer.getValue();
96
coinRemoveAllChildren(pcBuffer);
99
in.setBuffer((void *)buffer.c_str(), buffer.size());
100
SoSeparator * node = SoDB::readAll(&in);
102
const char* doc = this->pcObject->getDocument()->getName();
103
const char* obj = this->pcObject->getNameInDocument();
104
adjustSelectionNodes(node, doc, obj);
105
pcBuffer->addChild(node);
108
else if (prop == &ivObj->FileName) {
110
const char* filename = ivObj->FileName.getValue();
111
QString fn = QString::fromUtf8(filename);
114
coinRemoveAllChildren(pcFile);
115
if (!fn.isEmpty() && file.open(QFile::ReadOnly)) {
116
QByteArray buffer = file.readAll();
117
in.setBuffer((void *)buffer.constData(), buffer.length());
118
SoSeparator * node = SoDB::readAll(&in);
120
const char* doc = this->pcObject->getDocument()->getName();
121
const char* obj = this->pcObject->getNameInDocument();
122
adjustSelectionNodes(node, doc, obj);
123
pcFile->addChild(node);
127
else if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId()) &&
128
strcmp(prop->getName(), "Placement") == 0) {
137
Base::Placement p = static_cast<const App::PropertyPlacement*>(prop)->getValue();
138
auto q0 = (float)p.getRotation().getValue()[0];
139
auto q1 = (float)p.getRotation().getValue()[1];
140
auto q2 = (float)p.getRotation().getValue()[2];
141
auto q3 = (float)p.getRotation().getValue()[3];
142
auto px = (float)p.getPosition().x;
143
auto py = (float)p.getPosition().y;
144
auto pz = (float)p.getPosition().z;
145
pcTransform->rotation.setValue(q0,q1,q2,q3);
146
pcTransform->translation.setValue(px,py,pz);
147
pcTransform->center.setValue(0.0f,0.0f,0.0f);
148
pcTransform->scaleFactor.setValue(1.0f,1.0f,1.0f);
152
void ViewProviderInventorObject::adjustSelectionNodes(SoNode* child, const char* docname,
155
if (child->getTypeId().isDerivedFrom(SoFCSelection::getClassTypeId())) {
156
static_cast<SoFCSelection*>(child)->documentName = docname;
157
static_cast<SoFCSelection*>(child)->objectName = objname;
159
else if (child->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
160
auto group = static_cast<SoGroup*>(child);
161
for (int i=0; i<group->getNumChildren(); i++) {
162
SoNode* subchild = group->getChild(i);
163
adjustSelectionNodes(subchild, docname, objname);