35namespace utf = boost::unit_test;
41wxString plotFilledShape(
const COLOR4D& aColor,
bool aMirrored =
false,
bool aFitToBoard =
false )
44 const wxString tempFile = tempDir.CreateChildFileStr(
"plot.svg" );
70 shapeOrigin =
VECTOR2I( 20000, 20000 );
79 wxFFile fileForReading( tempFile, wxT(
"r" ) );
83 fileForReading.ReadAll( &content );
84 fileForReading.Close();
91std::set<std::string> fillOpacities(
const wxString& aSvg )
93 const std::string doc = aSvg.ToStdString();
94 const std::string key =
"fill-opacity:";
95 std::set<std::string> values;
97 for(
size_t pos = doc.find( key ); pos != std::string::npos; pos = doc.find( key, pos + 1 ) )
99 size_t start = pos + key.size();
100 size_t end = doc.find_first_not_of(
"0123456789.", start );
102 values.insert( doc.substr( start,
end - start ) );
109std::set<std::string> strokeOpacities(
const wxString& aSvg )
111 const std::string doc = aSvg.ToStdString();
112 const std::string key =
"stroke-opacity:";
113 std::set<std::string> values;
115 for(
size_t pos = doc.find( key ); pos != std::string::npos; pos = doc.find( key, pos + 1 ) )
117 size_t start = pos + key.size();
118 size_t end = doc.find_first_not_of(
"0123456789.", start );
120 values.insert( doc.substr( start,
end - start ) );
133 SVG_PLOT(
const wxString& aSvg )
137 if( !document.has_value() )
138 BOOST_FAIL( document.error() );
140 m_document = std::make_unique<wxXmlDocument>( std::move( *document ) );
142 tl::expected<KI_TEST::SVG_VIEWBOX, wxString> viewBox =
KI_TEST::ParseViewBox( *m_document->GetRoot() );
144 if( !viewBox.has_value() )
145 BOOST_FAIL( viewBox.error() );
147 m_viewBox = *viewBox;
152 const KI_TEST::SVG_VIEWBOX& ViewBox()
const {
return m_viewBox; }
154 wxString RectAttribute(
const wxString& aName )
const {
return m_rect->GetAttribute( aName ); }
157 std::unique_ptr<wxXmlDocument> m_document;
158 KI_TEST::SVG_VIEWBOX m_viewBox = {};
159 const wxXmlNode* m_rect =
nullptr;
170 std::set<std::string> values = fillOpacities( plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.5 ) ) );
180 std::set<std::string> values = fillOpacities( plotFilledShape(
COLOR4D( 0.0, 0.0, 1.0, 1.0 ) ) );
182 BOOST_REQUIRE_EQUAL( values.count(
"1.0000" ), 1 );
185 for(
const std::string& value : values )
192 const std::vector<std::pair<double, std::string>> cases = {
193 { 0.0,
"0.0000" }, { 0.25,
"0.2500" }, { 0.5,
"0.5000" }, { 0.75,
"0.7500" }, { 1.0,
"1.0000" }
196 for(
const auto& [alpha,
expected] : cases )
200 std::set<std::string> values = fillOpacities( plotFilledShape(
COLOR4D( 0.5, 0.5, 0.5, alpha ) ) );
205 for(
const auto& [otherAlpha, other] : cases )
207 if( other !=
expected && other !=
"1.0000" )
217 const wxString svg = plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.25 ) );
218 std::set<std::string> values = strokeOpacities( svg );
240 const bool isMirrored =
false;
241 const bool isFitToBoard =
false;
243 const wxString svg = plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.25 ), isMirrored, isFitToBoard );
244 const SVG_PLOT svgPlot( svg );
255 BOOST_TEST( svgPlot.RectAttribute( wxT(
"x" ) ) == wxT(
"0.254000" ) );
261 const bool isMirrored =
true;
262 const bool isFitToBoard =
false;
263 const wxString svg = plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.25 ), isMirrored, isFitToBoard );
264 const SVG_PLOT svgPlot( svg );
275 BOOST_TEST( svgPlot.RectAttribute( wxT(
"x" ) ) == wxT(
"-10.414000" ) );
281 const bool isMirrored =
false;
282 const bool isFitToBoard =
true;
283 const wxString svg = plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.25 ), isMirrored, isFitToBoard );
284 const SVG_PLOT svgPlot( svg );
295 BOOST_TEST( svgPlot.RectAttribute( wxT(
"x" ) ) == wxT(
"50.800000" ) );
301 const bool isMirrored =
true;
302 const bool isFitToBoard =
true;
303 const wxString svg = plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.25 ), isMirrored, isFitToBoard );
304 const SVG_PLOT svgPlot( svg );
315 BOOST_TEST( svgPlot.RectAttribute( wxT(
"x" ) ) == wxT(
"-60.960000" ) );
A color representation with 4 components: red, green, blue, alpha.
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)
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb values,...
virtual bool StartPlot(const wxString &aPageNumber) override
Create SVG file header.
virtual void SetPlotBBox(const BOX2I &aBBoxIU) override
Set an explicit bounding box for the plotted content (in IUs).
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
virtual bool EndPlot() override
@ FILLED_SHAPE
Fill with object color.
const wxXmlNode * FindFirstRect(const wxXmlNode &aNode)
Find the first <rect> element in the given XML node's descendants.
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).
Plotting engines similar to ps (PostScript, Gerber, svg)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
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)
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
static const auto kSvgValTol
BOOST_AUTO_TEST_CASE(FillOpacityMatchesColorAlpha)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I