diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp index f3d2207417..9e7a6dd7f2 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp +++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp @@ -44,10 +44,12 @@ #include #include #include +#include #include #include + // Some wx widget ID to know what widget has fired a event: #define ID_INCREMENT 256 // space between 2 ID type. Bigger than the layer count max @@ -117,14 +119,6 @@ PANEL_SETUP_BOARD_STACKUP::PANEL_SETUP_BOARD_STACKUP( PAGED_DIALOG* aParent, PCB buildLayerStackPanel( true ); synchronizeWithBoard( true ); computeBoardThickness(); - - m_choiceCopperLayers->Bind( wxEVT_CHOICE, - [&]( wxCommandEvent& ) - { - updateCopperLayerCount(); - showOnlyActiveLayers(); - Layout(); - } ); } @@ -134,6 +128,94 @@ PANEL_SETUP_BOARD_STACKUP::~PANEL_SETUP_BOARD_STACKUP() } +void PANEL_SETUP_BOARD_STACKUP::onCopperLayersSelCount( wxCommandEvent& event ) +{ + updateCopperLayerCount(); + showOnlyActiveLayers(); + computeBoardThickness(); + Layout(); +} + + +void PANEL_SETUP_BOARD_STACKUP::onAdjustDielectricThickness( wxCommandEvent& event ) +{ + // The list of items that can be modified: + std::vector< BOARD_STACKUP_ROW_UI_ITEM* > items_candidate; + + // Some dielectric layers can have a locked thickness, so calculate the min + // acceptable thickness + int min_thickness = 0; + + for( BOARD_STACKUP_ROW_UI_ITEM& ui_item : m_rowUiItemsList ) + { + BOARD_STACKUP_ITEM* item = ui_item.m_Item; + + if( !item->IsThicknessEditable() || !ui_item.m_isEnabled ) + continue; + + // We are looking for locked thickness items only: + wxCheckBox* cb_box = dynamic_cast ( ui_item.m_ThicknessLockCtrl ); + + if( cb_box && !cb_box->GetValue() ) + { + items_candidate.push_back( &ui_item ); + continue; + } + + wxTextCtrl* textCtrl = static_cast( ui_item.m_ThicknessCtrl ); + wxString txt = textCtrl->GetValue(); + + int item_thickness = ValueFromString( m_frame->GetUserUnits(), txt ); + min_thickness += item_thickness; + } + + wxString title; + + if( min_thickness == 0 ) + title.Printf( _( "Enter board thickness in %s" ), + GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); + else + title.Printf( _( "Enter expected board thickness in %s (min value %s)" ), + GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ), + StringFromValue( m_frame->GetUserUnits(), min_thickness ) ); + + wxTextEntryDialog dlg( this, title, _( "Adjust not locked dielectric thickness layers" ) ); + + if( dlg.ShowModal() != wxID_OK ) + return; + + wxString result = dlg.GetValue(); + + int iu_thickness = ValueFromString( m_frame->GetUserUnits(), result ); + + if( iu_thickness <= min_thickness ) + { + wxMessageBox( wxString::Format( _("Too small value (min value %s %s). Aborted" ), + StringFromValue( m_frame->GetUserUnits(), min_thickness ), + GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ) ); + return; + } + + // Now adjust not locked dielectric thickness layers: + + if( items_candidate.size() ) + { + int thickness_layer = ( iu_thickness - min_thickness ) / items_candidate.size(); + wxString txt = StringFromValue( m_frame->GetUserUnits(), thickness_layer ); + + for( BOARD_STACKUP_ROW_UI_ITEM* ui_item : items_candidate ) + { + wxTextCtrl* textCtrl = static_cast( ui_item->m_ThicknessCtrl ); + textCtrl->SetValue( txt ); + } + } + else + wxMessageBox( _( "All dielectric thickness layers are locked" ) ); + + computeBoardThickness(); +} + + void PANEL_SETUP_BOARD_STACKUP::disconnectEvents() { // Disconnect Events connected to items in m_controlItemsList @@ -902,17 +984,6 @@ void PANEL_SETUP_BOARD_STACKUP::buildLayerStackPanel( bool aCreatedInitialStacku // Transfer current UI settings to m_stackup but not to the board bool PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup() { - // First, verify the list of layers currently in stackup: if it doesn't match the list - // of layers set in PANEL_SETUP_LAYERS prompt the user to update the stackup - LSET layersList = m_panelLayers->GetUILayerMask() & BOARD_STACKUP::StackupAllowedBrdLayers(); - - if( m_enabledLayers != layersList ) - OnLayersOptionsChanged( m_panelLayers->GetUILayerMask() ); - - // The board thickness and the thickness from stackup settings should be compatible - // so verify that compatibility - int stackup_thickness = 0; - wxString txt; wxString error_msg; bool success = true; @@ -1008,7 +1079,6 @@ bool PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup() int new_thickness = ValueFromString( m_frame->GetUserUnits(), txt ); item->SetThickness( new_thickness, sub_item ); - stackup_thickness += new_thickness; if( new_thickness < 0 ) { diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.h b/pcbnew/board_stackup_manager/panel_board_stackup.h index 88e22b53ce..b1882792ff 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.h +++ b/pcbnew/board_stackup_manager/panel_board_stackup.h @@ -198,6 +198,8 @@ private: void onAddDielectricLayer( wxCommandEvent& event ) override; void onRemoveDielectricLayer( wxCommandEvent& event ) override; void onRemoveDielUI( wxUpdateUIEvent& event ) override; + void onCopperLayersSelCount( wxCommandEvent& event ) override; + void onAdjustDielectricThickness( wxCommandEvent& event ) override; /** Update the icons color (swatches in first grid column) * @param aRow is the row (index in m_rowUiItemsList) that manages the icon to update. diff --git a/pcbnew/board_stackup_manager/panel_board_stackup_base.cpp b/pcbnew/board_stackup_manager/panel_board_stackup_base.cpp index dcaaacb4c5..bfc9f90408 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup_base.cpp +++ b/pcbnew/board_stackup_manager/panel_board_stackup_base.cpp @@ -136,6 +136,9 @@ PANEL_SETUP_BOARD_STACKUP_BASE::PANEL_SETUP_BOARD_STACKUP_BASE( wxWindow* parent m_tcCTValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); bBottomSizer->Add( m_tcCTValue, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_buttonAdjust = new wxButton( this, wxID_ANY, _("Adjust Dielectric Thickness"), wxDefaultPosition, wxDefaultSize, 0 ); + bBottomSizer->Add( m_buttonAdjust, 0, wxALL, 5 ); + bBottomSizer->Add( 0, 0, 1, wxEXPAND, 5 ); @@ -148,21 +151,24 @@ PANEL_SETUP_BOARD_STACKUP_BASE::PANEL_SETUP_BOARD_STACKUP_BASE( wxWindow* parent this->SetSizer( bMainSizer ); this->Layout(); - bMainSizer->Fit( this ); // Connect Events + m_choiceCopperLayers->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onCopperLayersSelCount ), NULL, this ); m_buttonAddDielectricLayer->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onAddDielectricLayer ), NULL, this ); m_buttonRemoveDielectricLayer->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onRemoveDielectricLayer ), NULL, this ); m_buttonRemoveDielectricLayer->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onRemoveDielUI ), NULL, this ); + m_buttonAdjust->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onAdjustDielectricThickness ), NULL, this ); m_buttonExport->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onExportToClipboard ), NULL, this ); } PANEL_SETUP_BOARD_STACKUP_BASE::~PANEL_SETUP_BOARD_STACKUP_BASE() { // Disconnect Events + m_choiceCopperLayers->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onCopperLayersSelCount ), NULL, this ); m_buttonAddDielectricLayer->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onAddDielectricLayer ), NULL, this ); m_buttonRemoveDielectricLayer->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onRemoveDielectricLayer ), NULL, this ); m_buttonRemoveDielectricLayer->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onRemoveDielUI ), NULL, this ); + m_buttonAdjust->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onAdjustDielectricThickness ), NULL, this ); m_buttonExport->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP_BASE::onExportToClipboard ), NULL, this ); } diff --git a/pcbnew/board_stackup_manager/panel_board_stackup_base.fbp b/pcbnew/board_stackup_manager/panel_board_stackup_base.fbp index c0f9b567bc..32baccad78 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup_base.fbp +++ b/pcbnew/board_stackup_manager/panel_board_stackup_base.fbp @@ -43,7 +43,7 @@ PANEL_SETUP_BOARD_STACKUP_BASE - -1,-1 + 680,281 ; ; forward_declare @@ -186,6 +186,7 @@ + onCopperLayersSelCount @@ -1195,6 +1196,79 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Adjust Dielectric Thickness + + 0 + + 0 + + + 0 + + 1 + m_buttonAdjust + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onAdjustDielectricThickness + + 5 wxEXPAND diff --git a/pcbnew/board_stackup_manager/panel_board_stackup_base.h b/pcbnew/board_stackup_manager/panel_board_stackup_base.h index dbe82ea9df..2847f4658e 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup_base.h +++ b/pcbnew/board_stackup_manager/panel_board_stackup_base.h @@ -57,18 +57,21 @@ class PANEL_SETUP_BOARD_STACKUP_BASE : public wxPanel wxStaticText* m_staticTextLossTg; wxStaticText* m_staticTextCT; wxTextCtrl* m_tcCTValue; + wxButton* m_buttonAdjust; wxButton* m_buttonExport; // Virtual event handlers, overide them in your derived class + virtual void onCopperLayersSelCount( wxCommandEvent& event ) { event.Skip(); } virtual void onAddDielectricLayer( wxCommandEvent& event ) { event.Skip(); } virtual void onRemoveDielectricLayer( wxCommandEvent& event ) { event.Skip(); } virtual void onRemoveDielUI( wxUpdateUIEvent& event ) { event.Skip(); } + virtual void onAdjustDielectricThickness( wxCommandEvent& event ) { event.Skip(); } virtual void onExportToClipboard( wxCommandEvent& event ) { event.Skip(); } public: - PANEL_SETUP_BOARD_STACKUP_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + PANEL_SETUP_BOARD_STACKUP_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 680,281 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); ~PANEL_SETUP_BOARD_STACKUP_BASE(); };