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>
28#include <dialog_export_idf.h>
29#include <pcbnew_settings.h>
30#include <project/project_file.h> // LAST_PATH_TYPE
31#include <kidialog.h>
32
33
35 DIALOG_EXPORT_IDF3_BASE( aEditFrame ),
36 m_editFrame( aEditFrame )
37{
38 SetFocus();
39
40 auto cfg = m_editFrame->GetPcbNewSettings();
41
42 m_idfThouOpt = cfg->m_ExportIdf.units_mils;
43 m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 );
44 m_AutoAdjust = cfg->m_ExportIdf.auto_adjust;
45 m_RefUnits = cfg->m_ExportIdf.ref_units;
46 m_XRef = cfg->m_ExportIdf.ref_x;
47 m_YRef = cfg->m_ExportIdf.ref_y;
48
49 m_cbRemoveUnspecified->SetValue( cfg->m_ExportIdf.no_unspecified );
50 m_cbRemoveDNP->SetValue( cfg->m_ExportIdf.no_dnp );
51
54
55 m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
56 wxString tmpStr;
57 tmpStr << m_XRef;
58 m_IDF_Xref->SetValue( tmpStr );
59 tmpStr = wxT( "" );
60 tmpStr << m_YRef;
61 m_IDF_Yref->SetValue( tmpStr );
62
63 if( m_AutoAdjust )
64 {
65 m_IDF_RefUnitChoice->Enable( false );
66 m_IDF_Xref->Enable( false );
67 m_IDF_Yref->Enable( false );
68 }
69 else
70 {
71 m_IDF_RefUnitChoice->Enable( true );
72 m_IDF_Xref->Enable( true );
73 m_IDF_Yref->Enable( true );
74 }
75
77
78 // Now all widgets have the size fixed, call FinishDialogSettings
80}
81
82
84{
85 m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
86
87 PCBNEW_SETTINGS* cfg = nullptr;
88
89 try
90 {
92 }
93 catch( const std::runtime_error& e )
94 {
95 wxFAIL_MSG( e.what() );
96 }
97
98 if( cfg )
99 {
103 cfg->m_ExportIdf.ref_x = m_XRef;
104 cfg->m_ExportIdf.ref_y = m_YRef;
105
107 cfg->m_ExportIdf.no_dnp = m_cbRemoveDNP->GetValue();
108 }
109}
110
111
112void DIALOG_EXPORT_IDF3::OnAutoAdjustOffset( wxCommandEvent& event )
113{
114 if( GetAutoAdjustOffset() )
115 {
116 m_IDF_RefUnitChoice->Enable( false );
117 m_IDF_Xref->Enable( false );
118 m_IDF_Yref->Enable( false );
119 }
120 else
121 {
122 m_IDF_RefUnitChoice->Enable( true );
123 m_IDF_Xref->Enable( true );
124 m_IDF_Yref->Enable( true );
125 }
126
127 event.Skip();
128}
129
130
132{
133 wxFileName fn = m_filePickerIDF->GetPath();
134
135 if( fn.FileExists() )
136 {
137 wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
138 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
139 dlg.SetOKLabel( _( "Overwrite" ) );
140 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
141
142 return ( dlg.ShowModal() == wxID_OK );
143 }
144
145 return true;
146}
147
148
149void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
150{
151 // Build default output file name
152 wxString path = GetLastPath( LAST_PATH_IDF );
153
154 if( path.IsEmpty() )
155 {
156 wxFileName brdFile = GetBoard()->GetFileName();
157 brdFile.SetExt( wxT( "emn" ) );
158 path = brdFile.GetFullPath();
159 }
160
161 DIALOG_EXPORT_IDF3 dlg( this );
162 dlg.FilePicker()->SetPath( path );
163
164 if ( dlg.ShowModal() != wxID_OK )
165 return;
166
167 bool thou = dlg.GetThouOption();
168 double aXRef;
169 double aYRef;
170
171 if( dlg.GetAutoAdjustOffset() )
172 {
174
175 aXRef = bbox.Centre().x * pcbIUScale.MM_PER_IU;
176 aYRef = bbox.Centre().y * pcbIUScale.MM_PER_IU;
177 }
178 else
179 {
180 aXRef = dlg.GetXRef();
181 aYRef = dlg.GetYRef();
182
183 if( dlg.GetRefUnitsChoice() == 1 )
184 {
185 // selected reference unit is in inches
186 aXRef *= 25.4;
187 aYRef *= 25.4;
188 }
189
190 }
191
192 wxBusyCursor dummy;
193
194 wxString fullFilename = dlg.FilePicker()->GetPath();
195 SetLastPath( LAST_PATH_IDF, fullFilename );
196
197 if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef, !dlg.GetNoUnspecifiedOption(),
198 !dlg.GetNoDNPOption() ) )
199 {
200 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), fullFilename );
201 wxMessageBox( msg );
202 return;
203 }
204}
205
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:929
const wxString & GetFileName() const
Definition: board.h:327
constexpr Vec Centre() const
Definition: box2.h:97
Class DIALOG_EXPORT_IDF3_BASE.
wxFilePickerCtrl * m_filePickerIDF
wxFilePickerCtrl * FilePicker()
bool TransferDataFromWindow() override
void OnAutoAdjustOffset(wxCommandEvent &event)
PCB_EDIT_FRAME * m_editFrame
DIALOG_EXPORT_IDF3(PCB_EDIT_FRAME *aEditFrame)
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...
int ShowModal() override
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.
@ LAST_PATH_IDF
Definition: project_file.h:52
std::vector< FAB_LAYER_COLOR > dummy
const double MM_PER_IU
Definition: base_units.h:78