Pcb_calculator: fix not working GetCalculator() template.
Use now wxWidgets functions to find a calculator panel. Fixes #9358 https://gitlab.com/kicad/code/kicad/issues/9358
This commit is contained in:
parent
593324bbaa
commit
a92516bcd2
|
@ -38,6 +38,8 @@ 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,6 +36,8 @@ 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
|
||||||
|
|
|
@ -42,6 +42,8 @@ PANEL_REGULATOR::PANEL_REGULATOR( wxWindow* parent, wxWindowID id,
|
||||||
long style, const wxString& name ) :
|
long style, const wxString& name ) :
|
||||||
PANEL_REGULATOR_BASE( parent, id, pos, size, style, name )
|
PANEL_REGULATOR_BASE( parent, id, pos, size, style, name )
|
||||||
{
|
{
|
||||||
|
SetName( GetWindowName() );
|
||||||
|
|
||||||
m_RegulatorListChanged = false;
|
m_RegulatorListChanged = false;
|
||||||
|
|
||||||
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
|
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
|
||||||
|
|
|
@ -35,6 +35,8 @@ 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;
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
#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 ) :
|
||||||
PANEL_TRANSLINE_BASE( parent, id, pos, size, style, name )
|
PANEL_TRANSLINE_BASE( parent, id, pos, size, style, name )
|
||||||
{
|
{
|
||||||
|
SetName( GetWindowName() );
|
||||||
m_currTransLine = nullptr;
|
m_currTransLine = nullptr;
|
||||||
m_currTransLineType = DEFAULT_TYPE;
|
m_currTransLineType = DEFAULT_TYPE;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ 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,6 +60,8 @@ 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,6 +34,8 @@ 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;
|
||||||
|
|
|
@ -82,8 +82,10 @@ 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()
|
||||||
{
|
{
|
||||||
PCB_CALCULATOR_FRAME* frame = (PCB_CALCULATOR_FRAME*) wxTheApp->GetTopWindow();
|
PANEL_TRANSLINE* panel = static_cast <PANEL_TRANSLINE*>(
|
||||||
return frame->GetCalculator<PANEL_TRANSLINE>();
|
wxFindWindowByName( PANEL_TRANSLINE::GetWindowName() ) );
|
||||||
|
wxASSERT( panel );
|
||||||
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,6 @@ 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 ).name() ] = aPanel;
|
|
||||||
|
|
||||||
m_notebook->AddPage( aPanel, panelUIName, false );
|
m_notebook->AddPage( aPanel, panelUIName, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,16 +49,14 @@ 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()
|
||||||
{
|
{
|
||||||
std::map<const char*, CALCULATOR_PANEL*>::iterator panel = m_panelTypes.find( typeid( T ).name() );
|
return static_cast<T*>( wxFindWindowByName( T::GetWindowName() ) );
|
||||||
|
|
||||||
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 );
|
||||||
|
@ -84,9 +82,6 @@ private:
|
||||||
bool m_macHack;
|
bool m_macHack;
|
||||||
|
|
||||||
std::vector<CALCULATOR_PANEL*> m_panels;
|
std::vector<CALCULATOR_PANEL*> m_panels;
|
||||||
std::map<const char*, CALCULATOR_PANEL*> m_panelTypes;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue