eeschema: add interface to SCHEMATIC for better testability

- added abstract class SCHEMATIC_IFACE
- added missing 'virtual' keyword at destructor
This commit is contained in:
Sylwester Kocjan 2021-01-25 22:19:07 +01:00 committed by Jon Evans
parent 0198d5a3bd
commit 114043fe93
4 changed files with 26 additions and 12 deletions

View File

@ -108,7 +108,7 @@ protected:
std::set<LIB_PART*, LIB_PART_LESS_THAN> m_libParts;
/// The schematic we're generating a netlist for
SCHEMATIC* m_schematic;
SCHEMATIC_IFACE* m_schematic;
/// The schematic's CurrentSheet when we entered. Restore on exiting.
SCH_SHEET_PATH m_savedCurrentSheet;
@ -163,7 +163,7 @@ public:
* @param aMasterList we take ownership of this here.
* @param aLibTable is the symbol library table of the project.
*/
NETLIST_EXPORTER_BASE( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER_BASE( SCHEMATIC_IFACE* aSchematic ) :
m_schematic( aSchematic )
{
wxASSERT( aSchematic );

View File

@ -101,7 +101,7 @@ struct SPICE_ITEM
class NETLIST_EXPORTER_PSPICE : public NETLIST_EXPORTER_BASE
{
public:
NETLIST_EXPORTER_PSPICE( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER_PSPICE( SCHEMATIC_IFACE* aSchematic ) :
NETLIST_EXPORTER_BASE( aSchematic )
{
}

View File

@ -35,13 +35,27 @@ class SCH_SHEET;
class SCH_SHEET_LIST;
class SCHEMATIC_IFACE
{
public:
SCHEMATIC_IFACE() {};
virtual ~SCHEMATIC_IFACE() {};
virtual CONNECTION_GRAPH* ConnectionGraph() const = 0;
virtual SCH_SHEET_LIST GetSheets() const = 0;
virtual void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) = 0;
virtual SCH_SHEET_PATH& CurrentSheet() const = 0;
virtual wxString GetFileName() const = 0;
virtual PROJECT& Prj() const = 0;
};
/**
* Holds all the data relating to one schematic
* A schematic may consist of one or more sheets (and one root sheet)
* Right now, eeschema can have only one schematic open at a time, but this could change.
* Please keep this possibility in mind when adding to this object.
*/
class SCHEMATIC : public EDA_ITEM
class SCHEMATIC : public SCHEMATIC_IFACE, public EDA_ITEM
{
friend class SCH_EDIT_FRAME;
@ -71,7 +85,7 @@ private:
public:
SCHEMATIC( PROJECT* aPrj );
~SCHEMATIC();
virtual ~SCHEMATIC();
virtual wxString GetClass() const override
{
@ -82,7 +96,7 @@ public:
void Reset();
/// Return a reference to the project this schematic is part of
PROJECT& Prj() const
PROJECT& Prj() const override
{
return *m_project;
}
@ -94,7 +108,7 @@ public:
* TODO: can this be cached?
* @return a SCH_SHEET_LIST containing the schematic hierarchy
*/
SCH_SHEET_LIST GetSheets() const
SCH_SHEET_LIST GetSheets() const override
{
return SCH_SHEET_LIST( m_rootSheet );
}
@ -122,19 +136,19 @@ public:
SCH_SCREEN* RootScreen() const;
/// Helper to retrieve the filename from the root sheet screen
wxString GetFileName() const;
wxString GetFileName() const override;
SCH_SHEET_PATH& CurrentSheet() const
SCH_SHEET_PATH& CurrentSheet() const override
{
return *m_currentSheet;
}
void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) override
{
*m_currentSheet = aPath;
}
CONNECTION_GRAPH* ConnectionGraph() const
CONNECTION_GRAPH* ConnectionGraph() const override
{
return m_connectionGraph;
}

View File

@ -46,7 +46,7 @@ struct SPICE_DC_PARAMS
class NETLIST_EXPORTER_PSPICE_SIM : public NETLIST_EXPORTER_PSPICE
{
public:
NETLIST_EXPORTER_PSPICE_SIM( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER_PSPICE_SIM( SCHEMATIC_IFACE* aSchematic ) :
NETLIST_EXPORTER_PSPICE( aSchematic )
{
}