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 (C) 2018-2019 KiCad Developers, see change_log.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 <pcb_edit_frame.h>
30#include <kidialog.h>
32#include <wx/checkbox.h>
33#include <wx/filepicker.h>
34#include <wx/sizer.h>
35
36
38 const wxString& aPath )
39 : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
40 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
41{
42 wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
43
44 // Ctreate the file picker. The path will be set later, when the widget size
45 // is set to.
46 m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, "",
47 _("Select a GenCAD export filename"),
49 wxDefaultPosition, wxSize( -1,-1 ),
50 wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
51 m_mainSizer->Add( m_filePicker, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5 );
52
53 m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
55 m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 10 );
56
57 wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
58 m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
59
60 SetSizer( m_mainSizer );
61
62 // Now all widgets have the size fixed, call FinishDialogSettings
64
65 // Set the path in m_filePicker, now the size is set
66 // (otherwise the text is truncated)
67 m_filePicker->SetPath( aPath );
68
69 Centre( wxBOTH );
70}
71
72
74{
75}
76
77
79{
80 auto it = m_options.find( aOption );
81
82 if( it == m_options.end() )
83 {
84 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
85 return false;
86 }
87
88 return it->second->IsChecked();
89}
90
91
92std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
93{
94 std::map<GENCAD_EXPORT_OPT, bool> retVal;
95
96 for( const auto& option : m_options )
97 retVal[option.first] = option.second->IsChecked();
98
99 return retVal;
100}
101
102
104{
105 return m_filePicker->GetPath();
106}
107
108
110{
111 if( !wxDialog::TransferDataFromWindow() )
112 return false;
113
114 wxString fn = GetFileName();
115
116 if( wxFile::Exists( fn ) )
117 {
118 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
119 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
120 dlg.SetOKLabel( _( "Overwrite" ) );
121 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
122
123 return ( dlg.ShowModal() == wxID_OK );
124 }
125
126 return true;
127}
128
129
131{
132 std::map<GENCAD_EXPORT_OPT, wxString> opts =
133 {
134 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
135 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
136 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
137 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
138 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
139 };
140
141 for( const auto& option : opts )
142 {
143 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
144 m_options[option.first] = chkbox;
145 m_optsSizer->Add( chkbox );
146 }
147}
148
bool TransferDataFromWindow() override
Create checkboxes for GenCAD export options.
DIALOG_GENCAD_EXPORT_OPTIONS(PCB_EDIT_FRAME *aParent, const wxString &aPath)
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Return all export settings.
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:88
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:43
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Definition: kidialog.cpp:51
int ShowModal() override
Definition: kidialog.cpp:95
The main frame for Pcbnew.
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.