From 9f2be3714f02cfe773e758215b35c221d4cac530 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 28 May 2020 14:36:54 +0100 Subject: [PATCH] Add unresolved variable testing for worksheet items. --- common/settings/color_settings.cpp | 4 ++-- eeschema/dialogs/dialog_erc.cpp | 2 +- eeschema/erc.cpp | 36 +++++++++++++++++++++++++----- eeschema/erc.h | 7 +++++- eeschema/sch_marker.cpp | 2 +- include/ws_proxy_view_item.h | 3 +++ pcbnew/drc/drc.cpp | 3 ++- pcbnew/drc/drc_textvar_tester.cpp | 35 ++++++++++++++++++++++++++--- pcbnew/drc/drc_textvar_tester.h | 7 +++--- 9 files changed, 81 insertions(+), 18 deletions(-) diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index 40d540cae0..c2eddaa27a 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -72,8 +72,8 @@ COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) : CLR( "schematic.component_body", LAYER_DEVICE_BACKGROUND, COLOR4D( LIGHTYELLOW ) ); CLR( "schematic.component_outline", LAYER_DEVICE, COLOR4D( RED ) ); CLR( "schematic.cursor", LAYER_SCHEMATIC_CURSOR, COLOR4D( BLACK ) ); - CLR( "schematic.erc_error", LAYER_ERC_ERR, COLOR4D( RED ).WithAlpha( 0.8 ) ); - CLR( "schematic.erc_warning", LAYER_ERC_WARN, COLOR4D( GREEN ).WithAlpha( 0.8 ) ); + CLR( "schematic.erc_error", LAYER_ERC_ERR, COLOR4D( PURERED ).WithAlpha( 0.8 ) ); + CLR( "schematic.erc_warning", LAYER_ERC_WARN, COLOR4D( PUREGREEN ).WithAlpha( 0.8 ) ); CLR( "schematic.fields", LAYER_FIELDS, COLOR4D( MAGENTA ) ); CLR( "schematic.grid", LAYER_SCHEMATIC_GRID, COLOR4D( DARKGRAY ) ); CLR( "schematic.grid_axes", LAYER_SCHEMATIC_GRID_AXES, COLOR4D( BLUE ) ); diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 4c23254b2a..f1b991c19a 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -323,7 +323,7 @@ void DIALOG_ERC::TestErc( REPORTER& aReporter ) } if( settings->IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) ) - TestTextVars( sch ); + TestTextVars( sch, m_parent->GetCanvas()->GetView()->GetWorksheet() ); // Display diags: m_markerTreeModel->SetProvider( m_markerProvider ); diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index ac23cbb6cb..c89dcb9900 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -29,7 +29,6 @@ */ #include -#include #include #include #include @@ -40,6 +39,8 @@ #include #include #include +#include +#include /* ERC tests : @@ -171,7 +172,7 @@ int TestDuplicateSheetNames( SCHEMATIC* aSchematic, bool aCreateMarker ) for( size_t i = 0; i < list.size(); i++ ) { - SCH_SHEET* item = list[i]; + SCH_SHEET* sheet = list[i]; for( size_t j = i + 1; j < list.size(); j++ ) { @@ -180,14 +181,14 @@ int TestDuplicateSheetNames( SCHEMATIC* aSchematic, 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( item->GetName().CmpNoCase( test_item->GetName() ) == 0 ) + if( sheet->GetName().CmpNoCase( test_item->GetName() ) == 0 ) { if( aCreateMarker ) { ERC_ITEM* ercItem = new ERC_ITEM( ERCE_DUPLICATE_SHEET_NAME ); - ercItem->SetItems( item, test_item ); + ercItem->SetItems( sheet, test_item ); - SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() ); + SCH_MARKER* marker = new SCH_MARKER( ercItem, sheet->GetPosition() ); screen->Append( marker ); } @@ -201,8 +202,16 @@ int TestDuplicateSheetNames( SCHEMATIC* aSchematic, bool aCreateMarker ) } -void TestTextVars( SCHEMATIC* aSchematic ) +void TestTextVars( SCHEMATIC* aSchematic, KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { + WS_DRAW_ITEM_LIST wsItems; + + if( aWorksheet ) + { + wsItems.SetMilsToIUfactor( IU_PER_MILS ); + wsItems.BuildWorkSheetGraphicList( aWorksheet->GetPageInfo(), aWorksheet->GetTitleBlock() ); + } + SCH_SCREENS screens( aSchematic->Root() ); for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) @@ -269,6 +278,21 @@ void TestTextVars( SCHEMATIC* aSchematic ) } } } + + for( WS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() ) + { + if( WS_DRAW_ITEM_TEXT* text = dynamic_cast( item ) ) + { + if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) + { + ERC_ITEM* ercItem = new ERC_ITEM( ERCE_UNRESOLVED_VARIABLE ); + ercItem->SetErrorMessage( _( "Unresolved text variable in worksheet." ) ); + + SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() ); + screen->Append( marker ); + } + } + } } } diff --git a/eeschema/erc.h b/eeschema/erc.h index 951d8c1f02..55ef881a91 100644 --- a/eeschema/erc.h +++ b/eeschema/erc.h @@ -36,6 +36,11 @@ class NETLIST_OBJECT_LIST; class SCH_SHEET_LIST; class SCHEMATIC; +namespace KIGFX +{ +class WS_PROXY_VIEW_ITEM; +} + /* For ERC markers: error types (used in diags, and to set the color): */ enum errortype @@ -122,7 +127,7 @@ int TestDuplicateSheetNames( SCHEMATIC* aSchematic, bool aCreateMarker ); * Function TestTextVars() * Checks for any unresolved text variable references. */ -void TestTextVars( SCHEMATIC* aSchematic ); +void TestTextVars( SCHEMATIC* aSchematic, KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); /** * Checks that there are not conflicting bus alias definitions in the schematic diff --git a/eeschema/sch_marker.cpp b/eeschema/sch_marker.cpp index 642ee4f362..24ef62a2c2 100644 --- a/eeschema/sch_marker.cpp +++ b/eeschema/sch_marker.cpp @@ -37,7 +37,7 @@ #include /// Factor to convert the maker unit shape to internal units: -#define SCALING_FACTOR Millimeter2iu( 0.1 ) +#define SCALING_FACTOR Millimeter2iu( 0.15 ) SCH_MARKER::SCH_MARKER( ERC_ITEM* aItem, const wxPoint& aPos ) : diff --git a/include/ws_proxy_view_item.h b/include/ws_proxy_view_item.h index f6e4372368..582a3e72da 100644 --- a/include/ws_proxy_view_item.h +++ b/include/ws_proxy_view_item.h @@ -80,6 +80,9 @@ public: m_colorLayer = aLayerId; } + const PAGE_INFO& GetPageInfo() { return *m_pageInfo; } + const TITLE_BLOCK& GetTitleBlock() { return *m_titleBlock; } + /// @copydoc VIEW_ITEM::ViewBBox() const BOX2I ViewBBox() const override; diff --git a/pcbnew/drc/drc.cpp b/pcbnew/drc/drc.cpp index cd14dfa404..0f86891809 100644 --- a/pcbnew/drc/drc.cpp +++ b/pcbnew/drc/drc.cpp @@ -633,7 +633,8 @@ void DRC::RunTests( wxTextCtrl* aMessages ) DRC_TEXTVAR_TESTER tester( [&]( MARKER_PCB* aMarker ) { addMarkerToPcb( commit, aMarker ); - } ); + }, + m_editFrame->GetCanvas()->GetWorksheet() ); tester.RunDRC( userUnits(), *m_pcb ); } diff --git a/pcbnew/drc/drc_textvar_tester.cpp b/pcbnew/drc/drc_textvar_tester.cpp index 900b98b488..c845f299b8 100644 --- a/pcbnew/drc/drc_textvar_tester.cpp +++ b/pcbnew/drc/drc_textvar_tester.cpp @@ -26,12 +26,15 @@ #include #include +#include +#include - -DRC_TEXTVAR_TESTER::DRC_TEXTVAR_TESTER( MARKER_HANDLER aMarkerHandler ) : +DRC_TEXTVAR_TESTER::DRC_TEXTVAR_TESTER( MARKER_HANDLER aMarkerHandler, + KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) : DRC_TEST_PROVIDER( std::move( aMarkerHandler ) ), m_units( EDA_UNITS::MILLIMETRES ), - m_board( nullptr ) + m_board( nullptr ), + m_worksheet( aWorksheet ) { } @@ -81,6 +84,32 @@ bool DRC_TEXTVAR_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) } } + WS_DRAW_ITEM_LIST wsItems; + + if( m_worksheet ) + { + wsItems.SetMilsToIUfactor( IU_PER_MILS ); + wsItems.BuildWorkSheetGraphicList( m_worksheet->GetPageInfo(), + m_worksheet->GetTitleBlock() ); + + for( WS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() ) + { + if( WS_DRAW_ITEM_TEXT* text = dynamic_cast( item ) ) + { + if( text->GetShownText().Matches( wxT( "*${*}*" ) ) ) + { + DRC_ITEM* drcItem = new DRC_ITEM( DRCE_UNRESOLVED_VARIABLE ); + drcItem->SetErrorMessage( _( "Unresolved text variable in worksheet." ) ); + + HandleMarker( new MARKER_PCB( drcItem, text->GetPosition() ) ); + success = false; + } + } + } + } + + // JEY TODO: Test text vars in worksheet... + return success; } diff --git a/pcbnew/drc/drc_textvar_tester.h b/pcbnew/drc/drc_textvar_tester.h index b46ba5cd2a..678d5b878f 100644 --- a/pcbnew/drc/drc_textvar_tester.h +++ b/pcbnew/drc/drc_textvar_tester.h @@ -34,15 +34,16 @@ class BOARD; class DRC_TEXTVAR_TESTER : public DRC_TEST_PROVIDER { public: - DRC_TEXTVAR_TESTER( MARKER_HANDLER aMarkerHandler ); + DRC_TEXTVAR_TESTER( MARKER_HANDLER aMarkerHandler, KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); virtual ~DRC_TEXTVAR_TESTER() {}; bool RunDRC( EDA_UNITS aUnits, BOARD& aBoard ) override; private: - EDA_UNITS m_units; - BOARD* m_board; + EDA_UNITS m_units; + BOARD* m_board; + KIGFX::WS_PROXY_VIEW_ITEM* m_worksheet; }; #endif // DRC_TEXTVAR_TESTER__H