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-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 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 <pcb_edit_frame.h>
34 #include <footprint_edit_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  // Do not copy a pad into it, it can create issue, and this is useless
198  if( pad == aPad )
199  continue;
200 
201  saveMe = true;
202  }
203 
204  if( saveMe )
205  {
206  ITEM_PICKER itemWrapper( module, UR_CHANGED );
207 
208  itemsList.PushItem( itemWrapper );
209  }
210  }
211 
212  SaveCopyInUndoList( itemsList, UR_CHANGED );
213  }
214 
215  // Update the current module and same others modules if requested.
216  for( module = m_Pcb->m_Modules; module; module = module->Next() )
217  {
218  if( !aSameFootprints && (module != Module_Ref) )
219  continue;
220 
221  if( module->GetFPID() != Module_Ref->GetFPID() )
222  continue;
223 
224  // Erase module on screen
225  if( aRedraw )
226  {
227  module->SetFlags( DO_NOT_DRAW );
229  module->ClearFlags( DO_NOT_DRAW );
230  }
231 
232  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
233  {
234  // Filters changes prohibited.
235  if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
236  continue;
237 
238  if( aPadOrientFilter &&
239  (pad->GetOrientation() - module->GetOrientation()) != pad_orient )
240  continue;
241 
242  if( aPadLayerFilter )
243  {
244  if( pad->GetLayerSet() != aPad->GetLayerSet() )
245  continue;
246  }
247 
248  // Do not copy a pad into it, it can create issue in custom pads
249  // and primitive list.
250  if( pad == aPad )
251  continue;
252 
253  // Copy physical characteristics:
254  pad->ImportSettingsFromMaster( *aPad );
255 
256  // copy also local mask margins:
257  pad->SetLocalSolderMaskMargin( aPad->GetLocalSolderMaskMargin() );
258  pad->SetLocalSolderPasteMargin( aPad->GetLocalSolderPasteMargin() );
259  pad->SetLocalSolderPasteMarginRatio( aPad->GetLocalSolderPasteMarginRatio() );
260  }
261 
262  module->CalculateBoundingBox();
263 
264  if( aRedraw )
266  }
267 
268  OnModify();
269 }
void DlgGlobalChange_PadSettings(D_PAD *aPad)
Function DlgGlobalChange_PadSettings changes pad characteristics for the given footprint or all footp...
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
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:403
MODULE * Next() const
Definition: class_module.h:121
MODULE * GetParent() const
Definition: class_pad.h:162
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:319
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
Definition of class FOOTPRINT_EDIT_FRAME.
const LIB_ID & GetFPID() const
Definition: class_module.h:191
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:282
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:790
double GetOrientation() const
Definition: class_module.h:187
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:395
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:160
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:409
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0)) override
Function SaveCopyInUndoList Creates a new entry in undo list of commands.
Definition: undo_redo.cpp:202
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:412
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
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:375
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.
The common library.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:283
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
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:241
#define DO_NOT_DRAW
Used to disable draw function.
Definition: base_struct.h:139