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 (C) 1992-2023 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <bitmaps.h>
25#include <confirm.h>
27#include <kiway.h>
28#include <symbol_edit_frame.h>
30#include <math/util.h> // for KiROUND
31#include <sch_symbol.h>
32#include <kiplatform/ui.h>
34#include <widgets/wx_grid.h>
36#include <string_utils.h>
37
38#include <dialog_sim_model.h>
39
43
44
48
49
51 LIB_SYMBOL* aLibEntry ) :
53 m_Parent( aParent ),
54 m_libEntry( aLibEntry ),
55 m_pinNameOffset( aParent, m_nameOffsetLabel, m_nameOffsetCtrl, m_nameOffsetUnits, true ),
56 m_delayedFocusCtrl( nullptr ),
57 m_delayedFocusGrid( nullptr ),
58 m_delayedFocusRow( -1 ),
59 m_delayedFocusColumn( -1 ),
60 m_delayedFocusPage( -1 )
61{
62 // Give a bit more room for combobox editors
63 m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
66 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this,
67 [&]( wxCommandEvent& aEvent )
68 {
69 OnAddField( aEvent );
70 } ) );
71 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
72
73 // Show/hide columns according to the user's preference
76
77 wxGridCellAttr* attr = new wxGridCellAttr;
78 attr->SetEditor( new GRID_CELL_URL_EDITOR( this, Prj().SchSearchS() ) );
79 m_grid->SetAttr( DATASHEET_FIELD, FDC_VALUE, attr );
80
82
83 // Configure button logos
84 m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
85 m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
86 m_bpMoveUp->SetBitmap( KiBitmap( BITMAPS::small_up ) );
87 m_bpMoveDown->SetBitmap( KiBitmap( BITMAPS::small_down ) );
88 m_addFilterButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
89 m_deleteFilterButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
90 m_editFilterButton->SetBitmap( KiBitmap( BITMAPS::small_edit ) );
91
93
94 if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
95 {
96 m_stdSizerButtonCancel->SetDefault();
97 m_stdSizerButtonOK->SetLabel( _( "Read Only" ) );
98 m_stdSizerButtonOK->Enable( false );
99 }
100
101 // wxFormBuilder doesn't include this event...
102 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
104 nullptr, this );
105
107 {
110 {
111 resetSize();
112 }
113 }
114
117
118 m_grid->GetParent()->Layout();
120 Layout();
121
123}
124
125
127{
128 m_lastOpenedPage = m_NoteBook->GetSelection( );
129
131 cfg->m_EditSymbolVisibleColumns = m_grid->GetShownColumnsAsString();
132
133 // Prevents crash bug in wxGrid's d'tor
135
136 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
138 nullptr, this );
139
140 // Delete the GRID_TRICKS.
141 m_grid->PopEventHandler( true );
142}
143
144
146{
147 if( !wxDialog::TransferDataToWindow() )
148 return false;
149
150 // Push a copy of each field into m_updateFields
152
153 // The Y axis for components in lib is from bottom to top while the screen axis is top
154 // to bottom: we must change the y coord sign for editing
155 for( size_t i = 0; i < m_fields->size(); ++i )
156 {
157 VECTOR2I pos = m_fields->at( i ).GetPosition();
158 pos.y = -pos.y;
159 m_fields->at( i ).SetPosition( pos );
160 }
161
162 // notify the grid
163 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
164 m_grid->ProcessTableMessage( msg );
166
168
169 m_KeywordCtrl->ChangeValue( m_libEntry->GetKeyWords() );
172 m_libEntry->GetUnitCount() == 1 );
173
174 // If a symbol contains no conversion-specific pins or graphic items, symbol->HasConversion()
175 // will return false. But when editing a symbol with DeMorgan option set, we don't want to
176 // keep turning it off just because there aren't any conversion-specific items yet, so we force
177 // it to on if the parent frame has it enabled.
179
180 m_OptionPower->SetValue( m_libEntry->IsPower() );
181
182 if( m_libEntry->IsPower() )
183 m_spiceFieldsButton->Hide();
184
188
193
194 wxArrayString tmp = m_libEntry->GetFPFilters();
195 m_FootprintFilterListBox->Append( tmp );
196
197 // Populate the list of root parts for inherited objects.
198 if( m_libEntry->IsAlias() )
199 {
200 wxArrayString symbolNames;
201 wxString libName = m_Parent->GetCurLib();
202
203 // Someone forgot to set the current library in the editor frame window.
204 wxCHECK( !libName.empty(), false );
205
206 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
207
208 // Do allow an inherited symbol to be derived from itself.
209 symbolNames.Remove( m_libEntry->GetName() );
210 m_inheritanceSelectCombo->Append( symbolNames );
211
212 LIB_SYMBOL_SPTR rootSymbol = m_libEntry->GetParent().lock();
213
214 wxCHECK( rootSymbol, false );
215
216 wxString parentName = UnescapeString( rootSymbol->GetName() );
217 int selection = m_inheritanceSelectCombo->FindString( parentName );
218
219 wxCHECK( selection != wxNOT_FOUND, false );
220 m_inheritanceSelectCombo->SetSelection( selection );
221
223 }
224
225 m_NoteBook->SetSelection( (unsigned) m_lastOpenedPage );
226
227 return true;
228}
229
230
232{
234 return false;
235
236 // Alias symbol reference can be empty because it inherits from the parent symbol.
237 if( m_libEntry->IsRoot() &&
239 {
240 if( m_NoteBook->GetSelection() != 0 )
241 m_NoteBook->SetSelection( 0 );
242
243 m_delayedErrorMessage = _( "References must start with a letter." );
248
249 return false;
250 }
251
252 // Check for missing field names.
253 for( int ii = MANDATORY_FIELDS; ii < (int) m_fields->size(); ++ii )
254 {
255 LIB_FIELD& field = m_fields->at( ii );
256 wxString fieldName = field.GetName( false );
257
258 if( fieldName.IsEmpty() && !field.GetText().IsEmpty() )
259 {
260 if( m_NoteBook->GetSelection() != 0 )
261 m_NoteBook->SetSelection( 0 );
262
263 m_delayedErrorMessage = _( "Fields must have a name." );
268
269 return false;
270 }
271 }
272
273 // Verify that the parent name is set if the symbol is inherited
274 if( m_libEntry->IsAlias() )
275 {
276 wxString parentName = m_inheritanceSelectCombo->GetValue();
277
278 if( parentName.IsEmpty() )
279 {
280 m_delayedErrorMessage = _( "Derived symbol must have a parent selected" );
281
282 return false;
283 }
284 }
285
286 /*
287 * Confirm destructive actions.
288 */
289
290 if( m_SelNumberOfUnits->GetValue() < m_libEntry->GetUnitCount() )
291 {
292 if( !IsOK( this, _( "Delete extra units from symbol?" ) ) )
293 return false;
294 }
295
296 if( !m_AsConvertButt->GetValue() && m_libEntry->HasConversion() )
297 {
298 if( !IsOK( this, _( "Delete alternate body style (De Morgan) from symbol?" ) ) )
299 return false;
300 }
301
302 return true;
303}
304
305
307{
308 if( !wxDialog::TransferDataFromWindow() )
309 return false;
310
312 return false;
313
314 wxString newName = EscapeString( m_SymbolNameCtrl->GetValue(), CTX_LIBID );
315 wxString oldName = m_libEntry->GetName();
316
317 if( oldName != newName )
318 {
319 wxString libName = m_Parent->GetCurLib();
320
321 if( m_Parent->GetLibManager().SymbolExists( newName, libName ) )
322 {
323 wxString msg;
324
325 msg.Printf( _( "Symbol name '%s' already in use in library '%s'." ),
326 UnescapeString( newName ),
327 libName );
328 DisplayErrorMessage( this, msg );
329 return false;
330 }
331
332 m_Parent->SaveCopyInUndoList( _( "Edit Symbol Properties" ), m_libEntry,
333 UNDO_REDO::LIB_RENAME );
334 }
335 else
336 {
337 m_Parent->SaveCopyInUndoList( _( "Edit Symbol Properties" ), m_libEntry );
338 }
339
340 // The Y axis for components in lib is from bottom to top while the screen axis is top
341 // to bottom: we must change the y coord sign when writing back to the library
342 for( int ii = 0; ii < (int) m_fields->size(); ++ii )
343 {
344 VECTOR2I pos = m_fields->at( ii ).GetPosition();
345 pos.y = -pos.y;
346 m_fields->at( ii ).SetPosition( pos );
347 m_fields->at( ii ).SetId( ii );
348 }
349
350 for( int ii = m_fields->GetNumberRows() - 1; ii >= MANDATORY_FIELDS; ii-- )
351 {
352 LIB_FIELD& field = m_fields->at( ii );
353 const wxString& fieldName = field.GetCanonicalName();
354
355 if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
356 m_fields->erase( m_fields->begin() + ii );
357 else if( fieldName.IsEmpty() )
358 field.SetName( _( "untitled" ) );
359 }
360
362
363 // Update the parent for inherited symbols
364 if( m_libEntry->IsAlias() )
365 {
366 wxString parentName = EscapeString( m_inheritanceSelectCombo->GetValue(), CTX_LIBID );
367
368 // The parentName was verified to be non-empty in the Validator
369 wxString libName = m_Parent->GetCurLib();
370
371 // Get the parent from the libManager based on the name set in the inheritance combo box.
372 LIB_SYMBOL* newParent = m_Parent->GetLibManager().GetAlias( parentName, libName );
373
374 // Verify that the requested parent exists
375 wxCHECK( newParent, false );
376
377 m_libEntry->SetParent( newParent );
378 }
379
380 m_libEntry->SetName( newName );
381 m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() );
384 !m_OptionPartsInterchangeable->GetValue() );
387
388 if( m_OptionPower->GetValue() )
389 {
391 // Power symbols must have value matching name for now
392 m_libEntry->GetValueField().SetText( newName );
393 }
394 else
395 {
397 }
398
402
405
406 if( m_PinsNameInsideButt->GetValue() )
407 {
408 int offset = KiROUND( (double) m_pinNameOffset.GetValue() );
409
410 // We interpret an offset of 0 as "outside", so make sure it's non-zero
411 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
412 }
413 else
414 {
415 m_libEntry->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
416 }
417
419
421
422 // It's possible that the symbol being edited has no pins, in which case there may be no
423 // alternate body style objects causing #LIB_SYMBOL::HasCoversion() to always return false.
424 // This allows the user to edit the alternate body style just in case this condition occurs.
426
427 return true;
428}
429
430
432{
433 wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
434 wxControl* control = editor->GetControl();
435
436 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
437 {
438 event.Veto();
439
441 m_delayedFocusRow = event.GetRow();
442 m_delayedFocusColumn = event.GetCol();
444 }
445 else if( event.GetCol() == FDC_NAME )
446 {
447 wxString newName = event.GetString();
448
449 for( int i = 0; i < m_grid->GetNumberRows(); ++i )
450 {
451 if( i == event.GetRow() )
452 continue;
453
454 if( newName.CmpNoCase( m_grid->GetCellValue( i, FDC_NAME ) ) == 0 )
455 {
456 DisplayError( this, wxString::Format( _( "The name '%s' is already in use." ),
457 newName ) );
458 event.Veto();
459 m_delayedFocusRow = event.GetRow();
460 m_delayedFocusColumn = event.GetCol();
461 }
462 }
463 }
464
465 editor->DecRef();
466}
467
468
470{
471 if( m_OptionPower->IsChecked() )
472 m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
473}
474
475
477{
478 if( !m_delayedFocusCtrl )
479 {
480 // If the validation fails and we throw up a dialog then GTK will give us another
481 // KillFocus event and we end up in infinite recursion. So we use m_delayedFocusCtrl
482 // as a re-entrancy block and then clear it again if validation passes.
485
486 if( m_SymbolNameCtrl->GetValidator()->Validate( m_SymbolNameCtrl ) )
487 {
488 m_delayedFocusCtrl = nullptr;
490 }
491 }
492
493 event.Skip();
494}
495
496
497void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
498{
500 return;
501
503 int fieldID = (int) m_fields->size();
504 LIB_FIELD newField( m_libEntry, fieldID );
505
507 schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
508
509 m_fields->push_back( newField );
510
511 // notify the grid
512 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
513 m_grid->ProcessTableMessage( msg );
514
515 m_grid->MakeCellVisible( (int) m_fields->size() - 1, 0 );
516 m_grid->SetGridCursor( (int) m_fields->size() - 1, 0 );
517
518 m_grid->EnableCellEditControl();
519 m_grid->ShowCellEditControl();
520
521 OnModify();
522}
523
524
526{
527 wxArrayInt selectedRows = m_grid->GetSelectedRows();
528
529 if( selectedRows.empty() && m_grid->GetGridCursorRow() >= 0 )
530 selectedRows.push_back( m_grid->GetGridCursorRow() );
531
532 if( selectedRows.empty() )
533 return;
534
535 for( int row : selectedRows )
536 {
537 if( row < MANDATORY_FIELDS )
538 {
539 DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
541 return;
542 }
543 }
544
545 m_grid->CommitPendingChanges( true /* quiet mode */ );
546 m_grid->ClearSelection();
547
548 // Reverse sort so deleting a row doesn't change the indexes of the other rows.
549 selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
550
551 for( int row : selectedRows )
552 {
553 m_fields->erase( m_fields->begin() + row );
554
555 // notify the grid
556 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
557 m_grid->ProcessTableMessage( msg );
558
559 if( m_grid->GetNumberRows() > 0 )
560 {
561 m_grid->MakeCellVisible( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
562 m_grid->SetGridCursor( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
563 }
564 }
565
566 OnModify();
567}
568
569
570void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
571{
573 return;
574
575 int i = m_grid->GetGridCursorRow();
576
577 if( i > MANDATORY_FIELDS )
578 {
579 LIB_FIELD tmp = m_fields->at( (unsigned) i );
580 m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
581 m_fields->insert( m_fields->begin() + i - 1, tmp );
582 m_grid->ForceRefresh();
583
584 m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
585 m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
586
587 OnModify();
588 }
589 else
590 {
591 wxBell();
592 }
593}
594
595
596void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
597{
599 return;
600
601 int i = m_grid->GetGridCursorRow();
602
603 if( i >= MANDATORY_FIELDS && i + 1 < m_fields->GetNumberRows() )
604 {
605 LIB_FIELD tmp = m_fields->at( (unsigned) i );
606 m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
607 m_fields->insert( m_fields->begin() + i + 1, tmp );
608 m_grid->ForceRefresh();
609
610 m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
611 m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
612
613 OnModify();
614 }
615 else
616 {
617 wxBell();
618 }
619}
620
621
623{
625 return;
626
627 std::vector<LIB_FIELD> fields;
628
629 for( const LIB_FIELD& field : *m_fields )
630 fields.emplace_back( field );
631
632 DIALOG_SIM_MODEL dialog( this, *m_libEntry, fields );
633
634 if( dialog.ShowModal() != wxID_OK )
635 return;
636
637 // Add in any new fields
638 for( const LIB_FIELD& editedField : fields )
639 {
640 bool found = false;
641
642 for( LIB_FIELD& existingField : *m_fields )
643 {
644 if( existingField.GetName() == editedField.GetName() )
645 {
646 found = true;
647 existingField.SetText( editedField.GetText() );
648 break;
649 }
650 }
651
652 if( !found )
653 {
654 m_fields->emplace_back( editedField );
655 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
656 m_grid->ProcessTableMessage( msg );
657 }
658 }
659
660 // Remove any deleted fields
661 for( int ii = (int) m_fields->size() - 1; ii >= 0; /* advance in loop */ )
662 {
663 LIB_FIELD& existingField = m_fields->at( ii );
664 bool found = false;
665
666 for( LIB_FIELD& editedField : fields )
667 {
668 if( editedField.GetName() == existingField.GetName() )
669 {
670 found = true;
671 break;
672 }
673 }
674
675 if( found )
676 {
677 ii--;
678 }
679 else
680 {
681 m_fields->erase( m_fields->begin() + ii );
682 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
683 m_grid->ProcessTableMessage( msg );
684 }
685 }
686
687 OnModify();
688 m_grid->ForceRefresh();
689}
690
691
693{
694 int idx = m_FootprintFilterListBox->HitTest( event.GetPosition() );
695 wxCommandEvent dummy;
696
697 if( idx >= 0 )
699 else
701}
702
703
705{
706 // Running the Footprint Browser gums up the works and causes the automatic cancel
707 // stuff to no longer work. So we do it here ourselves.
708 EndQuasiModal( wxID_CANCEL );
709}
710
711
713{
714 wxString filterLine;
715 WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Add Footprint Filter" ), filterLine );
716
717 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue().IsEmpty() )
718 return;
719
720 filterLine = dlg.GetValue();
721 filterLine.Replace( wxT( " " ), wxT( "_" ) );
722
723 // duplicate filters do no harm, so don't be a nanny.
724
725 m_FootprintFilterListBox->Append( filterLine );
726 m_FootprintFilterListBox->SetSelection( (int) m_FootprintFilterListBox->GetCount() - 1 );
727
728 OnModify();
729}
730
731
733{
734 int ii = m_FootprintFilterListBox->GetSelection();
735
736 if( ii >= 0 )
737 {
738 m_FootprintFilterListBox->Delete( (unsigned) ii );
739
740 if( m_FootprintFilterListBox->GetCount() == 0 )
741 m_FootprintFilterListBox->SetSelection( wxNOT_FOUND );
742 else
743 m_FootprintFilterListBox->SetSelection( std::max( 0, ii - 1 ) );
744 }
745
746 OnModify();
747}
748
749
751{
752 int idx = m_FootprintFilterListBox->GetSelection();
753
754 if( idx >= 0 )
755 {
756 wxString filter = m_FootprintFilterListBox->GetStringSelection();
757
758 WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Edit Footprint Filter" ), filter );
759
760 if( dlg.ShowModal() == wxID_OK && !dlg.GetValue().IsEmpty() )
761 {
762 m_FootprintFilterListBox->SetString( (unsigned) idx, dlg.GetValue() );
763 OnModify();
764 }
765 }
766}
767
768
770{
771 // Account for scroll bars
773
774 m_grid->AutoSizeColumn( FDC_NAME );
775 m_grid->SetColSize( FDC_NAME, std::max( 72, m_grid->GetColSize( FDC_NAME ) ) );
776
777 int fixedColsWidth = m_grid->GetColSize( FDC_NAME );
778
779 for( int i = 2; i < m_grid->GetNumberCols(); i++ )
780 fixedColsWidth += m_grid->GetColSize( i );
781
782 m_grid->SetColSize( FDC_VALUE, std::max( 120, width - fixedColsWidth ) );
783}
784
785
786void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
787{
788 m_OptionPartsInterchangeable->Enable( m_SelNumberOfUnits->GetValue() > 1 );
790
791 if( m_grid->IsCellEditControlShown() )
792 {
793 int row = m_grid->GetGridCursorRow();
794 int col = m_grid->GetGridCursorCol();
795
796 if( row == VALUE_FIELD && col == FDC_VALUE && m_OptionPower->IsChecked() )
797 {
798 wxGridCellEditor* editor = m_grid->GetCellEditor( row, col );
799 m_SymbolNameCtrl->ChangeValue( editor->GetValue() );
800 editor->DecRef();
801 }
802 }
803
804 // Handle shown columns changes
805 std::bitset<64> shownColumns = m_grid->GetShownColumns();
806
807 if( shownColumns != m_shownColumns )
808 {
809 m_shownColumns = shownColumns;
810
811 if( !m_grid->IsCellEditControlShown() )
813 }
814
815 // Handle a delayed focus. The delay allows us to:
816 // a) change focus when the error was triggered from within a killFocus handler
817 // b) show the correct notebook page in the background before the error dialog comes up
818 // when triggered from an OK or a notebook page change
819
820 if( m_delayedFocusPage >= 0 && m_NoteBook->GetSelection() != m_delayedFocusPage )
821 {
822 m_NoteBook->ChangeSelection( (unsigned) m_delayedFocusPage );
824 }
825
826 if( !m_delayedErrorMessage.IsEmpty() )
827 {
828 // We will re-enter this routine when the error dialog is displayed, so make
829 // sure we don't keep putting up more dialogs.
830 wxString msg = m_delayedErrorMessage;
831 m_delayedErrorMessage = wxEmptyString;
832
833 // Do not use DisplayErrorMessage(); it screws up window order on Mac
834 DisplayError( nullptr, msg );
835 }
836
838 {
839 m_delayedFocusCtrl->SetFocus();
840
841 if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
842 textEntry->SelectAll();
843
844 m_delayedFocusCtrl = nullptr;
845 }
846 else if( m_delayedFocusGrid )
847 {
848 m_delayedFocusGrid->SetFocus();
851
852 m_delayedFocusGrid->EnableCellEditControl( true );
853 m_delayedFocusGrid->ShowCellEditControl();
854
855 m_delayedFocusGrid = nullptr;
858 }
859}
860
861
863{
864 auto new_size = event.GetSize();
865
866 if( new_size != m_size )
867 {
868 m_size = new_size;
869
871 }
872
873 // Always propagate a wxSizeEvent:
874 event.Skip();
875}
876
877
879{
880 bSizerLowerBasicPanel->Show( !aIsAlias );
881 m_inheritanceSelectCombo->Enable( aIsAlias );
882 m_inheritsStaticText->Enable( aIsAlias );
883 m_grid->ForceRefresh();
884}
885
886
888{
889 if( m_OptionPower->IsChecked() )
890 {
891 m_excludeFromSimCheckBox->SetValue( true );
892 m_excludeFromBomCheckBox->SetValue( true );
893 m_excludeFromBoardCheckBox->SetValue( true );
894 m_excludeFromBomCheckBox->Enable( false );
895 m_excludeFromBoardCheckBox->Enable( false );
896 m_excludeFromSimCheckBox->Enable( false );
897 m_spiceFieldsButton->Show( false );
898 }
899 else
900 {
901 m_excludeFromBomCheckBox->Enable( true );
902 m_excludeFromBoardCheckBox->Enable( true );
903 m_excludeFromSimCheckBox->Enable( true );
904 m_spiceFieldsButton->Show( true );
905 }
906
907 OnModify();
908}
909
910
911void DIALOG_LIB_SYMBOL_PROPERTIES::OnText( wxCommandEvent& event )
912{
913 OnModify();
914}
915
916
917void DIALOG_LIB_SYMBOL_PROPERTIES::OnCombobox( wxCommandEvent& event )
918{
919 OnModify();
920}
921
922
923void DIALOG_LIB_SYMBOL_PROPERTIES::OnCheckBox( wxCommandEvent& event )
924{
925 OnModify();
926}
927
928
930{
931 OnModify();
932}
933
934
936{
937 OnModify();
938}
939
940
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
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:106
Class DIALOG_LIB_SYMBOL_PROPERTIES_BASE.
void OnSymbolNameKillFocus(wxFocusEvent &event) override
void OnFilterDClick(wxMouseEvent &event) override
void OnSpinCtrlText(wxCommandEvent &event) override
void OnSizeGrid(wxSizeEvent &event) override
DIALOG_LIB_SYMBOL_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aLibEntry)
void OnUpdateUI(wxUpdateUIEvent &event) override
FIELDS_GRID_TABLE< LIB_FIELD > * m_fields
void OnCancelButtonClick(wxCommandEvent &event) override
void OnDeleteFootprintFilter(wxCommandEvent &event) override
void OnEditFootprintFilter(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
void OnCombobox(wxCommandEvent &event) override
void OnMoveUp(wxCommandEvent &event) override
void OnText(wxCommandEvent &event) override
void OnMoveDown(wxCommandEvent &event) override
void OnAddFootprintFilter(wxCommandEvent &event) override
void OnCheckBox(wxCommandEvent &event) override
void OnSymbolNameText(wxCommandEvent &event) override
void onPowerCheckBox(wxCommandEvent &aEvent) override
void OnAddField(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void OnSpinCtrl(wxSpinEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void resetSize()
Clear the existing dialog size and position.
void EndQuasiModal(int retCode)
void OnModify()
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetTextSize(VECTOR2I aNewSize)
Definition: eda_text.cpp:355
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:180
int GetNumberRows() override
A text control validator used for validating the text allowed in fields.
Definition: validators.h:238
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Field object used in symbol libraries.
Definition: lib_field.h:62
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:507
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:489
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:498
Define a library symbol object.
Definition: lib_symbol.h:99
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition: lib_symbol.h:668
int GetPinNameOffset() const
Definition: lib_symbol.h:661
wxString GetKeyWords() const
Definition: lib_symbol.h:191
void SetConversion(bool aSetConvert, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the symbol.
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:285
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:214
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition: lib_symbol.h:660
bool IsAlias() const
Definition: lib_symbol.h:215
bool IsPower() const
Definition: lib_symbol.cpp:714
void SetPower()
Definition: lib_symbol.cpp:728
bool ShowPinNames() const
Definition: lib_symbol.h:669
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
Definition: lib_symbol.h:279
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition: lib_symbol.h:676
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:606
wxString GetName() const override
Definition: lib_symbol.h:160
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:189
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:226
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
Definition: lib_symbol.h:692
bool GetExcludedFromBOM() const
Definition: lib_symbol.h:693
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
Definition: lib_symbol.h:700
LIB_FIELD & GetValueField()
Return reference to the value field.
bool GetExcludedFromSim() const
Definition: lib_symbol.h:685
void SetFPFilters(const wxArrayString &aFilters)
Definition: lib_symbol.h:224
int GetUnitCount() const override
For items with units, return the number of units.
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:127
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:599
void SetNormal()
Definition: lib_symbol.cpp:756
bool ShowPinNumbers() const
Definition: lib_symbol.h:677
void SetExcludedFromSim(bool aExcludeFromSim)
Set or clear the exclude from simulation flag.
Definition: lib_symbol.h:684
bool GetExcludedFromBoard() const
Definition: lib_symbol.h:701
static bool IsReferenceStringValid(const wxString &aReferenceString)
Test for an acceptable reference string.
Definition: sch_symbol.cpp:756
void SetBitmap(const wxBitmapBundle &aBmp)
The symbol library editor main window.
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
bool GetShowDeMorgan() const
bool IsSymbolFromLegacyLibrary() const
bool IsSymbolFromSchematic() const
SYMBOL_EDITOR_SETTINGS * GetSettings() const
void SaveCopyInUndoList(const wxString &aDescription, EDA_ITEM *aItem, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT)
Create a copy of the current symbol, and save it in the undo list.
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SetShowDeMorgan(bool show)
LIB_SYMBOL * GetAlias(const wxString &aAlias, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
bool SymbolExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:299
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:157
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:255
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:269
std::bitset< 64 > GetShownColumns()
Definition: wx_grid.cpp:288
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:449
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
This file is part of the common library.
#define _(s)
@ FDC_NAME
@ FDC_VALUE
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:45
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: gtk/ui.cpp:195
std::vector< FAB_LAYER_COLOR > dummy
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_LIBID
Definition: string_utils.h:54
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
@ DATASHEET_FIELD
name of datasheet
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588