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.

805 lines
28 KiB

14 years ago
8 years ago
8 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 override;
  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 HitTestFilledArea
  195. * tests if the given wxPoint is within the bounds of a filled area of this zone.
  196. * @param aRefPos A wxPoint to test
  197. * @return bool - true if a hit, else false
  198. */
  199. bool HitTestFilledArea( const wxPoint& aRefPos ) const;
  200. /**
  201. * Some intersecting zones, despite being on the same layer with the same net, cannot be
  202. * merged due to other parameters such as fillet radius. The copper pour will end up
  203. * effectively merged though, so we want to keep the corners of such intersections sharp.
  204. */
  205. void GetColinearCorners( BOARD* aBoard, std::set<VECTOR2I>& aCorners );
  206. /**
  207. * Function TransformSolidAreasShapesToPolygonSet
  208. * Convert solid areas full shapes to polygon set
  209. * (the full shape is the polygon area with a thick outline)
  210. * Used in 3D view
  211. * Arcs (ends of segments) are approximated by segments
  212. * @param aCornerBuffer = a buffer to store the polygons
  213. * @param aError = Maximum error allowed between true arc and polygon approx
  214. */
  215. void TransformSolidAreasShapesToPolygonSet(
  216. SHAPE_POLY_SET& aCornerBuffer, int aError = ARC_HIGH_DEF ) const;
  217. /**
  218. * Function TransformOutlinesShapeWithClearanceToPolygon
  219. * Convert the outlines shape to a polygon with no holes
  220. * inflated (optional) by max( aClearanceValue, the zone clearance)
  221. * (holes are linked to external outline by overlapping segments)
  222. * Used in filling zones calculations
  223. * Circles (vias) and arcs (ends of tracks) are approximated by segments
  224. * @param aCornerBuffer = a buffer to store the polygon
  225. * @param aMinClearanceValue = the min clearance around outlines
  226. * @param aUseNetClearance = true to use a clearance which is the max value between
  227. * aMinClearanceValue and the net clearance
  228. * false to use aMinClearanceValue only
  229. * @param aPreserveCorners an optional set of corners which should not be smoothed.
  230. * if both aMinClearanceValue = 0 and aUseNetClearance = false: create the zone outline polygon.
  231. */
  232. void TransformOutlinesShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  233. int aMinClearanceValue, bool aUseNetClearance,
  234. std::set<VECTOR2I>* aPreserveCorners = nullptr ) const;
  235. /**
  236. * Function TransformShapeWithClearanceToPolygon
  237. * Convert the zone shape to a closed polygon
  238. * Used in filling zones calculations
  239. * Circles and arcs are approximated by segments
  240. * @param aCornerBuffer = a buffer to store the polygon
  241. * @param aClearanceValue = the clearance around the pad
  242. * @param aError = the maximum deviation from true circle
  243. * @param ignoreLineWidth = used for edge cut items where the line width is only
  244. * for visualization
  245. */
  246. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue,
  247. int aError = ARC_HIGH_DEF, bool ignoreLineWidth = false ) const override;
  248. /**
  249. * Function HitTestForCorner
  250. * tests if the given wxPoint is near a corner.
  251. * @param refPos is the wxPoint to test.
  252. * @param aAccuracy increase the item bounding box by this amount.
  253. * @param aCornerHit [out] is the index of the closest vertex found, useless when return
  254. * value is false.
  255. * @return bool - true if some corner was found to be closer to refPos than aClearance; false
  256. * otherwise.
  257. */
  258. bool HitTestForCorner( const wxPoint& refPos, int aAccuracy,
  259. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const;
  260. /**
  261. * Function HitTestForCorner
  262. * tests if the given wxPoint is near a corner.
  263. * @param refPos is the wxPoint to test.
  264. * @param aAccuracy increase the item bounding box by this amount.
  265. * @return bool - true if some corner was found to be closer to refPos than aClearance; false
  266. * otherwise.
  267. */
  268. bool HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const;
  269. /**
  270. * Function HitTestForEdge
  271. * tests if the given wxPoint is near a segment defined by 2 corners.
  272. * @param refPos is the wxPoint to test.
  273. * @param aAccuracy increase the item bounding box by this amount.
  274. * @param aCornerHit [out] is the index of the closest vertex found, useless when return
  275. * value is false.
  276. * @return bool - true if some edge was found to be closer to refPos than aClearance.
  277. */
  278. bool HitTestForEdge( const wxPoint& refPos, int aAccuracy,
  279. SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const;
  280. /**
  281. * Function HitTestForEdge
  282. * tests if the given wxPoint is near a segment defined by 2 corners.
  283. * @param refPos is the wxPoint to test.
  284. * @param aAccuracy increase the item bounding box by this amount.
  285. * @return bool - true if some edge was found to be closer to refPos than aClearance.
  286. */
  287. bool HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const;
  288. /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
  289. * bool aContained = true, int aAccuracy ) const
  290. */
  291. bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  292. /**
  293. * Function UnFill
  294. * Removes the zone filling
  295. * @return true if a previous filling is removed, false if no change
  296. * (when no filling found)
  297. */
  298. bool UnFill();
  299. /* Geometric transformations: */
  300. /**
  301. * Function Move
  302. * Move the outlines
  303. * @param offset = moving vector
  304. */
  305. void Move( const wxPoint& offset ) override;
  306. /**
  307. * Function MoveEdge
  308. * Move the outline Edge
  309. * @param offset = moving vector
  310. * @param aEdge = start point of the outline edge
  311. */
  312. void MoveEdge( const wxPoint& offset, int aEdge );
  313. /**
  314. * Function Rotate
  315. * Move the outlines
  316. * @param centre = rot centre
  317. * @param angle = in 0.1 degree
  318. */
  319. void Rotate( const wxPoint& centre, double angle ) override;
  320. /**
  321. * Function Flip
  322. * Flip this object, i.e. change the board side for this object
  323. * (like Mirror() but changes layer)
  324. * @param aCentre - the rotation point.
  325. */
  326. virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
  327. /**
  328. * Function Mirror
  329. * Mirror the outlines , relative to a given horizontal axis
  330. * the layer is not changed
  331. * @param aMirrorRef = axis position
  332. * @param aMirrorLeftRight mirror across Y axis (otherwise mirror across X)
  333. */
  334. void Mirror( const wxPoint& aMirrorRef, bool aMirrorLeftRight );
  335. /**
  336. * Function GetClass
  337. * returns the class name.
  338. * @return wxString
  339. */
  340. wxString GetClass() const override
  341. {
  342. return wxT( "ZONE_CONTAINER" );
  343. }
  344. /** Access to m_Poly parameters
  345. */
  346. int GetNumCorners( void ) const
  347. {
  348. return m_Poly->TotalVertices();
  349. }
  350. /**
  351. * Function Iterate
  352. * returns an iterator to visit all points of the zone's main outline without holes.
  353. * @return SHAPE_POLY_SET::ITERATOR - an iterator to visit the zone vertices without holes.
  354. */
  355. SHAPE_POLY_SET::ITERATOR Iterate()
  356. {
  357. return m_Poly->Iterate();
  358. }
  359. /**
  360. * Function IterateWithHoles
  361. * returns an iterator to visit all points of the zone's main outline with holes.
  362. * @return SHAPE_POLY_SET::ITERATOR - an iterator to visit the zone vertices with holes.
  363. */
  364. SHAPE_POLY_SET::ITERATOR IterateWithHoles()
  365. {
  366. return m_Poly->IterateWithHoles();
  367. }
  368. /**
  369. * Function CIterateWithHoles
  370. * returns an iterator to visit all points of the zone's main outline with holes.
  371. * @return SHAPE_POLY_SET::ITERATOR - an iterator to visit the zone vertices with holes.
  372. */
  373. SHAPE_POLY_SET::CONST_ITERATOR CIterateWithHoles() const
  374. {
  375. return m_Poly->CIterateWithHoles();
  376. }
  377. void RemoveAllContours( void )
  378. {
  379. m_Poly->RemoveAllContours();
  380. }
  381. const VECTOR2I& GetCornerPosition( int aCornerIndex ) const
  382. {
  383. SHAPE_POLY_SET::VERTEX_INDEX index;
  384. // Convert global to relative indices
  385. if( !m_Poly->GetRelativeIndices( aCornerIndex, &index ) )
  386. throw( std::out_of_range( "aCornerIndex-th vertex does not exist" ) );
  387. return m_Poly->CVertex( index );
  388. }
  389. void SetCornerPosition( int aCornerIndex, wxPoint new_pos )
  390. {
  391. SHAPE_POLY_SET::VERTEX_INDEX relativeIndices;
  392. // Convert global to relative indices
  393. if( m_Poly->GetRelativeIndices( aCornerIndex, &relativeIndices ) )
  394. {
  395. if( m_Poly->Vertex( relativeIndices ).x != new_pos.x ||
  396. m_Poly->Vertex( relativeIndices ).y != new_pos.y )
  397. SetNeedRefill( true );
  398. m_Poly->Vertex( relativeIndices ).x = new_pos.x;
  399. m_Poly->Vertex( relativeIndices ).y = new_pos.y;
  400. }
  401. else
  402. throw( std::out_of_range( "aCornerIndex-th vertex does not exist" ) );
  403. }
  404. /**
  405. * Function NewHole
  406. * creates a new hole on the zone; i.e., a new contour on the zone's outline.
  407. */
  408. void NewHole()
  409. {
  410. m_Poly->NewHole();
  411. }
  412. /**
  413. * Add a new corner to the zone outline (to the main outline or a hole)
  414. * @param aPosition is the position of the new corner.
  415. * @param aHoleIdx is the index of the hole (-1 for the main outline, >= 0 for hole).
  416. * @param aAllowDuplication is a flag to indicate whether it is allowed to add this corner
  417. * even if it is duplicated.
  418. * @return true if the corner was added, false if error (aHoleIdx > hole count -1)
  419. */
  420. bool AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication = false );
  421. HATCH_STYLE GetHatchStyle() const
  422. {
  423. return m_hatchStyle;
  424. }
  425. void SetHatchStyle( HATCH_STYLE aStyle )
  426. {
  427. m_hatchStyle = aStyle;
  428. }
  429. /**
  430. * Function IsSame
  431. * tests if 2 zones are equivalent:
  432. * 2 zones are equivalent if they have same parameters and same outlines
  433. * info, filling is not taken into account
  434. * @param aZoneToCompare = zone to compare with "this"
  435. */
  436. bool IsSame( const ZONE_CONTAINER &aZoneToCompare );
  437. /**
  438. * Function ClearFilledPolysList
  439. * clears the list of filled polygons.
  440. */
  441. void ClearFilledPolysList()
  442. {
  443. m_FilledPolysList.RemoveAllContours();
  444. }
  445. /**
  446. * Function GetFilledPolysList
  447. * returns a reference to the list of filled polygons.
  448. * @return Reference to the list of filled polygons.
  449. */
  450. const SHAPE_POLY_SET& GetFilledPolysList() const
  451. {
  452. return m_FilledPolysList;
  453. }
  454. /** (re)create a list of triangles that "fill" the solid areas.
  455. * used for instance to draw these solid areas on opengl
  456. */
  457. void CacheTriangulation();
  458. /**
  459. * Function SetFilledPolysList
  460. * sets the list of filled polygons.
  461. */
  462. void SetFilledPolysList( SHAPE_POLY_SET& aPolysList )
  463. {
  464. m_FilledPolysList = aPolysList;
  465. }
  466. /**
  467. * Function SetFilledPolysList
  468. * sets the list of filled polygons.
  469. */
  470. void SetRawPolysList( SHAPE_POLY_SET& aPolysList )
  471. {
  472. m_RawPolysList = aPolysList;
  473. }
  474. /**
  475. * Function GetSmoothedPoly
  476. * returns a pointer to the corner-smoothed version of m_Poly.
  477. * @param aPreserveCorners - set of corners which should /not/ be smoothed
  478. * @return SHAPE_POLY_SET* - pointer to the polygon.
  479. */
  480. bool BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly,
  481. std::set<VECTOR2I>* aPreserveCorners ) const;
  482. void SetCornerSmoothingType( int aType ) { m_cornerSmoothingType = aType; };
  483. int GetCornerSmoothingType() const { return m_cornerSmoothingType; }
  484. void SetCornerRadius( unsigned int aRadius );
  485. unsigned int GetCornerRadius() const { return m_cornerRadius; }
  486. bool GetFilledPolysUseThickness() const { return m_FilledPolysUseThickness; }
  487. void SetFilledPolysUseThickness( bool aOption ) { m_FilledPolysUseThickness = aOption; }
  488. /**
  489. * add a polygon to the zone outline
  490. * if the zone outline is empty, this is the main outline
  491. * else it is a hole inside the main outline
  492. */
  493. void AddPolygon( std::vector< wxPoint >& aPolygon );
  494. void AddPolygon( const SHAPE_LINE_CHAIN& aPolygon );
  495. void SetFillSegments( const ZONE_SEGMENT_FILL& aSegments )
  496. {
  497. m_FillSegmList = aSegments;
  498. }
  499. SHAPE_POLY_SET& RawPolysList()
  500. {
  501. return m_RawPolysList;
  502. }
  503. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  504. BITMAP_DEF GetMenuImage() const override;
  505. EDA_ITEM* Clone() const override;
  506. /**
  507. * Accessors to parameters used in Keepout zones:
  508. */
  509. bool GetIsKeepout() const { return m_isKeepout; }
  510. bool GetDoNotAllowCopperPour() const { return m_doNotAllowCopperPour; }
  511. bool GetDoNotAllowVias() const { return m_doNotAllowVias; }
  512. bool GetDoNotAllowTracks() const { return m_doNotAllowTracks; }
  513. void SetIsKeepout( bool aEnable ) { m_isKeepout = aEnable; }
  514. void SetDoNotAllowCopperPour( bool aEnable ) { m_doNotAllowCopperPour = aEnable; }
  515. void SetDoNotAllowVias( bool aEnable ) { m_doNotAllowVias = aEnable; }
  516. void SetDoNotAllowTracks( bool aEnable ) { m_doNotAllowTracks = aEnable; }
  517. /**
  518. * Hatch related methods
  519. */
  520. /**
  521. * Function GetHatchPitch
  522. * @return int - the zone hatch pitch in iu.
  523. */
  524. int GetHatchPitch() const;
  525. /**
  526. * Function GetDefaultHatchPitchMils
  527. * @return int - the default hatch pitch in internal units.
  528. */
  529. static int GetDefaultHatchPitch();
  530. /**
  531. * Function SetHatch
  532. * sets all hatch parameters for the zone.
  533. * @param aHatchStyle is the style of the hatch, specified as one of HATCH_STYLE possible
  534. * values.
  535. * @param aHatchPitch is the hatch pitch in iu.
  536. * @param aRebuildHatch is a flag to indicate whether to re-hatch after having set the
  537. * previous parameters.
  538. */
  539. void SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch );
  540. /**
  541. * Function SetHatchPitch
  542. * sets the hatch pitch parameter for the zone.
  543. * @param aPitch is the hatch pitch in iu.
  544. */
  545. void SetHatchPitch( int aPitch );
  546. /**
  547. * Function UnHatch
  548. * clears the zone's hatch.
  549. */
  550. void UnHatch();
  551. /**
  552. * Function Hatch
  553. * computes the hatch lines depending on the hatch parameters and stores it in the zone's
  554. * attribute m_HatchLines.
  555. */
  556. void Hatch();
  557. const std::vector<SEG>& GetHatchLines() const { return m_HatchLines; }
  558. bool GetHV45() const { return m_hv45; }
  559. void SetHV45( bool aConstrain ) { m_hv45 = aConstrain; }
  560. /** @return the hash value previously calculated by BuildHashValue().
  561. * used in zone filling calculations
  562. */
  563. MD5_HASH GetHashValue() { return m_filledPolysHash; }
  564. /** Build the hash value of m_FilledPolysList, and store it internally
  565. * in m_filledPolysHash.
  566. * Used in zone filling calculations, to know if m_FilledPolysList is up to date.
  567. */
  568. void BuildHashValue() { m_filledPolysHash = m_FilledPolysList.GetHash(); }
  569. #if defined(DEBUG)
  570. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  571. #endif
  572. virtual void SwapData( BOARD_ITEM* aImage ) override;
  573. private:
  574. SHAPE_POLY_SET* m_Poly; ///< Outline of the zone.
  575. int m_cornerSmoothingType;
  576. unsigned int m_cornerRadius;
  577. LSET m_layerSet;
  578. /* Priority: when a zone outline is inside and other zone, if its priority is higher
  579. * the other zone priority, it will be created inside.
  580. * if priorities are equal, a DRC error is set
  581. */
  582. unsigned m_priority;
  583. /* A zone outline can be a keepout zone.
  584. * It will be never filled, and DRC should test for pads, tracks and vias
  585. */
  586. bool m_isKeepout;
  587. /* For keepout zones only:
  588. * what is not allowed inside the keepout ( pads, tracks and vias )
  589. */
  590. bool m_doNotAllowCopperPour;
  591. bool m_doNotAllowVias;
  592. bool m_doNotAllowTracks;
  593. ZoneConnection m_PadConnection;
  594. int m_ZoneClearance; ///< Clearance value in internal units.
  595. int m_ZoneMinThickness; ///< Minimum thickness value in filled areas.
  596. bool m_FilledPolysUseThickness; ///< outline of filled polygons have thickness.
  597. /** True when a zone was filled, false after deleting the filled areas. */
  598. bool m_IsFilled;
  599. /** False when a zone was refilled, true after changes in zone params.
  600. * m_needRefill = false does not imply filled areas are up to date, just
  601. * the zone was refilled after edition, and does not need refilling
  602. */
  603. bool m_needRefill;
  604. ///< Width of the gap in thermal reliefs.
  605. int m_ThermalReliefGap;
  606. ///< Width of the copper bridge in thermal reliefs.
  607. int m_ThermalReliefCopperBridge;
  608. /** How to fill areas:
  609. * ZFM_POLYGONS => use solid polygons
  610. * ZFM_HATCH_PATTERN => use a grid pattern as shape
  611. */
  612. ZONE_FILL_MODE m_FillMode;
  613. /// Grid style shape: thickness of lines (if 0 -> solid shape)
  614. int m_HatchFillTypeThickness;
  615. /// Grid style shape: dist between center of lines (grid size) (0 -> solid shape)
  616. int m_HatchFillTypeGap;
  617. /// Grid style shape: orientation in degrees of the grid lines
  618. double m_HatchFillTypeOrientation;
  619. /// Grid pattern smoothing type, similar to corner smoothing type
  620. ///< 0 = no smoothing, 1 = fillet, >= 2 = arc
  621. int m_HatchFillTypeSmoothingLevel;
  622. /// Grid pattern smoothing value for smoothing shape size calculations
  623. /// this is the ratio between the gap and the chamfer size
  624. double m_HatchFillTypeSmoothingValue;
  625. /// The index of the corner being moved or nullptr if no corner is selected.
  626. SHAPE_POLY_SET::VERTEX_INDEX* m_CornerSelection;
  627. /// Variable used in polygon calculations.
  628. int m_localFlgs;
  629. /** Segments used to fill the zone (#m_FillMode ==1 ), when fill zone by segment is used.
  630. * In this case the segments have #m_ZoneMinThickness width.
  631. */
  632. ZONE_SEGMENT_FILL m_FillSegmList;
  633. /* set of filled polygons used to draw a zone as a filled area.
  634. * from outlines (m_Poly) but unlike m_Poly these filled polygons have no hole
  635. * (they are all in one piece) In very simple cases m_FilledPolysList is same
  636. * as m_Poly. In less simple cases (when m_Poly has holes) m_FilledPolysList is
  637. * a polygon equivalent to m_Poly, without holes but with extra outline segment
  638. * connecting "holes" with external main outline. In complex cases an outline
  639. * described by m_Poly can have many filled areas
  640. */
  641. SHAPE_POLY_SET m_FilledPolysList;
  642. SHAPE_POLY_SET m_RawPolysList;
  643. MD5_HASH m_filledPolysHash; // A hash value used in zone filling calculations
  644. // to see if the filled areas are up to date
  645. HATCH_STYLE m_hatchStyle; // hatch style, see enum above
  646. int m_hatchPitch; // for DIAGONAL_EDGE, distance between 2 hatch lines
  647. std::vector<SEG> m_HatchLines; // hatch lines
  648. std::vector<int> m_insulatedIslands;
  649. bool m_hv45; // constrain edges to horizontal, vertical or 45º
  650. };
  651. #endif // CLASS_ZONE_H_