Revert "Lazy loading of stackup UI widgets."

This reverts commit 00a82905ec.
This commit is contained in:
Seth Hillbrand 2023-05-24 08:54:16 -07:00
parent ee19354484
commit 5226855158
2 changed files with 52 additions and 52 deletions

View File

@ -717,26 +717,20 @@ void PANEL_SETUP_BOARD_STACKUP::showOnlyActiveLayers()
ui_row_item.m_isEnabled = show_item; ui_row_item.m_isEnabled = show_item;
if( show_item && !ui_row_item.m_Icon ) // Show or not items of this row:
lazyBuildRowUI( ui_row_item ); ui_row_item.m_Icon->Show( show_item );
ui_row_item.m_LayerName->Show( show_item );
ui_row_item.m_LayerTypeCtrl->Show( show_item );
ui_row_item.m_MaterialCtrl->Show( show_item );
if( ui_row_item.m_Icon ) if( ui_row_item.m_MaterialButt )
{ ui_row_item.m_MaterialButt->Show( show_item );
// Show or not items of this row:
ui_row_item.m_Icon->Show( show_item );
ui_row_item.m_LayerName->Show( show_item );
ui_row_item.m_LayerTypeCtrl->Show( show_item );
ui_row_item.m_MaterialCtrl->Show( show_item );
if( ui_row_item.m_MaterialButt ) ui_row_item.m_ThicknessCtrl->Show( show_item );
ui_row_item.m_MaterialButt->Show( show_item ); ui_row_item.m_ThicknessLockCtrl->Show( show_item );
ui_row_item.m_ColorCtrl->Show( show_item );
ui_row_item.m_ThicknessCtrl->Show( show_item ); ui_row_item.m_EpsilonCtrl->Show( show_item );
ui_row_item.m_ThicknessLockCtrl->Show( show_item ); ui_row_item.m_LossTgCtrl->Show( show_item );
ui_row_item.m_ColorCtrl->Show( show_item );
ui_row_item.m_EpsilonCtrl->Show( show_item );
ui_row_item.m_LossTgCtrl->Show( show_item );
}
} }
} }
@ -781,11 +775,16 @@ wxControl* PANEL_SETUP_BOARD_STACKUP::addSpacer()
} }
void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_row_item ) BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow,
BOARD_STACKUP_ITEM* aStackupItem,
int aSublayerIdx )
{ {
BOARD_STACKUP_ITEM* item = ui_row_item.m_Item; wxASSERT( aStackupItem );
int sublayerIdx = ui_row_item.m_SubItem; wxASSERT( aSublayerIdx >= 0 && aSublayerIdx < aStackupItem->GetSublayersCount() );
int row = ui_row_item.m_Row;
BOARD_STACKUP_ROW_UI_ITEM ui_row_item( aStackupItem, aSublayerIdx );
BOARD_STACKUP_ITEM* item = aStackupItem;
int row = aRow;
// Add color swatch icon. The color will be updated later, // Add color swatch icon. The color will be updated later,
// when all widgets are initialized // when all widgets are initialized
@ -793,13 +792,15 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
m_fgGridSizer->Add( bitmap, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 4 ); m_fgGridSizer->Add( bitmap, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 4 );
ui_row_item.m_Icon = bitmap; ui_row_item.m_Icon = bitmap;
ui_row_item.m_isEnabled = true;
if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC ) if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
{ {
wxString lname = item->FormatDielectricLayerName(); wxString lname = item->FormatDielectricLayerName();
if( item->GetSublayersCount() > 1 ) if( item->GetSublayersCount() > 1 )
{ {
lname << wxT( " (" ) << sublayerIdx +1 << wxT( "/" ) lname << wxT( " (" ) << aSublayerIdx+1 << wxT( "/" )
<< item->GetSublayersCount() << wxT( ")" ); << item->GetSublayersCount() << wxT( ")" );
} }
@ -808,8 +809,8 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
ui_row_item.m_LayerName = st_text; ui_row_item.m_LayerName = st_text;
// For a dielectric layer, the layer type choice is not for each sublayer, // For a dielectric layer, the layer type choice is not for each sublayer,
// only for the first (sublayerIdx = 0), and is common to all sublayers // only for the first (aSublayerIdx = 0), and is common to all sublayers
if( sublayerIdx == 0 ) if( aSublayerIdx == 0 )
{ {
wxChoice* choice = new wxChoice( m_scGridWin, wxID_ANY, wxDefaultPosition, wxChoice* choice = new wxChoice( m_scGridWin, wxID_ANY, wxDefaultPosition,
wxDefaultSize, m_core_prepreg_choice ); wxDefaultSize, m_core_prepreg_choice );
@ -845,7 +846,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
if( item->IsMaterialEditable() ) if( item->IsMaterialEditable() )
{ {
wxString matName = item->GetMaterial( sublayerIdx ); wxString matName = item->GetMaterial( aSublayerIdx );
addMaterialChooser( ID_ITEM_MATERIAL+row, &matName, ui_row_item ); addMaterialChooser( ID_ITEM_MATERIAL+row, &matName, ui_row_item );
} }
else else
@ -857,7 +858,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
{ {
wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, ID_ITEM_THICKNESS+row ); wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, ID_ITEM_THICKNESS+row );
textCtrl->SetMinSize( m_numericTextCtrlSize ); textCtrl->SetMinSize( m_numericTextCtrlSize );
textCtrl->ChangeValue( m_frame->StringFromValue( item->GetThickness( sublayerIdx ), true ) ); textCtrl->ChangeValue( m_frame->StringFromValue( item->GetThickness( aSublayerIdx ), true ) );
m_fgGridSizer->Add( textCtrl, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 2 ); m_fgGridSizer->Add( textCtrl, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 2 );
m_controlItemsList.push_back( textCtrl ); m_controlItemsList.push_back( textCtrl );
textCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, textCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED,
@ -869,7 +870,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
{ {
wxCheckBox* cb_box = new wxCheckBox( m_scGridWin, ID_ITEM_THICKNESS_LOCKED+row, wxCheckBox* cb_box = new wxCheckBox( m_scGridWin, ID_ITEM_THICKNESS_LOCKED+row,
wxEmptyString ); wxEmptyString );
cb_box->SetValue( item->IsThicknessLocked( sublayerIdx ) ); cb_box->SetValue( item->IsThicknessLocked( aSublayerIdx ) );
m_fgGridSizer->Add( cb_box, 0, wxALIGN_CENTER_VERTICAL, 2 ); m_fgGridSizer->Add( cb_box, 0, wxALIGN_CENTER_VERTICAL, 2 );
ui_row_item.m_ThicknessLockCtrl = cb_box; ui_row_item.m_ThicknessLockCtrl = cb_box;
} }
@ -886,9 +887,9 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
if( item->IsColorEditable() ) if( item->IsColorEditable() )
{ {
if( item->GetColor( sublayerIdx ).StartsWith( wxT( "#" ) ) ) // User defined color if( item->GetColor( aSublayerIdx ).StartsWith( wxT( "#" ) ) ) // User defined color
{ {
ui_row_item.m_UserColor = COLOR4D( item->GetColor( sublayerIdx ) ).ToColour(); ui_row_item.m_UserColor = COLOR4D( item->GetColor( aSublayerIdx ) ).ToColour();
} }
else else
ui_row_item.m_UserColor = GetDefaultUserColor( item->GetType() ); ui_row_item.m_UserColor = GetDefaultUserColor( item->GetType() );
@ -898,17 +899,17 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
m_fgGridSizer->Add( bm_combo, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL|wxEXPAND, 2 ); m_fgGridSizer->Add( bm_combo, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL|wxEXPAND, 2 );
if( item->GetColor( sublayerIdx ).StartsWith( wxT( "#" ) ) ) if( item->GetColor( aSublayerIdx ).StartsWith( wxT( "#" ) ) )
{ {
selected = GetColorUserDefinedListIdx( item->GetType() ); selected = GetColorUserDefinedListIdx( item->GetType() );
bm_combo->SetString( selected, item->GetColor( sublayerIdx ) ); bm_combo->SetString( selected, item->GetColor( aSublayerIdx ) );
} }
else else
{ {
// Note: don't use bm_combo->FindString() because the combo strings are translated. // Note: don't use bm_combo->FindString() because the combo strings are translated.
for( size_t ii = 0; ii < GetStandardColors( item->GetType() ).size(); ii++ ) for( size_t ii = 0; ii < GetStandardColors( item->GetType() ).size(); ii++ )
{ {
if( GetStandardColorName( item->GetType(), ii ) == item->GetColor( sublayerIdx ) ) if( GetStandardColorName( item->GetType(), ii ) == item->GetColor( aSublayerIdx ) )
{ {
selected = ii; selected = ii;
break; break;
@ -926,7 +927,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
if( item->HasEpsilonRValue() ) if( item->HasEpsilonRValue() )
{ {
wxString txt = UIDouble2Str( item->GetEpsilonR( sublayerIdx ) ); wxString txt = UIDouble2Str( item->GetEpsilonR( aSublayerIdx ) );
wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString, wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString,
wxDefaultPosition, m_numericFieldsSize ); wxDefaultPosition, m_numericFieldsSize );
textCtrl->ChangeValue( txt ); textCtrl->ChangeValue( txt );
@ -940,7 +941,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
if( item->HasLossTangentValue() ) if( item->HasLossTangentValue() )
{ {
wxString txt = UIDouble2Str( item->GetLossTangent( sublayerIdx ) );; wxString txt = UIDouble2Str( item->GetLossTangent( aSublayerIdx ) );;
wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString, wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString,
wxDefaultPosition, m_numericFieldsSize ); wxDefaultPosition, m_numericFieldsSize );
textCtrl->ChangeValue( txt ); textCtrl->ChangeValue( txt );
@ -951,6 +952,8 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro
{ {
ui_row_item.m_LossTgCtrl = addSpacer(); ui_row_item.m_LossTgCtrl = addSpacer();
} }
return ui_row_item;
} }
@ -970,8 +973,7 @@ void PANEL_SETUP_BOARD_STACKUP::rebuildLayerStackPanel( bool aRelinkItems )
for( BOARD_STACKUP_ROW_UI_ITEM& ui_item: m_rowUiItemsList ) for( BOARD_STACKUP_ROW_UI_ITEM& ui_item: m_rowUiItemsList )
{ {
// This remove and delete the current ui_item.m_MaterialCtrl sizer // This remove and delete the current ui_item.m_MaterialCtrl sizer
if( ui_item.m_MaterialCtrl ) ui_item.m_MaterialCtrl->SetSizer( nullptr );
ui_item.m_MaterialCtrl->SetSizer( nullptr );
// Delete other widgets // Delete other widgets
delete ui_item.m_Icon; // Color icon in first column (column 1) delete ui_item.m_Icon; // Color icon in first column (column 1)
@ -1018,8 +1020,6 @@ void PANEL_SETUP_BOARD_STACKUP::rebuildLayerStackPanel( bool aRelinkItems )
// Now enable/disable stackup items, according to the m_enabledLayers config // Now enable/disable stackup items, according to the m_enabledLayers config
showOnlyActiveLayers(); showOnlyActiveLayers();
updateIconColor();
m_scGridWin->Layout(); m_scGridWin->Layout();
m_scGridWin->Show(); m_scGridWin->Show();
} }
@ -1079,10 +1079,14 @@ void PANEL_SETUP_BOARD_STACKUP::buildLayerStackPanel( bool aCreateInitialStackup
{ {
for( int sub_idx = 0; sub_idx < item->GetSublayersCount(); sub_idx++ ) for( int sub_idx = 0; sub_idx < item->GetSublayersCount(); sub_idx++ )
{ {
m_rowUiItemsList.emplace_back( item, sub_idx, row ); BOARD_STACKUP_ROW_UI_ITEM ui_row_item = createRowData( row, item, sub_idx );
m_rowUiItemsList.emplace_back( ui_row_item );
row++; row++;
} }
} }
updateIconColor();
} }
@ -1574,12 +1578,9 @@ void PANEL_SETUP_BOARD_STACKUP::updateIconColor( int aRow )
for( unsigned row = 0; row < m_rowUiItemsList.size(); row++ ) for( unsigned row = 0; row < m_rowUiItemsList.size(); row++ )
{ {
if( m_rowUiItemsList[row].m_Icon ) wxBitmap bmp( m_colorIconsSize.x, m_colorIconsSize.y / 2, bitmap_depth );
{ drawBitmap( bmp, getColorIconItem( row ) );
wxBitmap bmp( m_colorIconsSize.x, m_colorIconsSize.y / 2, bitmap_depth ); m_rowUiItemsList[row].m_Icon->SetBitmap( bmp );
drawBitmap( bmp, getColorIconItem( row ) );
m_rowUiItemsList[row].m_Icon->SetBitmap( bmp );
}
} }
} }

View File

@ -51,7 +51,6 @@ struct BOARD_STACKUP_ROW_UI_ITEM
int m_SubItem; // For multilayer dielectric, the index in sublayer list. int m_SubItem; // For multilayer dielectric, the index in sublayer list.
// Must be >= 0 and < m_Item sublayer count. Used only for dielectic // Must be >= 0 and < m_Item sublayer count. Used only for dielectic
// 0 is the base list of parameters (always existing) // 0 is the base list of parameters (always existing)
int m_Row; // The row number in the parent grid
bool m_isEnabled; // True if the row is in board bool m_isEnabled; // True if the row is in board
// false if not (this row is not shown on the panel) // false if not (this row is not shown on the panel)
wxStaticBitmap* m_Icon; // Color icon in first column (column 1) wxStaticBitmap* m_Icon; // Color icon in first column (column 1)
@ -67,11 +66,10 @@ struct BOARD_STACKUP_ROW_UI_ITEM
COLOR4D m_UserColor; // User-specified color (if any) COLOR4D m_UserColor; // User-specified color (if any)
BOARD_STACKUP_ROW_UI_ITEM( BOARD_STACKUP_ITEM* aItem, int aSubItem, int aRow ) : BOARD_STACKUP_ROW_UI_ITEM( BOARD_STACKUP_ITEM* aItem, int aSubItem = 1 ) :
m_Item( aItem ), m_Item( aItem ),
m_SubItem( aSubItem ), m_SubItem( aSubItem ),
m_Row( aRow ), m_isEnabled( true ),
m_isEnabled( false ),
m_Icon( nullptr ), m_Icon( nullptr ),
m_LayerName( nullptr ), m_LayerName( nullptr ),
m_LayerTypeCtrl( nullptr ), m_LayerTypeCtrl( nullptr ),
@ -118,7 +116,7 @@ public:
bool TransferDataFromWindow() override; bool TransferDataFromWindow() override;
private: private:
/** Creates the controls in a BOARD_STACKUP_ROW_UI_ITEM relative to the aStackupItem. /** Creates a BOARD_STACKUP_ROW_UI_ITEM relative to the aStackupItem.
* @return a BOARD_STACKUP_ROW_UI_ITEM filled with corresponding widgets * @return a BOARD_STACKUP_ROW_UI_ITEM filled with corresponding widgets
* @param aRow is the row index in the row list * @param aRow is the row index in the row list
* @param aStackupItem is the stackup item controlled by the created * @param aStackupItem is the stackup item controlled by the created
@ -127,7 +125,8 @@ private:
* this is the index of the sublayer to used inside aStackupItem * this is the index of the sublayer to used inside aStackupItem
* (from 0 to sub layer count - 1) * (from 0 to sub layer count - 1)
*/ */
void lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_row_item ); BOARD_STACKUP_ROW_UI_ITEM createRowData( int aRow, BOARD_STACKUP_ITEM* aStackupItem,
int aSublayerIdx );
/** add a Spacer in m_fgGridSizer when a empty cell is needed /** add a Spacer in m_fgGridSizer when a empty cell is needed
*/ */