33#include <boost/test/unit_test.hpp>
46#include <wx/filename.h>
47#include <wx/stdpaths.h>
55 wxString tempDir = wxStandardPaths::Get().GetTempDir();
56 wxString projectPath = tempDir + wxFileName::GetPathSeparator()
57 + wxT(
"test_design_block.kicad_pro" );
61 m_schematic = std::make_unique<SCHEMATIC>(
nullptr );
70 if( wxFileExists( file ) )
79 wxString tempDir = wxStandardPaths::Get().GetTempDir();
80 wxString fileName = wxFileName::CreateTempFileName(
81 tempDir + wxFileName::GetPathSeparator() + aPrefix );
99 aScreen->
Append( junction );
103 group->SetName(
"DesignBlock" );
104 group->AddItem( wire );
105 group->AddItem( junction );
129 m_schematic->CreateDefaultScreens();
131 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
134 SCH_SCREEN* screen = topSheets[0]->GetScreen();
137 screen->
SetFileName(
"test_design_block.kicad_sch" );
141 CreateDesignBlockContent( screen, &group1,
VECTOR2I( 0, 0 ) );
145 size_t group1MemberCount = group1->
GetItems().size();
150 CreateDesignBlockContent( screen, &group2,
VECTOR2I( 5000000, 0 ) );
154 size_t group2MemberCount = group2->
GetItems().size();
158 BOOST_CHECK( group1Uuid != group2Uuid );
161 int groupCountBefore = 0;
168 <<
" UUID: " <<
group->m_Uuid.AsString().ToStdString()
169 <<
" Members: " <<
group->GetItems().size() );
175 wxString fileName = GetTempFileName(
"test_design_block" );
176 fileName +=
".kicad_sch";
177 m_tempFiles.push_back( fileName );
180 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( fileName, topSheets[0], m_schematic.get() ) );
181 BOOST_CHECK( wxFileExists( fileName ) );
184 m_schematic->Reset();
185 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
188 BOOST_CHECK_NO_THROW( loadedSheet = io.
LoadSchematicFile( fileName, m_schematic.get() ) );
191 m_schematic->AddTopLevelSheet( loadedSheet );
192 m_schematic->RemoveTopLevelSheet( defaultSheet );
199 int groupCountAfter = 0;
200 int totalMembersAfter = 0;
208 <<
" UUID: " <<
group->m_Uuid.AsString().ToStdString()
209 <<
" Members: " <<
group->GetItems().size() );
213 totalMembersAfter +=
group->GetItems().size();
222 if( screenItem == member )
229 BOOST_CHECK_MESSAGE( found,
"Group member should exist on screen" );
248 m_schematic->CreateDefaultScreens();
250 std::vector<SCH_SHEET*> topSheets = m_schematic->GetTopLevelSheets();
253 SCH_SCREEN* mainScreen = topSheets[0]->GetScreen();
255 mainScreen->
SetFileName(
"test_duplicate_uuid.kicad_sch" );
265 KIID wireUuid1(
"11111111-1111-1111-1111-111111111111" );
266 KIID junctionUuid1(
"22222222-2222-2222-2222-222222222222" );
267 KIID groupUuid1(
"33333333-3333-3333-3333-333333333333" );
272 const_cast<KIID&
>( wire1->
m_Uuid ) = wireUuid1;
273 mainScreen->
Append( wire1 );
276 const_cast<KIID&
>( junction1->
m_Uuid ) = junctionUuid1;
277 mainScreen->
Append( junction1 );
280 group1->
SetName(
"DesignBlock" );
281 const_cast<KIID&
>( group1->
m_Uuid ) = groupUuid1;
284 mainScreen->
Append( group1 );
290 const_cast<KIID&
>( wire2->
m_Uuid ) = wireUuid1;
291 mainScreen->
Append( wire2 );
294 const_cast<KIID&
>( junction2->
m_Uuid ) = junctionUuid1;
295 mainScreen->
Append( junction2 );
298 group2->
SetName(
"DesignBlock" );
299 const_cast<KIID&
>( group2->
m_Uuid ) = groupUuid1;
302 mainScreen->
Append( group2 );
305 std::map<KIID, int> uuidCounts;
308 uuidCounts[item->m_Uuid]++;
310 int duplicatesFound = 0;
312 for(
const auto& pair : uuidCounts )
314 if( pair.second > 1 )
316 duplicatesFound += pair.second - 1;
318 <<
" count: " << pair.second );
339 uuidCounts[item->m_Uuid]++;
341 for(
const auto& pair : uuidCounts )
343 BOOST_CHECK_MESSAGE( pair.second == 1,
344 "UUID should be unique after ReplaceDuplicateTimeStamps: "
345 << pair.first.AsString().ToStdString() );
357 <<
" UUID: " <<
group->m_Uuid.AsString().ToStdString()
358 <<
" Members: " <<
group->GetItems().size() );
366 bool memberOnScreen =
false;
370 if( screenItem == member )
372 memberOnScreen =
true;
377 BOOST_CHECK_MESSAGE( memberOnScreen,
378 "Group member should be on screen. Member UUID: "
379 << member->m_Uuid.AsString().ToStdString() );
386 wxString fileName = GetTempFileName(
"test_dup_uuid" );
387 fileName +=
".kicad_sch";
388 m_tempFiles.push_back( fileName );
391 BOOST_CHECK_NO_THROW( io.
SaveSchematicFile( fileName, topSheets[0], m_schematic.get() ) );
393 m_schematic->Reset();
394 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
398 m_schematic->AddTopLevelSheet( loadedSheet );
399 m_schematic->RemoveTopLevelSheet( defaultSheet );
406 int membersWithValidPointers = 0;
414 <<
" Members: " <<
group->GetItems().size() );
421 bool memberOnScreen =
false;
425 if( screenItem == member )
427 memberOnScreen =
true;
428 membersWithValidPointers++;
433 BOOST_CHECK_MESSAGE( memberOnScreen,
434 "Loaded group member should be on screen" );
441 BOOST_TEST_MESSAGE(
"Test passed: Duplicate UUIDs correctly handled and groups preserved" );
std::unordered_set< EDA_ITEM * > & GetItems()
void AddItem(EDA_ITEM *aItem)
Add item to group.
void SetName(const wxString &aName)
A base class for most all the KiCad significant classes used in schematics and boards.
EE_TYPE OfType(KICAD_T aType) const
Container for project specific data.
A set of SCH_ITEMs (i.e., without duplicates).
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
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,...
void SetEndPoint(const VECTOR2I &aPosition)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
int ReplaceDuplicateTimeStamps()
Test all sheet and symbol objects in the schematic for duplicate time stamps and replaces them as nec...
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
Class to handle a set of SCH_ITEMs.
std::unique_ptr< SCHEMATIC > m_schematic
std::vector< wxString > m_tempFiles
SETTINGS_MANAGER m_settingsManager
void CreateDesignBlockContent(SCH_SCREEN *aScreen, SCH_GROUP **aOutGroup, const VECTOR2I &aOffset)
Create a simple design block content: a wire and junction in a group.
wxString GetTempFileName(const wxString &aPrefix)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(TestMultipleDesignBlocksGroupIntegrity)
Test that multiple design block instances maintain correct group membership after save/reload This is...
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I