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.

1428 lines
49 KiB

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