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  aPad->SetPrimitives( mp.GetPrimitives() );
79 
80  if( aDraw )
82 
83  aPad->GetParent()->SetLastEditTime();
84 
85  OnModify();
86 }
87 
90 static wxString GetNextPadName( wxString aPadName )
91 {
92  // Automatically increment the current pad number.
93  int num = 0;
94  int ponder = 1;
95 
96  // Trim and extract the trailing numeric part
97  while( aPadName.Len()
98  && aPadName.Last() >= '0'
99  && aPadName.Last() <= '9' )
100  {
101  num += ( aPadName.Last() - '0' ) * ponder;
102  aPadName.RemoveLast();
103  ponder *= 10;
104  }
105 
106  num++; // Use next number for the new pad
107  aPadName << num;
108 
109  return aPadName;
110 }
111 
112 /* Add a new pad to aModule.
113  */
114 void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
115 {
116  m_Pcb->m_Status_Pcb = 0;
117  aModule->SetLastEditTime();
118 
119  D_PAD* pad = new D_PAD( aModule );
120 
121  // Add the new pad to end of the module pad list.
122  aModule->PadsList().PushBack( pad );
123 
124  // Update the pad properties,
125  // and keep NETINFO_LIST::ORPHANED as net info
126  // which is the default when nets cannot be handled.
127  Import_Pad_Settings( pad, false );
128 
130 
131  // Set the relative pad position
132  // ( pad position for module orient, 0, and relative to the module position)
133 
134  wxPoint pos0 = pad->GetPosition() - aModule->GetPosition();
135  RotatePoint( &pos0, -aModule->GetOrientation() );
136  pad->SetPos0( pos0 );
137 
138  /* NPTH pads take empty pad number (since they can't be connected),
139  * other pads get incremented from the last one edited */
140  wxString padName;
141 
143  {
144  padName = GetNextPadName( GetDesignSettings()
145  .m_Pad_Master.GetName() );
146  }
147 
148  pad->SetName( padName );
150 
151  aModule->CalculateBoundingBox();
152  SetMsgPanel( pad );
153 
154  if( draw )
156 }
157 
158 
159 void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
160 {
161  if( aPad == NULL )
162  return;
163 
164  MODULE* module = aPad->GetParent();
165  module->SetLastEditTime();
166 
167  // aQuery = true to prompt for confirmation, false to delete silently
168  if( aQuery )
169  {
170  wxString msg;
171  msg.Printf( _( "Delete Pad (footprint %s %s) ?" ),
172  GetChars( module->GetReference() ),
173  GetChars( module->GetValue() ) );
174 
175  if( !IsOK( this, msg ) )
176  return;
177  }
178 
179  // Stores the initial bounding box to refresh the old area
180  EDA_RECT bbox = module->GetBoundingBox();
181 
182  m_Pcb->m_Status_Pcb = 0;
183 
184  GetBoard()->PadDelete( aPad );
185 
186  // Update the bounding box
187  module->CalculateBoundingBox();
188 
189  // Refresh the modified screen area, using the initial bounding box
190  // which is perhaps larger than the new bounding box
191  m_canvas->RefreshDrawingRect( bbox );
192 
193  OnModify();
194 }
195 
196 
197 // Rotate selected pad 90 degrees.
198 void PCB_BASE_FRAME::RotatePad( D_PAD* aPad, wxDC* DC )
199 {
200  if( aPad == NULL )
201  return;
202 
203  MODULE* module = aPad->GetParent();
204 
205  module->SetLastEditTime();
206 
207  OnModify();
208 
209  if( DC )
210  module->Draw( m_canvas, DC, GR_XOR );
211 
212  wxSize sz = aPad->GetSize();
213  std::swap( sz.x, sz.y );
214  aPad->SetSize( sz );
215 
216  sz = aPad->GetDrillSize();
217  std::swap( sz.x, sz.y );
218  aPad->SetDrillSize( sz );
219 
220  wxPoint pt = aPad->GetOffset();
221  std::swap( pt.x, pt.y );
222  aPad->SetOffset( pt );
223 
224  aPad->SetOffset( wxPoint( aPad->GetOffset().x, -aPad->GetOffset().y ) );
225 
226  sz = aPad->GetDelta();
227  std::swap( sz.x, sz.y );
228  sz.x = -sz.x;
229  aPad->SetDelta( sz );
230 
231  module->CalculateBoundingBox();
232  SetMsgPanel( aPad );
233 
234  if( DC )
235  module->Draw( m_canvas, DC, GR_OR );
236 }
bool MergePrimitivesAsPolygon(SHAPE_POLY_SET *aMergedPolygon=NULL, int aCircleToSegmentsCount=32)
Merge all basic shapes, converted to a polygon in one polygon, in m_customShapeAsPolygon.
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:226
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:336
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:398
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:65
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:175
MODULE * GetParent() const
Definition: class_pad.h:162
BOARD * GetBoard() const
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:467
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:305
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
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:302
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)
void SetAnchorPadShape(PAD_SHAPE_T aShape)
Function SetAnchorPadShape Set the shape of the anchor pad for custm shped pads.
Definition: class_pad.h:253
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:267
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:784
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:182
double GetOrientation() const
Definition: class_module.h:180
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
const wxPoint & GetPosition() const override
Definition: class_pad.h:220
const wxSize & GetSize() const
Definition: class_pad.h:269
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
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:1336
Pad object description.
Definition: gr_basic.h:42
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
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:439
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:272
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
DLIST< D_PAD > & PadsList()
Definition: class_module.h:154
Module description (excepted pads)
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:277
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:131
void Import_Pad_Settings(D_PAD *aPad, bool aDraw)
bool SetPrimitives(const std::vector< PAD_CS_PRIMITIVE > &aPrimitivesList)
Import to the basic shape list.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_pad.cpp:199
const wxPoint & GetOffset() const
Definition: class_pad.h:278
#define DO_NOT_DRAW
Used to disable draw function.
Definition: base_struct.h:139
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:271
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:237