KiCad PCB EDA Suite
dialog_export_idf.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2013-2015 Cirilo Bernardo
9  * Copyright (C) 2013-2017 KiCad Developers, see change_log.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <pcb_edit_frame.h>
30 #include <kiface_i.h>
31 #include <pcbnew.h>
32 #include <class_board.h>
33 #include <convert_to_biu.h>
34 #include <widgets/text_ctrl_eval.h>
35 
36 // IDF export header generated by wxFormBuilder
37 #include <dialog_export_idf_base.h>
38 #include <pcb_edit_frame.h>
39 #include <confirm.h>
40 
41 #define OPTKEY_IDF_THOU wxT( "IDFExportThou" )
42 #define OPTKEY_IDF_REF_AUTOADJ wxT( "IDFRefAutoAdj" )
43 #define OPTKEY_IDF_REF_UNITS wxT( "IDFRefUnits" )
44 #define OPTKEY_IDF_REF_X wxT( "IDFRefX" )
45 #define OPTKEY_IDF_REF_Y wxT( "IDFRefY" )
46 
47 
49 {
50 private:
51  wxConfigBase* m_config;
52  bool m_idfThouOpt; // remember last preference for units in THOU
53  bool m_AutoAdjust; // remember last Reference Point AutoAdjust setting
54  int m_RefUnits; // remember last units for Reference Point
55  double m_XRef; // remember last X Reference Point
56  double m_YRef; // remember last Y Reference Point
57 
58 public:
60  DIALOG_EXPORT_IDF3_BASE( parent )
61  {
62  m_config = Kiface().KifaceSettings();
63  SetFocus();
64  m_idfThouOpt = false;
65  m_config->Read( OPTKEY_IDF_THOU, &m_idfThouOpt );
66  m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 );
67  m_config->Read( OPTKEY_IDF_REF_AUTOADJ, &m_AutoAdjust, false );
68  m_config->Read( OPTKEY_IDF_REF_UNITS, &m_RefUnits, 0 );
69  m_config->Read( OPTKEY_IDF_REF_X, &m_XRef, 0.0 );
70  m_config->Read( OPTKEY_IDF_REF_Y, &m_YRef, 0.0 );
71 
72  m_cbAutoAdjustOffset->SetValue( m_AutoAdjust );
73  m_cbAutoAdjustOffset->Bind( wxEVT_CHECKBOX, &DIALOG_EXPORT_IDF3::OnAutoAdjustOffset, this );
74 
75  m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
76  wxString tmpStr;
77  tmpStr << m_XRef;
78  m_IDF_Xref->SetValue( tmpStr );
79  tmpStr = wxT( "" );
80  tmpStr << m_YRef;
81  m_IDF_Yref->SetValue( tmpStr );
82 
83  if( m_AutoAdjust )
84  {
85  m_IDF_RefUnitChoice->Enable( false );
86  m_IDF_Xref->Enable( false );
87  m_IDF_Yref->Enable( false );
88  }
89  else
90  {
91  m_IDF_RefUnitChoice->Enable( true );
92  m_IDF_Xref->Enable( true );
93  m_IDF_Yref->Enable( true );
94  }
95 
96  m_sdbSizerOK->SetDefault();
97 
98  // Now all widgets have the size fixed, call FinishDialogSettings
100  }
101 
103  {
104  m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
105  m_config->Write( OPTKEY_IDF_THOU, m_idfThouOpt );
106  m_config->Write( OPTKEY_IDF_REF_AUTOADJ, GetAutoAdjustOffset() );
107  m_config->Write( OPTKEY_IDF_REF_UNITS, m_IDF_RefUnitChoice->GetSelection() );
108  m_config->Write( OPTKEY_IDF_REF_X, m_IDF_Xref->GetValue() );
109  m_config->Write( OPTKEY_IDF_REF_Y, m_IDF_Yref->GetValue() );
110  }
111 
113  {
114  return m_rbUnitSelection->GetSelection() == 1;
115  }
116 
117  wxFilePickerCtrl* FilePicker()
118  {
119  return m_filePickerIDF;
120  }
121 
123  {
124  return m_IDF_RefUnitChoice->GetSelection();
125  }
126 
127  double GetXRef()
128  {
129  return DoubleValueFromString( UNSCALED_UNITS, m_IDF_Xref->GetValue() );
130  }
131 
132  double GetYRef()
133  {
134  return DoubleValueFromString( UNSCALED_UNITS, m_IDF_Yref->GetValue() );
135  }
136 
138  {
139  return m_cbAutoAdjustOffset->GetValue();
140  }
141 
142  void OnAutoAdjustOffset( wxCommandEvent& event )
143  {
144  if( GetAutoAdjustOffset() )
145  {
146  m_IDF_RefUnitChoice->Enable( false );
147  m_IDF_Xref->Enable( false );
148  m_IDF_Yref->Enable( false );
149  }
150  else
151  {
152  m_IDF_RefUnitChoice->Enable( true );
153  m_IDF_Xref->Enable( true );
154  m_IDF_Yref->Enable( true );
155  }
156 
157  event.Skip();
158  }
159 
160  bool TransferDataFromWindow() override;
161 };
162 
163 
165 {
166  wxFileName fn = m_filePickerIDF->GetPath();
167 
168  if( fn.FileExists() )
169  {
170  wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
171  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
172  dlg.SetOKLabel( _( "Overwrite" ) );
173  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
174 
175  return ( dlg.ShowModal() == wxID_OK );
176  }
177 
178  return true;
179 }
180 
181 
182 void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
183 {
184  wxFileName fn;
185 
186  // Build default file name
187  fn = GetBoard()->GetFileName();
188  fn.SetExt( wxT( "emn" ) );
189 
190  DIALOG_EXPORT_IDF3 dlg( this );
191  dlg.FilePicker()->SetPath( fn.GetFullPath() );
192 
193  if ( dlg.ShowModal() != wxID_OK )
194  return;
195 
196  bool thou = dlg.GetThouOption();
197  double aXRef;
198  double aYRef;
199 
200  if( dlg.GetAutoAdjustOffset() )
201  {
203 
204  aXRef = bbox.Centre().x * MM_PER_IU;
205  aYRef = bbox.Centre().y * MM_PER_IU;
206  }
207  else
208  {
209  aXRef = dlg.GetXRef();
210  aYRef = dlg.GetYRef();
211 
212  if( dlg.GetRefUnitsChoice() == 1 )
213  {
214  // selected reference unit is in inches
215  aXRef *= 25.4;
216  aYRef *= 25.4;
217  }
218 
219  }
220 
221  wxBusyCursor dummy;
222 
223  wxString fullFilename = dlg.FilePicker()->GetPath();
224 
225  if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef ) )
226  {
227  wxString msg = _( "Unable to create " ) + fullFilename;
228  wxMessageBox( msg );
229  return;
230  }
231 }
void OnExportIDF3(wxCommandEvent &event)
Function OnExportIDF3 will export the current BOARD to a IDFv3 board and lib files.
#define OPTKEY_IDF_THOU
wxFilePickerCtrl * m_filePickerIDF
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
This file is part of the common library.
void OnAutoAdjustOffset(wxCommandEvent &event)
Class BOARD to handle a board.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
#define OPTKEY_IDF_REF_X
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:804
bool TransferDataFromWindow() override
const wxString & GetFileName() const
Definition: class_board.h:237
#define OPTKEY_IDF_REF_UNITS
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:302
Class DIALOG_EXPORT_IDF3_BASE.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
#define OPTKEY_IDF_REF_Y
wxPoint Centre() const
Definition: eda_rect.h:60
wxFilePickerCtrl * FilePicker()
BOARD * GetBoard()
wxConfigBase * m_config
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
DIALOG_EXPORT_IDF3(PCB_EDIT_FRAME *parent)
#define OPTKEY_IDF_REF_AUTOADJ