From c83f1ea1cddcd8336e1526a850d3cadae83a416f Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Wed, 4 Aug 2021 16:22:07 -0400 Subject: [PATCH] Gerbview: support more filetypes from the command line, e.g. zip Also parse other extensions, and use new heuristics to guess if we don't know the extension. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/5680 --- gerbview/gerbview_frame.cpp | 51 +++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index fe4c8a05d4..13fb8cbe8e 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -253,24 +254,46 @@ bool GERBVIEW_FRAME::OpenProjectFiles( const std::vector& aFileSet, in const unsigned limit = std::min( unsigned( aFileSet.size() ), unsigned( GERBER_DRAWLAYERS_COUNT ) ); - int layer = 0; - - for( unsigned i = 0; i < limit; ++i, ++layer ) + for( unsigned i = 0; i < limit; ++i ) { - SetActiveLayer( layer ); + wxString ext = wxFileName( aFileSet[i] ).GetExt().Lower(); - // Try to guess the type of file by its ext - // if it is .drl (KiCad files), .nc or .xnc it is a drill file - wxFileName fn( aFileSet[i] ); - wxString ext = fn.GetExt(); - - if( ext == DrillFileExtension || // our Excellon format - ext == "nc" || ext == "xnc" ) // alternate ext for Excellon format - LoadExcellonFiles( aFileSet[i] ); - else if( ext == GerberJobFileExtension ) + if( ext == "zip" ) + LoadZipArchiveFile( aFileSet[i] ); + else if( ext == "gbrprj" ) LoadGerberJobFile( aFileSet[i] ); else - LoadGerberFiles( aFileSet[i] ); + { + GERBER_ORDER_ENUM fnameLayer; + wxString fnameExtensionMatched; + + GERBER_FILE_IMAGE_LIST::GetGerberLayerFromFilename( aFileSet[i], fnameLayer, + fnameExtensionMatched ); + + if( fnameLayer == GERBER_ORDER_ENUM::GERBER_LAYER_UNKNOWN ) + { + if( EXCELLON_IMAGE::TestFileIsExcellon( aFileSet[i] ) ) + { + fnameLayer = GERBER_ORDER_ENUM::GERBER_DRILL; + } + else if( GERBER_FILE_IMAGE::TestFileIsRS274( aFileSet[i] ) ) + { + // If we have no way to know what layer it is, just guess + fnameLayer = GERBER_ORDER_ENUM::GERBER_TOP_COPPER; + } + } + + switch( fnameLayer ) + { + case GERBER_ORDER_ENUM::GERBER_DRILL: + LoadExcellonFiles( aFileSet[i] ); + break; + case GERBER_ORDER_ENUM::GERBER_LAYER_UNKNOWN: + break; + default: + LoadGerberFiles( aFileSet[i] ); + } + } } }