router: extend dump format to support automatic regressions tests of interactive routing scenarios

This commit is contained in:
Tomasz Wlostowski 2022-10-24 00:34:42 +02:00
parent f25d449d5f
commit 65507e7186
12 changed files with 133 additions and 22 deletions

View File

@ -215,4 +215,13 @@ ITEM::~ITEM()
{
}
const std::string ITEM::Format() const
{
std::stringstream ss;
ss << KindStr() << " ";
ss << "net " << m_net << " ";
ss << "layers " << m_layers.Start() << " " << m_layers.End();
return ss.str();
}
}

View File

@ -245,6 +245,8 @@ public:
void SetIsCompoundShapePrimitive() { m_isCompoundShapePrimitive = true; }
bool IsCompoundShapePrimitive() const { return m_isCompoundShapePrimitive; }
virtual const std::string Format() const;
private:
bool collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly, int aOverrideClearance ) const;

View File

@ -1225,6 +1225,7 @@ bool LINE::HasLockedSegments() const
return false;
}
void LINE::Clear()
{
m_hasVia = false;
@ -1232,5 +1233,13 @@ void LINE::Clear()
}
const std::string SEGMENT::Format( ) const
{
std::stringstream ss;
ss << ITEM::Format() << " ";
ss << m_seg.Format( false );
return ss.str();
}
}

View File

@ -61,7 +61,7 @@ void LOGGER::Save( const std::string& aFilename )
}
void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item )
void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item, const SIZES_SETTINGS* sizes )
{
LOGGER::EVENT_ENTRY ent;
@ -69,6 +69,10 @@ void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item
ent.p = pos;
ent.uuid = KIID(0);
if( sizes )
{
ent.sizes = *sizes;
}
if( item && item->Parent() )
ent.uuid = item->Parent()->m_Uuid;

View File

@ -30,6 +30,8 @@
#include <math/vector2d.h>
#include <kiid.h>
#include "pns_sizes_settings.h"
class SHAPE_LINE_CHAIN;
class SHAPE;
@ -54,6 +56,7 @@ public:
VECTOR2I p;
EVENT_TYPE type;
KIID uuid;
SIZES_SETTINGS sizes;
};
LOGGER();
@ -61,7 +64,7 @@ public:
void Save( const std::string& aFilename );
void Clear();
void Log( EVENT_TYPE evt, const VECTOR2I& pos = VECTOR2I(), const ITEM* item = nullptr );
void Log( EVENT_TYPE evt, const VECTOR2I& pos = VECTOR2I(), const ITEM* item = nullptr, const SIZES_SETTINGS* sizes = nullptr );
const std::vector<EVENT_ENTRY>& GetEvents()
{

View File

@ -422,9 +422,10 @@ public:
return m_collisionQueryScope;
}
private:
void Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant = false );
private:
/// nodes are not copyable
NODE( const NODE& aB );
NODE& operator=( const NODE& aB );

View File

@ -432,15 +432,16 @@ bool ROUTER::StartRouting( const VECTOR2I& aP, ITEM* aStartItem, int aLayer )
m_placer->SetDebugDecorator( m_iface->GetDebugDecorator() );
m_placer->SetLogger( m_logger );
if( m_logger )
{
m_logger->Clear();
m_logger->Log( LOGGER::EVT_START_ROUTE, aP, aStartItem );
}
if( m_placer->Start( aP, aStartItem ) )
{
m_state = ROUTE_TRACK;
if( m_logger )
{
m_logger->Clear();
m_logger->Log( LOGGER::EVT_START_ROUTE, aP, aStartItem, &m_sizes );
}
return true;
}
else
@ -755,6 +756,36 @@ bool ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem )
return ret;
}
bool ROUTER::GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS::ITEM*>& aAdded )
{
NODE *node;
ITEM_SET current;
if( m_state == ROUTE_TRACK )
{
node = m_placer->CurrentNode( true );
current = m_placer->Traces();
}
else if ( m_state == DRAG_SEGMENT )
{
node = m_dragger->CurrentNode();
current = m_dragger->Traces();
}
std::unique_ptr<NODE> tmpNode( node->Branch() );
for( auto item : current )
{
std::unique_ptr<ITEM> ip( item.item->Clone() );
tmpNode->Add( std::move( ip ) );
}
tmpNode->GetUpdatedItems( aRemoved, aAdded );
//printf("added %d removed %d\n", aRemoved.size(), aAdded.size() );
return true;
}
void ROUTER::CommitRouting( NODE* aNode )
{
@ -918,7 +949,7 @@ void ROUTER::ToggleViaPlacement()
if( m_logger )
{
m_logger->Log( LOGGER::EVT_TOGGLE_VIA );
m_logger->Log( LOGGER::EVT_TOGGLE_VIA, VECTOR2I(), nullptr, &m_sizes );
}
}
}

View File

@ -150,6 +150,7 @@ public:
void UndoLastSegment();
void CommitRouting();
bool GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS::ITEM*>& aAdded );
void StopRouting();
void ClearViewDecorations();

View File

@ -117,6 +117,13 @@ public:
return 2;
}
virtual const std::string Format() const override;
void SetShape( const SHAPE_SEGMENT& aShape )
{
m_seg = aShape;
}
private:
SHAPE_SEGMENT m_seg;
};

View File

@ -166,6 +166,7 @@ OPT_BOX2I VIA::ChangedArea( const VIA* aOther ) const
return OPT_BOX2I();
}
const VIA_HANDLE VIA::MakeHandle() const
{
VIA_HANDLE h;
@ -176,4 +177,13 @@ const VIA_HANDLE VIA::MakeHandle() const
return h;
}
const std::string VIA::Format( ) const
{
std::stringstream ss;
ss << ITEM::Format() << " drill " << m_drill << " ";
ss << m_shape.Format( false );
return ss.str();
}
}

View File

@ -160,6 +160,8 @@ public:
const VIA_HANDLE MakeHandle() const;
virtual const std::string Format() const override;
private:
int m_diameter;
int m_drill;

View File

@ -24,6 +24,10 @@
#include <advanced_config.h>
#include <functional>
#include <iomanip>
#include <utility>
#include <sstream>
using namespace std::placeholders;
#include <board.h>
#include <board_design_settings.h>
@ -557,6 +561,10 @@ void ROUTER_TOOL::saveRouterDebugLog()
fname_dump.SetPath( cwd );
fname_dump.SetName( "pns.dump" );
wxFileName fname_settings( cwd );
fname_settings.SetPath( cwd );
fname_settings.SetName( "pns.settings" );
wxString msg = wxString::Format( _( "Event file: %s\nBoard dump: %s" ), fname_log.GetFullPath(), fname_log.GetFullPath() );
int rv = OKOrCancelDialog( nullptr, _("Save router log"), _("Would you like to save the router\nevent log for debugging purposes?"), msg, _("OK"), _("Cancel") );
@ -564,26 +572,30 @@ void ROUTER_TOOL::saveRouterDebugLog()
if( !rv )
return;
FILE *f = fopen( fname_log.GetFullPath().c_str(), "wb" );
FILE *f = fopen( fname_settings.GetFullPath().c_str(), "wb" );
std::string settingsStr = m_router->Settings().FormatAsString();
fprintf(f,"%s\n", settingsStr.c_str( ) );
fclose(f);
// save base router configuration (mode, etc.)
fprintf(f, "config %d %d %d %d\n",
m_router->Settings().Mode(),
m_router->Settings().RemoveLoops() ? 1 : 0,
m_router->Settings().GetFixAllSegments() ? 1 : 0,
static_cast<int>( m_router->Settings().GetCornerMode() )
);
f = fopen( fname_log.GetFullPath().c_str(), "wb" );
fprintf(f, "mode %d\n", m_router->Mode() );
const auto& events = logger->GetEvents();
for( const auto& evt : events)
{
fprintf( f, "event %d %d %d %s\n", evt.p.x, evt.p.y, evt.type,
static_cast<const char*>( evt.uuid.AsString().c_str() ) );
fprintf( f, "event %d %d %d %s %d %d %d %d %d %d %d\n", evt.p.x, evt.p.y, evt.type,
static_cast<const char*>( evt.uuid.AsString().c_str() ),
evt.sizes.TrackWidth(),
evt.sizes.ViaDiameter(),
evt.sizes.ViaDrill(),
evt.sizes.TrackWidthIsExplicit() ? 1: 0,
evt.sizes.GetLayerBottom(),
evt.sizes.GetLayerTop(),
evt.sizes.ViaType() );
}
fclose( f );
// Export as *.kicad_pcb format, using a strategy which is specifically chosen
// as an example on how it could also be used to send it to the system clipboard.
@ -593,6 +605,26 @@ void ROUTER_TOOL::saveRouterDebugLog()
PROJECT* prj = m_iface->GetBoard()->GetProject();
prj->GetProjectFile().SaveAs( cwd, "pns" );
std::vector<PNS::ITEM*> added, removed;
if( !m_router->GetUpdatedItems( removed, added ) )
{
fclose( f );
return;
}
for( auto item : removed )
{
fprintf(f, "removed %s\n", item->Parent()->m_Uuid.AsString().c_str().AsChar() );
}
for( auto item : added )
{
fprintf(f, "added %s\n", item->Format().c_str() );
}
fclose( f );
}