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.

265 lines
11 KiB

14 years ago
14 years ago
14 years ago
14 years ago
8 years ago
14 years ago
14 years ago
8 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <zone_settings.h>
  26. #include <pcbnew.h>
  27. #include <pcb_base_frame.h>
  28. #include <board.h>
  29. #include <settings/color_settings.h>
  30. #include <zones.h>
  31. #include <zone.h>
  32. #include <wx/dataview.h>
  33. #include <widgets/color_swatch.h>
  34. ZONE_SETTINGS::ZONE_SETTINGS()
  35. {
  36. m_ZonePriority = 0;
  37. m_FillMode = ZONE_FILL_MODE::POLYGONS; // Mode for filling zone
  38. // Zone clearance value
  39. m_ZoneClearance = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, ZONE_CLEARANCE_MIL );
  40. // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) :
  41. m_ZoneMinThickness = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, ZONE_THICKNESS_MIL );
  42. m_HatchThickness = 0; // good value of grid line thickness for ZFM_GRID_PATTERN
  43. m_HatchGap = 0; // good value of grid line gap for ZFM_GRID_PATTERN
  44. m_HatchOrientation = ANGLE_0; // Grid style: orientation of grid lines
  45. m_HatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
  46. m_HatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
  47. m_HatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
  48. m_HatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
  49. m_NetcodeSelection = 0; // Net code selection for the current zone
  50. m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; // Option to show the zone
  51. // outlines only, short
  52. // hatches or full hatches
  53. m_BorderHatchPitch = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, ZONE_BORDER_HATCH_DIST_MIL );
  54. m_Layers.reset().set( F_Cu );
  55. m_Name = wxEmptyString;
  56. // thickness of the gap in thermal reliefs:
  57. m_ThermalReliefGap = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, ZONE_THERMAL_RELIEF_GAP_MIL );
  58. // thickness of the copper bridge in thermal reliefs:
  59. m_ThermalReliefSpokeWidth = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL );
  60. m_padConnection = ZONE_CONNECTION::THERMAL; // How pads are covered by copper in zone
  61. m_Locked = false;
  62. m_cornerSmoothingType = SMOOTHING_NONE;
  63. m_cornerRadius = 0;
  64. m_removeIslands = ISLAND_REMOVAL_MODE::AREA;
  65. m_minIslandArea = 10 * pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM;
  66. SetIsRuleArea( false );
  67. SetDoNotAllowCopperPour( false );
  68. SetDoNotAllowVias( true );
  69. SetDoNotAllowTracks( true );
  70. SetDoNotAllowPads( true );
  71. SetDoNotAllowFootprints( false );
  72. m_TeardropType = TEARDROP_TYPE::TD_NONE;
  73. }
  74. ZONE_SETTINGS& ZONE_SETTINGS::operator << ( const ZONE& aSource )
  75. {
  76. m_ZonePriority = aSource.GetAssignedPriority();
  77. m_FillMode = aSource.GetFillMode();
  78. m_ZoneClearance = aSource.GetLocalClearance();
  79. m_ZoneMinThickness = aSource.GetMinThickness();
  80. m_HatchThickness = aSource.GetHatchThickness();
  81. m_HatchGap = aSource.GetHatchGap();
  82. m_HatchOrientation = aSource.GetHatchOrientation();
  83. m_HatchSmoothingLevel = aSource.GetHatchSmoothingLevel();
  84. m_HatchSmoothingValue = aSource.GetHatchSmoothingValue();
  85. m_HatchBorderAlgorithm = aSource.GetHatchBorderAlgorithm();
  86. m_HatchHoleMinArea = aSource.GetHatchHoleMinArea();
  87. m_NetcodeSelection = aSource.GetNetCode();
  88. m_Name = aSource.GetZoneName();
  89. m_ZoneBorderDisplayStyle = aSource.GetHatchStyle();
  90. m_BorderHatchPitch = aSource.GetBorderHatchPitch();
  91. m_ThermalReliefGap = aSource.GetThermalReliefGap();
  92. m_ThermalReliefSpokeWidth = aSource.GetThermalReliefSpokeWidth();
  93. m_padConnection = aSource.GetPadConnection();
  94. m_cornerSmoothingType = aSource.GetCornerSmoothingType();
  95. m_cornerRadius = aSource.GetCornerRadius();
  96. m_isRuleArea = aSource.GetIsRuleArea();
  97. m_keepoutDoNotAllowCopperPour = aSource.GetDoNotAllowCopperPour();
  98. m_keepoutDoNotAllowVias = aSource.GetDoNotAllowVias();
  99. m_keepoutDoNotAllowTracks = aSource.GetDoNotAllowTracks();
  100. m_keepoutDoNotAllowPads = aSource.GetDoNotAllowPads();
  101. m_keepoutDoNotAllowFootprints = aSource.GetDoNotAllowFootprints();
  102. m_Locked = aSource.IsLocked();
  103. m_removeIslands = aSource.GetIslandRemovalMode();
  104. m_minIslandArea = aSource.GetMinIslandArea();
  105. // Currently, the teardrop area type is not really a ZONE_SETTINGS parameter,
  106. // but a ZONE parameter only.
  107. // However it can be used in dialogs
  108. m_TeardropType = aSource.GetTeardropAreaType();
  109. m_Layers = aSource.GetLayerSet();
  110. return *this;
  111. }
  112. void ZONE_SETTINGS::ExportSetting( ZONE& aTarget, bool aFullExport ) const
  113. {
  114. aTarget.SetFillMode( m_FillMode );
  115. aTarget.SetLocalClearance( m_ZoneClearance );
  116. aTarget.SetMinThickness( m_ZoneMinThickness );
  117. aTarget.SetHatchThickness( m_HatchThickness );
  118. aTarget.SetHatchGap( m_HatchGap );
  119. aTarget.SetHatchOrientation( m_HatchOrientation );
  120. aTarget.SetHatchSmoothingLevel( m_HatchSmoothingLevel );
  121. aTarget.SetHatchSmoothingValue( m_HatchSmoothingValue );
  122. aTarget.SetHatchBorderAlgorithm( m_HatchBorderAlgorithm );
  123. aTarget.SetHatchHoleMinArea( m_HatchHoleMinArea );
  124. aTarget.SetThermalReliefGap( m_ThermalReliefGap );
  125. aTarget.SetThermalReliefSpokeWidth( m_ThermalReliefSpokeWidth );
  126. aTarget.SetPadConnection( m_padConnection );
  127. aTarget.SetCornerSmoothingType( m_cornerSmoothingType );
  128. aTarget.SetCornerRadius( m_cornerRadius );
  129. aTarget.SetIsRuleArea( GetIsRuleArea() );
  130. aTarget.SetDoNotAllowCopperPour( GetDoNotAllowCopperPour() );
  131. aTarget.SetDoNotAllowVias( GetDoNotAllowVias() );
  132. aTarget.SetDoNotAllowTracks( GetDoNotAllowTracks() );
  133. aTarget.SetDoNotAllowPads( GetDoNotAllowPads() );
  134. aTarget.SetDoNotAllowFootprints( GetDoNotAllowFootprints() );
  135. aTarget.SetLocked( m_Locked );
  136. aTarget.SetIslandRemovalMode( GetIslandRemovalMode() );
  137. aTarget.SetMinIslandArea( GetMinIslandArea() );
  138. // Currently, the teardrop area type is not imported from a ZONE_SETTINGS, because
  139. // it is not really a ZONE_SETTINGS parameter, but a ZONE parameter only
  140. #if 0
  141. aTarget.SetTeardropAreaType( m_TeardropType );
  142. #endif
  143. if( aFullExport )
  144. {
  145. aTarget.SetAssignedPriority( m_ZonePriority );
  146. aTarget.SetLayerSet( m_Layers );
  147. aTarget.SetZoneName( m_Name );
  148. if( !m_isRuleArea )
  149. aTarget.SetNetCode( m_NetcodeSelection );
  150. }
  151. // call SetBorderDisplayStyle last, because hatch lines will be rebuilt,
  152. // using new parameters values
  153. aTarget.SetBorderDisplayStyle( m_ZoneBorderDisplayStyle,
  154. m_BorderHatchPitch, true );
  155. }
  156. void ZONE_SETTINGS::SetCornerRadius( int aRadius )
  157. {
  158. if( aRadius < 0 )
  159. m_cornerRadius = 0;
  160. else
  161. m_cornerRadius = aRadius;
  162. }
  163. #ifdef __WXOSX_MAC__
  164. const static wxSize LAYER_BITMAP_SIZE( 28, 28 ); // wxCocoa impl unhappy if this isn't square...
  165. #else
  166. const static wxSize LAYER_BITMAP_SIZE( 24, 16 );
  167. #endif
  168. const static wxSize CHECKERBOARD_SIZE( 8, 8 );
  169. // A helper for setting up a dialog list for specifying zone layers. Used by all three
  170. // zone settings dialogs.
  171. void ZONE_SETTINGS::SetupLayersList( wxDataViewListCtrl* aList, PCB_BASE_FRAME* aFrame,
  172. LSET aLayers, bool aFpEditorMode )
  173. {
  174. BOARD* board = aFrame->GetBoard();
  175. COLOR4D backgroundColor = aFrame->GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
  176. // In the Footprint Editor In1_Cu is used as a proxy for "all inner layers"
  177. if( aFpEditorMode )
  178. aLayers.set( In1_Cu );
  179. wxDataViewColumn* checkColumn = aList->AppendToggleColumn( wxEmptyString );
  180. wxDataViewColumn* layerColumn = aList->AppendIconTextColumn( wxEmptyString );
  181. wxDataViewColumn* layerIDColumn = aList->AppendTextColumn( wxEmptyString );
  182. layerIDColumn->SetHidden( true );
  183. int textWidth = 0;
  184. for( LSEQ layer = aLayers.UIOrder(); layer; ++layer )
  185. {
  186. PCB_LAYER_ID layerID = *layer;
  187. wxString layerName = board->GetLayerName( layerID );
  188. if( aFpEditorMode && layerID == In1_Cu )
  189. layerName = _( "Inner layers" );
  190. // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
  191. textWidth = std::max( textWidth, KIUI::GetTextSize( layerName, aList ).x );
  192. COLOR4D layerColor = aFrame->GetColorSettings()->GetColor( layerID );
  193. auto bitmap = COLOR_SWATCH::MakeBitmap( layerColor, backgroundColor, LAYER_BITMAP_SIZE,
  194. CHECKERBOARD_SIZE, aList->GetBackgroundColour() );
  195. wxIcon icon;
  196. icon.CopyFromBitmap( bitmap );
  197. wxVector<wxVariant> row;
  198. row.push_back( wxVariant( m_Layers.test( layerID ) ) );
  199. row.push_back( wxVariant( wxDataViewIconText( layerName, icon ) ) );
  200. row.push_back( wxVariant( wxString::Format( wxT( "%i" ), layerID ) ) );
  201. aList->AppendItem( row );
  202. if( m_Layers.test( layerID ) )
  203. aList->SetToggleValue( true, (unsigned) aList->GetItemCount() - 1, 0 );
  204. }
  205. int checkColSize = 22;
  206. int layerColSize = textWidth + LAYER_BITMAP_SIZE.x + 15;
  207. #ifdef __WXMAC__
  208. // TODO: something in wxWidgets 3.1.x makes checkbox padding really large...
  209. int checkColMargins = 40;
  210. #else
  211. int checkColMargins = 0;
  212. #endif
  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 + checkColMargins + layerColSize,
  217. aList->GetMinClientSize().y ) );
  218. checkColumn->SetWidth( checkColSize );
  219. layerColumn->SetWidth( layerColSize );
  220. }