From 40b2eabfc16cce68374d7ceee56ea7630616a33f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 17 Mar 2020 12:49:49 +0000 Subject: [PATCH] Add a user-defined ratio for text offset from wire/bus. Fixes https://gitlab.com/kicad/code/kicad/issues/2392 --- eeschema/dialogs/panel_setup_formatting.cpp | 7 + .../dialogs/panel_setup_formatting_base.cpp | 15 +- .../dialogs/panel_setup_formatting_base.fbp | 188 +++++++++++++++++- .../dialogs/panel_setup_formatting_base.h | 3 + eeschema/eeschema_config.cpp | 17 ++ eeschema/general.h | 7 + eeschema/sch_text.cpp | 25 +-- 7 files changed, 246 insertions(+), 16 deletions(-) diff --git a/eeschema/dialogs/panel_setup_formatting.cpp b/eeschema/dialogs/panel_setup_formatting.cpp index e36ae58621..1eac5abff6 100644 --- a/eeschema/dialogs/panel_setup_formatting.cpp +++ b/eeschema/dialogs/panel_setup_formatting.cpp @@ -68,6 +68,8 @@ bool PANEL_SETUP_FORMATTING::TransferDataToWindow() m_wireWidth.SetValue( GetDefaultWireThickness() ); m_junctionSize.SetValue( SCH_JUNCTION::g_SymbolSize ); + m_textOffsetRatioCtrl->SetValue( wxString::Format( "%f", GetTextOffsetRatio() * 100.0 ) ); + int superSubFlags = ENABLE_SUBSCRIPT_MARKUP | ENABLE_SUPERSCRIPT_MARKUP; m_checkSuperSub->SetValue( GetTextMarkupFlags() & superSubFlags ); @@ -104,6 +106,11 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() SetDefaultWireThickness( m_wireWidth.GetValue() ); SCH_JUNCTION::g_SymbolSize = m_junctionSize.GetValue(); + double dtmp = 0.0; + wxString msg = m_textOffsetRatioCtrl->GetValue(); + msg.ToDouble( &dtmp ); + SetTextOffsetRatio( dtmp / 100.0 ); + int superSubFlags = ENABLE_SUBSCRIPT_MARKUP | ENABLE_SUPERSCRIPT_MARKUP; if( m_checkSuperSub->GetValue() ) diff --git a/eeschema/dialogs/panel_setup_formatting_base.cpp b/eeschema/dialogs/panel_setup_formatting_base.cpp index 6163034c5c..b127b7b324 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.cpp +++ b/eeschema/dialogs/panel_setup_formatting_base.cpp @@ -59,6 +59,19 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi m_textSizeUnits->Wrap( -1 ); fgSizer2->Add( m_textSizeUnits, 0, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); + m_textOffsetRatioLabel = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Text offset ratio:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_textOffsetRatioLabel->Wrap( -1 ); + m_textOffsetRatioLabel->SetToolTip( _("Percentage of the text size to offset text above or below wire or bus") ); + + fgSizer2->Add( m_textOffsetRatioLabel, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + + m_textOffsetRatioCtrl = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer2->Add( m_textOffsetRatioCtrl, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); + + m_offsetRatioUnits = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("%"), wxDefaultPosition, wxDefaultSize, 0 ); + m_offsetRatioUnits->Wrap( -1 ); + fgSizer2->Add( m_offsetRatioUnits, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); + sbSizer4->Add( fgSizer2, 1, wxEXPAND|wxBOTTOM, 5 ); @@ -78,7 +91,7 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Connections") ), wxVERTICAL ); wxFlexGridSizer* fgSizer32; - fgSizer32 = new wxFlexGridSizer( 0, 3, 3, 0 ); + fgSizer32 = new wxFlexGridSizer( 0, 3, 5, 0 ); fgSizer32->AddGrowableCol( 1 ); fgSizer32->SetFlexibleDirection( wxBOTH ); fgSizer32->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); diff --git a/eeschema/dialogs/panel_setup_formatting_base.fbp b/eeschema/dialogs/panel_setup_formatting_base.fbp index 9ddc0818de..14b55001e7 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.fbp +++ b/eeschema/dialogs/panel_setup_formatting_base.fbp @@ -427,6 +427,192 @@ -1 + + 5 + wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Text offset ratio: + 0 + + 0 + + + 0 + + 1 + m_textOffsetRatioLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Percentage of the text size to offset text above or below wire or bus + + + + -1 + + + + 5 + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_textOffsetRatioCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + % + 0 + + 0 + + + 0 + + 1 + m_offsetRatioUnits + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + @@ -583,7 +769,7 @@ wxFLEX_GROWMODE_SPECIFIED none 0 - 3 + 5 5 wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT diff --git a/eeschema/dialogs/panel_setup_formatting_base.h b/eeschema/dialogs/panel_setup_formatting_base.h index 01c6f6b9b5..0c0e38f800 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.h +++ b/eeschema/dialogs/panel_setup_formatting_base.h @@ -38,6 +38,9 @@ class PANEL_SETUP_FORMATTING_BASE : public wxPanel wxStaticText* m_textSizeLabel; wxTextCtrl* m_textSizeCtrl; wxStaticText* m_textSizeUnits; + wxStaticText* m_textOffsetRatioLabel; + wxTextCtrl* m_textOffsetRatioCtrl; + wxStaticText* m_offsetRatioUnits; wxCheckBox* m_checkSuperSub; wxStaticText* m_superSubHint; wxStaticText* m_busWidthLabel; diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index a41ff7915f..c32a00314b 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -58,6 +58,7 @@ static int s_defaultBusThickness = Mils2iu( DEFAULTBUSTHICKNESS ); static int s_defaultWireThickness = Mils2iu( DEFAULTDRAWLINETHICKNESS ); static int s_defaultTextSize = Mils2iu( DEFAULT_SIZE_TEXT ); static int s_drawDefaultLineThickness = -1; +static double s_textOffsetRatio = 0.08; static bool s_selectTextAsBox = false; static bool s_selectDrawChildren = true; static bool s_selectFillShapes = false; @@ -274,6 +275,18 @@ void SetDefaultLineThickness( int aThickness ) } +double GetTextOffsetRatio() +{ + return s_textOffsetRatio; +} + + +void SetTextOffsetRatio( double aOffsetRatio ) +{ + s_textOffsetRatio = aOffsetRatio; +} + + bool GetSelectionTextAsBox() { return s_selectTextAsBox; @@ -365,6 +378,10 @@ void SCH_EDIT_FRAME::AddFormattingParameters( std::vector& params ) &s_defaultTextSize, Mils2iu( DEFAULT_SIZE_TEXT ), 5, 1000, nullptr, 1 / IU_PER_MILS ) ); + params.push_back( new PARAM_CFG_DOUBLE( wxT( "TextOffsetRatio" ), + &s_textOffsetRatio, + (double) TXT_MARGIN / DEFAULT_SIZE_TEXT, + -200.0, 200.0 ) ); params.push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "LineThickness" ), &s_drawDefaultLineThickness, Mils2iu( appSettings->m_Drawing.default_line_thickness ), diff --git a/eeschema/general.h b/eeschema/general.h index 6373f146e9..cceb4ee9d9 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -48,6 +48,7 @@ class ERC_SETTINGS; #define DEFAULT_REPEAT_LABEL_INC 1 ///< the default value (overwritten by the eeschema config) #define DEFAULT_REPEAT_OFFSET_PIN 100 ///< the default value (overwritten by the eeschema config) ///< when repeating a pin +#define TXT_MARGIN 4 ///< The thickness to draw busses that do not have a specific width ///< (can be changed in preference menu) @@ -113,6 +114,12 @@ void SetDefaultLineThickness( int aThickness ); int GetDefaultTextSize(); void SetDefaultTextSize( int aSize ); +/** + * Amount to offset text above/below wires & busses. Expressed as a ratio of the text size. + */ +double GetTextOffsetRatio(); +void SetTextOffsetRatio( double aOffsetRatio ); + /** * Default line thickness used to draw/plot busses. */ diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index d99e3c0c4e..aad0bbc613 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -51,12 +51,6 @@ extern void IncrementLabelMember( wxString& name, int aIncrement ); -// Only for tests: set DRAW_BBOX to 1 to draw the bounding box of labels -#define DRAW_BBOX 0 - -// Margin in internal units (mils) between labels and wires -#define TXT_MARGIN 4 - /* Coding polygons for global symbol graphic shapes. * the first parml is the number of corners * others are the corners coordinates in reduced units @@ -140,7 +134,8 @@ wxPoint SCH_TEXT::GetSchematicTextOffset() const wxPoint text_offset; // add an offset to x (or y) position to aid readability of text on a wire or line - int thick_offset = Mils2iu( TXT_MARGIN ) + ( GetPenSize() + GetDefaultLineThickness() ) / 2; + int thick_offset = KiROUND( GetTextOffsetRatio() * GetTextSize().y ); + thick_offset += ( GetPenSize() + GetDefaultLineThickness() ) / 2; switch( GetLabelSpinStyle() ) { @@ -771,7 +766,8 @@ wxPoint SCH_GLOBALLABEL::GetSchematicTextOffset() const case PINSHEETLABEL_SHAPE::PS_OUTPUT: case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: - offset += TXT_MARGIN; + offset += KiROUND( GetTextOffsetRatio() * GetTextSize().y ); + ; break; default: @@ -1184,23 +1180,24 @@ const EDA_RECT SCH_HIERLABEL::GetBoundingBox() const wxPoint SCH_HIERLABEL::GetSchematicTextOffset() const { wxPoint text_offset; - int width = std::max( GetThickness(), GetDefaultLineThickness() ); - int ii = GetTextWidth() + TXT_MARGIN + width; + int thickness = std::max( GetThickness(), GetDefaultLineThickness() ); + int offset = KiROUND( GetTextOffsetRatio() * GetTextSize().y ); + int total_offset = GetTextWidth() + offset + thickness; switch( GetLabelSpinStyle() ) { default: case LABEL_SPIN_STYLE::LEFT: - text_offset.x = -ii; + text_offset.x = -total_offset; break; // Orientation horiz normale case LABEL_SPIN_STYLE::UP: - text_offset.y = -ii; + text_offset.y = -total_offset; break; // Orientation vert UP case LABEL_SPIN_STYLE::RIGHT: - text_offset.x = ii; + text_offset.x = total_offset; break; // Orientation horiz inverse case LABEL_SPIN_STYLE::BOTTOM: - text_offset.y = ii; + text_offset.y = total_offset; break; // Orientation vert BOTTOM }