A veritable cornucopia of wxWidgets hacks for pcb calculator.

Most of these are display hacks because (at least on OSX) assigning
bitmaps or doing a layout before the controls are visible tends to
not work.  There are also some layout cleanups and some layout hacks
(horizontal radio button groups, for instance, lay out on top of each
other on OSX).

Fixes https://gitlab.com/kicad/code/kicad/issues/7491
This commit is contained in:
Jeff Young 2021-02-11 23:43:08 +00:00
parent baed5ed1cb
commit 9094ba8033
10 changed files with 2275 additions and 1776 deletions

View File

@ -78,6 +78,11 @@ void PCB_CALCULATOR_FRAME::TransfPanelDataToAttenuator()
void PCB_CALCULATOR_FRAME::TransfAttenuatorDataToPanel()
{
// TODO: make attenuator bitmaps transparent so we can remove this
m_attenuatorPanel->SetBackgroundColour( *wxWHITE );
m_attenuatorBitmap->SetBitmap( *m_currAttenuator->m_SchBitMap );
wxString msg;
msg.Printf( wxT( "%g" ), m_currAttenuator->m_Attenuation );
@ -99,7 +104,9 @@ void PCB_CALCULATOR_FRAME::TransfAttenuatorDataToPanel()
if( m_currAttenuator->m_FormulaName )
{
if( m_currAttenuator->m_FormulaName->StartsWith( "<!" ) )
{
m_panelAttFormula->SetPage( *m_currAttenuator->m_FormulaName );
}
else
{
wxString html_txt;
@ -108,7 +115,9 @@ void PCB_CALCULATOR_FRAME::TransfAttenuatorDataToPanel()
}
}
else
{
m_panelAttFormula->SetPage( wxEmptyString );
}
}
@ -140,8 +149,11 @@ void PCB_CALCULATOR_FRAME::TransfAttenuatorResultsToPanel()
m_Att_R1_Value->SetValue( msg );
msg.Printf( wxT( "%g" ), m_currAttenuator->m_R2 );
m_Att_R2_Value->SetValue( msg );
if( m_currAttenuator->m_ResultCount < 3 )
{
m_Att_R3_Value->SetValue( wxEmptyString );
}
else
{
msg.Printf( wxT( "%g" ), m_currAttenuator->m_R3 );
@ -150,17 +162,3 @@ void PCB_CALCULATOR_FRAME::TransfAttenuatorResultsToPanel()
}
void PCB_CALCULATOR_FRAME::OnPaintAttenuatorPanel( wxPaintEvent& event )
{
wxPaintDC dc( m_panelDisplayAttenuator );
if( m_currAttenuator && m_currAttenuator->m_SchBitMap )
{
wxSize size = m_panelDisplayAttenuator->GetSize();
size.x -= m_currAttenuator->m_SchBitMap->GetWidth();
size.y -= m_currAttenuator->m_SchBitMap->GetHeight();
dc.DrawBitmap( *m_currAttenuator->m_SchBitMap, size.x / 2, size.y / 2 );
}
event.Skip();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -30,13 +30,13 @@ class UNIT_SELECTOR_THICKNESS;
#include <wx/icon.h>
#include <wx/statbmp.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/statbox.h>
#include <wx/radiobut.h>
#include <wx/textctrl.h>
#include <wx/choice.h>
#include <wx/button.h>
#include <wx/panel.h>
#include <wx/radiobox.h>
#include <wx/bmpbuttn.h>
#include <wx/html/htmlwin.h>
@ -60,6 +60,7 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
wxStatusBar* m_statusBar;
wxNotebook* m_Notebook;
wxPanel* m_panelRegulators;
wxPanel* m_panelRegulatorBitmaps;
wxStaticBitmap* m_bitmapRegul4pins;
wxStaticBitmap* m_bitmapRegul3pins;
wxStaticText* m_RegulFormula;
@ -95,7 +96,8 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
wxStaticText* m_RegulMessage;
wxPanel* m_panelAttenuators;
wxRadioBox* m_AttenuatorsSelection;
wxPanel* m_panelDisplayAttenuator;
wxPanel* m_attenuatorPanel;
wxStaticBitmap* m_attenuatorBitmap;
wxStaticText* m_attenuationLabel;
wxTextCtrl* m_AttValueCtrl;
wxStaticText* m_attUnit;
@ -120,7 +122,6 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
wxHtmlWindow* m_Attenuator_Messages;
wxHtmlWindow* m_panelAttFormula;
wxPanel* m_panelESeries;
wxStaticText* m_staticTextESeriesMsg111;
wxStaticText* m_ESrequired;
wxTextCtrl* m_ResRequired;
wxStaticText* m_UnitRegultR111;
@ -130,7 +131,11 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
wxStaticText* m_ESrequired11;
wxTextCtrl* m_ResExclude2;
wxStaticText* m_UnitRegultR1112;
wxRadioBox* m_rbESerieSelection;
wxStaticLine* m_staticline6;
wxRadioButton* m_e1;
wxRadioButton* m_e3;
wxRadioButton* m_e6;
wxRadioButton* m_e12;
wxStaticText* m_ESerieSimpleSolution;
wxTextCtrl* m_ESeries_Sol2R;
wxStaticText* m_ESeriesSimpleErr;
@ -146,6 +151,7 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
wxStaticText* m_ESeriesAltErr1;
wxTextCtrl* m_ESeriesError4R;
wxStaticText* m_ESeriesAltPercent1;
wxStaticLine* m_staticline7;
wxButton* m_buttonEScalculate;
wxHtmlWindow* m_panelESeriesHelp;
wxPanel* m_panelColorCode;
@ -164,7 +170,8 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
wxStaticBitmap* m_Band_tol_bitmap;
wxPanel* m_panelTransline;
wxRadioBox* m_TranslineSelection;
wxPanel* m_panelDisplayshape;
wxPanel* m_translinePanel;
wxStaticBitmap* m_translineBitmap;
wxStaticLine* m_staticline1;
wxStaticText* m_EpsilonR_label;
wxTextCtrl* m_Value_EpsilonR;
@ -374,6 +381,7 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
// Virtual event handlers, overide them in your derived class
virtual void OnClosePcbCalc( wxCloseEvent& event ) { event.Skip(); }
virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void OnRegulTypeSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRegulatorResetButtonClick( wxCommandEvent& event ) { event.Skip(); }
@ -383,13 +391,11 @@ class PCB_CALCULATOR_FRAME_BASE : public KIWAY_PLAYER
virtual void OnAddRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnAttenuatorSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnPaintAttenuatorPanel( wxPaintEvent& event ) { event.Skip(); }
virtual void OnCalculateAttenuator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnESerieSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnESeriesSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCalculateESeries( wxCommandEvent& event ) { event.Skip(); }
virtual void OnToleranceSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTranslineSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnPaintTranslinePanel( wxPaintEvent& event ) { event.Skip(); }
virtual void OnTranslineEpsilonR_Button( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTranslineTanD_Button( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTranslineRho_Button( wxCommandEvent& event ) { event.Skip(); }

View File

@ -53,11 +53,6 @@ void eserie::set_rb( uint32_t a_rb )
rb_state = a_rb;
}
uint32_t eserie::get_rb( void )
{
return rb_state;
}
std::array<r_data, S4R + 1> eserie::get_rslt( void )
{
return results;
@ -414,9 +409,16 @@ void PCB_CALCULATOR_FRAME::OnCalculateESeries( wxCommandEvent& event )
m_ESeries_Sol4R->SetValue( fs );
}
void PCB_CALCULATOR_FRAME::OnESerieSelection( wxCommandEvent& event )
void PCB_CALCULATOR_FRAME::OnESeriesSelection( wxCommandEvent& event )
{
r.set_rb ( event.GetSelection() );
if( event.GetEventObject() == m_e1 )
r.set_rb( E1 );
else if( event.GetEventObject() == m_e3 )
r.set_rb( E3 );
else if( event.GetEventObject() == m_e12 )
r.set_rb( E12 );
else
r.set_rb( E6 );
}
void PCB_CALCULATOR_FRAME::ES_Init() // initialize ESeries tab at each pcb-calculator start

View File

@ -232,10 +232,7 @@ public:
/**
* Interface for CheckBox, RadioButton, RequriedResistor and calculated Results
*/
void set_4R_cb ( bool a_tb );
bool get_4R_cb ( void );
void set_rb ( uint32_t a_rb );
uint32_t get_rb ( void );
void set_reqR ( double aR );
std::array<r_data,S4R+1> get_rslt ( void );
};

View File

@ -22,17 +22,22 @@
#include <bitmaps.h>
#include <geometry/shape_poly_set.h>
#include <kiface_i.h>
#include "bitmaps/color_code_value_and_name.xpm"
#include "bitmaps/color_code_value.xpm"
#include "bitmaps/color_code_multiplier.xpm"
#include "bitmaps/color_code_tolerance.xpm"
#include "attenuators/attenuator_classes.h"
#include "class_regulator_data.h"
#include "pcb_calculator_frame.h"
#include "pcb_calculator_settings.h"
// extension of pcb_calculator data filename:
const wxString DataFileNameExt( wxT("pcbcalc") );
PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
PCB_CALCULATOR_FRAME_BASE( aParent )
PCB_CALCULATOR_FRAME_BASE( aParent ),
m_lastNotebookPage( -1 )
{
m_bpButtonCalcAtt->SetBitmap( KiBitmap( small_down_xpm ) );
m_bpButtonAnalyze->SetBitmap( KiBitmap( small_down_xpm ) );
@ -46,16 +51,24 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_TWMode = TW_MASTER_CURRENT;
m_TWNested = false;
// TODO: make regulator bitmaps transparent so we can remove this
m_panelRegulatorBitmaps->SetBackgroundColour( *wxWHITE );
SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
// some methods in code and avoid link errors
// Populate transline list ordered like in dialog menu list
const static TRANSLINE_TYPE_ID tltype_list[8] =
{
MICROSTRIP_TYPE, CPW_TYPE, GROUNDED_CPW_TYPE,
RECTWAVEGUIDE_TYPE, COAX_TYPE, C_MICROSTRIP_TYPE,
STRIPLINE_TYPE, TWISTEDPAIR_TYPE
};
{
MICROSTRIP_TYPE,
CPW_TYPE,
GROUNDED_CPW_TYPE,
RECTWAVEGUIDE_TYPE,
COAX_TYPE,
C_MICROSTRIP_TYPE,
STRIPLINE_TYPE,
TWISTEDPAIR_TYPE
};
for( int ii = 0; ii < 8; ii++ )
m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) );
@ -67,6 +80,10 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
m_currAttenuator = m_attenuator_list[0];
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_staticTextAttMsg->SetFont( infoFont );
LoadSettings( config() );
ReadDataFile();
@ -120,49 +137,89 @@ PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME()
for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
delete m_attenuator_list[ii];
/* This needed for OSX: avoids furter OnDraw processing after this
* destructor and before the native window is destroyed
*/
// This needed for OSX: avoids furter OnDraw processing after this destructor and before
// the native window is destroyed
this->Freeze();
}
void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
{
if( m_Notebook->GetSelection() != m_lastNotebookPage )
{
// Kick all the things that wxWidgets can't seem to redraw on its own.
wxCommandEvent event2( wxEVT_RADIOBUTTON );
event2.SetEventObject( m_TranslineSelection );
event2.SetInt( m_currTransLineType );
m_TranslineSelection->ProcessCommand( event2 );
for( int i = 0; i < m_attenuator_list.size(); ++i )
{
if( m_attenuator_list[i] == m_currAttenuator )
{
event2.SetEventObject( m_AttenuatorsSelection );
event2.SetInt( i );
m_AttenuatorsSelection->ProcessCommand( event2 );
break;
}
}
static wxBitmap* valueNameBitmap = new wxBitmap( color_code_value_and_name_xpm );
m_Band1bitmap->SetBitmap( *valueNameBitmap );
static wxBitmap* valueBitmap = new wxBitmap( color_code_value_xpm );
m_Band2bitmap->SetBitmap( *valueBitmap );
m_Band3bitmap->SetBitmap( *valueBitmap );
m_Band4bitmap->SetBitmap( *valueBitmap );
static wxBitmap* multiplierBitmap = new wxBitmap( color_code_multiplier_xpm );
m_Band_mult_bitmap->SetBitmap( *multiplierBitmap );
static wxBitmap* toleranceBitmap = new wxBitmap( color_code_tolerance_xpm );
m_Band_tol_bitmap->SetBitmap( *toleranceBitmap );
// 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.
if( m_Notebook->IsShownOnScreen() )
m_lastNotebookPage = m_Notebook->GetSelection();
}
}
void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
{
if( m_RegulatorListChanged )
{
wxString msg;
wxString title = _( "Write Data Failed" );
if( GetDataFilename().IsEmpty() )
{
int opt = wxMessageBox(
_("Data modified, and no data filename to save modifications\n"\
"Do you want to exit and abandon your change?"),
_("Regulator list change"),
wxYES_NO | wxICON_QUESTION );
msg = _( "No data filename to save modifications.\n"
"Do you want to exit and abandon your changes?" );
if( opt == wxNO )
if( wxMessageBox( msg, title, wxYES_NO | wxICON_QUESTION ) == wxNO )
return;
}
else
{
if( !WriteDataFile() )
{
wxString msg;
msg.Printf( _("Unable to write file \"%s\"\n"\
"Do you want to exit and abandon your change?"),
msg.Printf( _( "Unable to write file '%s'\n"
"Do you want to exit and abandon your changes?"),
GetDataFilename() );
int opt = wxMessageBox( msg, _("Write Data File Error"),
wxYES_NO | wxICON_ERROR );
if( opt == wxNO )
if( wxMessageBox( msg, title, wxYES_NO | wxICON_ERROR ) == wxNO )
return;
}
}
}
event.Skip();
// Destroy();
}
void PCB_CALCULATOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
if( aCfg == NULL )
@ -199,10 +256,10 @@ void PCB_CALCULATOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
m_ElectricalSpacingUnitsSelector->SetSelection( cfg->m_Electrical.spacing_units );
m_ElectricalSpacingVoltage->SetValue( cfg->m_Electrical.spacing_voltage );
for( auto& transline : m_transline_list )
for( TRANSLINE_IDENT* transline : m_transline_list )
transline->ReadConfig();
for( auto& attenuator : m_attenuator_list )
for( ATTENUATOR* attenuator : m_attenuator_list )
attenuator->ReadConfig();
}
@ -273,23 +330,6 @@ void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event )
}
void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event )
{
wxPaintDC dc( m_panelDisplayshape );
TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
if( tr_ident )
{
wxSize size = m_panelDisplayshape->GetSize();
size.x -= tr_ident->m_Icon->GetWidth();
size.y -= tr_ident->m_Icon->GetHeight();
dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 );
}
event.Skip();
}
/* returns the full filename of the selected pcb_calculator data file
* the extension file is forced
*/
@ -303,6 +343,7 @@ const wxString PCB_CALCULATOR_FRAME::GetDataFilename()
return fn.GetFullPath();
}
/* Initialize the full filename of the selected pcb_calculator data file
* force the standard extension of the file (.pcbcalc)
* aFilename = the full filename, with or without extension

View File

@ -70,6 +70,9 @@ private:
std::vector<ATTENUATOR*> m_attenuator_list;
wxString m_lastSelectedRegulatorName; // last regulator name selected
int m_lastNotebookPage;
int m_lastRadioButton;
public:
PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
~PCB_CALCULATOR_FRAME();
@ -78,10 +81,7 @@ private:
// Event handlers
void OnClosePcbCalc( wxCloseEvent& event ) override;
// These 3 functions are called by the OnPaint event, to draw
// icons that show the current item on the specific panels
void OnPaintTranslinePanel( wxPaintEvent& event ) override;
void OnPaintAttenuatorPanel( wxPaintEvent& event ) override;
void OnUpdateUI( wxUpdateUIEvent& event ) override;
// Config read-write, virtual from EDA_BASE_FRAME
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
@ -127,7 +127,7 @@ private:
* Radio Buttons to select the E-serie for the resistor calculator
* @param event contains the radio button state
*/
void OnESerieSelection( wxCommandEvent& event ) override;
void OnESeriesSelection( wxCommandEvent& event ) override;
/**
* Function TW_WriteConfig
@ -174,23 +174,23 @@ private:
* Function TWCalculateWidth
* Calculate track width required based on given current and temperature rise.
*/
double TWCalculateWidth(
double aCurrent, double aThickness, double aDeltaT_C, bool aUseInternalLayer );
double TWCalculateWidth( double aCurrent, double aThickness, double aDeltaT_C,
bool aUseInternalLayer );
/**
* Function TWCalculateCurrent
* Calculate maximum current based on given width and temperature rise.
*/
double TWCalculateCurrent(
double aWidth, double aThickness, double aDeltaT_C, bool aUseInternalLayer );
double TWCalculateCurrent( double aWidth, double aThickness, double aDeltaT_C,
bool aUseInternalLayer );
/**
* Function TWDisplayValues
* Displays the results of a calculation (including resulting values such
* as the resistance and power loss).
*/
void TWDisplayValues( double aCurrent, double aExtWidth, double aIntWidth, double aExtThickness,
double aIntThickness );
void TWDisplayValues( double aCurrent, double aExtWidth, double aIntWidth,
double aExtThickness, double aIntThickness );
/**
* Function TWUpdateModeDisplay
@ -246,8 +246,9 @@ private:
* Displays the results of the calculation.
*/
void VSDisplayValues( double aViaResistance, double aVoltageDrop, double aPowerLoss,
double aEstimatedAmpacity, double aThermalResistance, double aCapacitance,
double aTimeDegradation, double aInductance, double aReactance );
double aEstimatedAmpacity, double aThermalResistance,
double aCapacitance, double aTimeDegradation, double aInductance,
double aReactance );
// Electrical spacing panel:
void OnElectricalSpacingUnitsSelection( wxCommandEvent& event ) override;

View File

@ -24,6 +24,8 @@
#include "common_data.h"
#include "pcb_calculator_frame.h"
#include "bitmaps/microstrip_zodd_zeven.xpm"
extern double DoubleFromString( const wxString& TextValue );
@ -103,10 +105,10 @@ static bool findMatch(wxArrayString& aList, const wxString& aValue, int& aIdx )
}
}
return success;
}
/**
* Function OnEpsilonR_Button
* Shows a list of current relative dielectric constant(Er)
@ -122,14 +124,14 @@ void PCB_CALCULATOR_FRAME::OnTranslineEpsilonR_Button( wxCommandEvent& event )
int prevChoice = 0;
findMatch( list, prevChoiceStr, prevChoice );
int index = wxGetSingleChoiceIndex( wxEmptyString,
_("Relative Dielectric Constants"),
int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Relative Dielectric Constants" ),
list, prevChoice );
if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
m_Value_EpsilonR->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
}
/**
* Function OnTanD_Button
* Shows a list of current dielectric loss factor (tangent delta)
@ -145,13 +147,14 @@ void PCB_CALCULATOR_FRAME::OnTranslineTanD_Button( wxCommandEvent& event )
int prevChoice = 0;
findMatch( list, prevChoiceStr, prevChoice );
int index = wxGetSingleChoiceIndex( wxEmptyString, _("Dielectric Loss Factor"),
list, prevChoice, NULL);
int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Dielectric Loss Factor" ), list,
prevChoice, NULL );
if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
m_Value_TanD->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
}
/**
* Function OnTranslineRho_Button
* Shows a list of current Specific resistance list (rho)
@ -167,20 +170,23 @@ void PCB_CALCULATOR_FRAME::OnTranslineRho_Button( wxCommandEvent& event )
int prevChoice = 0;
findMatch( list, prevChoiceStr, prevChoice );
int index = wxGetSingleChoiceIndex( wxEmptyString, _("Specific Resistance"),
list, prevChoice, NULL);
int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Specific Resistance" ), list,
prevChoice, NULL );
if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
m_Value_Rho->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
}
// Minor helper struct to handle dialog items for a given parameter
struct DLG_PRM_DATA
{
wxStaticText * name;
wxTextCtrl * value;
UNIT_SELECTOR * unit;
wxStaticText* name;
wxTextCtrl* value;
UNIT_SELECTOR* unit;
};
/**
* Function TranslineTypeSelection
* Must be called after selection of a new transline.
@ -191,17 +197,25 @@ struct DLG_PRM_DATA
*/
void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType )
{
wxString msg;
#define DOUBLE_TO_CTLR( dlg_item, value ) { msg.Printf( wxT( "%g" ), value );\
dlg_item->SetValue( msg ); }
m_currTransLineType = aType;
if( (m_currTransLineType < START_OF_LIST_TYPE )
|| ( m_currTransLineType >= END_OF_LIST_TYPE ) )
|| ( m_currTransLineType >= END_OF_LIST_TYPE ) )
{
m_currTransLineType = DEFAULT_TYPE;
}
// TODO: make transline bitmaps transparent so we can remove this
m_translinePanel->SetBackgroundColour( *wxWHITE );
m_translineBitmap->SetBitmap( *m_transline_list[m_currTransLineType]->m_Icon );
// This helper bitmap is shown for coupled microstrip only:
m_bmCMicrostripZoddZeven->Show( aType == C_MICROSTRIP_TYPE );
static wxBitmap* microstrip = new wxBitmap( microstrip_zodd_zeven_xpm );
m_bmCMicrostripZoddZeven->SetBitmap( *microstrip );
m_fgSizerZcomment->Show( aType == C_MICROSTRIP_TYPE );
TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
@ -246,28 +260,28 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
{ m_EpsilonR_label,m_Value_EpsilonR, NULL },
{ m_TanD_label,m_Value_TanD, NULL },
{ m_Rho_label, m_Value_Rho, NULL },
{ m_substrate_prm4_label,m_Substrate_prm4_Value, m_SubsPrm4_choiceUnit },
{ m_substrate_prm5_label,m_Substrate_prm5_Value, m_SubsPrm5_choiceUnit },
{ m_substrate_prm6_label,m_Substrate_prm6_Value, m_SubsPrm6_choiceUnit },
{ m_substrate_prm7_label,m_Substrate_prm7_Value, m_SubsPrm7_choiceUnit },
{ m_substrate_prm8_label,m_Substrate_prm8_Value, m_SubsPrm8_choiceUnit },
{ m_substrate_prm9_label,m_Substrate_prm9_Value, m_SubsPrm9_choiceUnit }
{ m_substrate_prm4_label, m_Substrate_prm4_Value, m_SubsPrm4_choiceUnit },
{ m_substrate_prm5_label, m_Substrate_prm5_Value, m_SubsPrm5_choiceUnit },
{ m_substrate_prm6_label, m_Substrate_prm6_Value, m_SubsPrm6_choiceUnit },
{ m_substrate_prm7_label, m_Substrate_prm7_Value, m_SubsPrm7_choiceUnit },
{ m_substrate_prm8_label, m_Substrate_prm8_Value, m_SubsPrm8_choiceUnit },
{ m_substrate_prm9_label, m_Substrate_prm9_Value, m_SubsPrm9_choiceUnit }
};
#define substrateprms_cnt (sizeof(substrateprms)/sizeof(substrateprms[0]))
struct DLG_PRM_DATA physprms[] =
{
{ m_phys_prm1_label,m_Phys_prm1_Value,m_choiceUnit_Param1 },
{ m_phys_prm2_label,m_Phys_prm2_Value,m_choiceUnit_Param2 },
{ m_phys_prm3_label,m_Phys_prm3_Value,m_choiceUnit_Param3 }
{ m_phys_prm1_label, m_Phys_prm1_Value, m_choiceUnit_Param1 },
{ m_phys_prm2_label, m_Phys_prm2_Value, m_choiceUnit_Param2 },
{ m_phys_prm3_label, m_Phys_prm3_Value, m_choiceUnit_Param3 }
};
#define physprms_cnt (sizeof(physprms)/sizeof(physprms[0]))
struct DLG_PRM_DATA elecprms[] =
{
{ m_elec_prm1_label,m_Elec_prm1_Value, m_choiceUnit_ElecPrm1 },
{ m_elec_prm2_label,m_Elec_prm2_Value, m_choiceUnit_ElecPrm2 },
{ m_elec_prm3_label,m_Elec_prm3_Value, m_choiceUnit_ElecPrm3 }
{ m_elec_prm1_label, m_Elec_prm1_Value, m_choiceUnit_ElecPrm1 },
{ m_elec_prm2_label, m_Elec_prm2_Value, m_choiceUnit_ElecPrm2 },
{ m_elec_prm3_label, m_Elec_prm3_Value, m_choiceUnit_ElecPrm3 }
};
#define elecprms_cnt (sizeof(elecprms)/sizeof(elecprms[0]))
@ -288,31 +302,31 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
struct DLG_PRM_DATA * data = NULL;
switch( prm->m_Type )
{
case PRM_TYPE_SUBS:
wxASSERT( idxsubs < substrateprms_cnt );
data = &substrateprms[idxsubs];
idxsubs++;
break;
case PRM_TYPE_SUBS:
wxASSERT( idxsubs < substrateprms_cnt );
data = &substrateprms[idxsubs];
idxsubs++;
break;
case PRM_TYPE_PHYS:
wxASSERT( idxphys < physprms_cnt );
data = &physprms[idxphys];
idxphys++;
break;
case PRM_TYPE_PHYS:
wxASSERT( idxphys < physprms_cnt );
data = &physprms[idxphys];
idxphys++;
break;
case PRM_TYPE_ELEC:
wxASSERT( idxelec < elecprms_cnt );
data = &elecprms[idxelec];
idxelec++;
break;
case PRM_TYPE_FREQUENCY:
wxASSERT( idxfreq < frequencyprms_cnt );
data = &frequencyprms[idxfreq];
idxfreq++;
break;
case PRM_TYPE_ELEC:
wxASSERT( idxelec < elecprms_cnt );
data = &elecprms[idxelec];
idxelec++;
break;
case PRM_TYPE_FREQUENCY:
wxASSERT( idxfreq < frequencyprms_cnt );
data = &frequencyprms[idxfreq];
idxfreq++;
break;
}
wxASSERT ( data );
data->name->SetToolTip( prm->m_ToolTip );
data->name->SetLabel( prm->m_DlgLabel != "" ? prm->m_DlgLabel + ':' : "" );
@ -320,7 +334,7 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
if( prm->m_Id != DUMMY_PRM )
{
DOUBLE_TO_CTLR( data->value, prm->m_Value );
data->value->SetValue( wxString::Format( "%g", prm->m_Value ) );
data->value->Enable( true );
}
else
@ -347,6 +361,7 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
substrateprms[idxsubs].name->SetToolTip(wxEmptyString);
substrateprms[idxsubs].value->SetValue(wxEmptyString);
substrateprms[idxsubs].value->Enable( false );
if( substrateprms[idxsubs].unit)
{
substrateprms[idxsubs].unit->Show( false );
@ -361,6 +376,7 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
physprms[idxphys].name->SetToolTip(wxEmptyString);
physprms[idxphys].value->SetValue(wxEmptyString);
physprms[idxphys].value->Enable( false );
if( physprms[idxphys].unit)
{
physprms[idxphys].unit->Show( false );
@ -375,6 +391,7 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
elecprms[idxelec].name->SetToolTip(wxEmptyString);
elecprms[idxelec].value->SetValue(wxEmptyString);
elecprms[idxelec].value->Enable( false );
if( elecprms[idxelec].unit)
{
elecprms[idxelec].unit->Show( false );
@ -389,6 +406,7 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
frequencyprms[idxfreq].name->SetToolTip(wxEmptyString);
frequencyprms[idxfreq].value->SetValue(wxEmptyString);
frequencyprms[idxfreq].value->Enable( false );
if( frequencyprms[idxfreq].unit )
{
frequencyprms[idxfreq].unit->Show( false );
@ -406,6 +424,7 @@ void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType
void PCB_CALCULATOR_FRAME::TransfDlgDataToTranslineParams()
{
TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
{
TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
@ -414,11 +433,13 @@ void PCB_CALCULATOR_FRAME::TransfDlgDataToTranslineParams()
double value = DoubleFromString(value_txt);
prm->m_Value = value;
UNIT_SELECTOR * unit_ctrl = (UNIT_SELECTOR * ) prm->m_UnitCtrl;
if( unit_ctrl )
{
prm->m_UnitSelection = unit_ctrl->GetSelection();
value *= unit_ctrl->GetUnitScale();
}
prm->m_NormalizedValue = value;
}
}
@ -427,7 +448,7 @@ void PCB_CALCULATOR_FRAME::TransfDlgDataToTranslineParams()
/**
* Function OnTranslineSelection
* Called on new transmission line selection
*/
*/
void PCB_CALCULATOR_FRAME::OnTranslineSelection( wxCommandEvent& event )
{
enum TRANSLINE_TYPE_ID id = (enum TRANSLINE_TYPE_ID) event.GetSelection();
@ -438,22 +459,6 @@ void PCB_CALCULATOR_FRAME::OnTranslineSelection( wxCommandEvent& event )
// The new size must be taken in account
m_panelTransline->GetSizer()->Layout();
m_panelTransline->Refresh();
// Delete previous warnings / errors
wxColour background = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
m_Value_EpsilonR->SetBackgroundColour( background );
m_Value_TanD->SetBackgroundColour( background );
m_Value_Rho->SetBackgroundColour( background );
m_Substrate_prm4_Value->SetBackgroundColour( background );
m_Substrate_prm5_Value->SetBackgroundColour( background );
m_Substrate_prm6_Value->SetBackgroundColour( background );
m_Substrate_prm7_Value->SetBackgroundColour( background );
m_Substrate_prm8_Value->SetBackgroundColour( background );
m_Substrate_prm9_Value->SetBackgroundColour( background );
m_Value_Frequency_Ctrl->SetBackgroundColour( background );
m_Phys_prm1_Value->SetBackgroundColour( background );
m_Phys_prm2_Value->SetBackgroundColour( background );
m_Phys_prm3_Value->SetBackgroundColour( background );
}
@ -461,7 +466,7 @@ void PCB_CALCULATOR_FRAME::OnTranslineSelection( wxCommandEvent& event )
* Function OnTransLineResetButtonClick
* Called when the user clicks the reset button. This sets
* the parameters to their default values.
*/
*/
void PCB_CALCULATOR_FRAME::OnTransLineResetButtonClick( wxCommandEvent& event )
{
TranslineTypeSelection( DEFAULT_TYPE );

View File

@ -108,10 +108,10 @@ double TRANSLINE_PRM::FromUserUnit()
TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
{
m_Type = aType; // The type of transline handled
m_Icon = NULL; // An xpm icon to display in dialogs
m_TLine = NULL; // The TRANSLINE itself
m_HasPrmSelection = false; // true if selection of parameters must be enabled in dialog menu
m_Type = aType; // The type of transline handled
m_Icon = NULL; // An xpm icon to display in dialogs
m_TLine = NULL; // The TRANSLINE itself
m_HasPrmSelection = false; // true if selection of parameters must be enabled in dialog menu
// Add common prms:
// Default values are for FR4
@ -139,7 +139,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
switch( m_Type )
{
case MICROSTRIP_TYPE: // microstrip
m_TLine = new MICROSTRIP();
m_TLine = new MICROSTRIP();
m_Icon = new wxBitmap( microstrip_xpm );
m_Messages.Add( _( "ErEff:" ) );
@ -178,7 +178,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
break;
case CPW_TYPE: // coplanar waveguide
m_TLine = new COPLANAR();
m_TLine = new COPLANAR();
m_Icon = new wxBitmap( cpw_xpm );
m_HasPrmSelection = true;
@ -211,7 +211,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
break;
case GROUNDED_CPW_TYPE: // grounded coplanar waveguide
m_TLine = new GROUNDEDCOPLANAR();
m_TLine = new GROUNDEDCOPLANAR();
m_Icon = new wxBitmap( cpw_back_xpm );
m_HasPrmSelection = true;
@ -245,7 +245,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
case RECTWAVEGUIDE_TYPE: // rectangular waveguide
m_TLine = new RECTWAVEGUIDE();
m_TLine = new RECTWAVEGUIDE();
m_Icon = new wxBitmap( rectwaveguide_xpm );
m_HasPrmSelection = true;
@ -279,7 +279,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
break;
case COAX_TYPE: // coaxial cable
m_TLine = new COAX();
m_TLine = new COAX();
m_Icon = new wxBitmap( coax_xpm );
m_HasPrmSelection = true;
@ -317,7 +317,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
break;
case C_MICROSTRIP_TYPE: // coupled microstrip
m_TLine = new C_MICROSTRIP();
m_TLine = new C_MICROSTRIP();
m_Icon = new wxBitmap( c_microstrip_xpm );
m_HasPrmSelection = true;
@ -368,7 +368,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
break;
case STRIPLINE_TYPE: // stripline
m_TLine = new STRIPLINE();
m_TLine = new STRIPLINE();
m_Icon = new wxBitmap( stripline_xpm );
m_Messages.Add( _( "ErEff:" ) );
@ -408,7 +408,7 @@ TRANSLINE_IDENT::TRANSLINE_IDENT( enum TRANSLINE_TYPE_ID aType )
break;
case TWISTEDPAIR_TYPE: // twisted pair
m_TLine = new TWISTEDPAIR();
m_TLine = new TWISTEDPAIR();
m_Icon = new wxBitmap( twistedpair_xpm );
m_HasPrmSelection = true;
@ -473,14 +473,12 @@ void TRANSLINE_IDENT::ReadConfig()
{
wxASSERT( cfg->m_TransLine.param_units.count( name ) );
for( auto& param : m_prms_List )
for( auto& p : m_prms_List )
{
try
{
param->m_Value =
cfg->m_TransLine.param_values.at( name ).at( param->m_KeyWord );
param->m_UnitSelection =
cfg->m_TransLine.param_units.at( name ).at( param->m_KeyWord );
p->m_Value = cfg->m_TransLine.param_values.at( name ).at( p->m_KeyWord );
p->m_UnitSelection = cfg->m_TransLine.param_units.at( name ).at( p->m_KeyWord );
}
catch( ... )
{}
@ -497,9 +495,7 @@ void TRANSLINE_IDENT::WriteConfig()
for( auto& param : m_prms_List )
{
if( !std::isfinite( param->m_Value ) )
{
param->m_Value = 0;
}
cfg->m_TransLine.param_values[ name ][ param->m_KeyWord ] = param->m_Value;
cfg->m_TransLine.param_units[ name ][ param->m_KeyWord ] = param->m_UnitSelection;