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.

594 lines
18 KiB

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