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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <confirm.h>
28#include <footprint_info_impl.h>
29#include <kiface_base.h>
30#include <pgm_base.h>
32
33#include <cvpcb_mainframe.h>
36#include <kiface_ids.h>
37#include <project_pcb.h>
38
39namespace CV {
40
41int testFootprintLink( const wxString& aFootprint, PROJECT* aProject )
42{
44 LIB_ID fpID;
45
46 fpID.Parse( aFootprint );
47
48 wxString libName = fpID.GetLibNickname();
49 wxString fpName = fpID.GetLibItemName();
50
51 // TODO(JE) this is a bit of a hack; CLI lazy-loading of libraries should be more unified
52 // Libraries may not be present at this point if running in kicad-cli because nothings will
53 // have triggered a load up to this point
54 if( !adapter->GetLibraryStatus( libName ) )
55 adapter->LoadOne( libName );
56
57 if( !adapter->HasLibrary( libName, false ) )
59 else if( !adapter->HasLibrary( libName, true ) )
61 else if( !adapter->FootprintExists( libName, fpName ) )
63
64 return 0;
65}
66
67
68static struct IFACE : public KIFACE_BASE
69{
70 // Of course all are virtual overloads, implementations of the KIFACE.
71
72 IFACE( const char* aName, KIWAY::FACE_T aType ) :
73 KIFACE_BASE( aName, aType )
74 {}
75
76 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
77
78 void OnKifaceEnd() override;
79
80 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
81 int aCtlBits = 0 ) override
82 {
83 switch( aClassId )
84 {
85 case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
86 case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
87 default: return nullptr;
88 }
89 }
90
101 void* IfaceOrAddress( int aDataId ) override
102 {
103 switch( aDataId )
104 {
105 // Return a pointer to the global instance of the footprint list.
107 return (void*) &GFootprintList;
108
110 return (void*) testFootprintLink;
111
112 default:
113 return nullptr;
114 }
115 }
116
117} kiface( "cvpcb", KIWAY::FACE_CVPCB );
118
119} // namespace
120
121using namespace CV;
122
123
125
126
127// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
128// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
129KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
130{
131 return &kiface;
132}
133
134
139
140
142
143// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so
144// we skip setting KICAD7_FOOTPRINT_DIR here for now. User should set the environment
145// variable.
146bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
147{
148 // This is process level, not project level, initialization of the DSO.
149
150 // Do nothing in here pertinent to a project!
151
154
155 start_common( aCtlBits );
156
157 return true;
158}
159
160
162{
163 end_common();
164}
The CvPcb application main window.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > GetLibraryStatus(const wxString &aNickname) const override
Returns the status of a loaded library, or nullopt if the library hasn't been loaded (yet)
std::optional< LIB_STATUS > LoadOne(const wxString &aNickname)
Loads or reloads the given library, if it exists.
bool FootprintExists(const wxString &aNickname, const wxString &aName)
A KIFACE implementation.
Definition kiface_base.h:39
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
Definition kiface_base.h:67
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition kiface_base.h:97
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:95
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:292
FACE_T
Known KIFACE implementations.
Definition kiway.h:298
@ FACE_CVPCB
Definition kiway.h:301
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:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:52
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
Container for data for KiCad programs.
Definition pgm_base.h:107
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:129
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
Definition project.h:65
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
This file is part of the common library.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:124
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition cvpcb.cpp:138
@ FRAME_CVPCB_DISPLAY
Definition frame_type.h:53
@ FRAME_CVPCB
Definition frame_type.h:52
#define KIFACE_API
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition kiface_ids.h:49
@ KIFACE_TEST_FOOTPRINT_LINK
Definition kiface_ids.h:47
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition kiface_ids.h:48
@ KIFACE_FOOTPRINT_LIST
Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew.
Definition kiface_ids.h:39
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition kiface_ids.h:50
#define KIFACE_GETTER
Definition kiway.h:110
Definition cvpcb.cpp:39
CV::IFACE KIFACE_BASE kiface("cvpcb", KIWAY::FACE_CVPCB)
int testFootprintLink(const wxString &aFootprint, PROJECT *aProject)
Definition cvpcb.cpp:41
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:146
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition cvpcb.cpp:72
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition cvpcb.cpp:101
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition cvpcb.cpp:80
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition cvpcb.cpp:161
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:155