diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp index e484db1547..666060fc7c 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp +++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp @@ -717,26 +717,20 @@ void PANEL_SETUP_BOARD_STACKUP::showOnlyActiveLayers() ui_row_item.m_isEnabled = show_item; - if( show_item && !ui_row_item.m_Icon ) - lazyBuildRowUI( ui_row_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_Icon ) - { - // 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_MaterialButt->Show( show_item ); - if( ui_row_item.m_MaterialButt ) - ui_row_item.m_MaterialButt->Show( show_item ); - - ui_row_item.m_ThicknessCtrl->Show( show_item ); - ui_row_item.m_ThicknessLockCtrl->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 ); - } + ui_row_item.m_ThicknessCtrl->Show( show_item ); + ui_row_item.m_ThicknessLockCtrl->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; - int sublayerIdx = ui_row_item.m_SubItem; - int row = ui_row_item.m_Row; + wxASSERT( aStackupItem ); + wxASSERT( aSublayerIdx >= 0 && aSublayerIdx < aStackupItem->GetSublayersCount() ); + + 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, // 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 ); ui_row_item.m_Icon = bitmap; + ui_row_item.m_isEnabled = true; + if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC ) { wxString lname = item->FormatDielectricLayerName(); if( item->GetSublayersCount() > 1 ) { - lname << wxT( " (" ) << sublayerIdx +1 << wxT( "/" ) + lname << wxT( " (" ) << aSublayerIdx+1 << 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; // 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 - if( sublayerIdx == 0 ) + // only for the first (aSublayerIdx = 0), and is common to all sublayers + if( aSublayerIdx == 0 ) { wxChoice* choice = new wxChoice( m_scGridWin, wxID_ANY, wxDefaultPosition, 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() ) { - wxString matName = item->GetMaterial( sublayerIdx ); + wxString matName = item->GetMaterial( aSublayerIdx ); addMaterialChooser( ID_ITEM_MATERIAL+row, &matName, ui_row_item ); } 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 ); 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_controlItemsList.push_back( textCtrl ); 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, wxEmptyString ); - cb_box->SetValue( item->IsThicknessLocked( sublayerIdx ) ); + cb_box->SetValue( item->IsThicknessLocked( aSublayerIdx ) ); m_fgGridSizer->Add( cb_box, 0, wxALIGN_CENTER_VERTICAL, 2 ); 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->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 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 ); - if( item->GetColor( sublayerIdx ).StartsWith( wxT( "#" ) ) ) + if( item->GetColor( aSublayerIdx ).StartsWith( wxT( "#" ) ) ) { selected = GetColorUserDefinedListIdx( item->GetType() ); - bm_combo->SetString( selected, item->GetColor( sublayerIdx ) ); + bm_combo->SetString( selected, item->GetColor( aSublayerIdx ) ); } else { // Note: don't use bm_combo->FindString() because the combo strings are translated. 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; break; @@ -926,7 +927,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro if( item->HasEpsilonRValue() ) { - wxString txt = UIDouble2Str( item->GetEpsilonR( sublayerIdx ) ); + wxString txt = UIDouble2Str( item->GetEpsilonR( aSublayerIdx ) ); wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString, wxDefaultPosition, m_numericFieldsSize ); textCtrl->ChangeValue( txt ); @@ -940,7 +941,7 @@ void PANEL_SETUP_BOARD_STACKUP::lazyBuildRowUI( BOARD_STACKUP_ROW_UI_ITEM& ui_ro if( item->HasLossTangentValue() ) { - wxString txt = UIDouble2Str( item->GetLossTangent( sublayerIdx ) );; + wxString txt = UIDouble2Str( item->GetLossTangent( aSublayerIdx ) );; wxTextCtrl* textCtrl = new wxTextCtrl( m_scGridWin, wxID_ANY, wxEmptyString, wxDefaultPosition, m_numericFieldsSize ); 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(); } + + 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 ) { // 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 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 showOnlyActiveLayers(); - updateIconColor(); - m_scGridWin->Layout(); 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++ ) { - 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++; } } + + updateIconColor(); } @@ -1574,12 +1578,9 @@ void PANEL_SETUP_BOARD_STACKUP::updateIconColor( int aRow ) 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 ) ); - m_rowUiItemsList[row].m_Icon->SetBitmap( bmp ); - } + wxBitmap bmp( m_colorIconsSize.x, m_colorIconsSize.y / 2, bitmap_depth ); + drawBitmap( bmp, getColorIconItem( row ) ); + m_rowUiItemsList[row].m_Icon->SetBitmap( bmp ); } } diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.h b/pcbnew/board_stackup_manager/panel_board_stackup.h index 03ace65e61..7851969a74 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.h +++ b/pcbnew/board_stackup_manager/panel_board_stackup.h @@ -51,7 +51,6 @@ struct BOARD_STACKUP_ROW_UI_ITEM int m_SubItem; // For multilayer dielectric, the index in sublayer list. // Must be >= 0 and < m_Item sublayer count. Used only for dielectic // 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 // false if not (this row is not shown on the panel) 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) - 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_SubItem( aSubItem ), - m_Row( aRow ), - m_isEnabled( false ), + m_isEnabled( true ), m_Icon( nullptr ), m_LayerName( nullptr ), m_LayerTypeCtrl( nullptr ), @@ -118,7 +116,7 @@ public: bool TransferDataFromWindow() override; 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 * @param aRow is the row index in the row list * @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 * (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 */