qa/pns: factor out simple 'playground' app to a separate file

This commit is contained in:
Tomasz Wlostowski 2021-05-28 01:10:58 +02:00
parent d31d2e28ca
commit 1c23b505e0
4 changed files with 181 additions and 81 deletions

View File

@ -65,6 +65,7 @@ add_executable( test_pns
../qa_utils/utility_program.cpp
../qa_utils/mocks.cpp
../../common/base_units.cpp
playground.cpp
)
# Pcbnew tests, so pretend to be pcbnew (for units, etc)

65
qa/pns/playground.cpp Normal file
View File

@ -0,0 +1,65 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 KiCad Developers.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
// (unless you want to improve it).
#include <pgm_base.h>
#include <qa_utils/utility_registry.h>
#include "pns_log_viewer_frame.h"
int playground_main_func( int argc, char* argv[] )
{
auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
Pgm().App().SetTopWindow( frame ); // wxApp gets a face.
frame->Show();
auto overlay = frame->GetPanel()->DebugOverlay();
overlay->SetIsFill(false);
overlay->SetLineWidth(10000);
auto hull = SHAPE_LINE_CHAIN( { VECTOR2I( 66280505, 107710033), VECTOR2I( 65914967, 107344495), VECTOR2I( 65914967, 106827549), VECTOR2I( 66280505, 106462011), VECTOR2I( 74810033, 106462009), VECTOR2I( 75175571, 106827547), VECTOR2I( 75175571, 107344493), VECTOR2I( 74810033, 107710031)}, true );
auto path = SHAPE_LINE_CHAIN( { VECTOR2I( 143928480, 109445996), VECTOR2I( 111066480, 109445996), VECTOR2I( 106254391, 104633907), VECTOR2I( 105909001, 104633907), VECTOR2I( 105775094, 104500000), VECTOR2I( 76250000, 104500000), VECTOR2I( 74287991, 106462009), VECTOR2I( 66280505, 106462011), VECTOR2I( 66012989, 106462011)}, false );
BOX2D bb ( path.BBox().GetPosition(), path.BBox().GetSize() );
frame->GetPanel()->GetView()->SetViewport(bb);
overlay->SetStrokeColor( WHITE );
overlay->SetLineWidth( 100000.0 );
overlay->Polyline( path );
overlay->SetStrokeColor( RED );
overlay->Polyline( hull );
overlay = nullptr;
return 0;
}
static bool registered = UTILITY_REGISTRY::Register( {
"playground",
"Geometry/drawing playground",
playground_main_func,
} );

View File

@ -27,8 +27,6 @@
#include <wx/clipbrd.h>
#include <pcb_painter.h>
#include <pcb_test_frame.h>
#include <qa_utils/utility_registry.h>
#include <pgm_base.h>
@ -40,14 +38,10 @@
#include "router/pns_diff_pair.h"
#include "router/pns_utils.h"
#include "pns_log_viewer_frame_base.h"
#include "pns_log_viewer_frame.h"
#include "qa/drc_proto/drc_proto.h"
#define ID_LIST_COPY 10001
#define ID_LIST_SHOW_ALL 10002
#define ID_LIST_SHOW_NONE 10003
#define TOM_EXTRA_DEBUG
class LABEL_MANAGER
@ -85,7 +79,7 @@ public:
{
for( int i = 0; i < aL.PointCount(); i++ )
{
char msg[10];
char msg[1024];
snprintf(msg, sizeof(msg), "%d", i );
Add( aL.CPoint(i), msg, color );
}
@ -237,79 +231,6 @@ private:
class PNS_LOG_VIEWER_FRAME : public PNS_LOG_VIEWER_FRAME_BASE, public PCB_TEST_FRAME_BASE
{
public:
PNS_LOG_VIEWER_FRAME( wxFrame* frame ) : PNS_LOG_VIEWER_FRAME_BASE( frame )
{
LoadSettings();
createView( this, PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
m_viewSizer->Add( m_galPanel.get(), 1, wxEXPAND, 5 );
Layout();
Show( true );
Maximize();
Raise();
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
m_galPanel->GetView()->GetPainter()->GetSettings() );
settings->SetZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE );
m_listPopupMenu = new wxMenu( wxT( "" ) );
m_listPopupMenu->Append( ID_LIST_COPY, wxT( "Copy selected geometry" ), wxT( "" ),
wxITEM_NORMAL );
m_listPopupMenu->Append( ID_LIST_SHOW_ALL, wxT( "Show all" ), wxT( "" ), wxITEM_NORMAL );
m_listPopupMenu->Append( ID_LIST_SHOW_NONE, wxT( "Show none" ), wxT( "" ), wxITEM_NORMAL );
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CONTEXT_MENU,
wxMouseEventHandler( PNS_LOG_VIEWER_FRAME::onListRightClick ), NULL,
this );
//m_itemList->Connect(m_itemList->GetId(),wxEVT_LISTBOX,wxCommandEventHandler(PNS_LOG_VIEWER_FRAME::onListSelect),NULL,this);
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_SELECTION_CHANGED,
wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListSelect ), NULL,
this );
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CHECKED,
wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListChecked ), NULL,
this );
m_itemList->AppendColumn( "Type" );
m_itemList->AppendColumn( "Value" );
}
virtual ~PNS_LOG_VIEWER_FRAME() {}
void SetLogFile( PNS_LOG_FILE* aLog );
private:
void drawLoggedItems( int iter );
void updateDumpPanel( int iter );
virtual void createUserTools() override;
void buildListTree( wxTreeListItem item, PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* ent,
int depth = 0 );
void syncModel();
PNS_TEST_DEBUG_DECORATOR::STAGE* getCurrentStage();
virtual void onReload( wxCommandEvent& event ) override;
virtual void onExit( wxCommandEvent& event ) override;
virtual void onRewindScroll( wxScrollEvent& event ) override;
virtual void onRewindCountText( wxCommandEvent& event ) override;
virtual void onListRightClick( wxMouseEvent& event );
virtual void onListSelect( wxCommandEvent& event );
virtual void onBtnRewindLeft( wxCommandEvent& event ) override;
virtual void onBtnRewindRight( wxCommandEvent& event ) override;
virtual void onListChecked( wxCommandEvent& event );
std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
std::shared_ptr<PNS_LOG_FILE> m_logFile;
std::shared_ptr<PNS_TEST_ENVIRONMENT> m_env;
int m_rewindIter;
wxMenu* m_listPopupMenu;
};
class WX_SHAPE_TREE_ITEM_DATA : public wxClientData
{
public:

View File

@ -0,0 +1,113 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 KiCad Developers.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
// (unless you want to improve it).
#ifndef __PNS_LOG_VIEWER_FRAME_H
#define __PNS_LOG_VIEWER_FRAME_H
#include <pcb_painter.h>
#include <pcb_test_frame.h>
#include "pns_log.h"
#include "pns_log_viewer_frame_base.h"
#define ID_LIST_COPY 10001
#define ID_LIST_SHOW_ALL 10002
#define ID_LIST_SHOW_NONE 10003
class PNS_LOG_VIEWER_FRAME : public PNS_LOG_VIEWER_FRAME_BASE, public PCB_TEST_FRAME_BASE
{
public:
PNS_LOG_VIEWER_FRAME( wxFrame* frame ) : PNS_LOG_VIEWER_FRAME_BASE( frame )
{
LoadSettings();
createView( this, PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
m_viewSizer->Add( m_galPanel.get(), 1, wxEXPAND, 5 );
Layout();
Show( true );
Maximize();
Raise();
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
m_galPanel->GetView()->GetPainter()->GetSettings() );
settings->SetZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE );
m_listPopupMenu = new wxMenu( wxT( "" ) );
m_listPopupMenu->Append( ID_LIST_COPY, wxT( "Copy selected geometry" ), wxT( "" ),
wxITEM_NORMAL );
m_listPopupMenu->Append( ID_LIST_SHOW_ALL, wxT( "Show all" ), wxT( "" ), wxITEM_NORMAL );
m_listPopupMenu->Append( ID_LIST_SHOW_NONE, wxT( "Show none" ), wxT( "" ), wxITEM_NORMAL );
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CONTEXT_MENU,
wxMouseEventHandler( PNS_LOG_VIEWER_FRAME::onListRightClick ), NULL,
this );
//m_itemList->Connect(m_itemList->GetId(),wxEVT_LISTBOX,wxCommandEventHandler(PNS_LOG_VIEWER_FRAME::onListSelect),NULL,this);
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_SELECTION_CHANGED,
wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListSelect ), NULL,
this );
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CHECKED,
wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListChecked ), NULL,
this );
m_itemList->AppendColumn( "Type" );
m_itemList->AppendColumn( "Value" );
}
virtual ~PNS_LOG_VIEWER_FRAME() {}
void SetLogFile( PNS_LOG_FILE* aLog );
private:
void drawLoggedItems( int iter );
void updateDumpPanel( int iter );
virtual void createUserTools() override;
void buildListTree( wxTreeListItem item, PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* ent,
int depth = 0 );
void syncModel();
PNS_TEST_DEBUG_DECORATOR::STAGE* getCurrentStage();
virtual void onReload( wxCommandEvent& event ) override;
virtual void onExit( wxCommandEvent& event ) override;
virtual void onRewindScroll( wxScrollEvent& event ) override;
virtual void onRewindCountText( wxCommandEvent& event ) override;
virtual void onListRightClick( wxMouseEvent& event );
virtual void onListSelect( wxCommandEvent& event );
virtual void onBtnRewindLeft( wxCommandEvent& event ) override;
virtual void onBtnRewindRight( wxCommandEvent& event ) override;
virtual void onListChecked( wxCommandEvent& event );
std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
std::shared_ptr<PNS_LOG_FILE> m_logFile;
std::shared_ptr<PNS_TEST_ENVIRONMENT> m_env;
int m_rewindIter;
wxMenu* m_listPopupMenu;
};
#endif