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.

183 lines
5.8 KiB

5 years ago
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-2021 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 <board.h>
  26. #include <board_connected_item.h>
  27. #include <board_design_settings.h>
  28. #include <connectivity/connectivity_data.h>
  29. #include <string_utils.h>
  30. #include <i18n_utility.h>
  31. #include <netinfo.h>
  32. using namespace std::placeholders;
  33. BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
  34. BOARD_ITEM( aParent, idtype ),
  35. m_netinfo( NETINFO_LIST::OrphanedItem() )
  36. {
  37. m_localRatsnestVisible = true;
  38. }
  39. bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
  40. {
  41. if( !IsOnCopperLayer() )
  42. aNetCode = 0;
  43. // if aNetCode < 0 (typically NETINFO_LIST::FORCE_ORPHANED) or no parent board,
  44. // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
  45. BOARD* board = GetBoard();
  46. if( ( aNetCode >= 0 ) && board )
  47. m_netinfo = board->FindNet( aNetCode );
  48. else
  49. m_netinfo = NETINFO_LIST::OrphanedItem();
  50. if( !aNoAssert )
  51. wxASSERT( m_netinfo );
  52. return ( m_netinfo != nullptr );
  53. }
  54. NETCLASS* BOARD_CONNECTED_ITEM::GetEffectiveNetclass() const
  55. {
  56. // NB: we must check the net first, as when it is 0 GetNetClass() will return the
  57. // orphaned net netclass, not the default netclass.
  58. if( !m_netinfo || m_netinfo->GetNetCode() == 0 )
  59. return GetBoard()->GetDesignSettings().GetDefault();
  60. else
  61. return GetNetClass();
  62. }
  63. int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
  64. {
  65. DRC_CONSTRAINT constraint;
  66. if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
  67. {
  68. BOARD_DESIGN_SETTINGS& bds = GetBoard()->GetDesignSettings();
  69. constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
  70. }
  71. if( constraint.Value().HasMin() )
  72. {
  73. if( aSource )
  74. *aSource = constraint.GetName();
  75. return constraint.Value().Min();
  76. }
  77. return 0;
  78. }
  79. int BOARD_CONNECTED_ITEM::GetNetCode() const
  80. {
  81. return m_netinfo ? m_netinfo->GetNetCode() : -1;
  82. }
  83. // Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
  84. // std::shared_ptr stuff shows up large in performance profiling.
  85. NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const
  86. {
  87. if( m_netinfo && m_netinfo->GetNetClass() )
  88. return m_netinfo->GetNetClass();
  89. else
  90. return GetBoard()->GetDesignSettings().GetDefault();
  91. }
  92. wxString BOARD_CONNECTED_ITEM::GetNetClassName() const
  93. {
  94. if( m_netinfo )
  95. return m_netinfo->GetNetClassName();
  96. else
  97. return wxEmptyString;
  98. }
  99. wxString BOARD_CONNECTED_ITEM::GetNetname() const
  100. {
  101. return m_netinfo ? m_netinfo->GetNetname() : wxString();
  102. }
  103. wxString BOARD_CONNECTED_ITEM::GetNetnameMsg() const
  104. {
  105. if( !GetBoard() )
  106. return wxT( "[** NO BOARD DEFINED **]" );
  107. wxString netname = GetNetname();
  108. if( !netname.length() )
  109. return wxT( "[<no net>]" );
  110. else if( GetNetCode() < 0 )
  111. return wxT( "[" ) + UnescapeString( netname ) + wxT( "](" ) + _( "Not Found" ) + wxT( ")" );
  112. else
  113. return wxT( "[" ) + UnescapeString( netname ) + wxT( "]" );
  114. }
  115. wxString BOARD_CONNECTED_ITEM::GetShortNetname() const
  116. {
  117. return m_netinfo->GetShortNetname();
  118. }
  119. static struct BOARD_CONNECTED_ITEM_DESC
  120. {
  121. BOARD_CONNECTED_ITEM_DESC()
  122. {
  123. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  124. if( layerEnum.Choices().GetCount() == 0 )
  125. {
  126. layerEnum.Undefined( UNDEFINED_LAYER );
  127. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  128. layerEnum.Map( *seq, LSET::Name( *seq ) );
  129. }
  130. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  131. REGISTER_TYPE( BOARD_CONNECTED_ITEM );
  132. propMgr.InheritsAfter( TYPE_HASH( BOARD_CONNECTED_ITEM ), TYPE_HASH( BOARD_ITEM ) );
  133. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ),
  134. new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, PCB_LAYER_ID, BOARD_ITEM>( _HKI( "Layer" ),
  135. &BOARD_CONNECTED_ITEM::SetLayer, &BOARD_CONNECTED_ITEM::GetLayer ) );
  136. propMgr.AddProperty( new PROPERTY_ENUM<BOARD_CONNECTED_ITEM, int>( _HKI( "Net" ),
  137. &BOARD_CONNECTED_ITEM::SetNetCode, &BOARD_CONNECTED_ITEM::GetNetCode ) );
  138. propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "NetName" ),
  139. NO_SETTER( BOARD_CONNECTED_ITEM, wxString ), &BOARD_CONNECTED_ITEM::GetNetname ) );
  140. propMgr.AddProperty( new PROPERTY<BOARD_CONNECTED_ITEM, wxString>( _HKI( "NetClass" ),
  141. NO_SETTER( BOARD_CONNECTED_ITEM, wxString ), &BOARD_CONNECTED_ITEM::GetNetClassName ) );
  142. }
  143. } _BOARD_CONNECTED_ITEM_DESC;