7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 21:05:15 +00:00

Fix a bunch more issues with sheetpaths and allowExtraText.

A sheetpath is required to correctly resolve text variables.
Depending on currentSheet is rife with bugs.

There are many places where we do *not* want to be prepending
field names to the field values, such as netlisting,
building PDF hypertext menus, etc.

Also, Find/Replace needs to work on unresolved text, as
that's what we're going to display (and if replace nuked
your variable references you wouldn't be happy).
This commit is contained in:
Jeff Young 2023-05-05 14:21:56 +01:00
parent fb6b8eaeea
commit b41d446f58
70 changed files with 347 additions and 270 deletions

View File

@ -89,7 +89,7 @@ void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContaine
callback_gal.SetIsFill( font->IsOutline() );
callback_gal.SetIsStroke( font->IsStroke() );
callback_gal.SetLineWidth( attrs.m_StrokeWidth );
font->Draw( &callback_gal, aText->GetShownText(), aText->GetDrawPos(), attrs );
font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs );
SHAPE_POLY_SET finalPoly;
int margin = attrs.m_StrokeWidth * 1.5 +
@ -135,7 +135,7 @@ void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContaine
attrs.m_Angle = aText->GetDrawRotation();
font->Draw( &callback_gal, aText->GetShownText(), aText->GetDrawPos(), attrs );
font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs );
}
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
*
* This program is free software; you can redistribute it and/or
@ -118,8 +118,12 @@ void DS_DRAW_ITEM_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
break;
case DS_DATA_ITEM::DS_TEXT:
aList.emplace_back( _( "Text" ), static_cast<DS_DRAW_ITEM_TEXT*>( this )->GetShownText() );
{
DS_DRAW_ITEM_TEXT* textItem = static_cast<DS_DRAW_ITEM_TEXT*>( this );
// Don't use GetShownText(); we want to see the variable references here
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, textItem->GetText() ) );
break;
}
case DS_DATA_ITEM::DS_POLYPOLYGON:
aList.emplace_back( _( "Imported Shape" ), wxEmptyString );
@ -190,7 +194,7 @@ bool DS_DRAW_ITEM_TEXT::HitTest( const BOX2I& aRect, bool aContains, int aAccura
wxString DS_DRAW_ITEM_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( _( "Text '%s'" ), GetShownText() );
return wxString::Format( _( "Text '%s'" ), KIUI::EllipsizeMenuText( GetText() ) );
}

View File

@ -270,7 +270,7 @@ void KIGFX::DS_PAINTER::draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const
attrs.m_StrokeWidth = std::max( aItem->GetEffectiveTextPenWidth(),
m_renderSettings.GetDefaultPenWidth() );
font->Draw( m_gal, aItem->GetShownText(), aItem->GetTextPos(), attrs );
font->Draw( m_gal, aItem->GetShownText( true ), aItem->GetTextPos(), attrs );
}

View File

@ -479,7 +479,7 @@ EDA_TEXT::GetRenderCache( const KIFONT::FONT* aFont, const wxString& forResolved
attrs.m_Angle = resolvedAngle;
font->GetLinesAsGlyphs( &m_render_cache, GetShownText(), GetDrawPos() + aOffset,
font->GetLinesAsGlyphs( &m_render_cache, forResolvedText, GetDrawPos() + aOffset,
attrs );
m_render_cache_angle = resolvedAngle;
m_render_cache_text = forResolvedText;
@ -527,7 +527,7 @@ BOX2I EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
BOX2I bbox;
wxArrayString strings;
wxString text = GetShownText();
wxString text = GetShownText( true );
int thickness = GetEffectiveTextPenWidth();
if( IsMultilineAllowed() )
@ -665,7 +665,7 @@ void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
{
std::vector<VECTOR2I> positions;
wxArrayString strings;
wxStringSplit( GetShownText(), strings, '\n' );
wxStringSplit( GetShownText( true ), strings, '\n' );
positions.reserve( strings.Count() );
@ -676,7 +676,8 @@ void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
}
else
{
printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText(), GetDrawPos() );
printOneLineOfText( aSettings, aOffset, aColor, aFillMode, GetShownText( true ),
GetDrawPos() );
}
}
@ -897,7 +898,7 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangula
shape->AddShape( triShape );
} );
font->Draw( &callback_gal, GetShownText(), GetDrawPos(), attrs );
font->Draw( &callback_gal, GetShownText( true ), GetDrawPos(), attrs );
}
else
{
@ -914,7 +915,7 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangula
shape->AddShape( aPoly.Clone() );
} );
font->Draw( &callback_gal, GetShownText(), GetDrawPos(), attrs );
font->Draw( &callback_gal, GetShownText( true ), GetDrawPos(), attrs );
}
return shape;

View File

@ -131,10 +131,10 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL
int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
plotter->Text( text->GetTextPos(), color, text->GetShownText(), text->GetTextAngle(),
text->GetTextSize(), text->GetHorizJustify(), text->GetVertJustify(),
penWidth, text->IsItalic(), text->IsBold(), text->IsMultilineAllowed(),
font );
plotter->Text( text->GetTextPos(), color, text->GetShownText( true ),
text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
text->IsMultilineAllowed(), font );
}
break;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -377,7 +377,7 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
if( symbol->GetUnitCount() > 1 )
{
msg.Printf( _( "Updated %s (unit %s) from %s to %s." ),
symbol->GetValueFieldText( true ),
symbol->GetValueFieldText( true, sheet, false ),
LIB_SYMBOL::SubReference( symbol->GetUnit(), false ),
prevRef,
newRef );
@ -385,7 +385,7 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
else
{
msg.Printf( _( "Updated %s from %s to %s." ),
symbol->GetValueFieldText( true ),
symbol->GetValueFieldText( true, sheet, false ),
prevRef,
newRef );
}
@ -395,14 +395,14 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
if( symbol->GetUnitCount() > 1 )
{
msg.Printf( _( "Annotated %s (unit %s) as %s." ),
symbol->GetValueFieldText( true ),
symbol->GetValueFieldText( true, sheet, false ),
LIB_SYMBOL::SubReference( symbol->GetUnit(), false ),
newRef );
}
else
{
msg.Printf( _( "Annotated %s as %s." ),
symbol->GetValueFieldText( true ),
symbol->GetValueFieldText( true, sheet, false ),
newRef );
}
}

View File

@ -337,12 +337,15 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T:
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( &m_sheet ),
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( &m_sheet, false ),
CTX_NETNAME );
case SCH_SHEET_PIN_T:
// Sheet pins need to use their parent sheet as their starting sheet or they will
// resolve variables on the current sheet first
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText(), CTX_NETNAME );
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( nullptr, false ),
CTX_NETNAME );
default:
wxFAIL_MSG( wxS( "Unhandled item type in GetNameForDriver" ) );
break;
@ -1379,7 +1382,7 @@ void CONNECTION_GRAPH::generateGlobalPowerPinSubGraphs()
// in the symbol, but we support legacy non-power symbols with global
// power connections based on invisible, power-in, pin's names.
if( pin->GetLibPin()->GetParent()->IsPower() )
connection->SetName( pin->GetParentSymbol()->GetValueFieldText( true, &sheet ) );
connection->SetName( pin->GetParentSymbol()->GetValueFieldText( true, &sheet, false ) );
else
connection->SetName( pin->GetShownName() );
@ -2593,11 +2596,11 @@ std::vector<const CONNECTION_SUBGRAPH*> CONNECTION_GRAPH::GetBusesNeedingMigrati
if( labels.size() > 1 )
{
bool different = false;
wxString first = static_cast<SCH_TEXT*>( labels.at( 0 ) )->GetShownText();
wxString first = static_cast<SCH_TEXT*>( labels.at( 0 ) )->GetShownText( false );
for( unsigned i = 1; i < labels.size(); ++i )
{
if( static_cast<SCH_TEXT*>( labels.at( i ) )->GetShownText() != first )
if( static_cast<SCH_TEXT*>( labels.at( i ) )->GetShownText( false ) != first )
{
different = true;
break;
@ -2937,7 +2940,7 @@ bool CONNECTION_GRAPH::ercCheckBusToNetConflicts( const CONNECTION_SUBGRAPH* aSu
case SCH_HIER_LABEL_T:
{
SCH_TEXT* text = static_cast<SCH_TEXT*>( item );
conn.ConfigureFromLabel( EscapeString( text->GetShownText(), CTX_NETNAME ) );
conn.ConfigureFromLabel( EscapeString( text->GetShownText( false ), CTX_NETNAME ) );
if( conn.IsBus() )
bus_item = ( !bus_item ) ? item : bus_item;

View File

@ -75,7 +75,7 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_SYMBO
m_newId->ChangeValue( UnescapeString( m_symbol->GetLibId().Format() ) );
m_specifiedReference->ChangeValue( m_symbol->GetRef( currentSheet ) );
m_specifiedValue->ChangeValue( m_symbol->GetValueFieldText( false ) );
m_specifiedValue->ChangeValue( UnescapeString( m_symbol->GetField( VALUE_FIELD )->GetText() ) );
m_specifiedId->ChangeValue( UnescapeString( m_symbol->GetLibId().Format() ) );
}
else
@ -426,12 +426,14 @@ bool DIALOG_CHANGE_SYMBOLS::isMatch( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aInsta
else if( m_matchByReference->GetValue() )
{
return WildCompareString( m_specifiedReference->GetValue(),
aSymbol->GetRef( aInstance, false ), false );
UnescapeString( aSymbol->GetRef( aInstance, false ) ),
false );
}
else if( m_matchByValue->GetValue() )
{
return WildCompareString( m_specifiedValue->GetValue(),
aSymbol->GetValueFieldText( false ), false );
UnescapeString( aSymbol->GetField( VALUE_FIELD )->GetText() ),
false );
}
else if( m_matchById )
{

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -287,7 +287,7 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow()
// Ensure the symbol has the Power (i.e. equivalent to a global label
// before adding its value in list
if( power->IsSymbolLikePowerGlobalLabel() )
existingLabels.insert( UnescapeString( power->GetValueFieldText( false ) ) );
existingLabels.insert( UnescapeString( power->GetField( VALUE_FIELD )->GetText() ) );
}
}

View File

@ -855,7 +855,7 @@ void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
m_dummySheet.SetFields( *m_fields );
m_dummySheetNameField.SetText( sheetName );
path += m_dummySheetNameField.GetShownText();
path += m_dummySheetNameField.GetShownText( false );
editor->DecRef();

View File

@ -147,7 +147,7 @@ int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
// We have found a second sheet: compare names
// we are using case insensitive comparison to avoid mistakes between
// similar names like Mysheet and mysheet
if( sheet->GetShownName().CmpNoCase( test_item->GetShownName() ) == 0 )
if( sheet->GetShownName( false ).CmpNoCase( test_item->GetShownName( false ) ) == 0 )
{
if( aCreateMarker )
{
@ -206,7 +206,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
for( SCH_FIELD& field : symbol->GetFields() )
{
if( unresolved( field.GetShownText() ) )
if( unresolved( field.GetShownText( true ) ) )
{
std::shared_ptr<ERC_ITEM> ercItem =
ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
@ -223,7 +223,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
for( SCH_FIELD& field : subSheet->GetFields() )
{
if( unresolved( field.GetShownText() ) )
if( unresolved( field.GetShownText( true ) ) )
{
std::shared_ptr<ERC_ITEM> ercItem =
ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
@ -236,7 +236,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
{
if( pin->GetShownText().Matches( wxT( "*${*}*" ) ) )
if( pin->GetShownText( true ).Matches( wxT( "*${*}*" ) ) )
{
std::shared_ptr<ERC_ITEM> ercItem =
ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
@ -249,7 +249,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
}
else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
{
if( text->GetShownText().Matches( wxT( "*${*}*" ) ) )
if( text->GetShownText( true ).Matches( wxT( "*${*}*" ) ) )
{
std::shared_ptr<ERC_ITEM> ercItem =
ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
@ -261,7 +261,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
}
else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
{
if( textBox->GetShownText().Matches( wxT( "*${*}*" ) ) )
if( textBox->GetShownText( true ).Matches( wxT( "*${*}*" ) ) )
{
std::shared_ptr<ERC_ITEM> ercItem =
ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
@ -277,7 +277,7 @@ void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
{
if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
{
if( text->GetShownText().Matches( wxT( "*${*}*" ) ) )
if( text->GetShownText( true ).Matches( wxT( "*${*}*" ) ) )
{
std::shared_ptr<ERC_ITEM> erc = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
erc->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
@ -819,14 +819,14 @@ int ERC_TESTER::TestSimilarLabels()
{
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
wxString normalized = label->GetShownText().Lower();
wxString normalized = label->GetShownText( false ).Lower();
if( !labelMap.count( normalized ) )
{
labelMap[normalized] = std::make_pair( label, subgraph->GetSheet() );
}
else if( labelMap.at( normalized ).first->GetShownText()
!= label->GetShownText() )
else if( labelMap.at( normalized ).first->GetShownText( false )
!= label->GetShownText( false ) )
{
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
ercItem->SetItems( label, labelMap.at( normalized ).first );

View File

@ -71,9 +71,9 @@ static wxString netList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH& aSheetPath )
*/
wxString netlist;
netlist << EscapeString( aSymbol->GetFootprintFieldText( true ), CTX_LINE ) << wxS( "\r" );
netlist << EscapeString( aSymbol->GetFootprintFieldText( true, &aSheetPath, false ), CTX_LINE ) << wxS( "\r" );
netlist << EscapeString( aSymbol->GetRef( &aSheetPath ), CTX_LINE ) << wxS( "\r" );
netlist << EscapeString( aSymbol->GetValueFieldText( true ), CTX_LINE );
netlist << EscapeString( aSymbol->GetValueFieldText( true, &aSheetPath, false ), CTX_LINE );
for( SCH_PIN* pin : aSymbol->GetPins( &aSheetPath ) )
{

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -166,7 +166,7 @@ protected:
switch( aField.GetId() )
{
case DATASHEET_FIELD:
text = m_symbol->GetDatasheetField().GetShownText( 0, false );
text = m_symbol->GetDatasheetField().GetShownText( false );
if( text.IsEmpty() || text == wxT( "~" ) )
{
@ -197,7 +197,7 @@ protected:
break;
default:
text = aField.GetShownText( 0, false );
text = aField.GetShownText( false );
fieldhtml.Replace( wxS( "__VALUE__" ), EscapeHTML( text ) );
}

View File

@ -391,7 +391,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
attrs.m_Angle = orient;
attrs.m_Multiline = false;
aPlotter->PlotText( textpos, color, GetShownText(), attrs, font );
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font );
}
@ -412,9 +412,9 @@ wxString LIB_FIELD::GetFullText( int unit ) const
}
wxString LIB_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const
wxString LIB_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
{
wxString text = EDA_TEXT::GetShownText( aDepth );
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
if( IsNameShown() )
text = GetName() << wxT( ": " ) << text;
@ -517,7 +517,9 @@ void LIB_FIELD::SetName( const wxString& aName )
wxString LIB_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetShownText() ) );
return wxString::Format( "%s '%s'",
UnescapeString( GetName() ),
KIUI::EllipsizeMenuText( GetText() ) );
}
@ -539,10 +541,11 @@ void LIB_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_I
LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
aList.emplace_back( _( "Field" ), GetName() );
// Don't use GetShownText(); we want to see the variable references here
aList.emplace_back( _( "Field" ), UnescapeString( GetName() ) );
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Text" ), UnescapeString( GetText() ) );
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );

View File

@ -152,7 +152,7 @@ public:
*/
wxString GetFullText( int unit = 1 ) const;
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
SCH_LAYER_ID GetDefaultLayer() const;

View File

@ -925,7 +925,7 @@ void LIB_SYMBOL::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, bool
// The reference is a special case: we should change the basic text
// to add '?' and the part id
wxString tmp = field.GetShownText();
wxString tmp = field.GetShownText( true );
if( field.GetId() == REFERENCE_FIELD )
{

View File

@ -406,8 +406,9 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
// Calculate pos according to mirror/rotation.
txtpos = aTransform.TransformCoordinate( txtpos ) + aOffset;
GRPrintText( DC, txtpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER,
GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), font );
GRPrintText( DC, txtpos, color, GetShownText( true ), orient, GetTextSize(),
GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(),
font );
}
@ -418,7 +419,7 @@ void LIB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Text" ), UnescapeString( GetText() ) );
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
@ -473,7 +474,7 @@ const BOX2I LIB_TEXT::GetBoundingBox() const
wxString LIB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) );
return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetText() ) );
}

View File

@ -321,15 +321,15 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
text.SetStart( VECTOR2I( pt1.x, -pt1.y ) );
text.SetEnd( VECTOR2I( pt2.x, -pt2.y ) );
GRPrintText( DC, text.GetDrawPos(), color, text.GetShownText(), text.GetTextAngle(),
GRPrintText( DC, text.GetDrawPos(), color, text.GetShownText( true ), text.GetTextAngle(),
text.GetTextSize(), text.GetHorizJustify(), text.GetVertJustify(), penWidth,
text.IsItalic(), text.IsBold(), font );
}
wxString LIB_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const
wxString LIB_TEXTBOX::GetShownText( bool aAllowExtraText, int aDepth ) const
{
wxString text = EDA_TEXT::GetShownText();
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
KIFONT::FONT* font = GetFont();
VECTOR2D size = GetEnd() - GetStart();
@ -461,7 +461,7 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
std::vector<VECTOR2I> positions;
wxArrayString strings_list;
wxStringSplit( GetShownText(), strings_list, '\n' );
wxStringSplit( GetShownText( true ), strings_list, '\n' );
positions.reserve( strings_list.Count() );
text.GetLinePositions( positions, (int) strings_list.Count() );

View File

@ -55,7 +55,7 @@ public:
VECTOR2I GetDrawPos() const override;
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
void MirrorHorizontally( const VECTOR2I& center );
void MirrorVertically( const VECTOR2I& center );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2018 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -79,7 +79,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName,
if( !symbol->GetIncludeOnBoard() )
continue;
footprint = symbol->GetFootprintFieldText( true );
footprint = symbol->GetFootprintFieldText( true, &sheetList[ i ], false );
if( footprint.IsEmpty() )
footprint = "$noname";
@ -88,7 +88,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName,
ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
ret |= fprintf( f, "%s", TO_UTF8( msg ) );
msg = symbol->GetValueFieldText( true );
msg = symbol->GetValueFieldText( true, &sheetList[ i ], false );
msg.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( footprint ) );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2018 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -88,7 +88,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
sheet ) );
}
footprint = symbol->GetFootprintFieldText( true );
footprint = symbol->GetFootprintFieldText( true, &sheet, false );
footprint.Replace( wxT( " " ), wxT( "_" ) );
if( footprint.IsEmpty() )
@ -102,7 +102,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
ret |= fprintf( f, " %s", TO_UTF8( field ) );
field = symbol->GetValueFieldText( true );
field = symbol->GetValueFieldText( true, &sheet, false );
field.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " %s", TO_UTF8( field ) );

View File

@ -223,7 +223,7 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
if( field.GetId() == REFERENCE_FIELD )
spiceItem.fields.back().SetText( symbol->GetRef( &sheet ) );
else
spiceItem.fields.back().SetText( field.GetShownText( &sheet, 0, false ) );
spiceItem.fields.back().SetText( field.GetShownText( &sheet, false ) );
}
readRefName( sheet, *symbol, spiceItem, refNames );
@ -335,9 +335,9 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
continue;
if( item->Type() == SCH_TEXT_T )
text = static_cast<SCH_TEXT*>( item )->GetShownText();
text = static_cast<SCH_TEXT*>( item )->GetShownText( &sheet, false );
else if( item->Type() == SCH_TEXTBOX_T )
text = static_cast<SCH_TEXTBOX*>( item )->GetShownText();
text = static_cast<SCH_TEXTBOX*>( item )->GetShownText( &sheet, false );
else
continue;

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013-2017 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -127,18 +127,18 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol,
int unit = symbol2->GetUnitSelection( aSheet );
// The lowest unit number wins. User should only set fields in any one unit.
candidate = symbol2->GetValueFieldText( m_resolveTextVars );
candidate = symbol2->GetValueFieldText( m_resolveTextVars, &sheetList[i], false );
if( !candidate.IsEmpty() && ( unit < minUnit || value.IsEmpty() ) )
value = candidate;
candidate = symbol2->GetFootprintFieldText( m_resolveTextVars );
candidate = symbol2->GetFootprintFieldText( m_resolveTextVars, &sheetList[i], false );
if( !candidate.IsEmpty() && ( unit < minUnit || footprint.IsEmpty() ) )
footprint = candidate;
candidate = m_resolveTextVars
? symbol2->GetField( DATASHEET_FIELD )->GetShownText( aSheet, 0, false )
? symbol2->GetField( DATASHEET_FIELD )->GetShownText( &sheetList[i], false )
: symbol2->GetField( DATASHEET_FIELD )->GetText();
if( !candidate.IsEmpty() && ( unit < minUnit || datasheet.IsEmpty() ) )
@ -152,7 +152,7 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol,
&& ( unit < minUnit || userFields.count( f.GetName() ) == 0 ) )
{
if( m_resolveTextVars )
userFields[ f.GetName() ] = f.GetShownText( aSheet, 0, false );
userFields[ f.GetName() ] = f.GetShownText( aSheet, false );
else
userFields[ f.GetName() ] = f.GetText();
}
@ -164,11 +164,11 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol,
}
else
{
value = aSymbol->GetValueFieldText( m_resolveTextVars );
footprint = aSymbol->GetFootprintFieldText( m_resolveTextVars );
value = aSymbol->GetValueFieldText( m_resolveTextVars, aSheet, false );
footprint = aSymbol->GetFootprintFieldText( m_resolveTextVars, aSheet, false );
if( m_resolveTextVars )
datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetShownText( aSheet, 0, false );
datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetShownText( aSheet, false );
else
datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetText();
@ -179,7 +179,7 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol,
if( f.GetText().size() )
{
if( m_resolveTextVars )
userFields[ f.GetName() ] = f.GetShownText( aSheet, 0, false );
userFields[ f.GetName() ] = f.GetShownText( aSheet, false );
else
userFields[ f.GetName() ] = f.GetText();
}
@ -321,7 +321,7 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl )
xproperty->AddAttribute( wxT( "name" ), fields[jj].GetCanonicalName() );
if( m_resolveTextVars )
xproperty->AddAttribute( wxT( "value" ), fields[jj].GetShownText( &sheet, 0, false ) );
xproperty->AddAttribute( wxT( "value" ), fields[jj].GetShownText( &sheet, false ) );
else
xproperty->AddAttribute( wxT( "value" ), fields[jj].GetText() );
}
@ -334,7 +334,7 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl )
if( m_resolveTextVars )
// do not allow GetShownText() to add any prefix useful only when displaying
// the field on screen
xproperty->AddAttribute( wxT( "value" ), sheetField.GetShownText( &sheet, 0, false ) );
xproperty->AddAttribute( wxT( "value" ), sheetField.GetShownText( &sheet, false ) );
else
xproperty->AddAttribute( wxT( "value" ), sheetField.GetText() );
}

View File

@ -1066,22 +1066,25 @@ void SCH_EDIT_FRAME::ShowFindReplaceDialog( bool aReplace )
switch( front->Type() )
{
case SCH_SYMBOL_T:
findString = static_cast<SCH_SYMBOL*>( front )->GetValueFieldText( true );
{
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( front );
findString = UnescapeString( symbol->GetField( VALUE_FIELD )->GetText() );
break;
}
case SCH_FIELD_T:
findString = static_cast<SCH_FIELD*>( front )->GetShownText();
findString = UnescapeString( static_cast<SCH_FIELD*>( front )->GetText() );
break;
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T:
case SCH_SHEET_PIN_T:
findString = static_cast<SCH_LABEL_BASE*>( front )->GetShownText();
findString = UnescapeString( static_cast<SCH_LABEL_BASE*>( front )->GetText() );
break;
case SCH_TEXT_T:
findString = static_cast<SCH_TEXT*>( front )->GetShownText();
findString = UnescapeString( static_cast<SCH_TEXT*>( front )->GetText() );
if( findString.Contains( wxT( "\n" ) ) )
findString = findString.Before( '\n' );
@ -1096,9 +1099,10 @@ void SCH_EDIT_FRAME::ShowFindReplaceDialog( bool aReplace )
if( m_findReplaceDialog )
m_findReplaceDialog->Destroy();
m_findReplaceDialog = new DIALOG_SCH_FIND(
this, static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ), wxDefaultPosition,
wxDefaultSize, aReplace ? wxFR_REPLACEDIALOG : 0 );
m_findReplaceDialog = new DIALOG_SCH_FIND( this,
static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ),
wxDefaultPosition, wxDefaultSize,
aReplace ? wxFR_REPLACEDIALOG : 0 );
m_findReplaceDialog->SetFindEntries( m_findStringHistoryList, findString );
m_findReplaceDialog->SetReplaceEntries( m_replaceStringHistoryList );

View File

@ -172,13 +172,14 @@ void SCH_FIELD::SetId( int aId )
}
wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, int aDepth,
bool aAllowExtraText ) const
wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
int aDepth ) const
{
std::function<bool( wxString* )> symbolResolver =
[&]( wxString* token ) -> bool
{
return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( token, aDepth + 1, aPath );
return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( token, aDepth + 1,
aPath );
};
std::function<bool( wxString* )> sheetResolver =
@ -194,7 +195,7 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, int aDepth,
aDepth + 1 );
};
wxString text = EDA_TEXT::GetShownText();
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
if( IsNameShown() && aAllowExtraText )
text = GetName() << wxS( ": " ) << text;
@ -322,7 +323,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
VECTOR2I textpos;
int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
if( ( !IsVisible() && !IsForceVisible() ) || GetShownText().IsEmpty() )
if( ( !IsVisible() && !IsForceVisible() ) || GetShownText( true ).IsEmpty() )
return;
COLOR4D bg = aSettings->GetBackgroundColor();
@ -375,8 +376,9 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
*/
textpos = GetBoundingBox().Centre() + aOffset;
GRPrintText( DC, textpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER,
GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), font );
GRPrintText( DC, textpos, color, GetShownText( true ), orient, GetTextSize(),
GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(),
font );
}
@ -580,7 +582,7 @@ bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) co
{
}
wxString text = GetShownText();
wxString text = UnescapeString( GetText() );
if( !IsVisible() && !searchHiddenFields )
return false;
@ -597,7 +599,7 @@ bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) co
// symbols with multiple parts.
if( aAuxData )
{
text = parentSymbol->GetRef((SCH_SHEET_PATH*) aAuxData );
text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
if( SCH_ITEM::Matches( text, aSearchData ) )
return true;
@ -643,7 +645,6 @@ bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
}
wxString text;
bool resolve = false; // Replace in source text, not shown text
bool isReplaced = false;
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
@ -669,7 +670,7 @@ bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
case VALUE_FIELD:
wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in value field." ) );
text = parentSymbol->GetValueFieldText( resolve );
text = parentSymbol->GetField( VALUE_FIELD )->GetText();
isReplaced = EDA_ITEM::Replace( aSearchData, text );
if( isReplaced )
@ -680,7 +681,7 @@ bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
case FOOTPRINT_FIELD:
wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
text = parentSymbol->GetFootprintFieldText( resolve );
text = parentSymbol->GetField( FOOTPRINT_FIELD )->GetText();
isReplaced = EDA_ITEM::Replace( aSearchData, text );
if( isReplaced )
@ -722,7 +723,7 @@ void SCH_FIELD::Rotate( const VECTOR2I& aCenter )
wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetShownText() ) );
return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetText() ) );
}
@ -730,10 +731,10 @@ void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_I
{
wxString msg;
aList.emplace_back( _( "Symbol Field" ), GetName() );
aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Text" ), UnescapeString( GetText() ) );
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
@ -901,7 +902,7 @@ BITMAPS SCH_FIELD::GetMenuImage() const
bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
// Do not hit test hidden or empty fields.
if( !IsVisible() || GetShownText().IsEmpty() )
if( !IsVisible() || GetShownText( true ).IsEmpty() )
return false;
BOX2I rect = GetBoundingBox();
@ -921,7 +922,7 @@ bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
// Do not hit test hidden fields.
if( !IsVisible() || GetShownText().IsEmpty() )
if( !IsVisible() || GetShownText( true ).IsEmpty() )
return false;
BOX2I rect = aRect;
@ -943,7 +944,7 @@ bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co
void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
{
if( GetShownText().IsEmpty() || aBackground )
if( GetShownText( true ).IsEmpty() || aBackground )
return;
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
@ -1023,7 +1024,7 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
attrs.m_Angle = orient;
attrs.m_Multiline = false;
aPlotter->PlotText( textpos, color, GetShownText(), attrs, font );
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font );
if( IsHypertext() )
{

Some files were not shown because too many files have changed in this diff Show More