You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
9.4 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
8 years ago
14 years ago
14 years ago
14 years ago
8 years ago
  1. /**
  2. * @brief class ZONE_SETTINGS used to handle zones parameters
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  8. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  9. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #include <zone_settings.h>
  29. #include <fctsys.h>
  30. #include <convert_to_biu.h>
  31. #include <pcbnew.h>
  32. #include <pcb_base_frame.h>
  33. #include <class_board.h>
  34. #include <zones.h>
  35. #include <class_zone.h>
  36. #include <wx/dataview.h>
  37. #include <widgets/color_swatch.h>
  38. ZONE_SETTINGS::ZONE_SETTINGS()
  39. {
  40. m_ZonePriority = 0;
  41. m_FillMode = ZFM_POLYGONS; // Mode for filling zone : 1 use segments, 0 use polygons
  42. // Zone clearance value
  43. m_ZoneClearance = Mils2iu( ZONE_CLEARANCE_MIL );
  44. // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
  45. m_ZoneMinThickness = Mils2iu( ZONE_THICKNESS_MIL );
  46. m_HatchFillTypeThickness = 0; // good value of grid line thickness if m_FillMode = ZFM_GRID_PATTERN
  47. m_HatchFillTypeGap = 0; // good value of grid line gap if m_FillMode = ZFM_GRID_PATTERN
  48. m_HatchFillTypeOrientation = 0.0; // Grid style: orientation of grid lines in degrees
  49. m_HatchFillTypeSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
  50. m_HatchFillTypeSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
  51. m_NetcodeSelection = 0; // Net code selection for the current zone
  52. m_CurrentZone_Layer = F_Cu; // Layer used to create the current zone
  53. m_Zone_HatchingStyle = ZONE_CONTAINER::DIAGONAL_EDGE; // Option to show the zone area (outlines only,
  54. //short hatches or full hatches
  55. m_ArcToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF; // Option to select number of segments to approximate a circle
  56. // ARC_APPROX_SEGMENTS_COUNT_LOW_DEF
  57. // or ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF segments
  58. // thickness of the gap in thermal reliefs:
  59. m_ThermalReliefGap = Mils2iu( ZONE_THERMAL_RELIEF_GAP_MIL );
  60. // thickness of the copper bridge in thermal reliefs:
  61. m_ThermalReliefCopperBridge = Mils2iu( ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL );
  62. m_PadConnection = PAD_ZONE_CONN_THERMAL; // How pads are covered by copper in zone
  63. m_Zone_45_Only = false;
  64. m_cornerSmoothingType = SMOOTHING_NONE;
  65. m_cornerRadius = 0;
  66. SetIsKeepout( false );
  67. SetDoNotAllowCopperPour( false );
  68. SetDoNotAllowVias( true );
  69. SetDoNotAllowTracks( true );
  70. }
  71. ZONE_SETTINGS& ZONE_SETTINGS::operator << ( const ZONE_CONTAINER& aSource )
  72. {
  73. m_ZonePriority = aSource.GetPriority();
  74. m_FillMode = aSource.GetFillMode();
  75. m_ZoneClearance = aSource.GetZoneClearance();
  76. m_ZoneMinThickness = aSource.GetMinThickness();
  77. m_HatchFillTypeThickness = aSource.GetHatchFillTypeThickness();
  78. m_HatchFillTypeGap = aSource.GetHatchFillTypeGap();
  79. m_HatchFillTypeOrientation = aSource.GetHatchFillTypeOrientation();
  80. m_HatchFillTypeSmoothingLevel = aSource.GetHatchFillTypeSmoothingLevel();
  81. m_HatchFillTypeSmoothingValue = aSource.GetHatchFillTypeSmoothingValue();
  82. m_NetcodeSelection = aSource.GetNetCode();
  83. m_Zone_HatchingStyle = aSource.GetHatchStyle();
  84. m_ArcToSegmentsCount = aSource.GetArcSegmentCount();
  85. m_ThermalReliefGap = aSource.GetThermalReliefGap();
  86. m_ThermalReliefCopperBridge = aSource.GetThermalReliefCopperBridge();
  87. m_PadConnection = aSource.GetPadConnection();
  88. m_cornerSmoothingType = aSource.GetCornerSmoothingType();
  89. m_cornerRadius = aSource.GetCornerRadius();
  90. m_isKeepout = aSource.GetIsKeepout();
  91. m_keepoutDoNotAllowCopperPour = aSource.GetDoNotAllowCopperPour();
  92. m_keepoutDoNotAllowVias = aSource.GetDoNotAllowVias();
  93. m_keepoutDoNotAllowTracks = aSource.GetDoNotAllowTracks();
  94. m_Zone_45_Only = aSource.GetHV45();
  95. m_CurrentZone_Layer = aSource.GetLayer();
  96. m_Layers = aSource.GetLayerSet();
  97. return *this;
  98. }
  99. void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) const
  100. {
  101. aTarget.SetFillMode( m_FillMode );
  102. aTarget.SetZoneClearance( m_ZoneClearance );
  103. aTarget.SetMinThickness( m_ZoneMinThickness );
  104. aTarget.SetHatchFillTypeThickness( m_HatchFillTypeThickness );
  105. aTarget.SetHatchFillTypeGap( m_HatchFillTypeGap );
  106. aTarget.SetHatchFillTypeOrientation( m_HatchFillTypeOrientation );
  107. aTarget.SetHatchFillTypeSmoothingLevel( m_HatchFillTypeSmoothingLevel );
  108. aTarget.SetHatchFillTypeSmoothingValue( m_HatchFillTypeSmoothingValue );
  109. aTarget.SetArcSegmentCount( m_ArcToSegmentsCount );
  110. aTarget.SetThermalReliefGap( m_ThermalReliefGap );
  111. aTarget.SetThermalReliefCopperBridge( m_ThermalReliefCopperBridge );
  112. aTarget.SetPadConnection( m_PadConnection );
  113. aTarget.SetCornerSmoothingType( m_cornerSmoothingType );
  114. aTarget.SetCornerRadius( m_cornerRadius );
  115. aTarget.SetIsKeepout( GetIsKeepout() );
  116. aTarget.SetDoNotAllowCopperPour( GetDoNotAllowCopperPour() );
  117. aTarget.SetDoNotAllowVias( GetDoNotAllowVias() );
  118. aTarget.SetDoNotAllowTracks( GetDoNotAllowTracks() );
  119. aTarget.SetHV45( m_Zone_45_Only );
  120. if( aFullExport )
  121. {
  122. aTarget.SetPriority( m_ZonePriority );
  123. aTarget.SetNetCode( m_NetcodeSelection );
  124. // Keepout zones can have multiple layers
  125. if( m_isKeepout )
  126. {
  127. aTarget.SetLayerSet( m_Layers );
  128. }
  129. else
  130. {
  131. aTarget.SetLayer( m_CurrentZone_Layer );
  132. }
  133. }
  134. // call SetHatch last, because hatch lines will be rebuilt,
  135. // using new parameters values
  136. aTarget.SetHatch( m_Zone_HatchingStyle, aTarget.GetDefaultHatchPitch(), true );
  137. }
  138. void ZONE_SETTINGS::SetCornerRadius( int aRadius )
  139. {
  140. if( aRadius < 0 )
  141. m_cornerRadius = 0;
  142. else
  143. m_cornerRadius = aRadius;
  144. }
  145. #ifdef __WXOSX_MAC__
  146. const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
  147. #else
  148. const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
  149. #endif
  150. // A helper for setting up a dialog list for specifying zone layers. Used by all three
  151. // zone settings dialogs.
  152. void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
  153. bool aShowCopper )
  154. {
  155. BOARD* board = aFrame->GetBoard();
  156. COLOR4D backgroundColor = aFrame->Settings().Colors().GetLayerColor( LAYER_PCB_BACKGROUND );
  157. LSET layers = aShowCopper ? LSET::AllCuMask( board->GetCopperLayerCount() )
  158. : LSET::AllNonCuMask();
  159. wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
  160. wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
  161. wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
  162. layerIDColumn->SetHidden( true );
  163. int textWidth = 0;
  164. for( LSEQ layer = layers.UIOrder(); layer; ++layer )
  165. {
  166. PCB_LAYER_ID layerID = *layer;
  167. wxString layerName = board->GetLayerName( layerID );
  168. // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
  169. textWidth = std::max( textWidth, GetTextSize( layerName, aList ).x );
  170. COLOR4D layerColor = aFrame->Settings().Colors().GetLayerColor( layerID );
  171. auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE );
  172. wxIcon icon;
  173. icon.CopyFromBitmap( bitmap );
  174. wxVector<wxVariant> row;
  175. row.push_back( wxVariant( m_Layers.test( layerID ) ) );
  176. row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
  177. row.push_back( wxVariant( wxString::Format( "%i", layerID ) ) );
  178. aList->AppendItem( row );
  179. if( m_CurrentZone_Layer == layerID )
  180. aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
  181. }
  182. int checkColSize = 22;
  183. int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
  184. // You'd think the fact that m_layers is a list would encourage wxWidgets not to save room
  185. // for the tree expanders... but you'd be wrong. Force indent to 0.
  186. aList->SetIndent( 0 );
  187. aList->SetMinClientSize( wxSize( checkColSize + layerColSize, aList->GetMinClientSize().y ) );
  188. checkColumn->SetWidth( checkColSize );
  189. layerColumn->SetWidth( layerColSize );
  190. }