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
29#include <wx/anybutton.h>
30#include <wx/filedlg.h>
31#include <wx/checkbox.h>
32#include <wx/filepicker.h>
33#include <wx/sizer.h>
34#include <wx/stattext.h>
35#include <wx/textctrl.h>
36
38
39#include <pcb_edit_frame.h>
40#include <kidialog.h>
43#include <string_utils.h>
44#include <board.h>
45
46
48 JOB_EXPORT_PCB_GENCAD* aJob ) :
49 DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
50 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
51 m_frame( aParent ),
52 m_job( aJob )
53{
54 wxBoxSizer* m_mainSizer = new wxBoxSizer( wxVERTICAL );
55
56 m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
57
58 m_textFile = new wxStaticText( this, wxID_ANY, _( "Output File:" ), wxDefaultPosition, wxDefaultSize, 0 );
59 m_textFile->Wrap( -1 );
60 m_fileSizer->Add( m_textFile, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5 );
61
62 m_outputFileName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
63 m_outputFileName->SetToolTip( _( "Enter a filename if you do not want to use default file names" ) );
64 m_outputFileName->SetMinSize( wxSize( 350, -1 ) );
65 m_fileSizer->Add( m_outputFileName, 1, wxALL | wxEXPAND, 5 );
66
67 m_browseButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1, -1 ),
68 wxBU_AUTODRAW | 0 );
69 m_fileSizer->Add( m_browseButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
70
71 m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 );
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 if( !aTitle.IsEmpty() )
83 SetTitle( aTitle );
84
85 if( aJob )
86 m_browseButton->Hide();
87
88 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
89 // non-job versions.
90 m_hash_key = TO_UTF8( GetTitle() );
91
92 // Now all widgets have the size fixed, call FinishDialogSettings
94
95 Layout();
96 Fit();
97
99 m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
100 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
101 nullptr, this );
102}
103
104
106{
107 m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
108 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
109 nullptr, this );
110}
111
112
114{
115 wxFileName brdFile( m_frame->GetBoard()->GetFileName() );
116 wxString fileDialogName( wxString::Format( wxS( "%s-gencad" ), brdFile.GetName() ) );
117
118 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
119 wxFileName fn( Prj().AbsolutePath( path ) );
120
121 wxFileDialog dlg( this, _( "Export GenCAD File" ), fn.GetPath(), fileDialogName,
122 FILEEXT::GencadFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
123 if( dlg.ShowModal() == wxID_OK )
124 m_outputFileName->SetValue( dlg.GetPath() );
125}
126
127
129{
130 auto it = m_options.find( aOption );
131
132 if( it == m_options.end() )
133 {
134 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
135 return false;
136 }
137
138 return it->second->IsChecked();
139}
140
141
143{
144 return m_outputFileName->GetValue();
145}
146
147
149{
150 if( !wxDialog::TransferDataToWindow() )
151 return false;
152
153 if( !m_job )
154 {
155 if( m_outputFileName->GetValue().IsEmpty() )
156 {
157 wxFileName brdFile = m_frame->GetBoard()->GetFileName();
158 brdFile.SetExt( wxT( "cad" ) );
159 m_outputFileName->SetValue( brdFile.GetFullPath() );
160 }
161 }
162 else
163 {
164 m_outputFileName->SetValue( m_job->GetConfiguredOutputPath() );
165 m_options[FLIP_BOTTOM_PADS]->SetValue( m_job->m_flipBottomPads );
166 m_options[UNIQUE_PIN_NAMES]->SetValue( m_job->m_useUniquePins );
167 m_options[INDIVIDUAL_SHAPES]->SetValue( m_job->m_useIndividualShapes );
168 m_options[USE_AUX_ORIGIN]->SetValue( m_job->m_useDrillOrigin );
169 m_options[STORE_ORIGIN_COORDS]->SetValue( m_job->m_storeOriginCoords );
170 }
171
172 return true;
173}
174
175
177{
178 if( !wxDialog::TransferDataFromWindow() )
179 return false;
180
181 if( m_job )
182 {
183 m_job->SetConfiguredOutputPath( GetFileName() );
184 m_job->m_flipBottomPads = GetOption( FLIP_BOTTOM_PADS );
185 m_job->m_useUniquePins = GetOption( UNIQUE_PIN_NAMES );
186 m_job->m_useIndividualShapes = GetOption( INDIVIDUAL_SHAPES );
187 m_job->m_useDrillOrigin = GetOption( USE_AUX_ORIGIN );
188 m_job->m_storeOriginCoords = GetOption( STORE_ORIGIN_COORDS );
189 }
190 else
191 {
192 wxString fn = GetFileName();
193
194 if( wxFile::Exists( fn ) )
195 {
196 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
197 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
198 dlg.SetOKLabel( _( "Overwrite" ) );
199 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
200
201 return ( dlg.ShowModal() == wxID_OK );
202 }
203 }
204
205 return true;
206}
207
208
210{
211 std::map<GENCAD_EXPORT_OPT, wxString> opts =
212 {
213 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
214 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
215 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
216 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
217 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
218 };
219
220 for( const auto& option : opts )
221 {
222 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
223 m_options[option.first] = chkbox;
224 m_optsSizer->Add( chkbox );
225 }
226}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
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.
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:42
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:55
int ShowModal() override
Definition kidialog.cpp:93
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
The main frame for Pcbnew.
A bitmap button widget that behaves like a standard dialog button except with an icon.
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()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition of file extensions used in Kicad.