7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-18 18:49:17 +00:00

Workaround for non-ASCII filenames in Windows

This commit is contained in:
Cirilo Bernardo 2017-03-03 09:53:49 +11:00 committed by Wayne Stambaugh
parent 966052272f
commit 68bcdec87e
38 changed files with 601 additions and 371 deletions

View File

@ -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
@ -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

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -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"
@ -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 )
{
@ -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";
@ -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 )
@ -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;
@ -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";
@ -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 )
{
@ -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;
@ -417,7 +395,7 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
} while( 0 );
#endif
file.close();
CLOSE_STREAM( file );
return NULL;
}
@ -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;
}
@ -457,7 +435,7 @@ SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
} while( 0 );
#endif
file.close();
CLOSE_STREAM( file );
return NULL;
}
@ -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 )
{

View File

@ -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() )
@ -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 )
{
@ -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() )

View File

@ -79,10 +79,10 @@ public:
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 );

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -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 )
{
@ -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 )
{
@ -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) );

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -71,10 +71,10 @@ public:
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

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -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;
@ -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 )
{
@ -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() )
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -56,10 +56,10 @@ public:
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

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -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;
@ -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 )
{
@ -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() )
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -65,10 +65,10 @@ public:
bool CalcNormals( SGFACESET* callingNode, SGNODE** aPtr = NULL );
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_COORDS_H

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -482,7 +482,7 @@ void SGFACESET::ReNameNodes( void )
}
bool SGFACESET::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGFACESET::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( ( NULL == m_Coords && NULL == m_RCoords )
|| ( NULL == m_CoordIndices ) )
@ -538,7 +538,7 @@ bool SGFACESET::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}
bool SGFACESET::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGFACESET::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
@ -670,7 +670,7 @@ bool SGFACESET::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}
bool SGFACESET::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( m_Coords || m_RCoords || m_CoordIndices
|| m_Colors || m_RColors

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -78,10 +78,10 @@ public:
bool CalcNormals( SGNODE** aPtr );
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;
/**
* Function GatherCoordIndices

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -162,7 +162,7 @@ void S3D::FormatColor( std::string& result, const SGCOLOR& aColor )
}
bool S3D::WritePoint( std::ofstream& aFile, const SGPOINT& aPoint )
bool S3D::WritePoint( std::ostream& aFile, const SGPOINT& aPoint )
{
aFile.write( (char*)&aPoint.x, sizeof(aPoint.x) );
aFile.write( (char*)&aPoint.y, sizeof(aPoint.y) );
@ -175,7 +175,7 @@ bool S3D::WritePoint( std::ofstream& aFile, const SGPOINT& aPoint )
}
bool S3D::WriteVector( std::ofstream& aFile, const SGVECTOR& aVector )
bool S3D::WriteVector( std::ostream& aFile, const SGVECTOR& aVector )
{
double x, y, z;
aVector.GetVector( x, y, z );
@ -190,7 +190,7 @@ bool S3D::WriteVector( std::ofstream& aFile, const SGVECTOR& aVector )
}
bool S3D::WriteColor( std::ofstream& aFile, const SGCOLOR& aColor )
bool S3D::WriteColor( std::ostream& aFile, const SGCOLOR& aColor )
{
float r, g, b;
aColor.GetColor( r, g, b );
@ -205,7 +205,7 @@ bool S3D::WriteColor( std::ofstream& aFile, const SGCOLOR& aColor )
}
S3D::SGTYPES S3D::ReadTag( std::ifstream& aFile, std::string& aName )
S3D::SGTYPES S3D::ReadTag( std::istream& aFile, std::string& aName )
{
char schar;
aFile.get( schar );
@ -293,7 +293,7 @@ S3D::SGTYPES S3D::ReadTag( std::ifstream& aFile, std::string& aName )
}
bool S3D::ReadPoint( std::ifstream& aFile, SGPOINT& aPoint )
bool S3D::ReadPoint( std::istream& aFile, SGPOINT& aPoint )
{
aFile.read( (char*)&aPoint.x, sizeof( aPoint.x ) );
aFile.read( (char*)&aPoint.y, sizeof( aPoint.y ) );
@ -306,7 +306,7 @@ bool S3D::ReadPoint( std::ifstream& aFile, SGPOINT& aPoint )
}
bool S3D::ReadVector( std::ifstream& aFile, SGVECTOR& aVector )
bool S3D::ReadVector( std::istream& aFile, SGVECTOR& aVector )
{
double x, y, z;
aFile.read( (char*)&x, sizeof(double) );
@ -321,7 +321,7 @@ bool S3D::ReadVector( std::ifstream& aFile, SGVECTOR& aVector )
}
bool S3D::ReadColor( std::ifstream& aFile, SGCOLOR& aColor )
bool S3D::ReadColor( std::istream& aFile, SGCOLOR& aColor )
{
float r, g, b;
aFile.read( (char*)&r, sizeof(float) );

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -32,7 +32,7 @@
#ifndef SG_HELPERS_H
#define SG_HELPERS_H
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
@ -210,13 +210,13 @@ namespace S3D
//
// write out an XYZ vertex
bool WritePoint( std::ofstream& aFile, const SGPOINT& aPoint );
bool WritePoint( std::ostream& aFile, const SGPOINT& aPoint );
// write out a unit vector
bool WriteVector( std::ofstream& aFile, const SGVECTOR& aVector );
bool WriteVector( std::ostream& aFile, const SGVECTOR& aVector );
// write out an RGB color
bool WriteColor( std::ofstream& aFile, const SGCOLOR& aColor );
bool WriteColor( std::ostream& aFile, const SGCOLOR& aColor );
//
// Cache related READ functions
@ -232,16 +232,16 @@ namespace S3D
* @return will be the NodeType which the tag represents or
* S3D::SGTYPES::SGTYPE_END on failure
*/
S3D::SGTYPES ReadTag( std::ifstream& aFile, std::string& aName );
S3D::SGTYPES ReadTag( std::istream& aFile, std::string& aName );
// read an XYZ vertex
bool ReadPoint( std::ifstream& aFile, SGPOINT& aPoint );
bool ReadPoint( std::istream& aFile, SGPOINT& aPoint );
// read a unit vector
bool ReadVector( std::ifstream& aFile, SGVECTOR& aVector );
bool ReadVector( std::istream& aFile, SGVECTOR& aVector );
// read an RGB color
bool ReadColor( std::ifstream& aFile, SGCOLOR& aColor );
bool ReadColor( std::istream& aFile, SGCOLOR& aColor );
};
#endif // SG_HELPERS_H

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -21,7 +21,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fstream>
#include <iostream>
#include <sstream>
#include <wx/log.h>
@ -195,7 +194,7 @@ void SGINDEX::ReNameNodes( void )
}
bool SGINDEX::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGINDEX::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( index.empty() )
return false;
@ -207,7 +206,7 @@ bool SGINDEX::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}
bool SGINDEX::writeCoordIndex( std::ofstream& aFile )
bool SGINDEX::writeCoordIndex( std::ostream& aFile )
{
size_t n = index.size();
@ -259,14 +258,14 @@ bool SGINDEX::writeCoordIndex( std::ofstream& aFile )
}
bool SGINDEX::writeColorIndex( std::ofstream& aFile )
bool SGINDEX::writeColorIndex( std::ostream& aFile )
{
aFile << " colorIndex [\n ";
return writeIndexList( aFile );
}
bool SGINDEX::writeIndexList( std::ofstream& aFile )
bool SGINDEX::writeIndexList( std::ostream& aFile )
{
// index to control formatting
int nv = 0;
@ -295,7 +294,7 @@ bool SGINDEX::writeIndexList( std::ofstream& aFile )
}
bool SGINDEX::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGINDEX::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
@ -364,7 +363,7 @@ bool SGINDEX::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}
bool SGINDEX::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGINDEX::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( !index.empty() )
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -35,9 +35,9 @@
class SGINDEX : public SGNODE
{
protected:
bool writeCoordIndex( std::ofstream& aFile );
bool writeColorIndex( std::ofstream& aFile );
bool writeIndexList( std::ofstream& aFile );
bool writeCoordIndex( std::ostream& aFile );
bool writeColorIndex( std::ostream& aFile );
bool writeIndexList( std::ostream& aFile );
public:
// for internal SG consumption only
@ -89,10 +89,10 @@ public:
void AddIndex( int aIndex );
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_INDEX_H

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -30,7 +30,7 @@
#ifndef SG_NODE_H
#define SG_NODE_H
#include <fstream>
#include <iostream>
#include <string>
#include <list>
#include <vector>
@ -227,7 +227,7 @@ public:
* writes this node's data to a VRML file; this includes
* all data of child and referenced nodes.
*/
virtual bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ) = 0;
virtual bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) = 0;
/**
* Function WriteCache
@ -236,7 +236,7 @@ public:
* If this function is invoked by the user, parentNode must be
* set to NULL in order to ensure coherent data.
*/
virtual bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ) = 0;
virtual bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) = 0;
/**
* Function ReadCache
@ -244,7 +244,7 @@ public:
* open the file for reading and invoke this function from a new
* SCENEGRAPH node.
*/
virtual bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ) = 0;
virtual bool ReadCache( std::istream& aFile, SGNODE* parentNode ) = 0;
};
#endif // SG_NODE_H

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -208,7 +208,7 @@ void SGNORMALS::ReNameNodes( void )
}
bool SGNORMALS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGNORMALS::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( norms.empty() )
return false;
@ -264,7 +264,7 @@ bool SGNORMALS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}
bool SGNORMALS::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGNORMALS::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
@ -333,7 +333,7 @@ bool SGNORMALS::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}
bool SGNORMALS::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGNORMALS::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( !norms.empty() )
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -56,10 +56,10 @@ public:
void AddNormal( const SGVECTOR& aNormal );
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_NORMALS_H

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -22,7 +22,6 @@
*/
#include <fstream>
#include <iostream>
#include <sstream>
#include <wx/log.h>
@ -357,7 +356,7 @@ void SGSHAPE::ReNameNodes( void )
}
bool SGSHAPE::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
bool SGSHAPE::WriteVRML( std::ostream& aFile, bool aReuseFlag )
{
if( !m_Appearance && !m_RAppearance
&& !m_FaceSet && !m_RFaceSet )
@ -401,7 +400,7 @@ bool SGSHAPE::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
}
bool SGSHAPE::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
bool SGSHAPE::WriteCache( std::ostream& aFile, SGNODE* parentNode )
{
if( NULL == parentNode )
{
@ -509,7 +508,7 @@ bool SGSHAPE::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
}
bool SGSHAPE::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
bool SGSHAPE::ReadCache( std::istream& aFile, SGNODE* parentNode )
{
if( m_Appearance || m_RAppearance || m_FaceSet || m_RFaceSet )
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -65,10 +65,10 @@ public:
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 );

121
common/streamwrapper.cpp Normal file
View File

@ -0,0 +1,121 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#if !defined( WIN32 ) || !defined( __GNUC__ )
#error streamwrapper.cpp should not be included in this build
#endif
#include "streamwrapper.h"
#include <wx/string.h>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
kicad::stream::stream()
{
m_buf = NULL;
m_stream = NULL;
return;
}
kicad::stream::~stream()
{
if( NULL != m_stream )
delete m_stream;
if( NULL != m_buf )
{
m_buf->close(); // ensure file is closed regardless of m_buf's destructor
delete m_buf;
}
return;
}
std::iostream* kicad::stream::Open( const char* aFileName, std::ios_base::openmode aMode )
{
if( NULL != m_stream )
{
delete m_stream;
m_stream = NULL;
}
if( NULL != m_buf )
{
m_buf->close();
delete m_buf;
}
int flags = 0;
if( aMode & std::ios_base::app )
flags |= _O_APPEND;
if( aMode & std::ios_base::out && aMode & std::ios_base::in )
flags |= _O_RDWR;
else if( aMode & std::ios_base::out )
flags |= _O_WRONLY;
else if( aMode & std::ios_base::in )
flags |= _O_RDONLY;
if( aMode & std::ios_base::binary )
flags |= _O_BINARY;
if( aMode & std::ios_base::out && aMode & std::ios_base::trunc
&& !( aMode & std::ios_base::app ) && !( aMode & std::ios_base::ate ) )
flags |= _O_TRUNC;
if( aMode & std::ios_base::out )
flags |= _O_CREAT;
//int fd = open( "testfile.txt", flags, S_IRUSR | S_IWUSR );
wxString lstr( wxString::FromUTF8Unchecked( aFileName ) );
int fd = _wopen( lstr.wc_str(), flags, _S_IREAD | _S_IWRITE );
if( fd >= 0 && aMode & std::ios_base::ate )
lseek( fd, 0, SEEK_END );
// NOTE: _O_RDONLY in Windows, O_RDONLY in Linux
m_buf = new __gnu_cxx::stdio_filebuf<char>( fd, aMode );
m_stream = new std::iostream( m_buf );
return m_stream;
}
void kicad::stream::Close( void )
{
if( m_buf )
m_buf->close();
return;
}
std::iostream* kicad::stream::GetStream( void )
{
return m_stream;
}

101
include/streamwrapper.h Normal file
View File

@ -0,0 +1,101 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef STREAMWRAPPER_H
#define STREAMWRAPPER_H
#include <iostream>
#if defined( WIN32 ) && defined( __GNUC__ )
#include <ext/stdio_filebuf.h>
#define OPEN_OSTREAM( var, name ) \
kicad::stream var ## _BUF_; \
std::ostream& var = *var ## _BUF_.Open( name, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary )
#define OPEN_ISTREAM( var, name ) \
kicad::stream var ## _BUF_; \
std::istream& var = *var ## _BUF_.Open( name, std::ios_base::in | std::ios_base::binary )
#define OPEN_IOSTREAM( var, name ) \
kicad::stream var ## _BUF_; \
std::iostream& var = *var ## _BUF_.Open( name, std::ios_base::out | std::ios_base::in | std::ios_base::binary )
#define CLOSE_STREAM( var ) var ## _BUF_.Close()
namespace kicad
{
class stream
{
private:
__gnu_cxx::stdio_filebuf<char>* m_buf;
std::iostream* m_stream;
public:
stream();
virtual ~stream();
std::iostream* Open( const char* aFileName, std::ios_base::openmode aMode );
void Close( void );
std::iostream* GetStream( void );
};
}
#elif defined( _MSC_VER ) // defined( WIN32 ) && defined( __GNUC__ )
#define OPEN_OSTREAM( var, name ) \
std::ofstream var; \
var.open( wxString::FromUTF8Unchecked( name ).wc_str(), \
std::ios_base::out | std::ios_base::trunc | std::ios_base::binary )
#define OPEN_ISTREAM( var, name ) \
std::ifstream var; \
var.open( wxString::FromUTF8Unchecked( name ).wc_str(), \
std::ios_base::in | std::ios_base::binary )
#define OPEN_IOSTREAM( var, name ) \
std::fstream var; \
var.open( wxString::FromUTF8Unchecked( name ).wc_str(), \
std::ios_base::out | std::ios_base::in | std::ios_base::binary )
#define CLOSE_STREAM( var ) var.close()
#else // defined( WIN32 ) && defined( __GNUC__ )
#define OPEN_OSTREAM( var, name ) \
std::ofstream var; \
var.open( name, std::ios_base::out | std::ios_base::trunc )
#define OPEN_ISTREAM( var, name ) \
std::ifstream var; \
var.open( name, std::ios_base::in )
#define OPEN_IOSTREAM( var, name ) \
std::fstream var; \
var.open( name, std::ios_base::out | std::ios_base::in )
#define CLOSE_STREAM( var ) var.close()
#endif // defined( WIN32 ) && defined( __GNUC__ )
#endif // STREAMWRAPPER_H

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009-2013 Lorenzo Mercantonio
* Copyright (C) 2014-2016 Cirilo Bernardo
* Copyright (C) 2014-2017 Cirilo Bernardo
* Copyright (C) 2013 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
@ -44,6 +44,7 @@
#include "macros.h"
#include "pgm_base.h"
#include "plugins/3dapi/ifsg_all.h"
#include "streamwrapper.h"
#include "vrml_layer.h"
#include "wxPcbStruct.h"
#include "../../kicad/kicad.h"
@ -62,7 +63,6 @@ static bool USE_DEFS; // true to reuse component definitions
static bool USE_RELPATH; // true to use relative paths in VRML inline{}
static double WORLD_SCALE = 1.0; // scaling from 0.1 in to desired VRML unit
static double BOARD_SCALE; // scaling from mm to desired VRML world scale
static std::ofstream output_file; // legacy VRML output stream
static const int PRECISION = 6; // legacy precision factor (now set to 6)
static wxString SUBDIR_3D; // legacy 3D subdirectory
static wxString PROJ_DIR; // project directory
@ -315,7 +315,7 @@ static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color
static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
VRML_LAYER* layer, double aHeight, bool aTopPlane );
static void write_triangle_bag( std::ofstream& aOut_file, VRML_COLOR& aColor,
static void write_triangle_bag( std::ostream& aOut_file, VRML_COLOR& aColor,
VRML_LAYER* aLayer, bool aPlane, bool aTop,
double aTop_z, double aBottom_z )
{
@ -415,7 +415,8 @@ static void write_triangle_bag( std::ofstream& aOut_file, VRML_COLOR& aColor,
}
static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName )
static void write_layers( MODEL_VRML& aModel, BOARD* aPcb,
const char* aFileName, std::ofstream* aOutputFile )
{
// VRML_LAYER board;
aModel.m_board.Tesselate( &aModel.m_holes );
@ -424,7 +425,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_PCB ),
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_PCB ),
&aModel.m_board, false, false, brdz, -brdz );
}
else
@ -445,7 +446,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TRACK ),
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
&aModel.m_top_copper, true, true,
aModel.GetLayerZ( F_Cu ), 0 );
}
@ -460,7 +461,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TIN ),
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
&aModel.m_top_tin, true, true,
aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
0 );
@ -477,7 +478,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TRACK ),
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ),
&aModel.m_bot_copper, true, false,
aModel.GetLayerZ( B_Cu ), 0 );
}
@ -492,7 +493,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TIN ),
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
&aModel.m_bot_tin, true, false,
aModel.GetLayerZ( B_Cu )
- Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
@ -510,7 +511,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TIN ),
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ),
&aModel.m_plated_holes, false, false,
aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
@ -527,7 +528,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_top_silk,
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_top_silk,
true, true, aModel.GetLayerZ( F_SilkS ), 0 );
}
else
@ -541,7 +542,7 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName
if( USE_INLINES )
{
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_bot_silk,
write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_bot_silk,
true, false, aModel.GetLayerZ( B_SilkS ), 0 );
}
else
@ -1265,7 +1266,8 @@ static void compose_quat( double q1[4], double q2[4], double qr[4] )
}
static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule )
static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb,
MODULE* aModule, std::ostream* aOutputFile )
{
if( !aModel.m_plainPCB )
{
@ -1404,29 +1406,28 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule
if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) )
continue;
}
}
output_file << "Transform {\n";
(*aOutputFile) << "Transform {\n";
// only write a rotation if it is >= 0.1 deg
if( std::abs( rot[3] ) > 0.0001745 )
{
output_file << " rotation " << std::setprecision( 5 );
output_file << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
(*aOutputFile) << " rotation " << std::setprecision( 5 );
(*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
}
output_file << " translation " << std::setprecision( PRECISION );
output_file << trans.x << " ";
output_file << trans.y << " ";
output_file << trans.z << "\n";
(*aOutputFile) << " translation " << std::setprecision( PRECISION );
(*aOutputFile) << trans.x << " ";
(*aOutputFile) << trans.y << " ";
(*aOutputFile) << trans.z << "\n";
output_file << " scale ";
output_file << sM->m_Scale.x << " ";
output_file << sM->m_Scale.y << " ";
output_file << sM->m_Scale.z << "\n";
(*aOutputFile) << " scale ";
(*aOutputFile) << sM->m_Scale.x << " ";
(*aOutputFile) << sM->m_Scale.y << " ";
(*aOutputFile) << sM->m_Scale.z << "\n";
output_file << " children [\n Inline {\n url \"";
(*aOutputFile) << " children [\n Inline {\n url \"";
if( USE_RELPATH )
{
@ -1439,8 +1440,8 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule
wxString fn = dstFile.GetFullPath();
fn.Replace( "\\", "/" );
output_file << TO_UTF8( fn ) << "\"\n } ]\n";
output_file << " }\n";
(*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
(*aOutputFile) << " }\n";
}
else
{
@ -1503,9 +1504,6 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt
// plain PCB or else PCB with copper and silkscreen
model3d.m_plainPCB = aUsePlainPCB;
// locale switch for C numeric output
LOCALE_IO* toggle = NULL;
try
{
@ -1537,8 +1535,16 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt
throw( std::runtime_error( "Could not create 3D model subdirectory" ) );
}
toggle = new LOCALE_IO;
output_file.open( TO_UTF8( aFullFileName ), std::ios_base::out );
OPEN_OSTREAM( output_file, TO_UTF8( aFullFileName ) );
if( output_file.fail() )
{
std::ostringstream ostr;
ostr << "Could not open file '" << TO_UTF8( aFullFileName ) << "'";
throw( std::runtime_error( ostr.str().c_str() ) );
}
output_file.imbue( std::locale( "C" ) );
// Begin with the usual VRML boilerplate
wxString fn = aFullFileName;
@ -1553,19 +1559,28 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt
output_file << WORLD_SCALE << " ";
output_file << WORLD_SCALE << "\n";
output_file << " children [\n";
}
// Export footprints
for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() )
export_vrml_module( model3d, pcb, module );
// Export footprints
for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() )
export_vrml_module( model3d, pcb, module, &output_file );
// write out the board and all layers
write_layers( model3d, pcb, TO_UTF8( aFullFileName ) );
// write out the board and all layers
write_layers( model3d, pcb, TO_UTF8( aFullFileName ), &output_file );
// Close the outer 'transform' node
if( USE_INLINES )
// Close the outer 'transform' node
output_file << "]\n}\n";
CLOSE_STREAM( output_file );
}
else
{
// Export footprints
for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() )
export_vrml_module( model3d, pcb, module, NULL );
// write out the board and all layers
write_layers( model3d, pcb, TO_UTF8( aFullFileName ), NULL );
}
}
catch( const std::exception& e )
{
@ -1576,14 +1591,6 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt
ok = false;
}
if( USE_INLINES )
{
output_file.close();
if( toggle )
delete toggle;
}
return ok;
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -28,8 +28,10 @@
#include <cmath>
#include <string>
#include <map>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/string.h>
#include "plugins/3d/3d_plugin.h"
#include "plugins/3dapi/ifsg_all.h"
#include "idf_parser.h"

Some files were not shown because too many files have changed in this diff Show More