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.

221 lines
7.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <board_design_settings.h>
  25. #include <pcb_edit_frame.h>
  26. #include <pcbnew_id.h>
  27. #include <pcb_track.h>
  28. #include <tools/pcb_actions.h>
  29. #include <tool/tool_manager.h>
  30. #include <wx/choice.h>
  31. void PCB_EDIT_FRAME::SetTrackSegmentWidth( PCB_TRACK* aItem, PICKED_ITEMS_LIST* aItemsListPicker,
  32. bool aUseDesignRules )
  33. {
  34. PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem );
  35. int new_width = -1;
  36. int new_drill = -1;
  37. if( aUseDesignRules )
  38. {
  39. MINOPTMAX<int> constraint = aItem->GetWidthConstraint();
  40. if( constraint.HasOpt() )
  41. new_width = constraint.Opt();
  42. else if( constraint.Min() > 0 )
  43. new_width = constraint.Min();
  44. if( via )
  45. {
  46. constraint = via->GetDrillConstraint();
  47. if( constraint.HasOpt() )
  48. new_drill = constraint.Opt();
  49. else if( constraint.Min() > 0 )
  50. new_drill = constraint.Min();
  51. }
  52. }
  53. else if( via && via->GetViaType() == VIATYPE::MICROVIA )
  54. {
  55. new_width = aItem->GetEffectiveNetClass()->GetuViaDiameter();
  56. new_drill = aItem->GetEffectiveNetClass()->GetuViaDrill();
  57. }
  58. else if( via )
  59. {
  60. new_width = GetDesignSettings().GetCurrentViaSize();
  61. new_drill = GetDesignSettings().GetCurrentViaDrill();
  62. }
  63. else
  64. {
  65. new_width = GetDesignSettings().GetCurrentTrackWidth();
  66. }
  67. if( new_width <= 0 )
  68. new_width = aItem->GetWidth();
  69. if( via && new_drill <= 0 )
  70. new_drill = via->GetDrillValue();
  71. if( aItem->GetWidth() != new_width || ( via && via->GetDrillValue() != new_drill ) )
  72. {
  73. ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
  74. picker.SetLink( aItem->Clone() );
  75. aItemsListPicker->PushItem( picker );
  76. aItem->SetWidth( new_width );
  77. if( via && new_drill > 0 )
  78. via->SetDrill( new_drill );
  79. }
  80. }
  81. void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
  82. {
  83. int ii;
  84. int id = event.GetId();
  85. switch( id )
  86. {
  87. case ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH:
  88. {
  89. if( GetDesignSettings().UseCustomTrackViaSize() )
  90. {
  91. GetDesignSettings().UseCustomTrackViaSize( false );
  92. GetDesignSettings().m_UseConnectedTrackWidth = true;
  93. }
  94. else
  95. {
  96. GetDesignSettings().m_UseConnectedTrackWidth =
  97. not GetDesignSettings().m_UseConnectedTrackWidth;
  98. }
  99. break;
  100. }
  101. case ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES:
  102. GetDesignSettings().m_UseConnectedTrackWidth = false;
  103. GetDesignSettings().SetTrackWidthIndex( 0 );
  104. GetDesignSettings().SetViaSizeIndex( 0 );
  105. break;
  106. case ID_POPUP_PCB_SELECT_AUTO_WIDTH:
  107. GetDesignSettings().m_UseConnectedTrackWidth = true;
  108. break;
  109. case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
  110. case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
  111. case ID_POPUP_PCB_SELECT_WIDTH3:
  112. case ID_POPUP_PCB_SELECT_WIDTH4:
  113. case ID_POPUP_PCB_SELECT_WIDTH5:
  114. case ID_POPUP_PCB_SELECT_WIDTH6:
  115. case ID_POPUP_PCB_SELECT_WIDTH7:
  116. case ID_POPUP_PCB_SELECT_WIDTH8:
  117. case ID_POPUP_PCB_SELECT_WIDTH9:
  118. case ID_POPUP_PCB_SELECT_WIDTH10:
  119. case ID_POPUP_PCB_SELECT_WIDTH11:
  120. case ID_POPUP_PCB_SELECT_WIDTH12:
  121. case ID_POPUP_PCB_SELECT_WIDTH13:
  122. case ID_POPUP_PCB_SELECT_WIDTH14:
  123. case ID_POPUP_PCB_SELECT_WIDTH15:
  124. case ID_POPUP_PCB_SELECT_WIDTH16:
  125. GetDesignSettings().m_UseConnectedTrackWidth = false;
  126. ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
  127. GetDesignSettings().SetTrackWidthIndex( ii );
  128. break;
  129. case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
  130. case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
  131. case ID_POPUP_PCB_SELECT_VIASIZE3:
  132. case ID_POPUP_PCB_SELECT_VIASIZE4:
  133. case ID_POPUP_PCB_SELECT_VIASIZE5:
  134. case ID_POPUP_PCB_SELECT_VIASIZE6:
  135. case ID_POPUP_PCB_SELECT_VIASIZE7:
  136. case ID_POPUP_PCB_SELECT_VIASIZE8:
  137. case ID_POPUP_PCB_SELECT_VIASIZE9:
  138. case ID_POPUP_PCB_SELECT_VIASIZE10:
  139. case ID_POPUP_PCB_SELECT_VIASIZE11:
  140. case ID_POPUP_PCB_SELECT_VIASIZE12:
  141. case ID_POPUP_PCB_SELECT_VIASIZE13:
  142. case ID_POPUP_PCB_SELECT_VIASIZE14:
  143. case ID_POPUP_PCB_SELECT_VIASIZE15:
  144. case ID_POPUP_PCB_SELECT_VIASIZE16:
  145. // select the new current value for via size (via diameter)
  146. ii = id - ID_POPUP_PCB_SELECT_VIASIZE1;
  147. GetDesignSettings().SetViaSizeIndex( ii );
  148. break;
  149. case ID_AUX_TOOLBAR_PCB_TRACK_WIDTH:
  150. ii = m_SelTrackWidthBox->GetSelection();
  151. if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
  152. {
  153. // this is the separator
  154. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  155. }
  156. else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
  157. {
  158. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  159. ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
  160. }
  161. else
  162. {
  163. GetDesignSettings().SetTrackWidthIndex( ii );
  164. GetDesignSettings().m_TempOverrideTrackWidth = true;
  165. }
  166. // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
  167. GetCanvas()->SetFocus();
  168. break;
  169. case ID_AUX_TOOLBAR_PCB_VIA_SIZE:
  170. ii = m_SelViaSizeBox->GetSelection();
  171. if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
  172. {
  173. // this is the separator
  174. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  175. }
  176. else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
  177. {
  178. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  179. ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
  180. }
  181. else
  182. {
  183. GetDesignSettings().SetViaSizeIndex( ii );
  184. }
  185. // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
  186. GetCanvas()->SetFocus();
  187. break;
  188. default:
  189. break;
  190. }
  191. m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged );
  192. }