KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_footprint_properties_fp_editor.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2015 Dick Hollenbeck, [email protected]
6 * Copyright (C) 2008 Wayne Stambaugh <[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
25#include <wx/debug.h>
26#include <wx/tokenzr.h>
27
30#include <bitmaps.h>
31#include <board_commit.h>
33#include <confirm.h>
34
37#include <embedded_files.h>
38#include <filename_resolver.h>
39#include <footprint.h>
41#include <pad.h>
44#include <layer_utils.h>
45#include <kiplatform/ui.h>
48#include <pgm_base.h>
50#include <tool/tool_manager.h>
51#include <tools/pcb_actions.h>
53#include <validators.h>
57#include <widgets/wx_grid.h>
58#include <zone.h>
59
61#include <project_pcb.h>
62#include <kidialog.h>
63
64
65class LAYERS_GRID_TABLE : public WX_GRID_TABLE_BASE, public std::vector<PCB_LAYER_ID>
66{
67public:
68 LAYERS_GRID_TABLE( PCB_BASE_FRAME* aFrame, const LSET& aForbiddenLayers );
70
71 int GetNumberRows() override { return (int) size(); }
72 int GetNumberCols() override { return 1; }
73
74 bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
75 bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
76 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
77
78 wxString GetValue( int aRow, int aCol ) override;
79 long GetValueAsLong( int aRow, int aCol ) override;
80
81 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
82 void SetValueAsLong( int aRow, int aCol, long aValue ) override;
83
84private:
86 wxGridCellAttr* m_layerColAttr;
87};
88
89
90LAYERS_GRID_TABLE::LAYERS_GRID_TABLE( PCB_BASE_FRAME* aFrame, const LSET& aForbiddenLayers ) :
91 m_frame( aFrame )
92{
93 m_layerColAttr = new wxGridCellAttr;
94 m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
95
96 m_layerColAttr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, aForbiddenLayers, true ) );
97}
98
99
104
105
106bool LAYERS_GRID_TABLE::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
107{
108 return aTypeName == wxGRID_VALUE_NUMBER;
109}
110
111
112bool LAYERS_GRID_TABLE::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
113{
114 return aTypeName == wxGRID_VALUE_NUMBER;
115}
116
117
118wxGridCellAttr* LAYERS_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind )
119{
120 m_layerColAttr->IncRef();
121 return enhanceAttr( m_layerColAttr, aRow, aCol, aKind );
122}
123
124
125wxString LAYERS_GRID_TABLE::GetValue( int aRow, int aCol )
126{
127 return m_frame->GetBoard()->GetLayerName( this->at( (size_t) aRow ) );
128}
129
130
131long LAYERS_GRID_TABLE::GetValueAsLong( int aRow, int aCol )
132{
133 return this->at( (size_t) aRow );
134}
135
136
137void LAYERS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString& aValue )
138{
139 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
140}
141
142
143void LAYERS_GRID_TABLE::SetValueAsLong( int aRow, int aCol, long aValue )
144{
145 this->at( (size_t) aRow ) = ToLAYER_ID( (int) aValue );
146}
147
148
149// Remember the last open page during session.
150
152
153
155 FOOTPRINT* aFootprint ) :
157 m_frame( aParent ),
158 m_footprint( aFootprint ),
159 m_initialized( false ),
163{
164 SetEvtHandlerEnabled( false );
165
166 // Create the extra panels.
169
170 m_NoteBook->AddPage( m_3dPanel, _("3D Models"), false );
171 m_NoteBook->AddPage( m_embeddedFiles, _( "Embedded Files" ) );
172
173 m_fields = new PCB_FIELDS_GRID_TABLE( m_frame, this, { m_embeddedFiles->GetLocalFiles() } );
174
175 {
176 LSET forbiddenLayers = LSET::AllCuMask() | LSET::AllTechMask();
177 forbiddenLayers.set( Edge_Cuts );
178 forbiddenLayers.set( Margin );
179
180 m_privateLayers = new LAYERS_GRID_TABLE( m_frame, forbiddenLayers );
181 }
182
183 {
184 LSET forbiddenLayers = LSET::AllLayersMask() & ~LSET::UserDefinedLayersMask();
185 m_customUserLayers = new LAYERS_GRID_TABLE( m_frame, forbiddenLayers );
186 }
187
188 m_delayedErrorMessage = wxEmptyString;
189 m_delayedFocusCtrl = nullptr;
190 m_delayedFocusGrid = nullptr;
194
195 // Give an icon
196 wxIcon icon;
197 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) );
198 SetIcon( icon );
199
200 m_itemsGrid->SetTable( m_fields );
201 m_itemsGrid->OverrideMinSize( 1.0, 1.0 );
204
205 m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
207 [this]( wxCommandEvent& aEvent )
208 {
209 OnAddPrivateLayer( aEvent );
210 } ) );
211 m_nettieGroupsGrid->PushEventHandler( new GRID_TRICKS( m_nettieGroupsGrid,
212 [this]( wxCommandEvent& aEvent )
213 {
214 OnAddNettieGroup( aEvent );
215 } ) );
216 m_jumperGroupsGrid->PushEventHandler( new GRID_TRICKS( m_jumperGroupsGrid,
217 [this]( wxCommandEvent& aEvent )
218 {
219 OnAddJumperGroup( aEvent );
220 } ) );
222 [this]( wxCommandEvent& aEvent )
223 {
224 OnAddCustomLayer( aEvent );
225 } ) );
226
227 m_itemsGrid->SetupColumnAutosizer( PFC_VALUE );
228 m_privateLayersGrid->SetupColumnAutosizer( 0 );
229 m_nettieGroupsGrid->SetupColumnAutosizer( 0 );
230 m_jumperGroupsGrid->SetupColumnAutosizer( 0 );
231 m_customUserLayersGrid->SetupColumnAutosizer( 0 );
232
233 m_itemsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
234 m_privateLayersGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
235 m_nettieGroupsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
236 m_jumperGroupsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
237 m_customUserLayersGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
238
239 m_itemsGrid->ShowHideColumns( "0 1 2 3 4 5 7" );
240
242
243 // Set font sizes
244 wxFont infoFont = KIUI::GetInfoFont( this ).Italic();
245 m_staticTextInfoCopper->SetFont( infoFont );
246 m_staticTextInfoPaste->SetFont( infoFont );
247
248 if( static_cast<int>( m_page ) >= 0 )
249 m_NoteBook->SetSelection( (unsigned) m_page );
250
252 {
257 }
259 {
261 }
262
263 // Update label text and tooltip for combined offset + ratio field
264 m_SolderPasteMarginLabel->SetLabel( _( "Solder paste clearance:" ) );
265 m_SolderPasteMarginLabel->SetToolTip( _( "Local solder paste clearance for this footprint.\n"
266 "Enter an absolute value (e.g., -0.1mm), a percentage "
267 "(e.g., -5%), or both (e.g., -0.1mm - 5%).\n"
268 "If blank, the global value is used." ) );
269
270 // Hide the old ratio controls - they're no longer needed
271 m_PasteMarginRatioLabel->Show( false );
272 m_PasteMarginRatioCtrl->Show( false );
273 m_PasteMarginRatioUnits->Show( false );
274
275 // Configure button logos
286
288
290 SetEvtHandlerEnabled( true );
291}
292
293
295{
296 // Prevents crash bug in wxGrid's d'tor
297 m_itemsGrid->DestroyTable( m_fields );
298 m_privateLayersGrid->DestroyTable( m_privateLayers );
300
301 // Delete the GRID_TRICKS.
302 m_itemsGrid->PopEventHandler( true );
303 m_privateLayersGrid->PopEventHandler( true );
304 m_nettieGroupsGrid->PopEventHandler( true );
305 m_jumperGroupsGrid->PopEventHandler( true );
306 m_customUserLayersGrid->PopEventHandler( true );
307
308 m_page = static_cast<NOTEBOOK_PAGES>( m_NoteBook->GetSelection() );
309
310 // the GL canvas on the 3D models page has to be visible before it is destroyed
311 m_NoteBook->SetSelection( static_cast<int>( NOTEBOOK_PAGES::PAGE_3D_MODELS ) );
312}
313
314
316{
317 LIB_ID fpID = m_footprint->GetFPID();
318 wxString footprintName = fpID.GetLibItemName();
319
320 m_FootprintNameCtrl->ChangeValue( footprintName );
321
322 m_DocCtrl->SetValue( EscapeString( m_footprint->GetLibDescription(), CTX_LINE ) );
323 m_KeywordCtrl->SetValue( m_footprint->GetKeywords() );
324
325 if( !wxDialog::TransferDataToWindow() )
326 return false;
327
328 if( !m_PanelGeneral->TransferDataToWindow() )
329 return false;
330
331 // Add the models to the panel
332 if( !m_3dPanel->TransferDataToWindow() )
333 return false;
334
335 if( !m_embeddedFiles->TransferDataToWindow() )
336 return false;
337
338 // Footprint Fields
339 for( PCB_FIELD* field : m_footprint->GetFields() )
340 {
341 wxCHECK2( field, continue );
342
343 m_fields->push_back( *field );
344 }
345
346 // Notify the grid
347 wxGridTableMessage tmsg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
348 m_itemsGrid->ProcessTableMessage( tmsg );
349
350 if( m_footprint->GetAttributes() & FP_THROUGH_HOLE )
351 m_componentType->SetSelection( 0 );
352 else if( m_footprint->GetAttributes() & FP_SMD )
353 m_componentType->SetSelection( 1 );
354 else
355 m_componentType->SetSelection( 2 );
356
357 // Private layers
358 for( PCB_LAYER_ID privateLayer : m_footprint->GetPrivateLayers().UIOrder() )
359 m_privateLayers->push_back( privateLayer );
360
361 // Notify the grid
362 wxGridTableMessage gridTableMessagesg( m_privateLayers, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
363 m_privateLayers->GetNumberRows() );
364 m_privateLayersGrid->ProcessTableMessage( gridTableMessagesg );
365
366 switch( m_footprint->GetStackupMode() )
367 {
369 {
370 m_cbCustomLayers->SetValue( false );
371
372 m_copperLayerCount->SetSelection( 0 );
373 break;
374 }
376 {
377 m_cbCustomLayers->SetValue( true );
378
379 const LSET& customFpLayers = m_footprint->GetStackupLayers();
380 const LSET customUserLayers = customFpLayers & LSET::UserDefinedLayersMask();
381
382 for( PCB_LAYER_ID customUserLayer : customUserLayers )
383 {
384 m_customUserLayers->push_back( customUserLayer );
385 }
386
387 // Set the number of copper layers
388 m_copperLayerCount->SetSelection( ( customFpLayers & LSET::AllCuMask() ).count() / 2 - 1 );
389 break;
390 }
391 }
393
394 // Notify the grid
395 {
396 wxGridTableMessage gridTableMessagesCustom( m_customUserLayers, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
397 m_customUserLayers->GetNumberRows() );
398 m_customUserLayersGrid->ProcessTableMessage( gridTableMessagesCustom );
399 }
400
401 m_boardOnly->SetValue( m_footprint->GetAttributes() & FP_BOARD_ONLY );
402 m_excludeFromPosFiles->SetValue( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES );
403 m_excludeFromBOM->SetValue( m_footprint->GetAttributes() & FP_EXCLUDE_FROM_BOM );
404 m_cbDNP->SetValue( m_footprint->GetAttributes() & FP_DNP );
405
406 // Local Clearances
407
408 if( m_footprint->GetLocalClearance().has_value() )
409 m_netClearance.SetValue( m_footprint->GetLocalClearance().value() );
410 else
411 m_netClearance.SetValue( wxEmptyString );
412
413 if( m_footprint->GetLocalSolderMaskMargin().has_value() )
414 m_solderMask.SetValue( m_footprint->GetLocalSolderMaskMargin().value() );
415 else
416 m_solderMask.SetValue( wxEmptyString );
417
418 m_solderPaste.SetOffsetValue( m_footprint->GetLocalSolderPasteMargin() );
419 m_solderPaste.SetRatioValue( m_footprint->GetLocalSolderPasteMarginRatio() );
420
421 m_noCourtyards->SetValue( m_footprint->AllowMissingCourtyard() );
422 m_allowBridges->SetValue( m_footprint->AllowSolderMaskBridges() );
423
424 switch( m_footprint->GetLocalZoneConnection() )
425 {
426 default:
427 case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
428 case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
429 case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
430 case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
431 }
432
433 for( const wxString& group : m_footprint->GetNetTiePadGroups() )
434 {
435 if( !group.IsEmpty() )
436 {
437 m_nettieGroupsGrid->AppendRows( 1 );
438 m_nettieGroupsGrid->SetCellValue( m_nettieGroupsGrid->GetNumberRows() - 1, 0, group );
439 }
440 }
441
442 m_cbDuplicatePadsAreJumpers->SetValue( m_footprint->GetDuplicatePadNumbersAreJumpers() );
443
444 for( const std::set<wxString>& group : m_footprint->JumperPadGroups() )
445 {
446 wxString groupTxt;
447
448 for( const wxString& pinNumber : group )
449 {
450 if( !groupTxt.IsEmpty() )
451 groupTxt << ", ";
452
453 groupTxt << pinNumber;
454 }
455
456 m_jumperGroupsGrid->AppendRows( 1 );
457 m_jumperGroupsGrid->SetCellValue( m_jumperGroupsGrid->GetNumberRows() - 1, 0, groupTxt );
458 }
459
460 // Items grid
461 for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
462 {
463 // Adjust min size to the column label size
464 m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false ) );
465 // Adjust the column size.
466 int col_size = m_itemsGrid->GetVisibleWidth( col );
467
468 if( col == PFC_LAYER ) // This one's a drop-down. Check all possible values.
469 {
470 BOARD* board = m_footprint->GetBoard();
471
472 for( PCB_LAYER_ID layer : board->GetEnabledLayers() )
473 col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
474
475 // Swatch and gaps:
476 col_size += KiROUND( 14 * GetDPIScaleFactor() ) + 12;
477 }
478
479 if( m_itemsGrid->IsColShown( col ) )
480 m_itemsGrid->SetColSize( col, col_size );
481 }
482
483 m_itemsGrid->SetRowLabelSize( 0 );
484
485 Layout();
486 m_initialized = true;
487
488 return true;
489}
490
491
493 LIB_ID* doOverwrite )
494{
495 if( aFootprintName.IsEmpty() )
496 {
497 m_delayedErrorMessage = _( "Footprint must have a name." );
498 return false;
499 }
500 else if( !FOOTPRINT::IsLibNameValid( aFootprintName ) )
501 {
502 m_delayedErrorMessage.Printf( _( "Footprint name may not contain '%s'." ),
504 return false;
505 }
506
507 LIB_ID fpID = m_footprint->GetFPID();
508 wxString libraryName = fpID.GetLibNickname();
509 wxString originalFPName = fpID.GetLibItemName();
510
512
513 if( aFootprintName != originalFPName && adapter->FootprintExists( libraryName, aFootprintName ) )
514 {
515 wxString msg = wxString::Format( _( "Footprint '%s' already exists in library '%s'." ),
516 aFootprintName, libraryName );
517
518 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
519 errorDlg.SetOKLabel( _( "Overwrite" ) );
520
521 if( errorDlg.ShowModal() == wxID_OK )
522 {
523 doOverwrite->SetLibNickname( libraryName );
524 doOverwrite->SetLibItemName( aFootprintName );
525 return true;
526 }
527 }
528
529 return true;
530}
531
532
534{
535 LSET userLayers;
536 if( m_cbCustomLayers->GetValue() )
537 {
538 userLayers |= LSET::AllCuMask( ( m_copperLayerCount->GetSelection() + 1 ) * 2 );
539
540 for( PCB_LAYER_ID layer : *m_customUserLayers )
541 {
542 userLayers.set( layer );
543 }
544 }
545 else
546 {
547 // The default stackup restricts nothing, so every standard layer is available.
548 userLayers |= LSET{ F_Cu, B_Cu };
549 userLayers |= LSET::InternalCuMask();
550 userLayers |= LSET::UserDefinedLayersMask();
551 }
552
553 return userLayers;
554}
555
556
558{
559 if( !m_itemsGrid->CommitPendingChanges() )
560 return false;
561
562 if( !DIALOG_SHIM::Validate() )
563 return false;
564
565 // First, test for invalid chars in footprint name
566 wxString footprintName = m_FootprintNameCtrl->GetValue();
567 LIB_ID overwrite;
568
569 if( !checkFootprintName( footprintName, &overwrite ) )
570 {
571 if( m_NoteBook->GetSelection() != 0 )
572 m_NoteBook->SetSelection( 0 );
573
576
577 return false;
578 }
579
580 // Check for valid field text properties
581 for( int i = 0; i < (int) m_fields->size(); ++i )
582 {
583 PCB_FIELD& field = m_fields->at( i );
584
585 // Check for missing field names.
586 if( field.GetName( false ).IsEmpty() )
587 {
589 m_delayedErrorMessage = wxString::Format( _( "Fields must have a name." ) );
592
593 return false;
594 }
595
596 int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
597 int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
598
599 if( field.GetTextWidth() < minSize || field.GetTextWidth() > maxSize )
600 {
602 m_delayedErrorMessage = wxString::Format( _( "The text width must be between %s and %s." ),
603 m_frame->StringFromValue( minSize, true ),
604 m_frame->StringFromValue( maxSize, true ) );
607
608 return false;
609 }
610
611 if( field.GetTextHeight() < minSize || field.GetTextHeight() > maxSize )
612 {
614 m_delayedErrorMessage = wxString::Format( _( "The text height must be between %s and %s." ),
615 m_frame->StringFromValue( minSize, true ),
616 m_frame->StringFromValue( maxSize, true ) );
619
620 return false;
621 }
622
623 // Test for acceptable values for thickness and size and clamp if fails
624 int maxPenWidth = ClampTextPenSize( field.GetTextThickness(), field.GetTextSize() );
625
626 if( field.GetTextThickness() > maxPenWidth )
627 {
628 m_itemsGrid->SetCellValue( i, PFC_THICKNESS, m_frame->StringFromValue( maxPenWidth, true ) );
629
631 m_delayedErrorMessage = _( "The text thickness is too large for the text size.\n"
632 "It will be clamped." );
635
636 return false;
637 }
638 }
639
640 if( !m_netClearance.Validate( 0, INT_MAX ) )
641 return false;
642
643 if( overwrite.IsValid() )
644 {
645 if( m_frame->DeleteFootprintFromLibrary( overwrite, false /* already confirmed */ ) )
646 m_frame->SyncLibraryTree( true );
647 }
648
649 // A custom layer set restricts which layers the footprint may use, so check that the user
650 // isn't removing a layer that is still used by the footprint. The default stackup imposes no
651 // such restriction, so nothing can be orphaned in that case.
652 if( m_cbCustomLayers->GetValue() )
653 {
656
657 if( orphanLayers.any() )
658 {
660 wxString::Format( _( "You are trying to remove layers that are used by the footprint: %s.\n"
661 "Please remove the objects that use these layers first." ),
662 LAYER_UTILS::AccumulateNames( orphanLayers, m_frame->GetBoard() ) );
667 return false;
668 }
669 }
670
671 return true;
672}
673
674
676{
677 if( !m_itemsGrid->CommitPendingChanges()
678 || !m_privateLayersGrid->CommitPendingChanges()
679 || !m_nettieGroupsGrid->CommitPendingChanges()
680 || !m_jumperGroupsGrid->CommitPendingChanges()
681 || !m_customUserLayersGrid->CommitPendingChanges() )
682 {
683 return false;
684 }
685
686 KIGFX::PCB_VIEW* view = m_frame->GetCanvas()->GetView();
687 PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
688 BOARD_COMMIT commit( m_frame );
689 commit.Modify( m_footprint );
690
691 // Must be done inside the commit to capture the undo state
692 // This will call TransferDataToWindow() on the 3D panel and
693 // the embedded files panel.
694 if( !DIALOG_SHIM::TransferDataFromWindow() )
695 return false;
696
697 // Clear out embedded files that are no longer in use
698 std::set<wxString> files;
699 std::set<wxString> files_to_delete;
700
701 // Get the new files from the footprint fields
702 for( const PCB_FIELD& field : *m_fields )
703 {
704 if( field.GetText().StartsWith( FILEEXT::KiCadUriPrefix ) )
705 files.insert( field.GetText() );
706 }
707
708 // Find any files referenced in the old fields that are not in the new fields
709 for( PCB_FIELD* field : m_footprint->GetFields() )
710 {
711 wxCHECK2( field, continue );
712
713 if( field->GetText().StartsWith( FILEEXT::KiCadUriPrefix ) )
714 {
715 if( files.find( field->GetText() ) == files.end() )
716 files_to_delete.insert( field->GetText() );
717 }
718 }
719
720 for( const wxString& file : files_to_delete )
721 {
722 wxString name = file.Mid( FILEEXT::KiCadUriPrefix.size() + 3 ); // Skip "kicad-embed://"
723 m_footprint->RemoveFile( name );
724 }
725
726 LIB_ID fpID = m_footprint->GetFPID();
727 fpID.SetLibItemName( m_FootprintNameCtrl->GetValue() );
728 m_footprint->SetFPID( fpID );
729
730 m_footprint->SetLibDescription( UnescapeString( m_DocCtrl->GetValue() ) );
731 m_footprint->SetKeywords( m_KeywordCtrl->GetValue() );
732
733 // Update fields
734 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
735
736 while( !m_footprint->GetFields().empty() )
737 {
738 PCB_FIELD* existing = m_footprint->GetFields().front();
739 view->Remove( existing );
740 m_footprint->Remove( existing );
741 delete existing;
742 }
743
744 for( PCB_FIELD& field : *m_fields )
745 {
746 PCB_FIELD* newField = field.CloneField();
747 m_footprint->Add( newField );
748 view->Add( newField );
749
750 if( newField->IsSelected() )
751 {
752 // The old copy was in the selection list, but this one is not. Remove the
753 // out-of-sync selection flag so we can re-add the field to the selection.
754 newField->ClearSelected();
755 selectionTool->AddItemToSel( newField, true );
756 }
757 }
758
759 LSET privateLayers;
760
761 for( PCB_LAYER_ID layer : *m_privateLayers )
762 privateLayers.set( layer );
763
764 m_footprint->SetPrivateLayers( privateLayers );
765
766 if( m_cbCustomLayers->GetValue() )
767 {
768 const LSET customLayers = getCustomLayersFromControls();
769
771 m_footprint->SetStackupLayers( std::move( customLayers ) );
772 }
773 else
774 {
775 // Just use the default stackup mode
777 }
778
779 int attributes = 0;
780
781 switch( m_componentType->GetSelection() )
782 {
783 case 0: attributes |= FP_THROUGH_HOLE; break;
784 case 1: attributes |= FP_SMD; break;
785 default: break;
786 }
787
788 if( m_boardOnly->GetValue() )
789 attributes |= FP_BOARD_ONLY;
790
791 if( m_excludeFromPosFiles->GetValue() )
792 attributes |= FP_EXCLUDE_FROM_POS_FILES;
793
794 if( m_excludeFromBOM->GetValue() )
795 attributes |= FP_EXCLUDE_FROM_BOM;
796
797 if( m_cbDNP->GetValue() )
798 attributes |= FP_DNP;
799
800 m_footprint->SetAttributes( attributes );
801
802 m_footprint->SetAllowMissingCourtyard( m_noCourtyards->GetValue() );
803 m_footprint->SetAllowSolderMaskBridges( m_allowBridges->GetValue() );
804
805 // Initialize mask clearances
806 if( m_netClearance.IsNull() )
807 m_footprint->SetLocalClearance( {} );
808 else
809 m_footprint->SetLocalClearance( m_netClearance.GetValue() );
810
811 if( m_solderMask.IsNull() )
812 m_footprint->SetLocalSolderMaskMargin( {} );
813 else
814 m_footprint->SetLocalSolderMaskMargin( m_solderMask.GetValue() );
815
816 m_footprint->SetLocalSolderPasteMargin( m_solderPaste.GetOffsetValue() );
817 m_footprint->SetLocalSolderPasteMarginRatio( m_solderPaste.GetRatioValue() );
818
819 switch( m_ZoneConnectionChoice->GetSelection() )
820 {
821 default:
822 case 0: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::INHERITED ); break;
823 case 1: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::FULL ); break;
824 case 2: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::THERMAL ); break;
825 case 3: m_footprint->SetLocalZoneConnection( ZONE_CONNECTION::NONE ); break;
826 }
827
828 m_footprint->ClearNetTiePadGroups();
829
830 for( int ii = 0; ii < m_nettieGroupsGrid->GetNumberRows(); ++ii )
831 {
832 wxString group = m_nettieGroupsGrid->GetCellValue( ii, 0 );
833
834 if( !group.IsEmpty() )
835 m_footprint->AddNetTiePadGroup( group );
836 }
837
838 m_footprint->SetDuplicatePadNumbersAreJumpers( m_cbDuplicatePadsAreJumpers->GetValue() );
839
840 std::set<wxString> availablePads;
841
842 for( const PAD* pad : m_footprint->Pads() )
843 availablePads.insert( pad->GetNumber() );
844
845 std::vector<std::set<wxString>> newJumpers;
846
847 for( int ii = 0; ii < m_jumperGroupsGrid->GetNumberRows(); ++ii )
848 {
849 wxStringTokenizer tokenizer( m_jumperGroupsGrid->GetCellValue( ii, 0 ), ", \t\r\n", wxTOKEN_STRTOK );
850 std::set<wxString>& group = newJumpers.emplace_back();
851
852 while( tokenizer.HasMoreTokens() )
853 {
854 wxString token = tokenizer.GetNextToken();
855
856 if( token.IsEmpty() )
857 continue;
858
859 if( !availablePads.count( token ) )
860 {
861 wxString msg;
862 msg.Printf( _( "Pad '%s' in jumper pad group %d does not exist in this footprint." ),
863 token, ii + 1 );
864 DisplayErrorMessage( this, msg );
865 return false;
866 }
867
868 group.insert( token );
869 }
870 }
871
872 m_footprint->JumperPadGroups() = std::move( newJumpers );
873
874 // Copy the models from the panel to the footprint
875 std::vector<FP_3DMODEL>& panelList = m_3dPanel->GetModelList();
876 std::vector<FP_3DMODEL>* fpList = &m_footprint->Models();
877 fpList->clear();
878 fpList->insert( fpList->end(), panelList.begin(), panelList.end() );
879
880 commit.Push( _( "Edit Footprint Properties" ) );
881
882 return true;
883}
884
885
887{
888 m_itemsGrid->OnAddRow(
889 [&]() -> std::pair<int, int>
890 {
891 const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
892
894
895 // Set active layer if legal; otherwise copy layer from previous text item
896 if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
897 newField.SetLayer( m_frame->GetActiveLayer() );
898 else
899 newField.SetLayer( m_fields->at( m_fields->size() - 1 ).GetLayer() );
900
901 newField.SetTextSize( dsnSettings.GetTextSize( newField.GetLayer() ) );
902 newField.SetTextThickness( dsnSettings.GetTextThickness( newField.GetLayer() ) );
903 newField.SetItalic( dsnSettings.GetTextItalic( newField.GetLayer() ) );
904
905 m_fields->push_back( newField );
906
907 // notify the grid
908 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
909 m_itemsGrid->ProcessTableMessage( msg );
910 OnModify();
911
912 return { m_fields->size() - 1, PFC_NAME };
913 } );
914}
915
916
918{
919 m_itemsGrid->OnDeleteRows(
920 [&]( int row )
921 {
922 if( row < m_fields->GetMandatoryRowCount() )
923 {
924 DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
925 m_fields->GetMandatoryRowCount() ) );
926 return false;
927 }
928
929 return true;
930 },
931 [&]( int row )
932 {
933 m_fields->erase( m_fields->begin() + row );
934
935 // notify the grid
936 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
937 m_itemsGrid->ProcessTableMessage( msg );
938 } );
939
940 OnModify();
941}
942
943
945 int aRow )
946{
947 aLayerTable.erase( aLayerTable.begin() + aRow );
948
949 // notify the grid
950 wxGridTableMessage msg( &aLayerTable, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
951 aGrid.ProcessTableMessage( msg );
952
953 OnModify();
954}
955
956
958 LAYERS_GRID_TABLE& aGridTable )
959{
960 PCB_LAYER_ID nextLayer = User_1;
961
962 while( alg::contains( aGridTable, nextLayer ) && nextLayer < User_45 )
963 nextLayer = ToLAYER_ID( nextLayer + 2 );
964
965 aGridTable.push_back( nextLayer );
966
967 // notify the grid
968 wxGridTableMessage msg( &aGridTable, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
969 aGrid.ProcessTableMessage( msg );
970 OnModify();
971
972 return { aGridTable.size() - 1, -1 };
973}
974
975
977{
978 m_privateLayersGrid->OnAddRow(
979 [&]()
980 {
982 } );
983}
984
985
987{
988 m_privateLayersGrid->OnDeleteRows(
989 [&]( int row )
990 {
992 } );
993}
994
995
1000
1001
1003{
1004 m_customUserLayersGrid->OnAddRow(
1005 [&]()
1006 {
1008 } );
1009}
1010
1011
1013{
1014 m_customUserLayersGrid->OnDeleteRows(
1015 [&]( int row )
1016 {
1018 } );
1019}
1020
1021
1026
1027
1032
1033
1038
1039
1044
1045
1047{
1048 aGrid->OnAddRow(
1049 [&]() -> std::pair<int, int>
1050 {
1051 aGrid->AppendRows( 1 );
1052 OnModify();
1053
1054 return { aGrid->GetNumberRows() - 1, 0 };
1055 } );
1056}
1057
1058
1060{
1061 aGrid->OnDeleteRows(
1062 [&]( int row )
1063 {
1064 aGrid->DeleteRows( row, 1 );
1065 } );
1066
1067 OnModify();
1068}
1069
1070
1072{
1073 // Handle a delayed focus. The delay allows us to:
1074 // a) change focus when the error was triggered from within a killFocus handler
1075 // b) show the correct notebook page in the background before the error dialog comes up
1076 // when triggered from an OK or a notebook page change
1077
1078 if( static_cast<int>( m_delayedFocusPage ) >= 0 )
1079 {
1080 if( m_NoteBook->GetSelection() != static_cast<int>( m_delayedFocusPage ) )
1081 m_NoteBook->ChangeSelection( static_cast<int>( m_delayedFocusPage ) );
1082
1084 }
1085
1086 if( !m_delayedErrorMessage.IsEmpty() )
1087 {
1088 // We will re-enter this routine when the error dialog is displayed, so make
1089 // sure we don't keep putting up more dialogs.
1090 wxString msg = m_delayedErrorMessage;
1091 m_delayedErrorMessage = wxEmptyString;
1092
1093 // Do not use DisplayErrorMessage(); it screws up window order on Mac
1094 DisplayError( nullptr, msg );
1095 }
1096
1097 if( m_delayedFocusCtrl )
1098 {
1099 m_delayedFocusCtrl->SetFocus();
1100
1101 if( wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
1102 textEntry->SelectAll();
1103
1104 m_delayedFocusCtrl = nullptr;
1105 }
1106 else if( m_delayedFocusGrid )
1107 {
1108 m_delayedFocusGrid->SetFocus();
1111
1112 if( !( m_delayedFocusColumn == 0 && m_delayedFocusRow < m_fields->GetMandatoryRowCount() ) )
1113 m_delayedFocusGrid->EnableCellEditControl( true );
1114
1115 m_delayedFocusGrid->ShowCellEditControl();
1116
1117 m_delayedFocusGrid = nullptr;
1118 m_delayedFocusRow = -1;
1120 }
1121}
1122
1123
1125{
1126 bool enableCustomCtrls = m_cbCustomLayers->GetValue();
1127
1128 m_copperLayerCount->Enable( enableCustomCtrls );
1129 m_customUserLayersGrid->Enable( enableCustomCtrls );
1130 m_bpAddCustomLayer->Enable( enableCustomCtrls );
1131 m_bpDeleteCustomLayer->Enable( enableCustomCtrls );
1132}
1133
1134
1136{
1137 if( !m_itemsGrid->CommitPendingChanges() )
1138 aEvent.Veto();
1139
1140 if( !m_privateLayersGrid->CommitPendingChanges() )
1141 aEvent.Veto();
1142
1143 if( !m_customUserLayersGrid->CommitPendingChanges() )
1144 aEvent.Veto();
1145}
1146
1147
1149{
1150 if( m_initialized )
1151 OnModify();
1152}
1153
1154
1156{
1157 if( m_initialized )
1158 OnModify();
1159}
1160
1161
1163{
1164 if( m_initialized )
1165 OnModify();
1166}
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:986
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
BASE_SET & set(size_t pos)
Definition base_set.h:116
Container for design settings for a BOARD object.
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
VECTOR2I GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:265
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:313
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:793
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1034
DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_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)
DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(FOOTPRINT_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
LSET getCustomLayersFromControls() const
Get the layers for the footprint from the controls that can be affected by the stackup.
bool checkFootprintName(const wxString &aFootprintName, LIB_ID *doOverwrite)
void onLayerGridRowDelete(WX_GRID &aGrid, LAYERS_GRID_TABLE &aLayerTable, int aRow)
std::pair< int, int > onLayerGridRowAddUserLayer(WX_GRID &aGrid, LAYERS_GRID_TABLE &aLayerTable)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:79
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...
void ClearSelected()
Definition eda_item.h:147
bool IsSelected() const
Definition eda_item.h:132
virtual int GetTextHeight() const
Definition eda_text.h:288
virtual int GetTextWidth() const
Definition eda_text.h:285
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:302
An interface to the global shared library manager that is schematic-specific and linked to one projec...
bool FootprintExists(const wxString &aNickname, const wxString &aName)
Provide a custom wxValidator object for limiting the allowable characters when defining footprint nam...
Definition validators.h:49
static bool IsLibNameValid(const wxString &aName)
Test for validity of a name of a footprint to be used in a footprint library ( no spaces,...
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
Test for validity of the name in a library of the footprint ( no spaces, dir separators ....
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:57
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:38
int ShowModal() override
Definition kidialog.cpp:89
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:70
LAYERS_GRID_TABLE(PCB_BASE_FRAME *aFrame, const LSET &aForbiddenLayers)
wxString GetValue(int aRow, int aCol) override
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override
void SetValueAsLong(int aRow, int aCol, long aValue) override
long GetValueAsLong(int aRow, int aCol) override
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition lib_id.cpp:107
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition lib_id.cpp:96
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
static const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition lset.cpp:672
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static const LSET & AllLayersMask()
Definition lset.cpp:637
static LSET UserDefinedLayersMask(int aUserDefinedLayerCount=MAX_USER_DEFINED_LAYERS)
Return a mask with the requested number of user defined layers.
Definition lset.cpp:700
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:573
Definition pad.h:61
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
PCB_FIELD * CloneField() const
Same as Clone, but returns a PCB_FIELD item.
Definition pcb_field.h:90
The selection tool: currently supports:
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
Definition pcb_text.cpp:495
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
Definition pcb_text.cpp:467
int GetTextThickness() const override
Definition pcb_text.cpp:480
VECTOR2I GetTextSize() const override
Definition pcb_text.cpp:453
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
int AddItemToSel(const TOOL_EVENT &aEvent)
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
Definition wx_grid.cpp:43
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
Definition wx_grid.cpp:738
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
Definition wx_grid.cpp:718
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
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:56
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition eda_text.h:57
@ FP_SMD
Definition footprint.h:84
@ FP_DNP
Definition footprint.h:89
@ FP_EXCLUDE_FROM_POS_FILES
Definition footprint.h:85
@ FP_BOARD_ONLY
Definition footprint.h:87
@ FP_EXCLUDE_FROM_BOM
Definition footprint.h:86
@ FP_THROUGH_HOLE
Definition footprint.h:83
@ EXPAND_INNER_LAYERS
The 'normal' stackup handling, where there is a single inner layer (In1) and rule areas using it expa...
Definition footprint.h:148
@ CUSTOM_LAYERS
Stackup handling where the footprint can have any number of copper layers, and objects on those layer...
Definition footprint.h:153
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
@ User_45
Definition layer_ids.h:164
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Cu
Definition layer_ids.h:61
@ Margin
Definition layer_ids.h:109
@ User_1
Definition layer_ids.h:120
@ F_Cu
Definition layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
wxString AccumulateNames(const LSEQ &aLayers, const BOARD *aBoard)
Accumulate layer names from a layer set into a comma separated string.
LSET GetOrphanedFootprintLayers(const FOOTPRINT &aFootprint, const LSET &aCustomUserLayers)
Compute the set of footprint-used layers that would be orphaned if the footprint's allowed layer set ...
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 UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LINE
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
#define DO_TRANSLATE
@ USER
The field ID hasn't been set yet; field is invalid.
Custom text control validator definitions.
@ 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