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
38namespace CV {
39
40static struct IFACE : public KIFACE_BASE
41{
42 // Of course all are virtual overloads, implementations of the KIFACE.
43
44 IFACE( const char* aName, KIWAY::FACE_T aType ) :
45 KIFACE_BASE( aName, aType )
46 {}
47
48 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
49
50 void OnKifaceEnd() override;
51
52 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
53 int aCtlBits = 0 ) override
54 {
55 switch( aClassId )
56 {
57 case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
58 case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
59 default: return nullptr;
60 }
61 }
62
73 void* IfaceOrAddress( int aDataId ) override
74 {
75 switch( aDataId )
76 {
77 // Return a pointer to the global instance of the footprint list.
79 return (void*) &GFootprintList;
80
81 // Return a new FP_LIB_TABLE with the global table installed as a fallback.
83 return (void*) new FP_LIB_TABLE( &GFootprintTable );
84
85 // Return a pointer to the global instance of the global footprint table.
87 return (void*) &GFootprintTable;
88
89 default:
90 return nullptr;
91 }
92 }
93
94} kiface( "cvpcb", KIWAY::FACE_CVPCB );
95
96} // namespace
97
98using namespace CV;
99
100
102
103
105
106
107// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
108// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
109KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
110{
111 process = (PGM_BASE*) aProgram;
112 return &kiface;
113}
114
115
117{
118 wxASSERT( process ); // KIFACE_GETTER has already been called.
119 return *process;
120}
121
122
123// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
124// is run from a python script, mot from a Kicad application
126{
127 return process;
128}
129
130
135
136
141
142
144
145// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so
146// we skip setting KICAD7_FOOTPRINT_DIR here for now. User should set the environment
147// variable.
148bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
149{
150 // This is process level, not project level, initialization of the DSO.
151
152 // Do nothing in here pertinent to a project!
153
156
157 start_common( aCtlBits );
158
159 /* Now that there are no *.mod files in the standard library, this function
160 has no utility. User should simply set the variable manually.
161 Looking for *.mod files which do not exist is fruitless.
162
163 // SetFootprintLibTablePath();
164 */
165
166 try
167 {
168 // The global table is not related to a specific project. All projects
169 // will use the same global table. So the KIFACE::OnKifaceStart() contract
170 // of avoiding anything project specific is not violated here.
171
173 {
174 DisplayInfoMessage( nullptr, _( "You have run CvPcb for the first time using the "
175 "new footprint library table method for finding "
176 "footprints.\nCvPcb has either copied the default "
177 "table or created an empty table in your home "
178 "folder.\nYou must first configure the library "
179 "table to include all footprint libraries not "
180 "included with KiCad.\nSee the \"Footprint Library "
181 "Table\" section of the CvPcb documentation for "
182 "more information." ) );
183 }
184 }
185 catch( const IO_ERROR& ioe )
186 {
187 DisplayErrorMessage( nullptr, _( "An error occurred attempting to load the global "
188 "footprint library table." ),
189 ioe.What() );
190 return false;
191 }
192
193 return true;
194}
195
196
198{
199 end_common();
200}
The CvPcb application main window.
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
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
Container for data for KiCad programs.
Definition: pgm_base.h:99
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:139
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
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.
static PGM_BASE * process
Definition: cvpcb.cpp:101
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: cvpcb.cpp:116
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: cvpcb.cpp:104
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: cvpcb.cpp:125
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:134
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
#define _(s)
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
@ FRAME_CVPCB_DISPLAY
Definition: frame_type.h:49
@ FRAME_CVPCB
Definition: frame_type.h:48
#define KIFACE_API
Definition: import_export.h:51
@ KIFACE_FOOTPRINT_LIST
Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew.
Definition: kiface_ids.h:39
@ 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:38
CV::IFACE KIFACE_BASE kiface("cvpcb", KIWAY::FACE_CVPCB)
see class PGM_BASE
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
!!!!!!!!!!!!!! This code is obsolete because of the merge into Pcbnew, don't bother with it.
Definition: cvpcb.cpp:148
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: cvpcb.cpp:44
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: cvpcb.cpp:73
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: cvpcb.cpp:52
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: cvpcb.cpp:197
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151