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 )
|
: wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~CALCULATOR_PANEL() {}
|
virtual ~CALCULATOR_PANEL() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the settings into the panel
|
* Load the settings into the panel
|
||||||
|
|
|
@ -38,8 +38,6 @@ PANEL_ATTENUATORS::PANEL_ATTENUATORS( wxWindow* parent, wxWindowID id,
|
||||||
long style, const wxString& name ) :
|
long style, const wxString& name ) :
|
||||||
PANEL_ATTENUATORS_BASE( parent, id, pos, size, style, name )
|
PANEL_ATTENUATORS_BASE( parent, id, pos, size, style, name )
|
||||||
{
|
{
|
||||||
SetName( GetWindowName() );
|
|
||||||
|
|
||||||
m_CurrAttenuator = nullptr;
|
m_CurrAttenuator = nullptr;
|
||||||
m_bpButtonCalcAtt->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
m_bpButtonCalcAtt->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ public:
|
||||||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
||||||
~PANEL_ATTENUATORS();
|
~PANEL_ATTENUATORS();
|
||||||
|
|
||||||
static wxString GetWindowName() { return wxT( "PANEL_ATTENUATORS" ); }
|
|
||||||
|
|
||||||
wxRadioBox* GetAttenuatorsSelector() { return m_AttenuatorsSelection; }
|
wxRadioBox* GetAttenuatorsSelector() { return m_AttenuatorsSelection; }
|
||||||
|
|
||||||
// Methods from CALCULATOR_PANEL that must be overriden
|
// 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 ),
|
PANEL_REGULATOR_BASE( parent, id, pos, size, style, name ),
|
||||||
m_RegulatorListChanged( false )
|
m_RegulatorListChanged( false )
|
||||||
{
|
{
|
||||||
SetName( GetWindowName() );
|
|
||||||
|
|
||||||
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
|
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
|
||||||
m_r1Units->SetLabel( wxT( "kΩ" ) );
|
m_r1Units->SetLabel( wxT( "kΩ" ) );
|
||||||
m_r2Units->SetLabel( wxT( "kΩ" ) );
|
m_r2Units->SetLabel( wxT( "kΩ" ) );
|
||||||
|
|
|
@ -35,8 +35,6 @@ public:
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static wxString GetWindowName() { return wxT( "PANEL_REGULATOR" ); }
|
|
||||||
|
|
||||||
void OnRegulatorCalcButtonClick( wxCommandEvent& event ) override;
|
void OnRegulatorCalcButtonClick( wxCommandEvent& event ) override;
|
||||||
void OnRegulatorResetButtonClick( wxCommandEvent& event ) override;
|
void OnRegulatorResetButtonClick( wxCommandEvent& event ) override;
|
||||||
void OnRegulTypeSelection( wxCommandEvent& event ) override;
|
void OnRegulTypeSelection( wxCommandEvent& event ) override;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <calculator_panels/panel_transline.h>
|
#include <calculator_panels/panel_transline.h>
|
||||||
#include <pcb_calculator_settings.h>
|
#include <pcb_calculator_settings.h>
|
||||||
|
|
||||||
|
|
||||||
PANEL_TRANSLINE::PANEL_TRANSLINE( wxWindow* parent, wxWindowID id,
|
PANEL_TRANSLINE::PANEL_TRANSLINE( wxWindow* parent, wxWindowID id,
|
||||||
const wxPoint& pos, const wxSize& size,
|
const wxPoint& pos, const wxSize& size,
|
||||||
long style, const wxString& name ) :
|
long style, const wxString& name ) :
|
||||||
|
@ -31,8 +32,6 @@ PANEL_TRANSLINE::PANEL_TRANSLINE( wxWindow* parent, wxWindowID id,
|
||||||
m_currTransLine( nullptr ),
|
m_currTransLine( nullptr ),
|
||||||
m_currTransLineType( DEFAULT_TYPE )
|
m_currTransLineType( DEFAULT_TYPE )
|
||||||
{
|
{
|
||||||
SetName( GetWindowName() );
|
|
||||||
|
|
||||||
m_bpButtonAnalyze->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
m_bpButtonAnalyze->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
||||||
m_bpButtonSynthetize->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
m_bpButtonSynthetize->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ public:
|
||||||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
||||||
~PANEL_TRANSLINE();
|
~PANEL_TRANSLINE();
|
||||||
|
|
||||||
static wxString GetWindowName() { return wxT( "PANEL_TRANSLINE" ); }
|
|
||||||
|
|
||||||
// Methods from CALCULATOR_PANEL that must be overriden
|
// Methods from CALCULATOR_PANEL that must be overriden
|
||||||
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
||||||
void SaveSettings( 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 ) :
|
long style, const wxString& name ) :
|
||||||
PANEL_VIA_SIZE_BASE( parent, id, pos, size, style, name )
|
PANEL_VIA_SIZE_BASE( parent, id, pos, size, style, name )
|
||||||
{
|
{
|
||||||
SetName( GetWindowName() );
|
|
||||||
|
|
||||||
m_viaResistivityUnits->SetLabel( wxT( "Ω•m" ) );
|
m_viaResistivityUnits->SetLabel( wxT( "Ω•m" ) );
|
||||||
m_viaTempUnits->SetLabel( wxT( "°C" ) );
|
m_viaTempUnits->SetLabel( wxT( "°C" ) );
|
||||||
m_viaResUnits->SetLabel( wxT( "Ω" ) );
|
m_viaResUnits->SetLabel( wxT( "Ω" ) );
|
||||||
|
|
|
@ -34,8 +34,6 @@ public:
|
||||||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
|
||||||
~PANEL_VIA_SIZE();
|
~PANEL_VIA_SIZE();
|
||||||
|
|
||||||
static wxString GetWindowName() { return wxT( "PANEL_VIA_SIZE" ); }
|
|
||||||
|
|
||||||
// Methods from CALCULATOR_PANEL that must be overriden
|
// Methods from CALCULATOR_PANEL that must be overriden
|
||||||
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
|
||||||
void SaveSettings( 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
|
// A helper function to get a reference to the PANEL_TRANSLINE
|
||||||
PANEL_TRANSLINE* getTranslinePanel()
|
PANEL_TRANSLINE* getTranslinePanel()
|
||||||
{
|
{
|
||||||
PANEL_TRANSLINE* panel = static_cast <PANEL_TRANSLINE*>(
|
PCB_CALCULATOR_FRAME* frame = (PCB_CALCULATOR_FRAME*) wxTheApp->GetTopWindow();
|
||||||
wxFindWindowByName( PANEL_TRANSLINE::GetWindowName() ) );
|
PANEL_TRANSLINE* transline = frame->GetCalculator<PANEL_TRANSLINE>();
|
||||||
wxASSERT( panel );
|
|
||||||
return panel;
|
wxASSERT( transline );
|
||||||
|
return transline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include <wx/notebook.h>
|
#include <wx/notebook.h>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#include <bitmaps.h>
|
#include <bitmaps.h>
|
||||||
#include <bitmap_store.h>
|
#include <bitmap_store.h>
|
||||||
#include <geometry/shape_poly_set.h>
|
#include <geometry/shape_poly_set.h>
|
||||||
|
@ -137,6 +139,8 @@ void PCB_CALCULATOR_FRAME::AddCalculator( CALCULATOR_PANEL *aPanel, const wxStri
|
||||||
{
|
{
|
||||||
// Update internal structures
|
// Update internal structures
|
||||||
m_panels.push_back( aPanel );
|
m_panels.push_back( aPanel );
|
||||||
|
m_panelTypes[ typeid( *aPanel ).hash_code() ] = aPanel;
|
||||||
|
|
||||||
m_notebook->AddPage( aPanel, panelUIName, false );
|
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.
|
// Kick all the things that wxWidgets can't seem to redraw on its own.
|
||||||
// This is getting seriously ridiculous....
|
// 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 );
|
wxCommandEvent event2( wxEVT_RADIOBUTTON );
|
||||||
event2.SetEventObject( translinePanel->GetTranslineSelector() );
|
event2.SetEventObject( translinePanel->GetTranslineSelector() );
|
||||||
|
@ -169,29 +184,22 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
||||||
translinePanel->GetTranslineSelector()->Command( event2 );
|
translinePanel->GetTranslineSelector()->Command( event2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( PANEL_ATTENUATORS* attenPanel = GetCalculator<PANEL_ATTENUATORS>() )
|
for( int i = 0; i < attenPanel->m_AttenuatorList.size(); ++i )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < attenPanel->m_AttenuatorList.size(); ++i )
|
if( attenPanel->m_AttenuatorList[i] == attenPanel->m_CurrAttenuator )
|
||||||
{
|
{
|
||||||
if( attenPanel->m_AttenuatorList[i] == attenPanel->m_CurrAttenuator )
|
wxCommandEvent event2( wxEVT_RADIOBUTTON );
|
||||||
{
|
event2.SetEventObject( attenPanel->GetAttenuatorsSelector() );
|
||||||
wxCommandEvent event2( wxEVT_RADIOBUTTON );
|
event2.SetInt( i );
|
||||||
event2.SetEventObject( attenPanel->GetAttenuatorsSelector() );
|
|
||||||
event2.SetInt( i );
|
|
||||||
|
|
||||||
attenPanel->GetAttenuatorsSelector()->Command( event2 );
|
attenPanel->GetAttenuatorsSelector()->Command( event2 );
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attenPanel->UpdateUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( PANEL_VIA_SIZE* viaSizePanel = GetCalculator<PANEL_VIA_SIZE>() )
|
attenPanel->UpdateUI();
|
||||||
viaSizePanel->Layout();
|
viaSizePanel->Layout();
|
||||||
|
regulPanel->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
|
// Until it's shown on screen the above won't work; but doing it anyway at least keeps
|
||||||
// putting new OnUpdateUI events into the queue until it *is* shown on screen.
|
// putting new OnUpdateUI events into the queue until it *is* shown on screen.
|
||||||
|
@ -202,20 +210,17 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
if( m_macHack )
|
if( m_macHack )
|
||||||
{
|
{
|
||||||
if( PANEL_ELECTRICAL_SPACING* elecSpacingPanel = GetCalculator<PANEL_ELECTRICAL_SPACING>() )
|
wxSize pageSize = elecSpacingPanel->GetSize();
|
||||||
{
|
|
||||||
wxSize pageSize = elecSpacingPanel->GetSize();
|
|
||||||
|
|
||||||
pageSize.x -= 100;
|
pageSize.x -= 100;
|
||||||
elecSpacingPanel->SetSize( pageSize );
|
elecSpacingPanel->SetSize( pageSize );
|
||||||
elecSpacingPanel->Layout();
|
elecSpacingPanel->Layout();
|
||||||
|
|
||||||
pageSize.x += 100;
|
pageSize.x += 100;
|
||||||
elecSpacingPanel->SetSize( pageSize );
|
elecSpacingPanel->SetSize( pageSize );
|
||||||
elecSpacingPanel->Layout();
|
elecSpacingPanel->Layout();
|
||||||
|
|
||||||
m_macHack = false;
|
m_macHack = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -229,7 +234,9 @@ void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
|
||||||
{
|
{
|
||||||
PANEL_REGULATOR* regPanel = GetCalculator<PANEL_REGULATOR>();
|
PANEL_REGULATOR* regPanel = GetCalculator<PANEL_REGULATOR>();
|
||||||
|
|
||||||
if( regPanel && regPanel->m_RegulatorListChanged )
|
wxASSERT( regPanel );
|
||||||
|
|
||||||
|
if( regPanel->m_RegulatorListChanged )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxString title = _( "Write Data Failed" );
|
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.
|
* 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>
|
template<typename T>
|
||||||
T* GetCalculator()
|
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 );
|
void AddCalculator( CALCULATOR_PANEL *aPanel, const wxString& panelUIName );
|
||||||
|
@ -82,6 +84,9 @@ private:
|
||||||
bool m_macHack;
|
bool m_macHack;
|
||||||
|
|
||||||
std::vector<CALCULATOR_PANEL*> m_panels;
|
std::vector<CALCULATOR_PANEL*> m_panels;
|
||||||
|
std::map<std::size_t, CALCULATOR_PANEL*> m_panelTypes;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue