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.

231 lines
8.2 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-2020 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* aTrackItem,
  32. PICKED_ITEMS_LIST* aItemsListPicker,
  33. bool aUseNetclassValue )
  34. {
  35. int initial_width;
  36. int new_width;
  37. int initial_drill = -1;
  38. int new_drill = -1;
  39. initial_width = aTrackItem->GetWidth();
  40. if( aUseNetclassValue )
  41. new_width = aTrackItem->GetEffectiveNetClass()->GetTrackWidth();
  42. else
  43. new_width = GetDesignSettings().GetCurrentTrackWidth();
  44. if( aTrackItem->Type() == PCB_VIA_T )
  45. {
  46. const PCB_VIA *via = static_cast<const PCB_VIA*>( aTrackItem );
  47. // Get the drill value, regardless it is default or specific
  48. initial_drill = via->GetDrillValue();
  49. if( via->GetViaType() == VIATYPE::MICROVIA )
  50. {
  51. new_width = aTrackItem->GetEffectiveNetClass()->GetuViaDiameter();
  52. new_drill = aTrackItem->GetEffectiveNetClass()->GetuViaDrill();
  53. }
  54. else if( aUseNetclassValue )
  55. {
  56. new_width = aTrackItem->GetEffectiveNetClass()->GetViaDiameter();
  57. new_drill = aTrackItem->GetEffectiveNetClass()->GetViaDrill();
  58. }
  59. else
  60. {
  61. new_width = GetDesignSettings().GetCurrentViaSize();
  62. new_drill = GetDesignSettings().GetCurrentViaDrill();
  63. }
  64. // Old versions set a drill value <= 0, when the default netclass it used but it could
  65. // be better to set the drill value to the actual value to avoid issues for existing vias,
  66. // if the default drill value is modified in the netclass, and not in current vias.
  67. if( via->GetDrill() <= 0 ) // means default netclass drill value used
  68. initial_drill = -1; // Force drill vias re-initialization
  69. }
  70. if( initial_width != new_width || initial_drill != new_drill )
  71. {
  72. if( aItemsListPicker )
  73. {
  74. aTrackItem->SetWidth( initial_width );
  75. ITEM_PICKER picker( nullptr, aTrackItem, UNDO_REDO::CHANGED );
  76. picker.SetLink( aTrackItem->Clone() );
  77. aItemsListPicker->PushItem( picker );
  78. aTrackItem->SetWidth( new_width );
  79. if( aTrackItem->Type() == PCB_VIA_T )
  80. {
  81. // Set new drill value. Note: currently microvias have only a default drill value
  82. PCB_VIA *via = static_cast<PCB_VIA*>( aTrackItem );
  83. if( new_drill > 0 )
  84. via->SetDrill( new_drill );
  85. else
  86. via->SetDrillDefault();
  87. }
  88. }
  89. }
  90. }
  91. void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
  92. {
  93. int ii;
  94. int id = event.GetId();
  95. switch( id )
  96. {
  97. case ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH:
  98. {
  99. if( GetDesignSettings().UseCustomTrackViaSize() )
  100. {
  101. GetDesignSettings().UseCustomTrackViaSize( false );
  102. GetDesignSettings().m_UseConnectedTrackWidth = true;
  103. }
  104. else
  105. {
  106. GetDesignSettings().m_UseConnectedTrackWidth =
  107. not GetDesignSettings().m_UseConnectedTrackWidth;
  108. }
  109. break;
  110. }
  111. case ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES:
  112. GetDesignSettings().m_UseConnectedTrackWidth = false;
  113. GetDesignSettings().SetTrackWidthIndex( 0 );
  114. GetDesignSettings().SetViaSizeIndex( 0 );
  115. break;
  116. case ID_POPUP_PCB_SELECT_AUTO_WIDTH:
  117. GetDesignSettings().m_UseConnectedTrackWidth = true;
  118. break;
  119. case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
  120. case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
  121. case ID_POPUP_PCB_SELECT_WIDTH3:
  122. case ID_POPUP_PCB_SELECT_WIDTH4:
  123. case ID_POPUP_PCB_SELECT_WIDTH5:
  124. case ID_POPUP_PCB_SELECT_WIDTH6:
  125. case ID_POPUP_PCB_SELECT_WIDTH7:
  126. case ID_POPUP_PCB_SELECT_WIDTH8:
  127. case ID_POPUP_PCB_SELECT_WIDTH9:
  128. case ID_POPUP_PCB_SELECT_WIDTH10:
  129. case ID_POPUP_PCB_SELECT_WIDTH11:
  130. case ID_POPUP_PCB_SELECT_WIDTH12:
  131. case ID_POPUP_PCB_SELECT_WIDTH13:
  132. case ID_POPUP_PCB_SELECT_WIDTH14:
  133. case ID_POPUP_PCB_SELECT_WIDTH15:
  134. case ID_POPUP_PCB_SELECT_WIDTH16:
  135. GetDesignSettings().m_UseConnectedTrackWidth = false;
  136. ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
  137. GetDesignSettings().SetTrackWidthIndex( ii );
  138. break;
  139. case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
  140. case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
  141. case ID_POPUP_PCB_SELECT_VIASIZE3:
  142. case ID_POPUP_PCB_SELECT_VIASIZE4:
  143. case ID_POPUP_PCB_SELECT_VIASIZE5:
  144. case ID_POPUP_PCB_SELECT_VIASIZE6:
  145. case ID_POPUP_PCB_SELECT_VIASIZE7:
  146. case ID_POPUP_PCB_SELECT_VIASIZE8:
  147. case ID_POPUP_PCB_SELECT_VIASIZE9:
  148. case ID_POPUP_PCB_SELECT_VIASIZE10:
  149. case ID_POPUP_PCB_SELECT_VIASIZE11:
  150. case ID_POPUP_PCB_SELECT_VIASIZE12:
  151. case ID_POPUP_PCB_SELECT_VIASIZE13:
  152. case ID_POPUP_PCB_SELECT_VIASIZE14:
  153. case ID_POPUP_PCB_SELECT_VIASIZE15:
  154. case ID_POPUP_PCB_SELECT_VIASIZE16:
  155. // select the new current value for via size (via diameter)
  156. ii = id - ID_POPUP_PCB_SELECT_VIASIZE1;
  157. GetDesignSettings().SetViaSizeIndex( ii );
  158. break;
  159. case ID_AUX_TOOLBAR_PCB_TRACK_WIDTH:
  160. ii = m_SelTrackWidthBox->GetSelection();
  161. if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
  162. {
  163. // this is the separator
  164. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  165. }
  166. else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
  167. {
  168. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  169. ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
  170. }
  171. else
  172. {
  173. GetDesignSettings().SetTrackWidthIndex( ii );
  174. GetDesignSettings().m_TempOverrideTrackWidth = true;
  175. }
  176. // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
  177. GetCanvas()->SetFocus();
  178. break;
  179. case ID_AUX_TOOLBAR_PCB_VIA_SIZE:
  180. ii = m_SelViaSizeBox->GetSelection();
  181. if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
  182. {
  183. // this is the separator
  184. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  185. }
  186. else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
  187. {
  188. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  189. ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
  190. }
  191. else
  192. {
  193. GetDesignSettings().SetViaSizeIndex( ii );
  194. }
  195. // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
  196. GetCanvas()->SetFocus();
  197. break;
  198. default:
  199. break;
  200. }
  201. m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged, true );
  202. }