From 30c7821ba2b3c76cabd0b166bf07097be1d9136a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 23 Nov 2014 12:41:57 +0100 Subject: [PATCH] Grebview: add info in layer manager for Excellon drill filles, similar to X2 file function info in X2 gerber files. --- common/hotkeys_basic.cpp | 3 ++ gerbview/class_GERBER.cpp | 2 +- gerbview/class_X2_gerber_attributes.cpp | 2 +- gerbview/class_X2_gerber_attributes.h | 2 +- gerbview/class_gerbview_layer_widget.cpp | 2 +- gerbview/excellon_read_drill_file.cpp | 38 +++++++++++++++++------- gerbview/readgerb.cpp | 4 +-- 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index e51bcd8b74..e03a24acf6 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -548,6 +548,9 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename, { wxFile cfgfile( aFilename ); + if( !cfgfile.IsOpened() ) // There is a problem to open file + return 0; + // get length cfgfile.SeekEnd(); wxFileOffset size = cfgfile.Tell(); diff --git a/gerbview/class_GERBER.cpp b/gerbview/class_GERBER.cpp index 1c79c6f684..e36065ba38 100644 --- a/gerbview/class_GERBER.cpp +++ b/gerbview/class_GERBER.cpp @@ -455,7 +455,7 @@ const wxString GERBER_IMAGE_LIST::GetDisplayName( int aIdx ) if( aIdx >= 0 && aIdx < (int)m_GERBER_List.size() ) gerber = m_GERBER_List[aIdx]; - if( gerber && gerber->m_InUse) + if( IsUsed(aIdx ) ) { if( gerber->m_FileFunction ) name.Printf( _( "Layer %d (%s, %s)" ), aIdx + 1, diff --git a/gerbview/class_X2_gerber_attributes.cpp b/gerbview/class_X2_gerber_attributes.cpp index beca5cdf23..4b5801a23a 100644 --- a/gerbview/class_X2_gerber_attributes.cpp +++ b/gerbview/class_X2_gerber_attributes.cpp @@ -95,7 +95,7 @@ void X2_ATTRIBUTE::DbgListPrms() * buff = the buffer containing current Gerber data (GERBER_BUFZ size) * text = a pointer to the first char to read in Gerber data */ -bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char*& aText ) +bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText ) { bool ok = true; wxString data; diff --git a/gerbview/class_X2_gerber_attributes.h b/gerbview/class_X2_gerber_attributes.h index 7b3250f971..d51ddbbf53 100644 --- a/gerbview/class_X2_gerber_attributes.h +++ b/gerbview/class_X2_gerber_attributes.h @@ -97,7 +97,7 @@ public: * or the end of line if the line does not contain '%' or aBuffer == NULL (X1 mode) * @return true if no error. */ - bool ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char*& aText ); + bool ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText ); /** * Debug function: pring using wxLogMessage le list of parameters diff --git a/gerbview/class_gerbview_layer_widget.cpp b/gerbview/class_gerbview_layer_widget.cpp index 94a2b1fb7a..0e543393dd 100644 --- a/gerbview/class_gerbview_layer_widget.cpp +++ b/gerbview/class_gerbview_layer_widget.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2010 Jean-Pierre Charras, jean-pierre.charras@gpisa-lab.inpg.fr + * Copyright (C) 2004-2010 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors. * diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index 2114eca452..fd5241947a 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -8,8 +8,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2011 Jean-Pierre Charras - * Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2014 Jean-Pierre Charras + * Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -75,6 +75,7 @@ #include #include #include +#include #include @@ -93,18 +94,24 @@ extern double ReadDouble( char*& text, bool aSkipSeparator = true ); extern void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem, APERTURE_T aAperture, int Dcode_index, - int aLayer, + int aLayer, const wxPoint& aPos, wxSize aSize, bool aLayerNegative ); void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, - int aLayer, + int aLayer, const wxPoint& aStart, const wxPoint& aEnd, wxSize aPenSize, bool aLayerNegative ); +// Getber X2 files have a file attribute which specify the type of image +// (copper, solder paste ... and sides tpo, bottom or inner copper layers) +// Excellon drill files do not have attributes, so, just to identify the image +// In gerbview, we add this attribute, like a Gerber drill file +static const char file_attribute[] = ".FileFunction,Other,Drill*"; + static EXCELLON_CMD excellonHeaderCmdList[] = { { "M0", DRILL_M_END, -1 }, // End of Program - No Rewind @@ -168,16 +175,16 @@ static EXCELLON_CMD excellon_G_CmdList[] = bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName ) { wxString msg; - int layer = getActiveLayer(); // current layer used in GerbView - EXCELLON_IMAGE* drill_Layer = (EXCELLON_IMAGE*) g_GERBER_List.GetGbrImage( layer ); + int layerId = getActiveLayer(); // current layer used in GerbView + EXCELLON_IMAGE* drill_Layer = (EXCELLON_IMAGE*) g_GERBER_List.GetGbrImage( layerId ); if( drill_Layer == NULL ) { - drill_Layer = new EXCELLON_IMAGE( this, layer ); - layer = g_GERBER_List.AddGbrImage( drill_Layer, layer ); + drill_Layer = new EXCELLON_IMAGE( this, layerId ); + layerId = g_GERBER_List.AddGbrImage( drill_Layer, layerId ); } - if( layer < 0 ) + if( layerId < 0 ) { DisplayError( this, _( "No room to load file" ) ); return false; @@ -220,7 +227,7 @@ bool EXCELLON_IMAGE::Read_EXCELLON_File( FILE * aFile, m_FileName = aFullFileName; m_Current_File = aFile; - SetLocaleTo_C_standard(); + LOCALE_IO toggleIo; // FILE_LINE_READER will close the file. if( m_Current_File == NULL ) @@ -289,7 +296,16 @@ bool EXCELLON_IMAGE::Read_EXCELLON_File( FILE * aFile, } // End switch } } - SetLocaleTo_Default(); + + // Add our file attribute, to identify the drill file + X2_ATTRIBUTE dummy; + char* text = (char*)file_attribute; + dummy.ParseAttribCmd( m_Current_File, NULL, 0, text ); + delete m_FileFunction; + m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy ); + + m_InUse = true; + return true; } diff --git a/gerbview/readgerb.cpp b/gerbview/readgerb.cpp index 6d49b34ef5..3a6f968e92 100644 --- a/gerbview/readgerb.cpp +++ b/gerbview/readgerb.cpp @@ -77,7 +77,7 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName, if( path != wxEmptyString ) wxSetWorkingDirectory( path ); - SetLocaleTo_C_standard(); + LOCALE_IO toggleIo; while( true ) { @@ -171,8 +171,8 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName, } } } + fclose( gerber->m_Current_File ); - SetLocaleTo_Default(); gerber->m_InUse = true;