Add unresolved variable testing for worksheet items.

This commit is contained in:
Jeff Young 2020-05-28 14:36:54 +01:00
parent e9e72bd8e4
commit 9f2be3714f
9 changed files with 81 additions and 18 deletions

View File

@ -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 ) );

View File

@ -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 );

View File

@ -29,7 +29,6 @@
*/
#include <fctsys.h>
#include <sch_draw_panel.h>
#include <kicad_string.h>
#include <sch_edit_frame.h>
#include <netlist_object.h>
@ -40,6 +39,8 @@
#include <sch_reference_list.h>
#include <schematic.h>
#include <wx/ffile.h>
#include <ws_draw_item.h>
#include <ws_proxy_view_item.h>
/* 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<WS_DRAW_ITEM_TEXT*>( 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 );
}
}
}
}
}

View File

@ -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

View File

@ -37,7 +37,7 @@
#include <erc_item.h>
/// 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 ) :

View File

@ -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;

View File

@ -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 );
}

View File

@ -26,12 +26,15 @@
#include <class_module.h>
#include <class_pcb_text.h>
#include <ws_draw_item.h>
#include <ws_proxy_view_item.h>
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<WS_DRAW_ITEM_TEXT*>( 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;
}

View File

@ -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