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 The KiCad Developers, see AUTHORS.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>
31#include <project/project_file.h> // LAST_PATH_TYPE
32#include <kidialog.h>
33
34
36 DIALOG_EXPORT_IDF3_BASE( aEditFrame ),
37 m_idfThouOpt( false ),
38 m_AutoAdjust( false ),
39 m_RefUnits( 0 ),
40 m_XRef( 0.0 ),
41 m_YRef( 0.0 ),
42 m_editFrame( aEditFrame )
43{
44 SetFocus();
45
47 {
48 m_idfThouOpt = cfg->m_ExportIdf.units_mils;
49 m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 );
50 m_AutoAdjust = cfg->m_ExportIdf.auto_adjust;
51 m_RefUnits = cfg->m_ExportIdf.ref_units;
52 m_XRef = cfg->m_ExportIdf.ref_x;
53 m_YRef = cfg->m_ExportIdf.ref_y;
54
55 m_cbRemoveUnspecified->SetValue( cfg->m_ExportIdf.no_unspecified );
56 m_cbRemoveDNP->SetValue( cfg->m_ExportIdf.no_dnp );
57 }
58
61
62 m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
63 wxString tmpStr;
64 tmpStr << m_XRef;
65 m_IDF_Xref->SetValue( tmpStr );
66 tmpStr = wxT( "" );
67 tmpStr << m_YRef;
68 m_IDF_Yref->SetValue( tmpStr );
69
70 if( m_AutoAdjust )
71 {
72 m_IDF_RefUnitChoice->Enable( false );
73 m_IDF_Xref->Enable( false );
74 m_IDF_Yref->Enable( false );
75 }
76 else
77 {
78 m_IDF_RefUnitChoice->Enable( true );
79 m_IDF_Xref->Enable( true );
80 m_IDF_Yref->Enable( true );
81 }
82
84
85 // Now all widgets have the size fixed, call FinishDialogSettings
87}
88
89
91{
92 m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
93
95 {
96 cfg->m_ExportIdf.units_mils = m_idfThouOpt;
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 cfg->m_ExportIdf.no_unspecified = m_cbRemoveUnspecified->GetValue();
103 cfg->m_ExportIdf.no_dnp = m_cbRemoveDNP->GetValue();
104 }
105}
106
107
108void DIALOG_EXPORT_IDF3::OnAutoAdjustOffset( wxCommandEvent& event )
109{
110 if( GetAutoAdjustOffset() )
111 {
112 m_IDF_RefUnitChoice->Enable( false );
113 m_IDF_Xref->Enable( false );
114 m_IDF_Yref->Enable( false );
115 }
116 else
117 {
118 m_IDF_RefUnitChoice->Enable( true );
119 m_IDF_Xref->Enable( true );
120 m_IDF_Yref->Enable( true );
121 }
122
123 event.Skip();
124}
125
126
128{
129 wxFileName fn = m_filePickerIDF->GetPath();
130
131 if( fn.FileExists() )
132 {
133 wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
134 KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
135 dlg.SetOKLabel( _( "Overwrite" ) );
136 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
137
138 return ( dlg.ShowModal() == wxID_OK );
139 }
140
141 return true;
142}
143
144
146{
148
149 // Build default output file name
150 wxString path = m_frame->GetLastPath( LAST_PATH_IDF );
151
152 if( path.IsEmpty() )
153 {
154 wxFileName brdFile = board->GetFileName();
155 brdFile.SetExt( wxT( "emn" ) );
156 path = brdFile.GetFullPath();
157 }
158
160 dlg.FilePicker()->SetPath( path );
161
162 if ( dlg.ShowModal() != wxID_OK )
163 return 0;
164
165 bool thou = dlg.GetThouOption();
166 double aXRef;
167 double aYRef;
168
169 if( dlg.GetAutoAdjustOffset() )
170 {
172 aXRef = bbox.Centre().x * pcbIUScale.MM_PER_IU;
173 aYRef = bbox.Centre().y * pcbIUScale.MM_PER_IU;
174 }
175 else
176 {
177 aXRef = dlg.GetXRef();
178 aYRef = dlg.GetYRef();
179
180 if( dlg.GetRefUnitsChoice() == 1 )
181 {
182 // selected reference unit is in inches
183 aXRef *= 25.4;
184 aYRef *= 25.4;
185 }
186 }
187
188 wxBusyCursor dummy;
189
190 wxString fullFilename = dlg.FilePicker()->GetPath();
191 m_frame->SetLastPath( LAST_PATH_IDF, fullFilename );
192
193 if( !m_frame->Export_IDF3( board, fullFilename, thou, aXRef, aYRef, !dlg.GetNoUnspecifiedOption(),
194 !dlg.GetNoDNPOption() ) )
195 {
196 wxMessageBox( wxString::Format( _( "Failed to create file '%s'." ), fullFilename ) );
197 }
198
199 return 0;
200}
201
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
int ExportIDF(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:980
const wxString & GetFileName() const
Definition: board.h:354
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:50
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition: kidialog.cpp:51
int ShowModal() override
Definition: kidialog.cpp:95
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.
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:612
BOARD * board() const
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer and display it in the wxTextCtrl.
Generic, UI-independent tool event.
Definition: tool_event.h:168
#define _(s)
This file is part of the common library.
@ LAST_PATH_IDF
Definition: project_file.h:54
std::vector< FAB_LAYER_COLOR > dummy
const double MM_PER_IU
Definition: base_units.h:80