KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_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 <algorithm>
23#include <memory>
24
25#include <bitmaps.h>
26#include <wx/tooltip.h>
27#include <wx/uiaction.h>
28#include <grid_tricks.h>
29#include <confirm.h>
30#include <kiface_base.h>
31#include <pin_numbers.h>
32#include <string_utils.h>
33#include <template_fieldnames.h>
34#include <kiplatform/ui.h>
40#include <sch_collectors.h>
41#include <fields_grid_table.h>
42#include <sch_edit_frame.h>
43#include <sch_reference_list.h>
44#include <schematic.h>
45#include <sch_commit.h>
46#include <sch_sheet_path.h>
47#include <tool/tool_manager.h>
48#include <tools/sch_actions.h>
49
50#include <dialog_sim_model.h>
53
54
55wxDEFINE_EVENT( SYMBOL_DELAY_FOCUS, wxCommandEvent );
56wxDEFINE_EVENT( SYMBOL_DELAY_SELECTION, wxCommandEvent );
57
58
69
70
71class SCH_PIN_TABLE_DATA_MODEL : public WX_GRID_TABLE_BASE, public std::vector<SCH_PIN>
72{
73public:
75 m_readOnlyAttr( nullptr ),
76 m_typeAttr( nullptr ),
77 m_shapeAttr( nullptr )
78 {
79 }
80
82 {
83 for( wxGridCellAttr* attr : m_nameAttrs )
84 attr->DecRef();
85
86 m_readOnlyAttr->DecRef();
87 m_typeAttr->DecRef();
88 m_shapeAttr->DecRef();
89 }
90
92 {
93 for( wxGridCellAttr* attr : m_nameAttrs )
94 attr->DecRef();
95
96 m_nameAttrs.clear();
97
98 if( m_readOnlyAttr )
99 m_readOnlyAttr->DecRef();
100
101 m_readOnlyAttr = new wxGridCellAttr;
102 m_readOnlyAttr->SetReadOnly( true );
103
104 for( const SCH_PIN& pin : *this )
105 {
106 SCH_PIN* lib_pin = pin.GetLibPin();
107 wxGridCellAttr* attr = nullptr;
108
109 if( !lib_pin || lib_pin->GetAlternates().empty() )
110 {
111 attr = new wxGridCellAttr;
112 attr->SetReadOnly( true );
113 attr->SetBackgroundColour( KIPLATFORM::UI::GetDialogBGColour() );
114 }
115 else
116 {
117 wxArrayString choices;
118 choices.push_back( lib_pin->GetName() );
119
120 for( const std::pair<const wxString, SCH_PIN::ALT>& alt : lib_pin->GetAlternates() )
121 choices.push_back( alt.first );
122
123 attr = new wxGridCellAttr();
124 attr->SetEditor( new GRID_CELL_COMBOBOX( choices ) );
125 }
126
127 m_nameAttrs.push_back( attr );
128 }
129
130 if( m_typeAttr )
131 m_typeAttr->DecRef();
132
133 m_typeAttr = new wxGridCellAttr;
135 m_typeAttr->SetReadOnly( true );
136
137 if( m_shapeAttr )
138 m_shapeAttr->DecRef();
139
140 m_shapeAttr = new wxGridCellAttr;
142 m_shapeAttr->SetReadOnly( true );
143 }
144
145 int GetNumberRows() override { return (int) size(); }
146 int GetNumberCols() override { return COL_COUNT; }
147
148 wxString GetColLabelValue( int aCol ) override
149 {
150 switch( aCol )
151 {
152 case COL_NUMBER: return _( "Number" );
153 case COL_BASE_NAME: return _( "Base Name" );
154 case COL_ALT_NAME: return _( "Alternate Assignment" );
155 case COL_TYPE: return _( "Electrical Type" );
156 case COL_SHAPE: return _( "Graphic Style" );
157 default: wxFAIL; return wxEmptyString;
158 }
159 }
160
161 bool IsEmptyCell( int row, int col ) override
162 {
163 return false; // don't allow adjacent cell overflow, even if we are actually empty
164 }
165
166 bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override
167 {
168 // Don't accept random values; must use the popup to change to a known alternate
169 return false;
170 }
171
172 wxString GetValue( int aRow, int aCol ) override
173 {
174 return GetValue( at( aRow ), aCol );
175 }
176
177 static wxString GetValue( const SCH_PIN& aPin, int aCol )
178 {
179 if( aCol == COL_ALT_NAME )
180 {
181 if( !aPin.GetLibPin() || aPin.GetLibPin()->GetAlternates().empty() )
182 return wxEmptyString;
183 else if( aPin.GetAlt().IsEmpty() )
184 return aPin.GetName();
185 else
186 return aPin.GetAlt();
187 }
188
189 switch( aCol )
190 {
191 case COL_NUMBER: return aPin.GetNumber();
192 case COL_BASE_NAME: return aPin.GetBaseName();
193 case COL_TYPE: return PinTypeNames()[static_cast<int>( aPin.GetType() )];
194 case COL_SHAPE: return PinShapeNames()[static_cast<int>( aPin.GetShape() )];
195 default: wxFAIL; return wxEmptyString;
196 }
197 }
198
199 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override
200 {
201 switch( aCol )
202 {
203 case COL_NUMBER:
204 case COL_BASE_NAME:
205 m_readOnlyAttr->IncRef();
206 return enhanceAttr( m_readOnlyAttr, aRow, aCol, aKind );
207
208 case COL_ALT_NAME:
209 m_nameAttrs[ aRow ]->IncRef();
210 return enhanceAttr( m_nameAttrs[ aRow ], aRow, aCol, aKind );
211
212 case COL_TYPE:
213 m_typeAttr->IncRef();
214 return enhanceAttr( m_typeAttr, aRow, aCol, aKind );
215
216 case COL_SHAPE:
217 m_shapeAttr->IncRef();
218 return enhanceAttr( m_shapeAttr, aRow, aCol, aKind );
219
220 default:
221 wxFAIL;
222 return nullptr;
223 }
224 }
225
226 void SetValue( int aRow, int aCol, const wxString &aValue ) override
227 {
228 SCH_PIN& pin = at( aRow );
229
230 switch( aCol )
231 {
232 case COL_ALT_NAME:
233 if( pin.GetLibPin() && aValue == pin.GetLibPin()->GetName() )
234 pin.SetAlt( wxEmptyString );
235 else
236 pin.SetAlt( aValue );
237 break;
238
239 case COL_NUMBER:
240 case COL_BASE_NAME:
241 case COL_TYPE:
242 case COL_SHAPE:
243 // Read-only.
244 break;
245
246 default:
247 wxFAIL;
248 break;
249 }
250 }
251
252 static bool compare( const SCH_PIN& lhs, const SCH_PIN& rhs, int sortCol, bool ascending )
253 {
254 wxString lhStr = GetValue( lhs, sortCol );
255 wxString rhStr = GetValue( rhs, sortCol );
256
257 if( lhStr == rhStr )
258 {
259 // Secondary sort key is always COL_NUMBER
260 sortCol = COL_NUMBER;
261 lhStr = GetValue( lhs, sortCol );
262 rhStr = GetValue( rhs, sortCol );
263 }
264
265 bool res;
266
267 // N.B. To meet the iterator sort conditions, we cannot simply invert the truth
268 // to get the opposite sort. i.e. ~(a<b) != (a>b)
269 auto cmp = [ ascending ]( const auto a, const auto b )
270 {
271 if( ascending )
272 return a < b;
273 else
274 return b < a;
275 };
276
277 switch( sortCol )
278 {
279 case COL_NUMBER:
280 case COL_BASE_NAME:
281 case COL_ALT_NAME:
282 res = cmp( PIN_NUMBERS::Compare( lhStr, rhStr ), 0 );
283 break;
284 case COL_TYPE:
285 case COL_SHAPE:
286 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
287 break;
288 default:
289 res = cmp( StrNumCmp( lhStr, rhStr ), 0 );
290 break;
291 }
292
293 return res;
294 }
295
296 void SortRows( int aSortCol, bool ascending )
297 {
298 std::sort( begin(), end(),
299 [ aSortCol, ascending ]( const SCH_PIN& lhs, const SCH_PIN& rhs ) -> bool
300 {
301 return compare( lhs, rhs, aSortCol, ascending );
302 } );
303 }
304
305protected:
306 std::vector<wxGridCellAttr*> m_nameAttrs;
307 wxGridCellAttr* m_readOnlyAttr;
308 wxGridCellAttr* m_typeAttr;
309 wxGridCellAttr* m_shapeAttr;
310};
311
312
315 m_symbol( nullptr ),
317 m_editorShown( false ),
318 m_fields( nullptr ),
319 m_dataModel( nullptr ),
320 m_embeddedFiles( nullptr ),
321 m_pinMapPanel( nullptr )
322{
323 m_symbol = aSymbol;
324
325 // GetLibSymbolRef() hands back a raw pointer into a unique_ptr owned by the schematic symbol.
326 // This dialog is quasi-modal, so the still-live schematic can free that part through
327 // SetLibSymbol() (library update, ERC, undo) while the dialog is open. Keep a private copy
328 // alive for the dialog's lifetime instead.
329 if( LIB_SYMBOL* libSymbol = aSymbol->GetLibSymbolRef().get() )
330 m_part = std::make_unique<LIB_SYMBOL>( *libSymbol );
331
332 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
333
334 if( m_part )
335 {
336 m_part->AppendParentEmbeddedFiles( embeddedFilesStack );
337 embeddedFilesStack.push_back( m_part->GetEmbeddedFiles() );
338 }
339
340 embeddedFilesStack.push_back( m_symbol->Schematic() );
341
342 if( m_symbol->GetEmbeddedFiles() )
343 {
344 m_embeddedFiles = new PANEL_EMBEDDED_FILES( m_notebook1, m_symbol->GetEmbeddedFiles(), 0, embeddedFilesStack );
345 m_notebook1->AddPage( m_embeddedFiles, _( "Embedded Files" ) );
346 embeddedFilesStack.push_back( m_embeddedFiles->GetLocalFiles() );
347 }
348
349 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_fieldsGrid, m_symbol, m_part.get(), embeddedFilesStack );
350 m_fieldsGrid->SetTable( m_fields );
351 m_fieldsGrid->OverrideMinSize( 1.0, 1.0 );
352 m_fieldsGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_fieldsGrid, this, embeddedFilesStack,
353 [&]( wxCommandEvent& aEvent )
354 {
355 OnAddField( aEvent );
356 } ) );
357 m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
358
359 int minWidth = wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
360
361 for( int ii = 0; ii <= 7; ++ii )
362 {
363 if( m_fieldsGrid->IsColShown( ii ) )
364 minWidth += m_fieldsGrid->GetColSize( ii );
365 }
366
367 m_fieldsGrid->SetMinSize( wxSize( minWidth, -1 ) );
368
369 // Putting too many columns in wxFormBuilder results in the minimum dialog size getting set too
370 // large (even with the m_grid->SetMinSize() call above).
371 m_fieldsGrid->SetColSize( 13, 48 ); // "Color"
372 m_fieldsGrid->SetColSize( 14, 136 ); // "Allow Autoplace"
373 m_fieldsGrid->SetupColumnAutosizer( 1 );
374
375 m_fieldsGrid->ShowHideColumns( "0 1 2 3 4 5 6 7" );
376 m_shownColumns = m_fieldsGrid->GetShownColumns();
377
379 bPinMapPageSizer->Add( m_pinMapPanel, 1, wxEXPAND, 5 );
380
381 if( m_part && m_part->IsMultiBodyStyle() )
382 {
383 wxSizer* altPinDefsSizer = m_pinGrid->GetContainingSizer();
384
385 // Multiple body styles are a superclass of alternate pin assignments, so don't allow free-form
386 // alternate assignments as well. (We won't know how to map the alternates back and forth when
387 // the body style is changed.)
388 wxStaticText* hint = new wxStaticText( m_pinTablePage, wxID_ANY, NO_PIN_FUNCTIONS_WITH_MULTIPLE_BODY_STYLES );
389 hint->SetFont( KIUI::GetControlFont( this ).Italic() );
390 altPinDefsSizer->AddStretchSpacer( 1 );
391 altPinDefsSizer->Add( hint, 0, wxALIGN_CENTER_HORIZONTAL );
392 altPinDefsSizer->AddStretchSpacer( 2 );
393 m_pinGrid->Hide();
394 altPinDefsSizer->Layout();
395 }
396 else
397 {
399
400 // Make a copy of the pins for editing
401 for( const std::unique_ptr<SCH_PIN>& pin : m_symbol->GetRawPins() )
402 m_dataModel->push_back( *pin );
403
404 m_dataModel->SortRows( COL_NUMBER, true );
405 m_dataModel->BuildAttrs();
406
407 m_pinGrid->SetTable( m_dataModel );
408 }
409
410 if( m_part && m_part->IsPower() )
411 m_spiceFieldsButton->Hide();
412
413 m_pinGrid->PushEventHandler( new GRID_TRICKS( m_pinGrid ) );
414 m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
415
416 wxFont infoFont = KIUI::GetSmallInfoFont( this );
417 m_libraryIDLabel->SetFont( infoFont );
418 m_tcLibraryID->SetFont( infoFont );
419 m_tcLibraryID->SetBackgroundColour( KIPLATFORM::UI::GetDialogBGColour() );
420
421 wxToolTip::Enable( true );
423
424 // Configure button logos
429
430 // wxFormBuilder doesn't include this event...
431 m_fieldsGrid->Bind( wxEVT_GRID_CELL_CHANGING, &DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging, this );
432 m_pinGrid->Bind( wxEVT_GRID_COL_SORT, &DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort, this );
433 Bind( SYMBOL_DELAY_FOCUS, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedFocus, this );
434 Bind( SYMBOL_DELAY_SELECTION, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedSelection, this );
435
436 wxCommandEvent* evt = new wxCommandEvent( SYMBOL_DELAY_SELECTION );
437 evt->SetClientData( new VECTOR2I( 0, FDC_VALUE ) );
438 QueueEvent( evt );
439
440 evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
441 evt->SetClientData( new VECTOR2I( 0, FDC_VALUE ) );
442 QueueEvent( evt );
443
444 // Remind user that they are editing the current variant.
445 wxString variantName = aParent->Schematic().GetCurrentVariant();
446
447 if( !variantName.IsEmpty() )
448 {
449 SetTitle( GetTitle() + wxS( " - " ) + variantName + _( " Design Variant" ) );
450
451 m_changeSymbolBtn->SetLabel( _( "Set Variant Symbol..." ) );
452
453 SCH_SHEET_PATH& currentSheet = aParent->GetCurrentSheet();
454 std::optional<SCH_SYMBOL_VARIANT> existingVariant =
455 aSymbol->GetVariant( currentSheet, variantName );
456
457 bool hasVariantSymbol = existingVariant.has_value() && existingVariant->m_SymbolOverride.has_value();
458
459 m_clearVariantSymbolBtn->Show( hasVariantSymbol );
460 }
461 else
462 {
464 }
465
466 Layout();
467 m_fieldsGrid->Layout();
468
469 if( GetSizer() )
470 GetSizer()->Fit( this );
471
473}
474
475
477{
478 // Prevents crash bug in wxGrid's d'tor
479 m_fieldsGrid->DestroyTable( m_fields );
480
481 if( m_dataModel )
482 m_pinGrid->DestroyTable( m_dataModel );
483
484 m_fieldsGrid->Unbind( wxEVT_GRID_CELL_CHANGING, &DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging, this );
485 m_pinGrid->Unbind( wxEVT_GRID_COL_SORT, &DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort, this );
486 Unbind( SYMBOL_DELAY_FOCUS, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedFocus, this );
487 Unbind( SYMBOL_DELAY_SELECTION, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedSelection, this );
488
489 // Delete the GRID_TRICKS.
490 m_fieldsGrid->PopEventHandler( true );
491 m_pinGrid->PopEventHandler( true );
492}
493
494
496{
497 return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
498}
499
500
505
506
508{
509 if( !wxDialog::TransferDataToWindow() )
510 return false;
511
512 const SCHEMATIC& schematic = GetParent()->Schematic();
513 SCH_SHEET_PATH& sheetPath = schematic.CurrentSheet();
514 wxString variantName = schematic.GetCurrentVariant();
515
516 LIB_SYMBOL* libSymbol = m_symbol->GetLibSymbolRef().get();
517 std::optional<SCH_SYMBOL_VARIANT> variant = m_symbol->GetVariant( sheetPath, variantName );
518 std::set<wxString> defined;
519
520 std::vector<SCH_FIELD*> orderedFields;
521 m_symbol->GetFields( orderedFields, false );
522
523 // Push a copy of each field into m_updateFields
524 for( SCH_FIELD* srcField : orderedFields )
525 {
526 SCH_FIELD field( *srcField );
527
528 // change offset to be symbol-relative
529 field.Offset( -m_symbol->GetPosition() );
530 field.SetText( schematic.ConvertKIIDsToRefs( m_symbol->GetFieldText( field.GetName(), &sheetPath,
531 variantName ) ) );
532
533 defined.insert( field.GetName() );
534 m_fields->push_back( field );
535 }
536
537 // Add in any template fieldnames not yet defined:
538 for( const TEMPLATE_FIELDNAME& templateFieldname :
540 {
541 if( defined.count( templateFieldname.m_Name ) <= 0 )
542 {
543 SCH_FIELD field( m_symbol, FIELD_T::USER, templateFieldname.m_Name );
544 field.SetVisible( templateFieldname.m_Visible );
545 m_fields->push_back( field );
546 }
547 }
548
549 // notify the grid
550 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
551 m_fieldsGrid->ProcessTableMessage( msg );
552
553 // If a multi-unit symbol, set up the unit selector and interchangeable checkbox.
554 if( m_symbol->IsMultiUnit() )
555 {
556 // Ensure symbol unit is the currently selected unit (mandatory in complex hierarchies)
557 // from the current sheet path, because it can be modified by previous calculations
558 m_symbol->SetUnit( m_symbol->GetUnitSelection( &sheetPath ) );
559
560 for( int ii = 1; ii <= m_symbol->GetUnitCount(); ii++ )
561 m_unitChoice->Append( m_symbol->GetUnitDisplayName( ii, false ) );
562
563 if( m_symbol->GetUnit() <= ( int )m_unitChoice->GetCount() )
564 m_unitChoice->SetSelection( m_symbol->GetUnit() - 1 );
565 }
566 else
567 {
568 m_unitLabel->Enable( false );
569 m_unitChoice->Enable( false );
570 }
571
572 if( libSymbol && libSymbol->IsMultiBodyStyle() )
573 {
574 if( libSymbol->HasDeMorganBodyStyles() )
575 {
576 m_bodyStyleChoice->Append( _( "Standard" ) );
577 m_bodyStyleChoice->Append( _( "Alternate" ) );
578 }
579 else
580 {
581 wxASSERT( (int) libSymbol->GetBodyStyleNames().size() == libSymbol->GetBodyStyleCount() );
582
583 for( int ii = 0; ii < libSymbol->GetBodyStyleCount(); ii++ )
584 {
585 try
586 {
587 m_bodyStyleChoice->Append( libSymbol->GetBodyStyleNames().at( ii ) );
588 }
589 catch( ... )
590 {
591 m_bodyStyleChoice->Append( wxT( "???" ) );
592 }
593 }
594 }
595
596 if( m_symbol->GetBodyStyle() <= (int) m_bodyStyleChoice->GetCount() )
597 m_bodyStyleChoice->SetSelection( m_symbol->GetBodyStyle() - 1 );
598 }
599 else
600 {
601 m_bodyStyle->Enable( false );
602 m_bodyStyleChoice->Enable( false );
603 }
604
605 // Set the symbol orientation and mirroring.
606 int orientation = m_symbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
607
608 switch( orientation )
609 {
610 default:
611 case SYM_ORIENT_0: m_orientationCtrl->SetSelection( 0 ); break;
612 case SYM_ORIENT_90: m_orientationCtrl->SetSelection( 1 ); break;
613 case SYM_ORIENT_270: m_orientationCtrl->SetSelection( 2 ); break;
614 case SYM_ORIENT_180: m_orientationCtrl->SetSelection( 3 ); break;
615 }
616
617 int mirror = m_symbol->GetOrientation() & ( SYM_MIRROR_X | SYM_MIRROR_Y );
618
619 switch( mirror )
620 {
621 default: m_mirrorCtrl->SetSelection( 0 ) ; break;
622 case SYM_MIRROR_X: m_mirrorCtrl->SetSelection( 1 ); break;
623 case SYM_MIRROR_Y: m_mirrorCtrl->SetSelection( 2 ); break;
624 }
625
626 m_cbExcludeFromSim->SetValue( m_symbol->GetExcludedFromSim( &sheetPath, variantName ) );
627 m_cbExcludeFromBom->SetValue( m_symbol->GetExcludedFromBOM( &sheetPath, variantName ) );
628 m_cbExcludeFromBoard->SetValue( m_symbol->GetExcludedFromBoard( &sheetPath, variantName ) );
629 m_cbExcludeFromPosFiles->SetValue( m_symbol->GetExcludedFromPosFiles( &sheetPath, variantName ) );
630 m_cbDNP->SetValue( m_symbol->GetDNP( &sheetPath, variantName ) );
631
632 switch( m_symbol->GetPassthroughMode() )
633 {
634 case SCH_SYMBOL::PASSTHROUGH_MODE::DEFAULT: m_choicePassthrough->SetSelection( 0 ); break;
635 case SCH_SYMBOL::PASSTHROUGH_MODE::BLOCK: m_choicePassthrough->SetSelection( 1 ); break;
636 case SCH_SYMBOL::PASSTHROUGH_MODE::FORCE: m_choicePassthrough->SetSelection( 2 ); break;
637 }
638
639 if( libSymbol )
640 {
641 m_ShowPinNumButt->SetValue( libSymbol->GetShowPinNumbers() );
642 m_ShowPinNameButt->SetValue( libSymbol->GetShowPinNames() );
643 m_LocalPower->SetValue( libSymbol->IsLocalPower() );
644 }
645
646 m_LocalPower->Enable( libSymbol && libSymbol->IsPower() );
647
648 // Set the symbol's library name.
649 m_tcLibraryID->SetValue( UnescapeString( m_symbol->GetLibId().Format() ) );
650
651 if( m_embeddedFiles && !m_embeddedFiles->TransferDataToWindow() )
652 return false;
653
654 m_pinMapPanel->SetSymbol( libSymbol );
655 m_pinMapPanel->TransferDataToWindow();
656
657 const bool hasSuffix = !schematic.GetRefSuffix( sheetPath ).IsEmpty();
658 m_composedRefLabel->Show( hasSuffix );
659 m_composedRef->Show( hasSuffix );
660
661 m_fieldsGrid->Layout();
662 Layout();
663 m_fieldsGrid->SetMinVisibleRows( this, 4 );
664
665 // Always open on the General page, unless the caller explicitly asked for the Pin Map
666 // tab (the Edit Pin Map button). This overrides DIALOG_SHIM's remembered-tab restore.
667 int targetPage = 0;
668
670 {
671 for( size_t page = 0; page < m_notebook1->GetPageCount(); ++page )
672 {
673 if( m_notebook1->GetPage( page ) == m_pinMapPage )
674 {
675 targetPage = (int) page;
676 break;
677 }
678 }
679 }
680
681 m_notebook1->ChangeSelection( targetPage );
682
683 return true;
684}
685
686
688{
689 if( !m_fieldsGrid->CommitPendingChanges() )
690 return;
691
692 m_fieldsGrid->ClearSelection();
693
694 std::vector<SCH_FIELD> fields;
695
696 for( const SCH_FIELD& field : *m_fields )
697 fields.emplace_back( field );
698
699 DIALOG_SIM_MODEL dialog( this, m_parentFrame, *m_symbol, fields );
700
701 if( dialog.ShowModal() != wxID_OK )
702 return;
703
704 // Add in any new fields
705 for( const SCH_FIELD& editedField : fields )
706 {
707 bool found = false;
708
709 for( SCH_FIELD& existingField : *m_fields )
710 {
711 if( existingField.GetName() == editedField.GetName() )
712 {
713 found = true;
714 existingField.SetText( editedField.GetText() );
715 break;
716 }
717 }
718
719 if( !found )
720 {
721 m_fields->emplace_back( editedField );
722 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
723 m_fieldsGrid->ProcessTableMessage( msg );
724 }
725 }
726
727 // Remove any deleted fields
728 for( int ii = (int) m_fields->size() - 1; ii >= 0; --ii )
729 {
730 SCH_FIELD& existingField = m_fields->at( ii );
731 bool found = false;
732
733 for( SCH_FIELD& editedField : fields )
734 {
735 if( editedField.GetName() == existingField.GetName() )
736 {
737 found = true;
738 break;
739 }
740 }
741
742 if( !found )
743 {
744 m_fieldsGrid->ClearSelection();
745 m_fields->erase( m_fields->begin() + ii );
746
747 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
748 m_fieldsGrid->ProcessTableMessage( msg );
749 }
750 }
751
752 OnModify();
753 m_fieldsGrid->ForceRefresh();
754}
755
756
758{
759 // Running the Footprint Browser gums up the works and causes the automatic cancel
760 // stuff to no longer work. So we do it here ourselves.
761 EndDialogShim( wxID_CANCEL );
762}
763
764
766{
767 LIB_ID id;
768
769 if( !m_fieldsGrid->CommitPendingChanges() || !m_fieldsGrid->Validate() )
770 return false;
771
772 // Check for missing field names.
773 for( size_t i = 0; i < m_fields->size(); ++i )
774 {
775 SCH_FIELD& field = m_fields->at( i );
776
777 if( field.IsMandatory() )
778 continue;
779
780 wxString fieldName = field.GetName( false );
781
782 if( fieldName.IsEmpty() )
783 {
784 DisplayErrorMessage( this, _( "Fields must have a name." ) );
785
786 wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
787 evt->SetClientData( new VECTOR2I( i, FDC_VALUE ) );
788 QueueEvent( evt );
789
790 return false;
791 }
792 }
793
794 wxString base;
795 wxString msg = m_symbol->BaseRefFromUser( GetParent()->GetCurrentSheet(),
796 m_fields->GetField( FIELD_T::REFERENCE )->GetText(), base );
797
798 if( !msg.IsEmpty() )
799 {
800 DisplayErrorMessage( this, msg );
801 return false;
802 }
803
804 return true;
805}
806
807
809{
810 if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
811 return false;
812
813 if( m_embeddedFiles && !m_embeddedFiles->CommitPendingChanges() )
814 return false;
815
816 if( !m_fieldsGrid->CommitPendingChanges() )
817 return false;
818
819 if( !m_pinGrid->CommitPendingChanges() )
820 return false;
821
822 if( !m_pinMapPanel->CommitPendingChanges() )
823 return false;
824
825 SCH_COMMIT commit( GetParent() );
826 SCH_SCREEN* currentScreen = GetParent()->GetScreen();
827 SCH_SHEET_PATH currentSheet = GetParent()->Schematic().CurrentSheet();
828 wxString currentVariant = GetParent()->Schematic().GetCurrentVariant();
829 bool replaceOnCurrentScreen;
830
831 wxCHECK( currentScreen, false );
832
833 // This needs to be done before the LIB_ID is changed to prevent stale library symbols in
834 // the schematic file.
835 replaceOnCurrentScreen = currentScreen->Remove( m_symbol );
836
837 // save old cmp in undo list if not already in edit, or moving ...
838 if( m_symbol->GetEditFlags() == 0 )
839 commit.Modify( m_symbol, currentScreen );
840
841 // Apply pin-map edits after the undo snapshot so undo restores them (issue #2282).
842 if( LIB_SYMBOL* libSymbol = m_symbol->GetLibSymbolRef().get() )
843 {
844 m_pinMapPanel->ApplyToSymbol( libSymbol );
845 GetParent()->Schematic().SyncLibSymbolPinMaps( m_symbol->GetSchSymbolLibraryName(), *libSymbol, &commit );
846 }
847
848 // Save current flags which could be modified by next change settings
849 EDA_ITEM_FLAGS flags = m_symbol->GetFlags();
850
851 //Set the part selection in multiple part per package
852 int unit_selection = m_unitChoice->IsEnabled() ? m_unitChoice->GetSelection() + 1 : 1;
853 m_symbol->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
854 m_symbol->SetUnit( unit_selection );
855
856 int bodyStyle_selection = m_bodyStyleChoice->IsEnabled() ? m_bodyStyleChoice->GetSelection() + 1 : 1;
857 m_symbol->SetBodyStyle( bodyStyle_selection );
858
859 switch( m_orientationCtrl->GetSelection() )
860 {
861 case 0: m_symbol->SetOrientation( SYM_ORIENT_0 ); break;
862 case 1: m_symbol->SetOrientation( SYM_ORIENT_90 ); break;
863 case 2: m_symbol->SetOrientation( SYM_ORIENT_270 ); break;
864 case 3: m_symbol->SetOrientation( SYM_ORIENT_180 ); break;
865 }
866
867 switch( m_mirrorCtrl->GetSelection() )
868 {
869 case 0: break;
870 case 1: m_symbol->SetOrientation( SYM_MIRROR_X ); break;
871 case 2: m_symbol->SetOrientation( SYM_MIRROR_Y ); break;
872 }
873
874 m_symbol->SetShowPinNames( m_ShowPinNameButt->GetValue() );
875 m_symbol->SetShowPinNumbers( m_ShowPinNumButt->GetValue() );
876 m_symbol->SetLocalPowerProp( m_LocalPower->GetValue() );
877
878 // Restore m_Flag modified by SetUnit() and other change settings from the dialog
879 m_symbol->ClearFlags();
880 m_symbol->SetFlags( flags );
881
882 // change all field positions from relative to absolute
883 for( SCH_FIELD& field : *m_fields )
884 field.Offset( m_symbol->GetPosition() );
885
886 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
887
888 for( SCH_FIELD& field : *m_fields )
889 {
890 const wxString& fieldName = field.GetUntranslatedName();
891
892 if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
893 continue;
894 else if( fieldName.IsEmpty() )
895 field.SetName( _( "untitled" ) );
896
897 if( !field.IsMandatory() )
898 field.SetOrdinal( ordinal++, FIELD_T::USER );
899
900 const SCH_FIELD* existingField = m_symbol->GetField( fieldName );
901 SCH_FIELD* tmp;
902
903 if( !existingField )
904 {
905 tmp = m_symbol->AddField( field );
906 tmp->SetParent( m_symbol );
907 }
908 else
909 {
910 wxString defaultText = m_symbol->Schematic()->ConvertRefsToKIIDs( existingField->GetText() );
911 tmp = const_cast<SCH_FIELD*>( existingField );
912
913 *tmp = field;
914
915 // References are not variant data and are set for the sheet below
916 if( !currentVariant.IsEmpty() && field.GetId() != FIELD_T::REFERENCE )
917 {
918 // Restore the default field text for existing fields.
919 tmp->SetText( defaultText, &currentSheet );
920
921 wxString variantText = m_symbol->Schematic()->ConvertRefsToKIIDs( field.GetText() );
922 tmp->SetText( variantText, &currentSheet, currentVariant );
923 }
924 }
925 }
926
927 for( int ii = (int) m_symbol->GetFields().size() - 1; ii >= 0; ii-- )
928 {
929 SCH_FIELD& symbolField = m_symbol->GetFields()[ii];
930
931 if( symbolField.IsMandatory() )
932 continue;
933
934 bool found = false;
935
936 for( const SCH_FIELD& editedField : *m_fields )
937 {
938 if( editedField.GetName() == symbolField.GetName() )
939 {
940 found = true;
941 break;
942 }
943 }
944
945 if( !found )
946 m_symbol->RemoveField( symbolField.GetName() );
947 }
948
949 std::stable_sort( m_symbol->GetFields().begin(), m_symbol->GetFields().end(),
950 []( const SCH_FIELD& lhs, const SCH_FIELD& rhs )
951 {
952 return lhs.GetOrdinal() < rhs.GetOrdinal();
953 } );
954
955 // Reference has a specific initialization, depending on the current active sheet
956 // because for a given symbol, in a complex hierarchy, there are more than one
957 // reference.
958 wxString base;
959 m_symbol->BaseRefFromUser( currentSheet, m_fields->GetField( FIELD_T::REFERENCE )->GetText(), base );
960 m_symbol->SetUserRef( currentSheet, base );
961
962 m_symbol->SetExcludedFromSim( m_cbExcludeFromSim->IsChecked(), &currentSheet, currentVariant );
963 m_symbol->SetExcludedFromBOM( m_cbExcludeFromBom->IsChecked(), &currentSheet, currentVariant );
964 m_symbol->SetExcludedFromBoard( m_cbExcludeFromBoard->IsChecked(), &currentSheet, currentVariant );
965 m_symbol->SetExcludedFromPosFiles( m_cbExcludeFromPosFiles->IsChecked(), &currentSheet, currentVariant );
966 m_symbol->SetDNP( m_cbDNP->IsChecked(), &currentSheet, currentVariant );
967
968 switch( m_choicePassthrough->GetSelection() )
969 {
970 case 0: m_symbol->SetPassthroughMode( SCH_SYMBOL::PASSTHROUGH_MODE::DEFAULT ); break;
971 case 1: m_symbol->SetPassthroughMode( SCH_SYMBOL::PASSTHROUGH_MODE::BLOCK ); break;
972 case 2: m_symbol->SetPassthroughMode( SCH_SYMBOL::PASSTHROUGH_MODE::FORCE ); break;
973 default: break;
974 }
975
976 // Update any assignments
977 if( m_dataModel )
978 {
979 for( const SCH_PIN& model_pin : *m_dataModel )
980 {
981 // map from the edited copy back to the "real" pin(s) in the symbol.
982 for( SCH_PIN* src_pin : m_symbol->GetPinsByNumber( model_pin.GetNumber() ) )
983 src_pin->SetAlt( model_pin.GetAlt() );
984 }
985 }
986
987 // Keep fields other than the reference, include/exclude flags, and alternate pin assignements
988 // in sync in multi-unit parts.
989 m_symbol->SyncOtherUnits( currentSheet, commit, nullptr, currentVariant );
990
991 if( m_embeddedFiles )
992 (void) m_embeddedFiles->TransferDataFromWindow();
993
994 if( replaceOnCurrentScreen )
995 currentScreen->Append( m_symbol );
996
997 if( !commit.Empty() )
998 commit.Push( _( "Edit Symbol Properties" ) );
999
1000 return true;
1001}
1002
1003
1005{
1006 wxGridCellEditor* editor = m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
1007 wxControl* control = editor->GetControl();
1008
1009 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
1010 {
1011 event.Veto();
1012 wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
1013 evt->SetClientData( new VECTOR2I( event.GetRow(), event.GetCol() ) );
1014 QueueEvent( evt );
1015 }
1016 else if( event.GetCol() == FDC_NAME )
1017 {
1018 wxString newName = event.GetString();
1019
1020 for( int i = 0; i < m_fieldsGrid->GetNumberRows(); ++i )
1021 {
1022 if( i == event.GetRow() )
1023 continue;
1024
1025 if( FieldNamesAreDuplicates( newName, m_fieldsGrid->GetCellValue( i, FDC_NAME ) ) )
1026 {
1027 DisplayErrorMessage( this, wxString::Format( _( "Field name '%s' already in use." ), newName ) );
1028 event.Veto();
1029 wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
1030 evt->SetClientData( new VECTOR2I( event.GetRow(), event.GetCol() ) );
1031 QueueEvent( evt );
1032 }
1033 }
1034 }
1035
1036 editor->DecRef();
1037}
1038
1039
1041{
1042 if( m_fields->GetFieldRow( FIELD_T::REFERENCE ) == aEvent.GetRow() && aEvent.GetCol() == FDC_VALUE )
1043 {
1044 wxCommandEvent* evt = new wxCommandEvent( SYMBOL_DELAY_SELECTION );
1045 evt->SetClientData( new VECTOR2I( aEvent.GetRow(), aEvent.GetCol() ) );
1046 QueueEvent( evt );
1047 }
1048
1049 m_editorShown = true;
1050
1051 // Let WX_GRID run its editor-positioning handler
1052 aEvent.Skip();
1053}
1054
1055
1057{
1058 m_editorShown = false;
1059}
1060
1061
1062void DIALOG_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
1063{
1064 m_fieldsGrid->OnAddRow(
1065 [&]() -> std::pair<int, int>
1066 {
1068
1069 newField.SetTextAngle( m_fields->GetField( FIELD_T::REFERENCE )->GetTextAngle() );
1070 newField.SetVisible( false );
1071
1072 m_fields->push_back( newField );
1073
1074 // notify the grid
1075 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1076 m_fieldsGrid->ProcessTableMessage( msg );
1077 OnModify();
1078
1079 return { m_fields->GetNumberRows() - 1, FDC_NAME };
1080 } );
1081}
1082
1083
1084void DIALOG_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
1085{
1086 m_fieldsGrid->OnDeleteRows(
1087 [&]( int row )
1088 {
1089 if( row < m_fields->GetMandatoryRowCount() )
1090 {
1091 DisplayErrorMessage( this, wxString::Format( _( "The first %d fields are mandatory." ),
1092 m_fields->GetMandatoryRowCount() ) );
1093 return false;
1094 }
1095
1096 return true;
1097 },
1098 [&]( int row )
1099 {
1100 if( !m_fields->EraseRow( row ) )
1101 return;
1102
1103 // notify the grid
1104 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
1105 m_fieldsGrid->ProcessTableMessage( msg );
1106 } );
1107
1108 OnModify();
1109}
1110
1111
1112void DIALOG_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
1113{
1114 m_fieldsGrid->OnMoveRowUp(
1115 [&]( int row )
1116 {
1117 return row > m_fields->GetMandatoryRowCount();
1118 },
1119 [&]( int row )
1120 {
1121 m_fields->SwapRows( row, row - 1 );
1122 m_fieldsGrid->ForceRefresh();
1123 OnModify();
1124 } );
1125}
1126
1127
1128void DIALOG_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
1129{
1130 m_fieldsGrid->OnMoveRowDown(
1131 [&]( int row )
1132 {
1133 return row >= m_fields->GetMandatoryRowCount();
1134 },
1135 [&]( int row )
1136 {
1137 m_fields->SwapRows( row, row + 1 );
1138 m_fieldsGrid->ForceRefresh();
1139 OnModify();
1140 } );
1141}
1142
1143
1149
1150
1156
1157
1163
1164
1166{
1167 if( !TransferDataFromWindow() )
1168 return;
1169
1170 if( !GetParent()->Schematic().GetCurrentVariant().IsEmpty() )
1172 else
1174}
1175
1176
1182
1183
1185{
1186 int row = aEvent.GetRow();
1187
1188 if( m_pinGrid->GetCellValue( row, COL_ALT_NAME ) == m_dataModel->GetValue( row, COL_BASE_NAME ) )
1189 m_dataModel->SetValue( row, COL_ALT_NAME, wxEmptyString );
1190
1191 // These are just to get the cells refreshed
1192 m_dataModel->SetValue( row, COL_TYPE, m_dataModel->GetValue( row, COL_TYPE ) );
1193 m_dataModel->SetValue( row, COL_SHAPE, m_dataModel->GetValue( row, COL_SHAPE ) );
1194
1195 OnModify();
1196}
1197
1198
1200{
1201 int sortCol = aEvent.GetCol();
1202 bool ascending;
1203
1204 // This is bonkers, but wxWidgets doesn't tell us ascending/descending in the
1205 // event, and if we ask it will give us pre-event info.
1206 if( m_pinGrid->IsSortingBy( sortCol ) )
1207 // same column; invert ascending
1208 ascending = !m_pinGrid->IsSortOrderAscending();
1209 else
1210 // different column; start with ascending
1211 ascending = true;
1212
1213 m_dataModel->SortRows( sortCol, ascending );
1214 m_dataModel->BuildAttrs();
1215}
1216
1217
1219{
1220 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinGrid );
1221
1222 // Account for scroll bars
1223 int pinTblWidth = KIPLATFORM::UI::GetUnobscuredSize( m_pinGrid ).x;
1224
1225 // Stretch the Base Name and Alternate Assignment columns to fit.
1226 for( int i = 0; i < COL_COUNT; ++i )
1227 {
1228 if( i != COL_BASE_NAME && i != COL_ALT_NAME )
1229 pinTblWidth -= m_pinGrid->GetColSize( i );
1230 }
1231
1232 if( pinTblWidth > 2 )
1233 {
1234 m_pinGrid->SetColSize( COL_BASE_NAME, pinTblWidth / 2 );
1235 m_pinGrid->SetColSize( COL_ALT_NAME, pinTblWidth / 2 );
1236 }
1237}
1238
1239
1240void DIALOG_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
1241{
1242 if( m_composedRef->IsShown() )
1243 {
1244 const SCH_SHEET_PATH& sheet = GetParent()->GetCurrentSheet();
1245 wxString composed;
1246
1247 m_symbol->BaseRefFromUser( sheet, m_fields->GetField( FIELD_T::REFERENCE )->GetText(), composed );
1248
1249 const SCHEMATIC& schematic = GetParent()->Schematic();
1250
1251 // Unannotated references are never suffixed, and a package takes the suffix it shares across sheets
1252 if( !composed.EndsWith( wxS( "?" ) ) )
1253 composed += schematic.GetPackageRefSuffix( m_symbol, sheet );
1254
1255 if( m_composedRef->GetLabelText() != composed )
1256 {
1257 m_composedRef->SetLabelText( composed );
1258 Layout();
1259 }
1260 }
1261
1262 std::bitset<64> shownColumns = m_fieldsGrid->GetShownColumns();
1263
1264 if( shownColumns != m_shownColumns )
1265 {
1266 m_shownColumns = shownColumns;
1267
1268 if( !m_fieldsGrid->IsCellEditControlShown() )
1269 m_fieldsGrid->SetGridWidthsDirty();
1270 }
1271}
1272
1273
1275{
1276 VECTOR2I *loc = static_cast<VECTOR2I*>( event.GetClientData() );
1277
1278 wxCHECK_RET( loc, wxT( "Missing focus cell location" ) );
1279
1280 // Run the AutoColumnSizer before setting focus (as it will clear any shown cell edit control
1281 // if it has to resize that column).
1282 m_fieldsGrid->RecomputeGridWidths();
1283
1284 // Handle a delayed focus
1285
1286 m_fieldsGrid->SetFocus();
1287 m_fieldsGrid->MakeCellVisible( loc->x, loc->y );
1288 m_fieldsGrid->SetGridCursor( loc->x, loc->y );
1289
1290 delete loc;
1291
1292 CallAfter(
1293 [this]()
1294 {
1295 m_fieldsGrid->EnableCellEditControl( true );
1296 } );
1297}
1298
1299
1301{
1302 VECTOR2I *loc = static_cast<VECTOR2I*>( event.GetClientData() );
1303
1304 wxCHECK_RET( loc, wxT( "Missing focus cell location" ) );
1305
1306 // Handle a delayed selection
1307 wxGridCellEditor* cellEditor = m_fieldsGrid->GetCellEditor( loc->x, loc->y );
1308
1309 if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
1311
1312 cellEditor->DecRef(); // we're done; must release
1313 delete loc;
1314}
1315
1316
1318{
1319 wxSize new_size = event.GetSize();
1320
1321 if( ( !m_editorShown || m_lastRequestedPinsSize != new_size ) && m_pinsSize != new_size )
1322 {
1323 m_pinsSize = new_size;
1324
1326 }
1327
1328 // We store this value to check whether the dialog is changing size. This might indicate
1329 // that the user is scaling the dialog with a grid-cell-editor shown. Some editors do not
1330 // close (at least on GTK) when the user drags a dialog corner
1331 m_lastRequestedPinsSize = new_size;
1332
1333 // Always propagate for a grid repaint (needed if the height changes, as well as width)
1334 event.Skip();
1335}
1336
1337
1338void DIALOG_SYMBOL_PROPERTIES::OnCheckBox( wxCommandEvent& event )
1339{
1340 OnModify();
1341}
1342
1343
1344void DIALOG_SYMBOL_PROPERTIES::OnUnitChoice( wxCommandEvent& event )
1345{
1346 if( m_dataModel )
1347 {
1348 EDA_ITEM_FLAGS flags = m_symbol->GetFlags();
1349
1350 int unit_selection = m_unitChoice->GetSelection() + 1;
1351
1352 // We need to select a new unit to build the new unit pin list
1353 // but we should not change the symbol, so the initial unit will be selected
1354 // after rebuilding the pin list
1355 int old_unit = m_symbol->GetUnit();
1356 m_symbol->SetUnit( unit_selection );
1357
1358 // Rebuild a copy of the pins of the new unit for editing
1359 m_dataModel->clear();
1360
1361 for( const std::unique_ptr<SCH_PIN>& pin : m_symbol->GetRawPins() )
1362 m_dataModel->push_back( *pin );
1363
1364 m_dataModel->SortRows( COL_NUMBER, true );
1365 m_dataModel->BuildAttrs();
1366
1367 m_symbol->SetUnit( old_unit );
1368
1369 // Restore m_Flag modified by SetUnit()
1370 m_symbol->ClearFlags();
1371 m_symbol->SetFlags( flags );
1372 }
1373
1374 OnModify();
1375}
1376
1377
1379{
1380 event.Enable( m_symbol && m_symbol->GetLibSymbolRef() );
1381}
1382
1383
1385{
1386 event.Enable( m_symbol && m_symbol->GetLibSymbolRef() );
1387}
1388
1389
1390void DIALOG_SYMBOL_PROPERTIES::OnPageChanging( wxBookCtrlEvent& aEvent )
1391{
1392 if( !m_fieldsGrid->CommitPendingChanges() )
1393 aEvent.Veto();
1394
1395 if( !m_pinGrid->CommitPendingChanges() )
1396 aEvent.Veto();
1397}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
bool Empty() const
Definition commit.h:145
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
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
DIALOG_SYMBOL_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Symbol Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU)
void OnSizePinsGrid(wxSizeEvent &event) override
std::unique_ptr< LIB_SYMBOL > m_part
void OnPinTableCellEdited(wxGridEvent &event) override
void OnGridEditorShown(wxGridEvent &event) override
void OnClearVariantSymbol(wxCommandEvent &) override
void OnUpdateUI(wxUpdateUIEvent &event) override
void OnEditSymbol(wxCommandEvent &) override
void OnCancelButtonClick(wxCommandEvent &event) override
virtual void onUpdateEditLibrarySymbol(wxUpdateUIEvent &event) override
PANEL_SYMBOL_PIN_MAP * m_pinMapPanel
SCH_PIN_TABLE_DATA_MODEL * m_dataModel
void OnMoveDown(wxCommandEvent &event) override
void OnPinTableColSort(wxGridEvent &aEvent)
void OnMoveUp(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
void OnAddField(wxCommandEvent &event) override
void OnGridEditorHidden(wxGridEvent &event) override
PANEL_EMBEDDED_FILES * m_embeddedFiles
void OnUnitChoice(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void OnPageChanging(wxNotebookEvent &event) override
DIALOG_SYMBOL_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SYMBOL *aSymbol)
void HandleDelayedFocus(wxCommandEvent &event)
void HandleDelayedSelection(wxCommandEvent &event)
void OnCheckBox(wxCommandEvent &event) override
void OnGridCellChanging(wxGridEvent &event)
void OnEditLibrarySymbol(wxCommandEvent &) override
void OnUpdateSymbol(wxCommandEvent &) override
void SelectPinMapPage()
Select the Pin Map page so the dialog opens directly on the pin-to-pad mapping editor (issue #2282).
void OnExchangeSymbol(wxCommandEvent &) override
virtual void onUpdateEditSymbol(wxUpdateUIEvent &event) override
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
virtual void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:576
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:269
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:61
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Define a library symbol object.
Definition lib_symbol.h:114
bool IsPower() const override
bool IsMultiBodyStyle() const override
Definition lib_symbol.h:904
bool IsLocalPower() const override
const std::vector< wxString > & GetBodyStyleNames() const
bool HasDeMorganBodyStyles() const override
int GetBodyStyleCount() const override
The body styles are a property of the drawings, which a derived symbol inherits from its root symbol ...
Composed widget that edits a symbol's named pin maps and the footprint each is bound to.
static int Compare(const wxString &lhs, const wxString &rhs)
TEMPLATES m_TemplateFieldNames
Project and global field name templates shared by project editors.
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
Holds all the data relating to one schematic.
Definition schematic.h:155
wxString GetPackageRefSuffix(const SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aPath) const
Return the suffix the package of a multi-unit symbol's instance composes with.
wxString ConvertKIIDsToRefs(const wxString &aSource) const
void SyncLibSymbolPinMaps(const wxString &aSchLibSymbolName, const LIB_SYMBOL &aSource, SCH_COMMIT *aCommit)
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:177
wxString GetCurrentVariant() const
Return the current variant being edited.
wxString GetRefSuffix(const SCH_SHEET_PATH &aPath) const
Return the composed reference suffix of aPath as of the last RefreshHierarchy().
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
bool IsMandatory() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetText(const wxString &aText) override
bool IsEmptyCell(int row, int col) override
wxString GetValue(int aRow, int aCol) override
std::vector< wxGridCellAttr * > m_nameAttrs
static bool compare(const SCH_PIN &lhs, const SCH_PIN &rhs, int sortCol, bool ascending)
void SortRows(int aSortCol, bool ascending)
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
static wxString GetValue(const SCH_PIN &aPin, int aCol)
wxString GetColLabelValue(int aCol) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
const std::map< wxString, ALT > & GetAlternates() const
Definition sch_pin.h:219
ALT GetAlt(const wxString &aAlt)
Definition sch_pin.h:233
SCH_PIN * GetLibPin() const
Definition sch_pin.h:109
const wxString & GetName() const
Definition sch_pin.cpp:530
const wxString & GetBaseName() const
Get the name without any alternates.
Definition sch_pin.cpp:539
const wxString & GetNumber() const
Definition sch_pin.h:144
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:403
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:438
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:76
std::optional< SCH_SYMBOL_VARIANT > GetVariant(const SCH_SHEET_PATH &aInstance, const wxString &aVariantName) const
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:185
virtual bool GetShowPinNames() const
Definition symbol.h:169
virtual bool GetShowPinNumbers() const
Definition symbol.h:175
const std::vector< TEMPLATE_FIELDNAME > & GetResolvedTemplateFieldNames()
Return the resolved project and global template field name list for read only access.
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
Definition wx_grid.cpp:44
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
wxDEFINE_EVENT(SYMBOL_DELAY_FOCUS, wxCommandEvent)
@ SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL
@ SYMBOL_PROPS_WANT_EXCHANGE_SYMBOL
@ SYMBOL_PROPS_WANT_UPDATE_SYMBOL
@ SYMBOL_PROPS_WANT_SET_VARIANT_SYMBOL
@ SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL
@ SYMBOL_PROPS_WANT_CLEAR_VARIANT_SYMBOL
#define _(s)
std::uint32_t EDA_ITEM_FLAGS
@ FDC_NAME
@ FDC_VALUE
wxColour GetDialogBGColour()
Definition wxgtk/ui.cpp:70
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition wxgtk/ui.cpp:496
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
KICOMMON_API void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
const std::vector< BITMAPS > & PinTypeIcons()
Definition pin_type.cpp:159
const wxArrayString & PinTypeNames()
Definition pin_type.cpp:150
const wxArrayString & PinShapeNames()
Definition pin_type.cpp:168
const std::vector< BITMAPS > & PinShapeIcons()
Definition pin_type.cpp:177
#define NO_PIN_FUNCTIONS_WITH_MULTIPLE_BODY_STYLES
Definition sch_actions.h:34
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
wxString UnescapeString(const wxString &aSource)
Hold a name of a symbol's field, field value, and default visibility.
@ SYM_ORIENT_270
Definition symbol.h:39
@ SYM_MIRROR_Y
Definition symbol.h:41
@ SYM_ORIENT_180
Definition symbol.h:38
@ SYM_MIRROR_X
Definition symbol.h:40
@ SYM_ORIENT_90
Definition symbol.h:37
@ SYM_ORIENT_0
Definition symbol.h:36
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.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ TRANSLATED
nanodbc::result res
static EDA_ORIENTATION orientation(double d)
KIBIS_PIN * pin
VECTOR2I end
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708