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, see <https://www.gnu.org/licenses/>.
21 */
22
24
25#include <common.h>
26#include <wx/anybutton.h>
27#include <wx/filedlg.h>
28#include <wx/checkbox.h>
29#include <wx/filepicker.h>
30#include <wx/sizer.h>
31#include <wx/stattext.h>
32#include <wx/textctrl.h>
33
35
36#include <pcb_edit_frame.h>
37#include <kidialog.h>
38#include <kiplatform/ui.h>
41#include <string_utils.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
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
123
124 if( dlg.ShowModal() == wxID_OK )
125 m_outputFileName->SetValue( dlg.GetPath() );
126}
127
128
130{
131 auto it = m_options.find( aOption );
132
133 if( it == m_options.end() )
134 {
135 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
136 return false;
137 }
138
139 return it->second->IsChecked();
140}
141
142
144{
145 return m_outputFileName->GetValue();
146}
147
148
150{
151 if( !wxDialog::TransferDataToWindow() )
152 return false;
153
154 if( !m_job )
155 {
156 if( m_outputFileName->GetValue().IsEmpty() )
157 {
158 wxFileName brdFile = m_frame->GetBoard()->GetFileName();
159 brdFile.SetExt( wxT( "cad" ) );
160 m_outputFileName->SetValue( brdFile.GetFullPath() );
161 }
162 }
163 else
164 {
165 m_outputFileName->SetValue( m_job->GetConfiguredOutputPath() );
166 m_options[FLIP_BOTTOM_PADS]->SetValue( m_job->m_flipBottomPads );
167 m_options[UNIQUE_PIN_NAMES]->SetValue( m_job->m_useUniquePins );
168 m_options[INDIVIDUAL_SHAPES]->SetValue( m_job->m_useIndividualShapes );
169 m_options[USE_AUX_ORIGIN]->SetValue( m_job->m_useDrillOrigin );
170 m_options[STORE_ORIGIN_COORDS]->SetValue( m_job->m_storeOriginCoords );
171 }
172
173 return true;
174}
175
176
178{
179 if( !wxDialog::TransferDataFromWindow() )
180 return false;
181
182 if( m_job )
183 {
184 m_job->SetConfiguredOutputPath( GetFileName() );
185 m_job->m_flipBottomPads = GetOption( FLIP_BOTTOM_PADS );
186 m_job->m_useUniquePins = GetOption( UNIQUE_PIN_NAMES );
187 m_job->m_useIndividualShapes = GetOption( INDIVIDUAL_SHAPES );
188 m_job->m_useDrillOrigin = GetOption( USE_AUX_ORIGIN );
189 m_job->m_storeOriginCoords = GetOption( STORE_ORIGIN_COORDS );
190 }
191 else
192 {
193 wxString fn = GetFileName();
194
195 if( wxFile::Exists( fn ) )
196 {
197 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
198 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
199 dlg.SetOKLabel( _( "Overwrite" ) );
200 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
201
202 return ( dlg.ShowModal() == wxID_OK );
203 }
204 }
205
206 return true;
207}
208
209
211{
212 std::map<GENCAD_EXPORT_OPT, wxString> opts =
213 {
214 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
215 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
216 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
217 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
218 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
219 };
220
221 for( const auto& option : opts )
222 {
223 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
224 m_options[option.first] = chkbox;
225 m_optsSizer->Add( chkbox );
226 }
227}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
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:38
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:51
int ShowModal() override
Definition kidialog.cpp:89
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:704
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:448
#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.