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.

366 lines
11 KiB

  1. #ifndef PCB_NETLIST_H
  2. #define PCB_NETLIST_H
  3. /**
  4. * @file pcb_netlist.h
  5. */
  6. /*
  7. * This program source code file is part of KiCad, a free EDA CAD application.
  8. *
  9. * Copyright (C) 2012 Jean-Pierre Charras.
  10. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>.
  11. * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version 2
  16. * of the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, you may find one here:
  25. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  26. * or you may search the http://www.gnu.org website for the version 2 license,
  27. * or you may write to the Free Software Foundation, Inc.,
  28. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  29. */
  30. #include <boost/ptr_container/ptr_vector.hpp>
  31. #include <wx/arrstr.h>
  32. #include <fpid.h>
  33. class MODULE;
  34. class REPORTER;
  35. /**
  36. * Class COMPONENT_NET
  37. * is used to store the component pin name to net name associations stored in a netlist.
  38. */
  39. class COMPONENT_NET
  40. {
  41. wxString m_pinName;
  42. wxString m_netNumber;
  43. wxString m_netName;
  44. public:
  45. COMPONENT_NET() {}
  46. COMPONENT_NET( const wxString& aPinName, const wxString& aNetName )
  47. {
  48. m_pinName = aPinName;
  49. m_netName = aNetName;
  50. }
  51. const wxString& GetPinName() const { return m_pinName; }
  52. const wxString& GetNetName() const { return m_netName; }
  53. bool IsValid() const { return !m_pinName.IsEmpty(); }
  54. bool operator <( const COMPONENT_NET& aNet ) const
  55. {
  56. return m_pinName < aNet.m_pinName;
  57. }
  58. #if defined(DEBUG)
  59. /**
  60. * Function Show
  61. * is used to output the object tree, currently for debugging only.
  62. * @param aNestLevel An aid to prettier tree indenting, and is the level
  63. * of nesting of this object within the overall tree.
  64. * @param aReporter A reference to a #REPORTER object to output to.
  65. */
  66. virtual void Show( int aNestLevel, REPORTER& aReporter );
  67. #endif
  68. };
  69. typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
  70. /**
  71. * Class COMPONENT
  72. * is used to store components and all of their related information found in a netlist.
  73. */
  74. class COMPONENT
  75. {
  76. COMPONENT_NETS m_nets;
  77. wxArrayString m_footprintFilters; ///< Footprint filters found in netlist.
  78. wxString m_reference; ///< The component reference designator found in netlist.
  79. wxString m_value; ///< The component value found in netlist.
  80. // ZZZ This timestamp is string, not time_t
  81. wxString m_timeStamp; ///< The component full time stamp found in netlist.
  82. /// The name of the component in #m_library used when it was placed on the schematic..
  83. wxString m_name;
  84. /// The name of the component library where #m_name was found.
  85. wxString m_library;
  86. /// The #FPID of the footprint assigned to the component.
  87. FPID m_fpid;
  88. /// The #MODULE loaded for #m_fpid.
  89. std::auto_ptr< MODULE > m_footprint;
  90. /// Set to true if #m_fpid was changed when the footprint link file was read.
  91. bool m_footprintChanged;
  92. static COMPONENT_NET m_emptyNet;
  93. public:
  94. COMPONENT( const FPID& aFPID,
  95. const wxString& aReference,
  96. const wxString& aValue,
  97. const wxString& aTimeStamp )
  98. {
  99. m_fpid = aFPID;
  100. m_reference = aReference;
  101. m_value = aValue;
  102. m_timeStamp = aTimeStamp;
  103. m_footprintChanged = false;
  104. }
  105. virtual ~COMPONENT() { };
  106. void AddNet( const wxString& aPinName, const wxString& aNetName )
  107. {
  108. m_nets.push_back( COMPONENT_NET( aPinName, aNetName ) );
  109. }
  110. unsigned GetNetCount() const { return m_nets.size(); }
  111. const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
  112. const COMPONENT_NET& GetNet( const wxString& aPinName );
  113. void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
  114. void SetName( const wxString& aName ) { m_name = aName;}
  115. const wxString& GetName() const { return m_name; }
  116. void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
  117. const wxString& GetLibrary() const { return m_library; }
  118. const wxString& GetReference() const { return m_reference; }
  119. const wxString& GetValue() const { return m_value; }
  120. void SetFPID( const FPID& aFPID )
  121. {
  122. m_footprintChanged = !m_fpid.empty() && (m_fpid != aFPID);
  123. m_fpid = aFPID;
  124. }
  125. const FPID& GetFPID() const { return m_fpid; }
  126. const wxString& GetTimeStamp() const { return m_timeStamp; }
  127. void SetFootprintFilters( const wxArrayString& aFilterList )
  128. {
  129. m_footprintFilters = aFilterList;
  130. }
  131. const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
  132. /**
  133. * Function MatchesFootprintFilters
  134. *
  135. * @return true if \a aFootprintName matches any of the footprint filters or no footprint
  136. * filters are defined.
  137. */
  138. bool MatchesFootprintFilters( const wxString& aFootprintName ) const;
  139. MODULE* GetModule( bool aRelease = false )
  140. {
  141. return ( aRelease ) ? m_footprint.release() : m_footprint.get();
  142. }
  143. void SetModule( MODULE* aModule );
  144. bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
  145. {
  146. return aLibrary == m_library && aName == m_name;
  147. }
  148. bool FootprintChanged() const { return m_footprintChanged; }
  149. #if defined(DEBUG)
  150. /**
  151. * Function Show
  152. * is used to output the object tree, currently for debugging only.
  153. * @param aNestLevel An aid to prettier tree indenting, and is the level
  154. * of nesting of this object within the overall tree.
  155. * @param aReporter A reference to a #REPORTER object to output to.
  156. */
  157. virtual void Show( int aNestLevel, REPORTER& aReporter );
  158. #endif
  159. };
  160. typedef boost::ptr_vector< COMPONENT > COMPONENTS;
  161. typedef COMPONENTS::iterator COMPONENTS_ITER;
  162. typedef COMPONENTS::const_iterator COMPONENTS_CITER;
  163. /**
  164. * Class NETLIST
  165. * stores all of information read from a netlist along with the flags used to update
  166. * the NETLIST in the #BOARD.
  167. */
  168. class NETLIST
  169. {
  170. COMPONENTS m_components; ///< Components found in the netlist.
  171. /// Remove footprints from #BOARD not found in netlist when true.
  172. bool m_deleteExtraFootprints;
  173. /// Do not actually make any changes. Only report changes to #BOARD from netlist
  174. /// when true.
  175. bool m_isDryRun;
  176. /// Find component by time stamp if true or reference designator if false.
  177. bool m_findByTimeStamp;
  178. /// Replace component footprints when they differ from the netlist if true.
  179. bool m_replaceFootprints;
  180. public:
  181. NETLIST() :
  182. m_deleteExtraFootprints( false ),
  183. m_isDryRun( false ),
  184. m_findByTimeStamp( false ),
  185. m_replaceFootprints( false )
  186. {
  187. }
  188. /**
  189. * Function IsEmpty()
  190. * @return true if there are no components in the netlist.
  191. */
  192. bool IsEmpty() const { return m_components.empty(); }
  193. /**
  194. * Function Clear
  195. * removes all components from the netlist.
  196. */
  197. void Clear() { m_components.clear(); }
  198. /**
  199. * Function GetCount
  200. * @return the number of components in the netlist.
  201. */
  202. unsigned GetCount() const { return m_components.size(); }
  203. /**
  204. * Function GetComponent
  205. * returns the #COMPONENT at \a aIndex.
  206. *
  207. * @param aIndex the index in #m_components to fetch.
  208. * @return a pointer to the #COMPONENT at \a Index.
  209. */
  210. COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
  211. /**
  212. * Function AddComponent
  213. * adds \a aComponent to the NETLIST.
  214. *
  215. * @note If \a aComponent already exists in the NETLIST, \a aComponent is deleted
  216. * to prevent memory leaks. An assertion is raised in debug builds.
  217. *
  218. * @param aComponent is the COMPONENT to save to the NETLIST.
  219. */
  220. void AddComponent( COMPONENT* aComponent );
  221. /*
  222. * Function GetComponentByReference
  223. * returns a #COMPONENT by \a aReference.
  224. *
  225. * @param aReference is the reference designator the #COMPONENT.
  226. * @return a pointer to the #COMPONENT that matches \a aReference if found. Otherwise NULL.
  227. */
  228. COMPONENT* GetComponentByReference( const wxString& aReference );
  229. /*
  230. * Function GetComponentByTimeStamp
  231. * returns a #COMPONENT by \a aTimeStamp.
  232. *
  233. * @param aTimeStamp is the time stamp the #COMPONENT.
  234. * @return a pointer to the #COMPONENT that matches \a aTimeStamp if found. Otherwise NULL.
  235. */
  236. COMPONENT* GetComponentByTimeStamp( const wxString& aTimeStamp );
  237. void SortByFPID();
  238. void SortByReference();
  239. void SetDeleteExtraFootprints( bool aDeleteExtraFootprints )
  240. {
  241. m_deleteExtraFootprints = aDeleteExtraFootprints;
  242. }
  243. bool GetDeleteExtraFootprints() const { return m_deleteExtraFootprints; }
  244. void SetIsDryRun( bool aIsDryRun ) { m_isDryRun = aIsDryRun; }
  245. bool IsDryRun() const { return m_isDryRun; }
  246. void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
  247. bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
  248. void SetReplaceFootprints( bool aReplaceFootprints )
  249. {
  250. m_replaceFootprints = aReplaceFootprints;
  251. }
  252. bool GetReplaceFootprints() const { return m_replaceFootprints; }
  253. /**
  254. * Function AnyFootprintsLinked
  255. * @return true if any component with a footprint link is found.
  256. */
  257. bool AnyFootprintsLinked() const;
  258. /**
  259. * Function AllFootprintsLinked
  260. * @return true if all components have a footprint link.
  261. */
  262. bool AllFootprintsLinked() const;
  263. /**
  264. * Function NoFootprintsLinked
  265. * @return true if none of the components have a footprint link.
  266. */
  267. bool NoFootprintsLinked() const { return !AnyFootprintsLinked(); }
  268. /**
  269. * Function AnyFootprintsChanged
  270. * @return true if any components footprints were changed when the footprint link file
  271. * (*.cmp) was loaded.
  272. */
  273. bool AnyFootprintsChanged() const;
  274. #if defined(DEBUG)
  275. /**
  276. * Function Show
  277. * is used to output the object tree, currently for debugging only.
  278. * @param aNestLevel An aid to prettier tree indenting, and is the level
  279. * of nesting of this object within the overall tree.
  280. * @param aReporter A reference to a #REPORTER object to output to.
  281. */
  282. virtual void Show( int aNestLevel, REPORTER& aReporter );
  283. #endif
  284. };
  285. #endif // PCB_NETLIST_H