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.

444 lines
12 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2012 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. /**
  25. * @file class_netinfo.h
  26. */
  27. /*
  28. * Classes to handle info on nets
  29. */
  30. #ifndef __CLASSES_NETINFO__
  31. #define __CLASSES_NETINFO__
  32. #include <vector>
  33. #include <gr_basic.h>
  34. #include <class_netclass.h>
  35. class wxDC;
  36. class wxPoint;
  37. class LINE_READER;
  38. class EDA_DRAW_PANEL;
  39. class EDA_DRAW_FRAME;
  40. class NETINFO_ITEM;
  41. class D_PAD;
  42. class BOARD;
  43. class BOARD_ITEM;
  44. class MSG_PANEL_ITEM;
  45. /*****************************/
  46. /* flags for a RATSNEST_ITEM */
  47. /*****************************/
  48. #define CH_VISIBLE 1 /* Visible */
  49. #define CH_UNROUTABLE 2 /* Don't use autorouter. */
  50. #define CH_ROUTE_REQ 4 /* Must be routed by the autorouter. */
  51. #define CH_ACTIF 8 /* Not routed. */
  52. #define LOCAL_RATSNEST_ITEM 0x8000 /* Line between two pads of a single module. */
  53. /**
  54. * Class RATSNEST_ITEM
  55. * describes a ratsnest line: a straight line connecting 2 pads
  56. */
  57. class RATSNEST_ITEM
  58. {
  59. private:
  60. int m_NetCode; // netcode ( = 1.. n , 0 is the value used for not connected items)
  61. public:
  62. int m_Status; // State: see previous defines (CH_ ...)
  63. D_PAD* m_PadStart; // pointer to the starting pad
  64. D_PAD* m_PadEnd; // pointer to ending pad
  65. int m_Lenght; // length of the line (used in some calculations)
  66. RATSNEST_ITEM();
  67. /**
  68. * Function GetNet
  69. * @return int - the net code.
  70. */
  71. int GetNet() const
  72. {
  73. return m_NetCode;
  74. }
  75. void SetNet( int aNetCode )
  76. {
  77. m_NetCode = aNetCode;
  78. }
  79. bool IsVisible()
  80. {
  81. return (m_Status & CH_VISIBLE) != 0;
  82. }
  83. bool IsActive()
  84. {
  85. return (m_Status & CH_ACTIF) != 0;
  86. }
  87. bool IsLocal()
  88. {
  89. return (m_Status & LOCAL_RATSNEST_ITEM) != 0;
  90. }
  91. /**
  92. * Function Draw
  93. */
  94. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
  95. const wxPoint& offset );
  96. };
  97. /**
  98. * Class NETINFO
  99. * is a container class for NETINFO_ITEM elements, which are the nets. That makes
  100. * this class a container for the nets.
  101. */
  102. class NETINFO_LIST
  103. {
  104. friend class BOARD;
  105. public:
  106. NETINFO_LIST( BOARD* aParent );
  107. ~NETINFO_LIST();
  108. /**
  109. * Function GetItem
  110. * @param aNetcode = netcode to identify a given NETINFO_ITEM
  111. * @return NETINFO_ITEM* - by \a aNetcode, or NULL if not found
  112. */
  113. NETINFO_ITEM* GetNetItem( int aNetcode ) const
  114. {
  115. if( unsigned( aNetcode ) >= GetNetCount() ) // catches < 0 too
  116. return NULL;
  117. return m_NetBuffer[aNetcode];
  118. }
  119. /**
  120. * Function GetNetCount
  121. * @return the number of nets ( always >= 1 )
  122. * because the first net is the "not connected" net and always exists
  123. */
  124. unsigned GetNetCount() const { return m_NetBuffer.size(); }
  125. /**
  126. * Function Append
  127. * adds \a aNewElement to the end of the list.
  128. */
  129. void AppendNet( NETINFO_ITEM* aNewElement );
  130. /**
  131. * Function GetPadCount
  132. * @return the number of pads in board
  133. */
  134. unsigned GetPadCount() const { return m_PadsFullList.size(); }
  135. /**
  136. * Function GetPads
  137. * returns a list of all the pads. The returned list is not
  138. * sorted and contains pointers to PADS, but those pointers do not convey
  139. * ownership of the respective PADs.
  140. * @return std::vector<D_PAD*>& - a full list of pads
  141. std::vector<D_PAD*>& GetPads()
  142. {
  143. return m_PadsFullList;
  144. }
  145. */
  146. /**
  147. * Function GetPad
  148. * @return the pad idx from m_PadsFullList
  149. */
  150. D_PAD* GetPad( unsigned aIdx ) const
  151. {
  152. if( aIdx < m_PadsFullList.size() )
  153. return m_PadsFullList[aIdx];
  154. else
  155. return NULL;
  156. }
  157. #if defined(DEBUG)
  158. void Show() const;
  159. #endif
  160. private:
  161. /**
  162. * Function DeleteData
  163. * deletes the list of nets (and free memory)
  164. */
  165. void clear();
  166. /**
  167. * Function buildListOfNets
  168. * builds or rebuilds the list of NETINFO_ITEMs
  169. * The list is sorted by names.
  170. */
  171. void buildListOfNets();
  172. /**
  173. * Function buildPadsFullList
  174. * creates the pad list, and initializes:
  175. * m_Pads (list of pads)
  176. * set m_Status_Pcb = LISTE_PAD_OK;
  177. * and clear for all pads in list the m_SubRatsnest member;
  178. * clear m_Pcb->m_FullRatsnest
  179. */
  180. void buildPadsFullList();
  181. BOARD* m_Parent;
  182. std::vector<NETINFO_ITEM*> m_NetBuffer; ///< net list (name, design constraints ..)
  183. std::vector<D_PAD*> m_PadsFullList; ///< contains all pads, sorted by pad's netname.
  184. ///< can be used in ratsnest calculations.
  185. };
  186. /**
  187. * Class NETINFO_ITEM
  188. * handles the data for a net
  189. */
  190. class NETINFO_ITEM
  191. {
  192. private:
  193. int m_NetCode; ///< A number equivalent to the net name.
  194. ///< Used for fast comparisons in ratsnest and DRC computations.
  195. wxString m_Netname; ///< Full net name like /mysheet/mysubsheet/vout
  196. ///< used by Eeschema
  197. wxString m_ShortNetname; // short net name, like vout from
  198. // /mysheet/mysubsheet/vout
  199. wxString m_NetClassName; // Net Class name. if void this is equivalent
  200. // to "default" (the first
  201. // item of the net classes list
  202. NETCLASS* m_NetClass;
  203. BOARD_ITEM* m_parent; ///< The parent board item object the net belongs to.
  204. public:
  205. int m_NbNodes; // Pads count for this net
  206. int m_NbLink; // Ratsnets count for this net
  207. int m_NbNoconn; // Ratsnets remaining to route count
  208. int m_Flag; // used in some calculations. Had no
  209. // special meaning
  210. std::vector <D_PAD*> m_PadInNetList; // List of pads connected to this net
  211. unsigned m_RatsnestStartIdx; /* Starting point of ratsnests of this
  212. * net (included) in a general buffer of
  213. * ratsnest (a vector<RATSNEST_ITEM*>
  214. * buffer) */
  215. unsigned m_RatsnestEndIdx; // Ending point of ratsnests of this net
  216. // (excluded) in this buffer
  217. NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = 0 );
  218. ~NETINFO_ITEM();
  219. /**
  220. * Function SetClass
  221. * sets \a aNetclass into this NET
  222. */
  223. void SetClass( const NETCLASS* aNetClass )
  224. {
  225. m_NetClass = (NETCLASS*) aNetClass;
  226. if( aNetClass )
  227. m_NetClassName = aNetClass->GetName();
  228. else
  229. m_NetClassName = NETCLASS::Default;
  230. }
  231. NETCLASS* GetNetClass()
  232. {
  233. return m_NetClass;
  234. }
  235. /**
  236. * Function GetClassName
  237. * returns the class name
  238. */
  239. const wxString& GetClassName() const
  240. {
  241. return m_NetClassName;
  242. }
  243. #if 1
  244. /**
  245. * Function GetTrackWidth
  246. * returns the width of tracks used to route this net.
  247. */
  248. int GetTrackWidth()
  249. {
  250. wxASSERT( m_NetClass );
  251. return m_NetClass->GetTrackWidth();
  252. }
  253. /**
  254. * Function GetViaSize
  255. * returns the size of vias used to route this net
  256. */
  257. int GetViaSize()
  258. {
  259. wxASSERT( m_NetClass );
  260. return m_NetClass->GetViaDiameter();
  261. }
  262. /**
  263. * Function GetMicroViaSize
  264. * returns the size of vias used to route this net
  265. */
  266. int GetMicroViaSize()
  267. {
  268. wxASSERT( m_NetClass );
  269. return m_NetClass->GetuViaDiameter();
  270. }
  271. /**
  272. * Function GetViaDrillSize
  273. * returns the size of via drills used to route this net
  274. */
  275. int GetViaDrillSize()
  276. {
  277. wxASSERT( m_NetClass );
  278. return m_NetClass->GetViaDrill();
  279. }
  280. /**
  281. * Function GetViaDrillSize
  282. * returns the size of via drills used to route this net
  283. */
  284. int GetMicroViaDrillSize()
  285. {
  286. wxASSERT( m_NetClass );
  287. return m_NetClass->GetuViaDrill();
  288. }
  289. #if 0
  290. /**
  291. * Function GetViaMinSize
  292. * returns the Minimum value for via sizes (used in DRC)
  293. */
  294. int GetViaMinSize()
  295. {
  296. wxASSERT( m_NetClass );
  297. return m_NetClass->GetViaMinSize();
  298. }
  299. #endif
  300. /**
  301. * Function GetClearance
  302. * returns the clearance when routing near aBoardItem
  303. */
  304. int GetClearance( BOARD_ITEM* aBoardItem )
  305. {
  306. wxASSERT( m_NetClass );
  307. return m_NetClass->GetClearance();
  308. }
  309. #endif
  310. /**
  311. * Function Draw
  312. * @todo we actually could show a NET, simply show all the tracks and
  313. * a pads or net name on pad and vias
  314. */
  315. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
  316. const wxPoint& offset );
  317. /**
  318. * Function GetNet
  319. * @return int - the netcode
  320. */
  321. int GetNet() const { return m_NetCode; }
  322. void SetNet( int aNetCode ) { m_NetCode = aNetCode; }
  323. int GetNodesCount() const { return m_PadInNetList.size(); }
  324. /**
  325. * Function GetNetname
  326. * @return const wxString * , a pointer to the full netname
  327. */
  328. wxString GetNetname() const { return m_Netname; }
  329. /**
  330. * Function GetShortNetname
  331. * @return const wxString * , a pointer to the short netname
  332. */
  333. wxString GetShortNetname() const { return m_ShortNetname; }
  334. /**
  335. * Function SetNetname
  336. * @param aNetname : the new netname
  337. */
  338. void SetNetname( const wxString& aNetname );
  339. /**
  340. * Function GetMsgPanelInfo
  341. * returns the information about the #NETINFO_ITEM in \a aList to display in the
  342. * message panel.
  343. *
  344. * @param aList is the list in which to place the status information.
  345. */
  346. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  347. };
  348. /***********************************************************/
  349. /* Description of a trace point for monitoring connections */
  350. /***********************************************************/
  351. #define START_ON_PAD 0x10
  352. #define END_ON_PAD 0x20
  353. #define START_ON_TRACK 0x40
  354. #define END_ON_TRACK 0x80
  355. /* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */
  356. enum StatusPcbFlags {
  357. LISTE_PAD_OK = 1, /* Pad list is Ok */
  358. LISTE_RATSNEST_ITEM_OK = 2, /* General Ratsnest is Ok */
  359. RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE ratsnest is Ok */
  360. CONNEXION_OK = 8, /* List of connections exists. */
  361. NET_CODES_OK = 0x10, /* Bit indicating that Netcode is OK,
  362. * do not change net name. */
  363. DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general
  364. * ratsnest (used in module moves) */
  365. };
  366. #endif // __CLASSES_NETINFO__