33#include <boost/mpl/list.hpp>
44#include <wx/xml/xml.h>
54 boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_test_units);
74 CONNECTIVITY_SCOPE connectivity( *
this );
81 std::unique_ptr<SCHEMATIC> schematic;
84 const auto selected = std::find_if( hierarchy.begin(), hierarchy.end(),
87 return path.PathHumanReadable() ==
"/First Subsheet/";
90 schematic->SetCurrentSheet( *selected );
91 EXPORTER exporter( schematic.get(),
nullptr );
93 for(
bool published : {
false,
true } )
99 BOOST_REQUIRE_EQUAL( sheets.size(), 2 );
100 std::set<wxString> names;
104 BOOST_CHECK(
path.at( 0 ) == selected->at( 0 ) );
105 names.insert(
path.PathHumanReadable() );
108 BOOST_CHECK( names.contains(
"/First Subsheet/" ) );
109 BOOST_CHECK( names.contains(
"/First Subsheet/Sub2/" ) );
113 const wxString variant = wxS(
"Simulation exclusion" );
114 schematic->AddVariant( variant );
118 for(
bool published : {
false,
true } )
122 for(
bool baseExcluded : {
false,
true } )
124 selected->Last()->SetExcludedFromSim( baseExcluded );
125 selected->Last()->SetExcludedFromSim( !baseExcluded, &parent, variant );
127 for(
const wxString& active : { wxString(), variant } )
129 schematic->SetCurrentVariant( active );
130 const auto sheets = exporter.SelectedSheets();
131 const bool excluded = active.IsEmpty() ? baseExcluded : !baseExcluded;
143 for(
bool published : {
false,
true } )
147 for(
bool local : {
false,
true } )
149 for(
const wxString&
name : { wxString(
"0" ), wxString(
"GND" ), wxString(
"gNd" ) } )
154 std::unique_ptr<SCHEMATIC> schematic;
160 if(
path.size() < 2 )
165 auto* symbol =
static_cast<SCH_SYMBOL*
>( item );
167 if( symbol->IsPower()
168 && symbol->GetField(
FIELD_T::VALUE )->GetText().StartsWith(
"REF" ) )
184 const auto nets = exporter.
GetNets();
185 BOOST_CHECK( nets.contains(
name ) );
186 BOOST_CHECK( std::none_of( nets.begin(), nets.end(), [&](
const wxString& net )
187 { return net.Lower().EndsWith( wxS(
"/" ) + name.Lower() ); } ) );
202 for(
const auto& [fixture, expectsSignals] :
203 { std::pair{
"issue7203",
false },
204 std::pair{
"netlists/hierarchy_aliases/hierarchy_aliases",
true },
205 std::pair{
"netlists/video/video",
true } } )
211 std::unique_ptr<SCHEMATIC> schematic;
213 auto exportText = [&]()
218 EXPORTER exporter( schematic.get(),
nullptr );
220 wxFFile file(
path,
"r" );
225 if constexpr( std::is_same_v<EXPORTER, NETLIST_EXPORTER_CADSTAR> )
227 const size_t start =
text.find(
".TIM " );
229 const size_t end =
text.find(
'\n', start );
231 text.erase( start,
end - start );
236 const wxString
expected = exportText();
237 const wxString marker = std::is_same_v<EXPORTER, NETLIST_EXPORTER_PADS> ?
"*SIGNAL*" :
".ADD_TER";
239 schematic->ConnectionGraph()->Reset();
240 schematic->Connectivity().Clear();
241 BOOST_REQUIRE( schematic->ConnectionGraph()->GetNetMap().empty() );
243 const wxString
actual = exportText();
254 for(
const char* fixture : {
"issue7203",
"netlists/hierarchy_aliases/hierarchy_aliases",
255 "netlists/video/video" } )
261 std::unique_ptr<SCHEMATIC> schematic;
263 auto exportFiles = [&]()
273 std::map<wxString, wxString>
result;
275 for(
const wxString&
path : paths )
277 wxFFile file(
path,
"r" );
281 const wxString relative =
path.Mid(
directory.length() + 1 );
283 if( relative ==
"netlist.net" )
285 const size_t start =
text.find(
"(Date: " );
287 const size_t end =
text.find(
'\n', start );
289 text.erase( start,
end - start );
295 BOOST_REQUIRE_GT(
result.size(), 1u );
298 const auto expected = exportFiles();
299 schematic->ConnectionGraph()->Reset();
300 schematic->Connectivity().Clear();
301 BOOST_REQUIRE( schematic->ConnectionGraph()->GetNetMap().empty() );
303 const auto actual = exportFiles();
331 std::unique_ptr<SCHEMATIC> schematic;
333 SCH_SCREEN& screen = *schematic->Hierarchy().front().LastScreen();
336 auto* native =
static_cast<SCH_LABEL*
>( *labels.begin() );
337 auto replacement = std::make_unique<UNNOTIFIED_LABEL>( *native );
338 screen.
Remove( native,
false );
339 std::unique_ptr<SCH_LABEL> original( native );
340 auto* label = replacement.get();
341 screen.
Append( replacement.release() );
342 schematic->Connectivity().Update( *schematic );
343 schematic->ConnectionGraph()->Reset();
345 label->EDA_TEXT::SetText(
"EXPORT_FORMAT_FRESH" );
350 BOOST_CHECK( formatter.
GetString().find(
"EXPORT_FORMAT_FRESH" ) != std::string::npos );
352 label->EDA_TEXT::SetText(
"EXPORT_FILE_FRESH" );
358 wxFFile file(
path,
"r" );
362 BOOST_CHECK(
text.Contains(
"EXPORT_FILE_FRESH" ) );
363 BOOST_CHECK( !
text.Contains(
"EXPORT_FORMAT_FRESH" ) );
371 for(
bool engine : {
false,
true } )
377 std::unique_ptr<SCHEMATIC> schematic;
379 const auto sheet = schematic->Hierarchy().front();
385 auto* candidate =
static_cast<SCH_SYMBOL*
>( item );
387 if( !candidate->IsPower() && !candidate->GetRef( &sheet ).StartsWith(
"#" ) )
398 screen.
Remove( symbol,
false );
399 symbol->
SetPosition( area->GetBoundingBox().Centre() );
401 std::unordered_set<SCH_SCREEN*> screens{ &screen };
405 area->SetDNP(
true );
406 symbol->
SetDNP(
false, &sheet );
409 const wxString reference = symbol->
GetRef( &sheet );
413 auto exportDnp = [&]()
417 wxXmlDocument document;
422 for( wxXmlNode* section = document.GetRoot()->GetChildren(); section; section = section->GetNext() )
424 if( section->GetName() !=
"components" )
427 for( wxXmlNode* component = section->GetChildren(); component; component = component->GetNext() )
429 if( component->GetAttribute(
"ref" ) != reference )
434 for( wxXmlNode* property = component->GetChildren(); property; property = property->GetNext() )
435 dnp |=
property->GetName() ==
"property" &&
property->GetAttribute(
"name" ) ==
"dnp";
443 BOOST_CHECK( !exportDnp() );
446 BOOST_CHECK( exportDnp() );
456 void write(
const char*,
int )
override
465 for(
bool engine : {
false,
true } )
471 std::unique_ptr<SCHEMATIC> schematic;
477 return error.Problem().Contains(
"Netlist output failed" );
481 BOOST_CHECK( !output.
GetString().empty() );
492 std::unique_ptr<SCHEMATIC> schematic;
494 auto* graph = schematic->ConnectionGraph();
496 auto*
chain = graph->CreateNetChainFromPotential( graph->GetPotentialNetChains().front().get(),
506 auto* candidate =
static_cast<SCH_LABEL*
>( item );
509 if( connection &&
chain->GetNets().contains( connection->Name() ) )
512 oldName = connection->Name();
522 label->
SetText(
"EXPORT_CHAIN_RENAMED" );
524 for(
bool usePublished : {
true,
false } )
528 enabled = usePublished;
532 const wxString file =
directory.PathStr() +
"/netlist.xml";
534 wxXmlDocument document;
536 std::set<wxString> members;
537 auto collect = [&](
auto&& self, wxXmlNode* node ) ->
void
539 for( ; node; node = node->GetNext() )
541 if( node->GetName() ==
"member" )
542 members.insert( node->GetAttribute(
"net" ) );
544 self( self, node->GetChildren() );
547 collect( collect, document.GetRoot() );
548 BOOST_CHECK( members.contains(
"/EXPORT_CHAIN_RENAMED" ) );
549 BOOST_CHECK( !members.contains( oldName ) );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual void cacheShownText()
virtual void SetText(const wxString &aText)
EE_TYPE OfType(KICAD_T aType) const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
wxString PathStr() const
Get the path to the temporary directory as a wxString.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Generate a netlist compatible with Allegro.
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
Write to specified output file.
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
NETLIST_EXPORTER_SPICE(SCHEMATIC *aSchematic, KIWAY *aKiway)
SCH_SHEET_LIST BuildSheetList(unsigned aNetlistOptions=0) const
Return the paths of exported sheets (either all or the current one).
std::set< wxString > GetNets() const
Return the list of nets.
virtual bool ReadSchematicAndLibraries(unsigned aNetlistOptions, REPORTER &aReporter)
Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs.
Generate a generic XML based netlist file.
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
const std::unordered_set< SCH_RULE_AREA * > & GetRuleAreaCache() const
Get the cache of rule areas enclosing this item.
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
bool ResolveDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
void cacheShownText() override
SCH_LABEL(const VECTOR2I &aPos=VECTOR2I(0, 0), const wxString &aText=wxEmptyString)
static std::vector< std::pair< SCH_RULE_AREA *, SCH_SCREEN * > > UpdateRuleAreasInScreens(std::unordered_set< SCH_SCREEN * > &screens, KIGFX::SCH_VIEW *view)
Update all rule area connectvity / caches in the given sheet paths.
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
uint64_t ConnectivityRevision() const
The only change signal that the connectivity engine reads from this screen.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void pop_back()
Forwarded method from std::vector.
virtual void SetDNP(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void SetPosition(const VECTOR2I &aPosition) override
VECTOR2I GetPosition() const override
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
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.
A wrapper for reporting to a wxString object.
bool m_ConnectivityEngine
Use the schematic connectivity engine instead of CONNECTION_GRAPH.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(CurrentSheetExportPreservesFullInstancePaths)
BOOST_AUTO_TEST_CASE_TEMPLATE(UsesPublishedNetsWithoutLegacyGraph, EXPORTER, PUBLISHED_EXPORTERS)
boost::mpl::list< NETLIST_EXPORTER_PADS, NETLIST_EXPORTER_CADSTAR > PUBLISHED_EXPORTERS
BOOST_GLOBAL_FIXTURE(GlobalConfig)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
VECTOR3I expected(15, 30, 45)
const SHAPE_LINE_CHAIN chain
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