From 4daf9039db1c570091885ff2a5fad47dd9284404 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 16 Apr 2015 17:26:51 +0200 Subject: [PATCH] Eeschema: Fix a very old bug relative to the tool to load power parts: Previously, only the lib named "power" was used (and therefore power parts defined in other libs not shown). Now, all power parts can be loaded from any library. Also, when loading power parts from the chose component dialog or the lib viewer, libs and parts are filtered: only power parts and libs containing power parts are listed. Hotkeys: move a few global strings in the files where ther are actually used (and make them local.) and code cleaning. Fix a few other minor issues. --- common/basicframe.cpp | 7 -- common/build_version.cpp | 2 +- common/hotkeys_basic.cpp | 14 +-- eeschema/class_libentry.h | 4 +- eeschema/class_library.cpp | 43 +++++++ eeschema/class_library.h | 105 +++++++++++++++++- eeschema/component_tree_search_container.cpp | 23 ++-- eeschema/component_tree_search_container.h | 28 ++++- .../dialog_edit_component_in_schematic.cpp | 4 +- eeschema/getpart.cpp | 56 +++++++--- eeschema/hotkeys.cpp | 34 ++++-- eeschema/libedit.cpp | 4 +- eeschema/onleftclick.cpp | 11 +- eeschema/sch_base_frame.h | 13 ++- eeschema/schframe.h | 7 +- eeschema/sheetlab.cpp | 8 +- eeschema/viewlib_frame.cpp | 52 ++++++++- eeschema/viewlib_frame.h | 17 +++ include/hotkeys_basic.h | 11 -- kicad/menubar.cpp | 2 +- pagelayout_editor/hotkeys.cpp | 9 +- pcbnew/hotkeys.cpp | 28 +++-- scripting/wx.i | 1 + 23 files changed, 378 insertions(+), 105 deletions(-) diff --git a/common/basicframe.cpp b/common/basicframe.cpp index 69c65d7f84..1edef83300 100644 --- a/common/basicframe.cpp +++ b/common/basicframe.cpp @@ -632,13 +632,6 @@ void EDA_BASE_FRAME::CopyVersionInfoToClipboard( wxCommandEvent& event ) tmp << wxT( "OFF\n" ); #endif - tmp << wxT( " KICAD_USE_WEBKIT=" ); -#ifdef KICAD_USE_WEBKIT - tmp << wxT( "ON\n" ); -#else - tmp << wxT( "OFF\n" ); -#endif - wxMessageBox( tmp, _("Version Information (copied to the clipboard)") ); wxTheClipboard->SetData( new wxTextDataObject( tmp ) ); diff --git a/common/build_version.cpp b/common/build_version.cpp index 310ea40916..c3aac181f5 100644 --- a/common/build_version.cpp +++ b/common/build_version.cpp @@ -30,7 +30,7 @@ #endif #ifndef KICAD_BUILD_VERSION -# define KICAD_BUILD_VERSION "(after 2015-mar-04 BZR unknown)" +# define KICAD_BUILD_VERSION "(after 2015-apr-15 BZR unknown)" #endif /** diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index 40e3d3d038..5cdea76294 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 Jean-Pierre Charras, j-p.charras at wanadoo.fr + * Copyright (C) 2015 Jean-Pierre Charras, j-p.charras at wanadoo.fr * Copyright (C) 2010-2011 Wayne Stambaugh - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -47,16 +47,6 @@ #define HOTKEYS_CONFIG_KEY wxT( "Keys" ) wxString g_CommonSectionTag( wxT( "[common]" ) ); -wxString g_SchematicSectionTag( wxT( "[eeschema]" ) ); -wxString g_LibEditSectionTag( wxT( "[libedit]" ) ); -wxString g_BoardEditorSectionTag( wxT( "[pcbnew]" ) ); -wxString g_ModuleEditSectionTag( wxT( "[footprinteditor]" ) ); - -wxString g_CommonSectionTitle( _HKI( "Common" ) ); -wxString g_SchematicSectionTitle( _HKI( "Schematic Editor" ) ); -wxString g_LibEditSectionTitle( _HKI( "Library Editor" ) ); -wxString g_BoardEditorSectionTitle( _HKI( "Board Editor" ) ); -wxString g_ModuleEditSectionTitle( _HKI( "Footprint Editor" ) ); /* Class to handle hotkey commnands. hotkeys have a default value diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 7c6d086bbf..f781122222 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -63,7 +63,7 @@ typedef boost::weak_ptr PART_REF; ///< weak pointer to LIB /* values for member .m_options */ -enum LibrEntryOptions +enum LIBRENTRYOPTIONS { ENTRY_NORMAL, // Libentry is a standard part (real or alias) ENTRY_POWER // Libentry is a power symbol @@ -207,7 +207,7 @@ class LIB_PART : public EDA_ITEM bool m_showPinNames; ///< Determines if part pin names are visible. bool m_showPinNumbers; ///< Determines if part pin numbers are visible. long m_dateModified; ///< Date the part was last modified. - LibrEntryOptions m_options; ///< Special part features such as POWER or NORMAL.) + LIBRENTRYOPTIONS m_options; ///< Special part features such as POWER or NORMAL.) int m_unitCount; ///< Number of units (parts) per package. LIB_ITEMS drawings; ///< How to draw this part. wxArrayString m_FootprintList; /**< List of suitable footprint names for the diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 2d7ba0ce0a..3116d1fb4c 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -115,6 +115,33 @@ void PART_LIB::GetEntryNames( wxArrayString& aNames, bool aSort, bool aMakeUpper } +void PART_LIB::GetEntryTypePowerNames( wxArrayString& aNames, bool aSort, bool aMakeUpperCase ) +{ + for( LIB_ALIAS_MAP::iterator it = m_amap.begin(); it!=m_amap.end(); it++ ) + { + LIB_ALIAS* alias = it->second; + LIB_PART* root = alias->GetPart(); + + if( !root || !root->IsPower() ) + continue; + + if( aMakeUpperCase ) + { + wxString tmp = (*it).first; + tmp.MakeUpper(); + aNames.Add( tmp ); + } + else + { + aNames.Add( (*it).first ); + } + } + + if( aSort ) + aNames.Sort(); +} + + /** * Function sortFunction * simple function used as comparator to sort a std::vector&. @@ -235,6 +262,22 @@ LIB_PART* PART_LIB::FindPart( const wxString& aName ) } +bool PART_LIB::HasPowerParts() +{ + // return true if at least one power part is found in lib + for( LIB_ALIAS_MAP::iterator it = m_amap.begin(); it!=m_amap.end(); it++ ) + { + LIB_ALIAS* alias = it->second; + LIB_PART* root = alias->GetPart(); + + if( root && root->IsPower() ) + return true; + } + + return false; +} + + bool PART_LIB::AddAlias( LIB_ALIAS* aAlias ) { wxASSERT( aAlias ); diff --git a/eeschema/class_library.h b/eeschema/class_library.h index 565c813ed3..b5149ccf54 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2011 Wayne Stambaugh - * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -72,6 +72,90 @@ class OUTPUTFORMATTER; #define DOC_EXT wxT( "dcm" ) +// Helper class to filter a list of libraries, and/or a list of PART_LIB +// in dialogs +class SCHLIB_FILTER +{ + wxArrayString m_allowedLibs; ///< a list of lib names to list some libraries + ///< if empty: no filter + bool m_filterPowerParts; ///< true to filter (show only) power parts + bool m_forceLoad; // When true, load a part lib from the lib + // which is given in m_allowedLibs[0] + +public: + SCHLIB_FILTER() + { + m_filterPowerParts = false; + } + + /** + * add a lib name to the allowed libraries + */ + void AddLib( const wxString& aLibName ) + { + m_allowedLibs.Add( aLibName ); + m_forceLoad = false; + } + + + /** + * add a lib name to the allowed libraries + */ + void LoadFrom( const wxString& aLibName ) + { + m_allowedLibs.Clear(); + m_allowedLibs.Add( aLibName ); + m_forceLoad = true; + } + + /** + * Clear the allowed libraries list (allows all libs) + */ + void ClearLibList() + { + m_allowedLibs.Clear(); + m_forceLoad = false; + } + + /** + * set the filtering of power parts + */ + void FilterPowerParts( bool aFilterEnable ) + { + m_filterPowerParts = aFilterEnable; + } + + // Accessors + + /** + * Function GetFilterPowerParts + * @return true if the filtering of power parts is on + */ + bool GetFilterPowerParts() const { return m_filterPowerParts; } + + + /** + * Function GetAllowedLibList + * @return am wxArrayString of the names of allowed libs + */ + const wxArrayString& GetAllowedLibList() const { return m_allowedLibs; } + + /** + * Function GetLibSource + * @return the name of the lib to use to load a part, or an a emty string + * Useful to load (in lib editor or lib viewer) a part from a given library + */ + const wxString& GetLibSource() const + { + static wxString dummy; + + if( m_forceLoad && m_allowedLibs.GetCount() > 0 ) + return m_allowedLibs[0]; + else + return dummy; + } +}; + /* Helpers for creating a list of part libraries. */ class PART_LIB; @@ -350,6 +434,16 @@ public: void GetEntryNames( wxArrayString& aNames, bool aSort = true, bool aMakeUpperCase = false ); + /** + * Load a string array with the names of entries of type POWER in this library. + * + * @param aNames - String array to place entry names into. + * @param aSort - Sort names if true. + * @param aMakeUpperCase - Force entry names to upper case. + */ + void GetEntryTypePowerNames( wxArrayString& aNames, bool aSort = true, + bool aMakeUpperCase = false ); + /** * Load string array with entry names matching name and/or key word. * @@ -547,6 +641,13 @@ public: * @throw IO_ERROR if there's any problem loading the library. */ static PART_LIB* LoadLibrary( const wxString& aFileName ) throw( IO_ERROR, boost::bad_pointer ); + + /** + * Function HasPowerParts + * @return true if at least one power part is found in lib + * Useful to select or list only libs containing power parts + */ + bool HasPowerParts(); }; diff --git a/eeschema/component_tree_search_container.cpp b/eeschema/component_tree_search_container.cpp index 2c4114fc3f..2d1f7404bc 100644 --- a/eeschema/component_tree_search_container.cpp +++ b/eeschema/component_tree_search_container.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Henner Zeller - * Copyright (C) 2014 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -98,12 +98,14 @@ bool COMPONENT_TREE_SEARCH_CONTAINER::scoreComparator( const TREE_NODE* a1, cons } -COMPONENT_TREE_SEARCH_CONTAINER::COMPONENT_TREE_SEARCH_CONTAINER( PART_LIBS* aLibs ) : - tree( NULL ), - libraries_added( 0 ), - preselect_unit_number( -1 ), - m_libs( aLibs ) +COMPONENT_TREE_SEARCH_CONTAINER::COMPONENT_TREE_SEARCH_CONTAINER( PART_LIBS* aLibs ) { + tree = NULL, + libraries_added = 0, + components_added = 0, + preselect_unit_number = -1, + m_libs = aLibs, + m_filter = CMP_FILTER_NONE; } @@ -134,8 +136,13 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddLibrary( PART_LIB& aLib ) { wxArrayString all_aliases; - aLib.GetEntryNames( all_aliases ); + if( m_filter == CMP_FILTER_POWER ) + aLib.GetEntryTypePowerNames( all_aliases ); + else + aLib.GetEntryNames( all_aliases ); + AddAliasList( aLib.GetName(), all_aliases, &aLib ); + ++libraries_added; } @@ -203,6 +210,8 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName, nodes.push_back( unit_node ); } } + + ++components_added; } } diff --git a/eeschema/component_tree_search_container.h b/eeschema/component_tree_search_container.h index 1d523fe1b0..47e518b361 100644 --- a/eeschema/component_tree_search_container.h +++ b/eeschema/component_tree_search_container.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Henner Zeller - * Copyright (C) 2014 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,10 +42,26 @@ class wxArrayString; // to have a search-as-you-type experience. class COMPONENT_TREE_SEARCH_CONTAINER { +public: + /** This enum allows a selective filtering of component to list + * currently: no filtering + * list power components only + */ + enum CMP_FILTER_TYPE + { + CMP_FILTER_NONE, ///< no filtering + CMP_FILTER_POWER ///< list components flagged PWR + }; + public: COMPONENT_TREE_SEARCH_CONTAINER( PART_LIBS* aLibs ); ~COMPONENT_TREE_SEARCH_CONTAINER(); + void SetFilter( CMP_FILTER_TYPE aFilter ) + { + m_filter = aFilter; + } + /** Function AddLibrary * Add all the components and their aliases of this library to be searched. * To be called in the setup phase to fill this container. @@ -102,6 +118,13 @@ public: */ LIB_ALIAS* GetSelectedAlias( int* aUnit ); + /** + * Function GetComponentsCount + * @return the number of components loaded in the tree + */ + int GetComponentsCount() { return components_added; } + + private: struct TREE_NODE; static bool scoreComparator( const TREE_NODE* a1, const TREE_NODE* a2 ); @@ -109,11 +132,14 @@ private: std::vector nodes; wxTreeCtrl* tree; int libraries_added; + int components_added; wxString preselect_node_name; int preselect_unit_number; PART_LIBS* m_libs; // no ownership + + enum CMP_FILTER_TYPE m_filter; // the current filter }; #endif /* COMPONENT_TREE_SEARCH_CONTAINER_H */ diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 1ed992db3d..c5a602054c 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -258,7 +258,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSelectChipName( wxCommandEvent& event { wxArrayString dummy; int dummyunit = 1; - wxString chipname = m_parent->SelectComponentFromLibrary( wxEmptyString, dummy, dummyunit, + wxString chipname = m_parent->SelectComponentFromLibrary( NULL, dummy, dummyunit, true, NULL, NULL ); if( chipname.IsEmpty() ) return; diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 5b7fb87d4e..8c8db7ea02 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2012 Wayne Stambaugh - * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -52,16 +52,21 @@ #include -wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( LIB_ALIAS* aPreselectedAlias, +wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( const SCHLIB_FILTER* aFilter, + LIB_ALIAS* aPreselectedAlias, int* aUnit, int* aConvert ) { // Close any open non-modal Lib browser, and open a new one, in "modal" mode: LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false ); + if( viewlibFrame ) viewlibFrame->Destroy(); viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER_MODAL, true ); + if( aFilter ) + viewlibFrame->SetFilter( aFilter ); + if( aPreselectedAlias ) { viewlibFrame->SetSelectedLibrary( aPreselectedAlias->GetLibraryName() ); @@ -93,38 +98,48 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( LIB_ALIAS* aPreselectedA } -wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, +wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const SCHLIB_FILTER* aFilter, wxArrayString& aHistoryList, int& aHistoryLastUnit, bool aUseLibBrowser, int* aUnit, int* aConvert ) { - int cmpCount = 0; wxString dialogTitle; PART_LIBS* libs = Prj().SchLibs(); COMPONENT_TREE_SEARCH_CONTAINER search_container( libs ); // Container doing search-as-you-type + bool loaded = false; - if( !aLibname.IsEmpty() ) + if( aFilter ) { - PART_LIB* currLibrary = libs->FindLibrary( aLibname ); + const wxArrayString& liblist = aFilter->GetAllowedLibList(); - if( currLibrary ) + for( unsigned ii = 0; ii < liblist.GetCount(); ii++ ) { - cmpCount = currLibrary->GetCount(); - search_container.AddLibrary( *currLibrary ); + PART_LIB* currLibrary = libs->FindLibrary( liblist[ii] ); + + if( currLibrary ) + { + loaded = true; + search_container.AddLibrary( *currLibrary ); + } } + + if( aFilter->GetFilterPowerParts() ) + search_container.SetFilter( COMPONENT_TREE_SEARCH_CONTAINER::CMP_FILTER_POWER ); + } - else + + if( !loaded ) { BOOST_FOREACH( PART_LIB& lib, *libs ) { - cmpCount += lib.GetCount(); search_container.AddLibrary( lib ); } } + if( !aHistoryList.empty() ) { // This is good for a transition for experienced users: giving them a History. Ideally, @@ -140,7 +155,7 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, } const int deMorgan = aConvert ? *aConvert : 1; - dialogTitle.Printf( _( "Choose Component (%d items loaded)" ), cmpCount ); + dialogTitle.Printf( _( "Choose Component (%d items loaded)" ), search_container.GetComponentsCount() ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, &search_container, deMorgan ); if( dlg.ShowModal() == wxID_CANCEL ) @@ -151,8 +166,8 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, if ( alias ) cmpName = alias->GetName(); - if( dlg.IsExternalBrowserSelected() ) // User requested big component browser. - cmpName = SelectComponentFromLibBrowser( alias, aUnit, aConvert); + if( dlg.IsExternalBrowserSelected() ) // User requested component browser. + cmpName = SelectComponentFromLibBrowser( aFilter, alias, aUnit, aConvert); if( !cmpName.empty() ) { @@ -165,7 +180,7 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, - const wxString& aLibname, + const SCHLIB_FILTER* aFilter, wxArrayString& aHistoryList, int& aHistoryLastUnit, bool aUseLibBrowser ) @@ -175,7 +190,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, SetRepeatItem( NULL ); m_canvas->SetIgnoreMouseEvents( true ); - wxString name = SelectComponentFromLibrary( aLibname, aHistoryList, aHistoryLastUnit, + wxString name = SelectComponentFromLibrary( aFilter, aHistoryList, aHistoryLastUnit, aUseLibBrowser, &unit, &convert ); if( name.IsEmpty() ) @@ -188,7 +203,12 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); - LIB_PART* part = Prj().SchLibs()->FindLibPart( name, aLibname ); + wxString libsource; // the library name to use. If empty, load from any lib + + if( aFilter ) + libsource = aFilter->GetLibSource(); + + LIB_PART* part = Prj().SchLibs()->FindLibPart( name, libsource ); if( !part ) { diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index 8a7a3b48bf..6cd2bf5ed9 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2011 Wayne Stambaugh - * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -307,13 +307,23 @@ static EDA_HOTKEY* viewlib_Hotkey_List[] = NULL }; +// Keyword Identifiers (tags) in key code configuration file (section names) +// (.m_SectionTag member of a EDA_HOTKEY_CONFIG) +static wxString schematicSectionTag( wxT( "[eeschema]" ) ); +static wxString libEditSectionTag( wxT( "[libedit]" ) ); + +// Titles for hotkey editor and hotkey display +static wxString commonSectionTitle( _HKI( "Common" ) ); +static wxString schematicSectionTitle( _HKI( "Schematic Editor" ) ); +static wxString libEditSectionTitle( _HKI( "Library Editor" ) ); + // list of sections and corresponding hotkey list for Eeschema (used to create // an hotkey config file) struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, - { &g_SchematicSectionTag, schematic_Hotkey_List, &g_SchematicSectionTitle }, - { &g_LibEditSectionTag, libEdit_Hotkey_List, &g_LibEditSectionTitle }, + { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle }, + { &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle }, + { &libEditSectionTag, libEdit_Hotkey_List, &schematicSectionTitle }, { NULL, NULL, NULL } }; @@ -321,25 +331,25 @@ struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[] = // (used to list current hotkeys) struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, - { &g_SchematicSectionTag, schematic_Hotkey_List, &g_SchematicSectionTitle }, - { NULL, NULL, NULL } + { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle }, + { &schematicSectionTitle, schematic_Hotkey_List, &schematicSectionTitle }, + { NULL, NULL, NULL } }; // list of sections and corresponding hotkey list for the component editor // (used to list current hotkeys) struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, - { &g_LibEditSectionTag, libEdit_Hotkey_List, &g_LibEditSectionTitle }, - { NULL, NULL, NULL } + { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle }, + { &libEditSectionTag, libEdit_Hotkey_List, &schematicSectionTitle }, + { NULL, NULL, NULL } }; // list of sections and corresponding hotkey list for the component browser // (used to list current hotkeys) struct EDA_HOTKEY_CONFIG g_Viewlib_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_basic_Hotkey_List, &g_CommonSectionTitle }, + { &g_CommonSectionTag, common_basic_Hotkey_List, &commonSectionTitle }, { NULL, NULL, NULL } }; diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 4ad4f0729b..6b2e2e41d2 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -134,7 +134,9 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) wxArrayString dummyHistoryList; int dummyLastUnit; - cmp_name = SelectComponentFromLibrary( lib->GetName(), dummyHistoryList, dummyLastUnit, + SCHLIB_FILTER filter; + filter.LoadFrom( lib->GetName() ); + cmp_name = SelectComponentFromLibrary( &filter, dummyHistoryList, dummyLastUnit, true, NULL, NULL ); if( cmp_name.IsEmpty() ) diff --git a/eeschema/onleftclick.cpp b/eeschema/onleftclick.cpp index ec9cb6220d..2e46ab011b 100644 --- a/eeschema/onleftclick.cpp +++ b/eeschema/onleftclick.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,6 +44,7 @@ #include #include #include +#include // fo class SCHLIB_FILTER to filter power parts // TODO(hzeller): These pairs of elmenets should be represented by an object, but don't want @@ -296,7 +297,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case ID_SCH_PLACE_COMPONENT: if( (item == NULL) || (item->GetFlags() == 0) ) { - GetScreen()->SetCurItem( Load_Component( aDC, wxEmptyString, + GetScreen()->SetCurItem( Load_Component( aDC, NULL, s_CmpNameList, s_CmpLastUnit, true ) ); m_canvas->SetAutoPanRequest( true ); } @@ -309,7 +310,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case ID_PLACE_POWER_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { - GetScreen()->SetCurItem( Load_Component( aDC, wxT( "power" ), + SCHLIB_FILTER filter; + filter.FilterPowerParts( true ); + GetScreen()->SetCurItem( Load_Component( aDC, &filter, s_PowerNameList, s_LastPowerUnit, false ) ); m_canvas->SetAutoPanRequest( true ); } diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index fed27d7dd8..0998623bd9 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -33,6 +33,7 @@ class LIB_VIEW_FRAME; class LIB_EDIT_FRAME; class LIB_ALIAS; class PART_LIB; +class SCHLIB_FILTER; /** * Class SCH_BASE_FRAME @@ -92,8 +93,9 @@ public: * Calls the library viewer to select component to import into schematic. * if the library viewer is currently running, it is closed and reopened * in modal mode. - * @param aLibname the lib name or an empty string. - * if aLibname is empty, the full list of libraries is used + * @param aFilter is a SCHLIB_FILTER filter to pass the allowed library names + * and/or the library name to load the component from and/or some other filter + * if NULL, no filtering. * @param aHistoryList list of previously loaded components * @param aHistoryLastUnit remembering last unit in last component. * @param aUseLibBrowser bool to call the library viewer to select the component @@ -102,7 +104,7 @@ public: * * @return the component name */ - wxString SelectComponentFromLibrary( const wxString& aLibname, + wxString SelectComponentFromLibrary( const SCHLIB_FILTER* aFilter, wxArrayString& aHistoryList, int& aHistoryLastUnit, bool aUseLibBrowser, @@ -116,6 +118,8 @@ protected: * Calls the library viewer to select component to import into schematic. * if the library viewer is currently running, it is closed and reopened * in modal mode. + * @param aFilter is a filter to pass the allowed library names + * and/or some other filter * @param aPreselectedAlias Preselected component alias. NULL if none. * @param aUnit Pointer to Unit-number. Input is the pre-selected unit, output * is the finally selected unit by the user. Can be NULL. @@ -123,7 +127,8 @@ protected: * output is the finally selected deMorgan type by the user. * @return the component name */ - wxString SelectComponentFromLibBrowser( LIB_ALIAS* aPreselectedAlias, + wxString SelectComponentFromLibBrowser( const SCHLIB_FILTER* aFilter, + LIB_ALIAS* aPreselectedAlias, int* aUnit, int* aConvert ); /** diff --git a/eeschema/schframe.h b/eeschema/schframe.h index f2675c41da..8b2ba0b6b0 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -61,6 +61,7 @@ class SCH_JUNCTION; class DIALOG_SCH_FIND; class wxFindDialogEvent; class wxFindReplaceData; +class SCHLIB_FILTER; /// enum used in RotationMiroir() @@ -1007,7 +1008,9 @@ private: * else search in all loaded libs * * @param aDC is the device context to draw upon. - * @param aLibName is the library name to load the component from. + * @param aFilters is a filter to pass the allowed lib names list, or library name + * to load the component from and/or some other filters + * if NULL, no filtering. * @param aHistoryList list remembering recently used component names. * @param aHistoryLastUnit remembering last unit in last component. * @param aUseLibBrowser is the flag to determine if the library browser should be launched. @@ -1016,7 +1019,7 @@ private: * want to change too much while other refactoring is going on) */ SCH_COMPONENT* Load_Component( wxDC* aDC, - const wxString& aLibName, + const SCHLIB_FILTER* aFilter, wxArrayString& aHistoryList, int& aHistoryLastUnit, bool aUseLibBrowser ); diff --git a/eeschema/sheetlab.cpp b/eeschema/sheetlab.cpp index 9f9079201b..5920ca1914 100644 --- a/eeschema/sheetlab.cpp +++ b/eeschema/sheetlab.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -94,8 +94,8 @@ int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, wxDC* aDC ) } aSheetPin->SetText( dlg.GetLabelName() ); - aSheetPin->SetSize( wxSize( ValueFromString( g_UserUnit, dlg.GetTextHeight() ), - ValueFromString( g_UserUnit, dlg.GetTextWidth() ) ) ); + aSheetPin->SetSize( wxSize( ValueFromString( g_UserUnit, dlg.GetTextWidth() ), + ValueFromString( g_UserUnit, dlg.GetTextHeight() ) ) ); aSheetPin->SetShape( dlg.GetConnectionType() ); if( aDC ) diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index cd8b8ba0c5..c46ea4cc9e 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -102,6 +102,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_HotkeysZoomAndGridList = g_Viewlib_Hokeys_Descr; m_cmpList = NULL; m_libList = NULL; + m_listPowerCmpOnly = false; SetScreen( new SCH_SCREEN( aKiway ) ); GetScreen()->m_Center = true; // Axis origin centered on screen. @@ -309,7 +310,36 @@ void LIB_VIEW_FRAME::ReCreateListLib() return; m_libList->Clear(); - m_libList->Append( Prj().SchLibs()->GetLibraryNames() ); + + wxArrayString libs = Prj().SchLibs()->GetLibraryNames(); + + // Remove not allowed libs from main list, if the allowed lib list is not empty + if( m_allowedLibs.GetCount() ) + { + for( unsigned ii = 0; ii < libs.GetCount(); ) + { + if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND ) + libs.RemoveAt( ii ); + else + ii++; + } + } + + // Remove libs which have no power components, if this filter is activated + if( m_listPowerCmpOnly ) + { + for( unsigned ii = 0; ii < libs.GetCount(); ) + { + PART_LIB* lib = Prj().SchLibs()->FindLibrary( libs[ii] ); + + if( lib && !lib->HasPowerParts() ) + libs.RemoveAt( ii ); + else + ii++; + } + } + + m_libList->Append( libs ); // Search for a previous selection: int index = m_libList->FindString( m_libraryName ); @@ -355,7 +385,11 @@ void LIB_VIEW_FRAME::ReCreateListCmp() wxArrayString nameList; - lib->GetEntryNames( nameList ); + if( m_listPowerCmpOnly ) + lib->GetEntryTypePowerNames( nameList ); + else + lib->GetEntryNames( nameList ); + m_cmpList->Append( nameList ); int index = m_cmpList->FindString( m_entryName ); @@ -537,3 +571,17 @@ void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event ) { Close(); } + +void LIB_VIEW_FRAME::SetFilter( const SCHLIB_FILTER* aFilter ) +{ + m_listPowerCmpOnly = false; + m_allowedLibs.Clear(); + + if( aFilter ) + { + m_allowedLibs = aFilter->GetAllowedLibList(); + m_listPowerCmpOnly = aFilter->GetFilterPowerParts(); + } + + ReCreateListLib(); +} diff --git a/eeschema/viewlib_frame.h b/eeschema/viewlib_frame.h index a24b76fd2f..0b0855da82 100644 --- a/eeschema/viewlib_frame.h +++ b/eeschema/viewlib_frame.h @@ -38,6 +38,7 @@ class wxListBox; class PART_LIB; +class SCHLIB_FILTER; /** @@ -108,6 +109,17 @@ public: void LoadSettings( wxConfigBase* aCfg ); void SaveSettings( wxConfigBase* aCfg ); + /** + * set a filter to display only libraries and/or components + * which match the filter + * + * @param aFilter is a filter to pass the allowed library name list + * and/or some other filter + * see SCH_BASE_FRAME::SelectComponentFromLibrary() for details. + * if aFilter == NULL, remove all filtering + */ + void SetFilter( const SCHLIB_FILTER* aFilter ); + /** * Set the selected library in the library window. * @@ -149,6 +161,7 @@ private: bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ); void DClickOnCmpList( wxCommandEvent& event ); +// Private members: wxComboBox* m_selpartBox; // List of libraries (for selection ) @@ -159,6 +172,10 @@ private: wxListBox* m_cmpList; // The list of components int m_cmpListWidth; // Last width of the window + // Filters to build list of libs/list of parts + bool m_listPowerCmpOnly; + wxArrayString m_allowedLibs; + wxString m_configPath; // subpath for configuration // TODO(hzeller): looks like these members were chosen to be static to survive different diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index 333b7fe570..373b2caeb3 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -46,17 +46,6 @@ class EDA_BASE_FRAME; * .m_SectionTag member of a EDA_HOTKEY_CONFIG */ extern wxString g_CommonSectionTag; -extern wxString g_SchematicSectionTag; -extern wxString g_LibEditSectionTag; -extern wxString g_BoardEditorSectionTag; -extern wxString g_ModuleEditSectionTag; - -extern wxString g_CommonSectionTitle; -extern wxString g_SchematicSectionTitle; -extern wxString g_LibEditSectionTitle; -extern wxString g_BoardEditorSectionTitle; -extern wxString g_ModuleEditSectionTitle; - /** * class EDA_HOTKEY diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index d523e88655..6e11dd987e 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -167,7 +167,7 @@ EDA_HOTKEY* common_Hotkey_List[] = // list of sections and corresponding hotkey list for Kicad // (used to create an hotkey config file, and edit hotkeys ) // here we have only one section. -wxString sectionTitle( _HKI( "Kicad Manager Hotkeys" ) ); +static wxString sectionTitle( _HKI( "Kicad Manager Hotkeys" ) ); struct EDA_HOTKEY_CONFIG kicad_Manager_Hokeys_Descr[] = { { &g_CommonSectionTag, common_Hotkey_List, §ionTitle }, diff --git a/pagelayout_editor/hotkeys.cpp b/pagelayout_editor/hotkeys.cpp index 05f966fbb6..8b1218e992 100644 --- a/pagelayout_editor/hotkeys.cpp +++ b/pagelayout_editor/hotkeys.cpp @@ -110,14 +110,17 @@ EDA_HOTKEY* s_PlEditor_Hotkey_List[] = NULL }; +// Titles for hotkey editor and hotkey display +static wxString commonSectionTitle( _HKI( "Common" ) ); + // list of sections and corresponding hotkey list for Pl_Editor // (used to create an hotkey config file) -wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) ); -wxString s_PlEditorSectionTitle( wxT( "Part Layout Editor" ) ); +static wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) ); +static wxString s_PlEditorSectionTitle( wxT( "Part Layout Editor" ) ); struct EDA_HOTKEY_CONFIG s_PlEditor_Hokeys_Descr[] = { - { &g_CommonSectionTag, s_Common_Hotkey_List, &g_CommonSectionTitle }, + { &g_CommonSectionTag, s_Common_Hotkey_List, &commonSectionTitle }, { &s_PlEditorSectionTag, s_PlEditor_Hotkey_List, &s_PlEditorSectionTitle }, { NULL, NULL, NULL } }; diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index 589ba9815c..7dc8325129 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -328,35 +328,45 @@ EDA_HOTKEY* module_viewer_Hotkey_List[] = { NULL }; +// Keyword Identifiers (tags) in key code configuration file (section names) +// (.m_SectionTag member of a EDA_HOTKEY_CONFIG) +static wxString boardEditorSectionTag( wxT( "[pcbnew]" ) ); +static wxString moduleEditSectionTag( wxT( "[footprinteditor]" ) ); + +// Titles for hotkey editor and hotkey display +static wxString commonSectionTitle( _HKI( "Common" ) ); +static wxString boardEditorSectionTitle( _HKI( "Board Editor" ) ); +static wxString moduleEditSectionTitle( _HKI( "Footprint Editor" ) ); + // list of sections and corresponding hotkey list for Pcbnew - // (used to create an hotkey config file, and edit hotkeys ) +// (used to create an hotkey config file, and edit hotkeys ) struct EDA_HOTKEY_CONFIG g_Pcbnew_Editor_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, - { &g_BoardEditorSectionTag, board_edit_Hotkey_List, &g_BoardEditorSectionTitle }, - { &g_ModuleEditSectionTag, module_edit_Hotkey_List, &g_ModuleEditSectionTitle }, + { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle }, + { &boardEditorSectionTag, board_edit_Hotkey_List, &boardEditorSectionTitle }, + { &moduleEditSectionTitle, module_edit_Hotkey_List, &moduleEditSectionTitle }, { NULL, NULL, NULL } }; // list of sections and corresponding hotkey list for the board editor // (used to list current hotkeys in the board editor) struct EDA_HOTKEY_CONFIG g_Board_Editor_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, - { &g_BoardEditorSectionTag, board_edit_Hotkey_List, &g_BoardEditorSectionTitle }, + { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle }, + { &boardEditorSectionTag, board_edit_Hotkey_List, &boardEditorSectionTitle }, { NULL, NULL, NULL } }; // list of sections and corresponding hotkey list for the footprint editor // (used to list current hotkeys in the module editor) struct EDA_HOTKEY_CONFIG g_Module_Editor_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_Hotkey_List, &g_CommonSectionTitle }, - { &g_ModuleEditSectionTag, module_edit_Hotkey_List, &g_ModuleEditSectionTitle }, + { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle }, + { &moduleEditSectionTitle, module_edit_Hotkey_List, &moduleEditSectionTitle }, { NULL, NULL, NULL } }; // list of sections and corresponding hotkey list for the footprint viewer // (used to list current hotkeys in the module viewer) struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hokeys_Descr[] = { - { &g_CommonSectionTag, common_basic_Hotkey_List, &g_CommonSectionTitle }, + { &g_CommonSectionTag, common_basic_Hotkey_List, &commonSectionTitle }, { NULL, NULL, NULL } }; diff --git a/scripting/wx.i b/scripting/wx.i index d5c07774ef..aa03a3f432 100644 --- a/scripting/wx.i +++ b/scripting/wx.i @@ -298,3 +298,4 @@ public: $result = wxArrayString2PyList($1); } +%template(wxPoint_Vector) std::vector;