KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_fields_table_presence.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
22
23#include <board.h>
24#include <board_commit.h>
25#include <footprint.h>
27#include <pcb_field.h>
28#include <template_fieldnames.h>
29#include <tool/tool_manager.h>
30
31
33{
35 m_footprint( new FOOTPRINT( &m_board ) ),
37 {
38 m_footprint->SetReference( wxS( "U1" ) );
39 m_board.Add( m_footprint );
40
41 m_model.AddColumn( GetDefaultFieldName( FIELD_T::REFERENCE, UNTRANSLATED ), wxS( "Reference" ), false );
42
43 int referenceCol = m_model.GetFieldNameCol( GetDefaultFieldName( FIELD_T::REFERENCE, UNTRANSLATED ) );
44 BOOST_REQUIRE( referenceCol >= 0 );
45 m_model.SetShowColumn( referenceCol, true );
46 }
47
48 void AddTestColumn( const wxString& aFieldName, bool aAddedByUser = false )
49 {
50 m_model.AddColumn( aFieldName, aFieldName, aAddedByUser );
51 m_col = m_model.GetFieldNameCol( aFieldName );
52 BOOST_REQUIRE( m_col >= 0 );
53 m_model.SetShowColumn( m_col, true );
54 m_model.RebuildRows();
55
56 BOOST_REQUIRE_EQUAL( m_model.GetNumberRows(), 1 );
57 }
58
59 void Apply()
60 {
61 TOOL_MANAGER toolMgr;
62 toolMgr.SetEnvironment( &m_board, nullptr, nullptr, nullptr, nullptr );
63
64 BOARD_COMMIT commit( &toolMgr, true, false );
65 TEMPLATES templates;
66
67 m_model.ApplyData( commit, templates );
68 }
69
73 int m_col = -1;
74};
75
76
77BOOST_FIXTURE_TEST_SUITE( FootprintFieldsTablePresence, FOOTPRINT_FIELDS_TABLE_PRESENCE_FIXTURE )
78
79
80BOOST_AUTO_TEST_CASE( UntouchedMissingPresetFieldRemainsAbsent )
81{
82 const wxString fieldName = wxS( "UninstantiatedPresetField" );
83
84 AddTestColumn( fieldName );
85
86 BOOST_REQUIRE( m_model.IsCellClear( 0, m_col ) );
87
88 Apply();
89
90 BOOST_CHECK( m_footprint->GetField( fieldName ) == nullptr );
91}
92
93
94BOOST_AUTO_TEST_CASE( ExplicitEmptyValueCreatesField )
95{
96 const wxString fieldName = wxS( "ExplicitlyEmptyField" );
97
98 AddTestColumn( fieldName );
99 BOOST_REQUIRE( m_model.IsCellClear( 0, m_col ) );
100
101 m_model.SetValue( 0, m_col, wxEmptyString );
102
103 BOOST_REQUIRE( !m_model.IsCellClear( 0, m_col ) );
104 BOOST_REQUIRE( m_model.IsCellEdited( 0, m_col ) );
105
106 Apply();
107
108 const PCB_FIELD* field = m_footprint->GetField( fieldName );
109 BOOST_REQUIRE( field );
110 BOOST_CHECK( field->GetText().IsEmpty() );
111}
112
113
114BOOST_AUTO_TEST_CASE( ExistingEmptyFieldCanBeCleared )
115{
116 const wxString fieldName = wxS( "ExistingEmptyField" );
117
118 m_footprint->Add( new PCB_FIELD( m_footprint, FIELD_T::USER, fieldName ) );
119 AddTestColumn( fieldName );
120
121 BOOST_REQUIRE( !m_model.IsCellClear( 0, m_col ) );
122 BOOST_REQUIRE( !m_model.IsCellEdited( 0, m_col ) );
123
124 m_model.ClearCell( 0, m_col );
125
126 BOOST_REQUIRE( m_model.IsCellClear( 0, m_col ) );
127 BOOST_REQUIRE( m_model.IsCellEdited( 0, m_col ) );
128
129 Apply();
130
131 BOOST_CHECK( m_footprint->GetField( fieldName ) == nullptr );
132}
133
134
135BOOST_AUTO_TEST_CASE( UserAddedColumnCreatesEmptyField )
136{
137 const wxString fieldName = wxS( "UserAddedEmptyField" );
138
139 AddTestColumn( fieldName, true );
140
141 BOOST_REQUIRE( !m_model.IsCellClear( 0, m_col ) );
142 BOOST_REQUIRE( m_model.IsCellEdited( 0, m_col ) );
143
144 Apply();
145
146 const PCB_FIELD* field = m_footprint->GetField( fieldName );
147 BOOST_REQUIRE( field );
148 BOOST_CHECK( field->GetText().IsEmpty() );
149}
150
151
152BOOST_AUTO_TEST_CASE( ExcludeFromSimulationAttributeIsEditable )
153{
154 const wxString fieldName = wxS( "${EXCLUDE_FROM_SIM}" );
155
156 AddTestColumn( fieldName );
157
158 BOOST_CHECK( !m_model.ColIsReadOnly( m_col ) );
159 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxString( wxS( "0" ) ) );
160
161 m_model.SetValue( 0, m_col, wxS( "1" ) );
162 Apply();
163
164 BOOST_CHECK( m_footprint->IsExcludedFromSim() );
165}
166
167
168BOOST_AUTO_TEST_CASE( ExcludeFromSimulationAttributeIsVariantAware )
169{
170 const wxString fieldName = wxS( "${EXCLUDE_FROM_SIM}" );
171 const wxString variantName = wxS( "Production" );
172
173 m_board.AddVariant( variantName );
174 m_model.SetCurrentVariant( variantName );
175 AddTestColumn( fieldName );
176
177 m_model.SetValue( 0, m_col, wxS( "1" ) );
178 Apply();
179
180 BOOST_CHECK( !m_footprint->IsExcludedFromSim() );
181 BOOST_CHECK( m_footprint->GetExcludedFromSimForVariant( variantName ) );
182}
183
184
185BOOST_AUTO_TEST_CASE( RenameAcrossComputedBoundaryResetsStoredValue )
186{
187 const wxString ordinaryFieldName = wxS( "OrdinaryField" );
188 const wxString computedFieldName = wxS( "@{1+2}" );
189 PCB_FIELD* field = new PCB_FIELD( m_footprint, FIELD_T::USER, ordinaryFieldName );
190
191 field->SetText( wxS( "Ordinary value" ) );
192 m_footprint->Add( field );
193 AddTestColumn( ordinaryFieldName );
194
195 m_model.RenameColumn( m_col, computedFieldName );
196
197 BOOST_REQUIRE( m_model.ColIsComputed( m_col ) );
198 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), computedFieldName );
199 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxString( wxS( "3" ) ) );
200
201 m_model.RenameColumn( m_col, ordinaryFieldName );
202
203 BOOST_REQUIRE( !m_model.ColIsComputed( m_col ) );
204 BOOST_CHECK( m_model.GetValue( 0, m_col ).IsEmpty() );
205
206 Apply();
207
208 field = m_footprint->GetField( ordinaryFieldName );
209 BOOST_REQUIRE( field );
210 BOOST_CHECK( field->GetText().IsEmpty() );
211 BOOST_CHECK( m_footprint->GetField( computedFieldName ) == nullptr );
212}
213
214
215// Repose #2771: an item change event need not mean that any field changed.
216BOOST_AUTO_TEST_CASE( RefreshMergesLiveFieldsWithoutLosingStagedEdits )
217{
218 const wxString name = wxS( "MPN" );
219 PCB_FIELD* field = new PCB_FIELD( m_footprint, FIELD_T::USER, name );
220 field->SetText( wxS( "original" ) );
221 m_footprint->Add( field );
222 AddTestColumn( name );
223 int editedCol = m_col;
225
226 m_model.SetValue( 0, editedCol, wxS( "staged" ) );
227 m_footprint->SetPosition( VECTOR2I( 100, 200 ) );
228 m_footprint->SetValue( wxS( "external value" ) );
229 m_model.UpdateReferences( m_model.GetReferenceList() );
230
231 BOOST_CHECK_EQUAL( m_model.GetValue( 0, editedCol ), wxS( "staged" ) );
232 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "external value" ) );
233 BOOST_CHECK( m_model.IsEdited() );
234
235 Apply();
236 BOOST_CHECK_EQUAL( field->GetText(), wxS( "staged" ) );
237 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "external value" ) );
238 BOOST_CHECK( !m_model.IsEdited() );
239
240 m_model.SetValue( 0, editedCol, wxS( "another staged edit" ) );
241 field->SetText( wxS( "newer external edit" ) );
242 m_model.UpdateReferences( m_model.GetReferenceList() );
243 BOOST_CHECK_EQUAL( m_model.GetValue( 0, editedCol ), wxS( "newer external edit" ) );
244 BOOST_CHECK( !m_model.IsEdited() );
245}
246
247
248BOOST_AUTO_TEST_CASE( RefreshPreservesClearAndExplicitEmptyCreation )
249{
250 const wxString removed = wxS( "Removed" );
251 m_footprint->Add( new PCB_FIELD( m_footprint, FIELD_T::USER, removed ) );
252 AddTestColumn( removed );
253 int removedCol = m_col;
254 m_model.ClearCell( 0, removedCol );
255
256 const wxString created = wxS( "Created" );
257 AddTestColumn( created );
258 m_model.SetValue( 0, m_col, wxEmptyString );
259 m_model.UpdateReferences( m_model.GetReferenceList() );
260
261 BOOST_CHECK( m_model.IsCellClear( 0, removedCol ) );
262 BOOST_CHECK( !m_model.IsCellClear( 0, m_col ) );
263 Apply();
264 BOOST_CHECK( !m_footprint->GetField( removed ) );
265 BOOST_REQUIRE( m_footprint->GetField( created ) );
266 BOOST_CHECK( m_footprint->GetField( created )->GetText().IsEmpty() );
267}
268
269
270// Repose #4001: switching the displayed variant must not change the board.
271BOOST_AUTO_TEST_CASE( VariantSwitchStagesAllEditsUntilApply )
272{
274 m_footprint->SetValue( wxS( "base" ) );
275 m_board.AddVariant( wxS( "A" ) );
276 m_board.AddVariant( wxS( "B" ) );
277 AddTestColumn( name );
278
279 m_model.SetCurrentVariant( wxS( "A" ) );
280 m_model.SetValue( 0, m_col, wxS( "A staged" ) );
281 m_model.SetCurrentVariant( wxS( "B" ) );
282 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "base" ) );
283 m_model.SetValue( 0, m_col, wxS( "B staged" ) );
284 m_model.SetCurrentVariant( wxS( "A" ) );
285 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "A staged" ) );
286 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "A" ), name ), wxS( "base" ) );
287 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "B" ), name ), wxS( "base" ) );
288 BOOST_CHECK( m_model.IsEdited() );
289
290 Apply();
291 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "base" ) );
292 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "A" ), name ), wxS( "A staged" ) );
293 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "B" ), name ), wxS( "B staged" ) );
294 BOOST_CHECK( !m_model.IsEdited() );
295 m_model.UpdateReferences( m_model.GetReferenceList() );
296 BOOST_CHECK( !m_model.IsEdited() );
297}
298
299
300BOOST_AUTO_TEST_CASE( DiscardingModelAfterVariantSwitchLeavesBoardUnchanged )
301{
302 m_footprint->SetValue( wxS( "base" ) );
304
305 {
306 FOOTPRINT_FIELDS_EDITOR_GRID_DATA_MODEL model( m_model.GetReferenceList() );
307 model.AddColumn( GetDefaultFieldName( FIELD_T::REFERENCE, UNTRANSLATED ), wxS( "Reference" ), false );
308 model.SetShowColumn( 0, true );
309 model.AddColumn( name, name, false );
310 model.RebuildRows();
311 model.SetValue( 0, 1, wxS( "discard me" ) );
312 model.SetCurrentVariant( wxS( "Another" ) );
313 BOOST_CHECK( model.IsEdited() );
314 }
315
316 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "base" ) );
317}
318
319
320BOOST_AUTO_TEST_CASE( CopyUsesStagedSourceValuesForDefaultAndNamedVariants )
321{
323 m_footprint->SetValue( wxS( "base" ) );
324 AddTestColumn( name );
325 m_model.SetCurrentVariant( wxS( "A" ) );
326 m_model.SetValue( 0, m_col, wxS( "A staged" ) );
327 m_model.SetCurrentVariant( wxS( "B" ) );
328 m_model.CopyCellFromVariant( 0, m_col, wxS( "A" ) );
329 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "A staged" ) );
330
331 m_model.SetCurrentVariant( wxEmptyString );
332 m_model.CopyCellFromVariant( 0, m_col, wxS( "B" ) );
333 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "A staged" ) );
334 m_model.SetValue( 0, m_col, wxS( "default staged" ) );
335 m_model.SetCurrentVariant( wxS( "A" ) );
336 m_model.CopyCellFromVariant( 0, m_col, GetDefaultVariantName() );
337 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "default staged" ) );
338 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "base" ) );
339
340 Apply();
341 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "default staged" ) );
342 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "A" ), name ), wxS( "default staged" ) );
343 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "B" ), name ), wxS( "A staged" ) );
344}
345
346
347BOOST_AUTO_TEST_CASE( CopyGroupedCellPreservesEachFootprintsSourceValue )
348{
350 m_footprint->SetValue( wxS( "base" ) );
351 m_footprint->AddVariant( wxS( "A" ) )->SetFieldValue( name, wxS( "first" ) );
352 AddTestColumn( name );
353 FOOTPRINT* other = new FOOTPRINT( &m_board );
354 other->SetReference( wxS( "U2" ) );
355 other->SetValue( wxS( "base" ) );
356 other->AddVariant( wxS( "A" ) )->SetFieldValue( name, wxS( "second" ) );
357 m_board.Add( other );
358 m_model.AddReferences( FOOTPRINT_REFERENCE_LIST{ FOOTPRINT_REF( *other ) } );
359 m_model.SetGroupingEnabled( true );
360 m_model.SetGroupColumn( m_col, true );
361 m_model.RebuildRows();
362 BOOST_REQUIRE_EQUAL( m_model.GetNumberRows(), 1 );
363 BOOST_REQUIRE_EQUAL( m_model.GetRowReferences( 0 ).size(), 2u );
364
365 m_model.CopyCellFromVariant( 0, m_col, wxS( "A" ) );
366 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), INDETERMINATE_STATE );
367 Apply();
368 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "first" ) );
369 BOOST_CHECK_EQUAL( other->GetValue(), wxS( "second" ) );
370}
371
372
373BOOST_AUTO_TEST_CASE( ApplyingBaseEditDoesNotCreateUntouchedVariantOverride )
374{
376 m_footprint->SetValue( wxS( "base" ) );
377 AddTestColumn( name );
378 m_model.SetCurrentVariant( wxS( "Untouched" ) );
379 m_model.SetCurrentVariant( wxEmptyString );
380 m_model.SetValue( 0, m_col, wxS( "new base" ) );
381 m_model.SetCurrentVariant( wxS( "Untouched" ) );
382 Apply();
383
384 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS( "Untouched" ), name ), wxS( "new base" ) );
385 BOOST_CHECK( !m_footprint->GetVariant( wxS( "Untouched" ) ) );
386 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "new base" ) );
387}
388
389
390BOOST_AUTO_TEST_CASE( FieldClearIsSharedWithNewVariantAndCanBeReverted )
391{
392 const wxString name = wxS( "SharedPresence" );
393 PCB_FIELD* field = new PCB_FIELD( m_footprint, FIELD_T::USER, name );
394 field->SetText( wxS( "base" ) );
395 m_footprint->Add( field );
396 AddTestColumn( name );
397 m_model.SetCurrentVariant( wxS( "A" ) );
398 m_model.ClearCell( 0, m_col );
399 m_model.SetCurrentVariant( wxS( "B" ) );
400 BOOST_CHECK( m_model.IsCellClear( 0, m_col ) );
401 m_model.RevertRow( 0 );
402 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "base" ) );
403 BOOST_CHECK( !m_model.IsEdited() );
404 m_model.ClearCell( 0, m_col );
405 m_model.SetCurrentVariant( wxS( "A" ) );
406 Apply();
407 BOOST_CHECK( !m_footprint->GetField( name ) );
408}
409
410
411BOOST_AUTO_TEST_CASE( UndoRestoresEditsInTheirVariantsAndPreservesExternalChanges )
412{
413 m_footprint->SetValue( wxS( "base" ) );
415 m_model.SetCurrentVariant( wxS( "A" ) );
416 m_model.SetValue( 0, m_col, wxS( "A staged" ) );
417 wxString snapshot = m_model.SerializeUndoState();
418 m_model.SetCurrentVariant( wxS( "B" ) );
419 m_model.SetValue( 0, m_col, wxS( "B staged" ) );
420 m_model.RestoreUndoState( snapshot );
421 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "base" ) );
422 m_model.SetCurrentVariant( wxS( "A" ) );
423 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "A staged" ) );
424
425 m_footprint->SetValue( wxS( "external" ) );
426 m_model.UpdateReferences( m_model.GetReferenceList() );
427 m_model.RestoreUndoState( snapshot );
428 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "external" ) );
429 BOOST_CHECK( !m_model.IsEdited() );
430}
431
432
433BOOST_AUTO_TEST_CASE( RefreshMergesInactiveVariantAndExternalFieldRemoval )
434{
435 const wxString name = wxS( "MPN" );
436 PCB_FIELD* field = new PCB_FIELD( m_footprint, FIELD_T::USER, name );
437 field->SetText( wxS( "base" ) );
438 m_footprint->Add( field );
439 AddTestColumn( name );
440 m_model.SetCurrentVariant( wxS( "A" ) );
441 m_model.SetValue( 0, m_col, wxS( "A staged" ) );
442 m_model.SetCurrentVariant( wxS( "B" ) );
443 m_model.SetValue( 0, m_col, wxS( "B staged" ) );
444
445 m_footprint->AddVariant( wxS( "A" ) )->SetFieldValue( name, wxS( "A external" ) );
446 m_model.UpdateReferences( m_model.GetReferenceList() );
447 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "B staged" ) );
448 m_model.SetCurrentVariant( wxS( "A" ) );
449 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "A external" ) );
450 m_model.SetCurrentVariant( wxS( "B" ) );
451 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "B staged" ) );
452
453 m_footprint->Remove( field );
454 delete field;
455 m_model.UpdateReferences( m_model.GetReferenceList() );
456 BOOST_CHECK( m_model.IsCellClear( 0, m_col ) );
457 BOOST_CHECK( !m_model.IsEdited() );
458 Apply();
459 BOOST_CHECK( !m_footprint->GetField( name ) );
460}
461
462
463BOOST_AUTO_TEST_CASE( RevertingVariantRetainsOtherVariantsEdits )
464{
465 m_footprint->SetValue( wxS( "base" ) );
467 m_model.SetCurrentVariant( wxS( "A" ) );
468 m_model.SetValue( 0, m_col, wxS( "A staged" ) );
469 m_model.SetCurrentVariant( wxS( "B" ) );
470 m_model.SetValue( 0, m_col, wxS( "B staged" ) );
471 m_model.RevertRow( 0 );
472 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "base" ) );
473 BOOST_CHECK( m_model.IsEdited() );
474 m_model.SetCurrentVariant( wxS( "A" ) );
475 BOOST_CHECK_EQUAL( m_model.GetValue( 0, m_col ), wxS( "A staged" ) );
476 Apply();
478 m_footprint->GetFieldValueForVariant( wxS( "B" ), GetDefaultFieldName( FIELD_T::VALUE, UNTRANSLATED ) ),
479 wxS( "base" ) );
480}
481
482
483// Repose #2772: display and export must resolve field references before Apply.
484BOOST_AUTO_TEST_CASE( MixedVariablesUseStagedFieldsForDisplayAndExport )
485{
486 m_footprint->SetValue( wxS( "10k" ) );
487 PCB_FIELD* nested = new PCB_FIELD( m_footprint, FIELD_T::USER, wxS( "Nested" ) );
488 nested->SetText( wxS( "Value: ${VALUE}" ) );
489 m_footprint->Add( nested );
490 PCB_FIELD* report = new PCB_FIELD( m_footprint, FIELD_T::USER, wxS( "Report" ) );
491 report->SetText( wxS( "${REFERENCE}: ${Nested} ${NESTED}" ) );
492 m_footprint->Add( report );
494 int valueCol = m_col;
495 AddTestColumn( wxS( "Nested" ) );
496 AddTestColumn( wxS( "Report" ) );
497 m_model.SetCurrentVariant( wxS( "A" ) );
498 m_model.SetValue( 0, valueCol, wxS( "4.7k" ) );
499
500 // User field names remain case-sensitive, unlike the built-in VALUE alias.
501 const wxString expected = wxS( "U1: Value: 4.7k ${NESTED}" );
502 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), expected );
503 BOOST_CHECK( m_model.Export( BOM_FMT_PRESET() ).Contains( expected ) );
504
505 m_model.SetCurrentVariant( wxS( "B" ) );
506 m_model.SetValue( 0, valueCol, wxS( "B staged" ) );
507 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS( "U1: Value: B staged ${NESTED}" ) );
508 m_model.SetCurrentVariant( wxS( "A" ) );
509 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), expected );
510 BOOST_CHECK( m_board.GetCurrentVariant().IsEmpty() );
511 BOOST_CHECK_EQUAL( m_footprint->GetValue(), wxS( "10k" ) );
512}
513
514
515BOOST_AUTO_TEST_CASE( MixedVariablesRespectClearEmptyAndMissingFields )
516{
517 PCB_FIELD* field = new PCB_FIELD( m_footprint, FIELD_T::USER, wxS( "MPN" ) );
518 field->SetText( wxS( "live" ) );
519 m_footprint->Add( field );
520 AddTestColumn( wxS( "MPN" ) );
521 int fieldCol = m_col;
522 AddTestColumn( wxS( "Report" ), true );
523 m_model.SetValue( 0, m_col, wxS( "[${MPN}] ${Unknown}" ) );
524 m_model.ClearCell( 0, fieldCol );
525 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS( "[] ${Unknown}" ) );
526 m_model.SetValue( 0, fieldCol, wxEmptyString );
527 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS( "[] ${Unknown}" ) );
528 m_model.SetValue( 0, fieldCol, wxS( "staged" ) );
529 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS( "[staged] ${Unknown}" ) );
530 m_model.RemoveColumn( fieldCol );
531 int reportCol = m_model.GetFieldNameCol( wxS( "Report" ) );
532 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, reportCol ), wxS( "[] ${Unknown}" ) );
533 BOOST_CHECK_EQUAL( field->GetText(), wxS( "live" ) );
534}
535
536
const char * name
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:236
This is the minimal equivalent to the SCH_REFERENCE so we can provide similar non-null guarantees thr...
void SetFieldValue(const wxString &aFieldName, const wxString &aValue)
Set a field value override for this variant.
Definition footprint.h:274
void SetReference(const wxString &aReference)
Definition footprint.h:915
void SetValue(const wxString &aValue)
Definition footprint.h:938
const wxString & GetValue() const
Definition footprint.h:933
FOOTPRINT_VARIANT * AddVariant(const wxString &aVariantName)
Add a new variant with the given name.
Master controller class:
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
std::vector< FOOTPRINT_REF > FOOTPRINT_REFERENCE_LIST
wxString GetDefaultVariantName()
FOOTPRINT_FIELDS_EDITOR_GRID_DATA_MODEL m_model
void AddTestColumn(const wxString &aFieldName, bool aAddedByUser=false)
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(UntouchedMissingPresetFieldRemainsAbsent)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
KIBIS_MODEL * model
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL(result, "25.4")
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:46
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708