KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_lib_symbol_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <pgm_base.h>
23#include <bitmaps.h>
24#include <confirm.h>
25#include <kiway.h>
27#include <symbol_edit_frame.h>
29#include <math/util.h> // for KiROUND
30#include <sch_symbol.h>
31#include <kiplatform/ui.h>
33#include <widgets/wx_grid.h>
35#include <string_utils.h>
36#include <template_fieldnames.h>
37#include <project_sch.h>
38#include <refdes_utils.h>
39#include <dialog_sim_model.h>
40#include <tools/sch_actions.h>
46
47#include <map>
48#include <set>
49#include <vector>
50
51#include <wx/msgdlg.h>
52
53#include "pin_numbers.h"
54
55
57using HAS_OWN_VALUE = bool ( * )( const LIB_SYMBOL& );
58
59
64static std::shared_ptr<LIB_SYMBOL> ancestorDefining( const LIB_SYMBOL* aSymbol, HAS_OWN_VALUE aHasOwn )
65{
66 std::shared_ptr<LIB_SYMBOL> source = aSymbol->GetParent().lock();
67 std::set<LIB_SYMBOL*> visited;
68
69 while( source && !aHasOwn( *source ) && visited.insert( source.get() ).second )
70 source = source->GetParent().lock();
71
72 return source && aHasOwn( *source ) ? source : nullptr;
73}
74
75
79
80
83 m_Parent( aParent ),
84 m_libEntry( aLibEntry ),
86 m_delayedFocusCtrl( nullptr ),
87 m_delayedFocusGrid( nullptr ),
91{
92 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
93 m_libEntry->AppendParentEmbeddedFiles( embeddedFilesStack );
94
95 m_embeddedFiles = new PANEL_EMBEDDED_FILES( m_NoteBook, m_libEntry->GetEmbeddedFiles(), 0, embeddedFilesStack );
96 m_NoteBook->AddPage( m_embeddedFiles, _( "Embedded Files" ) );
97 embeddedFilesStack.push_back( m_embeddedFiles->GetLocalFiles() );
98
99 // The filters page is the third tab, between Units & Body Styles and Pin Connections.
101
102 // The Footprint field a match is assigned to lives on the General page.
103 m_fpFiltersPanel->SetFootprintFieldAccessors( [this]()
104 {
106 },
107 [this]( const wxString& aFootprintName )
108 {
109 assignFootprintToField( aFootprintName );
110 } );
111
112 m_NoteBook->InsertPage( 2, m_fpFiltersPanel, _( "Footprint Filters" ) );
113
115 bPinMapPageSizer->Add( m_pinMapPanel, 1, wxEXPAND, 5 );
116
117 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_libEntry, embeddedFilesStack );
118 m_grid->SetTable( m_fields );
119 m_grid->OverrideMinSize( 1.0, 1.0 );
120 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, embeddedFilesStack,
121 [&]( wxCommandEvent& aEvent )
122 {
123 OnAddField( aEvent );
124 } ) );
125 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
126
127 // Load the FIELDS_GRID_TABLE -- ensure we are calling the overloaded push_back method
128 std::vector<SCH_FIELD> fields;
129 m_libEntry->CopyFields( fields );
130
131 for( const SCH_FIELD& f : fields )
132 m_fields->push_back( f );
133
134 if( std::shared_ptr<LIB_SYMBOL> parent = m_libEntry->GetParent().lock() )
135 addInheritedFields( parent );
136
137 int minWidth = wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
138
139 for( int ii = 0; ii <= 7; ++ii )
140 {
141 if( m_grid->IsColShown( ii ) )
142 minWidth += m_grid->GetColSize( ii );
143 }
144
145 m_grid->SetMinSize( wxSize( minWidth, -1 ) );
146
147 // Putting too many columns in wxFormBuilder results in the minimum dialog size getting set too
148 // large (even with the m_grid->SetMinSize() call above).
149 m_grid->SetColSize( 13, 48 ); // "Color"
150 m_grid->SetColSize( 14, 136 ); // "Allow Autoplace"
151 m_grid->SetColSize( 15, 62 ); // "Private"
152 m_grid->SetupColumnAutosizer( 1 );
153
154 m_grid->ShowHideColumns( "0 1 2 3 4 5 6 7" );
155
157
158 m_unitNamesGrid->PushEventHandler( new GRID_TRICKS( m_unitNamesGrid ) );
159 m_unitNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
160 m_unitNamesGrid->SetupColumnAutosizer( 1 );
161
163 [this]( wxCommandEvent& aEvent )
164 {
165 OnAddBodyStyle( aEvent );
166 } ) );
167 m_bodyStyleNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
168 m_bodyStyleNamesGrid->SetupColumnAutosizer( 0 );
169
170 m_jumperGroupsGrid->SetupColumnAutosizer( 0 );
171 m_jumperGroupsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
172
173 m_jumperGroupsGrid->PushEventHandler( new GRID_TRICKS( m_jumperGroupsGrid,
174 [this]( wxCommandEvent& aEvent )
175 {
176 OnAddJumperGroup( aEvent );
177 } ) );
178
179 // Configure button logos
184
189
192
194
195 if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
196 {
197 m_stdSizerButtonCancel->SetDefault();
198 m_stdSizerButtonOK->SetLabel( _( "Read Only" ) );
199 m_stdSizerButtonOK->Enable( false );
200 }
201
202 // wxFormBuilder doesn't include this event...
203 m_grid->Bind( wxEVT_GRID_CELL_CHANGING, &DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging, this );
204 m_grid->Bind( wxEVT_GRID_CELL_CHANGED, &DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanged, this );
205 m_grid->GetGridWindow()->Bind( wxEVT_MOTION, &DIALOG_LIB_SYMBOL_PROPERTIES::OnGridMotion, this );
206
207 // Send a request to load footprint libs (if not loaded)
208 // This will shorten the time it takes to display the matching filters when the user swaps tabs
209 // or opens the footprint assignment dialog.
211
213 {
216 {
217 resetSize();
218 }
219 }
220
223
224 m_grid->GetParent()->Layout();
225 syncControlStates( m_libEntry->IsDerived() );
226 Layout();
227
229}
230
231
233{
234 // TransferDataToWindow restores the remembered page, so defer the switch to a flag it honours.
235 m_forcePinMapPage = true;
236
237 for( size_t page = 0; page < m_NoteBook->GetPageCount(); ++page )
238 {
239 if( m_NoteBook->GetPage( page ) == m_pinMapPage )
240 {
241 m_NoteBook->SetSelection( page );
242 return;
243 }
244 }
245}
246
247
249{
250 m_lastOpenedPage = m_NoteBook->GetSelection( );
251
252 // Prevents crash bug in wxGrid's d'tor
253 m_grid->DestroyTable( m_fields );
254
255 m_grid->Unbind( wxEVT_GRID_CELL_CHANGING, &DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging, this );
256 m_grid->Unbind( wxEVT_GRID_CELL_CHANGED, &DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanged, this );
257 m_grid->GetGridWindow()->Unbind( wxEVT_MOTION, &DIALOG_LIB_SYMBOL_PROPERTIES::OnGridMotion, this );
258
259 // Delete the GRID_TRICKS.
260 m_grid->PopEventHandler( true );
261 m_unitNamesGrid->PopEventHandler( true );
262 m_bodyStyleNamesGrid->PopEventHandler( true );
263 m_jumperGroupsGrid->PopEventHandler( true );
264}
265
266
267void DIALOG_LIB_SYMBOL_PROPERTIES::addInheritedFields( const std::shared_ptr<LIB_SYMBOL>& aParent )
268{
269 if( std::shared_ptr<LIB_SYMBOL> ancestor = aParent->GetParent().lock() )
270 addInheritedFields( ancestor );
271
272 wxString source = UnescapeString( aParent->GetName() );
273 std::vector<SCH_FIELD*> parentFields;
274 aParent->GetFields( parentFields );
275
276 for( SCH_FIELD* parentField : parentFields )
277 {
278 // Flatten() only passes down a mandatory field the ancestor actually sets
279 if( parentField->IsMandatory() && parentField->GetText().IsEmpty() )
280 continue;
281
282 bool found = false;
283
284 for( size_t ii = 0; ii < m_fields->size(); ++ii )
285 {
286 SCH_FIELD& field = m_fields->at( ii );
287 bool match = false;
288
289 if( parentField->IsMandatory() )
290 match = field.GetId() == parentField->GetId();
291 else if( !field.IsMandatory() )
292 match = field.GetUntranslatedName() == parentField->GetUntranslatedName();
293
294 if( match )
295 {
296 m_fields->SetFieldInherited( ii, *parentField, source );
297 found = true;
298 break;
299 }
300 }
301
302 if( !found && !parentField->IsMandatory() )
303 m_fields->AddInheritedField( *parentField, source );
304 }
305}
306
307
309{
310 if( !wxDialog::TransferDataToWindow() )
311 return false;
312
313 std::set<wxString> defined;
314
315 for( SCH_FIELD& field : *m_fields )
316 defined.insert( field.GetName() );
317
318 // Add in any global template field names not yet defined.
319 for( const TEMPLATE_FIELDNAME& templateFieldname :
320 Pgm().GetCommonSettings()->m_FieldNameTemplates.GetTemplateFieldNames( TEMPLATES::SCOPE::GLOBAL ) )
321 {
322 if( defined.count( templateFieldname.m_Name ) <= 0 )
323 {
324 SCH_FIELD field( m_libEntry, FIELD_T::USER, templateFieldname.m_Name );
325 field.SetVisible( templateFieldname.m_Visible );
326 m_fields->push_back( field );
327 m_addedTemplateFields.insert( templateFieldname.m_Name );
328 }
329 }
330
331 // The Y axis for components in library file is from bottom to top while the screen axis is top
332 // to bottom.However it is nowhandled by the lib file parser/writer.
333
334 // notify the grid
335 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
336 m_grid->ProcessTableMessage( msg );
337
338 m_SymbolNameCtrl->ChangeValue( UnescapeString( m_libEntry->GetName() ) );
339
340 // GetKeyWords() resolves through the parent, so saving it would turn inheritance into an override
341 m_KeywordCtrl->ChangeValue( m_libEntry->GetRawKeyWords() );
342
343 // Keywords are not a field, so the inherited value is shown as a hint
344 auto hasOwnKeyWords = []( const LIB_SYMBOL& aSymbol )
345 {
346 return !aSymbol.GetRawKeyWords().IsEmpty();
347 };
348
349 std::shared_ptr<LIB_SYMBOL> source = ancestorDefining( m_libEntry, hasOwnKeyWords );
350
351 if( source )
352 {
353 m_keywordsSource = UnescapeString( source->GetName() );
354 m_KeywordCtrl->SetHint( source->GetRawKeyWords() );
355 }
356
358
359 m_unitSpinCtrl->SetValue( m_libEntry->GetUnitCount() );
360 m_OptionPartsInterchangeable->SetValue( !m_libEntry->UnitsLocked() || m_libEntry->GetUnitCount() == 1 );
361
363
364 // The map accessor is raw storage, so a derived symbol has to be shown its root's names
365 std::shared_ptr<LIB_SYMBOL> root = m_libEntry->GetRootSymbol();
366 const std::map<int, wxString>& unitNames = root->GetUnitDisplayNames();
367
368 for( int unit = 0; unit < m_libEntry->GetUnitCount(); unit++ )
369 {
370 if( unitNames.contains( unit + 1 ) )
371 m_unitNamesGrid->SetCellValue( unit, 1, unitNames.at( unit + 1 ) );
372 }
373
374 if( m_libEntry->HasDeMorganBodyStyles() )
375 {
376 m_radioDeMorgan->SetValue( true );
377 }
378 else if( m_libEntry->IsMultiBodyStyle() )
379 {
380 m_radioCustom->SetValue( true );
381
382 for( const wxString& name : m_libEntry->GetBodyStyleNames() )
383 {
384 int row = m_bodyStyleNamesGrid->GetNumberRows();
385 m_bodyStyleNamesGrid->AppendRows( 1 );
386 m_bodyStyleNamesGrid->SetCellValue( row, 0, name );
387 }
388 }
389 else
390 {
391 m_radioSingle->SetValue( true );
392 }
393
395
396 m_OptionPower->SetValue( m_libEntry->IsPower() );
397 m_OptionLocalPower->SetValue( m_libEntry->IsLocalPower() );
398
399 if( m_libEntry->IsPower() )
400 {
401 m_spiceFieldsButton->Hide();
402 m_OptionLocalPower->Enable();
403 }
404 else
405 {
406 m_OptionLocalPower->Enable( false );
407 }
408
409 m_excludeFromSimCheckBox->SetValue( m_libEntry->GetExcludedFromSim() );
410 m_excludeFromBomCheckBox->SetValue( m_libEntry->GetExcludedFromBOM() );
411 m_excludeFromBoardCheckBox->SetValue( m_libEntry->GetExcludedFromBoard() );
412 m_excludeFromPosFilesCheckBox->SetValue( m_libEntry->GetExcludedFromPosFiles() );
413
414 m_ShowPinNumButt->SetValue( m_libEntry->GetShowPinNumbers() );
415 m_ShowPinNameButt->SetValue( m_libEntry->GetShowPinNames() );
416 m_PinsNameInsideButt->SetValue( m_libEntry->GetPinNameOffset() != 0 );
417 m_pinNameOffset.ChangeValue( m_libEntry->GetPinNameOffset() );
418
419 wxArrayString fpFilters = m_libEntry->GetFPFilters();
420 wxString fpFiltersSource;
421
422 if( m_libEntry->GetRawFPFilters().IsEmpty() )
423 {
424 m_inheritedFpFilters = fpFilters;
425
426 auto hasOwnFilters = []( const LIB_SYMBOL& aSymbol )
427 {
428 return !aSymbol.GetRawFPFilters().IsEmpty();
429 };
430
431 std::shared_ptr<LIB_SYMBOL> fpSource = ancestorDefining( m_libEntry, hasOwnFilters );
432
433 if( fpSource )
434 fpFiltersSource = UnescapeString( fpSource->GetName() );
435 }
436
437 m_fpFiltersPanel->SetFilters( fpFilters, fpFiltersSource );
438
439 m_cbDuplicatePinsAreJumpers->SetValue( m_libEntry->GetDuplicatePinNumbersAreJumpers() );
440
441 std::set<wxString> availablePins;
442
443 for( const SCH_PIN* pin : m_libEntry->GetGraphicalPins( 0, 0 ) )
444 availablePins.insert( pin->GetNumber() );
445
446 for( const JUMPER_GROUP& group : m_libEntry->JumperPinGroups().GetAll() )
447 {
448 wxString groupTxt;
449
450 for( const wxString& pinNumber : group.GetNames() )
451 {
452 if( !groupTxt.IsEmpty() )
453 groupTxt << ", ";
454
455 groupTxt << pinNumber;
456 }
457
458 m_jumperGroupsGrid->AppendRows( 1 );
459 m_jumperGroupsGrid->SetCellValue( m_jumperGroupsGrid->GetNumberRows() - 1, 0, groupTxt );
460 }
461
462 // Populate the list of root parts for inherited objects.
463 if( m_libEntry->IsDerived() )
464 {
465 wxArrayString symbolNames;
466 wxString libName = m_libEntry->GetLibNickname();
467
468 if( !libName.empty() )
469 {
470 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
471
472 // Sort the list of symbols for easier search
473 symbolNames.Sort( []( const wxString& a, const wxString& b ) -> int
474 {
475 return StrNumCmp( a, b, CMP_T::IGNORE_CASE );
476 } );
477
478 // Don't allow a symbol to be derived from itself
479 if( symbolNames.Index( m_libEntry->GetName() ) != wxNOT_FOUND )
480 symbolNames.Remove( m_libEntry->GetName() );
481
482 // Don't allow a symbol to be derived from any of its descendants (would create
483 // circular inheritance)
484 wxArrayString descendants;
485 m_Parent->GetLibManager().GetDerivedSymbolNames( m_libEntry->GetName(), libName, descendants );
486
487 for( const wxString& descendant : descendants )
488 {
489 if( symbolNames.Index( descendant ) != wxNOT_FOUND )
490 symbolNames.Remove( descendant );
491 }
492
493 m_inheritanceSelectCombo->Append( symbolNames );
494
495 if( std::shared_ptr<LIB_SYMBOL> rootSymbol = m_libEntry->GetParent().lock() )
496 {
497 wxString parentName = UnescapeString( rootSymbol->GetName() );
498 int selection = m_inheritanceSelectCombo->FindString( parentName );
499
500 if( selection != wxNOT_FOUND )
501 m_inheritanceSelectCombo->SetSelection( selection );
502 }
503 }
504
506 }
507
508 m_NoteBook->SetSelection( (unsigned) m_lastOpenedPage );
509
510 m_embeddedFiles->TransferDataToWindow();
511
512 m_grid->SetMinVisibleRows( this, 4 );
513
514 m_pinMapPanel->SetSymbol( m_libEntry );
515 m_pinMapPanel->TransferDataToWindow();
516
517 // Always open on the General page, unless the caller explicitly asked for the Pin Map
518 // tab (the Edit Pin Map button). This overrides DIALOG_SHIM's remembered-tab restore.
519 int targetPage = 0;
520
522 {
523 for( size_t page = 0; page < m_NoteBook->GetPageCount(); ++page )
524 {
525 if( m_NoteBook->GetPage( page ) == m_pinMapPage )
526 {
527 targetPage = (int) page;
528 break;
529 }
530 }
531 }
532
533 m_NoteBook->ChangeSelection( targetPage );
534
535 return true;
536}
537
538
540{
541 if( !m_grid->CommitPendingChanges() )
542 return false;
543
544 // Symbol reference can be empty because it inherits from the parent symbol.
545 if( m_libEntry->IsRoot() )
546 {
547 SCH_FIELD* field = m_fields->GetField( FIELD_T::REFERENCE );
548
549 if( UTIL::GetRefDesPrefix( field->GetText() ).IsEmpty() )
550 {
551 if( m_NoteBook->GetSelection() != 0 )
552 m_NoteBook->SetSelection( 0 );
553
554 m_delayedErrorMessage = _( "References must start with a letter." );
559
560 return false;
561 }
562 }
563
564 // Check for missing field names.
565 for( int ii = 0; ii < (int) m_fields->size(); ++ii )
566 {
567 SCH_FIELD& field = m_fields->at( ii );
568
569 if( field.IsMandatory() )
570 continue;
571
572 wxString fieldName = field.GetName( false );
573
574 if( fieldName.IsEmpty() && !field.GetText().IsEmpty() )
575 {
576 if( m_NoteBook->GetSelection() != 0 )
577 m_NoteBook->SetSelection( 0 );
578
579 m_delayedErrorMessage = _( "Fields must have a name." );
584
585 return false;
586 }
587 }
588
589 // Verify that the parent name is set if the symbol is inherited
590 if( m_libEntry->IsDerived() )
591 {
592 wxString parentName = m_inheritanceSelectCombo->GetValue();
593
594 if( parentName.IsEmpty() )
595 {
596 m_delayedErrorMessage = _( "Derived symbol must have a parent selected" );
597 return false;
598 }
599 }
600
601 if( !m_unitNamesGrid->CommitPendingChanges() )
602 return false;
603
604 std::set<wxString> seenSubRefs;
605
606 for( int row = 0; row < m_unitNamesGrid->GetNumberRows(); ++row )
607 {
608 wxString subRef = m_unitNamesGrid->GetCellValue( row, 1 );
609
610 if( subRef.IsEmpty() )
611 subRef = LIB_SYMBOL::LetterSubReference( row + 1, 'A' );
612
613 // For empty names we only check letter reference for collsions, which means the user _could_
614 // end up with a collision if they name a unit with a digit, and then use the symbol in a
615 // schematic which uses .digit, -digit or _digit notation for units. We'll leave that to ERC
616 // to catch.
617
618 if( !seenSubRefs.insert( subRef.Upper() ).second )
619 {
620 m_delayedErrorMessage = wxString::Format( _( "The unit name '%s' is already in use." ), subRef );
623 m_delayedFocusRow = row;
625 return false;
626 }
627 }
628
629 /*
630 * Confirm destructive actions.
631 */
632
633 if( m_unitSpinCtrl->GetValue() < m_libEntry->GetUnitCount() )
634 {
635 if( !IsOK( this, _( "Delete extra units from symbol?" ) ) )
636 return false;
637 }
638
639 int bodyStyleCount = 0;
640
641 if( m_radioSingle->GetValue() )
642 {
643 bodyStyleCount = 1;
644 }
645 else if( m_radioDeMorgan->GetValue() )
646 {
647 bodyStyleCount = 2;
648 }
649 else if( m_radioCustom->GetValue() )
650 {
651 if( !m_bodyStyleNamesGrid->CommitPendingChanges() )
652 return false;
653
654 for( int ii = 0; ii < m_bodyStyleNamesGrid->GetNumberRows(); ++ii )
655 {
656 if( !m_bodyStyleNamesGrid->GetCellValue( ii, 0 ).IsEmpty() )
657 bodyStyleCount++;
658 }
659 }
660
661 if( m_radioCustom->GetValue() && bodyStyleCount < 2 )
662 {
663 m_delayedErrorMessage = _( "Custom body styles must have at least 2 entries" );
664 return false;
665 }
666
667 if( bodyStyleCount < m_libEntry->GetBodyStyleCount() )
668 {
669 if( !IsOK( this, _( "Delete extra body styles from symbol?" ) ) )
670 return false;
671 }
672
673 return true;
674}
675
676
678{
679 if( !m_grid->CommitPendingChanges()
680 || !m_unitNamesGrid->CommitPendingChanges()
681 || !m_bodyStyleNamesGrid->CommitPendingChanges()
682 || !m_jumperGroupsGrid->CommitPendingChanges()
683 || !m_pinMapPanel->CommitPendingChanges()
684 || !m_embeddedFiles->CommitPendingChanges() )
685 {
686 return false;
687 }
688
689 wxString newName = EscapeString( m_SymbolNameCtrl->GetValue(), CTX_LIBID );
690 wxString oldName = m_libEntry->GetName();
691
692 if( newName.IsEmpty() )
693 {
694 wxMessageBox( _( "Symbol must have a name." ) );
695 return false;
696 }
697
699
700 if( oldName != newName )
701 {
702 wxString libName = m_libEntry->GetLibNickname();
703
704 if( !libName.empty() && m_Parent->GetLibManager().SymbolNameInUse( newName, libName ) )
705 {
706 DisplayErrorMessage( this, wxString::Format( _( "Symbol name '%s' already in use in library '%s'." ),
707 UnescapeString( newName ),
708 libName ) );
709 return false;
710 }
711
712 opType = UNDO_REDO::LIB_RENAME;
713 }
714
715 // When invoked from the library tree (Symbol Properties context menu) we edit a buffered
716 // copy that is not the symbol loaded in the editor. The editor-coupled side effects below
717 // (undo list, view/title refresh) operate on the frame's current symbol, so only run them
718 // when we are actually editing it. The library-tree path does its own buffer/tree update.
719 bool editingCurrentSymbol = ( m_libEntry == m_Parent->GetCurSymbol() );
720
721 if( editingCurrentSymbol )
722 m_Parent->SaveCopyInUndoList( _( "Edit Symbol Properties" ), m_libEntry, opType );
723
724 // The Y axis for components in lib is from bottom to top while the screen axis is top
725 // to bottom: we must change the y coord sign when writing back to the library
726 std::vector<SCH_FIELD> fieldsToSave;
727 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
728
729 for( size_t ii = 0; ii < m_fields->size(); ++ii )
730 {
731 SCH_FIELD& field = m_fields->at( ii );
732
733 if( !field.IsMandatory() )
734 field.SetOrdinal( ordinal++, FIELD_T::USER );
735
736 wxString fieldName = field.GetUntranslatedName();
737
738 // Writing an unmodified inherited row into the derived symbol would stop it from
739 // tracking the parent field, and an empty mandatory field is how the symbol inherits it
740 if( m_fields->IsInherited( ii ) )
741 {
742 if( field.IsMandatory() )
743 {
744 SCH_FIELD emptyField( *m_libEntry->GetField( field.GetId() ) );
745 emptyField.SetText( wxEmptyString );
746 fieldsToSave.push_back( emptyField );
747 }
748
749 continue;
750 }
751
752 if( field.GetText().IsEmpty() )
753 {
754 if( fieldName.IsEmpty() || m_addedTemplateFields.contains( fieldName ) )
755 continue; // Skip empty fields that are not mandatory or template fields
756 }
757 else if( fieldName.IsEmpty() )
758 {
759 field.SetName( _( "untitled" ) ); // Set a default name for unnamed fields
760 }
761
762 fieldsToSave.push_back( field );
763 }
764
765 m_libEntry->SetFields( fieldsToSave );
766
767 // Update the parent for inherited symbols
768 if( m_libEntry->IsDerived() && !m_libEntry->GetLibNickname().empty() )
769 {
770 wxString parentName = EscapeString( m_inheritanceSelectCombo->GetValue(), CTX_LIBID );
771 wxString libName = m_libEntry->GetLibNickname();
772
773 // Get the parent from the libManager based on the name set in the inheritance combo box.
774 LIB_SYMBOL* newParent = m_Parent->GetLibManager().GetSymbol( parentName, libName );
775
776 // Verify that the requested parent exists
777 wxCHECK( newParent, false );
778
779 m_libEntry->SetParent( newParent );
780 }
781
782 m_libEntry->SetName( newName );
783 m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() );
784
785 // A derived symbol owns no drawings, so none of this is its to change and none of it is
786 // written out on save
787 if( !m_libEntry->IsDerived() )
788 {
789 m_libEntry->SetUnitCount( m_unitSpinCtrl->GetValue(), true );
790 m_libEntry->LockUnits( m_libEntry->GetUnitCount() > 1 && !m_OptionPartsInterchangeable->GetValue() );
791
792 m_libEntry->GetUnitDisplayNames().clear();
793
794 for( int row = 0; row < m_unitNamesGrid->GetNumberRows(); row++ )
795 {
796 if( !m_unitNamesGrid->GetCellValue( row, 1 ).IsEmpty() )
797 m_libEntry->GetUnitDisplayNames()[row+1] = m_unitNamesGrid->GetCellValue( row, 1 );
798 }
799
800 // SetBodyStyleCount() adds and deletes draw items relative to the current count, so it
801 // has to run before the flag and the names it derives from are overwritten
802 if( m_radioSingle->GetValue() )
803 {
804 m_libEntry->SetBodyStyleCount( 1, false, false );
805 m_libEntry->SetHasDeMorganBodyStyles( false );
806 m_libEntry->SetBodyStyleNames( {} );
807 }
808 else if( m_radioDeMorgan->GetValue() )
809 {
810 m_libEntry->SetBodyStyleCount( 2, false, true );
811 m_libEntry->SetHasDeMorganBodyStyles( true );
812 m_libEntry->SetBodyStyleNames( {} );
813 }
814 else
815 {
816 std::vector<wxString> bodyStyleNames;
817
818 for( int row = 0; row < m_bodyStyleNamesGrid->GetNumberRows(); ++row )
819 {
820 if( !m_bodyStyleNamesGrid->GetCellValue( row, 0 ).IsEmpty() )
821 bodyStyleNames.push_back( m_bodyStyleNamesGrid->GetCellValue( row, 0 ) );
822 }
823
824 m_libEntry->SetBodyStyleCount( bodyStyleNames.size(), true, true );
825 m_libEntry->SetHasDeMorganBodyStyles( false );
826 m_libEntry->SetBodyStyleNames( bodyStyleNames );
827 }
828 }
829
830 if( m_OptionPower->GetValue() )
831 {
832 if( m_OptionLocalPower->GetValue() )
833 m_libEntry->SetLocalPower();
834 else
835 m_libEntry->SetGlobalPower();
836 }
837 else
838 {
839 m_libEntry->SetNormal();
840 }
841
842 m_libEntry->SetExcludedFromSim( m_excludeFromSimCheckBox->GetValue() );
843 m_libEntry->SetExcludedFromBOM( m_excludeFromBomCheckBox->GetValue() );
844 m_libEntry->SetExcludedFromBoard( m_excludeFromBoardCheckBox->GetValue() );
845 m_libEntry->SetExcludedFromPosFiles( m_excludeFromPosFilesCheckBox->GetValue() );
846
847 m_libEntry->SetShowPinNumbers( m_ShowPinNumButt->GetValue() );
848 m_libEntry->SetShowPinNames( m_ShowPinNameButt->GetValue() );
849
850 if( m_PinsNameInsideButt->GetValue() )
851 {
852 int offset = KiROUND( (double) m_pinNameOffset.GetValue() );
853
854 // We interpret an offset of 0 as "outside", so make sure it's non-zero
855 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
856 }
857 else
858 {
859 m_libEntry->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
860 }
861
862 wxArrayString fpFilters = m_fpFiltersPanel->GetFilters();
863
864 m_libEntry->SetFPFilters( fpFilters == m_inheritedFpFilters ? wxArrayString() : fpFilters );
865
866 m_libEntry->SetDuplicatePinNumbersAreJumpers( m_cbDuplicatePinsAreJumpers->GetValue() );
867
868 JUMPER_GROUP_SET jumpers;
869
870 for( int ii = 0; ii < m_jumperGroupsGrid->GetNumberRows(); ++ii )
871 {
872 wxStringTokenizer tokenizer( m_jumperGroupsGrid->GetCellValue( ii, 0 ), ", \t\r\n", wxTOKEN_STRTOK );
873 std::set<wxString> names;
874
875 while( tokenizer.HasMoreTokens() )
876 {
877 wxString token = tokenizer.GetNextToken();
878
879 if( token.IsEmpty() )
880 continue;
881
882 if( !m_libEntry->HasPinNumber( token ) )
883 {
884 DisplayErrorMessage( this, wxString::Format( _( "Pin '%s' in jumper pin group %d does not exist "
885 "in this symbol." ),
886 token,
887 ii + 1 ) );
888 return false;
889 }
890
891 names.insert( token );
892 }
893
894 if( std::optional<JUMPER_GROUP> group = JUMPER_GROUP::Make( std::move( names ) ) )
895 jumpers.Add( std::move( *group ) );
896 }
897
898 m_libEntry->JumperPinGroups() = jumpers;
899
900 m_pinMapPanel->ApplyToSymbol( m_libEntry );
901
902 (void) m_embeddedFiles->TransferDataFromWindow();
903
904 if( editingCurrentSymbol )
905 m_Parent->UpdateAfterSymbolProperties( &oldName );
906
907 return true;
908}
909
910
911void DIALOG_LIB_SYMBOL_PROPERTIES::OnBodyStyle( wxCommandEvent& event )
912{
913 if( event.GetEventObject() == m_radioDeMorgan || event.GetEventObject() == m_radioCustom )
914 {
915 PIN_NUMBERS pinNumbersWithAlternates;
916
917 for( SCH_PIN* pin : m_libEntry->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ) )
918 {
919 if( !pin->GetAlternates().empty() )
920 pinNumbersWithAlternates.insert( pin->GetNumber() );
921 }
922
923 if( pinNumbersWithAlternates.size() )
924 {
926 wxString::Format( _( "(Pins %s.)" ), pinNumbersWithAlternates.GetSummary() ) );
927
928 m_radioSingle->SetValue( true );
929 return;
930 }
931 }
932
934}
935
936
938{
939 aEvent.Skip();
940
941 wxPoint pos = aEvent.GetPosition();
942 wxPoint unscolled_pos = m_grid->CalcUnscrolledPosition( pos );
943 int row = m_grid->YToRow( unscolled_pos.y );
944 int col = m_grid->XToCol( unscolled_pos.x );
945
946 if( row == wxNOT_FOUND || col == wxNOT_FOUND || !m_fields->IsInherited( row ) )
947 {
948 m_grid->SetToolTip( "" );
949 return;
950 }
951
952 m_grid->SetToolTip( wxString::Format( _( "This field is inherited from '%s'." ), m_fields->InheritedFrom( row ) ) );
953}
954
955
957{
958 wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
959 wxControl* control = editor->GetControl();
960
961 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
962 {
963 event.Veto();
964
966 m_delayedFocusRow = event.GetRow();
967 m_delayedFocusColumn = event.GetCol();
969 }
970 else if( event.GetCol() == FDC_NAME )
971 {
972 wxString newName = event.GetString();
973
974 for( int i = 0; i < m_grid->GetNumberRows(); ++i )
975 {
976 if( i == event.GetRow() )
977 continue;
978
979 if( FieldNamesAreDuplicates( newName, m_grid->GetCellValue( i, FDC_NAME ) ) )
980 {
981 DisplayErrorMessage( this, wxString::Format( _( "The name '%s' is already in use." ), newName ) );
982 event.Veto();
983 m_delayedFocusRow = event.GetRow();
984 m_delayedFocusColumn = event.GetCol();
985 }
986 }
987 }
988
989 editor->DecRef();
990}
991
992
994{
995 m_grid->ForceRefresh();
996 OnModify();
997}
998
999
1001{
1002 OnModify();
1003}
1004
1005
1007{
1008 if( !m_delayedFocusCtrl )
1009 {
1010 // If the validation fails and we throw up a dialog then GTK will give us another
1011 // KillFocus event and we end up in infinite recursion. So we use m_delayedFocusCtrl
1012 // as a re-entrancy block and then clear it again if validation passes.
1015
1016 if( m_SymbolNameCtrl->GetValidator()->Validate( m_SymbolNameCtrl ) )
1017 {
1018 m_delayedFocusCtrl = nullptr;
1019 m_delayedFocusPage = -1;
1020 }
1021 }
1022
1023 event.Skip();
1024}
1025
1026
1027void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
1028{
1029 m_grid->OnAddRow(
1030 [&]() -> std::pair<int, int>
1031 {
1032 SYMBOL_EDITOR_SETTINGS* settings = m_Parent->GetSettings();
1034
1035 newField.SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
1036 schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
1037 newField.SetVisible( false );
1038
1039 m_fields->push_back( newField );
1040
1041 // notify the grid
1042 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1043 m_grid->ProcessTableMessage( msg );
1044 OnModify();
1045
1046 return { m_fields->size() - 1, FDC_NAME };
1047 } );
1048}
1049
1050
1052{
1053 m_grid->OnDeleteRows(
1054 [&]( int row )
1055 {
1056 if( row < m_fields->GetMandatoryRowCount() )
1057 {
1058 DisplayErrorMessage( this, wxString::Format( _( "The first %d fields are mandatory." ),
1059 m_fields->GetMandatoryRowCount() ) );
1060 return false;
1061 }
1062
1063 return true;
1064 },
1065 [&]( int row )
1066 {
1067 if( !m_fields->EraseRow( row ) )
1068 return;
1069
1070 // notify the grid
1071 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
1072 m_grid->ProcessTableMessage( msg );
1073 } );
1074
1075 OnModify();
1076}
1077
1078
1079void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
1080{
1081 m_grid->OnMoveRowUp(
1082 [&]( int row )
1083 {
1084 return row > m_fields->GetMandatoryRowCount();
1085 },
1086 [&]( int row )
1087 {
1088 m_fields->SwapRows( row, row - 1 );
1089 m_grid->ForceRefresh();
1090 OnModify();
1091 } );
1092}
1093
1094
1095void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
1096{
1097 m_grid->OnMoveRowDown(
1098 [&]( int row )
1099 {
1100 return row >= m_fields->GetMandatoryRowCount();
1101 },
1102 [&]( int row )
1103 {
1104 m_fields->SwapRows( row, row + 1 );
1105 m_grid->ForceRefresh();
1106 OnModify();
1107 } );
1108}
1109
1110
1112{
1113 m_bodyStyleNamesGrid->OnAddRow(
1114 [&]() -> std::pair<int, int>
1115 {
1116 m_bodyStyleNamesGrid->AppendRows( 1 );
1117 OnModify();
1118
1119 return { m_bodyStyleNamesGrid->GetNumberRows() - 1, 0 };
1120 } );
1121}
1122
1123
1125{
1126 m_bodyStyleNamesGrid->OnDeleteRows(
1127 [&]( int row )
1128 {
1129 m_bodyStyleNamesGrid->DeleteRows( row );
1130 } );
1131
1132 OnModify();
1133}
1134
1135
1137{
1138 m_bodyStyleNamesGrid->OnMoveRowUp(
1139 [&]( int row )
1140 {
1141 m_bodyStyleNamesGrid->SwapRows( row, row - 1 );
1142 OnModify();
1143 } );
1144}
1145
1146
1148{
1149 m_bodyStyleNamesGrid->OnMoveRowDown(
1150 [&]( int row )
1151 {
1152 m_bodyStyleNamesGrid->SwapRows( row, row + 1 );
1153 OnModify();
1154 } );
1155}
1156
1157
1159{
1160 if( !m_grid->CommitPendingChanges() )
1161 return;
1162
1163 m_grid->ClearSelection();
1164
1165 std::vector<SCH_FIELD> fields;
1166
1167 for( const SCH_FIELD& field : *m_fields )
1168 fields.emplace_back( field );
1169
1170 DIALOG_SIM_MODEL dialog( this, m_parentFrame, *m_libEntry, fields );
1171
1172 if( dialog.ShowModal() != wxID_OK )
1173 return;
1174
1175 // Add in any new fields
1176 for( const SCH_FIELD& editedField : fields )
1177 {
1178 bool found = false;
1179
1180 for( SCH_FIELD& existingField : *m_fields )
1181 {
1182 if( existingField.GetName() == editedField.GetName() )
1183 {
1184 found = true;
1185 existingField.SetText( editedField.GetText() );
1186 break;
1187 }
1188 }
1189
1190 if( !found )
1191 {
1192 m_fields->emplace_back( editedField );
1193 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1194 m_grid->ProcessTableMessage( msg );
1195 }
1196 }
1197
1198 // Remove any deleted fields
1199 for( int ii = (int) m_fields->size() - 1; ii >= 0; --ii )
1200 {
1201 SCH_FIELD& existingField = m_fields->at( ii );
1202 bool found = false;
1203
1204 for( SCH_FIELD& editedField : fields )
1205 {
1206 if( editedField.GetName() == existingField.GetName() )
1207 {
1208 found = true;
1209 break;
1210 }
1211 }
1212
1213 if( !found )
1214 {
1215 m_grid->ClearSelection();
1216
1217 // An inherited row resets to the ancestor's value instead of disappearing
1218 if( !m_fields->EraseRow( ii ) )
1219 continue;
1220
1221 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
1222 m_grid->ProcessTableMessage( msg );
1223 }
1224 }
1225
1226 OnModify();
1227 m_grid->ForceRefresh();
1228}
1229
1230
1232{
1233 // Running the Footprint Browser gums up the works and causes the automatic cancel
1234 // stuff to no longer work. So we do it here ourselves.
1235 EndDialogShim( wxID_CANCEL );
1236}
1237
1238
1240{
1241 int row = m_fields->GetFieldRow( FIELD_T::FOOTPRINT );
1242
1243 // The footprint field is read-only for a power symbol, which has no footprint.
1244 return row != -1 && !m_grid->IsReadOnly( row, FDC_VALUE );
1245}
1246
1247
1248void DIALOG_LIB_SYMBOL_PROPERTIES::assignFootprintToField( const wxString& aFootprintName )
1249{
1250 int row = m_fields->GetFieldRow( FIELD_T::FOOTPRINT );
1251
1252 if( row == -1 )
1253 return;
1254
1255 m_grid->SetCellValue( row, FDC_VALUE, aFootprintName );
1256 m_grid->ForceRefresh();
1257 OnModify();
1258}
1259
1260
1261void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
1262{
1263 m_OptionPartsInterchangeable->Enable( !m_libEntry->IsDerived() && m_unitSpinCtrl->GetValue() > 1 );
1264 m_pinNameOffset.Enable( m_PinsNameInsideButt->GetValue() );
1265
1266 // Handle shown columns changes
1267 std::bitset<64> shownColumns = m_grid->GetShownColumns();
1268
1269 if( shownColumns != m_shownColumns )
1270 {
1271 m_shownColumns = shownColumns;
1272
1273 if( !m_grid->IsCellEditControlShown() )
1274 m_grid->SetGridWidthsDirty();
1275 }
1276
1277 // Handle a delayed focus. The delay allows us to:
1278 // a) change focus when the error was triggered from within a killFocus handler
1279 // b) show the correct notebook page in the background before the error dialog comes up
1280 // when triggered from an OK or a notebook page change
1281
1282 if( m_delayedFocusPage >= 0 && m_NoteBook->GetSelection() != m_delayedFocusPage )
1283 {
1284 m_NoteBook->ChangeSelection( (unsigned) m_delayedFocusPage );
1285 m_delayedFocusPage = -1;
1286 }
1287
1288 if( !m_delayedErrorMessage.IsEmpty() )
1289 {
1290 // We will re-enter this routine when the error dialog is displayed, so make
1291 // sure we don't keep putting up more dialogs.
1292 wxString msg = m_delayedErrorMessage;
1293 m_delayedErrorMessage = wxEmptyString;
1294
1295 // Do not use DisplayErrorMessage(); it screws up window order on Mac
1296 DisplayError( nullptr, msg );
1297 }
1298
1299 if( m_delayedFocusCtrl )
1300 {
1301 m_delayedFocusCtrl->SetFocus();
1302
1303 if( wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
1304 textEntry->SelectAll();
1305
1306 m_delayedFocusCtrl = nullptr;
1307 }
1308 else if( m_delayedFocusGrid )
1309 {
1310 m_delayedFocusGrid->SetFocus();
1313
1314 m_delayedFocusGrid->EnableCellEditControl( true );
1315 m_delayedFocusGrid->ShowCellEditControl();
1316
1317 m_delayedFocusGrid = nullptr;
1318 m_delayedFocusRow = -1;
1320 }
1321}
1322
1323
1325{
1326 bSizerLowerBasicPanel->Show( !aIsAlias );
1327 m_inheritanceSelectCombo->Enable( aIsAlias );
1328 m_inheritsStaticText->Enable( aIsAlias );
1329
1330 // The drawings a derived symbol inherits carry the units and body styles with them
1331 m_unitSpinCtrl->Enable( !aIsAlias );
1332 m_unitNamesGrid->Enable( !aIsAlias );
1333
1335
1336 m_grid->ForceRefresh();
1337}
1338
1339
1341{
1342 bool editable = !m_libEntry->IsDerived();
1343 bool custom = editable && m_radioCustom->GetValue();
1344
1345 m_radioSingle->Enable( editable );
1346 m_radioDeMorgan->Enable( editable );
1347 m_radioCustom->Enable( editable );
1348
1349 m_bodyStyleNamesGrid->Enable( custom );
1350 m_bpAddBodyStyle->Enable( custom );
1351 m_bpMoveUpBodyStyle->Enable( custom );
1352 m_bpMoveDownBodyStyle->Enable( custom );
1353 m_bpDeleteBodyStyle->Enable( custom );
1354}
1355
1356
1358{
1359 if( m_OptionPower->IsChecked() )
1360 {
1361 m_excludeFromSimCheckBox->SetValue( true );
1362 m_excludeFromBomCheckBox->SetValue( true );
1363 m_excludeFromBoardCheckBox->SetValue( true );
1364 m_excludeFromPosFilesCheckBox->SetValue( true );
1365 m_excludeFromBomCheckBox->Enable( false );
1366 m_excludeFromBoardCheckBox->Enable( false );
1367 m_excludeFromSimCheckBox->Enable( false );
1368 m_excludeFromPosFilesCheckBox->Enable( false );
1369 m_spiceFieldsButton->Show( false );
1370 m_OptionLocalPower->Enable( true );
1371 }
1372 else
1373 {
1374 m_excludeFromBomCheckBox->Enable( true );
1375 m_excludeFromBoardCheckBox->Enable( true );
1376 m_excludeFromSimCheckBox->Enable( true );
1377 m_excludeFromPosFilesCheckBox->Enable( true );
1378 m_spiceFieldsButton->Show( true );
1379 m_OptionLocalPower->Enable( false );
1380 }
1381
1382 OnModify();
1383}
1384
1385
1387{
1388 if( !m_keywordsSource.IsEmpty() && m_KeywordCtrl->IsEmpty() )
1389 m_KeywordCtrl->SetToolTip( wxString::Format( _( "This field is inherited from '%s'." ), m_keywordsSource ) );
1390 else
1391 m_KeywordCtrl->UnsetToolTip();
1392}
1393
1394
1395void DIALOG_LIB_SYMBOL_PROPERTIES::OnText( wxCommandEvent& event )
1396{
1397 if( event.GetEventObject() == m_KeywordCtrl )
1399
1400 OnModify();
1401}
1402
1403
1404void DIALOG_LIB_SYMBOL_PROPERTIES::OnCombobox( wxCommandEvent& event )
1405{
1406 OnModify();
1407}
1408
1409
1410void DIALOG_LIB_SYMBOL_PROPERTIES::OnCheckBox( wxCommandEvent& event )
1411{
1412 OnModify();
1413}
1414
1415
1417{
1418 m_unitNamesGrid->CommitPendingChanges( true /* aQuietMode */ );
1419
1420 int extra = m_unitNamesGrid->GetNumberRows() - m_unitSpinCtrl->GetValue();
1421 int needed = m_unitSpinCtrl->GetValue() - m_unitNamesGrid->GetNumberRows();
1422
1423 if( extra > 0 )
1424 {
1425 m_unitNamesGrid->DeleteRows( m_unitNamesGrid->GetNumberRows() - extra, extra );
1426 return true;
1427 }
1428
1429 if( needed > 0 )
1430 {
1431 m_unitNamesGrid->AppendRows( needed );
1432
1433 for( int row = m_unitNamesGrid->GetNumberRows() - needed; row < m_unitNamesGrid->GetNumberRows(); ++row )
1434 m_unitNamesGrid->SetCellValue( row, 0, LIB_SYMBOL::LetterSubReference( row + 1, 'A' ) );
1435
1436 return true;
1437 }
1438
1439 return false;
1440}
1441
1442
1444{
1445 if( updateUnitCount() )
1446 OnModify();
1447}
1448
1449
1451{
1452 // wait for kill focus to update unit count
1453}
1454
1455
1457{
1458 if( updateUnitCount() )
1459 OnModify();
1460}
1461
1462
1464{
1465 if( updateUnitCount() )
1466 OnModify();
1467}
1468
1469
1471{
1472 if( !m_grid->CommitPendingChanges() )
1473 aEvent.Veto();
1474}
1475
1476
1478{
1479 m_jumperGroupsGrid->OnAddRow(
1480 [&]() -> std::pair<int, int>
1481 {
1482 m_jumperGroupsGrid->AppendRows( 1 );
1483 OnModify();
1484
1485 return { m_jumperGroupsGrid->GetNumberRows() - 1, 0 };
1486 } );
1487}
1488
1489
1491{
1492 m_jumperGroupsGrid->OnDeleteRows(
1493 [&]( int row )
1494 {
1495 m_jumperGroupsGrid->DeleteRows( row, 1 );
1496 } );
1497
1498 OnModify();
1499}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
DIALOG_LIB_SYMBOL_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=ID_LIBEDIT_NOTEBOOK, const wxString &title=_("Library Symbol Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnSymbolNameKillFocus(wxFocusEvent &event) override
void OnUnitSpinCtrlText(wxCommandEvent &event) override
void OnPageChanging(wxNotebookEvent &event) override
void OnBodyStyle(wxCommandEvent &event) override
wxString m_keywordsSource
Ancestor supplying the keywords while the symbol leaves them empty.
DIALOG_LIB_SYMBOL_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aLibEntry)
void OnUpdateUI(wxUpdateUIEvent &event) override
void OnBodyStyleMoveUp(wxCommandEvent &event) override
void OnCancelButtonClick(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
void OnCombobox(wxCommandEvent &event) override
void OnUnitSpinCtrlEnter(wxCommandEvent &event) override
void OnAddBodyStyle(wxCommandEvent &event) override
void OnMoveUp(wxCommandEvent &event) override
void OnDeleteBodyStyle(wxCommandEvent &event) override
void OnAddJumperGroup(wxCommandEvent &event) override
void OnText(wxCommandEvent &event) override
void OnUnitSpinCtrlKillFocus(wxFocusEvent &event) override
void OnMoveDown(wxCommandEvent &event) override
void SelectPinMapPage()
Switch the notebook to the Pin Map page (issue #2282).
bool m_forcePinMapPage
When set by SelectPinMapPage(), TransferDataToWindow opens the Pin Map page instead of the remembered...
void OnCheckBox(wxCommandEvent &event) override
void OnSymbolNameText(wxCommandEvent &event) override
void assignFootprintToField(const wxString &aFootprintName)
void OnBodyStyleMoveDown(wxCommandEvent &event) override
void OnRemoveJumperGroup(wxCommandEvent &event) override
void onPowerCheckBox(wxCommandEvent &aEvent) override
void OnAddField(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void addInheritedFields(const std::shared_ptr< LIB_SYMBOL > &aParent)
void OnUnitSpinCtrl(wxSpinEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void resetSize()
Clear the existing dialog size and position.
void EndDialogShim(int aReturnCode)
A mode agnostic way to close a dialog.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
EDA_BASE_FRAME * m_parentFrame
int ShowModal() override
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:513
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
A text control validator used for validating the text allowed in fields.
Definition validators.h:137
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:61
Represents an (ordered) list of JUMPER_GROUP objects.
void Add(JUMPER_GROUP aGroup)
Add a JUMPER_GROUP to the set.
Represents a group of jumper pins or pads, keyed by name.
static std::optional< JUMPER_GROUP > Make(std::set< wxString > aNames)
Factory method to create a JUMPER_GROUP from a set of names.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Define a library symbol object.
Definition lib_symbol.h:114
std::weak_ptr< LIB_SYMBOL > & GetParent()
Definition lib_symbol.h:152
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition lib_symbol.h:240
bool IsDerived() const
Definition lib_symbol.h:241
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
The footprint filters/matches panel of the symbol properties dialog.
Composed widget that edits a symbol's named pin maps and the footprint each is bound to.
container_type::size_type size() const
Definition pin_numbers.h:70
void insert(value_type const &v)
Definition pin_numbers.h:58
wxString GetSummary() const
bool IsMandatory() const
void SetOrdinal(int aOrdinal, FIELD_T aType)
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
FIELD_T GetId() const
Definition sch_field.h:143
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
The symbol library editor main window.
bool IsSymbolFromLegacyLibrary() const
bool IsSymbolFromSchematic() const
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
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.
bool(*)(const LIB_SYMBOL &) HAS_OWN_VALUE
Reports whether a symbol sets its own value for some inheritable property.
static std::shared_ptr< LIB_SYMBOL > ancestorDefining(const LIB_SYMBOL *aSymbol, HAS_OWN_VALUE aHasOwn)
Return the nearest ancestor of aSymbol that sets its own value, as reported by aHasOwn,...
#define _(s)
@ FDC_NAME
@ FDC_VALUE
bool StartFootprintLibrariesLoad(KIWAY &aKiway)
Start loading the footprint libraries in the background.
std::string source
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Collection of utility functions for component reference designators (refdes)
#define NO_BODY_STYLES_WITH_ALTERNATE_PIN_FUNCTIONS
Definition sch_actions.h:37
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
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:...
@ IGNORE_CASE
@ CTX_LIBID
Hold a name of a symbol's field, field value, and default visibility.
#define ALL_UNITS
Definition symbol.h:150
#define ALL_BODY_STYLES
Definition symbol.h:151
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ TRANSLATED
KIBIS_PIN * pin
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708