From 6910df3972e8094c599fcc740db3110dcbe4a525 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 22 Feb 2011 18:59:46 +0100 Subject: [PATCH] Pcbnew: fix 2 (minor) issues Cvpcb: code cleaning. --- cvpcb/autosel.cpp | 10 +---- cvpcb/class_footprints_listbox.cpp | 24 ++++------ cvpcb/cvframe.cpp | 45 +++++++++++++++++++ cvpcb/footprint_info.h | 71 +++++++++++++++++++++++++++++- cvpcb/listlib.cpp | 62 +++++++------------------- cvpcb/setvisu.cpp | 4 +- include/id.h | 2 +- pcbnew/onleftclick.cpp | 7 +-- 8 files changed, 145 insertions(+), 80 deletions(-) diff --git a/cvpcb/autosel.cpp b/cvpcb/autosel.cpp index 7e69a8322d..7b3c7a1dfc 100644 --- a/cvpcb/autosel.cpp +++ b/cvpcb/autosel.cpp @@ -149,14 +149,8 @@ found in the default search paths." ), if( alias.m_Name.CmpNoCase( component.m_Value ) != 0 ) continue; - BOOST_FOREACH( FOOTPRINT_INFO& footprint, m_footprints ) - { - if( alias.m_FootprintName.CmpNoCase( footprint.m_Module ) == 0 ) - { - SetNewPkg( footprint.m_Module ); - break; - } - } + if( m_footprints.GetModuleInfo( alias.m_FootprintName ) ) + SetNewPkg( alias.m_FootprintName ); if( component.m_Module.IsEmpty() ) { diff --git a/cvpcb/class_footprints_listbox.cpp b/cvpcb/class_footprints_listbox.cpp index b819fb34d3..56ee5f8318 100644 --- a/cvpcb/class_footprints_listbox.cpp +++ b/cvpcb/class_footprints_listbox.cpp @@ -12,17 +12,6 @@ #include "cvstruct.h" -FOOTPRINT_INFO* GetModuleDescrByName( const wxString& FootprintName, FOOTPRINT_LIST& list ) -{ - BOOST_FOREACH( FOOTPRINT_INFO & footprint, list ) - { - if( footprint.m_Module == FootprintName ) - return &footprint; - } - - return NULL; -} - /***************************************/ /* ListBox handling the footprint list */ /***************************************/ @@ -127,9 +116,11 @@ void FOOTPRINTS_LISTBOX::SetFootprintFullList( FOOTPRINT_LIST& list ) m_FullFootprintList.Clear(); - BOOST_FOREACH( FOOTPRINT_INFO & footprint, list ) { + for( unsigned ii = 0; ii < list.GetCount(); ii++ ) + { + FOOTPRINT_INFO & footprint = list.GetItem(ii); msg.Printf( wxT( "%3d %s" ), m_FullFootprintList.GetCount() + 1, - footprint.m_Module.GetData() ); + GetChars(footprint.m_Module) ); m_FullFootprintList.Add( msg ); } @@ -145,7 +136,6 @@ void FOOTPRINTS_LISTBOX::SetFootprintFullList( FOOTPRINT_LIST& list ) void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT* Component, FOOTPRINT_LIST& list ) { - FOOTPRINT_LIST::iterator i; wxString msg; unsigned jj; int OldSelection = GetSelection(); @@ -153,7 +143,9 @@ void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT* Component, m_FilteredFootprintList.Clear(); - BOOST_FOREACH( FOOTPRINT_INFO & footprint, list ) { + for( unsigned ii = 0; ii < list.GetCount(); ii++ ) + { + FOOTPRINT_INFO& footprint = list.GetItem(ii); /* Search for matching footprints */ for( jj = 0; jj < Component->m_FootprintFilter.GetCount(); jj++ ) { @@ -250,7 +242,7 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event ) FOOTPRINT_INFO* Module; wxString FootprintName = GetSelectedFootprint(); - Module = GetModuleDescrByName( FootprintName, GetParent()->m_footprints ); + Module = GetParent()->m_footprints.GetModuleInfo( FootprintName ); wxASSERT(Module); if( GetParent()->DrawFrame ) { diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 94c51f38bd..595070a6f5 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -17,6 +17,8 @@ #include "dialog_cvpcb_config.h" #include "class_DisplayFootprintsFrame.h" #include "cvpcb_id.h" +#include "dialog_load_error.h" + #include "build_version.h" @@ -603,3 +605,46 @@ void CVPCB_MAINFRAME::DisplayStatus() msg.Empty(); SetStatusText( msg, 2 ); } + +/* + * Read the list of libraries (*.mod files) and populates m_footprints + * ( list of availaible modules in libs ). + * for each module are stored + * the module name + * documentation string + * associated keywords + */ +bool CVPCB_MAINFRAME::LoadFootprintFiles( ) +{ + /* Check if there are footprint libraries in project file */ + if( m_ModuleLibNames.GetCount() == 0 ) + { + wxMessageBox( _( "No PCB footprint libraries are listed in the current project file." ), + _( "Project File Error" ), wxOK | wxICON_ERROR ); + return false; + } + + m_footprints.ReadFootprintFiles(m_ModuleLibNames); + + /* Display error messages, if any */ + if( !m_footprints.m_filesNotFound.IsEmpty() || !m_footprints.m_filesInvalid.IsEmpty() ) + { + DIALOG_LOAD_ERROR dialog(NULL); + if( !m_footprints.m_filesNotFound.IsEmpty() ) + { + wxString message = _("Some files could not be found!"); + dialog.MessageSet(message); + dialog.ListSet(m_footprints.m_filesNotFound); + } + + /* Display if there are invalid files */ + if( !m_footprints.m_filesInvalid.IsEmpty() ) + { + dialog.MessageSet( _("Some files are invalid!")); + dialog.ListSet(m_footprints.m_filesInvalid); + } + dialog.ShowModal(); + } + + return true; +} diff --git a/cvpcb/footprint_info.h b/cvpcb/footprint_info.h index 6d2bda6e9d..95beb40535 100644 --- a/cvpcb/footprint_info.h +++ b/cvpcb/footprint_info.h @@ -27,7 +27,76 @@ public: } }; -typedef boost::ptr_vector< FOOTPRINT_INFO > FOOTPRINT_LIST; +class FOOTPRINT_LIST +{ +public: + boost::ptr_vector< FOOTPRINT_INFO > m_List; + wxString m_filesNotFound; + wxString m_filesInvalid; + +public: + + /** + * Function GetCount + * @return the number of items stored in list + */ + unsigned GetCount() { return m_List.size(); } + + /** + * Function GetModuleInfo + * @return the item stored in list if found + * @param aFootprintName = the name of item + */ + FOOTPRINT_INFO * GetModuleInfo( const wxString & aFootprintName ) + { + BOOST_FOREACH( FOOTPRINT_INFO& footprint, m_List ) + { + if( aFootprintName.CmpNoCase( footprint.m_Module ) == 0 ) + return &footprint; + } + return NULL; + } + + /** + * Function GetItem + * @return the aIdx item in list + * @param aIdx = index of the given item + */ + FOOTPRINT_INFO & GetItem( unsigned aIdx ) + { + return m_List[aIdx]; + } + + /** + * Function AddItem + * add aItem in list + * @param aItem = item to add + */ + void AddItem( FOOTPRINT_INFO* aItem ) + { + m_List.push_back( aItem); + } + + /** + * Function ReadFootprintFiles + * Read the list of libraries (*.mod files) and populates m_List ( list of availaible modules in libs ). + * for each module, are stored + * the module name + * documentation string + * associated keywords + * library name + * Module description format: + * $MODULE c64acmd First line of module description + * Li c64acmd DIN connector Library reference + * Cd Europe 96 AC male vertical documentation string + * Kw PAD_CONN DIN associated keywords + * ...... other data (pads, outlines ..) + * $Endmodule + * + * @param aFootprintsLibNames = an array string giving the list of libraries to load + */ + bool ReadFootprintFiles( wxArrayString & aFootprintsLibNames ); +}; /* FOOTPRINT object list sort function. */ inline bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 ) diff --git a/cvpcb/listlib.cpp b/cvpcb/listlib.cpp index 122e1aac0a..c0221c27cc 100644 --- a/cvpcb/listlib.cpp +++ b/cvpcb/listlib.cpp @@ -4,7 +4,7 @@ /* - * Functions to read footprint libraries and fill m_footprints by availlable footprints names + * Functions to read footprint libraries and fill m_footprints by available footprints names * and their documentation (comments and keywords) */ #include "fctsys.h" @@ -20,14 +20,13 @@ #include "filter_reader.h" #include "footprint_info.h" -#include "dialog_load_error.h" -/* - * Read the list of libraries (*.mod files) and populates m_footprints ( list of availaible modules in libs ). +/* Read the list of libraries (*.mod files) * for each module are stored * the module name * documentation string * associated keywords + * lib name * Module description format: * $MODULE c64acmd First line of module description * Li c64acmd DIN connector Library reference @@ -35,39 +34,29 @@ * Kw PAD_CONN DIN associated keywords * ...... other data (pads, outlines ..) * $Endmodule - * */ -bool CVPCB_MAINFRAME::LoadFootprintFiles( ) +bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString & aFootprintsLibNames ) { FILE* file; wxFileName filename; wxString libname; - wxString files_not_found; - wxString files_invalid; - /* Check if footprint m_footprints is not empty */ - if( !m_footprints.empty() ) - m_footprints.clear(); - - /* Check if there are footprint libraries in project file */ - if( m_ModuleLibNames.GetCount() == 0 ) - { - wxMessageBox( _( "No PCB footprint libraries are listed in the current project file." ), - _( "Project File Error" ), wxOK | wxICON_ERROR ); - return false; - } + // Clear data before reading files + m_filesNotFound.Empty(); + m_filesInvalid.Empty(); + m_List.clear(); /* Parse Libraries Listed */ - for( unsigned ii = 0; ii < m_ModuleLibNames.GetCount(); ii++ ) + for( unsigned ii = 0; ii < aFootprintsLibNames.GetCount(); ii++ ) { - filename = m_ModuleLibNames[ii]; + filename = aFootprintsLibNames[ii]; filename.SetExt( ModuleFileExtension ); libname = wxGetApp().FindLibraryPath( filename ); if( libname.IsEmpty() ) { - files_not_found << filename.GetFullName() << wxT("\n"); + m_filesNotFound << filename.GetFullName() << wxT("\n"); continue; } @@ -76,7 +65,7 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles( ) if( file == NULL ) { - files_invalid << libname << _(" (file cannot be opened)") << wxT("\n"); + m_filesInvalid << libname << _(" (file cannot be opened)") << wxT("\n"); continue; } @@ -93,7 +82,7 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles( ) wxString msg; msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library." ), GetChars( libname ) ); - files_invalid << msg << wxT("\n"); + m_filesInvalid << msg << wxT("\n"); continue; } @@ -115,7 +104,7 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles( ) FOOTPRINT_INFO* ItemLib = new FOOTPRINT_INFO(); ItemLib->m_Module = CONV_FROM_UTF8( StrPurge( line ) ); ItemLib->m_LibName = libname; - m_footprints.push_back( ItemLib ); + AddItem( ItemLib ); while( reader.ReadLine() ) { @@ -143,30 +132,11 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles( ) if( !end ) { - files_invalid << libname << _(" (Unexpected end of file)") << wxT("\n"); + m_filesInvalid << libname << _(" (Unexpected end of file)") << wxT("\n"); } } - m_footprints.sort(); - /* Display error messages, if any */ - if( !files_not_found.IsEmpty() || !files_invalid.IsEmpty() ) - { - DIALOG_LOAD_ERROR dialog(NULL); - if( !files_not_found.IsEmpty() ) - { - wxString message = _("Some files could not be found!"); - dialog.MessageSet(message); - dialog.ListSet(files_not_found); - } - - /* Display if there are invalid files */ - if( !files_invalid.IsEmpty() ) - { - dialog.MessageSet( _("Some files are invalid!")); - dialog.ListSet(files_invalid); - } - dialog.ShowModal(); - } + m_List.sort(); return true; } diff --git a/cvpcb/setvisu.cpp b/cvpcb/setvisu.cpp index f259bc2a98..5bea06fa5b 100644 --- a/cvpcb/setvisu.cpp +++ b/cvpcb/setvisu.cpp @@ -20,8 +20,6 @@ #include "3d_viewer.h" -extern FOOTPRINT_INFO* GetModuleDescrByName( const wxString& FootprintName, FOOTPRINT_LIST& list ); - /* * Create or Update the frame showing the current highlighted footprint * and (if showed) the 3D display frame @@ -48,7 +46,7 @@ void CVPCB_MAINFRAME::CreateScreenCmp() { msg = _( "Footprint: " ) + FootprintName; DrawFrame->SetTitle( msg ); - FOOTPRINT_INFO* Module = GetModuleDescrByName( FootprintName, m_footprints ); + FOOTPRINT_INFO* Module = m_footprints.GetModuleInfo( FootprintName ); msg = _( "Lib: " ); if( Module ) diff --git a/include/id.h b/include/id.h index 39107bfa91..f55bb0acab 100644 --- a/include/id.h +++ b/include/id.h @@ -208,6 +208,7 @@ enum main_id ID_TB_OPTIONS_SELECT_CURSOR, ID_TB_OPTIONS_SHOW_POLAR_COORD, ID_TB_OPTIONS_SHOW_GRID, + ID_TB_OPTIONS_SHOW_PADS_SKETCH, ID_TB_OPTIONS_SHOW_ZONES, ID_TB_OPTIONS_SHOW_ZONES_DISABLE, @@ -222,7 +223,6 @@ enum main_id ID_TB_OPTIONS_HIDDEN_PINS, ID_TB_OPTIONS_BUS_WIRES_ORIENT, - ID_TB_OPTIONS_SHOW_PADS_SKETCH, ID_TB_OPTIONS_SHOW_VIAS_SKETCH, ID_TB_OPTIONS_SHOW_TRACKS_SKETCH, ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH, diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index 6f8d689266..d2ae6822e4 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -78,11 +78,8 @@ void WinEDA_PcbFrame::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) break; case TYPE_DRAWSEGMENT: - if( m_ID_current_state == 0 ) - { - Place_DrawItem( (DRAWSEGMENT*) DrawStruct, aDC ); - exit = true; - } + Place_DrawItem( (DRAWSEGMENT*) DrawStruct, aDC ); + exit = true; break; case TYPE_DIMENSION: