1 /*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com
6 * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@gmail.com>
7 * Copyright (C) 1992-2021 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
27 #include <base_units.h>
28 #include <bitmaps.h>
29 #include <board_commit.h>
30 #include <board.h>
31 #include <board_design_settings.h>
32 #include <footprint.h>
33 #include <confirm.h>
34 #include <core/arraydim.h>
35 #include <convert_basic_shapes_to_polygon.h> // for enum RECT_CHAMFER_POSITIONS definition
36 #include <geometry/shape_segment.h>
37 #include <dialog_pad_properties.h>
38 #include <gal/graphics_abstraction_layer.h>
39 #include <dialogs/html_message_box.h>
40 #include <macros.h>
41 #include <pad.h>
42 #include <pcb_base_frame.h>
43 #include <footprint_edit_frame.h>
44 #include <pcb_painter.h>
45 #include <pcbnew_settings.h>
46 #include <settings/color_settings.h>
47 #include <view/view_controls.h>
48 #include <widgets/net_selector.h>
49 #include <tool/tool_manager.h>
50 #include <tools/pad_tool.h>
51 #include <advanced_config.h> // for pad property feature management
52 #include <wx/choicdlg.h>
53
54
55 // list of pad shapes, ordered like the pad shape wxChoice in dialog.
56 static PAD_SHAPE code_shape[] =
57 {
58 PAD_SHAPE::CIRCLE,
59 PAD_SHAPE::OVAL,
60 PAD_SHAPE::RECT,
61 PAD_SHAPE::TRAPEZOID,
62 PAD_SHAPE::ROUNDRECT,
63 PAD_SHAPE::CHAMFERED_RECT,
64 PAD_SHAPE::CHAMFERED_RECT, // choice = CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT
65 PAD_SHAPE::CUSTOM, // choice = CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR
66 PAD_SHAPE::CUSTOM // choice = PAD_SHAPE::CUSTOM_RECT_ANCHOR
67 };
68
69
70 // the ordered index of the pad shape wxChoice in dialog.
71 // keep it consistent with code_shape[] and dialog strings
72 enum CODE_CHOICE
73 {
74 CHOICE_SHAPE_CIRCLE = 0,
75 CHOICE_SHAPE_OVAL,
76 CHOICE_SHAPE_RECT,
77 CHOICE_SHAPE_TRAPEZOID,
78 CHOICE_SHAPE_ROUNDRECT,
79 CHOICE_SHAPE_CHAMFERED_RECT,
80 CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT,
81 CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR,
82 CHOICE_SHAPE_CUSTOM_RECT_ANCHOR
83 };
84
85
86 static PAD_ATTRIB code_type[] =
87 {
88 PAD_ATTRIB::PTH,
89 PAD_ATTRIB::SMD,
90 PAD_ATTRIB::CONN,
91 PAD_ATTRIB::NPTH,
92 PAD_ATTRIB::SMD // Aperture pad :type SMD with no copper layers,
93 // only on tech layers (usually only on paste layer
94 };
95
96
97 // These define have the same value as the m_PadType wxChoice GetSelected() return value
98 #define PTH_DLG_TYPE 0
99 #define SMD_DLG_TYPE 1
100 #define CONN_DLG_TYPE 2
101 #define NPTH_DLG_TYPE 3
102 #define APERTURE_DLG_TYPE 4
103
104
ShowPadPropertiesDialog(PAD * aPad)105 void PCB_BASE_FRAME::ShowPadPropertiesDialog( PAD* aPad )
106 {
107 DIALOG_PAD_PROPERTIES dlg( this, aPad );
108
109 dlg.ShowQuasiModal();
110 }
111
112
DIALOG_PAD_PROPERTIES(PCB_BASE_FRAME * aParent,PAD * aPad)113 DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad ) :
114 DIALOG_PAD_PROPERTIES_BASE( aParent ),
115 m_parent( aParent ),
116 m_canUpdate( false ),
117 m_posX( aParent, m_posXLabel, m_posXCtrl, m_posXUnits ),
118 m_posY( aParent, m_posYLabel, m_posYCtrl, m_posYUnits ),
119 m_sizeX( aParent, m_sizeXLabel, m_sizeXCtrl, m_sizeXUnits ),
120 m_sizeY( aParent, m_sizeYLabel, m_sizeYCtrl, m_sizeYUnits ),
121 m_offsetX( aParent, m_offsetXLabel, m_offsetXCtrl, m_offsetXUnits ),
122 m_offsetY( aParent, m_offsetYLabel, m_offsetYCtrl, m_offsetYUnits ),
123 m_padToDie( aParent, m_padToDieLabel, m_padToDieCtrl, m_padToDieUnits ),
124 m_trapDelta( aParent, m_trapDeltaLabel, m_trapDeltaCtrl, m_trapDeltaUnits ),
125 m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits ),
126 m_cornerRatio( aParent, m_cornerRatioLabel, m_cornerRatioCtrl, m_cornerRatioUnits ),
127 m_chamferRatio( aParent, m_chamferRatioLabel, m_chamferRatioCtrl, m_chamferRatioUnits ),
128 m_mixedCornerRatio( aParent, m_mixedCornerRatioLabel, m_mixedCornerRatioCtrl,
129 m_mixedCornerRatioUnits ),
130 m_mixedChamferRatio( aParent, m_mixedChamferRatioLabel, m_mixedChamferRatioCtrl,
131 m_mixedChamferRatioUnits ),
132 m_holeX( aParent, m_holeXLabel, m_holeXCtrl, m_holeXUnits ),
133 m_holeY( aParent, m_holeYLabel, m_holeYCtrl, m_holeYUnits ),
134 m_clearance( aParent, m_clearanceLabel, m_clearanceCtrl, m_clearanceUnits ),
135 m_maskMargin( aParent, m_maskMarginLabel, m_maskMarginCtrl, m_maskMarginUnits ),
136 m_pasteMargin( aParent, m_pasteMarginLabel, m_pasteMarginCtrl, m_pasteMarginUnits ),
137 m_pasteMarginRatio( aParent, m_pasteMarginRatioLabel, m_pasteMarginRatioCtrl,
138 m_pasteMarginRatioUnits ),
139 m_spokeWidth( aParent, m_spokeWidthLabel, m_spokeWidthCtrl, m_spokeWidthUnits ),
140 m_thermalGap( aParent, m_thermalGapLabel, m_thermalGapCtrl, m_thermalGapUnits ),
141 m_pad_orientation( aParent, m_PadOrientText, m_cb_padrotation, m_orientationUnits )
142 {
143 SetName( PAD_PROPERTIES_DLG_NAME );
144 m_isFpEditor = dynamic_cast<FOOTPRINT_EDIT_FRAME*>( aParent ) != nullptr;
145
146 m_currentPad = aPad; // aPad can be NULL, if the dialog is called
147 // from the footprint editor to set default pad setup
148
149 m_board = m_parent->GetBoard();
150
151 // Configure display origin transforms
152 m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
153 m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
154
155 m_padNetSelector->SetBoard( m_board );
156 m_padNetSelector->SetNetInfo( &m_board->GetNetInfo() );
157
158 m_cbShowPadOutline->SetValue( m_sketchPreview );
159
160 m_FlippedWarningIcon->SetBitmap( KiBitmap( BITMAPS::dialog_warning ) );
161 m_nonCopperWarningIcon->SetBitmap( KiBitmap( BITMAPS::dialog_warning ) );
162
163 m_padMaster = m_parent->GetDesignSettings().m_Pad_Master.get();
164 m_dummyPad = new PAD( (FOOTPRINT*) nullptr );
165
166 if( aPad )
167 {
168 SetTitle( _( "Pad Properties" ) );
169
170 *m_dummyPad = *aPad;
171 m_dummyPad->ClearFlags( SELECTED|BRIGHTENED );
172 }
173 else
174 {
175 SetTitle( _( "Default Pad Properties for Add Pad Tool" ) );
176
177 *m_dummyPad = *m_padMaster;
178 }
179
180 if( m_isFpEditor )
181 {
182 m_padNetLabel->Show( false );
183 m_padNetSelector->Show( false );
184 }
185
186 // Pad needs to have a parent for painting; use the parent board for its design settings
187 if( !m_dummyPad->GetParent() )
188 m_dummyPad->SetParent( m_board );
189
190 m_cornerRatio.SetUnits( EDA_UNITS::PERCENT );
191 m_chamferRatio.SetUnits( EDA_UNITS::PERCENT );
192 m_mixedCornerRatio.SetUnits( EDA_UNITS::PERCENT );
193 m_mixedChamferRatio.SetUnits( EDA_UNITS::PERCENT );
194 m_pad_orientation.SetUnits( EDA_UNITS::DEGREES );
195 m_pad_orientation.SetPrecision( 3 );
196
197 m_pasteMargin.SetNegativeZero();
198
199 m_pasteMarginRatio.SetUnits( EDA_UNITS::PERCENT );
200 m_pasteMarginRatio.SetNegativeZero();
201
202 initValues();
203
204 wxFont infoFont = KIUI::GetInfoFont( this );
205 m_copperLayersLabel->SetFont( infoFont );
206 m_techLayersLabel->SetFont( infoFont );
207 m_parentInfo->SetFont( infoFont );
208
209 infoFont.SetStyle( wxFONTSTYLE_ITALIC );
210 m_nonCopperNote->SetFont( infoFont );
211 m_staticTextInfoPaste->SetFont( infoFont );
212 m_staticTextInfoNegVal->SetFont( infoFont );
213 m_staticTextInfoPosValue->SetFont( infoFont );
214 m_staticTextPrimitiveListWarning->SetFont( infoFont );
215
216 // Do not allow locking items in the footprint editor
217 m_locked->Show( !m_isFpEditor );
218
219 // Usually, TransferDataToWindow is called by OnInitDialog
220 // calling it here fixes all widget sizes so FinishDialogSettings can safely fix minsizes
221 TransferDataToWindow();
222
223 // Initialize canvas to be able to display the dummy pad:
224 prepareCanvas();
225
226 SetInitialFocus( m_padNumCtrl );
227 m_sdbSizerOK->SetDefault();
228 m_canUpdate = true;
229
230 m_padNetSelector->Connect( NET_SELECTED,
231 wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ),
232 nullptr, this );
233
234 // Now all widgets have the size fixed, call FinishDialogSettings
235 finishDialogSettings();
236
237 // Update widgets
238 wxUpdateUIEvent dummyUI;
239 OnUpdateUI( dummyUI );
240
241 // Post a dummy size event to force the pad preview panel to update the
242 // view: actual size, best zoom ... after the frame is shown
243 PostSizeEvent();
244 }
245
246
~DIALOG_PAD_PROPERTIES()247 DIALOG_PAD_PROPERTIES::~DIALOG_PAD_PROPERTIES()
248 {
249 m_padNetSelector->Disconnect( NET_SELECTED,
250 wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ),
251 nullptr, this );
252
253 delete m_dummyPad;
254 delete m_axisOrigin;
255 }
256
257
258 // Store the pad draw option during a session.
259 bool DIALOG_PAD_PROPERTIES::m_sketchPreview = false;
260
261
OnInitDialog(wxInitDialogEvent & event)262 void DIALOG_PAD_PROPERTIES::OnInitDialog( wxInitDialogEvent& event )
263 {
264 m_selectedColor = COLOR4D( 1.0, 1.0, 1.0, 0.7 );
265
266 // Needed on some WM to be sure the pad is redrawn according to the final size
267 // of the canvas, with the right zoom factor
268 redraw();
269 }
270
271
OnCancel(wxCommandEvent & event)272 void DIALOG_PAD_PROPERTIES::OnCancel( wxCommandEvent& event )
273 {
274 // Mandatory to avoid m_panelShowPadGal trying to draw something
275 // in a non valid context during closing process:
276 m_padPreviewGAL->StopDrawing();
277
278 // Now call default handler for wxID_CANCEL command event
279 event.Skip();
280 }
281
282
enablePrimitivePage(bool aEnable)283 void DIALOG_PAD_PROPERTIES::enablePrimitivePage( bool aEnable )
284 {
285 // Enable or disable the widgets in page managing custom shape primitives
286 m_listCtrlPrimitives->Enable( aEnable );
287 m_buttonDel->Enable( aEnable );
288 m_buttonEditShape->Enable( aEnable );
289 m_buttonAddShape->Enable( aEnable );
290 m_buttonDup->Enable( aEnable );
291 m_buttonGeometry->Enable( aEnable );
292 }
293
294
prepareCanvas()295 void DIALOG_PAD_PROPERTIES::prepareCanvas()
296 {
297 // Initialize the canvas to display the pad
298 m_padPreviewGAL = new PCB_DRAW_PANEL_GAL( m_boardViewPanel, -1, wxDefaultPosition,
299 wxDefaultSize,
300 m_parent->GetGalDisplayOptions(),
301 m_parent->GetCanvas()->GetBackend() );
302
303 m_padPreviewSizer->Add( m_padPreviewGAL, 12, wxEXPAND | wxALL, 5 );
304
305 // Show the X and Y axis. It is useful because pad shape can have an offset
306 // or be a complex shape.
307 KIGFX::COLOR4D axis_color = LIGHTBLUE;
308
309 m_axisOrigin = new KIGFX::ORIGIN_VIEWITEM( axis_color, KIGFX::ORIGIN_VIEWITEM::CROSS,
310 Millimeter2iu( 0.2 ),
311 VECTOR2D( m_dummyPad->GetPosition() ) );
312 m_axisOrigin->SetDrawAtZero( true );
313
314 m_padPreviewGAL->UpdateColors();
315 m_padPreviewGAL->SetStealsFocus( false );
316 m_padPreviewGAL->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
317
318 KIGFX::VIEW_CONTROLS* parentViewControls = m_parent->GetCanvas()->GetViewControls();
319 m_padPreviewGAL->GetViewControls()->ApplySettings( parentViewControls->GetSettings() );
320
321 m_padPreviewGAL->Show();
322
323 KIGFX::VIEW* view = m_padPreviewGAL->GetView();
324
325 // fix the pad render mode (filled/not filled)
326 auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
327 bool sketchMode = m_cbShowPadOutline->IsChecked();
328 settings->SetSketchMode( LAYER_PADS_TH, sketchMode );
329 settings->SetSketchMode( LAYER_PAD_FR, sketchMode );
330 settings->SetSketchMode( LAYER_PAD_BK, sketchMode );
331 settings->SetSketchModeGraphicItems( sketchMode );
332
333 settings->SetHighContrast( false );
334 settings->SetContrastModeDisplay( HIGH_CONTRAST_MODE::NORMAL );
335
336 // gives a non null grid size (0.001mm) because GAL layer does not like a 0 size grid:
337 double gridsize = 0.001 * IU_PER_MM;
338 view->GetGAL()->SetGridSize( VECTOR2D( gridsize, gridsize ) );
339
340 // And do not show the grid:
341 view->GetGAL()->SetGridVisibility( false );
342 view->Add( m_dummyPad );
343 view->Add( m_axisOrigin );
344
345 m_padPreviewGAL->StartDrawing();
346 Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_PAD_PROPERTIES::OnResize ) );
347 }
348
349
updateRoundRectCornerValues()350 void DIALOG_PAD_PROPERTIES::updateRoundRectCornerValues()
351 {
352 // Note: use ChangeValue() to avoid generating a wxEVT_TEXT event
353 m_cornerRadius.ChangeValue( m_dummyPad->GetRoundRectCornerRadius() );
354
355 m_cornerRatio.ChangeDoubleValue( m_dummyPad->GetRoundRectRadiusRatio() * 100.0 );
356 m_mixedCornerRatio.ChangeDoubleValue( m_dummyPad->GetRoundRectRadiusRatio() * 100.0 );
357
358 m_chamferRatio.ChangeDoubleValue( m_dummyPad->GetChamferRectRatio() * 100.0 );
359 m_mixedChamferRatio.ChangeDoubleValue( m_dummyPad->GetChamferRectRatio() * 100.0 );
360 }
361
362
onCornerRadiusChange(wxCommandEvent & event)363 void DIALOG_PAD_PROPERTIES::onCornerRadiusChange( wxCommandEvent& event )
364 {
365 if( m_dummyPad->GetShape() != PAD_SHAPE::ROUNDRECT &&
366 m_dummyPad->GetShape() != PAD_SHAPE::CHAMFERED_RECT )
367 {
368 return;
369 }
370
371 if( m_cornerRadius.GetValue() < 0 )
372 m_cornerRadiusCtrl->ChangeValue( "0" );
373
374 transferDataToPad( m_dummyPad );
375 m_dummyPad->SetRoundRectCornerRadius( m_cornerRadius.GetValue() );
376
377 m_cornerRatio.ChangeDoubleValue( m_dummyPad->GetRoundRectRadiusRatio() * 100.0 );
378 m_mixedCornerRatio.ChangeDoubleValue( m_dummyPad->GetRoundRectRadiusRatio() * 100.0 );
379
380 redraw();
381 }
382
383
onCornerSizePercentChange(wxCommandEvent & event)384 void DIALOG_PAD_PROPERTIES::onCornerSizePercentChange( wxCommandEvent& event )
385 {
386 if( m_dummyPad->GetShape() != PAD_SHAPE::ROUNDRECT &&
387 m_dummyPad->GetShape() != PAD_SHAPE::CHAMFERED_RECT )
388 {
389 return;
390 }
391
392 wxObject* ctrl = event.GetEventObject();
393 wxString value = event.GetString();
394 bool changed = false;
395
396 if( ctrl == m_cornerRatioCtrl || ctrl == m_mixedCornerRatioCtrl )
397 {
398 double ratioPercent;
399
400 if( value.ToDouble( &ratioPercent ) )
401 {
402 // Clamp ratioPercent to acceptable value (0.0 to 50.0)
403 if( ratioPercent < 0.0 )
404 {
405 m_cornerRatio.SetDoubleValue( 0.0 );
406 m_mixedCornerRatio.SetDoubleValue( 0.0 );
407 }
408 else if( ratioPercent > 50.0 )
409 {
410 m_cornerRatio.SetDoubleValue( 50.0 );
411 m_mixedCornerRatio.SetDoubleValue( 50.0 );
412 }
413
414 if( ctrl == m_cornerRatioCtrl )
415 m_mixedCornerRatioCtrl->ChangeValue( value );
416 else
417 m_cornerRatioCtrl->ChangeValue( value );
418
419 changed = true;
420 }
421 }
422 else if( ctrl == m_chamferRatioCtrl || ctrl == m_mixedChamferRatioCtrl )
423 {
424 double ratioPercent;
425
426 if( value.ToDouble( &ratioPercent ) )
427 {
428 // Clamp ratioPercent to acceptable value (0.0 to 50.0)
429 if( ratioPercent < 0.0 )
430 {
431 m_chamferRatio.SetDoubleValue( 0.0 );
432 m_mixedChamferRatio.SetDoubleValue( 0.0 );
433 }
434 else if( ratioPercent > 50.0 )
435 {
436 m_chamferRatio.SetDoubleValue( 50.0 );
437 m_mixedChamferRatio.SetDoubleValue( 50.0 );
438 }
439
440 if( ctrl == m_chamferRatioCtrl )
441 m_mixedChamferRatioCtrl->ChangeValue( value );
442 else
443 m_chamferRatioCtrl->ChangeValue( value );
444
445 changed = true;
446 }
447 }
448
449 if( changed )
450 {
451 transferDataToPad( m_dummyPad );
452 m_cornerRadius.ChangeValue( m_dummyPad->GetRoundRectCornerRadius() );
453 }
454
455 redraw();
456 }
457
458
initValues()459 void DIALOG_PAD_PROPERTIES::initValues()
460 {
461 wxString msg;
462
463 // Disable pad net name wxTextCtrl if the caller is the footprint editor
464 // because nets are living only in the board managed by the board editor
465 m_canEditNetName = m_parent->IsType( FRAME_PCB_EDITOR );
466
467 m_PadLayerAdhCmp->SetLabel( m_board->GetLayerName( F_Adhes ) );
468 m_PadLayerAdhCu->SetLabel( m_board->GetLayerName( B_Adhes ) );
469 m_PadLayerPateCmp->SetLabel( m_board->GetLayerName( F_Paste ) );
470 m_PadLayerPateCu->SetLabel( m_board->GetLayerName( B_Paste ) );
471 m_PadLayerSilkCmp->SetLabel( m_board->GetLayerName( F_SilkS ) );
472 m_PadLayerSilkCu->SetLabel( m_board->GetLayerName( B_SilkS ) );
473 m_PadLayerMaskCmp->SetLabel( m_board->GetLayerName( F_Mask ) );
474 m_PadLayerMaskCu->SetLabel( m_board->GetLayerName( B_Mask ) );
475 m_PadLayerECO1->SetLabel( m_board->GetLayerName( Eco1_User ) );
476 m_PadLayerECO2->SetLabel( m_board->GetLayerName( Eco2_User ) );
477 m_PadLayerDraft->SetLabel( m_board->GetLayerName( Dwgs_User ) );
478
479 if( m_currentPad )
480 {
481 m_locked->SetValue( m_currentPad->IsLocked() );
482 m_isFlipped = m_currentPad->IsFlipped();
483
484 FOOTPRINT* footprint = m_currentPad->GetParent();
485
486 if( footprint )
487 {
488 double angle = m_dummyPad->GetOrientation();
489 angle -= footprint->GetOrientation();
490 m_dummyPad->SetOrientation( angle );
491
492 // Display parent footprint info
493 msg.Printf( _("Footprint %s (%s), %s, rotated %g deg"),
494 footprint->Reference().GetShownText(),
495 footprint->Value().GetShownText(),
496 footprint->IsFlipped() ? _( "back side (mirrored)" ) : _( "front side" ),
497 footprint->GetOrientationDegrees() );
498 }
499
500 m_parentInfo->SetLabel( msg );
501 }
502 else
503 {
504 m_locked->Hide();
505 m_isFlipped = false;
506 }
507
508 if( m_isFlipped )
509 {
510 // flip pad (up/down) around its position
511 m_dummyPad->Flip( m_dummyPad->GetPosition(), false );
512 }
513
514 m_primitives = m_dummyPad->GetPrimitives();
515
516 m_FlippedWarningSizer->Show( m_isFlipped );
517
518 if( m_currentPad )
519 {
520 m_padNumCtrl->SetValue( m_dummyPad->GetNumber() );
521 }
522 else
523 {
524 PAD_TOOL* padTool = m_parent->GetToolManager()->GetTool<PAD_TOOL>();
525 m_padNumCtrl->SetValue( padTool->GetLastPadNumber() );
526 }
527
528 m_padNetSelector->SetSelectedNetcode( m_dummyPad->GetNetCode() );
529
530 // Display current pad parameters units:
531 m_posX.ChangeValue( m_dummyPad->GetPosition().x );
532 m_posY.ChangeValue( m_dummyPad->GetPosition().y );
533
534 m_holeX.ChangeValue( m_dummyPad->GetDrillSize().x );
535 m_holeY.ChangeValue( m_dummyPad->GetDrillSize().y );
536
537 m_sizeX.ChangeValue( m_dummyPad->GetSize().x );
538 m_sizeY.ChangeValue( m_dummyPad->GetSize().y );
539
540 m_offsetShapeOpt->SetValue( m_dummyPad->GetOffset() != wxPoint() );
541 m_offsetX.ChangeValue( m_dummyPad->GetOffset().x );
542 m_offsetY.ChangeValue( m_dummyPad->GetOffset().y );
543
544 if( m_dummyPad->GetDelta().x )
545 {
546 m_trapDelta.ChangeValue( m_dummyPad->GetDelta().x );
547 m_trapAxisCtrl->SetSelection( 0 );
548 }
549 else
550 {
551 m_trapDelta.ChangeValue( m_dummyPad->GetDelta().y );
552 m_trapAxisCtrl->SetSelection( 1 );
553 }
554
555 m_padToDieOpt->SetValue( m_dummyPad->GetPadToDieLength() != 0 );
556 m_padToDie.ChangeValue( m_dummyPad->GetPadToDieLength() );
557
558 m_clearance.ChangeValue( m_dummyPad->GetLocalClearance() );
559 m_maskMargin.ChangeValue( m_dummyPad->GetLocalSolderMaskMargin() );
560 m_spokeWidth.ChangeValue( m_dummyPad->GetThermalSpokeWidth() );
561 m_thermalGap.ChangeValue( m_dummyPad->GetThermalGap() );
562 m_pasteMargin.ChangeValue( m_dummyPad->GetLocalSolderPasteMargin() );
563 m_pasteMarginRatio.ChangeDoubleValue( m_dummyPad->GetLocalSolderPasteMarginRatio() * 100.0 );
564 m_pad_orientation.ChangeDoubleValue( m_dummyPad->GetOrientation() );
565
566 switch( m_dummyPad->GetZoneConnection() )
567 {
568 default:
569 case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
570 case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
571 case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
572 case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
573 }
574
575 if( m_dummyPad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL )
576 m_ZoneCustomPadShape->SetSelection( 1 );
577 else
578 m_ZoneCustomPadShape->SetSelection( 0 );
579
580 switch( m_dummyPad->GetShape() )
581 {
582 default:
583 case PAD_SHAPE::CIRCLE: m_PadShapeSelector->SetSelection( CHOICE_SHAPE_CIRCLE ); break;
584 case PAD_SHAPE::OVAL: m_PadShapeSelector->SetSelection( CHOICE_SHAPE_OVAL ); break;
585 case PAD_SHAPE::RECT: m_PadShapeSelector->SetSelection( CHOICE_SHAPE_RECT ); break;
586 case PAD_SHAPE::TRAPEZOID: m_PadShapeSelector->SetSelection( CHOICE_SHAPE_TRAPEZOID ); break;
587 case PAD_SHAPE::ROUNDRECT: m_PadShapeSelector->SetSelection( CHOICE_SHAPE_ROUNDRECT ); break;
588
589 case PAD_SHAPE::CHAMFERED_RECT:
590 if( m_dummyPad->GetRoundRectRadiusRatio() > 0.0 )
591 m_PadShapeSelector->SetSelection( CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT );
592 else
593 m_PadShapeSelector->SetSelection( CHOICE_SHAPE_CHAMFERED_RECT );
594 break;
595
596 case PAD_SHAPE::CUSTOM:
597 if( m_dummyPad->GetAnchorPadShape() == PAD_SHAPE::RECT )
598 m_PadShapeSelector->SetSelection( CHOICE_SHAPE_CUSTOM_RECT_ANCHOR );
599 else
600 m_PadShapeSelector->SetSelection( CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR );
601 break;
602 }
603
604 m_cbTopLeft->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT) );
605 m_cbTopLeft1->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT) );
606 m_cbTopRight->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT) );
607 m_cbTopRight1->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT) );
608 m_cbBottomLeft->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT) );
609 m_cbBottomLeft1->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT) );
610 m_cbBottomRight->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_RIGHT) );
611 m_cbBottomRight1->SetValue( (m_dummyPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_RIGHT) );
612
613 updateRoundRectCornerValues();
614
615 enablePrimitivePage( PAD_SHAPE::CUSTOM == m_dummyPad->GetShape() );
616
617 // Type of pad selection
618 bool aperture = m_dummyPad->GetAttribute() == PAD_ATTRIB::SMD && m_dummyPad->IsAperturePad();
619
620 if( aperture )
621 {
622 m_padType->SetSelection( APERTURE_DLG_TYPE );
623 }
624 else
625 {
626 switch( m_dummyPad->GetAttribute() )
627 {
628 case PAD_ATTRIB::PTH: m_padType->SetSelection( PTH_DLG_TYPE ); break;
629 case PAD_ATTRIB::SMD: m_padType->SetSelection( SMD_DLG_TYPE ); break;
630 case PAD_ATTRIB::CONN: m_padType->SetSelection( CONN_DLG_TYPE ); break;
631 case PAD_ATTRIB::NPTH: m_padType->SetSelection( NPTH_DLG_TYPE ); break;
632 }
633 }
634
635 switch( m_dummyPad->GetProperty() )
636 {
637 case PAD_PROP::NONE: m_choiceFabProperty->SetSelection( 0 ); break;
638 case PAD_PROP::BGA: m_choiceFabProperty->SetSelection( 1 ); break;
639 case PAD_PROP::FIDUCIAL_LOCAL: m_choiceFabProperty->SetSelection( 2 ); break;
640 case PAD_PROP::FIDUCIAL_GLBL: m_choiceFabProperty->SetSelection( 3 ); break;
641 case PAD_PROP::TESTPOINT: m_choiceFabProperty->SetSelection( 4 ); break;
642 case PAD_PROP::HEATSINK: m_choiceFabProperty->SetSelection( 5 ); break;
643 case PAD_PROP::CASTELLATED: m_choiceFabProperty->SetSelection( 6 ); break;
644 }
645
646 // Ensure the pad property is compatible with the pad type
647 if( m_dummyPad->GetAttribute() == PAD_ATTRIB::NPTH )
648 {
649 m_choiceFabProperty->SetSelection( 0 );
650 m_choiceFabProperty->Enable( false );
651 }
652
653 if( m_dummyPad->GetDrillShape() != PAD_DRILL_SHAPE_OBLONG )
654 m_holeShapeCtrl->SetSelection( 0 );
655 else
656 m_holeShapeCtrl->SetSelection( 1 );
657
658 updatePadLayersList( m_dummyPad->GetLayerSet(), m_dummyPad->GetRemoveUnconnected(),
659 m_dummyPad->GetKeepTopBottom() );
660
661 // Update some dialog widgets state (Enable/disable options):
662 wxCommandEvent cmd_event;
663 OnPadShapeSelection( cmd_event );
664 OnOffsetCheckbox( cmd_event );
665
666 // Update basic shapes list
667 displayPrimitivesList();
668 }
669
670 // A small helper function, to display coordinates:
formatCoord(EDA_UNITS aUnits,wxPoint aCoord)671 static wxString formatCoord( EDA_UNITS aUnits, wxPoint aCoord )
672 {
673 return wxString::Format( "(X:%s Y:%s)",
674 MessageTextFromValue( aUnits, aCoord.x ),
675 MessageTextFromValue( aUnits, aCoord.y ) );
676 }
677
displayPrimitivesList()678 void DIALOG_PAD_PROPERTIES::displayPrimitivesList()
679 {
680 m_listCtrlPrimitives->ClearAll();
681
682 wxListItem itemCol;
683 itemCol.SetImage(-1);
684
685 for( int ii = 0; ii < 5; ++ii )
686 m_listCtrlPrimitives->InsertColumn(ii, itemCol);
687
688 wxString bs_info[5];
689
690 for( unsigned ii = 0; ii < m_primitives.size(); ++ii )
691 {
692 const std::shared_ptr<PCB_SHAPE>& primitive = m_primitives[ii];
693
694 for( wxString& s : bs_info )
695 s.Empty();
696
697 bs_info[4] = _( "width" ) + wxS( " " )+ MessageTextFromValue( m_units,
698 primitive->GetWidth() );
699
700 switch( primitive->GetShape() )
701 {
702 case SHAPE_T::SEGMENT:
703 bs_info[0] = _( "Segment" );
704 bs_info[1] = _( "from" ) + wxS( " " )+ formatCoord( m_units, primitive->GetStart() );
705 bs_info[2] = _( "to" ) + wxS( " " )+ formatCoord( m_units, primitive->GetEnd() );
706 break;
707
708 case SHAPE_T::BEZIER:
709 bs_info[0] = _( "Bezier" );
710 bs_info[1] = _( "from" ) + wxS( " " )+ formatCoord( m_units, primitive->GetStart() );
711 bs_info[2] = _( "to" ) + wxS( " " )+ formatCoord( m_units, primitive->GetEnd() );
712 break;
713
714 case SHAPE_T::ARC:
715 bs_info[0] = _( "Arc" );
716 bs_info[1] = _( "center" ) + wxS( " " )+ formatCoord( m_units, primitive->GetCenter() );
717 bs_info[2] = _( "start" ) + wxS( " " )+ formatCoord( m_units, primitive->GetStart() );
718 bs_info[3] = _( "angle" ) + wxS( " " )+ FormatAngle( primitive->GetArcAngle() );
719 break;
720
721 case SHAPE_T::CIRCLE:
722 if( primitive->GetWidth() )
723 bs_info[0] = _( "ring" );
724 else
725 bs_info[0] = _( "circle" );
726
727 bs_info[1] = formatCoord( m_units, primitive->GetStart() );
728 bs_info[2] = _( "radius" ) + wxS( " " )+ MessageTextFromValue( m_units,
729 primitive->GetRadius() );
730 break;
731
732 case SHAPE_T::POLY:
733 bs_info[0] = "Polygon";
734 bs_info[1] = wxString::Format( _( "corners count %d" ),
735 (int) primitive->GetPolyShape().Outline( 0 ).PointCount() );
736 break;
737
738 default:
739 bs_info[0] = "Unknown primitive";
740 break;
741 }
742
743 long tmp = m_listCtrlPrimitives->InsertItem( ii, bs_info[0] );
744 m_listCtrlPrimitives->SetItemData( tmp, ii );
745
746 for( int jj = 0, col = 0; jj < 5; ++jj )
747 m_listCtrlPrimitives->SetItem( tmp, col++, bs_info[jj] );
748 }
749
750 // Now columns are filled, ensure correct width of columns
751 for( unsigned ii = 0; ii < 5; ++ii )
752 m_listCtrlPrimitives->SetColumnWidth( ii, wxLIST_AUTOSIZE );
753 }
754
755
OnResize(wxSizeEvent & event)756 void DIALOG_PAD_PROPERTIES::OnResize( wxSizeEvent& event )
757 {
758 redraw();
759 event.Skip();
760 }
761
762
onChangePadMode(wxCommandEvent & event)763 void DIALOG_PAD_PROPERTIES::onChangePadMode( wxCommandEvent& event )
764 {
765 m_sketchPreview = m_cbShowPadOutline->GetValue();
766
767 KIGFX::VIEW* view = m_padPreviewGAL->GetView();
768
769 // fix the pad render mode (filled/not filled)
770 KIGFX::PCB_RENDER_SETTINGS* settings =
771 static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
772
773 settings->SetSketchMode( LAYER_PADS_TH, m_sketchPreview );
774 settings->SetSketchMode( LAYER_PAD_FR, m_sketchPreview );
775 settings->SetSketchMode( LAYER_PAD_BK, m_sketchPreview );
776 settings->SetSketchModeGraphicItems( m_sketchPreview );
777
778 settings->SetHighContrast( false );
779 settings->SetContrastModeDisplay( HIGH_CONTRAST_MODE::NORMAL );
780
781 redraw();
782 }
783
784
OnPadShapeSelection(wxCommandEvent & event)785 void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
786 {
787 switch( m_PadShapeSelector->GetSelection() )
788 {
789 case CHOICE_SHAPE_CIRCLE:
790 case CHOICE_SHAPE_OVAL:
791 case CHOICE_SHAPE_RECT:
792 m_shapePropsBook->SetSelection( 0 );
793 break;
794
795 case CHOICE_SHAPE_TRAPEZOID:
796 m_shapePropsBook->SetSelection( 1 );
797 break;
798
799 case CHOICE_SHAPE_ROUNDRECT:
800 {
801 m_shapePropsBook->SetSelection( 2 );
802
803 // A reasonable default (from IPC-7351C)
804 if( m_dummyPad->GetRoundRectRadiusRatio() == 0.0 )
805 m_cornerRatio.ChangeValue( 25 );
806
807 break;
808 }
809
810 case CHOICE_SHAPE_CHAMFERED_RECT:
811 m_shapePropsBook->SetSelection( 3 );
812
813 // Reasonable default
814 if( m_dummyPad->GetChamferRectRatio() == 0.0 )
815 m_dummyPad->SetChamferRectRatio( 0.2 );
816
817 // Ensure the displayed value is up to date:
818 m_chamferRatio.ChangeDoubleValue( m_dummyPad->GetChamferRectRatio() * 100.0 );
819
820 // A reasonable default is one corner chamfered (usual for some SMD pads).
821 if( !m_cbTopLeft->GetValue() && !m_cbTopRight->GetValue()
822 && !m_cbBottomLeft->GetValue() && !m_cbBottomRight->GetValue() )
823 {
824 m_cbTopLeft->SetValue( true );
825 m_cbTopRight->SetValue( false );
826 m_cbBottomLeft->SetValue( false );
827 m_cbBottomRight->SetValue( false );
828 }
829
830 break;
831
832 case CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT:
833 m_shapePropsBook->SetSelection( 4 );
834
835 // Reasonable defaults (corner radius from IPC-7351C)
836 if( m_dummyPad->GetRoundRectRadiusRatio() == 0.0
837 && m_dummyPad->GetChamferRectRatio() == 0.0 )
838 {
839 if( m_dummyPad->GetRoundRectRadiusRatio() == 0.0 )
840 m_dummyPad->SetRoundRectRadiusRatio( 0.25 );
841
842 if( m_dummyPad->GetChamferRectRatio() == 0.0 )
843 m_dummyPad->SetChamferRectRatio( 0.2 );
844 }
845
846 // Ensure the displayed values are up to date:
847 m_mixedChamferRatio.ChangeDoubleValue( m_dummyPad->GetChamferRectRatio() * 100.0 );
848 m_mixedCornerRatio.ChangeDoubleValue( m_dummyPad->GetRoundRectRadiusRatio() * 100.0 );
849 break;
850
851 case CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR: // PAD_SHAPE::CUSTOM, circular anchor
852 case CHOICE_SHAPE_CUSTOM_RECT_ANCHOR: // PAD_SHAPE::CUSTOM, rect anchor
853 m_shapePropsBook->SetSelection( 0 );
854 break;
855 }
856
857 // Readjust props book size
858 wxSize size = m_shapePropsBook->GetSize();
859 size.y = m_shapePropsBook->GetPage( m_shapePropsBook->GetSelection() )->GetBestSize().y;
860 m_shapePropsBook->SetMaxSize( size );
861
862 m_sizeY.Enable( m_PadShapeSelector->GetSelection() != CHOICE_SHAPE_CIRCLE
863 && m_PadShapeSelector->GetSelection() != CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR );
864
865 m_offsetShapeOpt->Enable( m_PadShapeSelector->GetSelection() != CHOICE_SHAPE_CIRCLE
866 && m_PadShapeSelector->GetSelection() != CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR
867 && m_PadShapeSelector->GetSelection() != CHOICE_SHAPE_CUSTOM_RECT_ANCHOR );
868
869 if( !m_offsetShapeOpt->IsEnabled() )
870 m_offsetShapeOpt->SetValue( false );
871
872 // Show/hide controls depending on m_offsetShapeOpt being enabled
873 m_offsetCtrls->Show( m_offsetShapeOpt->GetValue() );
874 m_offsetShapeOptLabel->Show( m_offsetShapeOpt->GetValue() );
875
876 bool is_custom = m_PadShapeSelector->GetSelection() == CHOICE_SHAPE_CUSTOM_CIRC_ANCHOR
877 || m_PadShapeSelector->GetSelection() == CHOICE_SHAPE_CUSTOM_RECT_ANCHOR;
878
879 enablePrimitivePage( is_custom );
880 m_staticTextcps->Enable( is_custom );
881 m_ZoneCustomPadShape->Enable( is_custom );
882
883 transferDataToPad( m_dummyPad );
884
885 updateRoundRectCornerValues();
886
887 for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
888 m_notebook->GetPage( i )->Layout();
889
890 // Resize the dialog if its height is too small to show all widgets:
891 if( m_MainSizer->GetSize().y < m_MainSizer->GetMinSize().y )
892 m_MainSizer->SetSizeHints( this );
893
894 redraw();
895 }
896
897
OnDrillShapeSelected(wxCommandEvent & event)898 void DIALOG_PAD_PROPERTIES::OnDrillShapeSelected( wxCommandEvent& event )
899 {
900 transferDataToPad( m_dummyPad );
901 redraw();
902 }
903
904
PadOrientEvent(wxCommandEvent & event)905 void DIALOG_PAD_PROPERTIES::PadOrientEvent( wxCommandEvent& event )
906 {
907 transferDataToPad( m_dummyPad );
908 redraw();
909 }
910
911
UpdateLayersDropdown()912 void DIALOG_PAD_PROPERTIES::UpdateLayersDropdown()
913 {
914 m_rbCopperLayersSel->Clear();
915
916 switch( m_padType->GetSelection() )
917 {
918 case PTH_DLG_TYPE:
919 m_rbCopperLayersSel->Append( _( "All copper layers" ) );
920 m_rbCopperLayersSel->Append( wxString::Format( _( "%s, %s and connected layers" ),
921 m_board->GetLayerName( F_Cu ),
922 m_board->GetLayerName( B_Cu ) ) );
923 m_rbCopperLayersSel->Append( _( "Connected layers only" ) );
924 m_rbCopperLayersSel->Append( _( "None" ) );
925 break;
926
927 case NPTH_DLG_TYPE:
928 m_rbCopperLayersSel->Append( wxString::Format( _( "%s and %s" ),
929 m_board->GetLayerName( F_Cu ),
930 m_board->GetLayerName( B_Cu ) ) );
931 m_rbCopperLayersSel->Append( m_board->GetLayerName( F_Cu ) );
932 m_rbCopperLayersSel->Append( m_board->GetLayerName( B_Cu ) );
933 m_rbCopperLayersSel->Append( _( "None" ) );
934 break;
935
936 case SMD_DLG_TYPE:
937 case CONN_DLG_TYPE:
938 m_rbCopperLayersSel->Append( m_board->GetLayerName( F_Cu ) );
939 m_rbCopperLayersSel->Append( m_board->GetLayerName( B_Cu ) );
940 break;
941
942 case APERTURE_DLG_TYPE:
943 m_rbCopperLayersSel->Append( _( "None" ) );
944 break;
945 }
946 }
947
948
PadTypeSelected(wxCommandEvent & event)949 void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event )
950 {
951 bool hasHole = true;
952 bool hasConnection = true;
953 bool hasProperty = true;
954
955 switch( m_padType->GetSelection() )
956 {
957 case PTH_DLG_TYPE: hasHole = true; hasConnection = true; hasProperty = true; break;
958 case SMD_DLG_TYPE: hasHole = false; hasConnection = true; hasProperty = true; break;
959 case CONN_DLG_TYPE: hasHole = false; hasConnection = true; hasProperty = true; break;
960 case NPTH_DLG_TYPE: hasHole = true; hasConnection = false; hasProperty = false; break;
961 case APERTURE_DLG_TYPE: hasHole = false; hasConnection = false; hasProperty = true; break;
962 }
963
964 // Update Layers dropdown list and selects the "best" layer set for the new pad type:
965 updatePadLayersList( {}, m_dummyPad->GetRemoveUnconnected(), m_dummyPad->GetKeepTopBottom() );
966
967 if( !hasHole )
968 {
969 m_holeX.ChangeValue( 0 );
970 m_holeY.ChangeValue( 0 );
971 }
972 else if ( m_holeX.GetValue() == 0 && m_currentPad )
973 {
974 m_holeX.ChangeValue( m_currentPad->GetDrillSize().x );
975 m_holeY.ChangeValue( m_currentPad->GetDrillSize().y );
976 }
977
978 if( !hasConnection )
979 {
980 m_padNumCtrl->ChangeValue( wxEmptyString );
981 m_padNetSelector->SetSelectedNetcode( 0 );
982 m_padToDieOpt->SetValue( false );
983 }
984 else if( m_padNumCtrl->GetValue().IsEmpty() && m_currentPad )
985 {
986 m_padNumCtrl->ChangeValue( m_currentPad->GetNumber() );
987 m_padNetSelector->SetSelectedNetcode( m_currentPad->GetNetCode() );
988 }
989
990 if( !hasProperty )
991 m_choiceFabProperty->SetSelection( 0 );
992
993 m_choiceFabProperty->Enable( hasProperty );
994
995 transferDataToPad( m_dummyPad );
996
997 redraw();
998 }
999
1000
OnUpdateUI(wxUpdateUIEvent & event)1001 void DIALOG_PAD_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
1002 {
1003 // Enable/disable position
1004 m_posX.Enable( !m_locked->GetValue() || m_isFpEditor );
1005 m_posY.Enable( !m_locked->GetValue() || m_isFpEditor );
1006
1007 bool hasHole = true;
1008 bool hasConnection = true;
1009
1010 switch( m_padType->GetSelection() )
1011 {
1012 case PTH_DLG_TYPE: /* PTH */ hasHole = true; hasConnection = true; break;
1013 case SMD_DLG_TYPE: /* SMD */ hasHole = false; hasConnection = true; break;
1014 case CONN_DLG_TYPE: /* CONN */ hasHole = false; hasConnection = true; break;
1015 case NPTH_DLG_TYPE: /* NPTH */ hasHole = true; hasConnection = false; break;
1016 case APERTURE_DLG_TYPE: /* Aperture */ hasHole = false; hasConnection = false; break;
1017 }
1018
1019 // Enable/disable hole controls
1020 m_holeShapeLabel->Enable( hasHole );
1021 m_holeShapeCtrl->Enable( hasHole );
1022 m_holeX.Enable( hasHole );
1023 m_holeY.Enable( hasHole && m_holeShapeCtrl->GetSelection() == 1 );
1024
1025 // Enable/disable number and net
1026 m_padNumLabel->Enable( hasConnection );
1027 m_padNumCtrl->Enable( hasConnection );
1028
1029 if( m_padNetLabel->IsShown() )
1030 {
1031 m_padNetLabel->Enable( hasConnection && m_canEditNetName && m_currentPad );
1032 m_padNetSelector->Enable( hasConnection && m_canEditNetName && m_currentPad );
1033 }
1034
1035 // Enable/disable pad length-to-die
1036 m_padToDieOpt->Enable( hasConnection );
1037
1038 if( !m_padToDieOpt->IsEnabled() )
1039 m_padToDieOpt->SetValue( false );
1040
1041 // We can show/hide this here because it doesn't require the layout to be refreshed.
1042 // All the others have to be done in their event handlers because doing a layout here
1043 // causes infinite looping on MSW.
1044 m_padToDie.Show( m_padToDieOpt->GetValue() );
1045
1046 // Enable/disable Copper Layers control
1047 m_rbCopperLayersSel->Enable( m_padType->GetSelection() != APERTURE_DLG_TYPE );
1048
1049 LSET cu_set = m_dummyPad->GetLayerSet() & LSET::AllCuMask();
1050
1051 switch( m_padType->GetSelection() )
1052 {
1053 case PTH_DLG_TYPE:
1054 if( !cu_set.any() )
1055 m_stackupImagesBook->SetSelection( 3 );
1056 else if( !m_dummyPad->GetRemoveUnconnected() )
1057 m_stackupImagesBook->SetSelection( 0 );
1058 else if( m_dummyPad->GetKeepTopBottom() )
1059 m_stackupImagesBook->SetSelection( 1 );
1060 else
1061 m_stackupImagesBook->SetSelection( 2 );
1062
1063 break;
1064
1065 case NPTH_DLG_TYPE:
1066 if( cu_set.test( F_Cu ) && cu_set.test( B_Cu ) )
1067 m_stackupImagesBook->SetSelection( 4 );
1068 else if( cu_set.test( F_Cu ) )
1069 m_stackupImagesBook->SetSelection( 5 );
1070 else if( cu_set.test( B_Cu ) )
1071 m_stackupImagesBook->SetSelection( 6 );
1072 else
1073 m_stackupImagesBook->SetSelection( 7 );
1074
1075 break;
1076
1077 case SMD_DLG_TYPE:
1078 case CONN_DLG_TYPE:
1079 case APERTURE_DLG_TYPE:
1080 m_stackupImagesBook->ChangeSelection( 3 );
1081 break;
1082 }
1083 }
1084
1085
OnUpdateUINonCopperWarning(wxUpdateUIEvent & event)1086 void DIALOG_PAD_PROPERTIES::OnUpdateUINonCopperWarning( wxUpdateUIEvent& event )
1087 {
1088 bool isOnCopperLayer = ( m_dummyPad->GetLayerSet() & LSET::AllCuMask() ).any();
1089 m_nonCopperWarningBook->ChangeSelection( isOnCopperLayer ? 0 : 1 );
1090 }
1091
1092
updatePadLayersList(LSET layer_mask,bool remove_unconnected,bool keep_top_bottom)1093 void DIALOG_PAD_PROPERTIES::updatePadLayersList( LSET layer_mask, bool remove_unconnected,
1094 bool keep_top_bottom )
1095 {
1096 UpdateLayersDropdown();
1097
1098 switch( m_padType->GetSelection() )
1099 {
1100 case PTH_DLG_TYPE:
1101 if( !layer_mask.any() )
1102 layer_mask = PAD::PTHMask();
1103
1104 if( !( layer_mask & LSET::AllCuMask() ).any() )
1105 m_rbCopperLayersSel->SetSelection( 3 );
1106 else if( !remove_unconnected )
1107 m_rbCopperLayersSel->SetSelection( 0 );
1108 else if( keep_top_bottom )
1109 m_rbCopperLayersSel->SetSelection( 1 );
1110 else
1111 m_rbCopperLayersSel->SetSelection( 2 );
1112
1113 break;
1114
1115 case SMD_DLG_TYPE:
1116 if( !layer_mask.any() )
1117 layer_mask = PAD::SMDMask();
1118
1119 if( layer_mask.test( F_Cu ) )
1120 m_rbCopperLayersSel->SetSelection( 0 );
1121 else
1122 m_rbCopperLayersSel->SetSelection( 1 );
1123
1124 break;
1125
1126 case CONN_DLG_TYPE:
1127 if( !layer_mask.any() )
1128 layer_mask = PAD::ConnSMDMask();
1129
1130 if( layer_mask.test( F_Cu ) )
1131 m_rbCopperLayersSel->SetSelection( 0 );
1132 else
1133 m_rbCopperLayersSel->SetSelection( 1 );
1134
1135 break;
1136
1137 case NPTH_DLG_TYPE:
1138 if( !layer_mask.any() )
1139 layer_mask = PAD::UnplatedHoleMask();
1140
1141 if( layer_mask.test( F_Cu ) && layer_mask.test( B_Cu ) )
1142 m_rbCopperLayersSel->SetSelection( 0 );
1143 else if( layer_mask.test( F_Cu ) )
1144 m_rbCopperLayersSel->SetSelection( 1 );
1145 else if( layer_mask.test( B_Cu ) )
1146 m_rbCopperLayersSel->SetSelection( 2 );
1147 else
1148 m_rbCopperLayersSel->SetSelection( 3 );
1149
1150 break;
1151
1152 case APERTURE_DLG_TYPE:
1153 if( !layer_mask.any() )
1154 layer_mask = PAD::ApertureMask();
1155
1156 m_rbCopperLayersSel->SetSelection( 0 );
1157 break;
1158 }
1159
1160 m_PadLayerAdhCmp->SetValue( layer_mask[F_Adhes] );
1161 m_PadLayerAdhCu->SetValue( layer_mask[B_Adhes] );
1162
1163 m_PadLayerPateCmp->SetValue( layer_mask[F_Paste] );
1164 m_PadLayerPateCu->SetValue( layer_mask[B_Paste] );
1165
1166 m_PadLayerSilkCmp->SetValue( layer_mask[F_SilkS] );
1167 m_PadLayerSilkCu->SetValue( layer_mask[B_SilkS] );
1168
1169 m_PadLayerMaskCmp->SetValue( layer_mask[F_Mask] );
1170 m_PadLayerMaskCu->SetValue( layer_mask[B_Mask] );
1171
1172 m_PadLayerECO1->SetValue( layer_mask[Eco1_User] );
1173 m_PadLayerECO2->SetValue( layer_mask[Eco2_User] );
1174
1175 m_PadLayerDraft->SetValue( layer_mask[Dwgs_User] );
1176 }
1177
1178
Show(bool aShow)1179 bool DIALOG_PAD_PROPERTIES::Show( bool aShow )
1180 {
1181 bool retVal = DIALOG_SHIM::Show( aShow );
1182
1183 if( aShow )
1184 {
1185 // It *should* work to set the stackup bitmap in the constructor, but it doesn't.
1186 // wxWidgets needs to have these set when the panel is visible for some reason.
1187 // https://gitlab.com/kicad/code/kicad/-/issues/5534
1188 m_stackupImage0->SetBitmap( KiBitmap( BITMAPS::pads_reset_unused ) );
1189 m_stackupImage1->SetBitmap( KiBitmap( BITMAPS::pads_remove_unused_keep_bottom ) );
1190 m_stackupImage2->SetBitmap( KiBitmap( BITMAPS::pads_remove_unused ) );
1191 m_stackupImage4->SetBitmap( KiBitmap( BITMAPS::pads_npth_top_bottom ) );
1192 m_stackupImage5->SetBitmap( KiBitmap( BITMAPS::pads_npth_top ) );
1193 m_stackupImage6->SetBitmap( KiBitmap( BITMAPS::pads_npth_bottom ) );
1194 m_stackupImage7->SetBitmap( KiBitmap( BITMAPS::pads_npth ) );
1195
1196 Layout();
1197 }
1198
1199 return retVal;
1200 }
1201
1202
OnSetCopperLayers(wxCommandEvent & event)1203 void DIALOG_PAD_PROPERTIES::OnSetCopperLayers( wxCommandEvent& event )
1204 {
1205 transferDataToPad( m_dummyPad );
1206 redraw();
1207 }
1208
1209
OnSetLayers(wxCommandEvent & event)1210 void DIALOG_PAD_PROPERTIES::OnSetLayers( wxCommandEvent& event )
1211 {
1212 transferDataToPad( m_dummyPad );
1213 redraw();
1214 }
1215
1216
padValuesOK()1217 bool DIALOG_PAD_PROPERTIES::padValuesOK()
1218 {
1219 bool error = transferDataToPad( m_dummyPad );
1220
1221 wxArrayString error_msgs;
1222 wxArrayString warning_msgs;
1223 wxString msg;
1224 wxSize pad_size = m_dummyPad->GetSize();
1225 wxSize drill_size = m_dummyPad->GetDrillSize();
1226
1227 if( m_dummyPad->GetShape() == PAD_SHAPE::CUSTOM )
1228 {
1229 // allow 0-sized anchor pads
1230 }
1231 else if( m_dummyPad->GetShape() == PAD_SHAPE::CIRCLE )
1232 {
1233 if( pad_size.x <= 0 )
1234 warning_msgs.Add( _( "Warning: Pad size is less than zero." ) );
1235 }
1236 else
1237 {
1238 if( pad_size.x <= 0 || pad_size.y <= 0 )
1239 warning_msgs.Add( _( "Warning: Pad size is less than zero." ) );
1240 }
1241
1242 // Test hole size against pad size
1243 if( m_dummyPad->IsOnCopperLayer() )
1244 {
1245 LSET lset = m_dummyPad->GetLayerSet() & LSET::AllCuMask();
1246 PCB_LAYER_ID layer = lset.Seq().at( 0 );
1247 int maxError = m_board->GetDesignSettings().m_MaxError;
1248 SHAPE_POLY_SET padOutline;
1249
1250 m_dummyPad->TransformShapeWithClearanceToPolygon( padOutline, layer, 0, maxError,
1251 ERROR_LOC::ERROR_INSIDE );
1252
1253 const SHAPE_SEGMENT* drillShape = m_dummyPad->GetEffectiveHoleShape();
1254 const SEG drillSeg = drillShape->GetSeg();
1255 SHAPE_POLY_SET drillOutline;
1256
1257 TransformOvalToPolygon( drillOutline, (wxPoint) drillSeg.A, (wxPoint) drillSeg.B,
1258 drillShape->GetWidth(), maxError, ERROR_LOC::ERROR_INSIDE );
1259
1260 drillOutline.BooleanSubtract( padOutline, SHAPE_POLY_SET::POLYGON_MODE::PM_FAST );
1261
1262 if( drillOutline.BBox().GetWidth() > 0 || drillOutline.BBox().GetHeight() > 0 )
1263 {
1264 warning_msgs.Add( _( "Warning: Pad drill will leave no copper or drill shape and "
1265 "pad shape do not overlap." ) );
1266 }
1267 }
1268
1269 if( m_dummyPad->GetLocalClearance() < 0 )
1270 warning_msgs.Add( _( "Warning: Negative local clearance values will have no effect." ) );
1271
1272 // Some pads need a negative solder mask clearance (mainly for BGA with small pads)
1273 // However the negative solder mask clearance must not create negative mask size
1274 // Therefore test for minimal acceptable negative value
1275 if( m_dummyPad->GetLocalSolderMaskMargin() < 0 )
1276 {
1277 int absMargin = abs( m_dummyPad->GetLocalSolderMaskMargin() );
1278
1279 if( m_dummyPad->GetShape() == PAD_SHAPE::CUSTOM )
1280 {
1281 for( const std::shared_ptr<PCB_SHAPE>& shape : m_dummyPad->GetPrimitives() )
1282 {
1283 EDA_RECT shapeBBox = shape->GetBoundingBox();
1284
1285 if( absMargin > shapeBBox.GetWidth() || absMargin > shapeBBox.GetHeight() )
1286 {
1287 warning_msgs.Add( _( "Warning: Negative solder mask clearances larger than "
1288 "some shape primitives. Results may be surprising." ) );
1289
1290 break;
1291 }
1292 }
1293 }
1294 else if( absMargin > pad_size.x || absMargin > pad_size.y )
1295 {
1296 warning_msgs.Add( _( "Warning: Negative solder mask clearance larger than pad. No "
1297 "solder mask will be generated." ) );
1298 }
1299 }
1300
1301 // Some pads need a positive solder paste clearance (mainly for BGA with small pads)
1302 // However, a positive value can create issues if the resulting shape is too big.
1303 // (like a solder paste creating a solder paste area on a neighbor pad or on the solder mask)
1304 // So we could ask for user to confirm the choice
1305 // For now we just check for disappearing paste
1306 wxSize paste_size;
1307 int paste_margin = m_dummyPad->GetLocalSolderPasteMargin();
1308 double paste_ratio = m_dummyPad->GetLocalSolderPasteMarginRatio();
1309
1310 paste_size.x = pad_size.x + paste_margin + KiROUND( pad_size.x * paste_ratio );
1311 paste_size.y = pad_size.y + paste_margin + KiROUND( pad_size.y * paste_ratio );
1312
1313 if( paste_size.x <= 0 || paste_size.y <= 0 )
1314 {
1315 warning_msgs.Add( _( "Warning: Negative solder paste margins larger than pad. No solder "
1316 "paste mask will be generated." ) );
1317 }
1318
1319 LSET padlayers_mask = m_dummyPad->GetLayerSet();
1320
1321 if( padlayers_mask == 0 )
1322 error_msgs.Add( _( "Error: pad has no layer." ) );
1323
1324 if( !padlayers_mask[F_Cu] && !padlayers_mask[B_Cu] )
1325 {
1326 if( ( drill_size.x || drill_size.y ) && m_dummyPad->GetAttribute() != PAD_ATTRIB::NPTH )
1327 {
1328 warning_msgs.Add( _( "Warning: Plated through holes should normally have a copper pad "
1329 "on at least one layer." ) );
1330 }
1331 }
1332
1333 if( error )
1334 error_msgs.Add( _( "Too large value for pad delta size." ) );
1335
1336 switch( m_dummyPad->GetAttribute() )
1337 {
1338 case PAD_ATTRIB::NPTH: // Not plated, but through hole, a hole is expected
1339 case PAD_ATTRIB::PTH: // Pad through hole, a hole is also expected
1340 if( drill_size.x <= 0
1341 || ( drill_size.y <= 0 && m_dummyPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ) )
1342 {
1343 warning_msgs.Add( _( "Warning: Through hole pad has no hole." ) );
1344 }
1345 break;
1346
1347 case PAD_ATTRIB::CONN: // Connector pads are smd pads, just they do not have solder paste.
1348 if( padlayers_mask[B_Paste] || padlayers_mask[F_Paste] )
1349 {
1350 warning_msgs.Add( _( "Warning: Connector pads normally have no solder paste. Use an "
1351 "SMD pad instead." ) );
1352 }
1353 KI_FALLTHROUGH;
1354
1355 case PAD_ATTRIB::SMD: // SMD and Connector pads (One external copper layer only)
1356 {
1357 LSET innerlayers_mask = padlayers_mask & LSET::InternalCuMask();
1358
1359 if( ( padlayers_mask[F_Cu] && padlayers_mask[B_Cu] ) || innerlayers_mask.count() != 0 )
1360 warning_msgs.Add( _( "Warning: SMD pad has no outer layers." ) );
1361 }
1362 break;
1363 }
1364
1365 if( ( m_dummyPad->GetProperty() == PAD_PROP::FIDUCIAL_GLBL ||
1366 m_dummyPad->GetProperty() == PAD_PROP::FIDUCIAL_LOCAL ) &&
1367 m_dummyPad->GetAttribute() == PAD_ATTRIB::NPTH )
1368 {
1369 warning_msgs.Add( _( "Warning: Fiducial property makes no sense on NPTH pads." ) );
1370 }
1371
1372 if( m_dummyPad->GetProperty() == PAD_PROP::TESTPOINT &&
1373 m_dummyPad->GetAttribute() == PAD_ATTRIB::NPTH )
1374 {
1375 warning_msgs.Add( _( "Warning: Testpoint property makes no sense on NPTH pads." ) );
1376 }
1377
1378 if( m_dummyPad->GetProperty() == PAD_PROP::HEATSINK &&
1379 m_dummyPad->GetAttribute() == PAD_ATTRIB::NPTH )
1380 {
1381 warning_msgs.Add( _( "Warning: Heatsink property makes no sense of NPTH pads." ) );
1382 }
1383
1384 if( m_dummyPad->GetProperty() == PAD_PROP::CASTELLATED &&
1385 m_dummyPad->GetAttribute() != PAD_ATTRIB::PTH )
1386 {
1387 warning_msgs.Add( _( "Warning: Castellated property is for PTH pads." ) );
1388 }
1389
1390 if( m_dummyPad->GetProperty() == PAD_PROP::BGA &&
1391 m_dummyPad->GetAttribute() != PAD_ATTRIB::SMD )
1392 {
1393 warning_msgs.Add( _( "Warning: BGA property is for SMD pads." ) );
1394 }
1395
1396 if( m_dummyPad->GetShape() == PAD_SHAPE::ROUNDRECT ||
1397 m_dummyPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT )
1398 {
1399 wxASSERT( m_cornerRatio.GetValue() == m_mixedCornerRatio.GetValue() );
1400
1401 if( m_cornerRatio.GetDoubleValue() < 0.0 )
1402 error_msgs.Add( _( "Error: Negative corner size." ) );
1403 else if( m_cornerRatio.GetDoubleValue() > 50.0 )
1404 warning_msgs.Add( _( "Warning: Corner size will make pad circular." ) );
1405 }
1406
1407 // PADSTACKS TODO: this will need to check each layer in the pad...
1408 if( m_dummyPad->GetShape() == PAD_SHAPE::CUSTOM )
1409 {
1410 SHAPE_POLY_SET mergedPolygon;
1411 m_dummyPad->MergePrimitivesAsPolygon( &mergedPolygon );
1412
1413 if( mergedPolygon.OutlineCount() > 1 )
1414 error_msgs.Add( _( "Error: Custom pad shape must resolve to a single polygon." ) );
1415 }
1416
1417
1418 if( error_msgs.GetCount() || warning_msgs.GetCount() )
1419 {
1420 wxString title = error_msgs.GetCount() ? _( "Pad Properties Errors" )
1421 : _( "Pad Properties Warnings" );
1422 HTML_MESSAGE_BOX dlg( this, title );
1423
1424 dlg.ListSet( error_msgs );
1425
1426 if( warning_msgs.GetCount() )
1427 dlg.ListSet( warning_msgs );
1428
1429 dlg.ShowModal();
1430 }
1431
1432 return error_msgs.GetCount() == 0;
1433 }
1434
1435
redraw()1436 void DIALOG_PAD_PROPERTIES::redraw()
1437 {
1438 if( !m_canUpdate )
1439 return;
1440
1441 KIGFX::VIEW* view = m_padPreviewGAL->GetView();
1442 m_padPreviewGAL->StopDrawing();
1443
1444 // The layer used to place primitive items selected when editing custom pad shapes
1445 // we use here a layer never used in a pad:
1446 #define SELECTED_ITEMS_LAYER Dwgs_User
1447
1448 view->SetTopLayer( SELECTED_ITEMS_LAYER );
1449 KIGFX::PCB_RENDER_SETTINGS* settings =
1450 static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
1451 settings->SetLayerColor( SELECTED_ITEMS_LAYER, m_selectedColor );
1452
1453 view->Update( m_dummyPad );
1454
1455 // delete previous items if highlight list
1456 while( m_highlight.size() )
1457 {
1458 delete m_highlight.back(); // the dtor also removes item from view
1459 m_highlight.pop_back();
1460 }
1461
1462 // highlight selected primitives:
1463 long select = m_listCtrlPrimitives->GetFirstSelected();
1464
1465 while( select >= 0 )
1466 {
1467 PCB_SHAPE* dummyShape = (PCB_SHAPE*) m_primitives[select]->Clone();
1468 dummyShape->SetLayer( SELECTED_ITEMS_LAYER );
1469 dummyShape->Rotate( wxPoint( 0, 0), m_dummyPad->GetOrientation() );
1470 dummyShape->Move( m_dummyPad->GetPosition() );
1471
1472 view->Add( dummyShape );
1473 m_highlight.push_back( dummyShape );
1474
1475 select = m_listCtrlPrimitives->GetNextSelected( select );
1476 }
1477
1478 BOX2I bbox = m_dummyPad->ViewBBox();
1479
1480 if( bbox.GetSize().x > 0 && bbox.GetSize().y > 0 )
1481 {
1482 // The origin always goes in the middle of the canvas; we want offsetting the pad
1483 // shape to move the pad, not the hole
1484 bbox.Move( -m_dummyPad->GetPosition() );
1485 int maxXExtent = std::max( abs( bbox.GetLeft() ), abs( bbox.GetRight() ) );
1486 int maxYExtent = std::max( abs( bbox.GetTop() ), abs( bbox.GetBottom() ) );
1487
1488 // Don't blow up the GAL on too-large numbers
1489 if( maxXExtent > INT_MAX / 4 )
1490 maxXExtent = INT_MAX / 4;
1491
1492 if( maxYExtent > INT_MAX / 4 )
1493 maxYExtent = INT_MAX / 4;
1494
1495 BOX2D viewBox( m_dummyPad->GetPosition(), {0, 0} );
1496 BOX2D canvasBox( m_dummyPad->GetPosition(), {0, 0} );
1497 viewBox.Inflate( maxXExtent * 1.4, maxYExtent * 1.4 ); // add a margin
1498 canvasBox.Inflate( maxXExtent * 2.0, maxYExtent * 2.0 );
1499
1500 view->SetBoundary( canvasBox );
1501
1502 // Autozoom
1503 view->SetViewport( viewBox );
1504
1505 m_padPreviewGAL->StartDrawing();
1506 m_padPreviewGAL->Refresh();
1507 }
1508 }
1509
1510
TransferDataToWindow()1511 bool DIALOG_PAD_PROPERTIES::TransferDataToWindow()
1512 {
1513 if( !wxDialog::TransferDataToWindow() )
1514 return false;
1515
1516 if( !m_panelGeneral->TransferDataToWindow() )
1517 return false;
1518
1519 if( !m_localSettingsPanel->TransferDataToWindow() )
1520 return false;
1521
1522 return true;
1523 }
1524
1525
TransferDataFromWindow()1526 bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow()
1527 {
1528 BOARD_COMMIT commit( m_parent );
1529
1530 if( !wxDialog::TransferDataFromWindow() )
1531 return false;
1532
1533 if( !m_panelGeneral->TransferDataFromWindow() )
1534 return false;
1535
1536 if( !m_localSettingsPanel->TransferDataFromWindow() )
1537 return false;
1538
1539 if( !padValuesOK() )
1540 return false;
1541
1542 transferDataToPad( m_padMaster );
1543
1544 PAD_TOOL* padTool = m_parent->GetToolManager()->GetTool<PAD_TOOL>();
1545 padTool->SetLastPadNumber( m_padMaster->GetNumber() );
1546
1547 // m_padMaster is a pattern: ensure there is no net for this pad:
1548 m_padMaster->SetNetCode( NETINFO_LIST::UNCONNECTED );
1549
1550 if( !m_currentPad ) // Set current Pad parameters
1551 return true;
1552
1553 commit.Modify( m_currentPad );
1554
1555 // redraw the area where the pad was, without pad (delete pad on screen)
1556 m_currentPad->SetFlags( DO_NOT_DRAW );
1557 m_parent->GetCanvas()->Refresh();
1558 m_currentPad->ClearFlags( DO_NOT_DRAW );
1559
1560 // Update values
1561 m_currentPad->SetShape( m_padMaster->GetShape() );
1562 m_currentPad->SetAttribute( m_padMaster->GetAttribute() );
1563 m_currentPad->SetOrientation( m_padMaster->GetOrientation() );
1564
1565 m_currentPad->SetLocked( m_locked->GetValue() );
1566
1567 if( !m_locked->GetValue() || m_isFpEditor )
1568 m_currentPad->SetPosition( m_padMaster->GetPosition() );
1569
1570 wxSize size;
1571 FOOTPRINT* footprint = m_currentPad->GetParent();
1572
1573 m_currentPad->SetSize( m_padMaster->GetSize() );
1574
1575 size = m_padMaster->GetDelta();
1576 m_currentPad->SetDelta( size );
1577
1578 m_currentPad->SetDrillSize( m_padMaster->GetDrillSize() );
1579 m_currentPad->SetDrillShape( m_padMaster->GetDrillShape() );
1580
1581 wxPoint offset = m_padMaster->GetOffset();
1582 m_currentPad->SetOffset( offset );
1583
1584 m_currentPad->SetPadToDieLength( m_padMaster->GetPadToDieLength() );
1585
1586 if( m_padMaster->GetShape() != PAD_SHAPE::CUSTOM )
1587 m_padMaster->DeletePrimitivesList();
1588
1589 m_currentPad->SetAnchorPadShape( m_padMaster->GetAnchorPadShape() );
1590 m_currentPad->ReplacePrimitives( m_padMaster->GetPrimitives() );
1591
1592 m_currentPad->SetLayerSet( m_padMaster->GetLayerSet() );
1593 m_currentPad->SetRemoveUnconnected( m_padMaster->GetRemoveUnconnected() );
1594 m_currentPad->SetKeepTopBottom( m_padMaster->GetKeepTopBottom() );
1595
1596 m_currentPad->SetNumber( m_padMaster->GetNumber() );
1597
1598 int padNetcode = NETINFO_LIST::UNCONNECTED;
1599
1600 // For PAD_ATTRIB::NPTH, ensure there is no net name selected
1601 if( m_padMaster->GetAttribute() != PAD_ATTRIB::NPTH )
1602 padNetcode = m_padNetSelector->GetSelectedNetcode();
1603
1604 m_currentPad->SetNetCode( padNetcode );
1605 m_currentPad->SetLocalClearance( m_padMaster->GetLocalClearance() );
1606 m_currentPad->SetLocalSolderMaskMargin( m_padMaster->GetLocalSolderMaskMargin() );
1607 m_currentPad->SetLocalSolderPasteMargin( m_padMaster->GetLocalSolderPasteMargin() );
1608 m_currentPad->SetLocalSolderPasteMarginRatio( m_padMaster->GetLocalSolderPasteMarginRatio() );
1609 m_currentPad->SetThermalSpokeWidth( m_padMaster->GetThermalSpokeWidth() );
1610 m_currentPad->SetThermalGap( m_padMaster->GetThermalGap() );
1611 m_currentPad->SetRoundRectRadiusRatio( m_padMaster->GetRoundRectRadiusRatio() );
1612 m_currentPad->SetChamferRectRatio( m_padMaster->GetChamferRectRatio() );
1613 m_currentPad->SetChamferPositions( m_padMaster->GetChamferPositions() );
1614 m_currentPad->SetZoneConnection( m_padMaster->GetZoneConnection() );
1615
1616 // rounded rect pads with radius ratio = 0 are in fact rect pads.
1617 // So set the right shape (and perhaps issues with a radius = 0)
1618 if( m_currentPad->GetShape() == PAD_SHAPE::ROUNDRECT &&
1619 m_currentPad->GetRoundRectRadiusRatio() == 0.0 )
1620 {
1621 m_currentPad->SetShape( PAD_SHAPE::RECT );
1622 }
1623
1624 // Set the fabrication property:
1625 m_currentPad->SetProperty( getSelectedProperty() );
1626
1627 // define the way the clearance area is defined in zones
1628 m_currentPad->SetCustomShapeInZoneOpt( m_padMaster->GetCustomShapeInZoneOpt() );
1629
1630 if( m_isFlipped )
1631 {
1632 // flip pad (up/down) around its position
1633 m_currentPad->Flip( m_currentPad->GetPosition(), false );
1634 }
1635
1636 if( footprint )
1637 {
1638 footprint->SetLastEditTime();
1639
1640 // compute the pos 0 value, i.e. pad position for footprint with orientation = 0
1641 // i.e. relative to footprint origin (footprint position)
1642 wxPoint pt = m_currentPad->GetPosition() - footprint->GetPosition();
1643 RotatePoint( &pt, -footprint->GetOrientation() );
1644 m_currentPad->SetPos0( pt );
1645 m_currentPad->SetOrientation( m_currentPad->GetOrientation() +
1646 footprint->GetOrientation() );
1647 }
1648
1649 m_parent->SetMsgPanel( m_currentPad );
1650
1651 // redraw the area where the pad was
1652 m_parent->GetCanvas()->Refresh();
1653
1654 commit.Push( _( "Modify pad" ) );
1655
1656 return true;
1657 }
1658
1659
getSelectedProperty()1660 PAD_PROP DIALOG_PAD_PROPERTIES::getSelectedProperty()
1661 {
1662 PAD_PROP prop = PAD_PROP::NONE;
1663
1664 switch( m_choiceFabProperty->GetSelection() )
1665 {
1666 case 0: prop = PAD_PROP::NONE; break;
1667 case 1: prop = PAD_PROP::BGA; break;
1668 case 2: prop = PAD_PROP::FIDUCIAL_LOCAL; break;
1669 case 3: prop = PAD_PROP::FIDUCIAL_GLBL; break;
1670 case 4: prop = PAD_PROP::TESTPOINT; break;
1671 case 5: prop = PAD_PROP::HEATSINK; break;
1672 case 6: prop = PAD_PROP::CASTELLATED; break;
1673 }
1674
1675 return prop;
1676 }
1677
1678
transferDataToPad(PAD * aPad)1679 bool DIALOG_PAD_PROPERTIES::transferDataToPad( PAD* aPad )
1680 {
1681 wxString msg;
1682
1683 if( !Validate() )
1684 return true;
1685 if( !m_panelGeneral->Validate() )
1686 return true;
1687 if( !m_localSettingsPanel->Validate() )
1688 return true;
1689 if( !m_spokeWidth.Validate( 0, INT_MAX ) )
1690 return false;
1691
1692 aPad->SetAttribute( code_type[m_padType->GetSelection()] );
1693 aPad->SetShape( code_shape[m_PadShapeSelector->GetSelection()] );
1694
1695 if( m_PadShapeSelector->GetSelection() == CHOICE_SHAPE_CUSTOM_RECT_ANCHOR )
1696 aPad->SetAnchorPadShape( PAD_SHAPE::RECT );
1697 else
1698 aPad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
1699
1700 if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
1701 aPad->ReplacePrimitives( m_primitives );
1702
1703 // Read pad clearances values:
1704 aPad->SetLocalClearance( m_clearance.GetValue() );
1705 aPad->SetLocalSolderMaskMargin( m_maskMargin.GetValue() );
1706 aPad->SetLocalSolderPasteMargin( m_pasteMargin.GetValue() );
1707 aPad->SetLocalSolderPasteMarginRatio( m_pasteMarginRatio.GetDoubleValue() / 100.0 );
1708 aPad->SetThermalSpokeWidth( m_spokeWidth.GetValue() );
1709 aPad->SetThermalGap( m_thermalGap.GetValue() );
1710
1711 // And rotation
1712 aPad->SetOrientation( m_pad_orientation.GetDoubleValue() );
1713
1714 switch( m_ZoneConnectionChoice->GetSelection() )
1715 {
1716 default:
1717 case 0: aPad->SetZoneConnection( ZONE_CONNECTION::INHERITED ); break;
1718 case 1: aPad->SetZoneConnection( ZONE_CONNECTION::FULL ); break;
1719 case 2: aPad->SetZoneConnection( ZONE_CONNECTION::THERMAL ); break;
1720 case 3: aPad->SetZoneConnection( ZONE_CONNECTION::NONE ); break;
1721 }
1722
1723 aPad->SetPosition( wxPoint( m_posX.GetValue(), m_posY.GetValue() ) );
1724
1725 if( m_holeShapeCtrl->GetSelection() == 0 )
1726 {
1727 aPad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
1728 aPad->SetDrillSize( wxSize( m_holeX.GetValue(), m_holeX.GetValue() ) );
1729 }
1730 else
1731 {
1732 aPad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
1733 aPad->SetDrillSize( wxSize( m_holeX.GetValue(), m_holeY.GetValue() ) );
1734 }
1735
1736 if( aPad->GetShape() == PAD_SHAPE::CIRCLE )
1737 aPad->SetSize( wxSize( m_sizeX.GetValue(), m_sizeX.GetValue() ) );
1738 else
1739 aPad->SetSize( wxSize( m_sizeX.GetValue(), m_sizeY.GetValue() ) );
1740
1741 // For a trapezoid, test delta value (be sure delta is not too large for pad size)
1742 // remember DeltaSize.x is the Y size variation
1743 bool error = false;
1744 wxSize delta( 0, 0 );
1745
1746 if( aPad->GetShape() == PAD_SHAPE::TRAPEZOID )
1747 {
1748 // For a trapezoid, only one of delta.x or delta.y is not 0, depending on axis.
1749 if( m_trapAxisCtrl->GetSelection() == 0 )
1750 delta.x = m_trapDelta.GetValue();
1751 else
1752 delta.y = m_trapDelta.GetValue();
1753
1754 if( delta.x < 0 && delta.x <= -aPad->GetSize().y )
1755 {
1756 delta.x = -aPad->GetSize().y + 2;
1757 error = true;
1758 }
1759
1760 if( delta.x > 0 && delta.x >= aPad->GetSize().y )
1761 {
1762 delta.x = aPad->GetSize().y - 2;
1763 error = true;
1764 }
1765
1766 if( delta.y < 0 && delta.y <= -aPad->GetSize().x )
1767 {
1768 delta.y = -aPad->GetSize().x + 2;
1769 error = true;
1770 }
1771
1772 if( delta.y > 0 && delta.y >= aPad->GetSize().x )
1773 {
1774 delta.y = aPad->GetSize().x - 2;
1775 error = true;
1776 }
1777 }
1778
1779 aPad->SetDelta( delta );
1780
1781 if( m_offsetShapeOpt->GetValue() )
1782 aPad->SetOffset( wxPoint( m_offsetX.GetValue(), m_offsetY.GetValue() ) );
1783 else
1784 aPad->SetOffset( wxPoint() );
1785
1786 // Read pad length die
1787 if( m_padToDieOpt->GetValue() )
1788 aPad->SetPadToDieLength( m_padToDie.GetValue() );
1789 else
1790 aPad->SetPadToDieLength( 0 );
1791
1792 aPad->SetNumber( m_padNumCtrl->GetValue() );
1793 aPad->SetNetCode( m_padNetSelector->GetSelectedNetcode() );
1794
1795 int chamfers = 0;
1796
1797 if( m_PadShapeSelector->GetSelection() == CHOICE_SHAPE_CHAMFERED_RECT )
1798 {
1799 if( m_cbTopLeft->GetValue() )
1800 chamfers |= RECT_CHAMFER_TOP_LEFT;
1801
1802 if( m_cbTopRight->GetValue() )
1803 chamfers |= RECT_CHAMFER_TOP_RIGHT;
1804
1805 if( m_cbBottomLeft->GetValue() )
1806 chamfers |= RECT_CHAMFER_BOTTOM_LEFT;
1807
1808 if( m_cbBottomRight->GetValue() )
1809 chamfers |= RECT_CHAMFER_BOTTOM_RIGHT;
1810 }
1811 else if( m_PadShapeSelector->GetSelection() == CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT )
1812 {
1813 if( m_cbTopLeft1->GetValue() )
1814 chamfers |= RECT_CHAMFER_TOP_LEFT;
1815
1816 if( m_cbTopRight1->GetValue() )
1817 chamfers |= RECT_CHAMFER_TOP_RIGHT;
1818
1819 if( m_cbBottomLeft1->GetValue() )
1820 chamfers |= RECT_CHAMFER_BOTTOM_LEFT;
1821
1822 if( m_cbBottomRight1->GetValue() )
1823 chamfers |= RECT_CHAMFER_BOTTOM_RIGHT;
1824 }
1825 aPad->SetChamferPositions( chamfers );
1826
1827 if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
1828 {
1829 // The pad custom has a "anchor pad" (a basic shape: round or rect pad)
1830 // that is the minimal area of this pad, and is useful to ensure a hole
1831 // diameter is acceptable, and is used in Gerber files as flashed area
1832 // reference
1833 if( aPad->GetAnchorPadShape() == PAD_SHAPE::CIRCLE )
1834 aPad->SetSize( wxSize( m_sizeX.GetValue(), m_sizeX.GetValue() ) );
1835
1836 // define the way the clearance area is defined in zones
1837 aPad->SetCustomShapeInZoneOpt( m_ZoneCustomPadShape->GetSelection() == 0 ?
1838 CUST_PAD_SHAPE_IN_ZONE_OUTLINE :
1839 CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL );
1840 }
1841
1842 switch( aPad->GetAttribute() )
1843 {
1844 case PAD_ATTRIB::PTH:
1845 break;
1846
1847 case PAD_ATTRIB::CONN:
1848 case PAD_ATTRIB::SMD:
1849 // SMD and PAD_ATTRIB::CONN has no hole.
1850 // basically, SMD and PAD_ATTRIB::CONN are same type of pads
1851 // PAD_ATTRIB::CONN has just a default non technical layers that differs from SMD
1852 // and are intended to be used in virtual edge board connectors
1853 // However we can accept a non null offset,
1854 // mainly to allow complex pads build from a set of basic pad shapes
1855 aPad->SetDrillSize( wxSize( 0, 0 ) );
1856 break;
1857
1858 case PAD_ATTRIB::NPTH:
1859 // Mechanical purpose only:
1860 // no net name, no pad name allowed
1861 aPad->SetNumber( wxEmptyString );
1862 aPad->SetNetCode( NETINFO_LIST::UNCONNECTED );
1863 break;
1864
1865 default:
1866 wxFAIL_MSG( "DIALOG_PAD_PROPERTIES::transferDataToPad: unknown pad type" );
1867 break;
1868 }
1869
1870 if( aPad->GetShape() == PAD_SHAPE::ROUNDRECT )
1871 {
1872 aPad->SetRoundRectRadiusRatio( m_cornerRatio.GetDoubleValue() / 100.0 );
1873 }
1874 else if( aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT )
1875 {
1876 if( m_PadShapeSelector->GetSelection() == CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT )
1877 {
1878 aPad->SetChamferRectRatio( m_mixedChamferRatio.GetDoubleValue() / 100.0 );
1879 aPad->SetRoundRectRadiusRatio( m_mixedCornerRatio.GetDoubleValue() / 100.0 );
1880 }
1881 else // Choice is CHOICE_SHAPE_CHAMFERED_RECT, no rounded corner
1882 {
1883 aPad->SetChamferRectRatio( m_chamferRatio.GetDoubleValue() / 100.0 );
1884 aPad->SetRoundRectRadiusRatio( 0 );
1885 }
1886 }
1887
1888 aPad->SetProperty( getSelectedProperty() );
1889
1890 LSET padLayerMask = LSET();
1891 int copperLayersChoice = m_rbCopperLayersSel->GetSelection();
1892
1893 aPad->SetRemoveUnconnected( false );
1894 aPad->SetKeepTopBottom( false );
1895
1896 switch( m_padType->GetSelection() )
1897 {
1898 case PTH_DLG_TYPE:
1899 switch( copperLayersChoice )
1900 {
1901 case 0:
1902 // All copper layers
1903 padLayerMask |= LSET::AllCuMask();
1904 break;
1905
1906 case 1:
1907 // Front, back and connected
1908 padLayerMask |= LSET::AllCuMask();
1909 aPad->SetRemoveUnconnected( true );
1910 aPad->SetKeepTopBottom( true );
1911 break;
1912
1913 case 2:
1914 // Connected only
1915 padLayerMask |= LSET::AllCuMask();
1916 aPad->SetRemoveUnconnected( true );
1917 break;
1918
1919 case 3:
1920 // No copper layers
1921 break;
1922 }
1923
1924 break;
1925
1926 case NPTH_DLG_TYPE:
1927 switch( copperLayersChoice )
1928 {
1929 case 0: padLayerMask.set( F_Cu ).set( B_Cu ); break;
1930 case 1: padLayerMask.set( F_Cu ); break;
1931 case 2: padLayerMask.set( B_Cu ); break;
1932 default: break;
1933 }
1934
1935 break;
1936
1937 case SMD_DLG_TYPE:
1938 case CONN_DLG_TYPE:
1939 switch( copperLayersChoice )
1940 {
1941 case 0: padLayerMask.set( F_Cu ); break;
1942 case 1: padLayerMask.set( B_Cu ); break;
1943 }
1944
1945 break;
1946
1947 case APERTURE_DLG_TYPE:
1948 // no copper layers
1949 break;
1950 }
1951
1952 if( m_PadLayerAdhCmp->GetValue() )
1953 padLayerMask.set( F_Adhes );
1954
1955 if( m_PadLayerAdhCu->GetValue() )
1956 padLayerMask.set( B_Adhes );
1957
1958 if( m_PadLayerPateCmp->GetValue() )
1959 padLayerMask.set( F_Paste );
1960
1961 if( m_PadLayerPateCu->GetValue() )
1962 padLayerMask.set( B_Paste );
1963
1964 if( m_PadLayerSilkCmp->GetValue() )
1965 padLayerMask.set( F_SilkS );
1966
1967 if( m_PadLayerSilkCu->GetValue() )
1968 padLayerMask.set( B_SilkS );
1969
1970 if( m_PadLayerMaskCmp->GetValue() )
1971 padLayerMask.set( F_Mask );
1972
1973 if( m_PadLayerMaskCu->GetValue() )
1974 padLayerMask.set( B_Mask );
1975
1976 if( m_PadLayerECO1->GetValue() )
1977 padLayerMask.set( Eco1_User );
1978
1979 if( m_PadLayerECO2->GetValue() )
1980 padLayerMask.set( Eco2_User );
1981
1982 if( m_PadLayerDraft->GetValue() )
1983 padLayerMask.set( Dwgs_User );
1984
1985 aPad->SetLayerSet( padLayerMask );
1986
1987 return error;
1988 }
1989
1990
OnOffsetCheckbox(wxCommandEvent & event)1991 void DIALOG_PAD_PROPERTIES::OnOffsetCheckbox( wxCommandEvent& event )
1992 {
1993 if( m_offsetShapeOpt->GetValue() )
1994 {
1995 m_offsetX.SetValue( m_dummyPad->GetOffset().x );
1996 m_offsetY.SetValue( m_dummyPad->GetOffset().y );
1997 }
1998
1999 // Show/hide controls depending on m_offsetShapeOpt being enabled
2000 m_offsetCtrls->Show( m_offsetShapeOpt->GetValue() );
2001 m_offsetShapeOptLabel->Show( m_offsetShapeOpt->GetValue() );
2002
2003 for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
2004 m_notebook->GetPage( i )->Layout();
2005
2006 OnValuesChanged( event );
2007 }
2008
2009
OnPadToDieCheckbox(wxCommandEvent & event)2010 void DIALOG_PAD_PROPERTIES::OnPadToDieCheckbox( wxCommandEvent& event )
2011 {
2012 if( m_padToDieOpt->GetValue() && m_currentPad )
2013 m_padToDie.SetValue( m_currentPad->GetPadToDieLength() );
2014
2015 OnValuesChanged( event );
2016 }
2017
2018
OnValuesChanged(wxCommandEvent & event)2019 void DIALOG_PAD_PROPERTIES::OnValuesChanged( wxCommandEvent& event )
2020 {
2021 if( m_canUpdate )
2022 {
2023 transferDataToPad( m_dummyPad );
2024
2025 // If the pad size has changed, update the displayed values for rounded rect pads.
2026 updateRoundRectCornerValues();
2027
2028 redraw();
2029 }
2030 }
2031
editPrimitive()2032 void DIALOG_PAD_PROPERTIES::editPrimitive()
2033 {
2034 long select = m_listCtrlPrimitives->GetFirstSelected();
2035
2036 if( select < 0 )
2037 {
2038 wxMessageBox( _( "No shape selected" ) );
2039 return;
2040 }
2041
2042 std::shared_ptr<PCB_SHAPE>& shape = m_primitives[select];
2043
2044 if( shape->GetShape() == SHAPE_T::POLY )
2045 {
2046 DIALOG_PAD_PRIMITIVE_POLY_PROPS dlg( this, m_parent, shape.get() );
2047
2048 if( dlg.ShowModal() != wxID_OK )
2049 return;
2050
2051 dlg.TransferDataFromWindow();
2052 }
2053
2054 else
2055 {
2056 DIALOG_PAD_PRIMITIVES_PROPERTIES dlg( this, m_parent, shape.get() );
2057
2058 if( dlg.ShowModal() != wxID_OK )
2059 return;
2060
2061 dlg.TransferDataFromWindow();
2062 }
2063
2064 displayPrimitivesList();
2065
2066 if( m_canUpdate )
2067 {
2068 transferDataToPad( m_dummyPad );
2069 redraw();
2070 }
2071 }
2072
2073
OnPrimitiveSelection(wxListEvent & event)2074 void DIALOG_PAD_PROPERTIES::OnPrimitiveSelection( wxListEvent& event )
2075 {
2076 // Called on a double click on the basic shapes list
2077 // To Do: highligth the primitive(s) currently selected.
2078 redraw();
2079 }
2080
2081
onPrimitiveDClick(wxMouseEvent & event)2082 void DIALOG_PAD_PROPERTIES::onPrimitiveDClick( wxMouseEvent& event )
2083 {
2084 editPrimitive();
2085 }
2086
2087
onEditPrimitive(wxCommandEvent & event)2088 void DIALOG_PAD_PROPERTIES::onEditPrimitive( wxCommandEvent& event )
2089 {
2090 editPrimitive();
2091 }
2092
2093
onDeletePrimitive(wxCommandEvent & event)2094 void DIALOG_PAD_PROPERTIES::onDeletePrimitive( wxCommandEvent& event )
2095 {
2096 long select = m_listCtrlPrimitives->GetFirstSelected();
2097
2098 if( select < 0 )
2099 return;
2100
2101 // Multiple selections are allowed. get them and remove corresponding shapes
2102 std::vector<long> indexes;
2103 indexes.push_back( select );
2104
2105 while( ( select = m_listCtrlPrimitives->GetNextSelected( select ) ) >= 0 )
2106 indexes.push_back( select );
2107
2108 // Erase all select shapes
2109 for( unsigned ii = indexes.size(); ii > 0; --ii )
2110 m_primitives.erase( m_primitives.begin() + indexes[ii-1] );
2111
2112 displayPrimitivesList();
2113
2114 if( m_canUpdate )
2115 {
2116 transferDataToPad( m_dummyPad );
2117 redraw();
2118 }
2119 }
2120
2121
onAddPrimitive(wxCommandEvent & event)2122 void DIALOG_PAD_PROPERTIES::onAddPrimitive( wxCommandEvent& event )
2123 {
2124 // Ask user for shape type
2125 wxString shapelist[] = {
2126 _( "Segment" ),
2127 _( "Arc" ),
2128 _( "Bezier" ),
2129 _( "Ring/Circle" ),
2130 _( "Polygon" )
2131 };
2132
2133 int type = wxGetSingleChoiceIndex( _( "Shape type:" ), _( "Add Primitive" ),
2134 arrayDim( shapelist ), shapelist, 0, this );
2135
2136 // User pressed cancel
2137 if( type == -1 )
2138 return;
2139
2140 SHAPE_T listtype[] = { SHAPE_T::SEGMENT, SHAPE_T::ARC, SHAPE_T::BEZIER, SHAPE_T::CIRCLE,
2141 SHAPE_T::POLY };
2142
2143 PCB_SHAPE* primitive = new PCB_SHAPE();
2144 primitive->SetShape( listtype[type] );
2145 primitive->SetWidth( m_board->GetDesignSettings().GetLineThickness( F_Cu ) );
2146 primitive->SetFilled( true );
2147
2148 if( listtype[type] == SHAPE_T::POLY )
2149 {
2150 DIALOG_PAD_PRIMITIVE_POLY_PROPS dlg( this, m_parent, primitive );
2151
2152 if( dlg.ShowModal() != wxID_OK )
2153 return;
2154 }
2155 else
2156 {
2157 DIALOG_PAD_PRIMITIVES_PROPERTIES dlg( this, m_parent, primitive );
2158
2159 if( dlg.ShowModal() != wxID_OK )
2160 return;
2161 }
2162
2163 m_primitives.emplace_back( primitive );
2164
2165 displayPrimitivesList();
2166
2167 if( m_canUpdate )
2168 {
2169 transferDataToPad( m_dummyPad );
2170 redraw();
2171 }
2172 }
2173
2174
onGeometryTransform(wxCommandEvent & event)2175 void DIALOG_PAD_PROPERTIES::onGeometryTransform( wxCommandEvent& event )
2176 {
2177 long select = m_listCtrlPrimitives->GetFirstSelected();
2178
2179 if( select < 0 )
2180 {
2181 wxMessageBox( _( "No shape selected" ) );
2182 return;
2183 }
2184
2185 // Multiple selections are allowed. Build selected shapes list
2186 std::vector<std::shared_ptr<PCB_SHAPE>> shapeList;
2187 shapeList.emplace_back( m_primitives[select] );
2188
2189 while( ( select = m_listCtrlPrimitives->GetNextSelected( select ) ) >= 0 )
2190 shapeList.emplace_back( m_primitives[select] );
2191
2192 DIALOG_PAD_PRIMITIVES_TRANSFORM dlg( this, m_parent, shapeList, false );
2193
2194 if( dlg.ShowModal() != wxID_OK )
2195 return;
2196
2197 dlg.Transform();
2198
2199 displayPrimitivesList();
2200
2201 if( m_canUpdate )
2202 {
2203 transferDataToPad( m_dummyPad );
2204 redraw();
2205 }
2206 }
2207
2208
onDuplicatePrimitive(wxCommandEvent & event)2209 void DIALOG_PAD_PROPERTIES::onDuplicatePrimitive( wxCommandEvent& event )
2210 {
2211 long select = m_listCtrlPrimitives->GetFirstSelected();
2212
2213 if( select < 0 )
2214 {
2215 wxMessageBox( _( "No shape selected" ) );
2216 return;
2217 }
2218
2219 // Multiple selections are allowed. Build selected shapes list
2220 std::vector<std::shared_ptr<PCB_SHAPE>> shapeList;
2221 shapeList.emplace_back( m_primitives[select] );
2222
2223 while( ( select = m_listCtrlPrimitives->GetNextSelected( select ) ) >= 0 )
2224 shapeList.emplace_back( m_primitives[select] );
2225
2226 DIALOG_PAD_PRIMITIVES_TRANSFORM dlg( this, m_parent, shapeList, true );
2227
2228 if( dlg.ShowModal() != wxID_OK )
2229 return;
2230
2231 // Transfer new settings
2232 // save duplicates to a separate vector to avoid m_primitives reallocation,
2233 // as shapeList contains pointers to its elements
2234 std::vector<std::shared_ptr<PCB_SHAPE>> duplicates;
2235 dlg.Transform( &duplicates, dlg.GetDuplicateCount() );
2236 std::move( duplicates.begin(), duplicates.end(), std::back_inserter( m_primitives ) );
2237
2238 displayPrimitivesList();
2239
2240 if( m_canUpdate )
2241 {
2242 transferDataToPad( m_dummyPad );
2243 redraw();
2244 }
2245 }
2246