← Back to team overview

kicad-developers team mailing list archive

[PATCH] Change track width setting to dropbox

 

Hi all,

I think it would be nice if the track width setting in the track
properties dialog used a combobox, so one could either enter a free value
or select one of the values set up in the design rules.

The appended patch implements this.

Question1: I had to extend WX_UNIT_BINDER to also accept a wxComboBox,
maybe it would be better to split it into two classes?

Question2: the dropdown also contains the netclass width, since this is
somewhat redundant should it be removed?

Something similar could also be done in the via properties for the
via/drill diameter if there is interest.


Have fun,

MGri


diff --git a/common/wx_unit_binder.cpp b/common/wx_unit_binder.cpp
index 6a9236b32..97a0ab410 100644
--- a/common/wx_unit_binder.cpp
+++ b/common/wx_unit_binder.cpp
@@ -25,6 +25,7 @@
 #include <wx/stattext.h>
 #include <wx/sizer.h>
 #include <wx/textctrl.h>
+#include <wx/combobox.h>
 #include <limits>
 #include <base_units.h>
 #include <wx/valnum.h>
@@ -36,6 +37,7 @@
 WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput,
                                 wxStaticText* aUnitLabel, wxSpinButton* aSpinButton ) :
     m_textCtrl( aTextInput ),
+    m_comboCtrl( NULL ),
     m_unitLabel( aUnitLabel ),
     m_units( g_UserUnit ),
     m_step( 1 ),
@@ -48,6 +50,22 @@ WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput,
 }
 
 
+WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxComboBox* aComboBox,
+                                wxStaticText* aUnitLabel, wxSpinButton* aSpinButton ) :
+    m_textCtrl( NULL ),
+    m_comboCtrl( aComboBox ),
+    m_unitLabel( aUnitLabel ),
+    m_units( g_UserUnit ),
+    m_step( 1 ),
+    m_min( 0 ),
+    m_max( 1 )
+{
+    // Use the currently selected units
+    m_comboCtrl->SetValue( wxT( "0" ) );
+    m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
+}
+
+
 WX_UNIT_BINDER::~WX_UNIT_BINDER()
 {
 }
@@ -57,7 +75,14 @@ void WX_UNIT_BINDER::SetValue( int aValue )
 {
     wxString s = StringFromValue( m_units, aValue, false );
 
-    m_textCtrl->SetValue( s );
+    if ( m_textCtrl )
+    {
+        m_textCtrl->SetValue( s );
+    } 
+    else
+    {
+        m_comboCtrl->SetValue( s );
+    }
 
     m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
 }
@@ -65,7 +90,16 @@ void WX_UNIT_BINDER::SetValue( int aValue )
 
 int WX_UNIT_BINDER::GetValue() const
 {
-    wxString s = m_textCtrl->GetValue();
+    wxString s;
+
+    if ( m_textCtrl )
+    {
+        s = m_textCtrl->GetValue();
+    }
+    else
+    {
+        s = m_comboCtrl->GetValue();
+    }
 
     return ValueFromString( m_units, s );
 }
@@ -75,12 +109,27 @@ bool WX_UNIT_BINDER::Valid() const
 {
     double dummy;
 
-    return m_textCtrl->GetValue().ToDouble( &dummy );
+    if ( m_textCtrl )
+    {
+        return m_textCtrl->GetValue().ToDouble( &dummy );
+    }
+    else
+    {
+        return m_comboCtrl->GetValue().ToDouble( &dummy );
+    }
 }
 
 
 void WX_UNIT_BINDER::Enable( bool aEnable )
 {
-    m_textCtrl->Enable( aEnable );
+    if ( m_textCtrl )
+    {
+        m_textCtrl->Enable( aEnable );
+    }
+    else
+    {
+        m_comboCtrl->Enable( aEnable );
+    }
     m_unitLabel->Enable( aEnable );
 }
+
diff --git a/include/wx_unit_binder.h b/include/wx_unit_binder.h
index ad4741d56..4e07bc32b 100644
--- a/include/wx_unit_binder.h
+++ b/include/wx_unit_binder.h
@@ -29,6 +29,7 @@
 #include <wx/spinbutt.h>
 
 class wxTextCtrl;
+class wxComboBox;
 class wxSpinButton;
 class wxStaticText;
 
@@ -45,6 +46,15 @@ public:
      */
     WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput, wxStaticText* aUnitLabel, wxSpinButton* aSpinButton = NULL );
 
+    /**
+     * Constructor.
+     * @param aParent is the parent window.
+     * @param aComboBox is the combo box widget used to edit the given value.
+     * @param aUnitLabel is the units label displayed next to the text field.
+     * @param aSpinButton is an optional spin button (for adjusting the input value)
+     */
+    WX_UNIT_BINDER( wxWindow* aParent, wxComboBox* aComboBox, wxStaticText* aUnitLabel, wxSpinButton* aSpinButton = NULL );
+
     virtual ~WX_UNIT_BINDER();
 
     /**
@@ -78,6 +88,8 @@ protected:
 
     ///> Text input control.
     wxTextCtrl*   m_textCtrl;
+    ///> Combobox control.
+    wxComboBox*   m_comboCtrl;
 
     ///> Label showing currently used units.
     wxStaticText* m_unitLabel;
diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp
index 4a2c69a26..7768c1ea6 100644
--- a/pcbnew/dialogs/dialog_track_via_properties.cpp
+++ b/pcbnew/dialogs/dialog_track_via_properties.cpp
@@ -204,6 +204,15 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen
         setCommonVal( trackEndY, m_TrackEndYCtrl, m_trackEndY );
         setCommonVal( trackWidth, m_TrackWidthCtrl, m_trackWidth );
 
+        wxString msg;
+
+        for( unsigned ii = 0; ii < aParent->GetDesignSettings().m_TrackWidthList.size(); ii++ )
+        {
+            int size = aParent->GetDesignSettings().m_TrackWidthList[ii];
+            msg.Printf( _( "%.3f" ), To_User_Unit( g_UserUnit, size ) );
+            m_TrackWidthCtrl->Append( msg );
+        }
+
         m_TrackLayerCtrl->SetLayersHotkeys( false );
         m_TrackLayerCtrl->SetLayerSet( LSET::AllNonCuMask() );
         m_TrackLayerCtrl->SetBoardFrame( aParent );
diff --git a/pcbnew/dialogs/dialog_track_via_properties.h b/pcbnew/dialogs/dialog_track_via_properties.h
index 3be7d4d77..24f295bd3 100644
--- a/pcbnew/dialogs/dialog_track_via_properties.h
+++ b/pcbnew/dialogs/dialog_track_via_properties.h
@@ -69,6 +69,16 @@ private:
             aTxtCtrl->SetValue( "<...>" );
     }
 
+    ///> Sets wxComboBox to the value stored in boost::optional<T> or "<...>" if it is not available.
+    template<typename T>
+        void setCommonVal( const boost::optional<T>& aVal, wxComboBox* aComboCtrl, WX_UNIT_BINDER& aBinder )
+    {
+        if( aVal )
+            aBinder.SetValue( *aVal );
+        else
+            aComboCtrl->SetValue( "<...>" );
+    }
+
     ///> Selected items to be modified.
     const SELECTION& m_items;
 
diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.cpp b/pcbnew/dialogs/dialog_track_via_properties_base.cpp
index 7cc9c2e5c..5af355aba 100644
--- a/pcbnew/dialogs/dialog_track_via_properties_base.cpp
+++ b/pcbnew/dialogs/dialog_track_via_properties_base.cpp
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Jun 17 2015)
+// C++ code generated with wxFormBuilder (version Aug 20 2017)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -65,7 +65,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgTrackLeftGridSizer->Add( m_TrackStartXLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_TrackStartXCtrl = new wxTextCtrl( m_sbTrackSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_TrackStartXCtrl->SetMaxLength( 0 ); 
 	fgTrackLeftGridSizer->Add( m_TrackStartXCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
 	
 	m_TrackStartXUnit = new wxStaticText( m_sbTrackSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -77,7 +76,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgTrackLeftGridSizer->Add( m_TrackStartYLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_TrackStartYCtrl = new wxTextCtrl( m_sbTrackSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_TrackStartYCtrl->SetMaxLength( 0 ); 
 	fgTrackLeftGridSizer->Add( m_TrackStartYCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_TrackStartYUnit = new wxStaticText( m_sbTrackSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -89,7 +87,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgTrackLeftGridSizer->Add( m_TrackEndXLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_TrackEndXCtrl = new wxTextCtrl( m_sbTrackSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_TrackEndXCtrl->SetMaxLength( 0 ); 
 	fgTrackLeftGridSizer->Add( m_TrackEndXCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_TrackEndXUnit = new wxStaticText( m_sbTrackSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -101,7 +98,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgTrackLeftGridSizer->Add( m_TrackEndYLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_TrackEndYCtrl = new wxTextCtrl( m_sbTrackSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_TrackEndYCtrl->SetMaxLength( 0 ); 
 	fgTrackLeftGridSizer->Add( m_TrackEndYCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_TrackEndYUnit = new wxStaticText( m_sbTrackSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -123,8 +119,7 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	m_TrackWidthLabel->Wrap( -1 );
 	fgTrackRightSizer->Add( m_TrackWidthLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxTOP|wxBOTTOM|wxRIGHT, 5 );
 	
-	m_TrackWidthCtrl = new wxTextCtrl( m_sbTrackSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_TrackWidthCtrl->SetMaxLength( 0 ); 
+	m_TrackWidthCtrl = new wxComboBox( m_sbTrackSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); 
 	fgTrackRightSizer->Add( m_TrackWidthCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_TrackWidthUnit = new wxStaticText( m_sbTrackSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -168,7 +163,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgViaLeftSizer->Add( m_ViaXLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_ViaXCtrl = new wxTextCtrl( m_sbViaSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_ViaXCtrl->SetMaxLength( 0 ); 
 	fgViaLeftSizer->Add( m_ViaXCtrl, 0, wxEXPAND, 5 );
 	
 	m_ViaXUnit = new wxStaticText( m_sbViaSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -180,7 +174,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgViaLeftSizer->Add( m_ViaYLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_ViaYCtrl = new wxTextCtrl( m_sbViaSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_ViaYCtrl->SetMaxLength( 0 ); 
 	fgViaLeftSizer->Add( m_ViaYCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_ViaYUnit = new wxStaticText( m_sbViaSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -203,7 +196,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgViaRightSizer->Add( m_ViaDiameterLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_ViaDiameterCtrl = new wxTextCtrl( m_sbViaSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_ViaDiameterCtrl->SetMaxLength( 0 ); 
 	fgViaRightSizer->Add( m_ViaDiameterCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_ViaDiameterUnit = new wxStaticText( m_sbViaSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -215,7 +207,6 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa
 	fgViaRightSizer->Add( m_ViaDrillLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
 	
 	m_ViaDrillCtrl = new wxTextCtrl( m_sbViaSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_ViaDrillCtrl->SetMaxLength( 0 ); 
 	fgViaRightSizer->Add( m_ViaDrillCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_ViaDrillUnit = new wxStaticText( m_sbViaSizer->GetStaticBox(), wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.fbp b/pcbnew/dialogs/dialog_track_via_properties_base.fbp
index a886bb710..c285ca20d 100644
--- a/pcbnew/dialogs/dialog_track_via_properties_base.fbp
+++ b/pcbnew/dialogs/dialog_track_via_properties_base.fbp
@@ -1728,7 +1728,7 @@
                                     <property name="border">5</property>
                                     <property name="flag">wxALIGN_CENTER_VERTICAL|wxEXPAND</property>
                                     <property name="proportion">0</property>
-                                    <object class="wxTextCtrl" expanded="0">
+                                    <object class="wxComboBox" expanded="0">
                                         <property name="BottomDockable">1</property>
                                         <property name="LeftDockable">1</property>
                                         <property name="RightDockable">1</property>
@@ -1742,6 +1742,7 @@
                                         <property name="caption"></property>
                                         <property name="caption_visible">1</property>
                                         <property name="center_pane">0</property>
+                                        <property name="choices"></property>
                                         <property name="close_button">1</property>
                                         <property name="context_help"></property>
                                         <property name="context_menu">1</property>
@@ -1759,7 +1760,6 @@
                                         <property name="max_size"></property>
                                         <property name="maximize_button">0</property>
                                         <property name="maximum_size"></property>
-                                        <property name="maxlength">0</property>
                                         <property name="min_size"></property>
                                         <property name="minimize_button">0</property>
                                         <property name="minimum_size"></property>
@@ -1772,6 +1772,7 @@
                                         <property name="pin_button">1</property>
                                         <property name="pos"></property>
                                         <property name="resize">Resizable</property>
+                                        <property name="selection">-1</property>
                                         <property name="show">1</property>
                                         <property name="size"></property>
                                         <property name="style"></property>
@@ -1787,6 +1788,7 @@
                                         <property name="window_name"></property>
                                         <property name="window_style"></property>
                                         <event name="OnChar"></event>
+                                        <event name="OnCombobox"></event>
                                         <event name="OnEnterWindow"></event>
                                         <event name="OnEraseBackground"></event>
                                         <event name="OnKeyDown"></event>
@@ -1810,8 +1812,6 @@
                                         <event name="OnSize"></event>
                                         <event name="OnText"></event>
                                         <event name="OnTextEnter"></event>
-                                        <event name="OnTextMaxLen"></event>
-                                        <event name="OnTextURL"></event>
                                         <event name="OnUpdateUI"></event>
                                     </object>
                                 </object>
diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.h b/pcbnew/dialogs/dialog_track_via_properties_base.h
index 721d9144e..2a0fa250b 100644
--- a/pcbnew/dialogs/dialog_track_via_properties_base.h
+++ b/pcbnew/dialogs/dialog_track_via_properties_base.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Jun 17 2015)
+// C++ code generated with wxFormBuilder (version Aug 20 2017)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -65,7 +65,7 @@ class DIALOG_TRACK_VIA_PROPERTIES_BASE : public DIALOG_SHIM
 		wxStaticText* m_TrackEndYUnit;
 		wxStaticLine* m_trackStaticLine;
 		wxStaticText* m_TrackWidthLabel;
-		wxTextCtrl* m_TrackWidthCtrl;
+		wxComboBox* m_TrackWidthCtrl;
 		wxStaticText* m_TrackWidthUnit;
 		wxCheckBox* m_trackNetclass;
 		wxStaticText* m_TrackLayerLabel;

Follow ups