77 auto pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
78 std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>(
nullptr );
80 auto &manager =
Pgm().GetSettingsManager();
82 manager.LoadProject(
"" );
84 schematic->SetProject( &manager.Prj() );
85 schematic->SetRoot( pi->LoadSchematicFile( aFilename, schematic.get() ) );
86 schematic->CurrentSheet().push_back( &schematic->Root() );
91 screen->UpdateLocalLibSymbolLinks();
98 if( schematic->RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
100 screen->FixLegacyPowerSymbolMismatches();
103 screen->MigrateSimModels();
109 sheet.UpdateAllScreenReferences();
114 schematic->ConnectionGraph()->Recalculate( sheets,
true );
144 void Reset()
override;
149 int aCtlBits = 0 )
override
324 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
325 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
326 const wxString& aSrcFilePath, wxString& aErrors )
override;
391 m_jobHandler = std::make_unique<EESCHEMA_JOBS_HANDLER>();
413 if( !fn.FileExists() )
422 if( symDialog.ShowModal() != wxID_OK )
442 _(
"An error occurred attempting to load the global symbol library table.\n"
443 "Please edit this global symbol library table in Preferences menu." );
473 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
474 const wxString& aSrcFilePath, wxString& aErrors )
476 wxFileName destFile( aSrcFilePath );
477 wxString destPath = destFile.GetPathWithSep();
478 wxUniChar pathSep = wxFileName::GetPathSeparator();
479 wxString ext = destFile.GetExt();
481 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
482 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
484 destFile.SetPath( destPath );
491 if( destFile.GetName() == aProjectName )
493 destFile.SetName( aNewProjectName );
495 else if( destFile.GetName() == aNewProjectName )
499 if( !aErrors.empty() )
500 aErrors += wxS(
"\n" );
502 msg.Printf(
_(
"Cannot copy file '%s' as it will be overwritten by the new root "
503 "sheet file." ), destFile.GetFullPath() );
517 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
522 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
527 if( destFile.GetName() == aProjectName + wxS(
"-cache" ) )
528 destFile.SetName( aNewProjectName + wxS(
"-cache" ) );
530 if( destFile.GetName() == aProjectName + wxS(
"-rescue" ) )
531 destFile.SetName( aNewProjectName + wxS(
"-rescue" ) );
533 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
537 bool success =
false;
539 if( destFile.GetName() == aProjectName )
540 destFile.SetName( aNewProjectName );
549 if( node->IsList() && node->GetNumberOfChildren() > 1
550 && node->GetChild( 0 )->IsSymbol()
551 && node->GetChild( 0 )->GetSymbol() ==
"source" )
553 auto pathNode = dynamic_cast<SEXPR::SEXPR_STRING*>( node->GetChild( 1 ) );
554 auto symNode = dynamic_cast<SEXPR::SEXPR_SYMBOL*>( node->GetChild( 1 ) );
558 path = pathNode->m_value;
560 path = symNode->m_value;
562 if( path == aProjectName + wxS(
".sch" ) )
563 path = aNewProjectName + wxS(
".sch" );
564 else if( path == aProjectBasePath +
"/" + aProjectName + wxS(
".sch" ) )
565 path = aNewProjectBasePath +
"/" + aNewProjectName + wxS(
".sch" );
566 else if( path.StartsWith( aProjectBasePath ) )
567 path.Replace( aProjectBasePath, aNewProjectBasePath, false );
570 pathNode->m_value = path;
572 symNode->m_value = path;
576 wxFFile destNetList( destFile.GetFullPath(),
"wb" );
578 if( destNetList.IsOpened() )
579 success = destNetList.Write( sexpr->AsString( 0 ) );
592 if( !aErrors.empty() )
593 aErrors += wxS(
"\n" );
595 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
599 else if( destFile.GetName() == wxS(
"sym-lib-table" ) )
602 symbolLibTable.
Load( aSrcFilePath );
604 for(
unsigned i = 0; i < symbolLibTable.
GetCount(); i++ )
609 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
"-cache.lib" ),
610 wxS(
"/" ) + aNewProjectName + wxS(
"-cache.lib" ) );
611 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
"-rescue.lib" ),
612 wxS(
"/" ) + aNewProjectName + wxS(
"-rescue.lib" ) );
613 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
".lib" ),
614 wxS(
"/" ) + aNewProjectName + wxS(
".lib" ) );
621 symbolLibTable.
Save( destFile.GetFullPath() );
627 if( !aErrors.empty() )
630 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
636 wxFAIL_MSG( wxS(
"Unexpected filetype for Eeschema::SaveFileAs()" ) );
constexpr EDA_IU_SCALE schIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
static PROGRESS_REPORTER & GetInstance()
static REPORTER & GetInstance()
The base frame for deriving all KiCad main window classes.
static void SetSchEditFrame(SCH_EDIT_FRAME *aSchEditFrame)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
An simple container class that lets us dispatch output jobs to kifaces.
void InitSettings(APP_SETTINGS_BASE *aSettings)
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
int m_start_flags
flags provided in OnKifaceStart()
bool IsSingle() const
Is this KIFACE running under single_top?
void CreateServer(int service, bool local=true)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
FACE_T
Known KIFACE implementations.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
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...
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
unsigned GetCount() const
Get the number of rows contained in the table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
Container for data for KiCad programs.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Schematic editor (Eeschema) main window.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
std::unique_ptr< SEXPR > ParseFromFile(const std::string &aFilename)
size_t GetNumberOfChildren() const
SEXPR * GetChild(size_t aIndex) const
The SIMULATOR_FRAME holds the main user-interface for running simulations.
The symbol library editor main window.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
Symbol library viewer main window.
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define KICAD_SCH_PORT_SERVICE_NUMBER
Scripting window listens for commands for other apps.
static PGM_BASE * process
PGM_BASE & Pgm()
The global Program "get" accessor.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static void traverseSEXPR(SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ FRAME_SCH_SYMBOL_EDITOR
@ PANEL_SCH_FIELD_NAME_TEMPLATES
@ DIALOG_SCH_LIBRARY_TABLE
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
const std::string BackupFileSuffix
const std::string KiCadSymbolLibFileExtension
const std::string LegacySchematicFileExtension
const std::string LegacySymbolDocumentFileExtension
const std::string NetlistFileExtension
const std::string KiCadSchematicFileExtension
const std::string SchematicSymbolFileExtension
const std::string LegacySymbolLibFileExtension
@ KIFACE_NETLIST_SCHEMATIC
#define KFCTL_CLI
Running as CLI app.
static std::unique_ptr< SCHEMATIC > readSchematicFromFile(const std::string &aFilename)
bool generateSchematicNetlist(const wxString &aFilename, wxString &aNetlist)
SCH::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("eeschema", KIWAY::FACE_SCH)
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
IFACE(const char *aName, KIWAY::FACE_T aType)
void Reset() override
Reloads global state.
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
std::unique_ptr< EESCHEMA_JOBS_HANDLER > m_jobHandler
bool loadGlobalLibTable()
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
int HandleJob(JOB *aJob) override
Definition of file extensions used in Kicad.