2013-03-27 18:34:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Tuomas Vaherkoski <tuomasvaherkoski@gmail.com>
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras@wanadoo.fr
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2014-04-27 13:49:41 +00:00
|
|
|
* Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-03-27 18:34:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file vrmlmodelparser.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <info3d_visu.h>
|
|
|
|
|
|
|
|
#include "3d_struct.h"
|
|
|
|
#include "modelparsers.h"
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
|
|
|
|
S3D_MODEL_PARSER( aMaster )
|
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
vrml1_parser = new VRML1_MODEL_PARSER( aMaster );
|
|
|
|
vrml2_parser = new VRML2_MODEL_PARSER( aMaster );
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
if( vrml1_parser )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
delete vrml1_parser;
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2014-07-30 09:01:25 +00:00
|
|
|
if( vrml2_parser )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
delete vrml2_parser;
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-21 11:59:57 +00:00
|
|
|
void VRML_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-08-21 11:59:57 +00:00
|
|
|
char line[128];
|
2014-07-30 09:01:25 +00:00
|
|
|
FILE* file;
|
2013-03-27 18:34:23 +00:00
|
|
|
|
2014-08-21 11:59:57 +00:00
|
|
|
//DBG( printf( "Load %s", GetChars( aFilename ) ) );
|
2013-03-27 18:34:23 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
file = wxFopen( aFilename, wxT( "rt" ) );
|
2013-03-27 18:34:23 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
if( file == NULL )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
return;
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
if( fgets( line, 11, file ) == NULL )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
fclose( file );
|
2014-08-16 18:01:00 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
return;
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2014-08-16 18:01:00 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
fclose( file );
|
2014-08-16 18:01:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( stricmp( line, "#VRML V2.0" ) == 0 )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
//DBG( printf( "About to parser a #VRML V2.0 file\n" ) );
|
2014-08-21 11:59:57 +00:00
|
|
|
vrml2_parser->Load( aFilename, aVrmlunits_to_3Dunits );
|
2014-08-16 18:01:00 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
return;
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2014-08-16 18:01:00 +00:00
|
|
|
else if( stricmp( line, "#VRML V1.0" ) == 0 )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
//DBG( printf( "About to parser a #VRML V1.0 file\n" ) );
|
2014-08-21 11:59:57 +00:00
|
|
|
vrml1_parser->Load( aFilename, aVrmlunits_to_3Dunits );
|
2014-04-27 13:49:41 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
return;
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
|
|
|
|
2014-08-16 18:01:00 +00:00
|
|
|
// DBG( printf( "Unknown VRML file format: %s\n", line ) );
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|