1
/***************************************************************************
2
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
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"
27
# include <Inventor/nodes/SoSeparator.h>
28
# include <Inventor/nodes/SoSwitch.h>
31
#include <Base/Exception.h>
32
#include <Base/Stream.h>
34
#include "ViewProviderExtern.h"
35
#include "SoFCSelection.h"
44
PROPERTY_SOURCE(Gui::ViewProviderExtern, Gui::ViewProvider)
47
ViewProviderExtern::ViewProviderExtern() = default;
49
ViewProviderExtern::~ViewProviderExtern() = default;
51
void ViewProviderExtern::setModeByString(const char* name, const char* ivFragment)
54
in.setBuffer((void*)ivFragment,std::strlen(ivFragment));
55
setModeBySoInput(name,in);
58
void ViewProviderExtern::setModeByFile(const char* name, const char* ivFileName)
61
Base::ifstream file(Base::FileInfo(ivFileName), std::ios::in | std::ios::binary);
63
std::streamoff size = 0;
64
std::streambuf* buf = file.rdbuf();
67
curr = buf->pubseekoff(0, std::ios::cur, std::ios::in);
68
size = buf->pubseekoff(0, std::ios::end, std::ios::in);
69
buf->pubseekoff(curr, std::ios::beg, std::ios::in);
73
std::vector<unsigned char> content;
74
content.reserve(size);
76
while (file.get((char&)c)) {
81
in.setBuffer(&(content[0]),content.size());
82
setModeBySoInput(name,in);
86
void ViewProviderExtern::setModeBySoInput(const char* name, SoInput &ivFileInput)
88
SoSeparator * root = SoDB::readAll(&ivFileInput);
90
std::vector<std::string>::iterator pos = std::find<std::vector<std::string>
91
::iterator,string>(modes.begin(),modes.end(),string(name));
92
if (pos == modes.end()) {
94
modes.emplace_back(name);
95
addDisplayMaskMode(root, name);
96
setDisplayMaskMode(name);
100
// not implemented yet
106
throw Base::RuntimeError("No valid Inventor input");
112
void ViewProviderExtern::adjustDocumentName(const char* docname)
114
for (int i=0; i<this->pcModeSwitch->getNumChildren(); i++) {
115
SoNode* child = this->pcModeSwitch->getChild(i);
116
adjustRecursiveDocumentName(child, docname);
120
void ViewProviderExtern::adjustRecursiveDocumentName(SoNode* child, const char* docname)
122
if (child->getTypeId().isDerivedFrom(SoFCSelection::getClassTypeId())) {
123
static_cast<SoFCSelection*>(child)->documentName = docname;
125
else if (child->getTypeId().isDerivedFrom( SoGroup::getClassTypeId())) {
126
SoGroup* group = static_cast<SoGroup*>(child);
127
for (int i=0; i<group->getNumChildren(); i++) {
128
SoNode* subchild = group->getChild(i);
129
adjustRecursiveDocumentName(subchild, docname);
134
const char* ViewProviderExtern::getDefaultDisplayMode() const
136
// returns the first item of the available modes
137
return (modes.empty() ? "" : modes.front().c_str());
140
std::vector<std::string> ViewProviderExtern::getDisplayModes() const