STEP: Export stpz files

Also include .stpz files as alternates to wrl/wrz models
This commit is contained in:
Seth Hillbrand 2020-08-25 19:27:08 -07:00
parent 1d2838bd92
commit d0e43ab9f1
2 changed files with 76 additions and 11 deletions

View File

@ -46,7 +46,11 @@ target_link_libraries( kicad2step
kicad2step_lib kicad2step_lib
${wxWidgets_LIBRARIES} ${wxWidgets_LIBRARIES}
${OCC_LIBRARIES} ${OCC_LIBRARIES}
) ${ZLIB_LIBRARIES} )
target_include_directories( kicad2step_lib PRIVATE
$<TARGET_PROPERTY:gzip-hpp,INTERFACE_INCLUDE_DIRECTORIES>
)
if( APPLE ) if( APPLE )
# puts binaries into the *.app bundle while linking # puts binaries into the *.app bundle while linking

View File

@ -29,6 +29,10 @@
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/filefn.h> #include <wx/filefn.h>
#include <wx/stdpaths.h>
#include <wx/wfstream.h>
#include <decompress.hpp>
#include "oce_utils.h" #include "oce_utils.h"
#include "kicadpad.h" #include "kicadpad.h"
@ -149,12 +153,14 @@ static void reverseCurve( KICADCURVE& aCurve )
// supported file types // supported file types
enum FormatType enum FormatType
{ {
FMT_NONE = 0, FMT_NONE,
FMT_STEP = 1, FMT_STEP,
FMT_IGES = 2, FMT_STEPZ,
FMT_EMN = 3, FMT_IGES,
FMT_IDF = 4, FMT_EMN,
FMT_WRL = 5, // .wrl files are replaced with MCAD equivalent FMT_IDF,
FMT_WRL,
FMT_WRZ
}; };
@ -172,16 +178,23 @@ FormatType fileType( const char* aFileName )
return FMT_NONE; return FMT_NONE;
} }
wxString ext = lfile.GetExt(); wxString ext = lfile.GetExt().Lower();
if( ext.Lower() == "wrl" ) if( ext == "wrl" )
return FMT_WRL; return FMT_WRL;
if( ext == "idf" || ext == "IDF" ) if( ext == "wrz" )
return FMT_WRZ;
if( ext == "idf" )
return FMT_IDF; // component outline return FMT_IDF; // component outline
else if( ext == "emn" || ext == "EMN" )
if( ext == "emn" )
return FMT_EMN; // PCB assembly return FMT_EMN; // PCB assembly
if( ext == "stpz" || ext == "gz" )
return FMT_STEPZ;
OPEN_ISTREAM( ifile, aFileName ); OPEN_ISTREAM( ifile, aFileName );
if( ifile.fail() ) if( ifile.fail() )
@ -952,7 +965,51 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L
} }
break; break;
case FMT_STEPZ:
{
wxFileInputStream ifile( aFileName );
wxFileName outFile( aFileName );
outFile.SetPath( wxStandardPaths::Get().GetTempDir() );
outFile.SetExt( "STEP" );
wxFileOffset size = ifile.GetLength();
if( size == wxInvalidOffset )
{
ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n",
aFileName ) );
return false;
}
{
wxFileOutputStream ofile( outFile.GetFullPath() );
if( !ofile.IsOk() )
{
ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n",
outFile.GetFullPath() ) );
return false;
}
char *buffer = new char[size];
ifile.Read( buffer, size);
std::string expanded = gzip::decompress( buffer, size );
delete[] buffer;
ofile.Write( expanded.data(), expanded.size() );
ofile.Close();
}
return getModelLabel( outFile.GetFullPath().ToStdString(), aScale, aLabel );
break;
}
case FMT_WRL: case FMT_WRL:
case FMT_WRZ:
/* WRL files are preferred for internal rendering, /* WRL files are preferred for internal rendering,
* due to superior material properties, etc. * due to superior material properties, etc.
* However they are not suitable for MCAD export. * However they are not suitable for MCAD export.
@ -982,6 +1039,10 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L
alts.Add( "STEP" ); alts.Add( "STEP" );
alts.Add( "Stp" ); alts.Add( "Stp" );
alts.Add( "Step" ); alts.Add( "Step" );
alts.Add( "stpz" );
alts.Add( "stpZ" );
alts.Add( "STPZ" );
alts.Add( "step.gz" );
// IGES files // IGES files
alts.Add( "iges" ); alts.Add( "iges" );