301 SCH_SHEET* original = m_schematic->GetTopLevelSheet();
302 auto copy = std::unique_ptr<SCH_SHEET>(
static_cast<SCH_SHEET*
>( original->
Clone() ) );
304 copy->SetName(
"Second" );
306 m_schematic->AddTopLevelSheet(
copy.release() );
308 BOOST_REQUIRE_EQUAL( sheets.size(), 2 );
309 auto& manager = m_schematic->NetChains();
311 m_schematic->ConnectionGraph()->Recalculate( sheets,
true );
312 const auto& chains = manager.GetPotentialNetChains();
313 BOOST_REQUIRE_EQUAL( chains.size(), 2 );
317 for(
const auto&
chain : chains )
321 std::set<wxString> references;
324 references.insert( symbol->GetRef( &sheets[0] ) );
326 const std::set<wxString>
expected{
"R1",
"R2",
"R3" };
327 BOOST_CHECK( references ==
expected );
330 for(
const wxString& net : chains[0]->GetNets() )
331 BOOST_CHECK( !chains[1]->GetNets().contains( net ) );
334 auto* bridge = *chains[0]->GetSymbols().begin();
335 const auto pins = bridge->GetPins( &sheets[0] );
336 BOOST_REQUIRE_EQUAL( pins.size(), 2u );
337 auto* first = manager.FindPotentialNetChainBetweenPins( pins[0], sheets[0], pins[1], sheets[0] );
338 auto* second = manager.FindPotentialNetChainBetweenPins( pins[0], sheets[1], pins[1], sheets[1] );
341 BOOST_CHECK( first != second );
343 for(
int endpoint : { 0, 1 } )
345 BOOST_CHECK( first->GetTerminalPath( endpoint ) == sheets[0].Path() );
346 BOOST_CHECK( second->GetTerminalPath( endpoint ) == sheets[1].Path() );
349 BOOST_CHECK( !manager.FindPotentialNetChainBetweenPins( pins[0], sheets[0], pins[1], sheets[1] ) );
351 auto* ambiguous = manager.CreateManualNetChain(
352 "AMBIGUOUS_INSTANCE", first->GetSymbols(), first->GetNets(),
353 first->GetTerminalPinA(), first->GetTerminalPinB(),
354 first->GetTerminalRef( 0 ), first->GetTerminalPinNum( 0 ),
355 first->GetTerminalRef( 1 ), first->GetTerminalPinNum( 1 ) );
356 BOOST_CHECK( !ambiguous );
359 manager.DeleteCommittedNetChain(
"AMBIGUOUS_INSTANCE" );
361 auto* firstCommitted = manager.CreateNetChainFromPotential( first,
"FIRST_INSTANCE" );
362 auto* secondCommitted = manager.CreateNetChainFromPotential( second,
"SECOND_INSTANCE" );
365 const auto firstNets = firstCommitted->GetNets();
366 const auto secondNets = secondCommitted->GetNets();
367 BOOST_CHECK( !manager.ReplaceNetChainTerminalPin(
368 {
"FIRST_INSTANCE", 0, pins[0]->m_Uuid, sheets[1].Path() } ) );
369 BOOST_CHECK( firstCommitted->GetTerminalPath( 0 ) == sheets[0].Path() );
371 {
"FIRST_INSTANCE", 0, pins[0]->m_Uuid, sheets[0].Path() } ) );
373 {
"SECOND_INSTANCE", 0, pins[0]->m_Uuid, sheets[1].Path() } ) );
374 m_schematic->ConnectionGraph()->Recalculate( sheets,
true );
375 BOOST_CHECK( firstCommitted->GetTerminalPath( 0 ) == sheets[0].Path() );
376 BOOST_CHECK( secondCommitted->GetTerminalPath( 0 ) == sheets[1].Path() );
377 BOOST_CHECK( firstCommitted->GetNets() == firstNets );
378 BOOST_CHECK( secondCommitted->GetNets() == secondNets );
379 BOOST_REQUIRE( manager.DeleteCommittedNetChain(
"FIRST_INSTANCE" ) );
380 BOOST_REQUIRE( manager.DeleteCommittedNetChain(
"SECOND_INSTANCE" ) );
386 std::unique_ptr<SCHEMATIC> schematic;
388 const auto path = schematic->Hierarchy().front();
396 auto* symbol =
static_cast<SCH_SYMBOL*
>( item );
398 if( symbol->GetRef( &
path ) == wxString(
"R1" ) )
399 left = symbol->GetPin( wxString(
"2" ) );
400 else if( symbol->GetRef( &
path ) == wxString(
"R2" ) )
401 right = symbol->GetPin( wxString(
"1" ) );
409 if(
static_cast<SCH_LABEL*
>( item )->GetText() == wxString(
"SIG" ) )
415 if( item->IsConnected(
left->GetPosition() ) && item->IsConnected(
right->GetPosition() ) )
416 wire =
static_cast<SCH_LINE*
>( item );
423 const_cast<KIID&
>( copiedWire->m_Uuid ) =
KIID();
424 const_cast<KIID&
>( copiedLabel->m_Uuid ) =
KIID();
425 copiedWire->Move(
VECTOR2I( 0, 10000000 ) );
426 copiedLabel->Move(
VECTOR2I( 0, 10000000 ) );
427 path.LastScreen()->Append( copiedWire );
428 path.LastScreen()->Append( copiedLabel );
429 const std::set<SCH_ITEM*>
expected{
left,
right, wire, label, copiedWire, copiedLabel };
431 schematic->ConnectionGraph()->Recalculate( schematic->Hierarchy(),
true );
435 BOOST_CHECK( std::set<SCH_ITEM*>( items.begin(), items.end() ) ==
expected );
virtual void SetText(const wxString &aText)
A schematic staged off to the side by an importer, ready to be swapped into a live SCHEMATIC in one s...
std::optional< SCH_SHEET_PATH > currentSheet
std::unique_ptr< CONNECTION_GRAPH > connectionGraph
bool preserveNetChains
Keep the schematic's net chains instead of the staged graph's, for append.
SCH_SHEET * targetSheet
Sheet whose screen receives the content. Null names the schematic's virtual root.
EE_RTREE screenItems
Spatial index that replaces the target screen's own.
BOOST_CHECK_EQUAL(result, "25.4")