@ -21,6 +21,8 @@
*/
# include <wx/hyperlink.h>
# include <advanced_config.h>
# include <functional>
using namespace std : : placeholders ;
# include <board.h>
@ -51,9 +53,7 @@ using namespace std::placeholders;
# include "pns_kicad_iface.h"
# ifdef DEBUG
# include <plugins/kicad/kicad_plugin.h>
# endif
using namespace KIGFX ;
@ -480,51 +480,80 @@ void ROUTER_TOOL::Reset( RESET_REASON aReason )
TOOL_BASE : : Reset ( aReason ) ;
}
// Saves the complete event log and the dump of the PCB, allowing us to
// recreate hard-to-find P&S quirks and bugs.
void ROUTER_TOOL : : handleCommonEvents ( const TOOL_EVENT & aEvent )
void ROUTER_TOOL : : saveRouterDebugLog ( )
{
# ifdef DEBUG
if ( aEvent . IsKeyPressed ( ) )
{
switch ( aEvent . KeyCode ( ) )
{
case ' 0 ' :
{
auto logger = m_router - > Logger ( ) ;
auto logger = m_router - > Logger ( ) ;
if ( ! logger )
return ;
if ( ! logger )
return ;
FILE * f = fopen ( " /tmp/pns.log " , " wb " ) ;
wxLogTrace ( " PNS " , " saving drag/route log... \n " ) ;
wxString cwd = wxGetCwd ( ) ;
const auto & events = logger - > GetEvents ( ) ;
wxFileName fname_log ( cwd ) ;
fname_log . SetName ( " pns.log " ) ;
for ( auto evt : events )
{
wxString id = " null " ;
wxFileName fname_dump ( cwd ) ;
fname_dump . SetName ( " pns.dump " ) ;
if ( evt . item & & evt . item - > Parent ( ) )
id = evt . item - > Parent ( ) - > m_Uuid . AsString ( ) ;
wxString msg = wxString : : Format ( _ ( " Event file: %s \n Board dump: %s " ) , fname_log . GetFullPath ( ) , fname_log . GetFullPath ( ) ) ;
fprintf ( f , " event %d %d %d %s \n " , evt . p . x , evt . p . y , evt . type ,
( const char * ) id . c_str ( ) ) ;
}
int rv = OKOrCancelDialog ( nullptr , _ ( " Save router log " ) , _ ( " Would you like to save the router \n event log for debugging purposes? " ) , msg , _ ( " OK " ) , _ ( " Cancel " ) ) ;
fclose ( f ) ;
if ( ! rv )
return ;
// 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.
FILE * f = fopen ( fname_log . GetFullPath ( ) . c_str ( ) , " wb " ) ;
PCB_IO pcb_io ;
// save base router configuration (mode, etc.)
fprintf ( f , " config %d %d %d \n " ,
m_router - > Settings ( ) . Mode ( ) ,
m_router - > Settings ( ) . RemoveLoops ( ) ? 1 : 0 ,
m_router - > Settings ( ) . GetFixAllSegments ( ) ? 1 : 0
) ;
pcb_io . Save ( " /tmp/pns.dump " , m_iface - > GetBoard ( ) , nullptr ) ;
const auto & events = logger - > GetEvents ( ) ;
break ;
}
}
for ( auto evt : events )
{
wxString id = " null " ;
if ( evt . item & & evt . item - > Parent ( ) )
id = evt . item - > Parent ( ) - > m_Uuid . AsString ( ) ;
fprintf ( f , " event %d %d %d %s \n " , evt . p . x , evt . p . y , evt . type ,
( const char * ) id . c_str ( ) ) ;
}
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.
PCB_IO pcb_io ;
pcb_io . Save ( fname_dump . GetFullPath ( ) , m_iface - > GetBoard ( ) , nullptr ) ;
}
void ROUTER_TOOL : : handleCommonEvents ( TOOL_EVENT & aEvent )
{
if ( ! aEvent . IsKeyPressed ( ) )
return ;
switch ( aEvent . KeyCode ( ) )
{
case ' 0 ' :
if ( ! ADVANCED_CFG : : GetCfg ( ) . m_ShowRouterDebugGraphics )
return ;
saveRouterDebugLog ( ) ;
aEvent . SetPassEvent ( false ) ;
break ;
default :
break ;
}
# endif
}
@ -1684,6 +1713,8 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
{
evt - > SetPassEvent ( ) ;
}
handleCommonEvents ( * evt ) ;
}
if ( footprint )