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.

1354 lines
40 KiB

14 years ago
14 years ago
14 years ago
12 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
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
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
14 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
12 years ago
12 years ago
12 years ago
16 years ago
14 years ago
16 years ago
14 years ago
16 years ago
14 years ago
16 years ago
14 years ago
16 years ago
16 years ago
14 years ago
14 years ago
16 years ago
14 years ago
16 years ago
16 years ago
14 years ago
16 years ago
14 years ago
16 years ago
16 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. * @file dialog_pad_properties.cpp
  3. * @brief dialog pad properties editor.
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  9. * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com
  10. * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
  11. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version 2
  16. * of the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, you may find one here:
  25. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  26. * or you may search the http://www.gnu.org website for the version 2 license,
  27. * or you may write to the Free Software Foundation, Inc.,
  28. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  29. */
  30. #include <fctsys.h>
  31. #include <common.h>
  32. #include <gr_basic.h>
  33. #include <class_drawpanel.h>
  34. #include <confirm.h>
  35. #include <pcbnew.h>
  36. #include <wxBasePcbFrame.h>
  37. #include <base_units.h>
  38. #include <board_commit.h>
  39. #include <class_board.h>
  40. #include <class_module.h>
  41. #include <dialog_pad_properties.h>
  42. #include <html_messagebox.h>
  43. // list of pad shapes, ordered like the pad shape wxChoice in dialog.
  44. static PAD_SHAPE_T code_shape[] = {
  45. PAD_SHAPE_CIRCLE,
  46. PAD_SHAPE_OVAL,
  47. PAD_SHAPE_RECT,
  48. PAD_SHAPE_TRAPEZOID,
  49. PAD_SHAPE_ROUNDRECT,
  50. };
  51. // the ordered index of the pad shape wxChoice in dialog.
  52. // keep it consistent with code_shape[] and dialog strings
  53. enum CODE_CHOICE {
  54. CHOICE_SHAPE_CIRCLE = 0,
  55. CHOICE_SHAPE_OVAL,
  56. CHOICE_SHAPE_RECT,
  57. CHOICE_SHAPE_TRAPEZOID,
  58. CHOICE_SHAPE_ROUNDRECT,
  59. };
  60. static PAD_ATTR_T code_type[] = {
  61. PAD_ATTRIB_STANDARD,
  62. PAD_ATTRIB_SMD,
  63. PAD_ATTRIB_CONN,
  64. PAD_ATTRIB_HOLE_NOT_PLATED
  65. };
  66. // Default mask layers setup for pads according to the pad type
  67. static const LSET std_pad_layers[] = {
  68. // PAD_ATTRIB_STANDARD:
  69. D_PAD::StandardMask(),
  70. // PAD_ATTRIB_SMD:
  71. D_PAD::SMDMask(),
  72. // PAD_ATTRIB_CONN:
  73. D_PAD::ConnSMDMask(),
  74. // PAD_ATTRIB_HOLE_NOT_PLATED:
  75. D_PAD::UnplatedHoleMask()
  76. };
  77. void PCB_BASE_FRAME::InstallPadOptionsFrame( D_PAD* aPad )
  78. {
  79. DIALOG_PAD_PROPERTIES dlg( this, aPad );
  80. dlg.ShowModal();
  81. }
  82. DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aPad ) :
  83. DIALOG_PAD_PROPERTIES_BASE( aParent ),
  84. m_OrientValidator( 1, &m_OrientValue )
  85. {
  86. m_canUpdate = false;
  87. m_parent = aParent;
  88. m_currentPad = aPad; // aPad can be NULL, if the dialog is called
  89. // from the footprint editor to set default pad setup
  90. m_board = m_parent->GetBoard();
  91. m_OrientValidator.SetRange( -360.0, 360.0 );
  92. m_PadOrientCtrl->SetValidator( m_OrientValidator );
  93. m_OrientValidator.SetWindow( m_PadOrientCtrl );
  94. m_padMaster = &m_parent->GetDesignSettings().m_Pad_Master;
  95. m_dummyPad = new D_PAD( (MODULE*) NULL );
  96. if( aPad )
  97. *m_dummyPad = *aPad;
  98. else // We are editing a "master" pad, i.e. a template to create new pads
  99. *m_dummyPad = *m_padMaster;
  100. // Show the X and Y axis. It is usefull because pad shape can have an offset
  101. // or be a complex shape.
  102. m_axisOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D(0.0, 0.0, 0.8, 1.0),
  103. KIGFX::ORIGIN_VIEWITEM::CROSS,
  104. Millimeter2iu( 0.2 ),
  105. VECTOR2D( m_dummyPad->GetPosition() ) );
  106. m_axisOrigin->SetDrawAtZero( true );
  107. if( m_parent->IsGalCanvasActive() )
  108. {
  109. m_panelShowPadGal->UseColorScheme( m_board->GetColorsSettings() );
  110. m_panelShowPadGal->SwitchBackend( m_parent->GetGalCanvas()->GetBackend() );
  111. m_panelShowPadGal->Show();
  112. m_panelShowPad->Hide();
  113. m_panelShowPadGal->GetView()->Add( m_dummyPad );
  114. m_panelShowPadGal->GetView()->Add( m_axisOrigin );
  115. m_panelShowPadGal->StartDrawing();
  116. Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_PAD_PROPERTIES::OnResize ) );
  117. }
  118. else
  119. {
  120. m_panelShowPad->Show();
  121. m_panelShowPadGal->Hide();
  122. }
  123. initValues();
  124. TransferDataToWindow();
  125. m_sdbSizerOK->SetDefault();
  126. m_canUpdate = true;
  127. FixOSXCancelButtonIssue();
  128. // Now all widgets have the size fixed, call FinishDialogSettings
  129. FinishDialogSettings();
  130. }
  131. void DIALOG_PAD_PROPERTIES::OnInitDialog( wxInitDialogEvent& event )
  132. {
  133. m_PadNumCtrl->SetFocus();
  134. m_PadNumCtrl->SetSelection( -1, -1 );
  135. }
  136. void DIALOG_PAD_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event )
  137. {
  138. wxPaintDC dc( m_panelShowPad );
  139. PAD_DRAWINFO drawInfo;
  140. EDA_COLOR_T color = BLACK;
  141. if( m_dummyPad->GetLayerSet()[F_Cu] )
  142. {
  143. color = m_board->GetVisibleElementColor( PAD_FR_VISIBLE );
  144. }
  145. if( m_dummyPad->GetLayerSet()[B_Cu] )
  146. {
  147. color = ColorMix( color, m_board->GetVisibleElementColor( PAD_BK_VISIBLE ) );
  148. }
  149. // What could happen: the pad color is *actually* black, or no
  150. // copper was selected
  151. if( color == BLACK )
  152. color = LIGHTGRAY;
  153. drawInfo.m_Color = color;
  154. drawInfo.m_HoleColor = DARKGRAY;
  155. drawInfo.m_Offset = m_dummyPad->GetPosition();
  156. drawInfo.m_Display_padnum = true;
  157. drawInfo.m_Display_netname = true;
  158. if( m_dummyPad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
  159. drawInfo.m_ShowNotPlatedHole = true;
  160. // Shows the local pad clearance
  161. drawInfo.m_PadClearance = m_dummyPad->GetLocalClearance();
  162. wxSize dc_size = dc.GetSize();
  163. dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
  164. // Calculate a suitable scale to fit the available draw area
  165. int dim = m_dummyPad->GetBoundingRadius() *2;
  166. // Invalid x size. User could enter zero, or have deleted all text prior to
  167. // entering a new value; this is also treated as zero. If dim is left at
  168. // zero, the drawing scale is zero and we get a crash.
  169. if( dim == 0 )
  170. {
  171. // If drill size has been set, use that. Otherwise default to 1mm.
  172. dim = m_dummyPad->GetDrillSize().x;
  173. if( dim == 0 )
  174. dim = Millimeter2iu( 1.0 );
  175. }
  176. if( m_dummyPad->GetLocalClearance() > 0 )
  177. dim += m_dummyPad->GetLocalClearance() * 2;
  178. double scale = (double) dc_size.x / dim;
  179. // If the pad is a circle, use the x size here instead.
  180. int ysize;
  181. if( m_dummyPad->GetShape() == PAD_SHAPE_CIRCLE )
  182. ysize = m_dummyPad->GetSize().x;
  183. else
  184. ysize = m_dummyPad->GetSize().y;
  185. dim = ysize + std::abs( m_dummyPad->GetDelta().x );
  186. // Invalid y size. See note about x size above.
  187. if( dim == 0 )
  188. {
  189. dim = m_dummyPad->GetDrillSize().y;
  190. if( dim == 0 )
  191. dim = Millimeter2iu( 0.1 );
  192. }
  193. if( m_dummyPad->GetLocalClearance() > 0 )
  194. dim += m_dummyPad->GetLocalClearance() * 2;
  195. double altscale = (double) dc_size.y / dim;
  196. scale = std::min( scale, altscale );
  197. // Give a margin
  198. scale *= 0.7;
  199. dc.SetUserScale( scale, scale );
  200. GRResetPenAndBrush( &dc );
  201. m_dummyPad->DrawShape( NULL, &dc, drawInfo );
  202. // Draw X and Y axis. Hhis is particularly useful to show the
  203. // reference position of pads with offset and no hole, or custom pad shapes
  204. const int linethickness = 0;
  205. GRLine( NULL, &dc, -int( dc_size.x/scale ), 0, int( dc_size.x/scale ), 0,
  206. linethickness, LIGHTBLUE ); // X axis
  207. GRLine( NULL, &dc, 0, -int( dc_size.y/scale ), 0, int( dc_size.y/scale ),
  208. linethickness, LIGHTBLUE ); // Y axis
  209. event.Skip();
  210. }
  211. void DIALOG_PAD_PROPERTIES::updateRoundRectCornerValues()
  212. {
  213. // Note:
  214. // To avoid generating a wxEVT_TEXT event from m_tcCornerSizeRatio
  215. // we use ChangeValue instead of SetValue, to set the displayed string
  216. if( m_dummyPad->GetShape() == PAD_SHAPE_ROUNDRECT )
  217. {
  218. m_tcCornerSizeRatio->ChangeValue( wxString::Format( "%.1f",
  219. m_dummyPad->GetRoundRectRadiusRatio()*100 ) );
  220. m_staticTextCornerRadiusValue->SetLabel( StringFromValue( g_UserUnit,
  221. m_dummyPad->GetRoundRectCornerRadius() ) );
  222. }
  223. else if( m_dummyPad->GetShape() == PAD_SHAPE_RECT )
  224. {
  225. m_tcCornerSizeRatio->ChangeValue( "0" );
  226. m_staticTextCornerRadiusValue->SetLabel( "0" );
  227. }
  228. else
  229. {
  230. m_tcCornerSizeRatio->ChangeValue( wxEmptyString );
  231. m_staticTextCornerRadiusValue->SetLabel( wxEmptyString );
  232. }
  233. }
  234. void DIALOG_PAD_PROPERTIES::onCornerSizePercentChange( wxCommandEvent& event )
  235. {
  236. if( m_dummyPad->GetShape() != PAD_SHAPE_ROUNDRECT )
  237. return;
  238. wxString value = m_tcCornerSizeRatio->GetValue();
  239. double rrRadiusRatioPercent;
  240. if( value.ToDouble( &rrRadiusRatioPercent ) )
  241. {
  242. // Clamp rrRadiusRatioPercent to acceptable value (0.0 to 50.0)
  243. if( rrRadiusRatioPercent < 0.0 )
  244. {
  245. rrRadiusRatioPercent = 0.0;
  246. m_tcCornerSizeRatio->ChangeValue( "0.0" );
  247. }
  248. if( rrRadiusRatioPercent > 50.0 )
  249. {
  250. rrRadiusRatioPercent = 0.5;
  251. m_tcCornerSizeRatio->ChangeValue( "50.0" );
  252. }
  253. transferDataToPad( m_dummyPad );
  254. m_staticTextCornerRadiusValue->SetLabel( StringFromValue( g_UserUnit,
  255. m_dummyPad->GetRoundRectCornerRadius() ) );
  256. redraw();
  257. }
  258. }
  259. void DIALOG_PAD_PROPERTIES::initValues()
  260. {
  261. wxString msg;
  262. double angle;
  263. // Disable pad net name wxTextCtrl if the caller is the footprint editor
  264. // because nets are living only in the board managed by the board editor
  265. m_canEditNetName = m_parent->IsType( FRAME_PCB );
  266. // Setup layers names from board
  267. // Should be made first, before calling m_rbCopperLayersSel->SetSelection()
  268. m_rbCopperLayersSel->SetString( 0, m_board->GetLayerName( F_Cu ) );
  269. m_rbCopperLayersSel->SetString( 1, m_board->GetLayerName( B_Cu ) );
  270. m_PadLayerAdhCmp->SetLabel( m_board->GetLayerName( F_Adhes ) );
  271. m_PadLayerAdhCu->SetLabel( m_board->GetLayerName( B_Adhes ) );
  272. m_PadLayerPateCmp->SetLabel( m_board->GetLayerName( F_Paste ) );
  273. m_PadLayerPateCu->SetLabel( m_board->GetLayerName( B_Paste ) );
  274. m_PadLayerSilkCmp->SetLabel( m_board->GetLayerName( F_SilkS ) );
  275. m_PadLayerSilkCu->SetLabel( m_board->GetLayerName( B_SilkS ) );
  276. m_PadLayerMaskCmp->SetLabel( m_board->GetLayerName( F_Mask ) );
  277. m_PadLayerMaskCu->SetLabel( m_board->GetLayerName( B_Mask ) );
  278. m_PadLayerECO1->SetLabel( m_board->GetLayerName( Eco1_User ) );
  279. m_PadLayerECO2->SetLabel( m_board->GetLayerName( Eco2_User ) );
  280. m_PadLayerDraft->SetLabel( m_board->GetLayerName( Dwgs_User ) );
  281. m_isFlipped = false;
  282. if( m_currentPad )
  283. {
  284. MODULE* footprint = m_currentPad->GetParent();
  285. m_isFlipped = m_currentPad->IsFlipped();
  286. if( m_isFlipped )
  287. m_staticModuleSideValue->SetLabel( _( "Back side (footprint is mirrored)" ) );
  288. // Diplay footprint rotation ( angles are in 0.1 degree )
  289. msg.Printf( wxT( "%.1f" ), footprint->GetOrientation() / 10.0 );
  290. m_staticModuleRotValue->SetLabel( msg );
  291. }
  292. if( m_isFlipped )
  293. {
  294. wxPoint pt = m_dummyPad->GetOffset();
  295. pt.y = -pt.y;
  296. m_dummyPad->SetOffset( pt );
  297. wxSize sz = m_dummyPad->GetDelta();
  298. sz.y = -sz.y;
  299. m_dummyPad->SetDelta( sz );
  300. // flip pad's layers
  301. m_dummyPad->SetLayerSet( FlipLayerMask( m_dummyPad->GetLayerSet() ) );
  302. }
  303. m_staticTextWarningPadFlipped->Show(m_isFlipped);
  304. m_PadNumCtrl->SetValue( m_dummyPad->GetPadName() );
  305. m_PadNetNameCtrl->SetValue( m_dummyPad->GetNetname() );
  306. // Set the unit name in dialog:
  307. wxStaticText* unitTexts[] =
  308. {
  309. m_PadPosX_Unit, m_PadPosY_Unit,
  310. m_PadDrill_X_Unit, m_PadDrill_Y_Unit,
  311. m_PadShapeSizeX_Unit, m_PadShapeSizeY_Unit,
  312. m_PadShapeOffsetX_Unit,m_PadShapeOffsetY_Unit,
  313. m_PadShapeDelta_Unit, m_PadLengthDie_Unit,
  314. m_NetClearanceUnits, m_SolderMaskMarginUnits, m_SolderPasteMarginUnits,
  315. m_ThermalWidthUnits, m_ThermalGapUnits, m_staticTextCornerSizeUnit
  316. };
  317. for( unsigned ii = 0; ii < DIM( unitTexts ); ++ii )
  318. unitTexts[ii]->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  319. // Display current pad parameters units:
  320. PutValueInLocalUnits( *m_PadPosition_X_Ctrl, m_dummyPad->GetPosition().x );
  321. PutValueInLocalUnits( *m_PadPosition_Y_Ctrl, m_dummyPad->GetPosition().y );
  322. PutValueInLocalUnits( *m_PadDrill_X_Ctrl, m_dummyPad->GetDrillSize().x );
  323. PutValueInLocalUnits( *m_PadDrill_Y_Ctrl, m_dummyPad->GetDrillSize().y );
  324. PutValueInLocalUnits( *m_ShapeSize_X_Ctrl, m_dummyPad->GetSize().x );
  325. PutValueInLocalUnits( *m_ShapeSize_Y_Ctrl, m_dummyPad->GetSize().y );
  326. PutValueInLocalUnits( *m_ShapeOffset_X_Ctrl, m_dummyPad->GetOffset().x );
  327. PutValueInLocalUnits( *m_ShapeOffset_Y_Ctrl, m_dummyPad->GetOffset().y );
  328. if( m_dummyPad->GetDelta().x )
  329. {
  330. PutValueInLocalUnits( *m_ShapeDelta_Ctrl, m_dummyPad->GetDelta().x );
  331. m_trapDeltaDirChoice->SetSelection( 0 );
  332. }
  333. else
  334. {
  335. PutValueInLocalUnits( *m_ShapeDelta_Ctrl, m_dummyPad->GetDelta().y );
  336. m_trapDeltaDirChoice->SetSelection( 1 );
  337. }
  338. PutValueInLocalUnits( *m_LengthPadToDieCtrl, m_dummyPad->GetPadToDieLength() );
  339. PutValueInLocalUnits( *m_NetClearanceValueCtrl, m_dummyPad->GetLocalClearance() );
  340. PutValueInLocalUnits( *m_SolderMaskMarginCtrl, m_dummyPad->GetLocalSolderMaskMargin() );
  341. PutValueInLocalUnits( *m_ThermalWidthCtrl, m_dummyPad->GetThermalWidth() );
  342. PutValueInLocalUnits( *m_ThermalGapCtrl, m_dummyPad->GetThermalGap() );
  343. // These 2 parameters are usually < 0, so prepare entering a negative value, if current is 0
  344. PutValueInLocalUnits( *m_SolderPasteMarginCtrl, m_dummyPad->GetLocalSolderPasteMargin() );
  345. if( m_dummyPad->GetLocalSolderPasteMargin() == 0 )
  346. m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
  347. msg.Printf( wxT( "%f" ), m_dummyPad->GetLocalSolderPasteMarginRatio() * 100.0 );
  348. if( m_dummyPad->GetLocalSolderPasteMarginRatio() == 0.0 && msg[0] == '0' )
  349. // Sometimes Printf adds a sign if the value is small
  350. m_SolderPasteMarginRatioCtrl->SetValue( wxT( "-" ) + msg );
  351. else
  352. m_SolderPasteMarginRatioCtrl->SetValue( msg );
  353. switch( m_dummyPad->GetZoneConnection() )
  354. {
  355. default:
  356. case PAD_ZONE_CONN_INHERITED:
  357. m_ZoneConnectionChoice->SetSelection( 0 );
  358. break;
  359. case PAD_ZONE_CONN_FULL:
  360. m_ZoneConnectionChoice->SetSelection( 1 );
  361. break;
  362. case PAD_ZONE_CONN_THERMAL:
  363. m_ZoneConnectionChoice->SetSelection( 2 );
  364. break;
  365. case PAD_ZONE_CONN_NONE:
  366. m_ZoneConnectionChoice->SetSelection( 3 );
  367. break;
  368. }
  369. if( m_currentPad )
  370. {
  371. MODULE* footprint = m_currentPad->GetParent();
  372. angle = m_currentPad->GetOrientation() - footprint->GetOrientation();
  373. if( m_isFlipped )
  374. angle = -angle;
  375. m_dummyPad->SetOrientation( angle );
  376. }
  377. angle = m_dummyPad->GetOrientation();
  378. NORMALIZE_ANGLE_180( angle ); // ? normalizing is in D_PAD::SetOrientation()
  379. // Set layers used by this pad: :
  380. setPadLayersList( m_dummyPad->GetLayerSet() );
  381. // Pad Orient
  382. switch( int( angle ) )
  383. {
  384. case 0:
  385. m_PadOrient->SetSelection( 0 );
  386. break;
  387. case 900:
  388. m_PadOrient->SetSelection( 1 );
  389. break;
  390. case -900:
  391. m_PadOrient->SetSelection( 2 );
  392. break;
  393. case 1800:
  394. case -1800:
  395. m_PadOrient->SetSelection( 3 );
  396. break;
  397. default:
  398. m_PadOrient->SetSelection( 4 );
  399. break;
  400. }
  401. switch( m_dummyPad->GetShape() )
  402. {
  403. default:
  404. case PAD_SHAPE_CIRCLE:
  405. m_PadShape->SetSelection( CHOICE_SHAPE_CIRCLE );
  406. break;
  407. case PAD_SHAPE_OVAL:
  408. m_PadShape->SetSelection( CHOICE_SHAPE_OVAL );
  409. break;
  410. case PAD_SHAPE_RECT:
  411. m_PadShape->SetSelection( CHOICE_SHAPE_RECT );
  412. break;
  413. case PAD_SHAPE_TRAPEZOID:
  414. m_PadShape->SetSelection( CHOICE_SHAPE_TRAPEZOID );
  415. break;
  416. case PAD_SHAPE_ROUNDRECT:
  417. m_PadShape->SetSelection( CHOICE_SHAPE_ROUNDRECT );
  418. break;
  419. }
  420. m_OrientValue = angle / 10.0;
  421. // Type of pad selection
  422. m_PadType->SetSelection( 0 );
  423. for( unsigned ii = 0; ii < DIM( code_type ); ii++ )
  424. {
  425. if( code_type[ii] == m_dummyPad->GetAttribute() )
  426. {
  427. m_PadType->SetSelection( ii );
  428. break;
  429. }
  430. }
  431. // Enable/disable Pad name,and pad length die
  432. // (disable for NPTH pads (mechanical pads)
  433. bool enable = m_dummyPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED;
  434. m_PadNumCtrl->Enable( enable );
  435. m_PadNetNameCtrl->Enable( m_canEditNetName && enable && m_currentPad != NULL );
  436. m_LengthPadToDieCtrl->Enable( enable );
  437. if( m_dummyPad->GetDrillShape() != PAD_DRILL_SHAPE_OBLONG )
  438. m_DrillShapeCtrl->SetSelection( 0 );
  439. else
  440. m_DrillShapeCtrl->SetSelection( 1 );
  441. // Update some dialog widgets state (Enable/disable options):
  442. wxCommandEvent cmd_event;
  443. setPadLayersList( m_dummyPad->GetLayerSet() );
  444. OnDrillShapeSelected( cmd_event );
  445. OnPadShapeSelection( cmd_event );
  446. updateRoundRectCornerValues();
  447. }
  448. void DIALOG_PAD_PROPERTIES::OnResize( wxSizeEvent& event )
  449. {
  450. redraw();
  451. event.Skip();
  452. }
  453. void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
  454. {
  455. switch( m_PadShape->GetSelection() )
  456. {
  457. case CHOICE_SHAPE_CIRCLE:
  458. m_ShapeDelta_Ctrl->Enable( false );
  459. m_trapDeltaDirChoice->Enable( false );
  460. m_ShapeSize_Y_Ctrl->Enable( false );
  461. m_ShapeOffset_X_Ctrl->Enable( false );
  462. m_ShapeOffset_Y_Ctrl->Enable( false );
  463. break;
  464. case CHOICE_SHAPE_OVAL:
  465. m_ShapeDelta_Ctrl->Enable( false );
  466. m_trapDeltaDirChoice->Enable( false );
  467. m_ShapeSize_Y_Ctrl->Enable( true );
  468. m_ShapeOffset_X_Ctrl->Enable( true );
  469. m_ShapeOffset_Y_Ctrl->Enable( true );
  470. break;
  471. case CHOICE_SHAPE_RECT:
  472. m_ShapeDelta_Ctrl->Enable( false );
  473. m_trapDeltaDirChoice->Enable( false );
  474. m_ShapeSize_Y_Ctrl->Enable( true );
  475. m_ShapeOffset_X_Ctrl->Enable( true );
  476. m_ShapeOffset_Y_Ctrl->Enable( true );
  477. break;
  478. case CHOICE_SHAPE_TRAPEZOID:
  479. m_ShapeDelta_Ctrl->Enable( true );
  480. m_trapDeltaDirChoice->Enable( true );
  481. m_ShapeSize_Y_Ctrl->Enable( true );
  482. m_ShapeOffset_X_Ctrl->Enable( true );
  483. m_ShapeOffset_Y_Ctrl->Enable( true );
  484. break;
  485. case CHOICE_SHAPE_ROUNDRECT:
  486. m_ShapeDelta_Ctrl->Enable( false );
  487. m_trapDeltaDirChoice->Enable( false );
  488. m_ShapeSize_Y_Ctrl->Enable( true );
  489. m_ShapeOffset_X_Ctrl->Enable( true );
  490. m_ShapeOffset_Y_Ctrl->Enable( true );
  491. // Ensure m_tcCornerSizeRatio contains the right value:
  492. m_tcCornerSizeRatio->ChangeValue( wxString::Format( "%.1f",
  493. m_dummyPad->GetRoundRectRadiusRatio()*100 ) );
  494. break;
  495. }
  496. // A few widgets are enabled only for rounded rect pads:
  497. m_tcCornerSizeRatio->Enable( m_PadShape->GetSelection() == CHOICE_SHAPE_ROUNDRECT );
  498. transferDataToPad( m_dummyPad );
  499. updateRoundRectCornerValues();
  500. redraw();
  501. }
  502. void DIALOG_PAD_PROPERTIES::OnDrillShapeSelected( wxCommandEvent& event )
  503. {
  504. if( m_PadType->GetSelection() == 1 || m_PadType->GetSelection() == 2 )
  505. {
  506. // pad type = SMD or CONN: no hole allowed
  507. m_PadDrill_X_Ctrl->Enable( false );
  508. m_PadDrill_Y_Ctrl->Enable( false );
  509. }
  510. else
  511. {
  512. switch( m_DrillShapeCtrl->GetSelection() )
  513. {
  514. case 0: //CIRCLE:
  515. m_PadDrill_X_Ctrl->Enable( true );
  516. m_PadDrill_Y_Ctrl->Enable( false );
  517. break;
  518. case 1: //OVALE:
  519. m_PadDrill_X_Ctrl->Enable( true );
  520. m_PadDrill_Y_Ctrl->Enable( true );
  521. break;
  522. }
  523. }
  524. transferDataToPad( m_dummyPad );
  525. redraw();
  526. }
  527. void DIALOG_PAD_PROPERTIES::PadOrientEvent( wxCommandEvent& event )
  528. {
  529. switch( m_PadOrient->GetSelection() )
  530. {
  531. case 0:
  532. m_dummyPad->SetOrientation( 0 );
  533. break;
  534. case 1:
  535. m_dummyPad->SetOrientation( 900 );
  536. break;
  537. case 2:
  538. m_dummyPad->SetOrientation( -900 );
  539. break;
  540. case 3:
  541. m_dummyPad->SetOrientation( 1800 );
  542. break;
  543. default:
  544. break;
  545. }
  546. m_OrientValue = m_dummyPad->GetOrientation() / 10.0;
  547. m_OrientValidator.TransferToWindow();
  548. transferDataToPad( m_dummyPad );
  549. redraw();
  550. }
  551. void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event )
  552. {
  553. unsigned ii = m_PadType->GetSelection();
  554. if( ii >= DIM( code_type ) ) // catches < 0 also
  555. ii = 0;
  556. LSET layer_mask = std_pad_layers[ii];
  557. setPadLayersList( layer_mask );
  558. // Enable/disable drill dialog items:
  559. event.SetId( m_DrillShapeCtrl->GetSelection() );
  560. OnDrillShapeSelected( event );
  561. if( ii == 0 || ii == DIM( code_type )-1 )
  562. m_DrillShapeCtrl->Enable( true );
  563. else
  564. m_DrillShapeCtrl->Enable( false );
  565. // Enable/disable Pad name,and pad length die
  566. // (disable for NPTH pads (mechanical pads)
  567. bool enable = ii != 3;
  568. m_PadNumCtrl->Enable( enable );
  569. m_PadNetNameCtrl->Enable( m_canEditNetName && enable && m_currentPad != NULL );
  570. m_LengthPadToDieCtrl->Enable( enable );
  571. }
  572. void DIALOG_PAD_PROPERTIES::setPadLayersList( LSET layer_mask )
  573. {
  574. LSET cu_set = layer_mask & LSET::AllCuMask();
  575. if( cu_set == LSET( F_Cu ) )
  576. m_rbCopperLayersSel->SetSelection( 0 );
  577. else if( cu_set == LSET( B_Cu ) )
  578. m_rbCopperLayersSel->SetSelection( 1 );
  579. else if( cu_set.any() )
  580. m_rbCopperLayersSel->SetSelection( 2 );
  581. else
  582. m_rbCopperLayersSel->SetSelection( 3 );
  583. m_PadLayerAdhCmp->SetValue( layer_mask[F_Adhes] );
  584. m_PadLayerAdhCu->SetValue( layer_mask[B_Adhes] );
  585. m_PadLayerPateCmp->SetValue( layer_mask[F_Paste] );
  586. m_PadLayerPateCu->SetValue( layer_mask[B_Paste] );
  587. m_PadLayerSilkCmp->SetValue( layer_mask[F_SilkS] );
  588. m_PadLayerSilkCu->SetValue( layer_mask[B_SilkS] );
  589. m_PadLayerMaskCmp->SetValue( layer_mask[F_Mask] );
  590. m_PadLayerMaskCu->SetValue( layer_mask[B_Mask] );
  591. m_PadLayerECO1->SetValue( layer_mask[Eco1_User] );
  592. m_PadLayerECO2->SetValue( layer_mask[Eco2_User] );
  593. m_PadLayerDraft->SetValue( layer_mask[Dwgs_User] );
  594. }
  595. // Called when select/deselect a layer.
  596. void DIALOG_PAD_PROPERTIES::OnSetLayers( wxCommandEvent& event )
  597. {
  598. transferDataToPad( m_dummyPad );
  599. redraw();
  600. }
  601. // test if all values are acceptable for the pad
  602. bool DIALOG_PAD_PROPERTIES::padValuesOK()
  603. {
  604. bool error = transferDataToPad( m_dummyPad );
  605. bool skip_tstoffset = false; // the offset prm is not always tested
  606. wxArrayString error_msgs;
  607. wxString msg;
  608. // Test for incorrect values
  609. if( (m_dummyPad->GetSize().x <= 0) ||
  610. ((m_dummyPad->GetSize().y <= 0) && (m_dummyPad->GetShape() != PAD_SHAPE_CIRCLE)) )
  611. {
  612. error_msgs.Add( _( "Pad size must be greater than zero" ) );
  613. }
  614. if( (m_dummyPad->GetSize().x < m_dummyPad->GetDrillSize().x) ||
  615. (m_dummyPad->GetSize().y < m_dummyPad->GetDrillSize().y) )
  616. {
  617. error_msgs.Add( _( "Incorrect value for pad drill: pad drill bigger than pad size" ) );
  618. skip_tstoffset = true; // offset prm will be not tested because if the drill value
  619. // is incorrect the offset prm is always seen as incorrect, even if it is 0
  620. }
  621. LSET padlayers_mask = m_dummyPad->GetLayerSet();
  622. if( padlayers_mask == 0 )
  623. error_msgs.Add( _( "Error: pad has no layer" ) );
  624. if( !padlayers_mask[F_Cu] && !padlayers_mask[B_Cu] )
  625. {
  626. if( m_dummyPad->GetDrillSize().x || m_dummyPad->GetDrillSize().y )
  627. {
  628. // Note: he message is shown in an HTML window
  629. msg = _( "Error: the pad is not on a copper layer and has a hole" );
  630. if( m_dummyPad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
  631. {
  632. msg += wxT( "<br><br><i>" );
  633. msg += _( "For NPTH pad, set pad size value to pad drill value,"
  634. " if you do not want this pad plotted in gerber files"
  635. );
  636. }
  637. error_msgs.Add( msg );
  638. }
  639. }
  640. if( !skip_tstoffset )
  641. {
  642. wxPoint max_size;
  643. max_size.x = std::abs( m_dummyPad->GetOffset().x );
  644. max_size.y = std::abs( m_dummyPad->GetOffset().y );
  645. max_size.x += m_dummyPad->GetDrillSize().x / 2;
  646. max_size.y += m_dummyPad->GetDrillSize().y / 2;
  647. if( ( m_dummyPad->GetSize().x / 2 < max_size.x ) ||
  648. ( m_dummyPad->GetSize().y / 2 < max_size.y ) )
  649. {
  650. error_msgs.Add( _( "Incorrect value for pad offset" ) );
  651. }
  652. }
  653. if( error )
  654. {
  655. error_msgs.Add( _( "Too large value for pad delta size" ) );
  656. }
  657. switch( m_dummyPad->GetAttribute() )
  658. {
  659. case PAD_ATTRIB_HOLE_NOT_PLATED: // Not plated, but through hole, a hole is expected
  660. case PAD_ATTRIB_STANDARD : // Pad through hole, a hole is also expected
  661. if( m_dummyPad->GetDrillSize().x <= 0 )
  662. error_msgs.Add( _( "Error: Through hole pad: drill diameter set to 0" ) );
  663. break;
  664. case PAD_ATTRIB_CONN: // Connector pads are smd pads, just they do not have solder paste.
  665. if( padlayers_mask[B_Paste] || padlayers_mask[F_Paste] )
  666. error_msgs.Add( _( "Error: Connector pads are not on the solder paste layer\n"
  667. "Use SMD pads instead" ) );
  668. // Fall trough
  669. case PAD_ATTRIB_SMD: // SMD and Connector pads (One external copper layer only)
  670. {
  671. LSET innerlayers_mask = padlayers_mask & LSET::InternalCuMask();
  672. if( ( padlayers_mask[F_Cu] && padlayers_mask[B_Cu] ) ||
  673. innerlayers_mask.count() != 0 )
  674. error_msgs.Add( _( "Error: only one external copper layer allowed for SMD or Connector pads" ) );
  675. }
  676. break;
  677. }
  678. if( m_dummyPad->GetShape() == PAD_SHAPE_ROUNDRECT )
  679. {
  680. wxString value = m_tcCornerSizeRatio->GetValue();
  681. double rrRadiusRatioPercent;
  682. if( !value.ToDouble( &rrRadiusRatioPercent ) )
  683. error_msgs.Add( _( "Incorrect corner size value" ) );
  684. else
  685. {
  686. if( rrRadiusRatioPercent < 0.0 )
  687. error_msgs.Add( _( "Incorrect (negative) corner size value" ) );
  688. else if( rrRadiusRatioPercent > 50.0 )
  689. error_msgs.Add( _( "Corner size value must be smaller than 50%" ) );
  690. }
  691. }
  692. if( error_msgs.GetCount() )
  693. {
  694. HTML_MESSAGE_BOX dlg( this, _("Pad setup errors list" ) );
  695. dlg.ListSet( error_msgs );
  696. dlg.ShowModal();
  697. }
  698. return error_msgs.GetCount() == 0;
  699. }
  700. void DIALOG_PAD_PROPERTIES::redraw()
  701. {
  702. if( m_parent->IsGalCanvasActive() )
  703. {
  704. m_parent->GetGalCanvas()->GetView()->Update( m_dummyPad );
  705. BOX2I bbox = m_dummyPad->ViewBBox();
  706. if( bbox.GetSize().x > 0 && bbox.GetSize().y > 0 )
  707. {
  708. // gives a size to the full drawable area
  709. BOX2I drawbox;
  710. drawbox.Move( m_dummyPad->GetPosition() );
  711. drawbox.Inflate( bbox.GetSize().x*2, bbox.GetSize().y*2 );
  712. m_panelShowPadGal->GetView()->SetBoundary( drawbox );
  713. // Autozoom
  714. m_panelShowPadGal->GetView()->SetViewport( BOX2D( bbox.GetOrigin(), bbox.GetSize() ) );
  715. // Add a margin
  716. m_panelShowPadGal->GetView()->SetScale( m_panelShowPadGal->GetView()->GetScale() * 0.7 );
  717. m_panelShowPadGal->Refresh();
  718. }
  719. }
  720. else
  721. {
  722. m_panelShowPad->Refresh();
  723. }
  724. }
  725. bool DIALOG_PAD_PROPERTIES::TransferDataToWindow()
  726. {
  727. if( !wxDialog::TransferDataToWindow() )
  728. return false;
  729. if( !m_panelGeneral->TransferDataToWindow() )
  730. return false;
  731. if( !m_localSettingsPanel->TransferDataToWindow() )
  732. return false;
  733. return true;
  734. }
  735. bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow()
  736. {
  737. BOARD_COMMIT commit( m_parent );
  738. if( !wxDialog::TransferDataFromWindow() )
  739. return false;
  740. if( !m_panelGeneral->TransferDataFromWindow() )
  741. return false;
  742. if( !m_localSettingsPanel->TransferDataFromWindow() )
  743. return false;
  744. if( !padValuesOK() )
  745. return false;
  746. bool rastnestIsChanged = false;
  747. int isign = m_isFlipped ? -1 : 1;
  748. transferDataToPad( m_padMaster );
  749. // m_padMaster is a pattern: ensure there is no net for this pad:
  750. m_padMaster->SetNetCode( NETINFO_LIST::UNCONNECTED );
  751. if( !m_currentPad ) // Set current Pad parameters
  752. return false;
  753. commit.Modify( m_currentPad );
  754. wxSize size;
  755. MODULE* footprint = m_currentPad->GetParent();
  756. footprint->SetLastEditTime();
  757. // redraw the area where the pad was, without pad (delete pad on screen)
  758. m_currentPad->SetFlags( DO_NOT_DRAW );
  759. m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() );
  760. m_currentPad->ClearFlags( DO_NOT_DRAW );
  761. // Update values
  762. m_currentPad->SetShape( m_padMaster->GetShape() );
  763. m_currentPad->SetAttribute( m_padMaster->GetAttribute() );
  764. if( m_currentPad->GetPosition() != m_padMaster->GetPosition() )
  765. {
  766. m_currentPad->SetPosition( m_padMaster->GetPosition() );
  767. rastnestIsChanged = true;
  768. }
  769. // compute the pos 0 value, i.e. pad position for footprint with orientation = 0
  770. // i.e. relative to footprint origin (footprint position)
  771. wxPoint pt = m_currentPad->GetPosition() - footprint->GetPosition();
  772. RotatePoint( &pt, -footprint->GetOrientation() );
  773. m_currentPad->SetPos0( pt );
  774. m_currentPad->SetOrientation( m_padMaster->GetOrientation() * isign
  775. + footprint->GetOrientation() );
  776. m_currentPad->SetSize( m_padMaster->GetSize() );
  777. size = m_padMaster->GetDelta();
  778. size.y *= isign;
  779. m_currentPad->SetDelta( size );
  780. m_currentPad->SetDrillSize( m_padMaster->GetDrillSize() );
  781. m_currentPad->SetDrillShape( m_padMaster->GetDrillShape() );
  782. wxPoint offset = m_padMaster->GetOffset();
  783. offset.y *= isign;
  784. m_currentPad->SetOffset( offset );
  785. m_currentPad->SetPadToDieLength( m_padMaster->GetPadToDieLength() );
  786. if( m_currentPad->GetLayerSet() != m_padMaster->GetLayerSet() )
  787. {
  788. rastnestIsChanged = true;
  789. m_currentPad->SetLayerSet( m_padMaster->GetLayerSet() );
  790. }
  791. if( m_isFlipped )
  792. {
  793. m_currentPad->SetLayerSet( FlipLayerMask( m_currentPad->GetLayerSet() ) );
  794. }
  795. m_currentPad->SetPadName( m_padMaster->GetPadName() );
  796. wxString padNetname;
  797. // For PAD_ATTRIB_HOLE_NOT_PLATED, ensure there is no net name selected
  798. if( m_padMaster->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
  799. padNetname = m_PadNetNameCtrl->GetValue();
  800. if( m_currentPad->GetNetname() != padNetname )
  801. {
  802. const NETINFO_ITEM* netinfo = m_board->FindNet( padNetname );
  803. if( !padNetname.IsEmpty() && netinfo == NULL )
  804. {
  805. DisplayError( NULL, _( "Unknown netname, netname not changed" ) );
  806. }
  807. else if( netinfo )
  808. {
  809. rastnestIsChanged = true;
  810. m_currentPad->SetNetCode( netinfo->GetNet() );
  811. }
  812. }
  813. m_currentPad->SetLocalClearance( m_padMaster->GetLocalClearance() );
  814. m_currentPad->SetLocalSolderMaskMargin( m_padMaster->GetLocalSolderMaskMargin() );
  815. m_currentPad->SetLocalSolderPasteMargin( m_padMaster->GetLocalSolderPasteMargin() );
  816. m_currentPad->SetLocalSolderPasteMarginRatio( m_padMaster->GetLocalSolderPasteMarginRatio() );
  817. m_currentPad->SetZoneConnection( m_padMaster->GetZoneConnection() );
  818. m_currentPad->SetThermalWidth( m_padMaster->GetThermalWidth() );
  819. m_currentPad->SetThermalGap( m_padMaster->GetThermalGap() );
  820. m_currentPad->SetRoundRectRadiusRatio( m_padMaster->GetRoundRectRadiusRatio() );
  821. // rounded rect pads with radius ratio = 0 are in fact rect pads.
  822. // So set the right shape (and perhaps issues with a radius = 0)
  823. if( m_currentPad->GetShape() == PAD_SHAPE_ROUNDRECT &&
  824. m_currentPad->GetRoundRectRadiusRatio() == 0.0 )
  825. {
  826. m_currentPad->SetShape( PAD_SHAPE_RECT );
  827. }
  828. footprint->CalculateBoundingBox();
  829. m_parent->SetMsgPanel( m_currentPad );
  830. // redraw the area where the pad was
  831. m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() );
  832. commit.Push( _( "Modify pad" ) );
  833. if( rastnestIsChanged ) // The net ratsnest must be recalculated
  834. m_board->m_Status_Pcb = 0;
  835. return true;
  836. }
  837. bool DIALOG_PAD_PROPERTIES::transferDataToPad( D_PAD* aPad )
  838. {
  839. wxString msg;
  840. int x, y;
  841. if( !Validate() )
  842. return true;
  843. if( !m_panelGeneral->Validate() )
  844. return true;
  845. if( !m_localSettingsPanel->Validate() )
  846. return true;
  847. m_OrientValidator.TransferFromWindow();
  848. aPad->SetAttribute( code_type[m_PadType->GetSelection()] );
  849. aPad->SetShape( code_shape[m_PadShape->GetSelection()] );
  850. // Read pad clearances values:
  851. aPad->SetLocalClearance( ValueFromTextCtrl( *m_NetClearanceValueCtrl ) );
  852. aPad->SetLocalSolderMaskMargin( ValueFromTextCtrl( *m_SolderMaskMarginCtrl ) );
  853. aPad->SetLocalSolderPasteMargin( ValueFromTextCtrl( *m_SolderPasteMarginCtrl ) );
  854. aPad->SetThermalWidth( ValueFromTextCtrl( *m_ThermalWidthCtrl ) );
  855. aPad->SetThermalGap( ValueFromTextCtrl( *m_ThermalGapCtrl ) );
  856. double dtmp = 0.0;
  857. msg = m_SolderPasteMarginRatioCtrl->GetValue();
  858. msg.ToDouble( &dtmp );
  859. // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
  860. if( dtmp < -50.0 )
  861. dtmp = -50.0;
  862. // A margin ratio is always <= 0
  863. // 0 means use full pad copper area
  864. if( dtmp > 0.0 )
  865. dtmp = 0.0;
  866. aPad->SetLocalSolderPasteMarginRatio( dtmp / 100 );
  867. switch( m_ZoneConnectionChoice->GetSelection() )
  868. {
  869. default:
  870. case 0:
  871. aPad->SetZoneConnection( PAD_ZONE_CONN_INHERITED );
  872. break;
  873. case 1:
  874. aPad->SetZoneConnection( PAD_ZONE_CONN_FULL );
  875. break;
  876. case 2:
  877. aPad->SetZoneConnection( PAD_ZONE_CONN_THERMAL );
  878. break;
  879. case 3:
  880. aPad->SetZoneConnection( PAD_ZONE_CONN_NONE );
  881. break;
  882. }
  883. // Read pad position:
  884. x = ValueFromTextCtrl( *m_PadPosition_X_Ctrl );
  885. y = ValueFromTextCtrl( *m_PadPosition_Y_Ctrl );
  886. aPad->SetPosition( wxPoint( x, y ) );
  887. aPad->SetPos0( wxPoint( x, y ) );
  888. // Read pad drill:
  889. x = ValueFromTextCtrl( *m_PadDrill_X_Ctrl );
  890. y = ValueFromTextCtrl( *m_PadDrill_Y_Ctrl );
  891. if( m_DrillShapeCtrl->GetSelection() == 0 )
  892. {
  893. aPad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
  894. y = x;
  895. }
  896. else
  897. aPad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
  898. aPad->SetDrillSize( wxSize( x, y ) );
  899. // Read pad shape size:
  900. x = ValueFromTextCtrl( *m_ShapeSize_X_Ctrl );
  901. y = ValueFromTextCtrl( *m_ShapeSize_Y_Ctrl );
  902. if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
  903. y = x;
  904. aPad->SetSize( wxSize( x, y ) );
  905. // Read pad length die
  906. aPad->SetPadToDieLength( ValueFromTextCtrl( *m_LengthPadToDieCtrl ) );
  907. // For a trapezoid, test delta value (be sure delta is not too large for pad size)
  908. // remember DeltaSize.x is the Y size variation
  909. bool error = false;
  910. if( aPad->GetShape() == PAD_SHAPE_TRAPEZOID )
  911. {
  912. wxSize delta;
  913. // For a trapezoid, only one of delta.x or delta.y is not 0, depending on
  914. // the direction.
  915. if( m_trapDeltaDirChoice->GetSelection() == 0 )
  916. delta.x = ValueFromTextCtrl( *m_ShapeDelta_Ctrl );
  917. else
  918. delta.y = ValueFromTextCtrl( *m_ShapeDelta_Ctrl );
  919. if( delta.x < 0 && delta.x <= -aPad->GetSize().y )
  920. {
  921. delta.x = -aPad->GetSize().y + 2;
  922. error = true;
  923. }
  924. if( delta.x > 0 && delta.x >= aPad->GetSize().y )
  925. {
  926. delta.x = aPad->GetSize().y - 2;
  927. error = true;
  928. }
  929. if( delta.y < 0 && delta.y <= -aPad->GetSize().x )
  930. {
  931. delta.y = -aPad->GetSize().x + 2;
  932. error = true;
  933. }
  934. if( delta.y > 0 && delta.y >= aPad->GetSize().x )
  935. {
  936. delta.y = aPad->GetSize().x - 2;
  937. error = true;
  938. }
  939. aPad->SetDelta( delta );
  940. }
  941. // Read pad shape offset:
  942. x = ValueFromTextCtrl( *m_ShapeOffset_X_Ctrl );
  943. y = ValueFromTextCtrl( *m_ShapeOffset_Y_Ctrl );
  944. aPad->SetOffset( wxPoint( x, y ) );
  945. aPad->SetOrientation( m_OrientValue * 10.0 );
  946. msg = m_PadNumCtrl->GetValue().Left( 4 );
  947. aPad->SetPadName( msg );
  948. // Check if user has set an existing net name
  949. const NETINFO_ITEM* netinfo = m_board->FindNet( m_PadNetNameCtrl->GetValue() );
  950. if( netinfo != NULL )
  951. aPad->SetNetCode( netinfo->GetNet() );
  952. else
  953. aPad->SetNetCode( NETINFO_LIST::UNCONNECTED );
  954. // Clear some values, according to the pad type and shape
  955. switch( aPad->GetShape() )
  956. {
  957. case PAD_SHAPE_CIRCLE:
  958. aPad->SetOffset( wxPoint( 0, 0 ) );
  959. aPad->SetDelta( wxSize( 0, 0 ) );
  960. x = aPad->GetSize().x;
  961. aPad->SetSize( wxSize( x, x ) );
  962. break;
  963. case PAD_SHAPE_RECT:
  964. aPad->SetDelta( wxSize( 0, 0 ) );
  965. break;
  966. case PAD_SHAPE_OVAL:
  967. aPad->SetDelta( wxSize( 0, 0 ) );
  968. break;
  969. case PAD_SHAPE_TRAPEZOID:
  970. break;
  971. case PAD_SHAPE_ROUNDRECT:
  972. aPad->SetDelta( wxSize( 0, 0 ) );
  973. break;
  974. default:
  975. ;
  976. }
  977. switch( aPad->GetAttribute() )
  978. {
  979. case PAD_ATTRIB_STANDARD:
  980. break;
  981. case PAD_ATTRIB_CONN:
  982. case PAD_ATTRIB_SMD:
  983. // SMD and PAD_ATTRIB_CONN has no hole.
  984. // basically, SMD and PAD_ATTRIB_CONN are same type of pads
  985. // PAD_ATTRIB_CONN has just a default non technical layers that differs from SMD
  986. // and are intended to be used in virtual edge board connectors
  987. // However we can accept a non null offset,
  988. // mainly to allow complex pads build from a set of basic pad shapes
  989. aPad->SetDrillSize( wxSize( 0, 0 ) );
  990. break;
  991. case PAD_ATTRIB_HOLE_NOT_PLATED:
  992. // Mechanical purpose only:
  993. // no offset, no net name, no pad name allowed
  994. aPad->SetOffset( wxPoint( 0, 0 ) );
  995. aPad->SetPadName( wxEmptyString );
  996. aPad->SetNetCode( NETINFO_LIST::UNCONNECTED );
  997. break;
  998. default:
  999. DisplayError( NULL, wxT( "Error: unknown pad type" ) );
  1000. break;
  1001. }
  1002. if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT )
  1003. {
  1004. wxString value = m_tcCornerSizeRatio->GetValue();
  1005. double rrRadiusRatioPercent;
  1006. if( value.ToDouble( &rrRadiusRatioPercent ) )
  1007. aPad->SetRoundRectRadiusRatio( rrRadiusRatioPercent / 100.0 );
  1008. }
  1009. LSET padLayerMask;
  1010. switch( m_rbCopperLayersSel->GetSelection() )
  1011. {
  1012. case 0:
  1013. padLayerMask.set( F_Cu );
  1014. break;
  1015. case 1:
  1016. padLayerMask.set( B_Cu );
  1017. break;
  1018. case 2:
  1019. padLayerMask |= LSET::AllCuMask();
  1020. break;
  1021. case 3: // No copper layers
  1022. break;
  1023. }
  1024. if( m_PadLayerAdhCmp->GetValue() )
  1025. padLayerMask.set( F_Adhes );
  1026. if( m_PadLayerAdhCu->GetValue() )
  1027. padLayerMask.set( B_Adhes );
  1028. if( m_PadLayerPateCmp->GetValue() )
  1029. padLayerMask.set( F_Paste );
  1030. if( m_PadLayerPateCu->GetValue() )
  1031. padLayerMask.set( B_Paste );
  1032. if( m_PadLayerSilkCmp->GetValue() )
  1033. padLayerMask.set( F_SilkS );
  1034. if( m_PadLayerSilkCu->GetValue() )
  1035. padLayerMask.set( B_SilkS );
  1036. if( m_PadLayerMaskCmp->GetValue() )
  1037. padLayerMask.set( F_Mask );
  1038. if( m_PadLayerMaskCu->GetValue() )
  1039. padLayerMask.set( B_Mask );
  1040. if( m_PadLayerECO1->GetValue() )
  1041. padLayerMask.set( Eco1_User );
  1042. if( m_PadLayerECO2->GetValue() )
  1043. padLayerMask.set( Eco2_User );
  1044. if( m_PadLayerDraft->GetValue() )
  1045. padLayerMask.set( Dwgs_User );
  1046. aPad->SetLayerSet( padLayerMask );
  1047. return error;
  1048. }
  1049. void DIALOG_PAD_PROPERTIES::OnValuesChanged( wxCommandEvent& event )
  1050. {
  1051. if( m_canUpdate )
  1052. {
  1053. transferDataToPad( m_dummyPad );
  1054. // If the pad size has changed, update the displayed values
  1055. // for rounded rect pads
  1056. updateRoundRectCornerValues();
  1057. redraw();
  1058. }
  1059. }