KiCad PCB EDA Suite
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-2019 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 auto cfg = m_parent->GetPcbNewSettings();
95
97 cfg->m_ExportIdf.auto_adjust = m_AutoAdjust;
98 cfg->m_ExportIdf.ref_units = m_RefUnits;
99 cfg->m_ExportIdf.ref_x = m_XRef;
100 cfg->m_ExportIdf.ref_y = m_YRef;
101 }
102
104 {
105 return m_rbUnitSelection->GetSelection() == 1;
106 }
107
108 wxFilePickerCtrl* FilePicker()
109 {
110 return m_filePickerIDF;
111 }
112
114 {
115 return m_IDF_RefUnitChoice->GetSelection();
116 }
117
118 double GetXRef()
119 {
121 }
122
123 double GetYRef()
124 {
126 }
127
129 {
130 return m_cbAutoAdjustOffset->GetValue();
131 }
132
133 void OnAutoAdjustOffset( wxCommandEvent& event )
134 {
135 if( GetAutoAdjustOffset() )
136 {
137 m_IDF_RefUnitChoice->Enable( false );
138 m_IDF_Xref->Enable( false );
139 m_IDF_Yref->Enable( false );
140 }
141 else
142 {
143 m_IDF_RefUnitChoice->Enable( true );
144 m_IDF_Xref->Enable( true );
145 m_IDF_Yref->Enable( true );
146 }
147
148 event.Skip();
149 }
150
151 bool TransferDataFromWindow() override;
152};
153
154
156{
157 wxFileName fn = m_filePickerIDF->GetPath();
158
159 if( fn.FileExists() )
160 {
161 wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
162 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
163 dlg.SetOKLabel( _( "Overwrite" ) );
164 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
165
166 return ( dlg.ShowModal() == wxID_OK );
167 }
168
169 return true;
170}
171
172
173void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
174{
175 // Build default output file name
176 wxString path = GetLastPath( LAST_PATH_IDF );
177
178 if( path.IsEmpty() )
179 {
180 wxFileName brdFile = GetBoard()->GetFileName();
181 brdFile.SetExt( wxT( "emn" ) );
182 path = brdFile.GetFullPath();
183 }
184
185 DIALOG_EXPORT_IDF3 dlg( this );
186 dlg.FilePicker()->SetPath( path );
187
188 if ( dlg.ShowModal() != wxID_OK )
189 return;
190
191 bool thou = dlg.GetThouOption();
192 double aXRef;
193 double aYRef;
194
195 if( dlg.GetAutoAdjustOffset() )
196 {
198
199 aXRef = bbox.Centre().x * pcbIUScale.MM_PER_IU;
200 aYRef = bbox.Centre().y * pcbIUScale.MM_PER_IU;
201 }
202 else
203 {
204 aXRef = dlg.GetXRef();
205 aYRef = dlg.GetYRef();
206
207 if( dlg.GetRefUnitsChoice() == 1 )
208 {
209 // selected reference unit is in inches
210 aXRef *= 25.4;
211 aYRef *= 25.4;
212 }
213
214 }
215
216 wxBusyCursor dummy;
217
218 wxString fullFilename = dlg.FilePicker()->GetPath();
219 SetLastPath( LAST_PATH_IDF, fullFilename );
220
221 if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef ) )
222 {
223 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), fullFilename );
224 wxMessageBox( msg );
225 return;
226 }
227}
228
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:821
const wxString & GetFileName() const
Definition: board.h:302
Vec Centre() const
Definition: box2.h:70
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: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
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:595
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)
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:451
@ LAST_PATH_IDF
Definition: project_file.h:50
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
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
const double MM_PER_IU
Definition: base_units.h:79