diff --git a/common/pcb.keywords b/common/pcb.keywords index dbbf3747f2..741644fc71 100644 --- a/common/pcb.keywords +++ b/common/pcb.keywords @@ -54,6 +54,7 @@ blind blind_buried_vias_allowed board_only bold +border bottom bottom_left bottom_right diff --git a/pcbnew/dialogs/dialog_textbox_properties.cpp b/pcbnew/dialogs/dialog_textbox_properties.cpp index 37d4449780..2af054b3f7 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.cpp +++ b/pcbnew/dialogs/dialog_textbox_properties.cpp @@ -357,28 +357,21 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() m_textBox->SetMirrored( m_mirrored->IsChecked() ); - - if( m_borderCheckbox->GetValue() ) - { - STROKE_PARAMS stroke = m_textBox->GetStroke(); - if( !m_borderWidth.IsIndeterminate() ) - stroke.SetWidth( m_borderWidth.GetValue() ); + m_textBox->SetBorderEnabled( m_borderCheckbox->GetValue() ); + STROKE_PARAMS stroke = m_textBox->GetStroke(); + if( !m_borderWidth.IsIndeterminate() ) + stroke.SetWidth( m_borderWidth.GetValue() ); - auto it = lineTypeNames.begin(); - std::advance( it, m_borderStyleCombo->GetSelection() ); + auto it = lineTypeNames.begin(); + std::advance( it, m_borderStyleCombo->GetSelection() ); - if( it == lineTypeNames.end() ) - stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT ); - else - stroke.SetPlotStyle( it->first ); - - m_textBox->SetStroke( stroke ); - } + if( it == lineTypeNames.end() ) + stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT ); else - { - m_textBox->DisableBorder(); - } + stroke.SetPlotStyle( it->first ); + + m_textBox->SetStroke( stroke ); m_textBox->ClearBoundingBoxCache(); m_textBox->ClearRenderCache(); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index f8e7bb9c5f..ecf919c236 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -2151,7 +2151,7 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE ) { - if( thickness > 0 ) + if( aTextBox->IsBorderEnabled() && thickness > 0 ) { std::vector pts = aTextBox->GetCorners(); diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index e764a235db..79bf7959f2 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -40,7 +40,8 @@ PCB_TEXTBOX::PCB_TEXTBOX( BOARD_ITEM* parent ) : PCB_SHAPE( parent, PCB_TEXTBOX_T, SHAPE_T::RECTANGLE ), - EDA_TEXT( pcbIUScale ) + EDA_TEXT( pcbIUScale ), + m_borderEnabled( true ) { SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); SetVertJustify( GR_TEXT_V_ALIGN_TOP ); @@ -522,7 +523,7 @@ void PCB_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID for( const VECTOR2I& pt : pts ) aBuffer.Append( pt ); - if( width > 0 ) + if( m_borderEnabled && width > 0 ) { // Add in segments TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aMaxError, aErrorLoc ); @@ -540,7 +541,7 @@ void PCB_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID for( int ii = 0; ii < poly.PointCount(); ++ii ) aBuffer.Append( poly.GetPoint( ii ) ); - if( width > 0 ) + if( m_borderEnabled && width > 0 ) { for( int ii = 0; ii < poly.SegmentCount(); ++ii ) { @@ -554,13 +555,13 @@ void PCB_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID bool PCB_TEXTBOX::IsBorderEnabled() const { - return m_stroke.GetWidth() >= 0; + return m_borderEnabled; } -void PCB_TEXTBOX::DisableBorder() +void PCB_TEXTBOX::SetBorderEnabled( bool enabled ) { - m_stroke.SetWidth( -1 ); + m_borderEnabled = enabled; } @@ -582,5 +583,12 @@ static struct PCB_TEXTBOX_DESC propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) ); propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) ); propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) ); + + const wxString textBoxProps = _( "Text Box" ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Border" ), + &PCB_TEXTBOX::SetBorderEnabled, + &PCB_TEXTBOX::IsBorderEnabled ), + textBoxProps ); } } _PCB_TEXTBOX_DESC; diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index 056367393d..7e96ef45cb 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -142,9 +142,11 @@ public: bool IsBorderEnabled() const; ///< Disables the border, this is done by changing the stroke internally - void DisableBorder(); + void SetBorderEnabled( bool enabled ); protected: + bool m_borderEnabled; ///< Controls drawing the border (as defined by the stroke members) + virtual void swapData( BOARD_ITEM* aImage ) override; const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); } diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index e63f0b9f55..30535a8761 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -3242,6 +3242,11 @@ PCB_TEXTBOX* PCB_PARSER::parsePCB_TEXTBOX( BOARD_ITEM* aParent ) break; } + case T_border: + textbox->SetBorderEnabled( parseBool() ); + NeedRIGHT(); + break; + case T_layer: textbox->SetLayer( parseBoardItemLayer() ); NeedRIGHT(); @@ -3268,6 +3273,10 @@ PCB_TEXTBOX* PCB_PARSER::parsePCB_TEXTBOX( BOARD_ITEM* aParent ) textbox->SetStroke( stroke ); + if( m_requiredVersion < 20230825 ) // compat, we move to an explicit flag + textbox->SetBorderEnabled( stroke.GetWidth() >= 0 ); + + if( FOOTPRINT* parentFP = dynamic_cast( aParent ) ) { textbox->Rotate( { 0, 0 }, parentFP->GetOrientation() ); diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index 35f511aa4e..3e0ab1a20f 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -1896,8 +1896,14 @@ void PCB_PLUGIN::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) const // PCB_TEXTBOXes are never hidden, so always omit "hide" attribute aTextBox->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE ); - if( aTextBox->GetStroke().GetWidth() > 0 ) - aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 ); + m_out->Print( aNestLevel + 1, "(border" ); + + if( aTextBox->IsBorderEnabled() ) + m_out->Print( 0, " yes)" ); + else + m_out->Print( 0, " no)" ); + + aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 ); if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() ) formatRenderCache( aTextBox, aNestLevel + 1 ); diff --git a/pcbnew/plugins/kicad/pcb_plugin.h b/pcbnew/plugins/kicad/pcb_plugin.h index 21e1eeecb6..946409c954 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.h +++ b/pcbnew/plugins/kicad/pcb_plugin.h @@ -137,7 +137,8 @@ class PCB_PLUGIN; // forward decl //#define SEXPR_BOARD_FILE_VERSION 20230410 // DNP attribute propagated from schematic to attr //#define SEXPR_BOARD_FILE_VERSION 20230517 // Teardrop parameters for pads and vias //#define SEXPR_BOARD_FILE_VERSION 20230620 // PCB Fields -#define SEXPR_BOARD_FILE_VERSION 20230730 // Connectivity for graphic shapes +//#define SEXPR_BOARD_FILE_VERSION 20230730 // Connectivity for graphic shapes +#define SEXPR_BOARD_FILE_VERSION 20230825 // Textbox explicit border flag #define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag #define LEGACY_ARC_FORMATTING 20210925 ///< These were the last to use old arc formatting