From bc8245ca7b599dafbfcc3ad15ba82e04fd3b248c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 2 Sep 2021 12:40:45 +0100 Subject: [PATCH] Attempt to untangle junction dot preferences. --- eeschema/dialogs/panel_setup_formatting.cpp | 3 +- eeschema/eeschema_config.cpp | 41 +++++++++++---------- eeschema/sch_base_frame.cpp | 3 +- eeschema/sch_base_frame.h | 8 ---- eeschema/sch_edit_frame.cpp | 7 +--- eeschema/sch_edit_frame.h | 2 + eeschema/schematic_settings.cpp | 7 +--- eeschema/schematic_settings.h | 9 +++-- 8 files changed, 35 insertions(+), 45 deletions(-) diff --git a/eeschema/dialogs/panel_setup_formatting.cpp b/eeschema/dialogs/panel_setup_formatting.cpp index b088f4d807..ec451148e1 100644 --- a/eeschema/dialogs/panel_setup_formatting.cpp +++ b/eeschema/dialogs/panel_setup_formatting.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -137,6 +136,8 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() if( m_choiceJunctionDotSize->GetSelection() != wxNOT_FOUND ) settings.m_JunctionSizeChoice = m_choiceJunctionDotSize->GetSelection(); + settings.m_JunctionSize = m_frame->GetSchematicJunctionSize(); + settings.m_IntersheetRefsShow = m_showIntersheetsReferences->GetValue(); settings.m_IntersheetRefsFormatShort = !m_radioFormatStandard->GetValue(); settings.m_IntersheetRefsPrefix = m_prefixCtrl->GetValue(); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 8cb8f91980..fe85873653 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -77,13 +77,16 @@ void SCH_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, bool SCH_EDIT_FRAME::LoadProjectSettings() { - GetRenderSettings()->SetDefaultPenWidth( m_defaults->m_DefaultLineWidth ); - GetRenderSettings()->m_DefaultWireThickness = m_defaults->m_DefaultWireThickness; - GetRenderSettings()->m_DefaultBusThickness = m_defaults->m_DefaultBusThickness; - GetRenderSettings()->m_LabelSizeRatio = m_defaults->m_LabelSizeRatio; - GetRenderSettings()->m_TextOffsetRatio = m_defaults->m_TextOffsetRatio; - GetRenderSettings()->m_PinSymbolSize = m_defaults->m_PinSymbolSize; - GetRenderSettings()->m_JunctionSize = m_defaults->m_JunctionSize; + SCHEMATIC_SETTINGS& settings = Schematic().Settings(); + settings.m_JunctionSize = GetSchematicJunctionSize(); + + GetRenderSettings()->SetDefaultPenWidth( settings.m_DefaultLineWidth ); + GetRenderSettings()->m_DefaultWireThickness = settings.m_DefaultWireThickness; + GetRenderSettings()->m_DefaultBusThickness = settings.m_DefaultBusThickness; + GetRenderSettings()->m_LabelSizeRatio = settings.m_LabelSizeRatio; + GetRenderSettings()->m_TextOffsetRatio = settings.m_TextOffsetRatio; + GetRenderSettings()->m_PinSymbolSize = settings.m_PinSymbolSize; + GetRenderSettings()->m_JunctionSize = settings.m_JunctionSize; // Verify some values, because the config file can be edited by hand, // and have bad values: @@ -97,9 +100,7 @@ bool SCH_EDIT_FRAME::LoadProjectSettings() Prj().GetProjectPath() ); if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) ) - { ShowInfoBarError( _( "Error loading drawing sheet." ), true ); - } return true; } @@ -116,16 +117,6 @@ void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage ) { Prj().GetProjectFile().NetSettings().ResolveNetClassAssignments( true ); - EESCHEMA_SETTINGS* cfg = static_cast( config() ); - SCHEMATIC_SETTINGS& settings = Schematic().Settings(); - - settings.m_JunctionSize = - Prj().GetProjectFile().NetSettings().m_NetClasses.GetDefaultPtr()->GetWireWidth() - * cfg->m_Drawing.junction_size_mult_list[ settings.m_JunctionSizeChoice ]; - - if( Schematic().Settings().m_JunctionSize < 1 ) - Schematic().Settings().m_JunctionSize = 1; - SaveProjectSettings(); Kiway().CommonSettingsChanged( false, true ); @@ -134,6 +125,18 @@ void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage ) } +int SCH_EDIT_FRAME::GetSchematicJunctionSize() +{ + std::vector& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list; + + NETCLASSPTR defaultNetclass = Prj().GetProjectFile().NetSettings().m_NetClasses.GetDefault(); + int sizeChoice = Schematic().Settings().m_JunctionSizeChoice; + int junctionSize = defaultNetclass->GetWireWidth() * sizeMultipliers[ sizeChoice ]; + + return std::max( junctionSize, 1 ); +} + + void SCH_EDIT_FRAME::SaveProjectSettings() { wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 2da6062e8c..a02f8dc3e4 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -82,8 +82,7 @@ SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindo const wxString& aTitle, const wxPoint& aPosition, const wxSize& aSize, long aStyle, const wxString& aFrameName ) : EDA_DRAW_FRAME( aKiway, aParent, aWindowType, aTitle, aPosition, aSize, aStyle, aFrameName ), - m_base_frame_defaults( nullptr, "base_Frame_defaults" ), - m_defaults( &m_base_frame_defaults ) + m_base_frame_defaults( nullptr, "base_Frame_defaults" ) { createCanvas(); diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 4896d1f576..5f07a52a72 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -110,11 +110,6 @@ public: KIGFX::SCH_RENDER_SETTINGS* GetRenderSettings(); - SCHEMATIC_SETTINGS& GetDefaults() - { - return *m_defaults; - } - COLOR4D GetDrawBgColor() const override; /** @@ -258,9 +253,6 @@ protected: /// These are only used by symbol_editor. Eeschema should be using the one inside /// the SCHEMATIC. SCHEMATIC_SETTINGS m_base_frame_defaults; - - SCHEMATIC_SETTINGS* m_defaults; - }; #endif // SCH_BASE_FRAME_H_ diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 7705054d1c..425747ea99 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -238,12 +238,9 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : LoadSettings( eeconfig() ); - // Also links the schematic to the loaded project + // NB: also links the schematic to the loaded project CreateScreens(); - // After schematic has been linked to project, SCHEMATIC_SETTINGS works - m_defaults = &m_schematic->Settings(); - setupTools(); setupUIConditions(); ReCreateMenuBar(); @@ -555,8 +552,6 @@ void SCH_EDIT_FRAME::CreateScreens() m_schematic->SetRoot( new SCH_SHEET( m_schematic ) ); - m_defaults = &m_schematic->Settings(); - SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic ); m_schematic->Root().SetScreen( rootScreen ); SetScreen( Schematic().RootScreen() ); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index ccd75e361e..214021b5a3 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -801,6 +801,8 @@ public: void FixupJunctions(); + int GetSchematicJunctionSize(); + void FocusOnItem( SCH_ITEM* aItem ); /** diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index e5ec755eff..9a123b9e3e 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -45,8 +44,8 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ), m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ), m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ), - m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ), m_JunctionSizeChoice( 3 ), + m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ), m_AnnotateStartNum( 0 ), m_IntersheetRefsShow( false ), m_IntersheetRefsListOwnPage( true ), @@ -124,9 +123,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin &m_PinSymbolSize, Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) ); - m_params.emplace_back( new PARAM_SCALED( "drawing.default_junction_size", - &m_JunctionSize, Mils2iu( defaultJunctionSize ), Mils2iu( 5 ), Mils2iu( 1000 ), - 1 / IU_PER_MILS ) ); + // m_JunctionSize is only a run-time cache of the calculated size. Do not save it. // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc ) m_params.emplace_back( new PARAM( "drawing.junction_size_choice", diff --git a/eeschema/schematic_settings.h b/eeschema/schematic_settings.h index 62b84a888d..78ad88682c 100644 --- a/eeschema/schematic_settings.h +++ b/eeschema/schematic_settings.h @@ -51,10 +51,11 @@ public: double m_LabelSizeRatio; double m_TextOffsetRatio; int m_PinSymbolSize; - int m_JunctionSize; // Size of junction dot in mils - // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc ) - int m_JunctionSizeChoice; - int m_AnnotateStartNum; // Starting value for annotation + + int m_JunctionSizeChoice; // none = 0, smallest = 1, small = 2, etc. + int m_JunctionSize; // a runtime cache of the calculated size + + int m_AnnotateStartNum; // Starting value for annotation bool m_IntersheetRefsShow; bool m_IntersheetRefsListOwnPage;