Skip to content

Commit

Permalink
Workaround for non-ASCII filenames in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Cirilo Bernardo authored and stambaughw committed Mar 3, 2017
1 parent 9660522 commit 68bcdec
Show file tree
Hide file tree
Showing 38 changed files with 601 additions and 371 deletions.
10 changes: 8 additions & 2 deletions 3d-viewer/3d_cache/sg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/3d-viewer
)
)

add_library( kicad_3dsg SHARED
set( SG_FILES
sg_base.cpp
sg_node.cpp
sg_helpers.cpp
Expand All @@ -29,6 +29,12 @@ add_library( kicad_3dsg SHARED
ifsg_api.cpp
)

if( MINGW )
list( APPEND SG_FILES ${CMAKE_SOURCE_DIR}/common/streamwrapper.cpp )
endif( MINGW )

add_library( kicad_3dsg SHARED ${SG_FILES} )

if( APPLE )
# puts library into the main kicad.app bundle in build tree
set_target_properties( kicad_3dsg PROPERTIES
Expand Down
56 changes: 17 additions & 39 deletions 3d-viewer/3d_cache/sg/ifsg_api.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
* Copyright (C) 2015-2017 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -28,6 +28,7 @@
#include <wx/log.h>
#include "plugins/3dapi/ifsg_api.h"
#include "plugins/3dapi/sg_version.h"
#include "streamwrapper.h"
#include "3d_cache/sg/sg_node.h"
#include "3d_cache/sg/scenegraph.h"
#include "3d_cache/sg/sg_appearance.h"
Expand Down Expand Up @@ -77,24 +78,6 @@ static void formatMaterial( SMATERIAL& mat, SGAPPEARANCE const* app )
}


class VRML_LOCALE
{
private:
std::string lname;

public:
VRML_LOCALE() : lname( setlocale( LC_NUMERIC, NULL ) )
{
setlocale( LC_NUMERIC, "C" ); // switch the numerics locale to "C"
}

~VRML_LOCALE()
{
setlocale( LC_NUMERIC, lname.c_str() ); // revert to the previous locale
}
};


bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
bool reuse, bool renameNodes )
{
Expand Down Expand Up @@ -141,12 +124,9 @@ bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
return false;
}

VRML_LOCALE vrmlLocale;
std::ofstream op;
op.open( filename, std::ios_base::out | std::ios_base::trunc
| std::ios_base::binary );
OPEN_OSTREAM( op, filename );

if( !op.is_open() )
if( op.fail() )
{
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
Expand All @@ -156,6 +136,7 @@ bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
return false;
}

op.imbue( std::locale( "C" ) );
op << "#VRML V2.0 utf8\n";

if( renameNodes )
Expand All @@ -168,11 +149,11 @@ bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,

if( !op.fail() )
{
op.close();
CLOSE_STREAM( op );
return true;
}

op.close();
CLOSE_STREAM( op );

do {
std::ostringstream ostr;
Expand Down Expand Up @@ -302,11 +283,9 @@ bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
}
}

std::ofstream output;
output.open( aFileName, std::ios_base::out | std::ios_base::trunc
| std::ios_base::binary );
OPEN_OSTREAM( output, aFileName );

if( !output.is_open() )
if( output.fail() )
{
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
Expand All @@ -324,7 +303,7 @@ bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
output << "(INTERNAL:0.0.0.0)";

bool rval = aNode->WriteCache( output, NULL );
output.close();
CLOSE_STREAM( output );

if( !rval )
{
Expand Down Expand Up @@ -382,10 +361,9 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
return NULL;
}

std::ifstream file;
file.open( aFileName, std::ios_base::in | std::ios_base::binary );
OPEN_ISTREAM( file, aFileName );

if( !file.is_open() )
if( file.fail() )
{
delete np;
std::ostringstream ostr;
Expand Down Expand Up @@ -417,7 +395,7 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
} while( 0 );
#endif

file.close();
CLOSE_STREAM( file );
return NULL;
}

Expand All @@ -431,7 +409,7 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,

if( name.compare( SG_VERSION_TAG ) )
{
file.close();
CLOSE_STREAM( file );
return NULL;
}

Expand All @@ -457,7 +435,7 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
} while( 0 );
#endif

file.close();
CLOSE_STREAM( file );
return NULL;
}

Expand All @@ -472,14 +450,14 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
// check the plugin tag
if( NULL != aTagCheck && NULL != aPluginMgr && !aTagCheck( name.c_str(), aPluginMgr ) )
{
file.close();
CLOSE_STREAM( file );
return NULL;
}

} while( 0 );

bool rval = np->ReadCache( file, NULL );
file.close();
CLOSE_STREAM( file );

if( !rval )
{
Expand Down
6 changes: 3 additions & 3 deletions 3d-viewer/3d_cache/sg/scenegraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void SCENEGRAPH::ReNameNodes( void )
}


bool SCENEGRAPH::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SCENEGRAPH::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( m_Transforms.empty() && m_RTransforms.empty()
&& m_Shape.empty() && m_RShape.empty() )
Expand Down Expand Up @@ -364,7 +364,7 @@ bool SCENEGRAPH::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}


bool SCENEGRAPH::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode && NULL != m_Parent )
{
Expand Down Expand Up @@ -510,7 +510,7 @@ bool SCENEGRAPH::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}


bool SCENEGRAPH::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SCENEGRAPH::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( !m_Transforms.empty() || !m_RTransforms.empty()
|| !m_Shape.empty() || !m_RShape.empty() )
Expand Down
6 changes: 3 additions & 3 deletions 3d-viewer/3d_cache/sg/scenegraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class SCENEGRAPH : public SGNODE
bool AddChildNode( SGNODE* aNode ) override;

void ReNameNodes( void ) override;
bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;

bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;

bool Prepare( const glm::dmat4* aTransform,
S3D::MATLIST& materials, std::vector< SMESH >& meshes );
Expand Down
8 changes: 4 additions & 4 deletions 3d-viewer/3d_cache/sg/sg_appearance.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
* Copyright (C) 2015-2017 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -289,7 +289,7 @@ void SGAPPEARANCE::ReNameNodes( void )
}


bool SGAPPEARANCE::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGAPPEARANCE::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( aReuseFlag )
{
Expand Down Expand Up @@ -366,7 +366,7 @@ bool SGAPPEARANCE::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}


bool SGAPPEARANCE::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGAPPEARANCE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
Expand Down Expand Up @@ -436,7 +436,7 @@ bool SGAPPEARANCE::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}


bool SGAPPEARANCE::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGAPPEARANCE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
S3D::ReadColor( aFile, ambient );
aFile.read( (char*)&shininess, sizeof(shininess) );
Expand Down
8 changes: 4 additions & 4 deletions 3d-viewer/3d_cache/sg/sg_appearance.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
* Copyright (C) 2015-2017 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -71,10 +71,10 @@ class SGAPPEARANCE : public SGNODE
bool AddChildNode( SGNODE* aNode ) override;

void ReNameNodes( void ) override;
bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;

bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
};

#endif // SG_APPEARANCE_H
8 changes: 4 additions & 4 deletions 3d-viewer/3d_cache/sg/sg_colors.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
* Copyright (C) 2015-2017 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -207,7 +207,7 @@ void SGCOLORS::ReNameNodes( void )
}


bool SGCOLORS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGCOLORS::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( colors.empty() )
return false;
Expand Down Expand Up @@ -265,7 +265,7 @@ bool SGCOLORS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}


bool SGCOLORS::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGCOLORS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
Expand Down Expand Up @@ -334,7 +334,7 @@ bool SGCOLORS::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}


bool SGCOLORS::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGCOLORS::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( !colors.empty() )
{
Expand Down
8 changes: 4 additions & 4 deletions 3d-viewer/3d_cache/sg/sg_colors.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
* Copyright (C) 2015-2017 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -56,10 +56,10 @@ class SGCOLORS : public SGNODE
void AddColor( const SGCOLOR& aColor );

void ReNameNodes( void ) override;
bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ) override;
bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;

bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ) override;
bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
};

#endif // SG_COLORS_H
8 changes: 4 additions & 4 deletions 3d-viewer/3d_cache/sg/sg_coords.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
* Copyright (C) 2015-2017 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -210,7 +210,7 @@ void SGCOORDS::ReNameNodes( void )
}


bool SGCOORDS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGCOORDS::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( coords.empty() )
return false;
Expand Down Expand Up @@ -272,7 +272,7 @@ bool SGCOORDS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}


bool SGCOORDS::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGCOORDS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
Expand Down Expand Up @@ -341,7 +341,7 @@ bool SGCOORDS::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}


bool SGCOORDS::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGCOORDS::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( !coords.empty() )
{
Expand Down
Loading

0 comments on commit 68bcdec

Please sign in to comment.