Actionize Gerber file commands.

Fixes https://gitlab.com/kicad/code/kicad/issues/2408
This commit is contained in:
Jeff Young 2020-05-03 23:02:07 +01:00
parent b8e0b9759a
commit ed3e366715
9 changed files with 100 additions and 78 deletions

View File

@ -33,7 +33,6 @@
#include <dialog_helpers.h>
#include <DCodeSelectionbox.h>
#include <gerbview_layer_widget.h>
#include <gerbview_draw_panel_gal.h>
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <tool/selection.h>
@ -48,16 +47,11 @@ BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
EVT_CLOSE( GERBVIEW_FRAME::OnCloseWindow )
EVT_SIZE( GERBVIEW_FRAME::OnSize )
EVT_TOOL( wxID_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_ERASE_ALL, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_RELOAD_ALL, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_LOAD_DRILL_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_LOAD_ZIP_ARCHIVE_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_LOAD_JOB_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
// Menu Files:
EVT_MENU( wxID_FILE, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_GERBVIEW_EXPORT_TO_PCBNEW, GERBVIEW_FRAME::ExportDataInPcbnewFormat )

View File

@ -23,7 +23,6 @@
*/
#include <fctsys.h>
#include <wx/fs_zip.h>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
#include <common.h>
@ -39,9 +38,8 @@
#include <widgets/progress_reporter.h>
// HTML Messages used more than one time:
#define MSG_NO_MORE_LAYER\
_( "<b>No more available free graphic layer</b> in Gerbview to load files" )
#define MSG_NOT_LOADED _( "\n<b>Not loaded:</b> <i>%s</i>" )
#define MSG_NO_MORE_LAYER _( "<b>No more available layers in Gerbview to load files" )
#define MSG_NOT_LOADED _( "\n<b>Not loaded:</b> <i>%s</i>" )
void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )
@ -119,14 +117,8 @@ void GERBVIEW_FRAME::OnClearJobFileHistory( wxCommandEvent& aEvent )
/* File commands. */
void GERBVIEW_FRAME::Files_io( wxCommandEvent& event )
{
int id = event.GetId();
switch( id )
switch( event.GetId() )
{
case wxID_FILE:
LoadGerberFiles( wxEmptyString );
break;
case ID_GERBVIEW_ERASE_ALL:
Clear_DrawLayers( false );
Zoom_Automatique( false );
@ -170,21 +162,6 @@ void GERBVIEW_FRAME::Files_io( wxCommandEvent& event )
}
break;
case ID_GERBVIEW_LOAD_DRILL_FILE:
LoadExcellonFiles( wxEmptyString );
GetCanvas()->Refresh();
break;
case ID_GERBVIEW_LOAD_ZIP_ARCHIVE_FILE:
LoadZipArchiveFile( wxEmptyString );
GetCanvas()->Refresh();
break;
case ID_GERBVIEW_LOAD_JOB_FILE:
LoadGerberJobFile( wxEmptyString );
GetCanvas()->Refresh();
break;
default:
wxFAIL_MSG( "File_io: unexpected command id" );
break;
@ -204,13 +181,13 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
{
/* Standard gerber filetypes
* (See http://en.wikipedia.org/wiki/Gerber_File)
* the .gbr (.pho in legacy files) extension is the default used in Pcbnew
* However there are a lot of other extensions used for gerber files
* Because the first letter is usually g, we accept g* as extension
* (Mainly internal copper layers do not have specific extension,
* and filenames are like *.g1, *.g2 *.gb1 ...).
* Now (2014) Ucamco (the company which manages the Gerber format) encourages
* use of .gbr only and the Gerber X2 file format.
* The .gbr (.pho in legacy files) extension is the default used in Pcbnew; however
* there are a lot of other extensions used for gerber files. Because the first letter
* is usually g, we accept g* as extension.
* (Mainly internal copper layers do not have specific extension, and filenames are like
* *.g1, *.g2 *.gb1 ...)
* Now (2014) Ucamco (the company which manages the Gerber format) encourages use of .gbr
* only and the Gerber X2 file format.
*/
filetypes = _( "Gerber files (.g* .lgr .pho)" );
filetypes << wxT("|");
@ -247,9 +224,7 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
currentPath.RemoveLast();
}
wxFileDialog dlg( this, _( "Open Gerber File(s)" ),
currentPath,
filename.GetFullName(),
wxFileDialog dlg( this, _( "Open Gerber File(s)" ), currentPath, filename.GetFullName(),
filetypes,
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
dlg.SetFilterIndex( lastGerberFileWildcard );
@ -669,12 +644,8 @@ bool GERBVIEW_FRAME::LoadZipArchiveFile( const wxString& aFullFileName )
else
currentPath = m_mruPath;
wxFileDialog dlg( this,
_( "Open Zip File" ),
currentPath,
filename.GetFullName(),
ZipFileWildcard(),
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
wxFileDialog dlg( this, _( "Open Zip File" ), currentPath, filename.GetFullName(),
ZipFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
if( dlg.ShowModal() == wxID_CANCEL )
return false;

View File

@ -29,8 +29,6 @@
#include <pgm_base.h>
/**
* Command IDs for the printed circuit board editor.
*
* Please add IDs that are unique to the gerber file viewer (GerbView) here and not in
* the global id.h file. This will prevent the entire project from being rebuilt when
* adding new commands to the GerbView.
@ -41,9 +39,6 @@ enum gerbview_ids
ID_MAIN_MENUBAR = ID_END_LIST,
ID_GERBVIEW_SHOW_LIST_DCODES,
ID_GERBVIEW_LOAD_DRILL_FILE,
ID_GERBVIEW_LOAD_JOB_FILE,
ID_GERBVIEW_LOAD_ZIP_ARCHIVE_FILE,
ID_GERBVIEW_ERASE_ALL,
ID_GERBVIEW_RELOAD_ALL,
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,

View File

@ -28,7 +28,6 @@
#include <kiface_i.h>
#include <menus_helpers.h>
#include <pgm_base.h>
#include <advanced_config.h>
#include <tool/actions.h>
#include <tool/conditional_menu.h>
#include <tool/tool_manager.h>
@ -108,25 +107,17 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
m_zipFileHistory.AddFilesToMenu();
}
fileMenu->AddItem( wxID_FILE, _( "Open &Gerber File(s)..." ),
_( "Open Gerber file(s) on the current layer. Previous data will be deleted" ),
load_gerber_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentGbrMenu, FILE_HISTORY::FileHistoryNotEmpty( recentGbrFiles ) );
fileMenu->AddItem( GERBVIEW_ACTIONS::openGerber, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentGbrMenu, FILE_HISTORY::FileHistoryNotEmpty( recentGbrFiles ) );
fileMenu->AddItem( ID_GERBVIEW_LOAD_DRILL_FILE, _( "Open &Excellon Drill File(s)..." ),
_( "Open Excellon drill file(s) on the current layer. Previous data will be deleted" ),
gerbview_drill_file_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentDrlMenu, FILE_HISTORY::FileHistoryNotEmpty( m_drillFileHistory ) );
fileMenu->AddItem( GERBVIEW_ACTIONS::openDrillFile, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentDrlMenu, FILE_HISTORY::FileHistoryNotEmpty( m_drillFileHistory ) );
fileMenu->AddItem( ID_GERBVIEW_LOAD_JOB_FILE, _( "Open Gerber &Job File..." ),
_( "Open a Gerber job file and its associated gerber files" ),
gerber_job_file_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentJobMenu, FILE_HISTORY::FileHistoryNotEmpty( m_jobFileHistory ) );
fileMenu->AddItem( GERBVIEW_ACTIONS::openJobFile, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentJobMenu, FILE_HISTORY::FileHistoryNotEmpty( m_jobFileHistory ) );
fileMenu->AddItem( ID_GERBVIEW_LOAD_ZIP_ARCHIVE_FILE, _( "Open &Zip Archive File..." ),
_( "Open a zipped archive (Gerber and Drill) file" ),
zip_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentZipMenu, FILE_HISTORY::FileHistoryNotEmpty( m_zipFileHistory ) );
fileMenu->AddItem( GERBVIEW_ACTIONS::openZipFile, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentZipMenu, FILE_HISTORY::FileHistoryNotEmpty( m_zipFileHistory ) );
fileMenu->AddSeparator();
fileMenu->AddItem( ID_GERBVIEW_ERASE_ALL, _( "Clear &All Layers" ),

View File

@ -31,14 +31,13 @@
#include <gbr_layer_box_selector.h>
#include <DCodeSelectionbox.h>
#include <dialog_helpers.h>
#include <bitmaps.h>
#include <kicad_string.h>
#include <wx/wupdlock.h>
#include <tool/actions.h>
#include <tool/action_toolbar.h>
#include <tools/gerbview_actions.h>
void GERBVIEW_FRAME::ReCreateHToolbar( void )
void GERBVIEW_FRAME::ReCreateHToolbar()
{
wxString msg;
@ -57,12 +56,8 @@ void GERBVIEW_FRAME::ReCreateHToolbar( void )
KiScaledBitmap( reload2_xpm, this ),
_( "Reload all layers" ) );
m_mainToolBar->AddTool( wxID_FILE, wxEmptyString, KiScaledBitmap( load_gerber_xpm, this ),
_( "Open Gerber file(s) on the current layer. Previous data will be deleted" ) );
m_mainToolBar->AddTool( ID_GERBVIEW_LOAD_DRILL_FILE, wxEmptyString,
KiScaledBitmap( gerbview_drill_file_xpm, this ),
_( "Open Excellon drill file(s) on the current layer. Previous data will be deleted" ) );
m_mainToolBar->Add( GERBVIEW_ACTIONS::openGerber );
m_mainToolBar->Add( GERBVIEW_ACTIONS::openDrillFile );
KiScaledSeparator( m_mainToolBar, this );
m_mainToolBar->AddTool( wxID_PRINT, wxEmptyString, KiScaledBitmap( print_button_xpm, this ),

View File

@ -55,6 +55,30 @@ OPT<TOOL_EVENT> GERBVIEW_ACTIONS::TranslateLegacyId( int aId )
// GERBVIEW_CONTROL
//
TOOL_ACTION GERBVIEW_ACTIONS::openGerber( "gerbview.Control.openGerber",
AS_GLOBAL, 0, "",
_( "Open Gerber File(s)..." ),
_( "Open Gerber file(s) on the current layer. Previous data will be deleted" ),
load_gerber_xpm );
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" ),
gerbview_drill_file_xpm );
TOOL_ACTION GERBVIEW_ACTIONS::openJobFile( "gerbview.Control.openJobFile",
AS_GLOBAL, 0, "",
_( "Open Gerber Job File..." ),
_( "Open a Gerber job file and its associated gerber files" ),
gerber_job_file_xpm );
TOOL_ACTION GERBVIEW_ACTIONS::openZipFile( "gerbview.Control.openZipFile",
AS_GLOBAL, 0, "",
_( "Open Zip Archive File..." ),
_( "Open a zipped archive (Gerber and Drill) file" ),
zip_xpm );
TOOL_ACTION GERBVIEW_ACTIONS::layerChanged( "gerbview.Control.layerChanged",
AS_GLOBAL, 0, "", "", "",
nullptr, AF_NOTIFY );

View File

@ -70,6 +70,12 @@ public:
static TOOL_ACTION layerChanged; // notification
// Files
static TOOL_ACTION openGerber;
static TOOL_ACTION openDrillFile;
static TOOL_ACTION openJobFile;
static TOOL_ACTION openZipFile;
// Highlighting
static TOOL_ACTION highlightClear;
static TOOL_ACTION highlightNet;

View File

@ -41,6 +41,42 @@ void GERBVIEW_CONTROL::Reset( RESET_REASON aReason )
}
int GERBVIEW_CONTROL::OpenGerber( const TOOL_EVENT& aEvent )
{
m_frame->LoadGerberFiles( wxEmptyString );
// loadListOfGerberAndDrillFiles() refreshes the canvas
return 0;
}
int GERBVIEW_CONTROL::OpenDrillFile( const TOOL_EVENT& aEvent )
{
m_frame->LoadExcellonFiles( wxEmptyString );
m_frame->GetCanvas()->Refresh();
return 0;
}
int GERBVIEW_CONTROL::OpenJobFile( const TOOL_EVENT& aEvent )
{
m_frame->LoadGerberJobFile( wxEmptyString );
m_frame->GetCanvas()->Refresh();
return 0;
}
int GERBVIEW_CONTROL::OpenZipFile( const TOOL_EVENT& aEvent )
{
m_frame->LoadZipArchiveFile( wxEmptyString );
m_frame->GetCanvas()->Refresh();
return 0;
}
int GERBVIEW_CONTROL::HighlightControl( const TOOL_EVENT& aEvent )
{
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
@ -187,6 +223,10 @@ int GERBVIEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
void GERBVIEW_CONTROL::setTransitions()
{
Go( &GERBVIEW_CONTROL::OpenGerber, GERBVIEW_ACTIONS::openGerber.MakeEvent() );
Go( &GERBVIEW_CONTROL::OpenDrillFile, GERBVIEW_ACTIONS::openDrillFile.MakeEvent() );
Go( &GERBVIEW_CONTROL::OpenJobFile, GERBVIEW_ACTIONS::openJobFile.MakeEvent() );
Go( &GERBVIEW_CONTROL::OpenZipFile, GERBVIEW_ACTIONS::openZipFile.MakeEvent() );
Go( &GERBVIEW_CONTROL::Print, ACTIONS::print.MakeEvent() );
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightClear.MakeEvent() );

View File

@ -53,6 +53,12 @@ public:
int LayerAlphaInc( const TOOL_EVENT& aEvent );
int LayerAlphaDec( const TOOL_EVENT& aEvent );
// Files
int OpenGerber( const TOOL_EVENT& aEvent );
int OpenDrillFile( const TOOL_EVENT& aEvent );
int OpenJobFile( const TOOL_EVENT& aEvent );
int OpenZipFile( const TOOL_EVENT& aEvent );
// Highlight control
int HighlightControl( const TOOL_EVENT& aEvent );