diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index 85c4016b06..1efe8e05d4 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -247,36 +247,33 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName ) int layerId = GetActiveLayer(); // current layer used in GerbView GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); auto gerber_layer = images->GetGbrImage( layerId ); - auto drill_layer = dynamic_cast( gerber_layer ); - if( gerber_layer && !drill_layer ) - { - // The active layer contains old gerber data we have to clear + // OIf the active layer contains old gerber or nc drill data, remove it + if( gerber_layer ) Erase_Current_DrawLayer( false ); - } - if( drill_layer == nullptr ) - { - drill_layer = new EXCELLON_IMAGE( layerId ); - layerId = images->AddGbrImage( drill_layer, layerId ); - } - - if( layerId < 0 ) - { - DisplayError( this, _( "No room to load file" ) ); - return false; - } + EXCELLON_IMAGE* drill_layer = new EXCELLON_IMAGE( layerId ); // Read the Excellon drill file: bool success = drill_layer->LoadFile( aFullFileName ); if( !success ) { - msg.Printf( _( "File %s not found" ), GetChars( aFullFileName ) ); + delete drill_layer; + msg.Printf( _( "File %s not found" ), aFullFileName ); DisplayError( this, msg ); return false; } + layerId = images->AddGbrImage( drill_layer, layerId ); + + if( layerId < 0 ) + { + delete drill_layer; + DisplayError( this, _( "No room to load file" ) ); + return false; + } + // Display errors list if( drill_layer->GetMessages().size() > 0 ) { diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 752afd7004..4eeaf621c2 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -284,6 +284,24 @@ bool GERBVIEW_FRAME::loadListOfGerberAndDrillFiles( const wxString& aPath, for( unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ ) { + + filename = aFilenameList[ii]; + + if( !filename.IsAbsolute() ) + filename.SetPath( aPath ); + + // Check for non existing files, to avoid creating broken or useless data + // and report all in one error list: + if( !filename.FileExists() ) + { + wxString warning; + warning << "" << _( "File not found:" ) << "
" + << filename.GetFullPath() << "
"; + reporter.Report( warning, REPORTER::RPT_WARNING ); + success = false; + continue; + } + if( !progress && wxGetUTCTimeMillis() - startTime > progressShowDelay ) { progress = std::make_unique( this, @@ -296,11 +314,6 @@ bool GERBVIEW_FRAME::loadListOfGerberAndDrillFiles( const wxString& aPath, progress->KeepRefreshing(); } - filename = aFilenameList[ii]; - - if( !filename.IsAbsolute() ) - filename.SetPath( aPath ); - m_lastFileName = filename.GetFullPath(); SetActiveLayer( layer, false ); diff --git a/gerbview/gerber_file_image_list.cpp b/gerbview/gerber_file_image_list.cpp index b6135c1b02..6e81336477 100644 --- a/gerbview/gerber_file_image_list.cpp +++ b/gerbview/gerber_file_image_list.cpp @@ -117,7 +117,7 @@ void GERBER_FILE_IMAGE_LIST::DeleteImage( int aIdx ) GERBER_FILE_IMAGE* gbr_image = GetGbrImage( aIdx ); delete gbr_image; - m_GERBER_List[ aIdx ] = NULL; + m_GERBER_List[ aIdx ] = nullptr; } // Build a name for image aIdx which can be used in layers manager diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 983c873941..0dc0a2f027 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -249,8 +249,8 @@ GERBVIEW_FRAME::~GERBVIEW_FRAME() void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - GetGalCanvas()->GetView()->Clear(); GetGalCanvas()->StopDrawing(); + GetGalCanvas()->GetView()->Clear(); if( m_toolManager ) m_toolManager->DeactivateTool(); diff --git a/gerbview/readgerb.cpp b/gerbview/readgerb.cpp index d36d6acfd6..23265ab06b 100644 --- a/gerbview/readgerb.cpp +++ b/gerbview/readgerb.cpp @@ -51,18 +51,21 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName ) } gerber = new GERBER_FILE_IMAGE( layer ); - images->AddGbrImage( gerber, layer ); - /* Read the gerber file */ + // Read the gerber file. The image will be added only if it can be read + // to avoid broken data. bool success = gerber->LoadGerberFile( GERBER_FullFileName ); if( !success ) { - msg.Printf( _( "File \"%s\" not found" ), GetChars( GERBER_FullFileName ) ); + delete gerber; + msg.Printf( _( "File \"%s\" not found" ), GERBER_FullFileName ); DisplayError( this, msg, 10 ); return false; } + images->AddGbrImage( gerber, layer ); + // Display errors list if( gerber->GetMessages().size() > 0 ) {