2018-11-22 14:29:59 +00:00
|
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
#include "libslic3r/GCode/PreviewData.hpp"
|
2018-09-18 11:35:05 +00:00
|
|
|
#include "GUI_Preview.hpp"
|
2018-11-07 13:44:47 +00:00
|
|
|
#include "GUI_App.hpp"
|
2018-09-18 11:35:05 +00:00
|
|
|
#include "GUI.hpp"
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "I18N.hpp"
|
2018-09-18 11:35:05 +00:00
|
|
|
#include "AppConfig.hpp"
|
|
|
|
#include "3DScene.hpp"
|
2018-11-22 14:29:59 +00:00
|
|
|
#include "BackgroundSlicingProcess.hpp"
|
2020-05-06 12:38:53 +00:00
|
|
|
#include "OpenGLManager.hpp"
|
2018-11-23 11:47:32 +00:00
|
|
|
#include "GLCanvas3D.hpp"
|
2018-09-18 13:50:52 +00:00
|
|
|
#include "PresetBundle.hpp"
|
2020-01-23 14:07:31 +00:00
|
|
|
#include "DoubleSlider.hpp"
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
#include <wx/notebook.h>
|
|
|
|
#include <wx/glcanvas.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/choice.h>
|
|
|
|
#include <wx/combo.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
|
2018-09-18 13:50:52 +00:00
|
|
|
// this include must follow the wxWidgets ones or it won't compile on Windows -> see http://trac.wxwidgets.org/ticket/2421
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "libslic3r/Print.hpp"
|
2018-11-26 15:17:59 +00:00
|
|
|
#include "libslic3r/SLAPrint.hpp"
|
2018-09-18 13:50:52 +00:00
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
2020-03-02 09:58:46 +00:00
|
|
|
View3D::View3D(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process)
|
|
|
|
: m_canvas_widget(nullptr)
|
|
|
|
, m_canvas(nullptr)
|
|
|
|
{
|
|
|
|
init(parent, model, config, process);
|
|
|
|
}
|
2018-12-04 12:55:25 +00:00
|
|
|
|
|
|
|
View3D::~View3D()
|
|
|
|
{
|
2020-03-02 09:58:46 +00:00
|
|
|
if (m_canvas != nullptr)
|
|
|
|
delete m_canvas;
|
|
|
|
|
2018-12-04 12:55:25 +00:00
|
|
|
if (m_canvas_widget != nullptr)
|
|
|
|
delete m_canvas_widget;
|
|
|
|
}
|
|
|
|
|
2020-03-02 09:58:46 +00:00
|
|
|
bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process)
|
2018-12-04 12:55:25 +00:00
|
|
|
{
|
2019-02-21 17:31:01 +00:00
|
|
|
if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */))
|
2018-12-04 12:55:25 +00:00
|
|
|
return false;
|
|
|
|
|
2020-05-06 12:38:53 +00:00
|
|
|
m_canvas_widget = OpenGLManager::create_wxglcanvas(*this);
|
2020-03-02 09:58:46 +00:00
|
|
|
if (m_canvas_widget == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_canvas = new GLCanvas3D(m_canvas_widget);
|
|
|
|
m_canvas->set_context(wxGetApp().init_glcontext(*m_canvas_widget));
|
|
|
|
m_canvas->bind_event_handlers();
|
2018-12-04 12:55:25 +00:00
|
|
|
|
2020-05-06 12:38:53 +00:00
|
|
|
m_canvas->allow_multisample(OpenGLManager::can_multisample());
|
2018-12-04 12:55:25 +00:00
|
|
|
// XXX: If have OpenGL
|
|
|
|
m_canvas->enable_picking(true);
|
|
|
|
m_canvas->enable_moving(true);
|
|
|
|
// XXX: more config from 3D.pm
|
|
|
|
m_canvas->set_model(model);
|
|
|
|
m_canvas->set_process(process);
|
|
|
|
m_canvas->set_config(config);
|
|
|
|
m_canvas->enable_gizmos(true);
|
2019-03-28 07:44:46 +00:00
|
|
|
m_canvas->enable_selection(true);
|
2019-07-19 13:36:55 +00:00
|
|
|
m_canvas->enable_main_toolbar(true);
|
|
|
|
m_canvas->enable_undoredo_toolbar(true);
|
2020-04-23 10:41:38 +00:00
|
|
|
m_canvas->enable_collapse_toolbar(true);
|
2020-01-28 12:15:21 +00:00
|
|
|
m_canvas->enable_labels(true);
|
2020-03-13 14:09:07 +00:00
|
|
|
#if ENABLE_SLOPE_RENDERING
|
|
|
|
m_canvas->enable_slope(true);
|
|
|
|
#endif // ENABLE_SLOPE_RENDERING
|
2018-12-04 12:55:25 +00:00
|
|
|
|
|
|
|
wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_sizer->Add(m_canvas_widget, 1, wxALL | wxEXPAND, 0);
|
|
|
|
|
|
|
|
SetSizer(main_sizer);
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-07 13:44:47 +00:00
|
|
|
|
2018-12-04 12:55:25 +00:00
|
|
|
void View3D::set_as_dirty()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->set_as_dirty();
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:15:27 +00:00
|
|
|
void View3D::bed_shape_changed()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->bed_shape_changed();
|
|
|
|
}
|
2018-12-04 12:55:25 +00:00
|
|
|
|
|
|
|
void View3D::select_view(const std::string& direction)
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->select_view(direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void View3D::select_all()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->select_all();
|
|
|
|
}
|
|
|
|
|
2019-05-14 09:57:39 +00:00
|
|
|
void View3D::deselect_all()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->deselect_all();
|
|
|
|
}
|
|
|
|
|
2018-12-04 12:55:25 +00:00
|
|
|
void View3D::delete_selected()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->delete_selected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void View3D::mirror_selection(Axis axis)
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->mirror_selection(axis);
|
|
|
|
}
|
|
|
|
|
|
|
|
int View3D::check_volumes_outside_state() const
|
|
|
|
{
|
|
|
|
return (m_canvas != nullptr) ? m_canvas->check_volumes_outside_state() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool View3D::is_layers_editing_enabled() const
|
|
|
|
{
|
|
|
|
return (m_canvas != nullptr) ? m_canvas->is_layers_editing_enabled() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool View3D::is_layers_editing_allowed() const
|
|
|
|
{
|
|
|
|
return (m_canvas != nullptr) ? m_canvas->is_layers_editing_allowed() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View3D::enable_layers_editing(bool enable)
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->enable_layers_editing(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool View3D::is_dragging() const
|
|
|
|
{
|
|
|
|
return (m_canvas != nullptr) ? m_canvas->is_dragging() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool View3D::is_reload_delayed() const
|
|
|
|
{
|
|
|
|
return (m_canvas != nullptr) ? m_canvas->is_reload_delayed() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View3D::reload_scene(bool refresh_immediately, bool force_full_scene_refresh)
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->reload_scene(refresh_immediately, force_full_scene_refresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void View3D::render()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
2019-03-04 08:41:25 +00:00
|
|
|
//m_canvas->render();
|
|
|
|
m_canvas->set_as_dirty();
|
2018-12-04 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 09:58:46 +00:00
|
|
|
Preview::Preview(
|
|
|
|
wxWindow* parent, Model* model, DynamicPrintConfig* config,
|
|
|
|
BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function<void()> schedule_background_process_func)
|
2018-11-23 11:47:32 +00:00
|
|
|
: m_canvas_widget(nullptr)
|
|
|
|
, m_canvas(nullptr)
|
2018-09-18 11:35:05 +00:00
|
|
|
, m_double_slider_sizer(nullptr)
|
|
|
|
, m_label_view_type(nullptr)
|
|
|
|
, m_choice_view_type(nullptr)
|
|
|
|
, m_label_show_features(nullptr)
|
|
|
|
, m_combochecklist_features(nullptr)
|
|
|
|
, m_checkbox_travel(nullptr)
|
|
|
|
, m_checkbox_retractions(nullptr)
|
|
|
|
, m_checkbox_unretractions(nullptr)
|
|
|
|
, m_checkbox_shells(nullptr)
|
2019-06-22 15:38:14 +00:00
|
|
|
, m_checkbox_legend(nullptr)
|
2018-09-18 11:35:05 +00:00
|
|
|
, m_config(config)
|
2018-11-22 14:29:59 +00:00
|
|
|
, m_process(process)
|
2018-09-18 11:35:05 +00:00
|
|
|
, m_gcode_preview_data(gcode_preview_data)
|
|
|
|
, m_number_extruders(1)
|
|
|
|
, m_preferred_color_mode("feature")
|
|
|
|
, m_loaded(false)
|
|
|
|
, m_enabled(false)
|
2018-11-12 14:35:58 +00:00
|
|
|
, m_schedule_background_process(schedule_background_process_func)
|
2019-03-21 10:54:25 +00:00
|
|
|
#ifdef __linux__
|
2019-03-18 13:07:55 +00:00
|
|
|
, m_volumes_cleanup_required(false)
|
2019-03-21 10:54:25 +00:00
|
|
|
#endif // __linux__
|
2018-09-18 11:35:05 +00:00
|
|
|
{
|
2020-03-02 09:58:46 +00:00
|
|
|
if (init(parent, model))
|
2018-12-04 12:55:25 +00:00
|
|
|
{
|
|
|
|
show_hide_ui_elements("none");
|
|
|
|
load_print();
|
|
|
|
}
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 09:58:46 +00:00
|
|
|
bool Preview::init(wxWindow* parent, Model* model)
|
2018-09-18 11:35:05 +00:00
|
|
|
{
|
2019-02-21 10:54:18 +00:00
|
|
|
if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */))
|
2018-12-04 12:55:25 +00:00
|
|
|
return false;
|
2018-09-18 11:35:05 +00:00
|
|
|
|
2020-05-06 12:38:53 +00:00
|
|
|
m_canvas_widget = OpenGLManager::create_wxglcanvas(*this);
|
2020-03-02 09:58:46 +00:00
|
|
|
if (m_canvas_widget == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_canvas = new GLCanvas3D(m_canvas_widget);
|
|
|
|
m_canvas->set_context(wxGetApp().init_glcontext(*m_canvas_widget));
|
|
|
|
m_canvas->bind_event_handlers();
|
2020-05-06 12:38:53 +00:00
|
|
|
m_canvas->allow_multisample(OpenGLManager::can_multisample());
|
2018-11-23 11:47:32 +00:00
|
|
|
m_canvas->set_config(m_config);
|
2019-04-02 11:47:49 +00:00
|
|
|
m_canvas->set_model(model);
|
2019-03-13 13:35:09 +00:00
|
|
|
m_canvas->set_process(m_process);
|
2018-11-23 11:47:32 +00:00
|
|
|
m_canvas->enable_legend_texture(true);
|
|
|
|
m_canvas->enable_dynamic_background(true);
|
2020-04-27 09:51:17 +00:00
|
|
|
m_canvas->enable_collapse_toolbar(true);
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
m_double_slider_sizer = new wxBoxSizer(wxHORIZONTAL);
|
2018-10-05 21:29:15 +00:00
|
|
|
create_double_slider();
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
m_label_view_type = new wxStaticText(this, wxID_ANY, _(L("View")));
|
|
|
|
|
|
|
|
m_choice_view_type = new wxChoice(this, wxID_ANY);
|
|
|
|
m_choice_view_type->Append(_(L("Feature type")));
|
|
|
|
m_choice_view_type->Append(_(L("Height")));
|
|
|
|
m_choice_view_type->Append(_(L("Width")));
|
|
|
|
m_choice_view_type->Append(_(L("Speed")));
|
2019-09-23 12:56:27 +00:00
|
|
|
m_choice_view_type->Append(_(L("Fan speed")));
|
2018-09-18 11:35:05 +00:00
|
|
|
m_choice_view_type->Append(_(L("Volumetric flow rate")));
|
|
|
|
m_choice_view_type->Append(_(L("Tool")));
|
2018-11-26 15:07:09 +00:00
|
|
|
m_choice_view_type->Append(_(L("Color Print")));
|
2018-09-18 11:35:05 +00:00
|
|
|
m_choice_view_type->SetSelection(0);
|
|
|
|
|
|
|
|
m_label_show_features = new wxStaticText(this, wxID_ANY, _(L("Show")));
|
|
|
|
|
|
|
|
m_combochecklist_features = new wxComboCtrl();
|
2019-02-04 09:35:16 +00:00
|
|
|
m_combochecklist_features->Create(this, wxID_ANY, _(L("Feature types")), wxDefaultPosition, wxSize(15 * wxGetApp().em_unit(), -1), wxCB_READONLY);
|
2018-09-19 08:34:21 +00:00
|
|
|
std::string feature_text = GUI::into_u8(_(L("Feature types")));
|
|
|
|
std::string feature_items = GUI::into_u8(
|
|
|
|
_(L("Perimeter")) + "|" +
|
2018-09-18 11:35:05 +00:00
|
|
|
_(L("External perimeter")) + "|" +
|
|
|
|
_(L("Overhang perimeter")) + "|" +
|
|
|
|
_(L("Internal infill")) + "|" +
|
|
|
|
_(L("Solid infill")) + "|" +
|
|
|
|
_(L("Top solid infill")) + "|" +
|
|
|
|
_(L("Bridge infill")) + "|" +
|
|
|
|
_(L("Gap fill")) + "|" +
|
|
|
|
_(L("Skirt")) + "|" +
|
|
|
|
_(L("Support material")) + "|" +
|
|
|
|
_(L("Support material interface")) + "|" +
|
|
|
|
_(L("Wipe tower")) + "|" +
|
2018-09-19 08:34:21 +00:00
|
|
|
_(L("Custom"))
|
|
|
|
);
|
2018-09-18 11:35:05 +00:00
|
|
|
Slic3r::GUI::create_combochecklist(m_combochecklist_features, feature_text, feature_items, true);
|
|
|
|
|
|
|
|
m_checkbox_travel = new wxCheckBox(this, wxID_ANY, _(L("Travel")));
|
|
|
|
m_checkbox_retractions = new wxCheckBox(this, wxID_ANY, _(L("Retractions")));
|
|
|
|
m_checkbox_unretractions = new wxCheckBox(this, wxID_ANY, _(L("Unretractions")));
|
|
|
|
m_checkbox_shells = new wxCheckBox(this, wxID_ANY, _(L("Shells")));
|
2019-06-22 15:38:14 +00:00
|
|
|
m_checkbox_legend = new wxCheckBox(this, wxID_ANY, _(L("Legend")));
|
|
|
|
m_checkbox_legend->SetValue(true);
|
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
wxBoxSizer* top_sizer = new wxBoxSizer(wxHORIZONTAL);
|
2018-11-23 11:47:32 +00:00
|
|
|
top_sizer->Add(m_canvas_widget, 1, wxALL | wxEXPAND, 0);
|
2018-09-18 11:35:05 +00:00
|
|
|
top_sizer->Add(m_double_slider_sizer, 0, wxEXPAND, 0);
|
|
|
|
|
|
|
|
wxBoxSizer* bottom_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
bottom_sizer->Add(m_label_view_type, 0, wxALIGN_CENTER_VERTICAL, 5);
|
2018-10-02 12:30:01 +00:00
|
|
|
bottom_sizer->Add(m_choice_view_type, 0, wxEXPAND | wxALL, 5);
|
2018-09-18 11:35:05 +00:00
|
|
|
bottom_sizer->AddSpacer(10);
|
|
|
|
bottom_sizer->Add(m_label_show_features, 0, wxALIGN_CENTER_VERTICAL, 5);
|
2018-10-02 12:30:01 +00:00
|
|
|
bottom_sizer->Add(m_combochecklist_features, 0, wxEXPAND | wxALL, 5);
|
2018-09-18 11:35:05 +00:00
|
|
|
bottom_sizer->AddSpacer(20);
|
2018-10-02 12:30:01 +00:00
|
|
|
bottom_sizer->Add(m_checkbox_travel, 0, wxEXPAND | wxALL, 5);
|
2018-09-18 11:35:05 +00:00
|
|
|
bottom_sizer->AddSpacer(10);
|
2018-10-02 12:30:01 +00:00
|
|
|
bottom_sizer->Add(m_checkbox_retractions, 0, wxEXPAND | wxALL, 5);
|
2018-09-18 11:35:05 +00:00
|
|
|
bottom_sizer->AddSpacer(10);
|
2018-10-02 12:30:01 +00:00
|
|
|
bottom_sizer->Add(m_checkbox_unretractions, 0, wxEXPAND | wxALL, 5);
|
2018-09-18 11:35:05 +00:00
|
|
|
bottom_sizer->AddSpacer(10);
|
2018-10-02 12:30:01 +00:00
|
|
|
bottom_sizer->Add(m_checkbox_shells, 0, wxEXPAND | wxALL, 5);
|
2019-06-22 15:38:14 +00:00
|
|
|
bottom_sizer->AddSpacer(20);
|
|
|
|
bottom_sizer->Add(m_checkbox_legend, 0, wxEXPAND | wxALL, 5);
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_sizer->Add(top_sizer, 1, wxALL | wxEXPAND, 0);
|
|
|
|
main_sizer->Add(bottom_sizer, 0, wxALL | wxEXPAND, 0);
|
|
|
|
|
|
|
|
SetSizer(main_sizer);
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
|
|
|
|
bind_event_handlers();
|
|
|
|
|
|
|
|
// sets colors for gcode preview extrusion roles
|
2018-09-19 12:11:36 +00:00
|
|
|
std::vector<std::string> extrusion_roles_colors = {
|
|
|
|
"Perimeter", "FFFF66",
|
|
|
|
"External perimeter", "FFA500",
|
|
|
|
"Overhang perimeter", "0000FF",
|
|
|
|
"Internal infill", "B1302A",
|
|
|
|
"Solid infill", "D732D7",
|
|
|
|
"Top solid infill", "FF1A1A",
|
|
|
|
"Bridge infill", "9999FF",
|
|
|
|
"Gap fill", "FFFFFF",
|
|
|
|
"Skirt", "845321",
|
|
|
|
"Support material", "00FF00",
|
|
|
|
"Support material interface", "008000",
|
|
|
|
"Wipe tower", "B3E3AB",
|
|
|
|
"Custom", "28CC94"
|
2018-09-18 11:35:05 +00:00
|
|
|
};
|
|
|
|
m_gcode_preview_data->set_extrusion_paths_colors(extrusion_roles_colors);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Preview::~Preview()
|
|
|
|
{
|
|
|
|
unbind_event_handlers();
|
|
|
|
|
2020-03-02 09:58:46 +00:00
|
|
|
if (m_canvas != nullptr)
|
|
|
|
delete m_canvas;
|
|
|
|
|
2018-11-23 11:47:32 +00:00
|
|
|
if (m_canvas_widget != nullptr)
|
|
|
|
delete m_canvas_widget;
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-24 13:55:14 +00:00
|
|
|
void Preview::set_as_dirty()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->set_as_dirty();
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
void Preview::set_number_extruders(unsigned int number_extruders)
|
|
|
|
{
|
|
|
|
if (m_number_extruders != number_extruders)
|
|
|
|
{
|
|
|
|
m_number_extruders = number_extruders;
|
2018-12-18 08:08:32 +00:00
|
|
|
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";
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::set_enabled(bool enabled)
|
|
|
|
{
|
|
|
|
m_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:15:27 +00:00
|
|
|
void Preview::bed_shape_changed()
|
|
|
|
{
|
|
|
|
if (m_canvas != nullptr)
|
|
|
|
m_canvas->bed_shape_changed();
|
|
|
|
}
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
void Preview::select_view(const std::string& direction)
|
|
|
|
{
|
2018-11-23 11:47:32 +00:00
|
|
|
m_canvas->select_view(direction);
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::set_drop_target(wxDropTarget* target)
|
|
|
|
{
|
|
|
|
if (target != nullptr)
|
|
|
|
SetDropTarget(target);
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:48:20 +00:00
|
|
|
void Preview::load_print(bool keep_z_range)
|
2018-09-18 11:35:05 +00:00
|
|
|
{
|
2018-11-26 14:16:35 +00:00
|
|
|
PrinterTechnology tech = m_process->current_printer_technology();
|
|
|
|
if (tech == ptFFF)
|
2019-03-19 09:48:20 +00:00
|
|
|
load_print_as_fff(keep_z_range);
|
2018-11-26 14:16:35 +00:00
|
|
|
else if (tech == ptSLA)
|
|
|
|
load_print_as_sla();
|
2019-10-30 07:28:40 +00:00
|
|
|
|
|
|
|
Layout();
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 13:07:55 +00:00
|
|
|
void Preview::reload_print(bool keep_volumes)
|
2018-09-18 11:35:05 +00:00
|
|
|
{
|
2019-03-21 10:44:39 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
// We are getting mysterious crashes on Linux in gtk due to OpenGL context activation GH #1874 #1955.
|
|
|
|
// So we are applying a workaround here: a delayed release of OpenGL vertex buffers.
|
2019-03-18 13:07:55 +00:00
|
|
|
if (!IsShown())
|
|
|
|
{
|
|
|
|
m_volumes_cleanup_required = !keep_volumes;
|
2019-03-18 11:59:52 +00:00
|
|
|
return;
|
2019-03-18 13:07:55 +00:00
|
|
|
}
|
2019-03-21 11:09:14 +00:00
|
|
|
#endif /* __linux __ */
|
2019-03-21 10:54:25 +00:00
|
|
|
if (
|
2019-03-19 09:54:54 +00:00
|
|
|
#ifdef __linux__
|
2019-03-21 10:54:25 +00:00
|
|
|
m_volumes_cleanup_required ||
|
|
|
|
#endif /* __linux__ */
|
|
|
|
!keep_volumes)
|
2019-02-28 14:27:03 +00:00
|
|
|
{
|
|
|
|
m_canvas->reset_volumes();
|
|
|
|
m_canvas->reset_legend_texture();
|
|
|
|
m_loaded = false;
|
2019-03-21 10:54:25 +00:00
|
|
|
#ifdef __linux__
|
2019-03-18 13:07:55 +00:00
|
|
|
m_volumes_cleanup_required = false;
|
2019-03-21 10:54:25 +00:00
|
|
|
#endif /* __linux__ */
|
2019-02-28 14:27:03 +00:00
|
|
|
}
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
load_print();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::refresh_print()
|
|
|
|
{
|
|
|
|
m_loaded = false;
|
|
|
|
|
|
|
|
if (!IsShown())
|
|
|
|
return;
|
|
|
|
|
2019-03-19 09:48:20 +00:00
|
|
|
load_print(true);
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 23:45:00 +00:00
|
|
|
void Preview::msw_rescale()
|
2019-04-16 08:05:45 +00:00
|
|
|
{
|
2019-04-16 10:11:48 +00:00
|
|
|
// rescale slider
|
2019-04-24 23:45:00 +00:00
|
|
|
if (m_slider) m_slider->msw_rescale();
|
2019-04-16 10:11:48 +00:00
|
|
|
|
|
|
|
// rescale warning legend on the canvas
|
2019-04-24 23:45:00 +00:00
|
|
|
get_canvas3d()->msw_rescale();
|
2019-04-16 10:11:48 +00:00
|
|
|
|
|
|
|
// rescale legend
|
|
|
|
refresh_print();
|
2019-04-16 08:05:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 14:10:33 +00:00
|
|
|
void Preview::move_double_slider(wxKeyEvent& evt)
|
|
|
|
{
|
|
|
|
if (m_slider)
|
|
|
|
m_slider->OnKeyDown(evt);
|
|
|
|
}
|
|
|
|
|
2019-06-18 09:40:26 +00:00
|
|
|
void Preview::edit_double_slider(wxKeyEvent& evt)
|
|
|
|
{
|
|
|
|
if (m_slider)
|
|
|
|
m_slider->OnChar(evt);
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
void Preview::bind_event_handlers()
|
|
|
|
{
|
|
|
|
this->Bind(wxEVT_SIZE, &Preview::on_size, this);
|
|
|
|
m_choice_view_type->Bind(wxEVT_CHOICE, &Preview::on_choice_view_type, this);
|
|
|
|
m_combochecklist_features->Bind(wxEVT_CHECKLISTBOX, &Preview::on_combochecklist_features, this);
|
|
|
|
m_checkbox_travel->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_travel, this);
|
|
|
|
m_checkbox_retractions->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_retractions, this);
|
|
|
|
m_checkbox_unretractions->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_unretractions, this);
|
|
|
|
m_checkbox_shells->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_shells, this);
|
2019-06-22 15:38:14 +00:00
|
|
|
m_checkbox_legend->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_legend, this);
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::unbind_event_handlers()
|
|
|
|
{
|
|
|
|
this->Unbind(wxEVT_SIZE, &Preview::on_size, this);
|
|
|
|
m_choice_view_type->Unbind(wxEVT_CHOICE, &Preview::on_choice_view_type, this);
|
|
|
|
m_combochecklist_features->Unbind(wxEVT_CHECKLISTBOX, &Preview::on_combochecklist_features, this);
|
|
|
|
m_checkbox_travel->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_travel, this);
|
|
|
|
m_checkbox_retractions->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_retractions, this);
|
|
|
|
m_checkbox_unretractions->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_unretractions, this);
|
|
|
|
m_checkbox_shells->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_shells, this);
|
2019-06-22 15:38:14 +00:00
|
|
|
m_checkbox_legend->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_legend, this);
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::show_hide_ui_elements(const std::string& what)
|
|
|
|
{
|
|
|
|
bool enable = (what == "full");
|
|
|
|
m_label_show_features->Enable(enable);
|
|
|
|
m_combochecklist_features->Enable(enable);
|
|
|
|
m_checkbox_travel->Enable(enable);
|
|
|
|
m_checkbox_retractions->Enable(enable);
|
|
|
|
m_checkbox_unretractions->Enable(enable);
|
|
|
|
m_checkbox_shells->Enable(enable);
|
2019-06-22 15:38:14 +00:00
|
|
|
m_checkbox_legend->Enable(enable);
|
2018-09-18 11:35:05 +00:00
|
|
|
|
|
|
|
enable = (what != "none");
|
|
|
|
m_label_view_type->Enable(enable);
|
|
|
|
m_choice_view_type->Enable(enable);
|
2018-11-26 14:16:35 +00:00
|
|
|
|
|
|
|
bool visible = (what != "none");
|
|
|
|
m_label_show_features->Show(visible);
|
|
|
|
m_combochecklist_features->Show(visible);
|
|
|
|
m_checkbox_travel->Show(visible);
|
|
|
|
m_checkbox_retractions->Show(visible);
|
|
|
|
m_checkbox_unretractions->Show(visible);
|
|
|
|
m_checkbox_shells->Show(visible);
|
2019-06-22 15:38:14 +00:00
|
|
|
m_checkbox_legend->Show(visible);
|
2018-11-26 14:16:35 +00:00
|
|
|
m_label_view_type->Show(visible);
|
|
|
|
m_choice_view_type->Show(visible);
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 06:43:27 +00:00
|
|
|
void Preview::reset_sliders(bool reset_all)
|
2018-09-18 11:35:05 +00:00
|
|
|
{
|
|
|
|
m_enabled = false;
|
2018-12-20 09:55:50 +00:00
|
|
|
// reset_double_slider();
|
2019-10-24 06:43:27 +00:00
|
|
|
if (reset_all)
|
|
|
|
m_double_slider_sizer->Hide((size_t)0);
|
|
|
|
else
|
|
|
|
m_double_slider_sizer->GetItem(size_t(0))->GetSizer()->Hide(1);
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 09:48:20 +00:00
|
|
|
void Preview::update_sliders(const std::vector<double>& layers_z, bool keep_z_range)
|
2018-09-18 11:35:05 +00:00
|
|
|
{
|
|
|
|
m_enabled = true;
|
2019-10-16 07:45:11 +00:00
|
|
|
|
2019-03-19 09:48:20 +00:00
|
|
|
update_double_slider(layers_z, keep_z_range);
|
2018-09-18 11:35:05 +00:00
|
|
|
m_double_slider_sizer->Show((size_t)0);
|
2019-11-27 15:03:16 +00:00
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_size(wxSizeEvent& evt)
|
|
|
|
{
|
|
|
|
evt.Skip();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_choice_view_type(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_preferred_color_mode = (m_choice_view_type->GetStringSelection() == L("Tool")) ? "tool" : "feature";
|
|
|
|
int selection = m_choice_view_type->GetCurrentSelection();
|
|
|
|
if ((0 <= selection) && (selection < (int)GCodePreviewData::Extrusion::Num_View_Types))
|
|
|
|
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)selection;
|
|
|
|
|
|
|
|
reload_print();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_combochecklist_features(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
int flags = Slic3r::GUI::combochecklist_get_flags(m_combochecklist_features);
|
|
|
|
m_gcode_preview_data->extrusion.role_flags = (unsigned int)flags;
|
|
|
|
refresh_print();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_checkbox_travel(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_gcode_preview_data->travel.is_visible = m_checkbox_travel->IsChecked();
|
2019-12-08 00:31:28 +00:00
|
|
|
m_gcode_preview_data->ranges.feedrate.set_mode(GCodePreviewData::FeedrateKind::TRAVEL, m_gcode_preview_data->travel.is_visible);
|
|
|
|
// Rather than refresh, reload print so that speed color ranges get recomputed (affected by travel visibility)
|
|
|
|
reload_print();
|
2018-09-18 11:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_checkbox_retractions(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_gcode_preview_data->retraction.is_visible = m_checkbox_retractions->IsChecked();
|
|
|
|
refresh_print();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_checkbox_unretractions(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_gcode_preview_data->unretraction.is_visible = m_checkbox_unretractions->IsChecked();
|
|
|
|
refresh_print();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::on_checkbox_shells(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_gcode_preview_data->shell.is_visible = m_checkbox_shells->IsChecked();
|
|
|
|
refresh_print();
|
|
|
|
}
|
|
|
|
|
2019-06-22 15:38:14 +00:00
|
|
|
void Preview::on_checkbox_legend(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_canvas->enable_legend_texture(m_checkbox_legend->IsChecked());
|
|
|
|
m_canvas_widget->Refresh();
|
|
|
|
}
|
|
|
|
|
2019-10-16 07:45:11 +00:00
|
|
|
void Preview::update_view_type(bool slice_completed)
|
2019-07-02 11:13:17 +00:00
|
|
|
{
|
|
|
|
const DynamicPrintConfig& config = wxGetApp().preset_bundle->project_config;
|
|
|
|
|
2020-01-16 15:01:19 +00:00
|
|
|
const wxString& choice = !wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes.empty() /*&&
|
2019-11-15 15:36:29 +00:00
|
|
|
(wxGetApp().extruders_edited_cnt()==1 || !slice_completed) */?
|
2019-10-10 14:03:58 +00:00
|
|
|
_(L("Color Print")) :
|
|
|
|
config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values.size() > 1 ?
|
|
|
|
_(L("Tool")) :
|
|
|
|
_(L("Feature type"));
|
2019-07-02 11:13:17 +00:00
|
|
|
|
|
|
|
int type = m_choice_view_type->FindString(choice);
|
|
|
|
if (m_choice_view_type->GetSelection() != 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 = "feature";
|
|
|
|
}
|
2019-10-16 07:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::create_double_slider()
|
|
|
|
{
|
2020-01-23 14:07:31 +00:00
|
|
|
m_slider = new DoubleSlider::Control(this, wxID_ANY, 0, 0, 0, 100);
|
2020-02-13 14:28:04 +00:00
|
|
|
bool sla_print_technology = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA;
|
|
|
|
bool sequential_print = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects");
|
|
|
|
m_slider->SetDrawMode(sla_print_technology, sequential_print);
|
2019-11-08 10:24:57 +00:00
|
|
|
|
2019-11-27 15:03:16 +00:00
|
|
|
m_double_slider_sizer->Add(m_slider, 0, wxEXPAND, 0);
|
2019-10-09 07:28:50 +00:00
|
|
|
|
2018-11-23 11:47:32 +00:00
|
|
|
// sizer, m_canvas_widget
|
|
|
|
m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this);
|
2020-02-03 20:27:53 +00:00
|
|
|
m_canvas_widget->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& event) {
|
|
|
|
if (event.GetKeyCode() == WXK_SHIFT)
|
|
|
|
m_slider->UseDefaultColors(true);
|
|
|
|
event.Skip();
|
|
|
|
});
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-27 13:50:57 +00:00
|
|
|
m_slider->Bind(wxEVT_SCROLL_CHANGED, &Preview::on_sliders_scroll_changed, this);
|
2018-11-07 13:44:47 +00:00
|
|
|
|
2019-05-17 13:04:06 +00:00
|
|
|
|
2020-01-23 14:07:31 +00:00
|
|
|
Bind(DoubleSlider::wxCUSTOMEVT_TICKSCHANGED, [this](wxEvent&) {
|
2019-10-10 14:03:58 +00:00
|
|
|
Model& model = wxGetApp().plater()->model();
|
2020-01-17 10:38:52 +00:00
|
|
|
model.custom_gcode_per_print_z = m_slider->GetTicksValues();
|
2019-07-02 11:13:17 +00:00
|
|
|
m_schedule_background_process();
|
|
|
|
|
2019-10-16 07:45:11 +00:00
|
|
|
update_view_type(false);
|
2019-07-02 11:13:17 +00:00
|
|
|
|
|
|
|
reload_print();
|
|
|
|
});
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 09:55:50 +00:00
|
|
|
// Find an index of a value in a sorted vector, which is in <z-eps, z+eps>.
|
|
|
|
// Returns -1 if there is no such member.
|
|
|
|
static int find_close_layer_idx(const std::vector<double>& zs, double &z, double eps)
|
|
|
|
{
|
|
|
|
if (zs.empty())
|
|
|
|
return -1;
|
|
|
|
auto it_h = std::lower_bound(zs.begin(), zs.end(), z);
|
|
|
|
if (it_h == zs.end()) {
|
|
|
|
auto it_l = it_h;
|
|
|
|
-- it_l;
|
|
|
|
if (z - *it_l < eps)
|
|
|
|
return int(zs.size() - 1);
|
|
|
|
} else if (it_h == zs.begin()) {
|
|
|
|
if (*it_h - z < eps)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
auto it_l = it_h;
|
|
|
|
-- it_l;
|
|
|
|
double dist_l = z - *it_l;
|
|
|
|
double dist_h = *it_h - z;
|
|
|
|
if (std::min(dist_l, dist_h) < eps) {
|
|
|
|
return (dist_l < dist_h) ? int(it_l - zs.begin()) : int(it_h - zs.begin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-01-23 11:49:39 +00:00
|
|
|
void Preview::check_slider_values(std::vector<CustomGCode::Item>& ticks_from_model,
|
2019-10-10 14:03:58 +00:00
|
|
|
const std::vector<double>& layers_z)
|
|
|
|
{
|
|
|
|
// All ticks that would end up outside the slider range should be erased.
|
|
|
|
// TODO: this should be placed into more appropriate part of code,
|
|
|
|
// this function is e.g. not called when the last object is deleted
|
|
|
|
unsigned int old_size = ticks_from_model.size();
|
|
|
|
ticks_from_model.erase(std::remove_if(ticks_from_model.begin(), ticks_from_model.end(),
|
2020-01-23 11:49:39 +00:00
|
|
|
[layers_z](CustomGCode::Item val)
|
2019-10-10 14:03:58 +00:00
|
|
|
{
|
2019-12-17 07:37:50 +00:00
|
|
|
auto it = std::lower_bound(layers_z.begin(), layers_z.end(), val.print_z - DoubleSlider::epsilon());
|
2019-10-10 14:03:58 +00:00
|
|
|
return it == layers_z.end();
|
|
|
|
}),
|
|
|
|
ticks_from_model.end());
|
|
|
|
if (ticks_from_model.size() != old_size)
|
|
|
|
m_schedule_background_process();
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:48:20 +00:00
|
|
|
void Preview::update_double_slider(const std::vector<double>& layers_z, bool keep_z_range)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-12-20 09:55:50 +00:00
|
|
|
// Save the initial slider span.
|
|
|
|
double z_low = m_slider->GetLowerValueD();
|
|
|
|
double z_high = m_slider->GetHigherValueD();
|
|
|
|
bool was_empty = m_slider->GetMaxValue() == 0;
|
2019-03-18 15:00:44 +00:00
|
|
|
bool force_sliders_full_range = was_empty;
|
2019-03-19 09:48:20 +00:00
|
|
|
if (!keep_z_range)
|
|
|
|
{
|
2019-09-04 11:16:44 +00:00
|
|
|
bool span_changed = layers_z.empty() || std::abs(layers_z.back() - m_slider->GetMaxValueD()) > DoubleSlider::epsilon()/*1e-6*/;
|
2019-03-19 09:48:20 +00:00
|
|
|
force_sliders_full_range |= span_changed;
|
|
|
|
}
|
2019-03-18 15:00:44 +00:00
|
|
|
bool snap_to_min = force_sliders_full_range || m_slider->is_lower_at_min();
|
2018-12-20 09:55:50 +00:00
|
|
|
bool snap_to_max = force_sliders_full_range || m_slider->is_higher_at_max();
|
|
|
|
|
2020-01-17 10:38:52 +00:00
|
|
|
// Detect and set manipulation mode for double slider
|
|
|
|
update_double_slider_mode();
|
|
|
|
|
2020-01-23 11:49:39 +00:00
|
|
|
CustomGCode::Info &ticks_info_from_model = wxGetApp().plater()->model().custom_gcode_per_print_z;
|
2020-01-17 10:38:52 +00:00
|
|
|
check_slider_values(ticks_info_from_model.gcodes, layers_z);
|
2019-09-05 09:47:04 +00:00
|
|
|
|
|
|
|
m_slider->SetSliderValues(layers_z);
|
2018-12-20 09:55:50 +00:00
|
|
|
assert(m_slider->GetMinValue() == 0);
|
|
|
|
m_slider->SetMaxValue(layers_z.empty() ? 0 : layers_z.size() - 1);
|
|
|
|
|
|
|
|
int idx_low = 0;
|
|
|
|
int idx_high = m_slider->GetMaxValue();
|
|
|
|
if (! layers_z.empty()) {
|
|
|
|
if (! snap_to_min) {
|
2019-09-04 11:16:44 +00:00
|
|
|
int idx_new = find_close_layer_idx(layers_z, z_low, DoubleSlider::epsilon()/*1e-6*/);
|
2018-12-20 09:55:50 +00:00
|
|
|
if (idx_new != -1)
|
|
|
|
idx_low = idx_new;
|
|
|
|
}
|
|
|
|
if (! snap_to_max) {
|
2019-09-04 11:16:44 +00:00
|
|
|
int idx_new = find_close_layer_idx(layers_z, z_high, DoubleSlider::epsilon()/*1e-6*/);
|
2018-12-20 09:55:50 +00:00
|
|
|
if (idx_new != -1)
|
|
|
|
idx_high = idx_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_slider->SetSelectionSpan(idx_low, idx_high);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2020-01-17 10:38:52 +00:00
|
|
|
m_slider->SetTicksValues(ticks_info_from_model);
|
2018-11-07 13:44:47 +00:00
|
|
|
|
2020-02-13 14:28:04 +00:00
|
|
|
bool sla_print_technology = wxGetApp().plater()->printer_technology() == ptSLA;
|
|
|
|
bool sequential_print = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects");
|
|
|
|
m_slider->SetDrawMode(sla_print_technology, sequential_print);
|
2020-02-14 08:51:51 +00:00
|
|
|
|
|
|
|
m_slider->SetExtruderColors(wxGetApp().plater()->get_extruder_colors_from_plater_config());
|
2020-01-10 15:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::update_double_slider_mode()
|
|
|
|
{
|
|
|
|
// true -> single-extruder printer profile OR
|
|
|
|
// multi-extruder printer profile , but whole model is printed by only one extruder
|
|
|
|
// false -> multi-extruder printer profile , and model is printed by several extruders
|
|
|
|
bool one_extruder_printed_model = true;
|
|
|
|
|
|
|
|
// extruder used for whole model for multi-extruder printer profile
|
|
|
|
int only_extruder = -1;
|
|
|
|
|
|
|
|
if (wxGetApp().extruders_edited_cnt() > 1)
|
|
|
|
{
|
|
|
|
const ModelObjectPtrs& objects = wxGetApp().plater()->model().objects;
|
|
|
|
|
|
|
|
// check if whole model uses just only one extruder
|
|
|
|
if (!objects.empty())
|
|
|
|
{
|
|
|
|
const int extruder = objects[0]->config.has("extruder") ?
|
|
|
|
objects[0]->config.option("extruder")->getInt() : 0;
|
|
|
|
|
|
|
|
auto is_one_extruder_printed_model = [objects, extruder]()
|
|
|
|
{
|
|
|
|
for (ModelObject* object : objects)
|
|
|
|
{
|
|
|
|
if (object->config.has("extruder") &&
|
|
|
|
object->config.option("extruder")->getInt() != extruder)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (object->volumes.size() > 1)
|
|
|
|
for (ModelVolume* volume : object->volumes)
|
|
|
|
if (volume->config.has("extruder") &&
|
|
|
|
volume->config.option("extruder")->getInt() != extruder)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (const auto& range : object->layer_config_ranges)
|
|
|
|
if (range.second.has("extruder") &&
|
|
|
|
range.second.option("extruder")->getInt() != extruder)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (is_one_extruder_printed_model())
|
|
|
|
only_extruder = extruder;
|
|
|
|
else
|
|
|
|
one_extruder_printed_model = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider->SetModeAndOnlyExtruder(one_extruder_printed_model, only_extruder);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::reset_double_slider()
|
|
|
|
{
|
|
|
|
m_slider->SetHigherValue(0);
|
|
|
|
m_slider->SetLowerValue(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::update_double_slider_from_canvas(wxKeyEvent& event)
|
|
|
|
{
|
|
|
|
if (event.HasModifiers()) {
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto key = event.GetKeyCode();
|
|
|
|
|
|
|
|
if (key == 'U' || key == 'D') {
|
|
|
|
const int new_pos = key == 'U' ? m_slider->GetHigherValue() + 1 : m_slider->GetHigherValue() - 1;
|
|
|
|
m_slider->SetHigherValue(new_pos);
|
2018-12-20 09:55:50 +00:00
|
|
|
if (event.ShiftDown() || m_slider->is_one_layer()) m_slider->SetLowerValue(m_slider->GetHigherValue());
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2019-06-22 15:39:09 +00:00
|
|
|
else if (key == 'L') {
|
|
|
|
m_checkbox_legend->SetValue(!m_checkbox_legend->GetValue());
|
|
|
|
auto evt = wxCommandEvent();
|
|
|
|
on_checkbox_legend(evt);
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
else if (key == 'S')
|
|
|
|
m_slider->ChangeOneLayerLock();
|
2020-02-03 20:27:53 +00:00
|
|
|
else if (key == WXK_SHIFT)
|
|
|
|
m_slider->UseDefaultColors(false);
|
2018-10-05 21:29:15 +00:00
|
|
|
else
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:48:20 +00:00
|
|
|
void Preview::load_print_as_fff(bool keep_z_range)
|
2018-11-26 14:16:35 +00:00
|
|
|
{
|
|
|
|
if (m_loaded || m_process->current_printer_technology() != ptFFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we require that there's at least one object and the posSlice step
|
|
|
|
// is performed on all of them(this ensures that _shifted_copies was
|
|
|
|
// populated and we know the number of layers)
|
2019-01-09 13:15:18 +00:00
|
|
|
bool has_layers = false;
|
2018-11-26 14:16:35 +00:00
|
|
|
const Print *print = m_process->fff_print();
|
2019-01-09 13:15:18 +00:00
|
|
|
if (print->is_step_done(posSlice)) {
|
2018-11-26 14:16:35 +00:00
|
|
|
for (const PrintObject* print_object : print->objects())
|
2019-01-09 13:15:18 +00:00
|
|
|
if (! print_object->layers().empty()) {
|
|
|
|
has_layers = true;
|
|
|
|
break;
|
2018-11-26 14:16:35 +00:00
|
|
|
}
|
2019-01-09 13:15:18 +00:00
|
|
|
}
|
|
|
|
if (print->is_step_done(posSupportMaterial)) {
|
|
|
|
for (const PrintObject* print_object : print->objects())
|
|
|
|
if (! print_object->support_layers().empty()) {
|
|
|
|
has_layers = true;
|
|
|
|
break;
|
2018-11-26 14:16:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:15:18 +00:00
|
|
|
if (! has_layers)
|
2018-11-26 14:16:35 +00:00
|
|
|
{
|
2019-10-24 06:43:27 +00:00
|
|
|
reset_sliders(true);
|
2018-11-26 14:16:35 +00:00
|
|
|
m_canvas->reset_legend_texture();
|
|
|
|
m_canvas_widget->Refresh();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_preferred_color_mode == "tool_or_feature")
|
|
|
|
{
|
|
|
|
// It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
|
|
|
|
// Color by feature if it is a single extruder print.
|
|
|
|
unsigned int number_extruders = (unsigned int)print->extruders().size();
|
|
|
|
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;
|
|
|
|
// If the->SetSelection changed the following line, revert it to "decide yourself".
|
|
|
|
m_preferred_color_mode = "tool_or_feature";
|
|
|
|
}
|
|
|
|
|
2019-01-29 14:11:29 +00:00
|
|
|
bool gcode_preview_data_valid = print->is_step_done(psGCodeExport) && ! m_gcode_preview_data->empty();
|
2018-11-26 14:16:35 +00:00
|
|
|
// Collect colors per extruder.
|
|
|
|
std::vector<std::string> colors;
|
2020-01-23 11:49:39 +00:00
|
|
|
std::vector<CustomGCode::Item> color_print_values = {};
|
2019-01-29 14:11:29 +00:00
|
|
|
// set color print values, if it si selected "ColorPrint" view type
|
|
|
|
if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
|
|
|
|
{
|
2019-11-27 14:27:44 +00:00
|
|
|
colors = wxGetApp().plater()->get_colors_for_color_print();
|
2019-11-04 15:28:57 +00:00
|
|
|
colors.push_back("#808080"); // gray color for pause print or custom G-code
|
2019-11-04 12:42:47 +00:00
|
|
|
|
2019-11-27 14:27:44 +00:00
|
|
|
if (!gcode_preview_data_valid)
|
2020-01-16 15:01:19 +00:00
|
|
|
color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
|
2019-01-29 14:11:29 +00:00
|
|
|
}
|
|
|
|
else if (gcode_preview_data_valid || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool) )
|
2018-11-26 14:16:35 +00:00
|
|
|
{
|
2019-11-27 14:27:44 +00:00
|
|
|
colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
2019-01-30 11:10:26 +00:00
|
|
|
color_print_values.clear();
|
2018-11-26 14:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsShown())
|
|
|
|
{
|
2019-11-27 15:03:16 +00:00
|
|
|
m_canvas->set_selected_extruder(0);
|
2019-03-14 15:31:55 +00:00
|
|
|
if (gcode_preview_data_valid) {
|
2019-01-15 09:00:34 +00:00
|
|
|
// Load the real G-code preview.
|
2018-11-26 14:16:35 +00:00
|
|
|
m_canvas->load_gcode_preview(*m_gcode_preview_data, colors);
|
2019-03-14 15:31:55 +00:00
|
|
|
m_loaded = true;
|
2019-07-02 11:13:17 +00:00
|
|
|
} else {
|
2019-01-15 09:00:34 +00:00
|
|
|
// Load the initial preview based on slices, not the final G-code.
|
2019-01-29 14:11:29 +00:00
|
|
|
m_canvas->load_preview(colors, color_print_values);
|
2019-07-02 11:13:17 +00:00
|
|
|
}
|
2019-01-15 09:00:34 +00:00
|
|
|
show_hide_ui_elements(gcode_preview_data_valid ? "full" : "simple");
|
|
|
|
// recalculates zs and update sliders accordingly
|
|
|
|
std::vector<double> zs = m_canvas->get_current_print_zs(true);
|
|
|
|
if (zs.empty()) {
|
|
|
|
// all layers filtered out
|
2019-11-27 15:03:16 +00:00
|
|
|
reset_sliders(true);
|
2019-01-15 09:00:34 +00:00
|
|
|
m_canvas_widget->Refresh();
|
|
|
|
} else
|
2019-03-19 09:48:20 +00:00
|
|
|
update_sliders(zs, keep_z_range);
|
2018-11-26 14:16:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preview::load_print_as_sla()
|
|
|
|
{
|
|
|
|
if (m_loaded || (m_process->current_printer_technology() != ptSLA))
|
|
|
|
return;
|
|
|
|
|
2018-11-26 15:17:59 +00:00
|
|
|
unsigned int n_layers = 0;
|
|
|
|
const SLAPrint* print = m_process->sla_print();
|
|
|
|
|
2019-03-22 20:26:58 +00:00
|
|
|
std::vector<double> zs;
|
|
|
|
double initial_layer_height = print->material_config().initial_layer_height.value;
|
2018-11-26 15:17:59 +00:00
|
|
|
for (const SLAPrintObject* obj : print->objects())
|
2019-03-27 09:59:29 +00:00
|
|
|
if (obj->is_step_done(slaposSliceSupports) && !obj->get_slice_index().empty())
|
2018-11-26 15:17:59 +00:00
|
|
|
{
|
2019-03-25 18:02:05 +00:00
|
|
|
auto low_coord = obj->get_slice_index().front().print_level();
|
|
|
|
for (auto& rec : obj->get_slice_index())
|
|
|
|
zs.emplace_back(initial_layer_height + (rec.print_level() - low_coord) * SCALING_FACTOR);
|
2018-11-26 15:17:59 +00:00
|
|
|
}
|
2019-03-22 20:26:58 +00:00
|
|
|
sort_remove_duplicates(zs);
|
2018-11-26 15:17:59 +00:00
|
|
|
|
2019-04-02 11:47:49 +00:00
|
|
|
m_canvas->reset_clipping_planes_cache();
|
|
|
|
|
2018-11-26 15:17:59 +00:00
|
|
|
n_layers = (unsigned int)zs.size();
|
|
|
|
if (n_layers == 0)
|
|
|
|
{
|
2019-10-24 06:43:27 +00:00
|
|
|
reset_sliders(true);
|
2018-11-26 15:17:59 +00:00
|
|
|
m_canvas_widget->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsShown())
|
|
|
|
{
|
|
|
|
m_canvas->load_sla_preview();
|
|
|
|
show_hide_ui_elements("none");
|
|
|
|
|
|
|
|
if (n_layers > 0)
|
2019-03-22 20:26:58 +00:00
|
|
|
update_sliders(zs);
|
2018-11-26 15:17:59 +00:00
|
|
|
|
|
|
|
m_loaded = true;
|
|
|
|
}
|
2018-11-26 14:16:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:04:06 +00:00
|
|
|
void Preview::on_sliders_scroll_changed(wxCommandEvent& event)
|
2018-11-27 13:50:57 +00:00
|
|
|
{
|
|
|
|
if (IsShown())
|
|
|
|
{
|
|
|
|
PrinterTechnology tech = m_process->current_printer_technology();
|
|
|
|
if (tech == ptFFF)
|
|
|
|
{
|
|
|
|
m_canvas->set_toolpaths_range(m_slider->GetLowerValueD() - 1e-6, m_slider->GetHigherValueD() + 1e-6);
|
2019-05-17 13:04:06 +00:00
|
|
|
m_canvas->render();
|
2018-11-27 13:50:57 +00:00
|
|
|
m_canvas->set_use_clipping_planes(false);
|
|
|
|
}
|
|
|
|
else if (tech == ptSLA)
|
|
|
|
{
|
2019-04-08 08:50:10 +00:00
|
|
|
m_canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), -m_slider->GetLowerValueD()));
|
|
|
|
m_canvas->set_clipping_plane(1, ClippingPlane(-Vec3d::UnitZ(), m_slider->GetHigherValueD()));
|
2018-11-27 14:36:31 +00:00
|
|
|
m_canvas->set_use_clipping_planes(m_slider->GetHigherValue() != 0);
|
2019-05-17 13:04:06 +00:00
|
|
|
m_canvas->render();
|
2018-11-27 13:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:04:06 +00:00
|
|
|
|
2018-09-18 11:35:05 +00:00
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|