KiCad PCB EDA Suite
eeschema.cpp File Reference
#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <confirm.h>
#include <gestfich.h>
#include <eda_dde.h>
#include <sch_edit_frame.h>
#include <lib_edit_frame.h>
#include <viewlib_frame.h>
#include <general.h>
#include <class_libentry.h>
#include <transform.h>
#include <symbol_lib_table.h>
#include <dialogs/dialog_global_sym_lib_table_config.h>
#include <dialogs/panel_sym_lib_table.h>
#include <kiway.h>
#include <sim/sim_plot_frame.h>
#include <sexpr/sexpr.h>
#include <sexpr/sexpr_parser.h>

Go to the source code of this file.

Classes

struct  SCH::IFACE
 

Namespaces

 SCH
 

Macros

#define CLR(x, y, z)
 

Functions

SCH::IFACE KIFACE_I SCH::kiface ("eeschema", KIWAY::FACE_SCH)
 
 IFACE (const char *aName, KIWAY::FACE_T aType)
 
bool OnKifaceStart (PGM_BASE *aProgram, int aCtlBits) override
 
void OnKifaceEnd () override
 
wxWindow * CreateWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 
void * IfaceOrAddress (int aDataId) override
 Function IfaceOrAddress return a pointer to the requested object. More...
 
void SaveFileAs (const wxString &aProjectBasePath, const wxString &aProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
 Function SaveFileAs Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating). More...
 
KIFACE_IKiface ()
 Global KIFACE_I "get" accessor. More...
 
 MY_API (KIFACE *) KIFACE_GETTER(int *aKIFACEversion
 
PGM_BASEPgm ()
 The global Program "get" accessor. More...
 
COLOR4D GetLayerColor (SCH_LAYER_ID aLayer)
 
void SetLayerColor (COLOR4D aColor, SCH_LAYER_ID aLayer)
 
static PARAM_CFG_ARRAYcfg_params ()
 
static void traverseSEXPR (SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
 

Variables

SCH_SHEETg_RootSheet = NULL
 
TRANSFORM DefaultTransform = TRANSFORM( 1, 0, 0, -1 )
 
static PGM_BASEprocess
 
int aKiwayVersion
 
int PGM_BASEaProgram
 
return & kiface
 
static COLOR4D s_layerColor [LAYER_ID_COUNT]
 

Macro Definition Documentation

◆ CLR

#define CLR (   x,
  y,
 
)
Value:
ca.push_back( new PARAM_CFG_SETCOLOR( true, wxT( x ),\
&s_layerColor[( y )], z ) );
static COLOR4D s_layerColor[LAYER_ID_COUNT]
Definition: eeschema.cpp:165
Configuration parameter - SetColor Class.

Function Documentation

◆ cfg_params()

static PARAM_CFG_ARRAY& cfg_params ( )
static

Definition at line 187 of file eeschema.cpp.

188 {
189  static PARAM_CFG_ARRAY ca;
190 
191  if( !ca.size() )
192  {
193  // These are KIFACE specific, they need to be loaded once when the
194  // eeschema KIFACE comes in.
195 
196 #define CLR(x, y, z)\
197  ca.push_back( new PARAM_CFG_SETCOLOR( true, wxT( x ),\
198  &s_layerColor[( y )], z ) );
199 
200  CLR( "Color4DWireEx", LAYER_WIRE, COLOR4D( GREEN ) )
201  CLR( "Color4DBusEx", LAYER_BUS, COLOR4D( BLUE ) )
202  CLR( "Color4DConnEx", LAYER_JUNCTION, COLOR4D( GREEN ) )
203  CLR( "Color4DLLabelEx", LAYER_LOCLABEL, COLOR4D( BLACK ) )
204  CLR( "Color4DHLabelEx", LAYER_HIERLABEL, COLOR4D( BROWN ) )
205  CLR( "Color4DGLabelEx", LAYER_GLOBLABEL, COLOR4D( RED ) )
206  CLR( "Color4DPinNumEx", LAYER_PINNUM, COLOR4D( RED ) )
207  CLR( "Color4DPinNameEx", LAYER_PINNAM, COLOR4D( CYAN ) )
208  CLR( "Color4DFieldEx", LAYER_FIELDS, COLOR4D( MAGENTA ) )
209  CLR( "Color4DReferenceEx", LAYER_REFERENCEPART, COLOR4D( CYAN ) )
210  CLR( "Color4DValueEx", LAYER_VALUEPART, COLOR4D( CYAN ) )
211  CLR( "Color4DNoteEx", LAYER_NOTES, COLOR4D( LIGHTBLUE ) )
212  CLR( "Color4DBodyEx", LAYER_DEVICE, COLOR4D( RED ) )
213  CLR( "Color4DBodyBgEx", LAYER_DEVICE_BACKGROUND, COLOR4D( LIGHTYELLOW ) )
214  CLR( "Color4DNetNameEx", LAYER_NETNAM, COLOR4D( DARKGRAY ) )
215  CLR( "Color4DPinEx", LAYER_PIN, COLOR4D( RED ) )
216  CLR( "Color4DSheetEx", LAYER_SHEET, COLOR4D( MAGENTA ) )
217  CLR( "Color4DSheetFileNameEx", LAYER_SHEETFILENAME, COLOR4D( BROWN ) )
218  CLR( "Color4DSheetNameEx", LAYER_SHEETNAME, COLOR4D( CYAN ) )
219  CLR( "Color4DSheetLabelEx", LAYER_SHEETLABEL, COLOR4D( BROWN ) )
220  CLR( "Color4DNoConnectEx", LAYER_NOCONNECT, COLOR4D( BLUE ) )
221  CLR( "Color4DErcWEx", LAYER_ERC_WARN, COLOR4D( GREEN ).WithAlpha(0.8 ) )
222  CLR( "Color4DErcEEx", LAYER_ERC_ERR, COLOR4D( RED ).WithAlpha(0.8 ) )
223  CLR( "Color4DGridEx", LAYER_SCHEMATIC_GRID, COLOR4D( DARKGRAY ) )
224  CLR( "Color4DBgCanvasEx", LAYER_SCHEMATIC_BACKGROUND, COLOR4D( WHITE ) )
225  CLR( "Color4DCursorEx", LAYER_SCHEMATIC_CURSOR, COLOR4D( BLACK ) )
226  CLR( "Color4DBrightenedEx", LAYER_BRIGHTENED, COLOR4D( PUREMAGENTA ) )
227  CLR( "Color4DHiddenEx", LAYER_HIDDEN, COLOR4D( LIGHTGRAY ) )
228  CLR( "Color4DWorksheetEx", LAYER_WORKSHEET, COLOR4D( RED ) )
229 // Macs look better with a lighter shadow
230 #ifdef __WXMAC__
231  CLR( "Color4DShadowEx", LAYER_SELECTION_SHADOWS, COLOR4D( .78, .92, 1.0, 0.8 ) )
232 #else
233  CLR( "Color4DShadowEx", LAYER_SELECTION_SHADOWS, COLOR4D( .4, .7, 1.0, 0.8 ) )
234 #endif
235  }
236 
237  return ca;
238 }
Definition: colors.h:57
A list of parameters type.
Definition: colors.h:61
#define CLR(x, y, z)
Definition: colors.h:59
Definition: colors.h:60
Definition: colors.h:58
Definition: colors.h:49
Definition: colors.h:45
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62

References BLACK, BLUE, BROWN, CLR, CYAN, DARKGRAY, GREEN, LAYER_BRIGHTENED, LAYER_BUS, LAYER_DEVICE, LAYER_DEVICE_BACKGROUND, LAYER_ERC_ERR, LAYER_ERC_WARN, LAYER_FIELDS, LAYER_GLOBLABEL, LAYER_HIDDEN, LAYER_HIERLABEL, LAYER_JUNCTION, LAYER_LOCLABEL, LAYER_NETNAM, LAYER_NOCONNECT, LAYER_NOTES, LAYER_PIN, LAYER_PINNAM, LAYER_PINNUM, LAYER_REFERENCEPART, LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_CURSOR, LAYER_SCHEMATIC_GRID, LAYER_SELECTION_SHADOWS, LAYER_SHEET, LAYER_SHEETFILENAME, LAYER_SHEETLABEL, LAYER_SHEETNAME, LAYER_VALUEPART, LAYER_WIRE, LAYER_WORKSHEET, LIGHTBLUE, LIGHTGRAY, LIGHTYELLOW, MAGENTA, PUREMAGENTA, RED, and WHITE.

Referenced by SCH::IFACE::OnKifaceEnd(), and SCH::IFACE::OnKifaceStart().

◆ CreateWindow()

wxWindow* kiface::CreateWindow ( wxWindow *  aParent,
int  aClassId,
KIWAY aKiway,
int  aCtlBits = 0 
)
override

Definition at line 323 of file eeschema.cpp.

327  {
328  if( destFile.GetName() == aProjectName )
329  destFile.SetName( aNewProjectName );
330 
331  // Sheet paths when auto-generated are relative to the root, so those will stay
332  // pointing to whatever they were pointing at.
333  // The author can create their own absolute and relative sheet paths. Absolute
334  // sheet paths aren't an issue, and relative ones will continue to work as long
335  // as the author didn't include any '..'s. If they did, it's still not clear
336  // whether they should be adjusted or not (as the author may be duplicating an
337  // entire tree with several projects within it), so we leave this as an exercise
338  // to the author.
339 
340  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
341  }
342  else if( ext == "sym" )
343  {
344  // Symbols are not project-specific. Keep their source names.
345  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
346  }
347  else if( ext == "lib" )
348  {
349  if( destFile.GetName() == aProjectName )
350  destFile.SetName( aNewProjectName );
351  else if( destFile.GetName() == aProjectName + "-cache" )
352  destFile.SetName( aNewProjectName + "-cache" );
353  else if( destFile.GetName() == aProjectName + "-rescue" )
354  destFile.SetName( aNewProjectName + "-rescue" );
355 
356  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
357  }
358  else if( ext == "net" )
359  {
360  bool success = false;
361 
362  if( destFile.GetName() == aProjectName )
363  destFile.SetName( aNewProjectName );
364 
365  try
366  {
367  SEXPR::PARSER parser;
368  std::unique_ptr<SEXPR::SEXPR> sexpr( parser.ParseFromFile( TO_UTF8( aSrcFilePath ) ) );
void CopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Function CopyFile.
Definition: gestfich.cpp:362
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48

◆ GetLayerColor()

COLOR4D GetLayerColor ( SCH_LAYER_ID  aLayer)

Definition at line 167 of file eeschema.cpp.

168 {
169  unsigned layer = ( aLayer );
170  wxASSERT( layer < arrayDim( s_layerColor ) );
171  return s_layerColor[layer];
172 }
static COLOR4D s_layerColor[LAYER_ID_COUNT]
Definition: eeschema.cpp:165
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108

References arrayDim(), and s_layerColor.

Referenced by WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls(), SCH_LINE::GetDefaultColor(), LIB_FIELD::GetDefaultColor(), LIB_ITEM::GetDefaultColor(), SCH_LINE::GetLineColor(), LIB_RECTANGLE::Plot(), LIB_CIRCLE::Plot(), LIB_BEZIER::Plot(), LIB_ARC::Plot(), LIB_POLYLINE::Plot(), SCH_JUNCTION::Plot(), SCH_NO_CONNECT::Plot(), SCH_BUS_ENTRY_BASE::Plot(), SCH_BITMAP::Plot(), SCH_FIELD::Plot(), SCH_TEXT::Plot(), SCH_LINE::Plot(), LIB_PART::Plot(), SCH_SHEET::Plot(), DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL(), LIB_PART::PlotLibFields(), DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF(), DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF(), DIALOG_PLOT_SCHEMATIC::plotOneSheetPS(), DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG(), LIB_PIN::PlotPinTexts(), LIB_PIN::PlotSymbol(), LIB_POLYLINE::print(), LIB_RECTANGLE::print(), LIB_CIRCLE::print(), LIB_BEZIER::print(), LIB_ARC::print(), SCH_MARKER::Print(), SCH_JUNCTION::Print(), SCH_NO_CONNECT::Print(), SCH_BUS_ENTRY_BASE::Print(), SCH_TEXT::Print(), SCH_LINE::Print(), SCH_FIELD::Print(), SCH_GLOBALLABEL::Print(), SCH_HIERLABEL::Print(), SCH_SHEET::Print(), SCH_PRINTOUT::PrintPage(), LIB_PIN::PrintPinElectricalTypeName(), LIB_PIN::PrintPinSymbol(), LIB_PIN::PrintPinTexts(), and SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL().

◆ IFACE()

kiface::IFACE ( const char *  aName,
KIWAY::FACE_T  aType 
)

Definition at line 315 of file eeschema.cpp.

315 {
316  wxFileName destFile( aSrcFilePath );
317  wxString destPath = destFile.GetPath();

◆ IfaceOrAddress()

void* kiface::IfaceOrAddress ( int  aDataId)
override

Function IfaceOrAddress return a pointer to the requested object.

The safest way to use this is to retrieve a pointer to a static instance of an interface, similar to how the KIFACE interface is exported. But if you know what you are doing use it to retrieve anything you want.

Parameters
aDataIdidentifies which object you want the address of.
Returns
void* - and must be cast into the know type.

Definition at line 378 of file eeschema.cpp.

◆ Kiface()

KIFACE_I& Kiface ( )

Global KIFACE_I "get" accessor.

Definition at line 146 of file eeschema.cpp.

146 { return kiface; }
return & kiface
Definition: eeschema.cpp:154

References SCH::kiface().

Referenced by SCH::IFACE::CreateWindow().

◆ MY_API()

MY_API ( KIFACE )

◆ OnKifaceEnd()

void kiface::OnKifaceEnd ( )
override

◆ OnKifaceStart()

bool kiface::OnKifaceStart ( PGM_BASE aProgram,
int  aCtlBits 
)
override

◆ Pgm()

PGM_BASE& Pgm ( )

The global Program "get" accessor.

Implemented in: 1) common/single_top.cpp, 2) kicad/kicad.cpp, and 3) scripting/kiway.i

Definition at line 158 of file eeschema.cpp.

159 {
160  wxASSERT( process ); // KIFACE_GETTER has already been called.
161  return *process;
162 }
static PGM_BASE * process
Definition: eeschema.cpp:143

References process.

◆ SaveFileAs()

void kiface::SaveFileAs ( const wxString &  aProjectBasePath,
const wxString &  aProjectName,
const wxString &  aNewProjectBasePath,
const wxString &  aNewProjectName,
const wxString &  aSrcFilePath,
wxString &  aErrors 
)
override

Function SaveFileAs Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating).

◆ SetLayerColor()

void SetLayerColor ( COLOR4D  aColor,
SCH_LAYER_ID  aLayer 
)

Definition at line 174 of file eeschema.cpp.

175 {
176  // Do not allow non-background layers to be completely white.
177  // This ensures the BW printing recognizes that the colors should be printed black.
178  if( aColor == COLOR4D::WHITE && aLayer != LAYER_SCHEMATIC_BACKGROUND )
179  aColor.Darken( 0.01 );
180 
181  unsigned layer = aLayer;
182  wxASSERT( layer < arrayDim( s_layerColor ) );
183  s_layerColor[layer] = aColor;
184 }
static COLOR4D s_layerColor[LAYER_ID_COUNT]
Definition: eeschema.cpp:165
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
COLOR4D & Darken(double aFactor)
Function Darken Makes the color darker by a given factor.
Definition: color4d.h:163
Definition: colors.h:49

References arrayDim(), KIGFX::COLOR4D::Darken(), LAYER_SCHEMATIC_BACKGROUND, s_layerColor, and WHITE.

Referenced by SCH::IFACE::OnKifaceStart(), and WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl().

◆ traverseSEXPR()

static void traverseSEXPR ( SEXPR::SEXPR *  aNode,
const std::function< void(SEXPR::SEXPR *)> &  aVisitor 
)
static

Definition at line 299 of file eeschema.cpp.

301 {
302  aVisitor( aNode );
303 
304  if( aNode->IsList() )
305  {
306  for( unsigned i = 0; i < aNode->GetNumberOfChildren(); i++ )
307  traverseSEXPR( aNode->GetChild( i ), aVisitor );
308  }
309 }
static void traverseSEXPR(SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
Definition: eeschema.cpp:299
size_t i
Definition: json11.cpp:649

References i.

Variable Documentation

◆ aKiwayVersion

int aKiwayVersion

Definition at line 151 of file eeschema.cpp.

◆ aProgram

int PGM_BASE* aProgram
Initial value:
{
int PGM_BASE * aProgram
Definition: eeschema.cpp:152
static PGM_BASE * process
Definition: eeschema.cpp:143

Definition at line 152 of file eeschema.cpp.

◆ DefaultTransform

◆ g_RootSheet

SCH_SHEET* g_RootSheet = NULL

Definition at line 47 of file eeschema.cpp.

Referenced by NETLIST_EXPORTER_GENERIC::addComponentFields(), SCH_EDIT_FRAME::AnnotateComponents(), SCH_EDITOR_CONTROL::BackAnnotateFootprints(), SCH_SCREENS::BuildClientSheetPathList(), CONNECTION_GRAPH::buildConnectionGraph(), SCH_EDIT_FRAME::BuildNetListBase(), SCH_SHEET_LIST::BuildSheetList(), SCH_EDIT_FRAME::CheckAnnotate(), SCH_EDIT_FRAME::checkSheetForRecursion(), SCH_SCREENS::ClearAnnotationOfNewSheetPaths(), SCH_EDIT_FRAME::CreateArchiveLibraryCacheFile(), DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), SCH_EDIT_FRAME::CreateNetlist(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), SCH_EDIT_FRAME::CreateScreens(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), DIALOG_ERC::DisplayERC_MarkersList(), SCH_EDIT_FRAME::doAutoSave(), SCH_EDIT_TOOL::Duplicate(), SCH_EDIT_FRAME::EditSheet(), NETLIST_EXPORTER::findAllUnitsOfComponent(), SCH_EDITOR_CONTROL::FindComponentAndItem(), SCH_EDITOR_CONTROL::FindNext(), SCH_EDIT_FRAME::FixupJunctions(), SCH_SCREEN::GetBusAlias(), SCH_PRINTOUT::GetPageInfo(), GetRescueLibraryFileName(), SCH_PRINTOUT::HasPage(), HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG(), SCH_EDIT_FRAME::importFile(), SCH_DRAWING_TOOLS::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), DIALOG_EDIT_COMPONENTS_LIBID::initDlg(), SCH_EDIT_FRAME::isAutoSaveRequired(), SCH_SCREEN::IsBusAlias(), SCH_EDIT_FRAME::KiwayMailIn(), SCH_EDITOR_CONTROL::LeaveSheet(), SCH_EDIT_FRAME::LoadSheetFromFile(), NETLIST_EXPORTER_GENERIC::makeComponents(), NETLIST_EXPORTER_GENERIC::makeDesignHeader(), mapExistingAnnotation(), SCH_EDIT_FRAME::OnCloseWindow(), DIALOG_ERC::OnLeftClickMarkersList(), SCH_EDIT_FRAME::OnOpenCvpcb(), SCH_EDIT_FRAME::OnOpenPcbnew(), DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked(), SCH_PRINTOUT::OnPrintPage(), DIALOG_BOM::OnRunGenerator(), SCH_EDIT_FRAME::OnUpdatePCB(), SCH_EDIT_FRAME::OpenProjectFiles(), SCH_EDITOR_CONTROL::Paste(), SCH_EDIT_FRAME::prepareForNetlist(), SCH_EDIT_FRAME::Print(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), SCH_EDIT_TOOL::Properties(), SCH_EDIT_FRAME::RecalculateConnections(), SCH_EDIT_FRAME::ReCreateMenuBar(), SCH_EDITOR_CONTROL::ReplaceAll(), SCH_EDIT_FRAME::SaveProject(), SCH_EDIT_FRAME::SaveProjectSettings(), SCH_SCREENS::SCH_SCREENS(), SCH_EDIT_FRAME::SetSheetNumberAndCount(), SCH_EDIT_FRAME::SyncToolbars(), DIALOG_ERC::TestErc(), SCH_SHEET_PATH::TestForRecursion(), SCH_SHEET_LIST::TestForRecursion(), DIALOG_PRINT_USING_PRINTER::TransferDataFromWindow(), DIALOG_SCH_SHEET_PROPS::TransferDataFromWindow(), NETLIST_DIALOG::TransferDataFromWindow(), DIALOG_BUS_MANAGER::TransferDataToWindow(), NETLIST_EXPORTER_PSPICE::UpdateDirectives(), WriteDiagnosticERC(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and SCH_EDIT_FRAME::~SCH_EDIT_FRAME().

◆ kiface

return& kiface

Definition at line 154 of file eeschema.cpp.

◆ process

PGM_BASE* process
static

Definition at line 143 of file eeschema.cpp.

Referenced by Pgm().

◆ s_layerColor

COLOR4D s_layerColor[LAYER_ID_COUNT]
static

Definition at line 165 of file eeschema.cpp.

Referenced by GetLayerColor(), and SetLayerColor().