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.

964 lines
28 KiB

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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2015 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 eeschema/netlist.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <schframe.h>
  30. #include <confirm.h>
  31. #include <netlist_exporter_kicad.h>
  32. #include <kiway.h>
  33. #include <netlist.h>
  34. #include <class_netlist_object.h>
  35. #include <class_library.h>
  36. #include <lib_pin.h>
  37. #include <sch_junction.h>
  38. #include <sch_component.h>
  39. #include <sch_line.h>
  40. #include <sch_no_connect.h>
  41. #include <sch_text.h>
  42. #include <sch_sheet.h>
  43. #include <algorithm>
  44. #include <invoke_sch_dialog.h>
  45. #include <boost/foreach.hpp>
  46. #define IS_WIRE false
  47. #define IS_BUS true
  48. /** @brief Kicad can use case sensitive or case insensitive comparisons for labels
  49. * Currently, it uses case insensitive.
  50. * Can be changed by comment/uncomment next lines.
  51. */
  52. inline int CmpLabel_KEEPCASE( const wxString& aString1, const wxString& aString2 )
  53. {
  54. return aString1.Cmp( aString2 ); // case sensitive
  55. //return aString1.CmpNoCase( aString2 ); // case insensitive
  56. }
  57. //Imported function:
  58. int TestDuplicateSheetNames( bool aCreateMarker );
  59. bool SCH_EDIT_FRAME::prepareForNetlist()
  60. {
  61. SCH_SHEET_LIST sheets;
  62. sheets.AnnotatePowerSymbols( Prj().SchLibs() );
  63. // Performs some controls:
  64. if( CheckAnnotate( NULL, 0 ) )
  65. {
  66. // Schematic must be annotated: call Annotate dialog and tell
  67. // the user why that is.
  68. InvokeDialogAnnotate( this, _( "Exporting the netlist requires a "
  69. "completely\nannotated schematic." ) );
  70. if( CheckAnnotate( NULL, 0 ) )
  71. return false;
  72. }
  73. // Test duplicate sheet names:
  74. if( TestDuplicateSheetNames( false ) > 0 )
  75. {
  76. if( !IsOK( NULL, _( "Error: duplicate sheet names. Continue?" ) ) )
  77. return false;
  78. }
  79. // Cleanup the entire hierarchy
  80. SCH_SCREENS screens;
  81. screens.SchematicCleanUp();
  82. return true;
  83. }
  84. void SCH_EDIT_FRAME::sendNetlist()
  85. {
  86. NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase();
  87. NETLIST_EXPORTER_KICAD exporter( net_atoms, Prj().SchLibs() );
  88. STRING_FORMATTER formatter;
  89. // @todo : trim GNL_ALL down to minimum for CVPCB
  90. exporter.Format( &formatter, GNL_ALL );
  91. Kiway().ExpressMail( FRAME_CVPCB,
  92. MAIL_EESCHEMA_NETLIST,
  93. formatter.GetString(), // an abbreviated "kicad" (s-expr) netlist
  94. this
  95. );
  96. }
  97. bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
  98. unsigned aNetlistOptions, REPORTER* aReporter )
  99. {
  100. if( !prepareForNetlist() )
  101. return false;
  102. std::auto_ptr<NETLIST_OBJECT_LIST> connectedItemsList( BuildNetListBase() );
  103. bool success = WriteNetListFile( connectedItemsList.release(), aFormat,
  104. aFullFileName, aNetlistOptions, aReporter );
  105. return success;
  106. }
  107. //#define NETLIST_DEBUG
  108. NETLIST_OBJECT_LIST::~NETLIST_OBJECT_LIST()
  109. {
  110. Clear();
  111. }
  112. void NETLIST_OBJECT_LIST::Clear()
  113. {
  114. NETLIST_OBJECTS::iterator iter;
  115. for( iter = begin(); iter != end(); iter++ )
  116. {
  117. NETLIST_OBJECT* item = *iter;
  118. delete item;
  119. }
  120. clear();
  121. }
  122. void NETLIST_OBJECT_LIST::SortListbyNetcode()
  123. {
  124. sort( this->begin(), this->end(), NETLIST_OBJECT_LIST::sortItemsbyNetcode );
  125. }
  126. void NETLIST_OBJECT_LIST::SortListbySheet()
  127. {
  128. sort( this->begin(), this->end(), NETLIST_OBJECT_LIST::sortItemsBySheet );
  129. }
  130. NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase()
  131. {
  132. // I own this list until I return it to the new owner.
  133. std::auto_ptr<NETLIST_OBJECT_LIST> ret( new NETLIST_OBJECT_LIST() );
  134. // Creates the flattened sheet list:
  135. SCH_SHEET_LIST aSheets;
  136. // Build netlist info
  137. bool success = ret->BuildNetListInfo( aSheets );
  138. if( !success )
  139. {
  140. SetStatusText( _( "No Objects" ) );
  141. return ret.release();
  142. }
  143. wxString msg = wxString::Format( _( "Net count = %d" ), int( ret->size() ) );
  144. SetStatusText( msg );
  145. return ret.release();
  146. }
  147. bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets )
  148. {
  149. SCH_SHEET_PATH* sheet;
  150. // Fill list with connected items from the flattened sheet list
  151. for( sheet = aSheets.GetFirst(); sheet != NULL;
  152. sheet = aSheets.GetNext() )
  153. {
  154. for( SCH_ITEM* item = sheet->LastScreen()->GetDrawItems(); item; item = item->Next() )
  155. {
  156. item->GetNetListItem( *this, sheet );
  157. }
  158. }
  159. if( size() == 0 )
  160. return false;
  161. // Sort objects by Sheet
  162. SortListbySheet();
  163. sheet = &(GetItem( 0 )->m_SheetPath);
  164. m_lastNetCode = m_lastBusNetCode = 1;
  165. for( unsigned ii = 0, istart = 0; ii < size(); ii++ )
  166. {
  167. NETLIST_OBJECT* net_item = GetItem( ii );
  168. if( net_item->m_SheetPath != *sheet ) // Sheet change
  169. {
  170. sheet = &(net_item->m_SheetPath);
  171. istart = ii;
  172. }
  173. switch( net_item->m_Type )
  174. {
  175. case NET_ITEM_UNSPECIFIED:
  176. wxMessageBox( wxT( "BuildNetListBase() error" ) );
  177. break;
  178. case NET_PIN:
  179. case NET_PINLABEL:
  180. case NET_SHEETLABEL:
  181. case NET_NOCONNECT:
  182. if( net_item->GetNet() != 0 )
  183. break;
  184. case NET_SEGMENT:
  185. // Test connections point to point type without bus.
  186. if( net_item->GetNet() == 0 )
  187. {
  188. net_item->SetNet( m_lastNetCode );
  189. m_lastNetCode++;
  190. }
  191. pointToPointConnect( net_item, IS_WIRE, istart );
  192. break;
  193. case NET_JUNCTION:
  194. // Control of the junction outside BUS.
  195. if( net_item->GetNet() == 0 )
  196. {
  197. net_item->SetNet( m_lastNetCode );
  198. m_lastNetCode++;
  199. }
  200. segmentToPointConnect( net_item, IS_WIRE, istart );
  201. // Control of the junction, on BUS.
  202. if( net_item->m_BusNetCode == 0 )
  203. {
  204. net_item->m_BusNetCode = m_lastBusNetCode;
  205. m_lastBusNetCode++;
  206. }
  207. segmentToPointConnect( net_item, IS_BUS, istart );
  208. break;
  209. case NET_LABEL:
  210. case NET_HIERLABEL:
  211. case NET_GLOBLABEL:
  212. // Test connections type junction without bus.
  213. if( net_item->GetNet() == 0 )
  214. {
  215. net_item->SetNet( m_lastNetCode );
  216. m_lastNetCode++;
  217. }
  218. segmentToPointConnect( net_item, IS_WIRE, istart );
  219. break;
  220. case NET_SHEETBUSLABELMEMBER:
  221. if( net_item->m_BusNetCode != 0 )
  222. break;
  223. case NET_BUS:
  224. // Control type connections point to point mode bus
  225. if( net_item->m_BusNetCode == 0 )
  226. {
  227. net_item->m_BusNetCode = m_lastBusNetCode;
  228. m_lastBusNetCode++;
  229. }
  230. pointToPointConnect( net_item, IS_BUS, istart );
  231. break;
  232. case NET_BUSLABELMEMBER:
  233. case NET_HIERBUSLABELMEMBER:
  234. case NET_GLOBBUSLABELMEMBER:
  235. // Control connections similar has on BUS
  236. if( net_item->GetNet() == 0 )
  237. {
  238. net_item->m_BusNetCode = m_lastBusNetCode;
  239. m_lastBusNetCode++;
  240. }
  241. segmentToPointConnect( net_item, IS_BUS, istart );
  242. break;
  243. }
  244. }
  245. #if defined(NETLIST_DEBUG) && defined(DEBUG)
  246. std::cout << "\n\nafter sheet local\n\n";
  247. DumpNetTable();
  248. #endif
  249. // Updating the Bus Labels Netcode connected by Bus
  250. connectBusLabels();
  251. // Group objects by label.
  252. for( unsigned ii = 0; ii < size(); ii++ )
  253. {
  254. switch( GetItem( ii )->m_Type )
  255. {
  256. case NET_PIN:
  257. case NET_SHEETLABEL:
  258. case NET_SEGMENT:
  259. case NET_JUNCTION:
  260. case NET_BUS:
  261. case NET_NOCONNECT:
  262. break;
  263. case NET_LABEL:
  264. case NET_GLOBLABEL:
  265. case NET_PINLABEL:
  266. case NET_BUSLABELMEMBER:
  267. case NET_GLOBBUSLABELMEMBER:
  268. labelConnect( GetItem( ii ) );
  269. break;
  270. case NET_SHEETBUSLABELMEMBER:
  271. case NET_HIERLABEL:
  272. case NET_HIERBUSLABELMEMBER:
  273. break;
  274. case NET_ITEM_UNSPECIFIED:
  275. break;
  276. }
  277. }
  278. #if defined(NETLIST_DEBUG) && defined(DEBUG)
  279. std::cout << "\n\nafter sheet global\n\n";
  280. DumpNetTable();
  281. #endif
  282. // Connection between hierarchy sheets
  283. for( unsigned ii = 0; ii < size(); ii++ )
  284. {
  285. if( GetItem( ii )->m_Type == NET_SHEETLABEL
  286. || GetItem( ii )->m_Type == NET_SHEETBUSLABELMEMBER )
  287. sheetLabelConnect( GetItem( ii ) );
  288. }
  289. // Sort objects by NetCode
  290. SortListbyNetcode();
  291. #if defined(NETLIST_DEBUG) && defined(DEBUG)
  292. std::cout << "\n\nafter qsort()\n";
  293. DumpNetTable();
  294. #endif
  295. // Compress numbers of Netcode having consecutive values.
  296. int NetCode = 0;
  297. m_lastNetCode = 0;
  298. for( unsigned ii = 0; ii < size(); ii++ )
  299. {
  300. if( GetItem( ii )->GetNet() != m_lastNetCode )
  301. {
  302. NetCode++;
  303. m_lastNetCode = GetItem( ii )->GetNet();
  304. }
  305. GetItem( ii )->SetNet( NetCode );
  306. }
  307. // Set the minimal connection info:
  308. setUnconnectedFlag();
  309. // find the best label object to give the best net name to each net
  310. findBestNetNameForEachNet();
  311. return true;
  312. }
  313. // Helper function to give a priority to sort labels:
  314. // NET_PINLABEL and NET_GLOBLABEL are global labels
  315. // and the priority is hight
  316. static int getPriority( const NETLIST_OBJECT* Objet )
  317. {
  318. switch( Objet->m_Type )
  319. {
  320. case NET_PIN: return 1;
  321. case NET_LABEL: return 2;
  322. case NET_HIERLABEL: return 3;
  323. case NET_PINLABEL: return 4;
  324. case NET_GLOBLABEL: return 5;
  325. default: break;
  326. }
  327. return 0;
  328. }
  329. /* function evalLabelsPriority used by findBestNetNameForEachNet()
  330. * evalLabelsPriority calculates the priority of alabel1 and aLabel2
  331. * return true if alabel1 has a highter priority than aLabel2
  332. */
  333. static bool evalLabelsPriority( const NETLIST_OBJECT* aLabel1,
  334. const NETLIST_OBJECT* aLabel2 )
  335. {
  336. int priority1 = getPriority( aLabel1 );
  337. int priority2 = getPriority( aLabel2 );
  338. if( priority1 != priority2 )
  339. return priority1 > priority2;
  340. // Objects have here the same priority, therefore they have the same type.
  341. // for global labels, we select the best candidate by alphabetic order
  342. // because they have no sheetpath as prefix name
  343. // for other labels, we select them before by sheet deep order
  344. // because the actual name is /sheetpath/label
  345. // and for a given path length, by alphabetic order
  346. if( aLabel1->m_Type == NET_PINLABEL || aLabel1->m_Type == NET_GLOBLABEL )
  347. return aLabel1->m_Label.Cmp( aLabel2->m_Label ) < 0;
  348. // not global: names are prefixed by their sheetpath
  349. // use name defined in higher hierarchical sheet
  350. // (i.e. shorter path because paths are /<timestamp1>/<timestamp2>/...
  351. // and timestamp = 8 letters.
  352. if( aLabel1->m_SheetPath.Path().Length() != aLabel2->m_SheetPath.Path().Length() )
  353. return aLabel1->m_SheetPath.Path().Length() < aLabel2->m_SheetPath.Path().Length();
  354. // Sheet paths have the same length: use alphabetic label name order
  355. // For labels on sheets having an equivalent deep in hierarchy, use
  356. // alphabetic label name order:
  357. if( aLabel1->m_Label.Cmp( aLabel2->m_Label ) != 0 )
  358. return aLabel1->m_Label.Cmp( aLabel2->m_Label ) < 0;
  359. return aLabel1->m_SheetPath.PathHumanReadable().Cmp(
  360. aLabel2->m_SheetPath.PathHumanReadable() ) < 0;
  361. }
  362. void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
  363. {
  364. int netcode = 0; // current netcode for tested items
  365. unsigned idxstart = 0; // index of the first item of this net
  366. NETLIST_OBJECT* item;
  367. NETLIST_OBJECT* candidate;
  368. // Pass 1: find the best name for labelled nets:
  369. candidate = NULL;
  370. for( unsigned ii = 0; ii <= size(); ii++ )
  371. {
  372. if( ii == size() ) // last item already tested
  373. item = NULL;
  374. else
  375. item = GetItem( ii );
  376. if( !item || netcode != item->GetNet() ) // End of net found
  377. {
  378. if( candidate ) // One or more labels exists, find the best
  379. {
  380. for (unsigned jj = idxstart; jj < ii; jj++ )
  381. GetItem( jj )->SetNetNameCandidate( candidate );
  382. }
  383. if( item == NULL )
  384. break;
  385. netcode = item->GetNet();
  386. candidate = NULL;
  387. idxstart = ii;
  388. }
  389. switch( item->m_Type )
  390. {
  391. case NET_HIERLABEL:
  392. case NET_LABEL:
  393. case NET_PINLABEL:
  394. case NET_GLOBLABEL:
  395. // A candidate is found: select the better between the previous
  396. // and this one
  397. if( candidate == NULL )
  398. candidate = item;
  399. else
  400. {
  401. if( evalLabelsPriority( item, candidate ) )
  402. // item has a highter priority than candidate
  403. // so update the best candidate
  404. candidate = item;
  405. }
  406. break;
  407. default:
  408. break;
  409. }
  410. }
  411. // Pass 2: find the best name for not labelled nets:
  412. // The "default" net name is Net-<<Ref cmp>_Pad<num pad>>
  413. // (see NETLIST_OBJECT::GetShortNetName())
  414. // therefore the "best" is the short net name alphabetically classed first
  415. // (to avoid net names changes when the net is not modified,
  416. // even if components are moved or deleted and undelete or replaced, as long
  417. // the reference is kept)
  418. // Build a list of items with no net names
  419. NETLIST_OBJECTS list; // no ownership of elements being pointed at
  420. for( unsigned ii = 0; ii < size(); ii++ )
  421. {
  422. item = GetItem( ii );
  423. if( !item->HasNetNameCandidate() )
  424. list.push_back( item );
  425. }
  426. if( list.size() == 0 )
  427. return;
  428. idxstart = 0;
  429. candidate = NULL;
  430. netcode = list[0]->GetNet();
  431. for( unsigned ii = 0; ii <= list.size(); ii++ )
  432. {
  433. if( ii < list.size() )
  434. item = list[ii];
  435. else
  436. item = NULL;
  437. if( !item || netcode != item->GetNet() ) // End of net found
  438. {
  439. if( candidate )
  440. {
  441. for (unsigned jj = idxstart; jj < ii; jj++ )
  442. {
  443. NETLIST_OBJECT* obj = list[jj];
  444. obj->SetNetNameCandidate( candidate );
  445. }
  446. }
  447. if( !item )
  448. break;
  449. netcode = item->GetNet();
  450. candidate = NULL;
  451. idxstart = ii;
  452. }
  453. // Examine all pins of the net to find the best candidate,
  454. // i.e. the first net name candidate, by alphabetic order
  455. // the net names are names bu_ilt by GetShortNetName
  456. // (Net-<{reference}-Pad{pad number}> like Net-<U3-Pad5>
  457. // Not named nets do not have usually a lot of members.
  458. // Many have only 2 members(a pad and a non connection symbol)
  459. if( item->m_Type == NET_PIN )
  460. {
  461. // A candidate is found, however components which are not in
  462. // netlist are not candidate because some have their reference
  463. // changed each time the netlist is built (power components)
  464. // and anyway obviously they are not a good candidate
  465. SCH_COMPONENT* link = item->GetComponentParent();
  466. if( link && link->IsInNetlist() )
  467. {
  468. // select the better between the previous and this one
  469. item->SetNetNameCandidate( item ); // Needed to calculate GetShortNetName
  470. if( candidate == NULL )
  471. candidate = item;
  472. else
  473. {
  474. if( item->GetShortNetName().Cmp( candidate->GetShortNetName() ) < 0 )
  475. candidate = item;
  476. }
  477. }
  478. }
  479. }
  480. }
  481. void NETLIST_OBJECT_LIST::sheetLabelConnect( NETLIST_OBJECT* SheetLabel )
  482. {
  483. if( SheetLabel->GetNet() == 0 )
  484. return;
  485. for( unsigned ii = 0; ii < size(); ii++ )
  486. {
  487. NETLIST_OBJECT* ObjetNet = GetItem( ii );
  488. if( ObjetNet->m_SheetPath != SheetLabel->m_SheetPathInclude )
  489. continue; //use SheetInclude, not the sheet!!
  490. if( (ObjetNet->m_Type != NET_HIERLABEL ) && (ObjetNet->m_Type != NET_HIERBUSLABELMEMBER ) )
  491. continue;
  492. if( ObjetNet->GetNet() == SheetLabel->GetNet() )
  493. continue; //already connected.
  494. if( CmpLabel_KEEPCASE( ObjetNet->m_Label, SheetLabel->m_Label ) != 0 )
  495. continue; //different names.
  496. // Propagate Netcode having all the objects of the same Netcode.
  497. if( ObjetNet->GetNet() )
  498. propageNetCode( ObjetNet->GetNet(), SheetLabel->GetNet(), IS_WIRE );
  499. else
  500. ObjetNet->SetNet( SheetLabel->GetNet() );
  501. }
  502. }
  503. void NETLIST_OBJECT_LIST::connectBusLabels()
  504. {
  505. for( unsigned ii = 0; ii < size(); ii++ )
  506. {
  507. NETLIST_OBJECT* Label = GetItem( ii );
  508. if( (Label->m_Type == NET_SHEETBUSLABELMEMBER)
  509. || (Label->m_Type == NET_BUSLABELMEMBER)
  510. || (Label->m_Type == NET_HIERBUSLABELMEMBER) )
  511. {
  512. if( Label->GetNet() == 0 )
  513. {
  514. Label->SetNet( m_lastNetCode );
  515. m_lastNetCode++;
  516. }
  517. for( unsigned jj = ii + 1; jj < size(); jj++ )
  518. {
  519. NETLIST_OBJECT* LabelInTst = GetItem( jj );
  520. if( (LabelInTst->m_Type == NET_SHEETBUSLABELMEMBER)
  521. || (LabelInTst->m_Type == NET_BUSLABELMEMBER)
  522. || (LabelInTst->m_Type == NET_HIERBUSLABELMEMBER) )
  523. {
  524. if( LabelInTst->m_BusNetCode != Label->m_BusNetCode )
  525. continue;
  526. if( LabelInTst->m_Member != Label->m_Member )
  527. continue;
  528. if( LabelInTst->GetNet() == 0 )
  529. LabelInTst->SetNet( Label->GetNet() );
  530. else
  531. propageNetCode( LabelInTst->GetNet(), Label->GetNet(), IS_WIRE );
  532. }
  533. }
  534. }
  535. }
  536. }
  537. void NETLIST_OBJECT_LIST::propageNetCode( int aOldNetCode, int aNewNetCode, bool aIsBus )
  538. {
  539. if( aOldNetCode == aNewNetCode )
  540. return;
  541. if( aIsBus == false ) // Propagate NetCode
  542. {
  543. for( unsigned jj = 0; jj < size(); jj++ )
  544. {
  545. NETLIST_OBJECT* object = GetItem( jj );
  546. if( object->GetNet() == aOldNetCode )
  547. object->SetNet( aNewNetCode );
  548. }
  549. }
  550. else // Propagate BusNetCode
  551. {
  552. for( unsigned jj = 0; jj < size(); jj++ )
  553. {
  554. NETLIST_OBJECT* object = GetItem( jj );
  555. if( object->m_BusNetCode == aOldNetCode )
  556. object->m_BusNetCode = aNewNetCode;
  557. }
  558. }
  559. }
  560. void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus,
  561. int start )
  562. {
  563. int netCode;
  564. if( aIsBus == false ) // Objects other than BUS and BUSLABELS
  565. {
  566. netCode = aRef->GetNet();
  567. for( unsigned i = start; i < size(); i++ )
  568. {
  569. NETLIST_OBJECT* item = GetItem( i );
  570. if( item->m_SheetPath != aRef->m_SheetPath ) //used to be > (why?)
  571. continue;
  572. switch( item->m_Type )
  573. {
  574. case NET_SEGMENT:
  575. case NET_PIN:
  576. case NET_LABEL:
  577. case NET_HIERLABEL:
  578. case NET_GLOBLABEL:
  579. case NET_SHEETLABEL:
  580. case NET_PINLABEL:
  581. case NET_JUNCTION:
  582. case NET_NOCONNECT:
  583. if( aRef->m_Start == item->m_Start
  584. || aRef->m_Start == item->m_End
  585. || aRef->m_End == item->m_Start
  586. || aRef->m_End == item->m_End )
  587. {
  588. if( item->GetNet() == 0 )
  589. item->SetNet( netCode );
  590. else
  591. propageNetCode( item->GetNet(), netCode, IS_WIRE );
  592. }
  593. break;
  594. case NET_BUS:
  595. case NET_BUSLABELMEMBER:
  596. case NET_SHEETBUSLABELMEMBER:
  597. case NET_HIERBUSLABELMEMBER:
  598. case NET_GLOBBUSLABELMEMBER:
  599. case NET_ITEM_UNSPECIFIED:
  600. break;
  601. }
  602. }
  603. }
  604. else // Object type BUS, BUSLABELS, and junctions.
  605. {
  606. netCode = aRef->m_BusNetCode;
  607. for( unsigned i = start; i < size(); i++ )
  608. {
  609. NETLIST_OBJECT* item = GetItem( i );
  610. if( item->m_SheetPath != aRef->m_SheetPath )
  611. continue;
  612. switch( item->m_Type )
  613. {
  614. case NET_ITEM_UNSPECIFIED:
  615. case NET_SEGMENT:
  616. case NET_PIN:
  617. case NET_LABEL:
  618. case NET_HIERLABEL:
  619. case NET_GLOBLABEL:
  620. case NET_SHEETLABEL:
  621. case NET_PINLABEL:
  622. case NET_NOCONNECT:
  623. break;
  624. case NET_BUS:
  625. case NET_BUSLABELMEMBER:
  626. case NET_SHEETBUSLABELMEMBER:
  627. case NET_HIERBUSLABELMEMBER:
  628. case NET_GLOBBUSLABELMEMBER:
  629. case NET_JUNCTION:
  630. if( aRef->m_Start == item->m_Start
  631. || aRef->m_Start == item->m_End
  632. || aRef->m_End == item->m_Start
  633. || aRef->m_End == item->m_End )
  634. {
  635. if( item->m_BusNetCode == 0 )
  636. item->m_BusNetCode = netCode;
  637. else
  638. propageNetCode( item->m_BusNetCode, netCode, IS_BUS );
  639. }
  640. break;
  641. }
  642. }
  643. }
  644. }
  645. void NETLIST_OBJECT_LIST::segmentToPointConnect( NETLIST_OBJECT* aJonction,
  646. bool aIsBus, int aIdxStart )
  647. {
  648. for( unsigned i = aIdxStart; i < size(); i++ )
  649. {
  650. NETLIST_OBJECT* segment = GetItem( i );
  651. // if different sheets, obviously no physical connection between elements.
  652. if( segment->m_SheetPath != aJonction->m_SheetPath )
  653. continue;
  654. if( aIsBus == IS_WIRE )
  655. {
  656. if( segment->m_Type != NET_SEGMENT )
  657. continue;
  658. }
  659. else
  660. {
  661. if( segment->m_Type != NET_BUS )
  662. continue;
  663. }
  664. if( IsPointOnSegment( segment->m_Start, segment->m_End, aJonction->m_Start ) )
  665. {
  666. // Propagation Netcode has all the objects of the same Netcode.
  667. if( aIsBus == IS_WIRE )
  668. {
  669. if( segment->GetNet() )
  670. propageNetCode( segment->GetNet(), aJonction->GetNet(), aIsBus );
  671. else
  672. segment->SetNet( aJonction->GetNet() );
  673. }
  674. else
  675. {
  676. if( segment->m_BusNetCode )
  677. propageNetCode( segment->m_BusNetCode, aJonction->m_BusNetCode, aIsBus );
  678. else
  679. segment->m_BusNetCode = aJonction->m_BusNetCode;
  680. }
  681. }
  682. }
  683. }
  684. void NETLIST_OBJECT_LIST::labelConnect( NETLIST_OBJECT* aLabelRef )
  685. {
  686. if( aLabelRef->GetNet() == 0 )
  687. return;
  688. for( unsigned i = 0; i < size(); i++ )
  689. {
  690. NETLIST_OBJECT* item = GetItem( i );
  691. if( item->GetNet() == aLabelRef->GetNet() )
  692. continue;
  693. if( item->m_SheetPath != aLabelRef->m_SheetPath )
  694. {
  695. if( item->m_Type != NET_PINLABEL && item->m_Type != NET_GLOBLABEL
  696. && item->m_Type != NET_GLOBBUSLABELMEMBER )
  697. continue;
  698. if( (item->m_Type == NET_GLOBLABEL
  699. || item->m_Type == NET_GLOBBUSLABELMEMBER)
  700. && item->m_Type != aLabelRef->m_Type )
  701. //global labels only connect other global labels.
  702. continue;
  703. }
  704. // NET_HIERLABEL are used to connect sheets.
  705. // NET_LABEL are local to a sheet
  706. // NET_GLOBLABEL are global.
  707. // NET_PINLABEL is a kind of global label (generated by a power pin invisible)
  708. if( item->IsLabelType() )
  709. {
  710. if( CmpLabel_KEEPCASE( item->m_Label, aLabelRef->m_Label ) != 0 )
  711. continue;
  712. if( item->GetNet() )
  713. propageNetCode( item->GetNet(), aLabelRef->GetNet(), IS_WIRE );
  714. else
  715. item->SetNet( aLabelRef->GetNet() );
  716. }
  717. }
  718. }
  719. void NETLIST_OBJECT_LIST::setUnconnectedFlag()
  720. {
  721. NETLIST_OBJECT* NetItemRef;
  722. unsigned NetStart, NetEnd;
  723. NET_CONNECTION_T StateFlag;
  724. NetStart = NetEnd = 0;
  725. StateFlag = UNCONNECTED;
  726. for( unsigned ii = 0; ii < size(); ii++ )
  727. {
  728. NetItemRef = GetItem( ii );
  729. if( NetItemRef->m_Type == NET_NOCONNECT && StateFlag != PAD_CONNECT )
  730. StateFlag = NOCONNECT_SYMBOL_PRESENT;
  731. // Analysis of current net.
  732. unsigned idxtoTest = ii + 1;
  733. if( ( idxtoTest >= size() )
  734. || ( NetItemRef->GetNet() != GetItem( idxtoTest )->GetNet() ) )
  735. {
  736. // Net analysis to update m_ConnectionType
  737. NetEnd = idxtoTest;
  738. /* set m_ConnectionType member to StateFlag for all items of
  739. * this net: */
  740. for( unsigned kk = NetStart; kk < NetEnd; kk++ )
  741. GetItem( kk )->m_ConnectionType = StateFlag;
  742. if( idxtoTest >= size() )
  743. return;
  744. // Start Analysis next Net
  745. StateFlag = UNCONNECTED;
  746. NetStart = idxtoTest;
  747. continue;
  748. }
  749. /* test the current item: if this is a pin and if the reference item
  750. * is also a pin, then 2 pins are connected, so set StateFlag to
  751. * PAD_CONNECT (can be already done) Of course, if the current
  752. * item is a no connect symbol, set StateFlag to
  753. * NOCONNECT_SYMBOL_PRESENT to inhibit error diags. However if
  754. * StateFlag is already set to PAD_CONNECT this state is kept (the
  755. * no connect symbol was surely an error and an ERC will report this)
  756. */
  757. for( ; ; idxtoTest++ )
  758. {
  759. if( ( idxtoTest >= size() )
  760. || ( NetItemRef->GetNet() != GetItem( idxtoTest )->GetNet() ) )
  761. break;
  762. switch( GetItem( idxtoTest )->m_Type )
  763. {
  764. case NET_ITEM_UNSPECIFIED:
  765. wxMessageBox( wxT( "BuildNetListBase() error" ) );
  766. break;
  767. case NET_SEGMENT:
  768. case NET_LABEL:
  769. case NET_HIERLABEL:
  770. case NET_GLOBLABEL:
  771. case NET_SHEETLABEL:
  772. case NET_PINLABEL:
  773. case NET_BUS:
  774. case NET_BUSLABELMEMBER:
  775. case NET_SHEETBUSLABELMEMBER:
  776. case NET_HIERBUSLABELMEMBER:
  777. case NET_GLOBBUSLABELMEMBER:
  778. case NET_JUNCTION:
  779. break;
  780. case NET_PIN:
  781. if( NetItemRef->m_Type == NET_PIN )
  782. StateFlag = PAD_CONNECT;
  783. break;
  784. case NET_NOCONNECT:
  785. if( StateFlag != PAD_CONNECT )
  786. StateFlag = NOCONNECT_SYMBOL_PRESENT;
  787. break;
  788. }
  789. }
  790. }
  791. }