KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_symbol_fields_table.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) 2017 Oliver Walters
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <advanced_config.h>
22#include <common.h>
23#include <base_units.h>
24#include <confirm.h>
25#include <eda_doc.h>
26#include <fields_grid_table.h>
27#include <schematic_settings.h>
28#include <general.h>
29#include <grid_tricks.h>
30#include <string_utils.h>
31#include <template_fieldnames.h>
32#include <kiface_base.h>
33#include <sch_edit_frame.h>
34#include <sch_group.h>
36#include <widgets/wx_infobar.h>
37#include <sch_reference_list.h>
41#include <widgets/wx_grid.h>
42#include <wx/debug.h>
43#include <wx/grid.h>
44#include <wx/textdlg.h>
45#include <wx/msgdlg.h>
50#include <project_sch.h>
52#include <jobs/job_export_bom.h>
53#include <tools/sch_actions.h>
54#include <tool/tool_manager.h>
56#include <sch_sheet_path.h>
57
58wxDEFINE_EVENT( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxCommandEvent );
59
61
62
63// Used for the footprint chooser grid helper
64static wxString getFootprintChooserSymbolNetlist( const std::vector<SCH_REFERENCE>& aReferences,
65 const wxString& aVariantName )
66{
67 std::vector<LIB_SYMBOL*> symbols;
68
69 for( const SCH_REFERENCE& reference : aReferences )
70 {
71 SCH_SYMBOL* symbol = reference.GetSymbol();
72
73 if( !symbol )
74 return wxEmptyString;
75
76 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
77
78 if( LIB_SYMBOL* variantSymbol =
79 symbol->GetVariantLibSymbol( aVariantName, reference.GetSheetPath() ) )
80 {
81 libSymbol = variantSymbol;
82 }
83
84 symbols.push_back( libSymbol );
85 }
86
87 return BuildFootprintChooserSymbolNetlist( symbols );
88}
89
90
91enum
92{
101};
102
104{
105public:
107 VIEW_CONTROLS_GRID_DATA_MODEL* aViewFieldsData,
109 FIELDS_TABLE_GRID_TRICKS( aParent, aGrid, aDataModel ),
110 m_dlg( aParent ),
111 m_viewControlsDataModel( aViewFieldsData ),
112 m_dataModel( aDataModel ),
113 m_files( aFiles )
114 {}
115
116protected:
117 bool toggleCell( int aRow, int aCol, bool aPreserveSelection = false ) override
118 {
119 if( !m_grid->IsEditable() || m_dataModel->IsCellReadOnly( aRow, aCol ) )
120 return false;
121
122 return GRID_TRICKS::toggleCell( aRow, aCol, aPreserveSelection );
123 }
124
125 void showFieldsTablePopupMenu( wxMenu& aMenu, wxGridEvent& aEvent ) override
126 {
127 int row = m_grid->GetGridCursorRow();
128 int col = m_grid->GetGridCursorCol();
129
130 if( row >= 0 && col >= 0 )
131 {
132 if( m_dataModel->GetColFieldName( col ) == GetDefaultFieldName( FIELD_T::FOOTPRINT, UNTRANSLATED ) )
133 {
134 aMenu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ), _( "Browse for footprint" ) );
135 aMenu.AppendSeparator();
136 }
137 else if( m_dataModel->GetColFieldName( col ) == GetDefaultFieldName( FIELD_T::DATASHEET, UNTRANSLATED ) )
138 {
139 aMenu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ), _( "Show datasheet in browser" ) );
140 aMenu.AppendSeparator();
141 }
142
143 SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( m_dlg->GetParent() );
144
145 if( frame && !frame->Schematic().GetCurrentVariant().IsEmpty() )
146 {
147 std::vector<SCH_REFERENCE> refs = m_dataModel->GetRowReferences( row );
148
149 if( refs.size() == 1 && refs[0].GetSymbol() )
150 {
151 aMenu.AppendSeparator();
152 aMenu.Append( MYID_SET_VARIANT_SYMBOL, _( "Set Variant Symbol..." ) );
153
154 const SCH_SYMBOL* symbol = refs[0].GetSymbol();
155 wxString variantName = frame->Schematic().GetCurrentVariant();
156 auto variant = symbol->GetVariant( refs[0].GetSheetPath(), variantName );
157
158 if( variant && variant->m_SymbolOverride )
159 aMenu.Append( MYID_CLEAR_VARIANT_SYMBOL, _( "Clear Variant Symbol" ) );
160 }
161 }
162 }
163
164 GRID_TRICKS::showPopupMenu( aMenu, aEvent );
165 }
166
167 void doFieldsTablePopupSelection( wxCommandEvent& aEvent ) override
168 {
169 int row = m_grid->GetGridCursorRow();
170 int col = m_grid->GetGridCursorCol();
171
172 if( aEvent.GetId() == MYID_SELECT_FOOTPRINT )
173 {
174 // pick a footprint using the footprint picker.
175 wxString fpid = m_grid->GetCellValue( row, col );
176
177 wxString symbolNetlist = getFootprintChooserSymbolNetlist(
178 m_dataModel->GetRowReferences( row ), m_dataModel->GetCurrentVariant() );
179
180 if( SelectFootprintFromChooser( m_dlg, fpid, symbolNetlist ) )
181 m_grid->SetCellValue( row, col, fpid );
182 }
183 else if( aEvent.GetId() == MYID_SHOW_DATASHEET )
184 {
185 wxString datasheetUri = m_grid->GetCellValue( row, col );
186 GetAssociatedDocument( m_dlg, datasheetUri, &m_dlg->Prj(), PROJECT_SCH::SchSearchS( &m_dlg->Prj() ),
187 { m_files } );
188 }
189 else if( aEvent.GetId() == MYID_SET_VARIANT_SYMBOL
190 || aEvent.GetId() == MYID_CLEAR_VARIANT_SYMBOL )
191 {
192 SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( m_dlg->GetParent() );
193
194 if( !frame )
195 return;
196
197 std::vector<SCH_REFERENCE> refs = m_dataModel->GetRowReferences( row );
198
199 if( refs.size() != 1 || !refs[0].GetSymbol() )
200 return;
201
202 SCH_SELECTION_TOOL* selectionTool = frame->GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
203 std::vector<SCH_ITEM*> items = { refs[0].GetSymbol() };
204 selectionTool->SyncSelection( refs[0].GetSheetPath(), nullptr, items );
205
206 if( aEvent.GetId() == MYID_SET_VARIANT_SYMBOL )
208 else
210 }
211 else if( aEvent.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE )
212 {
213 if( !m_grid->CommitPendingChanges( false ) )
214 return;
215
216 // Pop-up column order is the order of the shown fields, not the viewControls order
217 col = aEvent.GetId() - GRIDTRICKS_FIRST_SHOWHIDE;
218
219 bool show = !m_dataModel->GetShowColumn( col );
220
221 m_dlg->ShowHideColumn( col, show );
222
223 wxString fieldName = m_dataModel->GetColFieldName( col );
224
225 for( row = 0; row < m_viewControlsDataModel->GetNumberRows(); row++ )
226 {
227 if( m_viewControlsDataModel->GetUntranslatedFieldName( row ) == fieldName )
228 m_viewControlsDataModel->SetValueAsBool( row, SHOW_FIELD_COLUMN, show );
229 }
230
231 if( m_viewControlsDataModel->GetView() )
232 m_viewControlsDataModel->GetView()->ForceRefresh();
233 }
234 else
235 {
237 }
238 }
239
240private:
245};
246
247
249 DIALOG_FIELDS_TABLE( aParent, aParent->eeconfig()->m_FieldEditorPanel,
250 aParent->Schematic().Settings(), aJob ),
251 m_parent( aParent ),
252 m_templateFieldNames( aParent->Prj().GetProjectFile().m_TemplateFieldNames )
253{
254 // Get all symbols from the list of schematic sheets
255 m_parent->Schematic().Hierarchy().GetSymbols( m_symbolsList, SYMBOL_FILTER_NON_POWER );
256
257 if( std::vector<FIELD_CASE_CONFLICT> conflicts = DetectFieldCaseConflicts( m_symbolsList ); !conflicts.empty() )
258 {
259 DIALOG_RESOLVE_FIELD_CASE_CONFLICTS resolver( this, m_parent, std::move( conflicts ) );
260
261 if( resolver.ShowModal() != wxID_OK )
262 {
263 m_aborted = true;
264 return;
265 }
266
267 m_symbolsList.Clear();
268 m_parent->Schematic().Hierarchy().GetSymbols( m_symbolsList, SYMBOL_FILTER_NON_POWER );
269 }
270
272
273 m_grid->UseNativeColHeader( true );
274 m_grid->SetTable( m_dataModel, true );
275
276 // The field-list grid regroups its rows, so the dialog's position-based Ctrl+Z would shift
277 // values onto the wrong field.
279
280 // must be done after SetTable(), which appears to re-set it
281 m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
282
283 // add Cut, Copy, and Paste to wxGrid
285 &m_parent->Schematic() ) );
286
287 m_variantListBox->Set( m_parent->Schematic().GetVariantNamesForUI() );
288
289 // A job keeps its own variant, otherwise follow the schematic.
290 wxString variantToSelect;
291
292 if( m_job )
293 variantToSelect = m_job->GetSelectedVariant();
294 else
295 variantToSelect = m_parent->Schematic().GetCurrentVariant();
296
297 if( !variantToSelect.IsEmpty() )
298 {
299 int toSelect = m_variantListBox->FindString( variantToSelect );
300
301 if( toSelect == wxNOT_FOUND )
302 m_variantListBox->SetSelection( 0 );
303 else
304 m_variantListBox->SetSelection( toSelect );
305 }
306 else
307 {
308 m_variantListBox->SetSelection( 0 );
309 }
310
312
313 if( m_job )
314 SetTitle( m_job->GetSettingsDialogTitle() );
315 else
316 SetTitle( _( "Symbol Fields Table" ) );
317
318 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
319 // non-job versions (which have different sizes).
320 m_hash_key = TO_UTF8( GetTitle() );
321
322 // Set the current variant for highlighting variant-specific field values
323 m_dataModel->SetCurrentVariant( resolveVariant() );
324
326 m_grid->ClearSelection();
327
329
331
332 SetSize( GetDefaultDialogSize() );
333
335
337
338 if( m_job )
339 m_outputFileName->SetValue( m_job->GetConfiguredOutputPath() );
340 else
341 m_outputFileName->SetValue( m_cfgBomSettings.m_BomExportFileName );
342
343 Center();
344
345 // Connect Events
346 m_grid->Bind( wxEVT_GRID_COL_SORT, &DIALOG_SYMBOL_FIELDS_TABLE::OnColSort, this );
347 m_grid->Bind( wxEVT_GRID_COL_MOVE, &DIALOG_SYMBOL_FIELDS_TABLE::OnColMove, this );
348 m_grid->GetGridWindow()->Bind( wxEVT_MOTION, &DIALOG_SYMBOL_FIELDS_TABLE::OnGridMouseMove, this );
351
352 if( !m_job )
353 {
354 // Start listening for schematic changes
355 m_parent->Schematic().AddListener( this );
356 }
357 else
358 {
359 // Don't allow editing
360 m_grid->EnableEditing( false );
361 m_buttonApply->Hide();
362 m_buttonExport->Hide();
363 }
364}
365
366
368{
369 if( m_aborted )
370 return;
371
372 if( !m_job )
373 m_parent->Schematic().RemoveListener( this );
374
377
378 // Disconnect Events
379 m_grid->GetGridWindow()->Unbind( wxEVT_MOTION, &DIALOG_SYMBOL_FIELDS_TABLE::OnGridMouseMove, this );
380 m_grid->Unbind( wxEVT_GRID_COL_SORT, &DIALOG_SYMBOL_FIELDS_TABLE::OnColSort, this );
381 m_grid->Unbind( wxEVT_GRID_COL_MOVE, &DIALOG_SYMBOL_FIELDS_TABLE::OnColMove, this );
384
385 // Delete the GRID_TRICKS.
386 m_grid->PopEventHandler( true );
387
388 // we gave ownership of m_viewControlsDataModel & m_dataModel to the wxGrids...
389}
390
391
393{
394 return new GRID_CELL_URL_EDITOR( this, PROJECT_SCH::SchSearchS( &Prj() ), { &m_parent->Schematic() } );
395}
396
397
399{
400 return new GRID_CELL_FPID_EDITOR(
401 this,
402 [this]( int aRow )
403 {
404 return getFootprintChooserSymbolNetlist( m_dataModel->GetRowReferences( aRow ),
405 m_dataModel->GetCurrentVariant() );
406 } );
407}
408
409
411{
412 if( !wxDialog::TransferDataToWindow() )
413 return false;
414
415 LoadFieldNames(); // loads rows into m_viewControlsDataModel and columns into m_dataModel
416
417 // Load our BOM view presets
418 SetUserBomPresets( m_cfgBomSettings.m_BomPresets );
419
420 BOM_PRESET preset = m_cfgBomSettings.m_BomSettings;
421
422 if( m_job )
423 loadJobBomPreset( *m_job, preset );
424
425 ApplyBomPreset( preset );
427
428 // Load BOM export format presets
429 SetUserBomFmtPresets( m_cfgBomSettings.m_BomFmtPresets );
430 BOM_FMT_PRESET fmtPreset = m_cfgBomSettings.m_BomFmtSettings;
431
432 if( m_job )
433 loadJobBomFmtPreset( *m_job, fmtPreset );
434
435 ApplyBomFmtPreset( fmtPreset );
437
438 if( !m_job )
439 m_outputFileName->SetValue( m_cfgBomSettings.m_BomExportFileName );
440
441 TOOL_MANAGER* toolManager = m_parent->GetToolManager();
442 SCH_SELECTION_TOOL* selectionTool = toolManager->GetTool<SCH_SELECTION_TOOL>();
443 SCH_SELECTION& selection = selectionTool->GetSelection();
444 SCH_SYMBOL* symbol = nullptr;
445
446 m_dataModel->SetGroupingEnabled( m_groupSymbolsBox->GetValue() );
447
448 setScope( static_cast<SCOPE>( m_scope->GetSelection() ) );
449
450 if( selection.GetSize() == 1 )
451 {
452 EDA_ITEM* item = selection.Front();
453
454 if( item->Type() == SCH_SYMBOL_T )
455 symbol = static_cast<SCH_SYMBOL*>( item );
456 else if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T )
457 symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
458 }
459
460 if( symbol )
461 {
462 for( int row = 0; row < m_dataModel->GetNumberRows(); ++row )
463 {
464 std::vector<SCH_REFERENCE> references = m_dataModel->GetRowReferences( row );
465 bool found = false;
466
467 for( const SCH_REFERENCE& ref : references )
468 {
469 if( ref.GetSymbol() == symbol )
470 {
471 found = true;
472 break;
473 }
474 }
475
476 if( found )
477 {
478 // Find the value column and the reference column if they're shown
479 int valueCol = -1;
480 int refCol = -1;
481 int anyCol = -1;
482
483 for( int col = 0; col < m_dataModel->GetNumberCols(); col++ )
484 {
485 if( m_dataModel->ColIsValue( col ) )
486 valueCol = col;
487 else if( m_dataModel->ColIsReference( col ) )
488 refCol = col;
489 else if( anyCol == -1 && m_dataModel->GetShowColumn( col ) )
490 anyCol = col;
491 }
492
493 if( valueCol != -1 && m_dataModel->GetShowColumn( valueCol ) )
494 m_grid->GoToCell( row, valueCol );
495 else if( refCol != -1 && m_dataModel->GetShowColumn( refCol ) )
496 m_grid->GoToCell( row, refCol );
497 else if( anyCol != -1 )
498 m_grid->GoToCell( row, anyCol );
499
500 break;
501 }
502 }
503 }
504
505 // We don't want table range selection events to happen until we've loaded the data or we
506 // we'll clear our selection as the grid is built before the code above can get the
507 // user's current selection.
509
511
512 return true;
513}
514
515
517{
518 if( !m_grid->CommitPendingChanges() )
519 return false;
520
521 if( !wxDialog::TransferDataFromWindow() )
522 return false;
523
524 if( m_job )
525 {
526 // and exit, don't even dream of saving changes from the data model
527 return true;
528 }
529
530 SCH_COMMIT commit( m_parent );
531 SCH_SHEET_PATH currentSheet = m_parent->GetCurrentSheet();
532
533 m_dataModel->ApplyData( commit, m_templateFieldNames );
534
535 if( !commit.Empty() )
536 {
537 commit.Push( wxS( "Symbol Fields Table Edit" ) ); // Push clears the commit buffer.
538 m_parent->OnModify();
539 }
540
541 // Reset the view to where we left the user
542 m_parent->SetCurrentSheet( currentSheet );
543 m_parent->SyncView();
544 m_parent->Refresh();
545
546 return true;
547}
548
549
551{
552 auto addMandatoryField =
553 [&]( FIELD_T aFieldId, bool aShow, bool aGroupBy )
554 {
555 m_mandatoryFieldListIndexes[aFieldId] = m_viewControlsDataModel->GetNumberRows();
556
558 aShow, aGroupBy );
559 };
560
561 // Add mandatory fields first show groupBy
562 addMandatoryField( FIELD_T::REFERENCE, true, true );
563 addMandatoryField( FIELD_T::VALUE, true, true );
564 addMandatoryField( FIELD_T::FOOTPRINT, true, true );
565 addMandatoryField( FIELD_T::DATASHEET, true, false );
566 addMandatoryField( FIELD_T::DESCRIPTION, false, false );
567
568 // Generated fields present only in the fields table
571
572 // User field names are stored and matched case-sensitively (see issue #24021), so each
573 // distinct name gets its own column rather than collapsing case variants together.
574 std::set<wxString> userFieldNames;
575
576 for( const SCH_REFERENCE& ref : m_symbolsList )
577 {
578 SCH_SYMBOL* symbol = ref.GetSymbol();
579
580 for( const SCH_FIELD& field : symbol->GetFields() )
581 {
582 if( !field.IsMandatory() && !field.IsPrivate() )
583 userFieldNames.insert( field.GetName() );
584 }
585 }
586
587 for( const wxString& fieldName : userFieldNames )
588 AddField( fieldName, GetGeneratedFieldDisplayName( fieldName ), true, false );
589
590 // Add any templateFieldNames which aren't already present.
591 for( const TEMPLATE_FIELDNAME& templateField : m_templateFieldNames.GetResolvedTemplateFieldNames() )
592 {
593 if( userFieldNames.count( templateField.m_Name ) == 0 )
594 AddField( templateField.m_Name, GetGeneratedFieldDisplayName( templateField.m_Name ), false, false );
595 }
596}
597
598
600{
601 m_dataModel->SetPath( m_parent->GetCurrentSheet() );
602 m_dataModel->SetScope( aScope );
603
604 if( aScope == SCOPE::SCOPE_SELECTION )
606
607 m_dataModel->RebuildRows();
608}
609
610
612{
613 std::unordered_set<KIID_PATH> selectionItems;
614 SCH_SELECTION_TOOL* selectionTool = m_parent->GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
615 const SCH_SELECTION& selection = selectionTool->GetSelection();
616 const KIID_PATH currentSheetPath = m_parent->GetCurrentSheet().Path();
617
618 auto addSelectionItem = [&]( EDA_ITEM* aItem )
619 {
620 SCH_SYMBOL* symbol = nullptr;
621
622 if( aItem->Type() == SCH_SYMBOL_T )
623 symbol = static_cast<SCH_SYMBOL*>( aItem );
624 else if( aItem->GetParent() && aItem->GetParent()->Type() == SCH_SYMBOL_T )
625 symbol = static_cast<SCH_SYMBOL*>( aItem->GetParent() );
626
627 if( symbol )
628 {
629 KIID_PATH path = currentSheetPath;
630 path.push_back( symbol->m_Uuid );
631 selectionItems.insert( path );
632
633 return;
634 }
635
636 if( aItem->Type() == SCH_SHEET_T )
637 {
638 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
639
640 SCH_SHEET_PATH selectedPath = m_parent->GetCurrentSheet();
641 selectedPath.push_back( sheet );
642
643 SCH_REFERENCE_LIST references;
644 m_parent->Schematic().Hierarchy().GetSymbolsWithinPath( references, selectedPath, SYMBOL_FILTER_NON_POWER );
645
646 for( const SCH_REFERENCE& ref : references )
647 {
648 if( ref.GetSymbol() )
649 {
650 KIID_PATH path = ref.GetSheetPath().Path();
651 path.push_back( ref.GetSymbol()->m_Uuid );
652 selectionItems.insert( path );
653 }
654 }
655 }
656 };
657
658 for( EDA_ITEM* item : selection )
659 {
660 if( item->Type() == SCH_GROUP_T )
661 static_cast<SCH_GROUP*>( item )->RunOnChildren( addSelectionItem, RECURSE_MODE::RECURSE );
662 else
663 addSelectionItem( item );
664 }
665
666 m_dataModel->SetSelectionItems( selectionItems );
667}
668
669
670void DIALOG_SYMBOL_FIELDS_TABLE::OnScope( wxCommandEvent& aEvent )
671{
672 switch( aEvent.GetSelection() )
673 {
674 case 0: setScope( SCOPE::SCOPE_ALL ); break;
675 case 1: setScope( SCOPE::SCOPE_SHEET ); break;
676 case 2: setScope( SCOPE::SCOPE_SHEET_RECURSIVE ); break;
677 case 3: setScope( SCOPE::SCOPE_SELECTION ); break;
678 }
679}
680
681
682void DIALOG_SYMBOL_FIELDS_TABLE::OnMenu( wxCommandEvent& aEvent )
683{
684 // Build a pop menu:
685 wxMenu menu;
686
687 menu.Append( MYID_INCLUDE_DNP, _( "Include 'DNP' Symbols" ),
688 _( "Show symbols marked 'DNP' in the table. This setting also controls whether or not 'DNP' "
689 "symbols are included on export." ),
690 wxITEM_CHECK );
691 menu.Check( MYID_INCLUDE_DNP, !m_dataModel->GetExcludeDNP() );
692
693 menu.Append( MYID_INCLUDE_EXCLUDED_FROM_BOM, _( "Include 'Exclude from BOM' Symbols" ),
694 _( "Show symbols marked 'Exclude from BOM' in the table. Symbols marked 'Exclude from BOM' "
695 "are never included on export." ),
696 wxITEM_CHECK );
697 menu.Check( MYID_INCLUDE_EXCLUDED_FROM_BOM, m_dataModel->GetIncludeExcludedFromBOM() );
698
699 menu.AppendSeparator();
700
701 menu.Append( MYID_HIGHLIGHT_ON_CROSS_PROBE, _( "Highlight on Cross-probe" ),
702 _( "Highlight corresponding item on canvas when it is selected in the table" ),
703 wxITEM_CHECK );
704 menu.Check( MYID_HIGHLIGHT_ON_CROSS_PROBE, m_cfgDialogSettings.selection_mode == 0 );
705
706 menu.Append( MYID_SELECT_ON_CROSS_PROBE, _( "Select on Cross-probe" ),
707 _( "Select corresponding item on canvas when it is selected in the table" ),
708 wxITEM_CHECK );
709 menu.Check( MYID_SELECT_ON_CROSS_PROBE, m_cfgDialogSettings.selection_mode == 1 );
710
711 // menuId is the selected submenu id from the popup menu or wxID_NONE
712 int menuId = m_bMenu->GetPopupMenuSelectionFromUser( menu );
713
714 if( menuId == 0 || menuId == MYID_INCLUDE_DNP )
715 {
716 m_dataModel->SetExcludeDNP( !m_dataModel->GetExcludeDNP() );
717 m_dataModel->RebuildRows();
718 m_grid->ForceRefresh();
719
721 }
722 else if( menuId == 1 || menuId == MYID_INCLUDE_EXCLUDED_FROM_BOM )
723 {
724 m_dataModel->SetIncludeExcludedFromBOM( !m_dataModel->GetIncludeExcludedFromBOM() );
725 m_dataModel->RebuildRows();
726 m_grid->ForceRefresh();
727
729 }
730 else if( menuId == 3 || menuId == MYID_HIGHLIGHT_ON_CROSS_PROBE )
731 {
732 if( m_cfgDialogSettings.selection_mode != 0 )
733 m_cfgDialogSettings.selection_mode = 0;
734 else
735 m_cfgDialogSettings.selection_mode = 2;
736 }
737 else if( menuId == 4 || menuId == MYID_SELECT_ON_CROSS_PROBE )
738 {
739 if( m_cfgDialogSettings.selection_mode != 1 )
740 m_cfgDialogSettings.selection_mode = 1;
741 else
742 m_cfgDialogSettings.selection_mode = 2;
743 }
744}
745
746
748{
749 // Cross-probing should only work in Edit page
750 if( m_nbPages->GetSelection() != 0 )
751 return;
752
753 // Cross-probing is disabled when we're in selection scope mode, otherwise
754 // we're just in a loop
755 if( m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION )
756 return;
757
758 // Multi-select can grab the rows that are expanded child refs, and also the row
759 // containing the list of all child refs. Make sure we add refs/symbols uniquely
760 std::set<SCH_REFERENCE> refs;
761 std::set<SCH_ITEM*> symbols;
762
763 for( int row : aRows )
764 {
765 for( const SCH_REFERENCE& ref : m_dataModel->GetRowReferences( row ) )
766 refs.insert( ref );
767 }
768
769 for( const SCH_REFERENCE& ref : refs )
770 symbols.insert( ref.GetSymbol() );
771
772 if( m_cfgDialogSettings.selection_mode == 0 )
773 {
774 SCH_EDITOR_CONTROL* editor = m_parent->GetToolManager()->GetTool<SCH_EDITOR_CONTROL>();
775
776 if( refs.size() > 0 )
777 {
778 // Use of full path based on UUID allows select of not yet annotated or duplicated
779 // symbols
780 wxString symbolPath = refs.begin()->GetFullPath();
781
782 // Focus only handles one item at this time
783 editor->FindSymbolAndItem( &symbolPath, nullptr, true, HIGHLIGHT_SYMBOL, wxEmptyString );
784 }
785 else
786 {
787 m_parent->ClearFocus();
788 }
789 }
790 else if( m_cfgDialogSettings.selection_mode == 1 )
791 {
792 SCH_SELECTION_TOOL* selectionTool = m_parent->GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
793 std::vector<SCH_ITEM*> items( symbols.begin(), symbols.end() );
794
795 if( refs.size() > 0 )
796 selectionTool->SyncSelection( refs.begin()->GetSheetPath(), nullptr, items );
797 else
798 selectionTool->ClearSelection();
799 }
800}
801
802
804{
806 {
807 m_cfgBomSettings.m_BomExportFileName = m_outputFileName->GetValue();
808 m_parent->SaveProject();
809 ClearModify();
810 }
811}
812
813
814void DIALOG_SYMBOL_FIELDS_TABLE::OnCancel( wxCommandEvent& aEvent )
815{
816 if( m_job )
817 {
818 EndModal( wxID_CANCEL );
819 }
820 else
821 {
822 // Discard any unsaved edit in the output filename field
823 m_outputFileName->SetValue( m_cfgBomSettings.m_BomExportFileName );
824 Close();
825 }
826}
827
828
829void DIALOG_SYMBOL_FIELDS_TABLE::OnOk( wxCommandEvent& aEvent )
830{
832 return;
833
834 if( m_job )
835 {
837 EndModal( wxID_OK );
838 }
839 else
840 {
841 if( m_cfgBomSettings.m_BomExportFileName != m_outputFileName->GetValue() )
842 {
843 m_cfgBomSettings.m_BomExportFileName = m_outputFileName->GetValue();
844 m_parent->OnModify();
845 }
846
847 Close();
848 }
849}
850
851
852void DIALOG_SYMBOL_FIELDS_TABLE::OnClose( wxCloseEvent& aEvent )
853{
854 if( m_job )
855 {
856 aEvent.Skip();
857 return;
858 }
859
860 m_grid->CommitPendingChanges( true );
861
862 if( m_dataModel->IsEdited() && aEvent.CanVeto() )
863 {
864 if( !HandleUnsavedChanges( this, _( "Save changes?" ),
865 [&]() -> bool
866 {
867 return TransferDataFromWindow();
868 } ) )
869 {
870 aEvent.Veto();
871 return;
872 }
873 }
874
875 if( savePresets( true ) )
876 m_parent->OnModify();
877
878 // Stop listening to schematic events
879 m_parent->Schematic().RemoveListener( this );
880 m_parent->ClearFocus();
881
882 wxCommandEvent* event = new wxCommandEvent( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxID_ANY );
883
884 if( wxWindow* parentWindow = GetParent() )
885 wxQueueEvent( parentWindow, event );
886}
887
888
889void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem )
890{
891 std::set<KIID_PATH> savedSelection = SaveGridSelection();
892
893 SCH_REFERENCE_LIST allRefs;
894 m_parent->Schematic().Hierarchy().GetSymbols( allRefs, SYMBOL_FILTER_NON_POWER );
895
896 for( SCH_ITEM* item : aSchItem )
897 {
898 if( item->Type() == SCH_SYMBOL_T )
899 {
900 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
901
902 // Don't add power symbols
903 if( !symbol->IsMissingLibSymbol() && symbol->IsPower() )
904 continue;
905
906 // Add all fields again in case this symbol has a new one
907 for( SCH_FIELD& field : symbol->GetFields() )
908 {
909 if( !field.IsMandatory() && !field.IsPrivate() )
910 AddField( field.GetUntranslatedName(), field.GetName(), true, false, false );
911 }
912
913 m_dataModel->AddReferences( getSymbolReferences( symbol, allRefs ) );
914 }
915 else if( item->Type() == SCH_SHEET_T )
916 {
917 std::set<SCH_SYMBOL*> symbols;
918 SCH_REFERENCE_LIST refs = getSheetSymbolReferences( *static_cast<SCH_SHEET*>( item ) );
919
920 for( SCH_REFERENCE& ref : refs )
921 symbols.insert( ref.GetSymbol() );
922
923 for( SCH_SYMBOL* symbol : symbols )
924 {
925 // Add all fields again in case this symbol has a new one
926 for( SCH_FIELD& field : symbol->GetFields() )
927 {
928 if( !field.IsMandatory() && !field.IsPrivate() )
929 AddField( field.GetUntranslatedName(), field.GetName(), true, false, false );
930 }
931 }
932
933 m_dataModel->AddReferences( refs );
934 }
935 }
936
937 rebuildRowsPreservingSelection( savedSelection );
938}
939
940
941void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem )
942{
943 std::set<KIID_PATH> savedSelection = SaveGridSelection();
944
945 for( SCH_ITEM* item : aSchItem )
946 {
947 if( item->Type() == SCH_SYMBOL_T )
948 m_dataModel->RemoveSymbol( *static_cast<SCH_SYMBOL*>( item ) );
949 else if( item->Type() == SCH_SHEET_T )
950 m_dataModel->RemoveReferences( getSheetSymbolReferences( *static_cast<SCH_SHEET*>( item ) ) );
951 }
952
953 rebuildRowsPreservingSelection( savedSelection );
954}
955
956
957void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem )
958{
959 std::set<KIID_PATH> savedSelection = SaveGridSelection();
960
961 SCH_REFERENCE_LIST allRefs;
962 m_parent->Schematic().Hierarchy().GetSymbols( allRefs, SYMBOL_FILTER_NON_POWER );
963
964 for( SCH_ITEM* item : aSchItem )
965 {
966 if( item->Type() == SCH_SYMBOL_T )
967 {
968 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
969
970 // Don't add power symbols
971 if( !symbol->IsMissingLibSymbol() && symbol->IsPower() )
972 continue;
973
974 // Add all fields again in case this symbol has a new one
975 for( SCH_FIELD& field : symbol->GetFields() )
976 {
977 if( !field.IsMandatory() && !field.IsPrivate() )
978 AddField( field.GetUntranslatedName(), field.GetName(), true, false, false );
979 }
980
981 m_dataModel->UpdateReferences( getSymbolReferences( symbol, allRefs ) );
982 }
983 else if( item->Type() == SCH_SHEET_T )
984 {
985 std::set<SCH_SYMBOL*> symbols;
986 SCH_REFERENCE_LIST refs = getSheetSymbolReferences( *static_cast<SCH_SHEET*>( item ) );
987
988 for( SCH_REFERENCE& ref : refs )
989 symbols.insert( ref.GetSymbol() );
990
991 for( SCH_SYMBOL* symbol : symbols )
992 {
993 // Add all fields again in case this symbol has a new one
994 for( SCH_FIELD& field : symbol->GetFields() )
995 {
996 if( !field.IsMandatory() && !field.IsPrivate() )
997 AddField( field.GetUntranslatedName(), field.GetName(), true, false, false );
998 }
999 }
1000
1001 m_dataModel->UpdateReferences( refs );
1002 }
1003 }
1004
1005 rebuildRowsPreservingSelection( savedSelection );
1006}
1007
1008
1010{
1011 m_dataModel->SetPath( aSch.CurrentSheet() );
1012
1013 if( m_dataModel->GetScope() != SCOPE::SCOPE_ALL )
1015}
1016
1017
1019{
1020 if( m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION )
1022}
1023
1024
1029
1030
1031void DIALOG_SYMBOL_FIELDS_TABLE::rebuildRowsPreservingSelection( const std::set<KIID_PATH>& aSavedSelection )
1032{
1034
1035 if( m_dataModel->GetScope() == SCOPE::SCOPE_SELECTION )
1037
1038 m_dataModel->RebuildRows();
1039 RestoreGridSelection( aSavedSelection );
1040
1042}
1043
1044
1046 SCH_REFERENCE_LIST& aCachedRefs )
1047{
1048 SCH_REFERENCE_LIST symbolRefs;
1049
1050 for( size_t i = 0; i < aCachedRefs.GetCount(); i++ )
1051 {
1052 SCH_REFERENCE& ref = aCachedRefs[i];
1053
1054 if( ref.GetSymbol() == aSymbol )
1055 {
1056 ref.Split(); // Figures out if we are annotated or not
1057 symbolRefs.AddItem( ref );
1058 }
1059 }
1060
1061 return symbolRefs;
1062}
1063
1064
1066{
1067 SCH_SHEET_LIST allSheets = m_parent->Schematic().Hierarchy();
1068 SCH_REFERENCE_LIST sheetRefs;
1069
1070 // We need to operate on all instances of the sheet
1071 for( const SCH_SHEET_INSTANCE& instance : aSheet.GetInstances() )
1072 {
1073 // For every sheet instance we need to get the current schematic sheet
1074 // instance that matches that particular sheet path from the root
1075 for( SCH_SHEET_PATH& basePath : allSheets )
1076 {
1077 if( basePath.Path() == instance.m_Path )
1078 {
1079 SCH_SHEET_PATH sheetPath = basePath;
1080 sheetPath.push_back( &aSheet );
1081
1082 // Create a list of all sheets in this path, starting with the path
1083 // of the sheet that we just deleted, then all of its subsheets
1084 SCH_SHEET_LIST subSheets;
1085 subSheets.push_back( sheetPath );
1086 allSheets.GetSheetsWithinPath( subSheets, sheetPath );
1087
1088 subSheets.GetSymbolsWithinPath( sheetRefs, sheetPath, SYMBOL_FILTER_NON_POWER, false );
1089 break;
1090 }
1091 }
1092 }
1093
1094 for( SCH_REFERENCE& ref : sheetRefs )
1095 ref.Split();
1096
1097 return sheetRefs;
1098}
1099
1100
1101void DIALOG_SYMBOL_FIELDS_TABLE::onAddVariant( wxCommandEvent& aEvent )
1102{
1103 if( !m_grid->CommitPendingChanges() )
1104 return;
1105
1106 if( !m_parent->ShowAddVariantDialog( this ) )
1107 return;
1108
1109 m_variantListBox->Set( m_parent->Schematic().GetVariantNamesForUI() );
1110
1111 wxString currentVariant = m_parent->Schematic().GetCurrentVariant();
1112
1113 if( !m_variantListBox->SetStringSelection( currentVariant ) )
1114 m_variantListBox->SetSelection( 0 );
1115
1116 onVariantSelectionChange( aEvent );
1117}
1118
1119
1121{
1122 if( !m_grid->CommitPendingChanges() )
1123 return;
1124
1125 int selection = m_variantListBox->GetSelection();
1126
1127 // An empty or default selection cannot be deleted.
1128 if( ( selection == wxNOT_FOUND ) || ( selection == 0 ) )
1129 {
1130 m_parent->GetInfoBar()->ShowMessageFor( _( "Cannot delete the default variant." ), 10000, wxICON_ERROR );
1131 return;
1132 }
1133
1134 wxString variantName = m_variantListBox->GetString( selection );
1135 m_dataModel->DeleteStoredVariant( variantName );
1136 m_variantListBox->Delete( selection );
1137
1138 VARIANT_PROXY_UNDO_ITEM* undoItem = new VARIANT_PROXY_UNDO_ITEM( &m_parent->Schematic() );
1139 SCH_COMMIT commit( m_parent );
1140 bool append = false;
1141
1142 m_parent->Schematic().DeleteVariant( variantName, &commit );
1143
1144 if( !commit.Empty() )
1145 {
1146 commit.Push();
1147 append = true;
1148 }
1149
1150 PICKED_ITEMS_LIST undoCmd;
1151 undoCmd.PushItem( ITEM_PICKER( m_parent->GetScreen(), undoItem, UNDO_REDO::VARIANTS ) );
1152 undoCmd.SetDescription( _( "Delete Variant" ) );
1153 m_parent->SaveCopyInUndoList( undoCmd, UNDO_REDO::VARIANTS, append );
1154
1155 m_parent->OnModify();
1156
1157 int newSelection = std::max( 0, selection - 1 );
1158 m_variantListBox->SetSelection( newSelection );
1159
1160 wxString selectedVariant = getSelectedVariant();
1161 m_parent->SetCurrentVariant( selectedVariant );
1162
1163 if( m_grid->CommitPendingChanges( true ) )
1164 {
1165 m_dataModel->SetCurrentVariant( selectedVariant );
1166 m_dataModel->UpdateReferences( m_dataModel->GetReferenceList() );
1167 m_dataModel->RebuildRows();
1168
1169 if( m_nbPages->GetSelection() == 1 )
1171 else
1172 m_grid->ForceRefresh();
1173 }
1174
1176 m_parent->SyncVariantUI();
1177}
1178
1179
1181{
1182 int selection = m_variantListBox->GetSelection();
1183
1184 // An empty or default selection cannot be renamed.
1185 if( ( selection == wxNOT_FOUND ) || ( selection == 0 ) )
1186 {
1187 m_parent->GetInfoBar()->ShowMessageFor( _( "Cannot rename the default variant." ), 10000, wxICON_ERROR );
1188 return;
1189 }
1190
1191 wxString oldVariantName = m_variantListBox->GetString( selection );
1192
1193 wxTextEntryDialog dlg( this, _( "Enter new variant name:" ), _( "Rename Design Variant" ), oldVariantName,
1194 wxOK | wxCANCEL | wxCENTER );
1195
1196 if( dlg.ShowModal() == wxID_CANCEL )
1197 return;
1198
1199 wxString newVariantName = dlg.GetValue().Trim().Trim( false );
1200
1201 // Same name (exact match) - nothing to do
1202 if( newVariantName == oldVariantName )
1203 return;
1204
1205 if( !m_parent->ValidateNewVariantName( newVariantName, oldVariantName ) )
1206 return;
1207
1208 if( !m_grid->CommitPendingChanges() )
1209 return;
1210
1211 bool wasCurrent = m_parent->Schematic().GetCurrentVariant() == oldVariantName;
1212
1213 m_dataModel->RenameStoredVariant( oldVariantName, newVariantName );
1214
1215 VARIANT_PROXY_UNDO_ITEM* undoItem = new VARIANT_PROXY_UNDO_ITEM( &m_parent->Schematic() );
1216 SCH_COMMIT commit( m_parent );
1217 PICKED_ITEMS_LIST* undoCmd = nullptr;
1218
1219 m_parent->Schematic().RenameVariant( oldVariantName, newVariantName, &commit );
1220
1221 if( !commit.Empty() )
1222 {
1223 commit.Push();
1224 undoCmd = m_parent->PopCommandFromUndoList();
1225 }
1226 else
1227 {
1228 undoCmd = new PICKED_ITEMS_LIST();
1229 }
1230
1231 undoCmd->PushItem( ITEM_PICKER( m_parent->GetScreen(), undoItem, UNDO_REDO::VARIANTS ) );
1232 undoCmd->SetDescription( _( "Rename Variant" ) );
1233 m_parent->PushCommandToUndoList( undoCmd );
1234
1235 m_parent->OnModify();
1236
1237 wxArrayString ctrlContents = m_variantListBox->GetStrings();
1238 ctrlContents.Remove( oldVariantName );
1239 ctrlContents.Add( newVariantName );
1240 ctrlContents.Sort( SortVariantNames ); // SortVariantNames ensures the default is always first
1241 m_variantListBox->Set( ctrlContents );
1242
1243 m_variantListBox->SetStringSelection( newVariantName );
1244
1246 m_parent->SyncVariantUI();
1247
1248 if( wasCurrent )
1249 m_parent->SetCurrentVariant( newVariantName );
1250}
1251
1252
1253void DIALOG_SYMBOL_FIELDS_TABLE::onCopyVariant( wxCommandEvent& aEvent )
1254{
1255 int selection = m_variantListBox->GetSelection();
1256
1257 // An empty or default selection cannot be copied.
1258 if( ( selection == wxNOT_FOUND ) || ( selection == 0 ) )
1259 {
1260 m_parent->GetInfoBar()->ShowMessageFor( _( "Cannot copy the default variant." ), 10000, wxICON_ERROR );
1261 return;
1262 }
1263
1264 wxString sourceVariantName = m_variantListBox->GetString( selection );
1265
1266 wxTextEntryDialog dlg( this, _( "Enter name for the copied variant:" ), _( "Copy Design Variant" ),
1267 sourceVariantName + wxS( "_copy" ), wxOK | wxCANCEL | wxCENTER );
1268
1269 if( dlg.ShowModal() == wxID_CANCEL )
1270 return;
1271
1272 wxString newVariantName = dlg.GetValue().Trim().Trim( false );
1273
1274 // Empty name is not allowed.
1275 if( newVariantName.IsEmpty() )
1276 {
1277 m_parent->GetInfoBar()->ShowMessageFor( _( "Variant name cannot be empty." ), 10000, wxICON_ERROR );
1278 return;
1279 }
1280
1281 // Duplicate name is not allowed.
1282 if( m_variantListBox->FindString( newVariantName ) != wxNOT_FOUND )
1283 {
1284 m_parent->GetInfoBar()->ShowMessageFor( wxString::Format( _( "Variant '%s' already exists." ),
1285 newVariantName ),
1286 10000, wxICON_ERROR );
1287 return;
1288 }
1289
1290 if( !m_grid->CommitPendingChanges() )
1291 return;
1292
1293 m_parent->Schematic().CopyVariant( sourceVariantName, newVariantName, nullptr /* no undo */ );
1294 m_parent->OnModify();
1295
1296 wxArrayString ctrlContents = m_variantListBox->GetStrings();
1297 ctrlContents.Add( newVariantName );
1298 ctrlContents.Sort( SortVariantNames ); // SortVariantNames ensures the default is always first
1299 m_variantListBox->Set( ctrlContents );
1300
1301 m_variantListBox->SetStringSelection( newVariantName );
1302
1303 onVariantSelectionChange( aEvent );
1304 m_parent->SyncVariantUI();
1305}
1306
1307
1309{
1310 int selection = m_variantListBox->GetSelection();
1311
1312 if( ( selection == wxNOT_FOUND ) || ( selection == 0 ) )
1313 {
1314 m_parent->GetInfoBar()->ShowMessageFor( _( "Cannot edit the default variant description." ), 10000,
1315 wxICON_ERROR );
1316 return;
1317 }
1318
1319 wxString variantName = m_variantListBox->GetString( selection );
1320 wxString currentDesc = m_parent->Schematic().GetVariantDescription( variantName );
1321
1322 wxDialog dlg( this, wxID_ANY, wxString::Format( _( "Edit Description for '%s'" ), variantName ), wxDefaultPosition,
1323 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
1324
1325 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
1326
1327 wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Description:" ) );
1328 mainSizer->Add( label, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 10 );
1329
1330 mainSizer->AddSpacer( 3 );
1331
1332 wxTextCtrl* descCtrl =
1333 new wxTextCtrl( &dlg, wxID_ANY, currentDesc, wxDefaultPosition, wxSize( 300, 60 ), wxTE_MULTILINE );
1334 mainSizer->Add( descCtrl, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 10 );
1335
1336 wxStdDialogButtonSizer* btnSizer = new wxStdDialogButtonSizer();
1337 btnSizer->AddButton( new wxButton( &dlg, wxID_OK ) );
1338 btnSizer->AddButton( new wxButton( &dlg, wxID_CANCEL ) );
1339 btnSizer->Realize();
1340 mainSizer->Add( btnSizer, 0, wxALL | wxALIGN_RIGHT, 5 );
1341
1342 dlg.SetSizer( mainSizer );
1343 dlg.Fit();
1344 dlg.Centre();
1345
1346 if( dlg.ShowModal() == wxID_CANCEL )
1347 return;
1348
1349 wxString newDesc = descCtrl->GetValue().Trim().Trim( false );
1350
1351 m_parent->Schematic().SetVariantDescription( variantName, newDesc );
1352 m_parent->OnModify();
1353}
1354
1355
1357{
1358 if( !m_grid->CommitPendingChanges() )
1359 return;
1360
1361 if( !m_job && m_parent )
1362 m_parent->SetCurrentVariant( getSelectedVariant() );
1363
1365}
1366
1367
1369{
1370 // Activating a variant only selects its staged values. Apply writes all edited variants.
1371 m_dataModel->SetCurrentVariant( getSelectedVariant() );
1372 m_dataModel->RebuildRows();
1373
1374 if( m_nbPages->GetSelection() == 1 )
1376 else
1377 m_grid->ForceRefresh();
1378
1381}
1382
1383
1385{
1386 const wxString shown = m_variantListBox->GetStringSelection();
1387
1388 m_variantListBox->Set( m_parent->Schematic().GetVariantNamesForUI() );
1389
1390 // A job keeps its own variant, otherwise follow the schematic, which an undo may be restoring
1391 selectVariant( m_job ? shown : m_parent->Schematic().GetCurrentVariant(), shown );
1392}
1393
1394
1396{
1397 if( !m_job )
1398 selectVariant( m_parent->Schematic().GetCurrentVariant(), m_variantListBox->GetStringSelection() );
1399}
1400
1401
1402void DIALOG_SYMBOL_FIELDS_TABLE::selectVariant( const wxString& aVariant, const wxString& aShown )
1403{
1404 // Variant names are case sensitive, but the list box's own lookup is not
1405 int index = m_variantListBox->FindString( aVariant, true );
1406 m_variantListBox->SetSelection( index == wxNOT_FOUND ? 0 : index );
1407
1408 if( m_variantListBox->GetStringSelection() == aShown )
1410 else
1412}
1413
1414
1416{
1417 int selection = m_variantListBox->GetSelection();
1418
1419 // Copy, rename, and delete are only enabled for non-default variant selections
1420 bool canModify = ( selection != wxNOT_FOUND ) && ( selection != 0 );
1421
1422 m_copyVariantButton->Enable( canModify );
1423 m_renameVariantButton->Enable( canModify );
1424 m_editVariantDescButton->Enable( canModify );
1425 m_deleteVariantButton->Enable( canModify );
1426}
1427
1428
1430{
1431 // A job keeps its own variant, otherwise follow the schematic.
1432 if( m_job )
1433 return getSelectedVariant();
1434
1435 return m_parent->Schematic().GetCurrentVariant();
1436}
1437
1438
1440{
1441 SCHEMATIC& schematic = m_parent->Schematic();
1442
1443 return schematic.ResolveTextVar( &schematic.CurrentSheet(), aToken, 0 );
1444}
int index
bool Empty() const
Definition commit.h:145
STD_BITMAP_BUTTON * m_renameVariantButton
STD_BITMAP_BUTTON * m_copyVariantButton
STD_BITMAP_BUTTON * m_deleteVariantButton
STD_BITMAP_BUTTON * m_editVariantDescButton
void saveJobSettings(JOB_EXPORT_BOM &aJob)
void SetUserBomFmtPresets(std::vector< BOM_FMT_PRESET > &aPresetList)
wxSize GetDefaultDialogSize() const
void OnColMove(wxGridEvent &aEvent)
void OnColSort(wxGridEvent &aEvent)
void OnGridMouseMove(wxMouseEvent &aEvent)
bool savePresets(bool aSaveCurrentSettings)
Store what changed since rememberLoadedPresets(); true if anything did.
wxString getSelectedVariant() const
void rememberLoadedPresets()
Remember the presets as loaded, which may differ from the stored ones after normalization.
void RestoreGridSelection(const std::set< KIID_PATH > &aItemKeys)
Restore a selection previously returned by SaveGridSelection().
std::map< FIELD_T, int > m_mandatoryFieldListIndexes
void onBomFmtPresetChanged(wxCommandEvent &aEvent)
void SetUserBomPresets(std::vector< BOM_PRESET > &aPresetList)
void ApplyBomFmtPreset(const wxString &aPresetName)
DIALOG_FIELDS_TABLE(wxWindow *aParent, FIELDS_TABLE_SETTINGS &aPanelSettings, FIELDS_TABLE_BOM_SETTINGS &aBomSettings, JOB_EXPORT_BOM *aJob)
FIELDS_TABLE_BOM_SETTINGS & m_cfgBomSettings
static void loadJobBomFmtPreset(const JOB_EXPORT_BOM &aJob, BOM_FMT_PRESET &aPreset)
FIELDS_TABLE_SETTINGS & m_cfgDialogSettings
static void loadJobBomPreset(const JOB_EXPORT_BOM &aJob, BOM_PRESET &aPreset)
void onBomPresetChanged(wxCommandEvent &aEvent)
std::set< KIID_PATH > SaveGridSelection()
Save the grid selection by stable item identity so it can survive a row rebuild.
void ApplyBomPreset(const wxString &aPresetName)
VIEW_CONTROLS_GRID_DATA_MODEL * m_viewControlsDataModel
void AddField(const wxString &aFieldName, const wxString &aLabelValue, bool aShow, bool aGroupBy, bool aAddedByUser=false)
void ExcludeFromControlUndoRedo(wxWindow *aWindow)
Opt a control out of the dialog's generic Ctrl+Z/Ctrl+Y undo/redo.
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:95
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
void OnSaveAndContinue(wxCommandEvent &aEvent) override
void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem) override
void onAddVariant(wxCommandEvent &aEvent) override
void selectVariant(const wxString &aVariant, const wxString &aShown)
Select aVariant, or the default when it is gone, rebuilding rows unless aShown stays.
SCH_REFERENCE_LIST getSheetSymbolReferences(SCH_SHEET &aSheet)
wxGridCellEditor * createDatasheetEditor() override
void OnOk(wxCommandEvent &aEvent) override
void OnSchSelectionChanged(SCHEMATIC &aSch) override
void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem) override
void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem) override
void showSelectedVariant()
Show the list box's selected variant in the grid without touching the schematic.
void FollowCurrentVariant()
Show the schematic's current variant, which the toolbar or an undo may have just changed.
void OnTableSelectionChanged(const std::set< int > &aRows) override
SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL * m_dataModel
void onVariantSelectionChange(wxCommandEvent &aEvent) override
void OnClose(wxCloseEvent &aEvent) override
void OnSchSheetChanged(SCHEMATIC &aSch) override
void onCopyVariant(wxCommandEvent &aEvent) override
void setScope(SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE aScope)
void onDeleteVariant(wxCommandEvent &aEvent) override
DIALOG_SYMBOL_FIELDS_TABLE(SCH_EDIT_FRAME *aParent, JOB_EXPORT_BOM *aJob=nullptr)
void OnCancel(wxCommandEvent &aEvent) override
void OnMenu(wxCommandEvent &aEvent) override
SCH_REFERENCE_LIST getSymbolReferences(SCH_SYMBOL *aSymbol, SCH_REFERENCE_LIST &aCachedRefs)
bool resolveTextVar(wxString *aToken) const override
void onRenameVariant(wxCommandEvent &aEvent) override
void LoadFieldNames()
Construct the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all field names in ...
void OnScope(wxCommandEvent &aEvent) override
void ReloadVariants()
Take the schematic's variant list again and show its current variant.
wxGridCellEditor * createFootprintEditor() override
void onEditVariantDescription(wxCommandEvent &aEvent) override
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM * GetParent() const
Definition eda_item.h:112
static const wxString ITEM_NUMBER_VARIABLE
FIELDS_TABLE_GRID_TRICKS(DIALOG_FIELDS_TABLE *aDialog, WX_GRID *aGrid, FIELDS_TABLE_DATA_MODEL_BASE *aDataModel)
static constexpr int FIRST_CLIENT_ID
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
WX_GRID * m_grid
I don't own the grid, but he owns me.
virtual bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Define a library symbol object.
Definition lib_symbol.h:114
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
static SEARCH_STACK * SchSearchS(PROJECT *aProject)
Accessor for Eeschema search stack.
Holds all the data relating to one schematic.
Definition schematic.h:155
wxString GetCurrentVariant() const
Return the current variant being edited.
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
static TOOL_ACTION clearVariantSymbol
static TOOL_ACTION setVariantSymbol
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.
Handle actions specific to the schematic editor.
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void Split()
Attempt to split the reference designator into a name (U) and number (1).
SCH_SYMBOL * GetSymbol() const
void SyncSelection(const std::optional< SCH_SHEET_PATH > &targetSheetPath, SCH_ITEM *focusItem, const std::vector< SCH_ITEM * > &items)
Set selection to items passed by parameter.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
SCH_SELECTION & GetSelection()
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetSymbolsWithinPath(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSheetPath, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets that are contained wi...
void GetSheetsWithinPath(std::vector< SCH_SHEET_PATH > &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition sch_sheet.h:563
Schematic symbol object.
Definition sch_symbol.h:76
std::optional< SCH_SYMBOL_VARIANT > GetVariant(const SCH_SHEET_PATH &aInstance, const wxString &aVariantName) const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
LIB_SYMBOL * GetVariantLibSymbol(const wxString &aVariantName, const SCH_SHEET_PATH &aPath) const
Resolve the alternate library symbol for a given variant.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:185
bool IsPower() const override
void showFieldsTablePopupMenu(wxMenu &aMenu, wxGridEvent &aEvent) override
SYMBOL_FIELDS_EDITOR_GRID_TRICKS(DIALOG_SYMBOL_FIELDS_TABLE *aParent, WX_GRID *aGrid, VIEW_CONTROLS_GRID_DATA_MODEL *aViewFieldsData, SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL *aDataModel, EMBEDDED_FILES *aFiles)
SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL * m_dataModel
void doFieldsTablePopupSelection(wxCommandEvent &aEvent) override
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false) override
VIEW_CONTROLS_GRID_DATA_MODEL * m_viewControlsDataModel
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
wxString GetGeneratedFieldDisplayName(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition common.cpp:481
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition confirm.cpp:146
This file is part of the common library.
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
@ MYID_INCLUDE_EXCLUDED_FROM_BOM
wxDEFINE_EVENT(EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxCommandEvent)
static wxString getFootprintChooserSymbolNetlist(const std::vector< SCH_REFERENCE > &aReferences, const wxString &aVariantName)
@ MYID_HIGHLIGHT_ON_CROSS_PROBE
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
Definition eda_doc.cpp:59
This file is part of the common library.
@ RECURSE
Definition eda_item.h:51
wxString BuildFootprintChooserSymbolNetlist(const LIB_SYMBOL *aSymbol)
bool SelectFootprintFromChooser(DIALOG_SHIM *aDialog, wxString &aFootprint, const wxString &aSymbolNetlist)
@ GRIDTRICKS_FIRST_SHOWHIDE
Definition grid_tricks.h:49
@ HIGHLIGHT_SYMBOL
Class to handle a set of SCH_ITEMs.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
int SortVariantNames(const wxString &aLhs, const wxString &aRhs)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A simple container for sheet instance information.
Hold a name of a symbol's field, field value, and default visibility.
std::vector< FIELD_CASE_CONFLICT > DetectFieldCaseConflicts(const SCH_REFERENCE_LIST &aSymbols)
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
@ TRANSLATED
std::string path
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_SHEET_T
Definition typeinfo.h:171