Move SCH_SCREEN project access to SCHEMATIC

SCH_SCREEN no longer needs to be a KIWAY_HOLDER
This commit is contained in:
Jon Evans 2020-05-20 22:27:48 -04:00
parent b36b7d5a5d
commit 7c7b7f41da
23 changed files with 62 additions and 43 deletions

View File

@ -44,8 +44,8 @@
wxString BASE_SCREEN::m_PageLayoutDescrFileName; // the name of the page layout descr file.
BASE_SCREEN::BASE_SCREEN( KICAD_T aType ) :
EDA_ITEM( aType )
BASE_SCREEN::BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType ) :
EDA_ITEM( aParent, aType )
{
m_UndoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
m_Initialized = false;

View File

@ -130,7 +130,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
// Initialize grid id to the default value (50 mils):
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
SetScreen( new SCH_SCREEN( aKiway ) );
SetScreen( new SCH_SCREEN );
GetScreen()->m_Center = true; // Axis origin centered on screen.
LoadSettings( config() );

View File

@ -124,7 +124,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
gal_opts.m_axesEnabled = true;
m_dummyScreen = new SCH_SCREEN( aKiway );
m_dummyScreen = new SCH_SCREEN();
SetScreen( m_dummyScreen );
GetScreen()->m_Center = true;
GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );

View File

@ -344,7 +344,7 @@ LIB_PART* LIB_MANAGER::GetBufferedPart( const wxString& aAlias, const wxString&
if( !bufferedParent )
{
bufferedParent = new LIB_PART( *parent.get() );
libBuf.CreateBuffer( bufferedParent, new SCH_SCREEN( &m_frame.Kiway() ) );
libBuf.CreateBuffer( bufferedParent, new SCH_SCREEN );
}
}
@ -353,7 +353,7 @@ LIB_PART* LIB_MANAGER::GetBufferedPart( const wxString& aAlias, const wxString&
if( bufferedParent )
bufferedPart->SetParent( bufferedParent );
libBuf.CreateBuffer( bufferedPart, new SCH_SCREEN( &m_frame.Kiway() ) );
libBuf.CreateBuffer( bufferedPart, new SCH_SCREEN );
}
catch( const IO_ERROR& e )
{
@ -402,7 +402,7 @@ bool LIB_MANAGER::UpdatePart( LIB_PART* aPart, const wxString& aLibrary )
partCopy->SetLibId( LIB_ID( aLibrary, aPart->GetLibId().GetLibItemName() ) );
SCH_SCREEN* screen = new SCH_SCREEN( &m_frame.Kiway() );
SCH_SCREEN* screen = new SCH_SCREEN;
libBuf.CreateBuffer( partCopy, screen );
screen->SetModify();
}
@ -724,16 +724,16 @@ LIB_MANAGER::LIB_BUFFER& LIB_MANAGER::getLibraryBuffer( const wxString& aLibrary
if( !libParent )
{
libParent = new LIB_PART( *oldParent.get() );
buf.CreateBuffer( libParent, new SCH_SCREEN( &m_frame.Kiway() ) );
buf.CreateBuffer( libParent, new SCH_SCREEN );
}
newSymbol = new LIB_PART( *part );
newSymbol->SetParent( libParent );
buf.CreateBuffer( newSymbol, new SCH_SCREEN( &m_frame.Kiway() ) );
buf.CreateBuffer( newSymbol, new SCH_SCREEN );
}
else if( !buf.GetPart( part->GetName() ) )
{
buf.CreateBuffer( new LIB_PART( *part ), new SCH_SCREEN( &m_frame.Kiway() ) );
buf.CreateBuffer( new LIB_PART( *part ), new SCH_SCREEN );
}
}

View File

@ -159,7 +159,7 @@ void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter,
if( aPlotFrameRef )
{
PlotWorkSheet( aPlotter, &aScreen->Prj(), m_parent->GetTitleBlock(),
PlotWorkSheet( aPlotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(),
m_parent->GetPageSettings(), aScreen->m_ScreenNumber,
aScreen->m_NumberOfScreens, m_parent->GetScreenDesc(),
aScreen->GetFileName(),

View File

@ -165,7 +165,7 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
if( aPlotFrameRef )
{
PlotWorkSheet( plotter, &aScreen->Prj(), m_parent->GetTitleBlock(), aPageInfo,
PlotWorkSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), aPageInfo,
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(), aScreen->GetFileName(),
plotter->GetColorMode() ?

View File

@ -139,7 +139,7 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( const wxString& aFileName,
if( aPlotFrameRef )
{
PlotWorkSheet( plotter, &aScreen->Prj(), m_parent->GetTitleBlock(), pageInfo,
PlotWorkSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), pageInfo,
aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
m_parent->GetScreenDesc(), aScreen->GetFileName(),
plotter->GetColorMode() ?

View File

@ -425,9 +425,8 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCH
if( !m_rootSheet->GetScreen() )
{
SCH_SCREEN* screen = new SCH_SCREEN( aKiway );
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
screen->SetFileName( aFileName );
screen->SetParent( m_schematic );
m_rootSheet->SetScreen( screen );
}
@ -600,11 +599,10 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
{
wxPoint pos = wxPoint( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) );
std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( m_rootSheet, pos ) );
SCH_SCREEN* screen = new SCH_SCREEN( m_kiway );
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
sheet->SetScreen( screen );
sheet->GetScreen()->SetFileName( sheet->GetFileName() );
sheet->GetScreen()->SetParent( m_schematic );
m_currentSheet = sheet.get();
loadSheet( sheetNode, i );

View File

@ -208,7 +208,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ):
wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, SCH_EDIT_FRAME_NAME ),
m_item_to_repeat( nullptr )
{
m_schematic = new SCHEMATIC();
m_schematic = new SCHEMATIC( &Prj() );
m_defaults = &m_schematic->Settings();
@ -419,8 +419,7 @@ void SCH_EDIT_FRAME::CreateScreens()
m_schematic->Reset();
m_schematic->SetRoot( new SCH_SHEET( m_schematic ) );
SCH_SCREEN* rootScreen = new SCH_SCREEN( &Kiway() );
rootScreen->SetParent( m_schematic );
SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic );
rootScreen->SetMaxUndoItems( m_UndoRedoCountMax );
m_schematic->Root().SetScreen( rootScreen );
SetScreen( Schematic().RootScreen() );
@ -431,7 +430,7 @@ void SCH_EDIT_FRAME::CreateScreens()
if( GetScreen() == NULL )
{
SCH_SCREEN* screen = new SCH_SCREEN( &Kiway() );
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
screen->SetMaxUndoItems( m_UndoRedoCountMax );
SetScreen( screen );
}

View File

@ -122,7 +122,7 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
if( processTextVars )
{
if( Schematic() )
project = &Schematic()->RootScreen()->Kiway().Prj();
project = &Schematic()->Prj();
if( aDepth < 10 )
{

View File

@ -692,9 +692,8 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
}
else
{
aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
aSheet->GetScreen()->SetParent( m_schematic );
try
{

View File

@ -120,9 +120,8 @@ static GRID_TYPE SchematicGridList[] = {
};
SCH_SCREEN::SCH_SCREEN( KIWAY* aKiway ) :
BASE_SCREEN( SCH_SCREEN_T ),
KIWAY_HOLDER( aKiway, KIWAY_HOLDER::HOLDER_TYPE::SCREEN ),
SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
BASE_SCREEN( aParent, SCH_SCREEN_T ),
m_paper( wxT( "A4" ) )
{
m_modification_sync = 0;
@ -592,13 +591,15 @@ bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
{
wxCHECK_RET( Schematic(), "Cannot call SCH_SCREEN::UpdateSymbolLinks with no SCHEMATIC" );
wxString msg;
std::unique_ptr< LIB_PART > libSymbol;
std::vector<SCH_COMPONENT*> symbols;
SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
SYMBOL_LIB_TABLE* libs = Schematic()->Prj().SchSymbolLibTable();
// This will be a nullptr if an s-expression schematic is loaded.
PART_LIBS* legacyLibs = Prj().SchLibs();
PART_LIBS* legacyLibs = Schematic()->Prj().SchLibs();
for( auto item : Items().OfType( SCH_COMPONENT_T ) )
symbols.push_back( static_cast<SCH_COMPONENT*>( item ) );

View File

@ -90,7 +90,7 @@ struct COMPONENT_SELECTION
}
};
class SCH_SCREEN : public BASE_SCREEN, public KIWAY_HOLDER
class SCH_SCREEN : public BASE_SCREEN
{
private:
@ -153,7 +153,7 @@ public:
/**
* Constructor
*/
SCH_SCREEN( KIWAY* aKiway );
SCH_SCREEN( EDA_ITEM* aParent = nullptr );
~SCH_SCREEN();

View File

@ -523,9 +523,8 @@ void SCH_SEXPR_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
}
else
{
aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
aSheet->GetScreen()->SetParent( m_schematic );
try
{

View File

@ -520,8 +520,8 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
PROJECT* project = nullptr;
if( Schematic()->RootScreen() )
project = &Schematic()->RootScreen()->Kiway().Prj();
if( Schematic() )
project = &Schematic()->Prj();
if( aDepth < 10 )
text = ExpandTextVars( text, &textResolver, project );

View File

@ -36,6 +36,7 @@
#include <sch_sheet.h>
#include <sch_screen.h>
#include <sch_component.h>
#include <schematic.h>
#include <lib_pin.h>
#include <preview_items/selection_area.h>
#include <sch_edit_frame.h>
@ -97,7 +98,7 @@ void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen )
m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( static_cast< int >( IU_PER_MILS ),
&aScreen->GetPageSettings(),
&aScreen->Prj(),
&aScreen->Schematic()->Prj(),
&aScreen->GetTitleBlock() ) );
m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber );
m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens );

View File

@ -25,8 +25,9 @@
#include <sch_marker.h>
SCHEMATIC::SCHEMATIC() :
SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) :
EDA_ITEM( nullptr, SCHEMATIC_T ),
m_project( aPrj ),
m_rootSheet( nullptr )
{
m_currentSheet = new SCH_SHEET_PATH();

View File

@ -29,6 +29,7 @@ class BUS_ALIAS;
class CONNECTION_GRAPH;
class EDA_BASE_FRAME;
class ERC_SETTINGS;
class PROJECT;
class SCH_SCREEN;
class SCH_SHEET;
@ -43,6 +44,7 @@ class SCHEMATIC : public EDA_ITEM
friend class SCH_EDIT_FRAME;
private:
PROJECT* m_project;
/// The top-level sheet in this schematic hierarchy (or potentially the only one)
SCH_SHEET* m_rootSheet;
@ -66,7 +68,7 @@ private:
ERC_SETTINGS* m_ercSettings;
public:
SCHEMATIC();
SCHEMATIC( PROJECT* aPrj );
~SCHEMATIC();
@ -78,6 +80,17 @@ public:
/// Initializes this schematic to a blank one, unloading anything existing
void Reset();
/// Return a reference to the project this schematic is part of
PROJECT& Prj() const
{
return *const_cast<PROJECT*>( m_project );
}
void SetProject( PROJECT& aPrj )
{
m_project = &aPrj;
}
/**
* Builds and returns an updated schematic hierarchy
* TODO: can this be cached?

View File

@ -94,7 +94,7 @@ bool SCH_EDIT_FRAME::checkForNoFullyDefinedLibIds( SCH_SHEET* aSheet )
void SCH_EDIT_FRAME::InitSheet( SCH_SHEET* aSheet, const wxString& aNewFilename )
{
aSheet->SetScreen( new SCH_SCREEN( &Kiway() ) );
aSheet->SetScreen( new SCH_SCREEN( &Schematic() ) );
aSheet->GetScreen()->SetModify();
aSheet->GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
aSheet->GetScreen()->SetFileName( aNewFilename );

View File

@ -1185,7 +1185,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
SCH_SEXPR_PLUGIN plugin;
SCH_SHEET paste_sheet;
SCH_SCREEN* paste_screen = new SCH_SCREEN( &m_frame->GetScreen()->Kiway() );
SCH_SCREEN* paste_screen = new SCH_SCREEN( &m_frame->Schematic() );
// Screen object on heap is owned by the sheet.
paste_sheet.SetScreen( paste_screen );

View File

@ -139,7 +139,12 @@ public:
bool m_IsPrinting;
public:
BASE_SCREEN( KICAD_T aType = SCREEN_T );
BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType = SCREEN_T );
BASE_SCREEN( KICAD_T aType = SCREEN_T ) :
BASE_SCREEN( nullptr, aType )
{}
~BASE_SCREEN() override { }
void InitDataPoints( const wxSize& aPageSizeInternalUnits );

View File

@ -39,7 +39,7 @@ class PROJECT;
class KIWAY_HOLDER
{
public:
enum HOLDER_TYPE { DIALOG, FRAME, PANEL, SCREEN };
enum HOLDER_TYPE { DIALOG, FRAME, PANEL };
KIWAY_HOLDER( KIWAY* aKiway, HOLDER_TYPE aType ) :
m_kiway( aKiway ),

View File

@ -39,7 +39,10 @@
class TEST_SCH_SHEET_FIXTURE
{
public:
TEST_SCH_SHEET_FIXTURE() : m_sheet(), m_csheet( m_sheet )
TEST_SCH_SHEET_FIXTURE() :
m_schematic( nullptr ),
m_sheet(),
m_csheet( m_sheet )
{
}