21#include <boost/test/data/test_case.hpp>
52const char*
const ORACLE_FIXTURES[] = {
53 "incremental_test",
"issue10430",
"issue10926_1",
"issue11926",
"issue12505",
"issue12814",
54 "issue13112",
"issue13162",
"issue13212",
"issue13431",
"issue13591",
"issue16223",
"issue6588",
"issue9367"
57const char*
const PARITY_FIXTURES[] = {
58 "incremental_test",
"issue10430",
"issue10926_1",
"issue11926",
"issue12505",
"issue12814",
59 "issue13112",
"issue13162",
"issue13212",
"issue13431",
"issue13591",
"issue16223",
"issue6588",
"issue9367",
60 "issue18346",
"unconnected_bus_entry_qa",
"netlist_exporter_unit_metadata_per_unit",
61 "netlists/multinetclasses/multinetclasses",
"issue22286/bugtest",
"issue7203",
"netlists/jumpers/jumpers",
62 "issue23058/issue23058",
"netlists/bus_junctions/bus_junctions",
63 "netlists/prefix_bus_alias/prefix_bus_alias",
64 "issue9673/issue9673",
"erc_directive_label_not_connected",
"netlists/legacy_power/legacy_power",
65 "same_local_global_power",
"issue1768/issue1768",
"issue18092/issue18092",
"issue22864/Test_Move_Grid",
66 "issue23840/BusAndVectors"
71 if( aExpected == aActual )
81void EraseDrivers( nlohmann::json& aValue )
83 if( aValue.is_object() )
85 aValue.erase(
"driver" );
86 aValue.erase(
"driver_path" );
89 if( aValue.is_structured() )
91 for(
auto& child : aValue )
92 EraseDrivers( child );
110 auto& facade = schematic->Connectivity();
111 facade.Update( *schematic );
114 auto classes = schematic->Project().GetProjectFile().NetSettings();
115 classes->SetNetclassLabelAssignment(
"/NET_1", {
"CORRUPTED" } );
116 classes->ClearCacheForNet(
"/NET_1" );
124 LegacyAndEngineDumpsMatch,
125 boost::unit_test::data::make( PARITY_FIXTURES ), fixture )
133 auto& facade = schematic->Connectivity();
134 facade.Update( *schematic );
137 EraseDrivers( legacy );
138 EraseDrivers( engine );
139 BOOST_CHECK_MESSAGE( legacy == engine, nlohmann::json::diff( legacy, engine ).
dump( 2 ) );
146 using KEY = std::pair<std::string, std::string>;
148 auto& facade = schematic->Connectivity();
149 facade.Update( *schematic );
150 const auto& keys = facade.Keys();
153 std::map<KEY, std::set<KEY>> legacyBuses;
154 std::map<int, std::set<KEY>> legacyNets;
155 std::map<KEY, const nlohmann::json*> shadowRows;
157 for(
const auto& row : shadow )
158 shadowRows.emplace( KEY{ row.at(
"path" ), row.at(
"item" ) }, &row );
160 for(
const auto& row : legacy )
162 const KEY key{ row.at(
"path" ), row.at(
"item" ) };
163 const auto path = schematic->Hierarchy().GetSheetPathByKIIDPath(
164 KIID_PATH( wxString::FromUTF8( key.first ) ) );
166 const auto* item =
path->LastScreen()->GetConnectivityItem(
KIID( key.second ) );
168 const auto* connection = item->Connection( &*
path );
170 if( !connection || !connection->Driver() )
173 if( connection->IsBus() )
174 legacyBuses[KEY{ row.at(
"driver_path" ), row.at(
"driver" ) }].insert( key );
175 else if( connection->IsNet() )
177 BOOST_REQUIRE_GT( connection->NetCode(), 0 );
178 legacyNets[connection->NetCode()].insert( key );
179 const auto after = shadowRows.find( key );
181 BOOST_CHECK( row.at(
"name" ) == after->second->at(
"name" ) );
182 BOOST_CHECK( row.at(
"type" ) == after->second->at(
"type" ) );
186 const auto itemKeys = [&](
const auto& items )
191 result.emplace( keys.Instance( item.inst ).AsString().ToStdString(),
192 item.item.AsString().ToStdString() );
196 const auto checkFields = [](
const auto& before,
const auto& after )
198 for(
const char* field : {
"name",
"local_name",
"type",
"netclasses" } )
199 BOOST_CHECK_MESSAGE( before.at( field ) == after.at( field ), field );
201 const auto checkMembers = [&](
const auto& self,
const auto& before,
const auto& after ) ->
void
205 for(
size_t i = 0; i < before.size(); ++i )
207 checkFields( before[i], after[i] );
208 self( self, before[i].at(
"members" ), after[i].at(
"members" ) );
212 for(
const char*
name : {
"/{FOO BAR HAM EGGS}",
"/{MIXED_BUS}",
"/A[0..4]",
"/D[0..7]" } )
214 const auto row = std::find_if( legacy.begin(), legacy.end(),
215 [&](
const auto& value ) { return value.at(
"name" ) == name; } );
217 const auto path = schematic->Hierarchy().GetSheetPathByKIIDPath(
218 KIID_PATH( wxString::FromUTF8( row->at(
"path" ).get<std::string>() ) ) );
220 const KIID itemId( row->at(
"item" ).get<std::string>() );
221 const auto instance = keys.FindInstance(
path->Path() );
225 const auto result = facade.Published().Rows().find(
ITEM_KEY{ itemId, *instance } );
227 const auto& component = facade.Published().Components().at(
result->second.component );
229 const auto actual = itemKeys( component.content->items );
230 const auto& expectedItems = legacyBuses.at( KEY{ row->at(
"driver_path" ), row->at(
"driver" ) } );
231 BOOST_CHECK_MESSAGE(
actual == expectedItems, nlohmann::json(
actual ).
dump()
232 <<
" expected " << nlohmann::json( expectedItems ).
dump() );
235 for(
const auto& before : legacy )
237 const KEY key{ before.at(
"path" ), before.at(
"item" ) };
239 if( !expectedItems.contains( key ) )
242 const auto after = shadowRows.find( key );
245 checkFields( before, *after->second );
246 checkMembers( checkMembers, before.at(
"members" ), after->second->at(
"members" ) );
251 for(
const auto& [code, items] : legacyNets )
253 const KEY& first = *items.begin();
254 const auto instance = keys.FindInstance(
KIID_PATH( wxString::FromUTF8( first.first ) ) );
258 const auto row = facade.Published().Rows().find(
ITEM_KEY{
KIID( first.second ), *instance } );
260 const auto& component = facade.Published().Components().at( row->second.component );
261 BOOST_CHECK( itemKeys( component.content->items ) == items );
265 BOOST_CHECK_GT( legacyNets.size(), 0u );
271 using KEY = std::pair<std::string, std::string>;
273 for(
const char* fixture : {
"netlists/hierarchy_aliases/hierarchy_aliases",
274 "netlists/multinetclasses/multinetclasses" } )
279 auto& facade = schematic->Connectivity();
280 facade.Update( *schematic );
281 const auto& keys = facade.Keys();
286 for(
size_t i = 0; i < legacy.size(); ++i )
288 BOOST_REQUIRE( legacy[i].at(
"path" ) == shadow[i].at(
"path" ) );
289 BOOST_REQUIRE( legacy[i].at(
"item" ) == shadow[i].at(
"item" ) );
292 const auto paths = schematic->Hierarchy();
293 std::map<int, std::set<KEY>> nets;
294 std::map<int, std::string> names;
296 for(
const auto& row : legacy )
298 const KEY key{ row.at(
"path" ), row.at(
"item" ) };
299 const auto path = paths.GetSheetPathByKIIDPath(
KIID_PATH( wxString::FromUTF8( key.first ) ) );
301 const auto* item =
path->LastScreen()->GetConnectivityItem(
KIID( key.second ) );
303 const auto* connection = item->Connection( &*
path );
305 if( connection && connection->IsNet() && connection->Driver() )
307 BOOST_REQUIRE_GT( connection->NetCode(), 0 );
308 nets[connection->NetCode()].insert( key );
309 names[connection->NetCode()] = connection->Name().ToStdString( wxConvUTF8 );
313 for(
const auto& [code, items] : nets )
315 const auto& first = *items.begin();
316 const auto instance = keys.FindInstance(
KIID_PATH( wxString::FromUTF8( first.first ) ) );
318 const auto row = facade.Published().Rows().find(
ITEM_KEY{
KIID( first.second ), *instance } );
320 const auto& component = facade.Published().Components().at( row->second.component );
323 for(
const ITEM_KEY& item : component.content->items )
324 actual.emplace( keys.Instance( item.
inst ).AsString().ToStdString(),
327 BOOST_CHECK_MESSAGE(
actual == items,
"Net code " << code );
329 BOOST_CHECK_EQUAL( keys.Name( component.name ).ToStdString( wxConvUTF8 ), names.at( code ) );
340 for(
bool engine : {
false,
true } )
344 config.m_ConnectivityEngine = engine;
346 schematic->RebuildConnectivity();
347 SCH_SCREEN* screen = schematic->GetCurrentScreen();
348 const KIID junction(
"2934c2df-d750-4949-9bb5-2d5234f61386" );
349 auto* wire =
dynamic_cast<SCH_LINE*
>(
351 auto* upper =
dynamic_cast<SCH_LINE*
>(
353 auto* lower =
dynamic_cast<SCH_LINE*
>(
359 BOOST_REQUIRE( wire->IsEndPoint( position ) && upper->IsEndPoint( position )
360 && lower->IsEndPoint( position ) );
362 const std::set<int> directions{ wire->GetAngleFrom( position ), upper->GetAngleFrom( position ),
363 lower->GetAngleFrom( position ) };
365 const VECTOR2I start = upper->GetStartPoint();
368 auto subscription = schematic->Connectivity().Subscribe(
375 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
377 schematic->CleanUp( &
move, screen );
381 move.Modify( wire, screen );
382 wire->Move(
VECTOR2I( 10000000, 10000000 ) );
384 BOOST_REQUIRE( upper->IsEndPoint( position ) && lower->IsEndPoint( position ) );
385 BOOST_REQUIRE_NE( upper->GetAngleFrom( position ), lower->GetAngleFrom( position ) );
396 if(
auto* line =
dynamic_cast<SCH_LINE*
>( item );
397 line && line->
IsEndPoint( start ) && line->IsEndPoint(
end ) )
402 const auto dump = [&]()
407 const std::string incremental =
dump();
408 schematic->RebuildConnectivity();
416 PreviouslyDisabledFixturesMatchFullAndFreshRebuildsAfterCommits,
417 boost::unit_test::data::make( ORACLE_FIXTURES ), fixture )
422 config.m_ConnectivityEngine =
true;
423 config.m_IncrementalConnectivity =
true;
427 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
431 schematic->RebuildConnectivity();
453 std::set<SCH_SCREEN*> seenScreens;
455 const auto isGeometry =
458 return item->IsConnectable()
464 std::vector<std::pair<SCH_SCREEN*, std::unique_ptr<SCH_ITEM>>> geometry;
468 if( !seenScreens.insert(
path.LastScreen() ).second )
473 if( isGeometry( item ) )
476 geometry.emplace_back(
path.LastScreen(),
static_cast<SCH_ITEM*
>( item->Clone() ) );
481 std::sort( geometry.begin(), geometry.end(),
482 [](
const auto& a,
const auto& b )
484 return a.second->m_Uuid < b.second->m_Uuid;
487 const VECTOR2I offset( 10000000, 10000000 );
489 rebuilt.
Update( *schematic,
true );
496 for(
SCH_ITEM* item : screen->Items() )
499 "Cleanup left a deleted item on the screen: "
500 << item->m_Uuid.AsString().ToStdString() );
505 rebuilt.
Update( *schematic,
true );
509 fresh.
Update( *schematic,
true );
511 std::map<int, int> toFresh;
512 std::map<int, int> fromFresh;
513 const auto& current = schematic->Connectivity();
515 for(
const auto& [key, row] : current.Published().Rows() )
517 const auto&
path = current.Keys().Instance( key.inst );
518 const auto actual = current.Connection( key.item,
path );
524 const auto forward = toFresh.emplace(
actual->NetCode(),
empty->NetCode() ).first;
525 const auto reverse = fromFresh.emplace(
empty->NetCode(),
actual->NetCode() ).first;
533 const auto restoreGeometry =
539 std::vector<SCH_ITEM*> removed;
540 std::vector<std::pair<SCH_SCREEN*, std::unique_ptr<SCH_ITEM>>> added;
544 for(
SCH_ITEM* item : screen->Items() )
546 if( isGeometry( item ) )
548 restore.
Remove( item, screen );
549 removed.push_back( item );
554 for(
const auto& [screen,
source] : geometry )
558 restore.
Add(
copy.get(), screen );
559 added.emplace_back( screen, std::move(
copy ) );
564 for(
auto& [screen, item] : added )
577 rebuilt.
Update( *schematic,
true );
584 commit.
Modify( symbol, screen );
585 symbol->
Move( movement );
587 BOOST_CHECK( !schematic->Connectivity().Published().Changes().Empty() );
594 auto symbolReplacement = std::make_unique<SCH_SYMBOL>( *symbol );
596 removal.
Remove( symbol, symbolScreen );
604 addition.
Add( symbolReplacement.get(), symbolScreen );
607 symbolReplacement.release();
611 std::vector<SCH_LABEL_BASE*> labels;
615 for(
SCH_ITEM* item : screen->Items() )
622 std::sort( labels.begin(), labels.end(),
623 [](
const auto* a,
const auto* b )
625 return a->m_Uuid < b->m_Uuid;
630 const wxString originalText = label->GetText();
632 for(
const wxString&
text : { wxString(
"ORACLE_" ) + originalText, originalText } )
635 rename.
Modify( label, label->GetParentScreen() );
636 label->SetText(
text );
642 for(
const auto& [screen,
source] : geometry )
648 SCH_ITEM* item = screen->GetConnectivityItem(
id );
653 move.Modify( item, screen );
654 item->
Move( offset );
657 BOOST_CHECK( !schematic->Connectivity().Published().Changes().Empty() );
661 item = screen->GetConnectivityItem(
id );
664 removal.
Remove( item, screen );
677 BOOST_TEST_MESSAGE( fixture <<
": checked " << labels.size() <<
" native label renames and restores, and "
678 << geometry.size() <<
" native geometry move/remove/restore sequences" );
680 CheckRows( original, incremental );
681 schematic->RebuildConnectivity();
687 boost::unit_test::data::make( {
"issue7203",
"netlists/hierarchy_aliases/hierarchy_aliases" } ),
691 const auto hierarchy = schematic->Hierarchy();
692 SCH_SCREEN* screen = hierarchy.front().LastScreen();
694 for(
const auto&
path : hierarchy )
698 const auto instances = std::ranges::count_if( hierarchy, [&](
const auto& other )
700 return other.LastScreen() == candidate;
703 if( instances > 1 && labels.begin() != labels.end() )
707 std::vector<SCH_SHEET_PATH> affected;
709 for(
const auto&
path : hierarchy )
711 if(
path.LastScreen() == screen )
712 affected.push_back(
path );
716 std::vector<SCH_ITEM*> sources;
719 sources.push_back( item );
724 incremental.
Update( *schematic );
729 std::vector<std::unique_ptr<SCH_ITEM>> items;
733 for(
const auto& item : items )
736 screen->
Remove( item.get(),
false );
739 } batch{ screen, {} };
740 batch.items.reserve( 500 );
742 for(
size_t i = 0; i < 500; ++i )
744 std::unique_ptr<SCH_ITEM>
copy( sources[i % sources.size()]->Duplicate(
false ) );
745 copy->SetParentGroup(
nullptr );
746 batch.items.push_back( std::move(
copy ) );
751 for(
int cycle = 0; cycle < 2; ++cycle )
753 for(
const auto& item : batch.items )
754 screen->
Append( item.get(),
false );
756 incremental.Update( *schematic );
758 for(
const auto&
path : affected )
760 for(
const auto& item : batch.items )
765 BOOST_CHECK_NE( edited, baseline );
766 rebuilt.
Update( *schematic,
true );
769 for(
const auto& item : batch.items )
772 incremental.Update( *schematic );
775 for(
const auto&
path : affected )
777 for(
const auto& item : batch.items )
781 rebuilt.
Update( *schematic,
true );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
virtual VECTOR2I GetPosition() const
virtual EDA_GROUP * GetParentGroup() const
EE_TYPE OfType(KICAD_T aType) const
wxString AsString() const
Commit for the schematic and symbol editors.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Model-owned source resolver.
void Update(SCHEMATIC &aSchematic, bool aRebuild=false)
std::optional< ITEM_VIEW > Connection(const KIID &aItem, const KIID_PATH &aPath) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_SCREEN * GetParentScreen() const
virtual void Move(const VECTOR2I &aMoveVector)
Move the item by aMoveVector to a new position.
Segment description base class to describe items which have 2 end points (track, wire,...
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
std::vector< SCH_LINE * > GetBusesAndWires(const VECTOR2I &aPosition, bool aIgnoreEndpoints=false) const
Return buses and wires passing through aPosition.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
SCH_ITEM * GetConnectivityItem(const KIID &aId) const
Resolve a drawing item or a connectable child on this screen; ambiguous IDs return null.
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool IsPower() const override
RAII class that sets an value at construction and resets it to the original value at destruction.
static bool empty(const wxTextEntryBase *aCtrl)
static std::string ToStdString(const wxString &aStr)
#define STRUCT_DELETED
flag indication structures to be erased
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
Value keys and the key session of the schematic connectivity engine.
std::map< std::pair< KIID_PATH, KIID >, DUMP_ROW > DUMP_ROWS
Rows by sheet path and item.
DUMP_ROWS CaptureRows(SCHEMATIC &aSchematic)
Canonical, pointer-free connectivity rows for migration and rebuild comparisons.
constexpr uint32_t INVALID_ID
Marks an unset handle.
std::string Dump(const DUMP_ROWS &aRows)
#define SKIP_CONNECTIVITY
#define DELETE_REMOVED_ITEMS
SETTINGS_MANAGER settings
std::unique_ptr< SCHEMATIC > schematic
Difference between two publications.
One item or pin in one sheet instance.
KIID item
The item or pin KIID.
INST_ID inst
The sheet instance that shows the item.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(ShadowDumpResolvesClassesWithoutLegacyAssignments)
BOOST_DATA_TEST_CASE_F(CONNECTIVITY_DUMP_FIXTURE, LegacyAndEngineDumpsMatch, boost::unit_test::data::make(PARITY_FIXTURES), fixture)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
VECTOR2< int32_t > VECTOR2I