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 <kidialog.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
60 m_cbRemoveUnspecified->SetValue( cfg->m_ExportIdf.no_unspecified );
61 m_cbRemoveDNP->SetValue( cfg->m_ExportIdf.no_dnp );
62
65
66 m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
67 wxString tmpStr;
68 tmpStr << m_XRef;
69 m_IDF_Xref->SetValue( tmpStr );
70 tmpStr = wxT( "" );
71 tmpStr << m_YRef;
72 m_IDF_Yref->SetValue( tmpStr );
73
74 if( m_AutoAdjust )
75 {
76 m_IDF_RefUnitChoice->Enable( false );
77 m_IDF_Xref->Enable( false );
78 m_IDF_Yref->Enable( false );
79 }
80 else
81 {
82 m_IDF_RefUnitChoice->Enable( true );
83 m_IDF_Xref->Enable( true );
84 m_IDF_Yref->Enable( true );
85 }
86
88
89 // Now all widgets have the size fixed, call FinishDialogSettings
91 }
92
94 {
95 m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
96
97 PCBNEW_SETTINGS* cfg = nullptr;
98
99 try
100 {
102 }
103 catch( const std::runtime_error& e )
104 {
105 wxFAIL_MSG( e.what() );
106 }
107
108 if( cfg )
109 {
113 cfg->m_ExportIdf.ref_x = m_XRef;
114 cfg->m_ExportIdf.ref_y = m_YRef;
115
117 cfg->m_ExportIdf.no_dnp = m_cbRemoveDNP->GetValue();
118 }
119 }
120
122 {
123 return m_rbUnitSelection->GetSelection() == 1;
124 }
125
126 wxFilePickerCtrl* FilePicker()
127 {
128 return m_filePickerIDF;
129 }
130
132 {
133 return m_IDF_RefUnitChoice->GetSelection();
134 }
135
136 double GetXRef()
137 {
139 }
140
141 double GetYRef()
142 {
144 }
145
147 {
148 return m_cbRemoveUnspecified->GetValue();
149 }
150
152 {
153 return m_cbRemoveDNP->GetValue();
154 }
155
157 {
158 return m_cbAutoAdjustOffset->GetValue();
159 }
160
161 void OnAutoAdjustOffset( wxCommandEvent& event )
162 {
163 if( GetAutoAdjustOffset() )
164 {
165 m_IDF_RefUnitChoice->Enable( false );
166 m_IDF_Xref->Enable( false );
167 m_IDF_Yref->Enable( false );
168 }
169 else
170 {
171 m_IDF_RefUnitChoice->Enable( true );
172 m_IDF_Xref->Enable( true );
173 m_IDF_Yref->Enable( true );
174 }
175
176 event.Skip();
177 }
178
179 bool TransferDataFromWindow() override;
180};
181
182
184{
185 wxFileName fn = m_filePickerIDF->GetPath();
186
187 if( fn.FileExists() )
188 {
189 wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
190 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
191 dlg.SetOKLabel( _( "Overwrite" ) );
192 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
193
194 return ( dlg.ShowModal() == wxID_OK );
195 }
196
197 return true;
198}
199
200
201void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
202{
203 // Build default output file name
204 wxString path = GetLastPath( LAST_PATH_IDF );
205
206 if( path.IsEmpty() )
207 {
208 wxFileName brdFile = GetBoard()->GetFileName();
209 brdFile.SetExt( wxT( "emn" ) );
210 path = brdFile.GetFullPath();
211 }
212
213 DIALOG_EXPORT_IDF3 dlg( this );
214 dlg.FilePicker()->SetPath( path );
215
216 if ( dlg.ShowModal() != wxID_OK )
217 return;
218
219 bool thou = dlg.GetThouOption();
220 double aXRef;
221 double aYRef;
222
223 if( dlg.GetAutoAdjustOffset() )
224 {
226
227 aXRef = bbox.Centre().x * pcbIUScale.MM_PER_IU;
228 aYRef = bbox.Centre().y * pcbIUScale.MM_PER_IU;
229 }
230 else
231 {
232 aXRef = dlg.GetXRef();
233 aYRef = dlg.GetYRef();
234
235 if( dlg.GetRefUnitsChoice() == 1 )
236 {
237 // selected reference unit is in inches
238 aXRef *= 25.4;
239 aYRef *= 25.4;
240 }
241
242 }
243
244 wxBusyCursor dummy;
245
246 wxString fullFilename = dlg.FilePicker()->GetPath();
247 SetLastPath( LAST_PATH_IDF, fullFilename );
248
249 if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef, !dlg.GetNoUnspecifiedOption(),
250 !dlg.GetNoDNPOption() ) )
251 {
252 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), fullFilename );
253 wxMessageBox( msg );
254 return;
255 }
256}
257
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:911
const wxString & GetFileName() const
Definition: board.h:319
Vec Centre() const
Definition: box2.h:87
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: 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
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.
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.
bool Export_IDF3(BOARD *aPcb, const wxString &aFullFileName, bool aUseThou, double aXRef, double aYRef, bool aIncludeUnspecified, bool aIncludeDNP)
Create an IDF3 compliant BOARD (*.emn) and LIBRARY (*.emp) file.
Definition: export_idf.cpp:608
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
#define _(s)
This file is part of the common library.
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:576
@ LAST_PATH_IDF
Definition: project_file.h:51
std::vector< FAB_LAYER_COLOR > dummy
const double MM_PER_IU
Definition: base_units.h:78