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

@ -21,6 +21,14 @@ public:
Polyline(Polyline &&other) : MultiPoint(std::move(other.points)) {} Polyline(Polyline &&other) : MultiPoint(std::move(other.points)) {}
Polyline& operator=(const Polyline &other) { points = other.points; return *this; } Polyline& operator=(const Polyline &other) { points = other.points; return *this; }
Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; } Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; }
static Polyline new_scale(std::vector<Pointf> points) {
Polyline pl;
Points int_points;
for (auto pt : points)
int_points.push_back(Point::new_scale(pt.x, pt.y));
pl.append(int_points);
return pl;
}
void append(const Point &point) { this->points.push_back(point); } void append(const Point &point) { this->points.push_back(point); }
void append(const Points &src) { this->append(src.begin(), src.end()); } void append(const Points &src) { this->append(src.begin(), src.end()); }

View file

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

View file

@ -9,25 +9,30 @@ class Bed_2D : public wxPanel
bool m_user_drawn_background = false; bool m_user_drawn_background = false;
bool m_painted = false; bool m_painted = false;
bool m_interactive = false;
double m_scale_factor; double m_scale_factor;
Pointf m_shift; Pointf m_shift;
Point m_pos; Pointf m_pos;
std::function<void(Pointf)> m_on_move = nullptr;
Point to_pixels(Pointf point); Point to_pixels(Pointf point);
Pointf to_units(Point point);
void repaint(); void repaint();
void mouse_event(wxMouseEvent event);
void set_pos(Pointf pos);
public: public:
Bed_2D(wxWindow* parent) Bed_2D(wxWindow* parent)
{ {
Create(parent, wxID_ANY, wxDefaultPosition, wxSize(250, -1), wxTAB_TRAVERSAL); Create(parent, wxID_ANY, wxDefaultPosition, wxSize(250, -1), wxTAB_TRAVERSAL);
// m_user_drawn_background = $^O ne 'darwin'; // m_user_drawn_background = $^O ne 'darwin';
m_user_drawn_background = true; m_user_drawn_background = true;
Bind(wxEVT_PAINT, ([this](wxPaintEvent e) Bind(wxEVT_PAINT, ([this](wxPaintEvent e) { repaint(); }));
{
repaint();
}));
// EVT_ERASE_BACKGROUND($self, sub{}) if $self->{user_drawn_background}; // EVT_ERASE_BACKGROUND($self, sub{}) if $self->{user_drawn_background};
// Bind(wxEVT_MOUSE_EVENTS, ([this](wxCommandEvent){/*mouse_event()*/; })); // Bind(EVT_MOUSE_EVENTS, ([this](wxMouseEvent event){/*mouse_event()*/; }));
Bind(wxEVT_SIZE, ([this](wxSizeEvent){Refresh(); })); Bind(wxEVT_LEFT_DOWN, ([this](wxMouseEvent event){ mouse_event(event); }));
Bind(wxEVT_MOTION, ([this](wxMouseEvent event){ mouse_event(event); }));
Bind(wxEVT_SIZE, ([this](wxSizeEvent e) { Refresh(); }));
} }
~Bed_2D(){} ~Bed_2D(){}

View file

@ -6,6 +6,8 @@
#include "Polygon.hpp" #include "Polygon.hpp"
#include "BoundingBox.hpp" #include "BoundingBox.hpp"
#include <wx/numformatter.h> #include <wx/numformatter.h>
#include "Model.hpp"
#include "boost/nowide/iostream.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -17,7 +19,7 @@ void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt)
auto main_sizer = new wxBoxSizer(wxVERTICAL); auto main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_panel, 1, wxEXPAND); main_sizer->Add(m_panel, 1, wxEXPAND);
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, /*wxEXPAND*/wxALIGN_CENTER_HORIZONTAL | wxBOTTOM/*ALL*/, 10); main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
SetSizer(main_sizer); SetSizer(main_sizer);
SetMinSize(GetSize()); SetMinSize(GetSize());
@ -158,11 +160,6 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
if (x_max < 0) x_max = 0; if (x_max < 0) x_max = 0;
if (y_min < 0) y_min = 0; if (y_min < 0) y_min = 0;
if (y_max < 0) y_max = 0; if (y_max < 0) y_max = 0;
// auto x_min = min(map $_->[X], @$points) || 0;
// auto x_max = max(map $_->[X], @$points) || 0;
// auto y_min = min(map $_->[Y], @$points) || 0;
// auto y_max = max(map $_->[Y], @$points) || 0;
// auto origin = [-x_min, -y_min];
auto origin = new ConfigOptionPoints{ Pointf(-x_min, -y_min) }; auto origin = new ConfigOptionPoints{ Pointf(-x_min, -y_min) };
m_shape_options_book->SetSelection(SHAPE_RECTANGULAR); m_shape_options_book->SetSelection(SHAPE_RECTANGULAR);
@ -177,11 +174,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
// is this a circle ? // is this a circle ?
{ {
// Analyze the array of points.Do they reside on a circle ? // Analyze the array of points.Do they reside on a circle ?
// auto polygon;// = Slic3r::Polygon->new_scale(@$points); auto center = polygon.bounding_box().center();
auto center = polygon.bounding_box().center();// ->bounding_box->center; std::vector<double> vertex_distances;
// auto /*@*/vertex_distances;// = map $center->distance_to($_), @$polygon;
// auto avg_dist = sum(/*@*/vertex_distances) / /*@*/vertex_distances;
std::vector<double> vertex_distances;// = map $center->distance_to($_), @$polygon;
double avg_dist = 0; double avg_dist = 0;
for (auto pt: polygon.points) for (auto pt: polygon.points)
{ {
@ -193,16 +187,16 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
bool defined_value = true; bool defined_value = true;
for (auto el: vertex_distances) for (auto el: vertex_distances)
{ {
if (abs(el - avg_dist) > 10 * SCALED_EPSILON/*scaled_epsilon*/) if (abs(el - avg_dist) > 10 * SCALED_EPSILON)
defined_value = false; defined_value = false;
break; break;
} }
if (defined_value/*!defined first{ abs($_ - $avg_dist) > 10 * scaled_epsilon } @vertex_distances*/) { if (defined_value) {
// all vertices are equidistant to center // all vertices are equidistant to center
m_shape_options_book->SetSelection(SHAPE_CIRCULAR); m_shape_options_book->SetSelection(SHAPE_CIRCULAR);
auto optgroup = m_optgroups[SHAPE_CIRCULAR]; auto optgroup = m_optgroups[SHAPE_CIRCULAR];
boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0); boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0);
optgroup->set_value("diameter", ret /*sprintf("%.0f", unscale(avg_dist * 2))*/); optgroup->set_value("diameter", ret);
update_shape(); update_shape();
return; return;
} }
@ -227,7 +221,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
void BedShapePanel::update_preview() void BedShapePanel::update_preview()
{ {
if (m_canvas) m_canvas->Refresh(); if (m_canvas) m_canvas->Refresh();
Refresh(); Refresh();
} }
@ -236,44 +230,57 @@ void BedShapePanel::update_shape()
{ {
auto page_idx = m_shape_options_book->GetSelection(); auto page_idx = m_shape_options_book->GetSelection();
if (page_idx == SHAPE_RECTANGULAR) { if (page_idx == SHAPE_RECTANGULAR) {
auto rect_size = m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size"); Pointf rect_size, rect_origin;
auto rect_origin = m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin"); try{
/* auto x = rect_size->x; rect_size = boost::any_cast<Pointf>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); }
auto y = rect_size->y; catch (const std::exception &e){
return;}
try{
rect_origin = boost::any_cast<Pointf>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin"));
}
catch (const std::exception &e){
return;}
auto x = rect_size.x;
auto y = rect_size.y;
// empty strings or '-' or other things // empty strings or '-' or other things
// if (!looks_like_number(x) || !looks_like_number(y)) return; if (x == 0 || y == 0) return;
if ((!x || !y) || x == 0 || y == 0) return; double x0 = 0.0;
// my($x0, $y0) = (0, 0); double y0 = 0.0;
// my($x1, $y1) = ($x, $y); double x1 = x;
// { double y1 = y;
// my($dx, $dy) = @$rect_origin;
// return if !looks_like_number($dx) || !looks_like_number($dy); # empty strings or '-' or other things auto dx = rect_origin.x;
// $x0 -= $dx; auto dy = rect_origin.y;
// $x1 -= $dx;
// $y0 -= $dy; x0 -= dx;
// $y1 -= $dy; x1 -= dx;
// } y0 -= dy;
// m_canvas->bed_shape([ y1 -= dy;
// [$x0, $y0], m_canvas->m_bed_shape = { Pointf(x0, y0),
// [$x1, $y0], Pointf(x1, y0),
// [$x1, $y1], Pointf(x1, y1),
// [$x0, $y1], Pointf(x0, y1)};
// ]);
} }
else if(page_idx == SHAPE_CIRCULAR) { else if(page_idx == SHAPE_CIRCULAR) {
// auto diameter = m_optgroups[SHAPE_CIRCULAR]->get_value("diameter"); double diameter;
// if (!diameter || diameter == 0) return ; try{
// r = diameter / 2; diameter = boost::any_cast<double>(m_optgroups[SHAPE_CIRCULAR]->get_value("diameter"));
// twopi = 2 * PI; }
// edges = 60; catch (const std::exception &e){
// polygon = Slic3r::Polygon->new_scale( return;
// map[$r * cos $_, $r * sin $_], }
// map{ $twopi / $edges*$_ } 1..$edges if (diameter == 0.0) return ;
// ); auto r = diameter / 2;
// m_canvas->bed_shape([ auto twopi = 2 * PI;
// map[unscale($_->x), unscale($_->y)], @$polygon #)) auto edges = 60;
// ]); std::vector<Pointf> points;
*/ } for (size_t i = 1; i <= 60; ++i){
auto angle = i * twopi / edges;
points.push_back(Pointf(r*cos(angle), r*sin(angle)));
}
m_canvas->m_bed_shape = points;
}
// $self->{on_change}->(); // $self->{on_change}->();
update_preview(); update_preview();
@ -282,8 +289,14 @@ void BedShapePanel::update_shape()
// Loads an stl file, projects it to the XY plane and calculates a polygon. // Loads an stl file, projects it to the XY plane and calculates a polygon.
void BedShapePanel::load_stl() void BedShapePanel::load_stl()
{ {
t_file_wild_card vec_FILE_WILDCARDS = get_file_wild_card();
std::vector<std::string> file_types = { "known", "stl", "obj", "amf", "prusa"};
wxString MODEL_WILDCARD;
for (auto file_type: file_types)
MODEL_WILDCARD += vec_FILE_WILDCARDS.at(file_type) + "|";
auto dialog = new wxFileDialog(this, "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):", "", "", auto dialog = new wxFileDialog(this, "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):", "", "",
wxFileSelectorDefaultWildcardStr/* &Slic3r::GUI::MODEL_WILDCARD*/, wxFD_OPEN | wxFD_FILE_MUST_EXIST); MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog->ShowModal() != wxID_OK) { if (dialog->ShowModal() != wxID_OK) {
dialog->Destroy(); dialog->Destroy();
return; return;
@ -292,21 +305,35 @@ void BedShapePanel::load_stl()
dialog->GetPaths(input_file); dialog->GetPaths(input_file);
dialog->Destroy(); dialog->Destroy();
// auto model = Slic3r::Model->read_from_file(input_file); std::string file_name = input_file[0].ToStdString();
// auto mesh = model->mesh;
// auto expolygons = mesh->horizontal_projection; Model model;
// try {
// if (expolygons.size() == 0) { model = Model::read_from_file(file_name);
// show_error(this, "The selected file contains no geometry."); }
// return; catch (std::exception &e) {
// } std::string msg = "Error! " + file_name + ": " + e.what() + ".";
// if (expolygons.size() > 1) { show_error(this, msg);
// show_error(this, "The selected file contains several disjoint areas. This is not supported."); exit(1);
// return; }
// }
// auto mesh = model.mesh();
// auto polygon = expolygons[0]->contour; auto expolygons = mesh.horizontal_projection();
// m_canvas->bed_shape([map[unscale($_->x), unscale($_->y)], @$polygon]);
if (expolygons.size() == 0) {
show_error(this, "The selected file contains no geometry.");
return;
}
if (expolygons.size() > 1) {
show_error(this, "The selected file contains several disjoint areas. This is not supported.");
return;
}
auto polygon = expolygons[0].contour;
std::vector<Pointf> points;
for (auto pt : polygon.points)
points.push_back(Pointf::new_unscale(pt));
m_canvas->m_bed_shape = points;
update_preview(); update_preview();
} }

View file

@ -24,14 +24,15 @@ public:
~BedShapePanel(){} ~BedShapePanel(){}
void build_panel(ConfigOptionPoints* default_pt); void build_panel(ConfigOptionPoints* default_pt);
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
int GetValue() { return 1/*m_canvas->bed_shape*/; }
ConfigOptionsGroupShp init_shape_options_page(std::string title); ConfigOptionsGroupShp init_shape_options_page(std::string title);
void set_shape(ConfigOptionPoints* points); void set_shape(ConfigOptionPoints* points);
void update_preview(); void update_preview();
void update_shape(); void update_shape();
void load_stl(); void load_stl();
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
std::vector<Pointf> GetValue() { return m_canvas->m_bed_shape; }
}; };
class BedShapeDialog : public wxDialog class BedShapeDialog : public wxDialog
@ -43,7 +44,7 @@ public:
~BedShapeDialog(){} ~BedShapeDialog(){}
void build_dialog(ConfigOptionPoints* default_pt); void build_dialog(ConfigOptionPoints* default_pt);
int GetValue() { return m_panel->GetValue(); } std::vector<Pointf> GetValue() { return m_panel->GetValue(); }
}; };
} // GUI } // GUI

View file

@ -491,7 +491,7 @@ void PointCtrl::BUILD()
temp->Add(y_textctrl); temp->Add(y_textctrl);
x_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId()); x_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId());
y_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId()); y_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), y_textctrl->GetId());
// // recast as a wxWindow to fit the calling convention // // recast as a wxWindow to fit the calling convention
sizer = dynamic_cast<wxSizer*>(temp); sizer = dynamic_cast<wxSizer*>(temp);

View file

@ -292,7 +292,11 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value))); config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value)));
} }
break; break;
case coPoints: case coPoints:{
ConfigOptionPoints points;
points.values = boost::any_cast<std::vector<Pointf>>(value);
config.set_key_value(opt_key, new ConfigOptionPoints(points));
}
break; break;
case coNone: case coNone:
break; break;

View file

@ -953,8 +953,7 @@ void TabPrinter::build()
auto dlg = new BedShapeDialog(this); auto dlg = new BedShapeDialog(this);
dlg->build_dialog(m_config->option<ConfigOptionPoints>("bed_shape")); dlg->build_dialog(m_config->option<ConfigOptionPoints>("bed_shape"));
if (dlg->ShowModal() == wxID_OK) if (dlg->ShowModal() == wxID_OK)
// load_key_value("bed_shape", dlg->GetValue()); load_key_value("bed_shape", dlg->GetValue());
;
})); }));
return sizer; return sizer;
@ -1567,6 +1566,7 @@ void Tab::save_preset(std::string name /*= ""*/)
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
show_error(this, "Something is wrong. It can't be saved.");
return; return;
} }