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.

1413 lines
42 KiB

5 years ago
5 years ago
5 years ago
7 years ago
7 years ago
7 years ago
Clean up arc/circle polygonization. 1) For a while now we've been using a calculated seg count from a given maxError, and a correction factor to push the radius out so that all the error is outside the arc/circle. However, the second calculation (which pre-dates the first) is pretty much just the inverse of the first (and yields nothing more than maxError back). This is particularly sub-optimal given the cost of trig functions. 2) There are a lot of old optimizations to reduce segcounts in certain situations, someting that our error-based calculation compensates for anyway. (Smaller radii need fewer segments to meet the maxError condition.) But perhaps more importantly we now surface maxError in the UI and we don't really want to call it "Max deviation except when it's not". 3) We were also clamping the segCount twice: once in the calculation routine and once in most of it's callers. Furthermore, the caller clamping was inconsistent (both in being done and in the clamping value). We now clamp only in the calculation routine. 4) There's no reason to use the correction factors in the 3Dviewer; it's just a visualization and whether the polygonization error is inside or outside the shape isn't really material. 5) The arc-correction-disabling stuff (used for solder mask layer) was somewhat fragile in that it depended on the caller to turn it back on afterwards. It's now only exposed as a RAII object which automatically cleans up when it goes out of scope. 6) There were also bugs in a couple of the polygonization routines where we'd accumulate round-off error in adding up the segments and end up with an overly long last segment (which of course would voilate the error max). This was the cause of the linked bug and also some issues with vias that we had fudged in the past with extra clearance. Fixes https://gitlab.com/kicad/code/kicad/issues/5567
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2020 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 <bitmaps.h>
  26. #include <geometry/geometry_utils.h>
  27. #include <geometry/shape_null.h>
  28. #include <advanced_config.h>
  29. #include <pcb_edit_frame.h>
  30. #include <pcb_screen.h>
  31. #include <class_board.h>
  32. #include <class_zone.h>
  33. #include <kicad_string.h>
  34. #include <math_for_graphics.h>
  35. #include <settings/color_settings.h>
  36. #include <settings/settings_manager.h>
  37. #include <trigo.h>
  38. #include <i18n_utility.h>
  39. ZONE_CONTAINER::ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent, bool aInFP )
  40. : BOARD_CONNECTED_ITEM( aParent, aInFP ? PCB_FP_ZONE_AREA_T : PCB_ZONE_AREA_T ),
  41. m_area( 0.0 )
  42. {
  43. m_CornerSelection = nullptr; // no corner is selected
  44. m_isFilled = false; // fill status : true when the zone is filled
  45. m_fillMode = ZONE_FILL_MODE::POLYGONS;
  46. m_borderStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
  47. m_borderHatchPitch = GetDefaultHatchPitch();
  48. m_hv45 = false;
  49. m_hatchThickness = 0;
  50. m_hatchGap = 0;
  51. m_hatchOrientation = 0.0;
  52. m_hatchSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
  53. m_hatchSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
  54. // used only if m_hatchSmoothingLevel > 0
  55. m_hatchHoleMinArea = 0.3; // Min size before holes are dropped (ratio of hole size)
  56. m_hatchBorderAlgorithm = 1; // 0 = use zone min thickness; 1 = use hatch width
  57. m_priority = 0;
  58. m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
  59. SetIsRuleArea( aInFP ); // Zones living in footprints have the rule area option
  60. SetDoNotAllowCopperPour( false ); // has meaning only if m_isRuleArea == true
  61. SetDoNotAllowVias( true ); // has meaning only if m_isRuleArea == true
  62. SetDoNotAllowTracks( true ); // has meaning only if m_isRuleArea == true
  63. SetDoNotAllowPads( true ); // has meaning only if m_isRuleArea == true
  64. SetDoNotAllowFootprints( false ); // has meaning only if m_isRuleArea == true
  65. m_cornerRadius = 0;
  66. SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
  67. m_Poly = new SHAPE_POLY_SET(); // Outlines
  68. m_fillVersion = 5; // set the "old" way to build filled polygon areas (< 6.0.x)
  69. m_islandRemovalMode = ISLAND_REMOVAL_MODE::ALWAYS;
  70. aParent->GetZoneSettings().ExportSetting( *this );
  71. m_needRefill = false; // True only after some edition.
  72. }
  73. ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone )
  74. : BOARD_CONNECTED_ITEM( aZone ),
  75. m_Poly( nullptr ),
  76. m_CornerSelection( nullptr )
  77. {
  78. InitDataFromSrcInCopyCtor( aZone );
  79. }
  80. ZONE_CONTAINER& ZONE_CONTAINER::operator=( const ZONE_CONTAINER& aOther )
  81. {
  82. BOARD_CONNECTED_ITEM::operator=( aOther );
  83. InitDataFromSrcInCopyCtor( aOther );
  84. return *this;
  85. }
  86. ZONE_CONTAINER::~ZONE_CONTAINER()
  87. {
  88. delete m_Poly;
  89. delete m_CornerSelection;
  90. }
  91. void ZONE_CONTAINER::InitDataFromSrcInCopyCtor( const ZONE_CONTAINER& aZone )
  92. {
  93. // members are expected non initialize in this.
  94. // InitDataFromSrcInCopyCtor() is expected to be called
  95. // only from a copy constructor.
  96. // Copy only useful EDA_ITEM flags:
  97. m_Flags = aZone.m_Flags;
  98. m_forceVisible = aZone.m_forceVisible;
  99. // Replace the outlines for aZone outlines.
  100. delete m_Poly;
  101. m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
  102. m_cornerSmoothingType = aZone.m_cornerSmoothingType;
  103. m_cornerRadius = aZone.m_cornerRadius;
  104. m_zoneName = aZone.m_zoneName;
  105. SetLayerSet( aZone.GetLayerSet() );
  106. m_priority = aZone.m_priority;
  107. m_isRuleArea = aZone.m_isRuleArea;
  108. m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
  109. m_doNotAllowVias = aZone.m_doNotAllowVias;
  110. m_doNotAllowTracks = aZone.m_doNotAllowTracks;
  111. m_doNotAllowPads = aZone.m_doNotAllowPads;
  112. m_doNotAllowFootprints = aZone.m_doNotAllowFootprints;
  113. m_PadConnection = aZone.m_PadConnection;
  114. m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
  115. m_ZoneMinThickness = aZone.m_ZoneMinThickness;
  116. m_fillVersion = aZone.m_fillVersion;
  117. m_islandRemovalMode = aZone.m_islandRemovalMode;
  118. m_minIslandArea = aZone.m_minIslandArea;
  119. m_isFilled = aZone.m_isFilled;
  120. m_needRefill = aZone.m_needRefill;
  121. m_thermalReliefGap = aZone.m_thermalReliefGap;
  122. m_thermalReliefSpokeWidth = aZone.m_thermalReliefSpokeWidth;
  123. m_fillMode = aZone.m_fillMode; // solid vs. hatched
  124. m_hatchThickness = aZone.m_hatchThickness;
  125. m_hatchGap = aZone.m_hatchGap;
  126. m_hatchOrientation = aZone.m_hatchOrientation;
  127. m_hatchSmoothingLevel = aZone.m_hatchSmoothingLevel;
  128. m_hatchSmoothingValue = aZone.m_hatchSmoothingValue;
  129. m_hatchBorderAlgorithm = aZone.m_hatchBorderAlgorithm;
  130. m_hatchHoleMinArea = aZone.m_hatchHoleMinArea;
  131. // For corner moving, corner index to drag, or nullptr if no selection
  132. delete m_CornerSelection;
  133. m_CornerSelection = nullptr;
  134. for( PCB_LAYER_ID layer : aZone.GetLayerSet().Seq() )
  135. {
  136. m_FilledPolysList[layer] = aZone.m_FilledPolysList.at( layer );
  137. m_RawPolysList[layer] = aZone.m_RawPolysList.at( layer );
  138. m_filledPolysHash[layer] = aZone.m_filledPolysHash.at( layer );
  139. m_FillSegmList[layer] = aZone.m_FillSegmList.at( layer ); // vector <> copy
  140. m_insulatedIslands[layer] = aZone.m_insulatedIslands.at( layer );
  141. }
  142. m_borderStyle = aZone.m_borderStyle;
  143. m_borderHatchPitch = aZone.m_borderHatchPitch;
  144. m_borderHatchLines = aZone.m_borderHatchLines;
  145. SetLocalFlags( aZone.GetLocalFlags() );
  146. m_netinfo = aZone.m_netinfo;
  147. m_hv45 = aZone.m_hv45;
  148. m_area = aZone.m_area;
  149. }
  150. EDA_ITEM* ZONE_CONTAINER::Clone() const
  151. {
  152. return new ZONE_CONTAINER( *this );
  153. }
  154. bool ZONE_CONTAINER::UnFill()
  155. {
  156. bool change = false;
  157. for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
  158. {
  159. change |= !pair.second.IsEmpty();
  160. pair.second.RemoveAllContours();
  161. }
  162. for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
  163. {
  164. change |= !pair.second.empty();
  165. pair.second.clear();
  166. }
  167. m_isFilled = false;
  168. m_fillFlags.clear();
  169. return change;
  170. }
  171. wxPoint ZONE_CONTAINER::GetPosition() const
  172. {
  173. return (wxPoint) GetCornerPosition( 0 );
  174. }
  175. PCB_LAYER_ID ZONE_CONTAINER::GetLayer() const
  176. {
  177. return BOARD_ITEM::GetLayer();
  178. }
  179. bool ZONE_CONTAINER::IsOnCopperLayer() const
  180. {
  181. return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
  182. }
  183. bool ZONE_CONTAINER::CommonLayerExists( const LSET aLayerSet ) const
  184. {
  185. LSET common = GetLayerSet() & aLayerSet;
  186. return common.count() > 0;
  187. }
  188. void ZONE_CONTAINER::SetLayer( PCB_LAYER_ID aLayer )
  189. {
  190. SetLayerSet( LSET( aLayer ) );
  191. m_Layer = aLayer;
  192. }
  193. void ZONE_CONTAINER::SetLayerSet( LSET aLayerSet )
  194. {
  195. if( GetIsRuleArea() )
  196. {
  197. // Rule areas can only exist on copper layers
  198. aLayerSet &= LSET::AllCuMask();
  199. }
  200. if( aLayerSet.count() == 0 )
  201. return;
  202. if( m_layerSet != aLayerSet )
  203. {
  204. SetNeedRefill( true );
  205. UnFill();
  206. m_FillSegmList.clear();
  207. m_FilledPolysList.clear();
  208. m_RawPolysList.clear();
  209. m_filledPolysHash.clear();
  210. m_insulatedIslands.clear();
  211. for( PCB_LAYER_ID layer : aLayerSet.Seq() )
  212. {
  213. m_FillSegmList[layer] = {};
  214. m_FilledPolysList[layer] = {};
  215. m_RawPolysList[layer] = {};
  216. m_filledPolysHash[layer] = {};
  217. m_insulatedIslands[layer] = {};
  218. }
  219. }
  220. m_layerSet = aLayerSet;
  221. // Set the single layer parameter. For zones that can be on many layers, this parameter
  222. // is arbitrary at best, but some code still uses it.
  223. // Priority is F_Cu then B_Cu then to the first selected layer
  224. m_Layer = aLayerSet.Seq()[0];
  225. if( m_Layer != F_Cu && aLayerSet[B_Cu] )
  226. m_Layer = B_Cu;
  227. }
  228. LSET ZONE_CONTAINER::GetLayerSet() const
  229. {
  230. return m_layerSet;
  231. }
  232. void ZONE_CONTAINER::ViewGetLayers( int aLayers[], int& aCount ) const
  233. {
  234. LSEQ layers = m_layerSet.Seq();
  235. for( unsigned int idx = 0; idx < layers.size(); idx++ )
  236. aLayers[idx] = LAYER_ZONE_START + layers[idx];
  237. aCount = layers.size();
  238. }
  239. double ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  240. {
  241. constexpr double HIDE = std::numeric_limits<double>::max();
  242. return aView->IsLayerVisible( LAYER_ZONES ) ? 0.0 : HIDE;
  243. }
  244. bool ZONE_CONTAINER::IsOnLayer( PCB_LAYER_ID aLayer ) const
  245. {
  246. return m_layerSet.test( aLayer );
  247. }
  248. const EDA_RECT ZONE_CONTAINER::GetBoundingBox() const
  249. {
  250. auto bb = m_Poly->BBox();
  251. EDA_RECT ret( (wxPoint) bb.GetOrigin(), wxSize( bb.GetWidth(), bb.GetHeight() ) );
  252. return ret;
  253. }
  254. int ZONE_CONTAINER::GetThermalReliefGap( D_PAD* aPad, wxString* aSource ) const
  255. {
  256. if( aPad->GetEffectiveThermalGap() == 0 )
  257. {
  258. if( aSource )
  259. *aSource = _( "zone" );
  260. return m_thermalReliefGap;
  261. }
  262. return aPad->GetEffectiveThermalGap( aSource );
  263. }
  264. int ZONE_CONTAINER::GetThermalReliefSpokeWidth( D_PAD* aPad, wxString* aSource ) const
  265. {
  266. if( aPad->GetEffectiveThermalSpokeWidth() == 0 )
  267. {
  268. if( aSource )
  269. *aSource = _( "zone" );
  270. return m_thermalReliefSpokeWidth;
  271. }
  272. return aPad->GetEffectiveThermalSpokeWidth( aSource );
  273. }
  274. void ZONE_CONTAINER::SetCornerRadius( unsigned int aRadius )
  275. {
  276. if( m_cornerRadius != aRadius )
  277. SetNeedRefill( true );
  278. m_cornerRadius = aRadius;
  279. }
  280. bool ZONE_CONTAINER::GetFilledPolysUseThickness( PCB_LAYER_ID aLayer ) const
  281. {
  282. if( ADVANCED_CFG::GetCfg().m_DebugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
  283. return false;
  284. return GetFilledPolysUseThickness();
  285. }
  286. bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  287. {
  288. // Normally accuracy is zoom-relative, but for the generic HitTest we just use
  289. // a fixed (small) value.
  290. int accuracy = std::max( aAccuracy, Millimeter2iu( 0.1 ) );
  291. return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
  292. }
  293. void ZONE_CONTAINER::SetSelectedCorner( const wxPoint& aPosition, int aAccuracy )
  294. {
  295. SHAPE_POLY_SET::VERTEX_INDEX corner;
  296. // If there is some corner to be selected, assign it to m_CornerSelection
  297. if( HitTestForCorner( aPosition, aAccuracy * 2, corner )
  298. || HitTestForEdge( aPosition, aAccuracy, corner ) )
  299. {
  300. if( m_CornerSelection == nullptr )
  301. m_CornerSelection = new SHAPE_POLY_SET::VERTEX_INDEX;
  302. *m_CornerSelection = corner;
  303. }
  304. }
  305. bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy,
  306. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
  307. {
  308. return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, aAccuracy );
  309. }
  310. bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const
  311. {
  312. SHAPE_POLY_SET::VERTEX_INDEX dummy;
  313. return HitTestForCorner( refPos, aAccuracy, dummy );
  314. }
  315. bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy,
  316. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
  317. {
  318. return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, aAccuracy );
  319. }
  320. bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const
  321. {
  322. SHAPE_POLY_SET::VERTEX_INDEX dummy;
  323. return HitTestForEdge( refPos, aAccuracy, dummy );
  324. }
  325. bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  326. {
  327. // Calculate bounding box for zone
  328. EDA_RECT bbox = GetBoundingBox();
  329. bbox.Normalize();
  330. EDA_RECT arect = aRect;
  331. arect.Normalize();
  332. arect.Inflate( aAccuracy );
  333. if( aContained )
  334. {
  335. return arect.Contains( bbox );
  336. }
  337. else
  338. {
  339. // Fast test: if aBox is outside the polygon bounding box, rectangles cannot intersect
  340. if( !arect.Intersects( bbox ) )
  341. return false;
  342. int count = m_Poly->TotalVertices();
  343. for( int ii = 0; ii < count; ii++ )
  344. {
  345. auto vertex = m_Poly->CVertex( ii );
  346. auto vertexNext = m_Poly->CVertex( ( ii + 1 ) % count );
  347. // Test if the point is within the rect
  348. if( arect.Contains( ( wxPoint ) vertex ) )
  349. return true;
  350. // Test if this edge intersects the rect
  351. if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
  352. return true;
  353. }
  354. return false;
  355. }
  356. }
  357. int ZONE_CONTAINER::GetLocalClearance( wxString* aSource ) const
  358. {
  359. if( m_isRuleArea )
  360. return 0;
  361. if( aSource )
  362. *aSource = _( "zone" );
  363. return m_ZoneClearance;
  364. }
  365. bool ZONE_CONTAINER::HitTestFilledArea( PCB_LAYER_ID aLayer, const wxPoint &aRefPos,
  366. int aAccuracy ) const
  367. {
  368. // Rule areas have no filled area, but it's generally nice to treat their interior as if it were
  369. // filled so that people don't have to select them by their outline (which is min-width)
  370. if( GetIsRuleArea() )
  371. return m_Poly->Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1, aAccuracy );
  372. if( !m_FilledPolysList.count( aLayer ) )
  373. return false;
  374. return m_FilledPolysList.at( aLayer ).Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1,
  375. aAccuracy );
  376. }
  377. bool ZONE_CONTAINER::HitTestCutout( const VECTOR2I& aRefPos, int* aOutlineIdx, int* aHoleIdx ) const
  378. {
  379. // Iterate over each outline polygon in the zone and then iterate over
  380. // each hole it has to see if the point is in it.
  381. for( int i = 0; i < m_Poly->OutlineCount(); i++ )
  382. {
  383. for( int j = 0; j < m_Poly->HoleCount( i ); j++ )
  384. {
  385. if( m_Poly->Hole( i, j ).PointInside( aRefPos ) )
  386. {
  387. if( aOutlineIdx )
  388. *aOutlineIdx = i;
  389. if( aHoleIdx )
  390. *aHoleIdx = j;
  391. return true;
  392. }
  393. }
  394. }
  395. return false;
  396. }
  397. void ZONE_CONTAINER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  398. {
  399. EDA_UNITS units = aFrame->GetUserUnits();
  400. wxString msg, msg2;
  401. if( GetIsRuleArea() )
  402. msg = _( "Rule Area" );
  403. else if( IsOnCopperLayer() )
  404. msg = _( "Copper Zone" );
  405. else
  406. msg = _( "Non-copper Zone" );
  407. // Display Cutout instead of Outline for holes inside a zone (i.e. when num contour !=0).
  408. // Check whether the selected corner is in a hole; i.e., in any contour but the first one.
  409. if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
  410. msg << wxT( " " ) << _( "Cutout" );
  411. aList.emplace_back( _( "Type" ), msg, DARKCYAN );
  412. if( GetIsRuleArea() )
  413. {
  414. msg.Empty();
  415. if( GetDoNotAllowVias() )
  416. AccumulateDescription( msg, _( "No vias" ) );
  417. if( GetDoNotAllowTracks() )
  418. AccumulateDescription( msg, _( "No tracks" ) );
  419. if( GetDoNotAllowPads() )
  420. AccumulateDescription( msg, _( "No pads" ) );
  421. if( GetDoNotAllowCopperPour() )
  422. AccumulateDescription( msg, _( "No copper zones" ) );
  423. if( GetDoNotAllowFootprints() )
  424. AccumulateDescription( msg, _( "No footprints" ) );
  425. if( !msg.IsEmpty() )
  426. aList.emplace_back( MSG_PANEL_ITEM( _( "Restrictions" ), msg, RED ) );
  427. }
  428. else if( IsOnCopperLayer() )
  429. {
  430. if( GetNetCode() >= 0 )
  431. {
  432. NETINFO_ITEM* net = GetNet();
  433. NETCLASS* netclass = nullptr;
  434. if( net )
  435. {
  436. if( net->GetNet() )
  437. netclass = GetNetClass();
  438. else
  439. netclass = GetBoard()->GetDesignSettings().GetDefault();
  440. msg = UnescapeString( net->GetNetname() );
  441. }
  442. else
  443. {
  444. msg = wxT( "<no name>" );
  445. }
  446. aList.emplace_back( _( "Net" ), msg, RED );
  447. if( netclass )
  448. aList.emplace_back( _( "NetClass" ), netclass->GetName(), DARKMAGENTA );
  449. }
  450. // Display priority level
  451. msg.Printf( wxT( "%d" ), GetPriority() );
  452. aList.emplace_back( _( "Priority" ), msg, BLUE );
  453. }
  454. wxString layerDesc;
  455. int count = 0;
  456. for( PCB_LAYER_ID layer : m_layerSet.Seq() )
  457. {
  458. if( count == 0 )
  459. layerDesc = GetBoard()->GetLayerName( layer );
  460. count++;
  461. }
  462. if( count > 1 )
  463. layerDesc.Printf( _( "%s and %d more" ), layerDesc, count - 1 );
  464. aList.emplace_back( _( "Layer" ), layerDesc, DARKGREEN );
  465. if( !m_zoneName.empty() )
  466. aList.emplace_back( _( "Name" ), m_zoneName, DARKMAGENTA );
  467. switch( m_fillMode )
  468. {
  469. case ZONE_FILL_MODE::POLYGONS: msg = _( "Solid" ); break;
  470. case ZONE_FILL_MODE::HATCH_PATTERN: msg = _( "Hatched" ); break;
  471. default: msg = _( "Unknown" ); break;
  472. }
  473. aList.emplace_back( _( "Fill Mode" ), msg, BROWN );
  474. msg = MessageTextFromValue( units, m_area, true, EDA_DATA_TYPE::AREA );
  475. aList.emplace_back( _( "Filled Area" ), msg, BLUE );
  476. wxString source;
  477. int clearance = GetOwnClearance( GetLayer(), &source );
  478. msg.Printf( _( "Min Clearance: %s" ), MessageTextFromValue( units, clearance ) );
  479. msg2.Printf( _( "(from %s)" ), source );
  480. aList.emplace_back( msg, msg2, BLACK );
  481. // Useful for statistics, especially when zones are complex the number of hatches
  482. // and filled polygons can explain the display and DRC calculation time:
  483. msg.Printf( wxT( "%d" ), (int) m_borderHatchLines.size() );
  484. aList.emplace_back( MSG_PANEL_ITEM( _( "HatchBorder Lines" ), msg, BLUE ) );
  485. PCB_LAYER_ID layer = m_Layer;
  486. // NOTE: This brings in dependence on PCB_EDIT_FRAME to the qa tests, which isn't ideal.
  487. // TODO: Figure out a way for items to know the active layer without the whole edit frame?
  488. #if 0
  489. if( PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( aFrame ) )
  490. if( m_FilledPolysList.count( pcbframe->GetActiveLayer() ) )
  491. layer = pcbframe->GetActiveLayer();
  492. #endif
  493. if( !GetIsRuleArea() )
  494. {
  495. auto layer_it = m_FilledPolysList.find( layer );
  496. if( layer_it == m_FilledPolysList.end() )
  497. layer_it = m_FilledPolysList.begin();
  498. if( layer_it != m_FilledPolysList.end() )
  499. {
  500. msg.Printf( wxT( "%d" ), layer_it->second.TotalVertices() );
  501. aList.emplace_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) );
  502. }
  503. }
  504. }
  505. /* Geometric transforms: */
  506. void ZONE_CONTAINER::Move( const wxPoint& offset )
  507. {
  508. /* move outlines */
  509. m_Poly->Move( offset );
  510. HatchBorder();
  511. for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
  512. pair.second.Move( offset );
  513. for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
  514. {
  515. for( SEG& seg : pair.second )
  516. {
  517. seg.A += VECTOR2I( offset );
  518. seg.B += VECTOR2I( offset );
  519. }
  520. }
  521. }
  522. void ZONE_CONTAINER::MoveEdge( const wxPoint& offset, int aEdge )
  523. {
  524. int next_corner;
  525. if( m_Poly->GetNeighbourIndexes( aEdge, nullptr, &next_corner ) )
  526. {
  527. m_Poly->SetVertex( aEdge, m_Poly->CVertex( aEdge ) + VECTOR2I( offset ) );
  528. m_Poly->SetVertex( next_corner, m_Poly->CVertex( next_corner ) + VECTOR2I( offset ) );
  529. HatchBorder();
  530. SetNeedRefill( true );
  531. }
  532. }
  533. void ZONE_CONTAINER::Rotate( const wxPoint& aCentre, double aAngle )
  534. {
  535. aAngle = -DECIDEG2RAD( aAngle );
  536. m_Poly->Rotate( aAngle, VECTOR2I( aCentre ) );
  537. HatchBorder();
  538. /* rotate filled areas: */
  539. for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
  540. pair.second.Rotate( aAngle, VECTOR2I( aCentre ) );
  541. for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
  542. {
  543. for( SEG& seg : pair.second )
  544. {
  545. wxPoint a( seg.A );
  546. RotatePoint( &a, aCentre, aAngle );
  547. seg.A = a;
  548. wxPoint b( seg.B );
  549. RotatePoint( &b, aCentre, aAngle );
  550. seg.B = a;
  551. }
  552. }
  553. }
  554. void ZONE_CONTAINER::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
  555. {
  556. Mirror( aCentre, aFlipLeftRight );
  557. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  558. if( GetIsRuleArea() )
  559. SetLayerSet( FlipLayerMask( GetLayerSet(), copperLayerCount ) );
  560. else
  561. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  562. }
  563. void ZONE_CONTAINER::Mirror( const wxPoint& aMirrorRef, bool aMirrorLeftRight )
  564. {
  565. // ZONE_CONTAINERs mirror about the x-axis (why?!?)
  566. m_Poly->Mirror( aMirrorLeftRight, !aMirrorLeftRight, VECTOR2I( aMirrorRef ) );
  567. HatchBorder();
  568. for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
  569. pair.second.Mirror( aMirrorLeftRight, !aMirrorLeftRight, VECTOR2I( aMirrorRef ) );
  570. for( std::pair<const PCB_LAYER_ID, ZONE_SEGMENT_FILL>& pair : m_FillSegmList )
  571. {
  572. for( SEG& seg : pair.second )
  573. {
  574. if( aMirrorLeftRight )
  575. {
  576. MIRROR( seg.A.x, aMirrorRef.x );
  577. MIRROR( seg.B.x, aMirrorRef.x );
  578. }
  579. else
  580. {
  581. MIRROR( seg.A.y, aMirrorRef.y );
  582. MIRROR( seg.B.y, aMirrorRef.y );
  583. }
  584. }
  585. }
  586. }
  587. ZONE_CONNECTION ZONE_CONTAINER::GetPadConnection( D_PAD* aPad, wxString* aSource ) const
  588. {
  589. if( aPad == NULL || aPad->GetEffectiveZoneConnection() == ZONE_CONNECTION::INHERITED )
  590. {
  591. if( aSource )
  592. *aSource = _( "zone" );
  593. return m_PadConnection;
  594. }
  595. else
  596. {
  597. return aPad->GetEffectiveZoneConnection( aSource );
  598. }
  599. }
  600. void ZONE_CONTAINER::RemoveCutout( int aOutlineIdx, int aHoleIdx )
  601. {
  602. // Ensure the requested cutout is valid
  603. if( m_Poly->OutlineCount() < aOutlineIdx || m_Poly->HoleCount( aOutlineIdx ) < aHoleIdx )
  604. return;
  605. SHAPE_POLY_SET cutPoly( m_Poly->Hole( aOutlineIdx, aHoleIdx ) );
  606. // Add the cutout back to the zone
  607. m_Poly->BooleanAdd( cutPoly, SHAPE_POLY_SET::PM_FAST );
  608. SetNeedRefill( true );
  609. }
  610. void ZONE_CONTAINER::AddPolygon( const SHAPE_LINE_CHAIN& aPolygon )
  611. {
  612. wxASSERT( aPolygon.IsClosed() );
  613. // Add the outline as a new polygon in the polygon set
  614. if( m_Poly->OutlineCount() == 0 )
  615. m_Poly->AddOutline( aPolygon );
  616. else
  617. m_Poly->AddHole( aPolygon );
  618. SetNeedRefill( true );
  619. }
  620. void ZONE_CONTAINER::AddPolygon( std::vector< wxPoint >& aPolygon )
  621. {
  622. if( aPolygon.empty() )
  623. return;
  624. SHAPE_LINE_CHAIN outline;
  625. // Create an outline and populate it with the points of aPolygon
  626. for( const wxPoint& pt : aPolygon)
  627. outline.Append( pt );
  628. outline.SetClosed( true );
  629. AddPolygon( outline );
  630. }
  631. bool ZONE_CONTAINER::AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication )
  632. {
  633. // Ensure the main outline exists:
  634. if( m_Poly->OutlineCount() == 0 )
  635. m_Poly->NewOutline();
  636. // If aHoleIdx >= 0, the corner musty be added to the hole, index aHoleIdx.
  637. // (remember: the index of the first hole is 0)
  638. // Return error if if does dot exist.
  639. if( aHoleIdx >= m_Poly->HoleCount( 0 ) )
  640. return false;
  641. m_Poly->Append( aPosition.x, aPosition.y, -1, aHoleIdx, aAllowDuplication );
  642. SetNeedRefill( true );
  643. return true;
  644. }
  645. wxString ZONE_CONTAINER::GetSelectMenuText( EDA_UNITS aUnits ) const
  646. {
  647. wxString text;
  648. // Check whether the selected contour is a hole (contour index > 0)
  649. if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
  650. text << wxT( " " ) << _( "(Cutout)" );
  651. if( GetIsRuleArea() )
  652. text << wxT( " " ) << _( "(Rule Area)" );
  653. else
  654. text << GetNetnameMsg();
  655. wxString layerDesc;
  656. int count = 0;
  657. for( PCB_LAYER_ID layer : m_layerSet.Seq() )
  658. {
  659. if( count == 0 )
  660. layerDesc = GetBoard()->GetLayerName( layer );
  661. count++;
  662. }
  663. if( count > 1 )
  664. layerDesc.Printf( _( "%s and %d more" ), layerDesc, count - 1 );
  665. return wxString::Format( _( "Zone Outline %s on %s" ), text, layerDesc );
  666. }
  667. int ZONE_CONTAINER::GetBorderHatchPitch() const
  668. {
  669. return m_borderHatchPitch;
  670. }
  671. void ZONE_CONTAINER::SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE aHatchStyle, int aHatchPitch,
  672. bool aRebuildHatch )
  673. {
  674. SetHatchPitch( aHatchPitch );
  675. m_borderStyle = aHatchStyle;
  676. if( aRebuildHatch )
  677. HatchBorder();
  678. }
  679. void ZONE_CONTAINER::SetHatchPitch( int aPitch )
  680. {
  681. m_borderHatchPitch = aPitch;
  682. }
  683. void ZONE_CONTAINER::UnHatchBorder()
  684. {
  685. m_borderHatchLines.clear();
  686. }
  687. // Creates hatch lines inside the outline of the complex polygon
  688. // sort function used in ::HatchBorder to sort points by descending wxPoint.x values
  689. bool sortEndsByDescendingX( const VECTOR2I& ref, const VECTOR2I& tst )
  690. {
  691. return tst.x < ref.x;
  692. }
  693. void ZONE_CONTAINER::HatchBorder()
  694. {
  695. UnHatchBorder();
  696. if( m_borderStyle == ZONE_BORDER_DISPLAY_STYLE::NO_HATCH
  697. || m_borderHatchPitch == 0
  698. || m_Poly->IsEmpty() )
  699. {
  700. return;
  701. }
  702. // define range for hatch lines
  703. int min_x = m_Poly->CVertex( 0 ).x;
  704. int max_x = m_Poly->CVertex( 0 ).x;
  705. int min_y = m_Poly->CVertex( 0 ).y;
  706. int max_y = m_Poly->CVertex( 0 ).y;
  707. for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
  708. {
  709. if( iterator->x < min_x )
  710. min_x = iterator->x;
  711. if( iterator->x > max_x )
  712. max_x = iterator->x;
  713. if( iterator->y < min_y )
  714. min_y = iterator->y;
  715. if( iterator->y > max_y )
  716. max_y = iterator->y;
  717. }
  718. // Calculate spacing between 2 hatch lines
  719. int spacing;
  720. if( m_borderStyle == ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE )
  721. spacing = m_borderHatchPitch;
  722. else
  723. spacing = m_borderHatchPitch * 2;
  724. // set the "length" of hatch lines (the length on horizontal axis)
  725. int hatch_line_len = m_borderHatchPitch;
  726. // To have a better look, give a slope depending on the layer
  727. LAYER_NUM layer = GetLayer();
  728. int slope_flag = (layer & 1) ? 1 : -1; // 1 or -1
  729. double slope = 0.707106 * slope_flag; // 45 degrees slope
  730. int max_a, min_a;
  731. if( slope_flag == 1 )
  732. {
  733. max_a = KiROUND( max_y - slope * min_x );
  734. min_a = KiROUND( min_y - slope * max_x );
  735. }
  736. else
  737. {
  738. max_a = KiROUND( max_y - slope * max_x );
  739. min_a = KiROUND( min_y - slope * min_x );
  740. }
  741. min_a = (min_a / spacing) * spacing;
  742. // calculate an offset depending on layer number,
  743. // for a better look of hatches on a multilayer board
  744. int offset = (layer * 7) / 8;
  745. min_a += offset;
  746. // loop through hatch lines
  747. #define MAXPTS 200 // Usually we store only few values per one hatch line
  748. // depending on the complexity of the zone outline
  749. static std::vector<VECTOR2I> pointbuffer;
  750. pointbuffer.clear();
  751. pointbuffer.reserve( MAXPTS + 2 );
  752. for( int a = min_a; a < max_a; a += spacing )
  753. {
  754. // get intersection points for this hatch line
  755. // Note: because we should have an even number of intersections with the
  756. // current hatch line and the zone outline (a closed polygon,
  757. // or a set of closed polygons), if an odd count is found
  758. // we skip this line (should not occur)
  759. pointbuffer.clear();
  760. // Iterate through all vertices
  761. for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
  762. {
  763. double x, y, x2, y2;
  764. int ok;
  765. SEG segment = *iterator;
  766. ok = FindLineSegmentIntersection( a, slope,
  767. segment.A.x, segment.A.y,
  768. segment.B.x, segment.B.y,
  769. &x, &y, &x2, &y2 );
  770. if( ok )
  771. {
  772. VECTOR2I point( KiROUND( x ), KiROUND( y ) );
  773. pointbuffer.push_back( point );
  774. }
  775. if( ok == 2 )
  776. {
  777. VECTOR2I point( KiROUND( x2 ), KiROUND( y2 ) );
  778. pointbuffer.push_back( point );
  779. }
  780. if( pointbuffer.size() >= MAXPTS ) // overflow
  781. {
  782. wxASSERT( 0 );
  783. break;
  784. }
  785. }
  786. // ensure we have found an even intersection points count
  787. // because intersections are the ends of segments
  788. // inside the polygon(s) and a segment has 2 ends.
  789. // if not, this is a strange case (a bug ?) so skip this hatch
  790. if( pointbuffer.size() % 2 != 0 )
  791. continue;
  792. // sort points in order of descending x (if more than 2) to
  793. // ensure the starting point and the ending point of the same segment
  794. // are stored one just after the other.
  795. if( pointbuffer.size() > 2 )
  796. sort( pointbuffer.begin(), pointbuffer.end(), sortEndsByDescendingX );
  797. // creates lines or short segments inside the complex polygon
  798. for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
  799. {
  800. int dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
  801. // Push only one line for diagonal hatch,
  802. // or for small lines < twice the line length
  803. // else push 2 small lines
  804. if( m_borderStyle == ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL
  805. || std::abs( dx ) < 2 * hatch_line_len )
  806. {
  807. m_borderHatchLines.emplace_back( SEG( pointbuffer[ip], pointbuffer[ ip + 1] ) );
  808. }
  809. else
  810. {
  811. double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
  812. slope = dy / dx;
  813. if( dx > 0 )
  814. dx = hatch_line_len;
  815. else
  816. dx = -hatch_line_len;
  817. int x1 = KiROUND( pointbuffer[ip].x + dx );
  818. int x2 = KiROUND( pointbuffer[ip + 1].x - dx );
  819. int y1 = KiROUND( pointbuffer[ip].y + dx * slope );
  820. int y2 = KiROUND( pointbuffer[ip + 1].y - dx * slope );
  821. m_borderHatchLines.emplace_back( SEG( pointbuffer[ip].x, pointbuffer[ip].y, x1, y1 ) );
  822. m_borderHatchLines.emplace_back( SEG( pointbuffer[ip+1].x, pointbuffer[ip+1].y, x2, y2 ) );
  823. }
  824. }
  825. }
  826. }
  827. int ZONE_CONTAINER::GetDefaultHatchPitch()
  828. {
  829. return Mils2iu( 20 );
  830. }
  831. BITMAP_DEF ZONE_CONTAINER::GetMenuImage() const
  832. {
  833. return add_zone_xpm;
  834. }
  835. void ZONE_CONTAINER::SwapData( BOARD_ITEM* aImage )
  836. {
  837. assert( aImage->Type() == PCB_ZONE_AREA_T );
  838. std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) );
  839. }
  840. void ZONE_CONTAINER::CacheTriangulation( PCB_LAYER_ID aLayer )
  841. {
  842. if( aLayer == UNDEFINED_LAYER )
  843. {
  844. for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
  845. pair.second.CacheTriangulation();
  846. }
  847. else
  848. {
  849. if( m_FilledPolysList.count( aLayer ) )
  850. m_FilledPolysList[ aLayer ].CacheTriangulation();
  851. }
  852. }
  853. bool ZONE_CONTAINER::IsIsland( PCB_LAYER_ID aLayer, int aPolyIdx )
  854. {
  855. if( GetNetCode() < 1 )
  856. return true;
  857. if( !m_insulatedIslands.count( aLayer ) )
  858. return false;
  859. return m_insulatedIslands.at( aLayer ).count( aPolyIdx );
  860. }
  861. void ZONE_CONTAINER::GetInteractingZones( PCB_LAYER_ID aLayer,
  862. std::vector<ZONE_CONTAINER*>* aZones ) const
  863. {
  864. int epsilon = Millimeter2iu( 0.001 );
  865. for( ZONE_CONTAINER* candidate : GetBoard()->Zones() )
  866. {
  867. if( candidate == this )
  868. continue;
  869. if( !candidate->GetLayerSet().test( aLayer ) )
  870. continue;
  871. if( candidate->GetIsRuleArea() )
  872. continue;
  873. if( candidate->GetNetCode() != GetNetCode() )
  874. continue;
  875. for( auto iter = m_Poly->CIterate(); iter; iter++ )
  876. {
  877. if( candidate->m_Poly->Collide( iter.Get(), epsilon ) )
  878. {
  879. aZones->push_back( candidate );
  880. break;
  881. }
  882. }
  883. }
  884. }
  885. bool ZONE_CONTAINER::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly, PCB_LAYER_ID aLayer,
  886. SHAPE_POLY_SET* aBoardOutline,
  887. SHAPE_POLY_SET* aSmoothedPolyWithApron ) const
  888. {
  889. if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations will not like it ...
  890. return false;
  891. if( GetIsRuleArea() )
  892. {
  893. // We like keepouts just the way they are....
  894. aSmoothedPoly = *m_Poly;
  895. return true;
  896. }
  897. BOARD* board = GetBoard();
  898. int maxError = ARC_HIGH_DEF;
  899. bool keepExternalFillets = false;
  900. if( board )
  901. {
  902. maxError = board->GetDesignSettings().m_MaxError;
  903. keepExternalFillets = board->GetDesignSettings().m_ZoneKeepExternalFillets;
  904. }
  905. auto smooth = [&]( SHAPE_POLY_SET& aPoly )
  906. {
  907. switch( m_cornerSmoothingType )
  908. {
  909. case ZONE_SETTINGS::SMOOTHING_CHAMFER:
  910. aPoly = aPoly.Chamfer( (int) m_cornerRadius );
  911. break;
  912. case ZONE_SETTINGS::SMOOTHING_FILLET:
  913. {
  914. aPoly = aPoly.Fillet( (int) m_cornerRadius, maxError );
  915. break;
  916. }
  917. default:
  918. break;
  919. }
  920. };
  921. std::vector<ZONE_CONTAINER*> interactingZones;
  922. GetInteractingZones( aLayer, &interactingZones );
  923. SHAPE_POLY_SET* maxExtents = m_Poly;
  924. SHAPE_POLY_SET withFillets;
  925. aSmoothedPoly = *m_Poly;
  926. // Should external fillets (that is, those applied to concave corners) be kept? While it
  927. // seems safer to never have copper extend outside the zone outline, 5.1.x and prior did
  928. // indeed fill them so we leave the mode available.
  929. if( keepExternalFillets )
  930. {
  931. withFillets = *m_Poly;
  932. smooth( withFillets );
  933. withFillets.BooleanAdd( *m_Poly, SHAPE_POLY_SET::PM_FAST );
  934. maxExtents = &withFillets;
  935. }
  936. for( ZONE_CONTAINER* zone : interactingZones )
  937. aSmoothedPoly.BooleanAdd( *zone->Outline(), SHAPE_POLY_SET::PM_FAST );
  938. if( !GetIsRuleArea() && aBoardOutline )
  939. aSmoothedPoly.BooleanIntersection( *aBoardOutline, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
  940. smooth( aSmoothedPoly );
  941. if( aSmoothedPolyWithApron )
  942. {
  943. SHAPE_POLY_SET bufferedExtents = *maxExtents;
  944. bufferedExtents.Inflate( m_ZoneMinThickness, 8 );
  945. *aSmoothedPolyWithApron = aSmoothedPoly;
  946. aSmoothedPolyWithApron->BooleanIntersection( bufferedExtents, SHAPE_POLY_SET::PM_FAST );
  947. }
  948. aSmoothedPoly.BooleanIntersection( *maxExtents, SHAPE_POLY_SET::PM_FAST );
  949. return true;
  950. }
  951. double ZONE_CONTAINER::CalculateFilledArea()
  952. {
  953. m_area = 0.0;
  954. // Iterate over each outline polygon in the zone and then iterate over
  955. // each hole it has to compute the total area.
  956. for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET>& pair : m_FilledPolysList )
  957. {
  958. SHAPE_POLY_SET& poly = pair.second;
  959. for( int i = 0; i < poly.OutlineCount(); i++ )
  960. {
  961. m_area += poly.Outline( i ).Area();
  962. for( int j = 0; j < poly.HoleCount( i ); j++ )
  963. m_area -= poly.Hole( i, j ).Area();
  964. }
  965. }
  966. return m_area;
  967. }
  968. /**
  969. * Function TransformSmoothedOutlineToPolygon
  970. * Convert the smoothed outline to polygons (optionally inflated by \a aClearance) and copy them
  971. * into \a aCornerBuffer.
  972. */
  973. void ZONE_CONTAINER::TransformSmoothedOutlineToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  974. int aClearance,
  975. SHAPE_POLY_SET* aBoardOutline ) const
  976. {
  977. // Creates the zone outline polygon (with holes if any)
  978. SHAPE_POLY_SET polybuffer;
  979. BuildSmoothedPoly( polybuffer, GetLayer(), aBoardOutline );
  980. // Calculate the polygon with clearance
  981. // holes are linked to the main outline, so only one polygon is created.
  982. if( aClearance )
  983. {
  984. BOARD* board = GetBoard();
  985. int maxError = ARC_HIGH_DEF;
  986. if( board )
  987. maxError = board->GetDesignSettings().m_MaxError;
  988. int segCount = GetArcToSegmentCount( aClearance, maxError, 360.0 );
  989. polybuffer.Inflate( aClearance, segCount );
  990. }
  991. polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
  992. aCornerBuffer.Append( polybuffer );
  993. }
  994. //
  995. /********* MODULE_ZONE_CONTAINER **************/
  996. //
  997. MODULE_ZONE_CONTAINER::MODULE_ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent ) :
  998. ZONE_CONTAINER( aParent, true )
  999. {
  1000. // in a footprint, net classes are not managed.
  1001. // so set the net to NETINFO_LIST::ORPHANED_ITEM
  1002. SetNetCode( -1, true );
  1003. }
  1004. MODULE_ZONE_CONTAINER::MODULE_ZONE_CONTAINER( const MODULE_ZONE_CONTAINER& aZone )
  1005. : ZONE_CONTAINER( aZone.GetParent(), true )
  1006. {
  1007. InitDataFromSrcInCopyCtor( aZone );
  1008. }
  1009. MODULE_ZONE_CONTAINER& MODULE_ZONE_CONTAINER::operator=( const MODULE_ZONE_CONTAINER& aOther )
  1010. {
  1011. ZONE_CONTAINER::operator=( aOther );
  1012. return *this;
  1013. }
  1014. EDA_ITEM* MODULE_ZONE_CONTAINER::Clone() const
  1015. {
  1016. return new MODULE_ZONE_CONTAINER( *this );
  1017. }
  1018. double MODULE_ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  1019. {
  1020. constexpr double HIDE = (double)std::numeric_limits<double>::max();
  1021. if( !aView )
  1022. return 0;
  1023. if( !aView->IsLayerVisible( LAYER_ZONES ) )
  1024. return HIDE;
  1025. bool flipped = GetParent() && GetParent()->GetLayer() == B_Cu;
  1026. // Handle Render tab switches
  1027. if( !flipped && !aView->IsLayerVisible( LAYER_MOD_FR ) )
  1028. return HIDE;
  1029. if( flipped && !aView->IsLayerVisible( LAYER_MOD_BK ) )
  1030. return HIDE;
  1031. // Other layers are shown without any conditions
  1032. return 0.0;
  1033. }
  1034. std::shared_ptr<SHAPE> ZONE_CONTAINER::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
  1035. {
  1036. std::shared_ptr<SHAPE> shape;
  1037. if( m_FilledPolysList.find( aLayer ) == m_FilledPolysList.end() )
  1038. {
  1039. shape = std::make_shared<SHAPE_NULL>();
  1040. }
  1041. else
  1042. {
  1043. shape.reset( m_FilledPolysList.at( aLayer ).Clone() );
  1044. }
  1045. return shape;
  1046. }
  1047. static struct ZONE_CONTAINER_DESC
  1048. {
  1049. ZONE_CONTAINER_DESC()
  1050. {
  1051. ENUM_MAP<ZONE_CONNECTION>::Instance()
  1052. .Map( ZONE_CONNECTION::INHERITED, _HKI( "Inherited" ) )
  1053. .Map( ZONE_CONNECTION::NONE, _HKI( "None" ) )
  1054. .Map( ZONE_CONNECTION::THERMAL, _HKI( "Thermal reliefs" ) )
  1055. .Map( ZONE_CONNECTION::FULL, _HKI( "Solid" ) )
  1056. .Map( ZONE_CONNECTION::THT_THERMAL, _HKI( "Reliefs for PTH" ) );
  1057. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  1058. REGISTER_TYPE( ZONE_CONTAINER );
  1059. propMgr.InheritsAfter( TYPE_HASH( ZONE_CONTAINER ), TYPE_HASH( BOARD_CONNECTED_ITEM ) );
  1060. propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, unsigned>( _HKI( "Priority" ),
  1061. &ZONE_CONTAINER::SetPriority, &ZONE_CONTAINER::GetPriority ) );
  1062. //propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, bool>( "Filled",
  1063. //&ZONE_CONTAINER::SetIsFilled, &ZONE_CONTAINER::IsFilled ) );
  1064. propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, wxString>( _HKI( "Name" ),
  1065. &ZONE_CONTAINER::SetZoneName, &ZONE_CONTAINER::GetZoneName ) );
  1066. propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, int>( _HKI( "Clearance" ),
  1067. &ZONE_CONTAINER::SetLocalClearance, &ZONE_CONTAINER::GetLocalClearance,
  1068. PROPERTY_DISPLAY::DISTANCE ) );
  1069. propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, int>( _HKI( "Min Width" ),
  1070. &ZONE_CONTAINER::SetMinThickness, &ZONE_CONTAINER::GetMinThickness,
  1071. PROPERTY_DISPLAY::DISTANCE ) );
  1072. propMgr.AddProperty( new PROPERTY_ENUM<ZONE_CONTAINER, ZONE_CONNECTION>( _HKI( "Pad Connections" ),
  1073. &ZONE_CONTAINER::SetPadConnection, &ZONE_CONTAINER::GetPadConnection ) );
  1074. propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, int>( _HKI( "Thermal Clearance" ),
  1075. &ZONE_CONTAINER::SetThermalReliefGap, &ZONE_CONTAINER::GetThermalReliefGap,
  1076. PROPERTY_DISPLAY::DISTANCE ) );
  1077. propMgr.AddProperty( new PROPERTY<ZONE_CONTAINER, int>( _HKI( "Thermal Spoke Width" ),
  1078. &ZONE_CONTAINER::SetThermalReliefSpokeWidth, &ZONE_CONTAINER::GetThermalReliefSpokeWidth,
  1079. PROPERTY_DISPLAY::DISTANCE ) );
  1080. }
  1081. } _ZONE_CONTAINER_DESC;
  1082. ENUM_TO_WXANY( ZONE_CONNECTION );