25#include "tl/expected.hpp"
26#include <boost/test/unit_test.hpp>
29#include <wx/mstream.h>
42#include <wx/xml/xml.h>
50 m_symbol = std::make_unique<LIB_SYMBOL>( wxT(
"TestSymbol" ),
nullptr );
55 void AddPin(
int x,
int y,
const wxString&
name,
const wxString& number )
57 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>(
m_symbol.get() );
60 pin->SetNumber( number );
71 m_symbol->AddDrawItem( rect.release() );
83 void AddPolyline(
const std::vector<std::pair<int, int>>& points )
88 for(
const auto& pt : points )
91 m_symbol->AddDrawItem( poly.release() );
99 arc->SetArcAngleAndEnd( endAngle - startAngle );
101 m_symbol->AddDrawItem( arc.release() );
106 std::unique_ptr<SCH_TEXT> txt = std::make_unique<SCH_TEXT>(
VECTOR2I(
schIUScale.MilsToIU( x ),
110 m_symbol->AddDrawItem( txt.release() );
124 wxFileName tempFile( wxFileName::CreateTempFileName( wxT(
"kicad_test_svg" ) ) );
127 tempFile.GetFullPath() ) )
129 wxRemoveFile( tempFile.GetFullPath() );
130 return wxEmptyString;
133 wxFFile file( tempFile.GetFullPath(), wxT(
"rb" ) );
136 if( file.IsOpened() )
137 file.ReadAll( &content );
139 wxRemoveFile( tempFile.GetFullPath() );
155 AddPin( 0, 0, wxT(
"VCC" ), wxT(
"1" ) );
156 AddPin( 0, 100, wxT(
"GND" ), wxT(
"2" ) );
157 AddPin( 0, 200, wxT(
"OUT" ), wxT(
"3" ) );
159 wxString svg = PlotToSvgString();
161 BOOST_CHECK( !svg.IsEmpty() );
162 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
163 BOOST_CHECK( svg.Contains( wxT(
"</svg>" ) ) );
165 BOOST_CHECK( svg.Contains( wxT(
"<path" ) ) || svg.Contains( wxT(
"<line" ) ) );
174 AddRectangle( -100, -100, 100, 100 );
176 wxString svg = PlotToSvgString();
178 BOOST_CHECK( !svg.IsEmpty() );
179 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
181 BOOST_CHECK( svg.Contains( wxT(
"<path" ) ) || svg.Contains( wxT(
"<rect" ) ) );
190 AddCircle( 0, 0, 50 );
192 wxString svg = PlotToSvgString();
194 BOOST_CHECK( !svg.IsEmpty() );
195 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
197 BOOST_CHECK( svg.Contains( wxT(
"<circle" ) ) || svg.Contains( wxT(
"<ellipse" ) )
198 || svg.Contains( wxT(
"<path" ) ) );
207 AddPolyline( { { 0, 0 }, { 50, 50 }, { 100, 0 }, { 100, 100 } } );
209 wxString svg = PlotToSvgString();
211 BOOST_CHECK( !svg.IsEmpty() );
212 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
214 BOOST_CHECK( svg.Contains( wxT(
"<path" ) ) || svg.Contains( wxT(
"<polyline" ) ) );
223 AddText( 0, 0, wxT(
"Test Label" ) );
225 wxString svg = PlotToSvgString();
227 BOOST_CHECK( !svg.IsEmpty() );
228 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
230 BOOST_CHECK( svg.Contains( wxT(
"<text" ) ) || svg.Contains( wxT(
"<path" ) ) );
240 AddRectangle( -100, -150, 100, 150 );
241 AddPin( -200, -100, wxT(
"A" ), wxT(
"1" ) );
242 AddPin( -200, 0, wxT(
"B" ), wxT(
"2" ) );
243 AddPin( -200, 100, wxT(
"C" ), wxT(
"3" ) );
244 AddPin( 200, -100, wxT(
"Y" ), wxT(
"4" ) );
245 AddPin( 200, 0, wxT(
"Z" ), wxT(
"5" ) );
246 AddPin( 200, 100, wxT(
"W" ), wxT(
"6" ) );
247 AddText( 0, 0, wxT(
"IC" ) );
249 wxString svg = PlotToSvgString();
251 BOOST_CHECK( !svg.IsEmpty() );
252 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
253 BOOST_CHECK( svg.Contains( wxT(
"</svg>" ) ) );
259 while( ( pos = svg.find( wxT(
"<path" ), pos ) ) != wxString::npos )
266 BOOST_CHECK( pathCount >= 1 );
284 AddRectangle( -50, -50, 50, 50 );
286 const wxString svg = PlotToSvgString();
constexpr EDA_IU_SCALE schIUScale
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetDefaultPenWidth(int aWidth)
void LoadColors(const COLOR_SETTINGS *aSettings) override
Simple container to manage line stroke parameters.
SYMBOL_SVG_EXPORT_FIXTURE()
~SYMBOL_SVG_EXPORT_FIXTURE()=default
wxString PlotToSvgString(int aUnit=0, int aBodyStyle=0)
void AddPolyline(const std::vector< std::pair< int, int > > &points)
void AddText(int x, int y, const wxString &text)
void AddCircle(int cx, int cy, int radius)
void AddPin(int x, int y, const wxString &name, const wxString &number)
std::unique_ptr< LIB_SYMBOL > m_symbol
void AddRectangle(int x1, int y1, int x2, int y2)
void AddArc(int cx, int cy, int radius, EDA_ANGLE startAngle, EDA_ANGLE endAngle)
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
KICOMMON_API int Mils2mm(double aVal)
Convert mils to mm.
tl::expected< wxXmlDocument, wxString > LoadSvg(const wxString &aSvg)
tl::expected< SVG_VIEWBOX, wxString > ParseViewBox(const wxXmlNode &aRoot)
Parse the four numbers of the SVG viewBox attribute (min-x, min-y, width, height).
bool PlotSymbolToSVG(LIB_SYMBOL &aDrawSymbol, LIB_SYMBOL &aFieldsSymbol, int aUnit, int aBodyStyle, const BOX2I &aBBox, SCH_RENDER_SETTINGS &aRenderSettings, bool aBlackAndWhite, const wxString &aFileName, REPORTER *aReporter)
Plot a single symbol variant (unit and body style) to an SVG file.
BOX2I GetSymbolPlotBBox(const LIB_SYMBOL &aSymbol, int aUnit, int aBodyStyle, bool aIncludeHiddenFields)
Compute the bounding box used to size a symbol SVG plot.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
BOOST_AUTO_TEST_CASE(SvgExport_ContainsPins)
Test that a symbol with pins produces SVG output.
VECTOR2< int32_t > VECTOR2I