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