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 <fctsys.h>
33 
34 #include <convert_to_biu.h>
35 #include <pcbnew.h>
36 #include <pcb_base_frame.h>
37 #include <class_board.h>
38 #include <zones.h>
39 
40 #include <class_zone.h>
41 #include <wx/dataview.h>
42 #include <widgets/color_swatch.h>
43 
45 {
46  m_ZonePriority = 0;
47  m_FillMode = ZFM_POLYGONS; // Mode for filling zone : 1 use segments, 0 use polygons
48  // Zone clearance value
50  // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
52  m_HatchFillTypeThickness = 0; // good value of grid line thickness if m_FillMode = ZFM_GRID_PATTERN
53  m_HatchFillTypeGap = 0; // good value of grid line gap if m_FillMode = ZFM_GRID_PATTERN
54  m_HatchFillTypeOrientation = 0.0; // Grid style: orientation of grid lines in degrees
55  m_HatchFillTypeSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
56  m_HatchFillTypeSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
57  m_NetcodeSelection = 0; // Net code selection for the current zone
58  m_CurrentZone_Layer = F_Cu; // Layer used to create the current zone
59  m_Zone_HatchingStyle = ZONE_CONTAINER::DIAGONAL_EDGE; // Option to show the zone area (outlines only,
60  //short hatches or full hatches
61 
62  // thickness of the gap in thermal reliefs:
64  // thickness of the copper bridge in thermal reliefs:
66 
67  m_PadConnection = PAD_ZONE_CONN_THERMAL; // How pads are covered by copper in zone
68 
69  m_Zone_45_Only = false;
70 
72  m_cornerRadius = 0;
73 
74  SetIsKeepout( false );
75  SetDoNotAllowCopperPour( false );
76  SetDoNotAllowVias( true );
77  SetDoNotAllowTracks( true );
78 }
79 
80 
82 {
83  m_ZonePriority = aSource.GetPriority();
84  m_FillMode = aSource.GetFillMode();
92  m_NetcodeSelection = aSource.GetNetCode();
98  m_cornerRadius = aSource.GetCornerRadius();
99  m_isKeepout = aSource.GetIsKeepout();
103  m_Zone_45_Only = aSource.GetHV45();
104 
105  m_CurrentZone_Layer = aSource.GetLayer();
106  m_Layers = aSource.GetLayerSet();
107 
108  return *this;
109 }
110 
111 
112 void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) const
113 {
114  aTarget.SetFillMode( m_FillMode );
126  aTarget.SetCornerRadius( m_cornerRadius );
127  aTarget.SetIsKeepout( GetIsKeepout() );
131  aTarget.SetHV45( m_Zone_45_Only );
132 
133  if( aFullExport )
134  {
135  aTarget.SetPriority( m_ZonePriority );
136  aTarget.SetNetCode( m_NetcodeSelection );
137 
138  // Keepout zones can have multiple layers
139  if( m_isKeepout )
140  {
141  aTarget.SetLayerSet( m_Layers );
142  }
143  else
144  {
145  aTarget.SetLayer( m_CurrentZone_Layer );
146  }
147  }
148 
149  // call SetHatch last, because hatch lines will be rebuilt,
150  // using new parameters values
151  aTarget.SetHatch( m_Zone_HatchingStyle, aTarget.GetDefaultHatchPitch(), true );
152 }
153 
154 
156 {
157  if( aRadius < 0 )
158  m_cornerRadius = 0;
159  else
160  m_cornerRadius = aRadius;
161 }
162 
163 
164 #ifdef __WXOSX_MAC__
165 const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
166 #else
167 const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
168 #endif
169 
170 // A helper for setting up a dialog list for specifying zone layers. Used by all three
171 // zone settings dialogs.
172 void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
173  bool aShowCopper )
174 {
175  BOARD* board = aFrame->GetBoard();
176  COLOR4D backgroundColor = aFrame->Settings().Colors().GetLayerColor( LAYER_PCB_BACKGROUND );
177  LSET layers = aShowCopper ? LSET::AllCuMask( board->GetCopperLayerCount() )
178  : LSET::AllNonCuMask();
179 
180  wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
181  wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
182  wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
183  layerIDColumn->SetHidden( true );
184 
185  int textWidth = 0;
186 
187  for( LSEQ layer = layers.UIOrder(); layer; ++layer )
188  {
189  PCB_LAYER_ID layerID = *layer;
190  wxString layerName = board->GetLayerName( layerID );
191 
192  // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
193  textWidth = std::max( textWidth, GetTextSize( layerName, aList ).x );
194 
195  COLOR4D layerColor = aFrame->Settings().Colors().GetLayerColor( layerID );
196  auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE );
197  wxIcon icon;
198  icon.CopyFromBitmap( bitmap );
199 
200  wxVector<wxVariant> row;
201  row.push_back( wxVariant( m_Layers.test( layerID ) ) );
202  row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
203  row.push_back( wxVariant( wxString::Format( "%i", layerID ) ) );
204  aList->AppendItem( row );
205 
206  if( m_CurrentZone_Layer == layerID )
207  aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
208  }
209 
210  int checkColSize = 22;
211  int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
212 
213  // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
214  // for the tree expanders... but you'd be wrong. Force indent to 0.
215  aList->SetIndent( 0 );
216  aList->SetMinClientSize( wxSize( checkColSize + layerColSize, aList->GetMinClientSize().y ) );
217 
218  checkColumn->SetWidth( checkColSize );
219  layerColumn->SetWidth( layerColSize );
220 }
221 
222 
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:629
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:81
void SetCornerSmoothingType(int aType)
Definition: class_zone.h:581
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
void SetHatchFillTypeSmoothingLevel(int aLevel)
Definition: class_zone.h:195
int GetNetCode() const
Function GetNetCode.
void SetHatchFillTypeSmoothingValue(double aValue)
Definition: class_zone.h:198
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:511
void SetCornerRadius(unsigned int aRadius)
Definition: class_zone.cpp:520
int GetHatchFillTypeThickness() const
Definition: class_zone.h:185
long m_ThermalReliefCopperBridge
thickness of the copper bridge in thermal reliefs
Definition: zone_settings.h:84
int m_HatchFillTypeSmoothingLevel
Grid pattern smoothing type, similar to corner smoothing type.
Definition: zone_settings.h:69
double m_HatchFillTypeOrientation
Grid style shape: orientation of grid lines in degrees.
Definition: zone_settings.h:68
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:699
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:190
int m_HatchFillTypeGap
Grid style shape: clearance between lines (0 -> solid shape)
Definition: zone_settings.h:67
double GetHatchFillTypeOrientation() const
Definition: class_zone.h:191
double GetHatchFillTypeSmoothingValue() const
Definition: class_zone.h:197
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:955
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL
Definition: zones.h:39
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:502
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:628
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: common.cpp:115
bool GetDoNotAllowVias() const
Definition: class_zone.h:623
Classes used in Pcbnew, CvPcb and GerbView.
void SetupLayersList(wxDataViewListCtrl *aList, PCB_BASE_FRAME *aFrame, bool aShowCopper)
A helper routine for the various zone dialogs (copper, non-copper, keepout).
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:88
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_zone.cpp:246
void SetDoNotAllowVias(bool aEnable)
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:74
ZoneConnection m_PadConnection
Definition: zone_settings.h:91
void SetLayerSet(LSET aLayerSet)
Definition: class_zone.cpp:225
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
PCB_LAYER_ID
A quick note on layer IDs:
void SetHatchFillTypeGap(int aStep)
Definition: class_zone.h:189
Class LSET is a set of PCB_LAYER_IDs.
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:510
unsigned int GetCornerRadius() const
Definition: class_zone.h:587
int m_cornerSmoothingType
Corner smoothing type.
Definition: zone_settings.h:89
PCB_GENERAL_SETTINGS & Settings()
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:150
int m_ZonePriority
Priority (0 ... N) of the zone.
Definition: zone_settings.h:62
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:622
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:217
#define ZONE_CLEARANCE_MIL
Definition: zones.h:42
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:64
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize)
Make a simple color swatch bitmap.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
void SetIsKeepout(bool aEnable)
const bool GetDoNotAllowVias() const
const bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
void SetDoNotAllowTracks(bool aEnable)
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:171
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
#define ZONE_THICKNESS_MIL
Definition: zones.h:40
int GetCornerSmoothingType() const
Definition: class_zone.h:583
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
const bool GetDoNotAllowTracks() const
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:621
COLORS_DESIGN_SETTINGS & Colors()
bool GetHV45() const
Definition: class_zone.h:680
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:155
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:49
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:627
ZONE_SETTINGS()
class ZONE_SETTINGS used to handle zones parameters
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:60
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: class_zone.h:149
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:94
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
ZoneConnection GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:864
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
bool m_keepoutDoNotAllowCopperPour
void SetHatchFillTypeOrientation(double aStep)
Definition: class_zone.h:192
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SetCornerRadius(int aRadius)
const bool GetDoNotAllowCopperPour() const
void SetHV45(bool aConstrain)
Definition: class_zone.h:681
double m_HatchFillTypeSmoothingValue
Grid pattern chamfer distance/fillet value.
Definition: zone_settings.h:71
int GetMinThickness() const
Definition: class_zone.h:176
bool GetDoNotAllowTracks() const
Definition: class_zone.h:624
void SetHatchFillTypeThickness(int aThickness)
Definition: class_zone.h:186
int GetHatchFillTypeSmoothingLevel() const
Definition: class_zone.h:194
void SetDoNotAllowCopperPour(bool aEnable)
#define ZONE_THERMAL_RELIEF_GAP_MIL
Definition: zones.h:38
BOARD * GetBoard() const
bool m_keepoutDoNotAllowTracks
int GetZoneClearance() const
Definition: class_zone.h:170
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:626
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:174
static const wxSize LAYER_BITMAP_SIZE(24, 16)
unsigned int m_cornerRadius
Corner chamfer distance / fillet radius.
Definition: zone_settings.h:90
LSEQ UIOrder() const
Definition: lset.cpp:803
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:177
int m_HatchFillTypeThickness
Grid style shape: thickness of lines (if 0 -> solid shape)
Definition: zone_settings.h:66
ZONE_SETTINGS & operator<<(const ZONE_CONTAINER &aSource)
operator << ( const ZONE_CONTAINER& ) was Function ImportSetting copies settings from a given zone in...
int GetHatchFillTypeGap() const
Definition: class_zone.h:188
Use thermal relief for pads.
Definition: zones.h:53
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:152
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:78
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
long m_ThermalReliefGap
thickness of the gap in thermal reliefs
Definition: zone_settings.h:83
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:65
bool m_keepoutDoNotAllowVias
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39