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.

205 lines
6.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 The 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_POPUP_PCB_SELECT_USE_NETCLASS_VALUES:
  88. GetDesignSettings().m_UseConnectedTrackWidth = false;
  89. GetDesignSettings().SetTrackWidthIndex( 0 );
  90. GetDesignSettings().SetViaSizeIndex( 0 );
  91. break;
  92. case ID_POPUP_PCB_SELECT_AUTO_WIDTH:
  93. GetDesignSettings().m_UseConnectedTrackWidth = true;
  94. break;
  95. case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
  96. case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
  97. case ID_POPUP_PCB_SELECT_WIDTH3:
  98. case ID_POPUP_PCB_SELECT_WIDTH4:
  99. case ID_POPUP_PCB_SELECT_WIDTH5:
  100. case ID_POPUP_PCB_SELECT_WIDTH6:
  101. case ID_POPUP_PCB_SELECT_WIDTH7:
  102. case ID_POPUP_PCB_SELECT_WIDTH8:
  103. case ID_POPUP_PCB_SELECT_WIDTH9:
  104. case ID_POPUP_PCB_SELECT_WIDTH10:
  105. case ID_POPUP_PCB_SELECT_WIDTH11:
  106. case ID_POPUP_PCB_SELECT_WIDTH12:
  107. case ID_POPUP_PCB_SELECT_WIDTH13:
  108. case ID_POPUP_PCB_SELECT_WIDTH14:
  109. case ID_POPUP_PCB_SELECT_WIDTH15:
  110. case ID_POPUP_PCB_SELECT_WIDTH16:
  111. GetDesignSettings().m_UseConnectedTrackWidth = false;
  112. ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
  113. GetDesignSettings().SetTrackWidthIndex( ii );
  114. break;
  115. case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
  116. case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
  117. case ID_POPUP_PCB_SELECT_VIASIZE3:
  118. case ID_POPUP_PCB_SELECT_VIASIZE4:
  119. case ID_POPUP_PCB_SELECT_VIASIZE5:
  120. case ID_POPUP_PCB_SELECT_VIASIZE6:
  121. case ID_POPUP_PCB_SELECT_VIASIZE7:
  122. case ID_POPUP_PCB_SELECT_VIASIZE8:
  123. case ID_POPUP_PCB_SELECT_VIASIZE9:
  124. case ID_POPUP_PCB_SELECT_VIASIZE10:
  125. case ID_POPUP_PCB_SELECT_VIASIZE11:
  126. case ID_POPUP_PCB_SELECT_VIASIZE12:
  127. case ID_POPUP_PCB_SELECT_VIASIZE13:
  128. case ID_POPUP_PCB_SELECT_VIASIZE14:
  129. case ID_POPUP_PCB_SELECT_VIASIZE15:
  130. case ID_POPUP_PCB_SELECT_VIASIZE16:
  131. // select the new current value for via size (via diameter)
  132. ii = id - ID_POPUP_PCB_SELECT_VIASIZE1;
  133. GetDesignSettings().SetViaSizeIndex( ii );
  134. break;
  135. case ID_AUX_TOOLBAR_PCB_TRACK_WIDTH:
  136. ii = m_SelTrackWidthBox->GetSelection();
  137. if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
  138. {
  139. // this is the separator
  140. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  141. }
  142. else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
  143. {
  144. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  145. ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
  146. }
  147. else
  148. {
  149. GetDesignSettings().SetTrackWidthIndex( ii );
  150. GetDesignSettings().m_TempOverrideTrackWidth = true;
  151. }
  152. // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
  153. GetCanvas()->SetFocus();
  154. break;
  155. case ID_AUX_TOOLBAR_PCB_VIA_SIZE:
  156. ii = m_SelViaSizeBox->GetSelection();
  157. if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
  158. {
  159. // this is the separator
  160. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  161. }
  162. else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
  163. {
  164. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  165. ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
  166. }
  167. else
  168. {
  169. GetDesignSettings().SetViaSizeIndex( ii );
  170. }
  171. // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
  172. GetCanvas()->SetFocus();
  173. break;
  174. default:
  175. break;
  176. }
  177. m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged );
  178. }