eeschema: add 'Already placed' category when choosing symbol

This commit is contained in:
Franck Jullien 2021-03-13 23:13:47 +01:00 committed by Mike Williams
parent 37df47a3e7
commit c010c7b0ea
9 changed files with 93 additions and 34 deletions

View File

@ -670,6 +670,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
{
// Use library viewer to choose a symbol
std::vector<PICKED_SYMBOL> dummyHistory;
std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
LIB_ID preselected;
wxString current = getLibIdValue( m_grid, aRow, COL_NEW_LIBID );
@ -679,8 +680,8 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
if( !current.IsEmpty() )
preselected.Parse( current, true );
PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibrary( nullptr, dummyHistory, false,
&preselected, false );
PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibrary(
nullptr, dummyHistory, dummyAlreadyPlaced, false, &preselected, false );
if( sel.LibId.empty() ) // command aborted
return false;

View File

@ -41,12 +41,13 @@ std::mutex DIALOG_SYMBOL_CHOOSER::g_Mutex;
DIALOG_SYMBOL_CHOOSER::DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect,
const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
bool aAllowFieldEdits, bool aShowFootprints ) :
DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
{
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
m_chooserPanel = new PANEL_SYMBOL_CHOOSER( aParent, this, aFilter, aHistoryList,
m_chooserPanel = new PANEL_SYMBOL_CHOOSER( aParent, this, aFilter, aHistoryList, aAlreadyPlaced,
aAllowFieldEdits, aShowFootprints,
[this]()
{

View File

@ -24,6 +24,7 @@
#define DIALOG_SYMBOL_CHOOSER_H
#include "dialog_shim.h"
#include <symbol_library_common.h>
#include <symbol_tree_model_adapter.h>
#include <footprint_info.h>
#include <widgets/html_window.h>
@ -50,7 +51,8 @@ public:
DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect,
const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
bool aAllowFieldEdits, bool aShowFootprints );
std::vector<PICKED_SYMBOL>& aAlreadyPlaced, bool aAllowFieldEdits,
bool aShowFootprints );
~DIALOG_SYMBOL_CHOOSER();

View File

@ -24,6 +24,7 @@
*/
#include <pgm_base.h>
#include <symbol_library.h>
#include <settings/settings_manager.h>
#include <project/project_file.h>
#include <core/kicad_algo.h>
@ -47,6 +48,7 @@
PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
bool aShowFootprints, const LIB_ID* aHighlight,
bool aAllowFields )
{
@ -56,8 +58,8 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER
if( !dialogLock.try_lock() )
return PICKED_SYMBOL();
DIALOG_SYMBOL_CHOOSER dlg( this, aHighlight, aFilter, aHistoryList, aAllowFields,
aShowFootprints );
DIALOG_SYMBOL_CHOOSER dlg( this, aHighlight, aFilter, aHistoryList, aAlreadyPlaced,
aAllowFields, aShowFootprints );
if( dlg.ShowModal() == wxID_CANCEL )
return PICKED_SYMBOL();

View File

@ -155,6 +155,7 @@ public:
*/
PICKED_SYMBOL PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
bool aShowFootprints, const LIB_ID* aHighlight = nullptr,
bool aAllowFields = true );

View File

@ -72,8 +72,11 @@ SYMBOL_CHOOSER_FRAME::SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
SetModal( true );
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
m_chooserPanel = new PANEL_SYMBOL_CHOOSER( this, this, nullptr /* no filter */,
s_SymbolHistoryList, false, false,
std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
m_chooserPanel =
new PANEL_SYMBOL_CHOOSER( this, this, nullptr /* no filter */, s_SymbolHistoryList,
dummyAlreadyPlaced, false, false,
[this]()
{
wxCommandEvent dummy;

View File

@ -25,6 +25,7 @@
#include <memory>
#include <kiplatform/ui.h>
#include <project_sch.h>
#include <tools/sch_drawing_tools.h>
#include <tools/sch_line_wire_bus_tool.h>
#include <tools/ee_selection_tool.h>
@ -49,7 +50,7 @@
#include <sch_bitmap.h>
#include <schematic.h>
#include <sch_commit.h>
#include <symbol_library_common.h>
#include <symbol_library.h>
#include <eeschema_settings.h>
#include <dialogs/dialog_label_properties.h>
#include <dialogs/dialog_text_properties.h>
@ -303,10 +304,43 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets();
SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
SYMBOL_LIB* cache = PROJECT_SCH::SchLibs( &m_frame->Prj() )->GetCacheLibrary();
std::vector<LIB_SYMBOL*> part_list;
for( SCH_SHEET_PATH& sheet : sheets )
{
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
{
if( item->Type() != SCH_SYMBOL_T )
continue;
SCH_SYMBOL* s = static_cast<SCH_SYMBOL*>( item );
LIB_SYMBOL* libSymbol = SchGetLibSymbol( s->GetLibId(), libs, cache );
if( libSymbol )
part_list.push_back( libSymbol );
}
}
// Remove redundant parts
sort( part_list.begin(), part_list.end() );
part_list.erase( unique( part_list.begin(), part_list.end() ), part_list.end() );
std::vector<PICKED_SYMBOL> alreadyPlaced;
for( LIB_SYMBOL* libSymbol : part_list )
{
PICKED_SYMBOL pickedSymbol;
pickedSymbol.LibId = libSymbol->GetLibId();
alreadyPlaced.push_back( pickedSymbol );
}
// Pick the symbol to be placed
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary( &filter, *historyList,
footprintPreviews );
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary(
&filter, *historyList, alreadyPlaced, footprintPreviews );
LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ? m_frame->GetLibSymbol( sel.LibId )
: nullptr;

View File

@ -52,6 +52,7 @@ wxString PANEL_SYMBOL_CHOOSER::g_powerSearchString;
PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
bool aAllowFieldEdits, bool aShowFootprints,
std::function<void()> aCloseHandler ) :
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
@ -119,29 +120,39 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
std::vector<LIB_SYMBOL> history_list_storage;
std::vector<LIB_TREE_ITEM*> history_list;
std::vector<LIB_SYMBOL> already_placed_storage;
std::vector<LIB_TREE_ITEM*> already_placed;
history_list_storage.reserve( aHistoryList.size() );
// Lambda to encapsulate the common logic
auto processList = [&]( const std::vector<PICKED_SYMBOL>& inputList,
std::vector<LIB_SYMBOL>& storageList,
std::vector<LIB_TREE_ITEM*>& resultList )
{
storageList.reserve( inputList.size() );
for( const PICKED_SYMBOL& i : aHistoryList )
for( const PICKED_SYMBOL& i : inputList )
{
LIB_SYMBOL* symbol = m_frame->GetLibSymbol( i.LibId );
// This can be null, for example when a symbol has been deleted from a library
if( symbol )
{
history_list_storage.emplace_back( *symbol );
storageList.emplace_back( *symbol );
for( const std::pair<int, wxString>& fieldDef : i.Fields )
{
LIB_FIELD* field = history_list_storage.back().GetFieldById( fieldDef.first );
LIB_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
if( field )
field->SetText( fieldDef.second );
}
history_list.push_back( &history_list_storage.back() );
resultList.push_back( &storageList.back() );
}
}
};
processList( aHistoryList, history_list_storage, history_list );
processList( aAlreadyPlaced, already_placed_storage, already_placed );
adapter->DoAddLibrary( wxT( "-- " ) + _( "Recently Used" ) + wxT( " --" ), wxEmptyString,
history_list, false, true );
@ -149,6 +160,9 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
if( !aHistoryList.empty() )
adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
adapter->DoAddLibrary( wxT( "-- " ) + _( "Already Placed" ) + wxT( " --" ), wxEmptyString,
already_placed, false, true );
const std::vector< wxString > libNicknames = libs->GetLogicalLibs();
if( !loaded )

View File

@ -57,6 +57,7 @@ public:
PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
const SYMBOL_LIBRARY_FILTER* aFilter,
std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
bool aAllowFieldEdits, bool aShowFootprints,
std::function<void()> aCloseHandler );