From 5f5620a1b975dbb7ffd9032a0e9c3e77eb722e75 Mon Sep 17 00:00:00 2001 From: charras Date: Wed, 31 Mar 2010 16:59:32 +0000 Subject: [PATCH] ++Pcbnew Pcbnew: Fixed an issue in GERBER file creation, under Vista and W7 only for non administrator users Plot files were 0 byte length. This was due to use of function tmpfile() in a GERBER function to create a temporary file that seems not working using mingw. Replaced by more usual files functions. --- CHANGELOG.txt | 8 ++++++++ common/common_plotDXF_functions.cpp | 10 +++++++--- common/common_plotGERBER_functions.cpp | 24 ++++++++++++++++++++---- common/common_plotHPGL_functions.cpp | 8 +++++--- common/common_plotPS_functions.cpp | 10 +++++++--- include/plot_common.h | 22 ++++++++++++---------- pcbnew/plotgerb.cpp | 18 ++++++++++++------ version.txt | 4 ++-- 8 files changed, 73 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9f4f91ff78..b35f1158f5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,14 @@ KiCad ChangeLog 2010 Please add newer entries at the top, list the date and your name with email address. +2010-mar-31, UPDATE Jean-Pierre Charras +================================================================================ +++Pcbnew + Fixed an issue in GERBER file creation, under Vista and W7 only for non administrator users + Plot files were 0 byte length. + This was due to use of function tmpfile() in a GERBER function + to create a temporary file that seems not working using mingw. + Replaced by more usual files functions. 2010-mar-29, UPDATE Jean-Pierre Charras ================================================================================ diff --git a/common/common_plotDXF_functions.cpp b/common/common_plotDXF_functions.cpp index ddb94d6ae0..b81ddade9d 100644 --- a/common/common_plotDXF_functions.cpp +++ b/common/common_plotDXF_functions.cpp @@ -27,7 +27,7 @@ void DXF_PLOTTER::set_viewport( wxPoint offset, } -void DXF_PLOTTER::start_plot( FILE* fout ) +bool DXF_PLOTTER::start_plot( FILE* fout ) { wxASSERT( !output_file ); output_file = fout; @@ -45,16 +45,20 @@ void DXF_PLOTTER::start_plot( FILE* fout ) /* End of layer table, begin entities */ fputs( "0\nENDTAB\n0\nENDSEC\n0\nSECTION\n2\nENTITIES\n", output_file ); + + return true; } -void DXF_PLOTTER::end_plot() +bool DXF_PLOTTER::end_plot() { wxASSERT( output_file ); /* DXF FOOTER */ fputs( "0\nENDSEC\n0\nEOF\n", output_file ); fclose( output_file ); - output_file = 0; + output_file = NULL; + + return true; } diff --git a/common/common_plotGERBER_functions.cpp b/common/common_plotGERBER_functions.cpp index 9a3094528a..311241cb0c 100644 --- a/common/common_plotGERBER_functions.cpp +++ b/common/common_plotGERBER_functions.cpp @@ -39,14 +39,22 @@ void GERBER_PLOTTER::set_viewport( wxPoint offset, * initialize global variable g_Plot_PlotOutputFile * @param aFile: an opened file to write to */ -void GERBER_PLOTTER::start_plot( FILE* aFile ) +bool GERBER_PLOTTER::start_plot( FILE* aFile ) { char Line[1024]; wxASSERT( !output_file ); final_file = aFile; - work_file = tmpfile(); + + // Create a temporary filename to store gerber file + // note tmpfile() does not work under Vista and W7 un user mode + m_workFilename = filename + wxT(".tmp"); + work_file = wxFopen( m_workFilename, wxT( "wt" )); output_file = work_file; + wxASSERT( output_file ); + if( output_file == NULL ) + return false; + DateAndTime( Line ); wxString Title = creator + wxT( " " ) + GetBuildVersion(); fprintf( output_file, "G04 (created by %s) date %s*\n", @@ -63,10 +71,12 @@ void GERBER_PLOTTER::start_plot( FILE* aFile ) fputs( "G04 APERTURE LIST*\n", output_file ); /* Select the default aperture */ set_current_line_width( -1 ); + + return true; } -void GERBER_PLOTTER::end_plot() +bool GERBER_PLOTTER::end_plot() { char line[1024]; wxString msg; @@ -75,7 +85,10 @@ void GERBER_PLOTTER::end_plot() /* Outfile is actually a temporary file! */ fputs( "M02*\n", output_file ); fflush( output_file ); - rewind( work_file ); // work_file == output_file !!! +// rewind( work_file ); // work_file == output_file !!! + fclose( work_file ); + work_file = wxFopen( m_workFilename, wxT( "rt" )); + wxASSERT( work_file ); output_file = final_file; @@ -92,7 +105,10 @@ void GERBER_PLOTTER::end_plot() fclose( work_file ); fclose( final_file ); + ::wxRemoveFile( m_workFilename ); output_file = 0; + + return true; } diff --git a/common/common_plotHPGL_functions.cpp b/common/common_plotHPGL_functions.cpp index e331d031cc..cd10b68fe2 100644 --- a/common/common_plotHPGL_functions.cpp +++ b/common/common_plotHPGL_functions.cpp @@ -28,20 +28,22 @@ void HPGL_PLOTTER::set_viewport( wxPoint offset, double aScale, int orient ) } -void HPGL_PLOTTER::start_plot( FILE* fout ) +bool HPGL_PLOTTER::start_plot( FILE* fout ) { wxASSERT( !output_file ); output_file = fout; fprintf( output_file, "IN;VS%d;PU;PA;SP%d;\n", pen_speed, pen_number ); + return true; } -void HPGL_PLOTTER::end_plot() +bool HPGL_PLOTTER::end_plot() { wxASSERT( output_file ); fputs( "PU;PA;SP0;\n", output_file ); fclose( output_file ); - output_file = 0; + output_file = NULL; + return true; } diff --git a/common/common_plotPS_functions.cpp b/common/common_plotPS_functions.cpp index 5383a89c0d..4dadd5a54c 100644 --- a/common/common_plotPS_functions.cpp +++ b/common/common_plotPS_functions.cpp @@ -249,7 +249,7 @@ void PS_PLOTTER::pen_to( wxPoint pos, char plume ) * BBox is the boundary box (position and size of the "client rectangle" * for drawings (page - margins) in mils (0.001 inch) */ -void PS_PLOTTER::start_plot( FILE* fout ) +bool PS_PLOTTER::start_plot( FILE* fout ) { wxASSERT( !output_file ); wxString msg; @@ -366,15 +366,19 @@ void PS_PLOTTER::start_plot( FILE* fout ) // Set default line width ( g_Plot_DefaultPenWidth is in user units ) fprintf( output_file, "%g setlinewidth\n", user_to_device_size( default_pen_width ) ); + + return true; } -void PS_PLOTTER::end_plot() +bool PS_PLOTTER::end_plot() { wxASSERT( output_file ); fputs( "showpage\ngrestore\n%%EOF\n", output_file ); fclose( output_file ); - output_file = 0; + output_file = NULL; + + return true; } diff --git a/include/plot_common.h b/include/plot_common.h index bab7a1019a..b5bbda8d85 100644 --- a/include/plot_common.h +++ b/include/plot_common.h @@ -47,8 +47,8 @@ public: PlotFormat GetPlotterType() { return m_PlotType; } - virtual void start_plot( FILE* fout ) = 0; - virtual void end_plot() = 0; + virtual bool start_plot( FILE* fout ) = 0; + virtual bool end_plot() = 0; virtual void set_negative( bool _negative ) { @@ -200,8 +200,8 @@ public: { } - virtual void start_plot( FILE* fout ); - virtual void end_plot(); + virtual bool start_plot( FILE* fout ); + virtual bool end_plot(); /* HPGL doesn't handle line thickness or color */ virtual void set_current_line_width( int width ) @@ -278,8 +278,8 @@ public: plot_scale_adjY = 1; } - virtual void start_plot( FILE* fout ); - virtual void end_plot(); + virtual bool start_plot( FILE* fout ); + virtual bool end_plot(); virtual void set_current_line_width( int width ); virtual void set_default_line_width( int width ); virtual void set_dash( bool dashed ); @@ -344,8 +344,8 @@ public: } - virtual void start_plot( FILE* fout ); - virtual void end_plot(); + virtual bool start_plot( FILE* fout ); + virtual bool end_plot(); virtual void set_current_line_width( int width ); virtual void set_default_line_width( int width ); @@ -375,6 +375,8 @@ protected: APERTURE::Aperture_Type type ); FILE* work_file, * final_file; + wxString m_workFilename; + void write_aperture_list(); std::vector apertures; @@ -388,8 +390,8 @@ public: { } - virtual void start_plot( FILE* fout ); - virtual void end_plot(); + virtual bool start_plot( FILE* fout ); + virtual bool end_plot(); /* For now we don't use 'thick' primitives, so no line width */ virtual void set_current_line_width( int width ) diff --git a/pcbnew/plotgerb.cpp b/pcbnew/plotgerb.cpp index ce2762aedd..7d490a16db 100644 --- a/pcbnew/plotgerb.cpp +++ b/pcbnew/plotgerb.cpp @@ -60,14 +60,20 @@ bool WinEDA_BasePcbFrame::Genere_GERBER( const wxString& FullFileName, int Layer plotter->set_creator( wxT( "PCBNEW-RS274X" ) ); plotter->set_filename( FullFileName ); - plotter->start_plot( output_file ); + if( plotter->start_plot( output_file ) ) + { + // Sheet refs on gerber CAN be useful... and they're always 1:1 + if( g_pcb_plot_options.Plot_Frame_Ref ) + PlotWorkSheet( plotter, GetScreen() ); + Plot_Layer( plotter, Layer, trace_mode ); - // Sheet refs on gerber CAN be useful... and they're always 1:1 - if( g_pcb_plot_options.Plot_Frame_Ref ) - PlotWorkSheet( plotter, GetScreen() ); - Plot_Layer( plotter, Layer, trace_mode ); + plotter->end_plot(); + } - plotter->end_plot(); + else // error in start_plot( ): failed opening a temporary file + { + wxMessageBox( _("Error when creating %s file: unable to create a temporary file")); + } delete plotter; SetLocaleTo_Default(); diff --git a/version.txt b/version.txt index c5406c38af..b457966e1a 100644 --- a/version.txt +++ b/version.txt @@ -1,4 +1,4 @@ release version: -2010 mar 30 (SVN 2479) +2010 apr 01 files (.zip,.tgz): -kicad-2010-03-30-final +kicad-2010-04-01-final