KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fields_data_model.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) 2023 <author>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * 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#include <nlohmann/json.hpp>
21#include <wx/string.h>
22#include <wx/debug.h>
23#include <wx/grid.h>
24#include <wx/settings.h>
25#include <common.h>
26#include <widgets/wx_grid.h>
27#include <sch_reference_list.h>
28#include <sch_commit.h>
29#include <sch_screen.h>
30#include "string_utils.h"
31
32#include "fields_data_model.h"
33
34
40class GRID_CELL_RESOLVED_TEXT_RENDERER : public wxGridCellStringRenderer
41{
42public:
44 wxGridCellStringRenderer()
45 {
46 }
47
48 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow, int aCol,
49 bool isSelected ) override
50 {
51 wxString value = aGrid.GetCellValue( aRow, aCol );
52
53 if( auto* model = dynamic_cast<FIELDS_EDITOR_GRID_DATA_MODEL*>( aGrid.GetTable() ) )
54 value = model->GetResolvedValue( aRow, aCol );
55
56 wxRect rect = aRect;
57 rect.Inflate( -1 );
58
59 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
60 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
61 aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
62 }
63
64 wxSize GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, int aRow, int aCol ) override
65 {
66 wxString value = aGrid.GetCellValue( aRow, aCol );
67
68 if( auto* model = dynamic_cast<FIELDS_EDITOR_GRID_DATA_MODEL*>( aGrid.GetTable() ) )
69 value = model->GetResolvedValue( aRow, aCol );
70
71 return wxGridCellStringRenderer::DoGetBestSize( aAttr, aDC, value );
72 }
73
74 wxGridCellRenderer* Clone() const override { return new GRID_CELL_RESOLVED_TEXT_RENDERER(); }
75};
76
77
86static KIID_PATH makeDataStoreKey( const SCH_SHEET_PATH& aSheetPath, const SCH_SYMBOL& aSymbol )
87{
88 KIID_PATH path = aSheetPath.Path();
89 path.push_back( aSymbol.m_Uuid );
90 return path;
91}
92
93
95{
96 switch( aCol )
97 {
98 case DISPLAY_NAME_COLUMN: return _( "Field" );
99 case LABEL_COLUMN: return m_forBOM ? _( "BOM Name" ) : _( "Label" );
100 case SHOW_FIELD_COLUMN: return _( "Include" );
101 case GROUP_BY_COLUMN: return _( "Group By" );
102 default: return wxT( "unknown column" );
103 };
104}
105
106
107wxString VIEW_CONTROLS_GRID_DATA_MODEL::GetValue( int aRow, int aCol )
108{
109 wxCHECK( aRow < GetNumberRows(), wxT( "bad row!" ) );
110
111 BOM_FIELD& rowData = m_fields[aRow];
112
113 switch( aCol )
114 {
116 for( FIELD_T fieldId : MANDATORY_FIELDS )
117 {
118 if( GetDefaultFieldName( fieldId, !DO_TRANSLATE ) == rowData.name )
119 return GetDefaultFieldName( fieldId, DO_TRANSLATE );
120 }
121
122 return rowData.name;
123
124 case LABEL_COLUMN:
125 return rowData.label;
126
127 default:
128 // we can't assert here because wxWidgets sometimes calls this without checking
129 // the column type when trying to see if there's an overflow
130 return wxT( "bad wxWidgets!" );
131 }
132}
133
134
136{
137 wxCHECK( aRow < GetNumberRows(), false );
138
139 BOM_FIELD& rowData = m_fields[aRow];
140
141 switch( aCol )
142 {
143 case SHOW_FIELD_COLUMN: return rowData.show;
144 case GROUP_BY_COLUMN: return rowData.groupBy;
145
146 default:
147 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
148 return false;
149 }
150}
151
152
153void VIEW_CONTROLS_GRID_DATA_MODEL::SetValue( int aRow, int aCol, const wxString &aValue )
154{
155 wxCHECK( aRow < GetNumberRows(), /*void*/ );
156
157 BOM_FIELD& rowData = m_fields[aRow];
158
159 switch( aCol )
160 {
162 // Not editable
163 break;
164
165 case LABEL_COLUMN:
166 rowData.label = aValue;
167 break;
168
169 default:
170 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
171 }
172
173 GetView()->Refresh();
174}
175
176
177void VIEW_CONTROLS_GRID_DATA_MODEL::SetValueAsBool( int aRow, int aCol, bool aValue )
178{
179 wxCHECK( aRow < GetNumberRows(), /*void*/ );
180
181 BOM_FIELD& rowData = m_fields[aRow];
182
183 switch( aCol )
184 {
185 case SHOW_FIELD_COLUMN: rowData.show = aValue; break;
186 case GROUP_BY_COLUMN: rowData.groupBy = aValue; break;
187
188 default:
189 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
190 }
191}
192
193
194void VIEW_CONTROLS_GRID_DATA_MODEL::AppendRow( const wxString& aFieldName, const wxString& aBOMName,
195 bool aShow, bool aGroupBy )
196{
197 m_fields.emplace_back( BOM_FIELD{ aFieldName, aBOMName, aShow, aGroupBy } );
198
199 if( wxGrid* grid = GetView() )
200 {
201 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
202 grid->ProcessTableMessage( msg );
203 }
204}
205
206
208{
209 wxCHECK( aRow >= 0 && aRow < GetNumberRows(), /* void */ );
210
211 m_fields.erase( m_fields.begin() + aRow );
212
213 if( wxGrid* grid = GetView() )
214 {
215 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
216 grid->ProcessTableMessage( msg );
217 }
218}
219
220
222{
223 wxCHECK( aRow >= 0 && aRow < GetNumberRows(), wxEmptyString );
224
225 BOM_FIELD& rowData = m_fields[aRow];
226
227 return rowData.name;
228}
229
230
231void VIEW_CONTROLS_GRID_DATA_MODEL::SetCanonicalFieldName( int aRow, const wxString& aName )
232{
233 wxCHECK( aRow >= 0 && aRow < GetNumberRows(), /* void */ );
234
235 BOM_FIELD& rowData = m_fields[aRow];
236
237 rowData.name = aName;
238}
239
240
241const wxString FIELDS_EDITOR_GRID_DATA_MODEL::QUANTITY_VARIABLE = wxS( "${QUANTITY}" );
242const wxString FIELDS_EDITOR_GRID_DATA_MODEL::ITEM_NUMBER_VARIABLE = wxS( "${ITEM_NUMBER}" );
243
244
245void FIELDS_EDITOR_GRID_DATA_MODEL::AddColumn( const wxString& aFieldName, const wxString& aLabel,
246 bool aAddedByUser, const wxString& aVariantName )
247{
248 // Don't add a field twice
249 if( GetFieldNameCol( aFieldName ) != -1 )
250 return;
251
252 m_cols.push_back( { aFieldName, aLabel, aAddedByUser, false, false } );
253
254 for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
255 updateDataStoreSymbolField( m_symbolsList[i], aFieldName, aVariantName );
256}
257
258
260 const wxString& aFieldName,
261 const wxString& aVariantName )
262{
263 const SCH_SYMBOL* symbol = aSymbolRef.GetSymbol();
264
265 if( !symbol )
266 return;
267
268 KIID_PATH key = makeDataStoreKey( aSymbolRef.GetSheetPath(), *symbol );
269
270 if( isAttribute( aFieldName ) )
271 {
272 m_dataStore[key][aFieldName] = getAttributeValue( aSymbolRef, aFieldName, aVariantName );
273 }
274 else if( const SCH_FIELD* field = symbol->FindFieldCaseInsensitive( aFieldName ) )
275 {
276 if( field->IsPrivate() )
277 {
278 m_dataStore[key][aFieldName] = wxEmptyString;
279 return;
280 }
281
282 wxString value = symbol->Schematic()->ConvertKIIDsToRefs( field->GetText( &aSymbolRef.GetSheetPath(),
283 aVariantName ) );
284
285 m_dataStore[key][aFieldName] = value;
286 }
287 else if( IsGeneratedField( aFieldName ) )
288 {
289 // Handle generated fields with variables as names (e.g. ${QUANTITY}) that are not present in
290 // the symbol by giving them the correct value
291 m_dataStore[key][aFieldName] = aFieldName;
292 }
293 else
294 {
295 m_dataStore[key][aFieldName] = wxEmptyString;
296 }
297}
298
299
301{
302 for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
303 {
304 if( SCH_SYMBOL* symbol = m_symbolsList[i].GetSymbol() )
305 {
306 KIID_PATH key = makeDataStoreKey( m_symbolsList[i].GetSheetPath(), *symbol );
307 m_dataStore[key].erase( m_cols[aCol].m_fieldName );
308 }
309 }
310
311 m_cols.erase( m_cols.begin() + aCol );
312
313 if( wxGrid* grid = GetView() )
314 {
315 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_COLS_DELETED, aCol, 1 );
316 grid->ProcessTableMessage( msg );
317 }
318}
319
320
321void FIELDS_EDITOR_GRID_DATA_MODEL::RenameColumn( int aCol, const wxString& newName )
322{
323 for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
324 {
325 SCH_SYMBOL* symbol = m_symbolsList[i].GetSymbol();
326 KIID_PATH key = makeDataStoreKey( m_symbolsList[i].GetSheetPath(), *symbol );
327
328 // Careful; field may have already been renamed from another sheet instance
329 if( auto node = m_dataStore[key].extract( m_cols[aCol].m_fieldName ) )
330 {
331 node.key() = newName;
332 m_dataStore[key].insert( std::move( node ) );
333 }
334 }
335
336 m_cols[aCol].m_fieldName = newName;
337 m_cols[aCol].m_label = newName;
338}
339
340
341int FIELDS_EDITOR_GRID_DATA_MODEL::GetFieldNameCol( const wxString& aFieldName ) const
342{
343 for( size_t i = 0; i < m_cols.size(); i++ )
344 {
345 if( m_cols[i].m_fieldName.CmpNoCase( aFieldName ) == 0 )
346 return static_cast<int>( i );
347 }
348
349 return -1;
350}
351
352
354{
355 std::vector<BOM_FIELD> fields;
356
357 for( const DATA_MODEL_COL& col : m_cols )
358 fields.push_back( { col.m_fieldName, col.m_label, col.m_show, col.m_group } );
359
360 return fields;
361}
362
363
364void FIELDS_EDITOR_GRID_DATA_MODEL::SetFieldsOrder( const std::vector<wxString>& aNewOrder )
365{
366 size_t foundCount = 0;
367
368 for( const wxString& newField : aNewOrder )
369 {
370 if( foundCount >= m_cols.size() )
371 break;
372
373 for( DATA_MODEL_COL& col : m_cols )
374 {
375 if( col.m_fieldName == newField )
376 {
377 std::swap( m_cols[foundCount], col );
378 foundCount++;
379 break;
380 }
381 }
382 }
383}
384
385
387{
388 // Check if aCol is the first visible column
389 for( int col = 0; col < aCol; ++col )
390 {
391 if( m_cols[col].m_show )
392 return false;
393 }
394
395 return true;
396}
397
398
399wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue( int aRow, int aCol )
400{
401 GetView()->SetReadOnly( aRow, aCol,
402 IsExpanderColumn( aCol ) || rowAttributeInheritedFromSheet( m_rows[aRow], aCol ) );
403 return GetValue( m_rows[aRow], aCol );
404}
405
406
408{
409 return GetValue( m_rows[aRow], aCol, wxT( ", " ), wxT( "-" ), true, false );
410}
411
412
413wxGridCellAttr* FIELDS_EDITOR_GRID_DATA_MODEL::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind )
414{
415 wxGridCellAttr* attr = nullptr;
416 bool needsUrlEditor = false;
417 bool needsVariantHighlight = false;
418 bool needsTextVarRenderer = false;
419 wxColour highlightColor;
420
421 // Check if we need URL editor
423 || IsURL( GetValue( m_rows[aRow], aCol ) ) )
424 {
425 if( m_urlEditor )
426 needsUrlEditor = true;
427 }
428
429 // Check if the raw value contains a text variable that should be resolved for display
430 if( aRow >= 0 && aRow < (int) m_rows.size() && aCol >= 0 && aCol < (int) m_cols.size() && !ColIsReference( aCol )
431 && !ColIsQuantity( aCol ) && !ColIsItemNumber( aCol ) )
432 {
433 wxString rawValue = GetValue( m_rows[aRow], aCol );
434
435 if( rawValue.Contains( wxT( "${" ) ) )
436 needsTextVarRenderer = true;
437 }
438
439 // Check if we need variant highlighting
440 if( !m_currentVariant.IsEmpty() && aRow >= 0 && aRow < (int) m_rows.size()
441 && aCol >= 0 && aCol < (int) m_cols.size() )
442 {
443 const wxString& fieldName = m_cols[aCol].m_fieldName;
444
445 // Skip Reference and generated fields (like ${QUANTITY}) for highlighting
446 if( !ColIsReference( aCol ) && !ColIsQuantity( aCol ) && !ColIsItemNumber( aCol ) )
447 {
448 const DATA_MODEL_ROW& row = m_rows[aRow];
449
450 // Check if any symbol in this row has a variant-specific value
451 for( const SCH_REFERENCE& ref : row.m_Refs )
452 {
453 wxString defaultValue = getDefaultFieldValue( ref, fieldName );
454
455 KIID_PATH symbolKey = KIID_PATH();
456
457 if( const SCH_SYMBOL* symbol = ref.GetSymbol() )
458 {
459 symbolKey = ref.GetSheetPath().Path();
460 symbolKey.push_back( symbol->m_Uuid );
461 }
462
463 // Get the current value from the data store
464 wxString currentValue;
465
466 if( m_dataStore.contains( symbolKey ) && m_dataStore[symbolKey].contains( fieldName ) )
467 currentValue = m_dataStore[symbolKey][fieldName];
468
469 if( currentValue != defaultValue )
470 {
471 needsVariantHighlight = true;
472
473 // Use a subtle highlight color that works in both light and dark themes
474 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
475 bool isDark = ( bg.Red() + bg.Green() + bg.Blue() ) < 384;
476
477 if( isDark )
478 highlightColor = wxColour( 80, 80, 40 ); // Dark gold/brown
479 else
480 highlightColor = wxColour( 255, 255, 200 ); // Light yellow
481
482 break;
483 }
484 }
485 }
486 }
487
488 // If we don't need any custom attributes, use the base class behavior
489 if( !needsUrlEditor && !needsVariantHighlight && !needsTextVarRenderer )
490 return WX_GRID_TABLE_BASE::GetAttr( aRow, aCol, aKind );
491
492 // URL cells: use m_urlEditor as base, potentially with variant highlight overlay
493 if( needsUrlEditor )
494 {
495 if( needsVariantHighlight )
496 {
497 // Clone the URL editor attribute and add highlight color
498 attr = m_urlEditor->Clone();
499 attr->SetBackgroundColour( highlightColor );
500 }
501 else
502 {
503 // Just use the URL editor attribute directly
504 m_urlEditor->IncRef();
505 attr = m_urlEditor;
506 }
507
508 return enhanceAttr( attr, aRow, aCol, aKind );
509 }
510
511 // Non-URL cells: start with column attributes if they exist.
512 // This preserves checkbox renderers and other column-specific settings.
513 if( m_colAttrs.find( aCol ) != m_colAttrs.end() && m_colAttrs[aCol] )
514 {
515 attr = m_colAttrs[aCol]->Clone();
516 }
517 else
518 {
519 attr = new wxGridCellAttr();
520 }
521
522 if( needsVariantHighlight )
523 attr->SetBackgroundColour( highlightColor );
524
525 if( needsTextVarRenderer )
526 {
527 if( !m_textVarRenderer )
529
530 m_textVarRenderer->IncRef();
531 attr->SetRenderer( m_textVarRenderer );
532
533 // Tint text-var cells if not already highlighted by variant
534 if( !needsVariantHighlight )
535 {
536 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
537 bool isDark = ( bg.Red() + bg.Green() + bg.Blue() ) < 384;
538
539 attr->SetBackgroundColour( isDark ? wxColour( 80, 70, 30 ) // Dark amber
540 : wxColour( 255, 252, 200 ) ); // Light yellow
541 }
542 }
543
544 return enhanceAttr( attr, aRow, aCol, aKind );
545}
546
547
549 const wxString& refDelimiter,
550 const wxString& refRangeDelimiter,
551 bool resolveVars,
552 bool listMixedValues )
553{
554 std::vector<SCH_REFERENCE> references;
555 std::set<wxString> mixedValues;
556 wxString fieldValue;
557
558 for( const SCH_REFERENCE& ref : group.m_Refs )
559 {
560 if( ColIsReference( aCol ) || ColIsQuantity( aCol ) || ColIsItemNumber( aCol ) )
561 {
562 references.push_back( ref );
563 }
564 else // Other columns are either a single value or ROW_MULTI_ITEMS
565 {
566 KIID_PATH symbolKey = makeDataStoreKey( ref.GetSheetPath(), *ref.GetSymbol() );
567
568 if( !m_dataStore.contains( symbolKey ) || !m_dataStore[symbolKey].contains( m_cols[aCol].m_fieldName ) )
569 return INDETERMINATE_STATE;
570
571 wxString refFieldValue = m_dataStore[symbolKey][m_cols[aCol].m_fieldName];
572
573 // Show the effective state when a sheet forces it on, but do not change
574 // the stored value so the symbol is never stamped on apply.
575 if( ColIsAttribute( aCol ) && attributeInheritedFromSheet( ref, m_cols[aCol].m_fieldName ) )
576 refFieldValue = wxS( "1" );
577
578 if( resolveVars )
579 {
580 if( IsGeneratedField( m_cols[aCol].m_fieldName ) )
581 {
582 // Generated fields (e.g. ${QUANTITY}) can't have un-applied values as they're
583 // read-only. Resolve them against the field.
584 refFieldValue = getFieldShownText( ref, m_cols[aCol].m_fieldName );
585 }
586 else if( refFieldValue.Contains( wxT( "${" ) ) )
587 {
588 // Resolve variables in the un-applied value using the parent symbol and instance
589 // data.
590 std::function<bool( wxString* )> symbolResolver =
591 [&]( wxString* token ) -> bool
592 {
593 return ref.GetSymbol()->ResolveTextVar( &ref.GetSheetPath(), token );
594 };
595
596 refFieldValue = ExpandTextVars( refFieldValue, & symbolResolver );
597 }
598 }
599
600 if( listMixedValues )
601 mixedValues.insert( refFieldValue );
602 else if( &ref == &group.m_Refs.front() )
603 fieldValue = refFieldValue;
604 else if( fieldValue != refFieldValue )
605 return INDETERMINATE_STATE;
606 }
607 }
608
609 if( listMixedValues )
610 {
611 fieldValue = wxEmptyString;
612
613 for( const wxString& value : mixedValues )
614 {
615 if( value.IsEmpty() )
616 continue;
617 else if( fieldValue.IsEmpty() )
618 fieldValue = value;
619 else
620 fieldValue += "," + value;
621 }
622 }
623
624 if( ColIsReference( aCol ) || ColIsQuantity( aCol ) || ColIsItemNumber( aCol ) )
625 {
626 // Remove duplicates (other units of multi-unit parts)
627 std::sort( references.begin(), references.end(),
628 []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
629 {
630 wxString l_ref( l.GetRef() << l.GetRefNumber() );
631 wxString r_ref( r.GetRef() << r.GetRefNumber() );
632 return StrNumCmp( l_ref, r_ref, true ) < 0;
633 } );
634
635 auto logicalEnd = std::unique( references.begin(), references.end(),
636 []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
637 {
638 // If unannotated then we can't tell what units belong together
639 // so we have to leave them all
640 if( l.GetRefNumber() == wxT( "?" ) )
641 return false;
642
643 wxString l_ref( l.GetRef() << l.GetRefNumber() );
644 wxString r_ref( r.GetRef() << r.GetRefNumber() );
645 return l_ref == r_ref;
646 } );
647
648 references.erase( logicalEnd, references.end() );
649 }
650
651 if( ColIsReference( aCol ) )
652 fieldValue = SCH_REFERENCE_LIST::Shorthand( references, refDelimiter, refRangeDelimiter );
653 else if( ColIsQuantity( aCol ) )
654 fieldValue = wxString::Format( wxT( "%d" ), (int) references.size() );
655 else if( ColIsItemNumber( aCol ) && group.m_Flag != CHILD_ITEM )
656 fieldValue = wxString::Format( wxT( "%d" ), group.m_ItemNumber );
657
658 return fieldValue;
659}
660
661
662void FIELDS_EDITOR_GRID_DATA_MODEL::SetValue( int aRow, int aCol, const wxString& aValue )
663{
664 wxCHECK_RET( aCol >= 0 && aCol < static_cast<int>( m_cols.size() ), wxS( "Invalid column number" ) );
665
666 // Can't modify references or generated fields (e.g. ${QUANTITY})
667 if( ColIsReference( aCol )
668 || ( IsGeneratedField( m_cols[aCol].m_fieldName ) && !ColIsAttribute( aCol ) ) )
669 {
670 return;
671 }
672
673 if( aValue == INDETERMINATE_STATE )
674 return;
675
676 DATA_MODEL_ROW& rowGroup = m_rows[aRow];
677
678 const SCH_SYMBOL* sharedSymbol = nullptr;
679 bool isSharedInstance = false;
680
681 for( const SCH_REFERENCE& ref : rowGroup.m_Refs )
682 {
683 const SCH_SCREEN* screen = nullptr;
684
685 // Check to see if the symbol associated with this row has more than one instance.
686 if( const SCH_SYMBOL* symbol = ref.GetSymbol() )
687 {
688 screen = static_cast<const SCH_SCREEN*>( symbol->GetParent() );
689
690 isSharedInstance = ( screen && ( screen->GetRefCount() > 1 ) );
691 sharedSymbol = symbol;
692 }
693
694 KIID_PATH key = makeDataStoreKey( ref.GetSheetPath(), *ref.GetSymbol() );
695 m_dataStore[key][m_cols[aCol].m_fieldName] = aValue;
696 }
697
698 // Update all of the other instances for the shared symbol as required.
699 if( isSharedInstance
700 && ( ( rowGroup.m_Flag == GROUP_SINGLETON ) || ( rowGroup.m_Flag == CHILD_ITEM ) ) )
701 {
702 for( DATA_MODEL_ROW& row : m_rows )
703 {
704 if( row.m_ItemNumber == aRow + 1 )
705 continue;
706
707 for( const SCH_REFERENCE& ref : row.m_Refs )
708 {
709 if( ref.GetSymbol() != sharedSymbol )
710 continue;
711
712 KIID_PATH key = makeDataStoreKey( ref.GetSheetPath(), *ref.GetSymbol() );
713 m_dataStore[key][m_cols[aCol].m_fieldName] = aValue;
714 }
715 }
716 }
717
718 m_edited = true;
719}
720
721
723{
724 wxCHECK( aCol >= 0 && aCol < static_cast<int>( m_cols.size() ), false );
725 return m_cols[aCol].m_fieldName == GetCanonicalFieldName( FIELD_T::REFERENCE );
726}
727
728
730{
731 wxCHECK( aCol >= 0 && aCol < static_cast<int>( m_cols.size() ), false );
732 return m_cols[aCol].m_fieldName == GetCanonicalFieldName( FIELD_T::VALUE );
733}
734
735
737{
738 wxCHECK( aCol >= 0 && aCol < static_cast<int>( m_cols.size() ), false );
739 return m_cols[aCol].m_fieldName == QUANTITY_VARIABLE;
740}
741
742
744{
745 wxCHECK( aCol >= 0 && aCol < static_cast<int>( m_cols.size() ), false );
746 return m_cols[aCol].m_fieldName == ITEM_NUMBER_VARIABLE;
747}
748
749
751{
752 wxCHECK( aCol >= 0 && aCol < static_cast<int>( m_cols.size() ), false );
753 return isAttribute( m_cols[aCol].m_fieldName );
754}
755
756
758 const DATA_MODEL_ROW& rhGroup,
759 FIELDS_EDITOR_GRID_DATA_MODEL* dataModel, int sortCol,
760 bool ascending )
761{
762 // Empty rows always go to the bottom, whether ascending or descending
763 if( lhGroup.m_Refs.size() == 0 )
764 return true;
765 else if( rhGroup.m_Refs.size() == 0 )
766 return false;
767
768 // N.B. To meet the iterator sort conditions, we cannot simply invert the truth
769 // to get the opposite sort. i.e. ~(a<b) != (a>b)
770 auto local_cmp =
771 [ ascending ]( const auto a, const auto b )
772 {
773 if( ascending )
774 return a < b;
775 else
776 return a > b;
777 };
778
779 // Primary sort key is sortCol; secondary is always REFERENCE (column 0)
780 if( sortCol < 0 || sortCol >= dataModel->GetNumberCols() )
781 sortCol = 0;
782
783 wxString lhs = dataModel->GetValue( lhGroup, sortCol, wxT( ", " ), wxT( "-" ), true ).Trim( true ).Trim( false );
784 wxString rhs = dataModel->GetValue( rhGroup, sortCol, wxT( ", " ), wxT( "-" ), true ).Trim( true ).Trim( false );
785
786 if( lhs == rhs || dataModel->ColIsReference( sortCol ) )
787 {
788 wxString lhRef = lhGroup.m_Refs[0].GetRef() + lhGroup.m_Refs[0].GetRefNumber();
789 wxString rhRef = rhGroup.m_Refs[0].GetRef() + rhGroup.m_Refs[0].GetRefNumber();
790 return local_cmp( StrNumCmp( lhRef, rhRef, true ), 0 );
791 }
792 else
793 {
794 return local_cmp( ValueStringCompare( lhs, rhs ), 0 );
795 }
796}
797
798
800{
802
803 // We're going to sort the rows based on their first reference, so the first reference
804 // had better be the lowest one.
805 for( DATA_MODEL_ROW& row : m_rows )
806 {
807 std::sort( row.m_Refs.begin(), row.m_Refs.end(),
808 []( const SCH_REFERENCE& lhs, const SCH_REFERENCE& rhs )
809 {
810 wxString lhs_ref( lhs.GetRef() << lhs.GetRefNumber() );
811 wxString rhs_ref( rhs.GetRef() << rhs.GetRefNumber() );
812 return StrNumCmp( lhs_ref, rhs_ref, true ) < 0;
813 } );
814 }
815
816 std::sort( m_rows.begin(), m_rows.end(),
817 [this]( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
818 {
819 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
820 } );
821
822 // Time to renumber the item numbers
823 int itemNumber = 1;
824
825 for( DATA_MODEL_ROW& row : m_rows )
826 {
827 row.m_ItemNumber = itemNumber++;
828 }
829
831}
832
833
835{
836 // If items are unannotated then we can't tell if they're units of the same symbol or not
837 if( lhRef.GetRefNumber() == wxT( "?" ) )
838 return false;
839
840 return ( lhRef.GetRef() == rhRef.GetRef() && lhRef.GetRefNumber() == rhRef.GetRefNumber() );
841}
842
843
845{
847 bool matchFound = false;
848
849 if( refCol == -1 )
850 return false;
851
852 // First check the reference column. This can be done directly out of the
853 // SCH_REFERENCEs as the references can't be edited in the grid.
854 if( m_cols[refCol].m_group )
855 {
856 // if we're grouping by reference, then only the prefix must match
857 if( lhRef.GetRef() != rhRef.GetRef() )
858 return false;
859
860 matchFound = true;
861 }
862
863 KIID_PATH lhRefKey = makeDataStoreKey( lhRef.GetSheetPath(), *lhRef.GetSymbol() );
864 KIID_PATH rhRefKey = makeDataStoreKey( rhRef.GetSheetPath(), *rhRef.GetSymbol() );
865
866 // Now check all the other columns.
867 for( size_t i = 0; i < m_cols.size(); ++i )
868 {
869 //Handled already
870 if( static_cast<int>( i ) == refCol )
871 continue;
872
873 if( !m_cols[i].m_group )
874 continue;
875
876 // If the field is generated (e.g. ${QUANTITY}), we need to resolve it through the symbol
877 // to get the actual current value; otherwise we need to pull it out of the store so the
878 // refresh can regroup based on values that haven't been applied to the schematic yet.
879 wxString lh, rh;
880
881 if( IsGeneratedField( m_cols[i].m_fieldName )
882 || IsGeneratedField( m_dataStore[lhRefKey][m_cols[i].m_fieldName] ) )
883 {
884 lh = getFieldShownText( lhRef, m_cols[i].m_fieldName );
885 }
886 else
887 {
888 lh = m_dataStore[lhRefKey][m_cols[i].m_fieldName];
889 }
890
891 if( IsGeneratedField( m_cols[i].m_fieldName )
892 || IsGeneratedField( m_dataStore[rhRefKey][m_cols[i].m_fieldName] ) )
893 {
894 rh = getFieldShownText( rhRef, m_cols[i].m_fieldName );
895 }
896 else
897 {
898 rh = m_dataStore[rhRefKey][m_cols[i].m_fieldName];
899 }
900
901 if( lh != rh )
902 return false;
903
904 matchFound = true;
905 }
906
907 return matchFound;
908}
909
910
912 const wxString& aFieldName )
913{
914 SCH_FIELD* field = aRef.GetSymbol()->GetField( aFieldName );
915
916 if( field )
917 {
918 if( field->IsPrivate() )
919 return wxEmptyString;
920 else
921 return field->GetShownText( &aRef.GetSheetPath(), false );
922 }
923
924 // Handle generated fields with variables as names (e.g. ${QUANTITY}) that are not present in
925 // the symbol by giving them the correct value by resolving against the symbol
926 if( IsGeneratedField( aFieldName ) )
927 {
928 int depth = 0;
929 const SCH_SHEET_PATH& path = aRef.GetSheetPath();
930
931 std::function<bool( wxString* )> symbolResolver =
932 [&]( wxString* token ) -> bool
933 {
934 return aRef.GetSymbol()->ResolveTextVar( &path, token, depth + 1 );
935 };
936
937 return ExpandTextVars( aFieldName, &symbolResolver );
938 }
939
940 return wxEmptyString;
941}
942
943
944bool FIELDS_EDITOR_GRID_DATA_MODEL::isAttribute( const wxString& aFieldName )
945{
946 return aFieldName == wxS( "${DNP}" )
947 || aFieldName == wxS( "${EXCLUDE_FROM_BOARD}" )
948 || aFieldName == wxS( "${EXCLUDE_FROM_BOM}" )
949 || aFieldName == wxS( "${EXCLUDE_FROM_SIM}" );
950}
951
952
953wxString FIELDS_EDITOR_GRID_DATA_MODEL::getAttributeValue( const SCH_REFERENCE& aRef, const wxString& aAttributeName,
954 const wxString& aVariantName )
955{
956 if( aAttributeName == wxS( "${DNP}" ) )
957 return aRef.GetSymbolDNP( aVariantName ) ? wxS( "1" ) : wxS( "0" );
958
959 if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
960 return aRef.GetSymbolExcludedFromBoard() ? wxS( "1" ) : wxS( "0" );
961
962 if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
963 return aRef.GetSymbolExcludedFromBOM( aVariantName ) ? wxS( "1" ) : wxS( "0" );
964
965 if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
966 return aRef.GetSymbolExcludedFromSim( aVariantName ) ? wxS( "1" ) : wxS( "0" );
967
968 return wxS( "0" );
969}
970
971
973 const wxString& aAttributeName ) const
974{
975 const SCH_SHEET_PATH& path = aRef.GetSheetPath();
976
977 if( aAttributeName == wxS( "${DNP}" ) )
978 return path.GetDNP( m_currentVariant );
979 else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
980 return path.GetExcludedFromBoard( m_currentVariant );
981 else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
982 return path.GetExcludedFromBOM( m_currentVariant );
983 else if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
984 return path.GetExcludedFromSim( m_currentVariant );
985
986 return false;
987}
988
989
991{
992 if( !ColIsAttribute( aCol ) || aGroup.m_Refs.empty() )
993 return false;
994
995 // Lock the cell only when every symbol in the row inherits it, so a mixed group
996 // stays editable and shows the indeterminate state.
997 for( const SCH_REFERENCE& ref : aGroup.m_Refs )
998 {
999 if( !attributeInheritedFromSheet( ref, m_cols[aCol].m_fieldName ) )
1000 return false;
1001 }
1002
1003 return true;
1004}
1005
1006
1008 const wxString& aFieldName )
1009{
1010 const SCH_SYMBOL* symbol = aRef.GetSymbol();
1011
1012 if( !symbol )
1013 return wxEmptyString;
1014
1015 // For attributes, get the default (non-variant) value
1016 if( isAttribute( aFieldName ) )
1017 return getAttributeValue( aRef, aFieldName, wxEmptyString );
1018
1019 // For regular fields, get the text without variant override
1020 if( const SCH_FIELD* field = symbol->GetField( aFieldName ) )
1021 {
1022 if( field->IsPrivate() )
1023 return wxEmptyString;
1024
1025 // Get the field text with empty variant name (default value)
1026 wxString value = symbol->Schematic()->ConvertKIIDsToRefs(
1027 field->GetText( &aRef.GetSheetPath(), wxEmptyString ) );
1028 return value;
1029 }
1030
1031 // For generated fields, return the field name itself
1032 if( IsGeneratedField( aFieldName ) )
1033 return aFieldName;
1034
1035 return wxEmptyString;
1036}
1037
1038
1040 const wxString& aAttributeName,
1041 const wxString& aValue,
1042 const wxString& aVariantName )
1043{
1044 bool attrChanged = false;
1045 bool newValue = aValue == wxS( "1" );
1046
1047 if( aAttributeName == wxS( "${DNP}" ) )
1048 {
1049 attrChanged = aRef.GetSymbolDNP( aVariantName ) != newValue;
1050 aRef.SetSymbolDNP( newValue, aVariantName );
1051 }
1052 else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
1053 {
1054 attrChanged = aRef.GetSymbolExcludedFromBoard() != newValue;
1055 aRef.SetSymbolExcludedFromBoard( newValue );
1056 }
1057 else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
1058 {
1059 attrChanged = aRef.GetSymbolExcludedFromBOM( aVariantName ) != newValue;
1060 aRef.SetSymbolExcludedFromBOM( newValue, aVariantName );
1061 }
1062 else if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
1063 {
1064 attrChanged = aRef.GetSymbolExcludedFromSim( aVariantName ) != newValue;
1065 aRef.SetSymbolExcludedFromSim( newValue, aVariantName );
1066 }
1067
1068 return attrChanged;
1069}
1070
1071
1076
1077
1082
1083
1085{
1086 if( !m_rebuildsEnabled )
1087 return;
1088
1089 if( GetView() )
1090 {
1091 // Commit any pending in-place edits before the row gets moved out from under
1092 // the editor.
1093 static_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
1094
1095 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
1096 GetView()->ProcessTableMessage( msg );
1097 }
1098
1099 m_rows.clear();
1100
1101 EDA_COMBINED_MATCHER matcher( m_filter.Lower(), CTX_SEARCH );
1102
1103 for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
1104 {
1106
1107 if( !m_filter.IsEmpty() && !matcher.Find( ref.GetFullRef().Lower() ) )
1108 continue;
1109
1110 if( m_excludeDNP )
1111 {
1112 bool isDNP = false;
1113
1114 if( !m_variantNames.empty() )
1115 {
1116 for( const wxString& variantName : m_variantNames )
1117 {
1118 if( ref.GetSymbol()->ResolveDNP( &ref.GetSheetPath(), variantName )
1119 || ref.GetSheetPath().GetDNP( variantName ) )
1120 {
1121 isDNP = true;
1122 break;
1123 }
1124 }
1125 }
1126 else
1127 {
1128 isDNP = ref.GetSymbol()->ResolveDNP( &ref.GetSheetPath(), m_currentVariant )
1130 }
1131
1132 if( isDNP )
1133 continue;
1134 }
1135
1136 if( !m_includeExcluded )
1137 {
1138 bool isExcluded = false;
1139
1140 if( !m_variantNames.empty() )
1141 {
1142 for( const wxString& variantName : m_variantNames )
1143 {
1144 if( ref.GetSymbol()->ResolveExcludedFromBOM( &ref.GetSheetPath(), variantName )
1145 || ref.GetSheetPath().GetExcludedFromBOM( variantName ) )
1146 {
1147 isExcluded = true;
1148 break;
1149 }
1150 }
1151 }
1152 else
1153 {
1154 isExcluded = ref.GetSymbol()->ResolveExcludedFromBOM( &ref.GetSheetPath(), m_currentVariant )
1156 }
1157
1158 if( isExcluded )
1159 continue;
1160 }
1161
1162 // Check if the symbol if on the current sheet or, in the sheet path somewhere
1163 // depending on scope
1164 if( ( m_scope == SCOPE::SCOPE_SHEET && ref.GetSheetPath() != m_path )
1165 || ( m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
1166 && !ref.GetSheetPath().IsContainedWithin( m_path ) ) )
1167 {
1168 continue;
1169 }
1170
1171 bool matchFound = false;
1172
1173 // Performance optimization for ungrouped case to skip the N^2 for loop
1174 if( !m_groupingEnabled && !ref.IsMultiUnit() )
1175 {
1176 m_rows.emplace_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
1177 continue;
1178 }
1179
1180 // See if we already have a row which this symbol fits into
1181 for( DATA_MODEL_ROW& row : m_rows )
1182 {
1183 // all group members must have identical refs so just use the first one
1184 SCH_REFERENCE rowRef = row.m_Refs[0];
1185
1186 if( unitMatch( ref, rowRef ) )
1187 {
1188 matchFound = true;
1189 row.m_Refs.push_back( ref );
1190 break;
1191 }
1192 else if( m_groupingEnabled && groupMatch( ref, rowRef ) )
1193 {
1194 matchFound = true;
1195 row.m_Refs.push_back( ref );
1196 row.m_Flag = GROUP_COLLAPSED;
1197 break;
1198 }
1199 }
1200
1201 if( !matchFound )
1202 m_rows.emplace_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
1203 }
1204
1205 if( GetView() )
1206 {
1207 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
1208 GetView()->ProcessTableMessage( msg );
1209 }
1210
1211 Sort();
1212}
1213
1214
1216{
1217 std::vector<DATA_MODEL_ROW> children;
1218
1219 for( SCH_REFERENCE& ref : m_rows[aRow].m_Refs )
1220 {
1221 bool matchFound = false;
1222
1223 // See if we already have a child group which this symbol fits into
1224 for( DATA_MODEL_ROW& child : children )
1225 {
1226 // group members are by definition all matching, so just check
1227 // against the first member
1228 if( unitMatch( ref, child.m_Refs[0] ) )
1229 {
1230 matchFound = true;
1231 child.m_Refs.push_back( ref );
1232 break;
1233 }
1234 }
1235
1236 if( !matchFound )
1237 children.emplace_back( DATA_MODEL_ROW( ref, CHILD_ITEM ) );
1238 }
1239
1240 if( children.size() < 2 )
1241 return;
1242
1243 std::sort( children.begin(), children.end(),
1244 [this]( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
1245 {
1246 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
1247 } );
1248
1249 m_rows[aRow].m_Flag = GROUP_EXPANDED;
1250 m_rows.insert( m_rows.begin() + aRow + 1, children.begin(), children.end() );
1251
1252 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
1253 GetView()->ProcessTableMessage( msg );
1254}
1255
1256
1258{
1259 auto firstChild = m_rows.begin() + aRow + 1;
1260 auto afterLastChild = firstChild;
1261 int deleted = 0;
1262
1263 while( afterLastChild != m_rows.end() && afterLastChild->m_Flag == CHILD_ITEM )
1264 {
1265 deleted++;
1266 afterLastChild++;
1267 }
1268
1269 m_rows[aRow].m_Flag = GROUP_COLLAPSED;
1270 m_rows.erase( firstChild, afterLastChild );
1271
1272 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
1273 GetView()->ProcessTableMessage( msg );
1274}
1275
1276
1278{
1279 DATA_MODEL_ROW& group = m_rows[aRow];
1280
1281 if( group.m_Flag == GROUP_COLLAPSED )
1282 ExpandRow( aRow );
1283 else if( group.m_Flag == GROUP_EXPANDED )
1284 CollapseRow( aRow );
1285}
1286
1287
1289{
1290 for( size_t i = 0; i < m_rows.size(); ++i )
1291 {
1292 if( m_rows[i].m_Flag == GROUP_EXPANDED )
1293 {
1294 CollapseRow( i );
1296 }
1297 }
1298}
1299
1300
1302{
1303 for( size_t i = 0; i < m_rows.size(); ++i )
1304 {
1305 if( m_rows[i].m_Flag == GROUP_COLLAPSED_DURING_SORT )
1306 ExpandRow( i );
1307 }
1308}
1309
1310
1312 const wxString& aVariantName )
1313{
1314 bool symbolModified = false;
1315 std::unique_ptr<SCH_SYMBOL> symbolCopy;
1316
1317 for( size_t i = 0; i < m_symbolsList.GetCount(); i++ )
1318 {
1319 SCH_SYMBOL* symbol = m_symbolsList[i].GetSymbol();
1320 SCH_SYMBOL* nextSymbol = nullptr;
1321
1322 if( ( i + 1 ) < m_symbolsList.GetCount() )
1323 nextSymbol = m_symbolsList[i + 1].GetSymbol();
1324
1325 if( i == 0 )
1326 symbolCopy = std::make_unique<SCH_SYMBOL>( *symbol );
1327
1328 KIID_PATH key = makeDataStoreKey( m_symbolsList[i].GetSheetPath(), *symbol );
1329 const std::map<wxString, wxString>& fieldStore = m_dataStore[key];
1330
1331 for( const auto& [srcName, srcValue] : fieldStore )
1332 {
1333 // Attributes bypass the field logic, so handle them first
1334 if( isAttribute( srcName ) )
1335 {
1336 symbolModified |= setAttributeValue( m_symbolsList[i], srcName, srcValue, aVariantName );
1337 continue;
1338 }
1339
1340 // Skip generated fields with variables as names (e.g. ${QUANTITY});
1341 // they can't be edited
1342 if( IsGeneratedField( srcName ) )
1343 continue;
1344
1345 SCH_FIELD* destField = symbol->FindFieldCaseInsensitive( srcName );
1346
1347 if( destField && !destField->IsMandatory() && destField->GetName() != srcName )
1348 {
1349 destField->SetName( srcName );
1350 symbolModified = true;
1351 }
1352
1353 if( destField && destField->IsPrivate() )
1354 {
1355 if( srcValue.IsEmpty() )
1356 continue;
1357 else
1358 destField->SetPrivate( false );
1359 }
1360
1361 int col = GetFieldNameCol( srcName );
1362 bool userAdded = ( col != -1 && m_cols[col].m_userAdded );
1363
1364 // Add a not existing field if it has a value for this symbol
1365 bool createField = !destField && ( !srcValue.IsEmpty() || userAdded );
1366
1367 if( createField )
1368 {
1369 destField = symbol->AddField( SCH_FIELD( symbol, FIELD_T::USER, srcName ) );
1370 destField->SetTextAngle( symbol->GetField( FIELD_T::REFERENCE )->GetTextAngle() );
1371
1372 if( const TEMPLATE_FIELDNAME* srcTemplate = aTemplateFieldnames.GetFieldName( srcName ) )
1373 destField->SetVisible( srcTemplate->m_Visible );
1374 else
1375 destField->SetVisible( false );
1376
1377 destField->SetTextPos( symbol->GetPosition() );
1378 symbolModified = true;
1379 }
1380
1381 if( !destField )
1382 continue;
1383
1384 // Reference is not editable from this dialog
1385 if( destField->GetId() == FIELD_T::REFERENCE )
1386 continue;
1387
1388 wxString previousValue = destField->GetText( &m_symbolsList[i].GetSheetPath(), aVariantName );
1389
1390 destField->SetText( symbol->Schematic()->ConvertRefsToKIIDs( srcValue ), &m_symbolsList[i].GetSheetPath(),
1391 aVariantName );
1392
1393 if( !createField && ( previousValue != srcValue ) )
1394 symbolModified = true;
1395 }
1396
1397 for( int ii = static_cast<int>( symbol->GetFields().size() ) - 1; ii >= 0; ii-- )
1398 {
1399 if( symbol->GetFields()[ii].IsMandatory() || symbol->GetFields()[ii].IsPrivate() )
1400 continue;
1401
1402 const wxString& existingName = symbol->GetFields()[ii].GetName();
1403
1404 bool stillTracked = std::any_of( fieldStore.begin(), fieldStore.end(),
1405 [&]( const auto& kv )
1406 {
1407 return kv.first.IsSameAs( existingName, false );
1408 } );
1409
1410 if( !stillTracked )
1411 {
1412 symbol->GetFields().erase( symbol->GetFields().begin() + ii );
1413 symbolModified = true;
1414 }
1415 }
1416
1417 if( symbolModified && ( symbol != nextSymbol ) )
1418 aCommit.Modified( symbol, symbolCopy.release(), m_symbolsList[i].GetSheetPath().LastScreen() );
1419
1420 // Only reset the modified flag and next symbol copy if the next symbol is different from the current one.
1421 if( symbol != nextSymbol )
1422 {
1423 if( nextSymbol )
1424 symbolCopy = std::make_unique<SCH_SYMBOL>( *nextSymbol );
1425 else
1426 symbolCopy.reset( nullptr );
1427
1428 symbolModified = false;
1429 }
1430 }
1431
1432 m_edited = false;
1433}
1434
1435
1437{
1438 int width = 0;
1439
1440 if( ColIsReference( aCol ) )
1441 {
1442 for( int row = 0; row < GetNumberRows(); ++row )
1443 width = std::max( width, KIUI::GetTextSize( GetValue( row, aCol ), GetView() ).x );
1444 }
1445 else
1446 {
1447 wxString fieldName = GetColFieldName( aCol ); // symbol fieldName or Qty string
1448
1449 for( unsigned symbolRef = 0; symbolRef < m_symbolsList.GetCount(); ++symbolRef )
1450 {
1451 KIID_PATH key = makeDataStoreKey( m_symbolsList[symbolRef].GetSheetPath(),
1452 *m_symbolsList[symbolRef].GetSymbol() );
1453 wxString text = m_dataStore[key][fieldName];
1454
1455 width = std::max( width, KIUI::GetTextSize( text, GetView() ).x );
1456 }
1457 }
1458
1459 return width;
1460}
1461
1462
1463void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyBomPreset( const BOM_PRESET& aPreset, const wxString& aVariantName )
1464{
1465 // Hide and un-group everything by default
1466 for( size_t i = 0; i < m_cols.size(); i++ )
1467 {
1468 SetShowColumn( i, false );
1469 SetGroupColumn( i, false );
1470 }
1471
1472 std::set<wxString> seen;
1473 std::vector<wxString> order;
1474
1475 // Set columns that are present and shown
1476 for( const BOM_FIELD& field : aPreset.fieldsOrdered )
1477 {
1478 // Ignore empty fields
1479 if( !field.name || seen.count( field.name ) )
1480 continue;
1481
1482 seen.insert( field.name );
1483 order.emplace_back( field.name );
1484
1485 int col = GetFieldNameCol( field.name );
1486
1487 // Add any missing fields, if the user doesn't add any data
1488 // they won't be saved to the symbols anyway
1489 if( col == -1 )
1490 {
1491 AddColumn( field.name, field.label, true, aVariantName );
1492 col = GetFieldNameCol( field.name );
1493 }
1494 else
1495 {
1496 SetColLabelValue( col, field.label );
1497 }
1498
1499 SetGroupColumn( col, field.groupBy );
1500 SetShowColumn( col, field.show );
1501 }
1502
1503 // Set grouping columns
1505
1506 SetFieldsOrder( order );
1507
1508 // Set our sorting
1509 int sortCol = GetFieldNameCol( aPreset.sortField );
1510
1511 if( sortCol == -1 )
1513
1514 SetSorting( sortCol, aPreset.sortAsc );
1515
1516 SetFilter( aPreset.filterString );
1517 SetExcludeDNP( aPreset.excludeDNP );
1519 SetCurrentVariant( aVariantName );
1520
1521 RebuildRows();
1522}
1523
1524
1526{
1527 BOM_PRESET current;
1528 current.readOnly = false;
1529 current.fieldsOrdered = GetFieldsOrdered();
1530
1531 if( GetSortCol() >= 0 && GetSortCol() < GetNumberCols() )
1532 current.sortField = GetColFieldName( GetSortCol() );
1533
1534 current.sortAsc = GetSortAsc();
1535 current.filterString = GetFilter();
1536 current.groupSymbols = GetGroupingEnabled();
1537 current.excludeDNP = GetExcludeDNP();
1539
1540 return current;
1541}
1542
1543
1545{
1546 wxString out;
1547
1548 if( m_cols.empty() )
1549 return out;
1550
1551 int last_col = -1;
1552
1553 // Find the location for the line terminator
1554 for( size_t col = 0; col < m_cols.size(); col++ )
1555 {
1556 if( m_cols[col].m_show )
1557 last_col = static_cast<int>( col );
1558 }
1559
1560 // No shown columns
1561 if( last_col == -1 )
1562 return out;
1563
1564 auto formatField =
1565 [&]( wxString field, bool last ) -> wxString
1566 {
1567 if( !settings.keepLineBreaks )
1568 {
1569 field.Replace( wxS( "\r" ), wxS( "" ) );
1570 field.Replace( wxS( "\n" ), wxS( "" ) );
1571 }
1572
1573 if( !settings.keepTabs )
1574 {
1575 field.Replace( wxS( "\t" ), wxS( "" ) );
1576 }
1577
1578 if( !settings.stringDelimiter.IsEmpty() )
1579 {
1580 field.Replace( settings.stringDelimiter,
1581 settings.stringDelimiter + settings.stringDelimiter );
1582 }
1583
1584 return settings.stringDelimiter + field + settings.stringDelimiter
1585 + ( last ? wxString( wxS( "\n" ) ) : settings.fieldDelimiter );
1586 };
1587
1588 // Column names
1589 for( size_t col = 0; col < m_cols.size(); col++ )
1590 {
1591 if( !m_cols[col].m_show )
1592 continue;
1593
1594 out.Append( formatField( m_cols[col].m_label, col == static_cast<size_t>( last_col ) ) );
1595 }
1596
1597 // Data rows
1598 for( size_t row = 0; row < m_rows.size(); row++ )
1599 {
1600 // Don't output child rows
1601 if( GetRowFlags( static_cast<int>( row ) ) == CHILD_ITEM )
1602 continue;
1603
1604 for( size_t col = 0; col < m_cols.size(); col++ )
1605 {
1606 if( !m_cols[col].m_show )
1607 continue;
1608
1609 // Get the unannotated version of the field, e.g. no "> " or "v " by
1610 out.Append( formatField( GetExportValue( static_cast<int>( row ), static_cast<int>( col ),
1611 settings.refDelimiter, settings.refRangeDelimiter ),
1612 col == static_cast<size_t>( last_col ) ) );
1613 }
1614 }
1615
1616 return out;
1617}
1618
1619
1621{
1622 bool refListChanged = false;
1623
1624 for( const SCH_REFERENCE& ref : aRefs )
1625 {
1626 if( !m_symbolsList.Contains( ref ) )
1627 {
1628 SCH_SYMBOL* symbol = ref.GetSymbol();
1629
1630 m_symbolsList.AddItem( ref );
1631
1632 KIID_PATH key = makeDataStoreKey( ref.GetSheetPath(), *symbol );
1633
1634 // Update the fields of every reference
1635 for( const SCH_FIELD& field : symbol->GetFields() )
1636 {
1637 if( !field.IsPrivate() )
1638 {
1639 wxString name = field.GetCanonicalName();
1640 wxString value = symbol->Schematic()->ConvertKIIDsToRefs( field.GetText() );
1641
1642 m_dataStore[key][name] = value;
1643 }
1644 }
1645
1646 for( const DATA_MODEL_COL& col : m_cols )
1647 m_dataStore[key].try_emplace( col.m_fieldName, wxEmptyString );
1648
1649 refListChanged = true;
1650 }
1651 }
1652
1653 if( refListChanged )
1654 m_symbolsList.SortBySymbolPtr();
1655}
1656
1657
1659{
1660 // The schematic event listener passes us the symbol after it has been removed,
1661 // so we can't just work with a SCH_REFERENCE_LIST like the other handlers as the
1662 // references are already gone. Instead we need to prune our list.
1663
1664 // Since we now use full KIID_PATH as keys, we need to find and remove all entries
1665 // that correspond to this symbol (their keys end with the symbol's UUID)
1666 KIID symbolUuid = aSymbol.m_Uuid;
1667 std::vector<KIID_PATH> keysToRemove;
1668
1669 for( const auto& [key, value] : m_dataStore )
1670 {
1671 if( !key.empty() && ( key.back() == symbolUuid ) )
1672 keysToRemove.push_back( key );
1673 }
1674
1675 for( const KIID_PATH& key : keysToRemove )
1676 m_dataStore.erase( key );
1677
1678 // Remove all refs that match this symbol using remove_if
1679 m_symbolsList.erase( std::remove_if( m_symbolsList.begin(), m_symbolsList.end(),
1680 [&aSymbol]( const SCH_REFERENCE& ref ) -> bool
1681 {
1682 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
1683 } ),
1684 m_symbolsList.end() );
1685}
1686
1687
1689{
1690 for( const SCH_REFERENCE& ref : aRefs )
1691 {
1692 int index = m_symbolsList.FindRefByFullPath( ref.GetFullPath() );
1693
1694 if( index != -1 )
1695 {
1696 KIID_PATH key = makeDataStoreKey( ref.GetSheetPath(), *ref.GetSymbol() );
1697 m_dataStore.erase( key );
1698 m_symbolsList.RemoveItem( index );
1699 }
1700 }
1701}
1702
1703
1705 const wxString& aVariantName )
1706{
1707 bool refListChanged = false;
1708
1709 for( const SCH_REFERENCE& ref : aRefs )
1710 {
1711 // Update the fields of every reference. Do this by iterating through the data model
1712 // columns; we must have all fields in the symbol added to the data model at this point,
1713 // and some of the data model columns may be variables that are not present in the symbol
1714 for( const DATA_MODEL_COL& col : m_cols )
1715 updateDataStoreSymbolField( ref, col.m_fieldName, aVariantName );
1716
1717 if( SCH_REFERENCE* listRef = m_symbolsList.FindItem( ref ) )
1718 {
1719 *listRef = ref;
1720 }
1721 else
1722 {
1723 m_symbolsList.AddItem( ref );
1724 refListChanged = true;
1725 }
1726 }
1727
1728 if( refListChanged )
1729 m_symbolsList.SortBySymbolPtr();
1730}
1731
1732
1734{
1735 // Serialize the un-applied edit store keyed by symbol identity (sheet path + UUID), so that
1736 // restoring it is independent of the current row grouping/order.
1737 nlohmann::json j = nlohmann::json::object();
1738
1739 for( const auto& [key, fields] : m_dataStore )
1740 {
1741 nlohmann::json jfields = nlohmann::json::object();
1742
1743 for( const auto& [name, value] : fields )
1744 jfields[std::string( name.ToUTF8() )] = std::string( value.ToUTF8() );
1745
1746 j[std::string( key.AsString().ToUTF8() )] = jfields;
1747 }
1748
1749 return wxString( j.dump() );
1750}
1751
1752
1754{
1755 nlohmann::json j = nlohmann::json::parse( aState.ToStdString(), nullptr, false );
1756
1757 if( !j.is_object() )
1758 return;
1759
1760 for( auto it = j.begin(); it != j.end(); ++it )
1761 {
1762 KIID_PATH key( wxString::FromUTF8( it.key().c_str() ) );
1763 std::map<wxString, wxString>& fields = m_dataStore[key];
1764
1765 for( auto fit = it.value().begin(); fit != it.value().end(); ++fit )
1766 fields[wxString::FromUTF8( fit.key().c_str() )] =
1767 wxString::FromUTF8( fit.value().get<std::string>().c_str() );
1768 }
1769
1770 m_edited = true;
1771 RebuildRows();
1772
1773 if( GetView() )
1774 GetView()->ForceRefresh();
1775}
1776
1777
1778bool FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows( size_t aPosition, size_t aNumRows )
1779{
1780 size_t curNumRows = m_rows.size();
1781
1782 if( aPosition >= curNumRows )
1783 {
1784 wxFAIL_MSG( wxString::Format( wxT( "Called FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows(aPosition=%lu, "
1785 "aNumRows=%lu)\nPosition value is invalid for present table with %lu rows" ),
1786 (unsigned long) aPosition, (unsigned long) aNumRows,
1787 (unsigned long) curNumRows ) );
1788
1789 return false;
1790 }
1791
1792 if( aNumRows > curNumRows - aPosition )
1793 {
1794 aNumRows = curNumRows - aPosition;
1795 }
1796
1797 if( aNumRows >= curNumRows )
1798 {
1799 m_rows.clear();
1800 m_dataStore.clear();
1801 }
1802 else
1803 {
1804 const auto first = m_rows.begin() + aPosition;
1805 std::vector<SCH_REFERENCE> dataMapRefs = first->m_Refs;
1806 m_rows.erase( first, first + aNumRows );
1807
1808 for( const SCH_REFERENCE& ref : dataMapRefs )
1809 m_dataStore.erase( ref.GetSheetPath().Path() );
1810 }
1811
1812 if( GetView() )
1813 {
1814 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPosition, aNumRows );
1815 GetView()->ProcessTableMessage( msg );
1816 }
1817
1818 return true;
1819}
1820
1821
1822std::vector<FIELD_CASE_CONFLICT> DetectFieldCaseConflicts( const SCH_REFERENCE_LIST& aSymbols )
1823{
1824 std::vector<FIELD_CASE_CONFLICT> conflicts;
1825
1826 for( unsigned i = 0; i < aSymbols.GetCount(); ++i )
1827 {
1828 SCH_SYMBOL* symbol = aSymbols[i].GetSymbol();
1829
1830 if( !symbol )
1831 continue;
1832
1833 std::map<wxString, std::vector<std::pair<wxString, wxString>>> groups;
1834
1835 for( const SCH_FIELD& field : symbol->GetFields() )
1836 {
1837 if( field.IsMandatory() || field.IsPrivate() )
1838 continue;
1839
1840 groups[field.GetName().Lower()].emplace_back( field.GetName(), field.GetText() );
1841 }
1842
1843 for( const auto& [key, members] : groups )
1844 {
1845 if( members.size() < 2 )
1846 continue;
1847
1849 c.symbol = symbol;
1850 c.sheetPath = aSymbols[i].GetSheetPath();
1851 c.reference = symbol->GetRef( &c.sheetPath );
1852 c.caseFoldedKey = key;
1853 c.variants = members;
1854 conflicts.push_back( std::move( c ) );
1855 }
1856 }
1857
1858 return conflicts;
1859}
int index
const char * name
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition commit.cpp:180
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Look in all existing matchers, return the earliest match of any of the existing.
const KIID m_Uuid
Definition eda_item.h:531
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:576
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:381
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:168
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:294
int GetFieldNameCol(const wxString &aFieldName) const
void AddColumn(const wxString &aFieldName, const wxString &aLabel, bool aAddedByUser, const wxString &aVariantName)
std::vector< DATA_MODEL_ROW > m_rows
void SetFieldsOrder(const std::vector< wxString > &aNewOrder)
SCH_REFERENCE_LIST m_symbolsList
The flattened by hierarchy list of symbols.
wxGridCellRenderer * m_textVarRenderer
Renderer for cells with text variable references.
void UpdateReferences(const SCH_REFERENCE_LIST &aRefs, const wxString &aVariantName)
wxString m_currentVariant
Current variant name for highlighting.
bool DeleteRows(size_t aPosition=0, size_t aNumRows=1) override
bool groupMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
void updateDataStoreSymbolField(const SCH_REFERENCE &aSymbolRef, const wxString &aFieldName, const wxString &aVariantName)
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
wxString SerializeUndoState() const override
wxString getAttributeValue(const SCH_REFERENCE &aRef, const wxString &aAttributeName, const wxString &aVariantNames)
wxString GetExportValue(int aRow, int aCol, const wxString &refDelimiter, const wxString &refRangeDelimiter)
wxString getDefaultFieldValue(const SCH_REFERENCE &aRef, const wxString &aFieldName)
Get the default (non-variant) value for a field.
wxString getFieldShownText(const SCH_REFERENCE &aRef, const wxString &aFieldName)
wxString GetResolvedValue(int aRow, int aCol)
void RenameColumn(int aCol, const wxString &newName)
FIELDS_EDITOR_GRID_DATA_MODEL(const SCH_REFERENCE_LIST &aSymbolsList, wxGridCellAttr *aURLEditor)
bool IsExpanderColumn(int aCol) const override
wxString Export(const BOM_FMT_PRESET &settings)
std::vector< wxString > m_variantNames
Variant names for multi-variant DNP filtering.
std::vector< DATA_MODEL_COL > m_cols
void SetSorting(int aCol, bool ascending)
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
void SetFilter(const wxString &aFilter)
bool setAttributeValue(SCH_REFERENCE &aRef, const wxString &aAttributeName, const wxString &aValue, const wxString &aVariantName=wxEmptyString)
Set the attribute value.
void RestoreUndoState(const wxString &aState) override
bool attributeInheritedFromSheet(const SCH_REFERENCE &aRef, const wxString &aAttributeName) const
static bool cmp(const DATA_MODEL_ROW &lhGroup, const DATA_MODEL_ROW &rhGroup, FIELDS_EDITOR_GRID_DATA_MODEL *dataModel, int sortCol, bool ascending)
void ApplyBomPreset(const BOM_PRESET &preset, const wxString &aVariantName)
static const wxString ITEM_NUMBER_VARIABLE
void SetIncludeExcludedFromBOM(bool include)
bool isAttribute(const wxString &aFieldName)
wxString GetValue(int aRow, int aCol) override
bool rowAttributeInheritedFromSheet(const DATA_MODEL_ROW &aGroup, int aCol)
static const wxString QUANTITY_VARIABLE
void SetGroupColumn(int aCol, bool group)
void RemoveSymbol(const SCH_SYMBOL &aSymbol)
std::vector< BOM_FIELD > GetFieldsOrdered()
void SetValue(int aRow, int aCol, const wxString &aValue) override
std::map< KIID_PATH, std::map< wxString, wxString > > m_dataStore
void ApplyData(SCH_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames, const wxString &aVariantName)
void SetColLabelValue(int aCol, const wxString &aLabel) override
void SetCurrentVariant(const wxString &aVariantName)
Set the current variant name for highlighting purposes.
void RemoveReferences(const SCH_REFERENCE_LIST &aRefs)
void SetShowColumn(int aCol, bool show)
void AddReferences(const SCH_REFERENCE_LIST &aRefs)
Cell renderer that shows the expanded result of text variables (e.g.
wxSize GetBestSize(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, int aRow, int aCol) override
wxGridCellRenderer * Clone() const override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
Definition kiid.h:44
wxString ConvertKIIDsToRefs(const wxString &aSource) const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
bool IsMandatory() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:128
FIELD_T GetId() const
Definition sch_field.h:132
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0, const wxString &aVariantName=wxEmptyString) const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
void SetPrivate(bool aPrivate)
Definition sch_item.h:247
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:268
bool IsPrivate() const
Definition sch_item.h:248
bool ResolveExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:314
bool ResolveDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:362
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
static wxString Shorthand(std::vector< SCH_REFERENCE > aList, const wxString &refDelimiter, const wxString &refRangeDelimiter)
Return a shorthand string representing all the references in the list.
A helper to define a symbol's reference designator in a schematic.
void SetSymbolExcludedFromBoard(bool aEnable)
const SCH_SHEET_PATH & GetSheetPath() const
void SetSymbolExcludedFromBOM(bool aEnable, const wxString &aVariant=wxEmptyString)
bool GetSymbolExcludedFromBOM(const wxString &aVariant=wxEmptyString) const
bool GetSymbolDNP(const wxString &aVariant=wxEmptyString) const
SCH_SYMBOL * GetSymbol() const
void SetSymbolExcludedFromSim(bool aEnable, const wxString &aVariant=wxEmptyString)
wxString GetRef() const
bool GetSymbolExcludedFromBoard() const
wxString GetFullRef(bool aIncludeUnit=true) const
Return reference name with unit altogether.
bool GetSymbolExcludedFromSim(const wxString &aVariant=wxEmptyString) const
bool IsMultiUnit() const
wxString GetRefNumber() const
void SetSymbolDNP(bool aEnable, const wxString &aVariant=wxEmptyString)
int GetRefCount() const
Definition sch_screen.h:168
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
bool GetDNP() const
Schematic symbol object.
Definition sch_symbol.h:69
SCH_FIELD * FindFieldCaseInsensitive(const wxString &aFieldName)
Search for a SCH_FIELD with aFieldName.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:885
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
void SetValueAsBool(int aRow, int aCol, bool aValue) override
wxString GetColLabelValue(int aCol) override
std::vector< BOM_FIELD > m_fields
void SetValue(int aRow, int aCol, const wxString &aValue) override
void AppendRow(const wxString &aFieldName, const wxString &aBOMName, bool aShow, bool aGroupBy)
bool GetValueAsBool(int aRow, int aCol) override
void SetCanonicalFieldName(int aRow, const wxString &aName)
wxString GetValue(int aRow, int aCol) override
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
Definition wx_grid.cpp:43
std::map< int, wxGridCellAttr * > m_colAttrs
Definition wx_grid.h:100
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
Definition wx_grid.h:64
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:59
bool IsGeneratedField(const wxString &aSource)
Returns true if the string is generated, e.g contains a single text var reference.
Definition common.cpp:456
The common library.
#define _(s)
@ CTX_SEARCH
std::vector< FIELD_CASE_CONFLICT > DetectFieldCaseConflicts(const SCH_REFERENCE_LIST &aSymbols)
static KIID_PATH makeDataStoreKey(const SCH_SHEET_PATH &aSheetPath, const SCH_SYMBOL &aSymbol)
Create a unique key for the data store by combining the KIID_PATH from the SCH_SHEET_PATH with the sy...
#define LABEL_COLUMN
#define DISPLAY_NAME_COLUMN
#define GROUP_BY_COLUMN
#define SHOW_FIELD_COLUMN
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:78
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
int ValueStringCompare(const wxString &strFWord, const wxString &strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
bool IsURL(wxString aStr)
Performs a URL sniff-test on a string.
wxString label
wxString name
wxString fieldDelimiter
wxString stringDelimiter
wxString refRangeDelimiter
wxString refDelimiter
wxString sortField
bool groupSymbols
std::vector< BOM_FIELD > fieldsOrdered
bool includeExcludedFromBOM
bool excludeDNP
wxString filterString
std::vector< SCH_REFERENCE > m_Refs
SCH_SHEET_PATH sheetPath
std::vector< std::pair< wxString, wxString > > variants
Hold a name of a symbol's field, field value, and default visibility.
wxString GetDefaultFieldName(FIELD_T aFieldId, bool aTranslateForHI)
Return a default symbol field name for a mandatory field type.
#define DO_TRANSLATE
#define MANDATORY_FIELDS
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
std::string path
KIBIS_MODEL * model
#define kv
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:46
GROUP_COLLAPSED_DURING_SORT
Definition wx_grid.h:43
GROUP_COLLAPSED
Definition wx_grid.h:42
GROUP_EXPANDED
Definition wx_grid.h:44
GROUP_SINGLETON
Definition wx_grid.h:41