qa_utils: PCB_TEST_FRAME compiles again...

This commit is contained in:
Tomasz Wlostowski 2020-09-05 01:13:20 +02:00
parent 91860dae2d
commit 7aefe6fdb4
2 changed files with 58 additions and 122 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2020 CERN
* Copyright (C) 2013-2017 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -22,12 +22,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
//#define USE_TOOL_MANAGER
#include <wx/timer.h>
#include <wx/math.h>
#include <wx/log.h>
#include <wx/popupwin.h>
#include <wx/cmdline.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <settings/color_settings.h>
#include <layers_id_colors_and_visibility.h>
#include <gal/graphics_abstraction_layer.h>
@ -62,80 +68,29 @@
#include "pcb_test_frame.h"
IMPLEMENT_APP( GAL_TEST_APP )
using namespace KIGFX;
bool GAL_TEST_APP::OnInit()
void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr<BOARD> b )
{
if( !wxApp::OnInit() )
return false;
m_board = b;
// Create the main frame window
auto frame = CreateMainFrame( (const char*) m_filename.c_str() );
return frame != nullptr;
}
void GAL_TEST_APP::OnInitCmdLine( wxCmdLineParser& parser )
{
parser.AddOption( "f", wxEmptyString, "Open board file" );
wxApp::OnInitCmdLine( parser );
}
bool GAL_TEST_APP::OnCmdLineParsed( wxCmdLineParser& parser )
{
wxString filename;
if( parser.Found( "f", &filename ) )
{
m_filename = filename;
}
return true;
}
class TEST_ACTIONS : public ACTIONS
{
public:
virtual ~TEST_ACTIONS() {};
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) override
{
return NULLOPT;
}
};
void PCB_TEST_FRAME::OnMenuFileOpen( wxCommandEvent& WXUNUSED( event ) )
{
}
void PCB_TEST_FRAME::OnMotion( wxMouseEvent& aEvent )
{
aEvent.Skip();
}
void PCB_TEST_FRAME::SetBoard( BOARD* b )
{
m_board.reset( b );
m_board->GetConnectivity()->Build( m_board.get() );
m_galPanel->DisplayBoard( m_board.get() );
m_galPanel->UpdateColors();
#ifdef USE_TOOL_MANAGER
m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
m_galPanel->GetViewControls(), nullptr, nullptr );
m_galPanel->GetViewControls(), nullptr );
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
#endif
}
BOARD* PCB_TEST_FRAME::LoadAndDisplayBoard( const std::string& filename )
BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename )
{
PLUGIN::RELEASER pi( new PCB_IO );
BOARD* brd = nullptr;
@ -149,40 +104,33 @@ BOARD* PCB_TEST_FRAME::LoadAndDisplayBoard( const std::string& filename )
wxString msg = wxString::Format( _( "Error loading board.\n%s" ),
ioe.Problem() );
printf( "%s\n", (const char*) msg.mb_str() );
return nullptr;
}
SetBoard( brd );
//SetBoard( brd );
return brd;
}
PCB_TEST_FRAME::PCB_TEST_FRAME( wxFrame* frame, const wxString& title, const wxPoint& pos,
const wxSize& size, long style, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType ) :
wxFrame( frame, wxID_ANY, title, pos, size, style )
class TEST_ACTIONS : public ACTIONS
{
// Make a menubar
wxMenu* fileMenu = new wxMenu;
fileMenu->Append( wxID_OPEN, wxT( "&Open..." ) );
fileMenu->AppendSeparator();
fileMenu->Append( wxID_EXIT, wxT( "E&xit" ) );
wxMenuBar* menuBar = new wxMenuBar;
menuBar->Append( fileMenu, wxT( "&File" ) );
SetMenuBar( menuBar );
Show( true );
Maximize();
Raise();
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) override
{
return OPT<TOOL_EVENT> ();
}
};
void PCB_TEST_FRAME_BASE::createView( wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType )
{
KIGFX::GAL_DISPLAY_OPTIONS options;
options.gl_antialiasing_mode = KIGFX::OPENGL_ANTIALIASING_MODE::NONE; //SUPERSAMPLING_X4;
m_galPanel = std::make_unique<PCB_DRAW_PANEL_GAL>( this, -1, wxPoint( 0,
m_galPanel = std::make_shared<PCB_DRAW_PANEL_GAL>( aParent, -1, wxPoint( 0,
0 ), wxDefaultSize, options, aGalType );
m_galPanel->UpdateColors();
m_galPanel->SetEvtHandlerEnabled( true );
m_galPanel->SetFocus();
m_galPanel->Show( true );
@ -195,38 +143,43 @@ PCB_TEST_FRAME::PCB_TEST_FRAME( wxFrame* frame, const wxString& title, const wxP
gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) );
gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) );
m_galPanel->Connect( wxEVT_MOTION,
wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), NULL, this );
//m_galPanel->Connect( wxEVT_MOTION,
//wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), NULL, this );
m_galPanel->GetViewControls()->ShowCursor( true );
#ifdef USE_TOOL_MANAGER
m_toolManager = std::make_unique<TOOL_MANAGER>( );
m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(),
m_galPanel->GetViewControls(), nullptr, nullptr );
m_galPanel->GetViewControls(), nullptr );
m_pcbActions = std::make_unique<TEST_ACTIONS>( );
m_toolDispatcher = std::make_unique<TOOL_DISPATCHER>( m_toolManager.get(), m_pcbActions.get() );
m_toolManager->RegisterTool( new SELECTION_TOOL );
//m_toolManager->RegisterTool( new SELECTION_TOOL );
createUserTools();
m_toolManager->InitTools();
m_galPanel->SetEventDispatcher( m_toolDispatcher.get() );
m_toolManager->InvokeTool( "common.InteractiveSelection" );
m_toolManager->InvokeTool( "test.DefaultTool" );
#endif
SetBoard( new BOARD );
//SetBoard( std::make_shared<BOARD>( new BOARD ));
}
PCB_TEST_FRAME::~PCB_TEST_FRAME()
PCB_TEST_FRAME_BASE::PCB_TEST_FRAME_BASE()
{
}
// Intercept menu commands
void PCB_TEST_FRAME::OnExit( wxCommandEvent& WXUNUSED( event ) )
PCB_TEST_FRAME_BASE::~PCB_TEST_FRAME_BASE()
{
// true is to force the frame to close
Close( true );
}
void PCB_TEST_FRAME_BASE::LoadSettings()
{
auto cs = Pgm().GetSettingsManager().GetColorSettings();
//cs->SetColorContext( COLOR_CONTEXT::PCB );
cs->Load();
}

View File

@ -46,44 +46,27 @@ namespace KIGFX {
class VIEW;
};
// Define a new application type
class GAL_TEST_APP : public wxApp
class PCB_TEST_FRAME_BASE
{
public:
virtual bool OnInit() override;
PCB_TEST_FRAME_BASE();
virtual ~PCB_TEST_FRAME_BASE();
virtual void OnInitCmdLine( wxCmdLineParser& parser ) override;
virtual bool OnCmdLineParsed( wxCmdLineParser& parser ) override;
virtual void SetBoard( std::shared_ptr<BOARD> b);
virtual BOARD* LoadAndDisplayBoard ( const std::string& filename );
private:
wxString m_filename;
};
std::shared_ptr < PCB_DRAW_PANEL_GAL > GetPanel() { return m_galPanel; }
std::shared_ptr < BOARD > GetBoard() { return m_board; }
class PCB_TEST_FRAME : public wxFrame
{
public:
PCB_TEST_FRAME(wxFrame *frame,
const wxString& title,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE,
PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType = PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
virtual ~PCB_TEST_FRAME();
void SetBoard( BOARD * b);
BOARD* LoadAndDisplayBoard ( const std::string& filename );
void LoadSettings();
protected:
virtual void OnExit(wxCommandEvent& event);
virtual void OnMotion( wxMouseEvent& aEvent );
virtual void OnMenuFileOpen( wxCommandEvent& WXUNUSED( event ) );
void createView( wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType = PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
virtual void createUserTools() {};
void buildView();
unique_ptr < PCB_DRAW_PANEL_GAL > m_galPanel;
unique_ptr < BOARD > m_board;
std::shared_ptr < PCB_DRAW_PANEL_GAL > m_galPanel;
std::shared_ptr < BOARD > m_board;
#ifdef USE_TOOL_MANAGER
unique_ptr < TOOL_MANAGER > m_toolManager;
unique_ptr < TOOL_DISPATCHER > m_toolDispatcher;
@ -91,6 +74,6 @@ protected:
#endif
};
wxFrame* CreateMainFrame( const std::string& aFileName );
void SetTopFrame ( wxFrame* aFrame );
#endif