1st installment of preview ported in c++

This commit is contained in:
Enrico Turri 2018-09-18 13:35:05 +02:00
parent 5fa99fd903
commit e3e5948982
13 changed files with 718 additions and 10 deletions

View File

@ -296,29 +296,52 @@ sub new {
}
});
Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D}, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); });
#======================================================================================================================================
Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D},
sub {
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D});
$self->{preview_iface}->set_viewport_from_scene($self->{canvas3D});
});
# Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D}, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); });
#======================================================================================================================================
}
Slic3r::GUI::register_on_request_update_callback(sub { $self->schedule_background_process; });
# Initialize 3D toolpaths preview
if ($Slic3r::GUI::have_OpenGL) {
#======================================================================================================================================
$self->{preview_iface} = Slic3r::GUI::create_preview_iface($self->{preview_notebook}, $self->{config}, $self->{print}, $self->{gcode_preview_data});
$self->{preview_page_idx} = $self->{preview_notebook}->GetPageCount-1;
#======================================================================================================================================
$self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print}, $self->{gcode_preview_data}, $self->{config});
Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 1);
Slic3r::GUI::_3DScene::enable_dynamic_background($self->{preview3D}->canvas, 1);
Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{preview3D}->canvas, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas); });
#======================================================================================================================================
$self->{preview_iface}->register_on_viewport_changed_callback(sub { $self->{preview_iface}->set_viewport_into_scene($self->{canvas3D}); });
#======================================================================================================================================
$self->{preview_notebook}->AddPage($self->{preview3D}, L('Preview'));
$self->{preview3D_page_idx} = $self->{preview_notebook}->GetPageCount-1;
}
EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{preview_notebook}, sub {
my $preview = $self->{preview_notebook}->GetCurrentPage;
if (($preview != $self->{preview3D}) && ($preview != $self->{canvas3D})) {
#======================================================================================================================================
if (($preview != $self->{preview3D}) && ($preview != $self->{canvas3D}) && ($preview != $self->{preview_iface})) {
# if (($preview != $self->{preview3D}) && ($preview != $self->{canvas3D})) {
#======================================================================================================================================
$preview->OnActivate if $preview->can('OnActivate');
} elsif ($preview == $self->{preview3D}) {
$self->{preview3D}->reload_print;
# sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
Slic3r::GUI::_3DScene::set_as_dirty($self->{preview3D}->canvas);
#======================================================================================================================================
} elsif ($preview == $self->{preview_iface}) {
$self->{preview_iface}->reload_print;
# sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
$self->{preview_iface}->set_canvas_as_dirty;
#======================================================================================================================================
} elsif ($preview == $self->{canvas3D}) {
if (Slic3r::GUI::_3DScene::is_reload_delayed($self->{canvas3D})) {
my $selections = $self->collect_selections;
@ -461,7 +484,10 @@ sub new {
$_->SetDropTarget(Slic3r::GUI::Plater::DropTarget->new($self))
for grep defined($_),
$self, $self->{canvas3D}, $self->{preview3D}, $self->{list};
#======================================================================================================================================
$self, $self->{canvas3D}, $self->{preview3D}, $self->{preview_iface}, $self->{list};
# $self, $self->{canvas3D}, $self->{preview3D}, $self->{list};
#======================================================================================================================================
# $self, $self->{canvas}, $self->{canvas3D}, $self->{preview3D};
EVT_COMMAND($self, -1, $SLICING_COMPLETED_EVENT, sub {
@ -491,6 +517,9 @@ sub new {
if ($self->{preview3D}) {
Slic3r::GUI::_3DScene::set_bed_shape($self->{preview3D}->canvas, $self->{config}->bed_shape);
}
#======================================================================================================================================
$self->{preview_iface}->set_bed_shape($self->{config}->bed_shape) if ($self->{preview_iface});
#======================================================================================================================================
$self->update;
{
@ -1006,6 +1035,9 @@ sub remove {
# Prevent toolpaths preview from rendering while we modify the Print object
$self->{preview3D}->enabled(0) if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->set_enabled(0) if $self->{preview_iface};
#======================================================================================================================================
# If no object index is supplied, remove the selected one.
if (! defined $obj_idx) {
@ -1031,6 +1063,9 @@ sub reset {
# Prevent toolpaths preview from rendering while we modify the Print object
$self->{preview3D}->enabled(0) if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->set_enabled(0) if $self->{preview_iface};
#======================================================================================================================================
@{$self->{objects}} = ();
$self->{model}->clear_objects;
@ -1392,6 +1427,9 @@ sub async_apply_config {
# Otherwise they will be just refreshed.
$self->{gcode_preview_data}->reset;
$self->{preview3D}->reload_print if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->reload_print if $self->{preview_iface};
#======================================================================================================================================
# We also need to reload 3D scene because of the wipe tower preview box
if ($self->{config}->wipe_tower) {
my $selections = $self->collect_selections;
@ -1427,6 +1465,9 @@ sub stop_background_process {
my ($self) = @_;
$self->{background_slicing_process}->stop();
$self->{preview3D}->reload_print if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->reload_print if $self->{preview_iface};
#======================================================================================================================================
}
# Called by the "Slice now" button, which is visible only if the background processing is disabled.
@ -1533,6 +1574,9 @@ sub export_gcode {
sub on_update_print_preview {
my ($self) = @_;
$self->{preview3D}->reload_print if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->reload_print if $self->{preview_iface};
#======================================================================================================================================
# in case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth:
my $selections = $self->collect_selections;
@ -1614,6 +1658,9 @@ sub on_process_completed {
# refresh preview
$self->{preview3D}->reload_print if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->reload_print if $self->{preview_iface};
#======================================================================================================================================
}
# Fill in the "Sliced info" box with the result of the G-code generator.
@ -1883,6 +1930,10 @@ sub update {
Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 0);
$self->{preview3D}->reset_gcode_preview_data if $self->{preview3D};
$self->{preview3D}->reload_print if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->reset_gcode_preview_data if $self->{preview_iface};
$self->{preview_iface}->reload_print if $self->{preview_iface};
#======================================================================================================================================
$self->schedule_background_process;
$self->Thaw;
}
@ -1959,6 +2010,9 @@ sub on_config_change {
# $self->{canvas}->update_bed_size;
Slic3r::GUI::_3DScene::set_bed_shape($self->{canvas3D}, $self->{config}->bed_shape) if $self->{canvas3D};
Slic3r::GUI::_3DScene::set_bed_shape($self->{preview3D}->canvas, $self->{config}->bed_shape) if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->set_bed_shape($self->{config}->bed_shape) if ($self->{preview_iface});
#======================================================================================================================================
$update_scheduled = 1;
} elsif ($opt_key =~ '^wipe_tower' || $opt_key eq 'single_extruder_multi_material') {
$update_scheduled = 1;
@ -1994,12 +2048,18 @@ sub on_config_change {
$update_scheduled = 1;
my $extruder_colors = $config->get('extruder_colour');
$self->{preview3D}->set_number_extruders(scalar(@{$extruder_colors}));
#======================================================================================================================================
$self->{preview_iface}->set_number_extruders(scalar(@{$extruder_colors}));
#======================================================================================================================================
} elsif ($opt_key eq 'max_print_height') {
$update_scheduled = 1;
} elsif ($opt_key eq 'printer_model') {
# update to force bed selection (for texturing)
Slic3r::GUI::_3DScene::set_bed_shape($self->{canvas3D}, $self->{config}->bed_shape) if $self->{canvas3D};
Slic3r::GUI::_3DScene::set_bed_shape($self->{preview3D}->canvas, $self->{config}->bed_shape) if $self->{preview3D};
#======================================================================================================================================
$self->{preview_iface}->set_bed_shape($self->{config}->bed_shape) if ($self->{preview_iface});
#======================================================================================================================================
$update_scheduled = 1;
}
}
@ -2450,12 +2510,24 @@ sub select_view {
my ($self, $direction) = @_;
my $idx_page = $self->{preview_notebook}->GetSelection;
my $page = ($idx_page == &Wx::wxNOT_FOUND) ? L('3D') : $self->{preview_notebook}->GetPageText($idx_page);
if ($page eq L('Preview')) {
Slic3r::GUI::_3DScene::select_view($self->{preview3D}->canvas, $direction);
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas);
#======================================================================================================================================
if (($page eq L('Preview')) || ($page eq L('_Preview_'))) {
#======================================================================================================================================
if ($page eq L('Preview')) {
Slic3r::GUI::_3DScene::select_view($self->{preview3D}->canvas, $direction);
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas);
#======================================================================================================================================
} else {
$self->{preview_iface}->select_view($direction);
$self->{preview_iface}->set_viewport_into_scene($self->{canvas3D});
}
#======================================================================================================================================
} else {
Slic3r::GUI::_3DScene::select_view($self->{canvas3D}, $direction);
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D});
#======================================================================================================================================
$self->{preview_iface}->set_viewport_from_scene($self->{canvas3D});
#======================================================================================================================================
}
}

View File

@ -222,6 +222,10 @@ add_library(libslic3r_gui STATIC
${LIBDIR}/slic3r/GUI/GUI.hpp
${LIBDIR}/slic3r/GUI/GUI_ObjectParts.cpp
${LIBDIR}/slic3r/GUI/GUI_ObjectParts.hpp
${LIBDIR}/slic3r/GUI/GUI_Preview.cpp
${LIBDIR}/slic3r/GUI/GUI_Preview.hpp
${LIBDIR}/slic3r/GUI/GUI_PreviewIface.cpp
${LIBDIR}/slic3r/GUI/GUI_PreviewIface.hpp
${LIBDIR}/slic3r/GUI/LambdaObjectDialog.cpp
${LIBDIR}/slic3r/GUI/LambdaObjectDialog.hpp
${LIBDIR}/slic3r/GUI/Tab.cpp
@ -463,6 +467,7 @@ set(XS_XSP_FILES
${XSP_DIR}/GUI_3DScene.xsp
${XSP_DIR}/GUI_Preset.xsp
${XSP_DIR}/GUI_Tab.xsp
${XSP_DIR}/GUI_Preview.xsp
${XSP_DIR}/Layer.xsp
${XSP_DIR}/Line.xsp
${XSP_DIR}/Model.xsp

View File

@ -63,6 +63,7 @@ REGISTER_CLASS(Preset, "GUI::Preset");
REGISTER_CLASS(PresetCollection, "GUI::PresetCollection");
REGISTER_CLASS(PresetBundle, "GUI::PresetBundle");
REGISTER_CLASS(TabIface, "GUI::Tab");
REGISTER_CLASS(PreviewIface, "GUI::Preview");
REGISTER_CLASS(ProgressStatusBar, "GUI::ProgressStatusBar");
REGISTER_CLASS(PresetUpdater, "PresetUpdater");
REGISTER_CLASS(AppController, "AppController");

View File

@ -46,6 +46,10 @@
#include "Tab.hpp"
#include "TabIface.hpp"
//##############################################################################################################################################################
#include "GUI_Preview.hpp"
#include "GUI_PreviewIface.hpp"
//##############################################################################################################################################################
#include "AboutDialog.hpp"
#include "AppConfig.hpp"
#include "ConfigSnapshotDialog.hpp"
@ -148,6 +152,10 @@ wxStaticBitmap *g_manifold_warning_icon = nullptr;
bool g_show_print_info = false;
bool g_show_manifold_warning_icon = false;
//##############################################################################################################################################################
PreviewIface* g_preview = nullptr; // <<< FIXME ENRICO -> add code to delete the pointer when the application closes
//##############################################################################################################################################################
static void init_label_colours()
{
auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
@ -665,6 +673,19 @@ TabIface* get_preset_tab_iface(char *name)
return new TabIface(nullptr);
}
//##############################################################################################################################################################
PreviewIface* create_preview_iface(wxNotebook* parent, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data)
{
if (g_preview == nullptr)
{
Preview* panel = new Preview(parent, config, print, gcode_preview_data);
g_preview = new PreviewIface(panel);
}
return g_preview;
}
//##############################################################################################################################################################
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
{

View File

@ -39,6 +39,11 @@ class AppConfig;
class PresetUpdater;
class DynamicPrintConfig;
class TabIface;
//##############################################################################################################################################################
class PreviewIface;
class Print;
class GCodePreviewData;
//##############################################################################################################################################################
#define _(s) Slic3r::GUI::I18N::translate((s))
@ -165,6 +170,10 @@ extern void open_preferences_dialog(int event_preferences);
void create_preset_tabs(int event_value_change, int event_presets_changed);
TabIface* get_preset_tab_iface(char *name);
//##############################################################################################################################################################
PreviewIface* create_preview_iface(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data);
//##############################################################################################################################################################
// add it at the end of the tab panel.
void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed);
// Change option value in config

View File

@ -0,0 +1,376 @@
#include "../../libslic3r/libslic3r.h"
#include "GUI_Preview.hpp"
#include "GUI.hpp"
#include "AppConfig.hpp"
#include "3DScene.hpp"
#include "../../libslic3r/GCode/PreviewData.hpp"
#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>
namespace Slic3r {
namespace GUI {
Preview::Preview(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data)
: m_canvas(nullptr)
, 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)
, m_config(config)
, m_print(print)
, m_gcode_preview_data(gcode_preview_data)
, m_number_extruders(1)
, m_preferred_color_mode("feature")
, m_loaded(false)
, m_enabled(false)
, m_force_sliders_full_range(false)
{
if (init(notebook, config, print, gcode_preview_data))
{
notebook->AddPage(this, _(L("_Preview_")));
show_hide_ui_elements("none");
reload_print();
}
}
bool Preview::init(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data)
{
if ((notebook == nullptr) || (config == nullptr) || (print == nullptr) || (gcode_preview_data == nullptr))
return false;
// creates this panel add append it to the given notebook as a new page
if (!Create(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize))
return false;
int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, WX_GL_SAMPLE_BUFFERS, 1, WX_GL_SAMPLES, 4, 0 };
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
const AppConfig* app_config = GUI::get_app_config();
bool enable_multisample = (app_config != nullptr) && (app_config->get("use_legacy_opengl") != "1") && (wxVersion >= 30003);
// if multisample is not enabled or supported by the graphic card, remove it from the attributes list
bool can_multisample = enable_multisample && wxGLCanvas::IsDisplaySupported(attribList); // <<< FIXME ENRICO IsDisplaySupported() seems not to work
if (!can_multisample)
attribList[4] = 0;
m_canvas = new wxGLCanvas(this, wxID_ANY, attribList);
if (m_canvas == nullptr)
return false;
_3DScene::add_canvas(m_canvas);
_3DScene::allow_multisample(m_canvas, can_multisample);
_3DScene::enable_shader(m_canvas, true);
_3DScene::set_config(m_canvas, m_config);
_3DScene::set_print(m_canvas, m_print);
_3DScene::enable_legend_texture(m_canvas, true);
_3DScene::enable_dynamic_background(m_canvas, true);
m_double_slider_sizer = new wxBoxSizer(wxHORIZONTAL);
create_double_slider(this, m_double_slider_sizer, m_canvas);
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")));
m_choice_view_type->Append(_(L("Volumetric flow rate")));
m_choice_view_type->Append(_(L("Tool")));
m_choice_view_type->SetSelection(0);
m_label_show_features = new wxStaticText(this, wxID_ANY, _(L("Show")));
m_combochecklist_features = new wxComboCtrl();
m_combochecklist_features->Create(this, wxID_ANY, _(L("Feature types")), wxDefaultPosition, wxSize(200, -1), wxCB_READONLY);
std::string feature_text = _(L("Feature types"));
std::string feature_items = _(L("Perimeter")) + "|" +
_(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")) + "|" +
_(L("Custom"));
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")));
wxBoxSizer* top_sizer = new wxBoxSizer(wxHORIZONTAL);
top_sizer->Add(m_canvas, 1, wxALL | wxEXPAND, 0);
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);
bottom_sizer->Add(m_choice_view_type, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_label_show_features, 0, wxALIGN_CENTER_VERTICAL, 5);
bottom_sizer->Add(m_combochecklist_features, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
bottom_sizer->AddSpacer(20);
bottom_sizer->Add(m_checkbox_travel, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_checkbox_retractions, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_checkbox_unretractions, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_checkbox_shells, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
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
std::vector<std::string> extrusion_roles_colors = {
"FFFF66", // Perimeter
"FFA500", // External perimeter
"0000FF", // Overhang perimeter
"B1302A", // Internal infill
"D732D7", // Solid infill
"FF1A1A", // Top solid infill
"9999FF", // Bridge infill
"FFFFFF", // Gap fill
"845321", // Skirt
"00FF00", // Support material
"008000", // Support material interface
"B3E3AB", // Wipe tower
"28CC94" // Custom
};
m_gcode_preview_data->set_extrusion_paths_colors(extrusion_roles_colors);
return true;
}
Preview::~Preview()
{
unbind_event_handlers();
if (m_canvas != nullptr)
{
_3DScene::remove_canvas(m_canvas);
delete m_canvas;
}
}
void Preview::register_on_viewport_changed_callback(void* callback)
{
if ((m_canvas != nullptr) && (callback != nullptr))
_3DScene::register_on_viewport_changed_callback(m_canvas, callback);
}
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;
m_preferred_color_mode = (type == tool_idx) ? "tool_or_feature" : "feature";
}
}
}
void Preview::reset_gcode_preview_data()
{
m_gcode_preview_data->reset();
_3DScene::reset_legend_texture();
}
void Preview::set_canvas_as_dirty()
{
if (m_canvas != nullptr)
_3DScene::set_as_dirty(m_canvas);
}
void Preview::set_enabled(bool enabled)
{
m_enabled = enabled;
}
void Preview::set_bed_shape(const Pointfs& shape)
{
if (m_canvas != nullptr)
_3DScene::set_bed_shape(m_canvas, shape);
}
void Preview::select_view(const std::string& direction)
{
if (m_canvas != nullptr)
_3DScene::select_view(m_canvas, direction);
}
void Preview::set_viewport_from_scene(wxGLCanvas* canvas)
{
if ((m_canvas != nullptr) && (canvas != nullptr))
_3DScene::set_viewport_from_scene(m_canvas, canvas);
}
void Preview::set_viewport_into_scene(wxGLCanvas* canvas)
{
if ((m_canvas != nullptr) && (canvas != nullptr))
_3DScene::set_viewport_from_scene(canvas, m_canvas);
}
void Preview::set_drop_target(wxDropTarget* target)
{
if (target != nullptr)
SetDropTarget(target);
}
void Preview::load_print()
{
}
void Preview::reload_print(bool force)
{
_3DScene::reset_volumes(m_canvas);
m_loaded = false;
if (!IsShown() && !force)
return;
load_print();
}
void Preview::refresh_print()
{
m_loaded = false;
if (!IsShown())
return;
load_print();
}
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);
}
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);
}
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);
enable = (what != "none");
m_label_view_type->Enable(enable);
m_choice_view_type->Enable(enable);
}
void Preview::reset_sliders()
{
m_enabled = false;
reset_double_slider();
m_double_slider_sizer->Hide((size_t)0);
}
void Preview::update_sliders()
{
m_enabled = true;
update_double_slider(m_force_sliders_full_range);
m_double_slider_sizer->Show((size_t)0);
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();
refresh_print();
}
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();
}
} // namespace GUI
} // namespace Slic3r

View File

@ -0,0 +1,91 @@
#ifndef slic3r_GUI_Preview_hpp_
#define slic3r_GUI_Preview_hpp_
#include <wx/panel.h>
#include "../../libslic3r/Point.hpp"
#include <string>
class wxNotebook;
class wxGLCanvas;
class wxBoxSizer;
class wxStaticText;
class wxChoice;
class wxComboCtrl;
class wxCheckBox;
namespace Slic3r {
class DynamicPrintConfig;
class Print;
class GCodePreviewData;
namespace GUI {
class Preview : public wxPanel
{
wxGLCanvas* m_canvas;
wxBoxSizer* m_double_slider_sizer;
wxStaticText* m_label_view_type;
wxChoice* m_choice_view_type;
wxStaticText* m_label_show_features;
wxComboCtrl* m_combochecklist_features;
wxCheckBox* m_checkbox_travel;
wxCheckBox* m_checkbox_retractions;
wxCheckBox* m_checkbox_unretractions;
wxCheckBox* m_checkbox_shells;
DynamicPrintConfig* m_config;
Print* m_print;
GCodePreviewData* m_gcode_preview_data;
unsigned int m_number_extruders;
std::string m_preferred_color_mode;
bool m_loaded;
bool m_enabled;
bool m_force_sliders_full_range;
public:
Preview(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data);
virtual ~Preview();
void register_on_viewport_changed_callback(void* callback);
void set_number_extruders(unsigned int number_extruders);
void reset_gcode_preview_data();
void set_canvas_as_dirty();
void set_enabled(bool enabled);
void set_bed_shape(const Pointfs& shape);
void select_view(const std::string& direction);
void set_viewport_from_scene(wxGLCanvas* canvas);
void set_viewport_into_scene(wxGLCanvas* canvas);
void set_drop_target(wxDropTarget* target);
void load_print();
void reload_print(bool force = false);
void refresh_print();
private:
bool init(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data);
void bind_event_handlers();
void unbind_event_handlers();
void show_hide_ui_elements(const std::string& what);
void reset_sliders();
void update_sliders();
void on_size(wxSizeEvent& evt);
void on_choice_view_type(wxCommandEvent& evt);
void on_combochecklist_features(wxCommandEvent& evt);
void on_checkbox_travel(wxCommandEvent& evt);
void on_checkbox_retractions(wxCommandEvent& evt);
void on_checkbox_unretractions(wxCommandEvent& evt);
void on_checkbox_shells(wxCommandEvent& evt);
};
} // namespace GUI
} // namespace Slic3r
#endif // slic3r_GUI_Preview_hpp_

View File

@ -0,0 +1,62 @@
#include "../../libslic3r/libslic3r.h"
#include "GUI_PreviewIface.hpp"
#include "GUI_Preview.hpp"
namespace Slic3r {
void PreviewIface::register_on_viewport_changed_callback(void* callback)
{
m_preview->register_on_viewport_changed_callback(callback);
}
void PreviewIface::set_number_extruders(unsigned int number_extruders)
{
m_preview->set_number_extruders(number_extruders);
}
void PreviewIface::reset_gcode_preview_data()
{
m_preview->reset_gcode_preview_data();
}
void PreviewIface::reload_print(bool force)
{
m_preview->reload_print(force);
}
void PreviewIface::set_canvas_as_dirty()
{
m_preview->set_canvas_as_dirty();
}
void PreviewIface::set_enabled(bool enabled)
{
m_preview->set_enabled(enabled);
}
void PreviewIface::set_bed_shape(const Pointfs& shape)
{
m_preview->set_bed_shape(shape);
}
void PreviewIface::select_view(const std::string& direction)
{
m_preview->select_view(direction);
}
void PreviewIface::set_viewport_from_scene(wxGLCanvas* canvas)
{
m_preview->set_viewport_from_scene(canvas);
}
void PreviewIface::set_viewport_into_scene(wxGLCanvas* canvas)
{
m_preview->set_viewport_into_scene(canvas);
}
void PreviewIface::set_drop_target(wxDropTarget* target)
{
m_preview->set_drop_target(target);
}
} // namespace Slic3r

View File

@ -0,0 +1,37 @@
#ifndef slic3r_GUI_PreviewIface_hpp_
#define slic3r_GUI_PreviewIface_hpp_
#include "../../libslic3r/Point.hpp"
class wxGLCanvas;
class wxDropTarget;
namespace Slic3r {
namespace GUI {
class Preview;
} // namespace GUI
class PreviewIface
{
GUI::Preview* m_preview;
public:
explicit PreviewIface(GUI::Preview* preview) : m_preview(preview) {}
void register_on_viewport_changed_callback(void* callback);
void set_number_extruders(unsigned int number_extruders);
void reset_gcode_preview_data();
void reload_print(bool force = false);
void set_canvas_as_dirty();
void set_enabled(bool enabled);
void set_bed_shape(const Pointfs& shape);
void select_view(const std::string& direction);
void set_viewport_from_scene(wxGLCanvas* canvas);
void set_viewport_into_scene(wxGLCanvas* canvas);
void set_drop_target(wxDropTarget* target);
};
} // namespace Slic3r
#endif // slic3r_GUI_PreviewIface_hpp_

View File

@ -59,6 +59,9 @@ void show_error_id(int id, std::string msg)
TabIface* get_preset_tab(char *name)
%code%{ RETVAL=Slic3r::GUI::get_preset_tab_iface(name); %};
PreviewIface* create_preview_iface(SV *ui, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data)
%code%{ RETVAL=Slic3r::GUI::create_preview_iface((wxNotebook*)wxPli_sv_2_object(aTHX_ ui, "Wx::Notebook"), config, print, gcode_preview_data); %};
bool load_language()
%code%{ RETVAL=Slic3r::GUI::load_language(); %};

28
xs/xsp/GUI_Preview.xsp Normal file
View File

@ -0,0 +1,28 @@
%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "slic3r/GUI/GUI_PreviewIface.hpp"
%}
%name{Slic3r::GUI::Preview} class PreviewIface {
void register_on_viewport_changed_callback(SV* callback)
%code%{ THIS->register_on_viewport_changed_callback((void*)callback); %};
void set_number_extruders(unsigned int number_extruders);
void reset_gcode_preview_data();
void reload_print(bool force = false);
void set_canvas_as_dirty();
void set_enabled(bool enabled);
void set_bed_shape(Pointfs shape);
void select_view(std::string direction);
void set_viewport_from_scene(SV *ui)
%code%{ THIS->set_viewport_from_scene((wxGLCanvas*)wxPli_sv_2_object(aTHX_ ui, "Wx::GLCanvas")); %};
void set_viewport_into_scene(SV *ui)
%code%{ THIS->set_viewport_into_scene((wxGLCanvas*)wxPli_sv_2_object(aTHX_ ui, "Wx::GLCanvas")); %};
void SetDropTarget(SV *ui)
%code%{ THIS->set_drop_target((wxDropTarget*)wxPli_sv_2_object(aTHX_ ui, "Wx::DropTarget")); %};
};

View File

@ -235,10 +235,12 @@ PresetCollection* O_OBJECT_SLIC3R
Ref<PresetCollection> O_OBJECT_SLIC3R_T
PresetBundle* O_OBJECT_SLIC3R
Ref<PresetBundle> O_OBJECT_SLIC3R_T
TabIface* O_OBJECT_SLIC3R
Ref<TabIface> O_OBJECT_SLIC3R_T
ProgressStatusBar* O_OBJECT_SLIC3R
Ref<ProgressStatusBar> O_OBJECT_SLIC3R_T
TabIface* O_OBJECT_SLIC3R
Ref<TabIface> O_OBJECT_SLIC3R_T
PreviewIface* O_OBJECT_SLIC3R
Ref<PreviewIface> O_OBJECT_SLIC3R_T
ProgressStatusBar* O_OBJECT_SLIC3R
Ref<ProgressStatusBar> O_OBJECT_SLIC3R_T
PresetUpdater* O_OBJECT_SLIC3R
Ref<PresetUpdater> O_OBJECT_SLIC3R_T

View File

@ -215,6 +215,7 @@
%typemap{PresetHints*};
%typemap{Ref<PresetHints>}{simple};
%typemap{TabIface*};
%typemap{PreviewIface*};
%typemap{ProgressStatusBar*};
%typemap{PrintRegionPtrs*};