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 (C) 1992-2022 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>
27#include <fp_lib_table.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{
43 FP_LIB_TABLE* libTable = PROJECT_PCB::PcbFootprintLibs( aProject );
44 const FP_LIB_TABLE_ROW* libTableRow = nullptr;
45 LIB_ID fpID;
46
47 fpID.Parse( aFootprint );
48
49 wxString libName = fpID.GetLibNickname();
50 wxString fpName = fpID.GetLibItemName();
51
52 try
53 {
54 libTableRow = libTable->FindRow( libName );
55 }
56 catch( const IO_ERROR& )
57 {
58 // Error state processed below
59 }
60
61 if( !libTableRow )
63 else if( !libTable->HasLibrary( libName, true ) )
65 else if( !libTable->FootprintExists( libName, fpName ) )
67 else
68 return 0;
69}
70
71
72static struct IFACE : public KIFACE_BASE
73{
74 // Of course all are virtual overloads, implementations of the KIFACE.
75
76 IFACE( const char* aName, KIWAY::FACE_T aType ) :
77 KIFACE_BASE( aName, aType )
78 {}
79
80 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
81
82 void OnKifaceEnd() override;
83
84 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
85 int aCtlBits = 0 ) override
86 {
87 switch( aClassId )
88 {
89 case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
90 case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
91 default: return nullptr;
92 }
93 }
94
105 void* IfaceOrAddress( int aDataId ) override
106 {
107 switch( aDataId )
108 {
109 // Return a pointer to the global instance of the footprint list.
111 return (void*) &GFootprintList;
112
113 // Return a new FP_LIB_TABLE with the global table installed as a fallback.
115 return (void*) new FP_LIB_TABLE( &GFootprintTable );
116
117 // Return a pointer to the global instance of the global footprint table.
119 return (void*) &GFootprintTable;
120
122 return (void*) testFootprintLink;
123
124 default:
125 return nullptr;
126 }
127 }
128
129} kiface( "cvpcb", KIWAY::FACE_CVPCB );
130
131} // namespace
132
133using namespace CV;
134
135
137
138
139// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
140// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
141KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
142{
143 return &kiface;
144}
145
146
151
152
157
158
160
161// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so
162// we skip setting KICAD7_FOOTPRINT_DIR here for now. User should set the environment
163// variable.
164bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
165{
166 // This is process level, not project level, initialization of the DSO.
167
168 // Do nothing in here pertinent to a project!
169
172
173 start_common( aCtlBits );
174
175 /* Now that there are no *.mod files in the standard library, this function
176 has no utility. User should simply set the variable manually.
177 Looking for *.mod files which do not exist is fruitless.
178
179 // SetFootprintLibTablePath();
180 */
181
182 try
183 {
184 // The global table is not related to a specific project. All projects
185 // will use the same global table. So the KIFACE::OnKifaceStart() contract
186 // of avoiding anything project specific is not violated here.
187
189 {
190 DisplayInfoMessage( nullptr, _( "You have run CvPcb for the first time using the "
191 "new footprint library table method for finding "
192 "footprints.\nCvPcb has either copied the default "
193 "table or created an empty table in your home "
194 "folder.\nYou must first configure the library "
195 "table to include all footprint libraries not "
196 "included with KiCad.\nSee the \"Footprint Library "
197 "Table\" section of the CvPcb documentation for "
198 "more information." ) );
199 }
200 }
201 catch( const IO_ERROR& ioe )
202 {
203 // we didnt get anywhere deregister the settings
204 aProgram->GetSettingsManager().FlushAndRelease( KifaceSettings(), false );
205
206 DisplayErrorMessage( nullptr, _( "An error occurred attempting to load the global "
207 "footprint library table." ),
208 ioe.What() );
209 return false;
210 }
211
212 return true;
213}
214
215
217{
218 end_common();
219}
The CvPcb application main window.
Hold a record identifying a library accessed by the appropriate footprint library #PLUGIN object in t...
Definition: fp_lib_table.h:42
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
A KIFACE implementation.
Definition: kiface_base.h:39
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();.
Definition: kiface_base.cpp:42
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().
Definition: kiface_base.cpp:32
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
FACE_T
Known KIFACE implementations.
Definition: kiway.h:285
@ FACE_CVPCB
Definition: kiway.h:288
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:51
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
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
Container for data for KiCad programs.
Definition: pgm_base.h:102
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Definition: project_pcb.cpp:37
Container for project specific data.
Definition: project.h:62
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
void FlushAndRelease(JSON_SETTINGS *aSettings, bool aSave=true)
If the given settings object is registered, save it to disk and unregister it.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:332
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
This file is part of the common library.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: cvpcb.cpp:136
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:150
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:156
#define _(s)
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:156
@ FRAME_CVPCB_DISPLAY
Definition: frame_type.h:53
@ FRAME_CVPCB
Definition: frame_type.h:52
#define KIFACE_API
Definition: import_export.h:61
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition: kiface_ids.h:62
@ KIFACE_TEST_FOOTPRINT_LINK
Definition: kiface_ids.h:60
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition: kiface_ids.h:61
@ 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:63
@ KIFACE_GLOBAL_FOOTPRINT_TABLE
Return the global FP_LIB_TABLE.
Definition: kiface_ids.h:53
@ KIFACE_NEW_FOOTPRINT_TABLE
Return a new FP_LIB_TABLE with the global table installed as a fallback.
Definition: kiface_ids.h:46
#define KIFACE_GETTER
Definition: kiway.h:111
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:164
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: cvpcb.cpp:76
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: cvpcb.cpp:105
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: cvpcb.cpp:84
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: cvpcb.cpp:216
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:151