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 <footprint.h>
31#include <project_pcb.h>
32
33
35 FOOTPRINT* aFootprint ) :
37 m_frame( aFrame ),
38 m_footprint( aFootprint )
39{
40 // Remove wxgrid's selection boxes
41 for( wxGrid* grid : { m_gridLibrary, m_gridSymbol } )
42 grid->SetCellHighlightPenWidth( 0 );
43
46
47 m_gridLibrary->SetCellValue( 0, 0, _( "Library: " ) );
48 m_gridLibrary->SetCellValue( 1, 0, _( "Footprint: " ) );
49}
50
51
53{
54 LIB_ID fpID = m_footprint->GetFPID();
55 wxString libName = fpID.GetLibNickname();
56 wxString fpName = fpID.GetLibItemName();
57 wxString libDesc;
58 wxString fpDesc;
59
62 const LIB_TABLE_ROW* libTableRow = nullptr;
63
64 try
65 {
66 libTableRow = libTable->FindRow( libName );
67 libDesc = libTableRow->GetDescr();
68 }
69 catch( const IO_ERROR& )
70 {
71 }
72
73 std::shared_ptr<FOOTPRINT> libFootprint;
74
75 try
76 {
77 libFootprint.reset( libTable->FootprintLoad( libName, fpName, true ) );
78 fpDesc = libFootprint->GetLibDescription();
79 }
80 catch( const IO_ERROR& )
81 {
82 }
83
84 m_gridLibrary->SetCellValue( 0, 1, fpID.GetLibNickname() );
85 m_gridLibrary->SetCellValue( 0, 2, libDesc );
86
87 m_gridLibrary->SetCellValue( 1, 1, fpID.GetLibItemName() );
88 m_gridLibrary->SetCellValue( 1, 2, fpDesc );
89
90 KIID_PATH symbolPath = m_footprint->GetPath();
91
93
94 for( int ii = 0; ii < (int) symbolPath.size(); ++ii )
95 {
96 m_gridSymbol->AppendRows();
97 m_gridSymbol->SetCellValue( ii, 0, ii == (int) symbolPath.size() - 1 ? _( "Symbol:" )
98 : _( "Sheet: " ) );
99 m_gridSymbol->SetCellValue( ii, 1, symbolPath[ii].AsString() );
100
101 if( !Kiface().IsSingle() && m_frame->Kiway().Player( FRAME_SCH, false ) )
102 {
103 std::string item = symbolPath[ii].AsString().ToStdString();
105 m_gridSymbol->SetCellValue( ii, 2, item );
106 }
107 }
108
110
111 return true;
112}
113
114
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:46
PROJECT * GetProject() const
Definition: board.h:476
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:233
const KIID_PATH & GetPath() const
Definition: footprint.h:249
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:368
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:62
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:157
#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:127