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