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.

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