diff --git a/pcb_calculator/calculator_panels/calculator_panel.h b/pcb_calculator/calculator_panels/calculator_panel.h index a02e7b17c9..be757e6a79 100644 --- a/pcb_calculator/calculator_panels/calculator_panel.h +++ b/pcb_calculator/calculator_panels/calculator_panel.h @@ -33,7 +33,7 @@ public: : wxPanel( aParent, aId, aPos, aSize, aStyle, aName ) {} - ~CALCULATOR_PANEL() {} + virtual ~CALCULATOR_PANEL() {} /** * Load the settings into the panel diff --git a/pcb_calculator/calculator_panels/panel_attenuators.cpp b/pcb_calculator/calculator_panels/panel_attenuators.cpp index f2c563dd27..3495dee0ac 100644 --- a/pcb_calculator/calculator_panels/panel_attenuators.cpp +++ b/pcb_calculator/calculator_panels/panel_attenuators.cpp @@ -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 ) ); diff --git a/pcb_calculator/calculator_panels/panel_attenuators.h b/pcb_calculator/calculator_panels/panel_attenuators.h index 2f23625582..aae3bc164f 100644 --- a/pcb_calculator/calculator_panels/panel_attenuators.h +++ b/pcb_calculator/calculator_panels/panel_attenuators.h @@ -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 diff --git a/pcb_calculator/calculator_panels/panel_regulator.cpp b/pcb_calculator/calculator_panels/panel_regulator.cpp index c15f265142..bc9ebabb69 100644 --- a/pcb_calculator/calculator_panels/panel_regulator.cpp +++ b/pcb_calculator/calculator_panels/panel_regulator.cpp @@ -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Ω" ) ); diff --git a/pcb_calculator/calculator_panels/panel_regulator.h b/pcb_calculator/calculator_panels/panel_regulator.h index ad8c3de850..df631cf289 100644 --- a/pcb_calculator/calculator_panels/panel_regulator.h +++ b/pcb_calculator/calculator_panels/panel_regulator.h @@ -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; diff --git a/pcb_calculator/calculator_panels/panel_transline.cpp b/pcb_calculator/calculator_panels/panel_transline.cpp index 522e3812b0..bea1232f67 100644 --- a/pcb_calculator/calculator_panels/panel_transline.cpp +++ b/pcb_calculator/calculator_panels/panel_transline.cpp @@ -24,6 +24,7 @@ #include #include + 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 ) ); diff --git a/pcb_calculator/calculator_panels/panel_transline.h b/pcb_calculator/calculator_panels/panel_transline.h index b8ac1e37c9..2a6b3b79fc 100644 --- a/pcb_calculator/calculator_panels/panel_transline.h +++ b/pcb_calculator/calculator_panels/panel_transline.h @@ -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; diff --git a/pcb_calculator/calculator_panels/panel_via_size.cpp b/pcb_calculator/calculator_panels/panel_via_size.cpp index 9c68f3aef3..699aa0c9a3 100644 --- a/pcb_calculator/calculator_panels/panel_via_size.cpp +++ b/pcb_calculator/calculator_panels/panel_via_size.cpp @@ -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( "Ω" ) ); diff --git a/pcb_calculator/calculator_panels/panel_via_size.h b/pcb_calculator/calculator_panels/panel_via_size.h index 5837e91dca..4f393ef3a6 100644 --- a/pcb_calculator/calculator_panels/panel_via_size.h +++ b/pcb_calculator/calculator_panels/panel_via_size.h @@ -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; diff --git a/pcb_calculator/params_read_write.cpp b/pcb_calculator/params_read_write.cpp index 747f84c4e3..95d8b77285 100644 --- a/pcb_calculator/params_read_write.cpp +++ b/pcb_calculator/params_read_write.cpp @@ -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 ( - wxFindWindowByName( PANEL_TRANSLINE::GetWindowName() ) ); - wxASSERT( panel ); - return panel; + PCB_CALCULATOR_FRAME* frame = (PCB_CALCULATOR_FRAME*) wxTheApp->GetTopWindow(); + PANEL_TRANSLINE* transline = frame->GetCalculator(); + + wxASSERT( transline ); + return transline; } diff --git a/pcb_calculator/pcb_calculator_frame.cpp b/pcb_calculator/pcb_calculator_frame.cpp index 2ff79a3548..658eec3366 100644 --- a/pcb_calculator/pcb_calculator_frame.cpp +++ b/pcb_calculator/pcb_calculator_frame.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include #include #include @@ -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* translinePanel = GetCalculator(); + PANEL_ATTENUATORS* attenPanel = GetCalculator(); + PANEL_VIA_SIZE* viaSizePanel = GetCalculator(); + PANEL_REGULATOR* regulPanel = GetCalculator(); + PANEL_ELECTRICAL_SPACING* elecSpacingPanel = GetCalculator(); + + wxASSERT( translinePanel ); + wxASSERT( attenPanel ); + wxASSERT( viaSizePanel ); + wxASSERT( regulPanel ); + wxASSERT( elecSpacingPanel ); + { wxCommandEvent event2( wxEVT_RADIOBUTTON ); event2.SetEventObject( translinePanel->GetTranslineSelector() ); @@ -169,29 +184,22 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event ) translinePanel->GetTranslineSelector()->Command( event2 ); } - if( PANEL_ATTENUATORS* attenPanel = GetCalculator() ) + 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() ); - event2.SetInt( i ); + wxCommandEvent event2( wxEVT_RADIOBUTTON ); + event2.SetEventObject( attenPanel->GetAttenuatorsSelector() ); + event2.SetInt( i ); - attenPanel->GetAttenuatorsSelector()->Command( event2 ); - break; - } + attenPanel->GetAttenuatorsSelector()->Command( event2 ); + break; } - - attenPanel->UpdateUI(); } - if( PANEL_VIA_SIZE* viaSizePanel = GetCalculator() ) - viaSizePanel->Layout(); - - if( PANEL_REGULATOR* regulPanel = GetCalculator() ) - regulPanel->Layout(); + attenPanel->UpdateUI(); + viaSizePanel->Layout(); + regulPanel->Layout(); // 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. @@ -202,20 +210,17 @@ void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event ) #ifdef __WXMAC__ if( m_macHack ) { - if( PANEL_ELECTRICAL_SPACING* elecSpacingPanel = GetCalculator() ) - { - wxSize pageSize = elecSpacingPanel->GetSize(); + wxSize pageSize = elecSpacingPanel->GetSize(); - pageSize.x -= 100; - elecSpacingPanel->SetSize( pageSize ); - elecSpacingPanel->Layout(); + pageSize.x -= 100; + elecSpacingPanel->SetSize( pageSize ); + elecSpacingPanel->Layout(); - pageSize.x += 100; - elecSpacingPanel->SetSize( pageSize ); - elecSpacingPanel->Layout(); + pageSize.x += 100; + elecSpacingPanel->SetSize( pageSize ); + elecSpacingPanel->Layout(); - m_macHack = false; - } + m_macHack = false; } #endif @@ -229,7 +234,9 @@ void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event ) { PANEL_REGULATOR* regPanel = GetCalculator(); - if( regPanel && regPanel->m_RegulatorListChanged ) + wxASSERT( regPanel ); + + if( regPanel->m_RegulatorListChanged ) { wxString msg; wxString title = _( "Write Data Failed" ); diff --git a/pcb_calculator/pcb_calculator_frame.h b/pcb_calculator/pcb_calculator_frame.h index 27d960ba53..93f6991d8b 100644 --- a/pcb_calculator/pcb_calculator_frame.h +++ b/pcb_calculator/pcb_calculator_frame.h @@ -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 T* GetCalculator() { - return static_cast( wxFindWindowByName( T::GetWindowName() ) ); + std::map::iterator panel = m_panelTypes.find( typeid( T ).hash_code() ); + + if( panel != m_panelTypes.end() ) + return static_cast( panel->second ); + + return nullptr; } void AddCalculator( CALCULATOR_PANEL *aPanel, const wxString& panelUIName ); @@ -82,6 +84,9 @@ private: bool m_macHack; std::vector m_panels; + std::map m_panelTypes; + + };