kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #19758
PATCH: fix broken workflows due to recent changes in IDF exporter
The attached patch adds an option to use a user-specified grid reference
for the IDF export (new behavior) or an automatically calculated reference
point (legacy behavior). This change was made to accommodate requests
for the legacy behavior; apparently my new improved features have broken
people's workflows again. :)
- Cirilo
=== modified file 'pcbnew/dialogs/dialog_export_idf.cpp'
--- pcbnew/dialogs/dialog_export_idf.cpp 2015-08-13 13:13:34 +0000
+++ pcbnew/dialogs/dialog_export_idf.cpp 2015-08-14 08:25:20 +0000
@@ -29,11 +29,13 @@
#include <kiface_i.h>
#include <pcbnew.h>
#include <class_board.h>
+#include <convert_from_iu.h>
// IDF export header generated by wxFormBuilder
#include <dialog_export_idf_base.h>
#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 @@
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,13 @@
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_IDF_RefUnitChoice->SetSelection( m_RefUnits );
wxString tmpStr;
tmpStr << m_XRef;
@@ -86,6 +92,19 @@
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 +118,7 @@
{
m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
m_config->Write( OPTKEY_IDF_THOU, m_idfThouOpt );
+ m_config->Write( OPTKEY_IDF_REF_AUTOADJ, AutoAdjustOffset() );
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 +149,29 @@
return DoubleValueFromString( UNSCALED_UNITS, m_IDF_Yref->GetValue() );
}
+ bool AutoAdjustOffset()
+ {
+ return m_cbAutoAdjustOffset->GetValue();
+ }
+
+ virtual void m_AutoAdjustOffset( wxMouseEvent& event )
+ {
+ if( AutoAdjustOffset() )
+ {
+ m_IDF_RefUnitChoice->Enable( true );
+ m_IDF_Xref->Enable( true );
+ m_IDF_Yref->Enable( true );
+ }
+ else
+ {
+ m_IDF_RefUnitChoice->Enable( false );
+ m_IDF_Xref->Enable( false );
+ m_IDF_Yref->Enable( false );
+ }
+
+ event.Skip( false );
+ }
+
};
@@ -151,14 +194,28 @@
return;
bool thou = dlg.GetThouOption();
- double aXRef = dlg.GetXRef();
- double aYRef = dlg.GetYRef();
-
- if( dlg.GetRefUnitsChoice() == 1 )
- {
- // selected reference unit is in inches
- aXRef *= 25.4;
- aYRef *= 25.4;
+ double aXRef;
+ double aYRef;
+
+ if( dlg.AutoAdjustOffset() )
+ {
+ 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;
=== modified file 'pcbnew/dialogs/dialog_export_idf_base.cpp'
--- pcbnew/dialogs/dialog_export_idf_base.cpp 2015-08-13 13:13:34 +0000
+++ pcbnew/dialogs/dialog_export_idf_base.cpp 2015-08-14 08:27:48 +0000
@@ -33,6 +33,9 @@
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 @@
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 );
@@ -110,8 +113,14 @@
bSizerIDFFile->Fit( this );
this->Centre( wxBOTH );
+
+ // Connect Events
+ m_cbAutoAdjustOffset->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_EXPORT_IDF3_BASE::m_AutoAdjustOffset ), NULL, this );
}
DIALOG_EXPORT_IDF3_BASE::~DIALOG_EXPORT_IDF3_BASE()
{
+ // Disconnect Events
+ m_cbAutoAdjustOffset->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_EXPORT_IDF3_BASE::m_AutoAdjustOffset ), NULL, this );
+
}
=== modified file 'pcbnew/dialogs/dialog_export_idf_base.fbp'
--- pcbnew/dialogs/dialog_export_idf_base.fbp 2015-08-13 13:13:34 +0000
+++ pcbnew/dialogs/dialog_export_idf_base.fbp 2015-08-14 08:27:47 +0000
@@ -366,6 +366,94 @@
<event name="OnUpdateUI"></event>
</object>
</object>
+ <object class="sizeritem" expanded="1">
+ <property name="border">5</property>
+ <property name="flag">wxALL</property>
+ <property name="proportion">0</property>
+ <object class="wxCheckBox" expanded="1">
+ <property name="BottomDockable">1</property>
+ <property name="LeftDockable">1</property>
+ <property name="RightDockable">1</property>
+ <property name="TopDockable">1</property>
+ <property name="aui_layer"></property>
+ <property name="aui_name"></property>
+ <property name="aui_position"></property>
+ <property name="aui_row"></property>
+ <property name="best_size"></property>
+ <property name="bg"></property>
+ <property name="caption"></property>
+ <property name="caption_visible">1</property>
+ <property name="center_pane">0</property>
+ <property name="checked">0</property>
+ <property name="close_button">1</property>
+ <property name="context_help"></property>
+ <property name="context_menu">1</property>
+ <property name="default_pane">0</property>
+ <property name="dock">Dock</property>
+ <property name="dock_fixed">0</property>
+ <property name="docking">Left</property>
+ <property name="enabled">1</property>
+ <property name="fg"></property>
+ <property name="floatable">1</property>
+ <property name="font"></property>
+ <property name="gripper">0</property>
+ <property name="hidden">0</property>
+ <property name="id">wxID_ANY</property>
+ <property name="label">Auto Adjust</property>
+ <property name="max_size"></property>
+ <property name="maximize_button">0</property>
+ <property name="maximum_size"></property>
+ <property name="min_size"></property>
+ <property name="minimize_button">0</property>
+ <property name="minimum_size"></property>
+ <property name="moveable">1</property>
+ <property name="name">m_cbAutoAdjustOffset</property>
+ <property name="pane_border">1</property>
+ <property name="pane_position"></property>
+ <property name="pane_size"></property>
+ <property name="permission">protected</property>
+ <property name="pin_button">1</property>
+ <property name="pos"></property>
+ <property name="resize">Resizable</property>
+ <property name="show">1</property>
+ <property name="size"></property>
+ <property name="style">wxCHK_2STATE</property>
+ <property name="subclass"></property>
+ <property name="toolbar_pane">0</property>
+ <property name="tooltip"></property>
+ <property name="validator_data_type"></property>
+ <property name="validator_style">wxFILTER_NONE</property>
+ <property name="validator_type">wxDefaultValidator</property>
+ <property name="validator_variable"></property>
+ <property name="window_extra_style"></property>
+ <property name="window_name"></property>
+ <property name="window_style"></property>
+ <event name="OnChar"></event>
+ <event name="OnCheckBox"></event>
+ <event name="OnEnterWindow"></event>
+ <event name="OnEraseBackground"></event>
+ <event name="OnKeyDown"></event>
+ <event name="OnKeyUp"></event>
+ <event name="OnKillFocus"></event>
+ <event name="OnLeaveWindow"></event>
+ <event name="OnLeftDClick"></event>
+ <event name="OnLeftDown"></event>
+ <event name="OnLeftUp">m_AutoAdjustOffset</event>
+ <event name="OnMiddleDClick"></event>
+ <event name="OnMiddleDown"></event>
+ <event name="OnMiddleUp"></event>
+ <event name="OnMotion"></event>
+ <event name="OnMouseEvents"></event>
+ <event name="OnMouseWheel"></event>
+ <event name="OnPaint"></event>
+ <event name="OnRightDClick"></event>
+ <event name="OnRightDown"></event>
+ <event name="OnRightUp"></event>
+ <event name="OnSetFocus"></event>
+ <event name="OnSize"></event>
+ <event name="OnUpdateUI"></event>
+ </object>
+ </object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
@@ -970,7 +1058,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
- <property name="selection">1</property>
+ <property name="selection">0</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxRA_SPECIFY_COLS</property>
=== modified file 'pcbnew/dialogs/dialog_export_idf_base.h'
--- pcbnew/dialogs/dialog_export_idf_base.h 2015-08-13 13:13:34 +0000
+++ pcbnew/dialogs/dialog_export_idf_base.h 2015-08-14 07:57:45 +0000
@@ -21,6 +21,7 @@
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/filepicker.h>
+#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>
@@ -43,6 +44,7 @@
wxStaticText* m_txtBrdFile;
wxFilePickerCtrl* m_filePickerIDF;
wxStaticText* m_staticText2;
+ wxCheckBox* m_cbAutoAdjustOffset;
wxStaticText* m_staticText5;
wxChoice* m_IDF_RefUnitChoice;
wxStaticText* m_staticText3;
@@ -54,6 +56,10 @@
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;
+
+ // Virtual event handlers, overide them in your derived class
+ virtual void m_AutoAdjustOffset( wxMouseEvent& event ) { event.Skip(); }
+
public:
=== modified file 'pcbnew/exporters/export_idf.cpp'
--- pcbnew/exporters/export_idf.cpp 2015-08-13 13:13:34 +0000
+++ pcbnew/exporters/export_idf.cpp 2015-08-14 08:14:35 +0000
@@ -36,6 +36,7 @@
#include <idf_parser.h>
#include <3d_struct.h>
#include <build_version.h>
+#include <convert_from_iu.h>
#ifndef PCBNEW
#define PCBNEW // needed to define the right value of Millimeter2iu(x)
@@ -540,7 +541,7 @@
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 )
Follow ups