45using JSON = nlohmann::json;
46using KEY = std::pair<std::string, std::string>;
51std::string
utf8(
const wxString& aText )
53 return aText.ToStdString( wxConvUTF8 );
71JSON valueJson(
const DUMP_VALUE& aValue )
73 std::set<std::string> classes;
75 for(
const wxString&
name : aValue.netclasses )
78 JSON row = { {
"name",
utf8( aValue.name ) }, {
"local_name",
utf8( aValue.localName ) },
79 {
"type", typeName( aValue.type ) },
80 {
"driver", aValue.driver ?
utf8( aValue.driver->AsString() ) :
"" },
81 {
"driver_path", aValue.driver ?
utf8( aValue.driverPath.AsString() ) :
"" },
82 {
"members", JSON::array() }, {
"netclasses", classes } };
84 for(
const DUMP_VALUE& member : aValue.members )
85 row[
"members"].push_back( valueJson( member ) );
91std::set<wxString> resolvedClasses(
const wxString& aName,
NET_SETTINGS* aSettings )
93 std::set<wxString> classes;
98 classes.insert( constituent->GetName() );
105DUMP_VALUE valueRow(
const wxString& aName,
const wxString& aLocalName,
CONNECTION_TYPE aType,
110 value.localName = aLocalName;
112 value.netclasses = resolvedClasses( aName, aSettings );
116 value.driver = aDriver->
m_Uuid;
117 value.driverPath = aDriverPath;
126 const wxString& aNamePrefix,
const wxString& aLocalPrefix,
SCH_ITEM* aDriver,
131 if( aNode.
kind == NODE::KIND::NET )
133 const auto& leaf = aMembers.
leaves.at( aNode.
leaf.value() );
134 return valueRow( leaf.Name(), aMembers.
schema->leaves.at( aNode.
leaf.value() ).name,
138 const wxString localName = aLocalPrefix + aNode.
text;
139 DUMP_VALUE row = valueRow( aPath + aNamePrefix + aNode.
text, localName,
141 aDriver, aDriverPath, aSettings );
142 wxString namePrefix = aNamePrefix;
143 wxString localPrefix = aLocalPrefix;
145 if( aNode.
kind == NODE::KIND::GROUP && !aNode.
prefix.empty() )
147 namePrefix += aNode.
prefix +
".";
148 localPrefix += aNode.
prefix +
".";
151 for(
const auto& member : aNode.
members )
153 row.members.push_back( memberRow( member, aMembers, aPath, namePrefix, localPrefix, aDriver, aDriverPath,
168 DUMP_VALUE row = valueRow(
name, aView.
FullLocalName(), aType, driver, driverPath, aSettings );
169 const auto members = aView.
Members();
174 const auto groupPrefix = [&](
const wxString& aPrefix )
176 if( aPrefix.empty() )
179 return aComponent.
suffix ? wxString::Format(
"%s_%u.", aPrefix, aComponent.
suffix ) : aPrefix + wxS(
"." );
182 const wxString localPrefix =
group ? groupPrefix( members.tree->prefix ) : wxString();
183 const auto& best = aComponent.
content->best;
186 const wxString namePrefix =
group && best && best->schema
188 ? groupPrefix( best->schema->prefix )
190 const wxString
path =
name.Left(
name.length() - aView.
Name(
true ).length() );
192 for(
const auto& member : members.tree->members )
194 row.members.push_back( memberRow( member, members,
path, namePrefix, localPrefix, driver, driverPath,
207 const wxString
name = !aConnection->
Driver() && aConnection->
Name(
true ) ==
"<NO NET>"
208 ? wxString() : aConnection->Name();
210 aConnection->
Sheet().
Path(), aSettings );
213 for(
const auto& member : aConnection->
Members() )
214 row.members.push_back( connectionRow( member.get(), aSettings ) );
223 std::map<KEY, JSON> sorted;
225 for(
const auto& [key, row] : aRows )
227 const std::string pathId =
utf8( key.first.AsString() );
228 const std::string itemId =
utf8( key.second.AsString() );
229 std::set<std::string> connected;
231 for(
const KIID& neighbour : row.connected )
235 json[
"path"] = pathId;
236 json[
"item"] = itemId;
237 json[
"dangling"] = row.dangling;
238 json[
"dangling_ends"] = row.danglingEnds;
239 json[
"connected"] = connected;
240 sorted.emplace( KEY{ pathId, itemId }, std::move(
json ) );
245 for(
auto& [key, row] : sorted )
246 result.push_back( std::move( row ) );
248 return result.dump( 2 ) +
"\n";
278 row.
value = connectionRow( aItem->Connection( &
path ), settings );
282 if(
auto* line =
dynamic_cast<SCH_LINE*
>( aItem ) )
284 row.
danglingEnds = { line->IsStartDangling(), line->IsEndDangling() };
288 row.
danglingEnds = { entry->IsStartDangling(), entry->IsEndDangling() };
292 row.
connected.insert( neighbour->m_Uuid );
294 if( !
rows.emplace( std::pair( pathId, aItem->m_Uuid ), std::move( row ) ).second )
296 throw std::runtime_error(
"Duplicate connectivity item " +
utf8( pathId.
AsString() )
297 +
utf8( aItem->m_Uuid.AsString() ) );
313 else if( item->IsConnectable() )
326 const auto& publication = aFacade.
Published();
327 const auto& keys = aFacade.
Keys();
328 const auto& auxiliary = publication.Auxiliary();
329 std::unique_ptr<NET_SETTINGS> settings;
334 settings = std::make_unique<NET_SETTINGS>(
nullptr,
"" );
335 settings->CopyFrom( *
source );
339 for(
const auto& [owner, patterns] :
source->GetChainPatternAssignments() )
341 for(
const auto& [matcher,
name] : patterns )
342 settings->SetChainPatternAssignment( owner, matcher->GetPattern(),
name );
346 std::map<INST_ID, SCH_SCREEN*> screens;
350 if(
auto instance = keys.FindInstance(
path.Path() ) )
351 screens.emplace( *instance,
path.LastScreen() );
356 for(
const auto& [key,
result] : publication.Rows() )
362 throw std::runtime_error(
"Cannot dump stale connectivity publication" );
365 row.
value = connectionRow( *view, publication.Components().at(
result.component ),
result.itemType,
367 const auto& island = auxiliary.Islands().at( auxiliary.IslandOf().at( key ) ).value;
368 const auto dangling = island.dangling.at( key.item );
371 const auto screen = screens.find( key.inst );
373 if( screen == screens.end() || !screen->second )
374 throw std::runtime_error(
"Cannot dump connectivity without its source instance" );
376 SCH_ITEM* item = screen->second->GetConnectivityItem( key.item );
379 throw std::runtime_error(
"Cannot dump connectivity without its source item" );
382 row.
danglingEnds = { ( dangling & 1 ) != 0, ( dangling & 2 ) != 0 };
392 const auto neighbors = auxiliary.NeighborsOf().find( key );
394 if( neighbors != auxiliary.NeighborsOf().end() )
395 row.
connected.insert( neighbors->second.begin(), neighbors->second.end() );
397 rows.emplace( std::pair(
path, key.item ), std::move( row ) );
KICAD_T Type() const
Returns the type of object.
wxString AsString() const
wxString AsString() const
A collection of nets and the parameters used to route or test these nets.
const std::vector< NETCLASS * > & GetConstituentNetclasses() const
Gets the netclasses which make up this netclass.
NET_SETTINGS stores various net-related settings in a project context.
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const wxString &aNetName)
Fetches the effective (may be aggregate) netclass for the given net name.
std::shared_ptr< NET_SETTINGS > & NetSettings()
virtual PROJECT_FILE & GetProjectFile() const
Holds all the data relating to one schematic.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Base class for a bus or wire entry.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString FullLocalName() const
SCH_SHEET_PATH Sheet() const
CONNECTION_TYPE Type() const
wxString Name(bool aIgnoreSheet=false) const
SCH_ITEM * Driver() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
Model-owned source resolver.
void ApplyNetclasses(NET_SETTINGS &aSettings) const
Replace label-derived assignments from a complete publication; invalidate changed net caches.
const SESSION_KEYS & Keys() const
std::optional< ITEM_VIEW > Connection(const KIID &aItem, const KIID_PATH &aPath) const
const PUBLICATION & Published() const
wxString FullLocalName() const
BUS_MEMBERS Members() const
SCH_ITEM * Driver() const
wxString Name(bool aIgnoreSheet=false) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
const std::vector< SCH_ITEM * > & ConnectedItems(const SCH_SHEET_PATH &aPath) const
Retrieve the set of items connected to this item on the given sheet.
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Segment description base class to describe items which have 2 end points (track, wire,...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
std::string utf8(const wxString &aText)
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.
std::string Dump(const DUMP_ROWS &aRows)
@ BUS
This item represents a bus vector.
@ NET
This item represents a net.
@ NONE
No connection to this item.
@ BUS_GROUP
This item represents a bus group.
Query-time snapshot; reacquire after Update.
std::shared_ptr< const BUS_SCHEMA > schema
std::vector< NET_VIEW > leaves
One node of the presentation tree.
wxString text
Container label text.
std::optional< size_t > leaf
Leaf ordinal of a NET node.
std::vector< NODE > members
@ GROUP
A list such as I2C{SDA SCL}. Members align by name with another group.
std::set< KIID > connected
std::vector< bool > danglingEnds
One connection or bus member.
One published net or bus with its identity.
uint32_t suffix
Zero for the holder of the base name.
std::shared_ptr< const COMPONENT_CONTENT > content
std::vector< DATABASE_CONNECTION::ROW > rows
wxString result
Test unit parsing edge cases and error handling.