KiCad PCB EDA Suite
Loading...
Searching...
No Matches
cvpcb.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) 2007 Jean-Pierre Charras, jp..charras at wanadoo.fr
5 * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <footprint.h>
24#include <kiface_base.h>
26#include <pad.h>
27#include <pgm_base.h>
29
30#include <cvpcb_mainframe.h>
33#include <kiface_services.h>
34
35#include <memory>
36#include <optional>
37#include <set>
38#include <project_pcb.h>
39
40namespace CV {
41
42int testFootprintLink( const wxString& aFootprint, PROJECT* aProject )
43{
45 LIB_ID fpID;
46
47 fpID.Parse( aFootprint );
48
49 wxString libName = fpID.GetLibNickname();
50 wxString fpName = fpID.GetLibItemName();
51
52 // TODO(JE) this is a bit of a hack; CLI lazy-loading of libraries should be more unified
53 // Libraries may not be present at this point if running in kicad-cli because nothings will
54 // have triggered a load up to this point
55 if( !adapter->GetLibraryStatus( libName ) )
56 adapter->LoadOne( libName );
57
58 if( !adapter->HasLibrary( libName, false ) )
60 else if( !adapter->HasLibrary( libName, true ) )
62 else if( !adapter->FootprintExists( libName, fpName ) )
64
65 return 0;
66}
67
68
69void getFootprintPadNumbers( const wxString& aFootprint, PROJECT* aProject, std::set<wxString>& aPadNumbers )
70{
71 LIB_ID fpID;
72
73 if( fpID.Parse( aFootprint ) >= 0 )
74 return;
75
76 if( std::optional<LIBRARY_MANAGER_ADAPTER*> mgr =
77 Pgm().GetLibraryManager().Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT ) )
78 {
79 ( *mgr )->BlockUntilLoaded();
80 }
81
83
84 if( !adapter )
85 return;
86
87 if( fpID.GetLibNickname().empty() )
88 {
89 for( const LIBRARY_TABLE_ROW* row : adapter->Rows() )
90 {
91 if( !adapter->IsLibraryLoaded( row->Nickname() ) )
92 adapter->LoadOne( row->Nickname() );
93 }
94 }
95 else
96 {
97 adapter->LoadOne( fpID.GetLibNickname() );
98 }
99
100 std::unique_ptr<FOOTPRINT> footprint;
101
102 // This runs across the kiface boundary, so let nothing escape into the caller's ERC loop.
103 try
104 {
105 footprint.reset( adapter->LoadFootprintWithOptionalNickname( fpID, false ) );
106 }
107 catch( ... )
108 {
109 }
110
111 if( !footprint )
112 return;
113
114 for( const PAD* pad : footprint->Pads() )
115 {
116 if( !pad->GetNumber().IsEmpty() )
117 aPadNumbers.insert( pad->GetNumber() );
118 }
119}
120
121
122static struct IFACE : public KIFACE_BASE
123{
124 // Of course all are virtual overloads, implementations of the KIFACE.
125
126 IFACE( const char* aName, KIWAY::FACE_T aType ) :
127 KIFACE_BASE( aName, aType )
128 {}
129
130 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
131
132 void OnKifaceEnd() override;
133
134 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
135 int aCtlBits = 0 ) override
136 {
137 switch( aClassId )
138 {
139 case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
140 case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
141 default: return nullptr;
142 }
143 }
144
155 void* IfaceOrAddress( int aDataId ) override
156 {
157 switch( aDataId )
158 {
161
165
166 default:
167 return nullptr;
168 }
169 }
170
171} kiface( "cvpcb", KIWAY::FACE_CVPCB );
172
173} // namespace
174
175using namespace CV;
176
177
179
180
181// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
182// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
183KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
184{
185 return &kiface;
186}
187
188
190
191// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so
192// we skip setting KICAD7_FOOTPRINT_DIR here for now. User should set the environment
193// variable.
194bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
195{
196 // This is process level, not project level, initialization of the DSO.
197
198 // Do nothing in here pertinent to a project!
199
202
203 start_common( aCtlBits );
204
205 return true;
206}
207
208
210{
211 end_common();
212}
The CvPcb application main window.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
FOOTPRINT * LoadFootprintWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID)
Load a footprint having aFootprintId with possibly an empty nickname.
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
bool FootprintExists(const wxString &aNickname, const wxString &aName)
A KIFACE implementation.
Definition kiface_base.h:35
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
Definition kiface_base.h:64
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition kiface_base.h:94
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:92
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
FACE_T
Known KIFACE implementations.
Definition kiway.h:354
@ FACE_CVPCB
Definition kiway.h:357
std::optional< LIB_STATUS > GetLibraryStatus(const wxString &aNickname) const
Returns the status of a loaded library, or nullopt if the library hasn't been loaded (yet)
bool IsLibraryLoaded(const wxString &aNickname)
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Like LIBRARY_MANAGER::Rows but filtered to the LIBRARY_TABLE_TYPE of this adapter.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Definition pad.h:61
Container for data for KiCad programs.
Definition pgm_base.h:102
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
Definition project.h:63
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
bool empty() const
Definition utf8.h:105
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:178
@ FRAME_CVPCB_DISPLAY
Definition frame_type.h:49
@ FRAME_CVPCB
Definition frame_type.h:48
#define KIFACE_API
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition kiface_ids.h:89
@ KIFACE_TEST_FOOTPRINT_LINK
Definition kiface_ids.h:87
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition kiface_ids.h:88
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition kiface_ids.h:90
@ KIFACE_FOOTPRINT_PAD_NUMBERS
Function pointer type: void (*)( const wxString& aFootprint, PROJECT* aProject, std::set<wxString>& a...
Definition kiface_ids.h:95
void * KifaceServiceAddress(T aAddress)
Return a service address for IfaceOrAddress().
#define KIFACE_GETTER
Definition kiway.h:110
Definition cvpcb.cpp:40
void getFootprintPadNumbers(const wxString &aFootprint, PROJECT *aProject, std::set< wxString > &aPadNumbers)
Definition cvpcb.cpp:69
CV::IFACE KIFACE_BASE kiface("cvpcb", KIWAY::FACE_CVPCB)
int testFootprintLink(const wxString &aFootprint, PROJECT *aProject)
Definition cvpcb.cpp:42
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
!!!!!!!!!!!!!! This code is obsolete because of the merge into Pcbnew, don't bother with it.
Definition cvpcb.cpp:194
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition cvpcb.cpp:126
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition cvpcb.cpp:155
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition cvpcb.cpp:134
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition cvpcb.cpp:209
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153