29#include <boost/test/unit_test.hpp>
56#include <wx/filename.h>
57#include <wx/wfstream.h>
58#include <wx/zipstrm.h>
67 +
"pcbnew/plugins/easyedapro/ProProject_LS2K0300Core_2025-11-14.epro2" );
71static void writeZipEntry( wxZipOutputStream& aZip,
const wxString& aName,
const std::string& aContent )
73 aZip.PutNextEntry( aName );
74 aZip.Write( aContent.data(), aContent.size() );
79static wxString makeTempElibz2Path(
const wxString& aPrefix )
81 wxString tempPath = wxFileName::CreateTempFileName( aPrefix );
82 wxRemoveFile( tempPath );
84 wxFileName fn( tempPath );
85 fn.SetExt( wxS(
"elibz2" ) );
87 return fn.GetFullPath();
91static void writeV3LibraryArchive(
const wxString& aPath,
const std::string& aSymbolIndex,
92 const std::string& aFootprintIndex,
const std::string& aElibu )
94 wxFFileOutputStream out( aPath );
97 wxZipOutputStream
zip( out, -1, wxConvUTF8 );
99 if( !aSymbolIndex.empty() )
100 writeZipEntry(
zip, wxS(
"symbol2.json" ), aSymbolIndex );
102 if( !aFootprintIndex.empty() )
103 writeZipEntry(
zip, wxS(
"footprint2.json" ), aFootprintIndex );
105 writeZipEntry(
zip, wxS(
"library.elibu" ), aElibu );
112 m_project(
Pgm().GetSettingsManager(), wxS(
"easyedapro_v3_import" ), wxS(
"easyedapro_v3_test" ) ),
113 m_schematic( nullptr ),
116 wxFileName archiveFile( m_project.DirStr(),
"sample",
"epro2" );
119 m_schematic.SetProject( &m_project.Project() );
121 m_plugin.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EASYEDAPRO_V3 ) );
124 BOOST_REQUIRE_NO_THROW( m_rootSheet = m_plugin->LoadSchematicFile( archiveFile.GetFullPath(), &m_schematic,
125 nullptr,
nullptr ) );
128 m_schematic.RefreshHierarchy();
130 BOOST_REQUIRE_NO_THROW( m_docs.Load() );
135 ~LOADED_SAMPLE() { s_instance =
nullptr; }
137 static LOADED_SAMPLE& Get() {
return *s_instance; }
139 KI_TEST::SCOPED_TEMP_PROJECT m_project;
142 EASYEDAPRO::V3_DOC_PARSER m_docs;
143 SCH_SHEET* m_rootSheet =
nullptr;
145 static inline LOADED_SAMPLE* s_instance =
nullptr;
156 wxString archivePath = makeTempElibz2Path( wxS(
"easyedapro_v3_mixed" ) );
158 const std::string symbolIndex = R
"({
161 "sym_uuid": { "uuid": "sym_uuid", "display_title": "SymbolName" }
167 const std::string footprintIndex = R
"({
171 "fp_uuid": { "uuid": "fp_uuid", "display_title": "FootprintName" }
176 const std::string elibu =
"{\"type\":\"DOCHEAD\"}||{\"docType\":\"SYMBOL\",\"uuid\":\"sym_uuid\"}|\n"
177 "{\"type\":\"DOCHEAD\"}||{\"docType\":\"FOOTPRINT\",\"uuid\":\"fp_uuid\"}|\n";
179 writeV3LibraryArchive( archivePath, symbolIndex, footprintIndex, elibu );
185 std::map<wxString, wxString> footprints =
188 BOOST_CHECK_EQUAL( symbols.at( wxS(
"SymbolName" ) ), wxString( wxS(
"sym_uuid" ) ) );
189 BOOST_CHECK_EQUAL( footprints.at( wxS(
"FootprintName" ) ), wxString( wxS(
"fp_uuid" ) ) );
197 wxString archivePath = makeTempElibz2Path( wxS(
"easyedapro_v3_dupes" ) );
199 const std::string symbolIndex = R
"({
202 "aaaaaaaa0001": { "uuid": "aaaaaaaa0001", "display_title": "DUP" },
203 "aaaaaaaa0002": { "uuid": "aaaaaaaa0002", "display_title": "DUP" },
204 "aaaaaaaa0003": { "uuid": "aaaaaaaa0003", "display_title": "DUP" }
210 const std::string elibu =
"{\"type\":\"DOCHEAD\"}||{\"docType\":\"SYMBOL\",\"uuid\":\"aaaaaaaa0001\"}|\n"
211 "{\"type\":\"DOCHEAD\"}||{\"docType\":\"SYMBOL\",\"uuid\":\"aaaaaaaa0002\"}|\n"
212 "{\"type\":\"DOCHEAD\"}||{\"docType\":\"SYMBOL\",\"uuid\":\"aaaaaaaa0003\"}|\n";
214 writeV3LibraryArchive( archivePath, symbolIndex, std::string(), elibu );
232 wxString archivePath = makeTempElibz2Path( wxS(
"easyedapro_v3_tombstone" ) );
234 const std::string footprintIndex = R
"({
244 const std::string elibu =
245 "{\"type\":\"DOCHEAD\"}||{\"docType\":\"FOOTPRINT\",\"uuid\":\"fp_tombstone\"}|\n"
246 "{\"type\":\"POLY\",\"id\":\"p1\",\"ticket\":1}||{\"path\":[[0,0],[10,10]],\"width\":1}|\n"
247 "{\"type\":\"POLY\",\"id\":\"p1\",\"ticket\":2}|||\n"
248 "{\"type\":\"POLY\",\"id\":\"p2\",\"ticket\":1}|||\n"
249 "{\"type\":\"POLY\",\"id\":\"p2\",\"ticket\":2}||{\"path\":[[0,0],[10,10]],\"width\":1}|\n"
250 "{\"type\":\"FILL\",\"id\":\"p3\",\"ticket\":1}||{\"path\":[[0,0],[10,10]]}|\n";
252 writeV3LibraryArchive( archivePath, std::string(), footprintIndex, elibu );
295 bool hasAtLeastOneSheet =
false;
297 for(
const auto& [schUuid, sch] :
project.at(
"schematics" ).items() )
299 if( sch.contains(
"sheets" ) && sch.at(
"sheets" ).is_array()
300 && !sch.at(
"sheets" ).empty() )
302 hasAtLeastOneSheet =
true;
315 const auto& pages =
v3.GetRawDocs( wxS(
"SCH_PAGE" ) );
318 bool hasTextValue =
false;
319 bool hasLineStartEnd =
false;
320 bool hasWireNetAttr =
false;
322 for(
const auto& [pageUuid, pageDoc] : pages )
326 if( row.
type == wxS(
"TEXT" ) && row.
inner.contains(
"value" ) )
329 if( row.
type == wxS(
"LINE" )
330 && row.
inner.contains(
"startX" ) && row.
inner.contains(
"startY" )
331 && row.
inner.contains(
"endX" ) && row.
inner.contains(
"endY" ) )
333 hasLineStartEnd =
true;
336 if( row.
type == wxS(
"ATTR" )
339 hasWireNetAttr =
true;
354 const auto& symbols =
v3.GetRawDocs( wxS(
"SYMBOL" ) );
357 bool hasBlobObject =
false;
359 for(
const auto& [symbolUuid, symbolDoc] : symbols )
363 if( row.
type != wxS(
"OBJ" ) )
368 if( content.StartsWith( wxS(
"blob:" ) ) )
370 hasBlobObject =
true;
388 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devices =
project.at(
"devices" );
392 for(
const auto& [devUuid, dev] : devices )
394 if( dev.title == aTitle )
409 wxString ls2kSymbolUuid = ls2kDevice->
attributes.at( wxS(
"Symbol" ) );
417 std::array<int, 6> unitPinCount = {};
421 int unit =
pin->GetUnit();
423 if( unit >= 1 && unit <= 5 )
424 unitPinCount[unit]++;
427 for(
int unit = 1; unit <= 5; ++unit )
428 BOOST_CHECK_MESSAGE( unitPinCount[unit] > 0,
"LS2K0300 should have pins in each unit" );
430 wxString sgmSymbolUuid = sgmDevice->
attributes.at( wxS(
"Symbol" ) );
437 bool hasLeftPins =
false;
438 bool hasRightPins =
false;
442 if(
pin->GetPosition().x < 0 )
448 else if(
pin->GetPosition().x > 0 )
463 SCHEMATIC& schematic = LOADED_SAMPLE::Get().m_schematic;
488 if( !
text->GetText().IsEmpty() )
496 if( !label->
GetText().IsEmpty() )
521 std::map<wxString, int> valueCounts;
523 for(
const auto& [pageUuid, pageDoc] :
v3.GetRawDocs( wxS(
"SCH_PAGE" ) ) )
527 if( row.
type != wxS(
"ATTR" ) )
539 if( value.IsEmpty() )
542 valueCounts[value]++;
547 if( align.StartsWith( wxS(
"RIGHT" ) ) )
548 candidates.push_back( { value, align, rotation } );
558 if( valueCounts[candidate.value] == 1 )
560 selected = candidate;
567 if( selected.align.StartsWith( wxS(
"RIGHT" ) ) )
569 else if( selected.align.StartsWith( wxS(
"LEFT" ) ) )
572 int rot = selected.rotation % 360;
579 for(
int i = 0; i < rot; i += 90 )
580 expectedSpinStyle = expectedSpinStyle.
RotateCCW();
584 SCHEMATIC& schematic = LOADED_SAMPLE::Get().m_schematic;
587 bool hasExpectedSpinStyle =
false;
600 if( label->
GetText() != selected.value )
605 if(
static_cast<int>( label->
GetSpinStyle() ) ==
static_cast<int>( expectedSpinStyle ) )
606 hasExpectedSpinStyle =
true;
611 BOOST_CHECK_MESSAGE( hasExpectedSpinStyle,
612 wxString::Format(
"Label '%s' spin style mismatch", selected.value ) );
621 std::set<wxString> netportSymbolUuids;
623 for(
const auto& [uuid, symDoc] :
v3.GetRawDocs( wxS(
"SYMBOL" ) ) )
627 if( row.
type == wxS(
"META" )
630 netportSymbolUuids.insert( uuid );
638 std::set<wxString> netportComponentIds;
640 for(
const auto& [pageUuid, pageDoc] :
v3.GetRawDocs( wxS(
"SCH_PAGE" ) ) )
644 if( row.
type != wxS(
"ATTR" ) )
652 if( netportSymbolUuids.count( symbolUuid ) )
659 std::set<wxString> expectedNetportNames;
661 for(
const auto& [pageUuid, pageDoc] :
v3.GetRawDocs( wxS(
"SCH_PAGE" ) ) )
665 if( row.
type != wxS(
"ATTR" ) )
670 if( !netportComponentIds.count( parentId ) )
677 row.
inner.value(
"value", nlohmann::json() ) );
679 if( !
name.IsEmpty() )
680 expectedNetportNames.insert(
name );
687 SCHEMATIC& schematic = LOADED_SAMPLE::Get().m_schematic;
689 int netportSymbolCount = 0;
690 int globalLabelCount = 0;
691 bool hasInputLabel =
false;
692 bool hasOutputLabel =
false;
693 bool hasBidiLabel =
false;
695 std::set<wxString> importedGlobalLabelNames;
707 wxString ref = symbol->
GetRef( &sheetPath,
false );
709 if( ref.StartsWith( wxS(
"#NET" ) ) )
710 netportSymbolCount++;
717 if( label->
GetText().IsEmpty() )
721 importedGlobalLabelNames.insert( label->
GetText() );
742 for(
const wxString&
expected : expectedNetportNames )
744 BOOST_CHECK_MESSAGE( importedGlobalLabelNames.count(
expected ) > 0,
745 wxString::Format(
"Missing global label '%s'",
expected ) );
752 SCHEMATIC& schematic = LOADED_SAMPLE::Get().m_schematic;
768 wxString ref = symbol->
GetRef( &sheetPath,
false );
770 if( ref == wxS(
"U6" ) )
772 else if( ref == wxS(
"U7" ) )
774 else if( ref == wxS(
"U1" ) )
784 "U7 should remain above U6 after EasyEDA Pro v3 import" );
790 BOOST_CHECK( u6Footprint.Contains( wxS(
"SOT-563-6" ) ) );
793 BOOST_CHECK( u1Footprint.Contains( wxS(
"BGA-286_17x17_12.0x12.0mm" ) ) );
799 SCHEMATIC& schematic = LOADED_SAMPLE::Get().m_schematic;
802 int plus5vShownCount = 0;
803 int plus5vOffsetCount = 0;
804 int plus5vUprightCount = 0;
805 int plus5vUprightAtSymbolXCount = 0;
806 int powerValueOnPinBodySideCheckedCount = 0;
807 int powerValueOnWrongPinSideCount = 0;
808 int otherPowerValueCount = 0;
809 int otherPowerShownCount = 0;
832 if( valueField->
IsVisible() && !valueText.IsEmpty() )
838 std::vector<SCH_PIN*> pins = symbol->
GetPins( &sheetPath );
844 switch( pins[0]->PinDrawOrient( symbol->
GetTransform() ) )
855 long long dot =
static_cast<long long>(
delta.x ) * dir.
x
856 +
static_cast<long long>(
delta.y ) * dir.
y;
858 powerValueOnPinBodySideCheckedCount++;
861 powerValueOnWrongPinSideCount++;
867 if( valueText == wxS(
"+5V" ) )
879 plus5vUprightCount++;
882 plus5vUprightAtSymbolXCount++;
888 else if( valueText.StartsWith( wxS(
"+" ) ) )
890 otherPowerValueCount++;
893 otherPowerShownCount++;
904 BOOST_CHECK( powerValueOnPinBodySideCheckedCount > 0 );
918 SCHEMATIC& schematic = LOADED_SAMPLE::Get().m_schematic;
922 SCH_SHEET* rootSheet = LOADED_SAMPLE::Get().m_rootSheet;
925 (void) item, rootSymbols++;
const wxString & GetPageNumber() const
Parses EasyEDA Pro v3 .epro2 archives.
const V3_DOC_RAW * FindRawDoc(const wxString &aDocType, const wxString &aUuid) const
void LoadLibrary()
Load all v3 docs from a library archive.
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
GR_TEXT_H_ALIGN_T GetHorizJustify() const
GR_TEXT_V_ALIGN_T GetVertJustify() const
EE_TYPE OfType(KICAD_T aType) const
int GetUnitCount() const override
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const override
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
Holds all the data relating to one schematic.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
EASYEDAPRO::SYM_INFO ParseSymbol(const EASYEDAPRO::V3_DOC_RAW &aDoc, const std::map< wxString, wxString > &aDeviceAttributes, const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap={})
VECTOR2I GetPosition() const override
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
SPIN_STYLE GetSpinStyle() const
LABEL_FLAG_SHAPE GetShape() const
Segment description base class to describe items which have 2 end points (track, wire,...
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
const wxString GetFootprintFieldText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) 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.
bool IsGlobalPower() const override
VECTOR2I GetPosition() const override
int GetOrientation() const override
Get the display symbol orientation.
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.
Spin style for labels of all kinds on schematics.
const TRANSFORM & GetTransform() const
BOOST_AUTO_TEST_CASE(LibraryIndexMergeKeepsSymbolAndFootprintNames)
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
nlohmann::json BuildV3ProjectIndexFromRawDocs(const V3_DOC_PARSER &aParser, bool aIncludeLibraryMetadata=true)
Build a minimal legacy-style project index from parsed v3 raw documents.
bool V3GetBool(const nlohmann::json &aObj, const char *aKey, bool aDefault)
int AlignToFontV(const wxString &aAlign)
Map an EasyEDA "HORIZ_VERT" alignment token to a KiCad justify code (0 top/left, 1 center,...
wxString V3JsonToString(const nlohmann::json &aValue, const wxString &aDefault)
int V3GetInt(const nlohmann::json &aObj, const char *aKey, int aDefault)
int AlignToFontH(const wxString &aAlign)
std::map< wxString, wxString > BuildV3LibraryItemMap(const V3_DOC_PARSER &aParser, const char *aIndexKey, const wxString &aDocType)
wxString V3GetString(const nlohmann::json &aObj, const char *aKey, const wxString &aDefault)
std::string GetTestDataRootDir()
PGM_BASE & Pgm()
The global program "get" accessor.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
std::map< wxString, wxString > attributes
std::unique_ptr< LIB_SYMBOL > libSymbol
Raw parsed document from an EasyEDA Pro v3 .epru stream.
std::map< wxString, size_t > rowById
std::vector< V3_ROW > rows
One parsed row from an EasyEDA Pro v3 .epru document stream.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
std::vector< DATABASE_CONNECTION::ROW > rows
BOOST_REQUIRE(res.columns()==1)
static wxString getEasyEdaProV3ArchivePath()
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
VECTOR2< int32_t > VECTOR2I