20#ifndef TEST_DIPTRACE_SCH_IMPORT_FIXTURE_H
21#define TEST_DIPTRACE_SCH_IMPORT_FIXTURE_H
63#include <wx/xml/xml.h>
85 if( sev & aSeverityMask )
94 std::ostringstream out;
98 if( !( sev & aSeverityMask ) )
101 if( out.tellp() > 0 )
104 out <<
text.ToStdString();
137 const char* examplesEnv = std::getenv(
"DIPTRACE_VIEWER_EXAMPLES_DIR" );
139 return examplesEnv && *examplesEnv ? examplesEnv :
"/home/seth/Downloads/DipTrace Viewer/Examples";
144 std::set<SCH_SCREEN*> seenScreens;
151 if( !screen || !seenScreens.insert( screen ).second )
156 if( item->Type() == aType )
166 std::set<SCH_SCREEN*> seenScreens;
172 if( !screen || !seenScreens.insert( screen ).second )
176 return static_cast<int>( seenScreens.size() );
196 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
197 maxPins = std::max( maxPins,
static_cast<int>( symbol->
GetPins().size() ) );
217 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
220 return fpField ? fpField->
GetText() : wxString();
242 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
243 return sheetPath.Last() ? sheetPath.Last()->GetName() : wxString();
254 aLeft = aRight = aUp = aDown = 0;
272 switch(
pin->GetOrientation() )
294 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
306 if( label->
GetText() == aText )
321 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
333 if( label->
GetText().StartsWith( aPrefix ) )
348 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
358 static_cast<void>( item );
382 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
388 if( !refField || !valField )
413 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
417 return field ? field->
GetText() : wxString();
439 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
515 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
527 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
535 static int DipTraceMmToSchIU(
double aMm ) {
return static_cast<int>( std::lround( aMm * 10000.0 ) ); }
548 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
565 if( color.
r > 0.01 || color.
g > 0.01 || color.
b < 0.99 )
576 if( ( p0 == aStart && p1 == aEnd ) || ( p0 == aEnd && p1 == aStart ) )
660 std::vector<int> units;
664 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
676 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
677 units.push_back( symbol->
GetUnit() );
681 std::sort( units.begin(), units.end() );
699 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes )
712 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
724 if( symbol->
GetRef( &sheetPath,
false ) == aRefdes && symbol->
GetUnit() == aUnit )
725 return static_cast<int>( symbol->
GetLibPins().size() );
737 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
749 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes || symbol->
GetUnit() != aUnit )
752 std::set<wxString> names;
755 names.insert(
pin->GetName() );
771 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
781 static_cast<void>( item );
804 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
812 return VECTOR2I( INT_MAX, INT_MAX );
830 if( symbol->
GetRef( &sheetPath,
false ) != aRefdes )
834 return static_cast<int>( field->GetHorizJustify() );
848 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
873 if( !sheetPath.Last() || sheetPath.Last()->GetName() != aSheetName )
885 if( !label->
GetText().StartsWith( aPrefix ) )
912 for( wxXmlNode* n = aNode; n; n = n->GetNext() )
914 if( n->GetType() == wxXML_TEXT_NODE && n->GetContent().Contains( aNeedle ) )
926 if( !wxFileExists( aXmlPath ) )
931 if( !doc.Load( aXmlPath ) )
934 wxXmlNode* root = doc.GetRoot();
936 if( !root || root->GetName() !=
"Source" )
939 wxXmlNode* schematicNode =
nullptr;
941 for( wxXmlNode* child = root->GetChildren(); child; child = child->GetNext() )
943 if( child->GetType() == wxXML_ELEMENT_NODE && child->GetName() ==
"Schematic" )
945 schematicNode = child;
954 int netPortCount = 0;
956 std::vector<wxXmlNode*> stack = { schematicNode };
958 while( !stack.empty() )
960 wxXmlNode* node = stack.back();
963 if( !node || node->GetType() != wxXML_ELEMENT_NODE )
966 if( node->GetName() ==
"Part" )
975 else if( node->GetName() ==
"Sheet" )
980 for( wxXmlNode* child = node->GetChildren(); child; child = child->GetNext() )
982 stack.push_back( child );
1008 wxFileName genLib( aFilePath );
1009 genLib.SetName( genLib.GetName() + wxT(
"-diptrace-import" ) );
1010 genLib.SetExt( wxT(
"kicad_sym" ) );
1012 if( genLib.FileExists() )
1013 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()
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual EDA_ANGLE GetTextAngle() const
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