diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 7cf962a50e..0aa8cc2338 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -193,7 +193,17 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName ) // Set the busy cursor wxBusyCursor wait; - return LoadListOfGerberAndDrillFiles( currentPath, filenamesList ); + bool isFirstFile = GetImagesList()->GetLoadedImageCount() == 0; + + bool success = LoadListOfGerberAndDrillFiles( currentPath, filenamesList ); + + // Auto zoom is only applied if there is only one file loaded + if ( isFirstFile ) + { + Zoom_Automatique( false ); + } + + return success; } diff --git a/gerbview/gerber_file_image_list.cpp b/gerbview/gerber_file_image_list.cpp index 062912e569..bd6b8030c3 100644 --- a/gerbview/gerber_file_image_list.cpp +++ b/gerbview/gerber_file_image_list.cpp @@ -70,6 +70,13 @@ GERBER_FILE_IMAGE* GERBER_FILE_IMAGE_LIST::GetGbrImage( int aIdx ) } +unsigned GERBER_FILE_IMAGE_LIST::GetLoadedImageCount() +{ + auto notNull = []( GERBER_FILE_IMAGE* image ){ return image != nullptr; }; + return std::count_if( m_GERBER_List.begin(), m_GERBER_List.end(), notNull ); +} + + int GERBER_FILE_IMAGE_LIST::AddGbrImage( GERBER_FILE_IMAGE* aGbrImage, int aIdx ) { int idx = aIdx; diff --git a/gerbview/gerber_file_image_list.h b/gerbview/gerber_file_image_list.h index 7428d93707..22b6dbd668 100644 --- a/gerbview/gerber_file_image_list.h +++ b/gerbview/gerber_file_image_list.h @@ -121,6 +121,13 @@ public: */ std::unordered_map SortImagesByZOrder(); + /** + * Get number of loaded images + * + * @return number of images loaded + */ + unsigned GetLoadedImageCount(); + private: // the list of loaded images (1 image = 1 gerber file) std::vector m_GERBER_List;