← Back to team overview

kicad-developers team mailing list archive

Re: PATCH: fix broken workflows due to recent changes in IDF exporter

 

OK, Here is attempt #2 to implement a legacy behavior option in IDF Export.
This is an ugly workaround but it should provide the correct behavior.
Please
test on MSWin and provide feedback whether it works or not.

- Cirilo


On Sat, Aug 15, 2015 at 7:16 AM, Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
wrote:

> Thanks Maurice,
>
>  There is obviously something strange with wxWidgets. I will need to
> read more and work out what the problem is. In this case I think
> wxFormBuilder is part of the problem; I can't use it to create a
> dispatcher for 'OnChange' and instead have had to use 'OnLeftMouseUp',
> and this seems to behave differently between MSWin and Linux.
>
> - Cirilo
>
>
> On Fri, Aug 14, 2015 at 10:04 PM, easyw <easyw@xxxxxxxxxxxx> wrote:
>
>> Hi Cirilo,
>>
>> I tried the patch in windows 8 64, and I have the following problems:
>> if I click to Auto Adjust,
>> 1. I got not only X,Y ref and Units disabled but also the other objects
>> in the dialog and the check box remains unchecked
>> (I cannot click on OK, Cancel until I click to kicad main window, not the
>> dialog nor the pcbnew)
>> 3. after retrning to the dialog I can click OK, but the export still
>> consider X,Y ref values...
>>
>> I forced in dialog_export_idf.cpp the option to get
>>    GetBoard()->ComputeBoundingBox( true );
>> to simulate the Auto Adjust checked,
>> then the export returns to the standard old way...
>>
>> thank you for support
>> Maurice
>>
>>
>> On 14/08/2015 10.32, Cirilo Bernardo wrote:
>>
>>> 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
>>>
>>>
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~kicad-developers
>>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~kicad-developers
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>>
>
=== 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 22:38:49 +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" )
@@ -53,6 +55,8 @@
 bool Export_IDF3( BOARD *aPcb, const wxString & aFullFileName, bool aUseThou,
                   double aXRef, double aYRef );
 
+void OnAutoAdjustCheck( wxCommandEvent& event );
+
 
 class DIALOG_EXPORT_IDF3: public DIALOG_EXPORT_IDF3_BASE
 {
@@ -60,6 +64,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 +79,14 @@
         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, OnAutoAdjustCheck, wxID_ANY, wxID_ANY, this );
+
         m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
         wxString tmpStr;
         tmpStr << m_XRef;
@@ -86,6 +95,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 )
@@ -97,8 +119,10 @@
 
     ~DIALOG_EXPORT_IDF3()
     {
+        m_cbAutoAdjustOffset->Unbind( wxEVT_CHECKBOX, OnAutoAdjustCheck, wxID_ANY, wxID_ANY, this );
         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 +153,29 @@
         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 +198,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.GetAutoAdjustOffset() )
+    {
+        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;
@@ -172,3 +233,9 @@
         return;
     }
 }
+
+void OnAutoAdjustCheck( wxCommandEvent& event )
+{
+    DIALOG_EXPORT_IDF3* dlg = (DIALOG_EXPORT_IDF3*) event.GetEventUserData();
+    dlg->OnAutoAdjustOffset( event );
+}

=== 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 21:30:04 +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 );
 	
 	

=== 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 21:30:02 +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"></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 21:30:04 +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;

=== 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 )


References