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.

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