51 + wxS(
"issue25112/issue25112.kicad_sch" );
65 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
MakeScopedModel(
const wxString& aVariantName,
66 const wxString& aFieldName,
67 bool aAddedByUser =
false )
69 auto model = std::make_unique<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>(
m_refs );
71 model->SetCurrentVariant( aVariantName );
73 model->AddColumn( aFieldName, aFieldName, aAddedByUser );
77 model->SetShowColumn( referenceCol,
true );
86 for(
size_t ii = 0; ii < modelRefs.
GetCount() && !found; ++ii )
88 for(
size_t jj = ii + 1; jj < modelRefs.
GetCount(); ++jj )
90 if( modelRefs[jj].GetSymbol() == modelRefs[ii].GetSymbol() )
92 m_symbol = modelRefs[ii].GetSymbol();
104 model->SetScope( SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE::SCOPE_SHEET );
105 model->RebuildRows();
109 for(
int ii = 0; ii <
model->GetNumberRows() &&
m_row < 0; ++ii )
125 BOOST_REQUIRE_EQUAL(
model->GetRowReferences(
m_row ).size(), 1u );
136 aModel.
ApplyData( commit, templates, aVariantName );
152 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
155 const wxString newFootprint = wxS(
"Resistor_SMD:R_0603_1608Metric" );
157 model->SetValue( m_row, m_col, newFootprint );
158 Apply( *
model, wxEmptyString );
166 const wxString fieldName = wxS(
"MPN" );
167 const wxString fieldValue = wxS(
"ABC123" );
169 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model = MakeScopedModel( wxEmptyString, fieldName );
173 m_symbol->AddField( field );
174 model->UpdateReferences( m_refs );
178 model->ClearCell( m_row, m_col );
181 model->RevertRow( m_row );
182 BOOST_CHECK( !
model->IsCellClear( m_row, m_col ) );
183 BOOST_CHECK( !
model->IsEdited() );
185 Apply( *
model, wxEmptyString );
187 const SCH_FIELD* appliedField = m_symbol->GetField( fieldName );
195 const wxString fieldName = wxS(
"GroupedState" );
196 const wxString fieldValue = wxS(
"Original" );
197 std::set<SCH_SYMBOL*> symbols;
203 if( !symbols.insert( symbol ).second )
213 model.AddColumn( fieldName, fieldName,
false );
216 int fieldCol =
model.GetFieldNameCol( fieldName );
220 model.SetShowColumn( referenceCol,
true );
221 model.SetShowColumn( fieldCol,
true );
222 model.SetGroupingEnabled(
true );
223 model.SetGroupColumn( fieldCol,
true );
229 for(
int row = 0; row <
model.GetNumberRows() && groupedRow < 0; ++row )
231 const std::vector<SCH_REFERENCE> refs =
model.GetRowReferences( row );
233 for(
size_t ii = 1; ii < refs.size(); ++ii )
235 if( refs[ii].GetSymbol() != refs[0].GetSymbol() )
238 symbolToModify = refs[ii].GetSymbol();
250 BOOST_CHECK( !
model.IsCellEdited( groupedRow, referenceCol ) );
251 BOOST_CHECK(
model.IsCellEdited( groupedRow, fieldCol ) );
252 BOOST_CHECK(
model.IsRowEdited( groupedRow ) );
260 const wxString variant = wxS(
"Assembly" );
262 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
266 const wxString newFootprint = wxS(
"Resistor_SMD:R_0603_1608Metric" );
270 model->SetValue( m_row, m_col, newFootprint );
271 Apply( *
model, variant );
283 const wxString variant = wxS(
"Assembly" );
285 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
286 MakeScopedModel( variant, wxS(
"${EXCLUDE_FROM_BOARD}" ) );
290 model->SetValue( m_row, m_col, wxS(
"1" ) );
291 Apply( *
model, variant );
293 BOOST_CHECK( m_symbol->GetExcludedFromBoard() );
299 const wxString fieldName = wxS(
"UninstantiatedPresetField" );
301 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
302 MakeScopedModel( wxEmptyString, fieldName );
306 Apply( *
model, wxEmptyString );
308 BOOST_CHECK( m_symbol->GetField( fieldName ) ==
nullptr );
314 const wxString fieldName = wxS(
"ExplicitlyEmptyField" );
316 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
317 MakeScopedModel( wxEmptyString, fieldName );
321 model->SetValue( m_row, m_col, wxEmptyString );
326 Apply( *
model, wxEmptyString );
328 const SCH_FIELD* field = m_symbol->GetField( fieldName );
330 BOOST_CHECK( field->
GetText().IsEmpty() );
336 const wxString fieldName = wxS(
"ExistingEmptyField" );
338 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
339 MakeScopedModel( wxEmptyString, fieldName );
342 model->UpdateReferences( m_refs );
347 model->ClearCell( m_row, m_col );
352 Apply( *
model, wxEmptyString );
354 BOOST_CHECK( m_symbol->GetField( fieldName ) ==
nullptr );
360 const wxString fieldName = wxS(
"UserAddedEmptyField" );
362 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
363 MakeScopedModel( wxEmptyString, fieldName,
true );
368 Apply( *
model, wxEmptyString );
370 const SCH_FIELD* field = m_symbol->GetField( fieldName );
372 BOOST_CHECK( field->
GetText().IsEmpty() );
378 const wxString fieldName = wxS(
"RevertedVariantField" );
380 std::unique_ptr<SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL>
model =
381 MakeScopedModel( wxS(
"Assembly" ), fieldName );
383 model->SetValue( m_row, m_col, wxEmptyString );
386 model->RevertRow( m_row );
391 Apply( *
model, wxS(
"Assembly" ) );
393 BOOST_CHECK( m_symbol->GetField( fieldName ) ==
nullptr );
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetText(const wxString &aText) override
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void ApplyData(SCH_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames, const wxString &aVariantName)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
SCH_SHEET_PATH m_scopePath
SCH_REFERENCE_LIST m_refs
std::unique_ptr< SCHEMATIC > m_schematic
std::unique_ptr< SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL > MakeScopedModel(const wxString &aVariantName, const wxString &aFieldName, bool aAddedByUser=false)
Build a model scoped to the first sheet path of a symbol that a later path also reaches.
void Apply(SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL &aModel, const wxString &aVariantName)
SCH_SHEET_PATH m_siblingPath
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.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(SheetScopedFieldEditSurvivesApply, ISSUE25112_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")