Fix the type-based pcb_calculator GetCalculator implementation
ix the problem with the original template-based implementation to limit
the amount of things that could be forgotten by new panel creators
(since we can't just have a static fail method warning about things
beinf forgotten).
This reverts commit a92516bcd2
.
This commit is contained in:
parent
5f53019290
commit
8a11e89d0f
|
@ -33,7 +33,7 @@ public:
|
|||
: wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
|
||||
{}
|
||||
|
||||
~CALCULATOR_PANEL() {}
|
||||
virtual ~CALCULATOR_PANEL() {}
|
||||
|
||||
/**
|
||||
* Load the settings into the panel
|
||||
|
|
|
@ -38,8 +38,6 @@ PANEL_ATTENUATORS::PANEL_ATTENUATORS( wxWindow* parent, wxWindowID id,
|
|||
long style, const wxString& name ) :
|
||||
PANEL_ATTENUATORS_BASE( parent, id, pos, size, style, name )
|
||||
{
|
||||
SetName( GetWindowName() );
|
||||
|
||||
m_CurrAttenuator = nullptr;
|
||||
m_bpButtonCalcAtt->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ public:
|
|||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
||||
~PANEL_ATTENUATORS();
|
||||
|
||||
static wxString GetWindowName() { return wxT( "PANEL_ATTENUATORS" ); }
|
||||
|
||||
wxRadioBox* GetAttenuatorsSelector() { return m_AttenuatorsSelection; }
|
||||
|
||||
// Methods from CALCULATOR_PANEL that must be overriden
|
||||
|
|
|
@ -43,8 +43,6 @@ PANEL_REGULATOR::PANEL_REGULATOR( wxWindow* parent, wxWindowID id,
|
|||
PANEL_REGULATOR_BASE( parent, id, pos, size, style, name ),
|
||||
m_RegulatorListChanged( false )
|
||||
{
|
||||
SetName( GetWindowName() );
|
||||
|
||||
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
|
||||
m_r1Units->SetLabel( wxT( "kΩ" ) );
|
||||
m_r2Units->SetLabel( wxT( "kΩ" ) );
|
||||
|
|
|
@ -35,8 +35,6 @@ public:
|
|||
|
||||
|
||||
public:
|
||||
static wxString GetWindowName() { return wxT( "PANEL_REGULATOR" ); }
|
||||
|
||||
void OnRegulatorCalcButtonClick( wxCommandEvent& event ) override;
|
||||
void OnRegulatorResetButtonClick( wxCommandEvent& event ) override;
|
||||
void OnRegulTypeSelection( wxCommandEvent& event ) override;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <calculator_panels/panel_transline.h>
|
||||
#include <pcb_calculator_settings.h>
|
||||
|
||||
|
||||
PANEL_TRANSLINE::PANEL_TRANSLINE( wxWindow* parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
long style, const wxString& name ) :
|
||||
|
@ -31,8 +32,6 @@ PANEL_TRANSLINE::PANEL_TRANSLINE( wxWindow* parent, wxWindowID id,
|
|||
m_currTransLine( nullptr ),
|
||||
m_currTransLineType( DEFAULT_TYPE )
|
||||
{
|
||||
SetName( GetWindowName() );
|
||||
|
||||
m_bpButtonAnalyze->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
||||
m_bpButtonSynthetize->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ public:
|
|||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
||||
~PANEL_TRANSLINE();
|
||||
|
||||
static wxString GetWindowName() { return wxT( "PANEL_TRANSLINE" ); }
|
||||
|
||||
// Methods from CALCULATOR_PANEL that must be overriden
|
||||
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
||||
void SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
||||
|
|
|
@ -60,8 +60,6 @@ PANEL_VIA_SIZE::PANEL_VIA_SIZE( wxWindow* parent, wxWindowID id,
|
|||
long style, const wxString& name ) :
|
||||
PANEL_VIA_SIZE_BASE( parent, id, pos, size, style, name )
|
||||
{
|
||||
SetName( GetWindowName() );
|
||||
|
||||
m_viaResistivityUnits->SetLabel( wxT( "Ω•m" ) );
|
||||
m_viaTempUnits->SetLabel( wxT( "°C" ) );
|
||||
m_viaResUnits->SetLabel( wxT( "Ω" ) );
|
||||
|
|
|
@ -34,8 +34,6 @@ public:
|
|||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
||||
~PANEL_VIA_SIZE();
|
||||
|
||||
static wxString GetWindowName() { return wxT( "PANEL_VIA_SIZE" ); }
|
||||
|
||||
// Methods from CALCULATOR_PANEL that must be overriden
|
||||
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
||||
void SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
||||
|
|
|
@ -79,10 +79,11 @@ double DoubleFromString( const wxString& TextValue )
|
|||
// A helper function to get a reference to the PANEL_TRANSLINE
|
||||
PANEL_TRANSLINE* getTranslinePanel()
|
||||
{
|
||||
PANEL_TRANSLINE* panel = static_cast <PANEL_TRANSLINE*>(
|
||||
wxFindWindowByName( PANEL_TRANSLINE::GetWindowName() ) );
|
||||
wxASSERT( panel );
|
||||
return panel;
|
||||
PCB_CALCULATOR_FRAME* frame = (PCB_CALCULATOR_FRAME*) wxTheApp->GetTopWindow();
|
||||
PANEL_TRANSLINE* transline = frame->GetCalculator<PANEL_TRANSLINE>();
|
||||
|
||||
wxASSERT( transline );
|
||||
return transline;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <wx/notebook.h>
|
||||
#include <wx/sizer.h>
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#include <bitmaps.h>
|
||||
#include <bitmap_store.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
|
@ -137,6 +139,8 @@ void PCB_CALCULATOR_FRAME::AddCalculator( CALCULATOR_PANEL *aPanel, const wxStri
|
|||
{
|
||||
// Update internal structures
|
||||
m_panels.push_back( aPanel );
|
||||
m_panelTypes[ typeid( *aPanel ).hash_code() ] = aPanel;
|
||||
|
||||
m_notebook->AddPage( aPanel, panelUIName, false );
|
||||
}
|
||||
|
||||
|
@ -160,7 +164,18 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
{
|
||||
// Kick all the things that wxWidgets can't seem to redraw on its own.
|
||||
// This is getting seriously ridiculous....
|
||||
if( PANEL_TRANSLINE* translinePanel = GetCalculator<PANEL_TRANSLINE>() )
|
||||
PANEL_TRANSLINE* translinePanel = GetCalculator<PANEL_TRANSLINE>();
|
||||
PANEL_ATTENUATORS* attenPanel = GetCalculator<PANEL_ATTENUATORS>();
|
||||
PANEL_VIA_SIZE* viaSizePanel = GetCalculator<PANEL_VIA_SIZE>();
|
||||
PANEL_REGULATOR* regulPanel = GetCalculator<PANEL_REGULATOR>();
|
||||
PANEL_ELECTRICAL_SPACING* elecSpacingPanel = GetCalculator<PANEL_ELECTRICAL_SPACING>();
|
||||
|
||||
wxASSERT( translinePanel );
|
||||
wxASSERT( attenPanel );
|
||||
wxASSERT( viaSizePanel );
|
||||
wxASSERT( regulPanel );
|
||||
wxASSERT( elecSpacingPanel );
|
||||
|
||||
{
|
||||
wxCommandEvent event2( wxEVT_RADIOBUTTON );
|
||||
event2.SetEventObject( translinePanel->GetTranslineSelector() );
|
||||
|
@ -169,8 +184,6 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
translinePanel->GetTranslineSelector()->Command( event2 );
|
||||
}
|
||||
|
||||
if( PANEL_ATTENUATORS* attenPanel = GetCalculator<PANEL_ATTENUATORS>() )
|
||||
{
|
||||
for( int i = 0; i < attenPanel->m_AttenuatorList.size(); ++i )
|
||||
{
|
||||
if( attenPanel->m_AttenuatorList[i] == attenPanel->m_CurrAttenuator )
|
||||
|
@ -185,12 +198,7 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
}
|
||||
|
||||
attenPanel->UpdateUI();
|
||||
}
|
||||
|
||||
if( PANEL_VIA_SIZE* viaSizePanel = GetCalculator<PANEL_VIA_SIZE>() )
|
||||
viaSizePanel->Layout();
|
||||
|
||||
if( PANEL_REGULATOR* regulPanel = GetCalculator<PANEL_REGULATOR>() )
|
||||
regulPanel->Layout();
|
||||
|
||||
// Until it's shown on screen the above won't work; but doing it anyway at least keeps
|
||||
|
@ -201,8 +209,6 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
// the first resize event.
|
||||
#ifdef __WXMAC__
|
||||
if( m_macHack )
|
||||
{
|
||||
if( PANEL_ELECTRICAL_SPACING* elecSpacingPanel = GetCalculator<PANEL_ELECTRICAL_SPACING>() )
|
||||
{
|
||||
wxSize pageSize = elecSpacingPanel->GetSize();
|
||||
|
||||
|
@ -216,7 +222,6 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
|
||||
m_macHack = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_lastNotebookPage = m_notebook->GetSelection();
|
||||
|
@ -229,7 +234,9 @@ void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
|
|||
{
|
||||
PANEL_REGULATOR* regPanel = GetCalculator<PANEL_REGULATOR>();
|
||||
|
||||
if( regPanel && regPanel->m_RegulatorListChanged )
|
||||
wxASSERT( regPanel );
|
||||
|
||||
if( regPanel->m_RegulatorListChanged )
|
||||
{
|
||||
wxString msg;
|
||||
wxString title = _( "Write Data Failed" );
|
||||
|
|
|
@ -49,14 +49,16 @@ public:
|
|||
|
||||
/*
|
||||
* Return the panel of given type or nullptr if there is no such panel exists.
|
||||
* Note: GetWindowName() is a static function expected existing in panels that
|
||||
* can be retrieved by GetCalculator() and returning the wxWindow name used to
|
||||
* create a panel
|
||||
*/
|
||||
template<typename T>
|
||||
T* GetCalculator()
|
||||
{
|
||||
return static_cast<T*>( wxFindWindowByName( T::GetWindowName() ) );
|
||||
std::map<std::size_t, CALCULATOR_PANEL*>::iterator panel = m_panelTypes.find( typeid( T ).hash_code() );
|
||||
|
||||
if( panel != m_panelTypes.end() )
|
||||
return static_cast<T*>( panel->second );
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AddCalculator( CALCULATOR_PANEL *aPanel, const wxString& panelUIName );
|
||||
|
@ -82,6 +84,9 @@ private:
|
|||
bool m_macHack;
|
||||
|
||||
std::vector<CALCULATOR_PANEL*> m_panels;
|
||||
std::map<std::size_t, CALCULATOR_PANEL*> m_panelTypes;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue