171{
174 wxString filename = aFileName;
175 wxFileName tmpfilename;
176
177 if( aFileName.Upper().EndsWith( wxT( "WRZ" ) ) )
178 {
179 wxFFileInputStream ifile( aFileName );
180 tmpfilename = wxFileName( aFileName );
181
182 tmpfilename.SetPath( wxStandardPaths::Get().GetTempDir() );
183 tmpfilename.SetExt( wxT( "WRL" ) );
184
185 wxFileOffset size = ifile.GetLength();
186
187 if( size == wxInvalidOffset )
188 return nullptr;
189
190 {
191 wxFFileOutputStream ofile( tmpfilename.GetFullPath() );
192
193 if( !ofile.IsOk() )
194 return nullptr;
195
196 char *buffer = new char[size];
197
198 ifile.Read( buffer, size);
199 std::string expanded;
200
201 try
202 {
203 expanded = gzip::decompress( buffer, size );
204 }
205 catch(...)
206 {
207 delete[] buffer;
208 return nullptr;
209 }
210
211 delete[] buffer;
212
213 ofile.Write( expanded.data(), expanded.size() );
214 ofile.Close();
215 }
216
217 filename = tmpfilename.GetFullPath();
218 }
219
220 try
221 {
222
223
225 }
227 {
228 wxLogError( wxS(
" * " ) +
_(
"[INFO] load failed: input line too long\n" ) );
229 return nullptr;
230 }
231
232
233
235
236
237 if( tmpfilename.IsOk() )
238 wxRemoveFile( tmpfilename.GetFullPath() );
239
241 {
242 wxLogTrace(
traceVrmlPlugin, wxT(
" * [INFO] Processing VRML 1.0 file" ) );
243
245
246 if( !bp->
Read( proc ) )
247 {
249 }
250 else
251 {
253
255 }
256
257 delete bp;
258 }
259 else
260 {
261 wxLogTrace(
traceVrmlPlugin, wxT(
" * [INFO] Processing VRML 2.0 file" ) );
262
264
265
267
268 if( !bp->
Read( proc ) )
269 {
271 }
272 else
273 {
275
276
278 }
279
280 delete bp;
281 }
282
283 if( nullptr != modelFile )
284 delete modelFile;
285
286
287#if ( defined( DEBUG_VRML1 ) && DEBUG_VRML1 > 3 ) \
288 || ( defined( DEBUG_VRML2 ) && DEBUG_VRML2 > 3 )
289 if( scene )
290 {
291 wxFileName fn( wxString::FromUTF8Unchecked( aFileName ) );
292 wxString output;
293
294 if( proc.GetVRMLType() == VRML_V1 )
295 output = wxT( "_vrml1-" );
296 else
297 output = wxT( "_vrml2-" );
298
299 output.append( fn.GetName() );
300 output.append( wxT(".wrl") );
302 }
303#endif
304
305 return scene;
306}
A LINE_READER that reads from an open file.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
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...
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
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.