From 2499a1d640791c7147587b4913c27a922e52d350 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 20 May 2020 23:00:23 -0400 Subject: [PATCH] Remove KIWAY dependence from SCH_PLUGINs --- eeschema/dialogs/dialog_sch_sheet_props.cpp | 2 +- eeschema/files-io.cpp | 6 +++--- eeschema/sch_eagle_plugin.cpp | 8 +++---- eeschema/sch_eagle_plugin.h | 2 +- eeschema/sch_io_mgr.h | 10 ++++----- eeschema/sch_legacy_plugin.cpp | 23 +++++++++------------ eeschema/sch_legacy_plugin.h | 7 +++---- eeschema/sch_plugin.cpp | 4 ++-- eeschema/sch_sexpr_plugin.cpp | 23 +++++++++------------ eeschema/sch_sexpr_plugin.h | 7 +++---- eeschema/sheet.cpp | 4 ++-- 11 files changed, 43 insertions(+), 53 deletions(-) diff --git a/eeschema/dialogs/dialog_sch_sheet_props.cpp b/eeschema/dialogs/dialog_sch_sheet_props.cpp index 6310677236..ee63a75c31 100644 --- a/eeschema/dialogs/dialog_sch_sheet_props.cpp +++ b/eeschema/dialogs/dialog_sch_sheet_props.cpp @@ -496,7 +496,7 @@ bool DIALOG_SCH_SHEET_PROPS::onSheetFilenameChanged( const wxString& aNewFilenam try { - pi->Save( newAbsoluteFilename, m_sheet, &Kiway() ); + pi->Save( newAbsoluteFilename, m_sheet, &m_frame->Schematic() ); } catch( const IO_ERROR& ioe ) { diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 59bff0fe93..fc9cc4a67e 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -134,7 +134,7 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName, try { - pi->Save( schematicFileName.GetFullPath(), aSheet, &Kiway() ); + pi->Save( schematicFileName.GetFullPath(), aSheet, &Schematic() ); success = true; } catch( const IO_ERROR& ioe ) @@ -332,7 +332,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in try { - Schematic().SetRoot( pi->Load( fullFileName, &Kiway(), &Schematic() ) ); + Schematic().SetRoot( pi->Load( fullFileName, &Schematic() ) ); GetCurrentSheet().push_back( &Schematic().Root() ); @@ -803,7 +803,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) Schematic().Reset(); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) ); - Schematic().SetRoot( pi->Load( aFileName, &Kiway(), &Schematic() ) ); + Schematic().SetRoot( pi->Load( aFileName, &Schematic() ) ); // Eagle sheets do not use a worksheet frame by default, so set it to an empty one WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance(); diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 1418954555..0794b51983 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -391,18 +391,16 @@ int SCH_EAGLE_PLUGIN::GetModifyHash() const } -SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, - SCH_SHEET* aAppendToMe, - const PROPERTIES* aProperties ) +SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, + SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { - wxASSERT( !aFileName || aKiway != NULL ); + wxASSERT( !aFileName || aSchematic != nullptr ); LOCALE_IO toggle; // toggles on, then off, the C locale. // Load the document wxXmlDocument xmlDocument; m_filename = aFileName; - m_kiway = aKiway; m_schematic = aSchematic; if( !xmlDocument.Load( m_filename.GetFullPath() ) ) diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index 9e02351596..c9f8916042 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -91,7 +91,7 @@ public: int GetModifyHash() const override; - SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, + SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override; bool CheckHeader( const wxString& aFileName ) override; diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 94c121e133..819637a339 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -209,7 +209,7 @@ public: * wrong, using line number and character offsets of the input file if * possible. */ - virtual SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, + virtual SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ); /** @@ -219,13 +219,13 @@ public: * * @param aFileName is the name of a file to save to on disk. * - * @param aSchematic is the class #SCH_SHEET in memory document tree from which to extract + * @param aSheet is the class #SCH_SHEET in memory document tree from which to extract * information when writing to \a aFileName. The caller continues to * own the SCHEMATIC, and the plugin should refrain from modifying the * SCHEMATIC if possible. * - * @param aKiway is the #KIWAY object used to access the component libraries loaded - * by the project. + * @param aSchematic is the #SCHEMATIC object used to access any schematic-wide or project + * information needed to save the document. * * @param aProperties is an associative array that can be used to tell the saver how to * save the file, because it can take any number of additional named @@ -237,7 +237,7 @@ public: * * @throw IO_ERROR if there is a problem saving or exporting. */ - virtual void Save( const wxString& aFileName, SCH_SHEET* aSchematic, KIWAY* aKiway, + virtual void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties = NULL ); /** diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index e192a67e0b..f339df2edb 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -576,22 +576,21 @@ SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN() } -void SCH_LEGACY_PLUGIN::init( KIWAY* aKiway, const PROPERTIES* aProperties ) +void SCH_LEGACY_PLUGIN::init( SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { m_version = 0; m_rootSheet = nullptr; m_props = aProperties; - m_kiway = aKiway; + m_schematic = aSchematic; m_cache = nullptr; m_out = nullptr; - m_schematic = nullptr; } -SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, +SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { - wxASSERT( !aFileName || aKiway != NULL ); + wxASSERT( !aFileName || aSchematic != NULL ); LOCALE_IO toggle; // toggles on, then off, the C locale. SCH_SHEET* sheet; @@ -617,19 +616,17 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SC } if( m_path.IsEmpty() ) - m_path = aKiway->Prj().GetProjectPath(); + m_path = aSchematic->Prj().GetProjectPath(); wxLogTrace( traceSchLegacyPlugin, "m_Normalized append path \"%s\".", m_path ); } else { - m_path = aKiway->Prj().GetProjectPath(); + m_path = aSchematic->Prj().GetProjectPath(); } m_currentPath.push( m_path ); - init( aKiway, aProperties ); - - m_schematic = aSchematic; + init( aSchematic, aProperties ); if( aAppendToMe == NULL ) { @@ -1821,7 +1818,7 @@ std::shared_ptr SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader } -void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWAY* aKiway, +void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." ); @@ -1829,7 +1826,7 @@ void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWA LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values. - init( aKiway, aProperties ); + init( aSchematic, aProperties ); wxFileName fn = aFileName; @@ -1848,7 +1845,7 @@ void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWA void SCH_LEGACY_PLUGIN::Format( SCH_SHEET* aSheet ) { wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." ); - wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." ); + wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." ); SCH_SCREEN* screen = aSheet->GetScreen(); diff --git a/eeschema/sch_legacy_plugin.h b/eeschema/sch_legacy_plugin.h index 7ca7e7fbf4..9445daf002 100644 --- a/eeschema/sch_legacy_plugin.h +++ b/eeschema/sch_legacy_plugin.h @@ -97,14 +97,14 @@ public: int GetModifyHash() const override; - SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway , SCHEMATIC* aSchematic, + SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe = nullptr, const PROPERTIES* aProperties = nullptr ) override; void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen, int version = EESCHEMA_VERSION ); - void Save( const wxString& aFileName, SCH_SHEET* aScreen, KIWAY* aKiway, + void Save( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic, const PROPERTIES* aProperties = nullptr ) override; void Format( SCH_SHEET* aSheet ); @@ -177,14 +177,13 @@ protected: wxString m_path; ///< Root project path for loading child sheets. std::stack m_currentPath;///< Stack to maintain nested sheet paths const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be nullptr. - KIWAY* m_kiway; ///< Required for path to legacy component libraries. SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded.. OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects. SCH_LEGACY_PLUGIN_CACHE* m_cache; SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded /// initialize PLUGIN like a constructor would. - void init( KIWAY* aKiway, const PROPERTIES* aProperties = nullptr ); + void init( SCHEMATIC* aSchematic, const PROPERTIES* aProperties = nullptr ); }; #endif // _SCH_LEGACY_PLUGIN_H_ diff --git a/eeschema/sch_plugin.cpp b/eeschema/sch_plugin.cpp index 5ae9e351fa..29d763be2e 100644 --- a/eeschema/sch_plugin.cpp +++ b/eeschema/sch_plugin.cpp @@ -47,7 +47,7 @@ void SCH_PLUGIN::SaveLibrary( const wxString& aFileName, const PROPERTIES* aProp } -SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, +SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { not_implemented( this, __FUNCTION__ ); @@ -55,7 +55,7 @@ SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC } -void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWAY* aKiway, +void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface. diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 20c5182000..b92455047a 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -407,23 +407,22 @@ SCH_SEXPR_PLUGIN::~SCH_SEXPR_PLUGIN() } -void SCH_SEXPR_PLUGIN::init( KIWAY* aKiway, const PROPERTIES* aProperties ) +void SCH_SEXPR_PLUGIN::init( SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { m_version = 0; m_rootSheet = nullptr; m_props = aProperties; - m_kiway = aKiway; + m_schematic = aSchematic; m_cache = nullptr; m_out = nullptr; m_fieldId = 100; // number arbitrarily > MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS - m_schematic = nullptr; } -SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, +SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { - wxASSERT( !aFileName || aKiway != NULL ); + wxASSERT( !aFileName || aSchematic != nullptr ); LOCALE_IO toggle; // toggles on, then off, the C locale. SCH_SHEET* sheet; @@ -449,19 +448,17 @@ SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCH } if( m_path.IsEmpty() ) - m_path = aKiway->Prj().GetProjectPath(); + m_path = aSchematic->Prj().GetProjectPath(); wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path ); } else { - m_path = aKiway->Prj().GetProjectPath(); + m_path = aSchematic->Prj().GetProjectPath(); } m_currentPath.push( m_path ); - init( aKiway, aProperties ); - - m_schematic = aSchematic; + init( aSchematic, aProperties ); if( aAppendToMe == NULL ) { @@ -582,7 +579,7 @@ void SCH_SEXPR_PLUGIN::LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet, int } -void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWAY* aKiway, +void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." ); @@ -590,7 +587,7 @@ void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWAY LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values. - init( aKiway, aProperties ); + init( aSchematic, aProperties ); wxFileName fn = aFileName; @@ -609,7 +606,7 @@ void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWAY void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet ) { wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." ); - wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." ); + wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." ); SCH_SCREEN* screen = aSheet->GetScreen(); diff --git a/eeschema/sch_sexpr_plugin.h b/eeschema/sch_sexpr_plugin.h index 0d1877eb9e..a1cfb21876 100644 --- a/eeschema/sch_sexpr_plugin.h +++ b/eeschema/sch_sexpr_plugin.h @@ -84,14 +84,14 @@ public: int GetModifyHash() const override; - SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway, SCHEMATIC* aSchematic, + SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe = nullptr, const PROPERTIES* aProperties = nullptr ) override; void LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet, int aVersion = SEXPR_SCHEMATIC_FILE_VERSION ); - void Save( const wxString& aFileName, SCH_SHEET* aSheet, KIWAY* aKiway, + void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties = nullptr ) override; void Format( SCH_SHEET* aSheet ); @@ -154,14 +154,13 @@ protected: wxString m_path; ///< Root project path for loading child sheets. std::stack m_currentPath;///< Stack to maintain nested sheet paths const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be nullptr. - KIWAY* m_kiway; ///< Required for path to legacy component libraries. SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded.. SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects. SCH_SEXPR_PLUGIN_CACHE* m_cache; /// initialize PLUGIN like a constructor would. - void init( KIWAY* aKiway, const PROPERTIES* aProperties = nullptr ); + void init( SCHEMATIC* aSchematic, const PROPERTIES* aProperties = nullptr ); }; #endif // _SCH_SEXPR_PLUGIN_H_ diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 363034e45d..967f84e6e3 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -134,12 +134,12 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier { if( aSheet->GetScreen() != nullptr ) { - newSheet.reset( pi->Load( fullFilename, &Kiway(), &Schematic() ) ); + newSheet.reset( pi->Load( fullFilename, &Schematic() ) ); } else { newSheet->SetFileName( fullFilename ); - pi->Load( fullFilename, &Kiway(), &Schematic(), newSheet.get() ); + pi->Load( fullFilename, &Schematic(), newSheet.get() ); } if( !pi->GetError().IsEmpty() )