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.

352 lines
10 KiB

  1. /*************************/
  2. /* Edition des Pastilles */
  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 "autorout.h"
  11. #include "trigo.h"
  12. #include "drag.h"
  13. #include "protos.h"
  14. /* Variables Locales */
  15. static bool Pad_Shape_Filter = TRUE;
  16. static bool Pad_Layer_Filter = TRUE;
  17. static bool Pad_Orient_Filter = TRUE;
  18. static bool Pad_Size_Change = TRUE;
  19. static bool Pad_Shape_Change = FALSE;
  20. static bool Pad_Orient_Change = FALSE;
  21. static bool Pad_Drill_Change = TRUE;
  22. enum id_pad_global_edit {
  23. ID_CHANGE_CURRENT_MODULE = 1900,
  24. ID_CHANGE_ID_MODULES,
  25. ID_CHANGE_GET_PAD_SETTINGS
  26. };
  27. /************************************/
  28. /* class WinEDA_PadGlobalEditFrame */
  29. /************************************/
  30. class WinEDA_PadGlobalEditFrame : public wxDialog
  31. {
  32. private:
  33. WinEDA_BasePcbFrame* m_Parent;
  34. D_PAD* CurrentPad;
  35. wxCheckBox* m_Pad_Shape_Filter;
  36. wxCheckBox* m_Pad_Layer_Filter;
  37. wxCheckBox* m_Pad_Orient_Filter;
  38. wxCheckBox* m_Pad_Size_Change;
  39. wxCheckBox* m_Pad_Shape_Change;
  40. wxCheckBox* m_Pad_Drill_Change;
  41. wxCheckBox* m_Pad_Orient_Change;
  42. public:
  43. // Constructor and destructor
  44. WinEDA_PadGlobalEditFrame( WinEDA_BasePcbFrame * parent, D_PAD * Pad );
  45. ~WinEDA_PadGlobalEditFrame() { }
  46. private:
  47. void PadPropertiesAccept( wxCommandEvent& event );
  48. void OnCancelClick( wxCommandEvent& event );
  49. DECLARE_EVENT_TABLE()
  50. };
  51. BEGIN_EVENT_TABLE( WinEDA_PadGlobalEditFrame, wxDialog )
  52. EVT_BUTTON( ID_CHANGE_CURRENT_MODULE, WinEDA_PadGlobalEditFrame::PadPropertiesAccept )
  53. EVT_BUTTON( ID_CHANGE_ID_MODULES, WinEDA_PadGlobalEditFrame::PadPropertiesAccept )
  54. EVT_BUTTON( ID_CHANGE_GET_PAD_SETTINGS, WinEDA_PadGlobalEditFrame::PadPropertiesAccept )
  55. EVT_BUTTON( wxID_CANCEL, WinEDA_PadGlobalEditFrame::OnCancelClick )
  56. END_EVENT_TABLE()
  57. /********************************************************************************/
  58. WinEDA_PadGlobalEditFrame::WinEDA_PadGlobalEditFrame( WinEDA_BasePcbFrame* parent,
  59. D_PAD* Pad ) :
  60. wxDialog( parent, -1, _( "Edit Pads Global" ), wxDefaultPosition, wxSize( 310, 235 ),
  61. DIALOG_STYLE )
  62. /********************************************************************************/
  63. {
  64. wxPoint pos;
  65. wxButton* Button;
  66. m_Parent = parent;
  67. SetFont( *g_DialogFont );
  68. Centre();
  69. CurrentPad = Pad;
  70. /* Creation des boutons de commande */
  71. pos.x = 150;
  72. pos.y = 10;
  73. Button = new wxButton( this, ID_CHANGE_GET_PAD_SETTINGS,
  74. _( "Pad Settings..." ), pos );
  75. Button->SetForegroundColour( wxColor( 0, 80, 0 ) );
  76. pos.y += Button->GetDefaultSize().y + 50;
  77. Button = new wxButton( this, ID_CHANGE_CURRENT_MODULE,
  78. _( "Change Module" ), pos );
  79. Button->SetForegroundColour( *wxRED );
  80. pos.y += Button->GetDefaultSize().y + 10;
  81. Button = new wxButton( this, ID_CHANGE_ID_MODULES,
  82. _( "Change ID Modules" ), pos );
  83. Button->SetForegroundColour( *wxRED );
  84. pos.y += Button->GetDefaultSize().y + 10;
  85. Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ), pos );
  86. Button->SetForegroundColour( *wxBLUE );
  87. // Selection des filtres de selection des pads :
  88. pos.x = 5;
  89. pos.y = 5;
  90. new wxStaticBox( this, -1, _( "Pad Filter :" ), pos, wxSize( 130, 75 ) );
  91. pos.x += 5;
  92. pos.y += 18;
  93. m_Pad_Shape_Filter = new wxCheckBox( this, -1, _( "Shape Filter" ), pos );
  94. m_Pad_Shape_Filter->SetValue( Pad_Shape_Filter );
  95. pos.y += 18;
  96. m_Pad_Layer_Filter = new wxCheckBox( this, -1, _( "Layer Filter" ), pos );
  97. m_Pad_Layer_Filter->SetValue( Pad_Layer_Filter );
  98. pos.y += 18;
  99. m_Pad_Orient_Filter = new wxCheckBox( this, -1, _( "Orient Filter" ), pos );
  100. m_Pad_Orient_Filter->SetValue( Pad_Orient_Filter );
  101. // Items a editer
  102. pos.x -= 5;
  103. pos.y += 25;
  104. new wxStaticBox( this, -1, _( "Change Items :" ), pos, wxSize( 130, 95 ) );
  105. pos.x += 5;
  106. pos.y += 18;
  107. m_Pad_Size_Change = new wxCheckBox( this, -1, _( "Change Size" ), pos );
  108. m_Pad_Size_Change->SetValue( Pad_Size_Change );
  109. pos.y += 18;
  110. m_Pad_Shape_Change = new wxCheckBox( this, -1, _( "Change Shape" ), pos );
  111. m_Pad_Shape_Change->SetValue( Pad_Shape_Change );
  112. pos.y += 18;
  113. m_Pad_Drill_Change = new wxCheckBox( this, -1, _( "Change Drill" ), pos );
  114. m_Pad_Drill_Change->SetValue( Pad_Drill_Change );
  115. pos.y += 18;
  116. m_Pad_Orient_Change = new wxCheckBox( this, -1, _( "Change Orientation" ), pos );
  117. m_Pad_Orient_Change->SetValue( Pad_Orient_Change );
  118. }
  119. /**********************************************************************/
  120. void WinEDA_PadGlobalEditFrame::OnCancelClick( wxCommandEvent& WXUNUSED (event) )
  121. /**********************************************************************/
  122. {
  123. EndModal( -1 );
  124. }
  125. /*************************************************************************/
  126. void WinEDA_PadGlobalEditFrame::PadPropertiesAccept( wxCommandEvent& event )
  127. /*************************************************************************/
  128. /* Met a jour les differents parametres pour le composant en cours d'�dition
  129. */
  130. {
  131. int returncode = 0;
  132. switch( event.GetId() )
  133. {
  134. case ID_CHANGE_GET_PAD_SETTINGS:
  135. m_Parent->InstallPadOptionsFrame( NULL, NULL, wxPoint( -1, -1 ) );
  136. break;
  137. case ID_CHANGE_ID_MODULES:
  138. returncode = 1;
  139. // Fall through
  140. case ID_CHANGE_CURRENT_MODULE:
  141. Pad_Shape_Filter = m_Pad_Shape_Filter->GetValue();
  142. Pad_Layer_Filter = m_Pad_Layer_Filter->GetValue();
  143. Pad_Orient_Filter = m_Pad_Orient_Filter->GetValue();
  144. Pad_Size_Change = m_Pad_Size_Change->GetValue();
  145. Pad_Shape_Change = m_Pad_Shape_Change->GetValue();
  146. Pad_Drill_Change = m_Pad_Drill_Change->GetValue();
  147. Pad_Orient_Change = m_Pad_Orient_Change->GetValue();
  148. EndModal( returncode );
  149. break;
  150. }
  151. }
  152. /***************************************************************************/
  153. void WinEDA_BasePcbFrame::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw )
  154. /***************************************************************************/
  155. /** Function Global_Import_Pad_Settings
  156. * Function to change pad caracteristics for the given footprint
  157. * or alls footprints which look like the given footprint
  158. * @param aPad pad to use as pattern. The given footprint is the parent of this pad
  159. * @param aDraw: if true: redraws the footprint
  160. */
  161. {
  162. MODULE* Module_Ref, * Module;
  163. int diag;
  164. bool Edit_Same_Modules = FALSE;
  165. if( aPad == NULL )
  166. return;
  167. Module = (MODULE*) aPad->GetParent();
  168. if( Module == NULL )
  169. {
  170. DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
  171. return;
  172. }
  173. wxString ref_name_module = Module->m_LibRef;
  174. Module->DisplayInfo( this );
  175. WinEDA_PadGlobalEditFrame* frame = new WinEDA_PadGlobalEditFrame( this, aPad );
  176. diag = frame->ShowModal();
  177. frame->Destroy();
  178. if( diag == -1 )
  179. return;
  180. if( diag == 1 )
  181. Edit_Same_Modules = TRUE;
  182. /* Recherche et copie du nom librairie de reference: */
  183. Module_Ref = Module;
  184. /* Mise a jour des modules ou du module */
  185. Module = (MODULE*) m_Pcb->m_Modules;
  186. for( ; Module != NULL; Module = Module->Next() )
  187. {
  188. if( !Edit_Same_Modules )
  189. if( Module != Module_Ref )
  190. continue;
  191. if( ref_name_module != Module->m_LibRef )
  192. continue;
  193. Module->DisplayInfo( this );
  194. /* Effacement du module */
  195. if ( aDraw )
  196. {
  197. Module->m_Flags |= DO_NOT_DRAW;
  198. DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
  199. Module->m_Flags &= ~DO_NOT_DRAW;
  200. }
  201. D_PAD* pt_pad = (D_PAD*) Module->m_Pads;
  202. for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
  203. {
  204. /* Filtrage des modifications interdites */
  205. if( Pad_Shape_Filter )
  206. {
  207. if( pt_pad->m_PadShape != g_Pad_Master.m_PadShape )
  208. continue;
  209. }
  210. if( Pad_Orient_Filter )
  211. {
  212. if( (pt_pad->m_Orient - Module->m_Orient) != g_Pad_Master.m_Orient )
  213. continue;
  214. }
  215. if( Pad_Layer_Filter )
  216. {
  217. if( pt_pad->m_Masque_Layer != g_Pad_Master.m_Masque_Layer )
  218. continue;
  219. else
  220. m_Pcb->m_Status_Pcb &= ~( LISTE_CHEVELU_OK | CONNEXION_OK);
  221. }
  222. /* Modif des caracteristiques: */
  223. if( Pad_Shape_Change )
  224. {
  225. pt_pad->m_Attribut = g_Pad_Master.m_Attribut;
  226. pt_pad->m_PadShape = g_Pad_Master.m_PadShape;
  227. }
  228. pt_pad->m_Masque_Layer = g_Pad_Master.m_Masque_Layer;
  229. if( Pad_Size_Change )
  230. {
  231. pt_pad->m_Size = g_Pad_Master.m_Size;
  232. pt_pad->m_DeltaSize = g_Pad_Master.m_DeltaSize;
  233. pt_pad->m_Offset = g_Pad_Master.m_Offset;
  234. }
  235. if( Pad_Drill_Change )
  236. {
  237. pt_pad->m_Drill = g_Pad_Master.m_Drill;
  238. pt_pad->m_DrillShape = g_Pad_Master.m_DrillShape;
  239. }
  240. if( Pad_Orient_Change )
  241. {
  242. pt_pad->m_Orient = g_Pad_Master.m_Orient + Module->m_Orient;
  243. }
  244. /* Traitement des cas particuliers : */
  245. if( g_Pad_Master.m_PadShape != PAD_TRAPEZOID )
  246. {
  247. pt_pad->m_DeltaSize.x = 0;
  248. pt_pad->m_DeltaSize.y = 0;
  249. }
  250. if( g_Pad_Master.m_PadShape == PAD_CIRCLE )
  251. pt_pad->m_Size.y = pt_pad->m_Size.x;
  252. switch( g_Pad_Master.m_Attribut & 0x7F )
  253. {
  254. case PAD_SMD:
  255. case PAD_CONN:
  256. pt_pad->m_Drill = wxSize( 0, 0 );
  257. pt_pad->m_Offset.x = 0;
  258. pt_pad->m_Offset.y = 0;
  259. break;
  260. default:
  261. break;
  262. }
  263. pt_pad->ComputeRayon();
  264. }
  265. Module->Set_Rectangle_Encadrement();
  266. if ( aDraw )
  267. DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
  268. }
  269. GetScreen()->SetModify();
  270. }