51using NET_NAMES = std::map<std::pair<std::string, std::string>, std::string>;
54void EraseDrivers( nlohmann::json& aValue )
56 if( aValue.is_object() )
58 aValue.erase(
"driver" );
59 aValue.erase(
"driver_path" );
62 if( aValue.is_structured() )
64 for(
auto& child : aValue )
65 EraseDrivers( child );
69std::string UserVisible(
const std::string& aDump )
71 auto rows = nlohmann::json::parse( aDump );
73 return rows.dump( 2 );
76std::string CommittedDump(
SCHEMATIC& aSchematic )
84std::string RebuiltDump(
SCHEMATIC& aSchematic )
87 full.
Update( aSchematic,
true );
91NET_NAMES NetNames(
const std::string& aDump )
95 for(
const auto& row : nlohmann::json::parse( aDump ) )
97 result.emplace( std::pair{ row.at(
"path" ).get<std::string>(), row.at(
"item" ).get<std::string>() },
98 row.at(
"name" ).get<std::string>() );
104std::string NetName(
const NET_NAMES& aNames,
const KIID_PATH& aPath,
const KIID& aItem )
106 const auto found = aNames.find( { aPath.
AsString().ToStdString( wxConvUTF8 ),
107 aItem.
AsString().ToStdString( wxConvUTF8 ) } );
108 BOOST_REQUIRE_MESSAGE( found != aNames.end(),
110 return found->second;
122 for(
bool enabled : {
false,
true } )
126 config.m_ConnectivityEngine = enabled;
128 std::unique_ptr<SCHEMATIC> schematic;
130 const auto hierarchy = schematic->Hierarchy();
131 BOOST_REQUIRE_EQUAL( hierarchy.size(), 4u );
132 std::vector<SCH_SHEET_PATH> children;
136 if(
path.size() == 2 )
137 children.push_back(
path );
140 BOOST_REQUIRE_EQUAL( children.size(), 3u );
141 std::sort( children.begin(), children.end(), [](
const auto& lhs,
const auto& rhs )
143 return lhs.Last()->GetName() < rhs.Last()->GetName();
145 SCH_SCREEN* screen = children.front().LastScreen();
151 bridge =
static_cast<SCH_LINE*
>( item );
158 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
159 schematic->SetCurrentSheet( children.front() );
160 schematic->RecalculateConnections(
nullptr,
GLOBAL_CLEANUP, &manager );
162 const KIID_PATH root = hierarchy.front().Path();
163 const auto check = [&](
bool joined )
165 const std::string committed = CommittedDump( *schematic );
166 const NET_NAMES names = NetNames( committed );
167 std::array<std::string, 6> parentNets;
174 BOOST_REQUIRE_EQUAL(
path.Last()->GetPins().size(), 2u );
175 std::set<wxString> texts;
179 BOOST_REQUIRE(
pin->GetText() == wxString(
"in" ) ||
pin->GetText() == wxString(
"out" ) );
181 const bool input =
pin->GetText() == wxString(
"in" );
182 const KIID child( input ?
"fbac9619-48e4-4bb4-ae58-b737c341dfb7"
183 :
"6b540c7f-cd51-4ae0-9753-e62094939d20" );
184 const std::string parentNet = NetName( names, root,
pin->m_Uuid );
185 BOOST_CHECK( !parentNet.empty() );
187 parentNets[2 *
index + !input] = parentNet;
191 for(
size_t first = 0; first < parentNets.size(); ++first )
193 for(
size_t second = first + 1; second < parentNets.size(); ++second )
195 const bool parentBridge = ( first == 1 && second == 2 ) || ( first == 3 && second == 4 );
196 BOOST_CHECK_EQUAL( parentNets[first] == parentNets[second], joined || parentBridge );
203 const std::string baseline = check(
true );
207 commit.
Modify( bridge, screen );
212 BOOST_CHECK( check(
false ) != baseline );
226 for(
bool enabled : {
false,
true } )
230 config.m_ConnectivityEngine = enabled;
232 std::unique_ptr<SCHEMATIC> schematic;
234 auto hierarchy = schematic->Hierarchy();
235 BOOST_REQUIRE_EQUAL( hierarchy.size(), 3u );
236 std::sort( hierarchy.begin(), hierarchy.end(), [](
const auto& lhs,
const auto& rhs )
238 return lhs.size() != rhs.size() ? lhs.size() < rhs.size()
239 : lhs.Last()->GetName() < rhs.Last()->GetName();
241 BOOST_REQUIRE_EQUAL( hierarchy[0].size(), 1u );
242 BOOST_REQUIRE_EQUAL( hierarchy[1].size(), 2u );
243 BOOST_REQUIRE_EQUAL( hierarchy[2].size(), 2u );
244 BOOST_REQUIRE_EQUAL( hierarchy[1].Last()->GetName(), wxString(
"subsheet1" ) );
245 BOOST_REQUIRE_EQUAL( hierarchy[2].Last()->GetName(), wxString(
"subsheet2" ) );
246 SCH_SCREEN* screen = hierarchy[1].LastScreen();
249 BOOST_REQUIRE( hierarchy[0].LastScreen() != hierarchy[2].LastScreen() );
254 if( item->m_Uuid ==
KIID(
"7e736d0c-601c-4f96-b4d2-138dfebf5932" ) )
255 bridge =
static_cast<SCH_LINE*
>( item );
261 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
262 schematic->SetCurrentSheet( hierarchy[1] );
263 schematic->RecalculateConnections(
nullptr,
GLOBAL_CLEANUP, &manager );
265 const KIID_PATH root = hierarchy[0].Path();
266 const KIID_PATH source = hierarchy[1].Path();
267 const KIID_PATH sibling = hierarchy[2].Path();
268 const std::vector<std::pair<KIID_PATH, KIID>> recipients{
269 { source,
KIID(
"24390c04-0f13-48b6-ae5a-ba48240c3289" ) },
270 { root,
KIID(
"2c0a5cdb-9772-4ba5-a787-71f4817b1e17" ) },
271 { root,
KIID(
"c87e9573-e811-44b1-99a7-05b54a8ac7d3" ) },
272 { root,
KIID(
"7ea56b40-7e69-4f46-899d-916eb5319378" ) },
273 { sibling,
KIID(
"837954e7-e02c-47dc-b569-f7787b8dce47" ) },
274 { sibling,
KIID(
"59996eb8-69ab-4ef2-9ed0-6da263326213" ) },
275 { sibling,
KIID(
"c836a852-d408-4f5b-9d40-88c91302bb01" ) },
276 { sibling,
KIID(
"6e69c8b0-e3b4-4882-ae1e-33126ecb39b0" ) }
278 const auto check = [&](
bool joined )
280 const std::string committed = CommittedDump( *schematic );
281 const NET_NAMES names = NetNames( committed );
282 const std::string
expected = joined ?
"GPIO1_14__46" :
"REG_ENABLE";
286 for(
const auto& [
path, item] : recipients )
292 const std::string baseline = check(
true );
296 commit.
Modify( bridge, screen );
301 BOOST_CHECK( check(
false ) != baseline );
315 for(
bool enabled : {
false,
true } )
319 config.m_ConnectivityEngine = enabled;
321 std::unique_ptr<SCHEMATIC> schematic;
328 std::vector<SCH_ITEM*> netItems;
330 for(
const char* uuid : {
"47160e4c-50a1-41c1-9f26-94bda63350fa",
"f1308710-8c5c-4584-a706-b3735972840b",
331 "20fe2096-2c56-4c5a-be18-dd8ed4e8c24b",
"8598689f-ce4f-414f-a720-b8fa4ecb6b41",
332 "17b6ce67-6699-41d5-a096-6714796adaa3" } )
336 netItems.push_back( item );
340 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
341 schematic->SetCurrentSheet(
path );
342 schematic->RecalculateConnections(
nullptr,
GLOBAL_CLEANUP, &manager );
343 auto netSettings = schematic->Project().GetProjectFile().NetSettings();
344 const auto originalAssignments = netSettings->GetNetclassLabelAssignments();
345 auto movedAssignments = originalAssignments;
346 BOOST_REQUIRE_EQUAL( movedAssignments.at( wxString(
"/NET_3" ) ).erase( wxString(
"CLASS3" ) ), 1u );
347 BOOST_REQUIRE_EQUAL( movedAssignments.at( wxString(
"/NET_3" ) ).erase( wxString(
"CLASS4" ) ), 1u );
348 BOOST_REQUIRE( movedAssignments.at( wxString(
"/NET_3" ) ).contains( wxString(
"CLASS_COMPLETE" ) ) );
349 const auto move = [&](
const VECTOR2I& offset,
const auto& assignments )
355 commit.
Modify( item, screen );
356 item->Move( offset );
360 BOOST_CHECK( stationaryArea->
GetPosition() == areaPosition );
361 BOOST_CHECK( netSettings->GetNetclassLabelAssignments() == assignments );
363 full.
Update( *schematic,
true );
367 BOOST_CHECK( netSettings->GetNetclassLabelAssignments() == assignments );
382 for(
bool enabled : {
false,
true } )
386 config.m_ConnectivityEngine = enabled;
388 std::unique_ptr<SCHEMATIC> schematic;
400 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
401 schematic->SetCurrentSheet(
path );
402 schematic->RecalculateConnections(
nullptr,
GLOBAL_CLEANUP, &manager );
403 const NET_NAMES names = NetNames( CommittedDump( *schematic ) );
404 const wxString sourceName = wxString::FromUTF8( NetName( names,
path.Path(), directive->
m_Uuid ) );
405 const wxString targetName = wxString::FromUTF8( NetName( names,
path.Path(), target->
m_Uuid ) );
409 auto netSettings = schematic->Project().GetProjectFile().NetSettings();
410 const auto originalAssignments = netSettings->GetNetclassLabelAssignments();
411 BOOST_REQUIRE( originalAssignments.at( sourceName ).contains( wxString(
"CLASS_COMPLETE" ) ) );
412 BOOST_REQUIRE( !originalAssignments.at( targetName ).contains( wxString(
"CLASS_COMPLETE" ) ) );
413 auto movedAssignments = originalAssignments;
414 movedAssignments.at( sourceName ).erase( wxString(
"CLASS_COMPLETE" ) );
415 movedAssignments.at( targetName ).insert( wxString(
"CLASS_COMPLETE" ) );
419 commit.
Modify( directive, screen );
422 BOOST_CHECK( netSettings->GetNetclassLabelAssignments() ==
expected );
426 move( original, originalAssignments );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
virtual VECTOR2I GetPosition() const
virtual void SetPosition(const VECTOR2I &aPos)
KICAD_T Type() const
Returns the type of object.
EE_TYPE OfType(KICAD_T aType) const
wxString AsString() const
wxString AsString() const
Holds all the data relating to one schematic.
SCH_CONNECTIVITY::FACADE & Connectivity() const
Commit for the schematic and symbol editors.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Model-owned source resolver.
void Update(SCHEMATIC &aSchematic, bool aRebuild=false)
void ApplyNetclasses(NET_SETTINGS &aSettings) const
Replace label-derived assignments from a complete publication; invalidate changed net caches.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Segment description base class to describe items which have 2 end points (track, wire,...
bool IsWire() const
Return true if the line is a wire.
VECTOR2I GetEndPoint() const
void SetEndPoint(const VECTOR2I &aPosition)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
SCH_ITEM * GetConnectivityItem(const KIID &aId) const
Resolve a drawing item or a connectable child on this screen; ambiguous IDs return null.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
RAII class that sets an value at construction and resets it to the original value at destruction.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::string Dump(SCHEMATIC &aSchematic)
Canonical, pointer-free connectivity rows for migration and rebuild comparisons.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(NativeThreeInstancesPropagateChildShortAndRestore)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I