From ff717fec3f167795fed0504394d67a5ee6683a2a Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Wed, 31 Aug 2022 10:35:27 +0100 Subject: [PATCH] Wait to save non-KiCad imported drawing sheet until user requests a save --- eeschema/eeschema_config.cpp | 19 +++++++++++++++++++ eeschema/files-io.cpp | 9 --------- eeschema/schematic_settings.cpp | 12 ++++++------ eeschema/schematic_settings.h | 1 + 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index bdbb2b7ca1..35a1a3d63d 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -64,6 +65,8 @@ bool SCH_EDIT_FRAME::LoadProjectSettings() LIB_SYMBOL::SetSubpartIdNotation( LIB_SYMBOL::GetSubpartIdSeparator(), LIB_SYMBOL::GetSubpartFirstId() ); + BASE_SCREEN::m_DrawingSheetFileName = settings.m_SchDrawingSheetFileName; + // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName. // If empty, or not existing, the default drawing sheet is loaded. wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName, @@ -127,6 +130,22 @@ void SCH_EDIT_FRAME::SaveProjectSettings() RecordERCExclusions(); + // TODO: We need to remove dependence on BASE_SCREEN + Prj().GetProjectFile().m_SchematicSettings->m_SchDrawingSheetFileName = BASE_SCREEN::m_DrawingSheetFileName; + + if( !BASE_SCREEN::m_DrawingSheetFileName.IsEmpty() ) + { + // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic) + + wxFileName layoutfn( BASE_SCREEN::m_DrawingSheetFileName ); + + if( !layoutfn.IsAbsolute() ) + layoutfn = wxFileName( Prj().GetProjectPath(), BASE_SCREEN::m_DrawingSheetFileName ); + + if( !layoutfn.FileExists() ) + DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetAbsolutePath() ); + } + GetSettingsManager()->SaveProject( fn.GetFullPath() ); } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index c53c99afd8..72abc0a92f 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1237,16 +1237,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) // to KiCad), so set it to an empty one DS_DATA_MODEL& drawingSheet = DS_DATA_MODEL::GetTheInstance(); drawingSheet.SetEmptyLayout(); - BASE_SCREEN::m_DrawingSheetFileName = "empty.kicad_wks"; - wxFileName layoutfn( Prj().GetProjectPath(), BASE_SCREEN::m_DrawingSheetFileName ); - wxFFile layoutfile; - - if( layoutfile.Open( layoutfn.GetFullPath(), "wb" ) ) - { - layoutfile.Write( DS_DATA_MODEL::EmptyLayout() ); - layoutfile.Close(); - } newfilename.SetPath( Prj().GetProjectPath() ); newfilename.SetName( Prj().GetProjectName() ); diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index 2176d7012a..700a3918a6 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -23,11 +23,12 @@ #include #include #include -#include #include +#include #include #include #include +#include #include @@ -58,7 +59,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_SpiceModelCurSheetAsRoot( true ), m_NgspiceSimulatorSettings( nullptr ) { - EESCHEMA_SETTINGS* appSettings = dynamic_cast( Kiface().KifaceSettings() ); + EESCHEMA_SETTINGS* appSettings = Pgm().GetSettingsManager().GetAppSettings(); int defaultLineThickness = appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_WIDTH_MILS; @@ -163,7 +164,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin } } - auto* cfg = dynamic_cast( Kiface().KifaceSettings() ); + auto* cfg = Pgm().GetSettingsManager().GetAppSettings(); if( cfg ) { @@ -172,7 +173,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin if( !templateFieldNames.IsEmpty() ) { - TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) ); + TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) ); try { @@ -185,9 +186,8 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin } }, {} ) ); - // TODO(JE) get rid of this static m_params.emplace_back( new PARAM( "page_layout_descr_file", - &BASE_SCREEN::m_DrawingSheetFileName, "" ) ); + &m_SchDrawingSheetFileName, "" ) ); m_params.emplace_back( new PARAM( "plot_directory", &m_PlotDirectoryName, "" ) ); diff --git a/eeschema/schematic_settings.h b/eeschema/schematic_settings.h index 93f49cd416..1c3882cff4 100644 --- a/eeschema/schematic_settings.h +++ b/eeschema/schematic_settings.h @@ -63,6 +63,7 @@ public: double m_DashedLineDashRatio; // Dash length as ratio of the lineWidth double m_DashedLineGapRatio; // Gap length as ratio of the lineWidth + wxString m_SchDrawingSheetFileName; wxString m_PlotDirectoryName; wxString m_NetFormatName;