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.

295 lines
9.4 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2012 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. /**
  25. * @file globaleditpad.cpp
  26. */
  27. #include <fctsys.h>
  28. #include <common.h>
  29. #include <class_drawpanel.h>
  30. #include <confirm.h>
  31. #include <wxPcbStruct.h>
  32. #include <module_editor_frame.h>
  33. #include <class_board.h>
  34. #include <class_module.h>
  35. #include <pcbnew.h>
  36. #include <dialog_global_pads_edition.h>
  37. /*
  38. * PCB_EDIT_FRAME::Function DlgGlobalChange_PadSettings
  39. * Function to change pad caracteristics for the given footprint
  40. * or alls footprints which look like the given footprint
  41. * Options are set by the opened dialog.
  42. * aPad is the pattern. The given footprint is the parent of this pad
  43. * aRedraw: if true: redraws the footprint
  44. */
  45. void PCB_EDIT_FRAME::DlgGlobalChange_PadSettings( D_PAD* aPad, bool aRedraw )
  46. {
  47. int diag;
  48. if( aPad == NULL )
  49. aPad = &GetDesignSettings().m_Pad_Master;
  50. MODULE* module = aPad->GetParent();
  51. if( module == NULL )
  52. {
  53. DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
  54. return;
  55. }
  56. SetMsgPanel( module );
  57. {
  58. DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
  59. diag = dlg.ShowModal();
  60. }
  61. if( diag == -1 )
  62. return;
  63. bool edit_Same_Modules = false;
  64. if( diag == 1 )
  65. edit_Same_Modules = true;
  66. GlobalChange_PadSettings( aPad,edit_Same_Modules,
  67. DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
  68. DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
  69. DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter,
  70. aRedraw, true );
  71. }
  72. /*
  73. * FOOTPRINT_EDIT_FRAME::Function DlgGlobalChange_PadSettings
  74. * Function to change pad caracteristics for the given footprint
  75. * or alls footprints which look like the given footprint
  76. * Options are set by the opened dialog.
  77. * aPad is the pattern. The given footprint is the parent of this pad
  78. */
  79. void FOOTPRINT_EDIT_FRAME::DlgGlobalChange_PadSettings( D_PAD* aPad )
  80. {
  81. int diag;
  82. if( aPad == NULL )
  83. aPad = &GetDesignSettings().m_Pad_Master;
  84. MODULE* module = aPad->GetParent();
  85. if( module == NULL )
  86. {
  87. DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
  88. return;
  89. }
  90. SetMsgPanel( module );
  91. {
  92. DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
  93. dlg.m_buttonIdModules->Enable( false );
  94. diag = dlg.ShowModal();
  95. }
  96. if( diag == -1 )
  97. return;
  98. bool edit_Same_Modules = false;
  99. if( diag == 1 )
  100. edit_Same_Modules = true;
  101. GlobalChange_PadSettings( aPad, edit_Same_Modules,
  102. DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
  103. DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
  104. DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter,
  105. true, false );
  106. }
  107. /*
  108. * Function GlobalChange_PadSettings
  109. * Function to change pad caracteristics for the given footprint
  110. * or alls footprints which look like the given footprint
  111. * aPad is the pattern. The given footprint is the parent of this pad
  112. * aSameFootprints: if true, make changes on all identical footprints
  113. * aPadShapeFilter: if true, make changes only on pads having the same shape as aPad
  114. * aPadOrientFilter: if true, make changes only on pads having the same orientation as aPad
  115. * aPadLayerFilter: if true, make changes only on pads having the same layers as aPad
  116. * aRedraw: if true: redraws the footprint
  117. * aSaveForUndo: if true: create an entry in the Undo/Redo list
  118. * (usually: true in Schematic editor, false in Module editor)
  119. */
  120. void PCB_BASE_FRAME::GlobalChange_PadSettings( D_PAD* aPad,
  121. bool aSameFootprints,
  122. bool aPadShapeFilter,
  123. bool aPadOrientFilter,
  124. bool aPadLayerFilter,
  125. bool aRedraw, bool aSaveForUndo )
  126. {
  127. if( aPad == NULL )
  128. aPad = &GetDesignSettings().m_Pad_Master;
  129. MODULE* module = aPad->GetParent();
  130. if( module == NULL )
  131. {
  132. DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
  133. return;
  134. }
  135. // Search and copy the name of library reference.
  136. MODULE* Module_Ref = module;
  137. double pad_orient = aPad->GetOrientation() - Module_Ref->GetOrientation();
  138. // Prepare an undo list:
  139. if( aSaveForUndo )
  140. {
  141. PICKED_ITEMS_LIST itemsList;
  142. for( module = m_Pcb->m_Modules; module; module = module->Next() )
  143. {
  144. if( !aSameFootprints && (module != Module_Ref) )
  145. continue;
  146. if( module->GetFPID() != Module_Ref->GetFPID() )
  147. continue;
  148. bool saveMe = false;
  149. for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
  150. {
  151. // Filters changes prohibited.
  152. if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
  153. continue;
  154. double currpad_orient = pad->GetOrientation() - module->GetOrientation();
  155. if( aPadOrientFilter && ( currpad_orient != pad_orient ) )
  156. continue;
  157. if( aPadLayerFilter && pad->GetLayerSet() != aPad->GetLayerSet() )
  158. continue;
  159. saveMe = true;
  160. }
  161. if( saveMe )
  162. {
  163. ITEM_PICKER itemWrapper( module, UR_CHANGED );
  164. itemsList.PushItem( itemWrapper );
  165. }
  166. }
  167. SaveCopyInUndoList( itemsList, UR_CHANGED );
  168. }
  169. // Update the current module and same others modules if requested.
  170. for( module = m_Pcb->m_Modules; module; module = module->Next() )
  171. {
  172. if( !aSameFootprints && (module != Module_Ref) )
  173. continue;
  174. if( module->GetFPID() != Module_Ref->GetFPID() )
  175. continue;
  176. // Erase module on screen
  177. if( aRedraw )
  178. {
  179. module->SetFlags( DO_NOT_DRAW );
  180. m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
  181. module->ClearFlags( DO_NOT_DRAW );
  182. }
  183. for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
  184. {
  185. // Filters changes prohibited.
  186. if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
  187. continue;
  188. if( aPadOrientFilter && (pad->GetOrientation() - module->GetOrientation()) != pad_orient )
  189. continue;
  190. if( aPadLayerFilter )
  191. {
  192. if( pad->GetLayerSet() != aPad->GetLayerSet() )
  193. continue;
  194. }
  195. // Change characteristics:
  196. pad->SetAttribute( aPad->GetAttribute() );
  197. pad->SetShape( aPad->GetShape() );
  198. pad->SetLayerSet( aPad->GetLayerSet() );
  199. pad->SetSize( aPad->GetSize() );
  200. pad->SetDelta( aPad->GetDelta() );
  201. pad->SetOffset( aPad->GetOffset() );
  202. pad->SetDrillSize( aPad->GetDrillSize() );
  203. pad->SetDrillShape( aPad->GetDrillShape() );
  204. pad->SetOrientation( pad_orient + module->GetOrientation() );
  205. // copy also local mask margins, because these parameters usually depend on
  206. // pad sizes and layers
  207. pad->SetLocalSolderMaskMargin( aPad->GetLocalSolderMaskMargin() );
  208. pad->SetLocalSolderPasteMargin( aPad->GetLocalSolderPasteMargin() );
  209. pad->SetLocalSolderPasteMarginRatio( aPad->GetLocalSolderPasteMarginRatio() );
  210. if( pad->GetShape() != PAD_SHAPE_TRAPEZOID )
  211. {
  212. pad->SetDelta( wxSize( 0, 0 ) );
  213. }
  214. if( pad->GetShape() == PAD_SHAPE_CIRCLE )
  215. {
  216. // Ensure pad size.y = pad size.x
  217. int size = pad->GetSize().x;
  218. pad->SetSize( wxSize( size, size ) );
  219. }
  220. switch( pad->GetAttribute() )
  221. {
  222. case PAD_ATTRIB_SMD:
  223. case PAD_ATTRIB_CONN:
  224. pad->SetDrillSize( wxSize( 0, 0 ) );
  225. break;
  226. default:
  227. break;
  228. }
  229. }
  230. module->CalculateBoundingBox();
  231. if( aRedraw )
  232. m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
  233. }
  234. OnModify();
  235. }