KiCad PCB EDA Suite
globaleditpad.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) 2009-2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <fctsys.h>
30 #include <common.h>
31 #include <class_drawpanel.h>
32 #include <confirm.h>
33 #include <wxPcbStruct.h>
34 #include <module_editor_frame.h>
35 
36 #include <class_board.h>
37 #include <class_module.h>
38 
39 #include <pcbnew.h>
41 
42 /*
43  * PCB_EDIT_FRAME::Function DlgGlobalChange_PadSettings
44  * Function to change pad caracteristics for the given footprint
45  * or alls footprints which look like the given footprint
46  * Options are set by the opened dialog.
47  * aPad is the pattern. The given footprint is the parent of this pad
48  * aRedraw: if true: redraws the footprint
49  */
51 {
52  int diag;
53 
54  if( aPad == NULL )
56 
57  MODULE* module = aPad->GetParent();
58 
59  if( module == NULL )
60  {
61  DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
62  return;
63  }
64 
65  SetMsgPanel( module );
66 
67  {
68  DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
69 
70  diag = dlg.ShowModal();
71  }
72 
73  if( diag == -1 )
74  return;
75 
76  bool edit_Same_Modules = false;
77  if( diag == 1 )
78  edit_Same_Modules = true;
79 
80  GlobalChange_PadSettings( aPad,edit_Same_Modules,
84  aRedraw, true );
85 }
86 
87 /*
88  * FOOTPRINT_EDIT_FRAME::Function DlgGlobalChange_PadSettings
89  * Function to change pad caracteristics for the given footprint
90  * or alls footprints which look like the given footprint
91  * Options are set by the opened dialog.
92  * aPad is the pattern. The given footprint is the parent of this pad
93  */
95 {
96  int diag;
97 
98  if( aPad == NULL )
100 
101  MODULE* module = aPad->GetParent();
102 
103  if( module == NULL )
104  {
105  DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
106  return;
107  }
108 
109  SetMsgPanel( module );
110 
111  {
112  DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
113 
114  dlg.m_buttonIdModules->Enable( false );
115 
116  diag = dlg.ShowModal();
117  }
118 
119  if( diag == -1 )
120  return;
121 
122  bool edit_Same_Modules = false;
123  if( diag == 1 )
124  edit_Same_Modules = true;
125 
126  GlobalChange_PadSettings( aPad, edit_Same_Modules,
130  true, false );
131 }
132 
133 /*
134  * Function GlobalChange_PadSettings
135  * Function to change pad caracteristics for the given footprint
136  * or alls footprints which look like the given footprint
137  * aPad is the pattern. The given footprint is the parent of this pad
138  * aSameFootprints: if true, make changes on all identical footprints
139  * aPadShapeFilter: if true, make changes only on pads having the same shape as aPad
140  * aPadOrientFilter: if true, make changes only on pads having the same orientation as aPad
141  * aPadLayerFilter: if true, make changes only on pads having the same layers as aPad
142  * aRedraw: if true: redraws the footprint
143  * aSaveForUndo: if true: create an entry in the Undo/Redo list
144  * (usually: true in Schematic editor, false in Module editor)
145  */
147  bool aSameFootprints,
148  bool aPadShapeFilter,
149  bool aPadOrientFilter,
150  bool aPadLayerFilter,
151  bool aRedraw, bool aSaveForUndo )
152 {
153  if( aPad == NULL )
155 
156  MODULE* module = aPad->GetParent();
157 
158  if( module == NULL )
159  {
160  DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
161  return;
162  }
163 
164  // Search and copy the name of library reference.
165  MODULE* Module_Ref = module;
166  double pad_orient = aPad->GetOrientation() - Module_Ref->GetOrientation();
167 
168  // Prepare an undo list:
169  if( aSaveForUndo )
170  {
171  PICKED_ITEMS_LIST itemsList;
172 
173  for( module = m_Pcb->m_Modules; module; module = module->Next() )
174  {
175  if( !aSameFootprints && (module != Module_Ref) )
176  continue;
177 
178  if( module->GetFPID() != Module_Ref->GetFPID() )
179  continue;
180 
181  bool saveMe = false;
182 
183  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
184  {
185  // Filters changes prohibited.
186  if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
187  continue;
188 
189  double currpad_orient = pad->GetOrientation() - module->GetOrientation();
190 
191  if( aPadOrientFilter && ( currpad_orient != pad_orient ) )
192  continue;
193 
194  if( aPadLayerFilter && pad->GetLayerSet() != aPad->GetLayerSet() )
195  continue;
196 
197  saveMe = true;
198  }
199 
200  if( saveMe )
201  {
202  ITEM_PICKER itemWrapper( module, UR_CHANGED );
203 
204  itemsList.PushItem( itemWrapper );
205  }
206  }
207 
208  SaveCopyInUndoList( itemsList, UR_CHANGED );
209  }
210 
211  // Update the current module and same others modules if requested.
212  for( module = m_Pcb->m_Modules; module; module = module->Next() )
213  {
214  if( !aSameFootprints && (module != Module_Ref) )
215  continue;
216 
217  if( module->GetFPID() != Module_Ref->GetFPID() )
218  continue;
219 
220  // Erase module on screen
221  if( aRedraw )
222  {
223  module->SetFlags( DO_NOT_DRAW );
225  module->ClearFlags( DO_NOT_DRAW );
226  }
227 
228  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
229  {
230  // Filters changes prohibited.
231  if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
232  continue;
233 
234  if( aPadOrientFilter && (pad->GetOrientation() - module->GetOrientation()) != pad_orient )
235  continue;
236 
237  if( aPadLayerFilter )
238  {
239  if( pad->GetLayerSet() != aPad->GetLayerSet() )
240  continue;
241  }
242 
243  // Change characteristics:
244  pad->SetAttribute( aPad->GetAttribute() );
245  pad->SetShape( aPad->GetShape() );
246 
247  pad->SetLayerSet( aPad->GetLayerSet() );
248 
249  pad->SetSize( aPad->GetSize() );
250  pad->SetDelta( aPad->GetDelta() );
251  pad->SetOffset( aPad->GetOffset() );
252 
253  pad->SetDrillSize( aPad->GetDrillSize() );
254  pad->SetDrillShape( aPad->GetDrillShape() );
255 
256  pad->SetOrientation( pad_orient + module->GetOrientation() );
257 
258  // copy also local mask margins, because these parameters usually depend on
259  // pad sizes and layers
260  pad->SetLocalSolderMaskMargin( aPad->GetLocalSolderMaskMargin() );
261  pad->SetLocalSolderPasteMargin( aPad->GetLocalSolderPasteMargin() );
262  pad->SetLocalSolderPasteMarginRatio( aPad->GetLocalSolderPasteMarginRatio() );
263 
264  if( pad->GetShape() != PAD_SHAPE_TRAPEZOID )
265  {
266  pad->SetDelta( wxSize( 0, 0 ) );
267  }
268 
269  if( pad->GetShape() == PAD_SHAPE_CIRCLE )
270  {
271  // Ensure pad size.y = pad size.x
272  int size = pad->GetSize().x;
273  pad->SetSize( wxSize( size, size ) );
274  }
275 
276  switch( pad->GetAttribute() )
277  {
278  case PAD_ATTRIB_SMD:
279  case PAD_ATTRIB_CONN:
280  pad->SetDrillSize( wxSize( 0, 0 ) );
281  break;
282 
283  default:
284  break;
285  }
286  }
287 
288  module->CalculateBoundingBox();
289 
290  if( aRedraw )
292  }
293 
294  OnModify();
295 }
void DlgGlobalChange_PadSettings(D_PAD *aPad)
Function DlgGlobalChange_PadSettings changes pad characteristics for the given footprint or all footp...
Definition of class FOOTPRINT_EDIT_FRAME.
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:238
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
This file is part of the common library.
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
Class BOARD to handle a board.
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:243
MODULE * Next() const
Definition: class_module.h:100
MODULE * GetParent() const
Definition: class_pad.h:108
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:306
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:221
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
const LIB_ID & GetFPID() const
Definition: class_module.h:164
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
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:773
double GetOrientation() const
Definition: class_module.h:160
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:235
void DlgGlobalChange_PadSettings(D_PAD *aPad, bool aRedraw)
Function DlgGlobalChange_PadSettings Function to change pad caracteristics for the given footprint or...
D_PAD * Next() const
Definition: class_pad.h:106
const wxSize & GetSize() const
Definition: class_pad.h:182
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:249
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:60
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:252
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...
DLIST< MODULE > m_Modules
Definition: class_board.h:245
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:214
void GlobalChange_PadSettings(D_PAD *aPad, bool aSameFootprints, bool aPadShapeFilter, bool aPadOrientFilter, bool aPadLayerFilter, bool aRedraw, bool aSaveForUndo)
Function GlobalChange_PadSettings Function to change pad caracteristics for the given footprint or al...
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
const wxSize & GetDelta() const
Definition: class_pad.h:185
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
The common library.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
Module description (excepted pads)
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
const wxPoint & GetOffset() const
Definition: class_pad.h:191
#define DO_NOT_DRAW
Used to disable draw function.
Definition: base_struct.h:125