KiCad PCB EDA Suite
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-2022 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 <pcbnew.h>
29#include <pcb_base_frame.h>
30#include <board.h>
32#include <zones.h>
33
34#include <zone.h>
35#include <wx/dataview.h>
37
39{
41 m_FillMode = ZONE_FILL_MODE::POLYGONS; // Mode for filling zone
42 // Zone clearance value
44 // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
46 // Arbitrary defaults for the hatch settings
47 m_HatchThickness = std::max( m_ZoneMinThickness * 4, pcbIUScale.mmToIU( 1.0 ) );
48 m_HatchGap = std::max( m_ZoneMinThickness * 6, pcbIUScale.mmToIU( 1.5 ) );
49 m_HatchOrientation = ANGLE_0; // Grid style: orientation of grid lines
50 m_HatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
51 m_HatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
52 m_HatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
53 m_HatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
54 m_NetcodeSelection = 0; // Net code selection for the current zone
56 // outlines only, short
57 // hatches or full hatches
59
60 m_Layers.reset().set( F_Cu );
61 m_Name = wxEmptyString;
62
63 // thickness of the gap in thermal reliefs:
65 // thickness of the copper bridge in thermal reliefs:
67
68 m_padConnection = ZONE_CONNECTION::THERMAL; // How pads are covered by copper in zone
69
70 m_Locked = false;
71
74
77
78 SetIsRuleArea( false );
80 SetDoNotAllowVias( true );
81 SetDoNotAllowTracks( true );
82 SetDoNotAllowPads( true );
84
86}
87
88
90{
92 m_FillMode = aSource.GetFillMode();
96 m_HatchGap = aSource.GetHatchGap();
102 m_NetcodeSelection = aSource.GetNetCode();
103 m_Name = aSource.GetZoneName();
111 m_isRuleArea = aSource.GetIsRuleArea();
117 m_Locked = aSource.IsLocked();
120
121 // Currently, the teardrop area type is not really a ZONE_SETTINGS parameter,
122 // but a ZONE parameter only.
123 // However it can be used in dialogs
125
126 m_Layers = aSource.GetLayerSet();
127
128 return *this;
129}
130
131
132void ZONE_SETTINGS::ExportSetting( ZONE& aTarget, bool aFullExport ) const
133{
134 aTarget.SetFillMode( m_FillMode );
138 aTarget.SetHatchGap( m_HatchGap );
149 aTarget.SetIsRuleArea( GetIsRuleArea() );
155 aTarget.SetLocked( m_Locked );
158 // Currently, the teardrop area type is not imported from a ZONE_SETTINGS, because
159 // it is not really a ZONE_SETTINGS parameter, but a ZONE parameter only
160#if 0
162#endif
163
164
165 if( aFullExport )
166 {
168 aTarget.SetLayerSet( m_Layers );
169 aTarget.SetZoneName( m_Name );
170
171 if( !m_isRuleArea )
173 }
174
175 // call SetBorderDisplayStyle last, because hatch lines will be rebuilt,
176 // using new parameters values
178 m_BorderHatchPitch, true );
179}
180
181
183{
184 if( aRadius < 0 )
185 m_cornerRadius = 0;
186 else
187 m_cornerRadius = aRadius;
188}
189
190
191#ifdef __WXOSX_MAC__
192const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
193#else
194const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
195#endif
196
197const static wxSize CHECKERBOARD_SIZE( 8, 8 );
198
199
200// A helper for setting up a dialog list for specifying zone layers. Used by all three
201// zone settings dialogs.
202void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
203 LSET aLayers, bool aFpEditorMode )
204{
205 BOARD* board = aFrame->GetBoard();
206 COLOR4D backgroundColor = aFrame->GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
207
208 // In the Footprint Editor In1_Cu is used as a proxy for "all inner layers"
209 if( aFpEditorMode )
210 aLayers.set( In1_Cu );
211
212 wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
213 wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
214 wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
215 layerIDColumn->SetHidden( true );
216
217 int textWidth = 0;
218
219 for( LSEQ layer = aLayers.UIOrder(); layer; ++layer )
220 {
221 PCB_LAYER_ID layerID = *layer;
222 wxString layerName = board->GetLayerName( layerID );
223
224 if( aFpEditorMode && layerID == In1_Cu )
225 layerName = _( "Inner layers" );
226
227 // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
228 textWidth = std::max( textWidth, KIUI::GetTextSize( layerName, aList ).x );
229
230 COLOR4D layerColor = aFrame->GetColorSettings()->GetColor( layerID );
231 auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE,
232 CHECKERBOARD_SIZE, aList->GetBackgroundColour() );
233 wxIcon icon;
234 icon.CopyFromBitmap( bitmap );
235
236 wxVector<wxVariant> row;
237 row.push_back( wxVariant( m_Layers.test( layerID ) ) );
238 row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
239 row.push_back( wxVariant( wxString::Format( wxT( "%i" ), layerID ) ) );
240 aList->AppendItem( row );
241
242 if( m_Layers.test( layerID ) )
243 aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
244 }
245
246 int checkColSize = 22;
247 int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
248
249#ifdef __WXMAC__
250 // TODO: something in wxWidgets 3.1.x pads checkbox columns with extra space. (It used to
251 // also be that the width of the column would get set too wide (to 30), but that's patched in
252 // our local wxWidgets fork.)
253 int checkColMargins = 40;
254#else
255 int checkColMargins = 0;
256#endif
257
258 // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
259 // for the tree expanders... but you'd be wrong. Force indent to 0.
260 aList->SetIndent( 0 );
261 aList->SetMinClientSize( wxSize( checkColSize + checkColMargins + layerColSize,
262 aList->GetMinClientSize().y ) );
263
264 checkColumn->SetWidth( checkColSize );
265 layerColumn->SetWidth( layerColSize );
266}
267
268
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void SetLocked(bool aLocked)
Definition: board_item.h:266
virtual bool IsLocked() const
Definition: board_item.cpp:71
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:269
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:474
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:102
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:493
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:532
LSEQ UIOrder() const
Definition: lset.cpp:922
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:70
bool m_keepoutDoNotAllowPads
void SetIsRuleArea(bool aEnable)
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
const bool GetDoNotAllowCopperPour() const
unsigned int m_cornerRadius
EDA_ANGLE m_HatchOrientation
Definition: zone_settings.h:88
int m_HatchBorderAlgorithm
Definition: zone_settings.h:93
void SetDoNotAllowVias(bool aEnable)
const bool GetDoNotAllowFootprints() const
int m_NetcodeSelection
Definition: zone_settings.h:95
long long int m_minIslandArea
bool m_keepoutDoNotAllowTracks
const bool GetDoNotAllowVias() const
double m_HatchSmoothingValue
Definition: zone_settings.h:91
const bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
int m_cornerSmoothingType
void SetDoNotAllowTracks(bool aEnable)
bool m_keepoutDoNotAllowCopperPour
ISLAND_REMOVAL_MODE m_removeIslands
double m_HatchHoleMinArea
Definition: zone_settings.h:92
const bool GetDoNotAllowTracks() const
int m_ZoneMinThickness
Definition: zone_settings.h:85
long long int GetMinIslandArea() const
long m_ThermalReliefSpokeWidth
TEARDROP_TYPE m_TeardropType
unsigned m_ZonePriority
Definition: zone_settings.h:81
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:97
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:83
ZONE_CONNECTION m_padConnection
long m_ThermalReliefGap
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowPads(bool aEnable)
const bool GetDoNotAllowPads() const
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:89
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:57
void SetHatchThickness(int aThickness)
Definition: zone.h:267
void SetHatchBorderAlgorithm(int aAlgo)
Definition: zone.h:285
void SetDoNotAllowPads(bool aEnable)
Definition: zone.h:714
int GetHatchBorderAlgorithm() const
Definition: zone.h:284
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:703
bool GetDoNotAllowVias() const
Definition: zone.h:705
void SetCornerRadius(unsigned int aRadius)
Definition: zone.cpp:381
void SetCornerSmoothingType(int aType)
Definition: zone.h:652
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:717
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuilBorderdHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:826
bool GetDoNotAllowPads() const
Definition: zone.h:707
void SetMinThickness(int aMinThickness)
Definition: zone.h:252
bool GetDoNotAllowTracks() const
Definition: zone.h:706
void SetHatchOrientation(const EDA_ANGLE &aStep)
Definition: zone.h:273
void SetHatchSmoothingValue(double aValue)
Definition: zone.h:279
void SetHatchSmoothingLevel(int aLevel)
Definition: zone.h:276
void SetDoNotAllowCopperPour(bool aEnable)
Definition: zone.h:711
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition: zone.h:187
long long int GetMinIslandArea() const
Definition: zone.h:720
void SetIsRuleArea(bool aEnable)
Definition: zone.h:710
wxString GetZoneName() const
Definition: zone.h:124
void SetDoNotAllowTracks(bool aEnable)
Definition: zone.h:713
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: zone.cpp:476
int GetMinThickness() const
Definition: zone.h:251
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: zone.h:173
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:248
int GetHatchThickness() const
Definition: zone.h:266
double GetHatchHoleMinArea() const
Definition: zone.h:281
void SetDoNotAllowVias(bool aEnable)
Definition: zone.h:712
int GetThermalReliefSpokeWidth() const
Definition: zone.h:195
int GetBorderHatchPitch() const
HatchBorder related methods.
Definition: zone.cpp:820
void SetLocalClearance(int aClearance)
Definition: zone.h:153
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: zone.h:586
void SetThermalReliefGap(int aThermalReliefGap)
Definition: zone.h:176
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:272
void SetLayerSet(LSET aLayerSet) override
Definition: zone.cpp:272
bool GetDoNotAllowFootprints() const
Definition: zone.h:708
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:174
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:715
bool GetDoNotAllowCopperPour() const
Definition: zone.h:704
int GetHatchGap() const
Definition: zone.h:269
void SetHatchHoleMinArea(double aPct)
Definition: zone.h:282
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:698
double GetHatchSmoothingValue() const
Definition: zone.h:278
int GetHatchSmoothingLevel() const
Definition: zone.h:275
unsigned int GetCornerRadius() const
Definition: zone.h:658
int GetCornerSmoothingType() const
Definition: zone.h:654
void SetAssignedPriority(unsigned aPriority)
Definition: zone.h:107
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: zone.h:249
void SetZoneName(const wxString &aName)
Definition: zone.h:125
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:693
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition: zone.h:718
void SetMinIslandArea(long long int aArea)
Definition: zone.h:721
int GetThermalReliefGap() const
Definition: zone.h:184
void SetHatchGap(int aStep)
Definition: zone.h:270
unsigned GetAssignedPriority() const
Definition: zone.h:112
#define _(s)
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:429
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ In1_Cu
Definition: layer_ids.h:65
@ F_Cu
Definition: layer_ids.h:64
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:70
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const double IU_PER_MM
Definition: base_units.h:77
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
static const wxSize CHECKERBOARD_SIZE(8, 8)
static const wxSize LAYER_BITMAP_SIZE(24, 16)
#define ZONE_THERMAL_RELIEF_GAP_MM
Definition: zones.h:33
@ THERMAL
Use thermal relief for pads.
#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