vrmlmodelparser.cpp 2.67 KB
Newer Older
1 2 3 4 5 6
/*
 * 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>
7
 * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *
 * 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"
39

40

41 42 43
VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
    S3D_MODEL_PARSER( aMaster )
{
44 45
}

46
VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
47
{
48 49 50 51 52 53 54 55
    for( unsigned int idx = 0; idx < childs.size(); idx++ )
    {
        if( childs[idx] )
        {
            delete childs[idx];
            childs[idx] = 0;
        }
    }
56 57
}

58
bool VRML_MODEL_PARSER::Load( const wxString& aFilename )
59
{
60
    char       line[11 + 1];
61
    FILE*      file;
62

63
    //DBG( printf( "Load %s", GetChars( aFilename ) ) );
64

65
    file = wxFopen( aFilename, wxT( "rt" ) );
66

67
    if( file == NULL )
68
        return false;
69

70
    if( fgets( line, 11, file ) == NULL )
71
    {
72
        fclose( file );
73
        return false;
74
    }
75

76
    fclose( file );
77

78 79
    childs.clear();

80
    if( stricmp( line, "#VRML V2.0" ) == 0 )
81
    {
82
        VRML2_MODEL_PARSER *vrml2_parser = new VRML2_MODEL_PARSER( this );
83
        vrml2_parser->Load( aFilename );
84
        delete vrml2_parser;
85
        return true;
86
    }
87
    else if( stricmp( line, "#VRML V1.0" ) == 0 )
88
    {
89
        VRML1_MODEL_PARSER *vrml1_parser = new VRML1_MODEL_PARSER( this );
90
        vrml1_parser->Load( aFilename );
91
        delete vrml1_parser;
92
        return true;
93 94
    }

95 96
    DBG( printf( "Unknown internal VRML file format: %s\n", line ) );
    return false;
97
}