diff --git a/pcb_calculator/calculator_panels/panel_attenuators.cpp b/pcb_calculator/calculator_panels/panel_attenuators.cpp index 644cd9817f..061e988401 100644 --- a/pcb_calculator/calculator_panels/panel_attenuators.cpp +++ b/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 ) ); diff --git a/pcb_calculator/calculator_panels/panel_attenuators.h b/pcb_calculator/calculator_panels/panel_attenuators.h index 3c805eefcc..287ee4e68e 100644 --- a/pcb_calculator/calculator_panels/panel_attenuators.h +++ b/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 diff --git a/pcb_calculator/calculator_panels/panel_regulator.cpp b/pcb_calculator/calculator_panels/panel_regulator.cpp index 1bf59d0d85..82474fc51a 100644 --- a/pcb_calculator/calculator_panels/panel_regulator.cpp +++ b/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" ) ); diff --git a/pcb_calculator/calculator_panels/panel_regulator.h b/pcb_calculator/calculator_panels/panel_regulator.h index df631cf289..ad8c3de850 100644 --- a/pcb_calculator/calculator_panels/panel_regulator.h +++ b/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; diff --git a/pcb_calculator/calculator_panels/panel_transline.cpp b/pcb_calculator/calculator_panels/panel_transline.cpp index 52f4d73f11..0131d3a49b 100644 --- a/pcb_calculator/calculator_panels/panel_transline.cpp +++ b/pcb_calculator/calculator_panels/panel_transline.cpp @@ -23,12 +23,12 @@ #include #include - 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; diff --git a/pcb_calculator/calculator_panels/panel_transline.h b/pcb_calculator/calculator_panels/panel_transline.h index 5836beb6db..d753f196c3 100644 --- a/pcb_calculator/calculator_panels/panel_transline.h +++ b/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; diff --git a/pcb_calculator/calculator_panels/panel_via_size.cpp b/pcb_calculator/calculator_panels/panel_via_size.cpp index ddad3512da..3cb261533c 100644 --- a/pcb_calculator/calculator_panels/panel_via_size.cpp +++ b/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( "Ω" ) ); diff --git a/pcb_calculator/calculator_panels/panel_via_size.h b/pcb_calculator/calculator_panels/panel_via_size.h index 4f393ef3a6..5837e91dca 100644 --- a/pcb_calculator/calculator_panels/panel_via_size.h +++ b/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; diff --git a/pcb_calculator/params_read_write.cpp b/pcb_calculator/params_read_write.cpp index 452a5f1fd4..1b818a21e3 100644 --- a/pcb_calculator/params_read_write.cpp +++ b/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 = static_cast ( + wxFindWindowByName( PANEL_TRANSLINE::GetWindowName() ) ); + wxASSERT( panel ); + return panel; } diff --git a/pcb_calculator/pcb_calculator_frame.cpp b/pcb_calculator/pcb_calculator_frame.cpp index 0fe5d4190b..2ff79a3548 100644 --- a/pcb_calculator/pcb_calculator_frame.cpp +++ b/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 ); } diff --git a/pcb_calculator/pcb_calculator_frame.h b/pcb_calculator/pcb_calculator_frame.h index 7ae9a02881..27d960ba53 100644 --- a/pcb_calculator/pcb_calculator_frame.h +++ b/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 T* GetCalculator() { - std::map::iterator panel = m_panelTypes.find( typeid( T ).name() ); - - if( panel != m_panelTypes.end() ) - return static_cast( panel->second ); - - return nullptr; + return static_cast( wxFindWindowByName( T::GetWindowName() ) ); } void AddCalculator( CALCULATOR_PANEL *aPanel, const wxString& panelUIName ); @@ -84,9 +82,6 @@ private: bool m_macHack; std::vector m_panels; - std::map m_panelTypes; - - };