53 std::unique_ptr<SCHEMATIC> schematic;
55 auto* original = schematic->GetTopLevelSheet();
56 original->SetName(
"Power" );
57 auto copy = std::unique_ptr<SCH_SHEET>(
static_cast<SCH_SHEET*
>( original->Clone() ) );
59 copy->SetName(
"Other" );
60 schematic->AddTopLevelSheet(
copy.release() );
61 const auto paths = schematic->Hierarchy();
62 BOOST_REQUIRE_EQUAL( paths.size(), 2u );
67 auto* candidate =
static_cast<SCH_LABEL*
>( item );
69 if( candidate->GetText() == wxString(
"NET_1" ) )
74 auto& facade = schematic->Connectivity();
76 auto netSettings = schematic->Project().GetProjectFile().NetSettings();
77 facade.Update( *schematic );
78 facade.ApplyNetclasses( *netSettings );
79 const auto originalAssignments = netSettings->GetNetclassLabelAssignments();
80 const std::set<wxString> expectedClasses{ wxString(
"CLASS2" ), wxString(
"CLASS3" ) };
81 BOOST_REQUIRE( originalAssignments.at( wxString(
"/Power/NET_1" ) ) == expectedClasses );
82 BOOST_REQUIRE( originalAssignments.at( wxString(
"/Other/NET_1" ) ) == expectedClasses );
85 netSettings->SetNetColorAssignment( wxString(
"/Power/NET_1" ), powerColor );
86 netSettings->SetNetColorAssignment( wxString(
"/Other/NET_1" ), otherColor );
90 for(
const auto& [
name, prefix] : std::vector<std::pair<wxString, wxString>>{
91 {
"Power",
"/Power/" }, {
"Power/Supply",
"/Power{slash}Supply/" },
92 {
"Power",
"/Power/" } } )
95 original->SetName(
name );
98 netSettings->RenameNetPathPrefix( oldPrefix, newPrefix );
99 facade.Update( *schematic );
100 facade.ApplyNetclasses( *netSettings );
101 std::map<wxString, std::set<wxString>> expectedAssignments;
103 for(
const auto& [net, classes] : originalAssignments )
105 expectedAssignments[net.StartsWith(
"/Power/" ) ? prefix + net.Mid( 7 ) : net] = classes;
108 const std::map<wxString, KIGFX::COLOR4D> expectedColors{
109 { prefix +
"NET_1", powerColor }, {
"/Other/NET_1", otherColor }
111 BOOST_CHECK( netSettings->GetNetclassLabelAssignments() == expectedAssignments );
112 BOOST_CHECK( netSettings->GetNetColorAssignments() == expectedColors );
114 for(
const auto&
path : paths )
116 const wxString
expected =
path.Last() == original ? prefix +
"NET_1" : wxString(
"/Other/NET_1" );
117 const auto view = facade.Connection( label->
m_Uuid,
path.Path() );
122 const auto incremental = facade.Published().Rows();
123 facade.Update( *schematic,
true );
124 facade.ApplyNetclasses( *netSettings );
125 BOOST_CHECK( facade.Published().Rows() == incremental );
126 BOOST_CHECK( netSettings->GetNetclassLabelAssignments() == expectedAssignments );
127 BOOST_CHECK( netSettings->GetNetColorAssignments() == expectedColors );
133 for(
const wxString& fixture : { wxString(
"issue7203" ), wxString(
"issue22938/issue22938" ) } )
138 std::unique_ptr<SCHEMATIC> schematic;
140 SCH_SHEET* original = schematic->GetTopLevelSheet();
142 auto copy = std::unique_ptr<SCH_SHEET>(
static_cast<SCH_SHEET*
>( original->
Clone() ) );
144 copy->SetName(
"Second" );
145 schematic->AddTopLevelSheet(
copy.release() );
146 std::vector<SCH_SHEET_PATH> roots;
150 if(
path.size() == 1 )
151 roots.push_back(
path );
154 BOOST_REQUIRE_EQUAL( roots.size(), 2 );
155 BOOST_REQUIRE( roots[0].LastScreen() == roots[1].LastScreen() );
168 auto* symbol =
static_cast<SCH_SYMBOL*
>( item );
171 if( symbol->IsLocalPower() && value == wxString(
"+48V" ) )
173 else if( symbol->IsGlobalPower() && value == wxString(
"+12V" ) )
187 const wxString localName =
text( local ).
GetText();
188 const wxString globalName =
text( global ).GetText();
189 auto& facade = schematic->Connectivity();
190 const auto check = [&]
192 facade.Update( *schematic );
197 const auto pins =
static_cast<SCH_SYMBOL*
>( item )->GetPins( &
path );
198 BOOST_REQUIRE_EQUAL( pins.size(), 1 );
202 const auto instance = facade.Keys().FindInstance(
path.Path() );
204 return facade.Published().Rows().at( { item->
m_Uuid, *instance } );
206 const auto& firstLocal = row( local, roots[0] );
207 const auto& secondLocal = row( local, roots[1] );
208 const auto& firstGlobal = row( global, roots[0] );
209 const auto& secondGlobal = row( global, roots[1] );
210 BOOST_CHECK( firstLocal.component != secondLocal.component );
211 BOOST_CHECK( firstGlobal.component == secondGlobal.component );
212 BOOST_CHECK( firstLocal.component != firstGlobal.component );
213 BOOST_CHECK( secondLocal.component != secondGlobal.component );
218 "/" +
path.Last()->GetName() +
"/" +
text( local ).GetText() );
222 const auto incremental = facade.Published().Rows();
223 facade.Update( *schematic,
true );
224 BOOST_CHECK( facade.Published().Rows() == incremental );
227 text( local ).SetText(
"LOCAL_SCOPE_EDITED" );
228 screen->
Update( local,
false );
230 text( global ).SetText(
"GLOBAL_SCOPE_EDITED" );
231 screen->
Update( global,
false );
233 text( local ).SetText( localName );
234 text( global ).SetText( globalName );
235 screen->
Update( local,
false );
236 screen->
Update( global,
false );
245 std::unique_ptr<SCHEMATIC> schematic;
247 const auto paths = schematic->Hierarchy();
248 SCH_SCREEN& screen = *paths.front().LastScreen();
252 label->
SetText(
"${CACHE_NAME}" );
253 label->SetConnectivityDirty();
254 schematic->Project().GetTextVars()[
"CACHE_NAME"] =
"FIRST";
255 auto& facade = schematic->Connectivity();
256 facade.Update( paths, 1, {} );
257 auto view = facade.Connection( label->m_Uuid, paths.front().Path() );
260 schematic->Project().GetTextVars()[
"CACHE_NAME"] =
"SECOND";
261 facade.Update( *schematic );
268 std::unique_ptr<SCHEMATIC> schematic;
270 auto& facade = schematic->Connectivity();
271 auto paths = schematic->Hierarchy();
272 facade.Update( paths, 1, {} );
274 const auto key = facade.Published().Rows().begin()->first;
275 const auto path = facade.Keys().Instance( key.inst );
276 auto view = facade.Connection( key.item,
path );
278 paths.push_back( paths.front() );
279 BOOST_CHECK_THROW( facade.Update( paths, 1, {} ), std::invalid_argument );
280 BOOST_CHECK( facade.Published().Rows().empty() );
281 BOOST_CHECK( !facade.Connection( key.item,
path ) );
282 BOOST_CHECK( view->Name().empty() );
283 facade.Update( schematic->Hierarchy(), 1, {} );
284 BOOST_CHECK( facade.Connection( key.item,
path ) );
290 std::unique_ptr<SCHEMATIC> schematic;
292 auto& facade = schematic->Connectivity();
293 const auto paths = schematic->Hierarchy();
296 for(
const auto& alias : schematic->GetAllBusAliases() )
297 aliases.insert_or_assign( alias->GetName(), alias->Members() );
299 facade.Update( paths, 1, aliases );
300 std::map<SCH_SCREEN*, size_t> instances;
302 for(
const auto&
path : paths )
303 ++instances[
path.LastScreen()];
305 const auto shared = std::find_if( instances.begin(), instances.end(),
306 [](
const auto& entry ) { return entry.second > 1; } );
309 size_t cleanViews = 0;
310 size_t dirtyViews = 0;
313 for(
const auto& [key, row] : facade.Published().Rows() )
315 const auto& instance = facade.Keys().Instance( key.inst );
316 const auto path = paths.GetSheetPathByKIIDPath( instance );
318 auto view = facade.Connection( key.item, instance );
320 if(
path->LastScreen() == dirty )
322 BOOST_CHECK( !view );
328 const auto expected = row.name ==
INVALID_ID ? wxString() : facade.Keys().Name( row.name );
334 BOOST_CHECK_GT( dirtyViews, 0u );
335 BOOST_CHECK_GT( cleanViews, 0u );
336 facade.Update( paths, 1, aliases );
338 for(
const auto& [key, row] : facade.Published().Rows() )
339 BOOST_CHECK( facade.Connection( key.item, facade.Keys().Instance( key.inst ) ) );
345 std::unique_ptr<SCHEMATIC> schematic;
347 auto sheet = std::unique_ptr<SCH_SHEET>(
348 static_cast<SCH_SHEET*
>( schematic->GetTopLevelSheet()->Clone() ) );
349 const_cast<KIID&
>( sheet->m_Uuid ) =
KIID();
350 sheet->SetScreen(
nullptr );
351 sheet->SetFileName(
"net_chains_four_nets.kicad_sch" );
352 sheet->SetParent( schematic->GetTopLevelSheet() );
353 schematic->GetTopLevelSheet()->GetScreen()->Append( sheet.release() );
354 schematic->RefreshHierarchy();
355 auto& facade = schematic->Connectivity();
356 BOOST_CHECK_NO_THROW( facade.Recalculate( *schematic,
true ) );
357 BOOST_CHECK( !facade.Published().Rows().empty() );
358 BOOST_CHECK( !schematic->NetChains().GetPotentialNetChains().empty() );
364 std::unique_ptr<SCHEMATIC> schematic;
366 const auto path = schematic->Hierarchy().front();
367 std::map<SCH_DIRECTIVE_LABEL*, std::unordered_set<SCH_RULE_AREA*>>
expected;
376 expected.emplace( directive, areas );
377 directive->ClearConnectedRuleAreas();
382 auto& facade = schematic->Connectivity();
383 facade.Update( *schematic );
384 facade.Recalculate( *schematic,
false );
385 BOOST_REQUIRE( facade.Published().Changes().changedItems.empty() );
387 for(
const auto& [directive, areas] :
expected )
389 BOOST_CHECK( directive->GetConnectedRuleAreas() == areas );
390 BOOST_CHECK( !directive->IsDangling() );
397 std::unique_ptr<SCHEMATIC> schematic;
399 const auto paths = schematic->Hierarchy();
400 schematic->ConnectionGraph()->Recalculate( paths,
true );
401 std::vector<std::tuple<SCH_LINE*, bool, bool>> lines;
402 std::vector<std::tuple<SCH_BUS_ENTRY_BASE*, bool, bool>> entries;
403 std::set<SCH_SCREEN*> seen;
405 for(
const auto&
path : paths )
409 if( !seen.insert( screen ).second )
416 lines.emplace_back( line, line->IsStartDangling(), line->IsEndDangling() );
417 line->SetDanglingState( !line->IsStartDangling(), !line->IsEndDangling() );
421 entries.emplace_back( entry, entry->IsStartDangling(), entry->IsEndDangling() );
422 entry->SetDanglingState( !entry->IsStartDangling(), !entry->IsEndDangling() );
429 schematic->Connectivity().Recalculate( *schematic );
431 for(
const auto& [line, start,
end] : lines )
437 for(
const auto& [entry, start,
end] : entries )
447 std::unique_ptr<SCHEMATIC> schematic;
449 const auto paths = schematic->BuildSheetListSortedByPageNumbers();
450 std::map<SCH_SCREEN*, std::vector<SCH_SHEET_PATH>> instances;
452 for(
const auto&
path : paths )
453 instances[
path.LastScreen()].push_back(
path );
456 std::vector<SCH_SHEET_PATH> shared;
458 for(
const auto& [screen, candidates] : instances )
460 if( candidates.size() < 2 )
465 auto* candidate =
static_cast<SCH_SYMBOL*
>( item );
467 if( candidate->GetUnitCount() > 1 )
483 for(
size_t selected : { size_t( 0 ), shared.size() - 1, size_t( 0 ) } )
485 const auto&
path = shared[selected];
487 schematic->SetCurrentSheet(
path );
488 path.UpdateAllScreenReferences();
489 schematic->ConnectionGraph()->Recalculate( paths,
true );
494 if( candidate->GetLibPin()->GetUnit() == unit
504 const bool dangling =
pin->IsDangling();
505 pin->SetIsDangling( !dangling );
507 schematic->Connectivity().Recalculate( *schematic );
517 std::unique_ptr<SCHEMATIC> schematic;
520 schematic->RebuildConnectivity();
521 const auto path = schematic->Hierarchy().front();
526 auto* symbol =
static_cast<SCH_SYMBOL*
>( item );
528 if( symbol->GetRef( &
path ) == wxS(
"R2" ) )
533 const auto longestChain = [&]()
537 for(
const auto&
chain : schematic->NetChains().GetPotentialNetChains() )
538 nets = std::max( nets,
chain->GetNets().size() );
542 const auto originalLength = longestChain();
543 BOOST_REQUIRE_EQUAL( originalLength, 4 );
545 manager.
SetEnvironment( schematic.get(),
nullptr,
nullptr,
nullptr,
nullptr );
551 schematic->RebuildConnectivity();
554 restoreCommit.
Modify( bridge,
path.LastScreen() );
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.
KICAD_T Type() const
Returns the type of object.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual void SetText(const wxString &aText)
EE_TYPE OfType(KICAD_T aType) const
A color representation with 4 components: red, green, blue, alpha.
Base class for a bus or wire entry.
Commit for the schematic and symbol editors.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
const std::unordered_set< SCH_RULE_AREA * > GetConnectedRuleAreas() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
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 IsConnectable() const override
EE_RTREE & Items()
Get the full RTree, usually for iterating.
void BumpConnectivityRevision(KICAD_T aChangedType=TYPE_NOT_INIT)
Increment the connectivity revisions of this screen.
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Refresh a changed item in the tree and invalidate connectivity.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
void SetPassthroughMode(PASSTHROUGH_MODE aMode)
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
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)
Value keys and the key session of the schematic connectivity engine.
std::map< wxString, std::vector< wxString > > BUS_ALIASES
Bus alias table, from alias name to member texts.
constexpr uint32_t INVALID_ID
Marks an unset handle.
@ PT_NC
not connected (must be left open)
@ PT_NIC
not internally connected (may be connected to anything)
Published connection of one item on one sheet instance.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(NativeSheetRenameEscapesPublishedNetPrefixes)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
const SHAPE_LINE_CHAIN chain
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")