KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_footprint_properties.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) 2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright (C) 2015 Dick Hollenbeck, [email protected]
7 * Copyright The 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, see <https://www.gnu.org/licenses/>.
21 */
22
24#include <bitmaps.h>
25#include <board_commit.h>
27#include <board.h>
28#include <footprint.h>
29#include <eda_group.h>
30#include <confirm.h>
31#include <core/kicad_algo.h>
33#include <filename_resolver.h>
34#include <pcb_edit_frame.h>
35#include <pcbnew_settings.h>
37#include <pgm_base.h>
38#include <project_pcb.h>
39#include <kiplatform/ui.h>
48#include <tool/tool_manager.h>
50
51
52int DIALOG_FOOTPRINT_PROPERTIES::m_page = 0; // remember the last open page during session
53
54
57 m_frame( aParent ),
58 m_footprint( aFootprint ),
66 m_initialized( false )
67{
68 // Create the extra panels. Embedded files is referenced by the 3D model panel.
71
72 m_NoteBook->AddPage( m_3dPanel, _("3D Models"), false );
73 m_NoteBook->AddPage( m_embeddedFiles, _( "Embedded Files" ) );
74
75 // Configure display origin transforms
78
79 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
80 embeddedFilesStack.push_back( m_embeddedFiles->GetLocalFiles() );
81 embeddedFilesStack.push_back( m_frame->GetBoard()->GetEmbeddedFiles() );
82
83 m_fields = new PCB_FIELDS_GRID_TABLE( m_frame, this, std::move( embeddedFilesStack ) );
84
85 m_delayedErrorMessage = wxEmptyString;
86 m_delayedFocusGrid = nullptr;
89 m_initialFocus = false;
90
91 // Give an icon
92 wxIcon icon;
93 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) );
94 SetIcon( icon );
95
96 m_itemsGrid->SetTable( m_fields );
97 m_itemsGrid->OverrideMinSize( 1.0, 1.0 );
98 m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
99 m_itemsGrid->SetupColumnAutosizer( PFC_VALUE );
100 m_itemsGrid->ShowHideColumns( "0 1 2 3 4 5 7" );
101
103 m_orientation.SetPrecision( 3 );
104
105 // Set predefined rotations in combo dropdown, according to the locale floating point
106 // separator notation
107 double rot_list[] = { 0.0, 90.0, -90.0, 180.0 };
108
109 for( size_t ii = 0; ii < m_orientationCtrl->GetCount() && ii < 4; ++ii )
110 m_orientationCtrl->SetString( ii, wxString::Format( "%.1f", rot_list[ii] ) );
111
112 // Set font size for items showing long strings:
113 wxFont infoFont = KIUI::GetSmallInfoFont( this );
114 m_libraryIDLabel->SetFont( infoFont );
115 m_tcLibraryID->SetFont( infoFont );
116
117 infoFont = KIUI::GetInfoFont( this ).Italic();
118 m_staticTextInfoCopper->SetFont( infoFont );
119 m_staticTextInfoPaste->SetFont( infoFont );
120
121 m_NoteBook->SetSelection( m_page );
122
123 if( m_page == 0 )
124 {
128 }
129 else if( m_page == 1 )
130 {
132 }
133
134 // Update label text and tooltip for combined offset + ratio field
135 m_SolderPasteMarginLabel->SetLabel( _( "Solder paste clearance:" ) );
136 m_SolderPasteMarginLabel->SetToolTip( _( "Local solder paste clearance for this footprint.\n"
137 "Enter an absolute value (e.g., -0.1mm), a percentage "
138 "(e.g., -5%), or both (e.g., -0.1mm - 5%).\n"
139 "If blank, the global value is used." ) );
140
141 // Configure button logos
144
145 m_tcLibraryID->SetBackgroundColour( KIPLATFORM::UI::GetDialogBGColour() );
146
147 // We can't set the tab order through wxWidgets due to shortcomings in their mnemonics
148 // implementation on MSW
149 m_tabOrder = {
159 m_cbDNP,
167 };
168
170
171 // The 3D model tab was added after the base dtor. The final dialog size needs to be set
172 // accordingly.
173 SetSizer( m_GeneralBoxSizer );
174 Layout();
175 m_GeneralBoxSizer->Fit( this );
176
178}
179
180
182{
183 // Prevents crash bug in wxGrid's d'tor
184 m_itemsGrid->DestroyTable( m_fields );
185
186 // Delete the GRID_TRICKS.
187 m_itemsGrid->PopEventHandler( true );
188
189 // free the memory used by all models, otherwise models which were
190 // browsed but not used would consume memory
192
193 // the GL canvas has to be visible before it is destroyed
194 m_page = m_NoteBook->GetSelection();
195 m_NoteBook->SetSelection( 1 );
196}
197
198
200{
202 {
204 Close();
205 }
206}
207
208
210{
212 {
214 Close();
215 }
216}
217
218
220{
222 {
224 Close();
225 }
226}
227
228
230{
232 {
234 Close();
235 }
236}
237
238
240{
241 if( !wxDialog::TransferDataToWindow() )
242 return false;
243
244 if( !m_PanelGeneral->TransferDataToWindow() )
245 return false;
246
247 // Add the models to the panel
248 if( !m_3dPanel->TransferDataToWindow() )
249 return false;
250
251 if( !m_embeddedFiles->TransferDataToWindow() )
252 return false;
253
254 wxString variantName;
255
256 if( m_footprint->GetBoard() )
257 variantName = m_footprint->GetBoard()->GetCurrentVariant();
258
259 // Footprint Fields
260 for( PCB_FIELD* srcField : m_footprint->GetFields() )
261 {
262 wxCHECK2( srcField, continue );
263
264 PCB_FIELD field( *srcField );
265 wxString text = m_footprint->GetFieldValueForVariant( variantName, field.GetName() );
266 field.SetText( m_footprint->GetBoard()->ConvertKIIDsToCrossReferences( text ) );
267
268 m_fields->push_back( field );
269 }
270
271 // notify the grid
272 wxGridTableMessage tmsg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
273 m_itemsGrid->ProcessTableMessage( tmsg );
274
275 // Footprint Properties
276
277 m_posX.SetValue( m_footprint->GetPosition().x );
278 m_posY.SetValue( m_footprint->GetPosition().y );
279
280 m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
281
282 EDA_ANGLE orientation = m_footprint->GetOrientation();
283 m_orientation.SetAngleValue( orientation.Normalize180() );
284
285 m_cbLocked->SetValue( m_footprint->IsLocked() );
286 m_cbLocked->SetToolTip( _( "Locked footprints cannot be freely moved or oriented on the canvas and can only be "
287 "selected when the 'Locked items' checkbox is checked in the selection filter." ) );
288
289 if( m_footprint->GetAttributes() & FP_THROUGH_HOLE )
290 m_componentType->SetSelection( 0 );
291 else if( m_footprint->GetAttributes() & FP_SMD )
292 m_componentType->SetSelection( 1 );
293 else
294 m_componentType->SetSelection( 2 );
295
296 m_boardOnly->SetValue( m_footprint->GetAttributes() & FP_BOARD_ONLY );
297
298 m_cbExcludeFromSim->SetValue( m_footprint->GetExcludedFromSimForVariant( variantName ) );
299 m_excludeFromPosFiles->SetValue( m_footprint->GetExcludedFromPosFilesForVariant( variantName ) );
300 m_excludeFromBOM->SetValue( m_footprint->GetExcludedFromBOMForVariant( variantName ) );
301 m_cbDNP->SetValue( m_footprint->GetDNPForVariant( variantName ) );
302
303 // Local Clearances
304
305 if( m_footprint->GetLocalClearance().has_value() )
306 m_netClearance.SetValue( m_footprint->GetLocalClearance().value() );
307 else
308 m_netClearance.SetValue( wxEmptyString );
309
310 if( m_footprint->GetLocalSolderMaskMargin().has_value() )
311 m_solderMask.SetValue( m_footprint->GetLocalSolderMaskMargin().value() );
312 else
313 m_solderMask.SetValue( wxEmptyString );
314
315 m_solderPaste.SetOffsetValue( m_footprint->GetLocalSolderPasteMargin() );
316 m_solderPaste.SetRatioValue( m_footprint->GetLocalSolderPasteMarginRatio() );
317
318 m_allowSolderMaskBridges->SetValue( m_footprint->AllowSolderMaskBridges() );
319
320 switch( m_footprint->GetLocalZoneConnection() )
321 {
322 default:
323 case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
324 case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
325 case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
326 case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
327 }
328
329 wxString jumperGroups;
330
331 if( m_footprint->GetDuplicatePadNumbersAreJumpers() )
332 jumperGroups = _( "all pads with duplicate numbers" );
333
334 for( const std::set<wxString>& group : m_footprint->JumperPadGroups() )
335 {
336 wxString groupTxt;
337
338 for( const wxString& pinNumber : group )
339 {
340 if( !groupTxt.IsEmpty() )
341 groupTxt << ", ";
342
343 groupTxt << pinNumber;
344 }
345
346 if( !jumperGroups.IsEmpty() )
347 jumperGroups << "; ";
348
349 jumperGroups << "(" << groupTxt << ")";
350 }
351
352 if( jumperGroups.IsEmpty() )
353 {
354 m_jumperGroupsText->SetLabel( _( "none" ) );
356 }
357 else
358 {
359 m_jumperGroupsText->SetLabel( jumperGroups );
360 }
361
362 // Show the footprint's FPID.
363 m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
364
365 for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
366 {
367 m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false ) );
368
369 // Adjust the column size.
370 int col_size = m_itemsGrid->GetVisibleWidth( col );
371
372 if( col == PFC_LAYER ) // This one's a drop-down. Check all possible values.
373 {
374 BOARD* board = m_footprint->GetBoard();
375
376 for( PCB_LAYER_ID layer : board->GetEnabledLayers() )
377 col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
378
379 // Swatch and gaps:
380 col_size += KiROUND( 14 * GetDPIScaleFactor() ) + 12;
381 }
382
383 if( m_itemsGrid->IsColShown( col ) )
384 m_itemsGrid->SetColSize( col, col_size );
385 }
386
387 m_itemsGrid->SetRowLabelSize( 0 );
388
389 Layout();
390 m_itemsGrid->SetMinVisibleRows( this, 4 );
391 m_initialized = true;
392
393 return true;
394}
395
396
398{
399 if( !m_itemsGrid->CommitPendingChanges() )
400 return false;
401
402 if( !DIALOG_SHIM::Validate() )
403 return false;
404
405 // Validate texts.
406 for( size_t i = 0; i < m_fields->size(); ++i )
407 {
408 PCB_FIELD& field = m_fields->at( i );
409
410 // Check for missing field names.
411 if( field.GetName( false ).IsEmpty() )
412 {
414 m_delayedErrorMessage = wxString::Format( _( "Fields must have a name." ) );
417
418 return false;
419 }
420
421 int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
422 int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
423 int width = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, PFC_WIDTH ) );
424 int height = m_frame->ValueFromString( m_itemsGrid->GetCellValue( i, PFC_HEIGHT ) );
425
426 if( width < minSize )
427 {
428 wxString min = m_frame->StringFromValue( minSize, true );
429
430 m_itemsGrid->SetCellValue( i, PFC_WIDTH, min );
431
433 m_delayedErrorMessage = wxString::Format( _( "Text width must be at least %s." ), min );
436
437 return false;
438 }
439 else if( width > maxSize )
440 {
441 wxString max = m_frame->StringFromValue( maxSize, true );
442
443 m_itemsGrid->SetCellValue( i, PFC_WIDTH, max );
444
446 m_delayedErrorMessage = wxString::Format( _( "Text width must be at most %s." ), max );
449
450 return false;
451 }
452
453 if( height < minSize )
454 {
455 wxString min = m_frame->StringFromValue( minSize, true );
456
457 m_itemsGrid->SetCellValue( i, PFC_HEIGHT, min );
458
460 m_delayedErrorMessage = wxString::Format( _( "Text height must be at least %s." ), min );
463
464 return false;
465 }
466 else if( height > maxSize )
467 {
468 wxString max = m_frame->StringFromValue( maxSize, true );
469
470 m_itemsGrid->SetCellValue( i, PFC_HEIGHT, max );
471
473 m_delayedErrorMessage = wxString::Format( _( "Text height must be at most %s." ), max );
476
477 return false;
478 }
479
480 // Test for acceptable values for thickness and size and clamp if fails
481 int maxPenWidth = ClampTextPenSize( field.GetTextThickness(), field.GetTextSize() );
482
483 if( field.GetTextThickness() > maxPenWidth )
484 {
485 wxString clamped = m_frame->StringFromValue( maxPenWidth, true );
486
487 m_itemsGrid->SetCellValue( i, PFC_THICKNESS, clamped );
488
490 m_delayedErrorMessage = wxString::Format( _( "Text thickness is too large for the text size.\n"
491 "It will be clamped at %s." ),
492 clamped );
495
496 return false;
497 }
498 }
499
500 if( !m_netClearance.Validate( 0, INT_MAX ) )
501 return false;
502
503 return true;
504}
505
506
508{
509 if( !Validate() )
510 return false;
511
512 if( !m_itemsGrid->CommitPendingChanges() )
513 return false;
514
515 KIGFX::PCB_VIEW* view = m_frame->GetCanvas()->GetView();
516 PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
517 BOARD_COMMIT commit( m_frame );
518 commit.Modify( m_footprint );
519
520 // Make sure this happens inside a commit to capture any changed files
521 if( !m_3dPanel->TransferDataFromWindow() )
522 return false;
523
524 if( !m_embeddedFiles->TransferDataFromWindow() )
525 return false;
526
527 // Clear out embedded files that are no longer in use
528 std::set<wxString> files;
529 std::set<wxString> files_to_delete;
530
531 // Get the new files from the footprint fields
532 for( PCB_FIELD& field : *m_fields )
533 {
534 if( field.GetText().StartsWith( FILEEXT::KiCadUriPrefix ) )
535 files.insert( field.GetText() );
536 }
537
538 // Find any files referenced in the old fields that are not in the new fields
539 for( PCB_FIELD* field : m_footprint->GetFields() )
540 {
541 wxCHECK2( field, continue );
542
543 if( field->GetText().StartsWith( FILEEXT::KiCadUriPrefix ) )
544 {
545 if( files.find( field->GetText() ) == files.end() )
546 files_to_delete.insert( field->GetText() );
547 }
548 }
549
550 for( const wxString& file : files_to_delete )
551 {
552 wxString name = file.Mid( FILEEXT::KiCadUriPrefix.size() + 3 ); // Skip "kicad-embed://"
553 m_footprint->RemoveFile( name );
554 }
555
556 // Update fields
557 BOARD* board = m_footprint->GetBoard();
558
559 wxString variantName;
560
561 if( board )
562 variantName = board->GetCurrentVariant();
563
564 // Save base field values before the update so we can detect variant changes
565 std::map<wxString, wxString> baseFieldValues;
566
567 for( PCB_FIELD* existing : m_footprint->GetFields() )
568 baseFieldValues[existing->GetName()] = existing->GetText();
569
570 std::vector<PCB_FIELD> newFields;
571 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
572
573 // The vector holds the fields by value, so it must not reallocate while newField is bound
574 newFields.reserve( m_fields->size() );
575
576 for( PCB_FIELD& field : *m_fields )
577 {
578 PCB_FIELD& newField = newFields.emplace_back( field );
579 wxString newText = commit.GetBoard()->ConvertCrossReferencesToKIIDs( field.GetText() );
580
581 if( !variantName.IsEmpty() )
582 {
583 auto it = baseFieldValues.find( field.GetName() );
584 wxString baseText = ( it != baseFieldValues.end() ) ? it->second : wxString();
585
586 FOOTPRINT_VARIANT* variant = m_footprint->GetVariant( variantName );
587
588 if( !variant )
589 variant = m_footprint->AddVariant( variantName );
590
591 if( variant )
592 variant->SetFieldValue( field.GetName(), newText );
593
594 newField.SetText( baseText );
595 }
596 else
597 {
598 newField.SetText( newText );
599 }
600
601 if( !field.IsMandatory() )
602 newField.SetOrdinal( ordinal++, FIELD_T::USER );
603 }
604
605 std::vector<PCB_FIELD*> addedFields;
606 std::vector<PCB_FIELD*> detachedFields;
607
608 m_footprint->UpdateFields( newFields, addedFields, detachedFields );
609
610 for( PCB_FIELD* field : detachedFields )
611 {
612 if( EDA_GROUP* parentGroup = field->GetParentGroup() )
613 parentGroup->RemoveItem( field );
614
615 delete field;
616 }
617
618 for( PCB_FIELD* field : m_footprint->GetFields() )
619 {
620 // Reused fields are already known to the view and to their group
621 if( alg::contains( addedFields, field ) )
622 {
623 view->Add( field );
624
625 if( EDA_GROUP* parentGroup = field->GetParentGroup() )
626 parentGroup->AddItem( field );
627 }
628 else
629 {
630 view->Update( field );
631 }
632
633 if( field->IsSelected() )
634 {
635 // The old copy was in the selection list, but this one is not. Remove the
636 // out-of-sync selection flag so we can re-add the field to the selection.
637 field->ClearSelected();
638 selectionTool->AddItemToSel( field, true );
639 }
640 }
641
642 // Initialize masks clearances
643 if( m_netClearance.IsNull() )
644 m_footprint->SetLocalClearance( {} );
645 else
646 m_footprint->SetLocalClearance( m_netClearance.GetValue() );
647
648 if( m_solderMask.IsNull() )
649 m_footprint->SetLocalSolderMaskMargin( {} );
650 else
651 m_footprint->SetLocalSolderMaskMargin( m_solderMask.GetValue() );
652
653 m_footprint->SetLocalSolderPasteMargin( m_solderPaste.GetOffsetValue() );
654 m_footprint->SetLocalSolderPasteMarginRatio( m_solderPaste.GetRatioValue() );
655
656 switch( m_ZoneConnectionChoice->GetSelection() )
657 {
658 default:
659 case 0: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::INHERITED ); break;
660 case 1: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::FULL ); break;
661 case 2: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::THERMAL ); break;
662 case 3: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::NONE ); break;
663 }
664
665 // Set Footprint Position
666 VECTOR2I pos( m_posX.GetValue(), m_posY.GetValue() );
667 m_footprint->SetPosition( pos );
668 m_footprint->SetLocked( m_cbLocked->GetValue() );
669
670 int attributes = 0;
671
672 switch( m_componentType->GetSelection() )
673 {
674 case 0: attributes |= FP_THROUGH_HOLE; break;
675 case 1: attributes |= FP_SMD; break;
676 default: break;
677 }
678
679 if( m_boardOnly->GetValue() )
680 attributes |= FP_BOARD_ONLY;
681
682 if( !variantName.IsEmpty() )
683 {
684 FOOTPRINT_VARIANT* variant = m_footprint->GetVariant( variantName );
685
686 if( !variant )
687 variant = m_footprint->AddVariant( variantName );
688
689 if( variant )
690 {
691 variant->SetExcludedFromSim( m_cbExcludeFromSim->GetValue() );
692 variant->SetExcludedFromPosFiles( m_excludeFromPosFiles->GetValue() );
693 variant->SetExcludedFromBOM( m_excludeFromBOM->GetValue() );
694 variant->SetDNP( m_cbDNP->GetValue() );
695 }
696
697 // Preserve base attribute flags for these four properties
698 if( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_SIM )
699 attributes |= FP_EXCLUDE_FROM_SIM;
700
701 if( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES )
702 attributes |= FP_EXCLUDE_FROM_POS_FILES;
703
704 if( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_BOM )
705 attributes |= FP_EXCLUDE_FROM_BOM;
706
707 if( m_footprint->GetAttributes() & FP_DNP )
708 attributes |= FP_DNP;
709 }
710 else
711 {
712 if( m_cbExcludeFromSim->GetValue() )
713 attributes |= FP_EXCLUDE_FROM_SIM;
714
715 if( m_excludeFromPosFiles->GetValue() )
716 attributes |= FP_EXCLUDE_FROM_POS_FILES;
717
718 if( m_excludeFromBOM->GetValue() )
719 attributes |= FP_EXCLUDE_FROM_BOM;
720
721 if( m_cbDNP->GetValue() )
722 attributes |= FP_DNP;
723 }
724
725 m_footprint->SetAttributes( attributes );
726
727 m_footprint->SetAllowSolderMaskBridges( m_allowSolderMaskBridges->GetValue() );
728
729 EDA_ANGLE orient = m_orientation.GetAngleValue().Normalize();
730
731 if( m_footprint->GetOrientation() != orient )
732 m_footprint->Rotate( m_footprint->GetPosition(), orient - m_footprint->GetOrientation() );
733
734 // Set component side, that also have effect on the fields positions on board
735 bool change_layer = false;
736
737 if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
738 {
739 if( m_footprint->GetLayer() == B_Cu )
740 change_layer = true;
741 }
742 else if( m_footprint->GetLayer() == F_Cu )
743 {
744 change_layer = true;
745 }
746
747 if( change_layer )
748 m_footprint->Flip( m_footprint->GetPosition(), m_frame->GetPcbNewSettings()->m_FlipDirection );
749
750 // Copy the models from the panel to the footprint
751 std::vector<FP_3DMODEL>& panelList = m_3dPanel->GetModelList();
752 std::vector<FP_3DMODEL>* fpList = &m_footprint->Models();
753 fpList->clear();
754 fpList->insert( fpList->end(), panelList.begin(), panelList.end() );
755
756 // This is a simple edit, we must create an undo entry
757 if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
758 commit.Push( _( "Edit Footprint Properties" ) );
759
761 return true;
762}
763
764
766{
767 m_itemsGrid->OnAddRow(
768 [&]() -> std::pair<int, int>
769 {
771
772 newField.SetVisible( false );
773 newField.SetLayer( m_footprint->GetLayer() == F_Cu ? F_Fab : B_Fab );
774 newField.SetFPRelativePosition( { 0, 0 } );
775 newField.StyleFromSettings( m_frame->GetDesignSettings(), true );
776
777 m_fields->push_back( newField );
778
779 // notify the grid
780 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
781 m_itemsGrid->ProcessTableMessage( msg );
782 OnModify();
783
784 return { m_fields->size() - 1, PFC_NAME };
785 } );
786}
787
788
790{
791 m_itemsGrid->OnDeleteRows(
792 [&]( int row )
793 {
794 if( row < m_fields->GetMandatoryRowCount() )
795 {
796 DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
797 m_fields->GetMandatoryRowCount() ) );
798 return false;
799 }
800
801 return true;
802 },
803 [&]( int row )
804 {
805 m_fields->erase( m_fields->begin() + row );
806
807 // notify the grid
808 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
809 m_itemsGrid->ProcessTableMessage( msg );
810 } );
811
812 OnModify();
813}
814
815
817{
818 if( !m_initialized )
819 return;
820
821 // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
822 // even when the original validation was triggered from a killFocus event, and so
823 // that the corresponding notebook page can be shown in the background when triggered
824 // from an OK.
825 if( m_delayedFocusRow >= 0 )
826 {
827 // We will re-enter this routine if an error dialog is displayed, so make sure we
828 // zero out our member variables first.
829 wxGrid* grid = m_delayedFocusGrid;
830 int row = m_delayedFocusRow;
831 int col = m_delayedFocusColumn;
832 wxString msg = m_delayedErrorMessage;
833
834 m_delayedFocusGrid = nullptr;
837 m_delayedErrorMessage = wxEmptyString;
838
839 if( !msg.IsEmpty() )
840 {
841 // Do not use DisplayErrorMessage(); it screws up window order on Mac
842 DisplayError( nullptr, msg );
843 }
844
845 grid->SetFocus();
846 grid->MakeCellVisible( row, col );
847
848 // Selecting the first grid item only makes sense for the
849 // items grid
850 if( !m_initialFocus || grid == m_itemsGrid )
851 {
852 grid->SetGridCursor( row, col );
853
854 if( !( col == 0 && row < m_fields->GetMandatoryRowCount() ) )
855 grid->EnableCellEditControl( true );
856
857 grid->ShowCellEditControl();
858
859 if( grid == m_itemsGrid && row == 0 && col == 0 )
860 {
861 wxGridCellEditor* referenceEditor = grid->GetCellEditor( 0, 0 );
862
863 if( wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
864 KIUI::SelectReferenceNumber( textEntry );
865
866 referenceEditor->DecRef();
867 }
868 }
869
870 m_initialFocus = false;
871 }
872}
873
874
875void DIALOG_FOOTPRINT_PROPERTIES::OnPageChanging( wxNotebookEvent& aEvent )
876{
877 if( !m_itemsGrid->CommitPendingChanges() )
878 aEvent.Veto();
879}
880
881
882void DIALOG_FOOTPRINT_PROPERTIES::OnCheckBox( wxCommandEvent& event )
883{
884 if( m_initialized )
885 OnModify();
886}
887
888
889void DIALOG_FOOTPRINT_PROPERTIES::OnCombobox( wxCommandEvent& event )
890{
891 if( m_initialized )
892 OnModify();
893}
894
895
896void DIALOG_FOOTPRINT_PROPERTIES::OnText( wxCommandEvent& event )
897{
898 if( m_initialized )
899 OnModify();
900}
901
902
903void DIALOG_FOOTPRINT_PROPERTIES::OnChoice( wxCommandEvent& event )
904{
905 if( m_initialized )
906 OnModify();
907}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:100
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:374
void SetFPRelativePosition(const VECTOR2I &aPos)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:936
wxString GetCurrentVariant() const
Definition board.h:521
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1183
DIALOG_FOOTPRINT_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Footprint Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnDeleteField(wxCommandEvent &) override
void OnUpdateUI(wxUpdateUIEvent &) override
void OnAddField(wxCommandEvent &) override
void OnText(wxCommandEvent &event) override
void OnCombobox(wxCommandEvent &event) override
PANEL_FP_PROPERTIES_3D_MODEL * m_3dPanel
void OnPageChanging(wxNotebookEvent &event) override
void EditLibraryFootprint(wxCommandEvent &) override
DIALOG_FOOTPRINT_PROPERTIES(PCB_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
void OnChoice(wxCommandEvent &event) override
void EditFootprint(wxCommandEvent &) override
void OnCheckBox(wxCommandEvent &event) override
void UpdateFootprint(wxCommandEvent &) override
void ChangeFootprint(wxCommandEvent &) override
std::vector< wxWindow * > m_tabOrder
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:94
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
EDA_ANGLE Normalize180()
Definition eda_angle.h:268
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:342
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:231
Variant information for a footprint.
Definition footprint.h:227
void SetExcludedFromPosFiles(bool aExclude)
Definition footprint.h:251
void SetExcludedFromSim(bool aExclude)
Definition footprint.h:248
void SetDNP(bool aDNP)
Definition footprint.h:242
void SetFieldValue(const wxString &aFieldName, const wxString &aValue)
Set a field value override for this variant.
Definition footprint.h:273
void SetExcludedFromBOM(bool aExclude)
Definition footprint.h:245
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:57
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:87
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
The main frame for Pcbnew.
void SetOrdinal(int aOrdinal, FIELD_T aType)
Definition pcb_field.h:127
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
The selection tool: currently supports:
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) override
Definition pcb_text.cpp:371
int GetTextThickness() const override
Definition pcb_text.cpp:497
VECTOR2I GetTextSize() const override
Definition pcb_text.cpp:470
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
void FlushCache(bool closePlugins=true)
Free all data in the cache and by default closes all plugins.
Definition 3d_cache.cpp:575
int AddItemToSel(const TOOL_EVENT &aEvent)
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
Declaration of the eda_3d_viewer class.
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition eda_text.h:61
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition eda_text.h:62
@ FP_SMD
Definition footprint.h:86
@ FP_DNP
Definition footprint.h:91
@ FP_EXCLUDE_FROM_POS_FILES
Definition footprint.h:87
@ FP_BOARD_ONLY
Definition footprint.h:89
@ FP_EXCLUDE_FROM_BOM
Definition footprint.h:88
@ FP_EXCLUDE_FROM_SIM
Definition footprint.h:92
@ FP_THROUGH_HOLE
Definition footprint.h:85
int ClampTextPenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition gr_text.cpp:69
static const std::string KiCadUriPrefix
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ F_Fab
Definition layer_ids.h:115
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
wxColour GetDialogBGColour()
Definition wxgtk/ui.cpp:64
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
KICOMMON_API void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
@ PFC_THICKNESS
see class PGM_BASE
wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
@ USER
The field ID hasn't been set yet; field is invalid.
@ TRANSLATED
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ NONE
Pads are not covered.
Definition zones.h:45
@ FULL
pads are covered by copper
Definition zones.h:47