KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zone_settings.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <zone_settings.h>
27
28#include <pcb_base_frame.h>
29#include <board.h>
31#include <zones.h>
32
33#include <zone.h>
34#include <wx/dataview.h>
36
38{
40 m_FillMode = ZONE_FILL_MODE::POLYGONS; // Mode for filling zone
41 // Zone clearance value
43 // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
45 // Arbitrary defaults for the hatch settings
46 m_HatchThickness = std::max( m_ZoneMinThickness * 4, pcbIUScale.mmToIU( 1.0 ) );
47 m_HatchGap = std::max( m_ZoneMinThickness * 6, pcbIUScale.mmToIU( 1.5 ) );
48 m_HatchOrientation = ANGLE_0; // Grid style: orientation of grid lines
49 m_HatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
50 m_HatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
51 m_HatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
52 m_HatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
53 m_NetcodeSelection = 0; // Net code selection for the current zone
54 m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; // Option to show the zone
55 // outlines only, short
56 // hatches or full hatches
58
59 m_Layers.reset().set( F_Cu );
60 m_Name = wxEmptyString;
61
62 // thickness of the gap in thermal reliefs:
64 // thickness of the copper bridge in thermal reliefs:
66
67 m_padConnection = ZONE_CONNECTION::THERMAL; // How pads are covered by copper in zone
68
69 m_Locked = false;
70
73
74 m_removeIslands = ISLAND_REMOVAL_MODE::ALWAYS;
76
77 SetIsRuleArea( false );
79 SetDoNotAllowVias( true );
80 SetDoNotAllowTracks( true );
81 SetDoNotAllowPads( true );
83
84 m_TeardropType = TEARDROP_TYPE::TD_NONE;
85}
86
87
88bool ZONE_SETTINGS::operator==( const ZONE_SETTINGS& aOther ) const
89{
90 if( m_ZonePriority != aOther.m_ZonePriority ) return false;
91 if( m_FillMode != aOther.m_FillMode ) return false;
92 if( m_ZoneClearance != aOther.m_ZoneClearance ) return false;
93 if( m_ZoneMinThickness != aOther.m_ZoneMinThickness ) return false;
94 if( m_HatchThickness != aOther.m_HatchThickness ) return false;
95 if( m_HatchGap != aOther.m_HatchGap ) return false;
96 if( m_HatchOrientation != aOther.m_HatchOrientation ) return false;
97 if( m_HatchSmoothingLevel != aOther.m_HatchSmoothingLevel ) return false;
98 if( m_HatchSmoothingValue != aOther.m_HatchSmoothingValue ) return false;
99 if( m_HatchBorderAlgorithm != aOther.m_HatchBorderAlgorithm ) return false;
100 if( m_HatchHoleMinArea != aOther.m_HatchHoleMinArea ) return false;
101 if( m_NetcodeSelection != aOther.m_NetcodeSelection ) return false;
102 if( m_Name != aOther.m_Name ) return false;
103 if( m_ZoneBorderDisplayStyle != aOther.m_ZoneBorderDisplayStyle ) return false;
104 if( m_BorderHatchPitch != aOther.m_BorderHatchPitch ) return false;
105 if( m_ThermalReliefGap != aOther.m_ThermalReliefGap ) return false;
106 if( m_ThermalReliefSpokeWidth != aOther.m_ThermalReliefSpokeWidth ) return false;
107 if( m_padConnection != aOther.m_padConnection ) return false;
108 if( m_cornerSmoothingType != aOther.m_cornerSmoothingType ) return false;
109 if( m_cornerRadius != aOther.m_cornerRadius ) return false;
110 if( m_isRuleArea != aOther.m_isRuleArea ) return false;
112 if( m_keepoutDoNotAllowVias != aOther.m_keepoutDoNotAllowVias ) return false;
113 if( m_keepoutDoNotAllowTracks != aOther.m_keepoutDoNotAllowTracks ) return false;
114 if( m_keepoutDoNotAllowPads != aOther.m_keepoutDoNotAllowPads ) return false;
116 if( m_Locked != aOther.m_Locked ) return false;
117 if( m_removeIslands != aOther.m_removeIslands ) return false;
118 if( m_minIslandArea != aOther.m_minIslandArea ) return false;
119
120 // Currently, the teardrop area type is not really a ZONE_SETTINGS parameter,
121 // but a ZONE parameter only.
122 // However it can be used in dialogs
123 if( m_TeardropType != aOther.m_TeardropType ) return false;
124
125 if( m_Layers != aOther.m_Layers ) return false;
126
127 return true;
128}
129
130
132{
134 m_FillMode = aSource.GetFillMode();
135 m_ZoneClearance = aSource.GetLocalClearance().value();
138 m_HatchGap = aSource.GetHatchGap();
144 m_NetcodeSelection = aSource.GetNetCode();
145 m_Name = aSource.GetZoneName();
153 m_isRuleArea = aSource.GetIsRuleArea();
159 m_Locked = aSource.IsLocked();
162
163 // Currently, the teardrop area type is not really a ZONE_SETTINGS parameter,
164 // but a ZONE parameter only.
165 // However it can be used in dialogs
167
168 m_Layers = aSource.GetLayerSet();
169
170 return *this;
171}
172
173
174void ZONE_SETTINGS::ExportSetting( ZONE& aTarget, bool aFullExport ) const
175{
176 aTarget.SetFillMode( m_FillMode );
180 aTarget.SetHatchGap( m_HatchGap );
191 aTarget.SetIsRuleArea( GetIsRuleArea() );
197 aTarget.SetLocked( m_Locked );
200 // Currently, the teardrop area type is not imported from a ZONE_SETTINGS, because
201 // it is not really a ZONE_SETTINGS parameter, but a ZONE parameter only
202#if 0
204#endif
205
206
207 if( aFullExport )
208 {
210 aTarget.SetLayerSet( m_Layers );
211 aTarget.SetZoneName( m_Name );
212
213 if( !m_isRuleArea )
215 }
216
217 // call SetBorderDisplayStyle last, because hatch lines will be rebuilt,
218 // using new parameters values
220 m_BorderHatchPitch, true );
221}
222
223
225{
226 if( aRadius < 0 )
227 m_cornerRadius = 0;
228 else
229 m_cornerRadius = aRadius;
230}
231
232
233#ifdef __WXOSX_MAC__
234const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
235#else
236const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
237#endif
238
239const static wxSize CHECKERBOARD_SIZE( 8, 8 );
240
241
243{
244 static ZONE_SETTINGS defaultSettings;
245
246 return defaultSettings;
247}
248
249
250// A helper for setting up a dialog list for specifying zone layers. Used by all three
251// zone settings dialogs.
252void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
253 LSET aLayers, bool aFpEditorMode )
254{
255 BOARD* board = aFrame->GetBoard();
256 COLOR4D backgroundColor = aFrame->GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
257
258 // In the Footprint Editor In1_Cu is used as a proxy for "all inner layers"
259 if( aFpEditorMode )
260 aLayers.set( In1_Cu );
261
262 wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
263 wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
264 wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
265 layerIDColumn->SetHidden( true );
266
267 int textWidth = 0;
268
269 for( LSEQ layer = aLayers.UIOrder(); layer; ++layer )
270 {
271 PCB_LAYER_ID layerID = *layer;
272 wxString layerName = board->GetLayerName( layerID );
273
274 if( aFpEditorMode && layerID == In1_Cu )
275 layerName = _( "Inner layers" );
276
277 // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
278 textWidth = std::max( textWidth, KIUI::GetTextSize( layerName, aList ).x );
279
280 COLOR4D layerColor = aFrame->GetColorSettings()->GetColor( layerID );
281 auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE,
282 CHECKERBOARD_SIZE, aList->GetBackgroundColour() );
283 wxIcon icon;
284 icon.CopyFromBitmap( bitmap );
285
286 wxVector<wxVariant> row;
287 row.push_back( wxVariant( m_Layers.test( layerID ) ) );
288 row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
289 row.push_back( wxVariant( wxString::Format( wxT( "%i" ), layerID ) ) );
290 aList->AppendItem( row );
291
292 if( m_Layers.test( layerID ) )
293 aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
294 }
295
296 int checkColSize = 22;
297 int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
298
299#ifdef __WXMAC__
300 // TODO: something in wxWidgets 3.1.x pads checkbox columns with extra space. (It used to
301 // also be that the width of the column would get set too wide (to 30), but that's patched in
302 // our local wxWidgets fork.)
303 int checkColMargins = 40;
304#else
305 int checkColMargins = 0;
306#endif
307
308 // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
309 // for the tree expanders... but you'd be wrong. Force indent to 0.
310 aList->SetIndent( 0 );
311 aList->SetMinClientSize( wxSize( checkColSize + checkColMargins + layerColSize,
312 aList->GetMinClientSize().y ) );
313
314 checkColumn->SetWidth( checkColSize );
315 layerColumn->SetWidth( layerColSize );
316}
317
318
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void SetLocked(bool aLocked)
Definition: board_item.h:300
virtual bool IsLocked() const
Definition: board_item.cpp:74
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:567
COLOR4D GetColor(int aLayer) const
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:520
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:574
LSEQ UIOrder() const
Definition: lset.cpp:1012
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:71
bool GetDoNotAllowCopperPour() const
bool m_keepoutDoNotAllowPads
void SetIsRuleArea(bool aEnable)
bool operator==(const ZONE_SETTINGS &aOther) const
unsigned int m_cornerRadius
bool GetDoNotAllowTracks() const
EDA_ANGLE m_HatchOrientation
Definition: zone_settings.h:89
int m_HatchBorderAlgorithm
Definition: zone_settings.h:94
void SetDoNotAllowVias(bool aEnable)
bool GetDoNotAllowFootprints() const
int m_NetcodeSelection
Definition: zone_settings.h:96
long long int m_minIslandArea
bool m_keepoutDoNotAllowTracks
bool GetDoNotAllowPads() const
double m_HatchSmoothingValue
Definition: zone_settings.h:92
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
int m_cornerSmoothingType
void SetDoNotAllowTracks(bool aEnable)
bool GetDoNotAllowVias() const
bool m_keepoutDoNotAllowCopperPour
ISLAND_REMOVAL_MODE m_removeIslands
double m_HatchHoleMinArea
Definition: zone_settings.h:93
int m_ZoneMinThickness
Definition: zone_settings.h:86
long long int GetMinIslandArea() const
long m_ThermalReliefSpokeWidth
TEARDROP_TYPE m_TeardropType
static const ZONE_SETTINGS & GetDefaultSettings()
unsigned m_ZonePriority
Definition: zone_settings.h:82
void SetCornerRadius(int aRadius)
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, LSET aLayers, bool aFpEditorMode)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
wxString m_Name
Definition: zone_settings.h:98
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:84
ZONE_CONNECTION m_padConnection
long m_ThermalReliefGap
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowPads(bool aEnable)
ZONE_SETTINGS & operator<<(const ZONE &aSource)
operator << ( const ZONE& ) was Function ImportSetting copies settings from a given zone into this ob...
int m_HatchSmoothingLevel
Definition: zone_settings.h:90
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
bool m_keepoutDoNotAllowFootprints
bool m_keepoutDoNotAllowVias
void SetDoNotAllowCopperPour(bool aEnable)
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
void SetHatchThickness(int aThickness)
Definition: zone.h:285
void SetHatchBorderAlgorithm(int aAlgo)
Definition: zone.h:303
void SetDoNotAllowPads(bool aEnable)
Definition: zone.h:721
int GetHatchBorderAlgorithm() const
Definition: zone.h:302
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:710
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:490
void SetLocalClearance(std::optional< int > aClearance)
Definition: zone.h:154
bool GetDoNotAllowVias() const
Definition: zone.h:712
void SetCornerRadius(unsigned int aRadius)
Definition: zone.cpp:395
void SetCornerSmoothingType(int aType)
Definition: zone.h:659
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuilBorderdHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:875
bool GetDoNotAllowPads() const
Definition: zone.h:714
void SetMinThickness(int aMinThickness)
Definition: zone.h:270
bool GetDoNotAllowTracks() const
Definition: zone.h:713
void SetHatchOrientation(const EDA_ANGLE &aStep)
Definition: zone.h:291
void SetHatchSmoothingValue(double aValue)
Definition: zone.h:297
void SetHatchSmoothingLevel(int aLevel)
Definition: zone.h:294
void SetDoNotAllowCopperPour(bool aEnable)
Definition: zone.h:718
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition: zone.h:205
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:724
long long int GetMinIslandArea() const
Definition: zone.h:727
void SetIsRuleArea(bool aEnable)
Definition: zone.h:717
void SetDoNotAllowTracks(bool aEnable)
Definition: zone.h:720
const wxString & GetZoneName() const
Definition: zone.h:131
int GetMinThickness() const
Definition: zone.h:269
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: zone.h:191
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:266
int GetHatchThickness() const
Definition: zone.h:284
double GetHatchHoleMinArea() const
Definition: zone.h:299
void SetDoNotAllowVias(bool aEnable)
Definition: zone.h:719
int GetThermalReliefSpokeWidth() const
Definition: zone.h:213
int GetBorderHatchPitch() const
HatchBorder related methods.
Definition: zone.cpp:869
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: zone.h:604
void SetThermalReliefGap(int aThermalReliefGap)
Definition: zone.h:194
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:290
void SetLayerSet(LSET aLayerSet) override
Definition: zone.cpp:267
bool GetDoNotAllowFootprints() const
Definition: zone.h:715
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:192
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:129
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:722
bool GetDoNotAllowCopperPour() const
Definition: zone.h:711
int GetHatchGap() const
Definition: zone.h:287
void SetHatchHoleMinArea(double aPct)
Definition: zone.h:300
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:705
double GetHatchSmoothingValue() const
Definition: zone.h:296
int GetHatchSmoothingLevel() const
Definition: zone.h:293
unsigned int GetCornerRadius() const
Definition: zone.h:665
int GetCornerSmoothingType() const
Definition: zone.h:661
void SetAssignedPriority(unsigned aPriority)
Definition: zone.h:114
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: zone.h:267
void SetZoneName(const wxString &aName)
Definition: zone.h:132
void SetTeardropAreaType(TEARDROP_TYPE aType)
Set the type of teardrop if the zone is a teardrop area for non teardrop area, the type must be TEARD...
Definition: zone.h:700
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition: zone.h:725
void SetMinIslandArea(long long int aArea)
Definition: zone.h:728
int GetThermalReliefGap() const
Definition: zone.h:202
void SetHatchGap(int aStep)
Definition: zone.h:288
unsigned GetAssignedPriority() const
Definition: zone.h:119
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:224
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ In1_Cu
Definition: layer_ids.h:65
@ F_Cu
Definition: layer_ids.h:64
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:74
const double IU_PER_MM
Definition: base_units.h:76
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
static const wxSize CHECKERBOARD_SIZE(8, 8)
static const wxSize LAYER_BITMAP_SIZE(24, 16)
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
#define ZONE_THERMAL_RELIEF_GAP_MM
Definition: zones.h:33
#define ZONE_BORDER_HATCH_DIST_MM
Definition: zones.h:39
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM
Definition: zones.h:34
#define ZONE_CLEARANCE_MM
Definition: zones.h:37
#define ZONE_THICKNESS_MM
Definition: zones.h:35