KiCad PCB EDA Suite
zone_settings.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
9  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
10  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <zone_settings.h>
31 
32 #include <convert_to_biu.h>
33 #include <pcbnew.h>
34 #include <pcb_base_frame.h>
35 #include <board.h>
37 #include <zones.h>
38 
39 #include <zone.h>
40 #include <wx/dataview.h>
41 #include <widgets/color_swatch.h>
42 
44 {
45  m_ZonePriority = 0;
46  m_FillMode = ZONE_FILL_MODE::POLYGONS; // Mode for filling zone
47  // Zone clearance value
49  // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
51  m_HatchThickness = 0; // good value of grid line thickness if m_FillMode = ZFM_GRID_PATTERN
52  m_HatchGap = 0; // good value of grid line gap if m_FillMode = ZFM_GRID_PATTERN
53  m_HatchOrientation = 0.0; // Grid style: orientation of grid lines in degrees
54  m_HatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
55  m_HatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
56  m_HatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
57  m_HatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
58  m_NetcodeSelection = 0; // Net code selection for the current zone
60  // outlines only, short
61  // hatches or full hatches
62 
63  m_Layers.reset().set( F_Cu );
64  m_Name = wxEmptyString;
65 
66  // thickness of the gap in thermal reliefs:
68  // thickness of the copper bridge in thermal reliefs:
70 
71  m_padConnection = ZONE_CONNECTION::THERMAL; // How pads are covered by copper in zone
72 
73  m_Zone_45_Only = false;
74  m_Locked = false;
75 
77  m_cornerRadius = 0;
78 
80  m_minIslandArea = 0;
81 
82  SetIsRuleArea( false );
83  SetDoNotAllowCopperPour( false );
84  SetDoNotAllowVias( true );
85  SetDoNotAllowTracks( true );
86  SetDoNotAllowPads( true );
87  SetDoNotAllowFootprints( false );
88 }
89 
90 
92 {
93  m_ZonePriority = aSource.GetPriority();
94  m_FillMode = aSource.GetFillMode();
98  m_HatchGap = aSource.GetHatchGap();
104  m_NetcodeSelection = aSource.GetNetCode();
105  m_Name = aSource.GetZoneName();
109  m_padConnection = aSource.GetPadConnection();
111  m_cornerRadius = aSource.GetCornerRadius();
112  m_isRuleArea = aSource.GetIsRuleArea();
118  m_Zone_45_Only = aSource.GetHV45();
119  m_Locked = aSource.IsLocked();
121  m_minIslandArea = aSource.GetMinIslandArea();
122 
123  m_Layers = aSource.GetLayerSet();
124 
125  return *this;
126 }
127 
128 
129 void ZONE_SETTINGS::ExportSetting( ZONE& aTarget, bool aFullExport ) const
130 {
131  aTarget.SetFillMode( m_FillMode );
135  aTarget.SetHatchGap( m_HatchGap );
145  aTarget.SetCornerRadius( m_cornerRadius );
146  aTarget.SetIsRuleArea( GetIsRuleArea() );
152  aTarget.SetHV45( m_Zone_45_Only );
153  aTarget.SetLocked( m_Locked );
155  aTarget.SetMinIslandArea( GetMinIslandArea() );
156 
157  if( aFullExport )
158  {
159  aTarget.SetPriority( m_ZonePriority );
160  aTarget.SetLayerSet( m_Layers );
161  aTarget.SetZoneName( m_Name );
162 
163  if( !m_isRuleArea )
164  aTarget.SetNetCode( m_NetcodeSelection );
165  }
166 
167  // call SetBorderDisplayStyle last, because hatch lines will be rebuilt,
168  // using new parameters values
170  true );
171 }
172 
173 
175 {
176  if( aRadius < 0 )
177  m_cornerRadius = 0;
178  else
179  m_cornerRadius = aRadius;
180 }
181 
182 
183 #ifdef __WXOSX_MAC__
184 const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
185 #else
186 const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
187 #endif
188 
189 const static wxSize CHECKERBOARD_SIZE( 8, 8 );
190 
191 
192 // A helper for setting up a dialog list for specifying zone layers. Used by all three
193 // zone settings dialogs.
194 void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
195  bool aShowCopper, bool aFpEditorMode )
196 {
197  BOARD* board = aFrame->GetBoard();
198  COLOR4D backgroundColor = aFrame->GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
199  LSET layers = aShowCopper ? LSET::AllCuMask( board->GetCopperLayerCount() )
200  : LSET::AllNonCuMask();
201 
202  // In the Footprint Editor In1_Cu is used as a proxy for "all inner layers"
203  if( aFpEditorMode )
204  layers.set( In1_Cu );
205 
206  wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
207  wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
208  wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
209  layerIDColumn->SetHidden( true );
210 
211  int textWidth = 0;
212 
213  for( LSEQ layer = layers.UIOrder(); layer; ++layer )
214  {
215  PCB_LAYER_ID layerID = *layer;
216  wxString layerName = board->GetLayerName( layerID );
217 
218  if( aFpEditorMode && layerID == In1_Cu )
219  layerName = _( "Inner layers" );
220 
221  // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
222  textWidth = std::max( textWidth, KIUI::GetTextSize( layerName, aList ).x );
223 
224  COLOR4D layerColor = aFrame->GetColorSettings()->GetColor( layerID );
225  auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE,
226  CHECKERBOARD_SIZE, aList->GetBackgroundColour() );
227  wxIcon icon;
228  icon.CopyFromBitmap( bitmap );
229 
230  wxVector<wxVariant> row;
231  row.push_back( wxVariant( m_Layers.test( layerID ) ) );
232  row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
233  row.push_back( wxVariant( wxString::Format( "%i", layerID ) ) );
234  aList->AppendItem( row );
235 
236  if( m_Layers.test( layerID ) )
237  aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
238  }
239 
240  int checkColSize = 22;
241  int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
242 
243  // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
244  // for the tree expanders... but you'd be wrong. Force indent to 0.
245  aList->SetIndent( 0 );
246  aList->SetMinClientSize( wxSize( checkColSize + layerColSize, aList->GetMinClientSize().y ) );
247 
248  checkColumn->SetWidth( checkColSize );
249  layerColumn->SetWidth( layerColSize );
250 }
251 
252 
int m_HatchSmoothingLevel
Definition: zone_settings.h:87
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
int GetHatchGap() const
Definition: zone.h:256
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition: zone.h:750
void SetCornerRadius(unsigned int aRadius)
Definition: zone.cpp:361
void SetHatchThickness(int aThickness)
Definition: zone.h:254
void SetZoneName(const wxString &aName)
Definition: zone.h:130
bool GetDoNotAllowFootprints() const
Definition: zone.h:738
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:361
void SetDoNotAllowTracks(bool aEnable)
Definition: zone.h:745
const bool GetDoNotAllowFootprints() const
int GetHatchThickness() const
Definition: zone.h:253
unsigned GetPriority() const
Definition: zone.h:122
const bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:733
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Set all hatch parameters for the zone.
Definition: zone.cpp:896
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
double m_HatchSmoothingValue
Definition: zone_settings.h:89
long long int GetMinIslandArea() const
ZONE_BORDER_DISPLAY_STYLE m_ZoneBorderDisplayStyle
Option to show the zone area (outlines only, short hatches or full hatches.
void SetLayerSet(LSET aLayerSet) override
Definition: zone.cpp:246
bool GetDoNotAllowVias() const
Definition: zone.h:735
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:773
double m_HatchHoleMinArea
Definition: zone_settings.h:90
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:291
double GetHatchSmoothingValue() const
Definition: zone.h:265
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
long long int m_minIslandArea
ISLAND_REMOVAL_MODE m_removeIslands
wxString m_Name
Definition: zone_settings.h:95
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL
Definition: zones.h:30
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:252
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
void SetHV45(bool aConstrain)
Definition: zone.h:803
virtual bool IsLocked() const
Definition: board_item.cpp:78
void SetPriority(unsigned aPriority)
Definition: zone.h:117
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: zone.h:180
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:181
ZONE_SETTINGS & operator<<(const ZONE &aSource)
operator << ( const ZONE& ) was Function ImportSetting copies settings from a given zone into this ob...
Classes used in Pcbnew, CvPcb and GerbView.
void SetIsRuleArea(bool aEnable)
Definition: zone.h:742
void SetDoNotAllowFootprints(bool aEnable)
int GetThermalReliefGap() const
Definition: zone.h:191
virtual COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
void SetDoNotAllowVias(bool aEnable)
int m_NetcodeSelection
Definition: zone_settings.h:93
double GetHatchHoleMinArea() const
Definition: zone.h:268
void SetHatchSmoothingValue(double aValue)
Definition: zone.h:266
bool GetDoNotAllowPads() const
Definition: zone.h:737
bool GetDoNotAllowCopperPour() const
Definition: zone.h:734
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:502
int GetMinThickness() const
Definition: zone.h:244
void SetHatchGap(int aStep)
Definition: zone.h:257
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:67
int m_cornerSmoothingType
int GetHatchSmoothingLevel() const
Definition: zone.h:262
static int GetDefaultHatchPitch()
Definition: zone.cpp:1088
void SetDoNotAllowPads(bool aEnable)
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
void SetDoNotAllowPads(bool aEnable)
Definition: zone.h:746
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: zone.cpp:494
void SetCornerSmoothingType(int aType)
Definition: zone.h:681
bool GetDoNotAllowTracks() const
Definition: zone.h:736
bool m_keepoutDoNotAllowPads
#define ZONE_CLEARANCE_MIL
Definition: zones.h:33
#define _(s)
void SetDoNotAllowVias(bool aEnable)
Definition: zone.h:744
const bool GetDoNotAllowVias() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
void SetMinThickness(int aMinThickness)
Definition: zone.h:245
void SetDoNotAllowTracks(bool aEnable)
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: zone.h:613
void SetHatchHoleMinArea(double aPct)
Definition: zone.h:269
void SetIsRuleArea(bool aEnable)
bool GetHV45() const
Definition: zone.h:802
#define ZONE_THICKNESS_MIL
Definition: zones.h:31
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:463
const bool GetDoNotAllowTracks() const
ZONE_CONNECTION m_padConnection
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
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
double GetHatchOrientation() const
Definition: zone.h:259
void SetHatchSmoothingLevel(int aLevel)
Definition: zone.h:263
Use thermal relief for pads.
unsigned int GetCornerRadius() const
Definition: zone.h:687
ZONE_SETTINGS()
class ZONE_SETTINGS used to handle zones parameters
const bool GetDoNotAllowPads() const
int m_HatchBorderAlgorithm
Definition: zone_settings.h:91
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:81
int GetHatchBorderAlgorithm() const
Definition: zone.h:271
COLOR4D GetColor(int aLayer) const
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:749
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: zone.h:242
void SetMinIslandArea(long long int aArea)
Definition: zone.h:754
long m_ThermalReliefSpokeWidth
void SetHatchBorderAlgorithm(int aAlgo)
Definition: zone.h:272
static const wxSize CHECKERBOARD_SIZE(8, 8)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetDoNotAllowCopperPour(bool aEnable)
Definition: zone.h:743
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
bool m_keepoutDoNotAllowCopperPour
Definition: layer_ids.h:70
int GetCopperLayerCount() const
Definition: board.cpp:454
void SetCornerRadius(int aRadius)
const bool GetDoNotAllowCopperPour() const
void SetHatchOrientation(double aStep)
Definition: zone.h:260
bool m_keepoutDoNotAllowFootprints
PCB background color.
Definition: layer_ids.h:215
void SetThermalReliefGap(int aThermalReliefGap)
Definition: zone.h:183
void SetDoNotAllowCopperPour(bool aEnable)
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, bool aShowCopper, bool aFpEditorMode=false)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
long long int GetMinIslandArea() const
Definition: zone.h:753
#define ZONE_THERMAL_RELIEF_GAP_MIL
Definition: zones.h:29
void SetLocalClearance(int aClearance)
Definition: zone.h:158
int GetThermalReliefSpokeWidth() const
Definition: zone.h:202
BOARD * GetBoard() const
bool m_keepoutDoNotAllowTracks
ZONE_CONNECTION GetPadConnection(PAD *aPad, wxString *aSource=nullptr) const
Definition: zone.cpp:774
static const wxSize LAYER_BITMAP_SIZE(24, 16)
unsigned int m_cornerRadius
wxString GetZoneName() const
Definition: zone.h:129
LSEQ UIOrder() const
Definition: lset.cpp:895
int GetCornerSmoothingType() const
Definition: zone.h:683
double m_HatchOrientation
Definition: zone_settings.h:86
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
long m_ThermalReliefGap
int m_ZoneMinThickness
Definition: zone_settings.h:83
bool m_keepoutDoNotAllowVias
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:747
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition: zone.h:194
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103