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.

177 lines
4.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <fctsys.h>
  27. #include <confirm.h>
  28. #include <trigo.h>
  29. #include <macros.h>
  30. #include <pcb_base_frame.h>
  31. #include <pcb_edit_frame.h>
  32. #include <footprint_edit_frame.h>
  33. #include <pcbnew.h>
  34. #include <class_board.h>
  35. #include <class_module.h>
  36. #include <class_pad.h>
  37. #include <board_design_settings.h>
  38. #include <dialog_push_pad_properties.h>
  39. /*
  40. * Exports the current pad settings to board design settings.
  41. */
  42. void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad )
  43. {
  44. if( aPad == NULL )
  45. return;
  46. SetMsgPanel( aPad );
  47. D_PAD& masterPad = GetDesignSettings().m_Pad_Master;
  48. masterPad.ImportSettingsFromMaster( *aPad );
  49. }
  50. /*
  51. * Imports the board design settings to aPad
  52. * - The position, names, and keys are not modifed.
  53. * The parameters are expected to be correct (i.e. settings are valid)
  54. */
  55. void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw )
  56. {
  57. if( aDraw )
  58. {
  59. aPad->SetFlags( DO_NOT_DRAW );
  60. GetGalCanvas()->Refresh();
  61. aPad->ClearFlags( DO_NOT_DRAW );
  62. }
  63. const D_PAD& mp = GetDesignSettings().m_Pad_Master;
  64. aPad->ImportSettingsFromMaster( mp );
  65. if( aDraw )
  66. GetGalCanvas()->Refresh();
  67. aPad->GetParent()->SetLastEditTime();
  68. OnModify();
  69. }
  70. /*
  71. * Compute the 'next' pad number for autoincrement
  72. * aPadName is the last pad name used
  73. * */
  74. static wxString GetNextPadName( wxString aPadName )
  75. {
  76. // Automatically increment the current pad number.
  77. int num = 0;
  78. int ponder = 1;
  79. // Trim and extract the trailing numeric part
  80. while( aPadName.Len() && aPadName.Last() >= '0' && aPadName.Last() <= '9' )
  81. {
  82. num += ( aPadName.Last() - '0' ) * ponder;
  83. aPadName.RemoveLast();
  84. ponder *= 10;
  85. }
  86. num++; // Use next number for the new pad
  87. aPadName << num;
  88. return aPadName;
  89. }
  90. /*
  91. * Add a new pad to aModule.
  92. */
  93. void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
  94. {
  95. aModule->SetLastEditTime();
  96. D_PAD* pad = new D_PAD( aModule );
  97. // Add the new pad to end of the module pad list.
  98. aModule->Add( pad );
  99. // Update the pad properties,
  100. // and keep NETINFO_LIST::ORPHANED as net info
  101. // which is the default when nets cannot be handled.
  102. Import_Pad_Settings( pad, false );
  103. pad->SetPosition( GetCrossHairPosition() );
  104. // Set the relative pad position
  105. // ( pad position for module orient, 0, and relative to the module position)
  106. wxPoint pos0 = pad->GetPosition() - aModule->GetPosition();
  107. RotatePoint( &pos0, -aModule->GetOrientation() );
  108. pad->SetPos0( pos0 );
  109. /* NPTH pads take empty pad number (since they can't be connected),
  110. * other pads get incremented from the last one edited */
  111. wxString padName;
  112. if( pad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
  113. padName = GetNextPadName( GetDesignSettings().m_Pad_Master.GetName() );
  114. pad->SetName( padName );
  115. GetDesignSettings().m_Pad_Master.SetName( padName );
  116. aModule->CalculateBoundingBox();
  117. SetMsgPanel( pad );
  118. if( draw )
  119. GetGalCanvas()->Refresh();
  120. }
  121. void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
  122. {
  123. if( aPad == NULL )
  124. return;
  125. MODULE* module = aPad->GetParent();
  126. module->SetLastEditTime();
  127. // aQuery = true to prompt for confirmation, false to delete silently
  128. if( aQuery )
  129. {
  130. wxString msg = wxString::Format( _( "Delete pad (footprint %s %s)?" ),
  131. module->GetReference(),
  132. module->GetValue() );
  133. if( !IsOK( this, msg ) )
  134. return;
  135. }
  136. GetBoard()->PadDelete( aPad );
  137. // Update the bounding box
  138. module->CalculateBoundingBox();
  139. GetGalCanvas()->Refresh();
  140. OnModify();
  141. }