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:
jean-pierre charras 2021-10-10 14:14:15 +02:00
parent 593324bbaa
commit a92516bcd2
11 changed files with 23 additions and 14 deletions

View File

@ -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 ) );

View File

@ -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

View File

@ -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" ) );

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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( "" ) );

View File

@ -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;

View File

@ -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;
} }

View File

@ -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 );
} }

View File

@ -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;
}; };