From 815c2c69e7fc5d3b99fc4c66ce4a994cc794bab9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 16 Aug 2021 19:57:15 +0100 Subject: [PATCH] Support for dielectric colors in board stackup. Fixes https://gitlab.com/kicad/code/kicad/issues/8491 --- 3d-viewer/3d_canvas/board_adapter.cpp | 27 +--- .../board_stackup_manager/board_stackup.cpp | 65 ++++---- .../panel_board_finish.cpp | 6 +- .../panel_board_stackup.cpp | 147 ++++++++++-------- .../panel_board_stackup.h | 8 +- .../stackup_predefined_prms.cpp | 68 +++++--- .../stackup_predefined_prms.h | 33 ++-- 7 files changed, 184 insertions(+), 170 deletions(-) diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index b4ab41e54e..48b91353f1 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -605,32 +605,7 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR case BS_ITEM_TYPE_DIELECTRIC: { - KIGFX::COLOR4D layerColor = COLOR4D::UNSPECIFIED; - const wxString& materialName = stackupItem->GetMaterial(); - - if( materialName.StartsWith( "FR4" ) ) - { - layerColor = findColor( "FR4 natural", g_BoardColors ); - } - else if( materialName.IsSameAs( "PTFE" ) - || materialName.IsSameAs( "Teflon" ) ) - { - layerColor = findColor( "PTFE natural", g_BoardColors ); - } - else if( materialName.IsSameAs( "Polyimide" ) - || materialName.IsSameAs( "Kapton" ) ) - { - layerColor = findColor( "Polyimide", g_BoardColors ); - } - else if( materialName.IsSameAs( "Al" ) ) - { - layerColor = findColor( "Aluminum", g_BoardColors ); - } - else // A default color value for unknown dielectric material - // (i.e. an exotic name entered by hand) - { - layerColor = findColor( "FR4 natural", g_BoardColors ); - } + KIGFX::COLOR4D layerColor = findColor( colorName, g_BoardColors ); if( bodyColor == COLOR4D( 0, 0, 0, 0 ) ) bodyColor = layerColor; diff --git a/pcbnew/board_stackup_manager/board_stackup.cpp b/pcbnew/board_stackup_manager/board_stackup.cpp index 5b3394e2d6..c177c9700b 100644 --- a/pcbnew/board_stackup_manager/board_stackup.cpp +++ b/pcbnew/board_stackup_manager/board_stackup.cpp @@ -28,7 +28,6 @@ #include #include // For _HKI definition #include "stackup_predefined_prms.h" -#include // for Double2Str() BOARD_STACKUP_ITEM::BOARD_STACKUP_ITEM( BOARD_STACKUP_ITEM_TYPE aType ) @@ -98,8 +97,7 @@ void BOARD_STACKUP_ITEM::AddDielectricPrms( int aDielectricPrmsIdx ) // add a DIELECTRIC_PRMS item to m_DielectricPrmsList DIELECTRIC_PRMS new_prms; - m_DielectricPrmsList.emplace( m_DielectricPrmsList.begin() + aDielectricPrmsIdx, - new_prms ); + m_DielectricPrmsList.emplace( m_DielectricPrmsList.begin() + aDielectricPrmsIdx, new_prms ); } @@ -107,9 +105,12 @@ void BOARD_STACKUP_ITEM::RemoveDielectricPrms( int aDielectricPrmsIdx ) { // Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList if possible - if( GetSublayersCount() < 2 || aDielectricPrmsIdx < 0 + if( GetSublayersCount() < 2 + || aDielectricPrmsIdx < 0 || aDielectricPrmsIdx >= GetSublayersCount() ) + { return; + } m_DielectricPrmsList.erase( m_DielectricPrmsList.begin() + aDielectricPrmsIdx ); } @@ -220,16 +221,14 @@ void BOARD_STACKUP_ITEM::SetMaterial( const wxString& aName, int aDielectricSubL bool BOARD_STACKUP_ITEM::HasEpsilonRValue() const { return m_Type == BS_ITEM_TYPE_DIELECTRIC - || m_Type == BS_ITEM_TYPE_SOLDERMASK - //|| m_Type == BS_ITEM_TYPE_SILKSCREEN - ; + || m_Type == BS_ITEM_TYPE_SOLDERMASK; }; bool BOARD_STACKUP_ITEM::HasLossTangentValue() const { return m_Type == BS_ITEM_TYPE_DIELECTRIC - || m_Type == BS_ITEM_TYPE_SOLDERMASK; + || m_Type == BS_ITEM_TYPE_SOLDERMASK; }; @@ -242,43 +241,25 @@ bool BOARD_STACKUP_ITEM::HasMaterialValue( int aDielectricSubLayer ) const bool BOARD_STACKUP_ITEM::IsMaterialEditable() const { - // The material is editable only for dielectric - return m_Type == BS_ITEM_TYPE_DIELECTRIC || - m_Type == BS_ITEM_TYPE_SOLDERMASK || - m_Type == BS_ITEM_TYPE_SILKSCREEN; + return m_Type == BS_ITEM_TYPE_DIELECTRIC + || m_Type == BS_ITEM_TYPE_SOLDERMASK + || m_Type == BS_ITEM_TYPE_SILKSCREEN; } bool BOARD_STACKUP_ITEM::IsColorEditable() const { - return m_Type == BS_ITEM_TYPE_SOLDERMASK || m_Type == BS_ITEM_TYPE_SILKSCREEN; + return m_Type == BS_ITEM_TYPE_DIELECTRIC + || m_Type == BS_ITEM_TYPE_SOLDERMASK + || m_Type == BS_ITEM_TYPE_SILKSCREEN; } bool BOARD_STACKUP_ITEM::IsThicknessEditable() const { - switch( m_Type ) - { - case BS_ITEM_TYPE_COPPER: - return true; - - case BS_ITEM_TYPE_DIELECTRIC: - return true; - - case BS_ITEM_TYPE_SOLDERMASK: - return true; - - case BS_ITEM_TYPE_SOLDERPASTE: - return false; - - case BS_ITEM_TYPE_SILKSCREEN: - return false; - - default: - break; - } - - return false; + return m_Type == BS_ITEM_TYPE_COPPER + || m_Type == BS_ITEM_TYPE_DIELECTRIC + || m_Type == BS_ITEM_TYPE_SOLDERMASK; } @@ -333,7 +314,7 @@ BOARD_STACKUP::BOARD_STACKUP( const BOARD_STACKUP& aOther ) // All items in aOther.m_list have to be duplicated, because aOther.m_list // manage pointers to these items - for( auto item : aOther.m_list ) + for( BOARD_STACKUP_ITEM* item : aOther.m_list ) { BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item ); Add( dup_item ); @@ -354,7 +335,7 @@ BOARD_STACKUP& BOARD_STACKUP::operator=( const BOARD_STACKUP& aOther ) // All items in aOther.m_list have to be duplicated, because aOther.m_list // manage pointers to these items - for( auto item : aOther.m_list ) + for( BOARD_STACKUP_ITEM* item : aOther.m_list ) { BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item ); Add( dup_item ); @@ -366,7 +347,7 @@ BOARD_STACKUP& BOARD_STACKUP::operator=( const BOARD_STACKUP& aOther ) void BOARD_STACKUP::RemoveAll() { - for( auto item : m_list ) + for( BOARD_STACKUP_ITEM* item : m_list ) delete item; m_list.clear(); @@ -387,7 +368,7 @@ int BOARD_STACKUP::BuildBoardThicknessFromStackup() const // return the board thickness from the thickness of BOARD_STACKUP_ITEM list int thickness = 0; - for( auto item : m_list ) + for( BOARD_STACKUP_ITEM* item : m_list ) { if( item->IsThicknessEditable() && item->IsEnabled() ) thickness += item->GetThickness(); @@ -645,8 +626,10 @@ void BOARD_STACKUP::FormatBoardStackup( OUTPUTFORMATTER* aFormatter, aFormatter->Quotew( item->GetTypeName() ).c_str() ); if( item->IsColorEditable() && IsPrmSpecified( item->GetColor() ) ) + { aFormatter->Print( 0, " (color %s)", aFormatter->Quotew( item->GetColor() ).c_str() ); + } for( int idx = 0; idx < item->GetSublayersCount(); idx++ ) { @@ -683,15 +666,19 @@ void BOARD_STACKUP::FormatBoardStackup( OUTPUTFORMATTER* aFormatter, // Other infos about board, related to layers and other fabrication specifications if( IsPrmSpecified( m_FinishType ) ) + { aFormatter->Print( nest_level, "(copper_finish %s)\n", aFormatter->Quotew( m_FinishType ).c_str() ); + } aFormatter->Print( nest_level, "(dielectric_constraints %s)\n", m_HasDielectricConstrains ? "yes" : "no" ); if( m_EdgeConnectorConstraints > 0 ) + { aFormatter->Print( nest_level, "(edge_connector %s)\n", m_EdgeConnectorConstraints > 1 ? "bevelled": "yes" ); + } if( m_CastellatedPads ) aFormatter->Print( nest_level, "(castellated_pads yes)\n" ); diff --git a/pcbnew/board_stackup_manager/panel_board_finish.cpp b/pcbnew/board_stackup_manager/panel_board_finish.cpp index 2a2015766d..777d024e47 100644 --- a/pcbnew/board_stackup_manager/panel_board_finish.cpp +++ b/pcbnew/board_stackup_manager/panel_board_finish.cpp @@ -39,7 +39,7 @@ PANEL_SETUP_BOARD_FINISH::PANEL_SETUP_BOARD_FINISH( PAGED_DIALOG* aParent, BOARD m_brdSettings = &m_board->GetDesignSettings(); // Get the translated list of choices and init m_choiceFinish - wxArrayString finish_list = GetCopperFinishStandardList( true ); + wxArrayString finish_list = GetStandardCopperFinishes( true ); m_choiceFinish->Append( finish_list ); m_choiceFinish->SetSelection( 0 ); // Will be correctly set later @@ -61,7 +61,7 @@ void PANEL_SETUP_BOARD_FINISH::synchronizeWithBoard() m_cbEgdesPlated->SetValue( brd_stackup.m_EdgePlating ); // find the choice depending on the initial finish setting - wxArrayString initial_finish_list = GetCopperFinishStandardList( false ); + wxArrayString initial_finish_list = GetStandardCopperFinishes( false ); unsigned idx; for( idx = 0; idx < initial_finish_list.GetCount(); idx++ ) @@ -82,7 +82,7 @@ bool PANEL_SETUP_BOARD_FINISH::TransferDataFromWindow() { BOARD_STACKUP& brd_stackup = m_brdSettings->GetStackupDescriptor(); - wxArrayString finish_list = GetCopperFinishStandardList( false ); + wxArrayString finish_list = GetStandardCopperFinishes( false ); int finish = m_choiceFinish->GetSelection() >= 0 ? m_choiceFinish->GetSelection() : 0; brd_stackup.m_FinishType = finish_list[finish]; diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp index a438588af6..80ab9ded0b 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp +++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp @@ -73,17 +73,6 @@ static wxColor pasteColor( 200, 200, 200 ); static void drawBitmap( wxBitmap& aBitmap, wxColor aColor ); -wxString getColourAsHexString( const wxColour aColour ) -{ - // NB: wxWidgets 3.0's color.GetAsString( wxC2S_HTML_SYNTAX ) pukes on alpha - return wxString::Format( wxT("#%02X%02X%02X%02X" ), - aColour.Red(), - aColour.Green(), - aColour.Blue(), - aColour.Alpha() ); -} - - PANEL_SETUP_BOARD_STACKUP::PANEL_SETUP_BOARD_STACKUP( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame, PANEL_SETUP_LAYERS* aPanelLayers ): PANEL_SETUP_BOARD_STACKUP_BASE( aParent->GetTreebook() ), @@ -432,10 +421,10 @@ wxColor PANEL_SETUP_BOARD_STACKUP::GetSelectedColor( int aRow ) const int idx = choice ? choice->GetSelection() : 0; - if( idx != GetColorUserDefinedListIdx() ) // a standard color is selected - return GetColorStandardList()[idx].GetColor( item->GetType() ); + if( IsCustomColorIdx( item->GetType(), idx ) ) + return m_rowUiItemsList[aRow].m_UserColor.ToColour(); else - return m_rowUiItemsList[aRow].m_UserColor; + return GetStandardColor( item->GetType(), idx ).ToColour(); } @@ -488,7 +477,6 @@ void PANEL_SETUP_BOARD_STACKUP::updateCopperLayerCount() void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync ) { const BOARD_STACKUP& brd_stackup = m_brdSettings->GetStackupDescriptor(); - const FAB_LAYER_COLOR* color_list = GetColorStandardList(); if( aFullSync ) { @@ -542,19 +530,22 @@ void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync ) if( item->IsColorEditable() ) { auto bm_combo = dynamic_cast( ui_row_item.m_ColorCtrl ); + int selected = 0; // The "not specified" item if( item->GetColor().StartsWith( "#" ) ) // User defined color { - ui_row_item.m_UserColor = COLOR4D( item->GetColor() ).ToColour(); + COLOR4D custom_color( item->GetColor() ); + + ui_row_item.m_UserColor = custom_color; + + selected = GetColorUserDefinedListIdx( item->GetType() ); if( bm_combo ) // Update user color shown in the wxBitmapComboBox { - bm_combo->SetString( GetColorUserDefinedListIdx(), item->GetColor() ); + bm_combo->SetString( selected, item->GetColor() ); wxBitmap layerbmp( m_colorSwatchesSize.x, m_colorSwatchesSize.y ); - LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D(), - wxColour( item->GetColor() ) ); - bm_combo->SetItemBitmap( GetColorUserDefinedListIdx(), layerbmp ); - bm_combo->SetSelection( GetColorUserDefinedListIdx() ); + LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D(), custom_color ); + bm_combo->SetItemBitmap( selected, layerbmp ); } } else @@ -563,17 +554,19 @@ void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync ) { // Note: don't use bm_combo->FindString() because the combo strings are // translated. - for( int ii = 0; ii < GetColorStandardListCount(); ii++ ) + for( int ii = 0; ii < GetStandardColorCount( item->GetType()); ii++ ) { - if( color_list[ii].GetName() == item->GetColor() ) + if( GetStandardColorName( item->GetType(), ii ) == item->GetColor() ) { - bm_combo->SetSelection( ii ); + selected = ii; break; } } } } + if( bm_combo ) + bm_combo->SetSelection( selected ); } if( item->HasEpsilonRValue() ) @@ -696,8 +689,6 @@ BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow, BOARD_STACKUP_ITEM* item = aStackupItem; int row = aRow; - const FAB_LAYER_COLOR* color_list = GetColorStandardList(); - // Add color swatch icon. The color will be updated later, // when all widgets are initialized wxStaticBitmap* bitmap = new wxStaticBitmap( m_scGridWin, wxID_ANY, wxNullBitmap ); @@ -806,26 +797,29 @@ BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow, ui_row_item.m_UserColor = GetDefaultUserColor( item->GetType() ); wxBitmapComboBox* bm_combo = createColorBox( item, row ); + int selected = 0; // The "not specified" item + m_fgGridSizer->Add( bm_combo, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL|wxEXPAND, 2 ); if( item->GetColor().StartsWith( "#" ) ) { - bm_combo->SetString( GetColorUserDefinedListIdx(), item->GetColor() ); - bm_combo->SetSelection( GetColorUserDefinedListIdx() ); + selected = GetColorUserDefinedListIdx( item->GetType() ); + bm_combo->SetString( selected, item->GetColor() ); } else { // Note: don't use bm_combo->FindString() because the combo strings are translated. - for( int ii = 0; ii < GetColorStandardListCount(); ii++ ) + for( int ii = 0; ii < GetStandardColorCount( item->GetType()); ii++ ) { - if( color_list[ii].GetName() == item->GetColor() ) + if( GetStandardColorName( item->GetType(), ii ) == item->GetColor() ) { - bm_combo->SetSelection( ii ); + selected = ii; break; } } } + bm_combo->SetSelection( selected ); ui_row_item.m_ColorCtrl = bm_combo; } else @@ -1107,31 +1101,23 @@ bool PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup() if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC ) { // Dielectric thickness layer can have a locked thickness: - wxCheckBox* cb_box = static_cast - ( ui_item.m_ThicknessLockCtrl ); + wxCheckBox* cb_box = static_cast( ui_item.m_ThicknessLockCtrl ); item->SetThicknessLocked( cb_box && cb_box->GetValue(), sub_item ); } } if( sub_item == 0 && item->IsColorEditable() ) { - const FAB_LAYER_COLOR* color_list = GetColorStandardList(); - wxBitmapComboBox* choice = dynamic_cast( ui_item.m_ColorCtrl ); if( choice ) { int idx = choice->GetSelection(); - if( idx == GetColorUserDefinedListIdx() ) - { - // NB: wxWidgets 3.0's color.GetAsString( wxC2S_HTML_SYNTAX ) pukes on alpha - item->SetColor( getColourAsHexString( ui_item.m_UserColor ) ); - } + if( IsCustomColorIdx( item->GetType(), idx ) ) + item->SetColor( ui_item.m_UserColor.ToHexString() ); else - { - item->SetColor( color_list[idx].GetName() ); - } + item->SetColor( GetStandardColorName( item->GetType(), idx ) ); } } @@ -1249,12 +1235,12 @@ void PANEL_SETUP_BOARD_STACKUP::OnLayersOptionsChanged( LSET aNewLayerSet ) void PANEL_SETUP_BOARD_STACKUP::onColorSelected( wxCommandEvent& event ) { - int idx = event.GetSelection(); - int item_id = event.GetId(); + int idx = event.GetSelection(); + int item_id = event.GetId(); + int row = item_id - ID_ITEM_COLOR; + BOARD_STACKUP_ITEM* item = m_rowUiItemsList[row].m_Item; - int row = item_id - ID_ITEM_COLOR; - - if( idx == GetColorStandardListCount() - 1 ) // Set user color is the last option in list + if( idx == GetStandardColorCount( item->GetType()) - 1 ) // Set user color is the last option in list { DIALOG_COLOR_PICKER dlg( this, m_rowUiItemsList[row].m_UserColor, true, nullptr, GetDefaultUserColor( m_rowUiItemsList[row].m_Item->GetType() ) ); @@ -1268,16 +1254,15 @@ void PANEL_SETUP_BOARD_STACKUP::onColorSelected( wxCommandEvent& event ) if( dlg.ShowModal() == wxID_OK ) { wxBitmapComboBox* combo = static_cast( FindWindowById( item_id ) ); - wxColour color = dlg.GetColor().ToColour(); + COLOR4D color = dlg.GetColor(); m_rowUiItemsList[row].m_UserColor = color; - // NB: wxWidgets 3.0's color.GetAsString( wxC2S_HTML_SYNTAX ) pukes on alpha - combo->SetString( idx, getColourAsHexString( color ) ); + combo->SetString( idx, color.ToHexString() ); wxBitmap layerbmp( m_colorSwatchesSize.x, m_colorSwatchesSize.y ); - LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D( 0, 0, 0, 0 ), COLOR4D( color ) ); - combo->SetItemBitmap( combo->GetCount()-1, layerbmp ); + LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D( 0, 0, 0, 0 ), color ); + combo->SetItemBitmap( combo->GetCount() - 1, layerbmp ); combo->SetSelection( idx ); } @@ -1356,10 +1341,43 @@ void PANEL_SETUP_BOARD_STACKUP::onMaterialChange( wxCommandEvent& event ) item->SetEpsilonR( substrate.m_EpsilonR, sub_item ); item->SetLossTangent( substrate.m_LossTangent, sub_item ); - wxTextCtrl* textCtrl; - textCtrl = static_cast( m_rowUiItemsList[row].m_MaterialCtrl ); + wxTextCtrl* textCtrl = static_cast( m_rowUiItemsList[row].m_MaterialCtrl ); textCtrl->ChangeValue( item->GetMaterial( sub_item ) ); + if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC + && !item->GetColor().StartsWith( "#" ) /* User defined color */ ) + { + if( substrate.m_Name.IsSameAs( "PTFE" ) + || substrate.m_Name.IsSameAs( "Teflon" ) ) + { + item->SetColor( "PTFE natural" ); + } + else if( substrate.m_Name.IsSameAs( "Polyimide" ) + || substrate.m_Name.IsSameAs( "Kapton" ) ) + { + item->SetColor( "Polyimide" ); + } + else if( substrate.m_Name.IsSameAs( "Al" ) ) + { + item->SetColor( "Aluminum" ); + } + else + { + item->SetColor( "FR4 natural" ); + } + } + + wxBitmapComboBox* picker = static_cast( m_rowUiItemsList[row].m_ColorCtrl ); + + for( int ii = 0; ii < GetStandardColorCount( item->GetType()); ii++ ) + { + if( GetStandardColorName( item->GetType(), ii ) == item->GetColor() ) + { + picker->SetSelection( ii ); + break; + } + } + // some layers have a material choice but not EpsilonR ctrl if( item->HasEpsilonRValue() ) { @@ -1468,32 +1486,29 @@ wxBitmapComboBox* PANEL_SETUP_BOARD_STACKUP::createColorBox( BOARD_STACKUP_ITEM* wxDefaultSize, 0, nullptr, wxCB_READONLY ); // Fills the combo box with choice list + bitmaps - const FAB_LAYER_COLOR* color_list = GetColorStandardList(); BOARD_STACKUP_ITEM_TYPE itemType = aStackupItem ? aStackupItem->GetType() : BS_ITEM_TYPE_SILKSCREEN; - for( int ii = 0; ii < GetColorStandardListCount(); ii++ ) + for( int ii = 0; ii < GetStandardColorCount( itemType ); ii++ ) { - wxColor curr_color; wxString label; + COLOR4D curr_color; // Defined colors have a name, the user color uses HTML notation ( i.e. #FF000080) - if( ii == GetColorUserDefinedListIdx() + if( IsCustomColorIdx( itemType, ii ) && aStackupItem && aStackupItem->GetColor().StartsWith( "#" ) ) { - curr_color = wxColour( COLOR4D( aStackupItem->GetColor() ).ToColour() ); - - // NB: wxWidgets 3.0's color.GetAsString( wxC2S_HTML_SYNTAX ) pukes on alpha - label = getColourAsHexString( curr_color ); + label = aStackupItem->GetColor(); + curr_color = COLOR4D( label ); } else { - curr_color = color_list[ii].GetColor( itemType ); - label = _( color_list[ii].GetName() ); + label = wxGetTranslation( GetStandardColorName( itemType, ii ) ); + curr_color = GetStandardColor( itemType, ii ); } wxBitmap layerbmp( m_colorSwatchesSize.x, m_colorSwatchesSize.y ); - LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D( 0, 0, 0, 0 ), COLOR4D( curr_color ) ); + LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D( 0, 0, 0, 0 ), curr_color ); combo->Append( label, layerbmp ); } diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.h b/pcbnew/board_stackup_manager/panel_board_stackup.h index 263e4e1456..1e2ac81009 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.h +++ b/pcbnew/board_stackup_manager/panel_board_stackup.h @@ -64,7 +64,7 @@ struct BOARD_STACKUP_ROW_UI_ITEM wxControl* m_EpsilonCtrl; // control shown in column 8 wxControl* m_LossTgCtrl; // control shown in column 9 - wxColour 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 = 1 ) : m_Item( aItem ), @@ -79,8 +79,7 @@ struct BOARD_STACKUP_ROW_UI_ITEM m_ThicknessLockCtrl( nullptr ), m_ColorCtrl( nullptr ), m_EpsilonCtrl( nullptr ), - m_LossTgCtrl( nullptr ), - m_UserColor( wxNullColour ) + m_LossTgCtrl( nullptr ) {} }; @@ -88,8 +87,7 @@ struct BOARD_STACKUP_ROW_UI_ITEM class PANEL_SETUP_BOARD_STACKUP : public PANEL_SETUP_BOARD_STACKUP_BASE { public: - PANEL_SETUP_BOARD_STACKUP( PAGED_DIALOG* aParent, - PCB_EDIT_FRAME* aFrame, + PANEL_SETUP_BOARD_STACKUP( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame, PANEL_SETUP_LAYERS* aPanelLayers ); ~PANEL_SETUP_BOARD_STACKUP(); diff --git a/pcbnew/board_stackup_manager/stackup_predefined_prms.cpp b/pcbnew/board_stackup_manager/stackup_predefined_prms.cpp index 331eace138..72cc880a2d 100644 --- a/pcbnew/board_stackup_manager/stackup_predefined_prms.cpp +++ b/pcbnew/board_stackup_manager/stackup_predefined_prms.cpp @@ -29,11 +29,10 @@ #include // _HKI definition #include "stackup_predefined_prms.h" -// A list of copper finish standard type names -// They are standard names in .gbdjob files, so avoid changing them or -// ensure they are compatible with .gbrjob file spec. -// These names are in fact usual copper finish names. -static wxString CopperFinishType[] = +// A list of copper finish standard type names. +// They are standard names in .gbdjob files, so avoid changing them or ensure they are +// compatible with .gbrjob file spec. +static wxString copperFinishType[] = { NotSpecifiedPrm(), // Not specified, not in .gbrjob file _HKI( "ENIG" ), // used in .gbrjob file @@ -52,13 +51,12 @@ static wxString CopperFinishType[] = }; -// A list of available colors for solder mask and silkscreen -// These names are used in .gbrjob file, so they are not fully free. -// Use only what is allowed in .gbrjob files. -// for other colors (user defined), the defined value is the -// html color syntax in .kicad_pcb files -// and RGB In gbrjob file. -static FAB_LAYER_COLOR solderMaskColors[] = +// A list of available colors for solder mask and silkscreen. +// These names are used in .gbrjob file, so they are not fully free. Use only what is allowed in +// .gbrjob files. +// For other colors (user defined), the defined value is the html color syntax in .kicad_pcb files +// and RGB in .gbrjob file. +static FAB_LAYER_COLOR gbrjobColors[] = { { NotSpecifiedPrm(), wxColor( 80, 80, 80 ) }, // Not specified, not in .gbrjob file { _HKI( "Green" ), wxColor( 60, 150, 80 ) }, // used in .gbrjob file @@ -68,35 +66,61 @@ static FAB_LAYER_COLOR solderMaskColors[] = { _HKI( "Black" ), wxColor( 20, 20, 20 ) }, // used in .gbrjob file { _HKI( "White" ), wxColor( 200, 200, 200 ) }, // used in .gbrjob file { _HKI( "Yellow" ), wxColor( 128, 128, 0 ) }, // 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 }; -wxArrayString GetCopperFinishStandardList( bool aTranslate ) +// These are used primarily as a source for the 3D renderer. They are not (at present) written +// to the .gbrjob file. +static FAB_LAYER_COLOR dielectricColors[] = +{ + { NotSpecifiedPrm(), wxColor( 80, 80, 80, 255 ) }, + { _HKI( "FR4 natural" ), wxColor( 109, 116, 75, 212 ) }, + { _HKI( "PTFE natural" ), wxColor( 252, 252, 250, 230 ) }, + { _HKI( "Polyimide" ), wxColor( 205, 130, 0, 170 ) }, + { _HKI( "Phenolic natural" ), wxColor( 92, 17, 6, 230 ) }, + { _HKI( "Aluminum" ), wxColor( 213, 213, 213, 255 ) }, + { _HKI( "User defined" ), wxColor( 128, 128, 128, 212 ) } +}; + + +wxArrayString GetStandardCopperFinishes( bool aTranslate ) { wxArrayString list; - for( unsigned ii = 0; ii < arrayDim( CopperFinishType ); ii++ ) - list.Add( aTranslate ? wxGetTranslation( CopperFinishType[ii] ) : CopperFinishType[ii] ); + for( unsigned ii = 0; ii < arrayDim( copperFinishType ); ii++ ) + list.Add( aTranslate ? wxGetTranslation( copperFinishType[ii] ) : copperFinishType[ii] ); return list; } -const FAB_LAYER_COLOR* GetColorStandardList() +const FAB_LAYER_COLOR* GetStandardColors( BOARD_STACKUP_ITEM_TYPE aType ) { - return solderMaskColors; + switch( aType ) + { + case BS_ITEM_TYPE_SILKSCREEN: return gbrjobColors; + case BS_ITEM_TYPE_SOLDERMASK: return gbrjobColors; + case BS_ITEM_TYPE_DIELECTRIC: return dielectricColors; + default: return nullptr; + } } -int GetColorStandardListCount() +int GetStandardColorCount( BOARD_STACKUP_ITEM_TYPE aType ) { - return arrayDim( solderMaskColors ); + switch( aType ) + { + case BS_ITEM_TYPE_SILKSCREEN: return arrayDim( gbrjobColors ); + case BS_ITEM_TYPE_SOLDERMASK: return arrayDim( gbrjobColors ); + case BS_ITEM_TYPE_DIELECTRIC: return arrayDim( dielectricColors ); + default: return 0; + } } -int GetColorUserDefinedListIdx() +int GetColorUserDefinedListIdx( BOARD_STACKUP_ITEM_TYPE aType ) { // this is the last item in list - return GetColorStandardListCount() - 1; + return GetStandardColorCount( aType ) - 1; } diff --git a/pcbnew/board_stackup_manager/stackup_predefined_prms.h b/pcbnew/board_stackup_manager/stackup_predefined_prms.h index a75e5514d4..16895d45b7 100644 --- a/pcbnew/board_stackup_manager/stackup_predefined_prms.h +++ b/pcbnew/board_stackup_manager/stackup_predefined_prms.h @@ -85,12 +85,12 @@ public: return m_colorName; } - wxColor GetColor( BOARD_STACKUP_ITEM_TYPE aItemType ) const + KIGFX::COLOR4D GetColor( BOARD_STACKUP_ITEM_TYPE aItemType ) const { if( aItemType == BS_ITEM_TYPE_SOLDERMASK ) - return m_color.WithAlpha( DEFAULT_SOLDERMASK_OPACITY ).ToColour(); + return m_color.WithAlpha( DEFAULT_SOLDERMASK_OPACITY ); else - return m_color.WithAlpha( 1.0 ).ToColour(); + return m_color.WithAlpha( 1.0 ); } private: @@ -104,26 +104,41 @@ private: * @return a wxArray of standard copper finish names. * @param aTranslate = false for the initial names, true for translated names */ -wxArrayString GetCopperFinishStandardList( bool aTranslate ); +wxArrayString GetStandardCopperFinishes( bool aTranslate ); /** * @return a list of standard FAB_LAYER_COLOR items for silkscreen and solder mask. */ -const FAB_LAYER_COLOR* GetColorStandardList(); +const FAB_LAYER_COLOR* GetStandardColors( BOARD_STACKUP_ITEM_TYPE aType ); /** * @return the count of colors in ColorStandardList */ -int GetColorStandardListCount(); +int GetStandardColorCount( BOARD_STACKUP_ITEM_TYPE aType ); /** * @return the index of the user defined color in ColorStandardList */ -int GetColorUserDefinedListIdx(); +int GetColorUserDefinedListIdx( BOARD_STACKUP_ITEM_TYPE aType ); -inline wxColour GetDefaultUserColor( BOARD_STACKUP_ITEM_TYPE aType ) +inline KIGFX::COLOR4D GetDefaultUserColor( BOARD_STACKUP_ITEM_TYPE aType ) { - return GetColorStandardList()[GetColorUserDefinedListIdx()].GetColor( aType ); + return GetStandardColors( aType )[GetColorUserDefinedListIdx( aType )].GetColor( aType ); +} + +inline KIGFX::COLOR4D GetStandardColor( BOARD_STACKUP_ITEM_TYPE aType, int aIdx ) +{ + return GetStandardColors( aType )[ aIdx ].GetColor( aType ); +} + +inline const wxString& GetStandardColorName( BOARD_STACKUP_ITEM_TYPE aType, int aIdx ) +{ + return GetStandardColors( aType )[ aIdx ].GetName(); +} + +inline bool IsCustomColorIdx( BOARD_STACKUP_ITEM_TYPE aType, int aIdx ) +{ + return aIdx == GetColorUserDefinedListIdx( aType ); }