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>
39 #include <zones.h>
40 
41 #include <class_zone.h>
42 #include <wx/dataview.h>
43 #include <widgets/color_swatch.h>
44 
46 {
47  m_ZonePriority = 0;
48  m_FillMode = ZONE_FILL_MODE::POLYGONS; // Mode for filling zone
49  // Zone clearance value
51  // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
54  0; // good value of grid line thickness if m_FillMode = ZFM_GRID_PATTERN
55  m_HatchFillTypeGap = 0; // good value of grid line gap if m_FillMode = ZFM_GRID_PATTERN
56  m_HatchFillTypeOrientation = 0.0; // Grid style: orientation of grid lines in degrees
57  m_HatchFillTypeSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
58  m_HatchFillTypeSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
59  m_NetcodeSelection = 0; // Net code selection for the current zone
60  m_CurrentZone_Layer = F_Cu; // Layer used to create the current zone
62  ZONE_HATCH_STYLE::DIAGONAL_EDGE; // Option to show the zone area (outlines only,
63  //short hatches or full hatches
64 
65  // thickness of the gap in thermal reliefs:
67  // thickness of the copper bridge in thermal reliefs:
69 
70  m_PadConnection = ZONE_CONNECTION::THERMAL; // How pads are covered by copper in zone
71 
72  m_Zone_45_Only = false;
73 
75  m_cornerRadius = 0;
76 
77  SetIsKeepout( false );
78  SetDoNotAllowCopperPour( false );
79  SetDoNotAllowVias( true );
80  SetDoNotAllowTracks( true );
81 }
82 
83 
85 {
86  m_ZonePriority = aSource.GetPriority();
87  m_FillMode = aSource.GetFillMode();
95  m_NetcodeSelection = aSource.GetNetCode();
101  m_cornerRadius = aSource.GetCornerRadius();
102  m_isKeepout = aSource.GetIsKeepout();
106  m_Zone_45_Only = aSource.GetHV45();
107 
108  m_CurrentZone_Layer = aSource.GetLayer();
109  m_Layers = aSource.GetLayerSet();
110 
111  return *this;
112 }
113 
114 
115 void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) const
116 {
117  aTarget.SetFillMode( m_FillMode );
129  aTarget.SetCornerRadius( m_cornerRadius );
130  aTarget.SetIsKeepout( GetIsKeepout() );
134  aTarget.SetHV45( m_Zone_45_Only );
135 
136  if( aFullExport )
137  {
138  aTarget.SetPriority( m_ZonePriority );
139 
140  // Keepout zones can have multiple layers and have no net
141  if( m_isKeepout )
142  {
143  aTarget.SetLayerSet( m_Layers );
144  }
145  else
146  {
147  aTarget.SetNetCode( m_NetcodeSelection );
148  aTarget.SetLayer( m_CurrentZone_Layer );
149  }
150  }
151 
152  // call SetHatch last, because hatch lines will be rebuilt,
153  // using new parameters values
154  aTarget.SetHatch( m_Zone_HatchingStyle, aTarget.GetDefaultHatchPitch(), true );
155 }
156 
157 
159 {
160  if( aRadius < 0 )
161  m_cornerRadius = 0;
162  else
163  m_cornerRadius = aRadius;
164 }
165 
166 
167 #ifdef __WXOSX_MAC__
168 const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
169 #else
170 const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
171 #endif
172 
173 // A helper for setting up a dialog list for specifying zone layers. Used by all three
174 // zone settings dialogs.
175 void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
176  bool aShowCopper, bool aFpEditorMode )
177 {
178  BOARD* board = aFrame->GetBoard();
179  COLOR4D backgroundColor = aFrame->ColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
180  LSET layers = aShowCopper ? LSET::AllCuMask( board->GetCopperLayerCount() )
181  : LSET::AllNonCuMask();
182 
183  wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
184  wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
185  wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
186  layerIDColumn->SetHidden( true );
187 
188  int textWidth = 0;
189 
190  for( LSEQ layer = layers.UIOrder(); layer; ++layer )
191  {
192  PCB_LAYER_ID layerID = *layer;
193  wxString layerName = board->GetLayerName( layerID );
194  if( aFpEditorMode && layerID == In1_Cu )
195  layerName = _( "Inner layers" );
196 
197  // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
198  textWidth = std::max( textWidth, GetTextSize( layerName, aList ).x );
199 
200  COLOR4D layerColor = aFrame->ColorSettings()->GetColor( layerID );
201  auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE );
202  wxIcon icon;
203  icon.CopyFromBitmap( bitmap );
204 
205  wxVector<wxVariant> row;
206  row.push_back( wxVariant( m_Layers.test( layerID ) ) );
207  row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
208  row.push_back( wxVariant( wxString::Format( "%i", layerID ) ) );
209  aList->AppendItem( row );
210 
211  if( m_CurrentZone_Layer == layerID )
212  aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
213  }
214 
215  int checkColSize = 22;
216  int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
217 
218  // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
219  // for the tree expanders... but you'd be wrong. Force indent to 0.
220  aList->SetIndent( 0 );
221  aList->SetMinClientSize( wxSize( checkColSize + layerColSize, aList->GetMinClientSize().y ) );
222 
223  checkColumn->SetWidth( checkColSize );
224  layerColumn->SetWidth( layerColSize );
225 }
226 
227 
void SetDoNotAllowTracks(bool aEnable)
Definition: class_zone.h:657
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:686
void SetCornerSmoothingType(int aType)
Definition: class_zone.h:609
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void SetHatch(ZONE_HATCH_STYLE aHatchStyle, int aHatchPitch, bool aRebuildHatch)
Function SetHatch sets all hatch parameters for the zone.
Definition: class_zone.cpp:970
void SetHatchFillTypeSmoothingLevel(int aLevel)
Definition: class_zone.h:223
int GetNetCode() const
Function GetNetCode.
void SetHatchFillTypeSmoothingValue(double aValue)
Definition: class_zone.h:226
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: class_zone.h:199
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:542
void SetCornerRadius(unsigned int aRadius)
Definition: class_zone.cpp:551
int GetHatchFillTypeThickness() const
Definition: class_zone.h:213
long m_ThermalReliefCopperBridge
thickness of the copper bridge in thermal reliefs
Definition: zone_settings.h:94
int m_HatchFillTypeSmoothingLevel
Grid pattern smoothing type, similar to corner smoothing type 0 = no smoothing, 1 = fillet,...
Definition: zone_settings.h:79
double m_HatchFillTypeOrientation
Grid style shape: orientation of grid lines in degrees.
Definition: zone_settings.h:78
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:709
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:213
int m_HatchFillTypeGap
Grid style shape: clearance between lines (0 -> solid shape)
Definition: zone_settings.h:77
double GetHatchFillTypeOrientation() const
Definition: class_zone.h:219
double GetHatchFillTypeSmoothingValue() const
Definition: class_zone.h:225
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL
Definition: zones.h:30
ZONE_CONNECTION m_PadConnection
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:533
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
void SetDoNotAllowVias(bool aEnable)
Definition: class_zone.h:656
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:263
bool GetDoNotAllowVias() const
Definition: class_zone.h:651
Classes used in Pcbnew, CvPcb and GerbView.
void SetPriority(unsigned aPriority)
Function SetPriority.
Definition: class_zone.h:94
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:277
void SetDoNotAllowVias(bool aEnable)
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:84
void SetLayerSet(LSET aLayerSet)
Definition: class_zone.cpp:248
PCB_LAYER_ID
A quick note on layer IDs:
void SetHatchFillTypeGap(int aStep)
Definition: class_zone.h:217
LSET is a set of PCB_LAYER_IDs.
unsigned int GetCornerRadius() const
Definition: class_zone.h:615
int m_cornerSmoothingType
Corner smoothing type.
Definition: zone_settings.h:99
COLOR_SETTINGS * ColorSettings()
Helper to retrieve the current color settings.
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:156
int m_ZonePriority
Priority (0 ... N) of the zone.
Definition: zone_settings.h:72
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:650
ZONE_HATCH_STYLE m_Zone_HatchingStyle
Option to show the zone area (outlines only, short hatches or full hatches.
Definition: zone_settings.h:91
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:240
#define ZONE_CLEARANCE_MIL
Definition: zones.h:33
int m_ZoneClearance
Minimal clearance value.
Definition: zone_settings.h:74
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:195
ZONE_CONNECTION GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:879
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
#define ZONE_THICKNESS_MIL
Definition: zones.h:31
ZONE_HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:538
int GetCornerSmoothingType() const
Definition: class_zone.h:611
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:649
bool GetHV45() const
Definition: class_zone.h:708
void SetThermalReliefCopperBridge(int aThermalReliefCopperBridge)
Definition: class_zone.h:161
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:58
void SetDoNotAllowCopperPour(bool aEnable)
Definition: class_zone.h:655
Use thermal relief for pads.
ZONE_SETTINGS()
class ZONE_SETTINGS used to handle zones parameters
ZONE_FILL_MODE m_FillMode
Definition: zone_settings.h:70
COLOR4D GetColor(int aLayer) const
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: class_zone.h:155
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:100
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
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
#define _(s)
Definition: 3d_actions.cpp:33
bool m_keepoutDoNotAllowCopperPour
void SetHatchFillTypeOrientation(double aStep)
Definition: class_zone.h:220
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SetCornerRadius(int aRadius)
const bool GetDoNotAllowCopperPour() const
void SetHV45(bool aConstrain)
Definition: class_zone.h:709
double m_HatchFillTypeSmoothingValue
Grid pattern chamfer distance/fillet value.
Definition: zone_settings.h:81
int GetMinThickness() const
Definition: class_zone.h:204
bool GetDoNotAllowTracks() const
Definition: class_zone.h:652
void SetHatchFillTypeThickness(int aThickness)
Definition: class_zone.h:214
int GetHatchFillTypeSmoothingLevel() const
Definition: class_zone.h:222
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).
#define ZONE_THERMAL_RELIEF_GAP_MIL
Definition: zones.h:29
BOARD * GetBoard() const
bool m_keepoutDoNotAllowTracks
int GetZoneClearance() const
Definition: class_zone.h:194
void SetIsKeepout(bool aEnable)
Definition: class_zone.h:654
static const wxSize LAYER_BITMAP_SIZE(24, 16)
unsigned int m_cornerRadius
Corner chamfer distance / fillet radius.
LSEQ UIOrder() const
Definition: lset.cpp:813
void SetMinThickness(int aMinThickness)
Definition: class_zone.h:205
int m_HatchFillTypeThickness
Grid style shape: thickness of lines (if 0 -> solid shape)
Definition: zone_settings.h:76
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:216
void SetThermalReliefGap(int aThermalReliefGap)
Definition: class_zone.h:158
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:88
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:93
int m_ZoneMinThickness
Min thickness value in filled areas.
Definition: zone_settings.h:75
bool m_keepoutDoNotAllowVias
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40