KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_idf.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) 2013-2015 Cirilo Bernardo
5 * Copyright (C) 2013-2023 KiCad Developers, see change_log.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <pcb_edit_frame.h>
26#include <board.h>
29#include <pcbnew_settings.h>
30#include <project/project_file.h> // LAST_PATH_TYPE
31#include <confirm.h>
32
33
35{
36private:
37 bool m_idfThouOpt; // remember last preference for units in THOU
38 bool m_AutoAdjust; // remember last Reference Point AutoAdjust setting
39 int m_RefUnits; // remember last units for Reference Point
40 double m_XRef; // remember last X Reference Point
41 double m_YRef; // remember last Y Reference Point
42
44
45public:
47 DIALOG_EXPORT_IDF3_BASE( parent ), m_parent( parent )
48 {
49 SetFocus();
50
51 auto cfg = m_parent->GetPcbNewSettings();
52
53 m_idfThouOpt = cfg->m_ExportIdf.units_mils;
54 m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 );
55 m_AutoAdjust = cfg->m_ExportIdf.auto_adjust;
56 m_RefUnits = cfg->m_ExportIdf.ref_units;
57 m_XRef = cfg->m_ExportIdf.ref_x;
58 m_YRef = cfg->m_ExportIdf.ref_y;
59
62
63 m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
64 wxString tmpStr;
65 tmpStr << m_XRef;
66 m_IDF_Xref->SetValue( tmpStr );
67 tmpStr = wxT( "" );
68 tmpStr << m_YRef;
69 m_IDF_Yref->SetValue( tmpStr );
70
71 if( m_AutoAdjust )
72 {
73 m_IDF_RefUnitChoice->Enable( false );
74 m_IDF_Xref->Enable( false );
75 m_IDF_Yref->Enable( false );
76 }
77 else
78 {
79 m_IDF_RefUnitChoice->Enable( true );
80 m_IDF_Xref->Enable( true );
81 m_IDF_Yref->Enable( true );
82 }
83
85
86 // Now all widgets have the size fixed, call FinishDialogSettings
88 }
89
91 {
92 m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
93
94 PCBNEW_SETTINGS* cfg = nullptr;
95
96 try
97 {
99 }
100 catch( const std::runtime_error& e )
101 {
102 wxFAIL_MSG( e.what() );
103 }
104
105 if( cfg )
106 {
110 cfg->m_ExportIdf.ref_x = m_XRef;
111 cfg->m_ExportIdf.ref_y = m_YRef;
112 }
113 }
114
116 {
117 return m_rbUnitSelection->GetSelection() == 1;
118 }
119
120 wxFilePickerCtrl* FilePicker()
121 {
122 return m_filePickerIDF;
123 }
124
126 {
127 return m_IDF_RefUnitChoice->GetSelection();
128 }
129
130 double GetXRef()
131 {
133 }
134
135 double GetYRef()
136 {
138 }
139
141 {
142 return m_cbAutoAdjustOffset->GetValue();
143 }
144
145 void OnAutoAdjustOffset( wxCommandEvent& event )
146 {
147 if( GetAutoAdjustOffset() )
148 {
149 m_IDF_RefUnitChoice->Enable( false );
150 m_IDF_Xref->Enable( false );
151 m_IDF_Yref->Enable( false );
152 }
153 else
154 {
155 m_IDF_RefUnitChoice->Enable( true );
156 m_IDF_Xref->Enable( true );
157 m_IDF_Yref->Enable( true );
158 }
159
160 event.Skip();
161 }
162
163 bool TransferDataFromWindow() override;
164};
165
166
168{
169 wxFileName fn = m_filePickerIDF->GetPath();
170
171 if( fn.FileExists() )
172 {
173 wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
174 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
175 dlg.SetOKLabel( _( "Overwrite" ) );
176 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
177
178 return ( dlg.ShowModal() == wxID_OK );
179 }
180
181 return true;
182}
183
184
185void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
186{
187 // Build default output file name
188 wxString path = GetLastPath( LAST_PATH_IDF );
189
190 if( path.IsEmpty() )
191 {
192 wxFileName brdFile = GetBoard()->GetFileName();
193 brdFile.SetExt( wxT( "emn" ) );
194 path = brdFile.GetFullPath();
195 }
196
197 DIALOG_EXPORT_IDF3 dlg( this );
198 dlg.FilePicker()->SetPath( path );
199
200 if ( dlg.ShowModal() != wxID_OK )
201 return;
202
203 bool thou = dlg.GetThouOption();
204 double aXRef;
205 double aYRef;
206
207 if( dlg.GetAutoAdjustOffset() )
208 {
210
211 aXRef = bbox.Centre().x * pcbIUScale.MM_PER_IU;
212 aYRef = bbox.Centre().y * pcbIUScale.MM_PER_IU;
213 }
214 else
215 {
216 aXRef = dlg.GetXRef();
217 aYRef = dlg.GetYRef();
218
219 if( dlg.GetRefUnitsChoice() == 1 )
220 {
221 // selected reference unit is in inches
222 aXRef *= 25.4;
223 aYRef *= 25.4;
224 }
225
226 }
227
228 wxBusyCursor dummy;
229
230 wxString fullFilename = dlg.FilePicker()->GetPath();
231 SetLastPath( LAST_PATH_IDF, fullFilename );
232
233 if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef ) )
234 {
235 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), fullFilename );
236 wxMessageBox( msg );
237 return;
238 }
239}
240
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:890
const wxString & GetFileName() const
Definition: board.h:313
Vec Centre() const
Definition: box2.h:71
Class DIALOG_EXPORT_IDF3_BASE.
wxFilePickerCtrl * m_filePickerIDF
DIALOG_EXPORT_IDF3(PCB_EDIT_FRAME *parent)
wxFilePickerCtrl * FilePicker()
bool TransferDataFromWindow() override
void OnAutoAdjustOffset(wxCommandEvent &event)
PCB_EDIT_FRAME * m_parent
void SetupStandardButtons(std::map< int, wxString > aLabels={})
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:47
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
DIALOG_EXPORT_IDF m_ExportIdf
PCBNEW_SETTINGS * GetPcbNewSettings() const
BOARD * GetBoard() const
The main frame for Pcbnew.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
bool Export_IDF3(BOARD *aPcb, const wxString &aFullFileName, bool aUseThou, double aXRef, double aYRef)
Create an IDF3 compliant BOARD (*.emn) and LIBRARY (*.emp) file.
Definition: export_idf.cpp:601
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
void OnExportIDF3(wxCommandEvent &event)
Export the current BOARD to a IDFv3 board and lib files.
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
This file is part of the common library.
#define _(s)
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
Definition: eda_units.cpp:565
@ LAST_PATH_IDF
Definition: project_file.h:51
std::vector< FAB_LAYER_COLOR > dummy
const double MM_PER_IU
Definition: base_units.h:79