Browse Source

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
6.0.7
jean-pierre charras 4 years ago
parent
commit
a92516bcd2
  1. 2
      pcb_calculator/calculator_panels/panel_attenuators.cpp
  2. 2
      pcb_calculator/calculator_panels/panel_attenuators.h
  3. 2
      pcb_calculator/calculator_panels/panel_regulator.cpp
  4. 2
      pcb_calculator/calculator_panels/panel_regulator.h
  5. 2
      pcb_calculator/calculator_panels/panel_transline.cpp
  6. 2
      pcb_calculator/calculator_panels/panel_transline.h
  7. 2
      pcb_calculator/calculator_panels/panel_via_size.cpp
  8. 2
      pcb_calculator/calculator_panels/panel_via_size.h
  9. 6
      pcb_calculator/params_read_write.cpp
  10. 2
      pcb_calculator/pcb_calculator_frame.cpp
  11. 13
      pcb_calculator/pcb_calculator_frame.h

2
pcb_calculator/calculator_panels/panel_attenuators.cpp

@ -38,6 +38,8 @@ 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 ) );

2
pcb_calculator/calculator_panels/panel_attenuators.h

@ -36,6 +36,8 @@ 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

2
pcb_calculator/calculator_panels/panel_regulator.cpp

@ -42,6 +42,8 @@ PANEL_REGULATOR::PANEL_REGULATOR( wxWindow* parent, wxWindowID id,
long style, const wxString& name ) :
PANEL_REGULATOR_BASE( parent, id, pos, size, style, name )
{
SetName( GetWindowName() );
m_RegulatorListChanged = false;
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );

2
pcb_calculator/calculator_panels/panel_regulator.h

@ -35,6 +35,8 @@ public:
public:
static wxString GetWindowName() { return wxT( "PANEL_REGULATOR" ); }
void OnRegulatorCalcButtonClick( wxCommandEvent& event ) override;
void OnRegulatorResetButtonClick( wxCommandEvent& event ) override;
void OnRegulTypeSelection( wxCommandEvent& event ) override;

2
pcb_calculator/calculator_panels/panel_transline.cpp

@ -23,12 +23,12 @@
#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 ) :
PANEL_TRANSLINE_BASE( parent, id, pos, size, style, name )
{
SetName( GetWindowName() );
m_currTransLine = nullptr;
m_currTransLineType = DEFAULT_TYPE;

2
pcb_calculator/calculator_panels/panel_transline.h

@ -36,6 +36,8 @@ 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;

2
pcb_calculator/calculator_panels/panel_via_size.cpp

@ -60,6 +60,8 @@ 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( "" ) );

2
pcb_calculator/calculator_panels/panel_via_size.h

@ -34,6 +34,8 @@ 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;

6
pcb_calculator/params_read_write.cpp

@ -82,8 +82,10 @@ double DoubleFromString( const wxString& TextValue )
// A helper function to get a reference to the PANEL_TRANSLINE
PANEL_TRANSLINE* getTranslinePanel()
{
PCB_CALCULATOR_FRAME* frame = (PCB_CALCULATOR_FRAME*) wxTheApp->GetTopWindow();
return frame->GetCalculator<PANEL_TRANSLINE>();
PANEL_TRANSLINE* panel = static_cast <PANEL_TRANSLINE*>(
wxFindWindowByName( PANEL_TRANSLINE::GetWindowName() ) );
wxASSERT( panel );
return panel;
}

2
pcb_calculator/pcb_calculator_frame.cpp

@ -137,8 +137,6 @@ void PCB_CALCULATOR_FRAME::AddCalculator( CALCULATOR_PANEL *aPanel, const wxStri
{
// Update internal structures
m_panels.push_back( aPanel );
m_panelTypes[ typeid( aPanel ).name() ] = aPanel;
m_notebook->AddPage( aPanel, panelUIName, false );
}

13
pcb_calculator/pcb_calculator_frame.h

@ -49,16 +49,14 @@ 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()
{
std::map<const char*, CALCULATOR_PANEL*>::iterator panel = m_panelTypes.find( typeid( T ).name() );
if( panel != m_panelTypes.end() )
return static_cast<T*>( panel->second );
return nullptr;
return static_cast<T*>( wxFindWindowByName( T::GetWindowName() ) );
}
void AddCalculator( CALCULATOR_PANEL *aPanel, const wxString& panelUIName );
@ -84,9 +82,6 @@ private:
bool m_macHack;
std::vector<CALCULATOR_PANEL*> m_panels;
std::map<const char*, CALCULATOR_PANEL*> m_panelTypes;
};

Loading…
Cancel
Save