From 0347515cecb970aaa4de6c649651061cfa44d2bc Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 12 Sep 2020 10:23:07 -0400 Subject: [PATCH] Support text expansion in dimensions --- pcbnew/class_dimension.cpp | 9 ++++++++- pcbnew/class_dimension.h | 2 ++ pcbnew/class_pcb_text.cpp | 5 ++--- pcbnew/dialogs/dialog_dimension_properties.cpp | 1 + pcbnew/pcb_painter.cpp | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index 950cb5b9f8..7a37ac8f82 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -50,13 +50,20 @@ DIMENSION::DIMENSION( BOARD_ITEM* aParent ) : m_extensionOffset( 0 ), m_textPosition( DIM_TEXT_POSITION::OUTSIDE ), m_keepTextAligned( true ), - m_text( this ), + m_text( aParent ), m_measuredValue( 0 ) { m_Layer = Dwgs_User; } +void DIMENSION::SetParent( EDA_ITEM* aParent ) +{ + BOARD_ITEM::SetParent( aParent ); + m_text.SetParent( aParent ); +} + + void DIMENSION::SetPosition( const wxPoint& aPos ) { m_text.SetTextPos( aPos ); diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index 109ce9d1e4..1fc495ef62 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -92,6 +92,8 @@ class DIMENSION : public BOARD_ITEM public: DIMENSION( BOARD_ITEM* aParent ); + void SetParent( EDA_ITEM* aParent ) override; + /** * The dimension's origin is the first feature point for the dimension. Every dimension has * one or more feature points, so every dimension has at least an origin. diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index 16d966fb0d..7c4c71ddfd 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -50,8 +50,7 @@ TEXTE_PCB::~TEXTE_PCB() wxString TEXTE_PCB::GetShownText( int aDepth ) const { - BOARD* board = static_cast( GetParent() ); - wxASSERT( board ); + BOARD* board = dynamic_cast( GetParent() ); std::function pcbTextResolver = [&]( wxString* token ) -> bool @@ -91,7 +90,7 @@ wxString TEXTE_PCB::GetShownText( int aDepth ) const bool processTextVars = false; wxString text = EDA_TEXT::GetShownText( &processTextVars ); - if( processTextVars && aDepth < 10 ) + if( board && processTextVars && aDepth < 10 ) text = ExpandTextVars( text, &pcbTextResolver, board->GetProject(), &boardTextResolver ); return text; diff --git a/pcbnew/dialogs/dialog_dimension_properties.cpp b/pcbnew/dialogs/dialog_dimension_properties.cpp index 581299017a..9ffd2b34b4 100644 --- a/pcbnew/dialogs/dialog_dimension_properties.cpp +++ b/pcbnew/dialogs/dialog_dimension_properties.cpp @@ -46,6 +46,7 @@ DIALOG_DIMENSION_PROPERTIES::DIALOG_DIMENSION_PROPERTIES( PCB_BASE_EDIT_FRAME* a wxASSERT( aItem->Type() == PCB_DIMENSION_T ); m_dimension = static_cast( aItem ); m_previewDimension = static_cast( m_dimension->Clone() ); + m_previewDimension->SetParent( m_frame->GetBoard() ); // Configure display origin transforms m_textPosX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD ); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 7df580d444..5732e50528 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1296,7 +1296,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) } m_gal->SetTextAttributes( &text ); - m_gal->StrokeText( aDimension->GetText(), position, text.GetTextAngleRadians() ); + m_gal->StrokeText( text.GetShownText(), position, text.GetTextAngleRadians() ); }