24#ifndef TEST_DIPTRACE_SCH_IMPORT_FIXTURE_H
25#define TEST_DIPTRACE_SCH_IMPORT_FIXTURE_H
67#include <wx/xml/xml.h>
89 if( sev & aSeverityMask )
98 std::ostringstream out;
102 if( !( sev & aSeverityMask ) )
105 if( out.tellp() > 0 )
108 out <<
text.ToStdString();
141 const char* examplesEnv = std::getenv(
"DIPTRACE_VIEWER_EXAMPLES_DIR" );
143 return examplesEnv && *examplesEnv ? examplesEnv :
"/home/seth/Downloads/DipTrace Viewer/Examples";
148 std::set<SCH_SCREEN*> seenScreens;
155 if( !screen || !seenScreens.insert( screen ).second )
160 if( item->Type() == aType )
170 std::set<SCH_SCREEN*> seenScreens;
176 if( !screen || !seenScreens.insert( screen ).second )
180 return static_cast<int>( seenScreens.size() );
200 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
201 maxPins = std::max( maxPins,
static_cast<int>( symbol->
GetPins().size() ) );
221 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
224 return fpField ? fpField->
GetText() : wxString();
246 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
247 return sheetPath.Last() ? sheetPath.Last()->GetName() : wxString();
258 aLeft = aRight = aUp = aDown = 0;
276 switch(
pin->GetOrientation() )
298 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
310 if( label->
GetText() == aText )
325 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
337 if( label->
GetText().StartsWith( aPrefix ) )
352 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
362 static_cast<void>( item );
386 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
392 if( !refField || !valField )
417 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
421 return field ? field->
GetText() : wxString();
443 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
519 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
531 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
539 static int DipTraceMmToSchIU(
double aMm ) {
return static_cast<int>( std::lround( aMm * 10000.0 ) ); }
552 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
569 if( color.
r > 0.01 || color.
g > 0.01 || color.
b < 0.99 )
580 if( ( p0 == aStart && p1 == aEnd ) || ( p0 == aEnd && p1 == aStart ) )
664 std::vector<int> units;
668 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
680 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
681 units.push_back( symbol->
GetUnit() );
685 std::sort( units.begin(), units.end() );
703 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
716 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
728 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes && symbol->
GetUnit() == aUnit )
729 return static_cast<int>( symbol->
GetLibPins().size() );
741 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
753 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes || symbol->
GetUnit() != aUnit )
756 std::set<wxString> names;
759 names.insert(
pin->GetName() );
775 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
785 static_cast<void>( item );
808 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
816 return VECTOR2I( INT_MAX, INT_MAX );
834 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
838 return static_cast<int>( field->GetHorizJustify() );
852 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
877 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
889 if( !label->
GetText().StartsWith( aPrefix ) )
916 for( wxXmlNode* n = aNode; n; n = n->GetNext() )
918 if( n->GetType() == wxXML_TEXT_NODE && n->GetContent().Contains( aNeedle ) )
930 if( !wxFileExists( aXmlPath ) )
935 if( !doc.Load( aXmlPath ) )
938 wxXmlNode* root = doc.GetRoot();
940 if( !root || root->GetName() !=
"Source" )
943 wxXmlNode* schematicNode =
nullptr;
945 for( wxXmlNode* child = root->GetChildren(); child; child = child->GetNext() )
947 if( child->GetType() == wxXML_ELEMENT_NODE && child->GetName() ==
"Schematic" )
949 schematicNode = child;
958 int netPortCount = 0;
960 std::vector<wxXmlNode*> stack = { schematicNode };
962 while( !stack.empty() )
964 wxXmlNode* node = stack.back();
967 if( !node || node->GetType() != wxXML_ELEMENT_NODE )
970 if( node->GetName() ==
"Part" )
979 else if( node->GetName() ==
"Sheet" )
984 for( wxXmlNode* child = node->GetChildren(); child; child = child->GetNext() )
986 stack.push_back( child );
1012 wxFileName genLib( aFilePath );
1013 genLib.SetName( genLib.GetName() + wxT(
"-diptrace-import" ) );
1014 genLib.SetExt( wxT(
"kicad_sym" ) );
1016 if( genLib.FileExists() )
1017 wxRemoveFile( genLib.GetFullPath() );
Reporter that records the severity of every message so a test can assert that an import ran without w...
std::vector< std::pair< SEVERITY, wxString > > m_messages
std::string MessagesOfSeverity(int aSeverityMask) const
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
int CountOfSeverity(int aSeverityMask) const
bool HasMessage() const override
Returns true if any messages were reported.
FILL_T GetFillMode() const
SHAPE_POLY_SET & GetPolyShape()
const EDA_ANGLE & GetTextAngle() const
virtual const wxString & GetText() const
Return the string associated with the text object.
EE_TYPE OfType(KICAD_T aType) const
A color representation with 4 components: red, green, blue, alpha.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
std::vector< SCH_PIN * > GetPins() const override
Holds all the data relating to one schematic.
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
A SCH_IO derivation for loading DipTrace schematic files (.dch).
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,...
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
STROKE_PARAMS GetStroke() const override
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.
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
VECTOR2I GetPosition() const override
std::vector< SCH_PIN * > GetLibPins() const
Populate a vector with all the pins from the library object that match the current unit and bodyStyle...
int GetUnitCount() const override
Return the number of units per package of the symbol.
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.
VECTOR2I GetPosition() const override
Represent a set of closed polygons.
int TotalVertices() const
Return total number of vertices stored in the set.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
KIGFX::COLOR4D GetColor() const
virtual bool GetShowPinNames() const
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
@ 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.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
int netPortCount
Parts with PartType="Net Port" (imported as global labels)
std::vector< int > UnitsForRefdesOnSheet(const wxString &aRefdes, const wxString &aSheetName)
Return the units of all symbols matching the resolved reference on the named sheet.
int FieldHorizJustify(const wxString &aRefdes, FIELD_T aFieldType)
The horizontal justification of a field (by type) of the first matching reference,...
int RefValueFieldSeparation(const wxString &aRefdes)
Distance between the reference and value field positions of the first symbol matching the reference d...
std::set< wxString > LibPinNamesForRefdesUnitOnSheet(const wxString &aRefdes, const wxString &aSheetName, int aUnit)
Return the library pin names for a specific placed unit on a sheet.
void PinOrientationCounts(const wxString &aRefdes, int &aLeft, int &aRight, int &aUp, int &aDown)
Count the pin orientations of the first symbol matching the reference designator, read from its embed...
std::string GetTestDataDir()
int LibPinCountForRefdesUnitOnSheet(const wxString &aRefdes, const wxString &aSheetName, int aUnit)
Return the placed symbol's resolved library pin count for a specific unit on a sheet.
static int DipTraceMmToSchIU(double aMm)
static bool XmlSubtreeContains(wxXmlNode *aNode, const wxString &aNeedle)
void RemoveGeneratedLibrary(const std::string &aFilePath)
static VECTOR2I DipTraceXmlSheetPointToKiCad(double aXmm, double aYmm)
int ShowsPinNames(const wxString &aRefdes)
Whether the embedded library symbol of the first matching reference shows its pin names.
int CountOpenPolysWithPointCountForRefdes(const wxString &aRefdes, int aPointCount)
int CountImportedScreens()
int MaxPinCountForRefdes(const wxString &aRefdes)
std::unique_ptr< SCHEMATIC > m_schematic
SETTINGS_MANAGER m_manager
int CountLabelsOnSheet(const wxString &aText, const wxString &aSheetName)
Count global labels whose text matches exactly on the sheet with the given name.
int CountFilledPolysForRefdes(const wxString &aRefdes)
wxString GetFootprintForRefdes(const wxString &aRefdes)
int UnitCountForRefdes(const wxString &aRefdes)
Return the unit count of the first library symbol matching the resolved reference.
wxString GetSheetNameForRefdes(const wxString &aRefdes)
Return the DipTrace sheet name carrying the symbol with the given reference, or empty.
bool HasLabelOnSheet(const wxString &aText, const wxString &aSheetName)
True when a global label whose text matches exists on the sheet with the given name.
DIPTRACE_SCH_IMPORT_FIXTURE()
std::string GetViewerExamplesDir()
wxString GetFieldValueForRefdes(const wxString &aRefdes, const wxString &aFieldName)
The text of a named field on the first symbol matching the reference designator, or an empty string w...
double ValueFieldAngleDegrees(const wxString &aRefdes)
The value-field text angle in degrees for the first symbol matching the reference designator,...
bool HasLabelStartingWithOnSheet(const wxString &aPrefix, const wxString &aSheetName)
True when any global label on the named sheet has text beginning with the given prefix.
VECTOR2I FieldPosForRefdes(const wxString &aRefdes, FIELD_T aFieldType)
The position of a field (by type) of the first symbol matching the reference, or a sentinel far-away ...
bool LabelConnectsToWireOnSheet(const wxString &aPrefix, const wxString &aSheetName)
True when a global label whose text starts with the prefix sits on a wire endpoint on the named sheet...
SCH_SHEET * LoadDipTraceSchematic(const std::string &aFilePath)
int CountJunctionsOnSheet(const wxString &aSheetName)
Count junctions on the sheet with the given name.
int CountSymbolShapes(const wxString &aRefdes, SHAPE_T aShapeType)
Count the library-symbol graphic shapes of a given type for the first matching reference.
int CountItemsOfType(KICAD_T aType)
int CountSheetGraphicLines(const wxString &aSheetName, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth)
int CountSymbolsForRefdesOnSheet(const wxString &aRefdes, const wxString &aSheetName)
int CountLinesOnSheet(const wxString &aSheetName)
Count SCH_LINE items on the DipTrace sheet with the given name.
DIPTRACE_COUNTING_REPORTER m_reporter
bool LoadDchXmlCounts(const std::string &aXmlPath, DCH_XML_COUNTS &aCounts)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
VECTOR2< int32_t > VECTOR2I