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.

807 lines
28 KiB

14 years ago
8 years ago
7 years ago
14 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 (C) 1992-2019 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. /**
  25. * @file class_zone.h
  26. */
  27. #ifndef CLASS_ZONE_H_
  28. #define CLASS_ZONE_H_
  29. #include <vector>
  30. #include <gr_basic.h>
  31. #include <class_board_item.h>
  32. #include <board_connected_item.h>
  33. #include <layers_id_colors_and_visibility.h>
  34. #include <geometry/shape_poly_set.h>
  35. #include <zone_settings.h>
  36. class EDA_RECT;
  37. class LINE_READER;
  38. class PCB_EDIT_FRAME;
  39. class BOARD;
  40. class ZONE_CONTAINER;
  41. class MSG_PANEL_ITEM;
  42. typedef std::vector<SEG> ZONE_SEGMENT_FILL;
  43. /**
  44. * Class ZONE_CONTAINER
  45. * handles a list of polygons defining a copper zone.
  46. * A zone is described by a main polygon, a time stamp, a layer, and a net name.
  47. * Other polygons inside the main polygon are holes in the zone.
  48. */
  49. class ZONE_CONTAINER : public BOARD_CONNECTED_ITEM
  50. {
  51. public:
  52. /**
  53. * Zone hatch styles
  54. */
  55. typedef enum HATCH_STYLE { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE } HATCH_STYLE;
  56. ZONE_CONTAINER( BOARD* parent );
  57. ZONE_CONTAINER( const ZONE_CONTAINER& aZone );
  58. ZONE_CONTAINER& operator=( const ZONE_CONTAINER &aOther );
  59. ~ZONE_CONTAINER();
  60. static inline bool ClassOf( const EDA_ITEM* aItem )
  61. {
  62. return aItem && aItem->Type() == PCB_ZONE_AREA_T;
  63. }
  64. /**
  65. * @return a wxPoint, position of the first point of the outline
  66. */
  67. const wxPoint GetPosition() const override;
  68. void SetPosition( const wxPoint& aPos ) override {}
  69. /**
  70. * Function SetPriority
  71. * @param aPriority = the priority level
  72. */
  73. void SetPriority( unsigned aPriority ) { m_priority = aPriority; }
  74. /**
  75. * Function GetPriority
  76. * @return the priority level of this zone
  77. */
  78. unsigned GetPriority() const { return m_priority; }
  79. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
  80. void SetLayerSet( LSET aLayerSet );
  81. virtual LSET GetLayerSet() const override;
  82. /**
  83. * Function Print
  84. * Prints the zone outline.
  85. * @param aFrame = current Frame
  86. * @param DC = current Device Context
  87. * @param aDrawMode = GR_OR, GR_XOR, GR_COPY ..
  88. * @param offset = Draw offset (usually wxPoint(0,0))
  89. */
  90. void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset = ZeroOffset ) override;
  91. /**
  92. * Function PrintFilledArea
  93. * Draws the filled area for this zone (polygon list .m_FilledPolysList)
  94. * @param aFrame = current Frame
  95. * @param DC = current Device Context
  96. * @param offset = Draw offset (usually wxPoint(0,0))
  97. * @param aDrawMode = GR_OR, GR_XOR, GR_COPY ..
  98. */
  99. void PrintFilledArea( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset = ZeroOffset );
  100. /** Function GetBoundingBox (virtual)
  101. * @return an EDA_RECT that is the bounding box of the zone outline
  102. */
  103. const EDA_RECT GetBoundingBox() const override;
  104. int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const override;
  105. /**
  106. * Function IsOnCopperLayer
  107. * @return true if this zone is on a copper layer, false if on a technical layer
  108. */
  109. bool IsOnCopperLayer() const;
  110. /**
  111. * Function CommonLayerExist
  112. * Test if this zone shares a common layer with the given layer set
  113. */
  114. bool CommonLayerExists( const LSET aLayerSet ) const;
  115. virtual void SetLayer( PCB_LAYER_ID aLayer ) override;
  116. virtual PCB_LAYER_ID GetLayer() const override;
  117. virtual bool IsOnLayer( PCB_LAYER_ID ) const override;
  118. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  119. void SetFillMode( ZONE_FILL_MODE aFillMode ) { m_FillMode = aFillMode; }
  120. ZONE_FILL_MODE GetFillMode() const { return m_FillMode; }
  121. void SetThermalReliefGap( int aThermalReliefGap ) { m_ThermalReliefGap = aThermalReliefGap; }
  122. int GetThermalReliefGap( D_PAD* aPad = NULL ) const;
  123. void SetThermalReliefCopperBridge( int aThermalReliefCopperBridge )
  124. {
  125. if( m_ThermalReliefCopperBridge != aThermalReliefCopperBridge )
  126. SetNeedRefill( true );
  127. m_ThermalReliefCopperBridge = aThermalReliefCopperBridge;
  128. }
  129. int GetThermalReliefCopperBridge( D_PAD* aPad = NULL ) const;
  130. bool IsFilled() const { return m_IsFilled; }
  131. void SetIsFilled( bool isFilled ) { m_IsFilled = isFilled; }
  132. bool NeedRefill() const { return m_needRefill; }
  133. void SetNeedRefill( bool aNeedRefill ) { m_needRefill = aNeedRefill; }
  134. int GetZoneClearance() const { return m_ZoneClearance; }
  135. void SetZoneClearance( int aZoneClearance ) { m_ZoneClearance = aZoneClearance; }
  136. ZoneConnection GetPadConnection( D_PAD* aPad = NULL ) const;
  137. void SetPadConnection( ZoneConnection aPadConnection ) { m_PadConnection = aPadConnection; }
  138. int GetMinThickness() const { return m_ZoneMinThickness; }
  139. void SetMinThickness( int aMinThickness )
  140. {
  141. if( m_ZoneMinThickness != aMinThickness )
  142. SetNeedRefill( true );
  143. m_ZoneMinThickness = aMinThickness;
  144. }
  145. int GetHatchFillTypeThickness() const { return m_HatchFillTypeThickness; }
  146. void SetHatchFillTypeThickness( int aThickness ) { m_HatchFillTypeThickness = aThickness; }
  147. int GetHatchFillTypeGap() const { return m_HatchFillTypeGap; }
  148. void SetHatchFillTypeGap( int aStep ) { m_HatchFillTypeGap = aStep; }
  149. double GetHatchFillTypeOrientation() const { return m_HatchFillTypeOrientation; }
  150. void SetHatchFillTypeOrientation( double aStep ) { m_HatchFillTypeOrientation = aStep; }
  151. int GetHatchFillTypeSmoothingLevel() const { return m_HatchFillTypeSmoothingLevel; }
  152. void SetHatchFillTypeSmoothingLevel( int aLevel ) { m_HatchFillTypeSmoothingLevel = aLevel; }
  153. double GetHatchFillTypeSmoothingValue() const { return m_HatchFillTypeSmoothingValue; }
  154. void SetHatchFillTypeSmoothingValue( double aValue ) { m_HatchFillTypeSmoothingValue = aValue; }
  155. int GetSelectedCorner() const
  156. {
  157. // Transform relative indices to global index
  158. int globalIndex = -1;
  159. if( m_CornerSelection )
  160. m_Poly->GetGlobalIndex( *m_CornerSelection, globalIndex );
  161. return globalIndex;
  162. }
  163. void SetSelectedCorner( int aCorner )
  164. {
  165. SHAPE_POLY_SET::VERTEX_INDEX selectedCorner;
  166. // If the global index of the corner is correct, assign it to m_CornerSelection
  167. if( m_Poly->GetRelativeIndices( aCorner, &selectedCorner ) )
  168. {
  169. if( m_CornerSelection == nullptr )
  170. m_CornerSelection = new SHAPE_POLY_SET::VERTEX_INDEX;
  171. *m_CornerSelection = selectedCorner;
  172. }
  173. else
  174. throw( std::out_of_range( "aCorner-th vertex does not exist" ) );
  175. }
  176. ///
  177. // Like HitTest but selects the current corner to be operated on
  178. void SetSelectedCorner( const wxPoint& aPosition, int aAccuracy );
  179. int GetLocalFlags() const { return m_localFlgs; }
  180. void SetLocalFlags( int aFlags ) { m_localFlgs = aFlags; }
  181. ZONE_SEGMENT_FILL& FillSegments() { return m_FillSegmList; }
  182. const ZONE_SEGMENT_FILL& FillSegments() const { return m_FillSegmList; }
  183. SHAPE_POLY_SET* Outline() { return m_Poly; }
  184. const SHAPE_POLY_SET* Outline() const { return const_cast< SHAPE_POLY_SET* >( m_Poly ); }
  185. void SetOutline( SHAPE_POLY_SET* aOutline ) { m_Poly = aOutline; }
  186. /**
  187. * Function HitTest
  188. * tests if a point is near an outline edge or a corner of this zone.
  189. * @param aPosition the wxPoint to test
  190. * @return bool - true if a hit, else false
  191. */
  192. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  193. /**
  194. * Function HitTest
  195. * tests if a point is inside the zone area, i.e. inside the main outline
  196. * and outside holes.
  197. * @param aPosition : the wxPoint to test
  198. * @return bool - true if a hit, else false
  199. */
  200. bool HitTestInsideZone( const wxPoint& aPosition ) const
  201. {
  202. return m_Poly->Contains( VECTOR2I( aPosition ), 0 );
  203. }
  204. /**
  205. * Function HitTestFilledArea
  206. * tests if the given wxPoint is within the bounds of a filled area of this zone.
  207. * @param aRefPos A wxPoint to test
  208. * @return bool - true if a hit, else false
  209. */
  210. bool HitTestFilledArea( const wxPoint& aRefPos ) const;
  211. /**
  212. * Function TransformSolidAreasShapesToPolygonSet
  213. * Convert solid areas full shapes to polygon set
  214. * (the full shape is the polygon area with a thick outline)
  215. * Used in 3D view
  216. * Arcs (ends of segments) are approximated by segments
  217. * @param aCornerBuffer = a buffer to store the polygons
  218. * @param aError = Maximum error allowed between true arc and polygon approx
  219. */
  220. void TransformSolidAreasShapesToPolygonSet(
  221. SHAPE_POLY_SET& aCornerBuffer, int aError = ARC_HIGH_DEF ) const;
  222. /**
  223. * Function TransformOutlinesShapeWithClearanceToPolygon
  224. * Convert the outlines shape to a polygon with no holes
  225. * inflated (optional) by max( aClearanceValue, the zone clearance)
  226. * (holes are linked to external outline by overlapping segments)
  227. * Used in filling zones calculations
  228. * Circles (vias) and arcs (ends of tracks) are approximated by segments
  229. * @param aCornerBuffer = a buffer to store the polygon
  230. * @param aMinClearanceValue = the min clearance around outlines
  231. * @param aUseNetClearance = true to use a clearance which is the max value between
  232. * aMinClearanceValue and the net clearance
  233. * false to use aMinClearanceValue only
  234. * if both aMinClearanceValue = 0 and aUseNetClearance = false: create the zone outline polygon.
  235. */
  236. void TransformOutlinesShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  237. int aMinClearanceValue,
  238. bool aUseNetClearance ) const;
  239. /**
  240. * Function TransformShapeWithClearanceToPolygon
  241. * Convert the zone shape to a closed polygon
  242. * Used in filling zones calculations
  243. * Circles and arcs are approximated by segments
  244. * @param aCornerBuffer = a buffer to store the polygon
  245. * @param aClearanceValue = the clearance around the pad
  246. * @param aError = the maximum deviation from true circle
  247. * @param ignoreLineWidth = used for edge cut items where the line width is only
  248. * for visualization
  249. */
  250. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue,
  251. int aError = ARC_HIGH_DEF, bool ignoreLineWidth = false ) const override;
  252. /**
  253. * Function HitTestForCorner
  254. * tests if the given wxPoint is near a corner.
  255. * @param refPos is the wxPoint to test.
  256. * @param aAccuracy increase the item bounding box by this amount.
  257. * @param aCornerHit [out] is the index of the closest vertex found, useless when return
  258. * value is false.
  259. * @return bool - true if some corner was found to be closer to refPos than aClearance; false
  260. * otherwise.
  261. */
  262. bool HitTestForCorner( const wxPoint& refPos, int aAccuracy,
  263. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const;
  264. /**
  265. * Function HitTestForCorner
  266. * tests if the given wxPoint is near a corner.
  267. * @param refPos is the wxPoint to test.
  268. * @param aAccuracy increase the item bounding box by this amount.
  269. * @return bool - true if some corner was found to be closer to refPos than aClearance; false
  270. * otherwise.
  271. */
  272. bool HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const;
  273. /**
  274. * Function HitTestForEdge
  275. * tests if the given wxPoint is near a segment defined by 2 corners.
  276. * @param refPos is the wxPoint to test.
  277. * @param aAccuracy increase the item bounding box by this amount.
  278. * @param aCornerHit [out] is the index of the closest vertex found, useless when return
  279. * value is false.
  280. * @return bool - true if some edge was found to be closer to refPos than aClearance.
  281. */
  282. bool HitTestForEdge( const wxPoint& refPos, int aAccuracy,
  283. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const;
  284. /**
  285. * Function HitTestForEdge
  286. * tests if the given wxPoint is near a segment defined by 2 corners.
  287. * @param refPos is the wxPoint to test.
  288. * @param aAccuracy increase the item bounding box by this amount.
  289. * @return bool - true if some edge was found to be closer to refPos than aClearance.
  290. */
  291. bool HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const;
  292. /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
  293. * bool aContained = true, int aAccuracy ) const
  294. */
  295. bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  296. /**
  297. * Function UnFill
  298. * Removes the zone filling
  299. * @return true if a previous filling is removed, false if no change
  300. * (when no filling found)
  301. */
  302. bool UnFill();
  303. /* Geometric transformations: */
  304. /**
  305. * Function Move
  306. * Move the outlines
  307. * @param offset = moving vector
  308. */
  309. void Move( const wxPoint& offset ) override;
  310. /**
  311. * Function MoveEdge
  312. * Move the outline Edge
  313. * @param offset = moving vector
  314. * @param aEdge = start point of the outline edge
  315. */
  316. void MoveEdge( const wxPoint& offset, int aEdge );
  317. /**
  318. * Function Rotate
  319. * Move the outlines
  320. * @param centre = rot centre
  321. * @param angle = in 0.1 degree
  322. */
  323. void Rotate( const wxPoint& centre, double angle ) override;
  324. /**
  325. * Function Flip
  326. * Flip this object, i.e. change the board side for this object
  327. * (like Mirror() but changes layer)
  328. * @param aCentre - the rotation point.
  329. */
  330. virtual void Flip( const wxPoint& aCentre ) override;
  331. /**
  332. * Function Mirror
  333. * Mirror the outlines , relative to a given horizontal axis
  334. * the layer is not changed
  335. * @param mirror_ref = vertical axis position
  336. */
  337. void Mirror( const wxPoint& mirror_ref );
  338. /**
  339. * Function GetClass
  340. * returns the class name.
  341. * @return wxString
  342. */
  343. wxString GetClass() const override
  344. {
  345. return wxT( "ZONE_CONTAINER" );
  346. }
  347. /** Access to m_Poly parameters
  348. */
  349. int GetNumCorners( void ) const
  350. {
  351. return m_Poly->TotalVertices();
  352. }
  353. /**
  354. * Function Iterate
  355. * returns an iterator to visit all points of the zone's main outline without holes.
  356. * @return SHAPE_POLY_SET::ITERATOR - an iterator to visit the zone vertices without holes.
  357. */
  358. SHAPE_POLY_SET::ITERATOR Iterate()
  359. {
  360. return m_Poly->Iterate();
  361. }
  362. /**
  363. * Function IterateWithHoles
  364. * returns an iterator to visit all points of the zone's main outline with holes.
  365. * @return SHAPE_POLY_SET::ITERATOR - an iterator to visit the zone vertices with holes.
  366. */
  367. SHAPE_POLY_SET::ITERATOR IterateWithHoles()
  368. {
  369. return m_Poly->IterateWithHoles();
  370. }
  371. /**
  372. * Function CIterateWithHoles
  373. * returns an iterator to visit all points of the zone's main outline with holes.
  374. * @return SHAPE_POLY_SET::ITERATOR - an iterator to visit the zone vertices with holes.
  375. */
  376. SHAPE_POLY_SET::CONST_ITERATOR CIterateWithHoles() const
  377. {
  378. return m_Poly->CIterateWithHoles();
  379. }
  380. void RemoveAllContours( void )
  381. {
  382. m_Poly->RemoveAllContours();
  383. }
  384. const VECTOR2I& GetCornerPosition( int aCornerIndex ) const
  385. {
  386. SHAPE_POLY_SET::VERTEX_INDEX index;
  387. // Convert global to relative indices
  388. if( !m_Poly->GetRelativeIndices( aCornerIndex, &index ) )
  389. throw( std::out_of_range( "aCornerIndex-th vertex does not exist" ) );
  390. return m_Poly->CVertex( index );
  391. }
  392. void SetCornerPosition( int aCornerIndex, wxPoint new_pos )
  393. {
  394. SHAPE_POLY_SET::VERTEX_INDEX relativeIndices;
  395. // Convert global to relative indices
  396. if( m_Poly->GetRelativeIndices( aCornerIndex, &relativeIndices ) )
  397. {
  398. if( m_Poly->Vertex( relativeIndices ).x != new_pos.x ||
  399. m_Poly->Vertex( relativeIndices ).y != new_pos.y )
  400. SetNeedRefill( true );
  401. m_Poly->Vertex( relativeIndices ).x = new_pos.x;
  402. m_Poly->Vertex( relativeIndices ).y = new_pos.y;
  403. }
  404. else
  405. throw( std::out_of_range( "aCornerIndex-th vertex does not exist" ) );
  406. }
  407. /**
  408. * Function NewHole
  409. * creates a new hole on the zone; i.e., a new contour on the zone's outline.
  410. */
  411. void NewHole()
  412. {
  413. m_Poly->NewHole();
  414. }
  415. /**
  416. * Add a new corner to the zone outline (to the main outline or a hole)
  417. * @param aPosition is the position of the new corner.
  418. * @param aHoleIdx is the index of the hole (-1 for the main outline, >= 0 for hole).
  419. * @param aAllowDuplication is a flag to indicate whether it is allowed to add this corner
  420. * even if it is duplicated.
  421. * @return true if the corner was added, false if error (aHoleIdx > hole count -1)
  422. */
  423. bool AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication = false );
  424. HATCH_STYLE GetHatchStyle() const
  425. {
  426. return m_hatchStyle;
  427. }
  428. void SetHatchStyle( HATCH_STYLE aStyle )
  429. {
  430. m_hatchStyle = aStyle;
  431. }
  432. /**
  433. * Function IsSame
  434. * tests if 2 zones are equivalent:
  435. * 2 zones are equivalent if they have same parameters and same outlines
  436. * info, filling is not taken into account
  437. * @param aZoneToCompare = zone to compare with "this"
  438. */
  439. bool IsSame( const ZONE_CONTAINER &aZoneToCompare );
  440. /**
  441. * Function ClearFilledPolysList
  442. * clears the list of filled polygons.
  443. */
  444. void ClearFilledPolysList()
  445. {
  446. m_FilledPolysList.RemoveAllContours();
  447. }
  448. /**
  449. * Function GetFilledPolysList
  450. * returns a reference to the list of filled polygons.
  451. * @return Reference to the list of filled polygons.
  452. */
  453. const SHAPE_POLY_SET& GetFilledPolysList() const
  454. {
  455. return m_FilledPolysList;
  456. }
  457. /** (re)create a list of triangles that "fill" the solid areas.
  458. * used for instance to draw these solid areas on opengl
  459. */
  460. void CacheTriangulation();
  461. /**
  462. * Function SetFilledPolysList
  463. * sets the list of filled polygons.
  464. */
  465. void SetFilledPolysList( SHAPE_POLY_SET& aPolysList )
  466. {
  467. m_FilledPolysList = aPolysList;
  468. }
  469. /**
  470. * Function SetFilledPolysList
  471. * sets the list of filled polygons.
  472. */
  473. void SetRawPolysList( SHAPE_POLY_SET& aPolysList )
  474. {
  475. m_RawPolysList = aPolysList;
  476. }
  477. /**
  478. * Function GetSmoothedPoly
  479. * returns a pointer to the corner-smoothed version of
  480. * m_Poly if it exists, otherwise it returns m_Poly.
  481. * @return SHAPE_POLY_SET* - pointer to the polygon.
  482. */
  483. bool BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly ) const;
  484. void SetCornerSmoothingType( int aType ) { m_cornerSmoothingType = aType; };
  485. int GetCornerSmoothingType() const { return m_cornerSmoothingType; }
  486. void SetCornerRadius( unsigned int aRadius );
  487. unsigned int GetCornerRadius() const { return m_cornerRadius; }
  488. bool GetFilledPolysUseThickness() const { return m_FilledPolysUseThickness; }
  489. void SetFilledPolysUseThickness( bool aOption ) { m_FilledPolysUseThickness = aOption; }
  490. /**
  491. * add a polygon to the zone outline
  492. * if the zone outline is empty, this is the main outline
  493. * else it is a hole inside the main outline
  494. */
  495. void AddPolygon( std::vector< wxPoint >& aPolygon );
  496. void AddPolygon( const SHAPE_LINE_CHAIN& aPolygon );
  497. void SetFillSegments( const ZONE_SEGMENT_FILL& aSegments )
  498. {
  499. m_FillSegmList = aSegments;
  500. }
  501. SHAPE_POLY_SET& RawPolysList()
  502. {
  503. return m_RawPolysList;
  504. }
  505. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  506. BITMAP_DEF GetMenuImage() const override;
  507. EDA_ITEM* Clone() const override;
  508. /**
  509. * Accessors to parameters used in Keepout zones:
  510. */
  511. bool GetIsKeepout() const { return m_isKeepout; }
  512. bool GetDoNotAllowCopperPour() const { return m_doNotAllowCopperPour; }
  513. bool GetDoNotAllowVias() const { return m_doNotAllowVias; }
  514. bool GetDoNotAllowTracks() const { return m_doNotAllowTracks; }
  515. void SetIsKeepout( bool aEnable ) { m_isKeepout = aEnable; }
  516. void SetDoNotAllowCopperPour( bool aEnable ) { m_doNotAllowCopperPour = aEnable; }
  517. void SetDoNotAllowVias( bool aEnable ) { m_doNotAllowVias = aEnable; }
  518. void SetDoNotAllowTracks( bool aEnable ) { m_doNotAllowTracks = aEnable; }
  519. /**
  520. * Hatch related methods
  521. */
  522. /**
  523. * Function GetHatchPitch
  524. * @return int - the zone hatch pitch in iu.
  525. */
  526. int GetHatchPitch() const;
  527. /**
  528. * Function GetDefaultHatchPitchMils
  529. * @return int - the default hatch pitch in internal units.
  530. */
  531. static int GetDefaultHatchPitch();
  532. /**
  533. * Function SetHatch
  534. * sets all hatch parameters for the zone.
  535. * @param aHatchStyle is the style of the hatch, specified as one of HATCH_STYLE possible
  536. * values.
  537. * @param aHatchPitch is the hatch pitch in iu.
  538. * @param aRebuildHatch is a flag to indicate whether to re-hatch after having set the
  539. * previous parameters.
  540. */
  541. void SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch );
  542. /**
  543. * Function SetHatchPitch
  544. * sets the hatch pitch parameter for the zone.
  545. * @param aPitch is the hatch pitch in iu.
  546. */
  547. void SetHatchPitch( int aPitch );
  548. /**
  549. * Function UnHatch
  550. * clears the zone's hatch.
  551. */
  552. void UnHatch();
  553. /**
  554. * Function Hatch
  555. * computes the hatch lines depending on the hatch parameters and stores it in the zone's
  556. * attribute m_HatchLines.
  557. */
  558. void Hatch();
  559. const std::vector<SEG>& GetHatchLines() const { return m_HatchLines; }
  560. bool GetHV45() const { return m_hv45; }
  561. void SetHV45( bool aConstrain ) { m_hv45 = aConstrain; }
  562. /** @return the hash value previously calculated by BuildHashValue().
  563. * used in zone filling calculations
  564. */
  565. MD5_HASH GetHashValue() { return m_filledPolysHash; }
  566. /** Build the hash value of m_FilledPolysList, and store it internally
  567. * in m_filledPolysHash.
  568. * Used in zone filling calculations, to know if m_FilledPolysList is up to date.
  569. */
  570. void BuildHashValue() { m_filledPolysHash = m_FilledPolysList.GetHash(); }
  571. #if defined(DEBUG)
  572. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  573. #endif
  574. virtual void SwapData( BOARD_ITEM* aImage ) override;
  575. private:
  576. SHAPE_POLY_SET* m_Poly; ///< Outline of the zone.
  577. int m_cornerSmoothingType;
  578. unsigned int m_cornerRadius;
  579. LSET m_layerSet;
  580. /* Priority: when a zone outline is inside and other zone, if its priority is higher
  581. * the other zone priority, it will be created inside.
  582. * if priorities are equal, a DRC error is set
  583. */
  584. unsigned m_priority;
  585. /* A zone outline can be a keepout zone.
  586. * It will be never filled, and DRC should test for pads, tracks and vias
  587. */
  588. bool m_isKeepout;
  589. /* For keepout zones only:
  590. * what is not allowed inside the keepout ( pads, tracks and vias )
  591. */
  592. bool m_doNotAllowCopperPour;
  593. bool m_doNotAllowVias;
  594. bool m_doNotAllowTracks;
  595. ZoneConnection m_PadConnection;
  596. int m_ZoneClearance; ///< Clearance value in internal units.
  597. int m_ZoneMinThickness; ///< Minimum thickness value in filled areas.
  598. bool m_FilledPolysUseThickness; ///< outline of filled polygons have thickness.
  599. /** True when a zone was filled, false after deleting the filled areas. */
  600. bool m_IsFilled;
  601. /** False when a zone was refilled, true after changes in zone params.
  602. * m_needRefill = false does not imply filled areas are up to date, just
  603. * the zone was refilled after edition, and does not need refilling
  604. */
  605. bool m_needRefill;
  606. ///< Width of the gap in thermal reliefs.
  607. int m_ThermalReliefGap;
  608. ///< Width of the copper bridge in thermal reliefs.
  609. int m_ThermalReliefCopperBridge;
  610. /** How to fill areas:
  611. * ZFM_POLYGONS => use solid polygons
  612. * ZFM_HATCH_PATTERN => use a grid pattern as shape
  613. */
  614. ZONE_FILL_MODE m_FillMode;
  615. /// Grid style shape: thickness of lines (if 0 -> solid shape)
  616. int m_HatchFillTypeThickness;
  617. /// Grid style shape: dist between center of lines (grid size) (0 -> solid shape)
  618. int m_HatchFillTypeGap;
  619. /// Grid style shape: orientation in degrees of the grid lines
  620. double m_HatchFillTypeOrientation;
  621. /// Grid pattern smoothing type, similar to corner smoothing type
  622. ///< 0 = no smoothing, 1 = fillet, >= 2 = arc
  623. int m_HatchFillTypeSmoothingLevel;
  624. /// Grid pattern smoothing value for smoothing shape size calculations
  625. /// this is the ratio between the gap and the chamfer size
  626. double m_HatchFillTypeSmoothingValue;
  627. /// The index of the corner being moved or nullptr if no corner is selected.
  628. SHAPE_POLY_SET::VERTEX_INDEX* m_CornerSelection;
  629. /// Variable used in polygon calculations.
  630. int m_localFlgs;
  631. /** Segments used to fill the zone (#m_FillMode ==1 ), when fill zone by segment is used.
  632. * In this case the segments have #m_ZoneMinThickness width.
  633. */
  634. ZONE_SEGMENT_FILL m_FillSegmList;
  635. /* set of filled polygons used to draw a zone as a filled area.
  636. * from outlines (m_Poly) but unlike m_Poly these filled polygons have no hole
  637. * (they are all in one piece) In very simple cases m_FilledPolysList is same
  638. * as m_Poly. In less simple cases (when m_Poly has holes) m_FilledPolysList is
  639. * a polygon equivalent to m_Poly, without holes but with extra outline segment
  640. * connecting "holes" with external main outline. In complex cases an outline
  641. * described by m_Poly can have many filled areas
  642. */
  643. SHAPE_POLY_SET m_FilledPolysList;
  644. SHAPE_POLY_SET m_RawPolysList;
  645. MD5_HASH m_filledPolysHash; // A hash value used in zone filling calculations
  646. // to see if the filled areas are up to date
  647. HATCH_STYLE m_hatchStyle; // hatch style, see enum above
  648. int m_hatchPitch; // for DIAGONAL_EDGE, distance between 2 hatch lines
  649. std::vector<SEG> m_HatchLines; // hatch lines
  650. std::vector<int> m_insulatedIslands;
  651. bool m_hv45; // constrain edges to horizontal, vertical or 45º
  652. };
  653. #endif // CLASS_ZONE_H_