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.

637 lines
19 KiB

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
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
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
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
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-2007 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file collectors.h
  26. */
  27. #ifndef COLLECTORS_H
  28. #define COLLECTORS_H
  29. /* This module contains a number of COLLECTOR implementations which are used
  30. to augment the functionality of class PCB_EDIT_FRAME.
  31. */
  32. #include <class_collector.h>
  33. #include <layers_id_colors_and_visibility.h> // LAYER_COUNT, layer defs
  34. class BOARD_ITEM;
  35. /**
  36. * Class COLLECTORS_GUIDE
  37. * is an abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR,
  38. * telling GENERAL_COLLECTOR what should be collected (aside from HitTest()ing
  39. * and KICAD_T scanTypes[], information which are provided to the GENERAL_COLLECTOR
  40. * through attributes or arguments separately).
  41. * <p>
  42. * A justification for this class is to keep the structural storage details of
  43. * the program's "global preferences" or "configuration options" out of
  44. * GENERAL_COLLECTOR::Inspect(). This class carries all the necessary details
  45. * in with it to the Inspect() call. The constructors or other functions of
  46. * this class's derivatives are then the only place where knowledge of the
  47. * specific structure of the global preference storage is needed. Thus,
  48. * GENERAL_COLLECTOR::Inspect() can be kept as simple as possible, and insulated
  49. * from changes in global preference storage (and even then it is
  50. * not simple enough).
  51. * <p>
  52. * This class introduces the notion of layer locking.
  53. */
  54. class COLLECTORS_GUIDE
  55. {
  56. public:
  57. virtual ~COLLECTORS_GUIDE() {}
  58. /**
  59. * Function IsLayerLocked
  60. * @return bool - true if the given layer is locked, else false.
  61. */
  62. virtual bool IsLayerLocked( int layer ) const = 0;
  63. /**
  64. * Function IsLayerVisible
  65. * @return bool - true if the given layer is visible, else false.
  66. */
  67. virtual bool IsLayerVisible( int layer ) const = 0;
  68. /**
  69. * Function IgnoreLockedLayers
  70. * @return bool - true if should ignore locked layers, else false.
  71. */
  72. virtual bool IgnoreLockedLayers() const = 0;
  73. /**
  74. * Function IgnoredNonVisibleLayers
  75. * @return bool - true if should ignore non-visible layers, else false.
  76. */
  77. virtual bool IgnoreNonVisibleLayers() const = 0;
  78. /**
  79. * Function GetPreferredLayer
  80. * @return int - the preferred layer for HitTest()ing.
  81. */
  82. virtual int GetPreferredLayer() const = 0;
  83. /**
  84. * Function IgnorePreferredLayer
  85. * provides wildcard behavior regarding the preferred layer.
  86. * @return bool - true if should ignore preferred layer, else false.
  87. */
  88. virtual bool IgnorePreferredLayer() const = 0;
  89. /**
  90. * Function IgnoreLockedItems
  91. * @return bool - true if should ignore locked items, else false.
  92. */
  93. virtual bool IgnoreLockedItems() const = 0;
  94. /**
  95. * Function IncludeSecondary
  96. * determines if the secondary criteria, or 2nd choice items should be
  97. * included.
  98. * @return bool - true if should include, else false.
  99. */
  100. virtual bool IncludeSecondary() const = 0;
  101. /**
  102. * Function IgnoreMTextsMarkedNoShow
  103. * @return bool - true if MTexts marked as "no show" should be ignored.
  104. */
  105. virtual bool IgnoreMTextsMarkedNoShow() const = 0;
  106. /**
  107. * Function IgnoreZones
  108. * @return bool - true if should ignore zones.
  109. virtual bool IgnoreZones() const = 0;
  110. can simply omit from scanTypes[] PCB_ZONE_T */
  111. /**
  112. * Function IgnoreMTextsOnCu
  113. * @return bool - true if should ignore MTexts on copper layer.
  114. */
  115. virtual bool IgnoreMTextsOnCopper() const = 0;
  116. /**
  117. * Function IgnoreMTextsOnCmp
  118. * @return bool - true if should ignore MTexts on component layer.
  119. */
  120. virtual bool IgnoreMTextsOnCmp() const = 0;
  121. /**
  122. * Function IgnoreModulesOnCu
  123. * @return bool - true if should ignore MODULEs on Back Side.
  124. */
  125. virtual bool IgnoreModulesOnCu() const = 0;
  126. /**
  127. * Function IgnoreModulesOnCmp
  128. * @return bool - ture if should ignore MODULEs on Front Side.
  129. */
  130. virtual bool IgnoreModulesOnCmp() const = 0;
  131. /**
  132. * Function IgnorePadsOnBack
  133. * @return bool - true if should ignore Pads on Back Side.
  134. */
  135. virtual bool IgnorePadsOnBack() const = 0;
  136. /**
  137. * Function IgnorePadsOnFront
  138. * @return bool - ture if should ignore PADSs on Front Side.
  139. */
  140. virtual bool IgnorePadsOnFront() const = 0;
  141. /**
  142. * Function IgnorePads
  143. * @return bool - true if should ignore PADSs on Front side and Back side.
  144. */
  145. virtual bool IgnorePads() const
  146. {
  147. return IgnorePadsOnFront() && IgnorePadsOnBack();
  148. }
  149. /**
  150. * Function IgnoreModulesVals
  151. * @return bool - true if should ignore modules values.
  152. */
  153. virtual bool IgnoreModulesVals() const = 0;
  154. /**
  155. * Function IgnoreModulesRefs
  156. * @return bool - true if should ignore module references.
  157. */
  158. virtual bool IgnoreModulesRefs() const = 0;
  159. /**
  160. * Function UseHitTesting
  161. * @return bool - true if Inspect() should use BOARD_ITEM::HitTest()
  162. * or false if Inspect() should use BOARD_ITEM::BoundsTest().
  163. virtual bool UseHitTesting() const = 0;
  164. */
  165. };
  166. /**
  167. * Class GENERAL_COLLECTOR
  168. * is intended for use when the right click button is pressed, or when the
  169. * plain "arrow" tool is in effect. This class can be used by window classes
  170. * such as PCB_EDIT_FRAME.
  171. *
  172. * Philosophy: this class knows nothing of the context in which a BOARD is used
  173. * and that means it knows nothing about which layers are visible or current,
  174. * but can handle those concerns by the SetPreferredLayer() function and the
  175. * SetLayerMask() function.
  176. */
  177. class GENERAL_COLLECTOR : public COLLECTOR
  178. {
  179. protected:
  180. /**
  181. * A place to hold collected objects which don't match precisely the search
  182. * criteria, but would be acceptable if nothing else is found.
  183. * "2nd" choice, which will be appended to the end of COLLECTOR's prime
  184. * "list" at the end of the search.
  185. */
  186. std::vector<BOARD_ITEM*> m_List2nd;
  187. /**
  188. * Determines which items are to be collected by Inspect()
  189. */
  190. const COLLECTORS_GUIDE* m_Guide;
  191. /**
  192. * The number of items that were originally in the primary list before the
  193. * m_List2nd was concatonated onto the end of it.
  194. */
  195. int m_PrimaryLength;
  196. public:
  197. /**
  198. * A scan list for all editable board items, like PcbGeneralLocateAndDisplay()
  199. */
  200. static const KICAD_T AllBoardItems[];
  201. /**
  202. * A scan list for all editable board items, except zones
  203. */
  204. static const KICAD_T AllButZones[];
  205. /**
  206. * A scan list for zones outlines only
  207. */
  208. static const KICAD_T Zones[];
  209. /**
  210. * A scan list for all primary board items, omitting items which are subordinate to
  211. * a MODULE, such as D_PAD and TEXTEMODULE.
  212. static const KICAD_T PrimaryItems[];
  213. */
  214. /**
  215. * A scan list for only MODULEs
  216. */
  217. static const KICAD_T ModuleItems[];
  218. /**
  219. * A scan list for PADs or MODULEs
  220. */
  221. static const KICAD_T PadsOrModules[];
  222. /**
  223. * A scan list for PADs, TRACKs, VIAs, or ZONEs
  224. */
  225. static const KICAD_T PadsTracksOrZones[];
  226. /**
  227. * A scan list for MODULEs and their items (for Modedit)
  228. */
  229. static const KICAD_T ModulesAndTheirItems[];
  230. /**
  231. * A scan list for only TRACKS
  232. */
  233. static const KICAD_T Tracks[];
  234. /**
  235. * Constructor GENERALCOLLECTOR
  236. */
  237. GENERAL_COLLECTOR()
  238. {
  239. SetScanTypes( AllBoardItems );
  240. }
  241. void Empty2nd()
  242. {
  243. m_List2nd.clear();
  244. }
  245. void Append2nd( BOARD_ITEM* item )
  246. {
  247. m_List2nd.push_back( item );
  248. }
  249. /**
  250. * Function SetGuide
  251. * records which COLLECTORS_GUIDE to use.
  252. * @param aGuide Which guide to use in the collection.
  253. */
  254. void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
  255. /**
  256. * Function operator[int]
  257. * overloads COLLECTOR::operator[](int) to return a BOARD_ITEM* instead of
  258. * an EDA_ITEM* type.
  259. * @param ndx The index into the list.
  260. * @return BOARD_ITEM* - or something derived from it, or NULL.
  261. */
  262. BOARD_ITEM* operator[]( int ndx ) const
  263. {
  264. if( (unsigned)ndx < (unsigned)GetCount() )
  265. return (BOARD_ITEM*) m_List[ ndx ];
  266. return NULL;
  267. }
  268. /**
  269. * Function GetPrimaryCount
  270. * @return int - The number if items which met the primary search criteria
  271. */
  272. int GetPrimaryCount() { return m_PrimaryLength; }
  273. /**
  274. * Function Inspect
  275. * is the examining function within the INSPECTOR which is passed to the
  276. * Iterate function.
  277. *
  278. * @param testItem An EDA_ITEM to examine.
  279. * @param testData is not used in this class.
  280. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
  281. * else SCAN_CONTINUE;
  282. */
  283. SEARCH_RESULT Inspect( EDA_ITEM* testItem, const void* testData );
  284. /**
  285. * Function Collect
  286. * scans a BOARD_ITEM using this class's Inspector method, which does the collection.
  287. * @param aItem A BOARD_ITEM to scan, may be a BOARD or MODULE, or whatever.
  288. * @param aScanList A list of KICAD_Ts with a terminating EOT, that specs
  289. * what is to be collected and the priority order of the resultant
  290. * collection in "m_List".
  291. * @param aRefPos A wxPoint to use in hit-testing.
  292. * @param aGuide The COLLECTORS_GUIDE to use in collecting items.
  293. */
  294. void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
  295. const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
  296. };
  297. /**
  298. * Class GENERAL_COLLECTORS_GUIDE
  299. * is a general implementation of a COLLECTORS_GUIDE. One of its constructors is
  300. * entitled to grab information from the program's global preferences.
  301. */
  302. class GENERAL_COLLECTORS_GUIDE : public COLLECTORS_GUIDE
  303. {
  304. private:
  305. // the storage architecture here is not important, since this is only
  306. // a carrier object and its functions are what is used, and data only indirectly.
  307. int m_PreferredLayer;
  308. bool m_IgnorePreferredLayer;
  309. int m_LayerLocked; ///< bit-mapped layer locked bits
  310. bool m_IgnoreLockedLayers;
  311. int m_LayerVisible; ///< bit-mapped layer visible bits
  312. bool m_IgnoreNonVisibleLayers;
  313. bool m_IgnoreLockedItems;
  314. bool m_IncludeSecondary;
  315. bool m_IgnoreMTextsMarkedNoShow;
  316. bool m_IgnoreMTextsOnCopper;
  317. bool m_IgnoreMTextsOnCmp;
  318. bool m_IgnoreModulesOnCu;
  319. bool m_IgnoreModulesOnCmp;
  320. bool m_IgnorePadsOnFront;
  321. bool m_IgnorePadsOnBack;
  322. bool m_IgnoreModulesVals;
  323. bool m_IgnoreModulesRefs;
  324. public:
  325. /**
  326. * Constructor GENERAL_COLLECTORS_GUIDE
  327. * grabs stuff from global preferences and uses reasonable defaults.
  328. * Add more constructors as needed.
  329. * @param aVisibleLayerMask = current visible layers (bit mask)
  330. * @param aPreferredLayer = the layer to search first
  331. */
  332. GENERAL_COLLECTORS_GUIDE( int aVisibleLayerMask, int aPreferredLayer )
  333. {
  334. m_PreferredLayer = LAYER_N_FRONT;
  335. m_IgnorePreferredLayer = false;
  336. m_LayerLocked = 0;
  337. m_LayerVisible = aVisibleLayerMask;
  338. m_IgnoreLockedLayers = true;
  339. m_IgnoreNonVisibleLayers = true;
  340. m_IgnoreLockedItems = false;
  341. #if defined(USE_MATCH_LAYER)
  342. m_IncludeSecondary = false;
  343. #else
  344. m_IncludeSecondary = true;
  345. #endif
  346. m_PreferredLayer = aPreferredLayer;
  347. m_IgnoreMTextsMarkedNoShow = true; // g_ModuleTextNOVColor;
  348. m_IgnoreMTextsOnCopper = true;
  349. m_IgnoreMTextsOnCmp = false;
  350. m_IgnoreModulesOnCu = true; // !Show_Modules_Cmp;
  351. m_IgnoreModulesOnCmp = false;
  352. m_IgnorePadsOnFront = false;
  353. m_IgnorePadsOnBack = false;
  354. m_IgnoreModulesVals = false;
  355. m_IgnoreModulesRefs = false;
  356. }
  357. /**
  358. * Function IsLayerLocked
  359. * @return bool - true if the given layer is locked, else false.
  360. */
  361. bool IsLayerLocked( int aLayer ) const { return (1<<aLayer) & m_LayerLocked; }
  362. void SetLayerLocked( int aLayer, bool isLocked )
  363. {
  364. if( isLocked )
  365. m_LayerLocked |= 1 << aLayer;
  366. else
  367. m_LayerLocked &= ~(1 << aLayer);
  368. }
  369. /**
  370. * Function IsLayerVisible
  371. * @return bool - true if the given layer is visible, else false.
  372. */
  373. bool IsLayerVisible( int aLayer ) const { return (1<<aLayer) & m_LayerVisible; }
  374. void SetLayerVisible( int aLayer, bool isVisible )
  375. {
  376. if( isVisible )
  377. m_LayerVisible |= 1 << aLayer;
  378. else
  379. m_LayerVisible &= ~(1 << aLayer);
  380. }
  381. void SetLayerVisibleBits( int aLayerBits ) { m_LayerVisible = aLayerBits; }
  382. /**
  383. * Function IgnoreLockedLayers
  384. * @return bool - true if should ignore locked layers, else false.
  385. */
  386. bool IgnoreLockedLayers() const { return m_IgnoreLockedLayers; }
  387. void SetIgnoreLockedLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
  388. /**
  389. * Function IgnoredNonVisibleLayers
  390. * @return bool - true if should ignore non-visible layers, else false.
  391. */
  392. bool IgnoreNonVisibleLayers() const { return m_IgnoreNonVisibleLayers; }
  393. void SetIgnoreNonVisibleLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
  394. /**
  395. * Function GetPreferredLayer
  396. * @return int - the preferred layer for HitTest()ing.
  397. */
  398. int GetPreferredLayer() const { return m_PreferredLayer; }
  399. void SetPreferredLayer( int aLayer ) { m_PreferredLayer = aLayer; }
  400. /**
  401. * Function IgnorePreferredLayer
  402. * provides wildcard behavior regarding the preferred layer.
  403. * @return bool - true if should ignore preferred layer, else false.
  404. */
  405. bool IgnorePreferredLayer() const { return m_IgnorePreferredLayer; }
  406. void SetIgnorePreferredLayer( bool ignore ) { m_IgnorePreferredLayer = ignore; }
  407. /**
  408. * Function IgnoreLockedItems
  409. * @return bool - true if should ignore locked items, else false.
  410. */
  411. bool IgnoreLockedItems() const { return m_IgnoreLockedItems; }
  412. void SetIgnoreLockedItems( bool ignore ) { m_IgnoreLockedItems = ignore; }
  413. /**
  414. * Function IncludeSecondary
  415. * determines if the secondary criteria, or 2nd choice items should be
  416. * included.
  417. * @return bool - true if should include, else false.
  418. */
  419. bool IncludeSecondary() const { return m_IncludeSecondary; }
  420. void SetIncludeSecondary( bool include ) { m_IncludeSecondary = include; }
  421. /**
  422. * Function IgnoreMTextsMarkedNoShow
  423. * @return bool - true if MTexts marked as "no show" should be ignored.
  424. */
  425. bool IgnoreMTextsMarkedNoShow() const { return m_IgnoreMTextsMarkedNoShow; }
  426. void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_IgnoreMTextsMarkedNoShow = ignore; }
  427. /**
  428. * Function IgnoreMTextsOnCu
  429. * @return bool - true if should ignore MTexts on copper layer.
  430. */
  431. bool IgnoreMTextsOnCopper() const { return m_IgnoreMTextsOnCopper; }
  432. void SetIgnoreMTextsOnCopper( bool ignore ) { m_IgnoreMTextsOnCopper = ignore; }
  433. /**
  434. * Function IgnoreMTextsOnCmp
  435. * @return bool - true if should ignore MTexts on component layer.
  436. */
  437. bool IgnoreMTextsOnCmp() const { return m_IgnoreMTextsOnCmp; }
  438. void SetIgnoreMTextsOnCmp( bool ignore ) { m_IgnoreMTextsOnCmp = ignore; }
  439. /**
  440. * Function IgnoreModulesOnCu
  441. * @return bool - true if should ignore MODULEs on copper layer.
  442. */
  443. bool IgnoreModulesOnCu() const { return m_IgnoreModulesOnCu; }
  444. void SetIgnoreModulesOnCu( bool ignore ) { m_IgnoreModulesOnCu = ignore; }
  445. /**
  446. * Function IgnoreModulesOnCmp
  447. * @return bool - true if should ignore MODULEs on component layer.
  448. */
  449. bool IgnoreModulesOnCmp() const { return m_IgnoreModulesOnCmp; }
  450. void SetIgnoreModulesOnCmp( bool ignore ) { m_IgnoreModulesOnCmp = ignore; }
  451. /**
  452. * Function IgnorePadsOnBack
  453. * @return bool - true if should ignore Pads on Back Side.
  454. */
  455. bool IgnorePadsOnBack() const { return m_IgnorePadsOnBack; }
  456. void SetIgnorePadsOnBack(bool ignore) { m_IgnorePadsOnBack = ignore; }
  457. /**
  458. * Function IgnorePadsOnFront
  459. * @return bool - true if should ignore PADSs on Front Side.
  460. */
  461. bool IgnorePadsOnFront() const { return m_IgnorePadsOnFront; }
  462. void SetIgnorePadsOnFront(bool ignore) { m_IgnorePadsOnFront = ignore; }
  463. /**
  464. * Function IgnoreModulesVals
  465. * @return bool - true if should ignore modules values.
  466. */
  467. bool IgnoreModulesVals() const { return m_IgnoreModulesVals; }
  468. void SetIgnoreModulesVals(bool ignore) { m_IgnoreModulesVals = ignore; }
  469. /**
  470. * Function IgnoreModulesRefs
  471. * @return bool - true if should ignore modules references.
  472. */
  473. bool IgnoreModulesRefs() const { return m_IgnoreModulesRefs; }
  474. void SetIgnoreModulesRefs(bool ignore) { m_IgnoreModulesRefs = ignore; }
  475. };
  476. /**
  477. * Class TYPE_COLLECTOR
  478. * merely gathers up all BOARD_ITEMs of a given set of KICAD_T type(s).
  479. * @see class COLLECTOR
  480. */
  481. class TYPE_COLLECTOR : public COLLECTOR
  482. {
  483. public:
  484. /**
  485. * Function operator[int]
  486. * overloads COLLECTOR::operator[](int) to return a BOARD_ITEM* instead of
  487. * an EDA_ITEM* type.
  488. * @param ndx The index into the list.
  489. * @return BOARD_ITEM* - or something derived from it, or NULL.
  490. */
  491. BOARD_ITEM* operator[]( int ndx ) const
  492. {
  493. if( (unsigned)ndx < (unsigned)GetCount() )
  494. return (BOARD_ITEM*) m_List[ ndx ];
  495. return NULL;
  496. }
  497. /**
  498. * Function Inspect
  499. * is the examining function within the INSPECTOR which is passed to the
  500. * Iterate function.
  501. *
  502. * @param testItem An EDA_ITEM to examine.
  503. * @param testData is not used in this class.
  504. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
  505. * else SCAN_CONTINUE;
  506. */
  507. SEARCH_RESULT Inspect( EDA_ITEM* testItem, const void* testData );
  508. /**
  509. * Function Collect
  510. * scans a BOARD_ITEM using this class's Inspector method, which does
  511. * the collection.
  512. * @param aBoard The BOARD_ITEM to scan.
  513. * @param aScanList The KICAD_Ts to gather up.
  514. */
  515. void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
  516. };
  517. #endif // COLLECTORS_H