KiCad PCB EDA Suite
cvpcb/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-2014 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 
30 #include <confirm.h>
31 #include <fp_lib_table.h>
32 #include <kiface_i.h>
33 #include <pgm_base.h>
35 
36 #include <cvpcb_mainframe.h>
37 #include <cvpcb_settings.h>
39 
40 
41 namespace CV {
42 
43 static struct IFACE : public KIFACE_I
44 {
45  // Of course all are virtual overloads, implementations of the KIFACE.
46 
47  IFACE( const char* aName, KIWAY::FACE_T aType ) :
48  KIFACE_I( aName, aType )
49  {}
50 
51  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
52 
53  void OnKifaceEnd() override;
54 
55  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
56  {
57  switch( aClassId )
58  {
59  case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
60  case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
61  default: return NULL;
62  }
63  }
64 
76  void* IfaceOrAddress( int aDataId ) override
77  {
78  return NULL;
79  }
80 
81 } kiface( "cvpcb", KIWAY::FACE_CVPCB );
82 
83 } // namespace
84 
85 using namespace CV;
86 
87 
88 static PGM_BASE* process;
89 
90 
91 KIFACE_I& Kiface() { return kiface; }
92 
93 
94 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
95 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
96 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
97 {
99  return &kiface;
100 }
101 
102 
104 {
105  wxASSERT( process ); // KIFACE_GETTER has already been called.
106  return *process;
107 }
108 
109 
110 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
111 // is run from a python script, mot from a Kicad application
113 {
114  return process;
115 }
116 
117 
119 
121 
122 
123 // A short lived implementation. cvpcb will get combine into pcbnew shortly, so
124 // we skip setting KISYSMOD here for now. User should set the environment
125 // variable.
126 
127 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
128 {
129  // This is process level, not project level, initialization of the DSO.
130 
131  // Do nothing in here pertinent to a project!
132 
135 
136  start_common( aCtlBits );
137 
138  /* Now that there are no *.mod files in the standard library, this function
139  has no utility. User should simply set the variable manually.
140  Looking for *.mod files which do not exist is fruitless.
141 
142  // SetFootprintLibTablePath();
143  */
144 
145  try
146  {
147  // The global table is not related to a specific project. All projects
148  // will use the same global table. So the KIFACE::OnKifaceStart() contract
149  // of avoiding anything project specific is not violated here.
150 
152  {
154  "You have run CvPcb for the first time using the "
155  "new footprint library table method for finding "
156  "footprints.\nCvPcb has either copied the default "
157  "table or created an empty table in your home "
158  "folder.\nYou must first configure the library "
159  "table to include all footprint libraries not "
160  "included with KiCad.\nSee the \"Footprint Library "
161  "Table\" section of the CvPcb documentation for "
162  "more information." ) );
163  }
164  }
165  catch( const IO_ERROR& ioe )
166  {
168  nullptr,
169  _( "An error occurred attempting to load the global footprint library table" ),
170  ioe.What() );
171  return false;
172  }
173 
174  return true;
175 }
176 
178 {
179  end_common();
180 }
KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIFACE.
Definition: kiface_i.h:37
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:89
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
This file is part of the common library.
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
PGM_BASE & Pgm()
The global Program "get" accessor.
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: cvpcb/cvpcb.cpp:76
DISPLAY_FOOTPRINTS_FRAME is used to display footprints.
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: cvpcb/cvpcb.cpp:91
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Function LoadGlobalTable loads the global footprint library table into aTable.
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:99
CV::IFACE KIFACE_I kiface("cvpcb", KIWAY::FACE_CVPCB)
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
#define KIFACE_GETTER
Definition: kiway.h:112
static PGM_BASE * process
Definition: cvpcb/cvpcb.cpp:88
int PGM_BASE * aProgram
Definition: cvpcb/cvpcb.cpp:97
FACE_T
Known KIFACE implementations.
Definition: kiway.h:279
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
see class PGM_BASE
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
#define _(s)
Definition: 3d_actions.cpp:33
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: cvpcb/cvpcb.cpp:47
KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
int aKIWAYversion
Definition: cvpcb/cvpcb.cpp:96
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_i.h:105
PGM_BASE * PgmOrNull()
similat to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:267
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
The CvPcb application main window.
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Function CreateWindow creates a wxWindow for the current project.
Definition: cvpcb/cvpcb.cpp:55