From c4be74a9d06e8224ff41fb2e2485dd0a9cc6402a Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 15 Apr 2019 06:59:36 -0700 Subject: [PATCH] eeschema: Prevent invalid '0' element in components In the component, an m_unit/m_convert element is 1-indexed as opposed to the library where they are 0-indexed. The 0-index in the library is reserved for those elements that are shared across all conversion/unit whereas it is invalid for the component. Fixes: lp:1824764 * https://bugs.launchpad.net/kicad/+bug/1824764 --- eeschema/class_libentry.cpp | 2 +- .../dialogs/dialog_edit_component_in_schematic.cpp | 14 +++++++------- eeschema/getpart.cpp | 8 ++++---- eeschema/lib_draw_item.cpp | 6 ++---- eeschema/lib_draw_item.h | 5 ++++- eeschema/sch_component.cpp | 4 ++-- eeschema/viewlib_frame.cpp | 10 +++++----- eeschema/viewlibs.cpp | 4 ++-- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 0a96f849db..48eeddf086 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -986,7 +986,7 @@ bool LIB_PART::HasConversion() const { for( const LIB_ITEM& item : m_drawings ) { - if( item.m_Convert > 1 ) + if( item.m_Convert > LIB_ITEM::LIB_CONVERT::BASE ) return true; } diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 4d675374d3..8570831d7d 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -175,7 +175,7 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataToWindow() if( m_part != nullptr && m_part->HasConversion() ) { - if( m_cmp->GetConvert() > 1 ) + if( m_cmp->GetConvert() > LIB_ITEM::LIB_CONVERT::BASE ) m_cbAlternateSymbol->SetValue( true ); } else @@ -252,7 +252,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnBrowseLibrary( wxCommandEvent& event for( int ii = 1; ii <= entry->GetUnitCount(); ii++ ) m_unitChoice->Append( LIB_PART::SubReference( ii, false ) ); - if( unit < 0 || unit >= m_unitChoice->GetCount() ) + if( unit < 0 || static_cast( unit )>= m_unitChoice->GetCount() ) unit = 0; m_unitChoice->SetSelection( unit ); @@ -405,15 +405,15 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() ); // For symbols with multiple shapes (De Morgan representation) Set the selected shape: - int conversion = m_cbAlternateSymbol->IsEnabled() - ? m_cbAlternateSymbol->GetValue() - : 0; - m_cmp->SetConvert( conversion ); + if( m_cbAlternateSymbol->IsEnabled() && m_cbAlternateSymbol->GetValue() ) + m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::DEMORGAN ); + else + m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::BASE ); //Set the part selection in multiple part per package int unit_selection = m_unitChoice->IsEnabled() ? m_unitChoice->GetSelection() + 1 - : 0; + : 1; m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection ); m_cmp->SetUnit( unit_selection ); diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 13951995e5..062862f9db 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -372,14 +372,14 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* aComponent ) aComponent->SetConvert( aComponent->GetConvert() + 1 ); - // ensure m_Convert = 0, 1 or 2 - // 0 and 1 = shape 1 = not converted + // ensure m_Convert = 1 or 2 + // 1 = shape 1 = not converted // 2 = shape 2 = first converted shape // > 2 is not used but could be used for more shapes // like multiple shapes for a programmable component // When m_Convert = val max, return to the first shape - if( aComponent->GetConvert() > 2 ) - aComponent->SetConvert( 1 ); + if( aComponent->GetConvert() > LIB_ITEM::LIB_CONVERT::DEMORGAN ) + aComponent->SetConvert( LIB_ITEM::LIB_CONVERT::BASE ); // The alternate symbol may cause a change in the connection status so test the // connections so the connection indicators are drawn correctly. diff --git a/eeschema/lib_draw_item.cpp b/eeschema/lib_draw_item.cpp index 381ce9b392..83d8fe0261 100644 --- a/eeschema/lib_draw_item.cpp +++ b/eeschema/lib_draw_item.cpp @@ -68,11 +68,9 @@ void LIB_ITEM::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList ) aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) ); - if( m_Convert == 0 ) - msg = _( "All" ); - else if( m_Convert == 1 ) + if( m_Convert == LIB_ITEM::LIB_CONVERT::BASE ) msg = _( "no" ); - else if( m_Convert == 2 ) + else if( m_Convert == LIB_ITEM::LIB_CONVERT::DEMORGAN ) msg = _( "yes" ); else msg = wxT( "?" ); diff --git a/eeschema/lib_draw_item.h b/eeschema/lib_draw_item.h index 2d0e4f03f7..e3919638ae 100644 --- a/eeschema/lib_draw_item.h +++ b/eeschema/lib_draw_item.h @@ -92,7 +92,6 @@ class LIB_ITEM : public EDA_ITEM * @param aColor Draw color */ virtual void drawEditGraphics( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor ) {} - friend class LIB_PART; @@ -134,6 +133,10 @@ public: virtual ~LIB_ITEM() { } + + // Define the enums for basic + enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 }; + /** * Provide a user-consumable name of the object type. Perform localization when * called so that run-time language selection works. diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 028ba32c6b..369349f1e5 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -193,8 +193,8 @@ SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aComponent ) : void SCH_COMPONENT::Init( const wxPoint& pos ) { m_Pos = pos; - m_unit = 0; // In multi unit chip - which unit to draw. - m_convert = 0; // De Morgan Handling + m_unit = 1; // In multi unit chip - which unit to draw. + m_convert = LIB_ITEM::LIB_CONVERT::BASE; // De Morgan Handling // The rotation/mirror transformation matrix. pos normal m_transform = TRANSFORM(); diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 81311a6ce5..7e0396cabf 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -228,7 +228,7 @@ LIB_VIEW_FRAME::~LIB_VIEW_FRAME() void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert ) { m_unit = aUnit > 0 ? aUnit : 1; - m_convert = aConvert > 0 ? aConvert : 1; + m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE; m_selection_changed = false; // Update canvas @@ -546,7 +546,7 @@ bool LIB_VIEW_FRAME::ReCreateListLib() m_libraryName = libs[0]; m_entryName = wxEmptyString; m_unit = 1; - m_convert = 1; + m_convert = LIB_ITEM::LIB_CONVERT::BASE; } bool cmp_changed = ReCreateListCmp(); @@ -577,7 +577,7 @@ bool LIB_VIEW_FRAME::ReCreateListCmp() { m_libraryName = wxEmptyString; m_entryName = wxEmptyString; - m_convert = 1; + m_convert = LIB_ITEM::LIB_CONVERT::BASE; m_unit = 1; return true; } @@ -591,7 +591,7 @@ bool LIB_VIEW_FRAME::ReCreateListCmp() { // Select the first library entry when the previous entry name does not exist in // the current library. - m_convert = 1; + m_convert = LIB_ITEM::LIB_CONVERT::BASE; m_unit = 1; index = 0; changed = true; @@ -665,7 +665,7 @@ void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName ) if( m_selection_changed ) { m_unit = 1; - m_convert = 1; + m_convert = LIB_ITEM::LIB_CONVERT::BASE; m_selection_changed = false; } diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index 1841e4d509..6ecbe64621 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -144,11 +144,11 @@ void LIB_VIEW_FRAME::onSelectSymbolBodyStyle( wxCommandEvent& aEvent ) { default: case ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT: - m_convert = 1; + m_convert = LIB_ITEM::LIB_CONVERT::BASE; break; case ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT: - m_convert = 2; + m_convert = LIB_ITEM::LIB_CONVERT::DEMORGAN; break; }