diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3d8c95f3f3..c63dff1e5d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -429,6 +429,7 @@ set( COMMON_SRCS settings/app_settings.cpp settings/color_settings.cpp + settings/cvpcb_settings.cpp settings/common_settings.cpp settings/json_settings.cpp settings/nested_settings.cpp diff --git a/cvpcb/cvpcb_settings.cpp b/common/settings/cvpcb_settings.cpp similarity index 99% rename from cvpcb/cvpcb_settings.cpp rename to common/settings/cvpcb_settings.cpp index 25e19cddc5..cd4d2de2f9 100644 --- a/cvpcb/cvpcb_settings.cpp +++ b/common/settings/cvpcb_settings.cpp @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index f7343497c5..aa7af50f6f 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2021 CERN - * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2022 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 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -239,11 +240,12 @@ class TEXT_BUTTON_FP_CHOOSER : public wxComboCtrl { public: TEXT_BUTTON_FP_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, - const wxString& aPreselect ) : + const wxString& aSymbolNetlist, const wxString& aPreselect ) : wxComboCtrl( aParent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ), m_dlg( aParentDlg ), - m_preselect( aPreselect ) + m_preselect( aPreselect ), + m_symbolNetlist( aSymbolNetlist.ToStdString() ) { SetButtonBitmaps( KiBitmap( BITMAPS::small_library ) ); @@ -260,13 +262,19 @@ protected: void OnButtonClick() override { // pick a footprint using the footprint picker. - wxString fpid = GetValue(); + wxString fpid = GetValue(); if( fpid.IsEmpty() ) fpid = m_preselect; KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, true, m_dlg ); + if( !m_symbolNetlist.empty() ) + { + KIWAY_EXPRESS event( FRAME_FOOTPRINT_VIEWER, MAIL_SYMBOL_NETLIST, m_symbolNetlist ); + frame->KiwayMailIn( event ); + } + if( frame->ShowModal( &fpid, m_dlg ) ) SetValue( fpid ); @@ -275,13 +283,24 @@ protected: DIALOG_SHIM* m_dlg; wxString m_preselect; + + /* + * Symbol netlist format: + * library:footprint + * reference + * value + * pinName,netName,pinFunction,pinType + * pinName,netName,pinFunction,pinType + * ... + */ + std::string m_symbolNetlist; }; -void GRID_CELL_FOOTPRINT_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, - wxEvtHandler* aEventHandler ) +void GRID_CELL_FPID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, + wxEvtHandler* aEventHandler ) { - m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_preselect ); + m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_symbolNetlist, m_preselect ); #if wxUSE_VALIDATORS // validate text in textctrl, if validator is set diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 3566140a38..4144b084e6 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -35,7 +35,6 @@ set( CVPCB_SRCS footprints_listbox.cpp library_listbox.cpp cvpcb_mainframe.cpp - cvpcb_settings.cpp listbox_base.cpp menubar.cpp readwrite_dlgs.cpp diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index 89cc101e8c..fca51618d9 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007 Jean-Pierre Charras, jp..charras at wanadoo.fr * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index e091354166..402b135da2 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index faa0d4c192..d582260129 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -26,9 +26,10 @@ #include #include #include +#include #include #include -#include +#include #include #include #include @@ -376,16 +377,20 @@ void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg ) { - CVPCB_SETTINGS* cfg = dynamic_cast( aCfg ); - wxCHECK( cfg, nullptr ); + CVPCB_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); return &cfg->m_FootprintViewer; } +PCB_VIEWERS_SETTINGS_BASE* DISPLAY_FOOTPRINTS_FRAME::GetViewerSettingsBase() const +{ + return Pgm().GetSettingsManager().GetAppSettings(); +} + + MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings() { - CVPCB_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); - wxCHECK( cfg, nullptr ); + CVPCB_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); return &cfg->m_FootprintViewerMagneticSettings; } @@ -462,21 +467,18 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() { CVPCB_MAINFRAME* parentframe = (CVPCB_MAINFRAME *) GetParent(); + COMPONENT* comp = parentframe->GetSelectedComponent(); FOOTPRINT* footprint = nullptr; const FOOTPRINT_INFO* fpInfo = nullptr; GetBoard()->DeleteAllFootprints(); + GetBoard()->GetNetInfo().RemoveUnusedNets(); GetCanvas()->GetView()->Clear(); wxString footprintName = parentframe->GetSelectedFootprint(); - if( footprintName.IsEmpty() ) - { - COMPONENT* comp = parentframe->GetSelectedComponent(); - - if( comp ) - footprintName = comp->GetFPID().GetUniStringLibId(); - } + if( footprintName.IsEmpty() && comp ) + footprintName = comp->GetFPID().GetUniStringLibId(); INFOBAR_REPORTER infoReporter( m_infoBar ); m_infoBar->Dismiss(); @@ -491,7 +493,25 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() } if( footprint ) + { + if( comp ) + { + for( PAD* pad : footprint->Pads() ) + { + const COMPONENT_NET& net = comp->GetNet( pad->GetNumber() ); + + if( !net.GetPinFunction().IsEmpty() ) + { + NETINFO_ITEM* netinfo = new NETINFO_ITEM( GetBoard() ); + netinfo->SetNetname( net.GetPinFunction() ); + GetBoard()->Add( netinfo ); + pad->SetNet( netinfo ); + } + } + } + GetBoard()->Add( footprint ); + } if( fpInfo ) SetStatusText( wxString::Format( _( "Lib: %s" ), fpInfo->GetLibNickname() ), 0 ); diff --git a/cvpcb/display_footprints_frame.h b/cvpcb/display_footprints_frame.h index cb7ce9741e..7e0ac81c8c 100644 --- a/cvpcb/display_footprints_frame.h +++ b/cvpcb/display_footprints_frame.h @@ -73,6 +73,8 @@ public: WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override; + PCB_VIEWERS_SETTINGS_BASE* GetViewerSettingsBase() const override; + MAGNETIC_SETTINGS* GetMagneticItemsSettings() override; ///< @copydoc EDA_DRAW_FRAME::UpdateMsgPanel() diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index f8924a3b60..182f8aaf66 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -829,7 +829,7 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) // set footprint column browse button attr = new wxGridCellAttr; - attr->SetEditor( new GRID_CELL_FOOTPRINT_ID_EDITOR( this ) ); + attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, wxEmptyString ) ); m_grid->SetColAttr( FOOTPRINT_FIELD, attr ); // set datasheet column viewer button diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 7f7b45247e..ded61d3f41 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -310,7 +310,7 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent, // so we need to handle m_part == nullptr // wxASSERT( m_part ); - m_fields = new FIELDS_GRID_TABLE( this, aParent, m_fieldsGrid, m_part ); + m_fields = new FIELDS_GRID_TABLE( this, aParent, m_fieldsGrid, m_symbol ); m_editorShown = false; m_lastRequestedSize = wxSize( 0, 0 ); diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index bb6b676c12..27ec0db289 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -58,6 +58,36 @@ enum #define DEFAULT_FONT_NAME _( "Default Font" ) +static wxString netList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH& aSheetPath ) +{ + /* + * Symbol netlist format: + * library:footprint + * reference + * value + * pinName,netName,pinFunction,pinType + * pinName,netName,pinFunction,pinType + * ... + */ + wxString netlist; + + netlist << EscapeString( aSymbol->GetFootprint( &aSheetPath, true ), CTX_LINE ) << wxS( "\r" ); + netlist << EscapeString( aSymbol->GetRef( &aSheetPath ), CTX_LINE ) << wxS( "\r" ); + netlist << EscapeString( aSymbol->GetValue( &aSheetPath, true ), CTX_LINE ); + + for( SCH_PIN* pin : aSymbol->GetPins( &aSheetPath ) ) + { + netlist << wxS( "\r" ); + netlist << EscapeString( pin->GetNumber(), CTX_CSV ) << wxS( "," ); + netlist << EscapeString( pin->GetDefaultNetName( aSheetPath ), CTX_CSV ) << wxS( "," ); + netlist << EscapeString( pin->GetName(), CTX_CSV ) << wxS( "," ); + netlist << EscapeString( pin->GetCanonicalElectricalTypeName(), CTX_CSV ); + } + + return netlist; +} + + template FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid, LIB_SYMBOL* aSymbol ) : @@ -80,7 +110,29 @@ FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a template -FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, +FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, + WX_GRID* aGrid, SCH_SYMBOL* aSymbol ) : + m_frame( aFrame ), + m_dialog( aDialog ), + m_grid( aGrid ), + m_parentType( SCH_SYMBOL_T ), + m_mandatoryFieldCount( MANDATORY_FIELDS ), + m_part( aSymbol->GetLibSymbolRef().get() ), + m_symbolNetlist( netList( aSymbol, aFrame->GetCurrentSheet() ) ), + m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ), + m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), REFERENCE_FIELD ), + m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ), + m_libIdValidator(), + m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), + m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), + m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME ) +{ + initGrid( aGrid ); +} + + +template +FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid, SCH_SHEET* aSheet ) : m_frame( aFrame ), m_dialog( aDialog ), @@ -101,7 +153,7 @@ FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a template -FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, +FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid, SCH_LABEL_BASE* aLabel ) : m_frame( aFrame ), m_dialog( aDialog ), @@ -147,7 +199,7 @@ void FIELDS_GRID_TABLE::initGrid( WX_GRID* aGrid ) m_valueAttr->SetEditor( valueEditor ); m_footprintAttr = new wxGridCellAttr; - GRID_CELL_FOOTPRINT_ID_EDITOR* fpIdEditor = new GRID_CELL_FOOTPRINT_ID_EDITOR( m_dialog ); + GRID_CELL_FPID_EDITOR* fpIdEditor = new GRID_CELL_FPID_EDITOR( m_dialog, m_symbolNetlist ); fpIdEditor->SetValidator( m_libIdValidator ); m_footprintAttr->SetEditor( fpIdEditor ); diff --git a/eeschema/fields_grid_table.h b/eeschema/fields_grid_table.h index 604a7f02b5..f102f3505c 100644 --- a/eeschema/fields_grid_table.h +++ b/eeschema/fields_grid_table.h @@ -77,9 +77,11 @@ class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector public: FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid, LIB_SYMBOL* aSymbol ); - FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid, + FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid, + SCH_SYMBOL* aSymbol ); + FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid, SCH_SHEET* aSheet ); - FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid, + FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid, SCH_LABEL_BASE* aLabel ); ~FIELDS_GRID_TABLE(); @@ -118,6 +120,7 @@ private: KICAD_T m_parentType; int m_mandatoryFieldCount; LIB_SYMBOL* m_part; + wxString m_symbolNetlist; wxString m_curdir; SCH_FIELD_VALIDATOR m_fieldNameValidator; diff --git a/include/mail_type.h b/include/mail_type.h index a944f90d55..2cfeb3e0ba 100644 --- a/include/mail_type.h +++ b/include/mail_type.h @@ -42,6 +42,7 @@ enum MAIL_T MAIL_ASSIGN_FOOTPRINTS, // CVPCB->SCH footprint stuffing MAIL_SCH_SAVE, // CVPCB->SCH save the schematic MAIL_EESCHEMA_NETLIST, // SCH->CVPCB netlist immediately after launching CVPCB + MAIL_SYMBOL_NETLIST, // SCH->FP_VIEWER symbol pin information MAIL_PCB_UPDATE, // SCH->PCB forward update MAIL_SCH_UPDATE, // PCB->SCH forward update MAIL_IMPORT_FILE, // Import a different format file diff --git a/cvpcb/cvpcb_settings.h b/include/settings/cvpcb_settings.h similarity index 100% rename from cvpcb/cvpcb_settings.h rename to include/settings/cvpcb_settings.h diff --git a/include/widgets/grid_text_button_helpers.h b/include/widgets/grid_text_button_helpers.h index df5c64edcf..3ffefcf725 100644 --- a/include/widgets/grid_text_button_helpers.h +++ b/include/widgets/grid_text_button_helpers.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2021 CERN - * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2022 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 @@ -89,18 +89,19 @@ protected: }; -class GRID_CELL_FOOTPRINT_ID_EDITOR : public GRID_CELL_TEXT_BUTTON +class GRID_CELL_FPID_EDITOR : public GRID_CELL_TEXT_BUTTON { public: - GRID_CELL_FOOTPRINT_ID_EDITOR( DIALOG_SHIM* aParent, - const wxString& aPreselect = wxEmptyString ) : + GRID_CELL_FPID_EDITOR( DIALOG_SHIM* aParent, const wxString& aSymbolNetlist, + const wxString& aPreselect = wxEmptyString ) : m_dlg( aParent ), - m_preselect( aPreselect ) + m_preselect( aPreselect ), + m_symbolNetlist( aSymbolNetlist ) { } wxGridCellEditor* Clone() const override { - return new GRID_CELL_FOOTPRINT_ID_EDITOR( m_dlg ); + return new GRID_CELL_FPID_EDITOR( m_dlg, m_symbolNetlist ); } void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override; @@ -108,6 +109,7 @@ public: protected: DIALOG_SHIM* m_dlg; wxString m_preselect; + wxString m_symbolNetlist; }; diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index ea39085f0d..b8327a8f13 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2012-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2016 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 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 @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -110,11 +112,12 @@ END_EVENT_TABLE() FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ), - wxDefaultPosition, wxDefaultSize, - aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? ( aParent ? PARENT_STYLE : MODAL_STYLE ) - : NONMODAL_STYLE, - aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? FOOTPRINT_VIEWER_FRAME_NAME_MODAL - : FOOTPRINT_VIEWER_FRAME_NAME ) + wxDefaultPosition, wxDefaultSize, + aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? ( aParent ? PARENT_STYLE : MODAL_STYLE ) + : NONMODAL_STYLE, + aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? FOOTPRINT_VIEWER_FRAME_NAME_MODAL + : FOOTPRINT_VIEWER_FRAME_NAME ), + m_comp( LIB_ID(), wxEmptyString, wxEmptyString, KIID_PATH(), {} ) { wxASSERT( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL || aFrameType == FRAME_FOOTPRINT_VIEWER ); @@ -145,7 +148,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent wxSizer* libSizer = new wxBoxSizer( wxVERTICAL ); m_libFilter = new wxSearchCtrl( libPanel, ID_MODVIEW_LIB_FILTER, wxEmptyString, - wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); m_libFilter->SetDescriptiveText( _( "Filter" ) ); libSizer->Add( m_libFilter, 0, wxEXPAND, 5 ); @@ -160,7 +163,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent wxSizer* fpSizer = new wxBoxSizer( wxVERTICAL ); m_fpFilter = new wxSearchCtrl( fpPanel, ID_MODVIEW_FOOTPRINT_FILTER, wxEmptyString, - wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); m_fpFilter->SetDescriptiveText( _( "Filter" ) ); m_fpFilter->SetToolTip( _( "Filter on footprint name, keywords, description and pad count.\n" @@ -738,14 +741,17 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent ) GetToolManager()->ResetTools( TOOL_BASE::MODEL_RELOAD ); GetBoard()->DeleteAllFootprints(); + GetBoard()->GetNetInfo().RemoveUnusedNets(); LIB_ID id; id.SetLibNickname( getCurNickname() ); id.SetLibItemName( getCurFootprintName() ); + FOOTPRINT* footprint = nullptr; + try { - GetBoard()->Add( loadFootprint( id ) ); + footprint = loadFootprint( id ); } catch( const IO_ERROR& ioe ) { @@ -757,6 +763,9 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent ) DisplayError( this, msg ); } + if( footprint ) + displayFootprint( footprint ); + UpdateTitle(); updateView(); @@ -767,6 +776,25 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent ) } +void FOOTPRINT_VIEWER_FRAME::displayFootprint( FOOTPRINT* aFootprint ) +{ + for( PAD* pad : aFootprint->Pads() ) + { + const COMPONENT_NET& net = m_comp.GetNet( pad->GetNumber() ); + + if( !net.GetPinFunction().IsEmpty() ) + { + NETINFO_ITEM* netinfo = new NETINFO_ITEM( GetBoard() ); + netinfo->SetNetname( net.GetPinFunction() ); + GetBoard()->Add( netinfo ); + pad->SetNet( netinfo ); + } + } + + GetBoard()->Add( aFootprint ); +} + + void FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList( wxMouseEvent& aEvent ) { wxCommandEvent evt; @@ -1004,6 +1032,52 @@ void FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton( wxUpdateUIEvent& aEvent ) } +void FOOTPRINT_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) +{ + const std::string& payload = mail.GetPayload(); + + switch( mail.Command() ) + { + case MAIL_SYMBOL_NETLIST: + { + /* + * Symbol netlist format: + * library:footprint + * reference + * value + * pinName,netName,pinFunction,pinType + * pinName,netName,pinFunction,pinType + * ... + */ + std::vector strings = split( payload, "\r" ); + LIB_ID libid; + + if( strings.size() >= 3 ) + { + libid.Parse( strings[0] ); + + m_comp.SetFPID( libid ); + m_comp.SetReference( strings[1] ); + m_comp.SetValue( strings[2] ); + + m_comp.ClearNets(); + + for( size_t ii = 3; ii < strings.size(); ++ii ) + { + std::vector pinData = split( strings[ii], "," ); + m_comp.AddNet( pinData[0], pinData[1], pinData[2], pinData[3] ); + } + } + + break; + } + + default: + ; + } +} + + bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent ) { if( aFootprint && !aFootprint->IsEmpty() ) @@ -1144,15 +1218,15 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) // Delete the current footprint GetBoard()->DeleteAllFootprints(); + GetBoard()->GetNetInfo().RemoveUnusedNets(); FOOTPRINT* footprint = Prj().PcbFootprintLibs()->FootprintLoad( getCurNickname(), getCurFootprintName() ); if( footprint ) - GetBoard()->Add( footprint, ADD_MODE::APPEND ); + displayFootprint( footprint ); Update3DView( true, true ); - updateView(); } diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index 80d3a4e348..9b6f76790d 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -29,6 +29,7 @@ #include #include #include +#include class wxSashLayoutWindow; class WX_LISTBOX; @@ -81,6 +82,8 @@ public: COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override; + void KiwayMailIn( KIWAY_EXPRESS& mail ) override; + protected: FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ); @@ -105,6 +108,8 @@ private: */ void UpdateTitle(); + void displayFootprint( FOOTPRINT* aFootprint ); + void doCloseWindow() override; void CloseFootprintViewer( wxCommandEvent& event ); void OnExitKiCad( wxCommandEvent& event ); @@ -165,6 +170,7 @@ private: friend struct PCB::IFACE; // constructor called from here only +private: wxSearchCtrl* m_libFilter; WX_LISTBOX* m_libList; // The list of library names. int m_libListWidth; // Last width of the window. @@ -173,6 +179,8 @@ private: WX_LISTBOX* m_fpList; // The list of footprint names. int m_fpListWidth; // Last width of the window. + COMPONENT m_comp; + bool m_autoZoom; double m_lastZoom; }; diff --git a/pcbnew/netlist_reader/pcb_netlist.h b/pcbnew/netlist_reader/pcb_netlist.h index 2c3acdef7b..db9833aafb 100644 --- a/pcbnew/netlist_reader/pcb_netlist.h +++ b/pcbnew/netlist_reader/pcb_netlist.h @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Jean-Pierre Charras. * Copyright (C) 2013-2016 Wayne Stambaugh . - * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2022 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 @@ -112,6 +112,8 @@ public: const COMPONENT_NET& GetNet( const wxString& aPinName ) const; + void ClearNets() { m_nets.clear(); } + void SortPins() { sort( m_nets.begin(), m_nets.end() ); } void SetName( const wxString& aName ) { m_name = aName;} @@ -120,7 +122,10 @@ public: void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; } const wxString& GetLibrary() const { return m_library; } + void SetReference( const wxString& aReference ) { m_reference = aReference; } const wxString& GetReference() const { return m_reference; } + + void SetValue( const wxString& aValue ) { m_value = aValue; } const wxString& GetValue() const { return m_value; } void SetProperties( std::map& aProps ) @@ -160,39 +165,40 @@ public: void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl ); private: - COMPONENT_NETS m_nets; ///< list of nets shared by the component pins - wxArrayString m_footprintFilters; ///< Footprint filters found in netlist. - int m_pinCount; ///< Number of pins found in netlist. - wxString m_reference; ///< The component reference designator found in netlist. - wxString m_value; ///< The component value found in netlist. + std::vector m_nets; ///< list of nets shared by the component pins + + wxArrayString m_footprintFilters; + int m_pinCount; + wxString m_reference; + wxString m_value; /// A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID, .. ] - KIID_PATH m_path; + KIID_PATH m_path; /// A vector of possible KIIDs corresponding to all units in a symbol - std::vector m_kiids; + std::vector m_kiids; - /// The name of the component in #m_library used when it was placed on the schematic.. - wxString m_name; + /// The name of the component in #m_library used when it was placed on the schematic. + wxString m_name; /// The name of the component library where #m_name was found. - wxString m_library; + wxString m_library; /// The #LIB_ID of the footprint assigned to the component. - LIB_ID m_fpid; + LIB_ID m_fpid; /// The alt LIB_ID of the footprint, when there are 2 different assigned footprints, /// One from the netlist, the other from the .cmp file. /// this one is a copy of the netlist footprint assignment - LIB_ID m_altFpid; + LIB_ID m_altFpid; /// The #FOOTPRINT loaded for #m_FPID. - std::unique_ptr< FOOTPRINT > m_footprint; + std::unique_ptr m_footprint; /// Component-specific properties found in the netlist. std::map m_properties; - static COMPONENT_NET m_emptyNet; + static COMPONENT_NET m_emptyNet; }; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index c24d5457d7..90d8b7863f 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -52,7 +52,7 @@ #include #include -#include +#include #include #include #include @@ -926,7 +926,22 @@ FOOTPRINT_EDITOR_SETTINGS* PCB_BASE_FRAME::GetFootprintEditorSettings() const PCB_VIEWERS_SETTINGS_BASE* PCB_BASE_FRAME::GetViewerSettingsBase() const { - return Pgm().GetSettingsManager().GetAppSettings(); + switch( GetFrameType() ) + { + case FRAME_PCB_EDITOR: + case FRAME_FOOTPRINT_EDITOR: + case FRAME_FOOTPRINT_WIZARD: + case FRAME_PCB_DISPLAY3D: + default: + return Pgm().GetSettingsManager().GetAppSettings(); + + case FRAME_FOOTPRINT_VIEWER: + case FRAME_FOOTPRINT_VIEWER_MODAL: + case FRAME_FOOTPRINT_PREVIEW: + case FRAME_CVPCB: + case FRAME_CVPCB_DISPLAY: + return Pgm().GetSettingsManager().GetAppSettings(); + } } diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 4091cdf284..9a474b8c6f 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2017 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -210,7 +210,12 @@ PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_view = new KIGFX::PCB_VIEW( true ); m_view->SetGAL( m_gal ); - m_painter = std::make_unique( m_gal ); + FRAME_T frameType = FRAME_FOOTPRINT_PREVIEW; + + if( EDA_BASE_FRAME* frame = dynamic_cast( aParentWindow ) ) + frameType = frame->GetFrameType(); + + m_painter = std::make_unique( m_gal, frameType ); m_view->SetPainter( m_painter.get() ); // This fixes the zoom in and zoom out limits: diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index f66b49d4d9..4a78e85283 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -76,34 +77,24 @@ PCBNEW_SETTINGS* pcbconfig() // Helpers for display options existing in Cvpcb and Pcbnew // Note, when running Cvpcb, pcbconfig() returns nullptr and viewer_settings() // returns the viewer options existing to Cvpcb and Pcbnew -static PCB_VIEWERS_SETTINGS_BASE* viewer_settings() +PCB_VIEWERS_SETTINGS_BASE* PCB_PAINTER::viewer_settings() { - if( pcbconfig() ) + switch( m_frameType ) + { + case FRAME_PCB_EDITOR: + case FRAME_FOOTPRINT_EDITOR: + case FRAME_FOOTPRINT_WIZARD: + case FRAME_PCB_DISPLAY3D: + default: return Pgm().GetSettingsManager().GetAppSettings(); - else - return dynamic_cast( Kiface().KifaceSettings() ); -} -static bool displayPadFill() -{ - return viewer_settings()->m_ViewersDisplay.m_DisplayPadFill; -} - -static bool displayGraphicsFill() -{ - return viewer_settings()->m_ViewersDisplay.m_DisplayGraphicsFill; -} - - -static bool displayTextFill() -{ - return viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; -} - - -static bool displayPadNumbers() -{ - return viewer_settings()->m_ViewersDisplay.m_DisplayPadNumbers; + case FRAME_FOOTPRINT_VIEWER: + case FRAME_FOOTPRINT_VIEWER_MODAL: + case FRAME_FOOTPRINT_PREVIEW: + case FRAME_CVPCB: + case FRAME_CVPCB_DISPLAY: + return Pgm().GetSettingsManager().GetAppSettings(); + } } @@ -406,8 +397,9 @@ bool PCB_RENDER_SETTINGS::GetShowPageLimits() const } -PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : +PCB_PAINTER::PCB_PAINTER( GAL* aGal, FRAME_T aFrameType ) : PAINTER( aGal ), + m_frameType( aFrameType ), m_maxError( ARC_HIGH_DEF ), m_holePlatingThickness( 0 ) { @@ -996,11 +988,11 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) wxString netname; wxString padNumber; - if( displayPadNumbers() ) + if( viewer_settings()->m_ViewersDisplay.m_DisplayPadNumbers ) { padNumber = UnescapeString( aPad->GetNumber() ); - if( !displayOpts ) + if( dynamic_cast( viewer_settings() ) ) netname = UnescapeString( aPad->GetShortNetname() ); } @@ -1078,7 +1070,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) // position to display 2 lines if( !netname.IsEmpty() && !padNumber.IsEmpty() ) { - size = size / 2.5; + size = size / 2.2; textpos.y = size / 1.7; } @@ -1089,11 +1081,12 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) tsize = std::min( tsize, size ); // Use a smaller text size to handle interline, pen size... - tsize *= 0.75; + tsize *= 0.85; VECTOR2D namesize( tsize, tsize ); m_gal->SetGlyphSize( namesize ); - m_gal->SetLineWidth( namesize.x / 12.0 ); + m_gal->SetLineWidth( namesize.x / 6.0 ); + m_gal->SetFontBold( true ); m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL ); } @@ -1106,12 +1099,13 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) tsize = std::min( tsize, size ); // Use a smaller text size to handle interline, pen size... - tsize *= 0.75; + tsize *= 0.85; tsize = std::min( tsize, size ); VECTOR2D numsize( tsize, tsize ); m_gal->SetGlyphSize( numsize ); - m_gal->SetLineWidth( numsize.x / 12.0 ); + m_gal->SetLineWidth( numsize.x / 6.0 ); + m_gal->SetFontBold( true ); m_gal->BitmapText( padNumber, textpos, ANGLE_HORIZONTAL ); } @@ -1137,7 +1131,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) return; } - bool outline_mode = !displayPadFill(); + bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayPadFill; if( m_pcbSettings.m_ForcePadSketchModeOff ) outline_mode = false; @@ -1452,7 +1446,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer ) { COLOR4D color = m_pcbSettings.GetColor( aShape, aShape->GetLayer() ); - bool outline_mode = !displayGraphicsFill(); + bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayGraphicsFill; int thickness = getLineThickness( aShape->GetWidth() ); PLOT_DASH_TYPE lineStyle = aShape->GetStroke().GetPlotStyle(); @@ -1773,7 +1767,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) TEXT_ATTRIBUTES attrs = aText->GetAttributes(); const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() ); - bool outline_mode = !displayTextFill(); + bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; m_gal->SetStrokeColor( color ); m_gal->SetFillColor( color ); @@ -1926,7 +1920,7 @@ void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer ) return; const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); - bool outline_mode = !displayTextFill(); + bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; TEXT_ATTRIBUTES attrs = aText->GetAttributes(); m_gal->SetStrokeColor( color ); @@ -2266,7 +2260,7 @@ void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer ) m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); - bool outline_mode = !displayGraphicsFill(); + bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayGraphicsFill; if( outline_mode ) m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 90e4a32508..d527ed699b 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -28,6 +28,7 @@ #ifndef PCB_PAINTER_H #define PCB_PAINTER_H +#include #include #include #include @@ -36,6 +37,7 @@ class EDA_ITEM; class PCB_DISPLAY_OPTIONS; +class PCB_VIEWERS_SETTINGS_BASE; class BOARD_ITEM; class PCB_ARC; class BOARD; @@ -153,7 +155,7 @@ protected: class PCB_PAINTER : public PAINTER { public: - PCB_PAINTER( GAL* aGal ); + PCB_PAINTER( GAL* aGal, FRAME_T aFrameType ); /// @copydoc PAINTER::GetSettings() virtual PCB_RENDER_SETTINGS* GetSettings() override @@ -165,6 +167,8 @@ public: virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override; protected: + PCB_VIEWERS_SETTINGS_BASE* viewer_settings(); + // Drawing functions for various types of PCB-specific items void draw( const PCB_TRACK* aTrack, int aLayer ); void draw( const PCB_ARC* aArc, int aLayer ); @@ -211,6 +215,7 @@ protected: protected: PCB_RENDER_SETTINGS m_pcbSettings; + FRAME_T m_frameType; int m_maxError; int m_holePlatingThickness; diff --git a/pcbnew/pcbnew_printout.cpp b/pcbnew/pcbnew_printout.cpp index 9ffae36325..ce2611850f 100644 --- a/pcbnew/pcbnew_printout.cpp +++ b/pcbnew/pcbnew_printout.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018 CERN * Author: Maciej Suminski * Author: Tomasz Wlostowski @@ -283,7 +283,7 @@ std::unique_ptr PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal ) KIGFX::PCB_PRINT_PAINTER::PCB_PRINT_PAINTER( GAL* aGal ) : - PCB_PAINTER( aGal ), + PCB_PAINTER( aGal, FRAME_PCB_EDITOR ), m_drillMarkReal( false ), m_drillMarkSize( 0 ) { }