KiCad PCB EDA Suite
pcbnew.cpp File Reference

Pcbnew main program. More...

#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <kiface_ids.h>
#include <confirm.h>
#include <macros.h>
#include <pcb_edit_frame.h>
#include <eda_dde.h>
#include <wx/file.h>
#include <wx/snglinst.h>
#include <gestfich.h>
#include <pcbnew.h>
#include <class_board.h>
#include <class_draw_panel_gal.h>
#include <fp_lib_table.h>
#include <footprint_edit_frame.h>
#include <footprint_viewer_frame.h>
#include <footprint_wizard_frame.h>
#include <footprint_preview_panel.h>
#include <footprint_info_impl.h>
#include <dialog_configure_paths.h>
#include "invoke_pcb_dialog.h"
#include "dialog_global_fp_lib_table_config.h"

Go to the source code of this file.

Classes

struct  PCB::IFACE
 

Namespaces

 PCB
 

Functions

bool IsWxPythonLoaded ()
 
PCB::IFACE KIFACE_I PCB::kiface ("pcbnew", KIWAY::FACE_PCB)
 
 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 &aSrcProjectName, 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
 
void PythonPluginsReloadBase ()
 Helper function PythonPluginsReloadBase Reload Python plugins if they are newer than the already loaded, and load new plugins if any It calls the LoadPlugins(bundlepath) Python method see kicadplugins.i. More...
 

Variables

static PGM_BASEprocess
 
int aKiwayVersion
 
int PGM_BASEaProgram
 
return & kiface
 
FP_LIB_TABLE GFootprintTable
 The global footprint library table. More...
 
FOOTPRINT_LIST_IMPL GFootprintList
 The global footprint info table. More...
 

Detailed Description

Pcbnew main program.

Definition in file pcbnew.cpp.

Function Documentation

◆ CreateWindow()

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

Definition at line 393 of file pcbnew.cpp.

397  {
398  if( destFile.GetName() == aSrcProjectName )
399  destFile.SetName( aNewProjectName );
400 
401  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
402  }
403  else if( ext == "brd" )
404  {
405  if( destFile.GetName() == aSrcProjectName )
406  destFile.SetName( aNewProjectName );
407 
408  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
409  }
410  else if( ext == "mod" || ext == "kicad_mod" )
411  {
412  // Footprints are not project-specific. Keep their source names.
413  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
414  }
415  else if( ext == "cmp" )
416  {
417  // JEY TODO
418  }
419  else if( ext == "rpt" )
420  {
421  // DRC must be the "gold standard". Since we can't gaurantee that there aren't
422  // any non-deterministic cases in the save-as algorithm, we don't want to certify
423  // the result with the source's DRC report. Therefore copy it under the old
424  // name.
425  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
426  }
427  else if( destFile.GetName() == "fp-lib-table" )
428  {
429  try
430  {
431  FP_LIB_TABLE fpLibTable;
432  fpLibTable.Load( aSrcFilePath );
433 
434  for( unsigned i = 0; i < fpLibTable.GetCount(); i++ )
435  {
436  LIB_TABLE_ROW& row = fpLibTable.At( i );
437  wxString uri = row.GetFullURI();
438 
439  uri.Replace( "/" + aSrcProjectName + ".pretty", "/" + aNewProjectName + ".pretty" );
440 
441  row.SetFullURI( uri );
442  }
443 
444  fpLibTable.Save( destFile.GetFullPath() );
445  }
446  catch( ... )
447  {
448  wxString msg;
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
unsigned GetCount() const
Get the number of rows contained in the table.
void CopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Function CopyFile.
Definition: gestfich.cpp:358
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
size_t i
Definition: json11.cpp:649
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.

◆ IFACE()

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

Definition at line 385 of file pcbnew.cpp.

385 {
386  wxFileName destFile( aSrcFilePath );
387  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 458 of file pcbnew.cpp.

458  {
459  wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
460  }
461 }
462 

◆ IsWxPythonLoaded()

bool IsWxPythonLoaded ( )

Definition at line 69 of file python_scripting.cpp.

70 {
71  return wxPythonLoaded;
72 }
static bool wxPythonLoaded
True if the wxPython scripting layer was successfully loaded.

Referenced by PCB::IFACE::OnKifaceEnd().

◆ Kiface()

KIFACE_I& Kiface ( )

Global KIFACE_I "get" accessor.

Definition at line 181 of file pcbnew.cpp.

181 { return kiface; }
return & kiface
Definition: pcbnew.cpp:189

References PCB::kiface().

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

◆ MY_API()

MY_API ( KIFACE )

◆ OnKifaceEnd()

void kiface::OnKifaceEnd ( )
override

◆ OnKifaceStart()

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

◆ PythonPluginsReloadBase()

void PythonPluginsReloadBase ( )

Helper function PythonPluginsReloadBase Reload Python plugins if they are newer than the already loaded, and load new plugins if any It calls the LoadPlugins(bundlepath) Python method see kicadplugins.i.

Definition at line 288 of file pcbnew.cpp.

289 {
290 #if defined( KICAD_SCRIPTING )
291  // Reload plugin list: reload Python plugins if they are newer than the already loaded,
292  // and load new plugins
293  char cmd[1024];
294 
295  snprintf( cmd, sizeof( cmd ), "pcbnew.LoadPlugins(\"%s\")", TO_UTF8( PyScriptingPath() ) );
296 
297  PyLOCK lock;
298 
299  // ReRun the Python method pcbnew.LoadPlugins (already called when starting Pcbnew)
300  int retv = PyRun_SimpleString( cmd );
301 
302  if( retv != 0 )
303  wxLogError( "Python error %d occurred running command:\n\n`%s`", retv, cmd );
304 #endif
305 }
#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
wxString PyScriptingPath()
Find the Python scripting path.

References PyScriptingPath(), and TO_UTF8.

Referenced by PCB_EDIT_FRAME::PythonPluginsReload().

◆ SaveFileAs()

void kiface::SaveFileAs ( const wxString &  aProjectBasePath,
const wxString &  aSrcProjectName,
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).

Variable Documentation

◆ aKiwayVersion

int aKiwayVersion

Definition at line 186 of file pcbnew.cpp.

◆ aProgram

int PGM_BASE* aProgram
Initial value:
{
static PGM_BASE * process
Definition: pcbnew.cpp:178
int PGM_BASE * aProgram
Definition: pcbnew.cpp:187

Definition at line 187 of file pcbnew.cpp.

Referenced by KIGFX::SHADER::programInfo().

◆ GFootprintList

FOOTPRINT_LIST_IMPL GFootprintList

The global footprint info table.

This is performance-intensive to build so we keep a hash-stamped global version. Any deviation from the request vs. stored hash will result in it being rebuilt.

Definition at line 316 of file pcbnew.cpp.

Referenced by FP_TREE_MODEL_ADAPTER::getFootprints(), PCB::IFACE::IfaceOrAddress(), FOOTPRINT_EDIT_FRAME::initLibraryTree(), PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), and PCB_BASE_EDIT_FRAME::~PCB_BASE_EDIT_FRAME().

◆ GFootprintTable

FP_LIB_TABLE GFootprintTable

The global footprint library table.

This is not dynamically allocated because in a multiple project environment we must keep its address constant (since it is the fallback table for multiple projects).

Definition at line 311 of file pcbnew.cpp.

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE(), FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount(), PCB::IFACE::IfaceOrAddress(), InvokePcbLibTableEditor(), PCB::IFACE::OnKifaceStart(), PROJECT::PcbFootprintLibs(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ kiface

◆ process

PGM_BASE* process
static

Definition at line 178 of file pcbnew.cpp.