From 3bb1fd83113f7fb5184e8dd09744e3b6854792b1 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 5 Mar 2022 17:18:42 +0100 Subject: [PATCH] Teardrops: fixes and enhancements: - do not allow smoothing outlines: outlines are already optimized. - do not allow settings incompatible with teardrop area (grid, thermal relief) - DIALOG_COPPER_ZONE: export zone settings to similar zones only. Fixes #11040 https://gitlab.com/kicad/code/kicad/issues/11040 --- pcbnew/dialogs/dialog_copper_zones.cpp | 53 +++++++++++++++++++++++--- pcbnew/teardrop/teardrop_types.h | 42 ++++++++++++++++++++ pcbnew/zone.cpp | 14 ++++++- pcbnew/zone.h | 13 +------ pcbnew/zone_settings.cpp | 11 ++++++ pcbnew/zone_settings.h | 6 +++ 6 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 pcbnew/teardrop/teardrop_types.h diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index b2ebcac80d..1568acdc6c 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -81,6 +81,7 @@ private: UNIT_BINDER m_gridStyleGap; UNIT_BINDER m_islandThreshold; bool m_hideAutoGeneratedNets; + bool m_isTeardrop; std::map m_netNameToNetCode; std::vector m_netInfoItemList; @@ -189,6 +190,26 @@ DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* m_settings.SetupLayersList( m_layers, m_Parent, LSET::AllCuMask( aParent->GetBoard()->GetCopperLayerCount() ), false ); + m_isTeardrop = m_settings.m_TeardropType != TEARDROP_TYPE::TD_NONE; + + switch( m_settings.m_TeardropType ) + { + case TEARDROP_TYPE::TD_NONE: + // standard copper zone + break; + + case TEARDROP_TYPE::TD_VIAPAD: + SetTitle( _( "Teardrop on Vias/Pads Properties" ) ); + break; + + case TEARDROP_TYPE::TD_TRACKEND: + SetTitle( _( "Teardrop on Tracks Properties" ) ); + break; + + default: + SetTitle( _( "Teardrop Properties" ) ); + break; + } m_settingsExported = false; m_currentlySelectedNetcode = INVALID_NET_CODE; @@ -223,6 +244,14 @@ bool DIALOG_COPPER_ZONE::TransferDataToWindow() m_cornerRadius.SetValue( m_settings.GetCornerRadius() ); m_PriorityLevelCtrl->SetValue( m_settings.m_ZonePriority ); + if( m_isTeardrop ) // outlines are never smoothed: they have alreay the right shape + { + m_cornerSmoothingChoice->SetSelection( 0 ); + m_cornerSmoothingChoice->Enable( false ); + m_cornerRadius.SetValue( 0 ); + m_cornerRadius.Enable( false ); + } + switch( m_settings.m_ZoneBorderDisplayStyle ) { case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break; @@ -244,6 +273,12 @@ bool DIALOG_COPPER_ZONE::TransferDataToWindow() case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break; } + if( m_isTeardrop ) + { + m_PadInZoneOpt->SetSelection( 0 ); + m_PadInZoneOpt->Enable( false ); + } + // Do not enable/disable antipad clearance and spoke width. They might be needed if // a footprint or pad overrides the zone to specify a thermal connection. m_antipadClearance.SetValue( m_settings.m_ThermalReliefGap ); @@ -270,11 +305,12 @@ bool DIALOG_COPPER_ZONE::TransferDataToWindow() // Initialize information required to display nets list readNetInformation(); - switch( m_settings.m_FillMode ) - { - case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break; - default: m_GridStyleCtrl->SetSelection( 0 ); break; - } + if( !m_isTeardrop && m_settings.m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN ) + m_GridStyleCtrl->SetSelection( 1 ); + else + m_GridStyleCtrl->SetSelection( 0 ); + + m_GridStyleCtrl->Enable( !m_isTeardrop ); m_gridStyleRotation.SetUnits( EDA_UNITS::DEGREES ); m_gridStyleRotation.SetAngleValue( m_settings.m_HatchOrientation ); @@ -655,6 +691,13 @@ void DIALOG_COPPER_ZONE::ExportSetupToOtherCopperZones( wxCommandEvent& event ) if( zone->GetIsRuleArea() ) continue; + // Export only to similar zones: + // Teardrop area -> teardrop area of same type + // copper zone -> copper zone + // Exporting current settings to a different zone type make no sense + if( m_settings.m_TeardropType != zone->GetTeardropAreaType() ) + continue; + m_settings.ExportSetting( *zone, false ); // false = partial export m_settingsExported = true; m_Parent->OnModify(); diff --git a/pcbnew/teardrop/teardrop_types.h b/pcbnew/teardrop/teardrop_types.h new file mode 100644 index 0000000000..97360cb2da --- /dev/null +++ b/pcbnew/teardrop/teardrop_types.h @@ -0,0 +1,42 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2021 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef TEARDROP_TYPES_H +#define TEARDROP_TYPES_H + +/** + * define the type of a teardrop: on a via or pad, or a track end + */ +enum class TEARDROP_TYPE +{ + TD_NONE = 0, // Not a teardrop: just a standard zone + TD_UNSPECIFIED, // Not specified/unknown teardrop type + TD_VIAPAD, // a teardrop on a via or pad + TD_TRACKEND // a teardrop on a track end + // (when 2 tracks having different widths have a teardrop on the + // end of the largest track) +}; + + +#endif // ifndef TEARDROP_TYPES_H diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index b77bf6bb20..ce3b92113d 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -520,6 +520,8 @@ void ZONE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& if( GetIsRuleArea() ) msg = _( "Rule Area" ); + else if( IsTeardropArea() ) + msg = _( "Teardrop Area" ); else if( IsOnCopperLayer() ) msg = _( "Copper Zone" ); else @@ -1068,6 +1070,12 @@ bool ZONE::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly, PCB_LAYER_ID aLayer const BOARD* board = GetBoard(); int maxError = ARC_HIGH_DEF; bool keepExternalFillets = false; + bool smooth_requested = m_cornerSmoothingType == ZONE_SETTINGS::SMOOTHING_CHAMFER + || m_cornerSmoothingType == ZONE_SETTINGS::SMOOTHING_FILLET; + + if( IsTeardropArea() ) // We use teardrop shapes with no smoothing + // these shapes are already optimized + smooth_requested = false; if( board ) { @@ -1079,6 +1087,10 @@ bool ZONE::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly, PCB_LAYER_ID aLayer auto smooth = [&]( SHAPE_POLY_SET& aPoly ) { + + if( !smooth_requested ) + return; + switch( m_cornerSmoothingType ) { case ZONE_SETTINGS::SMOOTHING_CHAMFER: @@ -1107,7 +1119,7 @@ bool ZONE::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly, PCB_LAYER_ID aLayer // Should external fillets (that is, those applied to concave corners) be kept? While it // seems safer to never have copper extend outside the zone outline, 5.1.x and prior did // indeed fill them so we leave the mode available. - if( keepExternalFillets ) + if( keepExternalFillets && smooth_requested ) { withFillets = flattened; smooth( withFillets ); diff --git a/pcbnew/zone.h b/pcbnew/zone.h index d620021fe1..ca1877d2e7 100644 --- a/pcbnew/zone.h +++ b/pcbnew/zone.h @@ -34,6 +34,7 @@ #include #include #include +#include class EDA_RECT; @@ -43,18 +44,6 @@ class BOARD; class ZONE; class MSG_PANEL_ITEM; -/** - * define the type of a teardrop: on a via or pad, or atrack end - */ -enum class TEARDROP_TYPE -{ - TD_NONE = 0, // Not a teardrop: just a standard zone - TD_UNSPECIFIED, // Not specified/unknown teardrop type - TD_VIAPAD, // a teardrop on a via or pad - TD_TRACKEND // a teardrop on a track end - // (when 2 tracks having different widths have a teardrop on the - // end of the largest track) -}; /** * Handle a list of polygons defining a copper zone. diff --git a/pcbnew/zone_settings.cpp b/pcbnew/zone_settings.cpp index d2bc111484..117120c0a9 100644 --- a/pcbnew/zone_settings.cpp +++ b/pcbnew/zone_settings.cpp @@ -122,6 +122,11 @@ ZONE_SETTINGS& ZONE_SETTINGS::operator << ( const ZONE& aSource ) m_removeIslands = aSource.GetIslandRemovalMode(); m_minIslandArea = aSource.GetMinIslandArea(); + // Currently, the teardrop area type is not really a ZONE_SETTINGS parameter, + // but a ZONE parameter only. + // However it can be used in dialogs + m_TeardropType = aSource.GetTeardropAreaType(); + m_Layers = aSource.GetLayerSet(); return *this; @@ -155,6 +160,12 @@ void ZONE_SETTINGS::ExportSetting( ZONE& aTarget, bool aFullExport ) const aTarget.SetLocked( m_Locked ); aTarget.SetIslandRemovalMode( GetIslandRemovalMode() ); aTarget.SetMinIslandArea( GetMinIslandArea() ); + // Currently, the teardrop area type is not imported from a ZONE_SETTINGS, because + // it is not really a ZONE_SETTINGS parameter, but a ZONE parameter only +#if 0 + aTarget.SetTeardropAreaType( m_TeardropType ); +#endif + if( aFullExport ) { diff --git a/pcbnew/zone_settings.h b/pcbnew/zone_settings.h index 3d48ea447f..9140a7ba29 100644 --- a/pcbnew/zone_settings.h +++ b/pcbnew/zone_settings.h @@ -33,6 +33,7 @@ #include #include #include +#include class wxDataViewListCtrl; @@ -107,6 +108,11 @@ public: bool m_Zone_45_Only; bool m_Locked; + /* A zone outline can be a teardrop zone with different rules + * priority, smoothed corners, thermal relief... + */ + TEARDROP_TYPE m_TeardropType; + private: int m_cornerSmoothingType; // Corner smoothing type unsigned int m_cornerRadius; // Corner chamfer distance / fillet radius