From d38c9b205fcb441a1b5f13301666c64a4b511479 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 7 Apr 2015 15:19:30 +0200 Subject: [PATCH] Extend max number of units per package: fix incorrect unit string for unit >= 52. Fix unit list limited to 26 in dialof edit compinent in schematic..cpp lib_pin.cpp: in 4 functions, use an unsigned param instead of int, for a better code. --- eeschema/class_libentry.cpp | 5 +++-- .../dialog_edit_component_in_schematic.cpp | 7 ++----- eeschema/eeschema_id.h | 13 +++++++++++-- eeschema/lib_pin.cpp | 19 ++++++++++--------- eeschema/lib_pin.h | 4 ++-- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 3c4d5da3e5..698e54e5aa 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -284,15 +284,16 @@ wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator ) // use one letter if letter = A .. Z or a ... z, and 2 letters otherwise // first letter is expected to be 'A' or 'a' (i.e. 26 letters are available) int u; + aUnit -= 1; // Unit number starts to 1. now to 0. - while( aUnit > 26 ) // more than one letter are needed + while( aUnit >= 26 ) // more than one letter are needed { u = aUnit / 26; subRef << wxChar( m_subpartFirstId + u -1 ); aUnit %= 26; } - u = m_subpartFirstId + aUnit - 1; + u = m_subpartFirstId + aUnit; subRef << wxChar( u ); } diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index b22c426880..1ed992db3d 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -958,14 +958,11 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() if( unitcount < 1 ) unitcount = 1; - if( unitcount > 26 ) - unitcount = 26; - unitChoice->Clear(); - for( int ii=0; ii < unitcount; ii++ ) + for( int ii = 1; ii <= unitcount; ii++ ) { - unitChoice->Append( wxString::Format( "%c", "?ABCDEFGHIJKLMNOPQRSTUVWXYZ"[ ii + 1 ] ) ); + unitChoice->Append( LIB_PART::SubReference( ii, false ) ); } // For components with multiple parts per package, set the unit selection diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index e3ab44b628..899c300c25 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -40,6 +40,13 @@ */ #define MAX_SELECT_ITEM_IDS 10 +/** + * The maximum number of units per package. + * Increase this number if that ever becomes a problem, but remember + * the popup menu to select a given unit could be not easy to use. + */ +#define MAX_UNIT_COUNT_PER_PACKAGE 64 + /** * Command IDs for the schematic editor. @@ -129,8 +136,10 @@ enum id_eeschema_frm // Unit select context menus command IDs. ID_POPUP_SCH_SELECT_UNIT_CMP, ID_POPUP_SCH_SELECT_UNIT1, - // ... leave room for 52 IDs , to select one unit among 52 in popup menu - ID_POPUP_SCH_SELECT_UNIT_CMP_MAX = ID_POPUP_SCH_SELECT_UNIT1 + 52, + // ... leave room for MAX_UNIT_COUNT_PER_PACKAGE IDs , + // to select one unit among MAX_UNIT_COUNT_PER_PACKAGE in popup menu + ID_POPUP_SCH_SELECT_UNIT_CMP_MAX = ID_POPUP_SCH_SELECT_UNIT1 + + MAX_UNIT_COUNT_PER_PACKAGE, // Change text type context menu command IDs. ID_POPUP_SCH_CHANGE_TYPE_TEXT, diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 501eb4ebba..4ac66f25ba 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -122,7 +122,7 @@ static const BITMAP_DEF iconsPinsElectricalType[] = #define PIN_ELECTRICAL_TYPE_CNT DIM( iconsPinsElectricalType ) -const wxString LIB_PIN::GetCanonicalElectricalTypeName( int aType ) +const wxString LIB_PIN::GetCanonicalElectricalTypeName( unsigned aType ) { // These strings are the canonical name of the electrictal type // Not translated, no space in name, only ASCII chars. @@ -144,7 +144,7 @@ const wxString LIB_PIN::GetCanonicalElectricalTypeName( int aType ) wxT( "???" ) }; - if( aType < 0 || aType > int( PIN_NMAX ) ) + if( aType > PIN_NMAX ) aType = PIN_NMAX; return msgPinElectricType[ aType ]; @@ -155,7 +155,7 @@ const wxString LIB_PIN::GetCanonicalElectricalTypeName( int aType ) // Note: the strings are *not* static because they are translated and must be built // on the fly, to be properly translated -static const wxString getPinOrientationName( int aPinOrientationCode ) +static const wxString getPinOrientationName( unsigned aPinOrientationCode ) { /* Note: The following name lists are sentence capitalized per the GNOME UI * standards for list controls. Please do not change the capitalization @@ -170,13 +170,13 @@ static const wxString getPinOrientationName( int aPinOrientationCode ) wxT( "???" ) }; - if( aPinOrientationCode < 0 || aPinOrientationCode > int( PIN_ORIENTATION_CNT ) ) + if( aPinOrientationCode > PIN_ORIENTATION_CNT ) aPinOrientationCode = PIN_ORIENTATION_CNT; return pin_orientation_names[ aPinOrientationCode ]; } -const wxString LIB_PIN::GetElectricalTypeName( int aPinsElectricalType ) +const wxString LIB_PIN::GetElectricalTypeName( unsigned aPinsElectricalType ) { const wxString pin_electrical_type_names[] = { // Keep these translated strings not static @@ -194,13 +194,13 @@ const wxString LIB_PIN::GetElectricalTypeName( int aPinsElectricalType ) wxT( "???" ) }; - if( aPinsElectricalType < 0 || aPinsElectricalType > int( PIN_ELECTRICAL_TYPE_CNT ) ) + if( aPinsElectricalType > PIN_ELECTRICAL_TYPE_CNT ) aPinsElectricalType = PIN_ELECTRICAL_TYPE_CNT; return pin_electrical_type_names[ aPinsElectricalType ]; } -static const wxString getPinStyleName( int aPinsStyle ) +static const wxString getPinStyleName( unsigned aPinsStyle ) { const wxString pin_style_names[] = { // Keep these translated strings not static @@ -216,7 +216,7 @@ static const wxString getPinStyleName( int aPinsStyle ) wxT( "???" ) }; - if( aPinsStyle < 0 || aPinsStyle > int( PIN_STYLE_CNT ) ) + if( aPinsStyle > PIN_STYLE_CNT ) aPinsStyle = PIN_STYLE_CNT; return pin_style_names[ aPinsStyle ]; @@ -1979,6 +1979,7 @@ void LIB_PIN::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) RED ) ); int styleCodeIndex = GetStyleCodeIndex( m_shape ); + if( styleCodeIndex >= 0 ) text = getPinStyleName( styleCodeIndex ); else @@ -1997,7 +1998,7 @@ void LIB_PIN::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) text = StringFromValue( g_UserUnit, m_length, true ); aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text, MAGENTA ) ); - text = getPinOrientationName( GetOrientationCodeIndex( m_orientation ) ); + text = getPinOrientationName( (unsigned) GetOrientationCodeIndex( m_orientation ) ); aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text, DARKMAGENTA ) ); } diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index cc9f3d0eb2..430cec9582 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -272,7 +272,7 @@ public: * @param aType is the electrical type (see enum ElectricPinType ) * @return The electrical name for a pin type (see enun MsgPinElectricType for names). */ - static const wxString GetCanonicalElectricalTypeName( int aType ); + static const wxString GetCanonicalElectricalTypeName( unsigned aType ); /** * return a string giving the electrical type of the pin. @@ -289,7 +289,7 @@ public: * @param aType is the electrical type (see enum ElectricPinType ) * @return The electrical name of the pin (see enun MsgPinElectricType for names). */ - static const wxString GetElectricalTypeName( int aType ); + static const wxString GetElectricalTypeName( unsigned aType ); /** * return a translated string for messages giving the electrical type of the pin.