KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_footprint_associations.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
26#include <widgets/wx_grid.h>
27#include <pcb_base_frame.h>
28#include <kiface_base.h>
29#include <fp_lib_table.h>
30#include <board.h>
31#include <footprint.h>
32#include <project_pcb.h>
33
34
36 FOOTPRINT* aFootprint ) :
38 m_frame( aFrame ),
39 m_footprint( aFootprint )
40{
41 // Remove wxgrid's selection boxes
42 for( wxGrid* grid : { m_gridLibrary, m_gridSymbol } )
43 grid->SetCellHighlightPenWidth( 0 );
44
47
48 m_gridLibrary->SetCellValue( 0, 0, _( "Library: " ) );
49 m_gridLibrary->SetCellValue( 1, 0, _( "Footprint: " ) );
50}
51
52
54{
55 LIB_ID fpID = m_footprint->GetFPID();
56 wxString libName = fpID.GetLibNickname();
57 wxString fpName = fpID.GetLibItemName();
58 wxString libDesc;
59 wxString fpDesc;
60
63 const LIB_TABLE_ROW* libTableRow = nullptr;
64
65 try
66 {
67 libTableRow = libTable->FindRow( libName );
68 libDesc = libTableRow->GetDescr();
69 }
70 catch( const IO_ERROR& )
71 {
72 }
73
74 std::shared_ptr<FOOTPRINT> libFootprint;
75
76 try
77 {
78 libFootprint.reset( libTable->FootprintLoad( libName, fpName, true ) );
79 fpDesc = libFootprint->GetLibDescription();
80 }
81 catch( const IO_ERROR& )
82 {
83 }
84
85 m_gridLibrary->SetCellValue( 0, 1, fpID.GetLibNickname() );
86 m_gridLibrary->SetCellValue( 0, 2, libDesc );
87
88 m_gridLibrary->SetCellValue( 1, 1, fpID.GetLibItemName() );
89 m_gridLibrary->SetCellValue( 1, 2, fpDesc );
90
91 KIID_PATH symbolPath = m_footprint->GetPath();
92
94
95 for( int ii = 0; ii < (int) symbolPath.size(); ++ii )
96 {
97 m_gridSymbol->AppendRows();
98 m_gridSymbol->SetCellValue( ii, 0, ii == (int) symbolPath.size() - 1 ? _( "Symbol:" )
99 : _( "Sheet: " ) );
100 m_gridSymbol->SetCellValue( ii, 1, symbolPath[ii].AsString() );
101
102 if( !Kiface().IsSingle() && m_frame->Kiway().Player( FRAME_SCH, false ) )
103 {
104 std::string item = symbolPath[ii].AsString().ToStdString();
106 m_gridSymbol->SetCellValue( ii, 2, item );
107 }
108 }
109
111
112 return true;
113}
114
115
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
PROJECT * GetProject() const
Definition: board.h:491
Class DIALOG_FOOTPRINT_ASSOCIATIONS_BASE.
DIALOG_FOOTPRINT_ASSOCIATIONS(PCB_BASE_FRAME *aFrame, FOOTPRINT *aFootprint)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const LIB_ID & GetFPID() const
Definition: footprint.h:248
const KIID_PATH & GetPath() const
Definition: footprint.h:263
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
FOOTPRINT * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
Load a footprint having aFootprintName from the library given by aNickname.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
bool IsSingle() const
Is this KIFACE running under single_top?
Definition: kiface_base.h:107
wxString AsString() const
Definition: kiid.cpp:348
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:527
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetDescr() const
Return the description of the library referenced by this row.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Definition: project_pcb.cpp:37
Container for project specific data.
Definition: project.h:64
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
#define _(s)
@ FRAME_SCH
Definition: frame_type.h:34
@ MAIL_SCH_GET_ITEM
Definition: mail_type.h:50
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:130