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.

460 lines
17 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file class_netlist_object.h
  27. * @brief Definition of the NETLIST_OBJECT class.
  28. */
  29. #ifndef _CLASS_NETLIST_OBJECT_H_
  30. #define _CLASS_NETLIST_OBJECT_H_
  31. #include <sch_sheet_path.h>
  32. #include <lib_pin.h> // LIB_PIN::PinStringNum( m_PinNum )
  33. class NETLIST_OBJECT_LIST;
  34. class SCH_COMPONENT;
  35. /* Type of Net objects (wires, labels, pins...) */
  36. enum NETLIST_ITEM_T
  37. {
  38. NET_ITEM_UNSPECIFIED, // only for not yet initialized instances
  39. NET_SEGMENT, // connection by wire
  40. NET_BUS, // connection by bus
  41. NET_JUNCTION, // connection by junction: can connect to
  42. // or more crossing wires
  43. NET_LABEL, // this is a local label
  44. NET_GLOBLABEL, // this is a global label that connect all
  45. // others global label in whole hierarchy
  46. NET_HIERLABEL, // element to indicate connection to a
  47. // higher-level sheet
  48. NET_SHEETLABEL, // element to indicate connection to a
  49. // lower-level sheet.
  50. NET_BUSLABELMEMBER, /* created when a bus label is found:
  51. * the bus label (like DATA[0..7] is
  52. * converted to n single labels like
  53. * DATA0, DATA1 ...
  54. */
  55. NET_GLOBBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
  56. // global bus label is found
  57. NET_HIERBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
  58. // hierarchical bus label is found
  59. NET_SHEETBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
  60. // pin sheet label using bus notation
  61. // is found
  62. NET_PINLABEL, /* created when a pin is POWER (IN or
  63. * OUT) with invisible attribute is found:
  64. * these pins are equivalent to a global
  65. * label and are automatically connected
  66. */
  67. NET_PIN, // this is an usual pin
  68. NET_NOCONNECT // this is a no connect symbol
  69. };
  70. /* Values for .m_FlagOfConnection member */
  71. enum NET_CONNECTION_T
  72. {
  73. UNCONNECTED = 0, /* Pin or Label not connected (error) */
  74. NOCONNECT_SYMBOL_PRESENT, /* Pin not connected but have a NoConnect
  75. * symbol on it (no error) */
  76. PAD_CONNECT /* Normal connection (no error) */
  77. };
  78. class NETLIST_OBJECT
  79. {
  80. public:
  81. NETLIST_ITEM_T m_Type; /* Type of item (see NETLIST_ITEM_T enum) */
  82. EDA_ITEM* m_Comp; /* Pointer to the library item that
  83. * created this net object (the parent)
  84. */
  85. SCH_ITEM* m_Link; /* For SCH_SHEET_PIN:
  86. * Pointer to the hierarchy sheet that
  87. * contains this SCH_SHEET_PIN
  88. * For Pins: pointer to the schematic component
  89. * that contains this pin
  90. */
  91. int m_Flag; /* flag used in calculations */
  92. SCH_SHEET_PATH m_SheetPath; // the sheet path which contains this item
  93. SCH_SHEET_PATH m_SheetPathInclude; // sheet path which contains the hierarchical label
  94. int m_ElectricalType; /* Has meaning only for Pins and
  95. * hierarchical pins: electrical type */
  96. int m_BusNetCode; /* Used for BUS connections */
  97. int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member
  98. * created from the BUS label ) member number.
  99. */
  100. NET_CONNECTION_T m_ConnectionType; // Used to store the connection type
  101. long m_PinNum; // pin number ( 1 long = 4 bytes -> 4 ascii codes)
  102. wxString m_Label; // Label text (for labels) or Pin name (for pins)
  103. wxPoint m_Start; // Position of object or for segments: starting point
  104. wxPoint m_End; // For segments (wire and buses): ending point
  105. private:
  106. int m_netCode; /* net code for all items except BUS
  107. * labels because a BUS label has
  108. * as many net codes as bus members
  109. */
  110. NETLIST_OBJECT* m_netNameCandidate; /* a pointer to a label connected to the net,
  111. * that can be used to give a name to the net
  112. * or a pin if there is no label in net
  113. * When no label, the pin is used to build
  114. * default net name.
  115. */
  116. public:
  117. #if defined(DEBUG)
  118. void Show( std::ostream& out, int ndx ) const; // override
  119. #endif
  120. NETLIST_OBJECT();
  121. NETLIST_OBJECT( NETLIST_OBJECT& aSource ); // Copy constructor
  122. ~NETLIST_OBJECT();
  123. // Accessors:
  124. void SetNet( int aNetCode ) { m_netCode = aNetCode; }
  125. int GetNet() const { return m_netCode; }
  126. /**
  127. * Set the item connection type:
  128. * UNCONNECTED Pin or Label not connected (error)
  129. * NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect
  130. * symbol on it (no error)
  131. * PAD_CONNECT Normal connection (no error)
  132. */
  133. void SetConnectionType( NET_CONNECTION_T aFlg = UNCONNECTED )
  134. {
  135. m_ConnectionType = aFlg;
  136. }
  137. NET_CONNECTION_T GetConnectionType()
  138. {
  139. return m_ConnectionType;
  140. }
  141. /**
  142. * Set m_netNameCandidate to a connected item which will
  143. * be used to calcule the net name of the item
  144. * Obviously the candidate can be only a label
  145. * when there is no label on the net a pad which will
  146. * used to build a net name (something like Cmp<REF>_Pad<PAD_NAME>
  147. * @param aCandidate = the connected item candidate
  148. */
  149. void SetNetNameCandidate( NETLIST_OBJECT* aCandidate );
  150. /**
  151. * @return true if an item has already a net name candidate
  152. * and false if not ( m_netNameCandidate == NULL )
  153. */
  154. bool HasNetNameCandidate() { return m_netNameCandidate != NULL; }
  155. /**
  156. * Function GetPinNum
  157. * returns a pin number in wxString form. Pin numbers are not always
  158. * numbers. \"A23\" would be a valid pin number.
  159. */
  160. wxString GetPinNumText()
  161. {
  162. // hide the ugliness in here, but do it inline.
  163. return LIB_PIN::PinStringNum( m_PinNum );
  164. }
  165. /** For Pins (NET_PINS):
  166. * @return the schematic component which contains this pin
  167. * (Note: this is the schematic component, not the library component
  168. * for others items: return NULL
  169. */
  170. SCH_COMPONENT* GetComponentParent() const
  171. {
  172. if( m_Link && m_Link->Type() == SCH_COMPONENT_T )
  173. return (SCH_COMPONENT*) m_Link;
  174. return NULL;
  175. }
  176. /**
  177. * Function IsLabelConnected
  178. * tests if the net list object is a hierarchical label or sheet label and is
  179. * connected to an associated hierarchical label or sheet label of \a aNetItem.
  180. *
  181. * @param aNetItem A pointer to a NETLIST_OBJECT to test against.
  182. * @return A bool value of true if there is a connection with \a aNetItem or false
  183. * if no connection to \a aNetItem.
  184. */
  185. bool IsLabelConnected( NETLIST_OBJECT* aNetItem );
  186. /**
  187. * Function IsLabelGlobal
  188. * @return true if the object is a global label
  189. * (i.e. an real global label or a pin label coming
  190. * from a power pin invisible
  191. */
  192. bool IsLabelGlobal() const
  193. {
  194. return ( m_Type == NET_PINLABEL ) || ( m_Type == NET_GLOBLABEL );
  195. }
  196. /**
  197. * Function IsLabelType
  198. * @return true if the object is a label of any type
  199. */
  200. bool IsLabelType() const;
  201. /**
  202. * Function GetNetName
  203. * @return the full net name of the item, i.e. the net name
  204. * from the "best" label, prefixed by the sheet path
  205. */
  206. wxString GetNetName() const;
  207. /**
  208. * Function GetShortNetName
  209. * @return the short net name of the item i.e. the net name
  210. * from the "best" label without any prefix.
  211. * 2 different nets can have the same short name
  212. */
  213. wxString GetShortNetName() const;
  214. /**
  215. * Function ConvertBusToNetListItems
  216. * breaks the text of a bus label type net list object into as many members as
  217. * it contains and creates a #NETLIST_OBJECT for each label and adds it to \a
  218. * aNetListItems.
  219. *
  220. * @param aNetListItems A reference to vector of #NETLIST_OBJECT pointers to add
  221. * the bus label NETLIST_OBJECTs.
  222. */
  223. void ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems );
  224. };
  225. /**
  226. * NETLIST_OBJECT_LIST is a class to handle the list of connected items
  227. * in a full schematic hierarchy for netlist and erc calculations
  228. */
  229. class NETLIST_OBJECT_LIST : public std::vector <NETLIST_OBJECT*>
  230. {
  231. bool m_isOwner; // = true if the objects in list are owned my me, and therefore
  232. // the memory should be freed by the destructor and the list cleared
  233. int m_lastNetCode; // Used in intermediate calculation: last net code created
  234. int m_lastBusNetCode; // Used in intermediate calculation:
  235. // last net code created for bus members
  236. public:
  237. /**
  238. * Constructor.
  239. * NETLIST_OBJECT_LIST handle a list of connected items.
  240. * the instance can be owner of items or not.
  241. * If it is the owner, the items are freeed by the destructor
  242. * @param aIsOwner true if the instance is the owner of item list
  243. * (default = false)
  244. */
  245. NETLIST_OBJECT_LIST( bool aIsOwner = false ) { m_isOwner = aIsOwner; }
  246. ~NETLIST_OBJECT_LIST();
  247. void SetOwner( bool aIsOwner ) { m_isOwner = aIsOwner; }
  248. /**
  249. * Function BuildNetListInfo
  250. * the master function of tgis class.
  251. * Build the list of connected objects (pins, labels ...) and
  252. * all info to generate netlists or run ERC diags
  253. * @param aSheets = the flattened sheet list
  254. * @return true if OK, false is not item found
  255. */
  256. bool BuildNetListInfo( SCH_SHEET_LIST& aSheets );
  257. /*
  258. * Acces to an item in list
  259. */
  260. NETLIST_OBJECT* GetItem( unsigned aIdx ) const
  261. {
  262. return *( this->begin() + aIdx );
  263. }
  264. /*
  265. * Acces to an item type
  266. */
  267. NETLIST_ITEM_T GetItemType( unsigned aIdx ) const
  268. {
  269. return GetItem( aIdx )->m_Type;
  270. }
  271. /*
  272. * Acces to an item net code
  273. */
  274. int GetItemNet( unsigned aIdx ) const
  275. {
  276. return GetItem( aIdx )->GetNet();
  277. }
  278. NET_CONNECTION_T GetConnectionType( unsigned aIdx )
  279. {
  280. return GetItem( aIdx )->GetConnectionType();
  281. }
  282. /**
  283. * Set the item connection type:
  284. * UNCONNECTED Pin or Label not connected (error)
  285. * NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect
  286. * symbol on it (no error)
  287. * PAD_CONNECT Normal connection (no error)
  288. */
  289. void SetConnectionType( unsigned aIdx, NET_CONNECTION_T aFlg = UNCONNECTED )
  290. {
  291. GetItem( aIdx )->SetConnectionType( aFlg );
  292. }
  293. /*
  294. * Delete all objects in list and clear list
  295. * (delete NETLIST_OBJECT items)
  296. */
  297. void FreeList();
  298. /*
  299. * Clear list but do not delete NETLIST_OBJECT items
  300. * (they can be deleted only if the instance is owner of the items
  301. */
  302. void Clear() { this->clear(); }
  303. /**
  304. * Reset the connection type of all items to UNCONNECTED type
  305. */
  306. void ResetConnectionsType()
  307. {
  308. for( unsigned ii = 0; ii < size(); ii++ )
  309. GetItem( ii )->SetConnectionType( UNCONNECTED );
  310. }
  311. /*
  312. * Sorts the list of connected items by net code
  313. */
  314. void SortListbyNetcode();
  315. /*
  316. * Sorts the list of connected items by sheet.
  317. * This sorting is used when searching "physical" connection between items
  318. * because obviously only items inside the same sheet can be connected
  319. */
  320. void SortListbySheet();
  321. #if defined(DEBUG)
  322. void DumpNetTable()
  323. {
  324. for( unsigned idx = 0; idx < size(); ++idx )
  325. {
  326. GetItem( idx )->Show( std::cout, idx );
  327. }
  328. }
  329. #endif
  330. private:
  331. /*
  332. * Propagate aNewNetCode to items having an internal netcode aOldNetCode
  333. * used to interconnect group of items already physically connected,
  334. * when a new connection is found between aOldNetCode and aNewNetCode
  335. */
  336. void propageNetCode( int aOldNetCode, int aNewNetCode, bool aIsBus );
  337. /*
  338. * This function merges the net codes of groups of objects already connected
  339. * to labels (wires, bus, pins ... ) when 2 labels are equivalents
  340. * (i.e. group objects connected by labels)
  341. */
  342. void labelConnect( NETLIST_OBJECT* aLabelRef );
  343. /* Comparison function to sort by increasing Netcode the list of connected items
  344. */
  345. static bool sortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
  346. {
  347. return Objet1->GetNet() < Objet2->GetNet();
  348. }
  349. /* Comparison routine to sort items by Sheet Number
  350. */
  351. static bool sortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
  352. {
  353. return Objet1->m_SheetPath.Cmp( Objet2->m_SheetPath ) < 0;
  354. }
  355. /*
  356. * Propagate net codes from a parent sheet to an include sheet,
  357. * from a pin sheet connection
  358. */
  359. void sheetLabelConnect( NETLIST_OBJECT* aSheetLabel );
  360. void pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start );
  361. /*
  362. * Search connections betweena junction and segments
  363. * Propagate the junction net code to objects connected by this junction.
  364. * The junction must have a valid net code
  365. * The list of objects is expected sorted by sheets.
  366. * Search is done from index aIdxStart to the last element of list
  367. */
  368. void segmentToPointConnect( NETLIST_OBJECT* aJonction, bool aIsBus, int aIdxStart );
  369. void connectBusLabels();
  370. /*
  371. * Set the m_FlagOfConnection member of items in list
  372. * depending on the connection type:
  373. * UNCONNECTED, PAD_CONNECT or NOCONNECT_SYMBOL_PRESENT
  374. * The list is expected sorted by order of net code,
  375. * i.e. items having the same net code are grouped
  376. */
  377. void setUnconnectedFlag();
  378. /**
  379. * Function findBestNetNameForEachNet
  380. * fill the .m_NetNameCandidate member of each item of aNetItemBuffer
  381. * with a reference to the "best" NETLIST_OBJECT usable to give a name to the net
  382. * If no suitable object found, .m_NetNameCandidate is filled with 0.
  383. * The "best" NETLIST_OBJECT is a NETLIST_OBJECT that have the type label
  384. * and by priority order:
  385. * the label is global or local
  386. * the label is in the first sheet in a hierarchy (the root sheet has the most priority)
  387. * alphabetic order.
  388. */
  389. void findBestNetNameForEachNet();
  390. };
  391. /**
  392. * Function IsBusLabel
  393. * test if \a aLabel has a bus notation.
  394. *
  395. * @param aLabel A wxString object containing the label to test.
  396. * @return true if text is a bus notation format otherwise false is returned.
  397. */
  398. extern bool IsBusLabel( const wxString& aLabel );
  399. #endif // _CLASS_NETLIST_OBJECT_H_