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/checkbox.h>
35#include <wx/filepicker.h>
36#include <wx/sizer.h>
37#include <wx/stattext.h>
38#include <wx/textctrl.h>
40#include <board.h>
41
42
43
45 const wxString& aPath ) :
46 DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
47 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
48 m_frame( aParent ),
49 m_job( nullptr )
50{
51 wxBoxSizer* m_mainSizer = new wxBoxSizer( wxVERTICAL );
52
53 m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
54
55 m_textFile = new wxStaticText( this, wxID_ANY, _( "Output File:" ), wxDefaultPosition, wxDefaultSize, 0 );
56 m_textFile->Wrap( -1 );
57 m_fileSizer->Add( m_textFile, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5 );
58
60 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
66 m_browseButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
67 wxSize( -1, -1 ), wxBU_AUTODRAW | 0 );
68 m_fileSizer->Add( m_browseButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
69
70 m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 );
71
72
73 m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
75 m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 5 );
76
77 wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
78 m_mainSizer->Add( stdButtons, 0, wxALL | wxEXPAND, 5 );
79
80 SetSizer( m_mainSizer );
81
82 // Now all widgets have the size fixed, call FinishDialogSettings
84
85 // Set the path in m_filePicker, now the size is set
86 // (otherwise the text is truncated)
87 m_outputFileName->SetValue( aPath );
88
89 Layout();
90 Fit();
91
92 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
93 m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
94 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
95 NULL, this );
96}
97
98
100 JOB_EXPORT_PCB_GENCAD* aJob ) :
101 DIALOG_GENCAD_EXPORT_OPTIONS( aParent, aJob->GetConfiguredOutputPath() )
102{
103 m_job = aJob;
104
105 m_browseButton->Hide();
106
107 // Set the title
108 SetTitle( aJob->GetSettingsDialogTitle() );
109}
110
111
113{
114 m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
115 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
116 NULL, this );
117}
118
119
121{
122 wxFileName brdFile( m_frame->GetBoard()->GetFileName() );
123 wxString fileDialogName( wxString::Format( wxS( "%s-gencad" ), brdFile.GetName() ) );
124
125 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
126 wxFileName fn( Prj().AbsolutePath( path ) );
127
128 wxFileDialog dlg( this, _( "Export GenCAD File" ), fn.GetPath(), fileDialogName,
129 FILEEXT::GencadFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
130 if( dlg.ShowModal() == wxID_OK )
131 m_outputFileName->SetValue( dlg.GetPath() );
132}
133
134
136{
137 auto it = m_options.find( aOption );
138
139 if( it == m_options.end() )
140 {
141 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
142 return false;
143 }
144
145 return it->second->IsChecked();
146}
147
148
149std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
150{
151 std::map<GENCAD_EXPORT_OPT, bool> retVal;
152
153 for( const auto& option : m_options )
154 retVal[option.first] = option.second->IsChecked();
155
156 return retVal;
157}
158
159
161{
162 return m_outputFileName->GetValue();
163}
164
165
167{
168 if( !wxDialog::TransferDataToWindow() )
169 return false;
170
171 if( m_job )
172 {
178 }
179 return true;
180}
181
182
184{
185 if( !wxDialog::TransferDataFromWindow() )
186 return false;
187
188 if( m_job )
189 {
196 }
197 else
198 {
199 wxString fn = GetFileName();
200
201 if( wxFile::Exists( fn ) )
202 {
203 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
204 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
205 dlg.SetOKLabel( _( "Overwrite" ) );
206 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
207
208 return ( dlg.ShowModal() == wxID_OK );
209 }
210 }
211
212 return true;
213}
214
215
217{
218 std::map<GENCAD_EXPORT_OPT, wxString> opts =
219 {
220 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
221 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
222 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
223 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
224 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
225 };
226
227 for( const auto& option : opts )
228 {
229 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
230 m_options[option.first] = chkbox;
231 m_optsSizer->Add( chkbox );
232 }
233}
234
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
const wxString & GetFileName() const
Definition: board.h:333
DIALOG_GENCAD_EXPORT_OPTIONS(PCB_EDIT_FRAME *aParent, const wxString &aPath)
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Return all export settings.
virtual void onBrowseClicked(wxCommandEvent &aEvent)
Create checkboxes for GenCAD export options.
std::map< GENCAD_EXPORT_OPT, bool > GetAllOptions() const
Return the selected file path.
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:52
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxString GetSettingsDialogTitle() const override
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition: job.cpp:153
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:43
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:351
GENCAD_EXPORT_OPT
Settings for GenCAD exporter.
#define _(s)
static wxString GencadFileWildcard()
This file is part of the common library.
Definition of file extensions used in Kicad.