KiCad PCB EDA Suite
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 <dick@softplc.com>
6  * Copyright (C) 1992-2021 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>
34 #include <cvpcb_settings.h>
36 #include <kiface_ids.h>
37 
38 namespace CV {
39 
40 static 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* CreateWindow( 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 
98 using namespace CV;
99 
100 
102 
103 
104 KIFACE_BASE& Kiface() { return kiface; }
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.
109 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
110 {
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 KICAD6_FOOTPRINT_DIR here for now. User should set the environment
147 // variable.
148 bool 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 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:134
A KIFACE implementation.
Definition: kiface_base.h:37
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:284
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
This file is part of the common library.
Container for data for KiCad programs.
Definition: pgm_base.h:93
Definition: cvpcb.cpp:38
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_base.cpp:94
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: cvpcb.cpp:73
Return the global FP_LIB_TABLE.
Definition: kiface_ids.h:53
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: cvpcb.cpp:197
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_base.h:94
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
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
static PGM_BASE * process
Definition: cvpcb.cpp:101
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_base.cpp:84
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
#define _(s)
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:110
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: cvpcb.cpp:104
FACE_T
Known KIFACE implementations.
Definition: kiway.h:266
int aKIWAYversion
Definition: cvpcb.cpp:109
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
see class PGM_BASE
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: cvpcb.cpp:44
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:148
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:92
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: cvpcb.cpp:116
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:299
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
int PGM_BASE * aProgram
Definition: cvpcb.cpp:110
The CvPcb application main window.
CV::IFACE KIFACE_BASE kiface("cvpcb", KIWAY::FACE_CVPCB)
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: cvpcb.cpp:52
Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew.
Definition: kiface_ids.h:39