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  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <wxPcbStruct.h>
29 #include <kiface_i.h>
30 #include <pcbnew.h>
31 #include <class_board.h>
32 #include <convert_to_biu.h>
33 
34 // IDF export header generated by wxFormBuilder
35 #include <dialog_export_idf_base.h>
36 #include <wxPcbStruct.h>
37 
38 #define OPTKEY_IDF_THOU wxT( "IDFExportThou" )
39 #define OPTKEY_IDF_REF_AUTOADJ wxT( "IDFRefAutoAdj" )
40 #define OPTKEY_IDF_REF_UNITS wxT( "IDFRefUnits" )
41 #define OPTKEY_IDF_REF_X wxT( "IDFRefX" )
42 #define OPTKEY_IDF_REF_Y wxT( "IDFRefY" )
43 
44 
46 {
47 private:
49  wxConfigBase* m_config;
50  bool m_idfThouOpt; // remember last preference for units in THOU
51  bool m_AutoAdjust; // remember last Reference Point AutoAdjust setting
52  int m_RefUnits; // remember last units for Reference Point
53  double m_XRef; // remember last X Reference Point
54  double m_YRef; // remember last Y Reference Point
55 
56 public:
58  DIALOG_EXPORT_IDF3_BASE( parent )
59  {
60  m_parent = parent;
61  m_config = Kiface().KifaceSettings();
62  SetFocus();
63  m_idfThouOpt = false;
64  m_config->Read( OPTKEY_IDF_THOU, &m_idfThouOpt );
65  m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 );
66  m_config->Read( OPTKEY_IDF_REF_AUTOADJ, &m_AutoAdjust, false );
67  m_config->Read( OPTKEY_IDF_REF_UNITS, &m_RefUnits, 0 );
68  m_config->Read( OPTKEY_IDF_REF_X, &m_XRef, 0.0 );
69  m_config->Read( OPTKEY_IDF_REF_Y, &m_YRef, 0.0 );
70 
71  m_cbAutoAdjustOffset->SetValue( m_AutoAdjust );
72  m_cbAutoAdjustOffset->Bind( wxEVT_CHECKBOX, &DIALOG_EXPORT_IDF3::OnAutoAdjustOffset, this );
73 
74  m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
75  wxString tmpStr;
76  tmpStr << m_XRef;
77  m_IDF_Xref->SetValue( tmpStr );
78  tmpStr = wxT( "" );
79  tmpStr << m_YRef;
80  m_IDF_Yref->SetValue( tmpStr );
81 
82  if( m_AutoAdjust )
83  {
84  m_IDF_RefUnitChoice->Enable( false );
85  m_IDF_Xref->Enable( false );
86  m_IDF_Yref->Enable( false );
87  }
88  else
89  {
90  m_IDF_RefUnitChoice->Enable( true );
91  m_IDF_Xref->Enable( true );
92  m_IDF_Yref->Enable( true );
93  }
94 
95  m_sdbSizerOK->SetDefault();
96 
97  // Now all widgets have the size fixed, call FinishDialogSettings
99  }
100 
102  {
103  m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
104  m_config->Write( OPTKEY_IDF_THOU, m_idfThouOpt );
105  m_config->Write( OPTKEY_IDF_REF_AUTOADJ, GetAutoAdjustOffset() );
106  m_config->Write( OPTKEY_IDF_REF_UNITS, m_IDF_RefUnitChoice->GetSelection() );
107  m_config->Write( OPTKEY_IDF_REF_X, m_IDF_Xref->GetValue() );
108  m_config->Write( OPTKEY_IDF_REF_Y, m_IDF_Yref->GetValue() );
109  }
110 
112  {
113  return m_rbUnitSelection->GetSelection() == 1;
114  }
115 
116  wxFilePickerCtrl* FilePicker()
117  {
118  return m_filePickerIDF;
119  }
120 
122  {
123  return m_IDF_RefUnitChoice->GetSelection();
124  }
125 
126  double GetXRef()
127  {
128  return DoubleValueFromString( UNSCALED_UNITS, m_IDF_Xref->GetValue() );
129  }
130 
131  double GetYRef()
132  {
133  return DoubleValueFromString( UNSCALED_UNITS, m_IDF_Yref->GetValue() );
134  }
135 
137  {
138  return m_cbAutoAdjustOffset->GetValue();
139  }
140 
141  void OnAutoAdjustOffset( wxCommandEvent& event )
142  {
143  if( GetAutoAdjustOffset() )
144  {
145  m_IDF_RefUnitChoice->Enable( false );
146  m_IDF_Xref->Enable( false );
147  m_IDF_Yref->Enable( false );
148  }
149  else
150  {
151  m_IDF_RefUnitChoice->Enable( true );
152  m_IDF_Xref->Enable( true );
153  m_IDF_Yref->Enable( true );
154  }
155 
156  event.Skip();
157  }
158 
159 };
160 
161 
166 void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
167 {
168  wxFileName fn;
169 
170  // Build default file name
171  fn = GetBoard()->GetFileName();
172  fn.SetExt( wxT( "emn" ) );
173 
174  DIALOG_EXPORT_IDF3 dlg( this );
175  dlg.FilePicker()->SetPath( fn.GetFullPath() );
176 
177  if ( dlg.ShowModal() != wxID_OK )
178  return;
179 
180  bool thou = dlg.GetThouOption();
181  double aXRef;
182  double aYRef;
183 
184  if( dlg.GetAutoAdjustOffset() )
185  {
187 
188  aXRef = bbox.Centre().x * MM_PER_IU;
189  aYRef = bbox.Centre().y * MM_PER_IU;
190  }
191  else
192  {
193  aXRef = dlg.GetXRef();
194  aYRef = dlg.GetYRef();
195 
196  if( dlg.GetRefUnitsChoice() == 1 )
197  {
198  // selected reference unit is in inches
199  aXRef *= 25.4;
200  aYRef *= 25.4;
201  }
202 
203  }
204 
205  wxBusyCursor dummy;
206 
207  wxString fullFilename = dlg.FilePicker()->GetPath();
208 
209  if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef ) )
210  {
211  wxString msg = _( "Unable to create " ) + fullFilename;
212  wxMessageBox( msg );
213  return;
214  }
215 }
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
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...
bool Export_IDF3(BOARD *aPcb, const wxString &aFullFileName, bool aUseThou, double aXRef, double aYRef)
Function Export_IDF3 Creates an IDF3 compliant BOARD (*.emn) and LIBRARY (*.emp) file.
Definition: export_idf.cpp:553
BOARD * GetBoard() const
#define OPTKEY_IDF_REF_X
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:839
const wxString & GetFileName() const
Definition: class_board.h:237
#define OPTKEY_IDF_REF_UNITS
Class DIALOG_EXPORT_IDF3_BASE.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
#define OPTKEY_IDF_REF_Y
wxPoint Centre() const
wxFilePickerCtrl * FilePicker()
wxConfigBase * m_config
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.
DIALOG_EXPORT_IDF3(PCB_EDIT_FRAME *parent)
#define OPTKEY_IDF_REF_AUTOADJ
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:301
PCB_EDIT_FRAME * m_parent