PNS Log Viewer: Add Open / Save as GUI functions

This commit is contained in:
Roberto Fernandez Bautista 2023-08-08 20:43:42 +02:00
parent 6ba250a4e6
commit fd7781510e
10 changed files with 140 additions and 47 deletions

View File

@ -177,6 +177,7 @@ void PCB_TEST_FRAME_BASE::createView( wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL
PCB_TEST_FRAME_BASE::PCB_TEST_FRAME_BASE()
{
m_mruPath = wxGetCwd();
}

View File

@ -49,7 +49,7 @@ namespace KIGFX {
class PCB_TEST_FRAME_BASE
{
public:
PCB_TEST_FRAME_BASE();
PCB_TEST_FRAME_BASE();
virtual ~PCB_TEST_FRAME_BASE();
virtual void SetBoard( std::shared_ptr<BOARD> b);
@ -68,6 +68,7 @@ protected:
std::shared_ptr < PCB_DRAW_PANEL_GAL > m_galPanel;
std::shared_ptr < BOARD > m_board;
KIGFX::GAL_DISPLAY_OPTIONS m_displayOptions;
wxString m_mruPath;
#ifdef USE_TOOL_MANAGER
unique_ptr < TOOL_MANAGER > m_toolManager;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<FileVersion major="1" minor="16" />
<object class="Project" expanded="1">
<property name="class_decoration">; </property>
<property name="code_generation">C++</property>
@ -52,6 +52,7 @@
<property name="subclass">; ; forward_declare</property>
<property name="title">P&amp;S Log Viewer</property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
@ -81,19 +82,33 @@
<property name="label">File</property>
<property name="name">m_menu1</property>
<property name="permission">protected</property>
<object class="wxMenuItem" expanded="0">
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Reload</property>
<property name="name">m_menuItem1</property>
<property name="label">Open</property>
<property name="name">m_menuOpen</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">onReload</event>
<event name="OnMenuSelection">onOpen</event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Save as...</property>
<property name="name">m_menuSaveAs</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">onSaveAs</event>
</object>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
@ -103,7 +118,7 @@
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Exit</property>
<property name="name">m_menuItem2</property>
<property name="name">m_menuExit</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
@ -596,11 +611,12 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnText">onFilterText</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
@ -665,7 +681,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
@ -730,7 +746,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
@ -867,11 +883,11 @@
<property name="permission">protected</property>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="0">
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer6</property>
<property name="orient">wxVERTICAL</property>

View File

@ -25,7 +25,7 @@
#include <wx/cmdline.h>
#include <qa_utils/utility_registry.h>
#include <pcbnew_utils/board_test_utils.h>
#include <advanced_config.h>
#include "pns_log_file.h"
#include "pns_log_viewer_frame.h"
@ -62,7 +62,7 @@ static const wxCmdLineEntryDesc g_cmdLineDesc[] = {
"filename",
_( "log file name (no extensions)" ).mb_str(),
wxCMD_LINE_VAL_STRING,
wxCMD_LINE_OPTION_MANDATORY,
wxCMD_LINE_PARAM_OPTIONAL,
},
{ wxCMD_LINE_NONE }
};
@ -76,7 +76,7 @@ int replay_main_func( int argc, char* argv[] )
"in debug KiCad builds." ) );
int cmd_parsed_ok = cl_parser.Parse();
if( cl_parser.Found("help") )
{
return 0;
@ -88,7 +88,6 @@ int replay_main_func( int argc, char* argv[] )
return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE;
}
wxString filename;
#if 0
long iter_limit = 256;
@ -97,17 +96,12 @@ int replay_main_func( int argc, char* argv[] )
cl_parser.Found( "steps-limit", &steps_limit );
#endif
filename = cl_parser.GetParam(0);
auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
PNS_LOG_FILE* logFile = new PNS_LOG_FILE;
KI_TEST::CONSOLE_LOG log;
KI_TEST::CONSOLE_MSG_REPORTER reporter( &log );
logFile->Load( wxFileName( argv[1] ), &reporter );
frame->SetLogFile( logFile );
if( cl_parser.GetParamCount() > 0 )
{
frame->LoadLogFile( cl_parser.GetParam( 0 ) );
}
return 0;
}

View File

@ -255,7 +255,7 @@ const std::set<PNS::ITEM*> deduplicate( const std::vector<PNS::ITEM*>& items )
rv.insert( item );
}
}
return rv;
}
@ -300,6 +300,21 @@ bool PNS_LOG_FILE::COMMIT_STATE::Compare( const PNS_LOG_FILE::COMMIT_STATE& aOth
}
bool PNS_LOG_FILE::SaveLog( const wxFileName& logFileName, REPORTER* aRpt )
{
std::vector<PNS::ITEM*> dummyHeads; // todo - save heads when we support it in QA
FILE* log_f = wxFopen( logFileName.GetFullPath(), "wb" );
wxString logString = PNS::LOGGER::FormatLogFileAsString( m_mode, m_commitState.m_addedItems,
m_commitState.m_removedIds, dummyHeads,
m_events );
fprintf( log_f, "%s\n", logString.c_str().AsChar() );
fclose( log_f );
return true;
}
bool PNS_LOG_FILE::Load( const wxFileName& logFileName, REPORTER* aRpt )
{
wxFileName fname_log( logFileName );

View File

@ -69,6 +69,9 @@ public:
bool Compare( const COMMIT_STATE& aOther );
};
// Saves a P&S event log only (e.g. after fixing a bug and wanting a new "golden" commit state)
bool SaveLog( const wxFileName& logFileName, REPORTER* aRpt );
// Loads a P&S event log and the associated board file. These two always go together.
bool Load( const wxFileName& logFileName, REPORTER* aRpt );

View File

@ -26,12 +26,15 @@
// (unless you want to improve it).
#include <string>
#include <confirm.h>
#include <wx/clipbrd.h>
#include <pgm_base.h>
#include <profile.h>
#include <reporter.h>
#include <trace_helpers.h>
#include <view/view_overlay.h>
#include <view/view_controls.h>
#include <wildcards_and_files_ext.h>
#include "label_manager.h"
@ -113,7 +116,8 @@ void PNS_LOG_VIEWER_OVERLAY::DrawAnnotations()
}
PNS_LOG_VIEWER_FRAME::PNS_LOG_VIEWER_FRAME( wxFrame* frame ) : PNS_LOG_VIEWER_FRAME_BASE( frame )
PNS_LOG_VIEWER_FRAME::PNS_LOG_VIEWER_FRAME( wxFrame* frame ) :
PNS_LOG_VIEWER_FRAME_BASE( frame ), m_rewindIter( 0 ), m_reporter( &m_consoleLog )
{
LoadSettings();
createView( this, PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
@ -249,6 +253,7 @@ void PNS_LOG_VIEWER_FRAME::drawSimpleShape( SHAPE* aShape, bool aIsSelected, con
}
}
void PNS_LOG_VIEWER_FRAME::drawLoggedItems( int iter )
{
if( !m_logPlayer )
@ -319,6 +324,15 @@ void PNS_LOG_VIEWER_FRAME::drawLoggedItems( int iter )
}
void PNS_LOG_VIEWER_FRAME::LoadLogFile( const wxString& aFile )
{
std::unique_ptr<PNS_LOG_FILE> logFile( new PNS_LOG_FILE );
if( logFile->Load( wxFileName( aFile ), &m_reporter ) )
SetLogFile( logFile.release() );
}
void PNS_LOG_VIEWER_FRAME::SetLogFile( PNS_LOG_FILE* aLog )
{
m_logPlayer.reset( new PNS_LOG_PLAYER );
@ -352,7 +366,6 @@ void PNS_LOG_VIEWER_FRAME::SetLogFile( PNS_LOG_FILE* aLog )
}
void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
{
SetBoard( aBoard );
@ -368,14 +381,51 @@ void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
m_galPanel->GetView()->SetViewport( bbd );
}
void PNS_LOG_VIEWER_FRAME::onReload( wxCommandEvent& event )
void PNS_LOG_VIEWER_FRAME::onOpen( wxCommandEvent& event )
{
event.Skip();
wxFileDialog dlg( this, "Select Log File", m_mruPath, wxEmptyString,
"PNS log files" + AddFileExtListToFilter( { "log" } ),
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() != wxID_CANCEL )
{
wxString logPath = dlg.GetPath();
LoadLogFile( logPath );
m_mruPath = wxFileName( logPath ).GetPath();
}
}
void PNS_LOG_VIEWER_FRAME::onSaveAs( wxCommandEvent& event )
{
if( !m_logFile )
{
DisplayError( this, wxT( "No log file Loaded!" ) );
return;
}
wxFileDialog dlg( this, "New log file", m_mruPath, wxEmptyString,
"PNS log files" + AddFileExtListToFilter( { "log" } ),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() != wxID_CANCEL )
{
// Enforce the extension, wxFileDialog is inept.
wxFileName create_me = EnsureFileExtension( dlg.GetPath(), "log" );
wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
m_logFile->SaveLog( create_me, &m_reporter );
m_mruPath = create_me.GetPath();
}
}
void PNS_LOG_VIEWER_FRAME::onExit( wxCommandEvent& event )
{
event.Skip();
Close();
}
@ -427,6 +477,7 @@ void PNS_LOG_VIEWER_FRAME::onBtnRewindLeft( wxCommandEvent& event )
updateDumpPanel( m_rewindIter );
updatePnsPreviewItems( m_rewindIter );
m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
m_rewindSlider->SetValue( m_rewindIter );
}
}
@ -443,6 +494,7 @@ void PNS_LOG_VIEWER_FRAME::onBtnRewindRight( wxCommandEvent& event )
updateDumpPanel( m_rewindIter );
updatePnsPreviewItems( m_rewindIter );
m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
m_rewindSlider->SetValue( m_rewindIter );
}
}

View File

@ -30,6 +30,7 @@
#include <pcb_painter.h>
#include <pcb_test_frame.h>
#include <pcbnew_utils/board_test_utils.h>
#include "pns_log_file.h"
#include "pns_log_player.h"
@ -50,6 +51,7 @@ public:
PNS_LOG_VIEWER_FRAME( wxFrame* frame );
virtual ~PNS_LOG_VIEWER_FRAME();
void LoadLogFile( const wxString& aFile );
void SetLogFile( PNS_LOG_FILE* aLog );
void SetBoard2( std::shared_ptr<BOARD> aBoard );
@ -65,7 +67,8 @@ private:
void updatePnsPreviewItems( int iter );
bool filterStringMatches( PNS_DEBUG_SHAPE* ent );
virtual void onReload( wxCommandEvent& event ) override;
virtual void onOpen( wxCommandEvent& event ) override;
virtual void onSaveAs( wxCommandEvent& event ) override;
virtual void onExit( wxCommandEvent& event ) override;
virtual void onRewindScroll( wxScrollEvent& event ) override;
virtual void onRewindCountText( wxCommandEvent& event ) override;
@ -91,6 +94,8 @@ private:
bool m_showRPIs = true;
bool m_showVertices = false;
wxString m_searchString;
KI_TEST::CONSOLE_LOG m_consoleLog;
KI_TEST::CONSOLE_MSG_REPORTER m_reporter;
};
class LABEL_MANAGER;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.9.0 Feb 6 2021)
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -15,13 +15,17 @@ PNS_LOG_VIEWER_FRAME_BASE::PNS_LOG_VIEWER_FRAME_BASE( wxWindow* parent, wxWindow
m_menubar1 = new wxMenuBar( 0 );
m_menu1 = new wxMenu();
wxMenuItem* m_menuItem1;
m_menuItem1 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Reload") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem1 );
wxMenuItem* m_menuOpen;
m_menuOpen = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Open") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuOpen );
wxMenuItem* m_menuItem2;
m_menuItem2 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Exit") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem2 );
wxMenuItem* m_menuSaveAs;
m_menuSaveAs = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Save as...") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuSaveAs );
wxMenuItem* m_menuExit;
m_menuExit = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Exit") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuExit );
m_menubar1->Append( m_menu1, wxT("File") );
@ -66,17 +70,17 @@ PNS_LOG_VIEWER_FRAME_BASE::PNS_LOG_VIEWER_FRAME_BASE( wxWindow* parent, wxWindow
fgSizer3->Add( m_filterString, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_chkShowRPItems = new wxCheckBox( this, wxID_ANY, wxT("Show RPIs"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer3->Add( m_chkShowRPItems, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
fgSizer3->Add( m_chkShowRPItems, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_chkThinLines = new wxCheckBox( this, wxID_ANY, wxT("Thin lines"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer3->Add( m_chkThinLines, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
fgSizer3->Add( m_chkThinLines, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_showVertices = new wxCheckBox( this, wxID_ANY, wxT("Show Vertices"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer3->Add( m_showVertices, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
fgSizer3->Add( m_showVertices, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_algoStatus = new wxStaticText( this, wxID_ANY, wxT("MyLabel"), wxDefaultPosition, wxDefaultSize, 0 );
m_algoStatus->Wrap( -1 );
m_algoStatus->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
m_algoStatus->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
fgSizer3->Add( m_algoStatus, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
@ -106,8 +110,9 @@ PNS_LOG_VIEWER_FRAME_BASE::PNS_LOG_VIEWER_FRAME_BASE( wxWindow* parent, wxWindow
this->Centre( wxBOTH );
// Connect Events
m_menu1->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onReload ), this, m_menuItem1->GetId());
m_menu1->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onExit ), this, m_menuItem2->GetId());
m_menu1->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onOpen ), this, m_menuOpen->GetId());
m_menu1->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onSaveAs ), this, m_menuSaveAs->GetId());
m_menu1->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onExit ), this, m_menuExit->GetId());
m_rewindLeft->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onBtnRewindLeft ), NULL, this );
m_rewindSlider->Connect( wxEVT_SCROLL_TOP, wxScrollEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onRewindScroll ), NULL, this );
m_rewindSlider->Connect( wxEVT_SCROLL_BOTTOM, wxScrollEventHandler( PNS_LOG_VIEWER_FRAME_BASE::onRewindScroll ), NULL, this );

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.9.0 Feb 6 2021)
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -58,7 +58,8 @@ class PNS_LOG_VIEWER_FRAME_BASE : public wxFrame
wxStatusBar* m_statusBar;
// Virtual event handlers, override them in your derived class
virtual void onReload( wxCommandEvent& event ) { event.Skip(); }
virtual void onOpen( wxCommandEvent& event ) { event.Skip(); }
virtual void onSaveAs( wxCommandEvent& event ) { event.Skip(); }
virtual void onExit( wxCommandEvent& event ) { event.Skip(); }
virtual void onBtnRewindLeft( wxCommandEvent& event ) { event.Skip(); }
virtual void onRewindScroll( wxScrollEvent& event ) { event.Skip(); }