Skip to content

Commit

Permalink
Fixed issue #1592 (DXF reader issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Jan 20, 2024
1 parent f1f92e5 commit 0f3d9b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,9 @@ De Boor algorithm for NURBS
static db::DPoint
b_spline_point (double x, const std::vector<std::pair<db::DPoint, double> > &control_points, int p, const std::vector<double> &t, int &k)
{
k = (int) (std::lower_bound (t.begin (), t.end (), x - 1e-6) - t.begin ());
double eps = 1e-12 * (fabs (t.back ()) + fabs (t.front ()));

k = (int) (std::lower_bound (t.begin (), t.end (), x - eps) - t.begin ());
--k;
if (k < p) {
k = p;
Expand Down Expand Up @@ -882,6 +884,12 @@ spline_interpolate (std::list<db::DPoint> &curve_points,

db::DPoint s1 = b_spline_point (t_start + 0.5 * dt, control_points, degree, knots, k1);
db::DPoint s2 = b_spline_point (t_start + 1.5 * dt, control_points, degree, knots, k2);
if (s1.to_string () == "-2.60657790172,-1.78843428245") {
tl::info << "@@@ BANG!";
}
if (s2.to_string () == "-2.60657790172,-1.78843428245") {
tl::info << "@@@ BANG!";
}

db::DVector p1 (s1, *current_curve_point);
db::DVector p2 (*pm, s1);
Expand Down Expand Up @@ -1740,6 +1748,7 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
std::string layer;
unsigned int xy_flag = 0;
int degree = 1;
int flags = 0;

while ((g = read_group_code ()) != 0) {
if (g == 8) {
Expand All @@ -1763,9 +1772,9 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector

} else if (g == 70) {

int flags = read_int32 ();
if (flags != 8 && flags != 12) {
warn ("Invalid SPLINE flag (code 70): " + tl::to_string (flags) + ". Only types 8 (non-rational) and 12 (rational) are supported currently.");
flags = read_int32 ();
if ((flags & 2) != 0) {
warn ("Invalid SPLINE flag (code 70): " + tl::to_string (flags) + ". Periodic splines not supported currently.");
}

} else if (g == 71) {
Expand Down Expand Up @@ -1814,6 +1823,13 @@ DXFReader::read_entities (db::Layout &layout, db::Cell &cell, const db::DVector
}
}

} else if ((flags & 1) && m_polyline_mode == 2) {

// create a polygon for the spline
db::DSimplePolygon p;
p.assign_hull (new_points.begin (), new_points.end (), tt);
cell.shapes (ll.second).insert (safe_from_double (p));

} else {

// create a path with width 0 for the spline
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/streamers/dxf/unit_tests/dbDXFReaderTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,20 @@ TEST(35c)
db::DXFReaderOptions opt;
run_test_public (_this, "issue_1422c.dxf", "issue_1422c_au.gds.gz", opt);
}

// issue #1592, polyline mode 2
TEST(36a)
{
db::DXFReaderOptions opt;
opt.dbu = 1e-5;
opt.polyline_mode = 2;
run_test_public (_this, "issue_1592.dxf.gz", "issue_1592a_au.oas.gz", opt, true);
}

// issue #1592
TEST(36b)
{
db::DXFReaderOptions opt;
opt.dbu = 1e-5;
run_test_public (_this, "issue_1592.dxf.gz", "issue_1592b_au.oas.gz", opt, true);
}
Binary file added testdata/dxf/issue_1592.dxf.gz
Binary file not shown.
Binary file added testdata/dxf/issue_1592a_au.oas.gz
Binary file not shown.
Binary file added testdata/dxf/issue_1592b_au.oas.gz
Binary file not shown.

0 comments on commit 0f3d9b9

Please sign in to comment.