diff --git a/common/jobs/job_export_pcb_gencad.cpp b/common/jobs/job_export_pcb_gencad.cpp index 41e09f9946..9d29be3eb4 100644 --- a/common/jobs/job_export_pcb_gencad.cpp +++ b/common/jobs/job_export_pcb_gencad.cpp @@ -19,7 +19,8 @@ */ #include <jobs/job_export_pcb_gencad.h> -#include <wx/translation.h> +#include <jobs/job_registry.h> +#include <i18n_utility.h> JOB_EXPORT_PCB_GENCAD::JOB_EXPORT_PCB_GENCAD() : @@ -30,10 +31,30 @@ JOB_EXPORT_PCB_GENCAD::JOB_EXPORT_PCB_GENCAD() : m_useDrillOrigin( false ), m_useUniquePins( false ) { + m_params.emplace_back( + new JOB_PARAM<bool>( "flip_bottom_pads", &m_flipBottomPads, m_flipBottomPads ) ); + m_params.emplace_back( new JOB_PARAM<bool>( "use_individual_shapes", &m_useIndividualShapes, + m_useIndividualShapes ) ); + m_params.emplace_back( new JOB_PARAM<bool>( "store_origin_coords", &m_storeOriginCoords, + m_storeOriginCoords ) ); + m_params.emplace_back( + new JOB_PARAM<bool>( "use_drill_origin", &m_useDrillOrigin, m_useDrillOrigin ) ); + m_params.emplace_back( + new JOB_PARAM<bool>( "use_unique_pins", &m_useUniquePins, m_useUniquePins ) ); +} + + +wxString JOB_EXPORT_PCB_GENCAD::GetDefaultDescription() const +{ + return _( "Export GenCAD File" ); } wxString JOB_EXPORT_PCB_GENCAD::GetSettingsDialogTitle() const { return _( "Export GenCAD Job Settings" ); -} \ No newline at end of file +} + + +REGISTER_JOB( pcb_export_gencad, _HKI( "PCB: Export GenCAD" ), KIWAY::FACE_PCB, + JOB_EXPORT_PCB_GENCAD ); \ No newline at end of file diff --git a/common/jobs/job_export_pcb_gencad.h b/common/jobs/job_export_pcb_gencad.h index cb2b2702b6..6d98d7ba6c 100644 --- a/common/jobs/job_export_pcb_gencad.h +++ b/common/jobs/job_export_pcb_gencad.h @@ -31,6 +31,7 @@ class KICOMMON_API JOB_EXPORT_PCB_GENCAD : public JOB { public: JOB_EXPORT_PCB_GENCAD(); + wxString GetDefaultDescription() const override; wxString GetSettingsDialogTitle() const override; wxString m_filename; diff --git a/pcbnew/dialogs/dialog_gencad_export_options.cpp b/pcbnew/dialogs/dialog_gencad_export_options.cpp index 11dd20ea8b..aecec00c56 100644 --- a/pcbnew/dialogs/dialog_gencad_export_options.cpp +++ b/pcbnew/dialogs/dialog_gencad_export_options.cpp @@ -26,36 +26,56 @@ #include "dialog_gencad_export_options.h" +#include <jobs/job_export_pcb_gencad.h> + #include <pcb_edit_frame.h> #include <kidialog.h> #include <wildcards_and_files_ext.h> #include <wx/checkbox.h> #include <wx/filepicker.h> #include <wx/sizer.h> +#include <wx/stattext.h> +#include <wx/textctrl.h> +#include "widgets/std_bitmap_button.h" +#include <board.h> + DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent, - const wxString& aPath ) - : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition, - wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) + const wxString& aPath ) : + DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition, + wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ), + m_frame( aParent ), + m_job( nullptr ) { - wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* m_mainSizer = new wxBoxSizer( wxVERTICAL ); + + m_fileSizer = new wxBoxSizer( wxHORIZONTAL ); + + m_textFile = new wxStaticText( this, wxID_ANY, _( "Output File:" ), wxDefaultPosition, wxDefaultSize, 0 ); + m_textFile->Wrap( -1 ); + m_fileSizer->Add( m_textFile, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5 ); + + m_outputFileName = + new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_outputFileName->SetToolTip( _( "Enter a filename if you do not want to use default file names" ) ); + m_outputFileName->SetMinSize( wxSize( 350, -1 ) ); + m_fileSizer->Add( m_outputFileName, 1, wxALL | wxEXPAND, 5 ); + + + m_browseButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, + wxSize( -1, -1 ), wxBU_AUTODRAW | 0 ); + m_fileSizer->Add( m_browseButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 ); + + m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 ); - // Ctreate the file picker. The path will be set later, when the widget size - // is set to. - m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, "", - _("Select a GenCAD export filename"), - FILEEXT::GencadFileWildcard(), - wxDefaultPosition, wxSize( -1,-1 ), - wxFLP_SAVE|wxFLP_USE_TEXTCTRL ); - m_mainSizer->Add( m_filePicker, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5 ); m_optsSizer = new wxGridSizer( 0, 1, 3, 3 ); createOptCheckboxes(); - m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 10 ); + m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 5 ); wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL ); - m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); + m_mainSizer->Add( stdButtons, 0, wxALL | wxEXPAND, 5 ); SetSizer( m_mainSizer ); @@ -64,14 +84,51 @@ DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aPar // Set the path in m_filePicker, now the size is set // (otherwise the text is truncated) - m_filePicker->SetPath( aPath ); + m_outputFileName->SetValue( aPath ); - Centre( wxBOTH ); + Layout(); + Fit(); + + m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) ); + m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ), + NULL, this ); +} + + +DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent, + JOB_EXPORT_PCB_GENCAD* aJob ) : + DIALOG_GENCAD_EXPORT_OPTIONS( aParent, aJob->GetConfiguredOutputPath() ) +{ + m_job = aJob; + + m_browseButton->Hide(); + + // Set the title + SetTitle( aJob->GetSettingsDialogTitle() ); } DIALOG_GENCAD_EXPORT_OPTIONS::~DIALOG_GENCAD_EXPORT_OPTIONS() { + m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ), + NULL, this ); +} + + +void DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked( wxCommandEvent& aEvent ) +{ + wxFileName brdFile( m_frame->GetBoard()->GetFileName() ); + wxString fileDialogName( wxString::Format( wxS( "%s-gencad" ), brdFile.GetName() ) ); + + wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() ); + wxFileName fn( Prj().AbsolutePath( path ) ); + + wxFileDialog dlg( this, _( "Export GenCAD File" ), fn.GetPath(), fileDialogName, + FILEEXT::GencadFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); + if( dlg.ShowModal() == wxID_OK ) + m_outputFileName->SetValue( dlg.GetPath() ); } @@ -102,7 +159,24 @@ std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() wxString DIALOG_GENCAD_EXPORT_OPTIONS::GetFileName() const { - return m_filePicker->GetPath(); + return m_outputFileName->GetValue(); +} + + +bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataToWindow() +{ + if( !wxDialog::TransferDataToWindow() ) + return false; + + if( m_job ) + { + m_options[FLIP_BOTTOM_PADS]->SetValue( m_job->m_flipBottomPads ); + m_options[UNIQUE_PIN_NAMES]->SetValue( m_job->m_useUniquePins ); + m_options[INDIVIDUAL_SHAPES]->SetValue( m_job->m_useIndividualShapes ); + m_options[USE_AUX_ORIGIN]->SetValue( m_job->m_useDrillOrigin ); + m_options[STORE_ORIGIN_COORDS]->SetValue( m_job->m_storeOriginCoords ); + } + return true; } @@ -111,16 +185,28 @@ bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataFromWindow() if( !wxDialog::TransferDataFromWindow() ) return false; - wxString fn = GetFileName(); - - if( wxFile::Exists( fn ) ) + if( m_job ) { - wxString msg = wxString::Format( _( "File %s already exists." ), fn ); - KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); - dlg.SetOKLabel( _( "Overwrite" ) ); - dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); + m_job->SetConfiguredOutputPath( GetFileName() ); + m_job->m_flipBottomPads = GetOption( FLIP_BOTTOM_PADS ); + m_job->m_useUniquePins = GetOption( UNIQUE_PIN_NAMES ); + m_job->m_useIndividualShapes = GetOption( INDIVIDUAL_SHAPES ); + m_job->m_useDrillOrigin = GetOption( USE_AUX_ORIGIN ); + m_job->m_storeOriginCoords = GetOption( STORE_ORIGIN_COORDS ); + } + else + { + wxString fn = GetFileName(); - return ( dlg.ShowModal() == wxID_OK ); + if( wxFile::Exists( fn ) ) + { + wxString msg = wxString::Format( _( "File %s already exists." ), fn ); + KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); + dlg.SetOKLabel( _( "Overwrite" ) ); + dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); + + return ( dlg.ShowModal() == wxID_OK ); + } } return true; diff --git a/pcbnew/dialogs/dialog_gencad_export_options.h b/pcbnew/dialogs/dialog_gencad_export_options.h index 03a37e08bc..3f1e69fe9f 100644 --- a/pcbnew/dialogs/dialog_gencad_export_options.h +++ b/pcbnew/dialogs/dialog_gencad_export_options.h @@ -33,6 +33,11 @@ class PCB_EDIT_FRAME; class wxFilePickerCtrl; class wxCheckBox; class wxGridSizer; +class wxFlexGridSizer; +class wxStaticText; +class wxTextCtrl; +class STD_BITMAP_BUTTON; +class PCB_EDIT_FRAME; ///< Settings for GenCAD exporter enum GENCAD_EXPORT_OPT @@ -44,11 +49,14 @@ enum GENCAD_EXPORT_OPT STORE_ORIGIN_COORDS // saves the origin point coordinates or (0, 0) }; +class JOB_EXPORT_PCB_GENCAD; + class DIALOG_GENCAD_EXPORT_OPTIONS : public DIALOG_SHIM { public: DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent, const wxString& aPath ); + DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent, JOB_EXPORT_PCB_GENCAD* aJob ); ~DIALOG_GENCAD_EXPORT_OPTIONS(); ///< Check whether an option has been selected. @@ -62,15 +70,24 @@ public: protected: bool TransferDataFromWindow() override; + bool TransferDataToWindow() override; + + virtual void onBrowseClicked( wxCommandEvent& aEvent ); ///< Create checkboxes for GenCAD export options. void createOptCheckboxes(); std::map<GENCAD_EXPORT_OPT, wxCheckBox*> m_options; + PCB_EDIT_FRAME* m_frame; + // Widgets - wxGridSizer* m_optsSizer; - wxFilePickerCtrl* m_filePicker; + wxGridSizer* m_optsSizer; + wxBoxSizer* m_fileSizer; + wxTextCtrl* m_outputFileName; + wxStaticText* m_textFile; + STD_BITMAP_BUTTON* m_browseButton; + JOB_EXPORT_PCB_GENCAD* m_job; }; #endif //__DIALOG_GENCAD_EXPORT_OPTIONS_H__ diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index e2070966be..be0c04b151 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -89,6 +89,7 @@ #include <dialogs/dialog_plot.h> #include <dialogs/dialog_drc_job_config.h> #include <dialogs/dialog_render_job.h> +#include <dialogs/dialog_gencad_export_options.h> #include <paths.h> #include "pcbnew_scripting_helpers.h" @@ -141,9 +142,17 @@ PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER( KIWAY* aKiway ) : } ); Register( "gencad", std::bind( &PCBNEW_JOBS_HANDLER::JobExportGencad, this, std::placeholders::_1 ), - []( JOB* job, wxWindow* aParent ) -> bool + [aKiway]( JOB* job, wxWindow* aParent ) -> bool { - return true; + JOB_EXPORT_PCB_GENCAD* gencadJob = dynamic_cast<JOB_EXPORT_PCB_GENCAD*>( job ); + + PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( + aKiway->Player( FRAME_PCB_EDITOR, false ) ); + + wxCHECK( gencadJob && editFrame, false ); + + DIALOG_GENCAD_EXPORT_OPTIONS dlg( editFrame, gencadJob ); + return dlg.ShowModal() == wxID_OK; } ); Register( "dxf", std::bind( &PCBNEW_JOBS_HANDLER::JobExportDxf, this, std::placeholders::_1 ), [aKiway]( JOB* job, wxWindow* aParent ) -> bool