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.

185 lines
4.4 KiB

10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*
  2. * KiRouter - a push-and-(sometimes-)shove PCB router
  3. *
  4. * Copyright (C) 2014 CERN
  5. * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
  6. * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <class_board.h>
  22. #include "pns_item.h"
  23. #include "pns_via.h"
  24. #include "pns_solid.h"
  25. #include "pns_node.h"
  26. #include "pns_sizes_settings.h"
  27. namespace PNS {
  28. int SIZES_SETTINGS::inheritTrackWidth( ITEM* aItem )
  29. {
  30. VECTOR2I p;
  31. assert( aItem->Owner() != NULL );
  32. switch( aItem->Kind() )
  33. {
  34. case ITEM::VIA_T:
  35. p = static_cast<VIA*>( aItem )->Pos();
  36. break;
  37. case ITEM::SOLID_T:
  38. p = static_cast<SOLID*>( aItem )->Pos();
  39. break;
  40. case ITEM::SEGMENT_T:
  41. return static_cast<SEGMENT*>( aItem )->Width();
  42. default:
  43. return 0;
  44. }
  45. JOINT* jt = static_cast<NODE*>( aItem->Owner() )->FindJoint( p, aItem );
  46. assert( jt != NULL );
  47. int mval = INT_MAX;
  48. ITEM_SET linkedSegs = jt->Links();
  49. linkedSegs.ExcludeItem( aItem ).FilterKinds( ITEM::SEGMENT_T );
  50. for( ITEM* item : linkedSegs.Items() )
  51. {
  52. int w = static_cast<SEGMENT*>( item )->Width();
  53. mval = std::min( w, mval );
  54. }
  55. return ( mval == INT_MAX ? 0 : mval );
  56. }
  57. void SIZES_SETTINGS::Init( BOARD* aBoard, ITEM* aStartItem, int aNet )
  58. {
  59. BOARD_DESIGN_SETTINGS &bds = aBoard->GetDesignSettings();
  60. NETCLASSPTR netClass;
  61. int net = aNet;
  62. if( aStartItem )
  63. net = aStartItem->Net();
  64. if( net >= 0 )
  65. {
  66. NETINFO_ITEM* ni = aBoard->FindNet( net );
  67. if( ni )
  68. {
  69. wxString netClassName = ni->GetClassName();
  70. netClass = bds.m_NetClasses.Find( netClassName );
  71. }
  72. }
  73. if( !netClass )
  74. netClass = bds.GetDefault();
  75. m_trackWidth = 0;
  76. if( bds.m_UseConnectedTrackWidth && aStartItem != NULL )
  77. {
  78. m_trackWidth = inheritTrackWidth( aStartItem );
  79. }
  80. if( !m_trackWidth && ( bds.UseNetClassTrack() && netClass != NULL ) ) // netclass value
  81. {
  82. m_trackWidth = netClass->GetTrackWidth();
  83. }
  84. if( !m_trackWidth )
  85. {
  86. m_trackWidth = bds.GetCurrentTrackWidth();
  87. }
  88. if( bds.UseNetClassVia() && netClass != NULL ) // netclass value
  89. {
  90. m_viaDiameter = netClass->GetViaDiameter();
  91. m_viaDrill = netClass->GetViaDrill();
  92. }
  93. else
  94. {
  95. m_viaDiameter = bds.GetCurrentViaSize();
  96. m_viaDrill = bds.GetCurrentViaDrill();
  97. }
  98. if( bds.UseCustomDiffPairDimensions() )
  99. {
  100. m_diffPairWidth = bds.GetCustomDiffPairWidth();
  101. m_diffPairGap = bds.GetCustomDiffPairGap();
  102. m_diffPairViaGap = bds.GetCustomDiffPairViaGap();
  103. }
  104. else
  105. {
  106. m_diffPairWidth = bds.m_DiffPairDimensionsList[ bds.GetDiffPairIndex() ].m_Width;
  107. m_diffPairGap = bds.m_DiffPairDimensionsList[ bds.GetDiffPairIndex() ].m_Gap;
  108. m_diffPairViaGap = bds.m_DiffPairDimensionsList[ bds.GetDiffPairIndex() ].m_ViaGap;
  109. }
  110. m_layerPairs.clear();
  111. }
  112. void SIZES_SETTINGS::ClearLayerPairs()
  113. {
  114. m_layerPairs.clear();
  115. }
  116. void SIZES_SETTINGS::AddLayerPair( int aL1, int aL2 )
  117. {
  118. int top = std::min( aL1, aL2 );
  119. int bottom = std::max( aL1, aL2 );
  120. m_layerPairs[bottom] = top;
  121. m_layerPairs[top] = bottom;
  122. }
  123. void SIZES_SETTINGS::ImportCurrent( BOARD_DESIGN_SETTINGS& aSettings )
  124. {
  125. m_trackWidth = aSettings.GetCurrentTrackWidth();
  126. m_viaDiameter = aSettings.GetCurrentViaSize();
  127. m_viaDrill = aSettings.GetCurrentViaDrill();
  128. }
  129. int SIZES_SETTINGS::GetLayerTop() const
  130. {
  131. if( m_layerPairs.empty() )
  132. return F_Cu;
  133. else
  134. return m_layerPairs.begin()->first;
  135. }
  136. int SIZES_SETTINGS::GetLayerBottom() const
  137. {
  138. if( m_layerPairs.empty() )
  139. return B_Cu;
  140. else
  141. return m_layerPairs.begin()->second;
  142. }
  143. }