30#include <boost/test/unit_test.hpp>
43#include <wx/mstream.h>
51 m_symbol = std::make_unique<LIB_SYMBOL>( wxT(
"TestSymbol" ),
nullptr );
56 void AddPin(
int x,
int y,
const wxString&
name,
const wxString& number )
58 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>(
m_symbol.get() );
61 pin->SetNumber( number );
72 m_symbol->AddDrawItem( rect.release() );
84 void AddPolyline(
const std::vector<std::pair<int, int>>& points )
89 for(
const auto& pt : points )
92 m_symbol->AddDrawItem( poly.release() );
100 arc->SetArcAngleAndEnd( endAngle - startAngle );
102 m_symbol->AddDrawItem( arc.release() );
107 std::unique_ptr<SCH_TEXT> txt = std::make_unique<SCH_TEXT>(
VECTOR2I(
schIUScale.MilsToIU( x ),
111 m_symbol->AddDrawItem( txt.release() );
123 if( aUnit && item.GetUnit() && item.GetUnit() != aUnit )
126 if( aBodyStyle && item.GetBodyStyle() && item.GetBodyStyle() != aBodyStyle )
130 bbox = item.GetBoundingBox();
132 bbox.
Merge( item.GetBoundingBox() );
143 return wxEmptyString;
152 std::unique_ptr<SVG_PLOTTER> plotter = std::make_unique<SVG_PLOTTER>();
153 plotter->SetRenderSettings( &renderSettings );
159 plotter->SetPageSettings( pageInfo );
160 plotter->SetColorMode(
true );
163 plotter->SetViewport( plot_offset,
schIUScale.IU_PER_MILS / 10, 1.0,
false );
164 plotter->SetCreator( wxT(
"Eeschema-SVG-Test" ) );
166 wxFileName tempFile( wxFileName::CreateTempFileName( wxT(
"kicad_test_svg" ) ) );
168 if( !plotter->OpenFile( tempFile.GetFullPath() ) )
170 wxRemoveFile( tempFile.GetFullPath() );
171 return wxEmptyString;
177 plotter->StartPlot( wxT(
"1" ) );
179 constexpr bool background =
true;
180 m_symbol->Plot( plotter.get(), background, plotOpts, aUnit, aBodyStyle,
VECTOR2I( 0, 0 ),
false );
181 m_symbol->Plot( plotter.get(), !background, plotOpts, aUnit, aBodyStyle,
VECTOR2I( 0, 0 ),
false );
182 m_symbol->PlotFields( plotter.get(), !background, plotOpts, aUnit, aBodyStyle,
VECTOR2I( 0, 0 ),
false );
187 wxFFile file( tempFile.GetFullPath(), wxT(
"rb" ) );
190 if( file.IsOpened() )
191 file.ReadAll( &content );
193 wxRemoveFile( tempFile.GetFullPath() );
209 AddPin( 0, 0, wxT(
"VCC" ), wxT(
"1" ) );
210 AddPin( 0, 100, wxT(
"GND" ), wxT(
"2" ) );
211 AddPin( 0, 200, wxT(
"OUT" ), wxT(
"3" ) );
213 wxString svg = PlotToSvgString();
215 BOOST_CHECK( !svg.IsEmpty() );
216 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
217 BOOST_CHECK( svg.Contains( wxT(
"</svg>" ) ) );
219 BOOST_CHECK( svg.Contains( wxT(
"<path" ) ) || svg.Contains( wxT(
"<line" ) ) );
228 AddRectangle( -100, -100, 100, 100 );
230 wxString svg = PlotToSvgString();
232 BOOST_CHECK( !svg.IsEmpty() );
233 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
235 BOOST_CHECK( svg.Contains( wxT(
"<path" ) ) || svg.Contains( wxT(
"<rect" ) ) );
244 AddCircle( 0, 0, 50 );
246 wxString svg = PlotToSvgString();
248 BOOST_CHECK( !svg.IsEmpty() );
249 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
251 BOOST_CHECK( svg.Contains( wxT(
"<circle" ) ) || svg.Contains( wxT(
"<ellipse" ) )
252 || svg.Contains( wxT(
"<path" ) ) );
261 AddPolyline( { { 0, 0 }, { 50, 50 }, { 100, 0 }, { 100, 100 } } );
263 wxString svg = PlotToSvgString();
265 BOOST_CHECK( !svg.IsEmpty() );
266 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
268 BOOST_CHECK( svg.Contains( wxT(
"<path" ) ) || svg.Contains( wxT(
"<polyline" ) ) );
277 AddText( 0, 0, wxT(
"Test Label" ) );
279 wxString svg = PlotToSvgString();
281 BOOST_CHECK( !svg.IsEmpty() );
282 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
284 BOOST_CHECK( svg.Contains( wxT(
"<text" ) ) || svg.Contains( wxT(
"<path" ) ) );
293 AddPin( 0, 0, wxT(
"PIN1" ), wxT(
"1" ) );
294 AddPin( 200, 0, wxT(
"PIN2" ), wxT(
"2" ) );
296 BOX2I bbox = GetSymbolBoundingBox();
309 AddRectangle( -50, -50, 50, 50 );
311 BOX2I bbox = GetSymbolBoundingBox();
314 int expectedWidth =
schIUScale.MilsToIU( 100 );
315 int expectedHeight =
schIUScale.MilsToIU( 100 );
328 AddCircle( 0, 0,
radius );
330 BOX2I bbox = GetSymbolBoundingBox();
346 AddRectangle( -100, -150, 100, 150 );
347 AddPin( -200, -100, wxT(
"A" ), wxT(
"1" ) );
348 AddPin( -200, 0, wxT(
"B" ), wxT(
"2" ) );
349 AddPin( -200, 100, wxT(
"C" ), wxT(
"3" ) );
350 AddPin( 200, -100, wxT(
"Y" ), wxT(
"4" ) );
351 AddPin( 200, 0, wxT(
"Z" ), wxT(
"5" ) );
352 AddPin( 200, 100, wxT(
"W" ), wxT(
"6" ) );
353 AddText( 0, 0, wxT(
"IC" ) );
355 wxString svg = PlotToSvgString();
357 BOOST_CHECK( !svg.IsEmpty() );
358 BOOST_CHECK( svg.Contains( wxT(
"<svg" ) ) );
359 BOOST_CHECK( svg.Contains( wxT(
"</svg>" ) ) );
365 while( ( pos = svg.find( wxT(
"<path" ), pos ) ) != wxString::npos )
372 BOOST_CHECK( pathCount >= 1 );
384 int rW = 255, gW = 0, bW = 0;
385 int rB = 255, gB = 0, bB = 0;
390 int avgDiff = ( diffR + diffG + diffB ) / 3;
392 int alpha = 255 - avgDiff;
404 int rW = 255, gW = 255, bW = 255;
405 int rB = 0, gB = 0, bB = 0;
410 int avgDiff = ( diffR + diffG + diffB ) / 3;
412 int alpha = 255 - avgDiff;
427 int rW = 255, gW = 128, bW = 128;
428 int rB = 128, gB = 0, bB = 0;
433 int avgDiff = ( diffR + diffG + diffB ) / 3;
435 int alpha = 255 - avgDiff;
438 BOOST_CHECK( alpha > 120 && alpha < 140 );
450 BOX2I bbox = GetSymbolBoundingBox();
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr size_type GetHeight() const
constexpr const Vec & GetOrigin() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetDefaultPenWidth(int aWidth)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
Base class for any item which can be embedded within the SCHEMATIC container class,...
void LoadColors(const COLOR_SETTINGS *aSettings) override
Simple container to manage line stroke parameters.
void AddText(int x, int y, const wxString &text)
void AddArc(int cx, int cy, int radius, EDA_ANGLE startAngle, EDA_ANGLE endAngle)
SYMBOL_CLIPBOARD_FIXTURE()
void AddPin(int x, int y, const wxString &name, const wxString &number)
void AddPolyline(const std::vector< std::pair< int, int > > &points)
~SYMBOL_CLIPBOARD_FIXTURE()=default
wxString PlotToSvgString(int aUnit=0, int aBodyStyle=0)
void AddRectangle(int x1, int y1, int x2, int y2)
std::unique_ptr< LIB_SYMBOL > m_symbol
void AddCircle(int cx, int cy, int radius)
BOX2I GetSymbolBoundingBox(int aUnit=0, int aBodyStyle=0)
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Plotting engines similar to ps (PostScript, Gerber, svg)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
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.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I