eeschema: add 'Already placed' category when choosing symbol
This commit is contained in:
parent
37df47a3e7
commit
c010c7b0ea
|
@ -670,6 +670,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
|
||||||
{
|
{
|
||||||
// Use library viewer to choose a symbol
|
// Use library viewer to choose a symbol
|
||||||
std::vector<PICKED_SYMBOL> dummyHistory;
|
std::vector<PICKED_SYMBOL> dummyHistory;
|
||||||
|
std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
|
||||||
LIB_ID preselected;
|
LIB_ID preselected;
|
||||||
wxString current = getLibIdValue( m_grid, aRow, COL_NEW_LIBID );
|
wxString current = getLibIdValue( m_grid, aRow, COL_NEW_LIBID );
|
||||||
|
|
||||||
|
@ -679,8 +680,8 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
|
||||||
if( !current.IsEmpty() )
|
if( !current.IsEmpty() )
|
||||||
preselected.Parse( current, true );
|
preselected.Parse( current, true );
|
||||||
|
|
||||||
PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibrary( nullptr, dummyHistory, false,
|
PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibrary(
|
||||||
&preselected, false );
|
nullptr, dummyHistory, dummyAlreadyPlaced, false, &preselected, false );
|
||||||
|
|
||||||
if( sel.LibId.empty() ) // command aborted
|
if( sel.LibId.empty() ) // command aborted
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -40,13 +40,14 @@ std::mutex DIALOG_SYMBOL_CHOOSER::g_Mutex;
|
||||||
|
|
||||||
DIALOG_SYMBOL_CHOOSER::DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect,
|
DIALOG_SYMBOL_CHOOSER::DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect,
|
||||||
const SYMBOL_LIBRARY_FILTER* aFilter,
|
const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aAllowFieldEdits, bool aShowFootprints ) :
|
bool aAllowFieldEdits, bool aShowFootprints ) :
|
||||||
DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize,
|
DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
||||||
{
|
{
|
||||||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
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,
|
aAllowFieldEdits, aShowFootprints,
|
||||||
[this]()
|
[this]()
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define DIALOG_SYMBOL_CHOOSER_H
|
#define DIALOG_SYMBOL_CHOOSER_H
|
||||||
|
|
||||||
#include "dialog_shim.h"
|
#include "dialog_shim.h"
|
||||||
|
#include <symbol_library_common.h>
|
||||||
#include <symbol_tree_model_adapter.h>
|
#include <symbol_tree_model_adapter.h>
|
||||||
#include <footprint_info.h>
|
#include <footprint_info.h>
|
||||||
#include <widgets/html_window.h>
|
#include <widgets/html_window.h>
|
||||||
|
@ -50,7 +51,8 @@ public:
|
||||||
DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect,
|
DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect,
|
||||||
const SYMBOL_LIBRARY_FILTER* aFilter,
|
const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
bool aAllowFieldEdits, bool aShowFootprints );
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced, bool aAllowFieldEdits,
|
||||||
|
bool aShowFootprints );
|
||||||
|
|
||||||
~DIALOG_SYMBOL_CHOOSER();
|
~DIALOG_SYMBOL_CHOOSER();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pgm_base.h>
|
#include <pgm_base.h>
|
||||||
|
#include <symbol_library.h>
|
||||||
#include <settings/settings_manager.h>
|
#include <settings/settings_manager.h>
|
||||||
#include <project/project_file.h>
|
#include <project/project_file.h>
|
||||||
#include <core/kicad_algo.h>
|
#include <core/kicad_algo.h>
|
||||||
|
@ -46,7 +47,8 @@
|
||||||
#include <dialog_symbol_chooser.h>
|
#include <dialog_symbol_chooser.h>
|
||||||
|
|
||||||
PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
|
PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aShowFootprints, const LIB_ID* aHighlight,
|
bool aShowFootprints, const LIB_ID* aHighlight,
|
||||||
bool aAllowFields )
|
bool aAllowFields )
|
||||||
{
|
{
|
||||||
|
@ -56,8 +58,8 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER
|
||||||
if( !dialogLock.try_lock() )
|
if( !dialogLock.try_lock() )
|
||||||
return PICKED_SYMBOL();
|
return PICKED_SYMBOL();
|
||||||
|
|
||||||
DIALOG_SYMBOL_CHOOSER dlg( this, aHighlight, aFilter, aHistoryList, aAllowFields,
|
DIALOG_SYMBOL_CHOOSER dlg( this, aHighlight, aFilter, aHistoryList, aAlreadyPlaced,
|
||||||
aShowFootprints );
|
aAllowFields, aShowFootprints );
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
if( dlg.ShowModal() == wxID_CANCEL )
|
||||||
return PICKED_SYMBOL();
|
return PICKED_SYMBOL();
|
||||||
|
|
|
@ -154,7 +154,8 @@ public:
|
||||||
* @return the selected symbol
|
* @return the selected symbol
|
||||||
*/
|
*/
|
||||||
PICKED_SYMBOL PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
|
PICKED_SYMBOL PickSymbolFromLibrary( const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aShowFootprints, const LIB_ID* aHighlight = nullptr,
|
bool aShowFootprints, const LIB_ID* aHighlight = nullptr,
|
||||||
bool aAllowFields = true );
|
bool aAllowFields = true );
|
||||||
|
|
||||||
|
|
|
@ -72,13 +72,16 @@ SYMBOL_CHOOSER_FRAME::SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||||
SetModal( true );
|
SetModal( true );
|
||||||
|
|
||||||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
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;
|
||||||
[this]()
|
m_chooserPanel =
|
||||||
{
|
new PANEL_SYMBOL_CHOOSER( this, this, nullptr /* no filter */, s_SymbolHistoryList,
|
||||||
wxCommandEvent dummy;
|
dummyAlreadyPlaced, false, false,
|
||||||
OnOK( dummy );
|
[this]()
|
||||||
} );
|
{
|
||||||
|
wxCommandEvent dummy;
|
||||||
|
OnOK( dummy );
|
||||||
|
} );
|
||||||
|
|
||||||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <kiplatform/ui.h>
|
#include <kiplatform/ui.h>
|
||||||
|
#include <project_sch.h>
|
||||||
#include <tools/sch_drawing_tools.h>
|
#include <tools/sch_drawing_tools.h>
|
||||||
#include <tools/sch_line_wire_bus_tool.h>
|
#include <tools/sch_line_wire_bus_tool.h>
|
||||||
#include <tools/ee_selection_tool.h>
|
#include <tools/ee_selection_tool.h>
|
||||||
|
@ -49,7 +50,7 @@
|
||||||
#include <sch_bitmap.h>
|
#include <sch_bitmap.h>
|
||||||
#include <schematic.h>
|
#include <schematic.h>
|
||||||
#include <sch_commit.h>
|
#include <sch_commit.h>
|
||||||
#include <symbol_library_common.h>
|
#include <symbol_library.h>
|
||||||
#include <eeschema_settings.h>
|
#include <eeschema_settings.h>
|
||||||
#include <dialogs/dialog_label_properties.h>
|
#include <dialogs/dialog_label_properties.h>
|
||||||
#include <dialogs/dialog_text_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 );
|
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
|
// Pick the symbol to be placed
|
||||||
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
|
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
|
||||||
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary( &filter, *historyList,
|
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary(
|
||||||
footprintPreviews );
|
&filter, *historyList, alreadyPlaced, footprintPreviews );
|
||||||
|
|
||||||
LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ? m_frame->GetLibSymbol( sel.LibId )
|
LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ? m_frame->GetLibSymbol( sel.LibId )
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
|
|
@ -51,7 +51,8 @@ wxString PANEL_SYMBOL_CHOOSER::g_powerSearchString;
|
||||||
|
|
||||||
PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
|
PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
|
||||||
const SYMBOL_LIBRARY_FILTER* aFilter,
|
const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aAllowFieldEdits, bool aShowFootprints,
|
bool aAllowFieldEdits, bool aShowFootprints,
|
||||||
std::function<void()> aCloseHandler ) :
|
std::function<void()> aCloseHandler ) :
|
||||||
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
|
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_SYMBOL> history_list_storage;
|
||||||
std::vector<LIB_TREE_ITEM*> history_list;
|
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,
|
||||||
for( const PICKED_SYMBOL& i : aHistoryList )
|
std::vector<LIB_SYMBOL>& storageList,
|
||||||
|
std::vector<LIB_TREE_ITEM*>& resultList )
|
||||||
{
|
{
|
||||||
LIB_SYMBOL* symbol = m_frame->GetLibSymbol( i.LibId );
|
storageList.reserve( inputList.size() );
|
||||||
|
|
||||||
// This can be null, for example when a symbol has been deleted from a library
|
for( const PICKED_SYMBOL& i : inputList )
|
||||||
if( symbol )
|
|
||||||
{
|
{
|
||||||
history_list_storage.emplace_back( *symbol );
|
LIB_SYMBOL* symbol = m_frame->GetLibSymbol( i.LibId );
|
||||||
|
|
||||||
for( const std::pair<int, wxString>& fieldDef : i.Fields )
|
if( symbol )
|
||||||
{
|
{
|
||||||
LIB_FIELD* field = history_list_storage.back().GetFieldById( fieldDef.first );
|
storageList.emplace_back( *symbol );
|
||||||
|
|
||||||
if( field )
|
for( const std::pair<int, wxString>& fieldDef : i.Fields )
|
||||||
field->SetText( fieldDef.second );
|
{
|
||||||
|
LIB_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
|
||||||
|
|
||||||
|
if( field )
|
||||||
|
field->SetText( fieldDef.second );
|
||||||
|
}
|
||||||
|
|
||||||
|
resultList.push_back( &storageList.back() );
|
||||||
}
|
}
|
||||||
|
|
||||||
history_list.push_back( &history_list_storage.back() );
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
processList( aHistoryList, history_list_storage, history_list );
|
||||||
|
processList( aAlreadyPlaced, already_placed_storage, already_placed );
|
||||||
|
|
||||||
adapter->DoAddLibrary( wxT( "-- " ) + _( "Recently Used" ) + wxT( " --" ), wxEmptyString,
|
adapter->DoAddLibrary( wxT( "-- " ) + _( "Recently Used" ) + wxT( " --" ), wxEmptyString,
|
||||||
history_list, false, true );
|
history_list, false, true );
|
||||||
|
@ -149,6 +160,9 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
||||||
if( !aHistoryList.empty() )
|
if( !aHistoryList.empty() )
|
||||||
adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
|
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();
|
const std::vector< wxString > libNicknames = libs->GetLogicalLibs();
|
||||||
|
|
||||||
if( !loaded )
|
if( !loaded )
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
|
PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
|
||||||
const SYMBOL_LIBRARY_FILTER* aFilter,
|
const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aAllowFieldEdits, bool aShowFootprints,
|
bool aAllowFieldEdits, bool aShowFootprints,
|
||||||
std::function<void()> aCloseHandler );
|
std::function<void()> aCloseHandler );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue