Commit 02c8d4db authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Minor fixes: coding style in 3d-viewer and minor code cleanup, and some fixes...

Minor fixes: coding style in 3d-viewer and minor code cleanup, and some fixes in bom python scripts, which did not work when a non ascii char (but a valid utf8 symbol) was found in xml netlist. Add comments.
parent 435ca8a7
Loading
Loading
Loading
Loading
+5 −11
Original line number Original line Diff line number Diff line
/*
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 *
 * Copyright (C) 2012 Jean-Pierre Charras, jp.charras@wanadoo.fr
 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras@wanadoo.fr
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
 *
 *
 * This program is free software; you can redistribute it and/or
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * modify it under the terms of the GNU General Public License
@@ -43,18 +43,12 @@ S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster,
                                            const wxString aExtension )
                                            const wxString aExtension )
{
{
    if ( aExtension == wxT( "x3d" ) )
    if ( aExtension == wxT( "x3d" ) )
    {
        return new X3D_MODEL_PARSER( aMaster );
        return new X3D_MODEL_PARSER( aMaster );
    }
    else if ( aExtension == wxT( "wrl" ) )
    else if ( aExtension == wxT( "wrl" ) )
    {
        return new VRML_MODEL_PARSER( aMaster );
        return new VRML_MODEL_PARSER( aMaster );
    }

    else
    {
    return NULL;
    return NULL;
 }
 }
}


const wxString S3D_MASTER::GetShape3DFullFilename()
const wxString S3D_MASTER::GetShape3DFullFilename()
{
{
+15 −0
Original line number Original line Diff line number Diff line
@@ -246,12 +246,27 @@ private:
class VRML_MODEL_PARSER: public S3D_MODEL_PARSER
class VRML_MODEL_PARSER: public S3D_MODEL_PARSER
{
{
public:
public:
    /**
     * ctor: initialize a VRML file parser
     * @param aMaster = a ref to a 3D footprint shape description to fill
     * by the vrml file data
     */
    VRML_MODEL_PARSER( S3D_MASTER* aMaster );
    VRML_MODEL_PARSER( S3D_MASTER* aMaster );

    ~VRML_MODEL_PARSER();
    ~VRML_MODEL_PARSER();


    /**
     * Function load
     * Load a 3D file and build a S3D_MASTER shape.
     * file has .vrml ext and can be VRML 1 or VRML 2 format
     * @param aFilename = the full filename to read
     * @param aVrmlunits_to_3Dunits = the csaling factor to convert the 3D file unit
     * to our internal units.
     */
    void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
    void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );


private:
private:
    S3D_MASTER*         m_curr3DShape;  ///< the current 3D shape to build from the file
    VRML1_MODEL_PARSER* vrml1_parser;
    VRML1_MODEL_PARSER* vrml1_parser;
    VRML2_MODEL_PARSER* vrml2_parser;
    VRML2_MODEL_PARSER* vrml2_parser;
};
};
+7 −11
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@
#include "modelparsers.h"
#include "modelparsers.h"
#include "vrml_aux.h"
#include "vrml_aux.h"


#define BUFLINE_SIZE 512

VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MASTER* aMaster ) :
    S3D_MODEL_PARSER( aMaster )
    S3D_MODEL_PARSER( aMaster )
{
{
@@ -50,23 +52,19 @@ VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML1_MODEL_PARSER::~VRML1_MODEL_PARSER()
VRML1_MODEL_PARSER::~VRML1_MODEL_PARSER()
{
{
    for( unsigned int idx = 0; idx < childs.size(); idx++ )
    for( unsigned int idx = 0; idx < childs.size(); idx++ )
    {
        delete childs[idx];
        delete childs[idx];
}
}
}




void VRML1_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
void VRML1_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    // DBG( printf( "Load %s\n", GetChars(aFilename) ) );
    // DBG( printf( "Load %s\n", GetChars(aFilename) ) );
    m_file = wxFopen( aFilename, wxT( "rt" ) );
    m_file = wxFopen( aFilename, wxT( "rt" ) );


    if( m_file == NULL )
    if( m_file == NULL )
    {
        return;
        return;
    }


    float vrmlunits_to_3Dunits = aVrmlunits_to_3Dunits;
    float vrmlunits_to_3Dunits = aVrmlunits_to_3Dunits;
    glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
    glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
@@ -122,7 +120,7 @@ void VRML1_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3


int VRML1_MODEL_PARSER::read_separator()
int VRML1_MODEL_PARSER::read_separator()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    // DBG( printf( "Separator\n" ) );
    // DBG( printf( "Separator\n" ) );


@@ -161,10 +159,8 @@ int VRML1_MODEL_PARSER::read_separator()
            read_NotImplemented( m_file, '}' );
            read_NotImplemented( m_file, '}' );
        }
        }
        else
        else
        {
            break;
            break;
    }
    }
    }


    return 0;
    return 0;
}
}
@@ -172,7 +168,7 @@ int VRML1_MODEL_PARSER::read_separator()


int VRML1_MODEL_PARSER::readMaterial()
int VRML1_MODEL_PARSER::readMaterial()
{
{
    char text[128];
    char text[BUFLINE_SIZE];
    S3D_MATERIAL* material = NULL;
    S3D_MATERIAL* material = NULL;


    // DBG( printf( "  readMaterial\n" ) );
    // DBG( printf( "  readMaterial\n" ) );
@@ -229,7 +225,7 @@ int VRML1_MODEL_PARSER::readMaterial()


int VRML1_MODEL_PARSER::readCoordinate3()
int VRML1_MODEL_PARSER::readCoordinate3()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    // DBG( printf( "  readCoordinate3\n" ) );
    // DBG( printf( "  readCoordinate3\n" ) );


@@ -257,7 +253,7 @@ int VRML1_MODEL_PARSER::readCoordinate3()


int VRML1_MODEL_PARSER::readIndexedFaceSet()
int VRML1_MODEL_PARSER::readIndexedFaceSet()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    // DBG( printf( "  readIndexedFaceSet\n" ) );
    // DBG( printf( "  readIndexedFaceSet\n" ) );


+16 −15
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@
#include "modelparsers.h"
#include "modelparsers.h"
#include "vrml_aux.h"
#include "vrml_aux.h"


#define BUFLINE_SIZE 512


/**
/**
 * Trace mask used to enable or disable the trace output of the VRML V2 parser code.
 * Trace mask used to enable or disable the trace output of the VRML V2 parser code.
@@ -71,7 +72,7 @@ VRML2_MODEL_PARSER::~VRML2_MODEL_PARSER()


void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    wxLogTrace( traceVrmlV2Parser, wxT( "Load %s" ), GetChars( aFilename ) );
    wxLogTrace( traceVrmlV2Parser, wxT( "Load %s" ), GetChars( aFilename ) );
    m_file = wxFopen( aFilename, wxT( "rt" ) );
    m_file = wxFopen( aFilename, wxT( "rt" ) );
@@ -140,7 +141,7 @@ void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3


int VRML2_MODEL_PARSER::read_Transform()
int VRML2_MODEL_PARSER::read_Transform()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -255,7 +256,7 @@ int VRML2_MODEL_PARSER::read_Transform()


int VRML2_MODEL_PARSER::read_DEF_Coordinate()
int VRML2_MODEL_PARSER::read_DEF_Coordinate()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    // Get the name of the definition.
    // Get the name of the definition.
    if( !GetNextTag( m_file, text, sizeof(text) ) )
    if( !GetNextTag( m_file, text, sizeof(text) ) )
@@ -288,7 +289,7 @@ int VRML2_MODEL_PARSER::read_DEF_Coordinate()


int VRML2_MODEL_PARSER::read_DEF()
int VRML2_MODEL_PARSER::read_DEF()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    if( !GetNextTag( m_file, text, sizeof(text) ) )
    if( !GetNextTag( m_file, text, sizeof(text) ) )
        return -1;
        return -1;
@@ -345,7 +346,7 @@ int VRML2_MODEL_PARSER::read_DEF()


int VRML2_MODEL_PARSER::read_USE()
int VRML2_MODEL_PARSER::read_USE()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    // Get the name of the definition.
    // Get the name of the definition.
    if( !GetNextTag( m_file, text, sizeof(text) ) )
    if( !GetNextTag( m_file, text, sizeof(text) ) )
@@ -372,7 +373,7 @@ int VRML2_MODEL_PARSER::read_USE()


int VRML2_MODEL_PARSER::read_Shape()
int VRML2_MODEL_PARSER::read_Shape()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -422,7 +423,7 @@ int VRML2_MODEL_PARSER::read_Shape()


int VRML2_MODEL_PARSER::read_Appearance()
int VRML2_MODEL_PARSER::read_Appearance()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -450,7 +451,7 @@ int VRML2_MODEL_PARSER::read_Appearance()
int VRML2_MODEL_PARSER::read_material()
int VRML2_MODEL_PARSER::read_material()
{
{
    S3D_MATERIAL* material = NULL;
    S3D_MATERIAL* material = NULL;
    char text[128];
    char text[BUFLINE_SIZE];


    if( GetNextTag( m_file, text, sizeof(text) ) )
    if( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -514,7 +515,7 @@ int VRML2_MODEL_PARSER::read_material()


int VRML2_MODEL_PARSER::read_Material()
int VRML2_MODEL_PARSER::read_Material()
{
{
    char text[128];
    char text[BUFLINE_SIZE];
    glm::vec3 vertex;
    glm::vec3 vertex;


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
@@ -594,7 +595,7 @@ int VRML2_MODEL_PARSER::read_Material()


int VRML2_MODEL_PARSER::read_IndexedFaceSet()
int VRML2_MODEL_PARSER::read_IndexedFaceSet()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    m_normalPerVertex = false;
    m_normalPerVertex = false;
    colorPerVertex = false;
    colorPerVertex = false;
@@ -671,7 +672,7 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()


int VRML2_MODEL_PARSER::read_IndexedLineSet()
int VRML2_MODEL_PARSER::read_IndexedLineSet()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -787,7 +788,7 @@ int VRML2_MODEL_PARSER::read_coordIndex()


int VRML2_MODEL_PARSER::read_Color()
int VRML2_MODEL_PARSER::read_Color()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -814,7 +815,7 @@ int VRML2_MODEL_PARSER::read_Color()


int VRML2_MODEL_PARSER::read_Normal()
int VRML2_MODEL_PARSER::read_Normal()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -847,7 +848,7 @@ int VRML2_MODEL_PARSER::read_Normal()


int VRML2_MODEL_PARSER::read_Coordinate()
int VRML2_MODEL_PARSER::read_Coordinate()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
@@ -876,7 +877,7 @@ int VRML2_MODEL_PARSER::read_Coordinate()
 */
 */
int VRML2_MODEL_PARSER::read_CoordinateDef()
int VRML2_MODEL_PARSER::read_CoordinateDef()
{
{
    char text[128];
    char text[BUFLINE_SIZE];


    while( GetNextTag( m_file, text, sizeof(text) ) )
    while( GetNextTag( m_file, text, sizeof(text) ) )
    {
    {
+9 −16
Original line number Original line Diff line number Diff line
@@ -41,21 +41,14 @@
VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
    S3D_MODEL_PARSER( aMaster )
    S3D_MODEL_PARSER( aMaster )
{
{
    vrml1_parser = new VRML1_MODEL_PARSER( aMaster );
    m_curr3DShape = aMaster;
    vrml2_parser = new VRML2_MODEL_PARSER( aMaster );
    vrml1_parser = NULL;
    vrml2_parser = NULL;
}
}




VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
{
{
    if( vrml1_parser )
    {
        delete vrml1_parser;
    }
    if( vrml2_parser )
    {
        delete vrml2_parser;
    }
}
}




@@ -69,32 +62,32 @@ void VRML_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3D
    file = wxFopen( aFilename, wxT( "rt" ) );
    file = wxFopen( aFilename, wxT( "rt" ) );


    if( file == NULL )
    if( file == NULL )
    {
        return;
        return;
    }


    if( fgets( line, 11, file ) == NULL )
    if( fgets( line, 11, file ) == NULL )
    {
    {
        fclose( file );
        fclose( file );

        return;
        return;
    }
    }


    fclose( file );
    fclose( file );



    if( stricmp( line, "#VRML V2.0" ) == 0 )
    if( stricmp( line, "#VRML V2.0" ) == 0 )
    {
    {
        //DBG( printf( "About to parser a #VRML V2.0 file\n" ) );
        //DBG( printf( "About to parser a #VRML V2.0 file\n" ) );
        vrml2_parser = new VRML2_MODEL_PARSER( m_curr3DShape );
        vrml2_parser->Load( aFilename, aVrmlunits_to_3Dunits );
        vrml2_parser->Load( aFilename, aVrmlunits_to_3Dunits );

        delete vrml2_parser;
        vrml2_parser = NULL;
        return;
        return;
    }
    }
    else if( stricmp( line, "#VRML V1.0" ) == 0 )
    else if( stricmp( line, "#VRML V1.0" ) == 0 )
    {
    {
        //DBG( printf( "About to parser a #VRML V1.0 file\n" ) );
        //DBG( printf( "About to parser a #VRML V1.0 file\n" ) );
        vrml1_parser = new VRML1_MODEL_PARSER( m_curr3DShape );
        vrml1_parser->Load( aFilename, aVrmlunits_to_3Dunits );
        vrml1_parser->Load( aFilename, aVrmlunits_to_3Dunits );

        delete vrml1_parser;
        vrml1_parser = NULL;
        return;
        return;
    }
    }


Loading