From 498fa8d8bad6691824adaaf22208bc2f205256c0 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 2 Jul 2020 23:42:36 -0400 Subject: [PATCH] Fix some things about template fieldname synchronization --- eeschema/eeschema_config.cpp | 2 -- eeschema/files-io.cpp | 24 +++++++++++++----------- eeschema/sch_edit_frame.cpp | 7 ++++--- eeschema/schematic.cpp | 12 ++++++++++++ eeschema/schematic.h | 3 +++ 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 9dbf843abf..43adcabe06 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -261,8 +261,6 @@ bool SCH_EDIT_FRAME::LoadProjectSettings() pglayout.SetPageLayout( filename ); - Prj().GetProjectFile().m_TemplateFieldNames = &m_templateFieldNames; - return true; } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 531c11310c..2c83e0fe4b 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -276,18 +276,24 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // it knows what consequences that will have on other KIFACEs running and using // this same PROJECT. It can be very harmful if that calling code is stupid. + // NOTE: The calling code should never call this in hosted (non-standalone) mode with a + // different project than what has been loaded by the manager frame. This will crash. + + bool differentProject = pro.GetFullPath() != Prj().GetProjectFullName(); + + if( differentProject ) + { + GetSettingsManager()->SaveProject(); + GetSettingsManager()->UnloadProject( &Prj() ); + GetSettingsManager()->LoadProject( pro.GetFullPath() ); + } + if( schFileType == SCH_IO_MGR::SCH_LEGACY ) { // Don't reload the symbol libraries if we are just launching Eeschema from KiCad again. // They are already saved in the kiface project object. - if( pro.GetFullPath() != Prj().GetProjectFullName() - || !Prj().GetElem( PROJECT::ELEM_SCH_PART_LIBS ) ) + if( differentProject || !Prj().GetElem( PROJECT::ELEM_SCH_PART_LIBS ) ) { - GetSettingsManager()->SaveProject(); - GetSettingsManager()->UnloadProject( &Prj() ); - - GetSettingsManager()->LoadProject( pro.GetFullPath() ); - // load the libraries here, not in SCH_SCREEN::Draw() which is a context // that will not tolerate DisplayError() dialog since we're already in an // event handler in there. @@ -303,10 +309,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in Prj().SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL ); } - // Make sure the project file name is set (it won't be in standalone mode) - if( pro.GetFullPath() != Prj().GetProjectFullName() ) - GetSettingsManager()->LoadProject( pro.GetFullPath() ); - // Load the symbol library table, this will be used forever more. Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); Prj().SchSymbolLibTable(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index d6a68c42ff..42d263a793 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -213,8 +213,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): { m_schematic = new SCHEMATIC( nullptr ); - Prj().GetProjectFile().m_TemplateFieldNames = &m_templateFieldNames; - m_showBorderAndTitleBlock = true; // true to show sheet references m_hasAutoSave = true; m_AboutTitle = "Eeschema"; @@ -303,7 +301,8 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): SCH_EDIT_FRAME::~SCH_EDIT_FRAME() { GetSettingsManager()->SaveProject(); - Prj().GetProjectFile().m_TemplateFieldNames = nullptr; + Schematic().SetTemplateFieldNames( nullptr ); + Schematic().Reset(); // Shutdown all running tools if( m_toolManager ) @@ -424,6 +423,8 @@ void SCH_EDIT_FRAME::CreateScreens() { m_schematic->Reset(); m_schematic->SetProject( &Prj() ); + m_schematic->SetTemplateFieldNames( &m_templateFieldNames ); + m_schematic->SetRoot( new SCH_SHEET( m_schematic ) ); m_defaults = &m_schematic->Settings(); diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index cafe5ffb7a..756ca1d4fa 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -85,6 +85,18 @@ void SCHEMATIC::SetProject( PROJECT* aPrj ) } +void SCHEMATIC::SetTemplateFieldNames( TEMPLATES* aTemplates ) +{ + wxASSERT( m_project ); + PROJECT_FILE& project = m_project->GetProjectFile(); + + project.m_TemplateFieldNames = aTemplates; + + if( project.m_SchematicSettings ) + project.m_SchematicSettings->m_TemplateFieldNames = aTemplates; +} + + void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet ) { wxCHECK_RET( aRootSheet, "Call to SetRoot with null SCH_SHEET!" ); diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 2d9baab4bd..cc11b1defb 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -81,6 +81,9 @@ public: void SetProject( PROJECT* aPrj ); + /// Sets up the template fieldnames link if this project is opened in eeschema + void SetTemplateFieldNames( TEMPLATES* aTemplates ); + /** * Builds and returns an updated schematic hierarchy * TODO: can this be cached?