KiCad PCB EDA Suite
eeschema.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2011 KiCad Developers, see change_log.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 
31 #include <fctsys.h>
32 #include <pgm_base.h>
33 #include <kiface_i.h>
34 #include <class_drawpanel.h>
35 #include <confirm.h>
36 #include <gestfich.h>
37 #include <eda_dde.h>
38 #include <schframe.h>
39 #include <libeditframe.h>
40 #include <viewlib_frame.h>
41 #include <eda_text.h>
42 
43 #include <general.h>
44 #include <class_libentry.h>
45 #include <hotkeys.h>
46 #include <transform.h>
48 #include <symbol_lib_table.h>
49 
50 #include <kiway.h>
51 #include <sim/sim_plot_frame.h>
52 
53 // The main sheet of the project
55 
56 // a transform matrix, to display components in lib editor
58 
59 
60 namespace SCH {
61 
62 static struct IFACE : public KIFACE_I
63 {
64  // Of course all are virtual overloads, implementations of the KIFACE.
65 
66  IFACE( const char* aName, KIWAY::FACE_T aType ) :
67  KIFACE_I( aName, aType )
68  {}
69 
70  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
71 
72  void OnKifaceEnd() override;
73 
74  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
75  {
76  switch( aClassId )
77  {
78  case FRAME_SCH:
79  {
80  SCH_EDIT_FRAME* frame = new SCH_EDIT_FRAME( aKiway, aParent );
81 
82  if( Kiface().IsSingle() )
83  {
84  // only run this under single_top, not under a project manager.
86  }
87  return frame;
88  }
89  break;
90 
92  {
93  LIB_EDIT_FRAME* frame = new LIB_EDIT_FRAME( aKiway, aParent );
94  return frame;
95  }
96  break;
97 
98 #ifdef KICAD_SPICE
99  case FRAME_SIMULATOR:
100  {
101  SIM_PLOT_FRAME* frame = new SIM_PLOT_FRAME( aKiway, aParent );
102  return frame;
103  }
104  break;
105 #endif /* KICAD_SPICE */
106 
107  case FRAME_SCH_VIEWER:
109  {
110  LIB_VIEW_FRAME* frame = new LIB_VIEW_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
111  return frame;
112  }
113  break;
114 
115  default:
116  return NULL;
117  }
118  }
119 
131  void* IfaceOrAddress( int aDataId ) override
132  {
133  return NULL;
134  }
135 
136 } kiface( "eeschema", KIWAY::FACE_SCH );
137 
138 } // namespace
139 
140 using namespace SCH;
141 
143 
144 
145 KIFACE_I& Kiface() { return kiface; }
146 
147 
148 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
149 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
150 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
151 {
152  process = aProgram;
153  return &kiface;
154 }
155 
156 
158 {
159  wxASSERT( process ); // KIFACE_GETTER has already been called.
160  return *process;
161 }
162 
163 
165 
167 {
168  wxASSERT( unsigned( aLayer ) < DIM( s_layerColor ) );
169  return s_layerColor[aLayer];
170 }
171 
172 void SetLayerColor( COLOR4D aColor, LAYERSCH_ID aLayer )
173 {
174  wxASSERT( unsigned( aLayer ) < DIM( s_layerColor ) );
175  s_layerColor[aLayer] = aColor;
176 }
177 
178 
180 {
181  static PARAM_CFG_ARRAY ca;
182 
183  if( !ca.size() )
184  {
185  // These are KIFACE specific, they need to be loaded once when the
186  // eeschema KIFACE comes in.
187 
188 #define CLR(x, y, z)\
189  ca.push_back( new PARAM_CFG_SETCOLOR( true, wxT( x ), &s_layerColor[y], z ) );
190 
191  CLR( "ColorWireEx", LAYER_WIRE, COLOR4D( GREEN ) )
192  CLR( "ColorBusEx", LAYER_BUS, COLOR4D( BLUE ) )
193  CLR( "ColorConnEx", LAYER_JUNCTION, COLOR4D( GREEN ) )
194  CLR( "ColorLLabelEx", LAYER_LOCLABEL, COLOR4D( BLACK ) )
195  CLR( "ColorHLabelEx", LAYER_HIERLABEL, COLOR4D( BROWN ) )
196  CLR( "ColorGLabelEx", LAYER_GLOBLABEL, COLOR4D( RED ) )
197  CLR( "ColorPinNumEx", LAYER_PINNUM, COLOR4D( RED ) )
198  CLR( "ColorPinNameEx", LAYER_PINNAM, COLOR4D( CYAN ) )
199  CLR( "ColorFieldEx", LAYER_FIELDS, COLOR4D( MAGENTA ) )
200  CLR( "ColorReferenceEx", LAYER_REFERENCEPART, COLOR4D( CYAN ) )
201  CLR( "ColorValueEx", LAYER_VALUEPART, COLOR4D( CYAN ) )
202  CLR( "ColorNoteEx", LAYER_NOTES, COLOR4D( LIGHTBLUE ) )
203  CLR( "ColorBodyEx", LAYER_DEVICE, COLOR4D( RED ) )
204  CLR( "ColorBodyBgEx", LAYER_DEVICE_BACKGROUND, COLOR4D( LIGHTYELLOW ) )
205  CLR( "ColorNetNameEx", LAYER_NETNAM, COLOR4D( DARKGRAY ) )
206  CLR( "ColorPinEx", LAYER_PIN, COLOR4D( RED ) )
207  CLR( "ColorSheetEx", LAYER_SHEET, COLOR4D( MAGENTA ) )
208  CLR( "ColorSheetFileNameEx", LAYER_SHEETFILENAME, COLOR4D( BROWN ) )
209  CLR( "ColorSheetNameEx", LAYER_SHEETNAME, COLOR4D( CYAN ) )
210  CLR( "ColorSheetLabelEx", LAYER_SHEETLABEL, COLOR4D( BROWN ) )
211  CLR( "ColorNoConnectEx", LAYER_NOCONNECT, COLOR4D( BLUE ) )
212  CLR( "ColorErcWEx", LAYER_ERC_WARN, COLOR4D( GREEN ) )
213  CLR( "ColorErcEEx", LAYER_ERC_ERR, COLOR4D( RED ) )
214  CLR( "ColorGridEx", LAYER_GRID, COLOR4D( DARKGRAY ) )
215  CLR( "ColorBgCanvasEx", LAYER_BACKGROUND, COLOR4D( WHITE ) )
216  CLR( "ColorBrighenedEx", LAYER_BRIGHTENED, COLOR4D( PUREMAGENTA ) )
217  }
218 
219  return ca;
220 }
221 
222 
223 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
224 {
225  // This is process level, not project level, initialization of the DSO.
226 
227  // Do nothing in here pertinent to a project!
228 
229  start_common( aCtlBits );
230 
231  // Give a default colour for all layers
232  // (actual color will be initialized by config)
233  for( LAYERSCH_ID ii = LAYER_FIRST; ii < LAYERSCH_ID_COUNT; ++ii )
234  SetLayerColor( COLOR4D( DARKGRAY ), ii );
235 
237 
238  // Must be called before creating the main frame in order to
239  // display the real hotkeys in menus or tool tips
241 
243 
244  try
245  {
246  // The global table is not related to a specific project. All projects
247  // will use the same global table. So the KIFACE::OnKifaceStart() contract
248  // of avoiding anything project specific is not violated here.
250  {
251  DisplayInfoMessage( NULL, _(
252  "You have run Eeschema for the first time using the new symbol library table "
253  "method for finding symbols.\n\n"
254  "Eeschema has either copied the default table or created an empty table in the "
255  "kicad configuration folder.\n\n"
256  "You must first configure the library table to include all symbol libraries you "
257  "want to use.\n\n"
258  "See the \"Symbol Library Table\" section of Eeschema documentation for more "
259  "information." ) );
260  }
261  }
262  catch( const IO_ERROR& ioe )
263  {
264  wxString msg = wxString::Format( _(
265  "An error occurred attempting to load the global symbol library table:\n\n%s" ),
266  GetChars( ioe.What() )
267  );
268  DisplayError( NULL, msg );
269  return false;
270  }
271 
272  return true;
273 }
274 
275 
277 {
280 }
Definition: colors.h:57
SCH::IFACE KIFACE_I kiface("eeschema", KIWAY::FACE_SCH)
void ReadHotkeyConfig(const wxString &Appname, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for th...
#define DIM(x)
of elements in an array
Definition: macros.h:98
A list of parameters type.
Class KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIF...
Definition: kiface_i.h:37
DDE server & client.
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:94
This file is part of the common library TODO brief description.
wxSocketServer * CreateServer(wxWindow *window, int service, bool local)
Definition: eda_dde.cpp:49
This file is part of the common library.
int aKiwayVersion
Definition: eeschema.cpp:150
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
Definition: eeschema.cpp:276
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:107
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
Definition: colors.h:61
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Function CreateWindow creates a wxWindow for the current project.
Definition: eeschema.cpp:74
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: eeschema.cpp:131
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: eeschema.cpp:66
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
Definition of base KiCad text object.
Component library viewer main window.
Definition: viewlib_frame.h:49
int PGM_BASE * aProgram
Definition: eeschema.cpp:151
#define CLR(x, y, z)
COLOR4D GetLayerColor(LAYERSCH_ID aLayer)
Definition: eeschema.cpp:166
LAYERSCH_ID
Definition: general.h:75
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Function LoadGlobalTable.
#define KICAD_SCH_PORT_SERVICE_NUMBER
Definition: eda_dde.h:42
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
Definition: eeschema.cpp:223
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
Definition: eeschema.cpp:60
KIFACE * KIFACE_GETTER(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
No name mangling. Each KIFACE (DSO/DLL) will implement this once.
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:104
Class LIB_ITEM definition.
static PARAM_CFG_ARRAY & cfg_params()
Definition: eeschema.cpp:179
void SetLayerColor(COLOR4D aColor, LAYERSCH_ID aLayer)
Definition: eeschema.cpp:172
struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[]
Definition: colors.h:59
The common library.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
Definition: colors.h:60
Implementing SIM_PLOT_FRAME_BASE.
FACE_T
Known KIFACE implementations.
Definition: kiway.h:263
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
eeschema DSO
Definition: kiway.h:265
bool IsSingle() const
Function IsSingle is this KIFACE_I running under single_top?
Definition: kiface_i.h:113
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
void wxConfigSaveSetups(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList)
Function wxConfigSaveSetups writes aList of PARAM_CFG_ARRAY elements to save configuration values to ...
The component library editor main window.
Definition: libeditframe.h:51
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
Definition: colors.h:58
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:57
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
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
static PGM_BASE * process
Definition: eeschema.cpp:142
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: eeschema.cpp:145
Definition: colors.h:49
Definition: colors.h:45
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: eeschema.cpp:157
#define SCH_EDIT_FRAME_NAME
Definition: schframe.h:112
void wxConfigLoadSetups(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG_ARRAY elements to load configuration values from ...
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
static COLOR4D s_layerColor[LAYERSCH_ID_COUNT]
Definition: eeschema.cpp:164
Definition of class LIB_EDIT_FRAME.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62