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_ids.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 adapter->LoadOne( fpID.GetLibNickname() );
88
89 std::unique_ptr<FOOTPRINT> footprint;
90
91 // This runs across the kiface boundary, so let nothing escape into the caller's ERC loop.
92 try
93 {
94 footprint.reset( adapter->LoadFootprint( fpID, false ) );
95 }
96 catch( ... )
97 {
98 }
99
100 if( !footprint )
101 return;
102
103 for( const PAD* pad : footprint->Pads() )
104 {
105 if( !pad->GetNumber().IsEmpty() )
106 aPadNumbers.insert( pad->GetNumber() );
107 }
108}
109
110
111static struct IFACE : public KIFACE_BASE
112{
113 // Of course all are virtual overloads, implementations of the KIFACE.
114
115 IFACE( const char* aName, KIWAY::FACE_T aType ) :
116 KIFACE_BASE( aName, aType )
117 {}
118
119 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
120
121 void OnKifaceEnd() override;
122
123 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
124 int aCtlBits = 0 ) override
125 {
126 switch( aClassId )
127 {
128 case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
129 case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
130 default: return nullptr;
131 }
132 }
133
144 void* IfaceOrAddress( int aDataId ) override
145 {
146 switch( aDataId )
147 {
149 return (void*) testFootprintLink;
150
152
153 default:
154 return nullptr;
155 }
156 }
157
158} kiface( "cvpcb", KIWAY::FACE_CVPCB );
159
160} // namespace
161
162using namespace CV;
163
164
166
167
168// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
169// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
170KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
171{
172 return &kiface;
173}
174
175
177
178// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so
179// we skip setting KICAD7_FOOTPRINT_DIR here for now. User should set the environment
180// variable.
181bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
182{
183 // This is process level, not project level, initialization of the DSO.
184
185 // Do nothing in here pertinent to a project!
186
189
190 start_common( aCtlBits );
191
192 return true;
193}
194
195
197{
198 end_common();
199}
The CvPcb application main window.
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.
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:63
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition kiface_base.h:93
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:91
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:311
FACE_T
Known KIFACE implementations.
Definition kiway.h:317
@ FACE_CVPCB
Definition kiway.h:320
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 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:62
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:165
@ 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:56
@ KIFACE_TEST_FOOTPRINT_LINK
Definition kiface_ids.h:54
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition kiface_ids.h:55
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition kiface_ids.h:57
@ KIFACE_FOOTPRINT_PAD_NUMBERS
Function pointer type: void (*)( const wxString& aFootprint, PROJECT* aProject, std::set<wxString>& a...
Definition kiface_ids.h:62
#define KIFACE_GETTER
Definition kiway.h:109
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:181
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition cvpcb.cpp:115
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition cvpcb.cpp:144
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition cvpcb.cpp:123
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition cvpcb.cpp:196
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:152