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.

234 lines
7.8 KiB

12 years ago
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time). Now, nets are saved with consecutive net codes (both modern & legacy plugins). Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp). Performed tests: - Changed a pad's net name from empty to existent - ok, name was changed. - Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty. - Changed a pad's net name from existent to empty - ok, net name became empty - Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed. - Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled. - Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes). - KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications). - A few boards were also saved using the legacy format and were opened with the master KiCad without any issues. - Change a net name for a pad, restore with undo/redo - ok - Remove everything, restore with undo - ok - Remove everything, reload netlist - ok Differences observed between files saved by the master branch KiCad and this one: - list of nets are not saved in any particular order, so net codes may differ - the default net class does not contain the unconnected net
12 years ago
12 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) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2020 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. #include <fctsys.h>
  26. #include <pcbnew.h>
  27. #include <class_board.h>
  28. #include <class_board_item.h>
  29. #include <connectivity/connectivity_data.h>
  30. using namespace std::placeholders;
  31. BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
  32. BOARD_ITEM( aParent, idtype ), m_netinfo( NETINFO_LIST::OrphanedItem() )
  33. {
  34. m_localRatsnestVisible = true;
  35. }
  36. bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
  37. {
  38. if( !IsOnCopperLayer() )
  39. aNetCode = 0;
  40. // if aNetCode < 0 ( typically NETINFO_LIST::FORCE_ORPHANED )
  41. // or no parent board,
  42. // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
  43. BOARD* board = GetBoard();
  44. //auto connectivity = board ? board->GetConnectivity() : nullptr;
  45. //bool addRatsnest = false;
  46. //if( connectivity )
  47. //addRatsnest = connectivity->Remove( this );
  48. if( ( aNetCode >= 0 ) && board )
  49. m_netinfo = board->FindNet( aNetCode );
  50. else
  51. m_netinfo = NETINFO_LIST::OrphanedItem();
  52. if( !aNoAssert )
  53. wxASSERT( m_netinfo );
  54. // Add only if it was previously added to the ratsnest
  55. //if( addRatsnest )
  56. // connectivity->Add( this );
  57. return ( m_netinfo != NULL );
  58. }
  59. // This method returns the Default netclass for nets which don't have their own.
  60. NETCLASS* BOARD_CONNECTED_ITEM::GetEffectiveNetclass() const
  61. {
  62. // NB: we must check the net first, as when it is 0 GetNetClass() will return the
  63. // orphaned net netclass, not the default netclass.
  64. if( m_netinfo->GetNet() == 0 )
  65. return GetBoard()->GetDesignSettings().GetDefault();
  66. else
  67. return GetNetClass();
  68. }
  69. /*
  70. * Clearances exist in a hiearchy. If a given level is specified then the remaining levels
  71. * are NOT consulted.
  72. *
  73. * LEVEL 1: (highest priority) local overrides (pad, footprint, etc.)
  74. * LEVEL 2: Rules
  75. * LEVEL 3: Accumulated local settings, netclass settings, & board design settings
  76. */
  77. int BOARD_CONNECTED_ITEM::GetClearance( PCB_LAYER_ID aLayer, BOARD_ITEM* aItem,
  78. wxString* aSource ) const
  79. {
  80. BOARD* board = GetBoard();
  81. int clearance = 0;
  82. wxString source;
  83. wxString* localSource = aSource ? &source : nullptr;
  84. BOARD_CONNECTED_ITEM* second = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
  85. // No clearance if "this" is not (yet) linked to a board therefore no available netclass
  86. if( !board )
  87. return clearance;
  88. // LEVEL 1: local overrides (pad, footprint, etc.)
  89. //
  90. if( GetLocalClearanceOverrides() > clearance )
  91. clearance = GetLocalClearanceOverrides( localSource );
  92. if( second && second->GetLocalClearanceOverrides() > clearance )
  93. clearance = second->GetLocalClearanceOverrides( localSource );
  94. if( clearance )
  95. {
  96. if( aSource )
  97. *aSource = *localSource;
  98. return clearance;
  99. }
  100. // LEVEL 2: Rules
  101. //
  102. if( GetRuleClearance( aItem, aLayer, &clearance, aSource ) )
  103. return clearance;
  104. // LEVEL 3: Accumulated local settings, netclass settings, & board design settings
  105. //
  106. BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
  107. NETCLASS* netclass = GetEffectiveNetclass();
  108. NETCLASS* secondNetclass = second ? second->GetEffectiveNetclass() : nullptr;
  109. if( bds.m_MinClearance > clearance )
  110. {
  111. if( aSource )
  112. *aSource = _( "board minimum" );
  113. clearance = bds.m_MinClearance;
  114. }
  115. if( netclass && netclass->GetClearance() > clearance )
  116. clearance = netclass->GetClearance( aSource );
  117. if( secondNetclass && secondNetclass->GetClearance() > clearance )
  118. clearance = secondNetclass->GetClearance( aSource );
  119. if( aItem && aItem->GetLayer() == Edge_Cuts && bds.m_CopperEdgeClearance > clearance )
  120. {
  121. if( aSource )
  122. *aSource = _( "board edge" );
  123. clearance = bds.m_CopperEdgeClearance;
  124. }
  125. if( GetLocalClearance() > clearance )
  126. clearance = GetLocalClearance( aSource );
  127. if( second && second->GetLocalClearance() > clearance )
  128. clearance = second->GetLocalClearance( aSource );
  129. return clearance;
  130. }
  131. bool BOARD_CONNECTED_ITEM::GetRuleClearance( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer,
  132. int* aClearance, wxString* aSource ) const
  133. {
  134. const DRC_CONSTRAINT* constraint = GetConstraint( this, aItem, DRC_RULE_ID_CLEARANCE, aLayer,
  135. aSource );
  136. if( constraint )
  137. {
  138. if( aSource )
  139. *aSource = wxString::Format( _( "'%s' rule" ), *aSource );
  140. *aClearance = constraint->m_Value.Min();
  141. return true;
  142. }
  143. return false;
  144. }
  145. // Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
  146. // std::shared_ptr stuff shows up large in performance profiling.
  147. NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const
  148. {
  149. NETCLASS* netclass = m_netinfo->GetNetClass();
  150. if( netclass )
  151. return netclass;
  152. else
  153. return GetBoard()->GetDesignSettings().GetDefault();
  154. }
  155. wxString BOARD_CONNECTED_ITEM::GetNetClassName() const
  156. {
  157. return m_netinfo->GetClassName();
  158. }
  159. static struct BOARD_CONNECTED_ITEM_DESC
  160. {
  161. BOARD_CONNECTED_ITEM_DESC()
  162. {
  163. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  164. if( layerEnum.Choices().GetCount() == 0 )
  165. {
  166. layerEnum.Undefined( UNDEFINED_LAYER );
  167. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  168. layerEnum.Map( *seq, LSET::Name( *seq ) );
  169. }
  170. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  171. REGISTER_TYPE( BOARD_CONNECTED_ITEM );
  172. propMgr.InheritsAfter( TYPE_HASH( BOARD_CONNECTED_ITEM ), TYPE_HASH( BOARD_ITEM ) );
  173. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _( "Layer" ),
  174. new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, PCB_LAYER_ID, BOARD_ITEM>( _( "Layer" ),
  175. &BOARD_CONNECTED_ITEM::SetLayer, &BOARD_CONNECTED_ITEM::GetLayer ) );
  176. propMgr.AddProperty( new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, int>( _( "Net" ),
  177. &BOARD_CONNECTED_ITEM::SetNetCode, &BOARD_CONNECTED_ITEM::GetNetCode ) );
  178. propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _( "NetName" ),
  179. NO_SETTER( BOARD_CONNECTED_ITEM, wxString ), &BOARD_CONNECTED_ITEM::GetNetname ) );
  180. propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _( "NetClass" ),
  181. NO_SETTER( BOARD_CONNECTED_ITEM, wxString ), &BOARD_CONNECTED_ITEM::GetNetClassName ) );
  182. }
  183. } _BOARD_CONNECTED_ITEM_DESC;