1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009-2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file globaleditpad.cpp
*/
#include <fctsys.h>
#include <common.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
#include <module_editor_frame.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <dialog_global_pads_edition_base.h>
/************************************/
/* class DIALOG_GLOBAL_PADS_EDITION */
/************************************/
class DIALOG_GLOBAL_PADS_EDITION : public DIALOG_GLOBAL_PADS_EDITION_BASE
{
private:
PCB_BASE_FRAME* m_parent;
D_PAD* m_currentPad;
public:
static bool m_Pad_Shape_Filter;
static bool m_Pad_Layer_Filter;
static bool m_Pad_Orient_Filter;
public:
DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad );
private:
void InstallPadEditor( wxCommandEvent& event );
void PadPropertiesAccept( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event );
};
DIALOG_GLOBAL_PADS_EDITION::DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad ) :
DIALOG_GLOBAL_PADS_EDITION_BASE( aParent )
{
m_parent = aParent;
m_currentPad = aPad;
// Pad filter selection.
m_Pad_Shape_Filter_CB->SetValue( m_Pad_Shape_Filter );
m_Pad_Layer_Filter_CB->SetValue( m_Pad_Layer_Filter );
m_Pad_Orient_Filter_CB->SetValue( m_Pad_Orient_Filter );
SetFocus();
GetSizer()->Fit( this );
Centre();
}
// Class DIALOG_GLOBAL_PADS_EDITION static variables
bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter = true;
bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter = true;
bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter = true;
void DIALOG_GLOBAL_PADS_EDITION::OnCancelClick( wxCommandEvent& event )
{
EndModal( -1 );
}
/* Calls the Pad editor.
*/
void DIALOG_GLOBAL_PADS_EDITION::InstallPadEditor( wxCommandEvent& event )
{
m_parent->InstallPadOptionsFrame( m_currentPad );
}
/* Update the parameters for the component being edited.
*/
void DIALOG_GLOBAL_PADS_EDITION::PadPropertiesAccept( wxCommandEvent& event )
{
int returncode = 0;
switch( event.GetId() )
{
case ID_CHANGE_ID_MODULES:
returncode = 1;
// Fall through
case ID_CHANGE_CURRENT_MODULE:
m_Pad_Shape_Filter = m_Pad_Shape_Filter_CB->GetValue();
m_Pad_Layer_Filter = m_Pad_Layer_Filter_CB->GetValue();
m_Pad_Orient_Filter = m_Pad_Orient_Filter_CB->GetValue();
EndModal( returncode );
break;
}
m_parent->OnModify();
}
/*
* PCB_EDIT_FRAME::Function DlgGlobalChange_PadSettings
* Function to change pad caracteristics for the given footprint
* or alls footprints which look like the given footprint
* Options are set by the opened dialog.
* aPad is the pattern. The given footprint is the parent of this pad
* aRedraw: if true: redraws the footprint
*/
void PCB_EDIT_FRAME::DlgGlobalChange_PadSettings( D_PAD* aPad, bool aRedraw )
{
int diag;
if( aPad == NULL )
aPad = &GetDesignSettings().m_Pad_Master;
MODULE* module = aPad->GetParent();
if( module == NULL )
{
DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
return;
}
SetMsgPanel( module );
{
DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
diag = dlg.ShowModal();
}
if( diag == -1 )
return;
bool edit_Same_Modules = false;
if( diag == 1 )
edit_Same_Modules = true;
GlobalChange_PadSettings( aPad,edit_Same_Modules,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter,
aRedraw, true );
}
/*
* FOOTPRINT_EDIT_FRAME::Function DlgGlobalChange_PadSettings
* Function to change pad caracteristics for the given footprint
* or alls footprints which look like the given footprint
* Options are set by the opened dialog.
* aPad is the pattern. The given footprint is the parent of this pad
*/
void FOOTPRINT_EDIT_FRAME::DlgGlobalChange_PadSettings( D_PAD* aPad )
{
int diag;
if( aPad == NULL )
aPad = &GetDesignSettings().m_Pad_Master;
MODULE* module = aPad->GetParent();
if( module == NULL )
{
DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
return;
}
SetMsgPanel( module );
{
DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
dlg.m_buttonIdModules->Enable( false );
diag = dlg.ShowModal();
}
if( diag == -1 )
return;
bool edit_Same_Modules = false;
if( diag == 1 )
edit_Same_Modules = true;
GlobalChange_PadSettings( aPad, edit_Same_Modules,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter,
true, false );
}
/*
* Function GlobalChange_PadSettings
* Function to change pad caracteristics for the given footprint
* or alls footprints which look like the given footprint
* aPad is the pattern. The given footprint is the parent of this pad
* aSameFootprints: if true, make changes on all identical footprints
* aPadShapeFilter: if true, make changes only on pads having the same shape as aPad
* aPadOrientFilter: if true, make changes only on pads having the same orientation as aPad
* aPadLayerFilter: if true, make changes only on pads having the same layers as aPad
* aRedraw: if true: redraws the footprint
* aSaveForUndo: if true: create an entry in the Undo/Redo list
* (usually: true in Schematic editor, false in Module editor)
*/
void PCB_BASE_FRAME::GlobalChange_PadSettings( D_PAD* aPad,
bool aSameFootprints,
bool aPadShapeFilter,
bool aPadOrientFilter,
bool aPadLayerFilter,
bool aRedraw, bool aSaveForUndo )
{
if( aPad == NULL )
aPad = &GetDesignSettings().m_Pad_Master;
MODULE* module = aPad->GetParent();
if( module == NULL )
{
DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
return;
}
// Search and copy the name of library reference.
MODULE* Module_Ref = module;
double pad_orient = aPad->GetOrientation() - Module_Ref->GetOrientation();
// Prepare an undo list:
if( aSaveForUndo )
{
PICKED_ITEMS_LIST itemsList;
for( module = m_Pcb->m_Modules; module; module = module->Next() )
{
if( !aSameFootprints && (module != Module_Ref) )
continue;
if( module->GetFPID() != Module_Ref->GetFPID() )
continue;
bool saveMe = false;
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
{
// Filters changes prohibited.
if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
continue;
double currpad_orient = pad->GetOrientation() - module->GetOrientation();
if( aPadOrientFilter && ( currpad_orient != pad_orient ) )
continue;
if( aPadLayerFilter && pad->GetLayerSet() != aPad->GetLayerSet() )
continue;
saveMe = true;
}
if( saveMe )
{
ITEM_PICKER itemWrapper( module, UR_CHANGED );
itemsList.PushItem( itemWrapper );
}
}
SaveCopyInUndoList( itemsList, UR_CHANGED );
}
// Update the current module and same others modules if requested.
for( module = m_Pcb->m_Modules; module; module = module->Next() )
{
if( !aSameFootprints && (module != Module_Ref) )
continue;
if( module->GetFPID() != Module_Ref->GetFPID() )
continue;
// Erase module on screen
if( aRedraw )
{
module->SetFlags( DO_NOT_DRAW );
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
module->ClearFlags( DO_NOT_DRAW );
}
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
{
// Filters changes prohibited.
if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
continue;
if( aPadOrientFilter && (pad->GetOrientation() - module->GetOrientation()) != pad_orient )
continue;
if( aPadLayerFilter )
{
if( pad->GetLayerSet() != aPad->GetLayerSet() )
continue;
else
m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
}
// Change characteristics:
pad->SetAttribute( aPad->GetAttribute() );
pad->SetShape( aPad->GetShape() );
pad->SetLayerSet( aPad->GetLayerSet() );
pad->SetSize( aPad->GetSize() );
pad->SetDelta( aPad->GetDelta() );
pad->SetOffset( aPad->GetOffset() );
pad->SetDrillSize( aPad->GetDrillSize() );
pad->SetDrillShape( aPad->GetDrillShape() );
pad->SetOrientation( pad_orient + module->GetOrientation() );
// copy also local mask margins, because these parameters usually depend on
// pad sizes and layers
pad->SetLocalSolderMaskMargin( aPad->GetLocalSolderMaskMargin() );
pad->SetLocalSolderPasteMargin( aPad->GetLocalSolderPasteMargin() );
pad->SetLocalSolderPasteMarginRatio( aPad->GetLocalSolderPasteMarginRatio() );
if( pad->GetShape() != PAD_SHAPE_TRAPEZOID )
{
pad->SetDelta( wxSize( 0, 0 ) );
}
if( pad->GetShape() == PAD_SHAPE_CIRCLE )
{
// Ensure pad size.y = pad size.x
int size = pad->GetSize().x;
pad->SetSize( wxSize( size, size ) );
}
switch( pad->GetAttribute() )
{
case PAD_ATTRIB_SMD:
case PAD_ATTRIB_CONN:
pad->SetDrillSize( wxSize( 0, 0 ) );
pad->SetOffset( wxPoint( 0, 0 ) );
break;
default:
break;
}
}
module->CalculateBoundingBox();
if( aRedraw )
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
}
OnModify();
}
|