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.

284 lines
7.9 KiB

16 years ago
  1. /*************/
  2. /* Edit pads */
  3. /*************/
  4. #include "fctsys.h"
  5. //#include "gr_basic.h"
  6. #include "common.h"
  7. #include "class_drawpanel.h"
  8. #include "confirm.h"
  9. #include "pcbnew.h"
  10. //#include "trigo.h"
  11. //#include "drag.h"
  12. //#include "protos.h"
  13. #include "dialog_global_pads_edition_base.h"
  14. /************************************/
  15. /* class DIALOG_GLOBAL_PADS_EDITION */
  16. /************************************/
  17. class DIALOG_GLOBAL_PADS_EDITION : public DIALOG_GLOBAL_PADS_EDITION_BASE
  18. {
  19. private:
  20. WinEDA_BasePcbFrame* m_Parent;
  21. D_PAD* m_CurrentPad;
  22. public:
  23. static bool m_Pad_Shape_Filter;
  24. static bool m_Pad_Layer_Filter;
  25. static bool m_Pad_Orient_Filter;
  26. public:
  27. DIALOG_GLOBAL_PADS_EDITION( WinEDA_BasePcbFrame* parent, D_PAD* Pad );
  28. ~DIALOG_GLOBAL_PADS_EDITION() { }
  29. private:
  30. void InstallPadEditor( wxCommandEvent& event );
  31. void PadPropertiesAccept( wxCommandEvent& event );
  32. void OnCancelClick( wxCommandEvent& event );
  33. };
  34. DIALOG_GLOBAL_PADS_EDITION::DIALOG_GLOBAL_PADS_EDITION(
  35. WinEDA_BasePcbFrame* parent,
  36. D_PAD* Pad ) :
  37. DIALOG_GLOBAL_PADS_EDITION_BASE( parent )
  38. {
  39. m_Parent = parent;
  40. m_CurrentPad = Pad;
  41. // Pad filter selection.
  42. m_Pad_Shape_Filter_CB->SetValue( m_Pad_Shape_Filter );
  43. m_Pad_Layer_Filter_CB->SetValue( m_Pad_Layer_Filter );
  44. m_Pad_Orient_Filter_CB->SetValue( m_Pad_Orient_Filter );
  45. SetFocus();
  46. GetSizer()->Fit( this );
  47. Centre();
  48. }
  49. /* Class DIALOG_GLOBAL_PADS_EDITION static variables */
  50. bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter = true;
  51. bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter = true;
  52. bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter = true;
  53. void DIALOG_GLOBAL_PADS_EDITION::OnCancelClick( wxCommandEvent& event )
  54. {
  55. EndModal( -1 );
  56. }
  57. /* Calls the Pad editor.
  58. */
  59. void DIALOG_GLOBAL_PADS_EDITION::InstallPadEditor( wxCommandEvent& event )
  60. {
  61. m_Parent->InstallPadOptionsFrame( m_CurrentPad );
  62. }
  63. /* Update the parameters for the component being edited.
  64. */
  65. void DIALOG_GLOBAL_PADS_EDITION::PadPropertiesAccept( wxCommandEvent& event )
  66. {
  67. int returncode = 0;
  68. switch( event.GetId() )
  69. {
  70. case ID_CHANGE_ID_MODULES:
  71. returncode = 1;
  72. // Fall through
  73. case ID_CHANGE_CURRENT_MODULE:
  74. m_Pad_Shape_Filter = m_Pad_Shape_Filter_CB->GetValue();
  75. m_Pad_Layer_Filter = m_Pad_Layer_Filter_CB->GetValue();
  76. m_Pad_Orient_Filter = m_Pad_Orient_Filter_CB->GetValue();
  77. EndModal( returncode );
  78. break;
  79. }
  80. }
  81. /** Function Global_Import_Pad_Settings
  82. * Function to change pad caracteristics for the given footprint
  83. * or alls footprints which look like the given footprint
  84. * @param aPad pad to use as pattern. The given footprint is the parent of
  85. * this pad
  86. * @param aDraw: if true: redraws the footprint
  87. */
  88. void WinEDA_BasePcbFrame::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw )
  89. {
  90. MODULE* Module_Ref, * Module;
  91. int diag;
  92. bool edit_Same_Modules = false;
  93. if( aPad == NULL )
  94. aPad = &g_Pad_Master;
  95. Module = (MODULE*) aPad->GetParent();
  96. if( Module == NULL )
  97. {
  98. DisplayError( this,
  99. wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
  100. return;
  101. }
  102. Module->DisplayInfo( this );
  103. DIALOG_GLOBAL_PADS_EDITION* dlg = new DIALOG_GLOBAL_PADS_EDITION( this, aPad );
  104. diag = dlg->ShowModal();
  105. dlg->Destroy();
  106. if( diag == -1 )
  107. return;
  108. if( diag == 1 )
  109. edit_Same_Modules = true;
  110. /* Search and copy the name of library reference. */
  111. Module_Ref = Module;
  112. int pad_orient = aPad->m_Orient - Module_Ref->m_Orient;
  113. // Prepare an undo list:
  114. PICKED_ITEMS_LIST itemsList;
  115. Module = (MODULE*) m_Pcb->m_Modules;
  116. for( ; Module != NULL; Module = Module->Next() )
  117. {
  118. if( !edit_Same_Modules && (Module != Module_Ref) )
  119. continue;
  120. if( Module->m_LibRef != Module_Ref->m_LibRef )
  121. continue;
  122. bool saveMe = false;
  123. D_PAD* pt_pad = (D_PAD*) Module->m_Pads;
  124. for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
  125. {
  126. /* Filters changes prohibited. */
  127. if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter
  128. && ( pt_pad->m_PadShape != aPad->m_PadShape ) )
  129. continue;
  130. if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter
  131. && ( (pt_pad->m_Orient - Module->m_Orient) != pad_orient ) )
  132. continue;
  133. if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter
  134. && ( pt_pad->m_Masque_Layer != aPad->m_Masque_Layer ) )
  135. continue;
  136. saveMe = true;
  137. }
  138. if( saveMe )
  139. {
  140. ITEM_PICKER itemWrapper( Module, UR_CHANGED );
  141. itemWrapper.m_PickedItemType = Module->Type();
  142. itemsList.PushItem( itemWrapper );
  143. }
  144. }
  145. SaveCopyInUndoList( itemsList, UR_CHANGED );
  146. /* Update the current module and same others modules if requested. */
  147. Module = (MODULE*) m_Pcb->m_Modules;
  148. for( ; Module != NULL; Module = Module->Next() )
  149. {
  150. if( !edit_Same_Modules && (Module != Module_Ref) )
  151. continue;
  152. if( Module->m_LibRef != Module_Ref->m_LibRef )
  153. continue;
  154. /* Erase module on screen */
  155. if( aDraw )
  156. {
  157. Module->m_Flags |= DO_NOT_DRAW;
  158. DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
  159. Module->m_Flags &= ~DO_NOT_DRAW;
  160. }
  161. D_PAD* pt_pad = (D_PAD*) Module->m_Pads;
  162. for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
  163. {
  164. /* Filters changes prohibited. */
  165. if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter
  166. && ( pt_pad->m_PadShape != aPad->m_PadShape ) )
  167. continue;
  168. if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter
  169. && ( (pt_pad->m_Orient - Module->m_Orient) != pad_orient ) )
  170. continue;
  171. if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter )
  172. {
  173. if( pt_pad->m_Masque_Layer != aPad->m_Masque_Layer )
  174. continue;
  175. else
  176. m_Pcb->m_Status_Pcb &=
  177. ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
  178. }
  179. /* Change characteristics.: */
  180. pt_pad->m_Attribut = aPad->m_Attribut;
  181. pt_pad->m_PadShape = aPad->m_PadShape;
  182. pt_pad->m_Masque_Layer = aPad->m_Masque_Layer;
  183. pt_pad->m_Size = aPad->m_Size;
  184. pt_pad->m_DeltaSize = aPad->m_DeltaSize;
  185. pt_pad->m_Offset = aPad->m_Offset;
  186. pt_pad->m_Drill = aPad->m_Drill;
  187. pt_pad->m_DrillShape = aPad->m_DrillShape;
  188. pt_pad->m_Orient = pad_orient + Module->m_Orient;
  189. // copy also local mask margins,
  190. // because these parameters usually depend on
  191. // pads sizes and layers
  192. pt_pad->m_LocalSolderMaskMargin = aPad->m_LocalSolderMaskMargin;
  193. pt_pad->m_LocalSolderPasteMargin = aPad->m_LocalSolderPasteMargin;
  194. pt_pad->m_LocalSolderPasteMarginRatio = aPad->m_LocalSolderPasteMarginRatio;
  195. if( pt_pad->m_PadShape != PAD_TRAPEZOID )
  196. {
  197. pt_pad->m_DeltaSize.x = 0;
  198. pt_pad->m_DeltaSize.y = 0;
  199. }
  200. if( pt_pad->m_PadShape == PAD_CIRCLE )
  201. pt_pad->m_Size.y = pt_pad->m_Size.x;
  202. switch( pt_pad->m_Attribut & 0x7F )
  203. {
  204. case PAD_SMD:
  205. case PAD_CONN:
  206. pt_pad->m_Drill = wxSize( 0, 0 );
  207. pt_pad->m_Offset.x = 0;
  208. pt_pad->m_Offset.y = 0;
  209. break;
  210. default:
  211. break;
  212. }
  213. pt_pad->ComputeRayon();
  214. }
  215. Module->Set_Rectangle_Encadrement();
  216. if( aDraw )
  217. DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
  218. }
  219. OnModify();
  220. }