better default grid

supermerill/SuperSlicer#1218
This commit is contained in:
remi durand 2021-06-01 17:52:58 +02:00
parent 51445fbb36
commit dc95440c3d
3 changed files with 76 additions and 15 deletions

View File

@ -81,15 +81,40 @@ void Bed_2D::repaint(const std::vector<Vec2d>& shape)
// draw grid // draw grid
auto step = 10; // 1cm grid auto step = 10; // 1cm grid
Polylines polylines; Polylines polylines;
for (auto x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step) { Polylines polylines_big;
Polylines polylines_small;
int idx = 1;
for (double x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step, ++idx) {
if (idx % 10 == 0)
polylines_big.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) }));
else if (idx % 2 == 1)
polylines_small.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) }));
else
polylines.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) })); polylines.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) }));
} }
for (auto y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step) { idx = 1;
for (double y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step, ++idx) {
if (idx % 10 == 0)
polylines_big.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) }));
else if (idx % 2 == 1)
polylines_small.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) }));
else
polylines.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) })); polylines.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) }));
} }
polylines = intersection_pl(polylines, (Polygons)bed_polygon); polylines = intersection_pl(polylines, (Polygons)bed_polygon);
polylines_big = intersection_pl(polylines_big, (Polygons)bed_polygon);
polylines_small = intersection_pl(polylines_small, (Polygons)bed_polygon);
dc.SetPen(wxPen(wxColour(230, 230, 230), 1, wxPENSTYLE_SOLID)); dc.SetPen(wxPen(wxColour(230, 230, 230), 1, wxPENSTYLE_SOLID));
for (auto pl : polylines_small)
{
for (size_t i = 0; i < pl.points.size() - 1; i++) {
Point pt1 = to_pixels(unscale(pl.points[i]), ch);
Point pt2 = to_pixels(unscale(pl.points[i + 1]), ch);
dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
}
}
dc.SetPen(wxPen(wxColour(230, 230, 230), 2, wxPENSTYLE_SOLID));
for (auto pl : polylines) for (auto pl : polylines)
{ {
for (size_t i = 0; i < pl.points.size() - 1; i++) { for (size_t i = 0; i < pl.points.size() - 1; i++) {
@ -98,6 +123,15 @@ void Bed_2D::repaint(const std::vector<Vec2d>& shape)
dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1)); dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
} }
} }
dc.SetPen(wxPen(wxColour(230, 230, 230), 3, wxPENSTYLE_SOLID));
for (auto pl : polylines_big)
{
for (size_t i = 0; i < pl.points.size() - 1; i++) {
Point pt1 = to_pixels(unscale(pl.points[i]), ch);
Point pt2 = to_pixels(unscale(pl.points[i + 1]), ch);
dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
}
}
// draw bed contour // draw bed contour
dc.SetPen(wxPen(wxColour(0, 0, 0), 1, wxPENSTYLE_SOLID)); dc.SetPen(wxPen(wxColour(0, 0, 0), 1, wxPENSTYLE_SOLID));

View File

@ -300,21 +300,36 @@ void Bed3D::calc_triangles(const ExPolygon& poly)
void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox)
{ {
Polylines axes_lines; Polylines axes_lines;
for (coord_t x = bed_bbox.min(0); x <= bed_bbox.max(0); x += scale_(10.0)) { Polylines axes_lines_big;
Polylines axes_lines_small;
for (coord_t x = bed_bbox.min(0), idx= 0; x <= bed_bbox.max(0); x += scale_(5.0), idx++) {
Polyline line; Polyline line;
line.append(Point(x, bed_bbox.min(1))); line.append(Point(x, bed_bbox.min(1)));
line.append(Point(x, bed_bbox.max(1))); line.append(Point(x, bed_bbox.max(1)));
if (idx % 10 == 0)
axes_lines_big.push_back(line);
else if(idx%2==1)
axes_lines_small.push_back(line);
else
axes_lines.push_back(line); axes_lines.push_back(line);
} }
for (coord_t y = bed_bbox.min(1); y <= bed_bbox.max(1); y += scale_(10.0)) { for (coord_t y = bed_bbox.min(1), idx = 0; y <= bed_bbox.max(1); y += scale_(5.0), idx++) {
Polyline line; Polyline line;
line.append(Point(bed_bbox.min(0), y)); line.append(Point(bed_bbox.min(0), y));
line.append(Point(bed_bbox.max(0), y)); line.append(Point(bed_bbox.max(0), y));
if (idx % 10 == 0)
axes_lines_big.push_back(line);
else if (idx % 2 == 1)
axes_lines_small.push_back(line);
else
axes_lines.push_back(line); axes_lines.push_back(line);
} }
// clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped // clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped
Lines gridlines = to_lines(intersection_pl(axes_lines, offset(poly, (float)SCALED_EPSILON))); Lines gridlines = to_lines(intersection_pl(axes_lines, offset(poly, (float)SCALED_EPSILON)));
Lines gridlines_big = to_lines(intersection_pl(axes_lines_big, offset(poly, (float)SCALED_EPSILON)));
Lines gridlines_small = to_lines(intersection_pl(axes_lines_small, offset(poly, (float)SCALED_EPSILON)));
// append bed contours // append bed contours
Lines contour_lines = to_lines(poly); Lines contour_lines = to_lines(poly);
@ -322,6 +337,10 @@ void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox)
if (!m_gridlines.set_from_lines(gridlines, GROUND_Z)) if (!m_gridlines.set_from_lines(gridlines, GROUND_Z))
printf("Unable to create bed grid lines\n"); printf("Unable to create bed grid lines\n");
if (!m_gridlines_big.set_from_lines(gridlines_big, GROUND_Z))
printf("Unable to create bed grid lines\n");
if (!m_gridlines_small.set_from_lines(gridlines_small, GROUND_Z))
printf("Unable to create bed grid lines\n");
} }
@ -559,13 +578,19 @@ void Bed3D::render_default(bool bottom) const
} }
// draw grid // draw grid
glsafe(::glLineWidth(1.5f * m_scale_factor));
if (has_model && !bottom) if (has_model && !bottom)
glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 1.0f)); glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 1.0f));
else else
glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 0.6f)); glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 0.6f));
glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); glsafe(::glLineWidth(0.5f * m_scale_factor));
glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines_small.get_vertex_data_size(), (GLvoid*)m_gridlines_small.get_vertices_data()));
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines_small.get_vertices_count()));
glsafe(::glLineWidth(1.5f * m_scale_factor));
glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data()));
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count())); glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count()));
glsafe(::glLineWidth(3.0f * m_scale_factor));
glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines_big.get_vertex_data_size(), (GLvoid*)m_gridlines_big.get_vertices_data()));
glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines_big.get_vertices_count()));
glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY));

View File

@ -82,6 +82,8 @@ private:
Polygon m_polygon; Polygon m_polygon;
GeometryBuffer m_triangles; GeometryBuffer m_triangles;
GeometryBuffer m_gridlines; GeometryBuffer m_gridlines;
GeometryBuffer m_gridlines_big;
GeometryBuffer m_gridlines_small;
mutable GLTexture m_texture; mutable GLTexture m_texture;
mutable GLModel m_model; mutable GLModel m_model;
mutable Vec3d m_model_offset{ Vec3d::Zero() }; mutable Vec3d m_model_offset{ Vec3d::Zero() };