diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index b0821b4ca5..5dd8f76510 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -191,20 +191,26 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT std::function symbolResolver = [&]( wxString* token ) -> bool { - return static_cast( m_parent )->ResolveTextVar( aPath, token, aDepth + 1 ); + SCH_SYMBOL* symbol = static_cast( m_parent ); + return symbol->ResolveTextVar( aPath, token, aDepth + 1 ); }; std::function sheetResolver = [&]( wxString* token ) -> bool { - return static_cast( m_parent )->ResolveTextVar( token, aDepth + 1 ); + SCH_SHEET* sheet = static_cast( m_parent ); + + SCH_SHEET_PATH path = *aPath; + path.push_back( sheet ); + + return sheet->ResolveTextVar( &path, token, aDepth + 1 ); }; std::function labelResolver = [&]( wxString* token ) -> bool { - return static_cast( m_parent )->ResolveTextVar( aPath, token, - aDepth + 1 ); + SCH_LABEL_BASE* label = static_cast( m_parent ); + return label->ResolveTextVar( aPath, token, aDepth + 1 ); }; wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth ); diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 3e11b07a58..e70289364c 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -769,7 +769,11 @@ bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* toke "(.([0-9])?([a-zA-Z]*))?" "$" ) ); - if( !Schematic() ) + wxCHECK( aPath, false ); + + SCHEMATIC* schematic = Schematic(); + + if( !schematic ) return false; if( operatingPoint.Matches( *token ) ) @@ -788,14 +792,14 @@ bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* toke *token = wxS( "?" ); if( connection ) - *token = Schematic()->GetOperatingPoint( connection->Name( false ), precision, range ); + *token = schematic->GetOperatingPoint( connection->Name( false ), precision, range ); return true; } if( token->Contains( ':' ) ) { - if( Schematic()->ResolveCrossReference( token, aDepth + 1 ) ) + if( schematic->ResolveCrossReference( token, aDepth + 1 ) ) return true; } @@ -852,7 +856,10 @@ bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* toke { SCH_SHEET* sheet = static_cast( m_parent ); - if( sheet->ResolveTextVar( token, aDepth + 1 ) ) + SCH_SHEET_PATH path = *aPath; + path.push_back( sheet ); + + if( sheet->ResolveTextVar( &path, token, aDepth + 1 ) ) return true; } else if( aPath && aPath->Last() ) @@ -860,7 +867,7 @@ bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* toke if( aPath->Last()->ResolveTextVar( aPath, token, aDepth + 1 ) ) return true; } - else if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) + else if( SCH_SHEET* sheet = schematic->CurrentSheet().Last() ) { if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) ) return true; @@ -1769,13 +1776,20 @@ void SCH_GLOBALLABEL::SetSpinStyle( SPIN_STYLE aSpinStyle ) bool SCH_GLOBALLABEL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const { - if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() ) - { - SCHEMATIC_SETTINGS& settings = Schematic()->Settings(); - wxString ref; - auto it = Schematic()->GetPageRefsMap().find( GetText() ); + wxCHECK( aPath, false ); - if( it == Schematic()->GetPageRefsMap().end() ) + SCHEMATIC* schematic = Schematic(); + + if( !schematic ) + return false; + + if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) ) + { + SCHEMATIC_SETTINGS& settings = schematic->Settings(); + wxString ref; + auto it = schematic->GetPageRefsMap().find( GetText() ); + + if( it == schematic->GetPageRefsMap().end() ) { ref = "?"; } @@ -1788,11 +1802,11 @@ bool SCH_GLOBALLABEL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* tok if( !settings.m_IntersheetRefsListOwnPage ) { - int currentPage = Schematic()->CurrentSheet().GetVirtualPageNumber(); + int currentPage = schematic->CurrentSheet().GetVirtualPageNumber(); alg::delete_matching( pageListCopy, currentPage ); } - std::map sheetPages = Schematic()->GetVirtualPageToSheetPagesMap(); + std::map sheetPages = schematic->GetVirtualPageToSheetPagesMap(); if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) ) { diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 3ee9924a3c..87faf21668 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -236,12 +236,16 @@ void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const { - if( !Schematic() ) + wxCHECK( aPath, false ); + + SCHEMATIC* schematic = Schematic(); + + if( !schematic ) return false; if( token->Contains( ':' ) ) { - if( Schematic()->ResolveCrossReference( token, aDepth + 1 ) ) + if( schematic->ResolveCrossReference( token, aDepth + 1 ) ) return true; } @@ -263,8 +267,7 @@ bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, in } } - SCH_SHEET_PATH sheetPath = aPath ? *aPath : findSelf(); - PROJECT* project = &Schematic()->Prj(); + PROJECT* project = &schematic->Prj(); // We cannot resolve text variables initially on load as we need to first load the screen and // then parse the hierarchy. So skip the resolution if the screen isn't set yet @@ -275,33 +278,34 @@ bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, in if( token->IsSameAs( wxT( "#" ) ) ) { - *token = wxString::Format( "%s", sheetPath.GetPageNumber() ); + *token = wxString::Format( "%s", aPath->GetPageNumber() ); return true; } else if( token->IsSameAs( wxT( "##" ) ) ) { - SCH_SHEET_LIST sheetList = Schematic()->GetSheets(); + SCH_SHEET_LIST sheetList = schematic->GetSheets(); *token = wxString::Format( wxT( "%d" ), (int) sheetList.size() ); return true; } else if( token->IsSameAs( wxT( "SHEETPATH" ) ) ) { - *token = sheetPath.PathHumanReadable(); + *token = aPath->PathHumanReadable(); return true; } // See if parent can resolve it (these will recurse to ancestors) - if( sheetPath.size() >= 2 ) + if( aPath->size() >= 2 ) { - sheetPath.pop_back(); + SCH_SHEET_PATH path = *aPath; + path.pop_back(); - if( sheetPath.Last()->ResolveTextVar( &sheetPath, token, aDepth + 1 ) ) + if( path.Last()->ResolveTextVar( aPath, token, aDepth + 1 ) ) return true; } else { - if( Schematic()->ResolveTextVar( token, aDepth + 1 ) ) + if( schematic->ResolveTextVar( token, aDepth + 1 ) ) return true; } diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 453e9d2f2b..e6da040f8c 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -157,10 +157,6 @@ public: * @param aDepth is a counter to limit recursion and circular references. */ bool ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth = 0 ) const; - bool ResolveTextVar( wxString* token, int aDepth = 0 ) - { - return ResolveTextVar( nullptr, token, aDepth ); - } void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index a74404932e..f58d8691b3 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -1274,10 +1274,11 @@ bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, i "(.([0-9])?([a-zA-Z]*))?" // format "$" ) ); + wxCHECK( aPath, false ); + SCHEMATIC* schematic = Schematic(); - // SCH_SYMBOL object has no context outside a schematic and the instance on a path. - if( !schematic || !aPath ) + if( !schematic ) return false; if( operatingPoint.Matches( *token ) ) diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index f27bc6d6f5..41ed66c8bb 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -292,15 +292,13 @@ wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtr if( aPath ) sheet = aPath->Last(); - else if( Schematic() ) - sheet = Schematic()->CurrentSheet().Last(); std::function textResolver = [&]( wxString* token ) -> bool { if( sheet ) { - if( sheet->ResolveTextVar( token, aDepth + 1 ) ) + if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) ) return true; } @@ -320,7 +318,7 @@ wxString SCH_TEXTBOX::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtr if( !font ) font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() ); - VECTOR2D size = GetEnd() - GetStart(); + VECTOR2I size = GetEnd() - GetStart(); int colWidth = GetTextAngle() == ANGLE_HORIZONTAL ? size.x : size.y; colWidth = abs( colWidth ) - GetTextMargin() * 2; diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 64e1e218fa..ffa77937bf 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -349,7 +349,9 @@ bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const { SCH_SHEET* refSheet = static_cast( refItem ); - if( refSheet->ResolveTextVar( &remainder, aDepth + 1 ) ) + sheetPath.push_back( refSheet ); + + if( refSheet->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) ) *token = remainder; return true; // Cross-reference is resolved whether or not the actual textvar was