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 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 <class_board.h>
31 #include <project.h>
32 #include <confirm.h>
34 
35 #include <wx/statline.h>
36 #include <wx/button.h>
37 
39  : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
40  wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
41 {
42  // Obtain a potential filename for the exported file
43  wxFileName fn = aParent->GetBoard()->GetFileName();
44  fn.SetExt( "cad" );
45 
46  // Create widgets
47  SetSizeHints( wxSize( 500, 200 ), wxDefaultSize );
48 
49  wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
50 
51  wxBoxSizer* m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
52 
53  m_filePath = new wxTextCtrl( this, wxID_ANY, fn.GetFullPath() );
54  m_fileSizer->Add( m_filePath, 1, wxEXPAND | wxRIGHT, 5 );
55 
56  wxButton* m_browseBtn = new wxButton( this, wxID_ANY, _( "Browse" ) );
57  m_browseBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
58  wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowse ), NULL, this );
59  m_fileSizer->Add( m_browseBtn, 0 );
60 
61  m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 );
62 
63 
64  m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
66  m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
67 
68 
69  wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
70  m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
71 
72  SetSizer( m_mainSizer );
73  Layout();
74  m_mainSizer->Fit( this );
75 
76  Centre( wxBOTH );
77 }
78 
79 
81 {
82 }
83 
84 
86 {
87  auto it = m_options.find( aOption );
88 
89  if( it == m_options.end() )
90  {
91  wxASSERT_MSG( false, "Missing checkbox for an option" );
92  return false;
93  }
94 
95  return it->second->IsChecked();
96 }
97 
98 
99 std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
100 {
101  std::map<GENCAD_EXPORT_OPT, bool> retVal;
102 
103  for( const auto& option : m_options )
104  retVal[option.first] = option.second->IsChecked();
105 
106  return retVal;
107 }
108 
109 
111 {
112  return m_filePath->GetValue();
113 }
114 
115 
117 {
118  if( !wxDialog::TransferDataFromWindow() )
119  return false;
120 
121  wxString fn = GetFileName();
122 
123  if( wxFile::Exists( fn ) )
124  {
125  wxString msg = wxString::Format( _( "File %s already exists." ), fn );
126  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
127  dlg.SetOKLabel( _( "Overwrite" ) );
128  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
129 
130  return ( dlg.ShowModal() == wxID_OK );
131  }
132 
133  return true;
134 }
135 
136 
138 {
139  std::map<GENCAD_EXPORT_OPT, wxString> opts =
140  {
141  { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
142  { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
143  { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
144  { USE_AUX_ORIGIN, _( "Use auxiliary axis as origin" ) },
145  { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
146  };
147 
148  for( const auto& option : opts )
149  {
150  wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
151  m_options[option.first] = chkbox;
152  m_optsSizer->Add( chkbox );
153  }
154 }
155 
156 
157 void DIALOG_GENCAD_EXPORT_OPTIONS::onBrowse( wxCommandEvent& aEvent )
158 {
159  wxFileDialog dlg( this, _( "Save GenCAD Board File" ),
160  wxPathOnly( Prj().GetProjectFullName() ),
161  m_filePath->GetValue(),
163  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
164 
165  if( dlg.ShowModal() == wxID_CANCEL )
166  return;
167 
168  m_filePath->SetValue( dlg.GetPath() );
169 }
void DoNotShowCheckbox(wxString file, int line)
Shows the &#39;do not show again&#39; checkbox
Definition: confirm.cpp:60
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
This file is part of the common library.
void onBrowse(wxCommandEvent &aEvent)
Browse output file event handler
Class BOARD to handle a board.
std::map< GENCAD_EXPORT_OPT, bool > GetAllOptions() const
Returns all export settings
BOARD * GetBoard() const
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:82
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
bool GetOption(GENCAD_EXPORT_OPT aOption) const
Checks whether an option has been selected
wxString GencadFileWildcard()
std::map< GENCAD_EXPORT_OPT, wxCheckBox * > m_options
const wxString & GetFileName() const
Definition: class_board.h:237
The common library.
GENCAD_EXPORT_OPT
Settings for GenCAD exporter
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
int ShowModal() override
Definition: confirm.cpp:102
wxString GetFileName() const
Returns the selected file path
DIALOG_GENCAD_EXPORT_OPTIONS(PCB_EDIT_FRAME *aParent)
void createOptCheckboxes()
Creates checkboxes for GenCAD export options