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.

579 lines
18 KiB

18 years ago
18 years ago
18 years ago
14 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
14 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2004-2022 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 COLLECTORS_H
  25. #define COLLECTORS_H
  26. /*
  27. * This module contains a number of COLLECTOR implementations which are used
  28. * to augment the functionality of class PCB_EDIT_FRAME.
  29. */
  30. #include <collector.h>
  31. #include <layer_ids.h> // LAYER_COUNT, layer defs
  32. #include <view/view.h>
  33. #include <board_item.h>
  34. /**
  35. * An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR telling it what
  36. * should be collected (aside from HitTest()ing and KICAD_T scanTypes, which are provided to the
  37. * GENERAL_COLLECTOR through attributes or arguments separately).
  38. * <p>
  39. * A justification for this class is to keep the structural storage details of the program's
  40. * "configuration options" out of GENERAL_COLLECTOR::Inspect(). This class carries all the
  41. * necessary details with it into the Inspect() call. The constructors or other functions of this
  42. * class's derivatives are then the only place where knowledge of the specific structure of the
  43. * global preference storage is needed. Thus, GENERAL_COLLECTOR::Inspect() can be kept as simple
  44. * as possible, and insulated from changes in global preference storage.
  45. * </p>
  46. * This class introduces the notion of layer locking.
  47. */
  48. class COLLECTORS_GUIDE
  49. {
  50. public:
  51. virtual ~COLLECTORS_GUIDE() {}
  52. /**
  53. * @return true if the given layer is visible, else false.
  54. */
  55. virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
  56. /**
  57. * @return the preferred layer for HitTest()ing.
  58. */
  59. virtual PCB_LAYER_ID GetPreferredLayer() const = 0;
  60. /**
  61. * @return true if should ignore locked items, else false.
  62. */
  63. virtual bool IgnoreLockedItems() const = 0;
  64. /**
  65. * Determine if the secondary criteria or 2nd choice items should be included.
  66. *
  67. * @return true if should include, else false.
  68. */
  69. virtual bool IncludeSecondary() const = 0;
  70. /**
  71. * @return true if footprint texts marked as "no show" should be ignored.
  72. */
  73. virtual bool IgnoreHiddenFPText() const = 0;
  74. /**
  75. * @return true if should ignore footprint text on back layers
  76. */
  77. virtual bool IgnoreFPTextOnBack() const = 0;
  78. /**
  79. * @return true if should ignore footprint text on front layers.
  80. */
  81. virtual bool IgnoreFPTextOnFront() const = 0;
  82. /**
  83. * @return true if should ignore FOOTPRINTs on Back Side.
  84. */
  85. virtual bool IgnoreFootprintsOnBack() const = 0;
  86. /**
  87. * @return true if should ignore FOOTPRINTs on Front Side.
  88. */
  89. virtual bool IgnoreFootprintsOnFront() const = 0;
  90. /**
  91. * @return true if should ignore Pads on Back Side.
  92. */
  93. virtual bool IgnorePadsOnBack() const = 0;
  94. /**
  95. * @return true if should ignore PADSs on Front Side.
  96. */
  97. virtual bool IgnorePadsOnFront() const = 0;
  98. /**
  99. * @return true if should ignore through-hole PADSs.
  100. */
  101. virtual bool IgnoreThroughHolePads() const = 0;
  102. /**
  103. * @return true if should ignore PADSs on Front side and Back side.
  104. */
  105. virtual bool IgnorePads() const
  106. {
  107. return IgnorePadsOnFront() && IgnorePadsOnBack() && IgnoreThroughHolePads();
  108. }
  109. /**
  110. * @return true if should ignore footprint values.
  111. */
  112. virtual bool IgnoreFPValues() const = 0;
  113. /**
  114. * @return true if should ignore footprint references.
  115. */
  116. virtual bool IgnoreFPReferences() const = 0;
  117. /**
  118. * @return true if should ignore through-hole vias
  119. */
  120. virtual bool IgnoreThroughVias() const = 0;
  121. /**
  122. * @return true if should ignore blind/buried vias
  123. */
  124. virtual bool IgnoreBlindBuriedVias() const = 0;
  125. /**
  126. * @return true if should ignore micro vias
  127. */
  128. virtual bool IgnoreMicroVias() const = 0;
  129. /**
  130. * @return true if should ignore tracks
  131. */
  132. virtual bool IgnoreTracks() const = 0;
  133. /**
  134. * @return true if should ignore the interiors of zones
  135. */
  136. virtual bool IgnoreZoneFills() const = 0;
  137. virtual double OnePixelInIU() const = 0;
  138. };
  139. /**
  140. * Collect #BOARD_ITEM objects.
  141. *
  142. * All this object really does is override the [] operator and return a #BOARD_ITEM instead
  143. * of a #EDA_ITEM. Derive all board collector objects from this class instead of the base
  144. * #COLLECTOR object.
  145. *
  146. * @see class COLLECTOR
  147. */
  148. class PCB_COLLECTOR : public COLLECTOR
  149. {
  150. public:
  151. /**
  152. * Overload the COLLECTOR::operator[](int) to return a #BOARD_ITEM instead of an #EDA_ITEM.
  153. *
  154. * @param ndx The index into the list.
  155. * @return a board item or NULL.
  156. */
  157. BOARD_ITEM* operator[]( int ndx ) const override
  158. {
  159. if( (unsigned)ndx < (unsigned)GetCount() )
  160. return (BOARD_ITEM*) m_list[ ndx ];
  161. return nullptr;
  162. }
  163. };
  164. /**
  165. * Used when the right click button is pressed, or when the select tool is in effect.
  166. * This class can be used by window classes such as PCB_EDIT_FRAME.
  167. *
  168. * Philosophy: this class knows nothing of the context in which a BOARD is used and that means
  169. * it knows nothing about which layers are visible or current, but can handle those concerns by
  170. * the SetPreferredLayer() function and the SetLayerSet() function.
  171. */
  172. class GENERAL_COLLECTOR : public PCB_COLLECTOR
  173. {
  174. protected:
  175. /**
  176. * A place to hold collected objects which don't match precisely the search
  177. * criteria, but would be acceptable if nothing else is found.
  178. * "2nd" choice, which will be appended to the end of COLLECTOR's prime
  179. * "list" at the end of the search.
  180. */
  181. std::vector<BOARD_ITEM*> m_List2nd;
  182. /**
  183. * Determine which items are to be collected by Inspect().
  184. */
  185. const COLLECTORS_GUIDE* m_Guide;
  186. public:
  187. /**
  188. * A scan list for all editable board items
  189. */
  190. static const std::vector<KICAD_T> AllBoardItems;
  191. /**
  192. * A scan list for zones outlines only
  193. */
  194. static const std::vector<KICAD_T> Zones;
  195. /**
  196. * A scan list for all primary board items, omitting items which are subordinate to
  197. * a FOOTPRINT, such as PAD and FP_TEXT.
  198. */
  199. static const std::vector<KICAD_T> BoardLevelItems;
  200. /**
  201. * A scan list for only FOOTPRINTs
  202. */
  203. static const std::vector<KICAD_T> Footprints;
  204. /**
  205. * A scan list for PADs, TRACKs, or VIAs
  206. */
  207. static const std::vector<KICAD_T> PadsOrTracks;
  208. /**
  209. * A scan list for primary footprint items.
  210. */
  211. static const std::vector<KICAD_T> FootprintItems;
  212. /**
  213. * A scan list for only TRACKs and ARCs
  214. */
  215. static const std::vector<KICAD_T> Tracks;
  216. /**
  217. * A scan list for TRACKs, VIAs, FOOTPRINTs
  218. */
  219. static const std::vector<KICAD_T> LockableItems;
  220. /**
  221. * A scan list for dimensions
  222. */
  223. static const std::vector<KICAD_T> Dimensions;
  224. /**
  225. * A scan list for items that can be dragged
  226. */
  227. static const std::vector<KICAD_T> DraggableItems;
  228. GENERAL_COLLECTOR() :
  229. m_Guide( nullptr )
  230. {
  231. SetScanTypes( AllBoardItems );
  232. }
  233. void Empty2nd()
  234. {
  235. m_List2nd.clear();
  236. }
  237. void Append2nd( BOARD_ITEM* item )
  238. {
  239. m_List2nd.push_back( item );
  240. }
  241. /**
  242. * Record which COLLECTORS_GUIDE to use.
  243. *
  244. * @param aGuide Which guide to use in the collection.
  245. */
  246. void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
  247. const COLLECTORS_GUIDE* GetGuide() const { return m_Guide; }
  248. /**
  249. * The examining function within the INSPECTOR which is passed to the Iterate function.
  250. * Search and collect all the objects which match the test data.
  251. *
  252. * @param testItem An EDA_ITEM to examine.
  253. * @param testData is not used in this class.
  254. * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE
  255. */
  256. INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
  257. /**
  258. * Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
  259. *
  260. * @param aItem A BOARD_ITEM to scan, may be a BOARD or FOOTPRINT, or whatever.
  261. * @param aScanList A list of KICAD_Ts that specs what is to be collected and the priority
  262. * order of the resultant collection in "m_list".
  263. * @param aRefPos A wxPoint to use in hit-testing.
  264. * @param aGuide The COLLECTORS_GUIDE to use in collecting items.
  265. */
  266. void Collect( BOARD_ITEM* aItem, const std::vector<KICAD_T>& aScanList,
  267. const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide );
  268. };
  269. /**
  270. * A general implementation of a COLLECTORS_GUIDE. One of its constructors is
  271. * entitled to grab information from the program's global preferences.
  272. */
  273. class GENERAL_COLLECTORS_GUIDE : public COLLECTORS_GUIDE
  274. {
  275. public:
  276. /**
  277. * Grab stuff from global preferences and uses reasonable defaults.
  278. *
  279. * Add more constructors as needed.
  280. *
  281. * @param aVisibleLayerMask is the current visible layers (bit mask).
  282. * @param aPreferredLayer is the layer to search first.
  283. */
  284. GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer,
  285. KIGFX::VIEW* aView )
  286. {
  287. VECTOR2I one( 1, 1 );
  288. m_preferredLayer = aPreferredLayer;
  289. m_visibleLayers = aVisibleLayerMask;
  290. m_ignoreLockedItems = false;
  291. #if defined(USE_MATCH_LAYER)
  292. m_includeSecondary = false;
  293. #else
  294. m_includeSecondary = true;
  295. #endif
  296. m_ignoreHiddenFPText = true; // g_ModuleTextNOVColor;
  297. m_ignoreFPTextOnBack = true;
  298. m_ignoreFPTextOnFront = false;
  299. m_ignoreFootprintsOnBack = true; // !Show_footprints_Cmp;
  300. m_ignoreFootprintsOnFront = false;
  301. m_ignorePadsOnFront = false;
  302. m_ignorePadsOnBack = false;
  303. m_ignoreThroughHolePads = false;
  304. m_ignoreFPValues = false;
  305. m_ignoreFPReferences = false;
  306. m_ignoreThroughVias = false;
  307. m_ignoreBlindBuriedVias = false;
  308. m_ignoreMicroVias = false;
  309. m_ignoreTracks = false;
  310. m_ignoreZoneFills = true;
  311. m_onePixelInIU = abs( aView->ToWorld( one, false ).x );
  312. }
  313. /**
  314. * @return true if the given layer is visible, else false.
  315. */
  316. bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
  317. {
  318. return m_visibleLayers[aLayerId];
  319. }
  320. void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
  321. {
  322. m_visibleLayers.set( aLayerId, isVisible );
  323. }
  324. void SetLayerVisibleBits( LSET aLayerBits ) { m_visibleLayers = aLayerBits; }
  325. /**
  326. * @return int - the preferred layer for HitTest()ing.
  327. */
  328. PCB_LAYER_ID GetPreferredLayer() const override { return m_preferredLayer; }
  329. void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_preferredLayer = aLayer; }
  330. /**
  331. * @return true if should ignore locked items, else false.
  332. */
  333. bool IgnoreLockedItems() const override { return m_ignoreLockedItems; }
  334. void SetIgnoreLockedItems( bool ignore ) { m_ignoreLockedItems = ignore; }
  335. /**
  336. * Determine if the secondary criteria, or 2nd choice items should be included.
  337. *
  338. * @return true if should include, else false.
  339. */
  340. bool IncludeSecondary() const override { return m_includeSecondary; }
  341. void SetIncludeSecondary( bool include ) { m_includeSecondary = include; }
  342. /**
  343. * @return true if MTexts marked as "no show" should be ignored.
  344. */
  345. bool IgnoreHiddenFPText() const override { return m_ignoreHiddenFPText; }
  346. void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_ignoreHiddenFPText = ignore; }
  347. /**
  348. * @return true if should ignore MTexts on back layers
  349. */
  350. bool IgnoreFPTextOnBack() const override { return m_ignoreFPTextOnBack; }
  351. void SetIgnoreMTextsOnBack( bool ignore ) { m_ignoreFPTextOnBack = ignore; }
  352. /**
  353. * @return true if should ignore MTexts on front layers
  354. */
  355. bool IgnoreFPTextOnFront() const override { return m_ignoreFPTextOnFront; }
  356. void SetIgnoreMTextsOnFront( bool ignore ) { m_ignoreFPTextOnFront = ignore; }
  357. /**
  358. * @return true if should ignore MODULEs on the back side
  359. */
  360. bool IgnoreFootprintsOnBack() const override { return m_ignoreFootprintsOnBack; }
  361. void SetIgnoreModulesOnBack( bool ignore ) { m_ignoreFootprintsOnBack = ignore; }
  362. /**
  363. * @return true if should ignore MODULEs on component layer.
  364. */
  365. bool IgnoreFootprintsOnFront() const override { return m_ignoreFootprintsOnFront; }
  366. void SetIgnoreModulesOnFront( bool ignore ) { m_ignoreFootprintsOnFront = ignore; }
  367. /**
  368. * @return true if should ignore Pads on Back Side.
  369. */
  370. bool IgnorePadsOnBack() const override { return m_ignorePadsOnBack; }
  371. void SetIgnorePadsOnBack(bool ignore) { m_ignorePadsOnBack = ignore; }
  372. /**
  373. * @return true if should ignore PADSs on Front Side.
  374. */
  375. bool IgnorePadsOnFront() const override { return m_ignorePadsOnFront; }
  376. void SetIgnorePadsOnFront(bool ignore) { m_ignorePadsOnFront = ignore; }
  377. /**
  378. * @return true if should ignore through-hole PADSs.
  379. */
  380. bool IgnoreThroughHolePads() const override { return m_ignoreThroughHolePads; }
  381. void SetIgnoreThroughHolePads(bool ignore) { m_ignoreThroughHolePads = ignore; }
  382. /**
  383. * @return true if should ignore footprints values.
  384. */
  385. bool IgnoreFPValues() const override { return m_ignoreFPValues; }
  386. void SetIgnoreModulesVals(bool ignore) { m_ignoreFPValues = ignore; }
  387. /**
  388. * @return true if should ignore footprints references.
  389. */
  390. bool IgnoreFPReferences() const override { return m_ignoreFPReferences; }
  391. void SetIgnoreModulesRefs(bool ignore) { m_ignoreFPReferences = ignore; }
  392. bool IgnoreThroughVias() const override { return m_ignoreThroughVias; }
  393. void SetIgnoreThroughVias( bool ignore ) { m_ignoreThroughVias = ignore; }
  394. bool IgnoreBlindBuriedVias() const override { return m_ignoreBlindBuriedVias; }
  395. void SetIgnoreBlindBuriedVias( bool ignore ) { m_ignoreBlindBuriedVias = ignore; }
  396. bool IgnoreMicroVias() const override { return m_ignoreMicroVias; }
  397. void SetIgnoreMicroVias( bool ignore ) { m_ignoreMicroVias = ignore; }
  398. bool IgnoreTracks() const override { return m_ignoreTracks; }
  399. void SetIgnoreTracks( bool ignore ) { m_ignoreTracks = ignore; }
  400. bool IgnoreZoneFills() const override { return m_ignoreZoneFills; }
  401. void SetIgnoreZoneFills( bool ignore ) { m_ignoreZoneFills = ignore; }
  402. double OnePixelInIU() const override { return m_onePixelInIU; }
  403. void SetOnePixelInIU( double aValue ) { m_onePixelInIU = aValue; }
  404. private:
  405. // the storage architecture here is not important, since this is only
  406. // a carrier object and its functions are what is used, and data only indirectly.
  407. PCB_LAYER_ID m_preferredLayer;
  408. LSET m_visibleLayers; ///< bit-mapped layer visible bits
  409. bool m_ignoreLockedItems;
  410. bool m_includeSecondary;
  411. bool m_ignoreHiddenFPText;
  412. bool m_ignoreFPTextOnBack;
  413. bool m_ignoreFPTextOnFront;
  414. bool m_ignoreFootprintsOnBack;
  415. bool m_ignoreFootprintsOnFront;
  416. bool m_ignorePadsOnFront;
  417. bool m_ignorePadsOnBack;
  418. bool m_ignoreThroughHolePads;
  419. bool m_ignoreFPValues;
  420. bool m_ignoreFPReferences;
  421. bool m_ignoreThroughVias;
  422. bool m_ignoreBlindBuriedVias;
  423. bool m_ignoreMicroVias;
  424. bool m_ignoreTracks;
  425. bool m_ignoreZoneFills;
  426. double m_onePixelInIU;
  427. };
  428. /**
  429. * Collect all #BOARD_ITEM objects of a given set of #KICAD_T type(s).
  430. *
  431. * @see class COLLECTOR
  432. */
  433. class PCB_TYPE_COLLECTOR : public PCB_COLLECTOR
  434. {
  435. public:
  436. /**
  437. * The examining function within the INSPECTOR which is passed to the Iterate function.
  438. *
  439. * @param testItem An EDA_ITEM to examine.
  440. * @param testData is not used in this class.
  441. * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE
  442. */
  443. INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
  444. /**
  445. * Collect #BOARD_ITEM objects using this class's Inspector method, which does the collection.
  446. *
  447. * @param aBoard The BOARD_ITEM to scan.
  448. * @param aTypes The KICAD_Ts to gather up.
  449. */
  450. void Collect( BOARD_ITEM* aBoard, const std::vector<KICAD_T>& aTypes );
  451. };
  452. /**
  453. * Collect all #BOARD_ITEM objects on a given layer.
  454. *
  455. * This only uses the primary object layer for comparison.
  456. */
  457. class PCB_LAYER_COLLECTOR : public PCB_COLLECTOR
  458. {
  459. public:
  460. PCB_LAYER_COLLECTOR( PCB_LAYER_ID aLayerId = UNDEFINED_LAYER ) :
  461. m_layer_id( aLayerId )
  462. { }
  463. void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
  464. /**
  465. * The examining function within the INSPECTOR which is passed to the iterate function.
  466. *
  467. * @param testItem An EDA_ITEM to examine.
  468. * @param testData is not used in this class.
  469. * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE
  470. */
  471. INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
  472. /**
  473. * Test a BOARD_ITEM using this class's Inspector method, which does the collection.
  474. *
  475. * @param aBoard The BOARD_ITEM to scan.
  476. * @param aTypes The KICAD_Ts to gather up.
  477. */
  478. void Collect( BOARD_ITEM* aBoard, const std::vector<KICAD_T>& aTypes );
  479. private:
  480. PCB_LAYER_ID m_layer_id;
  481. };
  482. #endif // COLLECTORS_H