Remove KIWAY dependence from SCH_PLUGINs

This commit is contained in:
Jon Evans 2020-05-20 23:00:23 -04:00
parent 7c7b7f41da
commit 2499a1d640
11 changed files with 43 additions and 53 deletions

View File

@ -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 )
{

View File

@ -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<wxString>& 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();

View File

@ -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() ) )

View File

@ -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;

View File

@ -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 );
/**

View File

@ -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<BUS_ALIAS> 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();

View File

@ -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<wxString> 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_

View File

@ -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.

View File

@ -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();

View File

@ -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<wxString> 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_

View File

@ -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() )