KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_gencad_export_options.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
28
30
31#include <pcb_edit_frame.h>
32#include <kidialog.h>
34#include <wx/anybutton.h>
35#include <wx/filedlg.h>
36#include <wx/checkbox.h>
37#include <wx/filepicker.h>
38#include <wx/sizer.h>
39#include <wx/stattext.h>
40#include <wx/textctrl.h>
42#include <board.h>
43
44
46 JOB_EXPORT_PCB_GENCAD* aJob ) :
47 DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
48 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
49 m_frame( aParent ),
50 m_job( aJob )
51{
52 wxBoxSizer* m_mainSizer = new wxBoxSizer( wxVERTICAL );
53
54 m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
55
56 m_textFile = new wxStaticText( this, wxID_ANY, _( "Output File:" ), wxDefaultPosition, wxDefaultSize, 0 );
57 m_textFile->Wrap( -1 );
58 m_fileSizer->Add( m_textFile, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5 );
59
60 m_outputFileName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
61 m_outputFileName->SetToolTip( _( "Enter a filename if you do not want to use default file names" ) );
62 m_outputFileName->SetMinSize( wxSize( 350, -1 ) );
63 m_fileSizer->Add( m_outputFileName, 1, wxALL | wxEXPAND, 5 );
64
65 m_browseButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1, -1 ),
66 wxBU_AUTODRAW | 0 );
67 m_fileSizer->Add( m_browseButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
68
69 m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 );
70
71 m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
73 m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 5 );
74
75 wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
76 m_mainSizer->Add( stdButtons, 0, wxALL | wxEXPAND, 5 );
77
78 SetSizer( m_mainSizer );
79
80 if( !aTitle.IsEmpty() )
81 SetTitle( aTitle );
82
83 if( aJob )
84 m_browseButton->Hide();
85
86 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
87 // non-job versions.
88 m_hash_key = TO_UTF8( GetTitle() );
89
90 // Now all widgets have the size fixed, call FinishDialogSettings
92
93 Layout();
94 Fit();
95
96 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
97 m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
98 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
99 nullptr, this );
100}
101
102
104{
105 m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
106 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
107 nullptr, this );
108}
109
110
112{
113 wxFileName brdFile( m_frame->GetBoard()->GetFileName() );
114 wxString fileDialogName( wxString::Format( wxS( "%s-gencad" ), brdFile.GetName() ) );
115
116 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
117 wxFileName fn( Prj().AbsolutePath( path ) );
118
119 wxFileDialog dlg( this, _( "Export GenCAD File" ), fn.GetPath(), fileDialogName,
120 FILEEXT::GencadFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
121 if( dlg.ShowModal() == wxID_OK )
122 m_outputFileName->SetValue( dlg.GetPath() );
123}
124
125
127{
128 auto it = m_options.find( aOption );
129
130 if( it == m_options.end() )
131 {
132 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
133 return false;
134 }
135
136 return it->second->IsChecked();
137}
138
139
141{
142 return m_outputFileName->GetValue();
143}
144
145
147{
148 if( !wxDialog::TransferDataToWindow() )
149 return false;
150
151 if( !m_job )
152 {
153 if( m_outputFileName->GetValue().IsEmpty() )
154 {
155 wxFileName brdFile = m_frame->GetBoard()->GetFileName();
156 brdFile.SetExt( wxT( "cad" ) );
157 m_outputFileName->SetValue( brdFile.GetFullPath() );
158 }
159 }
160 else
161 {
168 }
169
170 return true;
171}
172
173
175{
176 if( !wxDialog::TransferDataFromWindow() )
177 return false;
178
179 if( m_job )
180 {
187 }
188 else
189 {
190 wxString fn = GetFileName();
191
192 if( wxFile::Exists( fn ) )
193 {
194 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
195 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
196 dlg.SetOKLabel( _( "Overwrite" ) );
197 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
198
199 return ( dlg.ShowModal() == wxID_OK );
200 }
201 }
202
203 return true;
204}
205
206
208{
209 std::map<GENCAD_EXPORT_OPT, wxString> opts =
210 {
211 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
212 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
213 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
214 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
215 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
216 };
217
218 for( const auto& option : opts )
219 {
220 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
221 m_options[option.first] = chkbox;
222 m_optsSizer->Add( chkbox );
223 }
224}
225
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
const wxString & GetFileName() const
Definition: board.h:354
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Return the selected file path.
virtual void onBrowseClicked(wxCommandEvent &aEvent)
Create checkboxes for GenCAD export options.
DIALOG_GENCAD_EXPORT_OPTIONS(PCB_EDIT_FRAME *aParent, const wxString &aTitle, JOB_EXPORT_PCB_GENCAD *aJob)
std::map< GENCAD_EXPORT_OPT, wxCheckBox * > m_options
~DIALOG_GENCAD_EXPORT_OPTIONS()
Check whether an option has been selected.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:61
std::string m_hash_key
Definition: dialog_shim.h:236
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition: job.cpp:153
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition: job.h:232
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:50
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition: kidialog.cpp:51
int ShowModal() override
Definition: kidialog.cpp:95
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
BOARD * GetBoard() const
The main frame for Pcbnew.
A bitmap button widget that behaves like a standard dialog button except with an icon.
void SetBitmap(const wxBitmapBundle &aBmp)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:355
GENCAD_EXPORT_OPT
Settings for GenCAD exporter.
#define _(s)
static wxString GencadFileWildcard()
This file is part of the common library.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:429
Definition of file extensions used in Kicad.