From 5371312c6f945e99bd464769626d83c7111f18ed Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 20 Apr 2025 19:58:53 +0100 Subject: [PATCH] Make auto text thickness active. --- common/eda_text.cpp | 16 ++- eeschema/sch_textbox.cpp | 4 +- include/eda_text.h | 11 ++ .../dialogs/dialog_tablecell_properties.cpp | 103 ++++++++++++++---- pcbnew/dialogs/dialog_tablecell_properties.h | 3 +- .../dialog_tablecell_properties_base.cpp | 14 ++- .../dialog_tablecell_properties_base.fbp | 6 +- .../dialog_tablecell_properties_base.h | 5 +- pcbnew/dialogs/dialog_text_properties.cpp | 85 +++++++++++---- pcbnew/dialogs/dialog_text_properties.h | 3 +- .../dialogs/dialog_text_properties_base.cpp | 14 ++- .../dialogs/dialog_text_properties_base.fbp | 6 +- pcbnew/dialogs/dialog_text_properties_base.h | 5 +- pcbnew/dialogs/dialog_textbox_properties.cpp | 81 ++++++++++---- pcbnew/dialogs/dialog_textbox_properties.h | 3 +- .../dialog_textbox_properties_base.cpp | 14 ++- .../dialog_textbox_properties_base.fbp | 6 +- .../dialogs/dialog_textbox_properties_base.h | 5 +- .../kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp | 38 ++----- pcbnew/pcb_tablecell.cpp | 7 +- pcbnew/pcb_text.cpp | 19 ++-- pcbnew/pcb_textbox.cpp | 7 +- 22 files changed, 313 insertions(+), 142 deletions(-) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 0ac89cc0ad..bea90d4f2e 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -289,6 +289,13 @@ void EDA_TEXT::SetTextThickness( int aWidth ) } +void EDA_TEXT::SetAutoThickness( bool aAuto ) +{ + if( GetAutoThickness() != aAuto ) + SetTextThickness( aAuto ? 0 : GetEffectiveTextPenWidth() ); +} + + void EDA_TEXT::SetTextAngle( const EDA_ANGLE& aAngle ) { m_attributes.m_Angle = aAngle; @@ -1041,7 +1048,7 @@ bool EDA_TEXT::IsDefaultFormatting() const return ( !IsMirrored() && GetHorizJustify() == GR_TEXT_H_ALIGN_CENTER && GetVertJustify() == GR_TEXT_V_ALIGN_CENTER - && GetTextThickness() == 0 + && GetAutoThickness() && !IsItalic() && !IsBold() && !IsMultilineAllowed() @@ -1070,7 +1077,7 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aControlBits ) const FormatDouble2Str( GetLineSpacing() ).c_str() ); } - if( GetTextThickness() ) + if( !GetAutoThickness() ) { aFormatter->Print( "(thickness %s)", EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextThickness() ).c_str() ); @@ -1357,8 +1364,11 @@ static struct EDA_TEXT_DESC textProps ) .SetIsHiddenFromRulesEditor(); + propMgr.AddProperty( new PROPERTY( _HKI( "Auto Thickness" ), + &EDA_TEXT::SetAutoThickness, &EDA_TEXT::GetAutoThickness ), + textProps ); propMgr.AddProperty( new PROPERTY( _HKI( "Thickness" ), - &EDA_TEXT::SetTextThickness, &EDA_TEXT::GetTextThickness, + &EDA_TEXT::SetTextThickness, &EDA_TEXT::GetTextThicknessProperty, PROPERTY_DISPLAY::PT_SIZE ), textProps ); propMgr.AddProperty( new PROPERTY( _HKI( "Italic" ), diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 4c3d90eee7..c6926ce99f 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -305,8 +305,8 @@ wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtr else colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() ); - getDrawFont()->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), - IsItalic() ); + getDrawFont()->LinebreakText( text, colWidth, GetTextSize(), GetEffectiveTextPenWidth(), + IsBold(), IsItalic() ); return text; } diff --git a/include/eda_text.h b/include/eda_text.h index acffab98b5..b135655325 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -125,6 +125,17 @@ public: void SetTextThickness( int aWidth ); int GetTextThickness() const { return m_attributes.m_StrokeWidth; }; + int GetTextThicknessProperty() const + { + if( GetAutoThickness() ) + return GetEffectiveTextPenWidth(); + else + return GetTextThickness(); + } + + void SetAutoThickness( bool aAuto ); + bool GetAutoThickness() const { return GetTextThickness() == 0; }; + /** * The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth. */ diff --git a/pcbnew/dialogs/dialog_tablecell_properties.cpp b/pcbnew/dialogs/dialog_tablecell_properties.cpp index ff0e8c1cc3..fe289edb2e 100644 --- a/pcbnew/dialogs/dialog_tablecell_properties.cpp +++ b/pcbnew/dialogs/dialog_tablecell_properties.cpp @@ -115,8 +115,8 @@ DIALOG_TABLECELL_PROPERTIES::DIALOG_TABLECELL_PROPERTIES( PCB_BASE_EDIT_FRAME* a m_italic->SetIsCheckButton(); m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) ); - m_adjustTextThickness->SetIsRadioButton(); - m_adjustTextThickness->SetBitmap( KiBitmapBundle( BITMAPS::edit_cmp_symb_links ) ); + m_autoTextThickness->SetIsCheckButton(); + m_autoTextThickness->SetBitmap( KiBitmapBundle( BITMAPS::edit_cmp_symb_links ) ); SetupStandardButtons(); Layout(); @@ -152,16 +152,20 @@ bool DIALOG_TABLECELL_PROPERTIES::TransferDataToWindow() bool firstCell = true; GR_TEXT_H_ALIGN_T hAlign = GR_TEXT_H_ALIGN_INDETERMINATE; GR_TEXT_V_ALIGN_T vAlign = GR_TEXT_V_ALIGN_INDETERMINATE; + int textThickness = 0; + int effectivePenWidth = 0; for( PCB_TABLECELL* cell : m_cells ) { - m_cellTextCtrl->SetValue( cell->GetText() ); if( firstCell ) { + m_cellTextCtrl->SetValue( cell->GetText() ); + m_fontCtrl->SetFontSelection( cell->GetFont() ); m_textWidth.SetValue( cell->GetTextWidth() ); m_textHeight.SetValue( cell->GetTextHeight() ); - m_textThickness.SetValue( cell->GetTextThickness() ); + textThickness = cell->GetTextThickness(); + effectivePenWidth = cell->GetEffectiveTextPenWidth(); hAlign = cell->GetHorizJustify(); vAlign = cell->GetVertJustify(); @@ -181,6 +185,9 @@ bool DIALOG_TABLECELL_PROPERTIES::TransferDataToWindow() } else { + if( cell->GetText() != m_cellTextCtrl->GetValue() ) + m_cellTextCtrl->SetValue( INDETERMINATE_STATE ); + if( cell->GetFont() != m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) ) m_fontCtrl->SetSelection( -1 ); @@ -190,8 +197,11 @@ bool DIALOG_TABLECELL_PROPERTIES::TransferDataToWindow() if( cell->GetTextHeight() != m_textHeight.GetValue() ) m_textHeight.SetValue( INDETERMINATE_STATE ); - if( cell->GetTextThickness() != m_textThickness.GetValue() ) - m_textThickness.SetValue( INDETERMINATE_STATE ); + if( cell->GetTextThickness() != textThickness ) + textThickness = -1; + + if( cell->GetEffectiveTextPenWidth() != effectivePenWidth ) + effectivePenWidth = -1; if( cell->GetHorizJustify() != hAlign ) hAlign = GR_TEXT_H_ALIGN_INDETERMINATE; @@ -229,6 +239,22 @@ bool DIALOG_TABLECELL_PROPERTIES::TransferDataToWindow() } } + m_textThickness.SetValue( INDETERMINATE_STATE ); + m_autoTextThickness->Check( false ); + + if( textThickness == 0 ) + { + if( effectivePenWidth > 0 ) + m_textThickness.SetValue( effectivePenWidth ); + + m_autoTextThickness->Check( true ); + m_textThickness.Enable( false ); + } + else if( textThickness > 0 ) + { + m_textThickness.SetValue( textThickness ); + } + return true; } @@ -244,18 +270,42 @@ void DIALOG_TABLECELL_PROPERTIES::onBoldToggle( wxCommandEvent& aEvent ) aEvent.Skip(); } -void DIALOG_TABLECELL_PROPERTIES::onAdjustTextThickness( wxCommandEvent& aEvent ) +void DIALOG_TABLECELL_PROPERTIES::onTextSize( wxCommandEvent& aEvent ) { - int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); - int thickness; + if( m_autoTextThickness->IsChecked() ) + { + int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); + int thickness; - // Calculate the "best" thickness from text size and bold option: - if( m_bold->IsChecked() ) - thickness = GetPenSizeForBold( textSize ); - else - thickness = GetPenSizeForNormal( textSize ); + // Calculate the "best" thickness from text size and bold option: + if( m_bold->IsChecked() ) + thickness = GetPenSizeForBold( textSize ); + else + thickness = GetPenSizeForNormal( textSize ); - m_textThickness.SetValue( thickness ); + m_textThickness.SetValue( thickness ); + } +} + + +void DIALOG_TABLECELL_PROPERTIES::onAutoTextThickness( wxCommandEvent& aEvent ) +{ + if( aEvent.IsChecked() ) + { + m_autoTextThickness->Check( true ); + + if( !m_textWidth.IsIndeterminate() && !m_textHeight.IsIndeterminate() ) + { + wxCommandEvent dummy; + onTextSize( dummy ); + } + + m_textThickness.Enable( false ); + } + else + { + m_textThickness.Enable( true ); + } } @@ -298,19 +348,22 @@ bool DIALOG_TABLECELL_PROPERTIES::TransferDataFromWindow() for( PCB_TABLECELL* cell : m_cells ) { - wxString txt = m_cellTextCtrl->GetValue(); + if( m_cellTextCtrl->GetValue() != INDETERMINATE_STATE ) + { + wxString txt = m_cellTextCtrl->GetValue(); #ifdef __WXMAC__ - // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting. - // Replace it now. - txt.Replace( "\r", "\n" ); + // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting. + // Replace it now. + txt.Replace( "\r", "\n" ); #elif defined( __WINDOWS__ ) - // On Windows, a new line is coded as \r\n. We use only \n in kicad files and in - // drawing routines so strip the \r char. - txt.Replace( "\r", "" ); + // On Windows, a new line is coded as \r\n. We use only \n in kicad files and in + // drawing routines so strip the \r char. + txt.Replace( "\r", "" ); #endif - cell->SetText( txt ); + cell->SetText( txt ); + } cell->SetBold( m_bold->IsChecked() ); cell->SetItalic( m_italic->IsChecked() ); @@ -324,7 +377,9 @@ bool DIALOG_TABLECELL_PROPERTIES::TransferDataFromWindow() if( !m_textHeight.IsIndeterminate() ) cell->SetTextHeight( m_textHeight.GetIntValue() ); - if( !m_textThickness.IsIndeterminate() ) + if( m_autoTextThickness->IsChecked() ) + cell->SetAutoThickness( true ); + else if( !m_textThickness.IsIndeterminate() ) cell->SetTextThickness( m_textThickness.GetIntValue() ); if( m_hAlignLeft->IsChecked() ) diff --git a/pcbnew/dialogs/dialog_tablecell_properties.h b/pcbnew/dialogs/dialog_tablecell_properties.h index 4ee206c68f..75d7f41dfe 100644 --- a/pcbnew/dialogs/dialog_tablecell_properties.h +++ b/pcbnew/dialogs/dialog_tablecell_properties.h @@ -58,7 +58,8 @@ private: void onHAlignButton( wxCommandEvent& aEvent ); void onVAlignButton( wxCommandEvent& aEvent ); - void onAdjustTextThickness( wxCommandEvent& aEvent ) override; + void onTextSize( wxCommandEvent &aEvent ) override; + void onAutoTextThickness( wxCommandEvent &aEvent ) override; void onBoldToggle( wxCommandEvent& aEvent ) override; void onEditTable( wxCommandEvent& aEvent ) override; diff --git a/pcbnew/dialogs/dialog_tablecell_properties_base.cpp b/pcbnew/dialogs/dialog_tablecell_properties_base.cpp index 08a04b29a3..8312280622 100644 --- a/pcbnew/dialogs/dialog_tablecell_properties_base.cpp +++ b/pcbnew/dialogs/dialog_tablecell_properties_base.cpp @@ -204,10 +204,10 @@ DIALOG_TABLECELL_PROPERTIES_BASE::DIALOG_TABLECELL_PROPERTIES_BASE( wxWindow* pa m_ThicknessUnits->Wrap( -1 ); gbSizer1->Add( m_ThicknessUnits, wxGBPosition( 2, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); - m_adjustTextThickness = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|wxBORDER_NONE ); - m_adjustTextThickness->SetToolTip( _("Adjust the text thickness") ); + m_autoTextThickness = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|wxBORDER_NONE ); + m_autoTextThickness->SetToolTip( _("Adjust the text thickness") ); - gbSizer1->Add( m_adjustTextThickness, wxGBPosition( 2, 3 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + gbSizer1->Add( m_autoTextThickness, wxGBPosition( 2, 3 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); bMargins->Add( gbSizer1, 0, wxEXPAND|wxTOP, 5 ); @@ -287,10 +287,12 @@ DIALOG_TABLECELL_PROPERTIES_BASE::DIALOG_TABLECELL_PROPERTIES_BASE( wxWindow* pa // Connect Events m_bold->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onBoldToggle ), NULL, this ); + m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::OnOkClick ), NULL, this ); + m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_ThicknessCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onThickness ), NULL, this ); - m_adjustTextThickness->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onAdjustTextThickness ), NULL, this ); + m_autoTextThickness->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onAutoTextThickness ), NULL, this ); m_editTable->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onEditTable ), NULL, this ); } @@ -298,10 +300,12 @@ DIALOG_TABLECELL_PROPERTIES_BASE::~DIALOG_TABLECELL_PROPERTIES_BASE() { // Disconnect Events m_bold->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onBoldToggle ), NULL, this ); + m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::OnOkClick ), NULL, this ); + m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_ThicknessCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onThickness ), NULL, this ); - m_adjustTextThickness->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onAdjustTextThickness ), NULL, this ); + m_autoTextThickness->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onAutoTextThickness ), NULL, this ); m_editTable->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TABLECELL_PROPERTIES_BASE::onEditTable ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_tablecell_properties_base.fbp b/pcbnew/dialogs/dialog_tablecell_properties_base.fbp index 42659466d2..dccdff1fab 100644 --- a/pcbnew/dialogs/dialog_tablecell_properties_base.fbp +++ b/pcbnew/dialogs/dialog_tablecell_properties_base.fbp @@ -1359,6 +1359,7 @@ + onTextSize OnOkClick @@ -1558,6 +1559,7 @@ + onTextSize OnOkClick @@ -1877,7 +1879,7 @@ 0 1 - m_adjustTextThickness + m_autoTextThickness 1 @@ -1900,7 +1902,7 @@ - onAdjustTextThickness + onAutoTextThickness diff --git a/pcbnew/dialogs/dialog_tablecell_properties_base.h b/pcbnew/dialogs/dialog_tablecell_properties_base.h index b67ce8a529..c24944aa8a 100644 --- a/pcbnew/dialogs/dialog_tablecell_properties_base.h +++ b/pcbnew/dialogs/dialog_tablecell_properties_base.h @@ -68,7 +68,7 @@ class DIALOG_TABLECELL_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_ThicknessLabel; wxTextCtrl* m_ThicknessCtrl; wxStaticText* m_ThicknessUnits; - BITMAP_BUTTON* m_adjustTextThickness; + BITMAP_BUTTON* m_autoTextThickness; wxTextCtrl* m_marginTopCtrl; wxStaticText* m_marginTopUnits; wxTextCtrl* m_marginLeftCtrl; @@ -81,9 +81,10 @@ class DIALOG_TABLECELL_PROPERTIES_BASE : public DIALOG_SHIM // Virtual event handlers, override them in your derived class virtual void onBoldToggle( wxCommandEvent& event ) { event.Skip(); } + virtual void onTextSize( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } virtual void onThickness( wxCommandEvent& event ) { event.Skip(); } - virtual void onAdjustTextThickness( wxCommandEvent& event ) { event.Skip(); } + virtual void onAutoTextThickness( wxCommandEvent& event ) { event.Skip(); } virtual void onEditTable( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index 19eb709893..63e3b1dbef 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -202,7 +202,8 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PC m_mirrored->SetIsCheckButton(); m_mirrored->SetBitmap( KiBitmapBundle( BITMAPS::text_mirrored ) ); - m_adjustTextThickness->SetBitmap( KiBitmapBundle( BITMAPS::edit_cmp_symb_links ) ); + m_autoTextThickness->SetIsCheckButton(); + m_autoTextThickness->SetBitmap( KiBitmapBundle( BITMAPS::edit_cmp_symb_links ) ); SetTitle( title ); m_hash_key = title; @@ -328,7 +329,18 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() m_textWidth.SetValue( m_item->GetTextSize().x ); m_textHeight.SetValue( m_item->GetTextSize().y ); - m_thickness.SetValue( m_item->GetTextThickness() ); + + if( m_item->GetAutoThickness() ) + { + m_autoTextThickness->Check( m_item->GetAutoThickness() ); + m_thickness.SetValue( m_item->GetEffectiveTextPenWidth() ); + m_thickness.Enable( false ); + } + else + { + m_thickness.SetValue( m_item->GetTextThickness() ); + } + m_posX.SetValue( m_item->GetFPRelativePosition().x ); m_posY.SetValue( m_item->GetFPRelativePosition().y ); @@ -371,7 +383,7 @@ void DIALOG_TEXT_PROPERTIES::onFontSelected( wxCommandEvent & aEvent ) if( KIFONT::FONT::IsStroke( aEvent.GetString() ) ) { m_thickness.Show( true ); - m_adjustTextThickness->Show( true ); + m_autoTextThickness->Show( true ); int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); int thickness = m_thickness.GetValue(); @@ -382,7 +394,7 @@ void DIALOG_TEXT_PROPERTIES::onFontSelected( wxCommandEvent & aEvent ) else { m_thickness.Show( false ); - m_adjustTextThickness->Show( false ); + m_autoTextThickness->Show( false ); } } @@ -430,18 +442,39 @@ void DIALOG_TEXT_PROPERTIES::onThickness( wxCommandEvent& event ) } -void DIALOG_TEXT_PROPERTIES::updateTextThickness( wxCommandEvent &aEvent ) +void DIALOG_TEXT_PROPERTIES::onTextSize( wxCommandEvent& aEvent ) { - int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); - int thickness; + if( m_autoTextThickness->IsChecked() ) + { + int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); + int thickness; - // Calculate the "best" thickness from text size and bold option: - if( m_bold->IsChecked() ) - thickness = GetPenSizeForBold( textSize ); - else - thickness = GetPenSizeForNormal( textSize ); + // Calculate the "best" thickness from text size and bold option: + if( m_bold->IsChecked() ) + thickness = GetPenSizeForBold( textSize ); + else + thickness = GetPenSizeForNormal( textSize ); - m_thickness.SetValue( thickness ); + m_thickness.SetValue( thickness ); + } +} + + +void DIALOG_TEXT_PROPERTIES::onAutoTextThickness( wxCommandEvent& aEvent ) +{ + if( aEvent.IsChecked() ) + { + m_autoTextThickness->Check( true ); + + wxCommandEvent dummy; + onTextSize( dummy ); + + m_thickness.Enable( false ); + } + else + { + m_thickness.Enable( true ); + } } @@ -512,19 +545,27 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() } m_item->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); - m_item->SetTextThickness( m_thickness.GetValue() ); - m_item->SetFPRelativePosition( VECTOR2I( m_posX.GetValue(), m_posY.GetValue() ) ); - - // Test for acceptable values for thickness and size and clamp if fails - int maxPenWidth = ClampTextPenSize( m_item->GetTextThickness(), m_item->GetTextSize() ); - if( m_item->GetTextThickness() > maxPenWidth ) + if( m_autoTextThickness->IsChecked() ) { - DisplayError( this, _( "The text thickness is too large for the text size.\n" - "It will be clamped." ) ); - m_item->SetTextThickness( maxPenWidth ); + m_item->SetAutoThickness( true ); + } + else + { + m_item->SetTextThickness( m_thickness.GetValue() ); + + // Test for acceptable values for thickness and size and clamp if fails + int maxPenWidth = ClampTextPenSize( m_item->GetTextThickness(), m_item->GetTextSize() ); + + if( m_item->GetTextThickness() > maxPenWidth ) + { + DisplayError( this, _( "The text thickness is too large for the text size.\n" + "It will be clamped." ) ); + m_item->SetTextThickness( maxPenWidth ); + } } + m_item->SetFPRelativePosition( VECTOR2I( m_posX.GetValue(), m_posY.GetValue() ) ); m_item->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); if( m_Visible->IsShown() ) diff --git a/pcbnew/dialogs/dialog_text_properties.h b/pcbnew/dialogs/dialog_text_properties.h index ceadfb5e18..61a9fd1dee 100644 --- a/pcbnew/dialogs/dialog_text_properties.h +++ b/pcbnew/dialogs/dialog_text_properties.h @@ -56,7 +56,8 @@ private: void onAlignButton( wxCommandEvent &aEvent ) override; void onValignButton( wxCommandEvent &aEvent ) override; void onThickness( wxCommandEvent &aEvent ) override; - void updateTextThickness( wxCommandEvent& aEvent ) override; + void onTextSize( wxCommandEvent &aEvent ) override; + void onAutoTextThickness( wxCommandEvent &aEvent ) override; bool TransferDataToWindow() override; bool TransferDataFromWindow() override; diff --git a/pcbnew/dialogs/dialog_text_properties_base.cpp b/pcbnew/dialogs/dialog_text_properties_base.cpp index 671290e0ca..82c41a4e0c 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.cpp +++ b/pcbnew/dialogs/dialog_text_properties_base.cpp @@ -204,10 +204,10 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi m_ThicknessUnits->Wrap( -1 ); bSizer8->Add( m_ThicknessUnits, 0, wxALIGN_CENTER_VERTICAL, 5 ); - m_adjustTextThickness = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|wxBORDER_NONE ); - m_adjustTextThickness->SetToolTip( _("Adjust the text thickness") ); + m_autoTextThickness = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|wxBORDER_NONE ); + m_autoTextThickness->SetToolTip( _("Adjust the text thickness") ); - bSizer8->Add( m_adjustTextThickness, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 3 ); + bSizer8->Add( m_autoTextThickness, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 3 ); gbSizer1->Add( bSizer8, wxGBPosition( 5, 2 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); @@ -308,9 +308,11 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi m_valignTop->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onValignButton ), NULL, this ); m_valignCenter->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onValignButton ), NULL, this ); m_valignBottom->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onValignButton ), NULL, this ); + m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); + m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); - m_adjustTextThickness->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::updateTextThickness ), NULL, this ); + m_autoTextThickness->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onAutoTextThickness ), NULL, this ); m_PositionXCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_PositionYCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_OrientCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); @@ -333,9 +335,11 @@ DIALOG_TEXT_PROPERTIES_BASE::~DIALOG_TEXT_PROPERTIES_BASE() m_valignTop->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onValignButton ), NULL, this ); m_valignCenter->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onValignButton ), NULL, this ); m_valignBottom->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onValignButton ), NULL, this ); + m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); + m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); - m_adjustTextThickness->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::updateTextThickness ), NULL, this ); + m_autoTextThickness->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::onAutoTextThickness ), NULL, this ); m_PositionXCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_PositionYCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_OrientCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_text_properties_base.fbp b/pcbnew/dialogs/dialog_text_properties_base.fbp index a9727be1f9..d6f77ef2e0 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.fbp +++ b/pcbnew/dialogs/dialog_text_properties_base.fbp @@ -1967,6 +1967,7 @@ + onTextSize OnOkClick @@ -2166,6 +2167,7 @@ + onTextSize OnOkClick @@ -2357,7 +2359,7 @@ 0 1 - m_adjustTextThickness + m_autoTextThickness 1 @@ -2380,7 +2382,7 @@ - updateTextThickness + onAutoTextThickness diff --git a/pcbnew/dialogs/dialog_text_properties_base.h b/pcbnew/dialogs/dialog_text_properties_base.h index f01c8c0e64..3b8fb08b40 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.h +++ b/pcbnew/dialogs/dialog_text_properties_base.h @@ -78,7 +78,7 @@ class DIALOG_TEXT_PROPERTIES_BASE : public DIALOG_SHIM wxTextCtrl* m_SizeYCtrl; wxStaticText* m_SizeYUnits; wxStaticText* m_ThicknessUnits; - BITMAP_BUTTON* m_adjustTextThickness; + BITMAP_BUTTON* m_autoTextThickness; wxStaticText* m_PositionXLabel; wxTextCtrl* m_PositionXCtrl; wxStaticText* m_PositionXUnits; @@ -103,7 +103,8 @@ class DIALOG_TEXT_PROPERTIES_BASE : public DIALOG_SHIM virtual void onBoldToggle( wxCommandEvent& event ) { event.Skip(); } virtual void onAlignButton( wxCommandEvent& event ) { event.Skip(); } virtual void onValignButton( wxCommandEvent& event ) { event.Skip(); } - virtual void updateTextThickness( wxCommandEvent& event ) { event.Skip(); } + virtual void onTextSize( wxCommandEvent& event ) { event.Skip(); } + virtual void onAutoTextThickness( wxCommandEvent& event ) { event.Skip(); } virtual void onThickness( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcbnew/dialogs/dialog_textbox_properties.cpp b/pcbnew/dialogs/dialog_textbox_properties.cpp index 325876ebf0..031f7963ec 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.cpp +++ b/pcbnew/dialogs/dialog_textbox_properties.cpp @@ -117,7 +117,8 @@ DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aPare m_separator4->SetIsSeparator(); - m_adjustTextThickness->SetBitmap( KiBitmapBundle( BITMAPS::edit_cmp_symb_links ) ); + m_autoTextThickness->SetIsCheckButton(); + m_autoTextThickness->SetBitmap( KiBitmapBundle( BITMAPS::edit_cmp_symb_links ) ); // Configure the layers list selector. Note that footprints are built outside the current // board and so we may need to show all layers if the text is on an unactivated layer. @@ -173,8 +174,7 @@ int PCB_BASE_EDIT_FRAME::ShowTextBoxPropertiesDialog( PCB_TEXTBOX* aTextBox ) bool DIALOG_TEXTBOX_PROPERTIES::TransferDataToWindow() { BOARD* board = m_frame->GetBoard(); - wxString converted = board->ConvertKIIDsToCrossReferences( - UnescapeString( m_textBox->GetText() ) ); + wxString converted = board->ConvertKIIDsToCrossReferences( UnescapeString( m_textBox->GetText() ) ); m_MultiLineText->SetValue( converted ); m_MultiLineText->SetSelection( -1, -1 ); @@ -188,7 +188,17 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataToWindow() m_textWidth.SetValue( m_textBox->GetTextSize().x ); m_textHeight.SetValue( m_textBox->GetTextSize().y ); - m_thickness.SetValue( m_textBox->GetTextThickness() ); + + if( m_textBox->GetAutoThickness() ) + { + m_autoTextThickness->Check( m_textBox->GetAutoThickness() ); + m_thickness.SetValue( m_textBox->GetEffectiveTextPenWidth() ); + m_thickness.Enable( false ); + } + else + { + m_thickness.SetValue( m_textBox->GetTextThickness() ); + } m_bold->Check( m_textBox->IsBold() ); m_italic->Check( m_textBox->IsItalic() ); @@ -296,18 +306,39 @@ void DIALOG_TEXTBOX_PROPERTIES::onThickness( wxCommandEvent& event ) } -void DIALOG_TEXTBOX_PROPERTIES::updateTextThickness( wxCommandEvent& aEvent ) +void DIALOG_TEXTBOX_PROPERTIES::onTextSize( wxCommandEvent& aEvent ) { - int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); - int thickness; + if( m_autoTextThickness->IsChecked() ) + { + int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() ); + int thickness; - // Calculate the "best" thickness from text size and bold option: - if( m_bold->IsChecked() ) - thickness = GetPenSizeForBold( textSize ); - else - thickness = GetPenSizeForNormal( textSize ); + // Calculate the "best" thickness from text size and bold option: + if( m_bold->IsChecked() ) + thickness = GetPenSizeForBold( textSize ); + else + thickness = GetPenSizeForNormal( textSize ); - m_thickness.SetValue( thickness ); + m_thickness.SetValue( thickness ); + } +} + + +void DIALOG_TEXTBOX_PROPERTIES::onAutoTextThickness( wxCommandEvent& aEvent ) +{ + if( aEvent.IsChecked() ) + { + m_autoTextThickness->Check( true ); + + wxCommandEvent dummy; + onTextSize( dummy ); + + m_thickness.Enable( false ); + } + else + { + m_thickness.Enable( true ); + } } @@ -374,16 +405,24 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() } m_textBox->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); - m_textBox->SetTextThickness( m_thickness.GetValue() ); - - // Test for acceptable values for thickness and size and clamp if fails - int maxPenWidth = ClampTextPenSize( m_textBox->GetTextThickness(), m_textBox->GetTextSize() ); - if( m_textBox->GetTextThickness() > maxPenWidth ) + if( m_autoTextThickness->IsChecked() ) { - DisplayError( this, _( "The text thickness is too large for the text size.\n" - "It will be clamped." ) ); - m_textBox->SetTextThickness( maxPenWidth ); + m_textBox->SetAutoThickness( true ); + } + else + { + m_textBox->SetTextThickness( m_thickness.GetValue() ); + + // Test for acceptable values for thickness and size and clamp if fails + int maxPenWidth = ClampTextPenSize( m_textBox->GetTextThickness(), m_textBox->GetTextSize() ); + + if( m_textBox->GetTextThickness() > maxPenWidth ) + { + DisplayError( this, _( "The text thickness is too large for the text size.\n" + "It will be clamped." ) ); + m_textBox->SetTextThickness( maxPenWidth ); + } } m_textBox->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); diff --git a/pcbnew/dialogs/dialog_textbox_properties.h b/pcbnew/dialogs/dialog_textbox_properties.h index 31033b36aa..c7d396c483 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.h +++ b/pcbnew/dialogs/dialog_textbox_properties.h @@ -48,7 +48,8 @@ private: void onValignButton( wxCommandEvent& aEvent ) override; void onThickness( wxCommandEvent& aEvent ) override; void onBorderChecked( wxCommandEvent& event ) override; - void updateTextThickness( wxCommandEvent& aEvent ) override; + void onTextSize( wxCommandEvent &aEvent ) override; + void onAutoTextThickness( wxCommandEvent &aEvent ) override; bool TransferDataToWindow() override; bool TransferDataFromWindow() override; diff --git a/pcbnew/dialogs/dialog_textbox_properties_base.cpp b/pcbnew/dialogs/dialog_textbox_properties_base.cpp index 9622c53065..75e64687b2 100644 --- a/pcbnew/dialogs/dialog_textbox_properties_base.cpp +++ b/pcbnew/dialogs/dialog_textbox_properties_base.cpp @@ -195,10 +195,10 @@ DIALOG_TEXTBOX_PROPERTIES_BASE::DIALOG_TEXTBOX_PROPERTIES_BASE( wxWindow* parent m_ThicknessUnits->Wrap( -1 ); bSizer5->Add( m_ThicknessUnits, 0, wxALIGN_CENTER_VERTICAL, 5 ); - m_adjustTextThickness = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|wxBORDER_NONE ); - m_adjustTextThickness->SetToolTip( _("Adjust the text thickness") ); + m_autoTextThickness = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|wxBORDER_NONE ); + m_autoTextThickness->SetToolTip( _("Adjust the text thickness") ); - bSizer5->Add( m_adjustTextThickness, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 3 ); + bSizer5->Add( m_autoTextThickness, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 3 ); gbSizer1->Add( bSizer5, wxGBPosition( 7, 2 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); @@ -268,11 +268,13 @@ DIALOG_TEXTBOX_PROPERTIES_BASE::DIALOG_TEXTBOX_PROPERTIES_BASE( wxWindow* parent m_vAlignTop->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onValignButton ), NULL, this ); m_vAlignCenter->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onValignButton ), NULL, this ); m_vAlignBottom->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onValignButton ), NULL, this ); + m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_borderCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onBorderChecked ), NULL, this ); + m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_ThicknessCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onThickness ), NULL, this ); - m_adjustTextThickness->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::updateTextThickness ), NULL, this ); + m_autoTextThickness->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onAutoTextThickness ), NULL, this ); m_OrientCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); } @@ -290,11 +292,13 @@ DIALOG_TEXTBOX_PROPERTIES_BASE::~DIALOG_TEXTBOX_PROPERTIES_BASE() m_vAlignTop->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onValignButton ), NULL, this ); m_vAlignCenter->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onValignButton ), NULL, this ); m_vAlignBottom->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onValignButton ), NULL, this ); + m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_borderCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onBorderChecked ), NULL, this ); + m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onTextSize ), NULL, this ); m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_ThicknessCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onThickness ), NULL, this ); - m_adjustTextThickness->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::updateTextThickness ), NULL, this ); + m_autoTextThickness->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::onAutoTextThickness ), NULL, this ); m_OrientCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEXTBOX_PROPERTIES_BASE::OnOkClick ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_textbox_properties_base.fbp b/pcbnew/dialogs/dialog_textbox_properties_base.fbp index 0d074fcec3..c53fc85b5c 100644 --- a/pcbnew/dialogs/dialog_textbox_properties_base.fbp +++ b/pcbnew/dialogs/dialog_textbox_properties_base.fbp @@ -1746,6 +1746,7 @@ + onTextSize OnOkClick @@ -2014,6 +2015,7 @@ + onTextSize OnOkClick @@ -2339,7 +2341,7 @@ 0 1 - m_adjustTextThickness + m_autoTextThickness 1 @@ -2362,7 +2364,7 @@ - updateTextThickness + onAutoTextThickness diff --git a/pcbnew/dialogs/dialog_textbox_properties_base.h b/pcbnew/dialogs/dialog_textbox_properties_base.h index 5094c89b55..8f6a500d20 100644 --- a/pcbnew/dialogs/dialog_textbox_properties_base.h +++ b/pcbnew/dialogs/dialog_textbox_properties_base.h @@ -77,7 +77,7 @@ class DIALOG_TEXTBOX_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_ThicknessLabel; wxTextCtrl* m_ThicknessCtrl; wxStaticText* m_ThicknessUnits; - BITMAP_BUTTON* m_adjustTextThickness; + BITMAP_BUTTON* m_autoTextThickness; wxStaticText* m_OrientLabel; wxComboBox* m_OrientCtrl; wxStaticText* m_borderWidthLabel; @@ -96,10 +96,11 @@ class DIALOG_TEXTBOX_PROPERTIES_BASE : public DIALOG_SHIM virtual void onBoldToggle( wxCommandEvent& event ) { event.Skip(); } virtual void onHalignButton( wxCommandEvent& event ) { event.Skip(); } virtual void onValignButton( wxCommandEvent& event ) { event.Skip(); } + virtual void onTextSize( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } virtual void onBorderChecked( wxCommandEvent& event ) { event.Skip(); } virtual void onThickness( wxCommandEvent& event ) { event.Skip(); } - virtual void updateTextThickness( wxCommandEvent& event ) { event.Skip(); } + virtual void onAutoTextThickness( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp index 36bdc35ba1..bb2c785079 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp @@ -587,17 +587,11 @@ void PCB_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText ) break; case T_bold: - { - bool value = parseMaybeAbsentBool( true ); - aText->SetBoldFlag( value ); - } + aText->SetBoldFlag( parseMaybeAbsentBool( true ) ); break; case T_italic: - { - bool value = parseMaybeAbsentBool( true ); - aText->SetItalicFlag( value ); - } + aText->SetItalicFlag( parseMaybeAbsentBool( true ) ); break; default: @@ -615,28 +609,12 @@ void PCB_IO_KICAD_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText ) switch( token ) { - case T_left: - aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); - break; - - case T_right: - aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); - break; - - case T_top: - aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP ); - break; - - case T_bottom: - aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); - break; - - case T_mirror: - aText->SetMirrored( true ); - break; - - default: - Expecting( "left, right, top, bottom, or mirror" ); + case T_left: aText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); break; + case T_right: aText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); break; + case T_top: aText->SetVertJustify( GR_TEXT_V_ALIGN_TOP ); break; + case T_bottom: aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); break; + case T_mirror: aText->SetMirrored( true ); break; + default: Expecting( "left, right, top, bottom, or mirror" ); } } diff --git a/pcbnew/pcb_tablecell.cpp b/pcbnew/pcb_tablecell.cpp index b5e6ff4bc1..416085d73c 100644 --- a/pcbnew/pcb_tablecell.cpp +++ b/pcbnew/pcb_tablecell.cpp @@ -117,7 +117,12 @@ void PCB_TABLECELL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorMessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) ); aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); - aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); + + if( GetTextThickness() ) + aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) ); + else + aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) ); + aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); } diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 9d45122248..3066e40102 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -59,17 +59,15 @@ PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype) : { SetKeepUpright( true ); - // Set text thickness to a default value - SetTextThickness( pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ) ); + // N.B. Do not automatically set text effects + // These are optional in the file format and so need to be defaulted to off. + SetLayer( F_SilkS ); if( aParent ) { SetTextPos( aParent->GetPosition() ); - // N.B. Do not automatically set text effects - // These are optional in the file format and so need to be defaulted - // to off. if( IsBackLayer( aParent->GetLayer() ) ) SetLayer( B_SilkS ); } @@ -292,7 +290,12 @@ void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() : _( "Default" ) ); - aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); + + if( GetTextThickness() ) + aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) ); + else + aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) ); + aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); } @@ -300,7 +303,7 @@ void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() : _( "Default" ) ); - aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); + + if( GetTextThickness() ) + aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) ); + else + aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) ); + aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );