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 <maciej.suminski@cern.ch>
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/filepicker.h>
35 #include <wx/statline.h>
36 
37 
39  const wxString& aPath )
40  : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
41  wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
42 {
43  wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
44 
45  // Ctreate the file picker. The path will be set later, when the widget size
46  // is set to.
47  m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, "",
48  _("Select a GenCAD export filename"),
50  wxDefaultPosition, wxSize( -1,-1 ),
51  wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
52  m_mainSizer->Add( m_filePicker, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5 );
53 
54  m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
56  m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 10 );
57 
58  wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
59  m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
60 
61  SetSizer( m_mainSizer );
62 
63  // Now all widgets have the size fixed, call FinishDialogSettings
65 
66  // Set the path in m_filePicker, now the size is set
67  // (otherwize the text is truncated)
68  m_filePicker->SetPath( aPath );
69 
70  Centre( wxBOTH );
71 }
72 
73 
75 {
76 }
77 
78 
80 {
81  auto it = m_options.find( aOption );
82 
83  if( it == m_options.end() )
84  {
85  wxASSERT_MSG( false, "Missing checkbox for an option" );
86  return false;
87  }
88 
89  return it->second->IsChecked();
90 }
91 
92 
93 std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
94 {
95  std::map<GENCAD_EXPORT_OPT, bool> retVal;
96 
97  for( const auto& option : m_options )
98  retVal[option.first] = option.second->IsChecked();
99 
100  return retVal;
101 }
102 
103 
105 {
106  return m_filePicker->GetPath();
107 }
108 
109 
111 {
112  if( !wxDialog::TransferDataFromWindow() )
113  return false;
114 
115  wxString fn = GetFileName();
116 
117  if( wxFile::Exists( fn ) )
118  {
119  wxString msg = wxString::Format( _( "File %s already exists." ), fn );
120  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
121  dlg.SetOKLabel( _( "Overwrite" ) );
122  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
123 
124  return ( dlg.ShowModal() == wxID_OK );
125  }
126 
127  return true;
128 }
129 
130 
132 {
133  std::map<GENCAD_EXPORT_OPT, wxString> opts =
134  {
135  { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
136  { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
137  { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
138  { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
139  { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
140  };
141 
142  for( const auto& option : opts )
143  {
144  wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
145  m_options[option.first] = chkbox;
146  m_optsSizer->Add( chkbox );
147  }
148 }
149 
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Checks whether an option has been selected
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:54
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
This file is part of the common library.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:83
std::map< GENCAD_EXPORT_OPT, bool > GetAllOptions() const
Returns all export settings
wxString GetFileName() const
Returns the selected file path
wxString GencadFileWildcard()
std::map< GENCAD_EXPORT_OPT, wxCheckBox * > m_options
Definition of file extensions used in Kicad.
GENCAD_EXPORT_OPT
Settings for GenCAD exporter
DIALOG_GENCAD_EXPORT_OPTIONS(PCB_EDIT_FRAME *aParent, const wxString &aPath)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
#define _(s)
Definition: 3d_actions.cpp:33
PCB_EDIT_FRAME is the main frame for Pcbnew.
int ShowModal() override
Definition: confirm.cpp:96
void createOptCheckboxes()
Creates checkboxes for GenCAD export options