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.

1365 lines
46 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2023 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 CLASS_BOARD_H_
  25. #define CLASS_BOARD_H_
  26. #include <board_item_container.h>
  27. #include <board_stackup_manager/board_stackup.h>
  28. #include <common.h> // Needed for stl hash extensions
  29. #include <convert_shape_list_to_polygon.h> // for OUTLINE_ERROR_HANDLER
  30. #include <hash.h>
  31. #include <layer_ids.h>
  32. #include <lset.h>
  33. #include <netinfo.h>
  34. #include <pcb_item_containers.h>
  35. #include <pcb_plot_params.h>
  36. #include <title_block.h>
  37. #include <tools/pcb_selection.h>
  38. #include <shared_mutex>
  39. #include <list>
  40. class BOARD_DESIGN_SETTINGS;
  41. class BOARD_CONNECTED_ITEM;
  42. class BOARD_COMMIT;
  43. class DRC_RTREE;
  44. class PCB_BASE_FRAME;
  45. class PCB_EDIT_FRAME;
  46. class PICKED_ITEMS_LIST;
  47. class BOARD;
  48. class FOOTPRINT;
  49. class ZONE;
  50. class PCB_TRACK;
  51. class PAD;
  52. class PCB_GROUP;
  53. class PCB_GENERATOR;
  54. class PCB_MARKER;
  55. class MSG_PANEL_ITEM;
  56. class NETLIST;
  57. class REPORTER;
  58. class SHAPE_POLY_SET;
  59. class CONNECTIVITY_DATA;
  60. class COMPONENT;
  61. class PROJECT;
  62. class PROGRESS_REPORTER;
  63. struct ISOLATED_ISLANDS;
  64. // The default value for m_outlinesChainingEpsilon to convert a board outlines to polygons
  65. // It is the max dist between 2 end points to see them connected
  66. #define DEFAULT_CHAINING_EPSILON_MM 0.01
  67. // Forward declare endpoint from class_track.h
  68. enum ENDPOINT_T : int;
  69. struct PTR_PTR_CACHE_KEY
  70. {
  71. BOARD_ITEM* A;
  72. BOARD_ITEM* B;
  73. bool operator==(const PTR_PTR_CACHE_KEY& other) const
  74. {
  75. return A == other.A && B == other.B;
  76. }
  77. };
  78. struct PTR_LAYER_CACHE_KEY
  79. {
  80. BOARD_ITEM* A;
  81. PCB_LAYER_ID Layer;
  82. bool operator==(const PTR_LAYER_CACHE_KEY& other) const
  83. {
  84. return A == other.A && Layer == other.Layer;
  85. }
  86. };
  87. struct PTR_PTR_LAYER_CACHE_KEY
  88. {
  89. BOARD_ITEM* A;
  90. BOARD_ITEM* B;
  91. PCB_LAYER_ID Layer;
  92. bool operator==(const PTR_PTR_LAYER_CACHE_KEY& other) const
  93. {
  94. return A == other.A && B == other.B && Layer == other.Layer;
  95. }
  96. };
  97. namespace std
  98. {
  99. template <>
  100. struct hash<PTR_PTR_CACHE_KEY>
  101. {
  102. std::size_t operator()( const PTR_PTR_CACHE_KEY& k ) const
  103. {
  104. std::size_t seed = 0xa82de1c0;
  105. hash_combine( seed, k.A, k.B );
  106. return seed;
  107. }
  108. };
  109. template <>
  110. struct hash<PTR_LAYER_CACHE_KEY>
  111. {
  112. std::size_t operator()( const PTR_LAYER_CACHE_KEY& k ) const
  113. {
  114. std::size_t seed = 0xa82de1c0;
  115. hash_combine( seed, k.A, k.Layer );
  116. return seed;
  117. }
  118. };
  119. template <>
  120. struct hash<PTR_PTR_LAYER_CACHE_KEY>
  121. {
  122. std::size_t operator()( const PTR_PTR_LAYER_CACHE_KEY& k ) const
  123. {
  124. std::size_t seed = 0xa82de1c0;
  125. hash_combine( seed, k.A, k.B, k.Layer );
  126. return seed;
  127. }
  128. };
  129. }
  130. /**
  131. * The allowed types of layers, same as Specctra DSN spec.
  132. */
  133. enum LAYER_T
  134. {
  135. LT_UNDEFINED = -1,
  136. LT_SIGNAL,
  137. LT_POWER,
  138. LT_MIXED,
  139. LT_JUMPER,
  140. LT_AUX,
  141. LT_FRONT,
  142. LT_BACK
  143. };
  144. /**
  145. * Container to hold information pertinent to a layer of a BOARD.
  146. */
  147. struct LAYER
  148. {
  149. LAYER()
  150. {
  151. clear();
  152. }
  153. void clear()
  154. {
  155. m_type = LT_SIGNAL;
  156. m_visible = true;
  157. m_number = 0;
  158. m_name.clear();
  159. m_userName.clear();
  160. m_opposite = m_number;
  161. }
  162. /*
  163. LAYER( const wxString& aName = wxEmptyString,
  164. LAYER_T aType = LT_SIGNAL, bool aVisible = true, int aNumber = -1 ) :
  165. m_name( aName ),
  166. m_type( aType ),
  167. m_visible( aVisible ),
  168. m_number( aNumber )
  169. {
  170. }
  171. */
  172. wxString m_name; ///< The canonical name of the layer. @see #LSET::Name
  173. wxString m_userName; ///< The user defined name of the layer.
  174. LAYER_T m_type; ///< The type of the layer. @see #LAYER_T
  175. bool m_visible;
  176. int m_number; ///< The layer ID. @see PCB_LAYER_ID
  177. int m_opposite; ///< Similar layer on opposite side of the board, if any.
  178. /**
  179. * Convert a #LAYER_T enum to a string representation of the layer type.
  180. *
  181. * @param aType The #LAYER_T to convert
  182. * @return The string representation of the layer type.
  183. */
  184. static const char* ShowType( LAYER_T aType );
  185. /**
  186. * Convert a string to a #LAYER_T
  187. *
  188. * @param aType The layer name to convert.
  189. * @return The binary representation of the layer type, or
  190. * LAYER_T(-1) if the string is invalid.
  191. */
  192. static LAYER_T ParseType( const char* aType );
  193. };
  194. // Helper class to handle high light nets
  195. class HIGH_LIGHT_INFO
  196. {
  197. protected:
  198. std::set<int> m_netCodes; // net(s) selected for highlight (-1 when no net selected )
  199. bool m_highLightOn; // highlight active
  200. void Clear()
  201. {
  202. m_netCodes.clear();
  203. m_highLightOn = false;
  204. }
  205. HIGH_LIGHT_INFO()
  206. {
  207. Clear();
  208. }
  209. private:
  210. friend class BOARD;
  211. };
  212. /**
  213. * Provide an interface to hook into board modifications and get callbacks
  214. * on certain modifications that are made to the board. This allows updating
  215. * auxiliary views other than the primary board editor view.
  216. */
  217. class BOARD;
  218. class BOARD_LISTENER
  219. {
  220. public:
  221. virtual ~BOARD_LISTENER() { }
  222. virtual void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) { }
  223. virtual void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem ) { }
  224. virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) { }
  225. virtual void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem ) { }
  226. virtual void OnBoardNetSettingsChanged( BOARD& aBoard ) { }
  227. virtual void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) { }
  228. virtual void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem ) { }
  229. virtual void OnBoardHighlightNetChanged( BOARD& aBoard ) { }
  230. virtual void OnBoardRatsnestChanged( BOARD& aBoard ) { }
  231. virtual void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
  232. std::vector<BOARD_ITEM*>& aRemovedItems,
  233. std::vector<BOARD_ITEM*>& aDeletedItems )
  234. {
  235. }
  236. };
  237. /**
  238. * Set of BOARD_ITEMs ordered by UUID.
  239. */
  240. typedef std::set<BOARD_ITEM*, CompareByUuid> BOARD_ITEM_SET;
  241. /**
  242. * Flags to specify how the board is being used.
  243. */
  244. enum class BOARD_USE
  245. {
  246. NORMAL, // A normal board
  247. FPHOLDER // A board that holds a single footprint
  248. };
  249. /**
  250. * Information pertinent to a Pcbnew printed circuit board.
  251. */
  252. class BOARD : public BOARD_ITEM_CONTAINER
  253. {
  254. public:
  255. static inline bool ClassOf( const EDA_ITEM* aItem )
  256. {
  257. return aItem && PCB_T == aItem->Type();
  258. }
  259. /**
  260. * Set what the board is going to be used for.
  261. *
  262. * @param aUse is the flag
  263. */
  264. void SetBoardUse( BOARD_USE aUse ) { m_boardUse = aUse; }
  265. /**
  266. * Get what the board use is.
  267. *
  268. * @return what the board is being used for
  269. */
  270. BOARD_USE GetBoardUse() const { return m_boardUse; }
  271. void IncrementTimeStamp();
  272. int GetTimeStamp() const { return m_timeStamp; }
  273. /**
  274. * Find out if the board is being used to hold a single footprint for editing/viewing.
  275. *
  276. * @return if the board is just holding a footprint
  277. */
  278. bool IsFootprintHolder() const
  279. {
  280. return m_boardUse == BOARD_USE::FPHOLDER;
  281. }
  282. void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
  283. const wxString &GetFileName() const { return m_fileName; }
  284. const TRACKS& Tracks() const { return m_tracks; }
  285. const FOOTPRINTS& Footprints() const { return m_footprints; }
  286. const DRAWINGS& Drawings() const { return m_drawings; }
  287. const ZONES& Zones() const { return m_zones; }
  288. const GENERATORS& Generators() const { return m_generators; }
  289. const MARKERS& Markers() const { return m_markers; }
  290. // SWIG requires non-const accessors for some reason to make the custom iterators in board.i
  291. // work. It would be good to remove this if we can figure out how to fix that.
  292. #ifdef SWIG
  293. DRAWINGS& Drawings() { return m_drawings; }
  294. TRACKS& Tracks() { return m_tracks; }
  295. #endif
  296. const BOARD_ITEM_SET GetItemSet();
  297. /**
  298. * The groups must maintain the following invariants. These are checked by
  299. * GroupsSanityCheck():
  300. * - An item may appear in at most one group
  301. * - Each group must contain at least one item
  302. * - If a group specifies a name, it must be unique
  303. * - The graph of groups containing subgroups must be cyclic.
  304. */
  305. const GROUPS& Groups() const { return m_groups; }
  306. const std::vector<BOARD_CONNECTED_ITEM*> AllConnectedItems();
  307. const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
  308. void SetProperties( const std::map<wxString, wxString>& aProps ) { m_properties = aProps; }
  309. void GetContextualTextVars( wxArrayString* aVars ) const;
  310. bool ResolveTextVar( wxString* token, int aDepth ) const;
  311. /// Visibility settings stored in board prior to 6.0, only used for loading legacy files
  312. LSET m_LegacyVisibleLayers;
  313. GAL_SET m_LegacyVisibleItems;
  314. /// True if the legacy board design settings were loaded from a file
  315. bool m_LegacyDesignSettingsLoaded;
  316. bool m_LegacyCopperEdgeClearanceLoaded;
  317. /// True if netclasses were loaded from the file
  318. bool m_LegacyNetclassesLoaded;
  319. BOARD();
  320. ~BOARD();
  321. VECTOR2I GetPosition() const override;
  322. void SetPosition( const VECTOR2I& aPos ) override;
  323. const VECTOR2I GetFocusPosition() const override { return GetBoundingBox().GetCenter(); }
  324. bool IsEmpty() const
  325. {
  326. return m_drawings.empty() && m_footprints.empty() && m_tracks.empty() && m_zones.empty();
  327. }
  328. void Move( const VECTOR2I& aMoveVector ) override;
  329. void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
  330. int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; }
  331. void SetGenerator( const wxString& aGenerator ) { m_generator = aGenerator; }
  332. const wxString& GetGenerator() const { return m_generator; }
  333. ///< @copydoc BOARD_ITEM_CONTAINER::Add()
  334. void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
  335. bool aSkipConnectivity = false ) override;
  336. ///< @copydoc BOARD_ITEM_CONTAINER::Remove()
  337. void Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override;
  338. /**
  339. * An efficient way to remove all items of a certain type from the board.
  340. * Because of how items are stored, this method has some limitations in order to preserve
  341. * performance: tracks, vias, and arcs are all removed together by PCB_TRACE_T, and all graphics
  342. * and text object types are removed together by PCB_SHAPE_T. If you need something more
  343. * granular than that, use BOARD::Remove.
  344. * @param aTypes is a list of one or more types to remove, or leave default to remove all
  345. */
  346. void RemoveAll( std::initializer_list<KICAD_T> aTypes = { PCB_NETINFO_T, PCB_MARKER_T,
  347. PCB_GROUP_T, PCB_ZONE_T,
  348. PCB_GENERATOR_T, PCB_FOOTPRINT_T,
  349. PCB_TRACE_T, PCB_SHAPE_T } );
  350. /**
  351. * Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for
  352. * listeners.
  353. */
  354. void FinalizeBulkAdd( std::vector<BOARD_ITEM*>& aNewItems );
  355. /**
  356. * Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event
  357. * for listeners.
  358. */
  359. void FinalizeBulkRemove( std::vector<BOARD_ITEM*>& aRemovedItems );
  360. void CacheTriangulation( PROGRESS_REPORTER* aReporter = nullptr,
  361. const std::vector<ZONE*>& aZones = {} );
  362. /**
  363. * Get the first footprint on the board or nullptr.
  364. *
  365. * This is used primarily by the footprint editor which knows there is only one.
  366. *
  367. * @return first footprint or null pointer
  368. */
  369. FOOTPRINT* GetFirstFootprint() const
  370. {
  371. return m_footprints.empty() ? nullptr : m_footprints.front();
  372. }
  373. /**
  374. * Remove all footprints from the deque and free the memory associated with them.
  375. */
  376. void DeleteAllFootprints();
  377. /**
  378. * @return null if aID is null. Returns an object of Type() == NOT_USED if the aID is not found.
  379. */
  380. BOARD_ITEM* GetItem( const KIID& aID ) const;
  381. void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
  382. /**
  383. * Convert cross-references back and forth between ${refDes:field} and ${kiid:field}
  384. */
  385. wxString ConvertCrossReferencesToKIIDs( const wxString& aSource ) const;
  386. wxString ConvertKIIDsToCrossReferences( const wxString& aSource ) const;
  387. /**
  388. * Return a list of missing connections between components/tracks.
  389. * @return an object that contains information about missing connections.
  390. */
  391. std::shared_ptr<CONNECTIVITY_DATA> GetConnectivity() const { return m_connectivity; }
  392. /**
  393. * Build or rebuild the board connectivity database for the board,
  394. * especially the list of connected items, list of nets and rastnest data
  395. * Needed after loading a board to have the connectivity database updated.
  396. */
  397. bool BuildConnectivity( PROGRESS_REPORTER* aReporter = nullptr );
  398. /**
  399. * Delete all MARKERS from the board.
  400. */
  401. void DeleteMARKERs();
  402. void DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions );
  403. PROJECT* GetProject() const { return m_project; }
  404. /**
  405. * Link a board to a given project.
  406. *
  407. * Should be called immediately after loading board in order for everything to work.
  408. *
  409. * @param aProject is a loaded project to link to.
  410. * @param aReferenceOnly avoids taking ownership of settings stored in project if true
  411. */
  412. void SetProject( PROJECT* aProject, bool aReferenceOnly = false );
  413. void ClearProject();
  414. /**
  415. * Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
  416. *
  417. * @param aCreateMarkers if true, create markers from serialized data; if false only
  418. * use serialized data to set existing markers to excluded.
  419. * The former is used on board load; the later after a DRC.
  420. */
  421. std::vector<PCB_MARKER*> ResolveDRCExclusions( bool aCreateMarkers );
  422. /**
  423. * Scan existing markers and record data from any that are Excluded.
  424. */
  425. void RecordDRCExclusions();
  426. /**
  427. * Update the visibility flags on the current unconnected ratsnest lines.
  428. */
  429. void UpdateRatsnestExclusions();
  430. /**
  431. * Reset all high light data to the init state
  432. */
  433. void ResetNetHighLight();
  434. /**
  435. * @return the set of net codes that should be highlighted
  436. */
  437. const std::set<int>& GetHighLightNetCodes() const
  438. {
  439. return m_highLight.m_netCodes;
  440. }
  441. /**
  442. * Select the netcode to be highlighted.
  443. *
  444. * @param aNetCode is the net to highlight.
  445. * @param aMulti is true if you want to add a highlighted net without clearing the old one.
  446. */
  447. void SetHighLightNet( int aNetCode, bool aMulti = false );
  448. /**
  449. * @return true if a net is currently highlighted
  450. */
  451. bool IsHighLightNetON() const { return m_highLight.m_highLightOn; }
  452. /**
  453. * Enable or disable net highlighting.
  454. *
  455. * If a netcode >= 0 has been set with SetHighLightNet and aValue is true, the net will be
  456. * highlighted. If aValue is false, net highlighting will be disabled regardless of
  457. * the highlight netcode being set.
  458. */
  459. void HighLightON( bool aValue = true );
  460. /**
  461. * Disable net highlight.
  462. */
  463. void HighLightOFF()
  464. {
  465. HighLightON( false );
  466. }
  467. /**
  468. * @return The number of copper layers in the BOARD.
  469. */
  470. int GetCopperLayerCount() const;
  471. void SetCopperLayerCount( int aCount );
  472. PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayer ) const;
  473. int LayerDepth( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer ) const;
  474. /**
  475. * A proxy function that calls the corresponding function in m_BoardSettings.
  476. *
  477. * @return the enabled layers in bit-mapped form.
  478. */
  479. LSET GetEnabledLayers() const;
  480. /**
  481. * A proxy function that calls the correspondent function in m_BoardSettings.
  482. *
  483. * @param aLayerMask the new bit-mask of enabled layers.
  484. */
  485. void SetEnabledLayers( LSET aLayerMask );
  486. /**
  487. * A proxy function that calls the correspondent function in m_BoardSettings
  488. * tests whether a given layer is enabled
  489. * @param aLayer = The layer to be tested
  490. * @return true if the layer is visible.
  491. */
  492. bool IsLayerEnabled( PCB_LAYER_ID aLayer ) const;
  493. /**
  494. * A proxy function that calls the correspondent function in m_BoardSettings
  495. * tests whether a given layer is visible
  496. *
  497. * @param aLayer is the layer to be tested.
  498. * @return true if the layer is visible otherwise false.
  499. */
  500. bool IsLayerVisible( PCB_LAYER_ID aLayer ) const;
  501. /**
  502. * A proxy function that calls the correspondent function in m_BoardSettings.
  503. *
  504. * @return the visible layers in bit-mapped form.
  505. */
  506. LSET GetVisibleLayers() const;
  507. /**
  508. * A proxy function that calls the correspondent function in m_BoardSettings
  509. * changes the bit-mask of visible layers.
  510. *
  511. * @param aLayerMask is the new bit-mask of visible layers.
  512. */
  513. void SetVisibleLayers( LSET aLayerMask );
  514. // these 2 functions are not tidy at this time, since there are PCB_LAYER_IDs that
  515. // are not stored in the bitmap.
  516. /**
  517. * Return a set of all the element categories that are visible.
  518. *
  519. * @return the set of visible GAL layers.
  520. * @see enum GAL_LAYER_ID
  521. */
  522. GAL_SET GetVisibleElements() const;
  523. /**
  524. * A proxy function that calls the correspondent function in m_BoardSettings.
  525. *
  526. * @param aMask is the new bit-mask of visible element bitmap or-ed from enum GAL_LAYER_ID
  527. * @see enum GAL_LAYER_ID
  528. */
  529. void SetVisibleElements( const GAL_SET& aMask );
  530. /**
  531. * Change the bit-mask of visible element categories and layers.
  532. *
  533. * @see enum GAL_LAYER_ID
  534. */
  535. void SetVisibleAlls();
  536. /**
  537. * Test whether a given element category is visible.
  538. *
  539. * @param aLayer is from the enum by the same name.
  540. * @return true if the element is visible otherwise false.
  541. * @see enum GAL_LAYER_ID
  542. */
  543. bool IsElementVisible( GAL_LAYER_ID aLayer ) const;
  544. /**
  545. * Change the visibility of an element category.
  546. *
  547. * @param aLayer is from the enum by the same name.
  548. * @param aNewState is the new visibility state of the element category.
  549. * @see enum GAL_LAYER_ID
  550. */
  551. void SetElementVisibility( GAL_LAYER_ID aLayer, bool aNewState );
  552. /**
  553. * Expect either of the two layers on which a footprint can reside, and returns
  554. * whether that layer is visible.
  555. *
  556. * @param aLayer is one of the two allowed layers for footprints: F_Cu or B_Cu
  557. * @return true if the layer is visible, otherwise false.
  558. */
  559. bool IsFootprintLayerVisible( PCB_LAYER_ID aLayer ) const;
  560. /**
  561. * @return the BOARD_DESIGN_SETTINGS for this BOARD
  562. */
  563. BOARD_DESIGN_SETTINGS& GetDesignSettings() const;
  564. BOARD_STACKUP GetStackupOrDefault() const;
  565. const PAGE_INFO& GetPageSettings() const { return m_paper; }
  566. void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
  567. const PCB_PLOT_PARAMS& GetPlotOptions() const { return m_plotOptions; }
  568. void SetPlotOptions( const PCB_PLOT_PARAMS& aOptions ) { m_plotOptions = aOptions; }
  569. TITLE_BLOCK& GetTitleBlock() { return m_titles; }
  570. const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
  571. void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
  572. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  573. EDA_UNITS GetUserUnits() { return m_userUnits; }
  574. void SetUserUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; }
  575. /**
  576. * Update any references within aItem (or its descendants) to the user units. Primarily
  577. * for automatic-unit dimensions.
  578. */
  579. void UpdateUserUnits( BOARD_ITEM* aItem, KIGFX::VIEW* aView );
  580. /**
  581. * Extract the board outlines and build a closed polygon from lines, arcs and circle items
  582. * on edge cut layer.
  583. *
  584. * Any closed outline inside the main outline is a hole. All contours should be closed,
  585. * i.e. have valid vertices to build a closed polygon.
  586. *
  587. * @param aOutlines is the #SHAPE_POLY_SET to fill in with outlines/holes.
  588. * @param aErrorHandler is an optional DRC_ITEM error handler.
  589. * @param aAllowUseArcsInPolygons = an optional option to allow adding arcs in
  590. * SHAPE_LINE_CHAIN polylines/polygons when building outlines from aShapeList
  591. * This is mainly for export to STEP files
  592. * @param aIncludeNPTHAsOutlines = an optional option to include NPTH pad holes
  593. * in board outlines. These holes can be seen like holes created by closed shapes
  594. * drawn on edge cut layer inside the board main outline.
  595. * @return true if success, false if a contour is not valid
  596. */
  597. bool GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
  598. OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr,
  599. bool aAllowUseArcsInPolygons = false,
  600. bool aIncludeNPTHAsOutlines = false );
  601. /**
  602. * @return a epsilon value that is the max distance between 2 points to see them
  603. * at the same coordinate when building the board outlines and tray to connect 2 end points
  604. * when buildind the outlines of the board
  605. * Too small value do not allow connecting 2 shapes (i.e. segments) not exactly connected
  606. * Too large value do not allow safely connecting 2 shapes like very short segments.
  607. */
  608. int GetOutlinesChainingEpsilon() { return( m_outlinesChainingEpsilon ); }
  609. void SetOutlinesChainingEpsilon( int aValue) { m_outlinesChainingEpsilon = aValue; }
  610. /**
  611. * Build a set of polygons which are the outlines of copper items (pads, tracks, vias, texts,
  612. * zones).
  613. *
  614. * Holes in vias or pads are ignored. The polygons are not merged. This is useful to
  615. * export the shape of copper layers to dxf polygons or 3D viewer/
  616. *
  617. * @param aLayer is a copper layer, like B_Cu, etc.
  618. * @param aOutlines is the SHAPE_POLY_SET to fill in with items outline.
  619. */
  620. void ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines ) const;
  621. /**
  622. * Return the ID of a layer.
  623. */
  624. PCB_LAYER_ID GetLayerID( const wxString& aLayerName ) const;
  625. /**
  626. * Return the name of a \a aLayer.
  627. *
  628. * @param aLayer is the #PCB_LAYER_ID of the layer.
  629. * @return a string containing the name of the layer.
  630. */
  631. const wxString GetLayerName( PCB_LAYER_ID aLayer ) const;
  632. /**
  633. * Changes the name of the layer given by aLayer.
  634. * @param aLayer A layer, like B_Cu, etc.
  635. * @param aLayerName The new layer name
  636. * @return true if aLayerName was legal and unique among other layer names at other layer
  637. * indices and aLayer was within range, else false.
  638. */
  639. bool SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName );
  640. /**
  641. * Return an "English Standard" name of a PCB layer when given \a aLayerNumber.
  642. *
  643. * This function is static so it can be called without a BOARD instance. Use
  644. * GetLayerName() if want the layer names of a specific BOARD, which could
  645. * be different than the default if the user has renamed any copper layers.
  646. *
  647. * @param aLayerId is the layer identifier (index) to fetch.
  648. * @return a string containing the layer name or "BAD INDEX" if aLayerId is not legal.
  649. */
  650. static wxString GetStandardLayerName( PCB_LAYER_ID aLayerId )
  651. {
  652. // a BOARD's standard layer name is the PCB_LAYER_ID fixed name
  653. return LayerName( aLayerId );
  654. }
  655. /**
  656. * Return the type of the copper layer given by aLayer.
  657. *
  658. * @param aIndex A layer index in m_Layer
  659. * @param aLayer A reference to a LAYER description.
  660. * @return false if the index was out of range.
  661. */
  662. bool SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer );
  663. /**
  664. * Return the type of the copper layer given by aLayer.
  665. *
  666. * @param aLayer A layer index, like B_Cu, etc.
  667. * @return the layer type, or LAYER_T(-1) if the index was out of range.
  668. */
  669. LAYER_T GetLayerType( PCB_LAYER_ID aLayer ) const;
  670. /**
  671. * Change the type of the layer given by aLayer.
  672. *
  673. * @param aLayer A layer index, like B_Cu, etc.
  674. * @param aLayerType The new layer type.
  675. * @return true if aLayerType was legal and aLayer was within range, else false.
  676. */
  677. bool SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType );
  678. /**
  679. * @param aNet Only count nodes belonging to this net.
  680. * @return the number of pads members of nets (i.e. with netcode > 0).
  681. */
  682. unsigned GetNodesCount( int aNet = -1 ) const;
  683. /**
  684. * Return a reference to a list of all the pads.
  685. *
  686. * The returned list is not sorted and contains pointers to PADS, but those pointers do
  687. * not convey ownership of the respective PADs.
  688. *
  689. * @return a full list of pads.
  690. */
  691. const std::vector<PAD*> GetPads() const;
  692. void BuildListOfNets()
  693. {
  694. m_NetInfo.buildListOfNets();
  695. }
  696. /**
  697. * Search for a net with the given netcode.
  698. *
  699. * @param aNetcode A netcode to search for.
  700. * @return the net if found or NULL if not found.
  701. */
  702. NETINFO_ITEM* FindNet( int aNetcode ) const;
  703. /**
  704. * Search for a net with the given name.
  705. *
  706. * @param aNetname A Netname to search for.
  707. * @return the net if found or NULL if not found.
  708. */
  709. NETINFO_ITEM* FindNet( const wxString& aNetname ) const;
  710. /**
  711. * Fetch the coupled netname for a given net.
  712. *
  713. * This accepts netnames suffixed by 'P', 'N', '+', '-', as well as additional numbers and
  714. * underscores following the suffix. So NET_P_123 is a valid positive net name matched to
  715. * NET_N_123.
  716. *
  717. * @return the polarity of the given net (or 0 if it is not a diffpair net).
  718. */
  719. int MatchDpSuffix( const wxString& aNetName, wxString& aComplementNet );
  720. /**
  721. * @return the coupled net for a given net. If not a diffpair, nullptr is returned.
  722. */
  723. NETINFO_ITEM* DpCoupledNet( const NETINFO_ITEM* aNet );
  724. const NETINFO_LIST& GetNetInfo() const
  725. {
  726. return m_NetInfo;
  727. }
  728. void RemoveUnusedNets( BOARD_COMMIT* aCommit )
  729. {
  730. m_NetInfo.RemoveUnusedNets( aCommit );
  731. }
  732. #ifndef SWIG
  733. /**
  734. * @return iterator to the first element of the NETINFO_ITEMs list.
  735. */
  736. NETINFO_LIST::iterator BeginNets() const
  737. {
  738. return m_NetInfo.begin();
  739. }
  740. /**
  741. * @return iterator to the last element of the NETINFO_ITEMs list.
  742. */
  743. NETINFO_LIST::iterator EndNets() const
  744. {
  745. return m_NetInfo.end();
  746. }
  747. #endif
  748. /**
  749. * @return the number of nets (NETINFO_ITEM).
  750. */
  751. unsigned GetNetCount() const
  752. {
  753. return m_NetInfo.GetNetCount();
  754. }
  755. /**
  756. * Calculate the bounding box containing all board items (or board edge segments).
  757. *
  758. * @param aBoardEdgesOnly is true if we are interested in board edge segments only.
  759. * @return the board's bounding box.
  760. */
  761. BOX2I ComputeBoundingBox( bool aBoardEdgesOnly = false, bool aIncludeHiddenText = false ) const;
  762. const BOX2I GetBoundingBox() const override
  763. {
  764. return ComputeBoundingBox( false, IsElementVisible( LAYER_HIDDEN_TEXT ) );
  765. }
  766. /**
  767. * Return the board bounding box calculated using exclusively the board edges (graphics
  768. * on Edge.Cuts layer).
  769. *
  770. * If there are items outside of the area limited by Edge.Cuts graphics, the items will
  771. * not be taken into account.
  772. *
  773. * @return bounding box calculated using exclusively the board edges.
  774. */
  775. const BOX2I GetBoardEdgesBoundingBox() const
  776. {
  777. return ComputeBoundingBox( true, false );
  778. }
  779. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  780. /**
  781. * May be re-implemented for each derived class in order to handle
  782. * all the types given by its member data. Implementations should call
  783. * inspector->Inspect() on types in scanTypes[], and may use IterateForward()
  784. * to do so on lists of such data.
  785. * @param inspector An INSPECTOR instance to use in the inspection.
  786. * @param testData Arbitrary data used by the inspector.
  787. * @param scanTypes Which KICAD_T types are of interest and the order to process them in.
  788. * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE, and
  789. * determined by the inspector.
  790. */
  791. INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  792. const std::vector<KICAD_T>& scanTypes ) override;
  793. /**
  794. * Search for a FOOTPRINT within this board with the given reference designator.
  795. *
  796. * Finds only the first one, if there is more than one such FOOTPRINT.
  797. *
  798. * @param aReference The reference designator of the FOOTPRINT to find.
  799. * @return If found the FOOTPRINT having the given reference designator, else nullptr.
  800. */
  801. FOOTPRINT* FindFootprintByReference( const wxString& aReference ) const;
  802. /**
  803. * Search for a FOOTPRINT within this board with the given path.
  804. *
  805. * @param aPath The path ([sheetUUID, .., symbolUUID]) to search for.
  806. * @return If found, the FOOTPRINT having the given uuid, else NULL.
  807. */
  808. FOOTPRINT* FindFootprintByPath( const KIID_PATH& aPath ) const;
  809. /**
  810. * Return the set of netname candidates for netclass assignment.
  811. */
  812. std::set<wxString> GetNetClassAssignmentCandidates() const;
  813. /**
  814. * Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
  815. *
  816. * Must be called after a Design Rules edit, or after reading a netlist (or editing
  817. * the list of nets) Also this function removes the non existing nets in netclasses
  818. * and add net nets in default netclass (this happens after reading a netlist)
  819. */
  820. void SynchronizeNetsAndNetClasses( bool aResetTrackAndViaSizes );
  821. /**
  822. * Copy the current project's text variables into the boards property cache.
  823. */
  824. void SynchronizeProperties();
  825. /**
  826. * Return the Similarity. Because we compare board to board, we just return 1.0 here
  827. */
  828. double Similarity( const BOARD_ITEM& aOther ) const override
  829. {
  830. return 1.0;
  831. }
  832. bool operator==( const BOARD_ITEM& aOther ) const override;
  833. wxString GetClass() const override
  834. {
  835. return wxT( "BOARD" );
  836. }
  837. #if defined(DEBUG)
  838. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  839. #endif
  840. /*************************/
  841. /* Copper Areas handling */
  842. /*************************/
  843. /**
  844. * Set the .m_NetCode member of all copper areas, according to the area Net Name
  845. * The SetNetCodesFromNetNames is an equivalent to net name, for fast comparisons.
  846. * However the Netcode is an arbitrary equivalence, it must be set after each netlist read
  847. * or net change
  848. * Must be called after pad netcodes are calculated
  849. * @return : error count
  850. * For non copper areas, netcode is set to 0
  851. */
  852. int SetAreasNetCodesFromNetNames();
  853. /**
  854. * Return the Zone at a given index.
  855. *
  856. * @param index The array type index into a collection of ZONE *.
  857. * @return a pointer to the Area or NULL if index out of range.
  858. */
  859. ZONE* GetArea( int index ) const
  860. {
  861. if( (unsigned) index < m_zones.size() )
  862. return m_zones[index];
  863. return nullptr;
  864. }
  865. /**
  866. * @return a std::list of pointers to all board zones (possibly including zones in footprints)
  867. */
  868. std::list<ZONE*> GetZoneList( bool aIncludeZonesInFootprints = false ) const;
  869. /**
  870. * @return The number of copper pour areas or ZONEs.
  871. */
  872. int GetAreaCount() const
  873. {
  874. return static_cast<int>( m_zones.size() );
  875. }
  876. /* Functions used in test, merge and cut outlines */
  877. /**
  878. * Add an empty copper area to board areas list.
  879. *
  880. * @param aNewZonesList is a PICKED_ITEMS_LIST * where to store new areas pickers (useful
  881. * in undo commands) can be NULL.
  882. * @param aNetcode is the netcode of the copper area (0 = no net).
  883. * @param aLayer is the layer of area.
  884. * @param aStartPointPosition is position of the first point of the polygon outline of this
  885. * area.
  886. * @param aHatch is the hatch option.
  887. * @return a reference to the new area.
  888. */
  889. ZONE* AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer,
  890. VECTOR2I aStartPointPosition, ZONE_BORDER_DISPLAY_STYLE aHatch );
  891. /**
  892. * Test for intersection of 2 copper areas.
  893. *
  894. * @param aZone1 is the area reference.
  895. * @param aZone2 is the area to compare for intersection calculations.
  896. * @return false if no intersection, true if intersection.
  897. */
  898. bool TestZoneIntersection( ZONE* aZone1, ZONE* aZone2 );
  899. /**
  900. * Find a pad \a aPosition on \a aLayer.
  901. *
  902. * @param aPosition A VECTOR2I object containing the position to hit test.
  903. * @param aLayerMask A layer or layers to mask the hit test.
  904. * @return A pointer to a PAD object if found or NULL if not found.
  905. */
  906. PAD* GetPad( const VECTOR2I& aPosition, LSET aLayerMask ) const;
  907. PAD* GetPad( const VECTOR2I& aPosition ) const
  908. {
  909. return GetPad( aPosition, LSET().set() );
  910. }
  911. /**
  912. * Find a pad connected to \a aEndPoint of \a aTrace.
  913. *
  914. * @param aTrace A pointer to a PCB_TRACK object to hit test against.
  915. * @param aEndPoint The end point of \a aTrace the hit test against.
  916. * @return A pointer to a PAD object if found or NULL if not found.
  917. */
  918. PAD* GetPad( const PCB_TRACK* aTrace, ENDPOINT_T aEndPoint ) const;
  919. /**
  920. * Return pad found at \a aPosition on \a aLayerMask using the fast search method.
  921. * <p>
  922. * The fast search method only works if the pad list has already been built.
  923. * </p>
  924. * @param aPosition A VECTOR2I object containing the position to hit test.
  925. * @param aLayerMask A layer or layers to mask the hit test.
  926. * @return A pointer to a PAD object if found or NULL if not found.
  927. */
  928. PAD* GetPadFast( const VECTOR2I& aPosition, LSET aLayerMask ) const;
  929. /**
  930. * Locate the pad connected at \a aPosition on \a aLayer starting at list position
  931. * \a aPad
  932. * <p>
  933. * This function uses a fast search in this sorted pad list and it is faster than
  934. * GetPadFast(). This list is a sorted pad list must be built before calling this
  935. * function.
  936. * </p>
  937. * @note The normal pad list is sorted by increasing netcodes.
  938. * @param aPadList is the list of pads candidates (a std::vector<PAD*>).
  939. * @param aPosition A VECTOR2I object containing the position to test.
  940. * @param aLayerMask A layer or layers to mask the hit test.
  941. * @return a PAD object pointer to the connected pad.
  942. */
  943. PAD* GetPad( std::vector<PAD*>& aPadList, const VECTOR2I& aPosition, LSET aLayerMask ) const;
  944. /**
  945. * First empties then fills the vector with all pads and sorts them by increasing x
  946. * coordinate, and for increasing y coordinate for same values of x coordinates. The vector
  947. * only holds pointers to the pads and those pointers are only references to pads which are
  948. * owned by the BOARD through other links.
  949. *
  950. * @param aVector Where to put the pad pointers.
  951. * @param aNetCode = the netcode filter:
  952. * = -1 to build the full pad list.
  953. * = a given netcode to build the pad list relative to the given net
  954. */
  955. void GetSortedPadListByXthenYCoord( std::vector<PAD*>& aVector, int aNetCode = -1 ) const;
  956. /**
  957. * Return data on the length and number of track segments connected to a given track.
  958. * This uses the connectivity data for the board to calculate connections
  959. *
  960. * @param aTrack Starting track (can also be a via) to check against for connection.
  961. * @return a tuple containing <number, length, package length>
  962. */
  963. std::tuple<int, double, double> GetTrackLength( const PCB_TRACK& aTrack ) const;
  964. /**
  965. * Collect all the TRACKs and VIAs that are members of a net given by aNetCode.
  966. * Used from python.
  967. *
  968. * @param aNetCode gives the id of the net.
  969. * @return list of track which are in the net identified by @a aNetCode.
  970. */
  971. TRACKS TracksInNet( int aNetCode );
  972. /**
  973. * Get a footprint by its bounding rectangle at \a aPosition on \a aLayer.
  974. *
  975. * If more than one footprint is at \a aPosition, then the closest footprint on the
  976. * active layer is returned. The distance is calculated via manhattan distance from
  977. * the center of the bounding rectangle to \a aPosition.
  978. *
  979. * @param aPosition A VECTOR2I object containing the position to test.
  980. * @param aActiveLayer Layer to test.
  981. * @param aVisibleOnly Search only the visible layers if true.
  982. * @param aIgnoreLocked Ignore locked footprints when true.
  983. */
  984. FOOTPRINT* GetFootprint( const VECTOR2I& aPosition, PCB_LAYER_ID aActiveLayer,
  985. bool aVisibleOnly, bool aIgnoreLocked = false ) const;
  986. /**
  987. * Returns the maximum clearance value for any object on the board. This considers
  988. * the clearances from board design settings as well as embedded clearances in footprints,
  989. * pads and zones. Includes electrical, physical, hole and edge clearances.
  990. */
  991. int GetMaxClearanceValue() const;
  992. /**
  993. * Map all nets in the given board to nets with the same name (if any) in the destination
  994. * board. If there are missing nets in the destination board, they will be created.
  995. *
  996. */
  997. void MapNets( BOARD* aDestBoard );
  998. void SanitizeNetcodes();
  999. /**
  1000. * Add a listener to the board to receive calls whenever something on the
  1001. * board has been modified. The board does not take ownership of the
  1002. * listener object. Make sure to call RemoveListener before deleting the
  1003. * listener object. The order of listener invocations is not guaranteed.
  1004. * If the specified listener object has been added before, it will not be
  1005. * added again.
  1006. */
  1007. void AddListener( BOARD_LISTENER* aListener );
  1008. /**
  1009. * Remove the specified listener. If it has not been added before, it
  1010. * will do nothing.
  1011. */
  1012. void RemoveListener( BOARD_LISTENER* aListener );
  1013. /**
  1014. * Remove all listeners
  1015. */
  1016. void RemoveAllListeners();
  1017. /**
  1018. * Notify the board and its listeners that an item on the board has
  1019. * been modified in some way.
  1020. */
  1021. void OnItemChanged( BOARD_ITEM* aItem );
  1022. /**
  1023. * Notify the board and its listeners that an item on the board has
  1024. * been modified in some way.
  1025. */
  1026. void OnItemsChanged( std::vector<BOARD_ITEM*>& aItems );
  1027. /**
  1028. * Notify the board and its listeners that items on the board have
  1029. * been modified in a composite operations
  1030. */
  1031. void OnItemsCompositeUpdate( std::vector<BOARD_ITEM*>& aAddedItems,
  1032. std::vector<BOARD_ITEM*>& aRemovedItems,
  1033. std::vector<BOARD_ITEM*>& aChangedItems );
  1034. /**
  1035. * Notify the board and its listeners that the ratsnest has been recomputed.
  1036. */
  1037. void OnRatsnestChanged();
  1038. /**
  1039. * Consistency check of internal m_groups structure.
  1040. *
  1041. * @param repair if true, modify groups structure until it passes the sanity check.
  1042. * @return empty string on success. Or error description if there's a problem.
  1043. */
  1044. wxString GroupsSanityCheck( bool repair = false );
  1045. /**
  1046. * @param repair if true, make one modification to groups structure that brings it
  1047. * closer to passing the sanity check.
  1048. * @return empty string on success. Or error description if there's a problem.
  1049. */
  1050. wxString GroupsSanityCheckInternal( bool repair );
  1051. struct GroupLegalOpsField
  1052. {
  1053. bool create : 1;
  1054. bool ungroup : 1;
  1055. bool removeItems : 1;
  1056. };
  1057. /**
  1058. * Check which selection tool group operations are legal given the selection.
  1059. *
  1060. * @return bit field of legal ops.
  1061. */
  1062. GroupLegalOpsField GroupLegalOps( const PCB_SELECTION& selection ) const;
  1063. bool LegacyTeardrops() const { return m_legacyTeardrops; }
  1064. void SetLegacyTeardrops( bool aFlag ) { m_legacyTeardrops = aFlag; }
  1065. // --------- Item order comparators ---------
  1066. struct cmp_items
  1067. {
  1068. bool operator() ( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
  1069. };
  1070. struct cmp_drawings
  1071. {
  1072. bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
  1073. };
  1074. public:
  1075. // ------------ Run-time caches -------------
  1076. mutable std::shared_mutex m_CachesMutex;
  1077. std::unordered_map<PTR_PTR_CACHE_KEY, bool> m_IntersectsCourtyardCache;
  1078. std::unordered_map<PTR_PTR_CACHE_KEY, bool> m_IntersectsFCourtyardCache;
  1079. std::unordered_map<PTR_PTR_CACHE_KEY, bool> m_IntersectsBCourtyardCache;
  1080. std::unordered_map<PTR_PTR_LAYER_CACHE_KEY, bool> m_IntersectsAreaCache;
  1081. std::unordered_map<PTR_PTR_LAYER_CACHE_KEY, bool> m_EnclosedByAreaCache;
  1082. std::unordered_map< wxString, LSET > m_LayerExpressionCache;
  1083. std::unordered_map<ZONE*, std::unique_ptr<DRC_RTREE>> m_CopperZoneRTreeCache;
  1084. std::shared_ptr<DRC_RTREE> m_CopperItemRTreeCache;
  1085. mutable std::unordered_map<const ZONE*, BOX2I> m_ZoneBBoxCache;
  1086. mutable std::optional<int> m_maxClearanceValue;
  1087. // ------------ DRC caches -------------
  1088. std::vector<ZONE*> m_DRCZones;
  1089. std::vector<ZONE*> m_DRCCopperZones;
  1090. int m_DRCMaxClearance;
  1091. int m_DRCMaxPhysicalClearance;
  1092. ZONE* m_SolderMaskBridges; // A container to build bridges on solder mask layers
  1093. std::map<ZONE*, std::map<PCB_LAYER_ID, ISOLATED_ISLANDS>> m_ZoneIsolatedIslandsMap;
  1094. private:
  1095. // The default copy constructor & operator= are inadequate,
  1096. // either write one or do not use it at all
  1097. BOARD( const BOARD& aOther ) = delete;
  1098. BOARD& operator=( const BOARD& aOther ) = delete;
  1099. template <typename Func, typename... Args>
  1100. void InvokeListeners( Func&& aFunc, Args&&... args )
  1101. {
  1102. for( auto&& l : m_listeners )
  1103. ( l->*aFunc )( std::forward<Args>( args )... );
  1104. }
  1105. // Refresh user layer opposites.
  1106. void recalcOpposites();
  1107. friend class PCB_EDIT_FRAME;
  1108. private:
  1109. /// the max distance between 2 end point to see them connected when building the board outlines
  1110. int m_outlinesChainingEpsilon;
  1111. /// What is this board being used for
  1112. BOARD_USE m_boardUse;
  1113. int m_timeStamp; // actually a modification counter
  1114. wxString m_fileName;
  1115. // These containers only have const accessors and must only be modified by Add()/Remove()
  1116. MARKERS m_markers;
  1117. DRAWINGS m_drawings;
  1118. FOOTPRINTS m_footprints;
  1119. TRACKS m_tracks;
  1120. GROUPS m_groups;
  1121. ZONES m_zones;
  1122. GENERATORS m_generators;
  1123. // Cache for fast access to items in the containers above by KIID, including children
  1124. std::unordered_map<KIID, BOARD_ITEM*> m_itemByIdCache;
  1125. LAYER m_layers[PCB_LAYER_ID_COUNT];
  1126. HIGH_LIGHT_INFO m_highLight; // current high light data
  1127. HIGH_LIGHT_INFO m_highLightPrevious; // a previously stored high light data
  1128. int m_fileFormatVersionAtLoad; // the version loaded from the file
  1129. wxString m_generator; // the generator tag from the file
  1130. std::map<wxString, wxString> m_properties;
  1131. std::shared_ptr<CONNECTIVITY_DATA> m_connectivity;
  1132. PAGE_INFO m_paper;
  1133. TITLE_BLOCK m_titles; // text in lower right of screen and plots
  1134. PCB_PLOT_PARAMS m_plotOptions;
  1135. PROJECT* m_project; // project this board is a part of
  1136. EDA_UNITS m_userUnits;
  1137. /**
  1138. * All of the board design settings are stored as a JSON object inside the project file. The
  1139. * object itself is located here because the alternative is to require a valid project be
  1140. * passed in when constructing a BOARD, since things in the BOARD constructor rely on access
  1141. * to the BOARD_DESIGN_SETTINGS object.
  1142. *
  1143. * A reference to this object is set up in the PROJECT_FILE for the PROJECT this board is
  1144. * part of, so that the JSON load/store operations work. This link is established when
  1145. * boards are loaded from disk.
  1146. */
  1147. std::unique_ptr<BOARD_DESIGN_SETTINGS> m_designSettings;
  1148. /**
  1149. * Teardrops in 7.0 were applied as a post-processing step (rather than from pad and via
  1150. * properties). If this flag is set, then auto-teardrop-generation will be disabled.
  1151. */
  1152. bool m_legacyTeardrops = false;
  1153. NETINFO_LIST m_NetInfo; // net info list (name, design constraints...
  1154. std::vector<BOARD_LISTENER*> m_listeners;
  1155. };
  1156. #endif // CLASS_BOARD_H_