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 The 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>
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
61 PROJECT* project = m_footprint->GetBoard()->GetProject();
63
64 if( std::optional<LIBRARY_TABLE_ROW*> row = adapter->GetRow( libName ); row )
65 libDesc = ( *row )->Description();
66
67 std::shared_ptr<FOOTPRINT> libFootprint;
68
69 try
70 {
71 libFootprint.reset( adapter->LoadFootprint( libName, fpName, true ) );
72 fpDesc = libFootprint->GetLibDescription();
73 }
74 catch( const IO_ERROR& )
75 {
76 }
77
78 m_gridLibrary->SetCellValue( 0, 1, fpID.GetLibNickname() );
79 m_gridLibrary->SetCellValue( 0, 2, libDesc );
80
81 m_gridLibrary->SetCellValue( 1, 1, fpID.GetLibItemName() );
82 m_gridLibrary->SetCellValue( 1, 2, fpDesc );
83
84 KIID_PATH symbolPath = m_footprint->GetPath();
85
86 m_gridSymbol->ClearRows();
87
88 for( int ii = 0; ii < (int) symbolPath.size(); ++ii )
89 {
90 m_gridSymbol->AppendRows();
91 m_gridSymbol->SetCellValue( ii, 0, ii == (int) symbolPath.size() - 1 ? _( "Symbol:" )
92 : _( "Sheet: " ) );
93 m_gridSymbol->SetCellValue( ii, 1, symbolPath[ii].AsString() );
94
95 if( !Kiface().IsSingle() && m_frame->Kiway().Player( FRAME_SCH, false ) )
96 {
97 std::string item = symbolPath[ii].AsString().ToStdString();
98 m_frame->Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_ITEM, item );
99 m_gridSymbol->SetCellValue( ii, 2, item );
100 }
101 }
102
104
105 return true;
106}
107
108
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
DIALOG_FOOTPRINT_ASSOCIATIONS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Footprint Associations"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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...
An interface to the global shared library manager that is schematic-specific and linked to one projec...
FOOTPRINT * LoadFootprint(const wxString &aNickname, const wxString &aName, bool aKeepUUID)
Load a FOOTPRINT having aName from the library given by aNickname.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
wxString AsString() const
Definition kiid.cpp:356
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
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
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
Definition project.h:65
#define _(s)
@ FRAME_SCH
Definition frame_type.h:34
@ MAIL_SCH_GET_ITEM
Definition mail_type.h:50
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)