← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Change track width setting to dropbox

 

Hi all,

Mathias Grimmberger <mgri@xxxxxxxxxxxxx> writes:
>
> Hi Wayne,
>
> Wayne Stambaugh <stambaughw@xxxxxxxxx> writes:
>
>> Rather than add a wxComboBox to the WX_UNIT_BINDER object, wouldn't be
>> be cleaner to change wxTextCtrl* to wxTextEntry* which wxComboBox and
>> wxTextCtrl (along with several others) are derived from?
>
> Yes, of course, I will change that.

Here is the version of the patch with a nicer modification to
WX_UNIT_BINDER.

BTW, I noticed that displaying e.g. track width in inches feels somehow
strange, would people like having selected values displayed in mils?


Have fun,

MGri

diff --git a/common/wx_unit_binder.cpp b/common/wx_unit_binder.cpp
index 6a9236b32..c1f0fef50 100644
--- a/common/wx_unit_binder.cpp
+++ b/common/wx_unit_binder.cpp
@@ -24,7 +24,7 @@
 
 #include <wx/stattext.h>
 #include <wx/sizer.h>
-#include <wx/textctrl.h>
+#include <wx/textentry.h>
 #include <limits>
 #include <base_units.h>
 #include <wx/valnum.h>
@@ -33,9 +33,9 @@
 
 #include "wx_unit_binder.h"
 
-WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput,
+WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextEntry* aTextInput,
                                 wxStaticText* aUnitLabel, wxSpinButton* aSpinButton ) :
-    m_textCtrl( aTextInput ),
+    m_textEntry( aTextInput ),
     m_unitLabel( aUnitLabel ),
     m_units( g_UserUnit ),
     m_step( 1 ),
@@ -43,7 +43,7 @@ WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput,
     m_max( 1 )
 {
     // Use the currently selected units
-    m_textCtrl->SetValue( wxT( "0" ) );
+    m_textEntry->SetValue( wxT( "0" ) );
     m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
 }
 
@@ -57,7 +57,7 @@ void WX_UNIT_BINDER::SetValue( int aValue )
 {
     wxString s = StringFromValue( m_units, aValue, false );
 
-    m_textCtrl->SetValue( s );
+    m_textEntry->SetValue( s );
 
     m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
 }
@@ -65,7 +65,7 @@ void WX_UNIT_BINDER::SetValue( int aValue )
 
 int WX_UNIT_BINDER::GetValue() const
 {
-    wxString s = m_textCtrl->GetValue();
+    wxString s = m_textEntry->GetValue();
 
     return ValueFromString( m_units, s );
 }
@@ -75,12 +75,14 @@ bool WX_UNIT_BINDER::Valid() const
 {
     double dummy;
 
-    return m_textCtrl->GetValue().ToDouble( &dummy );
+    return m_textEntry->GetValue().ToDouble( &dummy );
 }
 
 
 void WX_UNIT_BINDER::Enable( bool aEnable )
 {
-    m_textCtrl->Enable( aEnable );
+    wxWindow* wxWin = dynamic_cast<wxWindow*> ( m_textEntry );
+    wxWin->Enable( aEnable );
     m_unitLabel->Enable( aEnable );
 }
+
diff --git a/include/wx_unit_binder.h b/include/wx_unit_binder.h
index ad4741d56..7639c8494 100644
--- a/include/wx_unit_binder.h
+++ b/include/wx_unit_binder.h
@@ -28,7 +28,7 @@
 #include <common.h>
 #include <wx/spinbutt.h>
 
-class wxTextCtrl;
+class wxTextEntry;
 class wxSpinButton;
 class wxStaticText;
 
@@ -39,11 +39,11 @@ public:
     /**
      * Constructor.
      * @param aParent is the parent window.
-     * @param aTextInput is the text input widget used to edit the given value.
+     * @param aTextInput is the text input widget used to edit the given value (wxTextCtrl, wxComboBox, ...).
      * @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, wxTextCtrl* aTextInput, wxStaticText* aUnitLabel, wxSpinButton* aSpinButton = NULL );
+    WX_UNIT_BINDER( wxWindow* aParent, wxTextEntry* aTextInput, wxStaticText* aUnitLabel, wxSpinButton* aSpinButton = NULL );
 
     virtual ~WX_UNIT_BINDER();
 
@@ -77,7 +77,7 @@ protected:
     void onTextChanged( wxEvent& aEvent );
 
     ///> Text input control.
-    wxTextCtrl*   m_textCtrl;
+    wxTextEntry*   m_textEntry;
 
     ///> 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..28d4c1b30 100644
--- a/pcbnew/dialogs/dialog_track_via_properties.cpp
+++ b/pcbnew/dialogs/dialog_track_via_properties.cpp
@@ -204,6 +204,13 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen
         setCommonVal( trackEndY, m_TrackEndYCtrl, m_trackEndY );
         setCommonVal( trackWidth, m_TrackWidthCtrl, m_trackWidth );
 
+        for( unsigned ii = 0; ii < aParent->GetDesignSettings().m_TrackWidthList.size(); ii++ )
+        {
+            int width = aParent->GetDesignSettings().m_TrackWidthList[ii];
+            wxString msg = StringFromValue( g_UserUnit, width, false );
+            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..14e15518c 100644
--- a/pcbnew/dialogs/dialog_track_via_properties.h
+++ b/pcbnew/dialogs/dialog_track_via_properties.h
@@ -59,14 +59,14 @@ private:
     ///> Checks if the dialog values are correct.
     bool check() const;
 
-    ///> Sets wxTextCtrl to the value stored in boost::optional<T> or "<...>" if it is not available.
+    ///> Sets wxTextEntry to the value stored in boost::optional<T> or "<...>" if it is not available.
     template<typename T>
-        void setCommonVal( const boost::optional<T>& aVal, wxTextCtrl* aTxtCtrl, WX_UNIT_BINDER& aBinder )
+        void setCommonVal( const boost::optional<T>& aVal, wxTextEntry* aTxtEntry, WX_UNIT_BINDER& aBinder )
     {
         if( aVal )
             aBinder.SetValue( *aVal );
         else
-            aTxtCtrl->SetValue( "<...>" );
+            aTxtEntry->SetValue( "<...>" );
     }
 
     ///> Selected items to be modified.
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

References