Merge branch 'master' into lm_sla_supports_auto

This commit is contained in:
Lukas Matena 2018-12-19 12:25:58 +01:00
commit 75ef3431b3
77 changed files with 5581 additions and 1010 deletions

View file

@ -65,11 +65,6 @@ PrinterTechnology BackgroundSlicingProcess::current_printer_technology() const
return m_print->technology();
}
static bool isspace(int ch)
{
return std::isspace(ch) != 0;
}
// This function may one day be merged into the Print, but historically the print was separated
// from the G-code generator.
void BackgroundSlicingProcess::process_fff()
@ -88,6 +83,27 @@ void BackgroundSlicingProcess::process_fff()
m_print->set_status(95, "Running post-processing scripts");
run_post_process_scripts(export_path, m_fff_print->config());
m_print->set_status(100, "G-code file exported to " + export_path);
} else if (! m_upload_job.empty()) {
// A print host upload job has been scheduled
// XXX: is fs::path::string() right?
// Generate a unique temp path to which the gcode is copied
boost::filesystem::path source_path = boost::filesystem::temp_directory_path()
/ boost::filesystem::unique_path(".printhost.%%%%-%%%%-%%%%-%%%%.gcode");
if (copy_file(m_temp_output_path, source_path.string()) != 0) {
throw std::runtime_error("Copying of the temporary G-code to the output G-code failed");
}
m_print->set_status(95, "Running post-processing scripts");
run_post_process_scripts(source_path.string(), m_fff_print->config());
m_print->set_status(100, (boost::format("Scheduling upload to `%1%`. See Window -> Print Host Upload Queue") % m_upload_job.printhost->get_host()).str());
m_upload_job.upload_data.source_path = std::move(source_path);
m_upload_job.upload_data.upload_path = m_fff_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string());
GUI::wxGetApp().printhost_job_queue().enqueue(std::move(m_upload_job));
} else {
m_print->set_status(100, "Slicing complete");
}
@ -373,13 +389,10 @@ void BackgroundSlicingProcess::schedule_upload(Slic3r::PrintHostJob upload_job)
if (! m_export_path.empty())
return;
const boost::filesystem::path path = boost::filesystem::temp_directory_path()
/ boost::filesystem::unique_path(".upload.%%%%-%%%%-%%%%-%%%%.gcode");
// Guard against entering the export step before changing the export path.
tbb::mutex::scoped_lock lock(m_print->state_mutex());
this->invalidate_step(bspsGCodeFinalize);
m_export_path = path.string();
m_export_path = std::string();
m_upload_job = std::move(upload_job);
}

View file

@ -163,17 +163,40 @@ void Field::get_value_by_opt_type(wxString& str)
break; }
case coString:
case coStrings:
case coFloatOrPercent:
m_value = str.ToStdString();
break;
case coFloatOrPercent: {
if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%')
{
double val;
if (!str.ToCDouble(&val))
{
show_error(m_parent, _(L("Input value contains incorrect symbol(s).\nUse, please, only digits")));
set_value(double_to_string(val), true);
}
else if (val > 1)
{
const int nVal = int(val);
wxString msg_text = wxString::Format(_(L("Do you mean %d%% instead of %dmm?\n"
"Select YES if you want to change this value to %d%%, \n"
"or NO if you are sure that %dmm is a correct value.")), nVal, nVal, nVal, nVal);
auto dialog = new wxMessageDialog(m_parent, msg_text, _(L("Parameter validation")), wxICON_WARNING | wxYES | wxNO);
if (dialog->ShowModal() == wxID_YES) {
set_value(wxString::Format("%s%%", str), true);
str += "%%";
}
}
}
m_value = str.ToStdString();
break; }
default:
break;
}
}
bool TextCtrl::is_defined_input_value() const
template<class T>
bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type)
{
if (static_cast<wxTextCtrl*>(window)->GetValue().empty() && m_opt.type != coString && m_opt.type != coStrings)
if (static_cast<T*>(win)->GetValue().empty() && type != coString && type != coStrings)
return false;
return true;
}
@ -252,7 +275,7 @@ void TextCtrl::BUILD() {
temp->GetToolTip()->Enable(true);
#endif // __WXGTK__
// if (!is_defined_input_value())
if (is_defined_input_value())
if (is_defined_input_value<wxTextCtrl>(window, m_opt.type))
on_change_field();
else
on_kill_focus(e);
@ -377,6 +400,9 @@ void SpinCtrl::BUILD() {
0, min_val, max_val, default_value);
// temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { tmp_value = undef_spin_val; on_change_field(); }), temp->GetId());
// #ys_FIXME_KILL_FOCUS
// wxEVT_KILL_FOCUS doesn't handled on OSX now
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e)
{
if (tmp_value < 0)
@ -386,6 +412,7 @@ void SpinCtrl::BUILD() {
on_change_field();
}
}), temp->GetId());
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e)
{
// # On OSX / Cocoa, wxSpinCtrl::GetValue() doesn't return the new value
@ -398,9 +425,15 @@ void SpinCtrl::BUILD() {
tmp_value = std::stoi(value);
else tmp_value = -9999;
// on_change_field();
// # We don't reset tmp_value here because _on_change might put callbacks
// # in the CallAfter queue, and we want the tmp value to be available from
// # them as well.
#ifdef __WXOSX__
// #ys_FIXME_KILL_FOCUS so call on_change_field() inside wxEVT_TEXT
if (tmp_value < 0) {
if (m_on_kill_focus != nullptr)
m_on_kill_focus(m_opt_id);
}
else
on_change_field();
#endif
}), temp->GetId());
temp->SetToolTip(get_tooltip_text(text_value));
@ -432,9 +465,24 @@ void Choice::BUILD() {
}
set_selection();
}
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
// temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
temp->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
if (temp->GetWindowStyle() != wxCB_READONLY) {
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) {
e.Skip();
double old_val = !m_value.empty() ? boost::any_cast<double>(m_value) : -99999;
if (is_defined_input_value<wxComboBox>(window, m_opt.type)) {
if (fabs(old_val - boost::any_cast<double>(get_value())) <= 0.0001)
return;
else
on_change_field();
}
else
on_kill_focus(e);
}), temp->GetId());
}
temp->SetToolTip(get_tooltip_text(temp->GetValue()));
}
@ -611,9 +659,7 @@ boost::any& Choice::get_value()
if (m_opt_id == rp_option)
return m_value = boost::any(ret_str);
if (m_opt.type != coEnum)
/*m_value = */get_value_by_opt_type(ret_str);
else
if (m_opt.type == coEnum)
{
int ret_enum = static_cast<wxComboBox*>(window)->GetSelection();
if (m_opt_id.compare("external_fill_pattern") == 0)
@ -638,7 +684,18 @@ boost::any& Choice::get_value()
m_value = static_cast<SeamPosition>(ret_enum);
else if (m_opt_id.compare("host_type") == 0)
m_value = static_cast<PrintHostType>(ret_enum);
}
else if (m_opt_id.compare("display_orientation") == 0)
m_value = static_cast<SLADisplayOrientation>(ret_enum);
}
else if (m_opt.gui_type == "f_enum_open") {
const int ret_enum = static_cast<wxComboBox*>(window)->GetSelection();
if (ret_enum < 0 || m_opt.enum_values.empty())
get_value_by_opt_type(ret_str);
else
m_value = atof(m_opt.enum_values[ret_enum].c_str());
}
else
get_value_by_opt_type(ret_str);
return m_value;
}
@ -702,8 +759,11 @@ void PointCtrl::BUILD()
temp->Add(new wxStaticText(m_parent, wxID_ANY, " y : "), 0, wxALIGN_CENTER_VERTICAL, 0);
temp->Add(y_textctrl);
x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId());
y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId());
// x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId());
// y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId());
x_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { OnKillFocus(e, x_textctrl); }), x_textctrl->GetId());
y_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { OnKillFocus(e, x_textctrl); }), y_textctrl->GetId());
// // recast as a wxWindow to fit the calling convention
sizer = dynamic_cast<wxSizer*>(temp);
@ -712,6 +772,16 @@ void PointCtrl::BUILD()
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
}
void PointCtrl::OnKillFocus(wxEvent& e, wxTextCtrl* win)
{
e.Skip();
if (!win->GetValue().empty()) {
on_change_field();
}
else
on_kill_focus(e);
}
void PointCtrl::set_value(const Vec2d& value, bool change_event)
{
m_disable_change_event = !change_event;

View file

@ -266,7 +266,6 @@ public:
}
boost::any& get_value() override;
bool is_defined_input_value() const ;
virtual void enable();
virtual void disable();
@ -395,6 +394,7 @@ public:
void BUILD() override;
void OnKillFocus(wxEvent& e, wxTextCtrl* win);
void set_value(const Vec2d& value, bool change_event = false);
void set_value(const boost::any& value, bool change_event = false);
boost::any& get_value() override;

View file

@ -617,42 +617,71 @@ bool GLCanvas3D::Bed::_are_equal(const Pointfs& bed_1, const Pointfs& bed_2)
return true;
}
const double GLCanvas3D::Axes::Radius = 0.5;
const double GLCanvas3D::Axes::ArrowBaseRadius = 2.5 * GLCanvas3D::Axes::Radius;
const double GLCanvas3D::Axes::ArrowLength = 5.0;
GLCanvas3D::Axes::Axes()
: origin(Vec3d::Zero())
, length(0.0f)
, length(Vec3d::Zero())
{
m_quadric = ::gluNewQuadric();
if (m_quadric != nullptr)
::gluQuadricDrawStyle(m_quadric, GLU_FILL);
}
void GLCanvas3D::Axes::render(bool depth_test) const
GLCanvas3D::Axes::~Axes()
{
if (depth_test)
::glEnable(GL_DEPTH_TEST);
else
::glDisable(GL_DEPTH_TEST);
if (m_quadric != nullptr)
::gluDeleteQuadric(m_quadric);
}
::glLineWidth(2.0f);
::glBegin(GL_LINES);
// draw line for x axis
void GLCanvas3D::Axes::render() const
{
if (m_quadric == nullptr)
return;
::glEnable(GL_DEPTH_TEST);
::glEnable(GL_LIGHTING);
// x axis
::glColor3f(1.0f, 0.0f, 0.0f);
::glVertex3dv(origin.data());
::glVertex3f((GLfloat)origin(0) + length, (GLfloat)origin(1), (GLfloat)origin(2));
// draw line for y axis
::glColor3f(0.0f, 1.0f, 0.0f);
::glVertex3dv(origin.data());
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1) + length, (GLfloat)origin(2));
::glEnd();
// draw line for Z axis
// (re-enable depth test so that axis is correctly shown when objects are behind it)
if (!depth_test)
::glEnable(GL_DEPTH_TEST);
::glPushMatrix();
::glTranslated(origin(0), origin(1), origin(2));
::glRotated(90.0, 0.0, 1.0, 0.0);
render_axis(length(0));
::glPopMatrix();
::glBegin(GL_LINES);
// y axis
::glColor3f(0.0f, 1.0f, 0.0f);
::glPushMatrix();
::glTranslated(origin(0), origin(1), origin(2));
::glRotated(-90.0, 1.0, 0.0, 0.0);
render_axis(length(1));
::glPopMatrix();
// z axis
::glColor3f(0.0f, 0.0f, 1.0f);
::glVertex3dv(origin.data());
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1), (GLfloat)origin(2) + length);
::glEnd();
::glPushMatrix();
::glTranslated(origin(0), origin(1), origin(2));
render_axis(length(2));
::glPopMatrix();
::glDisable(GL_LIGHTING);
}
void GLCanvas3D::Axes::render_axis(double length) const
{
::gluQuadricOrientation(m_quadric, GLU_OUTSIDE);
::gluCylinder(m_quadric, Radius, Radius, length, 32, 1);
::gluQuadricOrientation(m_quadric, GLU_INSIDE);
::gluDisk(m_quadric, 0.0, Radius, 32, 1);
::glTranslated(0.0, 0.0, length);
::gluQuadricOrientation(m_quadric, GLU_OUTSIDE);
::gluCylinder(m_quadric, ArrowBaseRadius, 0.0, ArrowLength, 32, 1);
::gluQuadricOrientation(m_quadric, GLU_INSIDE);
::gluDisk(m_quadric, 0.0, ArrowBaseRadius, 32, 1);
}
GLCanvas3D::Shader::Shader()
: m_shader(nullptr)
@ -1133,8 +1162,21 @@ GLCanvas3D::Selection::Selection()
, m_valid(false)
, m_bounding_box_dirty(true)
{
#if ENABLE_RENDER_SELECTION_CENTER
m_quadric = ::gluNewQuadric();
if (m_quadric != nullptr)
::gluQuadricDrawStyle(m_quadric, GLU_FILL);
#endif // ENABLE_RENDER_SELECTION_CENTER
}
#if ENABLE_RENDER_SELECTION_CENTER
GLCanvas3D::Selection::~Selection()
{
if (m_quadric != nullptr)
::gluDeleteQuadric(m_quadric);
}
#endif // ENABLE_RENDER_SELECTION_CENTER
void GLCanvas3D::Selection::set_volumes(GLVolumePtrs* volumes)
{
m_volumes = volumes;
@ -1436,6 +1478,14 @@ bool GLCanvas3D::Selection::is_from_single_object() const
return (0 <= idx) && (idx < 1000);
}
bool GLCanvas3D::Selection::requires_uniform_scale() const
{
if (is_single_full_instance() || is_single_modifier() || is_single_volume())
return false;
return true;
}
int GLCanvas3D::Selection::get_object_idx() const
{
return (m_cache.content.size() == 1) ? m_cache.content.begin()->first : -1;
@ -1490,8 +1540,13 @@ void GLCanvas3D::Selection::translate(const Vec3d& displacement)
#if ENABLE_MODELVOLUME_TRANSFORM
if ((m_mode == Volume) || (*m_volumes)[i]->is_wipe_tower)
{
Vec3d local_displacement = (m_cache.volumes_data[i].get_instance_rotation_matrix() * m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_instance_mirror_matrix()).inverse() * displacement;
(*m_volumes)[i]->set_volume_offset(m_cache.volumes_data[i].get_volume_position() + local_displacement);
if (_requires_local_axes())
(*m_volumes)[i]->set_volume_offset(m_cache.volumes_data[i].get_volume_position() + displacement);
else
{
Vec3d local_displacement = (m_cache.volumes_data[i].get_instance_rotation_matrix() * m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_instance_mirror_matrix()).inverse() * displacement;
(*m_volumes)[i]->set_volume_offset(m_cache.volumes_data[i].get_volume_position() + local_displacement);
}
}
else if (m_mode == Instance)
(*m_volumes)[i]->set_instance_offset(m_cache.volumes_data[i].get_instance_position() + displacement);
@ -1520,9 +1575,14 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
if (is_single_full_instance())
#if ENABLE_WORLD_ROTATIONS
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_instance_rotation_matrix());
(*m_volumes)[i]->set_instance_rotation(new_rotation);
if (local)
(*m_volumes)[i]->set_instance_rotation(rotation);
else
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_instance_rotation_matrix());
(*m_volumes)[i]->set_instance_rotation(new_rotation);
}
}
#else
#if ENABLE_MODELVOLUME_TRANSFORM
@ -1535,11 +1595,16 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
else if (is_single_volume() || is_single_modifier())
#if ENABLE_WORLD_ROTATIONS
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
const Transform3d& inst_m = m_cache.volumes_data[i].get_instance_rotation_matrix();
Vec3d new_rotation = Geometry::extract_euler_angles(inst_m.inverse() * m * inst_m * m_cache.volumes_data[i].get_volume_rotation_matrix());
(*m_volumes)[i]->set_volume_rotation(new_rotation);
}
if (_requires_local_axes())
(*m_volumes)[i]->set_volume_rotation(rotation);
else
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
const Transform3d& inst_m = m_cache.volumes_data[i].get_instance_rotation_matrix();
Vec3d new_rotation = Geometry::extract_euler_angles(inst_m.inverse() * m * inst_m * m_cache.volumes_data[i].get_volume_rotation_matrix());
(*m_volumes)[i]->set_volume_rotation(new_rotation);
}
}
#else
(*m_volumes)[i]->set_volume_rotation(rotation);
#endif // ENABLE_WORLD_ROTATIONS
@ -1960,7 +2025,7 @@ void GLCanvas3D::Selection::erase()
void GLCanvas3D::Selection::render() const
{
if (is_empty())
if (!m_valid || is_empty())
return;
// render cumulative bounding box of selected volumes
@ -1968,6 +2033,28 @@ void GLCanvas3D::Selection::render() const
_render_synchronized_volumes();
}
#if ENABLE_RENDER_SELECTION_CENTER
void GLCanvas3D::Selection::render_center() const
{
if (!m_valid || is_empty() || (m_quadric == nullptr))
return;
const Vec3d& center = get_bounding_box().center();
::glDisable(GL_DEPTH_TEST);
::glEnable(GL_LIGHTING);
::glColor3f(1.0f, 1.0f, 1.0f);
::glPushMatrix();
::glTranslated(center(0), center(1), center(2));
::gluSphere(m_quadric, 0.75, 32, 32);
::glPopMatrix();
::glDisable(GL_LIGHTING);
}
#endif // ENABLE_RENDER_SELECTION_CENTER
void GLCanvas3D::Selection::_update_valid()
{
m_valid = (m_volumes != nullptr) && (m_model != nullptr);
@ -2501,9 +2588,14 @@ void GLCanvas3D::Selection::_ensure_on_bed()
}
#endif // ENABLE_ENSURE_ON_BED_WHILE_SCALING
const float GLCanvas3D::Gizmos::OverlayTexturesScale = 1.0f;
const float GLCanvas3D::Gizmos::OverlayOffsetX = 10.0f * OverlayTexturesScale;
const float GLCanvas3D::Gizmos::OverlayGapY = 5.0f * OverlayTexturesScale;
bool GLCanvas3D::Selection::_requires_local_axes() const
{
return (m_mode == Volume) && is_from_single_instance();
}
const float GLCanvas3D::Gizmos::OverlayIconsScale = 1.0f;
const float GLCanvas3D::Gizmos::OverlayBorder = 5.0f;
const float GLCanvas3D::Gizmos::OverlayGapY = 5.0f * OverlayIconsScale;
GLCanvas3D::Gizmos::Gizmos()
: m_enabled(false)
@ -2584,6 +2676,23 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
m_gizmos.insert(GizmosMap::value_type(SlaSupports, gizmo));
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_background_texture.metadata.filename = "toolbar_background.png";
m_background_texture.metadata.left = 16;
m_background_texture.metadata.top = 16;
m_background_texture.metadata.right = 16;
m_background_texture.metadata.bottom = 16;
if (!m_background_texture.metadata.filename.empty())
{
if (!m_background_texture.texture.load_from_file(resources_dir() + "/icons/" + m_background_texture.metadata.filename, false))
{
_reset();
return false;
}
}
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
return true;
}
@ -2606,24 +2715,22 @@ std::string GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, con
float cnv_h = (float)canvas.get_canvas_size().get_height();
float height = _get_total_overlay_height();
float top_y = 0.5f * (cnv_h - height);
float top_y = 0.5f * (cnv_h - height) + OverlayBorder;
for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
float tex_size = (float)it->second->get_textures_size() * OverlayTexturesScale;
float half_tex_size = 0.5f * tex_size;
float icon_size = (float)it->second->get_textures_size() * OverlayIconsScale;
// we currently use circular icons for gizmo, so we check the radius
if (it->second->is_activable(selection) && (it->second->get_state() != GLGizmoBase::On))
{
bool inside = (mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size;
bool inside = (OverlayBorder <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= OverlayBorder + icon_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + icon_size);
it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
if (inside)
name = it->second->get_name();
}
top_y += (tex_size + OverlayGapY);
top_y += (icon_size + OverlayGapY);
}
return name;
@ -2636,17 +2743,16 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec
float cnv_h = (float)canvas.get_canvas_size().get_height();
float height = _get_total_overlay_height();
float top_y = 0.5f * (cnv_h - height);
float top_y = 0.5f * (cnv_h - height) + OverlayBorder;
for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
float tex_size = (float)it->second->get_textures_size() * OverlayTexturesScale;
float half_tex_size = 0.5f * tex_size;
float icon_size = (float)it->second->get_textures_size() * OverlayIconsScale;
// we currently use circular icons for gizmo, so we check the radius
if (it->second->is_activable(selection) && ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size))
bool inside = (OverlayBorder <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= OverlayBorder + icon_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + icon_size);
if (it->second->is_activable(selection) && inside)
{
if ((it->second->get_state() == GLGizmoBase::On))
{
@ -2662,7 +2768,7 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec
else
it->second->set_state(GLGizmoBase::Off);
top_y += (tex_size + OverlayGapY);
top_y += (icon_size + OverlayGapY);
}
GizmosMap::iterator it = m_gizmos.find(m_current);
@ -2734,20 +2840,18 @@ bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const
float cnv_h = (float)canvas.get_canvas_size().get_height();
float height = _get_total_overlay_height();
float top_y = 0.5f * (cnv_h - height);
float top_y = 0.5f * (cnv_h - height) + OverlayBorder;
for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
float tex_size = (float)it->second->get_textures_size() * OverlayTexturesScale;
float half_tex_size = 0.5f * tex_size;
float icon_size = (float)it->second->get_textures_size() * OverlayIconsScale;
// we currently use circular icons for gizmo, so we check the radius
if ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)
if ((OverlayBorder <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= OverlayBorder + icon_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + icon_size))
return true;
top_y += (tex_size + OverlayGapY);
top_y += (icon_size + OverlayGapY);
}
return false;
@ -3020,21 +3124,102 @@ void GLCanvas3D::Gizmos::_render_overlay(const GLCanvas3D& canvas, const GLCanva
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float height = _get_total_overlay_height();
float top_x = (OverlayOffsetX - 0.5f * cnv_w) * inv_zoom;
float top_y = 0.5f * height * inv_zoom;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float scaled_border = OverlayBorder * inv_zoom;
float top_x = (-0.5f * cnv_w) * inv_zoom;
float top_y = (0.5f * height) * inv_zoom;
float left = top_x;
float top = top_y;
float right = left + _get_total_overlay_width() * inv_zoom;
float bottom = top - height * inv_zoom;
// renders background
unsigned int bg_tex_id = m_background_texture.texture.get_id();
float bg_tex_width = (float)m_background_texture.texture.get_width();
float bg_tex_height = (float)m_background_texture.texture.get_height();
if ((bg_tex_id != 0) && (bg_tex_width > 0) && (bg_tex_height > 0))
{
float inv_bg_tex_width = (bg_tex_width != 0.0f) ? 1.0f / bg_tex_width : 0.0f;
float inv_bg_tex_height = (bg_tex_height != 0.0f) ? 1.0f / bg_tex_height : 0.0f;
float bg_uv_left = 0.0f;
float bg_uv_right = 1.0f;
float bg_uv_top = 1.0f;
float bg_uv_bottom = 0.0f;
float bg_left = left;
float bg_right = right;
float bg_top = top;
float bg_bottom = bottom;
float bg_width = right - left;
float bg_height = top - bottom;
float bg_min_size = std::min(bg_width, bg_height);
float bg_uv_i_left = (float)m_background_texture.metadata.left * inv_bg_tex_width;
float bg_uv_i_right = 1.0f - (float)m_background_texture.metadata.right * inv_bg_tex_width;
float bg_uv_i_top = 1.0f - (float)m_background_texture.metadata.top * inv_bg_tex_height;
float bg_uv_i_bottom = (float)m_background_texture.metadata.bottom * inv_bg_tex_height;
float bg_i_left = bg_left + scaled_border;
float bg_i_right = bg_right - scaled_border;
float bg_i_top = bg_top - scaled_border;
float bg_i_bottom = bg_bottom + scaled_border;
bg_uv_left = bg_uv_i_left;
bg_i_left = bg_left;
if ((OverlayBorder > 0) && (bg_uv_top != bg_uv_i_top))
{
if (bg_uv_left != bg_uv_i_left)
GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_i_top, bg_top, { { bg_uv_left, bg_uv_i_top }, { bg_uv_i_left, bg_uv_i_top }, { bg_uv_i_left, bg_uv_top }, { bg_uv_left, bg_uv_top } });
GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_i_top, bg_top, { { bg_uv_i_left, bg_uv_i_top }, { bg_uv_i_right, bg_uv_i_top }, { bg_uv_i_right, bg_uv_top }, { bg_uv_i_left, bg_uv_top } });
if (bg_uv_right != bg_uv_i_right)
GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_i_top, bg_top, { { bg_uv_i_right, bg_uv_i_top }, { bg_uv_right, bg_uv_i_top }, { bg_uv_right, bg_uv_top }, { bg_uv_i_right, bg_uv_top } });
}
if ((OverlayBorder > 0) && (bg_uv_left != bg_uv_i_left))
GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_i_bottom, bg_i_top, { { bg_uv_left, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_top }, { bg_uv_left, bg_uv_i_top } });
GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_i_bottom, bg_i_top, { { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_top }, { bg_uv_i_left, bg_uv_i_top } });
if ((OverlayBorder > 0) && (bg_uv_right != bg_uv_i_right))
GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_i_bottom, bg_i_top, { { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_right, bg_uv_i_bottom }, { bg_uv_right, bg_uv_i_top }, { bg_uv_i_right, bg_uv_i_top } });
if ((OverlayBorder > 0) && (bg_uv_bottom != bg_uv_i_bottom))
{
if (bg_uv_left != bg_uv_i_left)
GLTexture::render_sub_texture(bg_tex_id, bg_left, bg_i_left, bg_bottom, bg_i_bottom, { { bg_uv_left, bg_uv_bottom }, { bg_uv_i_left, bg_uv_bottom }, { bg_uv_i_left, bg_uv_i_bottom }, { bg_uv_left, bg_uv_i_bottom } });
GLTexture::render_sub_texture(bg_tex_id, bg_i_left, bg_i_right, bg_bottom, bg_i_bottom, { { bg_uv_i_left, bg_uv_bottom }, { bg_uv_i_right, bg_uv_bottom }, { bg_uv_i_right, bg_uv_i_bottom }, { bg_uv_i_left, bg_uv_i_bottom } });
if (bg_uv_right != bg_uv_i_right)
GLTexture::render_sub_texture(bg_tex_id, bg_i_right, bg_right, bg_bottom, bg_i_bottom, { { bg_uv_i_right, bg_uv_bottom }, { bg_uv_right, bg_uv_bottom }, { bg_uv_right, bg_uv_i_bottom }, { bg_uv_i_right, bg_uv_i_bottom } });
}
}
top_x += OverlayBorder * inv_zoom;
top_y -= OverlayBorder * inv_zoom;
#else
float top_x = (OverlayBorder - 0.5f * cnv_w) * inv_zoom;
float top_y = (0.5f * height - OverlayBorder) * inv_zoom;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float scaled_gap_y = OverlayGapY * inv_zoom;
for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
float tex_size = (float)it->second->get_textures_size() * OverlayTexturesScale * inv_zoom;
GLTexture::render_texture(it->second->get_texture_id(), top_x, top_x + tex_size, top_y - tex_size, top_y);
float icon_size = (float)it->second->get_textures_size() * OverlayIconsScale * inv_zoom;
GLTexture::render_texture(it->second->get_texture_id(), top_x, top_x + icon_size, top_y - icon_size, top_y);
#if ENABLE_IMGUI
if (it->second->get_state() == GLGizmoBase::On)
it->second->render_input_window(2.0f * OverlayOffsetX + tex_size * zoom, 0.5f * cnv_h - top_y * zoom, selection);
it->second->render_input_window(2.0f * OverlayBorder + icon_size * zoom, 0.5f * cnv_h - top_y * zoom, selection);
#endif // ENABLE_IMGUI
top_y -= (tex_size + scaled_gap_y);
top_y -= (icon_size + scaled_gap_y);
}
}
@ -3047,19 +3232,35 @@ void GLCanvas3D::Gizmos::_render_current_gizmo(const GLCanvas3D::Selection& sele
float GLCanvas3D::Gizmos::_get_total_overlay_height() const
{
float height = 0.0f;
float height = 2.0f * OverlayBorder;
for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if (it->first == SlaSupports && wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA)
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
height += (float)it->second->get_textures_size() * OverlayTexturesScale + OverlayGapY;
height += (float)it->second->get_textures_size() * OverlayIconsScale + OverlayGapY;
}
return height - OverlayGapY;
}
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float GLCanvas3D::Gizmos::_get_total_overlay_width() const
{
float max_icon_width = 0.0f;
for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
max_icon_width = std::max(max_icon_width, (float)it->second->get_textures_size() * OverlayIconsScale);
}
return max_icon_width + 2.0f * OverlayBorder;
}
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLGizmoBase* GLCanvas3D::Gizmos::_get_current() const
{
GizmosMap::const_iterator it = m_gizmos.find(m_current);
@ -3434,11 +3635,16 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
: m_canvas(canvas)
, m_context(nullptr)
, m_in_render(false)
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
, m_toolbar(GLToolbar::Normal)
#else
, m_toolbar(*this)
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#if ENABLE_REMOVE_TABS_FROM_PLATER
, m_view_toolbar(nullptr)
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
, m_use_clipping_planes(false)
, m_sidebar_field("")
, m_config(nullptr)
, m_process(nullptr)
, m_model(nullptr)
@ -3668,7 +3874,7 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape)
// Set the origin and size for painting of the coordinate system axes.
m_axes.origin = Vec3d(0.0, 0.0, (double)GROUND_Z);
set_axes_length(0.3f * (float)m_bed.get_bounding_box().max_size());
set_bed_axes_length(0.1 * m_bed.get_bounding_box().max_size());
if (new_shape)
zoom_to_bed();
@ -3676,9 +3882,9 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape)
m_dirty = true;
}
void GLCanvas3D::set_axes_length(float length)
void GLCanvas3D::set_bed_axes_length(double length)
{
m_axes.length = length;
m_axes.length = length * Vec3d::Ones();
}
void GLCanvas3D::set_color_by(const std::string& value)
@ -3938,21 +4144,20 @@ void GLCanvas3D::render()
_render_background();
if (is_custom_bed) // untextured bed needs to be rendered before objects
{
_render_bed(theta);
// disable depth testing so that axes are not covered by ground
_render_axes(false);
}
_render_objects();
_render_sla_slices();
_render_selection();
_render_axes();
if (!is_custom_bed) // textured bed needs to be rendered after objects
{
_render_axes(true);
_render_bed(theta);
}
#if ENABLE_RENDER_SELECTION_CENTER
_render_selection_center();
#endif // ENABLE_RENDER_SELECTION_CENTER
// we need to set the mouse's scene position here because the depth buffer
// could be invalidated by the following gizmo render methods
@ -4675,7 +4880,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
int layer_editing_object_idx = is_layers_editing_enabled() ? selected_object_idx : -1;
m_layers_editing.last_object_id = layer_editing_object_idx;
bool gizmos_overlay_contains_mouse = m_gizmos.overlay_contains_mouse(*this, m_mouse.position);
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
int toolbar_contains_mouse = m_toolbar.contains_mouse(m_mouse.position, *this);
#else
int toolbar_contains_mouse = m_toolbar.contains_mouse(m_mouse.position);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#if ENABLE_REMOVE_TABS_FROM_PLATER
int view_toolbar_contains_mouse = (m_view_toolbar != nullptr) ? m_view_toolbar->contains_mouse(m_mouse.position, *this) : -1;
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
@ -4699,7 +4908,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if (evt.LeftDClick() && (toolbar_contains_mouse != -1))
{
m_toolbar_action_running = true;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.do_action((unsigned int)toolbar_contains_mouse, *this);
#else
m_toolbar.do_action((unsigned int)toolbar_contains_mouse);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
}
else if (evt.LeftDClick() && (m_gizmos.get_current_type() != Gizmos::Undefined))
{
@ -4778,7 +4991,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if (toolbar_contains_mouse != -1)
{
m_toolbar_action_running = true;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.do_action((unsigned int)toolbar_contains_mouse, *this);
#else
m_toolbar.do_action((unsigned int)toolbar_contains_mouse);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_mouse.left_down = false;
}
else
@ -4983,7 +5200,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if (evt.LeftUp() && !m_mouse.dragging && (m_hover_volume_id == -1) && !gizmos_overlay_contains_mouse && !m_gizmos.is_dragging() && !is_layers_editing_enabled())
{
// deselect and propagate event through callback
if (m_picking_enabled && !m_toolbar_action_running && !m_mouse.ignore_up_event)
if (!evt.ShiftDown() && m_picking_enabled && !m_toolbar_action_running && !m_mouse.ignore_up_event)
{
m_selection.clear();
m_selection.set_mode(Selection::Instance);
@ -5061,7 +5278,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// updates toolbar overlay
if (tooltip.empty())
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
tooltip = m_toolbar.update_hover_state(m_mouse.position, *this);
#else
tooltip = m_toolbar.update_hover_state(m_mouse.position);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
// updates view toolbar overlay
if (tooltip.empty() && (m_view_toolbar != nullptr))
@ -5413,6 +5634,17 @@ void GLCanvas3D::update_gizmos_on_off_state()
m_gizmos.update_on_off_state(get_selection());
}
void GLCanvas3D::handle_sidebar_focus_event(const std::string& opt_key, bool focus_on)
{
m_sidebar_field = focus_on ? opt_key : "";
if (!m_sidebar_field.empty())
{
m_gizmos.reset_all_states();
m_dirty = true;
}
}
bool GLCanvas3D::_is_shown_on_screen() const
{
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
@ -5429,7 +5661,24 @@ bool GLCanvas3D::_init_toolbar()
if (!m_toolbar.is_enabled())
return true;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
ItemsIconsTexture::Metadata icons_data;
icons_data.filename = "toolbar.png";
icons_data.icon_size = 36;
icons_data.icon_border_size = 1;
icons_data.icon_gap_size = 1;
BackgroundTexture::Metadata background_data;
background_data.filename = "toolbar_background.png";
background_data.left = 16;
background_data.top = 16;
background_data.right = 16;
background_data.bottom = 16;
if (!m_toolbar.init(icons_data, background_data))
#else
if (!m_toolbar.init("toolbar.png", 36, 1, 1))
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
{
// unable to init the toolbar texture, disable it
m_toolbar.set_enabled(false);
@ -5438,6 +5687,10 @@ bool GLCanvas3D::_init_toolbar()
// m_toolbar.set_layout_type(GLToolbar::Layout::Vertical);
m_toolbar.set_layout_type(GLToolbar::Layout::Horizontal);
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.set_layout_orientation(GLToolbar::Layout::Top);
m_toolbar.set_border(5.0f);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.set_separator_size(5);
m_toolbar.set_gap_size(2);
@ -5524,9 +5777,6 @@ bool GLCanvas3D::_init_toolbar()
if (!m_toolbar.add_item(item))
return false;
if (!m_toolbar.add_separator())
return false;
enable_toolbar_item("add", true);
return true;
@ -5872,9 +6122,9 @@ void GLCanvas3D::_render_bed(float theta) const
m_bed.render(theta);
}
void GLCanvas3D::_render_axes(bool depth_test) const
void GLCanvas3D::_render_axes() const
{
m_axes.render(depth_test);
m_axes.render();
}
void GLCanvas3D::_render_objects() const
@ -5950,6 +6200,14 @@ void GLCanvas3D::_render_selection() const
m_selection.render();
}
#if ENABLE_RENDER_SELECTION_CENTER
void GLCanvas3D::_render_selection_center() const
{
if (!m_gizmos.is_running())
m_selection.render_center();
}
#endif // ENABLE_RENDER_SELECTION_CENTER
void GLCanvas3D::_render_warning_texture() const
{
if (!m_warning_texture_enabled)
@ -6063,7 +6321,11 @@ void GLCanvas3D::_render_toolbar() const
#if !ENABLE_REMOVE_TABS_FROM_PLATER
_resize_toolbar();
#endif // !ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.render(*this);
#else
m_toolbar.render();
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
}
#if ENABLE_REMOVE_TABS_FROM_PLATER
@ -6093,9 +6355,7 @@ void GLCanvas3D::_render_camera_target() const
::glColor3f(0.0f, 1.0f, 0.0f);
::glVertex3d(target(0), target(1) - half_length, target(2));
::glVertex3d(target(0), target(1) + half_length, target(2));
::glEnd();
::glBegin(GL_LINES);
// draw line for z axis
::glColor3f(0.0f, 0.0f, 1.0f);
::glVertex3d(target(0), target(1), target(2) - half_length);
::glVertex3d(target(0), target(1), target(2) + half_length);
@ -7721,25 +7981,54 @@ void GLCanvas3D::_resize_toolbar() const
float zoom = get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLToolbar::Layout::EOrientation orientation = m_toolbar.get_layout_orientation();
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
switch (m_toolbar.get_layout_type())
{
default:
case GLToolbar::Layout::Horizontal:
{
// centers the toolbar on the top edge of the 3d scene
unsigned int toolbar_width = m_toolbar.get_width();
float top = (0.5f * (float)cnv_size.get_height() - 2.0f) * inv_zoom;
float left = -0.5f * (float)toolbar_width * inv_zoom;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float top, left;
if (orientation == GLToolbar::Layout::Top)
{
top = 0.5f * (float)cnv_size.get_height() * inv_zoom;
left = -0.5f * m_toolbar.get_width() * inv_zoom;
}
else
{
top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom;
left = -0.5f * m_toolbar.get_width() * inv_zoom;
}
#else
float top = 0.5f * (float)cnv_size.get_height() * inv_zoom;
float left = -0.5f * m_toolbar.get_width() * inv_zoom;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.set_position(top, left);
break;
}
case GLToolbar::Layout::Vertical:
{
// centers the toolbar on the right edge of the 3d scene
unsigned int toolbar_width = m_toolbar.get_width();
unsigned int toolbar_height = m_toolbar.get_height();
float top = 0.5f * (float)toolbar_height * inv_zoom;
float left = (0.5f * (float)cnv_size.get_width() - toolbar_width - 2.0f) * inv_zoom;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float top, left;
if (orientation == GLToolbar::Layout::Left)
{
top = 0.5f * m_toolbar.get_height() * inv_zoom;
left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom;
}
else
{
top = 0.5f * m_toolbar.get_height() * inv_zoom;
left = (0.5f * (float)cnv_size.get_width() - m_toolbar.get_width()) * inv_zoom;
}
#else
float top = 0.5f * m_toolbar.get_height() * inv_zoom;
float left = (0.5f * (float)cnv_size.get_width() - m_toolbar.get_width()) * inv_zoom;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
m_toolbar.set_position(top, left);
break;
}
@ -7748,6 +8037,7 @@ void GLCanvas3D::_resize_toolbar() const
#if ENABLE_REMOVE_TABS_FROM_PLATER
if (m_view_toolbar != nullptr)
{
// places the toolbar on the bottom-left corner of the 3d scene
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar->get_height()) * inv_zoom;
float left = -0.5f * (float)cnv_size.get_width() * inv_zoom;
m_view_toolbar->set_position(top, left);

View file

@ -20,6 +20,8 @@ class wxTimerEvent;
class wxPaintEvent;
class wxGLCanvas;
class GLUquadric;
typedef class GLUquadric GLUquadricObj;
namespace Slic3r {
@ -155,7 +157,7 @@ class GLCanvas3D
// float distance;
#if !ENABLE_CONSTRAINED_CAMERA_TARGET
Vec3d target;
#endif !// ENABLE_CONSTRAINED_CAMERA_TARGET
#endif // ENABLE_CONSTRAINED_CAMERA_TARGET
private:
#if ENABLE_CONSTRAINED_CAMERA_TARGET
@ -231,12 +233,20 @@ class GLCanvas3D
struct Axes
{
static const double Radius;
static const double ArrowBaseRadius;
static const double ArrowLength;
Vec3d origin;
float length;
Vec3d length;
GLUquadricObj* m_quadric;
Axes();
~Axes();
void render(bool depth_test) const;
void render() const;
private:
void render_axis(double length) const;
};
class Shader
@ -481,8 +491,15 @@ public:
mutable BoundingBoxf3 m_bounding_box;
mutable bool m_bounding_box_dirty;
#if ENABLE_RENDER_SELECTION_CENTER
GLUquadricObj* m_quadric;
#endif // ENABLE_RENDER_SELECTION_CENTER
public:
Selection();
#if ENABLE_RENDER_SELECTION_CENTER
~Selection();
#endif // ENABLE_RENDER_SELECTION_CENTER
void set_volumes(GLVolumePtrs* volumes);
@ -515,6 +532,7 @@ public:
bool is_wipe_tower() const { return m_type == WipeTower; }
bool is_modifier() const { return (m_type == SingleModifier) || (m_type == MultipleModifier); }
bool is_single_modifier() const { return m_type == SingleModifier; }
bool is_multiple_modifier() const { return m_type == MultipleModifier; }
bool is_single_full_instance() const;
bool is_multiple_full_instance() const { return m_type == MultipleFullInstance; }
bool is_single_full_object() const { return m_type == SingleFullObject; }
@ -526,6 +544,7 @@ public:
bool is_from_single_object() const;
bool contains_volume(unsigned int volume_idx) const { return std::find(m_list.begin(), m_list.end(), volume_idx) != m_list.end(); }
bool requires_uniform_scale() const;
// Returns the the object id if the selection is from a single object, otherwise is -1
int get_object_idx() const;
@ -557,6 +576,9 @@ public:
void erase();
void render() const;
#if ENABLE_RENDER_SELECTION_CENTER
void render_center() const;
#endif // ENABLE_RENDER_SELECTION_CENTER
private:
void _update_valid();
@ -577,6 +599,7 @@ public:
#if ENABLE_ENSURE_ON_BED_WHILE_SCALING
void _ensure_on_bed();
#endif // ENABLE_ENSURE_ON_BED_WHILE_SCALING
bool _requires_local_axes() const;
};
class ClippingPlane
@ -607,8 +630,8 @@ public:
private:
class Gizmos
{
static const float OverlayTexturesScale;
static const float OverlayOffsetX;
static const float OverlayIconsScale;
static const float OverlayBorder;
static const float OverlayGapY;
public:
@ -628,6 +651,9 @@ private:
bool m_enabled;
typedef std::map<EType, GLGizmoBase*> GizmosMap;
GizmosMap m_gizmos;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
BackgroundTexture m_background_texture;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
EType m_current;
public:
@ -696,6 +722,9 @@ private:
void _render_current_gizmo(const Selection& selection) const;
float _get_total_overlay_height() const;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float _get_total_overlay_width() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLGizmoBase* _get_current() const;
};
@ -769,11 +798,16 @@ private:
mutable Gizmos m_gizmos;
mutable GLToolbar m_toolbar;
#if ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLToolbar* m_view_toolbar;
#else
GLRadioToolbar* m_view_toolbar;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
ClippingPlane m_clipping_planes[2];
bool m_use_clipping_planes;
mutable SlaCap m_sla_caps[2];
std::string m_sidebar_field;
mutable GLVolumeCollection m_volumes;
Selection m_selection;
@ -824,7 +858,11 @@ public:
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
#if ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_view_toolbar(GLToolbar* toolbar) { m_view_toolbar = toolbar; }
#else
void set_view_toolbar(GLRadioToolbar* toolbar) { m_view_toolbar = toolbar; }
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
bool init(bool useVBOs, bool use_legacy_opengl);
@ -856,8 +894,7 @@ public:
// fills the m_bed.m_grid_lines and sets m_bed.m_origin.
// Sets m_bed.m_polygon to limit the object placement.
void set_bed_shape(const Pointfs& shape);
void set_axes_length(float length);
void set_bed_axes_length(double length);
void set_clipping_plane(unsigned int id, const ClippingPlane& plane)
{
@ -972,7 +1009,7 @@ public:
void viewport_changed();
#endif // ENABLE_CONSTRAINED_CAMERA_TARGET
void handle_sidebar_focus_event(const std::string& opt_key) {}
void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on);
private:
bool _is_shown_on_screen() const;
@ -997,9 +1034,12 @@ private:
void _picking_pass() const;
void _render_background() const;
void _render_bed(float theta) const;
void _render_axes(bool depth_test) const;
void _render_axes() const;
void _render_objects() const;
void _render_selection() const;
#if ENABLE_RENDER_SELECTION_CENTER
void _render_selection_center() const;
#endif // ENABLE_RENDER_SELECTION_CENTER
void _render_warning_texture() const;
void _render_legend_texture() const;
void _render_layer_editing_overlay() const;

File diff suppressed because it is too large Load diff

View file

@ -77,6 +77,9 @@ public:
void do_action(wxEvtHandler *target);
bool is_enabled() const;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool is_disabled() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool is_hovered() const;
bool is_pressed() const;
@ -94,7 +97,25 @@ private:
// from left to right
struct ItemsIconsTexture
{
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
struct Metadata
{
// path of the file containing the icons' texture
std::string filename;
// size of the square icons, in pixels
unsigned int icon_size;
// size of the border, in pixels
unsigned int icon_border_size;
// distance between two adjacent icons (to avoid filtering artifacts), in pixels
unsigned int icon_gap_size;
Metadata();
};
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLTexture texture;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Metadata metadata;
#else
// size of the square icons, in pixels
unsigned int items_icon_size;
// distance from the border, in pixels
@ -103,25 +124,82 @@ struct ItemsIconsTexture
unsigned int items_icon_gap_size;
ItemsIconsTexture();
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
};
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
struct BackgroundTexture
{
struct Metadata
{
// path of the file containing the background texture
std::string filename;
// size of the left edge, in pixels
unsigned int left;
// size of the right edge, in pixels
unsigned int right;
// size of the top edge, in pixels
unsigned int top;
// size of the bottom edge, in pixels
unsigned int bottom;
Metadata();
};
GLTexture texture;
Metadata metadata;
};
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
class GLToolbar
{
public:
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
enum EType : unsigned char
{
Normal,
Radio,
Num_Types
};
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
struct Layout
{
enum Type : unsigned char
enum EType : unsigned char
{
Horizontal,
Vertical,
Num_Types
};
Type type;
enum EOrientation : unsigned int
{
Top,
Bottom,
Left,
Right,
Center,
Num_Locations
};
EType type;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
EOrientation orientation;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float top;
float left;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float border;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float separator_size;
float gap_size;
float icons_scale;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float width;
float height;
bool dirty;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Layout();
};
@ -129,25 +207,50 @@ public:
private:
typedef std::vector<GLToolbarItem*> ItemsList;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
EType m_type;
#else
GLCanvas3D& m_parent;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool m_enabled;
ItemsIconsTexture m_icons_texture;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
BackgroundTexture m_background_texture;
mutable Layout m_layout;
#else
Layout m_layout;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
ItemsList m_items;
public:
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
explicit GLToolbar(EType type);
#else
explicit GLToolbar(GLCanvas3D& parent);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
~GLToolbar();
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool init(const ItemsIconsTexture::Metadata& icons_texture, const BackgroundTexture::Metadata& background_texture);
#else
bool init(const std::string& icons_texture_filename, unsigned int items_icon_size, unsigned int items_icon_border_size, unsigned int items_icon_gap_size);
Layout::Type get_layout_type() const;
void set_layout_type(Layout::Type type);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Layout::EType get_layout_type() const;
void set_layout_type(Layout::EType type);
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Layout::EOrientation get_layout_orientation() const;
void set_layout_orientation(Layout::EOrientation orientation);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_position(float top, float left);
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_border(float border);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_separator_size(float size);
void set_gap_size(float size);
void set_icons_scale(float scale);
bool is_enabled() const;
void set_enabled(bool enable);
@ -160,42 +263,89 @@ public:
void enable_item(const std::string& name);
void disable_item(const std::string& name);
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void select_item(const std::string& name);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool is_item_pressed(const std::string& name) const;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool is_item_disabled(const std::string& name) const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#if ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
std::string update_hover_state(const Vec2d& mouse_pos);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#else
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
void update_hover_state(const Vec2d& mouse_pos);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
void do_action(unsigned int item_id, GLCanvas3D& parent);
#else
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Vec2d& mouse_pos) const;
void do_action(unsigned int item_id);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void render(const GLCanvas3D& parent) const;
#else
void render() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
private:
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void calc_layout() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float get_width_horizontal() const;
float get_width_vertical() const;
float get_height_horizontal() const;
float get_height_vertical() const;
float get_main_size() const;
#if ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
std::string update_hover_state_horizontal(const Vec2d& mouse_pos);
std::string update_hover_state_vertical(const Vec2d& mouse_pos);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#else
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
void update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
void update_hover_state_horizontal(const Vec2d& mouse_pos);
void update_hover_state_vertical(const Vec2d& mouse_pos);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
void render_horizontal(const GLCanvas3D& parent) const;
void render_vertical(const GLCanvas3D& parent) const;
#else
int contains_mouse_horizontal(const Vec2d& mouse_pos) const;
int contains_mouse_vertical(const Vec2d& mouse_pos) const;
void render_horizontal() const;
void render_vertical() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
};
#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE
class GLRadioToolbarItem
{
public:
@ -274,6 +424,7 @@ public:
void render(const GLCanvas3D& parent) const;
};
#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE
} // namespace GUI
} // namespace Slic3r

View file

@ -195,6 +195,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value)));
else if (opt_key.compare("host_type") == 0)
config.set_key_value(opt_key, new ConfigOptionEnum<PrintHostType>(boost::any_cast<PrintHostType>(value)));
else if (opt_key.compare("display_orientation") == 0)
config.set_key_value(opt_key, new ConfigOptionEnum<SLADisplayOrientation>(boost::any_cast<SLADisplayOrientation>(value)));
}
break;
case coPoints:{

View file

@ -73,7 +73,6 @@ GUI_App::GUI_App()
: wxApp()
#if ENABLE_IMGUI
, m_imgui(new ImGuiWrapper())
, m_printhost_queue(new PrintHostJobQueue())
#endif // ENABLE_IMGUI
{}
@ -142,6 +141,8 @@ bool GUI_App::OnInit()
update_mode();
SetTopWindow(mainframe);
m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg()));
CallAfter([this]() {
// temporary workaround for the correct behavior of the Scrolled sidebar panel
auto& panel = sidebar();

View file

@ -92,7 +92,7 @@ class GUI_App : public wxApp
std::unique_ptr<ImGuiWrapper> m_imgui;
#endif // ENABLE_IMGUI
std::unique_ptr<PrintHostJobQueue> m_printhost_queue;
std::unique_ptr<PrintHostJobQueue> m_printhost_job_queue;
public:
bool OnInit() override;
@ -164,7 +164,7 @@ public:
ImGuiWrapper* imgui() { return m_imgui.get(); }
#endif // ENABLE_IMGUI
PrintHostJobQueue& printhost_queue() { return *m_printhost_queue.get(); }
PrintHostJobQueue& printhost_job_queue() { return *m_printhost_job_queue.get(); }
};
DECLARE_APP(GUI_App)

View file

@ -982,6 +982,10 @@ void ObjectList::del_instances_from_object(const int obj_idx)
bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, const int type)
{
if (obj_idx == 1000)
// Cannot delete a wipe tower.
return false;
if (type == itVolume) {
const auto volume = (*m_objects)[obj_idx]->volumes[idx];
@ -1399,6 +1403,20 @@ void ObjectList::update_selections()
auto& selection = wxGetApp().plater()->canvas3D()->get_selection();
wxDataViewItemArray sels;
// We doesn't update selection if SettingsItem for the current object/part is selected
if (GetSelectedItemsCount() == 1 && m_objects_model->GetItemType(GetSelection()) == itSettings )
{
const auto item = GetSelection();
if (selection.is_single_full_object() &&
m_objects_model->GetIdByItem(m_objects_model->GetParent(item)) == selection.get_object_idx())
return;
if (selection.is_single_volume() || selection.is_modifier()) {
const auto gl_vol = selection.get_volume(*selection.get_volume_idxs().begin());
if (m_objects_model->GetVolumeIdByItem(m_objects_model->GetParent(item)) == gl_vol->volume_idx())
return;
}
}
if (selection.is_single_full_object())
{
sels.Add(m_objects_model->GetItemById(selection.get_object_idx()));
@ -1459,13 +1477,11 @@ void ObjectList::update_selections()
select_items(sels);
#ifdef __WXMSW__
if (GetSelection()) {
const int sel_item_row = GetRowByItem(GetSelection());
const int sel_item_row = m_objects_model->GetRowByItem(GetSelection());
ScrollLines(sel_item_row - m_selected_row);
m_selected_row = sel_item_row;
}
#endif //__WXMSW__
}
void ObjectList::update_selections_on_canvas()
@ -1656,7 +1672,9 @@ void ObjectList::change_part_type()
void ObjectList::last_volume_is_deleted(const int obj_idx)
{
if (obj_idx < 0 || (*m_objects).empty() || (*m_objects)[obj_idx]->volumes.empty())
if (obj_idx < 0 || m_objects->empty() ||
obj_idx <= m_objects->size() ||
(*m_objects)[obj_idx]->volumes.empty())
return;
auto volume = (*m_objects)[obj_idx]->volumes[0];

View file

@ -25,18 +25,6 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
m_og->m_on_change = [this](const std::string& opt_key, const boost::any& value) {
std::vector<std::string> axes{ "_x", "_y", "_z" };
if (opt_key == "scale_unit") {
const wxString& selection = boost::any_cast<wxString>(value);
for (auto axis : axes) {
std::string key = "scale" + axis;
m_og->set_side_text(key, selection);
}
m_is_percent_scale = selection == _("%");
update_scale_values();
return;
}
std::string param;
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
@ -51,29 +39,51 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
change_rotation_value(new_value);
else if (param == "scale")
change_scale_value(new_value);
else if (param == "size")
change_size_value(new_value);
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
};
m_og->m_fill_empty_value = [this](const std::string& opt_key)
{
if (opt_key == "scale_unit")
return;
std::string param;
std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
double value = 0.0;
if (param == "position") {
int axis = opt_key.back() == 'x' ? 0 :
opt_key.back() == 'y' ? 1 : 2;
m_og->set_value(opt_key, double_to_string(cache_position(axis)));
return;
value = cache_position(axis);
}
else if (param == "rotation") {
int axis = opt_key.back() == 'x' ? 0 :
opt_key.back() == 'y' ? 1 : 2;
value = cache_rotation(axis);
}
else if (param == "scale") {
int axis = opt_key.back() == 'x' ? 0 :
opt_key.back() == 'y' ? 1 : 2;
value = cache_scale(axis);
}
else if (param == "size") {
int axis = opt_key.back() == 'x' ? 0 :
opt_key.back() == 'y' ? 1 : 2;
value = cache_size(axis);
}
m_og->set_value(opt_key, double_to_string(0.0));
m_og->set_value(opt_key, double_to_string(value));
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false);
};
m_og->m_set_focus = [this](const std::string& opt_key)
{
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key);
wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, true);
};
ConfigOptionDef def;
@ -106,59 +116,37 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
auto add_og_to_object_settings = [](const std::string& option_name, const std::string& sidetext)
{
Line line = { _(option_name), "" };
if (option_name == "Scale") {
line.near_label_widget = [](wxWindow* parent) {
auto btn = new PrusaLockButton(parent, wxID_ANY);
btn->Bind(wxEVT_BUTTON, [btn](wxCommandEvent &event) {
event.Skip();
wxTheApp->CallAfter([btn]() {
wxGetApp().obj_manipul()->set_uniform_scaling(btn->IsLocked());
});
});
return btn;
};
}
ConfigOptionDef def;
def.type = coFloat;
def.default_value = new ConfigOptionFloat(0.0);
def.width = 50;
if (option_name == "Rotation")
{
def.min = -360;
def.max = 360;
}
const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
std::vector<std::string> axes{ "x", "y", "z" };
for (auto axis : axes) {
if (axis == "z" && option_name != "Scale")
if (axis == "z")
def.sidetext = sidetext;
Option option = Option(def, lower_name + "_" + axis);
option.opt.full_width = true;
line.append_option(option);
}
if (option_name == "Scale")
{
def.width = 45;
def.type = coStrings;
def.gui_type = "select_open";
def.enum_labels.push_back(L("%"));
def.enum_labels.push_back(L("mm"));
def.default_value = new ConfigOptionStrings{ "mm" };
const Option option = Option(def, lower_name + "_unit");
line.append_option(option);
}
return line;
};
// Settings table
m_og->append_line(add_og_to_object_settings(L("Position"), L("mm")), &m_move_Label);
m_og->append_line(add_og_to_object_settings(L("Rotation"), "°"));
m_og->append_line(add_og_to_object_settings(L("Scale"), "mm"));
m_og->append_line(add_og_to_object_settings(L("Rotation"), "°"), &m_rotate_Label);
m_og->append_line(add_og_to_object_settings(L("Scale"), "%"), &m_scale_Label);
m_og->append_line(add_og_to_object_settings(L("Size"), "mm"));
/* Unused parameter at this time
def.label = L("Place on bed");
@ -204,9 +192,11 @@ int ObjectManipulation::ol_selection()
void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& selection)
{
wxString move_label = _(L("Position"));
wxString move_label = _(L("Position:"));
wxString rotate_label = _(L("Rotation:"));
wxString scale_label = _(L("Scale factors:"));
#if ENABLE_MODELVOLUME_TRANSFORM
if (selection.is_single_full_instance() || selection.is_single_full_object())
if (selection.is_single_full_instance())
#else
if (selection.is_single_full_object())
{
@ -232,6 +222,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
update_position_value(volume->get_instance_offset());
update_rotation_value(volume->get_instance_rotation());
update_scale_value(volume->get_instance_scaling_factor());
update_size_value(volume->get_instance_transformation().get_matrix(true, true) * volume->bounding_box.size());
#else
update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation());
@ -239,19 +230,15 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
#endif // ENABLE_MODELVOLUME_TRANSFORM
m_og->enable();
}
else if (selection.is_wipe_tower())
else if (selection.is_single_full_object())
{
// the selection contains a single volume
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
#if ENABLE_MODELVOLUME_TRANSFORM
update_position_value(volume->get_volume_offset());
update_rotation_value(volume->get_volume_rotation());
update_scale_value(volume->get_volume_scaling_factor());
#else
update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation());
update_scale_value(volume->get_scaling_factor());
#endif // ENABLE_MODELVOLUME_TRANSFORM
const BoundingBoxf3& box = selection.get_bounding_box();
update_position_value(box.center());
reset_rotation_value();
reset_scale_value();
update_size_value(box.size());
rotate_label = _(L("Rotate:"));
scale_label = _(L("Scale:"));
m_og->enable();
}
else if (selection.is_single_modifier() || selection.is_single_volume())
@ -262,6 +249,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
update_position_value(volume->get_volume_offset());
update_rotation_value(volume->get_volume_rotation());
update_scale_value(volume->get_volume_scaling_factor());
update_size_value(volume->bounding_box.size());
#else
update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation());
@ -272,14 +260,18 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
else if (wxGetApp().obj_list()->multiple_selection())
{
reset_settings_value();
move_label = _(L("Displacement"));
move_label = _(L("Translate:"));
rotate_label = _(L("Rotate:"));
scale_label = _(L("Scale:"));
update_size_value(selection.get_bounding_box().size());
m_og->enable();
}
else
reset_settings_value();
m_move_Label->SetLabel(move_label);
m_og->get_field("scale_unit")->disable();// temporary decision
m_rotate_Label->SetLabel(rotate_label);
m_scale_Label->SetLabel(scale_label);
}
void ObjectManipulation::reset_settings_value()
@ -299,7 +291,7 @@ void ObjectManipulation::reset_position_value()
m_og->set_value("position_y", def_0);
m_og->set_value("position_z", def_0);
cache_position = { 0., 0., 0. };
cache_position = Vec3d::Zero();
}
void ObjectManipulation::reset_rotation_value()
@ -307,68 +299,26 @@ void ObjectManipulation::reset_rotation_value()
m_og->set_value("rotation_x", def_0);
m_og->set_value("rotation_y", def_0);
m_og->set_value("rotation_z", def_0);
cache_rotation = Vec3d::Zero();
}
void ObjectManipulation::reset_scale_value()
{
m_is_percent_scale = true;
m_og->set_value("scale_unit", _("%"));
m_og->set_value("scale_x", def_100);
m_og->set_value("scale_y", def_100);
m_og->set_value("scale_z", def_100);
cache_scale = Vec3d(100.0, 100.0, 100.0);
}
void ObjectManipulation::update_values()
void ObjectManipulation::reset_size_value()
{
int selection = ol_selection();
if (selection < 0 || wxGetApp().mainframe->m_plater->model().objects.size() <= selection) {
m_og->set_value("position_x", def_0);
m_og->set_value("position_y", def_0);
m_og->set_value("position_z", def_0);
m_og->set_value("scale_x" , def_0);
m_og->set_value("scale_y" , def_0);
m_og->set_value("scale_z" , def_0);
m_og->set_value("rotation_x", def_0);
m_og->set_value("rotation_y", def_0);
m_og->set_value("rotation_z", def_0);
m_og->disable();
return;
}
m_is_percent_scale = boost::any_cast<wxString>(m_og->get_value("scale_unit")) == _("%");
m_og->set_value("size_x", def_0);
m_og->set_value("size_y", def_0);
m_og->set_value("size_z", def_0);
update_position_values();
update_scale_values();
update_rotation_values();
m_og->enable();
}
void ObjectManipulation::update_scale_values()
{
int selection = ol_selection();
ModelObjectPtrs& objects = wxGetApp().mainframe->m_plater->model().objects;
auto instance = objects[selection]->instances.front();
auto size = objects[selection]->instance_bounding_box(0).size();
if (m_is_percent_scale) {
m_og->set_value("scale_x", double_to_string(instance->get_scaling_factor(X) * 100, 2));
m_og->set_value("scale_y", double_to_string(instance->get_scaling_factor(Y) * 100, 2));
m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * 100, 2));
}
else {
m_og->set_value("scale_x", double_to_string(size(0), 2));
m_og->set_value("scale_y", double_to_string(size(1), 2));
m_og->set_value("scale_z", double_to_string(size(2), 2));
}
}
void ObjectManipulation::update_position_values()
{
auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front();
m_og->set_value("position_x", double_to_string(instance->get_offset(X), 2));
m_og->set_value("position_y", double_to_string(instance->get_offset(Y), 2));
m_og->set_value("position_z", double_to_string(instance->get_offset(Z), 2));
cache_size = Vec3d::Zero();
}
void ObjectManipulation::update_position_value(const Vec3d& position)
@ -382,42 +332,21 @@ void ObjectManipulation::update_position_value(const Vec3d& position)
void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor)
{
// this is temporary
// to be able to update the values as size
// we need to store somewhere the original size
// or have it passed as parameter
if (!m_is_percent_scale) {
m_is_percent_scale = true;
m_og->set_value("scale_unit", _("%"));
}
auto scale = scaling_factor * 100.0;
m_og->set_value("scale_x", double_to_string(scale(0), 2));
m_og->set_value("scale_y", double_to_string(scale(1), 2));
m_og->set_value("scale_z", double_to_string(scale(2), 2));
cache_scale = scale;
}
void ObjectManipulation::update_rotation_values()
void ObjectManipulation::update_size_value(const Vec3d& size)
{
update_rotation_value(wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front()->get_rotation());
}
m_og->set_value("size_x", double_to_string(size(0), 2));
m_og->set_value("size_y", double_to_string(size(1), 2));
m_og->set_value("size_z", double_to_string(size(2), 2));
void ObjectManipulation::update_rotation_value(double angle, Axis axis)
{
std::string axis_str;
switch (axis) {
case X: {
axis_str = "rotation_x";
break; }
case Y: {
axis_str = "rotation_y";
break; }
case Z: {
axis_str = "rotation_z";
break; }
}
m_og->set_value(axis_str, round_nearest(int(Geometry::rad2deg(angle)), 0));
cache_size = size;
}
void ObjectManipulation::update_rotation_value(const Vec3d& rotation)
@ -425,16 +354,15 @@ void ObjectManipulation::update_rotation_value(const Vec3d& rotation)
m_og->set_value("rotation_x", double_to_string(round_nearest(Geometry::rad2deg(rotation(0)), 0), 2));
m_og->set_value("rotation_y", double_to_string(round_nearest(Geometry::rad2deg(rotation(1)), 0), 2));
m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(rotation(2)), 0), 2));
}
cache_rotation = rotation;
}
void ObjectManipulation::change_position_value(const Vec3d& position)
{
Vec3d displacement(position - cache_position);
auto canvas = wxGetApp().plater()->canvas3D();
canvas->get_selection().start_dragging();
canvas->get_selection().translate(displacement);
canvas->get_selection().translate(position - cache_position);
canvas->do_move();
cache_position = position;
@ -442,38 +370,62 @@ void ObjectManipulation::change_position_value(const Vec3d& position)
void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
{
GLCanvas3D* canvas = wxGetApp().plater()->canvas3D();
const GLCanvas3D::Selection& selection = canvas->get_selection();
Vec3d rad_rotation;
for (size_t i = 0; i < 3; ++i)
{
rad_rotation(i) = Geometry::deg2rad(rotation(i));
auto canvas = wxGetApp().plater()->canvas3D();
}
canvas->get_selection().start_dragging();
canvas->get_selection().rotate(rad_rotation, false);
canvas->get_selection().rotate(rad_rotation, selection.is_single_full_instance());
canvas->do_rotate();
}
void ObjectManipulation::change_scale_value(const Vec3d& scale)
{
Vec3d scaling_factor;
if (m_is_percent_scale)
scaling_factor = scale*0.01;
else {
int selection = ol_selection();
ModelObjectPtrs& objects = *wxGetApp().model_objects();
auto size = objects[selection]->instance_bounding_box(0).size();
for (size_t i = 0; i < 3; ++i)
scaling_factor(i) = scale(i) / size(i);
Vec3d scaling_factor = scale;
const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
if (selection.requires_uniform_scale())
{
Vec3d abs_scale_diff = (scale - cache_scale).cwiseAbs();
double max_diff = abs_scale_diff(X);
Axis max_diff_axis = X;
if (max_diff < abs_scale_diff(Y))
{
max_diff = abs_scale_diff(Y);
max_diff_axis = Y;
}
if (max_diff < abs_scale_diff(Z))
{
max_diff = abs_scale_diff(Z);
max_diff_axis = Z;
}
scaling_factor = Vec3d(scale(max_diff_axis), scale(max_diff_axis), scale(max_diff_axis));
}
scaling_factor *= 0.01;
auto canvas = wxGetApp().plater()->canvas3D();
canvas->get_selection().start_dragging();
canvas->get_selection().scale(scaling_factor, false);
canvas->do_scale();
}
void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& v)
void ObjectManipulation::change_size_value(const Vec3d& size)
{
std::cout << label << " => " << " X:" << v(0) << " Y:" << v(1) << " Z:" << v(2) << std::endl;
const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
Vec3d ref_size = cache_size;
if (selection.is_single_full_instance())
{
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
ref_size = volume->bounding_box.size();
}
change_scale_value(100.0 * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2)));
}
} //namespace GUI

View file

@ -14,12 +14,14 @@ namespace GUI {
class ObjectManipulation : public OG_Settings
{
bool m_is_percent_scale = false; // true -> percentage scale unit
// false -> uniform scale unit
bool m_is_uniform_scale = false; // It indicates if scale is uniform
Vec3d cache_position { 0., 0., 0. };
Vec3d cache_rotation { 0., 0., 0. };
Vec3d cache_scale { 100., 100., 100. };
Vec3d cache_size { 0., 0., 0. };
wxStaticText* m_move_Label = nullptr;
wxStaticText* m_scale_Label = nullptr;
wxStaticText* m_rotate_Label = nullptr;
public:
ObjectManipulation(wxWindow* parent);
@ -36,31 +38,22 @@ public:
void reset_position_value();
void reset_rotation_value();
void reset_scale_value();
void reset_size_value();
void update_values();
// update position values displacements or "gizmos"
void update_position_values();
void update_position_value(const Vec3d& position);
// update scale values after scale unit changing or "gizmos"
void update_scale_values();
void update_scale_value(const Vec3d& scaling_factor);
// update rotation values object selection changing
void update_rotation_values();
// update size values after scale unit changing or "gizmos"
void update_size_value(const Vec3d& size);
// update rotation value after "gizmos"
void update_rotation_value(double angle, Axis axis);
void update_rotation_value(const Vec3d& rotation);
void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; }
// change values
void change_position_value(const Vec3d& position);
void change_rotation_value(const Vec3d& rotation);
void change_scale_value(const Vec3d& scale);
private:
void print_cashe_value(const std::string& label, const Vec3d& value);
void change_size_value(const Vec3d& size);
};
}}

View file

@ -92,7 +92,11 @@ bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, Ba
return true;
}
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void View3D::set_view_toolbar(GLToolbar* toolbar)
#else
void View3D::set_view_toolbar(GLRadioToolbar* toolbar)
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
{
if (m_canvas != nullptr)
m_canvas->set_view_toolbar(toolbar);
@ -365,7 +369,11 @@ Preview::~Preview()
}
#if ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void Preview::set_view_toolbar(GLToolbar* toolbar)
#else
void Preview::set_view_toolbar(GLRadioToolbar* toolbar)
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
{
if (m_canvas != nullptr)
m_canvas->set_view_toolbar(toolbar);
@ -377,17 +385,13 @@ void Preview::set_number_extruders(unsigned int number_extruders)
if (m_number_extruders != number_extruders)
{
m_number_extruders = number_extruders;
int type = 0; // color by a feature type
if (number_extruders > 1)
{
int tool_idx = m_choice_view_type->FindString(_(L("Tool")));
int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type
m_choice_view_type->SetSelection(type);
if ((0 <= type) && (type < (int)GCodePreviewData::Extrusion::Num_View_Types))
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
int tool_idx = m_choice_view_type->FindString(_(L("Tool")));
int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type
m_choice_view_type->SetSelection(type);
if ((0 <= type) && (type < (int)GCodePreviewData::Extrusion::Num_View_Types))
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
m_preferred_color_mode = (type == tool_idx) ? "tool_or_feature" : "feature";
}
m_preferred_color_mode = (type == tool_idx) ? "tool_or_feature" : "feature";
}
}

View file

@ -28,9 +28,15 @@ class Model;
namespace GUI {
class GLCanvas3D;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#if ENABLE_REMOVE_TABS_FROM_PLATER
class GLToolbar;
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
#else
#if ENABLE_REMOVE_TABS_FROM_PLATER
class GLRadioToolbar;
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#if ENABLE_REMOVE_TABS_FROM_PLATER
class View3D : public wxPanel
@ -53,7 +59,11 @@ public:
wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; }
GLCanvas3D* get_canvas3d() { return m_canvas; }
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_view_toolbar(GLToolbar* toolbar);
#else
void set_view_toolbar(GLRadioToolbar* toolbar);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_as_dirty();
void set_bed_shape(const Pointfs& shape);
@ -122,7 +132,11 @@ public:
wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; }
#if ENABLE_REMOVE_TABS_FROM_PLATER
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_view_toolbar(GLToolbar* toolbar);
#else
void set_view_toolbar(GLRadioToolbar* toolbar);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
void set_number_extruders(unsigned int number_extruders);

View file

@ -18,6 +18,7 @@
#include "ProgressStatusBar.hpp"
#include "3DScene.hpp"
#include "AppConfig.hpp"
#include "PrintHostDialogs.hpp"
#include "wxExtensions.hpp"
#include "I18N.hpp"
@ -30,7 +31,8 @@ namespace GUI {
MainFrame::MainFrame(const bool no_plater, const bool loaded) :
wxFrame(NULL, wxID_ANY, SLIC3R_BUILD, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE),
m_no_plater(no_plater),
m_loaded(loaded)
m_loaded(loaded),
m_printhost_queue_dlg(new PrintHostQueueDialog(this))
{
// Load the icon either from the exe, or from the ico file.
#if _WIN32
@ -326,7 +328,7 @@ void MainFrame::init_menubar()
size_t tab_offset = 0;
if (m_plater) {
#if ENABLE_REMOVE_TABS_FROM_PLATER
append_menu_item(windowMenu, wxID_ANY, L("Plater Tab\tCtrl+1"), L("Show the plater"),
append_menu_item(windowMenu, wxID_HIGHEST + 1, L("Plater Tab\tCtrl+1"), L("Show the plater"),
[this](wxCommandEvent&) { select_tab(0); }, "application_view_tile.png");
#else
append_menu_item(windowMenu, wxID_ANY, L("Select Plater Tab\tCtrl+1"), L("Show the plater"),
@ -338,22 +340,35 @@ void MainFrame::init_menubar()
windowMenu->AppendSeparator();
}
#if ENABLE_REMOVE_TABS_FROM_PLATER
append_menu_item(windowMenu, wxID_ANY, L("Print Settings Tab\tCtrl+2"), L("Show the print settings"),
append_menu_item(windowMenu, wxID_HIGHEST + 2, L("Print Settings Tab\tCtrl+2"), L("Show the print settings"),
[this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 0); }, "cog.png");
append_menu_item(windowMenu, wxID_ANY, L("Filament Settings Tab\tCtrl+3"), L("Show the filament settings"),
append_menu_item(windowMenu, wxID_HIGHEST + 3, L("Filament Settings Tab\tCtrl+3"), L("Show the filament settings"),
[this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 1); }, "spool.png");
append_menu_item(windowMenu, wxID_ANY, L("Printer Settings Tab\tCtrl+4"), L("Show the printer settings"),
append_menu_item(windowMenu, wxID_HIGHEST + 4, L("Printer Settings Tab\tCtrl+4"), L("Show the printer settings"),
[this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 2); }, "printer_empty.png");
if (m_plater) {
windowMenu->AppendSeparator();
wxMenuItem* item_3d = append_menu_item(windowMenu, wxID_ANY, L("3D\tCtrl+5"), L("Show the 3D editing view"),
[this](wxCommandEvent&) { m_plater->select_view_3D("3D"); }, "");
wxMenuItem* item_preview = append_menu_item(windowMenu, wxID_ANY, L("Preview\tCtrl+6"), L("Show the 3D slices preview"),
[this](wxCommandEvent&) { m_plater->select_view_3D("Preview"); }, "");
wxMenuItem* item_3d = append_menu_item(windowMenu, wxID_HIGHEST + 5, L("3D\tCtrl+5"), L("Show the 3D editing view"),
[this](wxCommandEvent&) { m_plater->select_view_3D("3D"); }, "");
wxMenuItem* item_preview = append_menu_item(windowMenu, wxID_HIGHEST + 6, L("Preview\tCtrl+6"), L("Show the 3D slices preview"),
[this](wxCommandEvent&) { m_plater->select_view_3D("Preview"); }, "");
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_change_view()); }, item_3d->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_change_view()); }, item_preview->GetId());
}
#if _WIN32
// This is needed on Windows to fake the CTRL+# of the window menu when using the numpad
wxAcceleratorEntry entries[6];
entries[0].Set(wxACCEL_CTRL, WXK_NUMPAD1, wxID_HIGHEST + 1);
entries[1].Set(wxACCEL_CTRL, WXK_NUMPAD2, wxID_HIGHEST + 2);
entries[2].Set(wxACCEL_CTRL, WXK_NUMPAD3, wxID_HIGHEST + 3);
entries[3].Set(wxACCEL_CTRL, WXK_NUMPAD4, wxID_HIGHEST + 4);
entries[4].Set(wxACCEL_CTRL, WXK_NUMPAD5, wxID_HIGHEST + 5);
entries[5].Set(wxACCEL_CTRL, WXK_NUMPAD6, wxID_HIGHEST + 6);
wxAcceleratorTable accel(6, entries);
SetAcceleratorTable(accel);
#endif // _WIN32
#else
append_menu_item(windowMenu, wxID_ANY, L("Select Print Settings Tab\tCtrl+2"), L("Show the print settings"),
[this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 0); }, "cog.png");
@ -362,6 +377,10 @@ void MainFrame::init_menubar()
append_menu_item(windowMenu, wxID_ANY, L("Select Printer Settings Tab\tCtrl+4"), L("Show the printer settings"),
[this, tab_offset](wxCommandEvent&) { select_tab(tab_offset + 2); }, "printer_empty.png");
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
windowMenu->AppendSeparator();
append_menu_item(windowMenu, wxID_ANY, L("Print Host Upload Queue"), L("Display the Print Host Upload Queue window"),
[this](wxCommandEvent&) { m_printhost_queue_dlg->ShowModal(); }, "arrow_up.png");
}
// View menu

View file

@ -21,7 +21,9 @@ class ProgressStatusBar;
namespace GUI
{
class Tab;
class PrintHostQueueDialog;
enum QuickSlice
{
@ -52,6 +54,8 @@ class MainFrame : public wxFrame
wxMenuItem* m_menu_item_repeat { nullptr };
wxMenuItem* m_menu_item_reslice_now { nullptr };
PrintHostQueueDialog *m_printhost_queue_dlg;
std::string get_base_name(const wxString full_name) const ;
std::string get_dir_name(const wxString full_name) const ;
@ -93,6 +97,8 @@ public:
void select_tab(size_t tab) const;
void select_view(const std::string& direction);
PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; }
Plater* m_plater { nullptr };
wxNotebook* m_tabpanel { nullptr };
wxProgressDialog* m_progress_dialog { nullptr };

View file

@ -6,6 +6,7 @@
#include <wx/button.h>
#include <wx/statbmp.h>
#include <wx/scrolwin.h>
#include <wx/clipbrd.h>
#include "libslic3r/libslic3r.h"
#include "libslic3r/Utils.hpp"
@ -61,8 +62,11 @@ MsgDialog::~MsgDialog() {}
// ErrorDialog
ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg) :
MsgDialog(parent, _(L("Slic3r error")), _(L("Slic3r has encountered an error")), wxBitmap(from_u8(Slic3r::var("Slic3r_192px_grayscale.png")), wxBITMAP_TYPE_PNG))
ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg)
: MsgDialog(parent, _(L("Slic3r error")), _(L("Slic3r has encountered an error")),
wxBitmap(from_u8(Slic3r::var("Slic3r_192px_grayscale.png")), wxBITMAP_TYPE_PNG),
wxID_NONE)
, msg(msg)
{
auto *panel = new wxScrolledWindow(this);
auto *p_sizer = new wxBoxSizer(wxVERTICAL);
@ -77,6 +81,20 @@ ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg) :
content_sizer->Add(panel, 1, wxEXPAND);
auto *btn_copy = new wxButton(this, wxID_ANY, _(L("Copy to clipboard")));
btn_copy->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxTextDataObject(this->msg)); // Note: the clipboard takes ownership of the pointer
wxTheClipboard->Close();
}
});
auto *btn_ok = new wxButton(this, wxID_OK);
btn_ok->SetFocus();
btn_sizer->Add(btn_copy, 0, wxRIGHT, HORIZ_SPACING);
btn_sizer->Add(btn_ok);
SetMaxSize(wxSize(-1, CONTENT_MAX_HEIGHT));
Fit();
}

View file

@ -50,14 +50,18 @@ protected:
// Generic error dialog, used for displaying exceptions
struct ErrorDialog : MsgDialog
class ErrorDialog : public MsgDialog
{
public:
ErrorDialog(wxWindow *parent, const wxString &msg);
ErrorDialog(ErrorDialog &&) = delete;
ErrorDialog(const ErrorDialog &) = delete;
ErrorDialog &operator=(ErrorDialog &&) = delete;
ErrorDialog &operator=(const ErrorDialog &) = delete;
virtual ~ErrorDialog();
private:
wxString msg;
};

View file

@ -213,7 +213,7 @@ void SlicedInfo::SetTextAndShow(SlisedInfoIdx idx, const wxString& text, const w
}
PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) :
wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY),
wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,-1), 0, nullptr, wxCB_READONLY),
preset_type(preset_type),
last_selected(wxNOT_FOUND)
{
@ -484,7 +484,7 @@ Sidebar::Sidebar(Plater *parent)
: wxPanel(parent), p(new priv(parent))
{
p->scrolled = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, -1));
p->scrolled->SetScrollbars(0, 1, 1, 1);
p->scrolled->SetScrollbars(0, 20, 1, 2);
// Sizer in the scrolled area
auto *scrolled_sizer = new wxBoxSizer(wxVERTICAL);
@ -732,8 +732,7 @@ void Sidebar::show_info_sizer()
p->object_info->info_materials->SetLabel(wxString::Format("%d", static_cast<int>(model_object->materials_count())));
auto& stats = model_object->volumes.front()->mesh.stl.stats;
auto sf = model_instance->get_scaling_factor();
p->object_info->info_volume->SetLabel(wxString::Format("%.2f", size(0) * size(1) * size(2) * sf(0) * sf(1) * sf(2)));
p->object_info->info_volume->SetLabel(wxString::Format("%.2f", size(0) * size(1) * size(2)));
p->object_info->info_facets->SetLabel(wxString::Format(_(L("%d (%d shells)")), static_cast<int>(model_object->facets_count()), stats.number_of_parts));
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
@ -913,7 +912,11 @@ struct Plater::priv
Sidebar *sidebar;
#if ENABLE_REMOVE_TABS_FROM_PLATER
View3D* view3D;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLToolbar view_toolbar;
#else
GLRadioToolbar view_toolbar;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#else
#if !ENABLE_IMGUI
wxPanel *panel3d;
@ -1030,6 +1033,7 @@ private:
bool can_decrease_instances() const;
bool can_split_to_objects() const;
bool can_split_to_volumes() const;
bool can_split() const;
bool layers_height_allowed() const;
bool can_delete_all() const;
bool can_arrange() const;
@ -1068,6 +1072,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
#endif // !ENABLE_REMOVE_TABS_FROM_PLATER
, delayed_scene_refresh(false)
, project_filename(wxEmptyString)
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
, view_toolbar(GLToolbar::Radio)
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
{
arranging.store(false);
rotoptimizing.store(false);
@ -1179,7 +1186,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
view3D_canvas->Bind(EVT_GLCANVAS_MODEL_UPDATE, [this](SimpleEvent&) { this->schedule_background_process(); });
view3D_canvas->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); });
view3D_canvas->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [q](Event<int> &evt) { evt.data == 1 ? q->increase_instances() : q->decrease_instances(); });
view3D_canvas->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [this](Event<int> &evt)
{ if (evt.data == 1) this->q->increase_instances(); else if (this->can_decrease_instances()) this->q->decrease_instances(); });
view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_MOVED, [this](SimpleEvent&) { update(); });
view3D_canvas->Bind(EVT_GLCANVAS_WIPETOWER_MOVED, &priv::on_wipetower_moved, this);
view3D_canvas->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, [this](Event<bool> &evt) { this->sidebar->enable_buttons(evt.data); });
@ -1205,7 +1213,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
canvas3Dwidget->Bind(EVT_GLCANVAS_MODEL_UPDATE, [this](SimpleEvent&) { this->schedule_background_process(); });
canvas3Dwidget->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
canvas3Dwidget->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); });
canvas3Dwidget->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [q](Event<int> &evt) { evt.data == 1 ? q->increase_instances() : q->decrease_instances(); });
canvas3Dwidget->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [this](Event<int> &evt)
{ if (evt.data == 1) this->q->increase_instances(); else if (this->can_decrease_instances()) this->q->decrease_instances(); });
canvas3Dwidget->Bind(EVT_GLCANVAS_INSTANCE_MOVED, [this](SimpleEvent&) { update(); });
canvas3Dwidget->Bind(EVT_GLCANVAS_WIPETOWER_MOVED, &priv::on_wipetower_moved, this);
canvas3Dwidget->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, [this](Event<bool> &evt) { this->sidebar->enable_buttons(evt.data); });
@ -1286,7 +1295,9 @@ void Plater::priv::select_view_3D(const std::string& name)
else if (name == "Preview")
set_current_panel(preview);
#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE
view_toolbar.set_selection(name);
#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE
}
#else
void Plater::priv::select_view(const std::string& direction)
@ -1485,7 +1496,7 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
#if !ENABLE_MODELVOLUME_TRANSFORM
const Vec3d bed_center = Slic3r::to_3d(bed_shape.center().cast<double>(), 0.0);
#endif // !ENABLE_MODELVOLUME_TRANSFORM
const Vec3d bed_size = Slic3r::to_3d(bed_shape.size().cast<double>(), 1.0);
const Vec3d bed_size = Slic3r::to_3d(bed_shape.size().cast<double>(), 1.0) - 2.0 * Vec3d::Ones();
bool need_arrange = false;
bool scaled_down = false;
@ -1517,9 +1528,10 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
if (max_ratio > 10000) {
// the size of the object is too big -> this could lead to overflow when moving to clipper coordinates,
// so scale down the mesh
// const Vec3d inverse = ratio.cwiseInverse();
// object->scale(inverse);
object->scale(ratio.cwiseInverse());
double inv = 1. / max_ratio;
object->scale_mesh(Vec3d(inv, inv, inv));
object->origin_translation = Vec3d::Zero();
object->center_around_origin();
scaled_down = true;
} else if (max_ratio > 5) {
const Vec3d inverse = ratio.cwiseInverse();
@ -1644,8 +1656,8 @@ void Plater::priv::selection_changed()
view3D->enable_toolbar_item("delete", can_delete_object());
view3D->enable_toolbar_item("more", can_increase_instances());
view3D->enable_toolbar_item("fewer", can_decrease_instances());
view3D->enable_toolbar_item("splitobjects", can_split_to_objects());
view3D->enable_toolbar_item("splitvolumes", can_split_to_volumes());
view3D->enable_toolbar_item("splitobjects", can_split/*_to_objects*/());
view3D->enable_toolbar_item("splitvolumes", can_split/*_to_volumes*/());
view3D->enable_toolbar_item("layersediting", layers_height_allowed());
// forces a frame render to update the view (to avoid a missed update if, for example, the context menu appears)
view3D->render();
@ -1653,8 +1665,8 @@ void Plater::priv::selection_changed()
this->canvas3D->enable_toolbar_item("delete", can_delete_object());
this->canvas3D->enable_toolbar_item("more", can_increase_instances());
this->canvas3D->enable_toolbar_item("fewer", can_decrease_instances());
this->canvas3D->enable_toolbar_item("splitobjects", can_split_to_objects());
this->canvas3D->enable_toolbar_item("splitvolumes", can_split_to_volumes());
this->canvas3D->enable_toolbar_item("splitobjects", can_split/*_to_objects*/());
this->canvas3D->enable_toolbar_item("splitvolumes", can_split/*_to_volumes*/());
this->canvas3D->enable_toolbar_item("layersediting", layers_height_allowed());
// forces a frame render to update the view (to avoid a missed update if, for example, the context menu appears)
this->canvas3D->render();
@ -2446,8 +2458,8 @@ void Plater::priv::on_action_layersediting(SimpleEvent&)
void Plater::priv::on_object_select(SimpleEvent& evt)
{
selection_changed();
wxGetApp().obj_list()->update_selections();
selection_changed();
}
void Plater::priv::on_viewport_changed(SimpleEvent& evt)
@ -2597,9 +2609,9 @@ bool Plater::priv::complit_init_object_menu()
// ui updates needs to be binded to the parent panel
if (q != nullptr)
{
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_objects() || can_split_to_volumes()); }, item_split->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_objects()); }, item_split_objects->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_volumes()); }, item_split_volumes->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split/*_to_objects() || can_split_to_volumes*/()); }, item_split->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split/*_to_objects*/()); }, item_split_objects->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split/*_to_volumes*/()); }, item_split_volumes->GetId());
}
return true;
}
@ -2618,7 +2630,7 @@ bool Plater::priv::complit_init_sla_object_menu()
// ui updates needs to be binded to the parent panel
if (q != nullptr)
{
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_objects()); }, item_split->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split/*_to_objects*/()); }, item_split->GetId());
}
return true;
@ -2637,7 +2649,7 @@ bool Plater::priv::complit_init_part_menu()
// ui updates needs to be binded to the parent panel
if (q != nullptr)
{
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_volumes()); }, item_split->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split/*_to_volumes*/()); }, item_split->GetId());
}
return true;
@ -2646,9 +2658,58 @@ bool Plater::priv::complit_init_part_menu()
#if ENABLE_REMOVE_TABS_FROM_PLATER
void Plater::priv::init_view_toolbar()
{
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
ItemsIconsTexture::Metadata icons_data;
icons_data.filename = "view_toolbar.png";
icons_data.icon_size = 64;
icons_data.icon_border_size = 0;
icons_data.icon_gap_size = 0;
BackgroundTexture::Metadata background_data;
background_data.filename = "toolbar_background.png";
background_data.left = 16;
background_data.top = 16;
background_data.right = 16;
background_data.bottom = 16;
if (!view_toolbar.init(icons_data, background_data))
#else
if (!view_toolbar.init("view_toolbar.png", 64, 0, 0))
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
return;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
view_toolbar.set_layout_orientation(GLToolbar::Layout::Bottom);
view_toolbar.set_border(5.0f);
view_toolbar.set_gap_size(1.0f);
GLToolbarItem::Data item;
item.name = "3D";
item.tooltip = GUI::L_str("3D editor view");
item.sprite_id = 0;
item.action_event = EVT_GLVIEWTOOLBAR_3D;
item.is_toggable = false;
if (!view_toolbar.add_item(item))
return;
item.name = "Preview";
item.tooltip = GUI::L_str("Preview");
item.sprite_id = 1;
item.action_event = EVT_GLVIEWTOOLBAR_PREVIEW;
item.is_toggable = false;
if (!view_toolbar.add_item(item))
return;
view_toolbar.enable_item("3D");
view_toolbar.enable_item("Preview");
view_toolbar.select_item("3D");
view_toolbar.set_enabled(true);
view3D->set_view_toolbar(&view_toolbar);
preview->set_view_toolbar(&view_toolbar);
#else
GLRadioToolbarItem::Data item;
item.name = "3D";
@ -2669,6 +2730,7 @@ void Plater::priv::init_view_toolbar()
preview->set_view_toolbar(&view_toolbar);
view_toolbar.set_selection("3D");
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
}
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
@ -2705,6 +2767,13 @@ bool Plater::priv::can_split_to_volumes() const
return sidebar->obj_list()->is_splittable();
}
bool Plater::priv::can_split() const
{
if (printer_technology == ptSLA)
return false;
return sidebar->obj_list()->is_splittable();
}
bool Plater::priv::layers_height_allowed() const
{
int obj_idx = get_selected_object_idx();
@ -3086,7 +3155,7 @@ void Plater::send_gcode()
}
default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string()));
Slic3r::PrintHostSendDialog dlg(default_output_file);
PrintHostSendDialog dlg(default_output_file);
if (dlg.ShowModal() == wxID_OK) {
upload_job.upload_data.upload_path = dlg.filename();
upload_job.upload_data.start_print = dlg.start_print();
@ -3178,6 +3247,8 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
if (p->preview) p->preview->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values);
update_scheduled = true;
} else if (opt_key == "host_type" && this->p->printer_technology == ptSLA) {
p->config->option<ConfigOptionEnum<PrintHostType>>(opt_key)->value = htSL1;
}
}

View file

@ -366,7 +366,8 @@ const std::vector<std::string>& Preset::printer_options()
"host_type", "print_host", "printhost_apikey", "printhost_cafile",
"single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode",
"between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction",
"cooling_tube_length", "parking_pos_retraction", "extra_loading_move", "max_print_height", "default_print_profile", "inherits",
"cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height",
"default_print_profile", "inherits",
"remaining_times", "silent_mode", "machine_max_acceleration_extruding", "machine_max_acceleration_retracting",
"machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e",
"machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e",
@ -455,6 +456,7 @@ const std::vector<std::string>& Preset::sla_printer_options()
"display_width", "display_height", "display_pixels_x", "display_pixels_y",
"display_orientation",
"printer_correction",
"print_host", "printhost_apikey", "printhost_cafile",
"printer_notes",
"inherits"
};

View file

@ -1,20 +1,28 @@
#include "PrintHostDialogs.hpp"
#include <algorithm>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include <wx/button.h>
#include <wx/dataview.h>
#include <wx/wupdlock.h>
#include <wx/debug.h>
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "GUI.hpp"
#include "MsgDialog.hpp"
#include "I18N.hpp"
#include "../Utils/PrintHost.hpp"
namespace fs = boost::filesystem;
namespace Slic3r {
namespace GUI {
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path)
: MsgDialog(nullptr, _(L("Send G-Code to printer host")), _(L("Upload to Printer Host with the following filename:")), wxID_NONE)
@ -45,5 +53,95 @@ fs::path PrintHostSendDialog::filename() const
bool PrintHostSendDialog::start_print() const
{
return box_print->GetValue(); }
return box_print->GetValue();
}
wxDEFINE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event);
wxDEFINE_EVENT(EVT_PRINTHOST_ERROR, PrintHostQueueDialog::Event);
PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_id)
: wxEvent(winid, eventType)
, job_id(job_id)
{}
PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_id, int progress)
: wxEvent(winid, eventType)
, job_id(job_id)
, progress(progress)
{}
PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_id, wxString error)
: wxEvent(winid, eventType)
, job_id(job_id)
, error(std::move(error))
{}
wxEvent *PrintHostQueueDialog::Event::Clone() const
{
return new Event(*this);
}
PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent)
: wxDialog(parent, wxID_ANY, _(L("Print host upload queue")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, on_progress_evt(this, EVT_PRINTHOST_PROGRESS, &PrintHostQueueDialog::on_progress, this)
, on_error_evt(this, EVT_PRINTHOST_ERROR, &PrintHostQueueDialog::on_error, this)
{
enum { HEIGHT = 800, WIDTH = 400, SPACING = 5 };
SetMinSize(wxSize(HEIGHT, WIDTH));
auto *topsizer = new wxBoxSizer(wxVERTICAL);
job_list = new wxDataViewListCtrl(this, wxID_ANY);
job_list->AppendTextColumn("ID", wxDATAVIEW_CELL_INERT);
job_list->AppendProgressColumn("Progress", wxDATAVIEW_CELL_INERT);
job_list->AppendTextColumn("Status", wxDATAVIEW_CELL_INERT);
job_list->AppendTextColumn("Host", wxDATAVIEW_CELL_INERT);
job_list->AppendTextColumn("Filename", wxDATAVIEW_CELL_INERT);
auto *btnsizer = new wxBoxSizer(wxHORIZONTAL);
auto *btn_cancel = new wxButton(this, wxID_DELETE, _(L("Cancel selected")));
auto *btn_close = new wxButton(this, wxID_CANCEL, _(L("Close")));
btnsizer->Add(btn_cancel, 0, wxRIGHT, SPACING);
btnsizer->AddStretchSpacer();
btnsizer->Add(btn_close);
topsizer->Add(job_list, 1, wxEXPAND | wxBOTTOM, SPACING);
topsizer->Add(btnsizer, 0, wxEXPAND);
SetSizer(topsizer);
}
void PrintHostQueueDialog::append_job(const PrintHostJob &job)
{
wxCHECK_RET(!job.empty(), "PrintHostQueueDialog: Attempt to append an empty job");
wxVector<wxVariant> fields;
fields.push_back(wxVariant(wxString::Format("%d", job_list->GetItemCount() + 1)));
fields.push_back(wxVariant(0));
fields.push_back(wxVariant(_(L("Enqueued"))));
fields.push_back(wxVariant(job.printhost->get_host()));
fields.push_back(wxVariant(job.upload_data.upload_path.string()));
job_list->AppendItem(fields);
}
void PrintHostQueueDialog::on_progress(Event &evt)
{
wxCHECK_RET(evt.job_id < job_list->GetItemCount(), "Out of bounds access to job list");
const wxVariant status(evt.progress < 100 ? _(L("Uploading")) : _(L("Complete")));
job_list->SetValue(wxVariant(evt.progress), evt.job_id, 1);
job_list->SetValue(status, evt.job_id, 2);
}
void PrintHostQueueDialog::on_error(Event &evt)
{
wxCHECK_RET(evt.job_id < job_list->GetItemCount(), "Out of bounds access to job list");
// TODO
}
}}

View file

@ -2,24 +2,27 @@
#define slic3r_PrintHostSendDialog_hpp_
#include <string>
#include <boost/filesystem/path.hpp>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include <wx/dialog.h>
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
#include "GUI.hpp"
#include "GUI_Utils.hpp"
#include "MsgDialog.hpp"
#include "../Utils/PrintHost.hpp"
class wxTextCtrl;
class wxCheckBox;
class wxDataViewListCtrl;
namespace Slic3r {
struct PrintHostJob;
namespace GUI {
class PrintHostSendDialog : public GUI::MsgDialog
{
@ -38,12 +41,38 @@ private:
class PrintHostQueueDialog : public wxDialog
{
public:
PrintHostQueueDialog();
class Event : public wxEvent
{
public:
size_t job_id;
int progress = 0; // in percent
wxString error;
Event(wxEventType eventType, int winid, size_t job_id);
Event(wxEventType eventType, int winid, size_t job_id, int progress);
Event(wxEventType eventType, int winid, size_t job_id, wxString error);
virtual wxEvent *Clone() const;
};
PrintHostQueueDialog(wxWindow *parent);
void append_job(const PrintHostJob &job);
private:
wxDataViewListCtrl *job_list;
// Note: EventGuard prevents delivery of progress evts to a freed PrintHostQueueDialog
EventGuard on_progress_evt;
EventGuard on_error_evt;
void on_progress(Event&);
void on_error(Event&);
};
wxDECLARE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event);
wxDECLARE_EVENT(EVT_PRINTHOST_ERROR, PrintHostQueueDialog::Event);
}
}}
#endif

View file

@ -270,7 +270,7 @@ Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::str
auto panel = this;
#endif
PageShp page(new Page(panel, title, icon_idx));
page->SetScrollbars(1, 1, 1, 2);
page->SetScrollbars(1, 20, 1, 2);
page->Hide();
m_hsizer->Add(page.get(), 1, wxEXPAND | wxLEFT, 5);
@ -1538,6 +1538,108 @@ bool Tab::current_preset_is_dirty()
return m_presets->current_is_dirty();
}
void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
{
const bool sla = m_presets->get_selected_preset().printer_technology() == ptSLA;
// Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment)
if (! sla) {
optgroup->append_single_option_line("host_type");
} else {
m_config->option<ConfigOptionEnum<PrintHostType>>("host_type", true)->value = htSL1;
}
auto printhost_browse = [this, optgroup] (wxWindow* parent) {
// TODO: SLA
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) {
BonjourDialog dialog(parent);
if (dialog.show_and_lookup()) {
optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
}
});
return sizer;
};
auto print_host_test = [this](wxWindow* parent) {
auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
if (! host) {
const auto text = wxString::Format("%s",
_(L("Could not get a valid Printer Host reference")));
show_error(this, text);
return;
}
wxString msg;
if (host->test(msg)) {
show_info(this, host->get_test_ok_msg(), _(L("Success!")));
} else {
show_error(this, host->get_test_failed_msg(msg));
}
});
return sizer;
};
Line host_line = optgroup->create_single_option_line("print_host");
host_line.append_widget(printhost_browse);
host_line.append_widget(print_host_test);
optgroup->append_line(host_line);
optgroup->append_single_option_line("printhost_apikey");
if (Http::ca_file_supported()) {
Line cafile_line = optgroup->create_single_option_line("printhost_cafile");
auto printhost_cafile_browse = [this, optgroup] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this, optgroup] (wxCommandEvent e) {
static const auto filemasks = _(L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"));
wxFileDialog openFileDialog(this, _(L("Open CA certificate file")), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() != wxID_CANCEL) {
optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true);
}
});
return sizer;
};
cafile_line.append_widget(printhost_cafile_browse);
optgroup->append_line(cafile_line);
auto printhost_cafile_hint = [this, optgroup] (wxWindow* parent) {
auto txt = new wxStaticText(parent, wxID_ANY,
_(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.")));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(txt);
return sizer;
};
Line cafile_hint { "", "" };
cafile_hint.full_width = 1;
cafile_hint.widget = std::move(printhost_cafile_hint);
optgroup->append_line(cafile_hint);
}
}
void TabPrinter::build()
{
m_presets = &m_preset_bundle->printers;
@ -1665,96 +1767,8 @@ void TabPrinter::build_fff()
}
#endif
optgroup = page->new_optgroup(_(L("Printer Host upload")));
optgroup->append_single_option_line("host_type");
auto printhost_browse = [this, optgroup] (wxWindow* parent) {
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) {
BonjourDialog dialog(parent);
if (dialog.show_and_lookup()) {
optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
}
});
return sizer;
};
auto print_host_test = [this](wxWindow* parent) {
auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
if (! host) {
const auto text = wxString::Format("%s",
_(L("Could not get a valid Printer Host reference")));
show_error(this, text);
return;
}
wxString msg;
if (host->test(msg)) {
show_info(this, host->get_test_ok_msg(), _(L("Success!")));
} else {
show_error(this, host->get_test_failed_msg(msg));
}
});
return sizer;
};
Line host_line = optgroup->create_single_option_line("print_host");
host_line.append_widget(printhost_browse);
host_line.append_widget(print_host_test);
optgroup->append_line(host_line);
optgroup->append_single_option_line("printhost_apikey");
if (Http::ca_file_supported()) {
Line cafile_line = optgroup->create_single_option_line("printhost_cafile");
auto printhost_cafile_browse = [this, optgroup] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this, optgroup] (wxCommandEvent e) {
static const auto filemasks = _(L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"));
wxFileDialog openFileDialog(this, _(L("Open CA certificate file")), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() != wxID_CANCEL) {
optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true);
}
});
return sizer;
};
cafile_line.append_widget(printhost_cafile_browse);
optgroup->append_line(cafile_line);
auto printhost_cafile_hint = [this, optgroup] (wxWindow* parent) {
auto txt = new wxStaticText(parent, wxID_ANY,
_(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.")));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(txt);
return sizer;
};
Line cafile_hint { "", "" };
cafile_hint.full_width = 1;
cafile_hint.widget = std::move(printhost_cafile_hint);
optgroup->append_line(cafile_hint);
}
optgroup = page->new_optgroup(_(L("Print Host upload")));
build_printhost(optgroup.get());
optgroup = page->new_optgroup(_(L("Firmware")));
optgroup->append_single_option_line("gcode_flavor");
@ -1897,6 +1911,9 @@ void TabPrinter::build_sla()
}
optgroup->append_line(line);
optgroup = page->new_optgroup(_(L("Print Host upload")));
build_printhost(optgroup.get());
page = add_options_page(_(L("Notes")), "note.png");
optgroup = page->new_optgroup(_(L("Notes")), 0);
option = optgroup->get_option("printer_notes");
@ -2041,6 +2058,7 @@ void TabPrinter::build_extruder_pages()
optgroup->append_single_option_line("cooling_tube_length");
optgroup->append_single_option_line("parking_pos_retraction");
optgroup->append_single_option_line("extra_loading_move");
optgroup->append_single_option_line("high_current_on_filament_swap");
m_pages.insert(m_pages.end() - n_after_single_extruder_MM, page);
m_has_single_extruder_MM_page = true;
}

View file

@ -325,6 +325,8 @@ class TabPrinter : public Tab
std::vector<PageShp> m_pages_fff;
std::vector<PageShp> m_pages_sla;
void build_printhost(ConfigOptionsGroup *optgroup);
public:
wxButton* m_serial_test_btn = nullptr;
wxButton* m_print_host_test_btn = nullptr;

View file

@ -953,6 +953,44 @@ void PrusaObjectDataViewModel::GetItemInfo(const wxDataViewItem& item, ItemType&
type = itUndef;
}
int PrusaObjectDataViewModel::GetRowByItem(const wxDataViewItem& item) const
{
if (m_objects.empty())
return -1;
int row_num = 0;
for (int i = 0; i < m_objects.size(); i++)
{
row_num++;
if (item == wxDataViewItem(m_objects[i]))
return row_num;
for (int j = 0; j < m_objects[i]->GetChildCount(); j++)
{
row_num++;
PrusaObjectDataViewModelNode* cur_node = m_objects[i]->GetNthChild(j);
if (item == wxDataViewItem(cur_node))
return row_num;
if (cur_node->m_type == itVolume && cur_node->GetChildCount() == 1)
row_num++;
if (cur_node->m_type == itInstanceRoot)
{
row_num++;
for (int t = 0; t < cur_node->GetChildCount(); t++)
{
row_num++;
if (item == wxDataViewItem(cur_node->GetNthChild(t)))
return row_num;
}
}
}
}
return -1;
}
wxString PrusaObjectDataViewModel::GetName(const wxDataViewItem &item) const
{
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
@ -1240,6 +1278,16 @@ IMPLEMENT_VARIANT_OBJECT(PrusaDataViewBitmapText)
// PrusaIconTextRenderer
// ---------------------------------------------------------
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
PrusaBitmapTextRenderer::PrusaBitmapTextRenderer(wxDataViewCellMode mode /*= wxDATAVIEW_CELL_EDITABLE*/,
int align /*= wxDVR_DEFAULT_ALIGNMENT*/):
wxDataViewRenderer(wxT("PrusaDataViewBitmapText"), mode, align)
{
SetMode(mode);
SetAlignment(align);
}
#endif // ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
bool PrusaBitmapTextRenderer::SetValue(const wxVariant &value)
{
m_value << value;
@ -1251,6 +1299,13 @@ bool PrusaBitmapTextRenderer::GetValue(wxVariant& WXUNUSED(value)) const
return false;
}
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING && wxUSE_ACCESSIBILITY
wxString PrusaBitmapTextRenderer::GetAccessibleDescription() const
{
return m_value.GetText();
}
#endif // wxUSE_ACCESSIBILITY && ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
bool PrusaBitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state)
{
int xoffset = 0;
@ -1291,12 +1346,12 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab
PrusaDataViewBitmapText data;
data << value;
m_bmp_from_editing_item = data.GetBitmap();
m_was_unusable_symbol = false;
wxPoint position = labelRect.GetPosition();
if (m_bmp_from_editing_item.IsOk()) {
const int bmp_width = m_bmp_from_editing_item.GetWidth();
if (data.GetBitmap().IsOk()) {
const int bmp_width = data.GetBitmap().GetWidth();
position.x += bmp_width;
labelRect.SetWidth(labelRect.GetWidth() - bmp_width);
}
@ -1304,6 +1359,7 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab
wxTextCtrl* text_editor = new wxTextCtrl(parent, wxID_ANY, data.GetText(),
position, labelRect.GetSize(), wxTE_PROCESS_ENTER);
text_editor->SetInsertionPointEnd();
text_editor->SelectAll();
return text_editor;
}
@ -1323,7 +1379,17 @@ bool PrusaBitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant&
}
}
value << PrusaDataViewBitmapText(text_editor->GetValue(), m_bmp_from_editing_item);
// The icon can't be edited so get its old value and reuse it.
wxVariant valueOld;
GetView()->GetModel()->GetValue(valueOld, m_item, 0);
PrusaDataViewBitmapText bmpText;
bmpText << valueOld;
// But replace the text with the value entered by user.
bmpText.SetText(text_editor->GetValue());
value << bmpText;
return true;
}

View file

@ -463,6 +463,7 @@ public:
int GetVolumeIdByItem(const wxDataViewItem& item) const;
int GetInstanceIdByItem(const wxDataViewItem& item) const;
void GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx);
int GetRowByItem(const wxDataViewItem& item) const;
bool IsEmpty() { return m_objects.empty(); }
// helper method for wxLog
@ -518,21 +519,44 @@ public:
// ----------------------------------------------------------------------------
// PrusaBitmapTextRenderer
// ----------------------------------------------------------------------------
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
class PrusaBitmapTextRenderer : public wxDataViewRenderer
#else
class PrusaBitmapTextRenderer : public wxDataViewCustomRenderer
#endif //ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
{
public:
PrusaBitmapTextRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int align = wxDVR_DEFAULT_ALIGNMENT):
wxDataViewCustomRenderer(wxT("PrusaDataViewBitmapText"), mode, align) {}
PrusaBitmapTextRenderer(wxDataViewCellMode mode =
#ifdef __WXOSX__
wxDATAVIEW_CELL_INERT
#else
wxDATAVIEW_CELL_EDITABLE
#endif
,int align = wxDVR_DEFAULT_ALIGNMENT
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
);
#else
) : wxDataViewCustomRenderer(wxT("PrusaDataViewBitmapText"), mode, align) {}
#endif //ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
bool SetValue(const wxVariant &value);
bool GetValue(wxVariant &value) const;
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING && wxUSE_ACCESSIBILITY
virtual wxString GetAccessibleDescription() const override;
#endif // wxUSE_ACCESSIBILITY && ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
virtual bool Render(wxRect cell, wxDC *dc, int state);
virtual wxSize GetSize() const;
bool HasEditorCtrl() const override { return true; }
bool HasEditorCtrl() const override
{
#ifdef __WXOSX__
return false;
#else
return true;
#endif
}
wxWindow* CreateEditorCtrl(wxWindow* parent,
wxRect labelRect,
const wxVariant& value) override;
@ -542,8 +566,7 @@ public:
private:
PrusaDataViewBitmapText m_value;
wxBitmap m_bmp_from_editing_item;
bool m_was_unusable_symbol;
bool m_was_unusable_symbol {false};
};