Commit 4daf9039 authored by jean-pierre charras's avatar jean-pierre charras

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.
parent 4354139f
......@@ -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 ) );
......
......@@ -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
/**
......
/*
* 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 <stambaughw@verizon.net>
* 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
......
......@@ -63,7 +63,7 @@ typedef boost::weak_ptr<LIB_PART> 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
......
......@@ -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<wxArrayString>&.
......@@ -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 );
......
/*
* 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 <stambaughw@verizon.net>
* 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();
};
......
......@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* 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;
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;
}
}
......
......@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* 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<TREE_NODE*> 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 */
/*
* 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;
......
/*
* 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 <stambaughw@verizon.net>
* 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 <boost/foreach.hpp>
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( aFilter )
{
const wxArrayString& liblist = aFilter->GetAllowedLibList();
if( !aLibname.IsEmpty() )
for( unsigned ii = 0; ii < liblist.GetCount(); ii++ )
{
PART_LIB* currLibrary = libs->FindLibrary( aLibname );
PART_LIB* currLibrary = libs->FindLibrary( liblist[ii] );
if( currLibrary )
{
cmpCount = currLibrary->GetCount();
loaded = true;
search_container.AddLibrary( *currLibrary );
}
}
else
if( aFilter->GetFilterPowerParts() )
search_container.SetFilter( COMPONENT_TREE_SEARCH_CONTAINER::CMP_FILTER_POWER );
}
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 )
{
......
/*
* 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 <stambaughw@verizon.net>
* 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,8 +331,8 @@ 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 },
{ &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
{ &schematicSectionTitle, schematic_Hotkey_List, &schematicSectionTitle },
{ NULL, NULL, NULL }
};
......@@ -330,8 +340,8 @@ struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[] =
// (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 },
{ &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
{ &libEditSectionTag, libEdit_Hotkey_List, &schematicSectionTitle },
{ NULL, NULL, NULL }
};
......@@ -339,7 +349,7 @@ struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[] =
// (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 }
};
......
......@@ -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() )
......
/*
* 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 <stambaughw@verizon.net>
* 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 <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_bitmap.h>
#include <class_library.h> // 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 );
}
......
......@@ -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 );
/**
......
......@@ -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 );
......
/*
* 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 <stambaughw@verizon.net>
* 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 )
......
......@@ -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;
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();
}
......@@ -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
......
......@@ -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
......
......@@ -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, &sectionTitle },
......
......@@ -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 }
};
......
......@@ -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 }
};
......
......@@ -298,3 +298,4 @@ public:
$result = wxArrayString2PyList($1);
}
%template(wxPoint_Vector) std::vector<wxPoint>;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment