Stackup manager: better code.

This commit is contained in:
jean-pierre charras 2019-09-09 16:45:21 +02:00
parent 8dd8740fa3
commit c3bd9b7b8f
7 changed files with 130 additions and 38 deletions

View File

@ -59,13 +59,13 @@ wxString BuildStackupReport( BOARD_STACKUP& aStackup, EDA_UNITS_T aUnits )
if( item->HasEpsilonRValue() )
{
txt.Printf( " EpsilonR %f", item->m_EpsilonR );
txt.Printf( " EpsilonR %s", item->FormatEpsilonR() );
report << txt;
}
if( item->HasLossTangentValue() )
{
txt.Printf( " LossTg %f", item->m_LossTangent );
txt.Printf( " LossTg %s", item->FormatLossTangent() );
report << txt;
}

View File

@ -164,6 +164,25 @@ bool BOARD_STACKUP_ITEM::IsThicknessEditable()
}
wxString BOARD_STACKUP_ITEM::FormatEpsilonR()
{
// return a wxString to print/display Epsilon R
wxString txt;
txt.Printf( "%.1f", m_EpsilonR );
return txt;
}
wxString BOARD_STACKUP_ITEM::FormatLossTangent()
{
// return a wxString to print/display Loss Tangent
wxString txt;
txt.Printf( "%g", m_LossTangent );
return txt;
}
BOARD_STACKUP::BOARD_STACKUP()
{
m_HasDielectricConstrains = false; // True if some dielectric layers have constrains

View File

@ -105,6 +105,12 @@ public:
/// @return a reasonable default value for a solder mask layer thickness
static int GetMaskDefaultThickness();
/// @return a wxString to print/display Epsilon R
wxString FormatEpsilonR();
/// @return a wxString to print/display Loss Tangent
wxString FormatLossTangent();
};

View File

@ -32,7 +32,6 @@
#include <wx/rawbmp.h>
#include "panel_board_stackup.h"
#include "stackup_predefined_prms.h"
#include <panel_setup_layers.h>
#include "board_stackup_reporter.h"
#include <bitmaps.h>
@ -259,12 +258,11 @@ void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync )
if( item->IsMaterialEditable() )
{
const FAB_SUBSTRATE* material_list = GetSubstrateMaterialStandardList();
wxChoice* choice = dynamic_cast<wxChoice*>( ui_row_item.m_MaterialCtrl );
for( int ii = 0; !material_list->m_Name.IsEmpty(); ++material_list, ii++ )
for( int ii = 0; ii < m_materialList.GetCount(); ii++ )
{
if( material_list->m_Name == item->m_Material )
if( m_materialList.GetSubstrate( ii )->m_Name == item->m_Material )
{
if( choice )
choice->SetSelection( ii );
@ -394,11 +392,10 @@ void PANEL_SETUP_BOARD_STACKUP::buildLayerStackPanel()
m_core_prepreg_choice.Add( _( "PrePreg" ) );
// Build an array string of available materials (for substrate/dielectric)
const FAB_SUBSTRATE* material_list = GetSubstrateMaterialStandardList();
wxArrayString materialChoices;
for( ; !material_list->m_Name.IsEmpty(); ++material_list )
materialChoices.Add( wxGetTranslation( material_list->m_Name ) );
for( int ii = 0; ii < m_materialList.GetCount(); ii++ )
materialChoices.Add( wxGetTranslation( m_materialList.GetSubstrate( ii )->m_Name ) );
// Build a full stackup for the dialog, with a active copper layer count
// = current board layer count to calculate a reasonable default
@ -464,11 +461,10 @@ void PANEL_SETUP_BOARD_STACKUP::buildLayerStackPanel()
{
wxChoice* choice = new wxChoice( m_scGridWin, ID_ITEM_MATERIAL+row, wxDefaultPosition,
wxDefaultSize, materialChoices );
material_list = GetSubstrateMaterialStandardList();
for( int ii = 0; !material_list->m_Name.IsEmpty(); ++material_list, ii++ )
for( int ii = 0; ii < m_materialList.GetCount(); ii++ )
{
if( material_list->m_Name == item->m_Material )
if( m_materialList.GetSubstrate( ii )->m_Name == item->m_Material )
choice->SetSelection( ii );
}
@ -709,10 +705,9 @@ bool PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup()
if( item->IsMaterialEditable() )
{
const FAB_SUBSTRATE* material_list = GetSubstrateMaterialStandardList();
wxChoice* choice = static_cast<wxChoice*>( m_rowUiItemsList[row].m_MaterialCtrl );
int idx = choice->GetSelection();
item->m_Material = material_list[idx].m_Name;
item->m_Material = m_materialList.GetSubstrate( idx )->m_Name;
}
if( item->m_Type == BS_ITEM_TYPE_DIELECTRIC )
@ -972,19 +967,18 @@ void PANEL_SETUP_BOARD_STACKUP::onMaterialChange( wxCommandEvent& event )
{
int row = event.GetId() - ID_ITEM_MATERIAL;
int selection = event.GetSelection();
const FAB_SUBSTRATE* material_list = GetSubstrateMaterialStandardList();
// Update Epsilon R and Loss tg
BOARD_STACKUP_ITEM* item = GetStackupItem( row );
item->m_Material = m_materialList.GetSubstrate( selection )->m_Name;
item->m_EpsilonR = m_materialList.GetSubstrate( selection )->m_EpsilonR;
item->m_LossTangent = m_materialList.GetSubstrate( selection )->m_LossTangent;
wxTextCtrl* textCtrl = static_cast<wxTextCtrl*>( m_rowUiItemsList[row].m_EpsilonCtrl );
textCtrl->SetValue( wxString::Format( "%.1f", material_list[selection].m_EpsilonR ) );
textCtrl->SetValue( item->FormatEpsilonR() );
textCtrl = static_cast<wxTextCtrl*>( m_rowUiItemsList[row].m_LossTgCtrl );
textCtrl->SetValue( wxString::Format( "%g", material_list[selection].m_Loss ) );
BOARD_STACKUP_ITEM* item = GetStackupItem( row );
item->m_Material = material_list[selection].m_Name;
item->m_EpsilonR = material_list[selection].m_EpsilonR;
item->m_LossTangent = material_list[selection].m_Loss;
textCtrl->SetValue( item->FormatLossTangent() );
}

View File

@ -33,6 +33,7 @@
#include "panel_board_stackup_base.h"
#include "class_board_stackup.h"
#include "stackup_predefined_prms.h"
class wxBitmapComboBox;
class PANEL_SETUP_LAYERS;
@ -166,6 +167,7 @@ private:
// restricted to allowed layers in stackup.
// when do not match the enabled layers
// in PANEL_SETUP_LAYERS the stackup is not up to date
FAB_SUBSTRATE_LIST m_materialList; // a list of currently available materials
std::vector<BOARD_STACKUP_ROW_UI_ITEM> m_rowUiItemsList; // List of items in m_fgGridSizer
BOARD* m_board;
BOARD_DESIGN_SETTINGS* m_brdSettings;

View File

@ -72,7 +72,7 @@ static FAB_LAYER_COLOR solderMaskColors[] =
{ _HKI( "White" ), wxColor( 200, 200, 200 ) }, // used in .gbrjob file
{ _HKI( "Yellow" ), wxColor( 128, 128, 0 ) }, // used in .gbrjob file
{ _HKI( "Purple" ), wxColor( 100, 0, 100 ) }, // used in .gbrjob file
{ _HKI( "user defined" ), wxColor( 128, 128, 128 ) }, //free. the name is a dummy name here
{ _HKI( USER_DEFINED ), wxColor( 128, 128, 128 ) }, //free. the name is a dummy name here
{ "", wxColor( 0, 0, 0 ) } // Sentinel
};
@ -91,11 +91,57 @@ static FAB_SUBSTRATE substrateMaterial[] =
{ _HKI( "PTFE" ), 2.1, 0.0002 }, // used in .gbrjob file
{ _HKI( "Teflon" ), 2.1, 0.0002 }, // used in .gbrjob file
{ _HKI( "Ceramic" ), 1.0, 0.0 }, // used in .gbrjob file
{ _HKI( "user defined" ), 1.0, 0.0 }, // Free
{ "", 0.0, 0.0 } // Sentinel
{ _HKI( USER_DEFINED ), 1.0, 0.0 }, // Free string
};
wxString FAB_SUBSTRATE::FormatEpsilonR()
{
// return a wxString to print/display Epsilon R
wxString txt;
txt.Printf( "%.1f", m_EpsilonR );
return txt;
}
wxString FAB_SUBSTRATE::FormatLossTangent()
{
// return a wxString to print/display Loss Tangent
wxString txt;
txt.Printf( "%g", m_LossTangent );
return txt;
}
FAB_SUBSTRATE_LIST::FAB_SUBSTRATE_LIST()
{
// Fills the m_substrateList with predefined params:
for( unsigned ii = 0; ii < arrayDim( substrateMaterial ); ++ii )
m_substrateList.push_back( substrateMaterial[ii] );
}
FAB_SUBSTRATE* FAB_SUBSTRATE_LIST::GetSubstrate( int aIdx )
{
if( aIdx >= 0 && aIdx < GetCount() )
return &m_substrateList[aIdx];
return nullptr;
}
FAB_SUBSTRATE* FAB_SUBSTRATE_LIST::GetSubstrate( const wxString& aName )
{
for( FAB_SUBSTRATE& item : m_substrateList )
{
if( item.m_Name.CmpNoCase( aName ) == 0 )
return &item;
}
return nullptr;
}
wxArrayString GetCopperFinishStandardList( bool aTranslate )
{
wxArrayString list;
@ -124,8 +170,3 @@ int GetColorUserDefinedListIdx()
return GetColorStandardListCount() - 1;
}
const FAB_SUBSTRATE* GetSubstrateMaterialStandardList()
{
return substrateMaterial;
}

View File

@ -42,6 +42,9 @@
// key string used for not specified parameters
#define NOT_SPECIFIED "Undefined"
// String in wxChoice to use user defined material or solder mask color
#define USER_DEFINED "user defined"
// A minor struct to handle color in gerber job file and dialog
struct FAB_LAYER_COLOR
{
@ -59,12 +62,44 @@ struct FAB_LAYER_COLOR
// A minor struct to handle substrates prms in gerber job file and dialog
struct FAB_SUBSTRATE
{
wxString m_Name; // the name (in job file) of material
double m_EpsilonR; // the epsilon r of this material
double m_Loss; // the loss (tanD) of this material
wxString m_Name; // the name (in job file) of material
double m_EpsilonR; // the epsilon r of this material
double m_LossTangent; // the loss tangent (tanD) of this material
wxString FormatEpsilonR(); // return a wxString to print/display Epsilon R
wxString FormatLossTangent();// return a wxString to print/display Loss Tangent
};
// A struct to handle a list of substrates prms in gerber job file and dialogs
class FAB_SUBSTRATE_LIST
{
///> The list of available substrates. It contians at least predefined substrates
std::vector<FAB_SUBSTRATE> m_substrateList;
public:
FAB_SUBSTRATE_LIST();
/**
* @return the number of substrates in list
*/
int GetCount() { return (int)m_substrateList.size(); }
/**
* @return the substrate in list of index aIdx
* if incorrect return nullptr
* @param aIdx is the index in substrate list.
*/
FAB_SUBSTRATE* GetSubstrate( int aIdx );
/**
* @return the substrate in list of name aName
* if not found return nullptr
* @param aName is the name of the substrate in substrate list.
* the comparison is case insensitve
*/
FAB_SUBSTRATE* GetSubstrate( const wxString& aName );
};
/**
* @return a wxArray of standard copper finish names.
@ -87,9 +122,4 @@ int GetColorStandardListCount();
*/
int GetColorUserDefinedListIdx();
/**
* @return a list of standard material items for dielectric.
*/
const FAB_SUBSTRATE* GetSubstrateMaterialStandardList();
#endif // #ifndef STACKUP_PREDEFINED_PRMS_H