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.

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