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-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 <fctsys.h>
31 #include <macros.h>
32 #include <fp_lib_table.h>
33 #include <kiface_i.h>
34 #include <pgm_base.h>
35 #include <wxstruct.h>
36 #include <confirm.h>
37 
38 #include <cvpcb.h>
39 #include <zones.h>
40 #include <cvpcb_mainframe.h>
41 #include <colors_selection.h>
42 #include <cvpcb_id.h>
43 
44 #include <build_version.h>
45 
46 #include <wx/snglinst.h>
47 
48 // Colors for layers and items
50 
51 // Constant string definitions for CvPcb
52 const wxString EquFileExtension( wxT( "equ" ) );
53 
54 // Wildcard for schematic retroannotation (import footprint names in schematic):
55 const wxString EquFilesWildcard( _( "Component/footprint equ files (*.equ)|*.equ" ) );
56 
57 namespace CV {
58 
59 static struct IFACE : public KIFACE_I
60 {
61  // Of course all are virtual overloads, implementations of the KIFACE.
62 
63  IFACE( const char* aName, KIWAY::FACE_T aType ) :
64  KIFACE_I( aName, aType )
65  {}
66 
67  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
68 
69  void OnKifaceEnd() override;
70 
71  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
72  {
73  switch( aClassId )
74  {
75  case FRAME_CVPCB:
76  {
77  CVPCB_MAINFRAME* frame = new CVPCB_MAINFRAME( aKiway, aParent );
78  return frame;
79  }
80  break;
81 
82  default:
83  ;
84  }
85 
86  return NULL;
87  }
88 
100  void* IfaceOrAddress( int aDataId ) override
101  {
102  return NULL;
103  }
104 
105 } kiface( "cvpcb", KIWAY::FACE_CVPCB );
106 
107 } // namespace
108 
109 using namespace CV;
110 
111 
113 
114 
115 KIFACE_I& Kiface() { return kiface; }
116 
117 
118 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
119 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
120 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
121 {
122  process = (PGM_BASE*) aProgram;
123  return &kiface;
124 }
125 
126 
128 {
129  wxASSERT( process ); // KIFACE_GETTER has already been called.
130  return *process;
131 }
132 
133 
135 
137 
138 
139 // A short lived implementation. cvpcb will get combine into pcbnew shortly, so
140 // we skip setting KISYSMOD here for now. User should set the environment
141 // variable.
142 
143 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
144 {
145  // This is process level, not project level, initialization of the DSO.
146 
147  // Do nothing in here pertinent to a project!
148 
149  start_common( aCtlBits );
150 
151  /* Now that there are no *.mod files in the standard library, this function
152  has no utility. User should simply set the variable manually.
153  Looking for *.mod files which do not exist is fruitless.
154 
155  // SetFootprintLibTablePath();
156  */
157 
158  try
159  {
160  // The global table is not related to a specific project. All projects
161  // will use the same global table. So the KIFACE::OnKifaceStart() contract
162  // of avoiding anything project specific is not violated here.
163 
164  if( !FP_LIB_TABLE::LoadGlobalTable( GFootprintTable ) )
165  {
166  DisplayInfoMessage( NULL, _(
167  "You have run CvPcb for the first time using the "
168  "new footprint library table method for finding "
169  "footprints. CvPcb has either copied the default "
170  "table or created an empty table in your home "
171  "folder. You must first configure the library "
172  "table to include all footprint libraries not "
173  "included with KiCad. See the \"Footprint Library "
174  "Table\" section of the CvPcb documentation for "
175  "more information." ) );
176  }
177  }
178  catch( const IO_ERROR& ioe )
179  {
180  wxString msg = wxString::Format( _(
181  "An error occurred attempting to load the global footprint library "
182  "table:\n\n%s" ),
183  GetChars( ioe.What() )
184  );
185  DisplayError( NULL, msg );
186  return false;
187  }
188 
189  return true;
190 }
191 
193 {
194  end_common();
195 }
static PGM_BASE * process
Definition: cvpcb.cpp:112
Class KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIF...
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:94
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it...
Definition: cvpcb.cpp:136
This file is part of the common library.
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:107
Definition: cvpcb.cpp:57
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: cvpcb.cpp:100
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: cvpcb.cpp:115
This file contains miscellaneous commonly used macros and functions.
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
Definition: cvpcb.cpp:192
const wxString EquFilesWildcard(_("Component/footprint equ files (*.equ)|*.equ"))
KIFACE * KIFACE_GETTER(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
No name mangling. Each KIFACE (DSO/DLL) will implement this once.
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:104
CV::IFACE KIFACE_I kiface("cvpcb", KIWAY::FACE_CVPCB)
Base window classes and related definitions.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
FACE_T
Known KIFACE implementations.
Definition: kiway.h:263
int aKIWAYversion
Definition: cvpcb.cpp:120
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
Definition: cvpcb.cpp:143
void DisplayInfoMessage(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:89
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: cvpcb.cpp:63
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Eeschema, Pcbnew and GerbView...
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: cvpcb.cpp:49
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: cvpcb.cpp:127
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
const wxString EquFileExtension(wxT("equ"))
The CvPcb application main window.
int PGM_BASE * aProgram
Definition: pcbnew.cpp:205
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Function CreateWindow creates a wxWindow for the current project.
Definition: cvpcb.cpp:71