mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
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:
parent
f90ea5060d
commit
7d29a7b45a
8 changed files with 239 additions and 172 deletions
|
@ -6,6 +6,8 @@
|
|||
#include "Polygon.hpp"
|
||||
#include "BoundingBox.hpp"
|
||||
#include <wx/numformatter.h>
|
||||
#include "Model.hpp"
|
||||
#include "boost/nowide/iostream.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
@ -17,7 +19,7 @@ void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt)
|
|||
|
||||
auto main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
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);
|
||||
SetMinSize(GetSize());
|
||||
|
@ -158,11 +160,6 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
|||
if (x_max < 0) x_max = 0;
|
||||
if (y_min < 0) y_min = 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) };
|
||||
|
||||
m_shape_options_book->SetSelection(SHAPE_RECTANGULAR);
|
||||
|
@ -177,11 +174,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
|||
// is this 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();// ->bounding_box->center;
|
||||
// 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;
|
||||
auto center = polygon.bounding_box().center();
|
||||
std::vector<double> vertex_distances;
|
||||
double avg_dist = 0;
|
||||
for (auto pt: polygon.points)
|
||||
{
|
||||
|
@ -193,16 +187,16 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
|||
bool defined_value = true;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
if (defined_value/*!defined first{ abs($_ - $avg_dist) > 10 * scaled_epsilon } @vertex_distances*/) {
|
||||
if (defined_value) {
|
||||
// all vertices are equidistant to center
|
||||
m_shape_options_book->SetSelection(SHAPE_CIRCULAR);
|
||||
auto optgroup = m_optgroups[SHAPE_CIRCULAR];
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
@ -227,7 +221,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
|||
|
||||
void BedShapePanel::update_preview()
|
||||
{
|
||||
if (m_canvas) m_canvas->Refresh();
|
||||
if (m_canvas) m_canvas->Refresh();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
@ -236,44 +230,57 @@ void BedShapePanel::update_shape()
|
|||
{
|
||||
auto page_idx = m_shape_options_book->GetSelection();
|
||||
if (page_idx == SHAPE_RECTANGULAR) {
|
||||
auto rect_size = m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size");
|
||||
auto rect_origin = m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin");
|
||||
/* auto x = rect_size->x;
|
||||
auto y = rect_size->y;
|
||||
Pointf rect_size, rect_origin;
|
||||
try{
|
||||
rect_size = boost::any_cast<Pointf>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); }
|
||||
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
|
||||
// if (!looks_like_number(x) || !looks_like_number(y)) return;
|
||||
if ((!x || !y) || x == 0 || y == 0) return;
|
||||
// my($x0, $y0) = (0, 0);
|
||||
// my($x1, $y1) = ($x, $y);
|
||||
// {
|
||||
// my($dx, $dy) = @$rect_origin;
|
||||
// return if !looks_like_number($dx) || !looks_like_number($dy); # empty strings or '-' or other things
|
||||
// $x0 -= $dx;
|
||||
// $x1 -= $dx;
|
||||
// $y0 -= $dy;
|
||||
// $y1 -= $dy;
|
||||
// }
|
||||
// m_canvas->bed_shape([
|
||||
// [$x0, $y0],
|
||||
// [$x1, $y0],
|
||||
// [$x1, $y1],
|
||||
// [$x0, $y1],
|
||||
// ]);
|
||||
if (x == 0 || y == 0) return;
|
||||
double x0 = 0.0;
|
||||
double y0 = 0.0;
|
||||
double x1 = x;
|
||||
double y1 = y;
|
||||
|
||||
auto dx = rect_origin.x;
|
||||
auto dy = rect_origin.y;
|
||||
|
||||
x0 -= dx;
|
||||
x1 -= dx;
|
||||
y0 -= dy;
|
||||
y1 -= dy;
|
||||
m_canvas->m_bed_shape = { Pointf(x0, y0),
|
||||
Pointf(x1, y0),
|
||||
Pointf(x1, y1),
|
||||
Pointf(x0, y1)};
|
||||
}
|
||||
else if(page_idx == SHAPE_CIRCULAR) {
|
||||
// auto diameter = m_optgroups[SHAPE_CIRCULAR]->get_value("diameter");
|
||||
// if (!diameter || diameter == 0) return ;
|
||||
// r = diameter / 2;
|
||||
// twopi = 2 * PI;
|
||||
// edges = 60;
|
||||
// polygon = Slic3r::Polygon->new_scale(
|
||||
// map[$r * cos $_, $r * sin $_],
|
||||
// map{ $twopi / $edges*$_ } 1..$edges
|
||||
// );
|
||||
// m_canvas->bed_shape([
|
||||
// map[unscale($_->x), unscale($_->y)], @$polygon #))
|
||||
// ]);
|
||||
*/ }
|
||||
double diameter;
|
||||
try{
|
||||
diameter = boost::any_cast<double>(m_optgroups[SHAPE_CIRCULAR]->get_value("diameter"));
|
||||
}
|
||||
catch (const std::exception &e){
|
||||
return;
|
||||
}
|
||||
if (diameter == 0.0) return ;
|
||||
auto r = diameter / 2;
|
||||
auto twopi = 2 * PI;
|
||||
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}->();
|
||||
update_preview();
|
||||
|
@ -282,8 +289,14 @@ void BedShapePanel::update_shape()
|
|||
// Loads an stl file, projects it to the XY plane and calculates a polygon.
|
||||
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):", "", "",
|
||||
wxFileSelectorDefaultWildcardStr/* &Slic3r::GUI::MODEL_WILDCARD*/, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
if (dialog->ShowModal() != wxID_OK) {
|
||||
dialog->Destroy();
|
||||
return;
|
||||
|
@ -292,21 +305,35 @@ void BedShapePanel::load_stl()
|
|||
dialog->GetPaths(input_file);
|
||||
dialog->Destroy();
|
||||
|
||||
// auto model = Slic3r::Model->read_from_file(input_file);
|
||||
// auto mesh = model->mesh;
|
||||
// auto expolygons = mesh->horizontal_projection;
|
||||
//
|
||||
// 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;
|
||||
// m_canvas->bed_shape([map[unscale($_->x), unscale($_->y)], @$polygon]);
|
||||
std::string file_name = input_file[0].ToStdString();
|
||||
|
||||
Model model;
|
||||
try {
|
||||
model = Model::read_from_file(file_name);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::string msg = "Error! " + file_name + ": " + e.what() + ".";
|
||||
show_error(this, msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto mesh = model.mesh();
|
||||
auto expolygons = mesh.horizontal_projection();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue