From 99c1d45fa01f3a5be2f65d476247a00d45640a7e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 26 Sep 2012 17:36:48 +0200 Subject: [PATCH 1/2] Added mutli-selection to cvpcb --- cvpcb/class_components_listbox.cpp | 2 +- cvpcb/cvstruct.h | 3 +- cvpcb/listboxes.cpp | 7 ++-- cvpcb/readwrite_dlgs.cpp | 51 ++++++++++++++++-------------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/cvpcb/class_components_listbox.cpp b/cvpcb/class_components_listbox.cpp index 2c09c5215d..9d0a7a721b 100644 --- a/cvpcb/class_components_listbox.cpp +++ b/cvpcb/class_components_listbox.cpp @@ -17,7 +17,7 @@ COMPONENTS_LISTBOX::COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, const wxPoint& loc, const wxSize& size, int nbitems, wxString choice[] ) : - ITEMS_LISTBOX_BASE( parent, id, loc, size ) + ITEMS_LISTBOX_BASE( parent, id, loc, size, ~wxLC_SINGLE_SEL) { } diff --git a/cvpcb/cvstruct.h b/cvpcb/cvstruct.h index c95bfde9fe..5d7ed48187 100644 --- a/cvpcb/cvstruct.h +++ b/cvpcb/cvstruct.h @@ -18,7 +18,8 @@ class ITEMS_LISTBOX_BASE : public wxListView { public: ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId, - const wxPoint& aLocation, const wxSize& aSize ); + const wxPoint& aLocation, const wxSize& aSize, + long aStyle = wxLC_SINGLE_SEL); ~ITEMS_LISTBOX_BASE(); diff --git a/cvpcb/listboxes.cpp b/cvpcb/listboxes.cpp index a3b432c24d..65393727c3 100644 --- a/cvpcb/listboxes.cpp +++ b/cvpcb/listboxes.cpp @@ -19,11 +19,12 @@ ******************************************************************************/ #define LISTB_STYLE wxSUNKEN_BORDER | wxLC_NO_HEADER | \ - wxLC_SINGLE_SEL | wxLC_REPORT | wxLC_VIRTUAL + wxLC_REPORT | wxLC_VIRTUAL ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId, - const wxPoint& aLocation, const wxSize& aSize ) : - wxListView( aParent, aId, aLocation, aSize, LISTB_STYLE ) + const wxPoint& aLocation, const wxSize& aSize, + long aStyle) : + wxListView( aParent, aId, aLocation, aSize, LISTB_STYLE | aStyle ) { InsertColumn( 0, wxEmptyString ); SetColumnWidth( 0, wxLIST_AUTOSIZE ); diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index 30f1c46a34..026b0ae77d 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -39,53 +39,58 @@ #define titleComponentLibErr _( "Component Library Error" ) - void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName ) { COMPONENT_INFO* Component; bool isUndefined = false; int NumCmp; + int LastCmp; wxString msg; if( m_components.empty() ) return; - NumCmp = m_ListCmp->GetSelection(); - - if( NumCmp < 0 ) + if(m_ListCmp->GetFirstSelected() < 0) { NumCmp = 0; m_ListCmp->SetSelection( NumCmp, true ); } - Component = &m_components[ NumCmp ]; + while( (NumCmp = m_ListCmp->GetFirstSelected() ) != -1) + { + Component = &m_components[NumCmp]; - if( Component == NULL ) - return; + if( Component == NULL ) + return; - isUndefined = Component->m_Footprint.IsEmpty(); + isUndefined = Component->m_Footprint.IsEmpty(); - Component->m_Footprint = aFootprintName; + Component->m_Footprint = aFootprintName; + + msg.Printf( CMP_FORMAT, NumCmp + 1, + GetChars( Component->m_Reference ), + GetChars( Component->m_Value ), + GetChars( Component->m_Footprint ) ); + + if( isUndefined ) + m_undefinedComponentCnt -= 1; + + m_ListCmp->SetString( NumCmp, msg ); + m_ListCmp->SetSelection( NumCmp, false ); + + isUndefined = false; + LastCmp = NumCmp; + + DisplayStatus(); + } - msg.Printf( CMP_FORMAT, NumCmp + 1, - GetChars( Component->m_Reference ), - GetChars( Component->m_Value ), - GetChars( Component->m_Footprint ) ); m_modified = true; - if( isUndefined ) - m_undefinedComponentCnt -= 1; - - m_ListCmp->SetString( NumCmp, msg ); - m_ListCmp->SetSelection( NumCmp, false ); - - // We activate next component: - if( NumCmp < (m_ListCmp->GetCount() - 1) ) - NumCmp++; + if( LastCmp < (m_ListCmp->GetCount() - 1) ) + NumCmp = LastCmp + 1; m_ListCmp->SetSelection( NumCmp, true ); - DisplayStatus(); } From 4fec212627181fc731e25b813deb229f94318308 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 26 Sep 2012 19:22:48 +0200 Subject: [PATCH 2/2] fixed code to better comply with the coding style guidelines --- cvpcb/readwrite_dlgs.cpp | 73 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index 026b0ae77d..ff42551271 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -41,56 +41,73 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName ) { - COMPONENT_INFO* Component; - bool isUndefined = false; - int NumCmp; - int LastCmp; - wxString msg; + COMPONENT_INFO* component; + bool hasFootprint = false; + int componentIndex; + wxString description; if( m_components.empty() ) return; + // if no component is selected, select the first one + if(m_ListCmp->GetFirstSelected() < 0) { - NumCmp = 0; - m_ListCmp->SetSelection( NumCmp, true ); + componentIndex = 0; + m_ListCmp->SetSelection( componentIndex, true ); } - while( (NumCmp = m_ListCmp->GetFirstSelected() ) != -1) - { - Component = &m_components[NumCmp]; + // iterate over the selection - if( Component == NULL ) + while( m_ListCmp->GetFirstSelected() != -1) + { + // get the component for the current iteration + + componentIndex = m_ListCmp->GetFirstSelected(); + component = &m_components[componentIndex]; + + if( component == NULL ) return; - isUndefined = Component->m_Footprint.IsEmpty(); + // check to see if the component has allready a footprint set. - Component->m_Footprint = aFootprintName; + hasFootprint = !(component->m_Footprint.IsEmpty()); - msg.Printf( CMP_FORMAT, NumCmp + 1, - GetChars( Component->m_Reference ), - GetChars( Component->m_Value ), - GetChars( Component->m_Footprint ) ); + component->m_Footprint = aFootprintName; - if( isUndefined ) + // create the new component description + + description.Printf( CMP_FORMAT, componentIndex + 1, + GetChars( component->m_Reference ), + GetChars( component->m_Value ), + GetChars( component->m_Footprint ) ); + + // if the component hasn't had a footprint associated with it + // it now has, so we decrement the count of components without + // a footprint assigned. + + if( !hasFootprint ) + { + hasFootprint = true; m_undefinedComponentCnt -= 1; + } - m_ListCmp->SetString( NumCmp, msg ); - m_ListCmp->SetSelection( NumCmp, false ); - - isUndefined = false; - LastCmp = NumCmp; - - DisplayStatus(); + // set the new description and deselect the processed component + m_ListCmp->SetString( componentIndex, description ); + m_ListCmp->SetSelection( componentIndex, false ); } + // mark this "session" as modified m_modified = true; - if( LastCmp < (m_ListCmp->GetCount() - 1) ) - NumCmp = LastCmp + 1; + // select the next component, if there is one + if( componentIndex < (m_ListCmp->GetCount() - 1) ) + componentIndex++; - m_ListCmp->SetSelection( NumCmp, true ); + m_ListCmp->SetSelection( componentIndex, true ); + // update the statusbar + DisplayStatus(); }