31 #ifdef KICAD_SCRIPTING 43 #include <wx/snglinst.h> 77 wxWindow*
CreateWindow( wxWindow* aParent,
int aClassId,
KIWAY* aKiway,
int aCtlBits = 0 )
override 85 #if defined( KICAD_SCRIPTING ) 123 if( dlg.ShowQuasiModal() == wxID_OK )
175 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aSrcProjectName,
176 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
177 const wxString& aSrcFilePath, wxString& aErrors )
override;
200 #if defined( BUILD_KIWAY_DLL ) 216 #if defined( KICAD_SCRIPTING ) 217 static bool scriptingSetup()
220 #if defined( __WINDOWS__ ) 225 wxFileName fn( kipython );
226 kipython = fn.GetPath();
230 if( wxDirExists( kipython ) )
234 wxSetEnv( wxT(
"PYTHONPATH" ), wxEmptyString );
235 wxSetEnv( wxT(
"PYTHONHOME" ), wxEmptyString );
239 wxGetEnv( wxT(
"PATH" ), &ppath );
241 kipython << wxT(
";" ) << ppath;
242 wxSetEnv( wxT(
"PATH" ), kipython );
245 #elif defined( __WXMAC__ ) 251 pypath += PATHS::GetOSXKicadDataDir() + wxT(
"/scripting" );
254 if( wxGetenv(
"KICAD_PATH") !=
NULL )
256 pypath += wxT(
":" ) + wxString( wxGetenv(
"KICAD_PATH") );
260 pypath += wxT(
":" ) +
Pgm().GetExecutablePath() +
261 wxT(
"Contents/Frameworks/python/site-packages" );
264 if( wxGetenv( wxT(
"PYTHONPATH" ) ) !=
NULL )
266 pypath = wxString( wxGetenv( wxT(
"PYTHONPATH" ) ) ) + wxT(
":" ) + pypath;
270 wxSetEnv(
"PYTHONPATH", pypath );
276 pypath =
Pgm().GetExecutablePath() + wxT(
"../" PYTHON_DEST );
278 if( !wxIsEmpty( wxGetenv( wxT(
"PYTHONPATH" ) ) ) )
279 pypath = wxString( wxGetenv( wxT(
"PYTHONPATH" ) ) ) + wxT(
":" ) + pypath;
281 wxSetEnv( wxT(
"PYTHONPATH" ), pypath );
289 if( !path.DirExists() && !path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
290 wxLogError(
"Warning: could not create user scripting path %s", path.GetPath() );
294 wxLogError(
"pcbnewInitPythonScripting() failed." );
300 #endif // KICAD_SCRIPTING 305 #if defined( KICAD_SCRIPTING ) 316 int retv = PyRun_SimpleString( cmd );
319 wxLogError(
"Python error %d occurred running command:\n\n`%s`", retv, cmd );
347 if( !fn.FileExists() )
351 fpDialog.ShowModal();
369 "An error occurred attempting to load the global footprint library table.\n" 370 "Please edit this global footprint library table in Preferences menu." 377 #if defined( KICAD_SCRIPTING ) 387 #if defined( KICAD_SCRIPTING_WXPYTHON ) 401 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
402 const wxString& aSrcFilePath, wxString& aErrors )
404 wxFileName destFile( aSrcFilePath );
405 wxString destPath = destFile.GetPathWithSep();
406 wxUniChar pathSep = wxFileName::GetPathSeparator();
407 wxString ext = destFile.GetExt();
409 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
410 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
412 wxString srcProjectFootprintLib = pathSep + aSrcProjectName +
".pretty" + pathSep;
413 wxString newProjectFootprintLib = pathSep + aNewProjectName +
".pretty" + pathSep;
415 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
417 destFile.SetPath( destPath );
421 if( destFile.GetName() == aSrcProjectName )
422 destFile.SetName( aNewProjectName );
424 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
428 if( destFile.GetName() == aSrcProjectName )
429 destFile.SetName( aNewProjectName );
431 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
436 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
442 else if( ext ==
"rpt" )
448 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
450 else if( destFile.GetName() ==
"fp-lib-table" )
455 fpLibTable.
Load( aSrcFilePath );
457 for(
unsigned i = 0; i < fpLibTable.
GetCount(); i++ )
462 uri.Replace(
"/" + aSrcProjectName +
".pretty",
"/" + aNewProjectName +
".pretty" );
467 fpLibTable.
Save( destFile.GetFullPath() );
473 if( !aErrors.empty() )
476 msg.Printf(
_(
"Cannot copy file \"%s\"." ), destFile.GetFullPath() );
482 wxFAIL_MSG(
"Unexpected filetype for Pcbnew::SaveFileAs()" );
virtual SETTINGS_MANAGER & GetSettingsManager() const
A KIFACE (I)mplementation.
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
It is only used for debugging, since "this" is not a wxWindow*.
#define KICAD_PCB_PORT_SERVICE_NUMBER
< Pcbnew listens on this port for commands from Eeschema
const std::string LegacyFootprintLibPathExtension
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 ...
bool pcbnewInitPythonScripting(const char *aStockScriptingPath, const char *aUserScriptingPath)
Initialize the python environment and publish the Pcbnew interface inside it.
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library TODO brief description.
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
This file is part of the common library.
const std::string KiCadFootprintFileExtension
Container for data for KiCad programs.
const std::string LegacyPcbFileExtension
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
const std::string BackupFileSuffix
unsigned GetCount() const
Get the number of rows contained in the table.
static PGM_BASE * process
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
APP_SETTINGS_BASE * KifaceSettings() const
const std::string ComponentFileExtension
const std::string KiCadPcbFileExtension
Return the global FP_LIB_TABLE.
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPcbEditFrame)
void pcbnewFinishPythonScripting()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
wxString PyScriptingPath(bool aUserPath)
Find the Python scripting path.
not specified: a GAL engine must be set by the client
FP_LIB_TABLE GFootprintTable
The global footprint library table.
IFACE(const char *aName, KIWAY::FACE_T aType)
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 InvokePcbLibTableEditor(KIWAY *aKiway, wxWindow *aCaller)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the glob...
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
bool IsSingle() const
Is this KIFACE_I running under single_top?
virtual const wxString What() const
A composite of Problem() and Where()
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
wxString PyPluginsPath(bool aUserPath)
Definition of file extensions used in Kicad.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Return a new FP_LIB_TABLE with the global table installed as a fallback.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
PCB::IFACE KIFACE_I kiface("pcbnew", KIWAY::FACE_PCB)
FACE_T
Known KIFACE implementations.
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
void PythonPluginsReloadBase()
Helper function PythonPluginsReloadBase Reload Python plugins if they are newer than the already load...
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.
Implement a participant in the KIWAY alchemy.
The main frame for Pcbnew.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
void InitSettings(APP_SETTINGS_BASE *aSettings)
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
static wxString GetGlobalTableFileName()
Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew.