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.

390 lines
10 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
  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. #include "collectors.h"
  25. #include "pcbnew.h" // class BOARD
  26. /* This module contains out of line member functions for classes given in
  27. * collectors.h. Those classes augment the functionality of class WinEDA_PcbFrame.
  28. */
  29. // see collectors.h
  30. const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = {
  31. // there are some restrictions on the order of items in the general case.
  32. // all items in m_Drawings for instance should be contiguous.
  33. // *** all items in a same list (shown here) must be contiguous ****
  34. TYPE_MARKER_PCB, // in m_markers
  35. TYPE_TEXTE, // in m_Drawings
  36. TYPE_DRAWSEGMENT, // in m_Drawings
  37. TYPE_COTATION, // in m_Drawings
  38. TYPE_MIRE, // in m_Drawings
  39. TYPE_VIA, // in m_Tracks
  40. TYPE_TRACK, // in m_Tracks
  41. TYPE_PAD, // in modules
  42. TYPE_TEXTE_MODULE, // in modules
  43. TYPE_MODULE, // in m_Modules
  44. TYPE_ZONE, // in m_Zones
  45. TYPE_ZONE_CONTAINER, // in m_ZoneDescriptorList
  46. EOT
  47. };
  48. /*
  49. * const KICAD_T GENERAL_COLLECTOR::PrimaryItems[] = {
  50. * TYPE_TEXTE,
  51. * TYPE_DRAWSEGMENT,
  52. * TYPE_COTATION,
  53. * TYPE_VIA,
  54. * TYPE_TRACK,
  55. * TYPE_MODULE,
  56. * EOT
  57. * };
  58. */
  59. const KICAD_T GENERAL_COLLECTOR::AllButZones[] = {
  60. TYPE_MARKER_PCB,
  61. TYPE_TEXTE,
  62. TYPE_DRAWSEGMENT,
  63. TYPE_COTATION,
  64. TYPE_MIRE,
  65. TYPE_VIA,
  66. TYPE_TRACK,
  67. TYPE_PAD,
  68. TYPE_TEXTE_MODULE,
  69. TYPE_MODULE,
  70. TYPE_ZONE_CONTAINER, // if it is visible on screen, it should be selectable
  71. EOT
  72. };
  73. const KICAD_T GENERAL_COLLECTOR::ModuleItems[] = {
  74. TYPE_MODULE,
  75. EOT
  76. };
  77. const KICAD_T GENERAL_COLLECTOR::PadsOrModules[] = {
  78. TYPE_PAD,
  79. TYPE_MODULE,
  80. EOT
  81. };
  82. const KICAD_T GENERAL_COLLECTOR::PadsTracksOrZones[] = {
  83. TYPE_PAD,
  84. TYPE_VIA,
  85. TYPE_TRACK,
  86. TYPE_ZONE,
  87. TYPE_ZONE_CONTAINER,
  88. EOT
  89. };
  90. const KICAD_T GENERAL_COLLECTOR::ModulesAndTheirItems[] = {
  91. TYPE_TEXTE_MODULE,
  92. TYPE_EDGE_MODULE,
  93. TYPE_PAD,
  94. TYPE_MODULE,
  95. EOT
  96. };
  97. const KICAD_T GENERAL_COLLECTOR::Tracks[] = {
  98. TYPE_TRACK,
  99. TYPE_VIA,
  100. EOT
  101. };
  102. /**
  103. * Function Inspect
  104. * is the examining function within the INSPECTOR which is passed to the
  105. * Iterate function. Searches and collects all the objects that the old
  106. * function PcbGeneralLocateAndDisplay() would find, except that it keeps all
  107. * that it finds and does not do any displaying.
  108. *
  109. * @param testItem An EDA_BaseStruct to examine.
  110. * @param notUsed The const void* testData.
  111. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
  112. * else SCAN_CONTINUE;
  113. */
  114. SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* notUsed )
  115. {
  116. BOARD_ITEM* item = (BOARD_ITEM*) testItem;
  117. MODULE* module = NULL;
  118. #if 0 // debugging
  119. static int breakhere = 0;
  120. switch( item->Type() )
  121. {
  122. case TYPE_PAD:
  123. {
  124. MODULE* m = (MODULE*) item->GetParent();
  125. if( m->GetReference() == wxT( "Y2" ) )
  126. {
  127. breakhere++;
  128. }
  129. }
  130. break;
  131. case TYPE_VIA:
  132. breakhere++;
  133. break;
  134. case TYPE_TRACK:
  135. breakhere++;
  136. break;
  137. case TYPE_ZONE:
  138. breakhere++;
  139. break;
  140. case TYPE_TEXTE:
  141. breakhere++;
  142. break;
  143. case TYPE_DRAWSEGMENT:
  144. breakhere++;
  145. break;
  146. case TYPE_COTATION:
  147. breakhere++;
  148. break;
  149. case TYPE_TEXTE_MODULE:
  150. {
  151. TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
  152. if( tm->m_Text == wxT( "10uH" ) )
  153. {
  154. breakhere++;
  155. }
  156. }
  157. break;
  158. case TYPE_MODULE:
  159. {
  160. MODULE* m = (MODULE*) item;
  161. if( m->GetReference() == wxT( "C98" ) )
  162. {
  163. breakhere++;
  164. }
  165. }
  166. break;
  167. default:
  168. breakhere++;
  169. break;
  170. }
  171. #endif
  172. switch( item->Type() )
  173. {
  174. case TYPE_PAD:
  175. // if pad is a thru hole, then it can be visible when its parent module is not.
  176. if( ( (D_PAD*) item )->m_Attribut != PAD_SMD ) // a hole is present, so multiple layers
  177. {
  178. // there are no pad specific visibility controls at this time.
  179. // proceed to the common tests below, but without the parent module test,
  180. // by leaving module==NULL
  181. }
  182. else // smd, so use common test below
  183. module = (MODULE*) item->GetParent();
  184. break;
  185. case TYPE_VIA:
  186. break;
  187. case TYPE_TRACK:
  188. break;
  189. case TYPE_ZONE:
  190. break;
  191. case TYPE_ZONE_CONTAINER:
  192. break;
  193. case TYPE_TEXTE:
  194. break;
  195. case TYPE_DRAWSEGMENT:
  196. break;
  197. case TYPE_COTATION:
  198. break;
  199. case TYPE_MIRE:
  200. break;
  201. case TYPE_TEXTE_MODULE:
  202. module = (MODULE*) item->GetParent();
  203. if( m_Guide->IgnoreMTextsMarkedNoShow() && ( (TEXTE_MODULE*) item )->m_NoShow )
  204. goto exit;
  205. if( module )
  206. {
  207. if( m_Guide->IgnoreMTextsOnCopper() && module->GetLayer()==LAYER_N_BACK )
  208. goto exit;
  209. if( m_Guide->IgnoreMTextsOnCmp() && module->GetLayer()==LAYER_N_FRONT )
  210. goto exit;
  211. }
  212. break;
  213. case TYPE_MODULE:
  214. module = (MODULE*) item;
  215. break;
  216. default:
  217. break;
  218. }
  219. // common tests:
  220. if( module ) // true from case TYPE_PAD, TYPE_TEXTE_MODULE, or TYPE_MODULE
  221. {
  222. if( m_Guide->IgnoreModulesOnCu() && module->GetLayer()==LAYER_N_BACK )
  223. goto exit;
  224. if( m_Guide->IgnoreModulesOnCmp() && module->GetLayer()==LAYER_N_FRONT )
  225. goto exit;
  226. }
  227. if( item->IsOnLayer( m_Guide->GetPreferredLayer() ) || m_Guide->IgnorePreferredLayer() )
  228. {
  229. int layer = item->GetLayer();
  230. // Modules and their subcomponents: text and pads are not sensitive to the layer
  231. // visibility controls. They all have their own separate visibility controls
  232. if( module || m_Guide->IsLayerVisible( layer ) || !m_Guide->IgnoreNonVisibleLayers() )
  233. {
  234. if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() )
  235. {
  236. if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() )
  237. {
  238. if( item->HitTest( m_RefPos ) )
  239. {
  240. Append( item );
  241. goto exit;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. if( m_Guide->IncludeSecondary() )
  248. {
  249. // for now, "secondary" means "tolerate any layer". It has
  250. // no effect on other criteria, since there is a separate "ignore" control for
  251. // those in the COLLECTORS_GUIDE
  252. int layer = item->GetLayer();
  253. // Modules and their subcomponents: text and pads are not sensitive to the layer
  254. // visibility controls. They all have their own separate visibility controls
  255. if( module || m_Guide->IsLayerVisible( layer ) || !m_Guide->IgnoreNonVisibleLayers() )
  256. {
  257. if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() )
  258. {
  259. if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() )
  260. {
  261. if( item->HitTest( m_RefPos ) )
  262. {
  263. Append2nd( item );
  264. goto exit;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. exit:
  271. return SEARCH_CONTINUE; // always when collecting
  272. }
  273. // see collectors.h
  274. void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
  275. const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide )
  276. {
  277. Empty(); // empty the collection, primary criteria list
  278. Empty2nd(); // empty the collection, secondary criteria list
  279. // remember guide, pass it to Inspect()
  280. SetGuide( &aGuide );
  281. SetScanTypes( aScanList );
  282. // remember where the snapshot was taken from and pass refPos to
  283. // the Inspect() function.
  284. SetRefPos( aRefPos );
  285. // visit the board or module with the INSPECTOR (me).
  286. aItem->Visit( this, // INSPECTOR* inspector
  287. NULL, // const void* testData, not used here
  288. m_ScanTypes );
  289. SetTimeNow(); // when snapshot was taken
  290. // record the length of the primary list before concatonating on to it.
  291. m_PrimaryLength = m_List.size();
  292. // append 2nd list onto end of the first list
  293. for( unsigned i = 0; i<m_List2nd.size(); ++i )
  294. Append( m_List2nd[i] );
  295. Empty2nd();
  296. }
  297. // see collectors.h
  298. SEARCH_RESULT TYPE_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* testData )
  299. {
  300. // The Vist() function only visits the testItem if its type was in the
  301. // the scanList, so therefore we can collect anything given to us here.
  302. Append( testItem );
  303. return SEARCH_CONTINUE; // always when collecting
  304. }
  305. void TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] )
  306. {
  307. Empty(); // empty any existing collection
  308. // visit the board with the INSPECTOR (me).
  309. aBoard->Visit( this, // INSPECTOR* inspector
  310. NULL, // const void* testData,
  311. aScanList );
  312. }
  313. //EOF