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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
9  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
10  * Copyright (C) 1992-2017 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 <fctsys.h>
31 
32 #include <convert_to_biu.h>
33 #include <pcbnew.h>
34 #include <pcb_base_frame.h>
35 #include <class_board.h>
36 #include <zones.h>
37 
38 #include <class_zone.h>
39 #include <wx/dataview.h>
40 #include <widgets/color_swatch.h>
41 
43 {
44  m_ZonePriority = 0;
45  m_FillMode = ZFM_POLYGONS; // Mode for filling zone : 1 use segments, 0 use polygons
46  // Zone clearance value
48  // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
50  m_NetcodeSelection = 0; // Net code selection for the current zone
51  m_CurrentZone_Layer = F_Cu; // Layer used to create the current zone
52  m_Zone_HatchingStyle = ZONE_CONTAINER::DIAGONAL_EDGE; // Option to show the zone area (outlines only, short hatches or full hatches
53 
54  m_ArcToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF; // Option to select number of segments to approximate a circle
55  // ARC_APPROX_SEGMENTS_COUNT_LOW_DEF
56  // or ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF segments
57 
58  // thickness of the gap in thermal reliefs:
60  // thickness of the copper bridge in thermal reliefs:
62 
63  m_PadConnection = PAD_ZONE_CONN_THERMAL; // How pads are covered by copper in zone
64 
65  m_Zone_45_Only = false;
66 
68  m_cornerRadius = 0;
69 
70  SetIsKeepout( false );
71  SetDoNotAllowCopperPour( false );
72  SetDoNotAllowVias( true );
73  SetDoNotAllowTracks( true );
74 }
75 
76 
78 {
79  m_ZonePriority = aSource.GetPriority();
80  m_FillMode = aSource.GetFillMode();
83  m_NetcodeSelection = aSource.GetNetCode();
90  m_cornerRadius = aSource.GetCornerRadius();
91  m_isKeepout = aSource.GetIsKeepout();
95  m_Zone_45_Only = aSource.GetHV45();
96 
97  m_CurrentZone_Layer = aSource.GetLayer();
98  m_Layers = aSource.GetLayerSet();
99 
100  return *this;
101 }
102 
103 
104 void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) const
105 {
106  aTarget.SetFillMode( m_FillMode );
114  aTarget.SetCornerRadius( m_cornerRadius );
115  aTarget.SetIsKeepout( GetIsKeepout() );
119  aTarget.SetHV45( m_Zone_45_Only );
120 
121  if( aFullExport )
122  {
123  aTarget.SetPriority( m_ZonePriority );
124  aTarget.SetNetCode( m_NetcodeSelection );
125 
126  // Keepout zones can have multiple layers
127  if( m_isKeepout )
128  {
129  aTarget.SetLayerSet( m_Layers );
130  }
131  else
132  {
133  aTarget.SetLayer( m_CurrentZone_Layer );
134  }
135  }
136 
137  // call SetHatch last, because hatch lines will be rebuilt,
138  // using new parameters values
139  aTarget.SetHatch( m_Zone_HatchingStyle, aTarget.GetDefaultHatchPitch(), true );
140 }
141 
142 
144 {
145  if( aRadius < 0 )
146  m_cornerRadius = 0;
147  else
148  m_cornerRadius = aRadius;
149 }
150 
151 
152 #ifdef __WXOSX_MAC__
153 const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
154 #else
155 const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
156 #endif
157 
158 // A helper for setting up a dialog list for specifying zone layers. Used by all three
159 // zone settings dialogs.
160 void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
161  bool aShowCopper )
162 {
163  BOARD* board = aFrame->GetBoard();
164  COLOR4D backgroundColor = aFrame->Settings().Colors().GetLayerColor( LAYER_PCB_BACKGROUND );
165  LSET layers = aShowCopper ? LSET::AllCuMask( board->GetCopperLayerCount() )
166  : LSET::AllNonCuMask();
167 
168  wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
169  wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
170  wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
171  layerIDColumn->SetHidden( true );
172 
173  int textWidth = 0;
174 
175  for( LSEQ layer = layers.UIOrder(); layer; ++layer )
176  {
177  PCB_LAYER_ID layerID = *layer;
178  wxString layerName = board->GetLayerName( layerID );
179 
180  // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
181  textWidth = std::max( textWidth, GetTextSize( layerName, aList ).x );
182 
183  COLOR4D layerColor = aFrame->Settings().Colors().GetLayerColor( layerID );
184  auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE );
185  wxIcon icon;
186  icon.CopyFromBitmap( bitmap );
187 
188  wxVector<wxVariant> row;
189  row.push_back( wxVariant( m_Layers.test( layerID ) ) );
190  row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
191  row.push_back( wxVariant( wxString::Format( "%i", layerID ) ) );
192  aList->AppendItem( row );
193 
194  if( m_CurrentZone_Layer == layerID )
195  aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
196  }
197 
198  int checkColSize = 22;
199  int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
200 
201  // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
202  // for the tree expanders... but you'd be wrong. Force indent to 0.
203  aList->SetIndent( 0 );
204  aList->SetMinClientSize( wxSize( checkColSize + layerColSize, aList->GetMinClientSize().y ) );
205 
206  checkColumn->SetWidth( checkColSize );
207  layerColumn->SetWidth( layerColSize );
208 }
209 
210 
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:631
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:673
int m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:72
void SetCornerSmoothingType(int aType)
Definition: class_zone.h:589
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
int m_ArcToSegmentsCount
Option to select number of segments to approximate a circle 16 or 32 segments.
Definition: zone_settings.h:75
const bool GetDoNotAllowTracks() const
int GetMinThickness() const
Definition: class_zone.h:204
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:624
int GetArcSegmentCount() const
Definition: class_zone.h:193
void SetCornerRadius(unsigned int aRadius)
Definition: class_zone.cpp:646
#define ARC_APPROX_SEGMENTS_COUNT_LOW_DEF
Definition: pcbnew.h:41
long m_ThermalReliefCopperBridge
thickness of the copper bridge in thermal reliefs
Definition: zone_settings.h:78
Class BOARD to handle a board.
const bool GetDoNotAllowCopperPour() const
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:696
int GetCopperLayerCount() const
Function GetCopperLayerCount.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
BOARD * GetBoard() const
Classes to handle copper zones.
int GetCornerSmoothingType() const
Definition: class_zone.h:591
void SetArcSegmentCount(int aArcSegCount)
Definition: class_zone.h:192
void SetHatch(int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL
Definition: zones.h:39
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:637
unsigned int GetCornerRadius() const
Definition: class_zone.h:595
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:630
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:111
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 ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:101
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:623
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:230
void SetDoNotAllowVias(bool aEnable)
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:65
ZoneConnection m_PadConnection
Definition: zone_settings.h:85
void SetLayerSet(LSET aLayerSet)
Definition: class_zone.cpp:210
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
ZoneConnection GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:995
int m_cornerSmoothingType
Corner smoothing type.
Definition: zone_settings.h:83
const bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
PCB_GENERAL_SETTINGS & Settings()
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:628
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
int m_ZonePriority
Priority (0 ... N) of the zone.
Definition: zone_settings.h:61
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:181
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:202
#define ZONE_CLEARANCE_MIL
Definition: zones.h:42
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:63
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize)
Make a simple color swatch bitmap.
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetIsKeepout(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
void SetZoneClearance(int aZoneClearance)
Definition: class_zone.h:199
#define ZONE_THICKNESS_MIL
Definition: zones.h:40
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
COLORS_DESIGN_SETTINGS & Colors()
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:186
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:48
int GetNetCode() const
Function GetNetCode.
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:629
ZONE_SETTINGS()
class ZONE_SETTINGS used to handle zones parameters
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:59
bool GetDoNotAllowTracks() const
Definition: class_zone.h:626
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: class_zone.h:180
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
bool GetDoNotAllowVias() const
Definition: class_zone.h:625
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
bool m_keepoutDoNotAllowCopperPour
Definition: zone_settings.h:95
void SetCornerRadius(int aRadius)
void SetHV45(bool aConstrain)
Definition: class_zone.h:683
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:519
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
bool GetHV45() const
Definition: class_zone.h:682
const bool GetDoNotAllowVias() const
void SetDoNotAllowCopperPour(bool aEnable)
#define ZONE_THERMAL_RELIEF_GAP_MIL
Definition: zones.h:38
bool m_keepoutDoNotAllowTracks
Definition: zone_settings.h:97
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:628
void SetPadConnection(ZoneConnection aPadConnection)
Definition: class_zone.h:202
static const wxSize LAYER_BITMAP_SIZE(24, 16)
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:107
unsigned int m_cornerRadius
Corner chamfer distance / fillet radius.
Definition: zone_settings.h:84
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:205
ZONE_SETTINGS & operator<<(const ZONE_CONTAINER &aSource)
operator << ( const ZONE_CONTAINER& ) was Function ImportSetting copies settings from a given zone in...
Use thermal relief for pads.
Definition: zones.h:53
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:183
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:69
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
int GetZoneClearance() const
Definition: class_zone.h:198
long m_ThermalReliefGap
thickness of the gap in thermal reliefs
Definition: zone_settings.h:77
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:64
bool m_keepoutDoNotAllowVias
Definition: zone_settings.h:96
LSEQ UIOrder() const
Definition: lset.cpp:800
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39