KiCad PCB EDA Suite
pad_edition_functions.cpp
Go to the documentation of this file.
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-2011 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 
31 #include <fctsys.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <trigo.h>
35 #include <macros.h>
36 #include <wxBasePcbFrame.h>
37 
38 #include <pcbnew.h>
39 #include <class_board.h>
40 #include <class_module.h>
41 #include <class_pad.h>
43 
44 /* Exports the current pad settings to board design settings.
45  */
47 {
48  if( aPad == NULL )
49  return;
50 
51  SetMsgPanel( aPad );
52 
53  D_PAD& masterPad = GetDesignSettings().m_Pad_Master;
54 
55  masterPad.ImportSettingsFromMaster( *aPad );
56 }
57 
58 
59 /* Imports the board design settings to aPad
60  * - The position, names, and keys are not modifed.
61  * The parameters are expected to be correct (i.e. settings are valid)
62  */
63 void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw )
64 {
65  if( aDraw )
66  {
67  aPad->SetFlags( DO_NOT_DRAW );
69  aPad->ClearFlags( DO_NOT_DRAW );
70  }
71 
72  const D_PAD& mp = GetDesignSettings().m_Pad_Master;
73 
74  aPad->ImportSettingsFromMaster( mp );
75 
76  if( aDraw )
78 
79  aPad->GetParent()->SetLastEditTime();
80 
81  OnModify();
82 }
83 
86 static wxString GetNextPadName( wxString aPadName )
87 {
88  // Automatically increment the current pad number.
89  int num = 0;
90  int ponder = 1;
91 
92  // Trim and extract the trailing numeric part
93  while( aPadName.Len()
94  && aPadName.Last() >= '0'
95  && aPadName.Last() <= '9' )
96  {
97  num += ( aPadName.Last() - '0' ) * ponder;
98  aPadName.RemoveLast();
99  ponder *= 10;
100  }
101 
102  num++; // Use next number for the new pad
103  aPadName << num;
104 
105  return aPadName;
106 }
107 
108 /* Add a new pad to aModule.
109  */
110 void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
111 {
112  m_Pcb->m_Status_Pcb = 0;
113  aModule->SetLastEditTime();
114 
115  D_PAD* pad = new D_PAD( aModule );
116 
117  // Add the new pad to end of the module pad list.
118  aModule->Pads().PushBack( pad );
119 
120  // Update the pad properties,
121  // and keep NETINFO_LIST::ORPHANED as net info
122  // which is the default when nets cannot be handled.
123  Import_Pad_Settings( pad, false );
124 
126 
127  // Set the relative pad position
128  // ( pad position for module orient, 0, and relative to the module position)
129 
130  wxPoint pos0 = pad->GetPosition() - aModule->GetPosition();
131  RotatePoint( &pos0, -aModule->GetOrientation() );
132  pad->SetPos0( pos0 );
133 
134  /* NPTH pads take empty pad number (since they can't be connected),
135  * other pads get incremented from the last one edited */
136  wxString padName;
137 
139  {
140  padName = GetNextPadName( GetDesignSettings()
141  .m_Pad_Master.GetPadName() );
142  }
143 
144  pad->SetPadName( padName );
146 
147  aModule->CalculateBoundingBox();
148  SetMsgPanel( pad );
149 
150  if( draw )
152 }
153 
154 
155 void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
156 {
157  if( aPad == NULL )
158  return;
159 
160  MODULE* module = aPad->GetParent();
161  module->SetLastEditTime();
162 
163  // aQuery = true to prompt for confirmation, false to delete silently
164  if( aQuery )
165  {
166  wxString msg;
167  msg.Printf( _( "Delete Pad (footprint %s %s) ?" ),
168  GetChars( module->GetReference() ),
169  GetChars( module->GetValue() ) );
170 
171  if( !IsOK( this, msg ) )
172  return;
173  }
174 
175  // Stores the initial bounding box to refresh the old area
176  EDA_RECT bbox = module->GetBoundingBox();
177 
178  m_Pcb->m_Status_Pcb = 0;
179 
180  GetBoard()->PadDelete( aPad );
181 
182  // Update the bounding box
183  module->CalculateBoundingBox();
184 
185  // Refresh the modified screen area, using the initial bounding box
186  // which is perhaps larger than the new bounding box
187  m_canvas->RefreshDrawingRect( bbox );
188 
189  OnModify();
190 }
191 
192 
193 // Rotate selected pad 90 degrees.
194 void PCB_BASE_FRAME::RotatePad( D_PAD* aPad, wxDC* DC )
195 {
196  if( aPad == NULL )
197  return;
198 
199  MODULE* module = aPad->GetParent();
200 
201  module->SetLastEditTime();
202 
203  OnModify();
204 
205  if( DC )
206  module->Draw( m_canvas, DC, GR_XOR );
207 
208  wxSize sz = aPad->GetSize();
209  std::swap( sz.x, sz.y );
210  aPad->SetSize( sz );
211 
212  sz = aPad->GetDrillSize();
213  std::swap( sz.x, sz.y );
214  aPad->SetDrillSize( sz );
215 
216  wxPoint pt = aPad->GetOffset();
217  std::swap( pt.x, pt.y );
218  aPad->SetOffset( pt );
219 
220  aPad->SetOffset( wxPoint( aPad->GetOffset().x, -aPad->GetOffset().y ) );
221 
222  sz = aPad->GetDelta();
223  std::swap( sz.x, sz.y );
224  sz.x = -sz.x;
225  aPad->SetDelta( sz );
226 
227  module->CalculateBoundingBox();
228  SetMsgPanel( aPad );
229 
230  if( DC )
231  module->Draw( m_canvas, DC, GR_OR );
232 }
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:238
void PadDelete(D_PAD *aPad)
Function PadDelete deletes a given bad from the BOARD by removing it from its module and from the m_N...
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
This file is part of the common library.
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw draws the footprint to the aDC.
Class BOARD to handle a board.
const wxPoint & GetPosition() const override
Definition: class_module.h:143
MODULE * GetParent() const
Definition: class_pad.h:108
BOARD * GetBoard() const
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:439
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:306
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
static wxString GetNextPadName(wxString aPadName)
Compute the 'next' pad number for autoincrement aPadName is the last pad name used.
void SetLastEditTime(time_t aTime)
Definition: class_module.h:269
This file contains miscellaneous commonly used macros and functions.
void DeletePad(D_PAD *aPad, bool aQuery=true)
Function DeletePad Delete the pad aPad.
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
void Export_Pad_Settings(D_PAD *aPad)
void RotatePad(D_PAD *Pad, wxDC *DC)
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Classes used in Pcbnew, CvPcb and GerbView.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:754
double GetOrientation() const
Definition: class_module.h:147
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
const wxSize & GetSize() const
Definition: class_pad.h:182
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
void AddPad(MODULE *Module, bool draw)
void ImportSettingsFromMaster(const D_PAD &aMasterPad)
Imports the pad settings from aMasterPad.
Definition: class_pad.cpp:1291
Pad object description.
Definition: gr_basic.h:42
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:411
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
Class EDA_RECT handles the component boundary box.
const wxSize & GetDelta() const
Definition: class_pad.h:185
void SetPadName(const wxString &name)
Set the pad name (sometimes called pad number, although it can be an array ref like AA12 the pad name...
Definition: class_pad.cpp:455
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
Module description (excepted pads)
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:190
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
void Import_Pad_Settings(D_PAD *aPad, bool aDraw)
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_pad.cpp:181
const wxPoint & GetOffset() const
Definition: class_pad.h:191
#define DO_NOT_DRAW
Used to disable draw function.
Definition: base_struct.h:125
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:184
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240