KiCad PCB EDA Suite
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 <board.h>
31#include <project.h>
32#include <confirm.h>
34#include <wx/checkbox.h>
35#include <wx/filepicker.h>
36#include <wx/statline.h>
37
38
40 const wxString& aPath )
41 : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
42 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
43{
44 wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
45
46 // Ctreate the file picker. The path will be set later, when the widget size
47 // is set to.
48 m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, "",
49 _("Select a GenCAD export filename"),
51 wxDefaultPosition, wxSize( -1,-1 ),
52 wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
53 m_mainSizer->Add( m_filePicker, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5 );
54
55 m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
57 m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 10 );
58
59 wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
60 m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
61
62 SetSizer( m_mainSizer );
63
64 // Now all widgets have the size fixed, call FinishDialogSettings
66
67 // Set the path in m_filePicker, now the size is set
68 // (otherwise the text is truncated)
69 m_filePicker->SetPath( aPath );
70
71 Centre( wxBOTH );
72}
73
74
76{
77}
78
79
81{
82 auto it = m_options.find( aOption );
83
84 if( it == m_options.end() )
85 {
86 wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
87 return false;
88 }
89
90 return it->second->IsChecked();
91}
92
93
94std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
95{
96 std::map<GENCAD_EXPORT_OPT, bool> retVal;
97
98 for( const auto& option : m_options )
99 retVal[option.first] = option.second->IsChecked();
100
101 return retVal;
102}
103
104
106{
107 return m_filePicker->GetPath();
108}
109
110
112{
113 if( !wxDialog::TransferDataFromWindow() )
114 return false;
115
116 wxString fn = GetFileName();
117
118 if( wxFile::Exists( fn ) )
119 {
120 wxString msg = wxString::Format( _( "File %s already exists." ), fn );
121 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
122 dlg.SetOKLabel( _( "Overwrite" ) );
123 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
124
125 return ( dlg.ShowModal() == wxID_OK );
126 }
127
128 return true;
129}
130
131
133{
134 std::map<GENCAD_EXPORT_OPT, wxString> opts =
135 {
136 { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
137 { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
138 { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
139 { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
140 { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
141 };
142
143 for( const auto& option : opts )
144 {
145 wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
146 m_options[option.first] = chkbox;
147 m_optsSizer->Add( chkbox );
148 }
149}
150
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:83
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: confirm.h:46
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Definition: confirm.cpp:56
int ShowModal() override
Definition: confirm.cpp:100
The main frame for Pcbnew.
This file is part of the common library.
GENCAD_EXPORT_OPT
Settings for GenCAD exporter.
#define _(s)
wxString GencadFileWildcard()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Definition of file extensions used in Kicad.