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 <confirm.h>
24#include <kiface_base.h>
25#include <pgm_base.h>
27
28#include <cvpcb_mainframe.h>
31#include <kiface_ids.h>
32#include <project_pcb.h>
33
34namespace CV {
35
36int testFootprintLink( const wxString& aFootprint, PROJECT* aProject )
37{
39 LIB_ID fpID;
40
41 fpID.Parse( aFootprint );
42
43 wxString libName = fpID.GetLibNickname();
44 wxString fpName = fpID.GetLibItemName();
45
46 // TODO(JE) this is a bit of a hack; CLI lazy-loading of libraries should be more unified
47 // Libraries may not be present at this point if running in kicad-cli because nothings will
48 // have triggered a load up to this point
49 if( !adapter->GetLibraryStatus( libName ) )
50 adapter->LoadOne( libName );
51
52 if( !adapter->HasLibrary( libName, false ) )
54 else if( !adapter->HasLibrary( libName, true ) )
56 else if( !adapter->FootprintExists( libName, fpName ) )
58
59 return 0;
60}
61
62
63static struct IFACE : public KIFACE_BASE
64{
65 // Of course all are virtual overloads, implementations of the KIFACE.
66
67 IFACE( const char* aName, KIWAY::FACE_T aType ) :
68 KIFACE_BASE( aName, aType )
69 {}
70
71 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
72
73 void OnKifaceEnd() override;
74
75 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
76 int aCtlBits = 0 ) override
77 {
78 switch( aClassId )
79 {
80 case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
81 case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
82 default: return nullptr;
83 }
84 }
85
96 void* IfaceOrAddress( int aDataId ) override
97 {
98 switch( aDataId )
99 {
101 return (void*) testFootprintLink;
102
103 default:
104 return nullptr;
105 }
106 }
107
108} kiface( "cvpcb", KIWAY::FACE_CVPCB );
109
110} // namespace
111
112using namespace CV;
113
114
116
117
118// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
119// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
120KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
121{
122 return &kiface;
123}
124
125
127
128// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so
129// we skip setting KICAD7_FOOTPRINT_DIR here for now. User should set the environment
130// variable.
131bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
132{
133 // This is process level, not project level, initialization of the DSO.
134
135 // Do nothing in here pertinent to a project!
136
139
140 start_common( aCtlBits );
141
142 return true;
143}
144
145
147{
148 end_common();
149}
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 > 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:48
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
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.
This file is part of the common library.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:115
@ 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
#define KIFACE_GETTER
Definition kiway.h:109
Definition cvpcb.cpp:34
CV::IFACE KIFACE_BASE kiface("cvpcb", KIWAY::FACE_CVPCB)
int testFootprintLink(const wxString &aFootprint, PROJECT *aProject)
Definition cvpcb.cpp:36
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:131
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition cvpcb.cpp:67
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition cvpcb.cpp:96
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition cvpcb.cpp:75
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition cvpcb.cpp:146
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