diff --git a/pcbnew/dialogs/dialog_export_idf.cpp b/pcbnew/dialogs/dialog_export_idf.cpp index 1f76b71d5b..5878c3b93c 100644 --- a/pcbnew/dialogs/dialog_export_idf.cpp +++ b/pcbnew/dialogs/dialog_export_idf.cpp @@ -29,11 +29,13 @@ #include #include #include +#include // IDF export header generated by wxFormBuilder #include #define OPTKEY_IDF_THOU wxT( "IDFExportThou" ) +#define OPTKEY_IDF_REF_AUTOADJ wxT( "IDFRefAutoAdj" ) #define OPTKEY_IDF_REF_UNITS wxT( "IDFRefUnits" ) #define OPTKEY_IDF_REF_X wxT( "IDFRefX" ) #define OPTKEY_IDF_REF_Y wxT( "IDFRefY" ) @@ -60,6 +62,7 @@ private: PCB_EDIT_FRAME* m_parent; wxConfigBase* m_config; bool m_idfThouOpt; // remember last preference for units in THOU + bool m_AutoAdjust; // remember last Reference Point AutoAdjust setting int m_RefUnits; // remember last units for Reference Point double m_XRef; // remember last X Reference Point double m_YRef; // remember last Y Reference Point @@ -74,10 +77,14 @@ public: m_idfThouOpt = false; m_config->Read( OPTKEY_IDF_THOU, &m_idfThouOpt ); m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 ); + m_config->Read( OPTKEY_IDF_REF_AUTOADJ, &m_AutoAdjust, false ); m_config->Read( OPTKEY_IDF_REF_UNITS, &m_RefUnits, 0 ); m_config->Read( OPTKEY_IDF_REF_X, &m_XRef, 0.0 ); m_config->Read( OPTKEY_IDF_REF_Y, &m_YRef, 0.0 ); + m_cbAutoAdjustOffset->SetValue( m_AutoAdjust ); + m_cbAutoAdjustOffset->Bind( wxEVT_CHECKBOX, &DIALOG_EXPORT_IDF3::OnAutoAdjustOffset, this ); + m_IDF_RefUnitChoice->SetSelection( m_RefUnits ); wxString tmpStr; tmpStr << m_XRef; @@ -86,6 +93,19 @@ public: tmpStr << m_YRef; m_IDF_Yref->SetValue( tmpStr ); + if( m_AutoAdjust ) + { + m_IDF_RefUnitChoice->Enable( false ); + m_IDF_Xref->Enable( false ); + m_IDF_Yref->Enable( false ); + } + else + { + m_IDF_RefUnitChoice->Enable( true ); + m_IDF_Xref->Enable( true ); + m_IDF_Yref->Enable( true ); + } + wxWindow* button = FindWindowByLabel( wxT( "OK" ) ); if( button ) @@ -99,6 +119,7 @@ public: { m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1; m_config->Write( OPTKEY_IDF_THOU, m_idfThouOpt ); + m_config->Write( OPTKEY_IDF_REF_AUTOADJ, GetAutoAdjustOffset() ); m_config->Write( OPTKEY_IDF_REF_UNITS, m_IDF_RefUnitChoice->GetSelection() ); m_config->Write( OPTKEY_IDF_REF_X, m_IDF_Xref->GetValue() ); m_config->Write( OPTKEY_IDF_REF_Y, m_IDF_Yref->GetValue() ); @@ -129,6 +150,29 @@ public: return DoubleValueFromString( UNSCALED_UNITS, m_IDF_Yref->GetValue() ); } + bool GetAutoAdjustOffset() + { + return m_cbAutoAdjustOffset->GetValue(); + } + + void OnAutoAdjustOffset( wxCommandEvent& event ) + { + if( GetAutoAdjustOffset() ) + { + m_IDF_RefUnitChoice->Enable( false ); + m_IDF_Xref->Enable( false ); + m_IDF_Yref->Enable( false ); + } + else + { + m_IDF_RefUnitChoice->Enable( true ); + m_IDF_Xref->Enable( true ); + m_IDF_Yref->Enable( true ); + } + + event.Skip(); + } + }; @@ -151,14 +195,28 @@ void PCB_EDIT_FRAME::ExportToIDF3( wxCommandEvent& event ) return; bool thou = dlg.GetThouOption(); - double aXRef = dlg.GetXRef(); - double aYRef = dlg.GetYRef(); + double aXRef; + double aYRef; - if( dlg.GetRefUnitsChoice() == 1 ) + if( dlg.GetAutoAdjustOffset() ) { - // selected reference unit is in inches - aXRef *= 25.4; - aYRef *= 25.4; + EDA_RECT bbox = GetBoard()->ComputeBoundingBox( true ); + + aXRef = bbox.Centre().x * MM_PER_IU; + aYRef = bbox.Centre().y * MM_PER_IU; + } + else + { + aXRef = dlg.GetXRef(); + aYRef = dlg.GetYRef(); + + if( dlg.GetRefUnitsChoice() == 1 ) + { + // selected reference unit is in inches + aXRef *= 25.4; + aYRef *= 25.4; + } + } wxBusyCursor dummy; diff --git a/pcbnew/dialogs/dialog_export_idf_base.cpp b/pcbnew/dialogs/dialog_export_idf_base.cpp index c27052ffc3..bfde1a52a2 100644 --- a/pcbnew/dialogs/dialog_export_idf_base.cpp +++ b/pcbnew/dialogs/dialog_export_idf_base.cpp @@ -33,6 +33,9 @@ DIALOG_EXPORT_IDF3_BASE::DIALOG_EXPORT_IDF3_BASE( wxWindow* parent, wxWindowID i m_staticText2->Wrap( -1 ); bSizer3->Add( m_staticText2, 0, wxALL, 5 ); + m_cbAutoAdjustOffset = new wxCheckBox( this, wxID_ANY, _("Auto Adjust"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE ); + bSizer3->Add( m_cbAutoAdjustOffset, 0, wxALL, 5 ); + wxBoxSizer* bSizer6; bSizer6 = new wxBoxSizer( wxHORIZONTAL ); @@ -83,7 +86,7 @@ DIALOG_EXPORT_IDF3_BASE::DIALOG_EXPORT_IDF3_BASE( wxWindow* parent, wxWindowID i wxString m_rbUnitSelectionChoices[] = { _("Millimeters"), _("Mils") }; int m_rbUnitSelectionNChoices = sizeof( m_rbUnitSelectionChoices ) / sizeof( wxString ); m_rbUnitSelection = new wxRadioBox( this, wxID_ANY, _("Output Units:"), wxDefaultPosition, wxDefaultSize, m_rbUnitSelectionNChoices, m_rbUnitSelectionChoices, 1, wxRA_SPECIFY_COLS ); - m_rbUnitSelection->SetSelection( 1 ); + m_rbUnitSelection->SetSelection( 0 ); bSizer2->Add( m_rbUnitSelection, 0, wxALL, 5 ); diff --git a/pcbnew/dialogs/dialog_export_idf_base.fbp b/pcbnew/dialogs/dialog_export_idf_base.fbp index 0837b482bb..3af95875c1 100644 --- a/pcbnew/dialogs/dialog_export_idf_base.fbp +++ b/pcbnew/dialogs/dialog_export_idf_base.fbp @@ -366,6 +366,94 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Auto Adjust + + 0 + + + 0 + + 1 + m_cbAutoAdjustOffset + 1 + + + protected + 1 + + Resizable + 1 + + wxCHK_2STATE + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxEXPAND @@ -970,7 +1058,7 @@ 1 Resizable - 1 + 0 1 wxRA_SPECIFY_COLS diff --git a/pcbnew/dialogs/dialog_export_idf_base.h b/pcbnew/dialogs/dialog_export_idf_base.h index 89e6d03ba4..47ac6b68f3 100644 --- a/pcbnew/dialogs/dialog_export_idf_base.h +++ b/pcbnew/dialogs/dialog_export_idf_base.h @@ -21,6 +21,7 @@ class DIALOG_SHIM; #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ class DIALOG_EXPORT_IDF3_BASE : public DIALOG_SHIM wxStaticText* m_txtBrdFile; wxFilePickerCtrl* m_filePickerIDF; wxStaticText* m_staticText2; + wxCheckBox* m_cbAutoAdjustOffset; wxStaticText* m_staticText5; wxChoice* m_IDF_RefUnitChoice; wxStaticText* m_staticText3; diff --git a/pcbnew/exporters/export_idf.cpp b/pcbnew/exporters/export_idf.cpp index 51ab61738e..acb0d847d0 100644 --- a/pcbnew/exporters/export_idf.cpp +++ b/pcbnew/exporters/export_idf.cpp @@ -36,6 +36,7 @@ #include #include <3d_struct.h> #include +#include #ifndef PCBNEW #define PCBNEW // needed to define the right value of Millimeter2iu(x) @@ -540,7 +541,7 @@ bool Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, bool aUseThou, SetLocaleTo_C_standard(); bool ok = true; - double scale = 1e-6; // we must scale internal units to mm for IDF + double scale = MM_PER_IU; // we must scale internal units to mm for IDF IDF3::IDF_UNIT idfUnit; if( aUseThou )