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.

925 lines
33 KiB

8 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef ZONE_H
  25. #define ZONE_H
  26. #include <mutex>
  27. #include <vector>
  28. #include <map>
  29. #include <gr_basic.h>
  30. #include <board_item.h>
  31. #include <board_connected_item.h>
  32. #include <layer_ids.h>
  33. #include <lset.h>
  34. #include <geometry/shape_poly_set.h>
  35. #include <zone_settings.h>
  36. #include <teardrop/teardrop_types.h>
  37. class LINE_READER;
  38. class PCB_EDIT_FRAME;
  39. class BOARD;
  40. class ZONE;
  41. class MSG_PANEL_ITEM;
  42. /**
  43. * A struct recording the isolated and single-pad islands within a zone. Each array holds
  44. * indexes into the outlines of a SHAPE_POLY_SET for a zone fill on a particular layer.
  45. *
  46. * Isolated outlines are those whose *connectivity cluster* contains no pads. These generate
  47. * DRC violations.
  48. *
  49. * Single-connection outlines are those with a *direct* connection to only a single item. These
  50. * participate in thermal spoke counting as a pad spoke to an *otherwise* unconnected island
  51. * provides no connectivity to the pad.
  52. */
  53. struct ISOLATED_ISLANDS
  54. {
  55. std::vector<int> m_IsolatedOutlines;
  56. std::vector<int> m_SingleConnectionOutlines;
  57. };
  58. /**
  59. * Handle a list of polygons defining a copper zone.
  60. *
  61. * A zone is described by a main polygon, a time stamp, a layer or a layer set, and a net name.
  62. * Other polygons inside the main polygon are holes in the zone.
  63. */
  64. class ZONE : public BOARD_CONNECTED_ITEM
  65. {
  66. public:
  67. ZONE( BOARD_ITEM_CONTAINER* parent );
  68. ZONE( const ZONE& aZone );
  69. ZONE& operator=( const ZONE &aOther );
  70. ~ZONE();
  71. void CopyFrom( const BOARD_ITEM* aOther ) override;
  72. static inline bool ClassOf( const EDA_ITEM* aItem )
  73. {
  74. return aItem && aItem->Type() == PCB_ZONE_T;
  75. }
  76. void Serialize( google::protobuf::Any &aContainer ) const override;
  77. bool Deserialize( const google::protobuf::Any &aContainer ) override;
  78. /**
  79. * Not all ZONEs are *really* BOARD_CONNECTED_ITEMs....
  80. */
  81. bool IsConnected() const override
  82. {
  83. return !GetIsRuleArea();
  84. }
  85. /**
  86. * Copy aZone data to me
  87. */
  88. void InitDataFromSrcInCopyCtor( const ZONE& aZone );
  89. /**
  90. * For rule areas which exclude footprints (and therefore participate in courtyard conflicts
  91. * during move).
  92. */
  93. bool IsConflicting() const;
  94. /**
  95. * @return a VECTOR2I, position of the first point of the outline
  96. */
  97. VECTOR2I GetPosition() const override;
  98. void SetPosition( const VECTOR2I& aPos ) override {}
  99. /**
  100. * @param aPriority is the priority level.
  101. */
  102. void SetAssignedPriority( unsigned aPriority ) { m_priority = aPriority; }
  103. /**
  104. * @return the priority level of this zone.
  105. */
  106. unsigned GetAssignedPriority() const { return m_priority; }
  107. bool HigherPriority( const ZONE* aOther ) const;
  108. bool SameNet( const ZONE* aOther ) const;
  109. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  110. wxString GetFriendlyName() const override;
  111. void SetLayerSet( const LSET& aLayerSet ) override;
  112. virtual LSET GetLayerSet() const override { return m_layerSet; }
  113. /**
  114. * Set the zone to be on the aLayerSet layers and only remove the fill polygons
  115. * from the unused layers, while keeping the fills on the layers in both the old
  116. * and new layer sets.
  117. */
  118. void SetLayerSetAndRemoveUnusedFills( const LSET& aLayerSet );
  119. ZONE_LAYER_PROPERTIES& LayerProperties( PCB_LAYER_ID aLayer )
  120. {
  121. return m_layerProperties[aLayer];
  122. }
  123. const ZONE_LAYER_PROPERTIES& LayerProperties( PCB_LAYER_ID aLayer ) const;
  124. std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES>& LayerProperties() { return m_layerProperties; }
  125. const std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES>& LayerProperties() const
  126. {
  127. return m_layerProperties;
  128. }
  129. void SetLayerProperties( const std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES>& aOther );
  130. const std::optional<VECTOR2I>& HatchingOffset( PCB_LAYER_ID aLayer ) const;
  131. const wxString& GetZoneName() const { return m_zoneName; }
  132. void SetZoneName( const wxString& aName ) { m_zoneName = aName; }
  133. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  134. {
  135. return BOARD_ITEM::Matches( GetZoneName(), aSearchData );
  136. }
  137. /**
  138. * @return the bounding box of the zone outline.
  139. */
  140. const BOX2I GetBoundingBox() const override;
  141. /**
  142. * Used to preload the zone bounding box cache so we don't have to worry about mutex-locking
  143. * it each time.
  144. */
  145. void CacheBoundingBox();
  146. /**
  147. * @return the zone's clearance in internal units.
  148. */
  149. std::optional<int> GetLocalClearance() const override;
  150. void SetLocalClearance( std::optional<int> aClearance ) { m_ZoneClearance = aClearance.value_or( 0 ); };
  151. /**
  152. * Return any local clearances set in the "classic" (ie: pre-rule) system.
  153. *
  154. * @param aSource [out] optionally reports the source as a user-readable string.
  155. * @return the clearance in internal units.
  156. */
  157. std::optional<int> GetLocalClearance( wxString* aSource ) const override
  158. {
  159. if( m_isRuleArea )
  160. return std::optional<int>();
  161. if( aSource )
  162. *aSource = _( "zone" );
  163. return GetLocalClearance();
  164. }
  165. /**
  166. * @return true if this zone is on a copper layer, false if on a technical layer.
  167. */
  168. bool IsOnCopperLayer() const override;
  169. virtual void SetLayer( PCB_LAYER_ID aLayer ) override;
  170. virtual PCB_LAYER_ID GetLayer() const override;
  171. // Return the first layer in GUI sequence.
  172. PCB_LAYER_ID GetFirstLayer() const;
  173. virtual bool IsOnLayer( PCB_LAYER_ID ) const override;
  174. virtual std::vector<int> ViewGetLayers() const override;
  175. double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
  176. void SetFillMode( ZONE_FILL_MODE aFillMode ) { m_fillMode = aFillMode; }
  177. ZONE_FILL_MODE GetFillMode() const { return m_fillMode; }
  178. void SetThermalReliefGap( int aThermalReliefGap )
  179. {
  180. if( m_thermalReliefGap != aThermalReliefGap )
  181. SetNeedRefill( true );
  182. m_thermalReliefGap = aThermalReliefGap;
  183. }
  184. int GetThermalReliefGap() const { return m_thermalReliefGap; }
  185. int GetThermalReliefGap( PAD* aPad, wxString* aSource = nullptr ) const;
  186. void SetThermalReliefSpokeWidth( int aThermalReliefSpokeWidth )
  187. {
  188. if( m_thermalReliefSpokeWidth != aThermalReliefSpokeWidth )
  189. SetNeedRefill( true );
  190. m_thermalReliefSpokeWidth = aThermalReliefSpokeWidth;
  191. }
  192. int GetThermalReliefSpokeWidth() const { return m_thermalReliefSpokeWidth; }
  193. /**
  194. * Compute the area currently occupied by the zone fill.
  195. *
  196. * @return the currently filled area
  197. */
  198. double CalculateFilledArea();
  199. /**
  200. * Compute the area of the zone outline (not the filled area).
  201. * @return the currently calculated area
  202. */
  203. double CalculateOutlineArea();
  204. /**
  205. * This area is cached from the most recent call to CalculateFilledArea().
  206. *
  207. * @return the filled area
  208. */
  209. double GetFilledArea()
  210. {
  211. return m_area;
  212. }
  213. /**
  214. * This area is cached from the most recent call to CalculateOutlineArea().
  215. *
  216. * @return the outline area
  217. */
  218. double GetOutlineArea()
  219. {
  220. return m_outlinearea;
  221. }
  222. std::mutex& GetLock()
  223. {
  224. return m_lock;
  225. }
  226. int GetFillFlag( PCB_LAYER_ID aLayer )
  227. {
  228. return m_fillFlags.test( aLayer );
  229. }
  230. void SetFillFlag( PCB_LAYER_ID aLayer, bool aFlag ) { m_fillFlags.set( aLayer, aFlag ); }
  231. bool IsFilled() const { return m_isFilled; }
  232. void SetIsFilled( bool isFilled ) { m_isFilled = isFilled; }
  233. bool NeedRefill() const { return m_needRefill; }
  234. void SetNeedRefill( bool aNeedRefill ) { m_needRefill = aNeedRefill; }
  235. ZONE_CONNECTION GetPadConnection() const { return m_PadConnection; }
  236. void SetPadConnection( ZONE_CONNECTION aPadConnection ) { m_PadConnection = aPadConnection; }
  237. int GetMinThickness() const { return m_ZoneMinThickness; }
  238. void SetMinThickness( int aMinThickness )
  239. {
  240. m_ZoneMinThickness = aMinThickness;
  241. m_hatchThickness = std::max( m_hatchThickness, aMinThickness );
  242. m_hatchGap = std::max( m_hatchGap, aMinThickness );
  243. SetNeedRefill( true );
  244. }
  245. int GetHatchThickness() const { return m_hatchThickness; }
  246. void SetHatchThickness( int aThickness ) { m_hatchThickness = aThickness; }
  247. int GetHatchGap() const { return m_hatchGap; }
  248. void SetHatchGap( int aStep ) { m_hatchGap = aStep; }
  249. EDA_ANGLE GetHatchOrientation() const { return m_hatchOrientation; }
  250. void SetHatchOrientation( const EDA_ANGLE& aStep ) { m_hatchOrientation = aStep; }
  251. int GetHatchSmoothingLevel() const { return m_hatchSmoothingLevel; }
  252. void SetHatchSmoothingLevel( int aLevel ) { m_hatchSmoothingLevel = aLevel; }
  253. double GetHatchSmoothingValue() const { return m_hatchSmoothingValue; }
  254. void SetHatchSmoothingValue( double aValue ) { m_hatchSmoothingValue = aValue; }
  255. double GetHatchHoleMinArea() const { return m_hatchHoleMinArea; }
  256. void SetHatchHoleMinArea( double aPct ) { m_hatchHoleMinArea = aPct; }
  257. int GetHatchBorderAlgorithm() const { return m_hatchBorderAlgorithm; }
  258. void SetHatchBorderAlgorithm( int aAlgo ) { m_hatchBorderAlgorithm = aAlgo; }
  259. ///
  260. int GetLocalFlags() const { return m_localFlgs; }
  261. void SetLocalFlags( int aFlags ) { m_localFlgs = aFlags; }
  262. SHAPE_POLY_SET* Outline() { return m_Poly; }
  263. const SHAPE_POLY_SET* Outline() const { return m_Poly; }
  264. void SetOutline( SHAPE_POLY_SET* aOutline ) { m_Poly = aOutline; }
  265. // @copydoc BOARD_ITEM::GetEffectiveShape
  266. virtual std::shared_ptr<SHAPE>
  267. GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  268. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  269. /**
  270. * Test if a point is near an outline edge or a corner of this zone.
  271. *
  272. * @param aPosition the VECTOR2I to test
  273. * @return true if a hit, else false
  274. */
  275. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  276. /**
  277. * Test if the given VECTOR2I is within the bounds of a filled area of this zone.
  278. *
  279. * @param aLayer is the layer to test on
  280. * @param aRefPos A VECTOR2I to test
  281. * @param aAccuracy Expand the distance by which the areas are expanded for the hittest
  282. * @return true if a hit, else false
  283. */
  284. bool HitTestFilledArea( PCB_LAYER_ID aLayer, const VECTOR2I& aRefPos, int aAccuracy = 0 ) const;
  285. /**
  286. * Test if the given point is contained within a cutout of the zone.
  287. *
  288. * @param aRefPos is the point to test
  289. * @param aOutlineIdx is the index of the outline containing the cutout
  290. * @param aHoleIdx is the index of the hole
  291. * @return true if aRefPos is inside a zone cutout
  292. */
  293. bool HitTestCutout( const VECTOR2I& aRefPos, int* aOutlineIdx = nullptr,
  294. int* aHoleIdx = nullptr ) const;
  295. /**
  296. * Some intersecting zones, despite being on the same layer with the same net, cannot be
  297. * merged due to other parameters such as fillet radius. The copper pour will end up
  298. * effectively merged though, so we need to do some calculations with them in mind.
  299. */
  300. void GetInteractingZones( PCB_LAYER_ID aLayer, std::vector<ZONE*>* aSameNetCollidingZones,
  301. std::vector<ZONE*>* aOtherNetIntersectingZones ) const;
  302. /**
  303. * Convert solid areas full shapes to polygon set
  304. * (the full shape is the polygon area with a thick outline)
  305. * Used in 3D view
  306. * Arcs (ends of segments) are approximated by segments
  307. *
  308. * @param aLayer is the layer of the zone to retrieve
  309. * @param aBuffer = a buffer to store the polygons
  310. * @param aError = Maximum error allowed between true arc and polygon approx
  311. */
  312. void TransformSolidAreasShapesToPolygon( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aBuffer ) const;
  313. /**
  314. * Convert the outlines shape to a polygon with no holes
  315. * inflated (optional) by max( aClearanceValue, the zone clearance)
  316. * (holes are linked to external outline by overlapping segments)
  317. * Used in filling zones calculations
  318. * Circles (vias) and arcs (ends of tracks) are approximated by segments.
  319. *
  320. * @param aBuffer is a buffer to store the polygon
  321. * @param aClearance is the min clearance around outlines
  322. * @param aBoardOutline is the board outline (if a valid one exists; nullptr otherwise)
  323. */
  324. void TransformSmoothedOutlineToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance,
  325. int aError, ERROR_LOC aErrorLoc,
  326. SHAPE_POLY_SET* aBoardOutline ) const;
  327. /**
  328. * Convert the zone shape to a closed polygon
  329. * Used in filling zones calculations
  330. * Circles and arcs are approximated by segments
  331. *
  332. * @param aLayer is the layer of the filled zone to retrieve
  333. * @param aBuffer is a buffer to store the polygon
  334. * @param aClearance is the clearance around the pad
  335. * @param aError is the maximum deviation from true circle
  336. * @param ignoreLineWidth is used for edge cut items where the line width is only for
  337. * visualization
  338. */
  339. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
  340. int aClearance, int aError, ERROR_LOC aErrorLoc,
  341. bool ignoreLineWidth = false ) const override;
  342. /**
  343. * Test if the given VECTOR2I is near a corner.
  344. *
  345. * @param refPos is the VECTOR2I to test.
  346. * @param aAccuracy increase the item bounding box by this amount.
  347. * @param aCornerHit [out, optional] is the index of the closest vertex found when return
  348. * value is true
  349. * @return true if some corner was found to be closer to refPos than aClearance; false
  350. * otherwise.
  351. */
  352. bool HitTestForCorner( const VECTOR2I& refPos, int aAccuracy,
  353. SHAPE_POLY_SET::VERTEX_INDEX* aCornerHit = nullptr ) const;
  354. /**
  355. * Test if the given VECTOR2I is near a segment defined by 2 corners.
  356. *
  357. * @param refPos is the VECTOR2I to test.
  358. * @param aAccuracy increase the item bounding box by this amount.
  359. * @param aCornerHit [out, optional] is the index of the closest vertex found when return
  360. * value is true.
  361. * @return true if some edge was found to be closer to refPos than aClearance.
  362. */
  363. bool HitTestForEdge( const VECTOR2I& refPos, int aAccuracy,
  364. SHAPE_POLY_SET::VERTEX_INDEX* aCornerHit = nullptr ) const;
  365. /**
  366. * @copydoc BOARD_ITEM::HitTest(const BOX2I& aRect, bool aContained, int aAccuracy) const
  367. */
  368. bool HitTest( const BOX2I& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  369. /**
  370. * Removes the zone filling.
  371. *
  372. * @return true if a previous filling is removed, false if no change (when no filling found).
  373. */
  374. bool UnFill();
  375. /* Geometric transformations: */
  376. /**
  377. * Move the outlines
  378. *
  379. * @param offset is moving vector
  380. */
  381. void Move( const VECTOR2I& offset ) override;
  382. /**
  383. * Move the outline Edge.
  384. *
  385. * @param offset is moving vector
  386. * @param aEdge is start point of the outline edge
  387. */
  388. void MoveEdge( const VECTOR2I& offset, int aEdge );
  389. /**
  390. * Rotate the outlines.
  391. *
  392. * @param aCentre is rot centre
  393. */
  394. void Rotate( const VECTOR2I& aCentre, const EDA_ANGLE& aAngle ) override;
  395. /**
  396. * Flip this object, i.e. change the board side for this object
  397. * (like Mirror() but changes layer).
  398. *
  399. * @param aCentre is the rotation point.
  400. * @param aFlipDirection is the direction of the flip.
  401. */
  402. virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  403. /**
  404. * Mirror the outlines relative to a given horizontal axis the layer is not changed.
  405. *
  406. * @param aMirrorRef is axis position
  407. * @param aFlipDirection is the direction of the flip.
  408. */
  409. void Mirror( const VECTOR2I& aMirrorRef, FLIP_DIRECTION aFlipDirection ) override;
  410. /**
  411. * @return the class name.
  412. */
  413. wxString GetClass() const override
  414. {
  415. return wxT( "ZONE" );
  416. }
  417. /**
  418. * Access to m_Poly parameters
  419. */
  420. int GetNumCorners( void ) const
  421. {
  422. return m_Poly->TotalVertices();
  423. }
  424. /**
  425. * Return an iterator to visit all points of the zone's main outline without holes.
  426. *
  427. * @return an iterator to visit the zone vertices without holes.
  428. */
  429. SHAPE_POLY_SET::ITERATOR Iterate()
  430. {
  431. return m_Poly->Iterate();
  432. }
  433. /**
  434. * Return an iterator to visit all points of the zone's main outline with holes.
  435. *
  436. * @return an iterator to visit the zone vertices with holes.
  437. */
  438. SHAPE_POLY_SET::ITERATOR IterateWithHoles()
  439. {
  440. return m_Poly->IterateWithHoles();
  441. }
  442. /**
  443. * Return an iterator to visit all points of the zone's main outline with holes.
  444. *
  445. * @return an iterator to visit the zone vertices with holes.
  446. */
  447. SHAPE_POLY_SET::CONST_ITERATOR CIterateWithHoles() const
  448. {
  449. return m_Poly->CIterateWithHoles();
  450. }
  451. void RemoveAllContours( void )
  452. {
  453. m_Poly->RemoveAllContours();
  454. }
  455. const VECTOR2I& GetCornerPosition( int aCornerIndex ) const
  456. {
  457. SHAPE_POLY_SET::VERTEX_INDEX index;
  458. // Convert global to relative indices
  459. if( !m_Poly->GetRelativeIndices( aCornerIndex, &index ) )
  460. throw( std::out_of_range( "aCornerIndex-th vertex does not exist" ) );
  461. return m_Poly->CVertex( index );
  462. }
  463. /**
  464. * Create a new hole on the zone; i.e., a new contour on the zone's outline.
  465. */
  466. void NewHole()
  467. {
  468. m_Poly->NewHole();
  469. }
  470. /**
  471. * Add a new corner to the zone outline (to the main outline or a hole)
  472. *
  473. * @param aPosition is the position of the new corner.
  474. * @param aHoleIdx is the index of the hole (-1 for the main outline, >= 0 for hole).
  475. * @param aAllowDuplication is a flag to indicate whether it is allowed to add this corner
  476. * even if it is duplicated.
  477. * @return true if the corner was added, false if error (aHoleIdx > hole count -1)
  478. */
  479. bool AppendCorner( VECTOR2I aPosition, int aHoleIdx, bool aAllowDuplication = false );
  480. ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const { return m_borderStyle; }
  481. void SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE aStyle ) { m_borderStyle = aStyle; }
  482. bool HasFilledPolysForLayer( PCB_LAYER_ID aLayer ) const
  483. {
  484. return m_FilledPolysList.count( aLayer ) > 0;
  485. }
  486. /**
  487. * @return a reference to the list of filled polygons.
  488. */
  489. const std::shared_ptr<SHAPE_POLY_SET>& GetFilledPolysList( PCB_LAYER_ID aLayer ) const
  490. {
  491. wxASSERT( m_FilledPolysList.count( aLayer ) );
  492. return m_FilledPolysList.at( aLayer );
  493. }
  494. SHAPE_POLY_SET* GetFill( PCB_LAYER_ID aLayer )
  495. {
  496. wxASSERT( m_FilledPolysList.count( aLayer ) );
  497. return m_FilledPolysList.at( aLayer ).get();
  498. }
  499. /**
  500. * Create a list of triangles that "fill" the solid areas used for instance to draw
  501. * these solid areas on OpenGL.
  502. */
  503. void CacheTriangulation( PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
  504. /**
  505. * Set the list of filled polygons.
  506. */
  507. void SetFilledPolysList( PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPolysList )
  508. {
  509. m_FilledPolysList[aLayer] = std::make_shared<SHAPE_POLY_SET>( aPolysList );
  510. }
  511. /**
  512. * Check if a given filled polygon is an insulated island.
  513. *
  514. * @param aLayer is the layer to test
  515. * @param aPolyIdx is an index into m_FilledPolysList[aLayer]
  516. * @return true if the given polygon is insulated (i.e. has no net connection)
  517. */
  518. bool IsIsland( PCB_LAYER_ID aLayer, int aPolyIdx ) const;
  519. void SetIsIsland( PCB_LAYER_ID aLayer, int aPolyIdx )
  520. {
  521. m_insulatedIslands[aLayer].insert( aPolyIdx );
  522. }
  523. bool BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly, PCB_LAYER_ID aLayer,
  524. SHAPE_POLY_SET* aBoardOutline,
  525. SHAPE_POLY_SET* aSmoothedPolyWithApron = nullptr ) const;
  526. void SetCornerSmoothingType( int aType ) { m_cornerSmoothingType = aType; };
  527. int GetCornerSmoothingType() const { return m_cornerSmoothingType; }
  528. void SetCornerRadius( unsigned int aRadius );
  529. unsigned int GetCornerRadius() const { return m_cornerRadius; }
  530. /**
  531. * Remove a cutout from the zone.
  532. *
  533. * @param aOutlineIdx is the zone outline the hole belongs to
  534. * @param aHoleIdx is the hole in the outline to remove
  535. */
  536. void RemoveCutout( int aOutlineIdx, int aHoleIdx );
  537. /**
  538. * Add a polygon to the zone outline.
  539. *
  540. * If the zone outline is empty, this is the main outline. Otherwise it is a hole
  541. * inside the main outline.
  542. */
  543. void AddPolygon( std::vector<VECTOR2I>& aPolygon );
  544. void AddPolygon( const SHAPE_LINE_CHAIN& aPolygon );
  545. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  546. BITMAPS GetMenuImage() const override;
  547. EDA_ITEM* Clone() const override;
  548. /**
  549. * @return true if the zone is a teardrop area
  550. */
  551. bool IsTeardropArea() const { return m_teardropType != TEARDROP_TYPE::TD_NONE; }
  552. /**
  553. * Set the type of teardrop if the zone is a teardrop area
  554. * for non teardrop area, the type must be TEARDROP_TYPE::TD_NONE
  555. */
  556. void SetTeardropAreaType( TEARDROP_TYPE aType ) { m_teardropType = aType; }
  557. /**
  558. * @return the type of the teardrop ( has meaning only if the zone is a teardrop area)
  559. */
  560. TEARDROP_TYPE GetTeardropAreaType() const { return m_teardropType; }
  561. /**
  562. * Accessor to determine if any keepout parameters are set
  563. */
  564. bool HasKeepoutParametersSet() const
  565. {
  566. return m_doNotAllowTracks || m_doNotAllowVias || m_doNotAllowPads || m_doNotAllowFootprints
  567. || m_doNotAllowZoneFills;
  568. }
  569. /**
  570. * Accessors to parameters used in Rule Area zones:
  571. */
  572. bool GetIsRuleArea() const { return m_isRuleArea; }
  573. void SetIsRuleArea( bool aEnable ) { m_isRuleArea = aEnable; }
  574. bool GetPlacementAreaEnabled() const { return m_placementAreaEnabled; }
  575. void SetPlacementAreaEnabled( bool aEnabled ) { m_placementAreaEnabled = aEnabled; }
  576. wxString GetPlacementAreaSource() const { return m_placementAreaSource; }
  577. void SetPlacementAreaSource( const wxString& aSource ) { m_placementAreaSource = aSource; }
  578. PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
  579. {
  580. return m_placementAreaSourceType;
  581. }
  582. void SetPlacementAreaSourceType( PLACEMENT_SOURCE_T aType )
  583. { m_placementAreaSourceType = aType;
  584. }
  585. bool GetDoNotAllowZoneFills() const { return m_doNotAllowZoneFills; }
  586. bool GetDoNotAllowVias() const { return m_doNotAllowVias; }
  587. bool GetDoNotAllowTracks() const { return m_doNotAllowTracks; }
  588. bool GetDoNotAllowPads() const { return m_doNotAllowPads; }
  589. bool GetDoNotAllowFootprints() const { return m_doNotAllowFootprints; }
  590. void SetDoNotAllowZoneFills( bool aEnable ) { m_doNotAllowZoneFills = aEnable; }
  591. void SetDoNotAllowVias( bool aEnable ) { m_doNotAllowVias = aEnable; }
  592. void SetDoNotAllowTracks( bool aEnable ) { m_doNotAllowTracks = aEnable; }
  593. void SetDoNotAllowPads( bool aEnable ) { m_doNotAllowPads = aEnable; }
  594. void SetDoNotAllowFootprints( bool aEnable ) { m_doNotAllowFootprints = aEnable; }
  595. ISLAND_REMOVAL_MODE GetIslandRemovalMode() const { return m_islandRemovalMode; }
  596. void SetIslandRemovalMode( ISLAND_REMOVAL_MODE aRemove ) { m_islandRemovalMode = aRemove; }
  597. long long int GetMinIslandArea() const { return m_minIslandArea; }
  598. void SetMinIslandArea( long long int aArea ) { m_minIslandArea = aArea; }
  599. /**
  600. * HatchBorder related methods
  601. */
  602. /**
  603. * @return the zone hatch pitch in iu.
  604. */
  605. int GetBorderHatchPitch() const { return m_borderHatchPitch; }
  606. void SetBorderHatchPitch( int aPitch ) { m_borderHatchPitch = aPitch; }
  607. /**
  608. * @return the default hatch pitch in internal units.
  609. */
  610. static int GetDefaultHatchPitch();
  611. /**
  612. * Set all hatch parameters for the zone.
  613. *
  614. * @param aBorderHatchStyle is the style of the hatch, specified as one of HATCH_STYLE
  615. possible values.
  616. * @param aBorderHatchPitch is the hatch pitch in iu.
  617. * @param aRebuildBorderHatch is a flag to indicate whether to re-hatch after having set the
  618. * previous parameters.
  619. */
  620. void SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch,
  621. bool aRebuilBorderdHatch );
  622. /**
  623. * Clear the zone's hatch.
  624. */
  625. void UnHatchBorder();
  626. /**
  627. * Compute the hatch lines depending on the hatch parameters and stores it in the zone's
  628. * attribute m_borderHatchLines.
  629. */
  630. void HatchBorder();
  631. const std::vector<SEG>& GetHatchLines() const { return m_borderHatchLines; }
  632. /**
  633. * Build the hash value of m_FilledPolysList, and store it internally in m_filledPolysHash.
  634. * Used in zone filling calculations, to know if m_FilledPolysList is up to date.
  635. */
  636. void BuildHashValue( PCB_LAYER_ID aLayer );
  637. /**
  638. * @return the hash value previously calculated by BuildHashValue().
  639. */
  640. HASH_128 GetHashValue( PCB_LAYER_ID aLayer );
  641. double Similarity( const BOARD_ITEM& aOther ) const override;
  642. bool operator==( const ZONE& aOther ) const;
  643. bool operator==( const BOARD_ITEM& aOther ) const override;
  644. #if defined(DEBUG)
  645. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  646. void SetFillPoly( PCB_LAYER_ID aLayer, SHAPE_POLY_SET* aPoly )
  647. {
  648. m_FilledPolysList[ aLayer ] = std::make_shared<SHAPE_POLY_SET>( *aPoly );
  649. SetFillFlag( aLayer, true );
  650. }
  651. #endif
  652. protected:
  653. virtual void swapData( BOARD_ITEM* aImage ) override;
  654. protected:
  655. SHAPE_POLY_SET* m_Poly; ///< Outline of the zone.
  656. int m_cornerSmoothingType;
  657. unsigned int m_cornerRadius;
  658. /// An optional unique name for this zone, used for identifying it in DRC checking
  659. wxString m_zoneName;
  660. LSET m_layerSet;
  661. std::map<PCB_LAYER_ID, ZONE_LAYER_PROPERTIES> m_layerProperties;
  662. /* Priority: when a zone outline is inside and other zone, if its priority is higher
  663. * the other zone priority, it will be created inside.
  664. * if priorities are equal, a DRC error is set
  665. */
  666. unsigned m_priority;
  667. /* A zone outline can be a keepout zone.
  668. * It will be never filled, and DRC should test for pads, tracks and vias
  669. */
  670. bool m_isRuleArea;
  671. /**
  672. * Placement rule area data
  673. */
  674. bool m_placementAreaEnabled;
  675. PLACEMENT_SOURCE_T m_placementAreaSourceType;
  676. wxString m_placementAreaSource;
  677. /* A zone outline can be a teardrop zone with different rules for priority
  678. * (always bigger priority than copper zones) and never removed from a
  679. * copper zone having the same netcode
  680. */
  681. TEARDROP_TYPE m_teardropType;
  682. /* For keepout zones only:
  683. * what is not allowed inside the keepout ( pads, tracks and vias )
  684. */
  685. bool m_doNotAllowZoneFills;
  686. bool m_doNotAllowVias;
  687. bool m_doNotAllowTracks;
  688. bool m_doNotAllowPads;
  689. bool m_doNotAllowFootprints;
  690. ZONE_CONNECTION m_PadConnection;
  691. int m_ZoneClearance; // Clearance value in internal units.
  692. int m_ZoneMinThickness; // Minimum thickness value in filled areas.
  693. int m_fillVersion; // See BOARD_DESIGN_SETTINGS for version
  694. // differences.
  695. ISLAND_REMOVAL_MODE m_islandRemovalMode;
  696. /**
  697. * When island removal mode is set to AREA, islands below this area will be removed.
  698. * If this value is negative, all islands will be removed.
  699. */
  700. long long int m_minIslandArea;
  701. /** True when a zone was filled, false after deleting the filled areas. */
  702. bool m_isFilled;
  703. /**
  704. * False when a zone was refilled, true after changes in zone params.
  705. * m_needRefill = false does not imply filled areas are up to date, just
  706. * the zone was refilled after edition, and does not need refilling
  707. */
  708. bool m_needRefill;
  709. int m_thermalReliefGap; // Width of the gap in thermal reliefs.
  710. int m_thermalReliefSpokeWidth; // Width of the copper bridge in thermal reliefs.
  711. ZONE_FILL_MODE m_fillMode; // fill with POLYGONS vs HATCH_PATTERN
  712. int m_hatchThickness; // thickness of lines (if 0 -> solid shape)
  713. int m_hatchGap; // gap between lines (0 -> solid shape
  714. EDA_ANGLE m_hatchOrientation; // orientation of grid lines
  715. int m_hatchSmoothingLevel; // 0 = no smoothing
  716. // 1 = fillet
  717. // 2 = arc low def
  718. // 3 = arc high def
  719. double m_hatchSmoothingValue; // hole chamfer/fillet size (ratio of hole size)
  720. double m_hatchHoleMinArea; // min size before holes are dropped (ratio)
  721. int m_hatchBorderAlgorithm; // 0 = use min zone thickness
  722. // 1 = use hatch thickness
  723. int m_localFlgs; // Variable used in polygon calculations.
  724. /* set of filled polygons used to draw a zone as a filled area.
  725. * from outlines (m_Poly) but unlike m_Poly these filled polygons have no hole
  726. * (they are all in one piece) In very simple cases m_FilledPolysList is same
  727. * as m_Poly. In less simple cases (when m_Poly has holes) m_FilledPolysList is
  728. * a polygon equivalent to m_Poly, without holes but with extra outline segment
  729. * connecting "holes" with external main outline. In complex cases an outline
  730. * described by m_Poly can have many filled areas
  731. */
  732. std::map<PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>> m_FilledPolysList;
  733. /// Temp variables used while filling
  734. LSET m_fillFlags;
  735. /// A hash value used in zone filling calculations to see if the filled areas are up to date
  736. std::map<PCB_LAYER_ID, HASH_128> m_filledPolysHash;
  737. ZONE_BORDER_DISPLAY_STYLE m_borderStyle; // border display style, see enum above
  738. int m_borderHatchPitch; // for DIAGONAL_EDGE, distance between 2 lines
  739. std::vector<SEG> m_borderHatchLines; // hatch lines
  740. /// For each layer, a set of insulated islands that were not removed
  741. std::map<PCB_LAYER_ID, std::set<int>> m_insulatedIslands;
  742. double m_area; // The filled zone area
  743. double m_outlinearea; // The outline zone area
  744. /// Lock used for multi-threaded filling on multi-layer zones
  745. std::mutex m_lock;
  746. };
  747. #ifndef SWIG
  748. DECLARE_ENUM_TO_WXANY( ZONE_CONNECTION )
  749. DECLARE_ENUM_TO_WXANY( ZONE_FILL_MODE )
  750. DECLARE_ENUM_TO_WXANY( ISLAND_REMOVAL_MODE )
  751. DECLARE_ENUM_TO_WXANY( PLACEMENT_SOURCE_T )
  752. #endif
  753. #endif // ZONE_H