diff --git a/common/base_screen.cpp b/common/base_screen.cpp index ae0d7eb216..7876f83161 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -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; diff --git a/eeschema/lib_view_frame.cpp b/eeschema/lib_view_frame.cpp index de6998b3ce..5ae87c9c3a 100644 --- a/eeschema/lib_view_frame.cpp +++ b/eeschema/lib_view_frame.cpp @@ -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() ); diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index bcca630404..1b8a6266aa 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -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 ); diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index 168c2b4b25..d66a91a995 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -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 ); } } diff --git a/eeschema/plot_schematic_PDF.cpp b/eeschema/plot_schematic_PDF.cpp index b66ec5637a..7c1c1ba1ad 100644 --- a/eeschema/plot_schematic_PDF.cpp +++ b/eeschema/plot_schematic_PDF.cpp @@ -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(), diff --git a/eeschema/plot_schematic_PS.cpp b/eeschema/plot_schematic_PS.cpp index 3c0bc4b536..6f57d447bd 100644 --- a/eeschema/plot_schematic_PS.cpp +++ b/eeschema/plot_schematic_PS.cpp @@ -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() ? diff --git a/eeschema/plot_schematic_SVG.cpp b/eeschema/plot_schematic_SVG.cpp index 89a5a3772f..c5d9274fe9 100644 --- a/eeschema/plot_schematic_SVG.cpp +++ b/eeschema/plot_schematic_SVG.cpp @@ -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() ? diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 812de3dfe3..1418954555 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -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 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 ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 0404493d63..5e66406cfc 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -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 ); } diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index c8c04ab832..917445f0d9 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -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 ) { diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 72f001a1d2..e192a67e0b 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -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 { diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 95862fb0eb..b5aaea721e 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -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 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( item ) ); diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 3883da9ede..a55a0d3dc2 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -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(); diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index c29bbfe07c..20c5182000 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -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 { diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index c2145174f0..f86a4a3451 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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 ); diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 33cad2f473..5e5099e4a4 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -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 ); diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index c53cdde068..f6a752650b 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -25,8 +25,9 @@ #include -SCHEMATIC::SCHEMATIC() : +SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) : EDA_ITEM( nullptr, SCHEMATIC_T ), + m_project( aPrj ), m_rootSheet( nullptr ) { m_currentSheet = new SCH_SHEET_PATH(); diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 4b88b23f1a..fa970e1a1c 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -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( m_project ); + } + + void SetProject( PROJECT& aPrj ) + { + m_project = &aPrj; + } + /** * Builds and returns an updated schematic hierarchy * TODO: can this be cached? diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 7aec94736d..363034e45d 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -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 ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 3b989c13c1..5e6a6806cf 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -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 ); diff --git a/include/base_screen.h b/include/base_screen.h index b9e938342a..678541b27a 100644 --- a/include/base_screen.h +++ b/include/base_screen.h @@ -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 ); diff --git a/include/kiway_holder.h b/include/kiway_holder.h index d231b84bba..7755ccdc7b 100644 --- a/include/kiway_holder.h +++ b/include/kiway_holder.h @@ -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 ), diff --git a/qa/eeschema/test_sch_sheet.cpp b/qa/eeschema/test_sch_sheet.cpp index 8c5bd7bde0..b4fd43a498 100644 --- a/qa/eeschema/test_sch_sheet.cpp +++ b/qa/eeschema/test_sch_sheet.cpp @@ -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 ) { }