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>
41#include <kiplatform/ui.h>
44#include <string_utils.h>
45#include <board.h>
46
47
49 JOB_EXPORT_PCB_GENCAD* aJob ) :
50 DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
51 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
52 m_frame( aParent ),
53 m_job( aJob )
54{
55 wxBoxSizer* m_mainSizer = new wxBoxSizer( wxVERTICAL );
56
57 m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
58
59 m_textFile = new wxStaticText( this, wxID_ANY, _( "Output File:" ), wxDefaultPosition, wxDefaultSize, 0 );
60 m_textFile->Wrap( -1 );
61 m_fileSizer->Add( m_textFile, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5 );
62
63 m_outputFileName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
64 m_outputFileName->SetToolTip( _( "Enter a filename if you do not want to use default file names" ) );
65 m_outputFileName->SetMinSize( wxSize( 350, -1 ) );
66 m_fileSizer->Add( m_outputFileName, 1, wxALL | wxEXPAND, 5 );
67
68 m_browseButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( -1, -1 ),
69 wxBU_AUTODRAW | 0 );
70 m_fileSizer->Add( m_browseButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
71
72 m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 );
73
74 m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
76 m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 5 );
77
78 wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
79 m_mainSizer->Add( stdButtons, 0, wxALL | wxEXPAND, 5 );
80
81 SetSizer( m_mainSizer );
82
83 if( !aTitle.IsEmpty() )
84 SetTitle( aTitle );
85
86 if( aJob )
87 m_browseButton->Hide();
88
89 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
90 // non-job versions.
91 m_hash_key = TO_UTF8( GetTitle() );
92
93 // Now all widgets have the size fixed, call FinishDialogSettings
95
96 Layout();
97 Fit();
98
100 m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
101 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
102 nullptr, this );
103}
104
105
107{
108 m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
109 wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
110 nullptr, this );
111}
112
113
115{
116 wxFileName brdFile( m_frame->GetBoard()->GetFileName() );
117 wxString fileDialogName( wxString::Format( wxS( "%s-gencad" ), brdFile.GetName() ) );
118
119 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
120 wxFileName fn( Prj().AbsolutePath( path ) );
121
122 wxFileDialog dlg( this, _( "Export GenCAD File" ), fn.GetPath(), fileDialogName,
123 FILEEXT::GencadFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
124
126
127 if( dlg.ShowModal() == wxID_OK )
128 m_outputFileName->SetValue( dlg.GetPath() );
129}
130
131
133{
134 auto it = m_options.find( aOption );
135
136 if( it == m_options.end() )
137 {
138 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
139 return false;
140 }
141
142 return it->second->IsChecked();
143}
144
145
147{
148 return m_outputFileName->GetValue();
149}
150
151
153{
154 if( !wxDialog::TransferDataToWindow() )
155 return false;
156
157 if( !m_job )
158 {
159 if( m_outputFileName->GetValue().IsEmpty() )
160 {
161 wxFileName brdFile = m_frame->GetBoard()->GetFileName();
162 brdFile.SetExt( wxT( "cad" ) );
163 m_outputFileName->SetValue( brdFile.GetFullPath() );
164 }
165 }
166 else
167 {
168 m_outputFileName->SetValue( m_job->GetConfiguredOutputPath() );
169 m_options[FLIP_BOTTOM_PADS]->SetValue( m_job->m_flipBottomPads );
170 m_options[UNIQUE_PIN_NAMES]->SetValue( m_job->m_useUniquePins );
171 m_options[INDIVIDUAL_SHAPES]->SetValue( m_job->m_useIndividualShapes );
172 m_options[USE_AUX_ORIGIN]->SetValue( m_job->m_useDrillOrigin );
173 m_options[STORE_ORIGIN_COORDS]->SetValue( m_job->m_storeOriginCoords );
174 }
175
176 return true;
177}
178
179
181{
182 if( !wxDialog::TransferDataFromWindow() )
183 return false;
184
185 if( m_job )
186 {
187 m_job->SetConfiguredOutputPath( GetFileName() );
188 m_job->m_flipBottomPads = GetOption( FLIP_BOTTOM_PADS );
189 m_job->m_useUniquePins = GetOption( UNIQUE_PIN_NAMES );
190 m_job->m_useIndividualShapes = GetOption( INDIVIDUAL_SHAPES );
191 m_job->m_useDrillOrigin = GetOption( USE_AUX_ORIGIN );
192 m_job->m_storeOriginCoords = GetOption( STORE_ORIGIN_COORDS );
193 }
194 else
195 {
196 wxString fn = GetFileName();
197
198 if( wxFile::Exists( fn ) )
199 {
200 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
201 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
202 dlg.SetOKLabel( _( "Overwrite" ) );
203 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
204
205 return ( dlg.ShowModal() == wxID_OK );
206 }
207 }
208
209 return true;
210}
211
212
214{
215 std::map<GENCAD_EXPORT_OPT, wxString> opts =
216 {
217 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
218 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
219 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
220 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
221 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
222 };
223
224 for( const auto& option : opts )
225 {
226 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
227 m_options[option.first] = chkbox;
228 m_optsSizer->Add( chkbox );
229 }
230}
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:558
GENCAD_EXPORT_OPT
Settings for GenCAD exporter.
#define _(s)
static wxString GencadFileWildcard()
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:717
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::string path
Definition of file extensions used in Kicad.