From 1ad4fb2eea71ca29ab54af70f49f3e4df9e1ce60 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 17 Sep 2024 13:26:33 +0200 Subject: [PATCH] Convert graphic to polygon or zone: fix some issues: - fix gap added twice - add missing gap setting in DIALOG_COPPER_ZONE and DIALOG_NON_COPPER_ZONES_EDITOR From master branch Fixes https://gitlab.com/kicad/code/kicad/-/issues/18724 --- pcbnew/dialogs/dialog_copper_zones.cpp | 33 +++++++++++++++++++ .../dialog_non_copper_zones_properties.cpp | 33 +++++++++++++++++++ pcbnew/tools/convert_tool.cpp | 4 ++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index 31e35f4a94..ba6fb60629 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -46,6 +46,9 @@ public: DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings, CONVERT_SETTINGS* aConvertSettings ); + ~DIALOG_COPPER_ZONE() + { delete m_gap; } + private: using NET_FILTER = std::unique_ptr; using NET_FILTER_LIST = std::vector; @@ -114,6 +117,11 @@ private: bool m_hideAutoGeneratedNets; bool m_isTeardrop; + wxStaticText* m_gapLabel; + wxTextCtrl* m_gapCtrl; + wxStaticText* m_gapUnits; + UNIT_BINDER* m_gap; + std::map m_netNameToNetCode; std::vector m_netInfoItemList; @@ -223,6 +231,19 @@ DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) ); bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 ); + m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) ); + m_gapCtrl = new wxTextCtrl( this, wxID_ANY ); + m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) ); + m_gap = new UNIT_BINDER( m_Parent, m_gapLabel, m_gapCtrl, m_gapUnits ); + m_gap->SetValue( m_convertSettings->m_Gap ); + + wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL ); + hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 5 ); + hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 5 ); + hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL|wxLEFT, 5 ); + bConvertSizer->AddSpacer( 2 ); + bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 ); + bConvertSizer->AddSpacer( 6 ); m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) ); bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 ); @@ -235,6 +256,13 @@ DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* SetTitle( _( "Convert to Copper Zone" ) ); } + else + { + m_gapLabel = nullptr; + m_gapCtrl = nullptr; + m_gapUnits = nullptr; + m_gap = nullptr; + } m_currentlySelectedNetcode = INVALID_NET_CODE; m_maxNetCode = INVALID_NET_CODE; @@ -266,6 +294,7 @@ bool DIALOG_COPPER_ZONE::TransferDataToWindow() m_rbCenterline->SetValue( true ); m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals ); + m_gap->Enable( m_rbEnvelope->GetValue() ); } m_cbLocked->SetValue( m_settings.m_Locked ); @@ -404,6 +433,9 @@ void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& ) } m_cornerRadiusCtrl->Enable(m_cornerSmoothingType > ZONE_SETTINGS::SMOOTHING_NONE ); + + if( m_gap ) + m_gap->Enable( m_rbEnvelope->GetValue() ); } @@ -461,6 +493,7 @@ bool DIALOG_COPPER_ZONE::TransferDataFromWindow() m_convertSettings->m_Strategy = CENTERLINE; m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue(); + m_convertSettings->m_Gap = m_gap->GetIntValue(); } m_settings.m_HatchOrientation = m_gridStyleRotation.GetAngleValue(); diff --git a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp index d4f944ba4c..99bb16e9df 100644 --- a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp +++ b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp @@ -42,6 +42,9 @@ public: DIALOG_NON_COPPER_ZONES_EDITOR( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings, CONVERT_SETTINGS* aConvertSettings ); + ~DIALOG_NON_COPPER_ZONES_EDITOR() + { delete m_gap; } + private: bool TransferDataToWindow() override; bool TransferDataFromWindow() override; @@ -61,6 +64,10 @@ private: UNIT_BINDER m_hatchGap; int m_cornerSmoothingType; UNIT_BINDER m_cornerRadius; + wxStaticText* m_gapLabel; + wxTextCtrl* m_gapCtrl; + wxStaticText* m_gapUnits; + UNIT_BINDER* m_gap; CONVERT_SETTINGS* m_convertSettings; wxRadioButton* m_rbCenterline; @@ -113,6 +120,19 @@ DIALOG_NON_COPPER_ZONES_EDITOR::DIALOG_NON_COPPER_ZONES_EDITOR( PCB_BASE_FRAME* m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) ); bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 ); + m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) ); + m_gapCtrl = new wxTextCtrl( this, wxID_ANY ); + m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) ); + m_gap = new UNIT_BINDER( m_parent, m_gapLabel, m_gapCtrl, m_gapUnits ); + m_gap->SetValue( m_convertSettings->m_Gap ); + + wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL ); + hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 5 ); + hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 5 ); + hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL|wxLEFT, 5 ); + bConvertSizer->AddSpacer( 2 ); + bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 ); + bConvertSizer->AddSpacer( 6 ); m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) ); @@ -126,6 +146,13 @@ DIALOG_NON_COPPER_ZONES_EDITOR::DIALOG_NON_COPPER_ZONES_EDITOR( PCB_BASE_FRAME* SetTitle( _( "Convert to Non Copper Zone" ) ); } + else + { + m_gapLabel = nullptr; + m_gapCtrl = nullptr; + m_gapUnits = nullptr; + m_gap = nullptr; + } bool fpEditorMode = m_parent->IsType( FRAME_FOOTPRINT_EDITOR ); @@ -152,6 +179,9 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::OnUpdateUI( wxUpdateUIEvent& ) } m_cornerRadiusCtrl->Enable(m_cornerSmoothingType > ZONE_SETTINGS::SMOOTHING_NONE ); + + if( m_gap ) + m_gap->Enable( m_rbEnvelope->GetValue() ); } @@ -165,6 +195,8 @@ bool DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow() m_rbCenterline->SetValue( true ); m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals ); + + m_gap->Enable( m_rbEnvelope->GetValue() ); } m_cornerSmoothingChoice->SetSelection( m_settings.GetCornerSmoothingType() ); @@ -262,6 +294,7 @@ bool DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow() m_convertSettings->m_Strategy = CENTERLINE; m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue(); + m_convertSettings->m_Gap = m_gap->GetIntValue(); } m_settings.SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() ); diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index 9ec9f65fd6..957dfccf89 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -354,10 +354,12 @@ int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) if( cfg.m_Strategy == BOUNDING_HULL ) { - polySet.Append( makePolysFromOpenGraphics( selection.GetItems(), cfg.m_Gap ) ); + polySet.Append( makePolysFromOpenGraphics( selection.GetItems(), 0 ) ); polySet.ClearArcs(); polySet.Simplify( SHAPE_POLY_SET::PM_FAST ); + + // Now inflate the bounding hull by cfg.m_Gap polySet.Inflate( cfg.m_Gap, CORNER_STRATEGY::ROUND_ALL_CORNERS, bds.m_MaxError, ERROR_OUTSIDE ); }