From 21a8dd6302b18489e3c5aca90053573c81a4618e Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 2 Aug 2021 16:53:15 -0400 Subject: [PATCH] Gerbview: Better file extension association when opening zips Fixes: https://gitlab.com/kicad/code/kicad/-/issues/7855 --- gerbview/files.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 5652dcfd6a..0c23bf8ed8 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -513,22 +513,6 @@ bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aR // The archive contains Gerber and/or Excellon drill files. Use the right loader. // However it can contain a few other files (reports, pdf files...), // which will be skipped. - // Gerber files ext is usually "gbr", but can be also another value, starting by "g" - // old gerber files ext from kicad is .pho - // drill files do not have a well defined ext - // It is .drl in kicad, but .txt in Altium for instance - // Allows only .drl for drill files. - if( curr_ext[0] != 'g' && curr_ext != "pho" && curr_ext != "drl" ) - { - if( aReporter ) - { - msg.Printf( _( "Skipped file '%s' (unknown type).\n" ), entry->GetName() ); - aReporter->Report( msg, RPT_SEVERITY_WARNING ); - } - - continue; - } - if( curr_ext == GerberJobFileExtension.c_str() ) { //We cannot read a gerber job file as a gerber plot file: skip it @@ -541,6 +525,21 @@ bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aR continue; } + wxString matchedExt; + enum GERBER_ORDER_ENUM order; + GERBER_FILE_IMAGE_LIST::GetGerberLayerFromFilename( fname, order, matchedExt ); + + if( order == GERBER_ORDER_ENUM::GERBER_LAYER_UNKNOWN ) + { + if( aReporter ) + { + msg.Printf( _( "Skipped file '%s' (unknown type).\n" ), entry->GetName() ); + aReporter->Report( msg, RPT_SEVERITY_WARNING ); + } + + continue; + } + int layer = GetActiveLayer(); if( layer == NO_AVAILABLE_LAYERS ) @@ -584,7 +583,7 @@ bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aR bool read_ok = true; - if( curr_ext[0] == 'g' || curr_ext == "pho" ) + if( order != GERBER_ORDER_ENUM::GERBER_DRILL ) { // Read gerber files: each file is loaded on a new GerbView layer read_ok = Read_GERBER_File( unzipped_tempfile ); @@ -593,7 +592,7 @@ bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aR GetCanvas()->GetView()->SetLayerHasNegatives( GERBER_DRAW_LAYER( layer ), GetGbrImage( layer )->HasNegativeItems() ); } - else // if( curr_ext == "drl" ) + else // Everything else is a drill file { read_ok = Read_EXCELLON_File( unzipped_tempfile ); }