69#include <wx/tokenzr.h>
103static int eeschemaMergeExport(
int aKind,
const wxString& aAncestor,
const wxString& aOurs,
104 const wxString& aTheirs,
const wxString& aOutput,
bool aInteractive,
105 bool aSingleFile,
REPORTER* aReporter );
107 const wxString& aLabelA,
const wxString& aLabelB,
108 wxWindow* aParent,
REPORTER* aReporter );
115 SCH_IO* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
116 std::unique_ptr<SCHEMATIC>
schematic = std::make_unique<SCHEMATIC>(
nullptr );
120 wxFileName pro( aFilename );
123 wxString projectPath = pro.GetFullPath();
140 std::vector<SCH_SHEET*> topLevelSheets =
schematic->GetTopLevelSheets();
141 bool rootIsTopLevel = std::find( topLevelSheets.begin(), topLevelSheets.end(), rootSheet )
142 != topLevelSheets.end();
145 if( !rootIsTopLevel && !rootIsVirtualRoot )
146 schematic->SetTopLevelSheets( { rootSheet } );
151 screen->UpdateLocalLibSymbolLinks();
158 if(
schematic->RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
161 screen->FixLegacyPowerSymbolMismatches();
165 screen->MigrateSimModels();
171 sheet.UpdateAllScreenReferences();
179 schematic->ConnectionGraph()->Recalculate( sheets,
true );
211 void Reset()
override;
236 return new SYMBOL_EDIT_FRAME( aKiway, aParent );
242 SIMULATOR_FRAME* frame =
new SIMULATOR_FRAME( aKiway, aParent );
245 catch(
const SIMULATOR_INIT_ERR& )
254 return new SYMBOL_VIEWER_FRAME( aKiway, aParent );
258 bool cancelled =
false;
317 return new PANEL_SYM_EDITING_OPTIONS( aParent,
this, frame );
325 std::vector<TOOL_ACTION*> actions;
326 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
329 actions.push_back( action );
332 controls.push_back( control );
338 return new PANEL_SYM_COLOR_SETTINGS( aParent );
357 return new PANEL_GRID_SETTINGS( aParent,
this, frame, cfg,
FRAME_SCH );
377 return new PANEL_EESCHEMA_EDITING_OPTIONS( aParent,
this, frame );
385 std::vector<TOOL_ACTION*> actions;
386 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
389 actions.push_back( action );
392 controls.push_back( control );
394 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb,
FRAME_SCH, actions, controls );
398 return new PANEL_EESCHEMA_COLOR_SETTINGS( aParent );
401 return new PANEL_TEMPLATE_FIELDNAMES( aParent,
nullptr );
417 return new PANEL_SIMULATOR_PREFERENCES( aParent );
459 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
460 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
461 const wxString& aSrcFilePath, wxString& aErrors )
override;
470 wxString* aError )
override;
475 wxString* aError )
override;
503 const wxString& aTheirs,
const wxString& aOutput,
bool aInteractive,
504 bool aSingleFile,
REPORTER* aReporter )
507 aOurs, aTheirs, aOutput, aInteractive, aSingleFile,
513 const wxString& aLabelA,
const wxString& aLabelB,
514 wxWindow* aParent,
REPORTER* aReporter )
517 aFileB, aLabelA, aLabelB, aParent, aReporter );
557 m_jobHandler = std::make_unique<EESCHEMA_JOBS_HANDLER>( aKiway );
565 if(
Pgm().ApiServerOrNull() )
590 constexpr static int interval = 150;
591 constexpr static int timeLimit = 120000;
609 [
this, aKiway]() ->
void
611 std::shared_ptr<BACKGROUND_JOB_REPORTER>
reporter =
617 bool aborted =
false;
619 reporter->Report(
_(
"Loading Symbol Libraries" ) );
631 std::this_thread::sleep_for( std::chrono::milliseconds( interval ) );
635 float progress = *loadStatus;
636 reporter->SetCurrentProgress( progress );
649 if( elapsed > timeLimit )
672 wxLogTrace(
traceLibraries,
"eeschema PreloadLibraries: aborted, skipping symbol processing" );
682 std::string payload =
"";
689 std::future<void> preloadFuture = std::async( std::launch::async, preload );
717 if(
Pgm().ApiServerOrNull() )
733 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
734 const wxString& aSrcFilePath, wxString& aErrors )
736 wxFileName destFile( aSrcFilePath );
737 wxString destPath = destFile.GetPathWithSep();
738 wxUniChar pathSep = wxFileName::GetPathSeparator();
739 wxString ext = destFile.GetExt();
741 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
742 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
744 destFile.SetPath( destPath );
751 if( destFile.GetName() == aProjectName )
753 destFile.SetName( aNewProjectName );
755 else if( destFile.GetName() == aNewProjectName )
759 if( !aErrors.empty() )
760 aErrors += wxS(
"\n" );
762 msg.Printf(
_(
"Cannot copy file '%s' as it will be overwritten by the new root "
763 "sheet file." ), destFile.GetFullPath() );
769 [&](
const std::string& token, wxString& value ) ->
bool
771 if( token ==
"project" && value == aProjectName )
773 value = aNewProjectName;
784 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
790 if( destFile.GetName() == aProjectName + wxS(
"-cache" ) )
791 destFile.SetName( aNewProjectName + wxS(
"-cache" ) );
793 if( destFile.GetName() == aProjectName + wxS(
"-rescue" ) )
794 destFile.SetName( aNewProjectName + wxS(
"-rescue" ) );
796 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
800 if( destFile.GetName() == aProjectName )
801 destFile.SetName( aNewProjectName );
804 [&](
const std::string& token, wxString& value ) ->
bool
806 if( token ==
"source" )
808 for( const wxString& extension : { wxString( wxT(
".sch" ) ), wxString( wxT(
".kicad_sch" ) ) } )
810 if( value == aProjectName + extension )
812 value = aNewProjectName + extension;
815 else if( value == aProjectBasePath +
"/" + aProjectName + extension )
817 value = aNewProjectBasePath +
"/" + aNewProjectName + extension;
820 else if( value.StartsWith( aProjectBasePath ) )
822 value.Replace( aProjectBasePath, aNewProjectBasePath, false );
834 wxFileName libTableFn( aSrcFilePath );
836 libTable.SetPath( destFile.GetFullPath() );
839 for( LIBRARY_TABLE_ROW& row : libTable.Rows() )
841 wxString uri = row.URI();
843 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
"-cache.lib" ),
844 wxS(
"/" ) + aNewProjectName + wxS(
"-cache.lib" ) );
845 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
"-rescue.lib" ),
846 wxS(
"/" ) + aNewProjectName + wxS(
"-rescue.lib" ) );
847 uri.Replace( wxS(
"/" ) + aProjectName + wxS(
".lib" ),
848 wxS(
"/" ) + aNewProjectName + wxS(
".lib" ) );
853 libTable.Save().map_error(
854 [&](
const LIBRARY_ERROR& aError )
858 if( !aErrors.empty() )
859 aErrors += wxT(
"\n" );
861 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
867 wxFAIL_MSG( wxS(
"Unexpected filetype for Eeschema::SaveFileAs()" ) );
874 return m_jobHandler->RunJob( aJob, aReporter, aProgressReporter );
909 wxCHECK( aServer,
false );
911 if( aSpec.
kind == DOCUMENT_SPEC::KIND::CREATE_KIND )
914 if( aSpec.
path.IsEmpty() )
917 *aError = wxS(
"No path specified to open" );
922 wxFileName projectPath( aSpec.
path );
929 projectPath.MakeAbsolute();
942 if( !settingsManager.
LoadProject( projectPath.GetFullPath(),
true ) )
943 wxLogTrace(
traceApi,
"Warning: no project file found for %s", aSpec.
path );
951 *aError = wxString::Format( wxS(
"Error loading project for %s" ), aSpec.
path );
956 wxFileName schPath( projectPath );
959 if( !schPath.FileExists() )
962 *aError = wxString::Format( wxS(
"File not found: %s" ), schPath.GetFullPath() );
976 *aError = wxS(
"Failed to load schematic" );
984 *aError = wxS(
"Failed to load schematic" );
1008 wxFileName schPath( aPath );
1009 schPath.MakeAbsolute();
1011 wxFileName projectPath( schPath );
1019 *aError = wxS(
"The current schematic has unsaved changes; save or revert it first" );
1035 settingsManager.
LoadProject( projectPath.GetFullPath(),
true );
1042 *aError = wxString::Format( wxS(
"Error creating project for %s" ), aPath );
1047 std::unique_ptr<SCHEMATIC>
schematic = std::make_unique<SCHEMATIC>(
project );
1051 schematic->RootScreen()->SetFileName( schPath.GetFullPath() );
1073 wxCHECK( aServer,
false );
1078 *aError = wxS(
"No document is currently open" );
1083 if( !aSchFileName.IsEmpty() )
1085 wxFileName currentSch(
m_openContext->GetCurrentFileName() );
1087 if( currentSch.GetFullName() != aSchFileName )
1090 *aError = wxS(
"Requested document does not match the open document" );
1103 wxCHECK_RET( aServer,
"no API server provided" );
constexpr EDA_IU_SCALE schIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
static CLI_PROGRESS_REPORTER & GetInstance()
static CLI_REPORTER & GetInstance()
static bool IsOnStandardSocketPath()
static void AnnounceToPrimary(FRAME_T aFrameType)
The base frame for deriving all KiCad main window classes.
static void SetSchEditFrame(SCH_EDIT_FRAME *aSchEditFrame)
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
Handle Eeschema job dispatches.
SNAP_INFERENCE_SETTINGS m_SnapInference
An simple container class that lets us dispatch output jobs to kifaces.
void RegisterHandler(API_HANDLER *aHandler)
Adds a new request handler to the server.
void DeregisterHandler(API_HANDLER *aHandler)
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
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?
static int Apply(const git_merge_driver_source *aSrc, const char **aPathOut, unsigned int *aModeOut, git_buf *aMergedOut)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
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.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
FACE_T
Known KIFACE implementations.
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
std::optional< float > AsyncLoadProgress() const
Returns async load progress between 0.0 and 1.0, or nullopt if load is not in progress.
std::vector< KI_ERROR > GetLibraryLoadErrors() const
Returns all library load errors as newline-separated strings for display.
void AbortAsyncLoad()
Aborts any async load in progress; blocks until fully done aborting.
void AsyncLoad()
Loads all available libraries for this adapter type in the background.
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 BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
void AddLibraryLoadMessages(const std::vector< KI_ERROR > &aMessages)
Add library load messages to all registered status bars.
void ClearLibraryLoadMessages()
Clear library load messages from all registered status bars.
KICAD_API_SERVER & GetApiServer()
virtual SETTINGS_MANAGER & GetSettingsManager() const
A progress reporter interface for use in multi-threaded environments.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
Holds all the data relating to one schematic.
Schematic editor (Eeschema) main window.
Base class that schematic file and library loading and saving plugins should derive from.
virtual SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load information from some input file format that this SCH_IO implementation knows about,...
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.
bool IsVirtualRootSheet() const
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
Symbol library viewer main window.
SNAP_INFERENCE_SETTINGS m_SnapInference
An interface to the global shared library manager that is schematic-specific and linked to one projec...
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ FRAME_SCH_SYMBOL_EDITOR
@ PANEL_SCH_FIELD_NAME_TEMPLATES
@ DIALOG_SCH_LIBRARY_TABLE
@ DIALOG_DESIGN_BLOCK_LIBRARY_TABLE
void CopySexprFile(const wxString &aSrcPath, const wxString &aDestPath, std::function< bool(const std::string &token, wxString &value)> aCallback, wxString &aErrors)
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
static const std::string LegacySchematicFileExtension
static const std::string NetlistFileExtension
static const std::string SymbolLibraryTableFileName
static const std::string ProjectFileExtension
static const std::string SchematicSymbolFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string KiCadSymbolLibFileExtension
static const std::string BackupFileSuffix
static const std::string LegacySymbolDocumentFileExtension
const wxChar *const traceLibraries
Flag to enable library table and library manager tracing.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
@ KIFACE_MERGE_DOCUMENT
int (*)( int aKind, const wxString& aAncestor, const wxString& aOurs, const wxString& aTheirs,...
@ KIFACE_NETLIST_SCHEMATIC
@ KIFACE_OPEN_DIFF_DIALOG
int (*)( int aKind, const wxString& aFileA, const wxString& aFileB, const wxString& aLabelA,...
#define KFCTL_CLI
Running as CLI app.
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
bool RegisterMergeDriver(const char *aName, MERGE_APPLY_FN aApply)
Register a KiCad merge driver with libgit2.
static int eeschemaMergeExport(int aKind, const wxString &aAncestor, const wxString &aOurs, const wxString &aTheirs, const wxString &aOutput, bool aInteractive, bool aSingleFile, REPORTER *aReporter)
static std::unique_ptr< SCHEMATIC > readSchematicFromFile(const std::string &aFilename)
SCH::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("eeschema", KIWAY::FACE_SCH)
bool generateSchematicNetlist(const wxString &aFilename, std::string &aNetlist)
static int eeschemaOpenDiffDialogExport(int aKind, const wxString &aFileA, const wxString &aFileB, const wxString &aLabelA, const wxString &aLabelB, wxWindow *aParent, REPORTER *aReporter)
void InvokeEditDesignBlockLibTable(KIWAY *aKiway, wxWindow *aParent)
PANEL_SNAPPING * CreateSnappingPanel(wxWindow *aParent, SETTINGS_T *aCfg, FRAME_T aFrameType, SNAP_INFERENCE_SETTINGS SETTINGS_T::*aInference=nullptr, MAGNETIC_SETTINGS SETTINGS_T::*aMagnetics=nullptr)
Build the snapping page for an editor.
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
wxString path
File path (KIND::FILE_KIND) or project path (KIND::FPID_KIND).
Implement a participant in the KIWAY alchemy.
std::future< void > m_libraryPreloadReturn
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
std::unique_ptr< API_HANDLER_SCH > m_openHandler
void PreloadLibraries(KIWAY *aKiway) override
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 ...
void ProjectChanged() override
void CancelPreload(bool aBlock=true) override
void closeCurrentDocument(KICAD_API_SERVER *aServer)
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
EESCHEMA_JOBS_HANDLER * JobHandler() const
Accessor for the non-job diff/merge exports (eeschemaMergeExport etc.).
std::atomic_bool m_libraryPreloadAbort
IFACE(const char *aName, KIWAY::FACE_T aType)
void RegisterLibraryHandlers(KICAD_API_SERVER *aServer) override
Register this face's library API handlers on the given server.
void Reset() override
Reloads global state.
bool HandleApiCloseDocument(const wxString &aSchFileName, KICAD_API_SERVER *aServer, wxString *aError) override
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter) override
std::unique_ptr< EESCHEMA_JOBS_HANDLER > m_jobHandler
std::unique_ptr< API_HANDLER_SCH_LIBRARIES > m_apiHandlerSchLibs
bool LoadAllLibraries() override
Starts a background load of all libraries of the type owned by this face.
std::atomic_bool m_libraryPreloadInProgress
bool HandleApiOpenDocument(const DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError) override
bool HandleJobConfig(JOB *aJob, wxWindow *aParent) override
std::shared_ptr< HEADLESS_SCH_CONTEXT > m_openContext
bool handleCreateSchematic(const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError)
SCHEMATIC * m_openSchematic
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
IbisParser parser & reporter
VECTOR3I expected(15, 30, 45)
static const long long MM
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.