BedShapeDialog and Bed_2D (as a part of it) are completed.

Added new_scale function to Polyline.
Fixed small bug in PointCtrl.
Extended change_opt_value for coPoints case.
This commit is contained in:
YuSanka 2018-01-30 12:10:12 +01:00
parent f90ea5060d
commit 7d29a7b45a
8 changed files with 239 additions and 172 deletions

View file

@ -3,14 +3,14 @@
#include <wx/dcbuffer.h>
#include "BoundingBox.hpp"
#include "Geometry.hpp"
#include "ClipperUtils.hpp"
namespace Slic3r {
namespace GUI {
void Bed_2D::repaint()
{
// auto dc = new wxAutoBufferedPaintDC(this);
wxClientDC dc(this);
wxAutoBufferedPaintDC dc(this);
auto cw = GetSize().GetWidth();
auto ch = GetSize().GetHeight();
// when canvas is not rendered yet, size is 0, 0
@ -22,23 +22,23 @@ void Bed_2D::repaint()
// and on Linux / GTK the background is erased to gray color.
// Fill DC with the background on Windows & Linux / GTK.
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); //GetSystemColour
dc.SetPen(/**new wxPen(color, 1, wxPENSTYLE_SOLID)*/*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID));
dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID));
dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID));
auto rect = GetUpdateRegion().GetBox();
dc.DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
}
// turn cw and ch from sizes to max coordinates
/* cw--;
cw--;
ch--;
auto cbb = BoundingBoxf(Pointf(0, 0),Pointf(cw, ch));
// leave space for origin point
cbb.min.translate(4, 0); // cbb.set_x_min(cbb.min.x + 4);
cbb.max.translate(-4, -4); // cbb.set_x_max(cbb.max.x - 4);cbb.set_y_max(cbb.max.y - 4);
cbb.min.translate(4, 0);
cbb.max.translate(-4, -4);
// leave space for origin label
cbb.max.translate(0, -13); // $cbb->set_y_max($cbb->y_max - 13);
cbb.max.translate(0, -13);
// read new size
cw = cbb.size().x;
@ -66,91 +66,87 @@ void Bed_2D::repaint()
shift.y - (cbb.max.y - GetSize().GetHeight()));
// draw bed fill
// {
dc->SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID));
dc->SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxSOLID));
wxPointList pt_list;
for (auto pt: m_bed_shape)
{
Point pt_pix = to_pixels(pt);
pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y));
}
dc->DrawPolygon(&pt_list, 0, 0);
// }
*/
// draw grid
// {
// auto step = 10; // 1cm grid
// Polylines polylines;
// for (auto x = bb.min.x - (bb.min.x % step) + step; x < bb.max.x; x += step) {
// // push @polylines, Slic3r::Polyline->new_scale([$x, $bb->y_min], [$x, $bb->y_max]);
// }
// for (auto y = bb.min.y - (bb.min.y % step) + step; y < bb.max.y; y += step) {
// // push @polylines, Slic3r::Polyline->new_scale([$bb->x_min, $y], [$bb->x_max, $y]);
// }
// // @polylines = @{intersection_pl(\@polylines, [$bed_polygon])};
//
// dc->SetPen(*new wxPen(*new wxColour(230, 230, 230), 1, wxSOLID));
// // for (auto pl: polylines)
// // dc->DrawLine(map @{$self->to_pixels([map unscale($_), @$_])}, @$_[0, -1]);
// }
//
// // draw bed contour
// {
// dc->SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID));
// dc->SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxTRANSPARENT));
// // dc->DrawPolygon([map $self->to_pixels($_), @$bed_shape], 0, 0);
// }
dc.SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxSOLID));
wxPointList pt_list;
for (auto pt: m_bed_shape)
{
Point pt_pix = to_pixels(pt);
pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y));
}
dc.DrawPolygon(&pt_list, 0, 0);
// auto origin_px = to_pixels(Pointf(0, 0));
//
// // draw axes
// {
// auto axes_len = 50;
// auto arrow_len = 6;
// auto arrow_angle = Geometry::deg2rad(45);
// dc->SetPen(*new wxPen(*new wxColour(255, 0, 0), 2, wxSOLID)); // red
// auto x_end = Pointf(origin_px.x + axes_len, origin_px.y);
// dc->DrawLine(wxPoint(origin_px), wxPoint(x_end));
// foreach my $angle(-$arrow_angle, +$arrow_angle) {
// auto end = x_end.clone;
// end->translate(-arrow_len, 0);
// end->rotate(angle, x_end);
// dc->DrawLine(x_end, end);
// }
//
// dc->SetPen(*new wxPen(*new wxColour(0, 255, 0), 2, wxSOLID)); // green
// auto y_end = Pointf(origin_px.x, origin_px.y - axes_len);
// dc->DrawLine(origin_px, y_end);
// foreach my $angle(-$arrow_angle, +$arrow_angle) {
// auto end = y_end->clone;
// end->translate(0, +arrow_len);
// end->rotate(angle, y_end);
// dc->DrawLine(y_end, end);
// }
// }
//
// // draw origin
// {
// dc->SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID));
// dc->SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxSOLID));
// dc->DrawCircle(origin_px.x, origin_px.y, 3);
//
// dc->SetTextForeground(*new wxColour(0, 0, 0));
// dc->SetFont(*new wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL));
// dc->DrawText("(0,0)", origin_px.x + 1, origin_px.y + 2);
// }
//
// // draw current position
// if (m_pos) {
// auto pos_px = to_pixels(m_pos);
// dc->SetPen(*new wxPen(*new wxColour(200, 0, 0), 2, wxSOLID));
// dc->SetBrush(*new wxBrush(*new wxColour(200, 0, 0), wxTRANSPARENT));
// dc->DrawCircle(pos_px, 5);
//
// dc->DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y);
// dc->DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15);
// }
// draw grid
auto step = 10; // 1cm grid
Polylines polylines;
for (auto x = bb.min.x - fmod(bb.min.x, step) + step; x < bb.max.x; x += step) {
Polyline pl = Polyline::new_scale({ Pointf(x, bb.min.y), Pointf(x, bb.max.y) });
polylines.push_back(pl);
}
for (auto y = bb.min.y - fmod(bb.min.y, step) + step; y < bb.max.y; y += step) {
polylines.push_back(Polyline::new_scale({ Pointf(bb.min.x, y), Pointf(bb.max.x, y) }));
}
polylines = intersection_pl(polylines, bed_polygon);
dc.SetPen(*new wxPen(*new wxColour(230, 230, 230), 1, wxSOLID));
for (auto pl : polylines)
{
for (size_t i = 0; i < pl.points.size()-1; i++){
Point pt1 = to_pixels(Pointf::new_unscale(pl.points[i]));
Point pt2 = to_pixels(Pointf::new_unscale(pl.points[i+1]));
dc.DrawLine(pt1.x, pt1.y, pt2.x, pt2.y);
}
}
// draw bed contour
dc.SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID));
dc.SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxTRANSPARENT));
dc.DrawPolygon(&pt_list, 0, 0);
auto origin_px = to_pixels(Pointf(0, 0));
// draw axes
auto axes_len = 50;
auto arrow_len = 6;
auto arrow_angle = Geometry::deg2rad(45.0);
dc.SetPen(*new wxPen(*new wxColour(255, 0, 0), 2, wxSOLID)); // red
auto x_end = Pointf(origin_px.x + axes_len, origin_px.y);
dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(x_end.x, x_end.y));
for (auto angle : { -arrow_angle, arrow_angle }){
auto end = x_end;
end.translate(-arrow_len, 0);
end.rotate(angle, x_end);
dc.DrawLine(wxPoint(x_end.x, x_end.y), wxPoint(end.x, end.y));
}
dc.SetPen(*new wxPen(*new wxColour(0, 255, 0), 2, wxSOLID)); // green
auto y_end = Pointf(origin_px.x, origin_px.y - axes_len);
dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(y_end.x, y_end.y));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = y_end;
end.translate(0, +arrow_len);
end.rotate(angle, y_end);
dc.DrawLine(wxPoint(y_end.x, y_end.y), wxPoint(end.x, end.y));
}
// draw origin
dc.SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID));
dc.SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxSOLID));
dc.DrawCircle(origin_px.x, origin_px.y, 3);
dc.SetTextForeground(*new wxColour(0, 0, 0));
dc.SetFont(*new wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL));
dc.DrawText("(0,0)", origin_px.x + 1, origin_px.y + 2);
// draw current position
if (m_pos!= Pointf(0, 0)) {
auto pos_px = to_pixels(m_pos);
dc.SetPen(*new wxPen(*new wxColour(200, 0, 0), 2, wxSOLID));
dc.SetBrush(*new wxBrush(*new wxColour(200, 0, 0), wxTRANSPARENT));
dc.DrawCircle(pos_px.x, pos_px.y, 5);
dc.DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y);
dc.DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15);
}
m_painted = true;
}
@ -163,5 +159,31 @@ Point Bed_2D::to_pixels(Pointf point){
return Point(p.x, GetSize().GetHeight() - p.y);
}
void Bed_2D::mouse_event(wxMouseEvent event){
if (!m_interactive) return;
if (!m_painted) return;
auto pos = event.GetPosition();
auto point = to_units(Point(pos.x, pos.y));
if (event.LeftDown() || event.Dragging()) {
if (m_on_move)
m_on_move(point) ;
Refresh();
}
}
// convert pixels into G - code coordinates
Pointf Bed_2D::to_units(Point point){
auto p = Pointf(point.x, GetSize().GetHeight() - point.y);
p.translate(m_shift.negative());
p.scale(1 / m_scale_factor);
return p;
}
void Bed_2D::set_pos(Pointf pos){
m_pos = pos;
Refresh();
}
} // GUI
} // Slic3r