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.

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