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 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2017 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 <sch_edit_frame.h>
39 #include <lib_edit_frame.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>
51 
52 #include <kiway.h>
53 #include <sim/sim_plot_frame.h>
54 
55 // The main sheet of the project
57 
58 // a transform matrix, to display components in lib editor
60 
61 
62 namespace SCH {
63 
64 static struct IFACE : public KIFACE_I
65 {
66  // Of course all are virtual overloads, implementations of the KIFACE.
67 
68  IFACE( const char* aName, KIWAY::FACE_T aType ) :
69  KIFACE_I( aName, aType )
70  {}
71 
72  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
73 
74  void OnKifaceEnd() override;
75 
76  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
77  {
78  switch( aClassId )
79  {
80  case FRAME_SCH:
81  {
82  SCH_EDIT_FRAME* frame = new SCH_EDIT_FRAME( aKiway, aParent );
83 
84  if( Kiface().IsSingle() )
85  {
86  // only run this under single_top, not under a project manager.
88  }
89  return frame;
90  }
91  break;
92 
94  {
95  LIB_EDIT_FRAME* frame = new LIB_EDIT_FRAME( aKiway, aParent );
96  return frame;
97  }
98  break;
99 
100 #ifdef KICAD_SPICE
101  case FRAME_SIMULATOR:
102  {
103  SIM_PLOT_FRAME* frame = new SIM_PLOT_FRAME( aKiway, aParent );
104  return frame;
105  }
106  break;
107 #endif /* KICAD_SPICE */
108 
109  case FRAME_SCH_VIEWER:
111  {
112  LIB_VIEW_FRAME* frame = new LIB_VIEW_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
113  return frame;
114  }
115  break;
116 
118  InvokeSchEditSymbolLibTable( aKiway, aParent );
119 
120  // Dialog has completed; nothing to return.
121  return nullptr;
122 
123  default:
124  return NULL;
125  }
126  }
127 
139  void* IfaceOrAddress( int aDataId ) override
140  {
141  return NULL;
142  }
143 
144 } kiface( "eeschema", KIWAY::FACE_SCH );
145 
146 } // namespace
147 
148 using namespace SCH;
149 
151 
152 
153 KIFACE_I& Kiface() { return kiface; }
154 
155 
156 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
157 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
158 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
159 {
160  process = aProgram;
161  return &kiface;
162 }
163 
164 
166 {
167  wxASSERT( process ); // KIFACE_GETTER has already been called.
168  return *process;
169 }
170 
171 
173 
175 {
176  unsigned layer = ( aLayer );
177  wxASSERT( layer < DIM( s_layerColor ) );
178  return s_layerColor[layer];
179 }
180 
181 void SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer )
182 {
183  // Do not allow non-background layers to be completely white.
184  // This ensures the BW printing recognizes that the colors should be
185  // printed black.
186  if( aColor == COLOR4D::WHITE && aLayer != LAYER_SCHEMATIC_BACKGROUND )
187  aColor.Darken( 0.01 );
188 
189  unsigned layer = aLayer;
190  wxASSERT( layer < DIM( s_layerColor ) );
191  s_layerColor[layer] = aColor;
192 }
193 
194 
196 {
197  static PARAM_CFG_ARRAY ca;
198 
199  if( !ca.size() )
200  {
201  // These are KIFACE specific, they need to be loaded once when the
202  // eeschema KIFACE comes in.
203 
204 #define CLR(x, y, z)\
205  ca.push_back( new PARAM_CFG_SETCOLOR( true, wxT( x ),\
206  &s_layerColor[( y )], z ) );
207 
208  CLR( "Color4DWireEx", LAYER_WIRE, COLOR4D( GREEN ) )
209  CLR( "Color4DBusEx", LAYER_BUS, COLOR4D( BLUE ) )
210  CLR( "Color4DConnEx", LAYER_JUNCTION, COLOR4D( GREEN ) )
211  CLR( "Color4DLLabelEx", LAYER_LOCLABEL, COLOR4D( BLACK ) )
212  CLR( "Color4DHLabelEx", LAYER_HIERLABEL, COLOR4D( BROWN ) )
213  CLR( "Color4DGLabelEx", LAYER_GLOBLABEL, COLOR4D( RED ) )
214  CLR( "Color4DPinNumEx", LAYER_PINNUM, COLOR4D( RED ) )
215  CLR( "Color4DPinNameEx", LAYER_PINNAM, COLOR4D( CYAN ) )
216  CLR( "Color4DFieldEx", LAYER_FIELDS, COLOR4D( MAGENTA ) )
217  CLR( "Color4DReferenceEx", LAYER_REFERENCEPART, COLOR4D( CYAN ) )
218  CLR( "Color4DValueEx", LAYER_VALUEPART, COLOR4D( CYAN ) )
219  CLR( "Color4DNoteEx", LAYER_NOTES, COLOR4D( LIGHTBLUE ) )
220  CLR( "Color4DBodyEx", LAYER_DEVICE, COLOR4D( RED ) )
221  CLR( "Color4DBodyBgEx", LAYER_DEVICE_BACKGROUND, COLOR4D( LIGHTYELLOW ) )
222  CLR( "Color4DNetNameEx", LAYER_NETNAM, COLOR4D( DARKGRAY ) )
223  CLR( "Color4DPinEx", LAYER_PIN, COLOR4D( RED ) )
224  CLR( "Color4DSheetEx", LAYER_SHEET, COLOR4D( MAGENTA ) )
225  CLR( "Color4DSheetFileNameEx", LAYER_SHEETFILENAME, COLOR4D( BROWN ) )
226  CLR( "Color4DSheetNameEx", LAYER_SHEETNAME, COLOR4D( CYAN ) )
227  CLR( "Color4DSheetLabelEx", LAYER_SHEETLABEL, COLOR4D( BROWN ) )
228  CLR( "Color4DNoConnectEx", LAYER_NOCONNECT, COLOR4D( BLUE ) )
229  CLR( "Color4DErcWEx", LAYER_ERC_WARN, COLOR4D( GREEN ).WithAlpha(0.8 ) )
230  CLR( "Color4DErcEEx", LAYER_ERC_ERR, COLOR4D( RED ).WithAlpha(0.8 ) )
231  CLR( "Color4DGridEx", LAYER_SCHEMATIC_GRID, COLOR4D( DARKGRAY ) )
232  CLR( "Color4DBgCanvasEx", LAYER_SCHEMATIC_BACKGROUND, COLOR4D( WHITE ) )
233  CLR( "Color4DCursorEx", LAYER_SCHEMATIC_CURSOR, COLOR4D( BLACK ) )
234  CLR( "Color4DBrightenedEx", LAYER_BRIGHTENED, COLOR4D( PUREMAGENTA ) )
235  CLR( "Color4DHiddenEx", LAYER_HIDDEN, COLOR4D( LIGHTGRAY ) )
236  CLR( "Color4DWorksheetEx", LAYER_WORKSHEET, COLOR4D( RED ) )
237  }
238 
239  return ca;
240 }
241 
242 
243 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
244 {
245  // This is process level, not project level, initialization of the DSO.
246 
247  // Do nothing in here pertinent to a project!
248 
249  start_common( aCtlBits );
250 
251  // Give a default colour for all layers
252  // (actual color will be initialized by config)
253  for( SCH_LAYER_ID ii = SCH_LAYER_ID_START; ii < SCH_LAYER_ID_END; ++ii )
254  SetLayerColor( COLOR4D( DARKGRAY ), ii );
255 
258 
259  // Must be called before creating the main frame in order to
260  // display the real hotkeys in menus or tool tips
262 
264 
266 
267  if( !fn.FileExists() )
268  {
269  DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( NULL );
270 
271  fpDialog.ShowModal();
272  }
273  else
274  {
275  try
276  {
277  // The global table is not related to a specific project. All projects
278  // will use the same global table. So the KIFACE::OnKifaceStart() contract
279  // of avoiding anything project specific is not violated here.
281  return false;
282  }
283  catch( const IO_ERROR& ioe )
284  {
285  // if we are here, a incorrect global symbol library table was found.
286  // Incorrect global symbol library table is not a fatal error:
287  // the user just has to edit the (partially) loaded table.
288  wxString msg = _(
289  "An error occurred attempting to load the global symbol library table.\n"
290  "Please edit this global symbol library table in Preferences menu."
291  );
292 
293  DisplayErrorMessage( NULL, msg, ioe.What() );
294  }
295  }
296 
297  return true;
298 }
299 
300 
302 {
305 }
Definition: colors.h:57
SCH::IFACE KIFACE_I kiface("eeschema", KIWAY::FACE_SCH)
#define DIM(x)
of elements in an array
Definition: macros.h:98
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
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:90
void SetLayerColor(COLOR4D aColor, SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:181
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
This file is part of the common library TODO brief description.
This file is part of the common library.
int aKiwayVersion
Definition: eeschema.cpp:158
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
Definition: eeschema.cpp:301
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:149
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:76
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: eeschema.cpp:139
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: eeschema.cpp:68
Schematic editor (Eeschema) main window.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
Definition of base KiCad text object.
Symbol library viewer main window.
Definition: viewlib_frame.h:44
int PGM_BASE * aProgram
Definition: eeschema.cpp:159
#define CLR(x, y, z)
#define SCH_EDIT_FRAME_NAME
Definition: draw_frame.h:50
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
#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:243
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
static COLOR4D s_layerColor[LAYER_ID_COUNT]
Definition: eeschema.cpp:172
Definition: eeschema.cpp:62
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:100
Class LIB_ITEM definition.
static PARAM_CFG_ARRAY & cfg_params()
Definition: eeschema.cpp:195
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:258
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
Definition: colors.h:60
SCH_LAYER_ID
Eeschema drawing layers.
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Implementing SIM_PLOT_FRAME_BASE.
FACE_T
Known KIFACE implementations.
Definition: kiway.h:264
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
int ReadHotkeyConfig(const wxString &aAppname, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys...
eeschema DSO
Definition: kiway.h:266
bool IsSingle() const
Function IsSingle is this KIFACE_I running under single_top?
Definition: kiface_i.h:115
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 symbol library editor main window.
Definition: colors.h:58
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:59
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
COLOR4D & Darken(double aFactor)
Function Darken Makes the color darker by a given factor.
Definition: color4d.h:165
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
static PGM_BASE * process
Definition: eeschema.cpp:150
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: eeschema.cpp:153
Definition: colors.h:49
Definition of class LIB_EDIT_FRAME.
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:49
Definition: colors.h:45
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: eeschema.cpp:165
void wxConfigLoadSetups(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG_ARRAY elements to load configuration values from ...
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
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62