Gerbview: Add menu item to open files with autodetection

Needs an icon at some point
This commit is contained in:
Mike Williams 2021-08-16 14:42:46 -04:00
parent 8692014691
commit 6ddd5ec37f
8 changed files with 32 additions and 16 deletions

View File

@ -164,9 +164,10 @@ bool GERBVIEW_FRAME::LoadFileOrShowDialog( const wxString& aFileName,
std::vector<int> fileTypesVec( filenamesList.Count(), filetype );
bool success = LoadListOfGerberAndDrillFiles( currentPath, filenamesList, &fileTypesVec );
// Auto zoom is only applied if there is only one file loaded
// Auto zoom / sort is only applied when no other files have been loaded
if( isFirstFile )
{
SortLayersByFileExtension();
Zoom_Automatique( false );
}
@ -174,6 +175,14 @@ bool GERBVIEW_FRAME::LoadFileOrShowDialog( const wxString& aFileName,
}
bool GERBVIEW_FRAME::LoadAutodetectedFiles( const wxString& aFileName )
{
// 2 = autodetect files
return LoadFileOrShowDialog( aFileName, AllFilesWildcard(), _( "Open Autodetected File(s)" ),
2 );
}
bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFileName )
{
wxString filetypes;

View File

@ -270,25 +270,13 @@ bool GERBVIEW_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
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:
LoadAutodetectedFiles( aFileSet[i] );
break;
default:
LoadGerberFiles( aFileSet[i] );

View File

@ -72,6 +72,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
recentGbrFiles.AddFilesToMenu();
}
fileMenu->Add( GERBVIEW_ACTIONS::openAutodetected );
fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu );
RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) );

View File

@ -60,6 +60,7 @@ void GERBVIEW_FRAME::ReCreateHToolbar()
// Set up toolbar
m_mainToolBar->Add( GERBVIEW_ACTIONS::clearAllLayers );
m_mainToolBar->Add( GERBVIEW_ACTIONS::reloadAllLayers );
m_mainToolBar->Add( GERBVIEW_ACTIONS::openAutodetected );
m_mainToolBar->Add( GERBVIEW_ACTIONS::openGerber );
m_mainToolBar->Add( GERBVIEW_ACTIONS::openDrillFile );

View File

@ -34,16 +34,22 @@
// GERBVIEW_CONTROL
//
TOOL_ACTION GERBVIEW_ACTIONS::openAutodetected( "gerbview.Control.openAutodetected",
AS_GLOBAL, 0, "",
_( "Open Autodetected File(s)..." ),
_( "Open Autodetected file(s) on a new layer." ),
BITMAPS::load_gerber );
TOOL_ACTION GERBVIEW_ACTIONS::openGerber( "gerbview.Control.openGerber",
AS_GLOBAL, 0, "",
_( "Open Gerber Plot File(s)..." ),
_( "Open Gerber plot file(s) on the current layer. Previous data will be deleted" ),
_( "Open Gerber plot file(s) on a new layer." ),
BITMAPS::load_gerber );
TOOL_ACTION GERBVIEW_ACTIONS::openDrillFile( "gerbview.Control.openDrillFile",
AS_GLOBAL, 0, "",
_( "Open Excellon Drill File(s)..." ),
_( "Open Excellon drill file(s) on the current layer. Previous data will be deleted" ),
_( "Open Excellon drill file(s) on a new layer." ),
BITMAPS::load_drill );
TOOL_ACTION GERBVIEW_ACTIONS::openJobFile( "gerbview.Control.openJobFile",

View File

@ -76,6 +76,7 @@ public:
static TOOL_ACTION layerChanged; // notification
// Files
static TOOL_ACTION openAutodetected;
static TOOL_ACTION openGerber;
static TOOL_ACTION openDrillFile;
static TOOL_ACTION openJobFile;

View File

@ -51,6 +51,14 @@ void GERBVIEW_CONTROL::Reset( RESET_REASON aReason )
}
int GERBVIEW_CONTROL::OpenAutodetected( const TOOL_EVENT& aEvent )
{
m_frame->LoadAutodetectedFiles( wxEmptyString );
return 0;
}
int GERBVIEW_CONTROL::OpenGerber( const TOOL_EVENT& aEvent )
{
m_frame->LoadGerberFiles( wxEmptyString );
@ -423,6 +431,7 @@ int GERBVIEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
void GERBVIEW_CONTROL::setTransitions()
{
Go( &GERBVIEW_CONTROL::OpenAutodetected, GERBVIEW_ACTIONS::openAutodetected.MakeEvent() );
Go( &GERBVIEW_CONTROL::OpenGerber, GERBVIEW_ACTIONS::openGerber.MakeEvent() );
Go( &GERBVIEW_CONTROL::OpenDrillFile, GERBVIEW_ACTIONS::openDrillFile.MakeEvent() );
Go( &GERBVIEW_CONTROL::OpenJobFile, GERBVIEW_ACTIONS::openJobFile.MakeEvent() );

View File

@ -50,6 +50,7 @@ public:
int ReloadAllLayers( const TOOL_EVENT& aEvent );
// Files
int OpenAutodetected( const TOOL_EVENT& aEvent );
int OpenGerber( const TOOL_EVENT& aEvent );
int OpenDrillFile( const TOOL_EVENT& aEvent );
int OpenJobFile( const TOOL_EVENT& aEvent );