2018-04-20 10:58:07 +00:00
|
|
|
#ifndef slic3r_BedShapeDialog_hpp_
|
|
|
|
#define slic3r_BedShapeDialog_hpp_
|
2018-01-25 12:46:04 +00:00
|
|
|
// The bed shape dialog.
|
|
|
|
// The dialog opens from Print Settins tab->Bed Shape : Set...
|
|
|
|
|
2020-05-26 15:42:57 +00:00
|
|
|
#include "GUI_Utils.hpp"
|
2018-01-25 12:46:04 +00:00
|
|
|
#include "2DBed.hpp"
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "I18N.hpp"
|
2018-01-25 12:46:04 +00:00
|
|
|
|
|
|
|
#include <wx/dialog.h>
|
|
|
|
#include <wx/choicebk.h>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
2020-05-27 11:19:26 +00:00
|
|
|
class ConfigOptionsGroup;
|
|
|
|
|
2018-01-25 12:46:04 +00:00
|
|
|
using ConfigOptionsGroupShp = std::shared_ptr<ConfigOptionsGroup>;
|
2020-08-19 11:04:51 +00:00
|
|
|
|
|
|
|
struct BedShape {
|
|
|
|
|
|
|
|
enum class Type {
|
|
|
|
Rectangular = 0,
|
|
|
|
Circular,
|
|
|
|
Custom,
|
|
|
|
Invalid
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Parameter {
|
|
|
|
RectSize,
|
|
|
|
RectOrigin,
|
|
|
|
Diameter
|
|
|
|
};
|
|
|
|
|
|
|
|
BedShape(const ConfigOptionPoints& points) {
|
|
|
|
auto polygon = Polygon::new_scale(points.values);
|
|
|
|
|
|
|
|
// is this a rectangle ?
|
|
|
|
if (points.size() == 4) {
|
|
|
|
auto lines = polygon.lines();
|
|
|
|
if (lines[0].parallel_to(lines[2]) && lines[1].parallel_to(lines[3])) {
|
|
|
|
// okay, it's a rectangle
|
|
|
|
// find origin
|
|
|
|
coordf_t x_min, x_max, y_min, y_max;
|
|
|
|
x_max = x_min = points.values[0](0);
|
|
|
|
y_max = y_min = points.values[0](1);
|
|
|
|
for (auto pt : points.values)
|
|
|
|
{
|
|
|
|
x_min = std::min(x_min, pt(0));
|
|
|
|
x_max = std::max(x_max, pt(0));
|
|
|
|
y_min = std::min(y_min, pt(1));
|
|
|
|
y_max = std::max(y_max, pt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
type = Type::Rectangular;
|
|
|
|
rectSize = Vec2d(x_max - x_min, y_max - y_min);
|
|
|
|
rectOrigin = Vec2d(-x_min, -y_min);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// is this a circle ?
|
|
|
|
{
|
|
|
|
// Analyze the array of points.Do they reside on a circle ?
|
|
|
|
auto center = polygon.bounding_box().center();
|
|
|
|
std::vector<double> vertex_distances;
|
|
|
|
double avg_dist = 0;
|
|
|
|
for (auto pt : polygon.points)
|
|
|
|
{
|
|
|
|
double distance = (pt - center).cast<double>().norm();
|
|
|
|
vertex_distances.push_back(distance);
|
|
|
|
avg_dist += distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
avg_dist /= vertex_distances.size();
|
|
|
|
bool defined_value = true;
|
|
|
|
for (auto el : vertex_distances)
|
|
|
|
{
|
|
|
|
if (abs(el - avg_dist) > 10 * SCALED_EPSILON)
|
|
|
|
defined_value = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (defined_value) {
|
|
|
|
// all vertices are equidistant to center
|
|
|
|
type = Type::Circular;
|
|
|
|
diameter = unscale<double>(avg_dist * 2);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (points.size() < 3) {
|
|
|
|
type = Type::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a custom bed shape, use the polygon provided.
|
|
|
|
type = Type::Custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void append_option_line(ConfigOptionsGroupShp optgroup, Parameter param);
|
|
|
|
static wxString get_name(Type type);
|
|
|
|
|
|
|
|
wxString get_full_name_with_params();
|
|
|
|
|
|
|
|
Type type = Type::Invalid;
|
|
|
|
Vec2d rectSize;
|
|
|
|
Vec2d rectOrigin;
|
|
|
|
|
|
|
|
double diameter;
|
|
|
|
};
|
|
|
|
|
2018-01-25 12:46:04 +00:00
|
|
|
class BedShapePanel : public wxPanel
|
|
|
|
{
|
2019-07-18 09:12:11 +00:00
|
|
|
static const std::string NONE;
|
|
|
|
static const std::string EMPTY_STRING;
|
|
|
|
|
2019-06-12 08:00:51 +00:00
|
|
|
Bed_2D* m_canvas;
|
2019-07-18 09:12:11 +00:00
|
|
|
std::vector<Vec2d> m_shape;
|
|
|
|
std::vector<Vec2d> m_loaded_shape;
|
2020-08-19 11:04:51 +00:00
|
|
|
std::string m_custom_shape;
|
2019-07-18 09:12:11 +00:00
|
|
|
std::string m_custom_texture;
|
2019-07-18 10:56:52 +00:00
|
|
|
std::string m_custom_model;
|
2018-01-25 12:46:04 +00:00
|
|
|
|
|
|
|
public:
|
2019-07-18 10:56:52 +00:00
|
|
|
BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY), m_custom_texture(NONE), m_custom_model(NONE) {}
|
|
|
|
|
|
|
|
void build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model);
|
2019-07-17 12:53:02 +00:00
|
|
|
|
2019-07-09 11:33:15 +00:00
|
|
|
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
|
2019-07-18 09:12:11 +00:00
|
|
|
const std::vector<Vec2d>& get_shape() const { return m_shape; }
|
|
|
|
const std::string& get_custom_texture() const { return (m_custom_texture != NONE) ? m_custom_texture : EMPTY_STRING; }
|
2019-07-18 10:56:52 +00:00
|
|
|
const std::string& get_custom_model() const { return (m_custom_model != NONE) ? m_custom_model : EMPTY_STRING; }
|
2019-07-09 11:33:15 +00:00
|
|
|
|
|
|
|
private:
|
2019-06-12 08:00:51 +00:00
|
|
|
ConfigOptionsGroupShp init_shape_options_page(const wxString& title);
|
2019-07-18 09:12:11 +00:00
|
|
|
wxPanel* init_texture_panel();
|
2019-07-18 10:56:52 +00:00
|
|
|
wxPanel* init_model_panel();
|
2019-07-17 12:53:02 +00:00
|
|
|
void set_shape(const ConfigOptionPoints& points);
|
|
|
|
void update_preview();
|
2018-01-25 12:46:04 +00:00
|
|
|
void update_shape();
|
|
|
|
void load_stl();
|
2019-07-18 09:12:11 +00:00
|
|
|
void load_texture();
|
2019-07-18 10:56:52 +00:00
|
|
|
void load_model();
|
2019-07-18 09:12:11 +00:00
|
|
|
|
2019-04-18 00:03:40 +00:00
|
|
|
wxChoicebook* m_shape_options_book;
|
|
|
|
std::vector <ConfigOptionsGroupShp> m_optgroups;
|
|
|
|
|
2019-07-09 11:33:15 +00:00
|
|
|
friend class BedShapeDialog;
|
2018-01-25 12:46:04 +00:00
|
|
|
};
|
|
|
|
|
2019-04-18 00:03:40 +00:00
|
|
|
class BedShapeDialog : public DPIDialog
|
2018-01-25 12:46:04 +00:00
|
|
|
{
|
2018-02-05 15:12:16 +00:00
|
|
|
BedShapePanel* m_panel;
|
2018-01-25 12:46:04 +00:00
|
|
|
public:
|
2019-04-18 00:03:40 +00:00
|
|
|
BedShapeDialog(wxWindow* parent) : DPIDialog(parent, wxID_ANY, _(L("Bed Shape")),
|
2019-02-06 08:49:32 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {}
|
2018-01-25 12:46:04 +00:00
|
|
|
|
2019-07-18 10:56:52 +00:00
|
|
|
void build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model);
|
|
|
|
|
2019-07-18 09:12:11 +00:00
|
|
|
const std::vector<Vec2d>& get_shape() const { return m_panel->get_shape(); }
|
|
|
|
const std::string& get_custom_texture() const { return m_panel->get_custom_texture(); }
|
2019-07-18 10:56:52 +00:00
|
|
|
const std::string& get_custom_model() const { return m_panel->get_custom_model(); }
|
2019-04-18 00:03:40 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void on_dpi_changed(const wxRect &suggested_rect) override;
|
2018-01-25 12:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // GUI
|
|
|
|
} // Slic3r
|
2018-04-20 10:58:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* slic3r_BedShapeDialog_hpp_ */
|