43#include <wx/filename.h>
44#include <wx/stdpaths.h>
46#include <wx/wfstream.h>
49#include <decompress.hpp>
52#define PLUGIN_VRML_MAJOR 1
53#define PLUGIN_VRML_MINOR 3
54#define PLUGIN_VRML_PATCH 2
55#define PLUGIN_VRML_REVNO 2
68 return "PLUGIN_3D_VRML";
72void GetPluginVersion(
unsigned char* Major,
unsigned char* Minor,
unsigned char* Patch,
73 unsigned char* Revision )
94 std::vector<std::string>
filters;
101 filters = {
"VRML 1.0/2.0 (*.wrl;*.wrz)|*.wrl;*.wrz",
102 "X3D (*.x3d)|*.x3d" };
104 extensions = {
"wrl",
"WRL",
"wrz",
"WRZ",
"x3d",
"X3D" };
105 filters = {
"VRML 1.0/2.0 (*.wrl;*.WRL;*.wrz;*.WRZ)|*.wrl;*.WRL;*.wrz;*.WRZ",
106 "X3D (*.x3d;*.X3D)|*.x3d;*.X3D" };
155 m_locale = setlocale( LC_NUMERIC,
nullptr );
156 setlocale( LC_NUMERIC,
"C" );
161 setlocale( LC_NUMERIC,
m_locale.c_str() );
174 wxString filename = aFileName;
175 wxFileName tmpfilename;
177 if( aFileName.Upper().EndsWith( wxT(
"WRZ" ) ) )
179 wxFFileInputStream ifile( aFileName );
180 tmpfilename = wxFileName( aFileName );
182 tmpfilename.SetPath( wxStandardPaths::Get().GetTempDir() );
183 tmpfilename.SetExt( wxT(
"WRL" ) );
185 wxFileOffset size = ifile.GetLength();
187 if( size == wxInvalidOffset )
191 wxFFileOutputStream ofile( tmpfilename.GetFullPath() );
196 char *buffer =
new char[size];
198 ifile.Read( buffer, size);
199 std::string expanded;
203 expanded = gzip::decompress( buffer, size );
205 catch( std::runtime_error& e )
208 wxString::FromUTF8Unchecked( e.what() ) );
215 wxLogTrace(
traceVrmlPlugin, wxS(
" * [INFO] wrz load failed: unknown error" ) );
223 ofile.Write( expanded.data(), expanded.size() );
227 filename = tmpfilename.GetFullPath();
238 wxLogError( wxString( wxS(
" * " ) )
239 << wxString::Format(
_(
"[INFO] load failed: %s" ), e.
What() ) );
249 if( tmpfilename.IsOk() )
250 wxRemoveFile( tmpfilename.GetFullPath() );
254 wxLogTrace(
traceVrmlPlugin, wxT(
" * [INFO] Processing VRML 1.0 file" ) );
258 if( !bp->
Read( proc ) )
273 wxLogTrace(
traceVrmlPlugin, wxT(
" * [INFO] Processing VRML 2.0 file" ) );
280 if( !bp->
Read( proc ) )
295 if(
nullptr != modelFile )
299#if ( defined( DEBUG_VRML1 ) && DEBUG_VRML1 > 3 ) \
300 || ( defined( DEBUG_VRML2 ) && DEBUG_VRML2 > 3 )
303 wxFileName fn( wxString::FromUTF8Unchecked( aFileName ) );
307 output = wxT(
"_vrml1-" );
309 output = wxT(
"_vrml2-" );
311 output.append( fn.GetName() );
312 output.append( wxT(
".wrl") );
325 scene = model.
Load( aFileName );
333 if(
nullptr == aFileName )
336 wxString fname = wxString::FromUTF8Unchecked( aFileName );
338 if( !wxFileName::FileExists( fname ) )
344 wxString ext = wxFileName( fname ).GetExt();
346 if( ext == wxT(
"x3d" ) || ext == wxT(
"X3D" ) )
describes the runtime-loadable interface to support loading and parsing of 3D models.
A LINE_READER that reads from an open file.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Define the basic data set required to represent a 3D model.
The base class of all Scene Graph nodes.
Represent the top node of a VRML1 model.
SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
The top node of a VRML2 model.
void SetEnableInline(bool enable)
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
WRLVERSION GetVRMLType(void)
SCENEGRAPH * Load(const wxString &aFileName)
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
collects header files for all SG* wrappers and the API
SGLIB_API bool WriteVRML(const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
Function WriteVRML writes out the given node and its subnodes to a VRML2 file.
char const * extensions[NEXTS]
char const * filters[NFILS]
#define PLUGIN_VRML_MAJOR
static struct FILE_DATA file_data
char const * GetModelExtension(int aIndex)
Function GetModelExtension.
bool CanRender(void)
Function CanRender.
SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
char const * GetFileFilter(int aIndex)
Function GetFileFilter.
#define PLUGIN_VRML_MINOR
void GetPluginVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
Function GetPluginVersion retrieves the version of the instantiated plugin for informational purposes...
SCENEGRAPH * LoadVRML(const wxString &aFileName, bool useInline)
const char * GetKicadPluginName(void)
Function GetKicadPluginName returns the name of the plugin instance; for example IDFv3.
int GetNExtensions(void)
Function GetNExtensions.
#define PLUGIN_VRML_PATCH
SCENEGRAPH * LoadX3D(const wxString &aFileName)
int GetNFilters(void)
Function GetNFilters.
#define PLUGIN_VRML_REVNO
defines the basic input class for VRML