Merge remote-tracking branch 'origin/master' into ys_aliases

This commit is contained in:
YuSanka 2019-11-28 10:34:05 +01:00
commit 773dace33c
41 changed files with 2257 additions and 332 deletions

View file

@ -105,6 +105,8 @@ set(SLIC3R_GUI_SOURCES
GUI/Camera.hpp
GUI/wxExtensions.cpp
GUI/wxExtensions.hpp
GUI/ExtruderSequenceDialog.cpp
GUI/ExtruderSequenceDialog.hpp
GUI/WipeTowerDialog.cpp
GUI/WipeTowerDialog.hpp
GUI/RammingChart.cpp

View file

@ -33,6 +33,7 @@
#include <boost/log/trivial.hpp>
#include <boost/nowide/cstdio.hpp>
#include "I18N.hpp"
#include "GUI.hpp"
namespace Slic3r {
@ -92,7 +93,15 @@ void BackgroundSlicingProcess::process_fff()
#else
m_fff_print->export_gcode(m_temp_output_path, m_gcode_preview_data);
#endif // ENABLE_THUMBNAIL_GENERATOR
if (this->set_step_started(bspsGCodeFinalize)) {
if (m_fff_print->model().custom_gcode_per_height != GUI::wxGetApp().model().custom_gcode_per_height) {
GUI::wxGetApp().model().custom_gcode_per_height = m_fff_print->model().custom_gcode_per_height;
// #ys_FIXME : controll text
GUI::show_info(nullptr, _(L("To except of redundant tool manipulation, \n"
"Color change(s) for unused extruder(s) was(were) deleted")), _(L("Info")));
}
if (this->set_step_started(bspsGCodeFinalize)) {
if (! m_export_path.empty()) {
//FIXME localize the messages
// Perform the final post-processing of the export path by applying the print statistics over the file name.
@ -108,7 +117,7 @@ void BackgroundSlicingProcess::process_fff()
m_print->set_status(100, _utf8(L("Slicing complete")));
}
this->set_step_done(bspsGCodeFinalize);
}
}
}
#if ENABLE_THUMBNAIL_GENERATOR
@ -139,8 +148,8 @@ void BackgroundSlicingProcess::process_sla()
if (m_thumbnail_cb != nullptr)
{
ThumbnailsList thumbnails;
m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, true, false);
// m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, false, false); // renders also supports and pad
m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, true, true);
// m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, false, true); // renders also supports and pad
for (const ThumbnailData& data : thumbnails)
{
if (data.is_valid())
@ -464,8 +473,8 @@ void BackgroundSlicingProcess::prepare_upload()
if (m_thumbnail_cb != nullptr)
{
ThumbnailsList thumbnails;
m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, true, false);
// m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, false, false); // renders also supports and pad
m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, true, true);
// m_thumbnail_cb(thumbnails, current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, false, true); // renders also supports and pad
for (const ThumbnailData& data : thumbnails)
{
if (data.is_valid())

View file

@ -132,6 +132,11 @@ public:
// This "finished" flag does not account for the final export of the output file (.gcode or zipped PNGs),
// and it does not account for the OctoPrint scheduling.
bool finished() const { return m_print->finished(); }
void set_force_update_print_regions(bool force_update_print_regions) {
if (m_fff_print)
m_fff_print->set_force_update_print_regions(force_update_print_regions);
}
private:
void thread_proc();

View file

@ -0,0 +1,235 @@
#include "ExtruderSequenceDialog.hpp"
#include <wx/wx.h>
#include <wx/stattext.h>
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/bmpcbox.h>
#include <vector>
#include <set>
#include <functional>
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "I18N.hpp"
#include "OptionsGroup.hpp"
namespace Slic3r {
namespace GUI {
ExtruderSequenceDialog::ExtruderSequenceDialog(const DoubleSlider::ExtrudersSequence& sequence)
: DPIDialog(NULL, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _(L("Set extruder sequence")),
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
m_sequence(sequence)
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
SetDoubleBuffered(true);
SetFont(wxGetApp().normal_font());
auto main_sizer = new wxBoxSizer(wxVERTICAL);
const int em = wxGetApp().em_unit();
m_bmp_del = ScalableBitmap(this, "remove_copies");
m_bmp_add = ScalableBitmap(this, "add_copies");
auto option_sizer = new wxBoxSizer(wxVERTICAL);
auto intervals_box = new wxStaticBox(this, wxID_ANY, _(L("Set extruder change for every"))+ " : ");
auto intervals_box_sizer = new wxStaticBoxSizer(intervals_box, wxVERTICAL);
m_intervals_grid_sizer = new wxFlexGridSizer(3, 5, em);
auto editor_sz = wxSize(4*em, wxDefaultCoord);
auto ID_RADIO_BUTTON = wxWindow::NewControlId(1);
wxRadioButton* rb_by_layers = new wxRadioButton(this, ID_RADIO_BUTTON, "", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
rb_by_layers->Bind(wxEVT_RADIOBUTTON, [this](wxCommandEvent& event) { m_sequence.is_mm_intervals = false; });
rb_by_layers->SetValue(!m_sequence.is_mm_intervals);
wxStaticText* st_by_layers = new wxStaticText(this, wxID_ANY, _(L("layers")));
m_interval_by_layers = new wxTextCtrl(this, wxID_ANY,
wxString::Format("%d", m_sequence.interval_by_layers),
wxDefaultPosition, editor_sz);
m_interval_by_layers->Bind(wxEVT_TEXT, [this, rb_by_layers](wxEvent&)
{
wxString str = m_interval_by_layers->GetValue();
if (str.IsEmpty()) {
m_interval_by_layers->SetValue(wxString::Format("%d", m_sequence.interval_by_layers));
return;
}
int val = wxAtoi(str);
if (val < 1) {
m_interval_by_layers->SetValue("1");
val = 1;
}
if (m_sequence.interval_by_layers == val)
return;
m_sequence.interval_by_layers = val;
m_sequence.is_mm_intervals = false;
rb_by_layers->SetValue(true);
});
m_intervals_grid_sizer->Add(rb_by_layers, 0, wxALIGN_CENTER_VERTICAL);
m_intervals_grid_sizer->Add(m_interval_by_layers,0, wxALIGN_CENTER_VERTICAL);
m_intervals_grid_sizer->Add(st_by_layers,0, wxALIGN_CENTER_VERTICAL);
wxRadioButton* rb_by_mm = new wxRadioButton(this, ID_RADIO_BUTTON, "");
rb_by_mm->Bind(wxEVT_RADIOBUTTON, [this](wxEvent&) { m_sequence.is_mm_intervals = true; });
rb_by_mm->SetValue(m_sequence.is_mm_intervals);
wxStaticText* st_by_mm = new wxStaticText(this, wxID_ANY, _(L("mm")));
m_interval_by_mm = new wxTextCtrl(this, wxID_ANY,
double_to_string(sequence.interval_by_mm),
wxDefaultPosition, editor_sz, wxTE_PROCESS_ENTER);
auto change_value = [this]()
{
wxString str = m_interval_by_mm->GetValue();
if (str.IsEmpty()) {
m_interval_by_mm->SetValue(wxString::Format("%d", m_sequence.interval_by_mm));
return;
}
str.Replace(",", ".", false);
double val;
if (str == "." || !str.ToCDouble(&val) || val <= 0.0)
val = 3.0; // default value
if (fabs(m_sequence.interval_by_layers - val) < 0.001)
return;
m_sequence.interval_by_mm = val;
};
m_interval_by_mm->Bind(wxEVT_TEXT, [this, rb_by_mm](wxEvent&)
{
m_sequence.is_mm_intervals = true;
rb_by_mm->SetValue(true);
});
m_interval_by_mm->Bind(wxEVT_KILL_FOCUS, [this, change_value](wxFocusEvent& event)
{
change_value();
event.Skip();
});
m_interval_by_mm->Bind(wxEVT_TEXT_ENTER, [this, change_value](wxEvent&)
{
change_value();
});
m_intervals_grid_sizer->Add(rb_by_mm, 0, wxALIGN_CENTER_VERTICAL);
m_intervals_grid_sizer->Add(m_interval_by_mm,0, wxALIGN_CENTER_VERTICAL);
m_intervals_grid_sizer->Add(st_by_mm,0, wxALIGN_CENTER_VERTICAL);
intervals_box_sizer->Add(m_intervals_grid_sizer, 0, wxLEFT, em);
option_sizer->Add(intervals_box_sizer, 0, wxEXPAND);
auto extruders_box = new wxStaticBox(this, wxID_ANY, _(L("Set extruder(tool) sequence"))+ " : ");
auto extruders_box_sizer = new wxStaticBoxSizer(extruders_box, wxVERTICAL);
m_extruders_grid_sizer = new wxFlexGridSizer(3, 5, em);
apply_extruder_sequence();
extruders_box_sizer->Add(m_extruders_grid_sizer, 0, wxALL, em);
option_sizer->Add(extruders_box_sizer, 0, wxEXPAND | wxTOP, em);
main_sizer->Add(option_sizer, 0, wxEXPAND | wxALL, em);
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
main_sizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, em);
SetSizer(main_sizer);
main_sizer->SetSizeHints(this);
/* For this moment min sizes for dialog and its sizer are calculated.
* If we left them, it can cause a problem with layouts during deleting of extruders
*/
if (m_sequence.extruders.size()>1)
{
wxSize sz = wxSize(-1, 10 * em);
SetMinSize(sz);
GetSizer()->SetMinSize(sz);
}
}
void ExtruderSequenceDialog::apply_extruder_sequence()
{
m_extruders_grid_sizer->Clear(true);
for (size_t extruder=0; extruder < m_sequence.extruders.size(); ++extruder)
{
wxBitmapComboBox* extruder_selector = nullptr;
apply_extruder_selector(&extruder_selector, this, "", wxDefaultPosition, wxSize(15*wxGetApp().em_unit(), -1));
extruder_selector->SetSelection(m_sequence.extruders[extruder]);
extruder_selector->Bind(wxEVT_COMBOBOX, [this, extruder_selector, extruder](wxCommandEvent& evt)
{
m_sequence.extruders[extruder] = extruder_selector->GetSelection();
evt.StopPropagation();
});
auto del_btn = new ScalableButton(this, wxID_ANY, m_bmp_del);
del_btn->SetToolTip(_(L("Remove extruder from sequence")));
if (m_sequence.extruders.size()==1)
del_btn->Disable();
del_btn->Bind(wxEVT_BUTTON, [this, extruder](wxEvent&) {
m_sequence.delete_extruder(extruder);
apply_extruder_sequence();
});
auto add_btn = new ScalableButton(this, wxID_ANY, m_bmp_add);
add_btn->SetToolTip(_(L("Add extruder to sequence")));
add_btn->Bind(wxEVT_BUTTON, [this, extruder](wxEvent&) {
m_sequence.add_extruder(extruder);
apply_extruder_sequence();
});
m_extruders_grid_sizer->Add(extruder_selector, 0, wxALIGN_CENTER_VERTICAL);
m_extruders_grid_sizer->Add(del_btn, 0, wxALIGN_CENTER_VERTICAL);
m_extruders_grid_sizer->Add(add_btn, 0, wxALIGN_CENTER_VERTICAL);
}
m_extruders_grid_sizer->ShowItems(true); // show items hidden in apply_extruder_selector()
Fit();
Refresh();
}
void ExtruderSequenceDialog::on_dpi_changed(const wxRect& suggested_rect)
{
SetFont(wxGetApp().normal_font());
m_bmp_add.msw_rescale();
m_bmp_del.msw_rescale();
const int em = em_unit();
m_intervals_grid_sizer->SetHGap(em);
m_intervals_grid_sizer->SetVGap(em);
m_extruders_grid_sizer->SetHGap(em);
m_extruders_grid_sizer->SetVGap(em);
msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL });
// wxSize size = get_size();
// SetMinSize(size);
Fit();
Refresh();
}
}
}

View file

@ -0,0 +1,45 @@
#ifndef slic3r_GUI_ExtruderSequenceDialog_hpp_
#define slic3r_GUI_ExtruderSequenceDialog_hpp_
#include "GUI_Utils.hpp"
#include "wxExtensions.hpp"
class wxTextCtrl;
class wxFlexGridSizer;
namespace Slic3r {
namespace GUI {
// ----------------------------------------------------------------------------
// ExtruderSequenceDialog: a node inside ObjectDataViewModel
// ----------------------------------------------------------------------------
class ExtruderSequenceDialog: public DPIDialog
{
ScalableBitmap m_bmp_del;
ScalableBitmap m_bmp_add;
DoubleSlider::ExtrudersSequence m_sequence;
wxTextCtrl* m_interval_by_layers {nullptr};
wxTextCtrl* m_interval_by_mm {nullptr};
wxFlexGridSizer* m_intervals_grid_sizer {nullptr};
wxFlexGridSizer* m_extruders_grid_sizer {nullptr};
public:
ExtruderSequenceDialog(const DoubleSlider::ExtrudersSequence& sequence);
~ExtruderSequenceDialog() {}
DoubleSlider::ExtrudersSequence GetValue() { return m_sequence; }
protected:
void apply_extruder_sequence();
void on_dpi_changed(const wxRect& suggested_rect) override;
};
}
}
#endif // slic3r_GUI_ExtruderSequenceDialog_hpp_

View file

@ -22,6 +22,7 @@
#include "slic3r/GUI/PresetBundle.hpp"
#include "slic3r/GUI/Tab.hpp"
#include "slic3r/GUI/GUI_Preview.hpp"
#include "GUI_App.hpp"
#include "GUI_ObjectList.hpp"
#include "GUI_ObjectManipulation.hpp"
@ -277,9 +278,9 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const
imgui.text(_(L("Cusp (mm)")));
ImGui::SameLine();
float widget_align = ImGui::GetCursorPosX();
ImGui::PushItemWidth(120.0f);
m_adaptive_cusp = std::min(m_adaptive_cusp, (float)m_slicing_parameters->max_layer_height);
ImGui::SliderFloat("", &m_adaptive_cusp, 0.0f, (float)m_slicing_parameters->max_layer_height, "%.2f");
ImGui::PushItemWidth(imgui.get_style_scaling() * 120.0f);
m_adaptive_cusp = clamp((float)m_slicing_parameters->min_layer_height, (float)m_slicing_parameters->max_layer_height, m_adaptive_cusp);
ImGui::SliderFloat("", &m_adaptive_cusp, (float)m_slicing_parameters->min_layer_height, (float)m_slicing_parameters->max_layer_height, "%.2f");
ImGui::Separator();
if (imgui.button(_(L("Smooth"))))
@ -289,8 +290,8 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const
ImGui::SetCursorPosX(text_align);
imgui.text(_(L("Radius")));
ImGui::SameLine();
ImGui::PushItemWidth(120.0f);
ImGui::SetCursorPosX(widget_align);
ImGui::PushItemWidth(imgui.get_style_scaling() * 120.0f);
int radius = (int)m_smooth_params.radius;
if (ImGui::SliderInt("##1", &radius, 1, 10))
m_smooth_params.radius = (unsigned int)radius;
@ -298,8 +299,8 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const
ImGui::SetCursorPosX(text_align);
imgui.text(_(L("Keep min")));
ImGui::SameLine();
ImGui::PushItemWidth(120.0f);
ImGui::SetCursorPosX(widget_align);
ImGui::PushItemWidth(imgui.get_style_scaling() * 120.0f);
imgui.checkbox("##2", m_smooth_params.keep_min);
ImGui::Separator();
@ -411,6 +412,35 @@ bool GLCanvas3D::LayersEditing::is_initialized() const
return m_shader.is_initialized();
}
std::string GLCanvas3D::LayersEditing::get_tooltip(const GLCanvas3D& canvas) const
{
std::string ret;
if (m_enabled && (m_layer_height_profile.size() >= 4))
{
float z = get_cursor_z_relative(canvas);
if (z != -1000.0f)
{
z *= m_object_max_z;
float h = 0.0f;
for (size_t i = m_layer_height_profile.size() - 2; i >= 2; i -= 2)
{
float zi = m_layer_height_profile[i];
float zi_1 = m_layer_height_profile[i - 2];
if ((zi_1 <= z) && (z <= zi))
{
float dz = zi - zi_1;
h = (dz != 0.0f) ? lerp(m_layer_height_profile[i - 1], m_layer_height_profile[i + 1], (z - zi_1) / dz) : m_layer_height_profile[i + 1];
break;
}
}
if (h > 0.0f)
ret = std::to_string(h);
}
}
return ret;
}
#if !ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
void GLCanvas3D::LayersEditing::_render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const
{
@ -659,7 +689,7 @@ void GLCanvas3D::LayersEditing::accept_changes(GLCanvas3D& canvas)
{
if (last_object_id >= 0) {
if (m_layer_height_profile_modified) {
wxGetApp().plater()->take_snapshot(_(L("Layers heights")));
wxGetApp().plater()->take_snapshot(_(L("Layer height profile-Manual edit")));
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
canvas.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
}
@ -967,47 +997,125 @@ GLCanvas3D::LegendTexture::LegendTexture()
{
}
void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas,
std::vector<std::pair<double, double>>& cp_legend_values)
void GLCanvas3D::LegendTexture::fill_color_print_legend_items( const GLCanvas3D& canvas,
const std::vector<float>& colors_in,
std::vector<float>& colors,
std::vector<std::string>& cp_legend_items)
{
if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint &&
wxGetApp().extruders_edited_cnt() == 1) // show color change legend only for single-material presets
std::vector<Model::CustomGCode> custom_gcode_per_height = wxGetApp().plater()->model().custom_gcode_per_height;
const int extruders_cnt = wxGetApp().extruders_edited_cnt();
if (extruders_cnt == 1)
{
auto& config = wxGetApp().preset_bundle->project_config;
const std::vector<double>& color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
if (!color_print_values.empty()) {
std::vector<double> print_zs = canvas.get_current_print_zs(true);
for (auto cp_value : color_print_values)
{
auto lower_b = std::lower_bound(print_zs.begin(), print_zs.end(), cp_value - DoubleSlider::epsilon());
if (lower_b == print_zs.end())
continue;
double current_z = *lower_b;
double previous_z = lower_b == print_zs.begin() ? 0.0 : *(--lower_b);
// to avoid duplicate values, check adding values
if (cp_legend_values.empty() ||
!(cp_legend_values.back().first == previous_z && cp_legend_values.back().second == current_z) )
cp_legend_values.push_back(std::pair<double, double>(previous_z, current_z));
}
if (custom_gcode_per_height.empty()) {
cp_legend_items.push_back(I18N::translate_utf8(L("Default print color")));
colors = colors_in;
return;
}
std::vector<std::pair<double, double>> cp_values;
std::vector<double> print_zs = canvas.get_current_print_zs(true);
for (auto custom_code : custom_gcode_per_height)
{
if (custom_code.gcode != ColorChangeCode)
continue;
auto lower_b = std::lower_bound(print_zs.begin(), print_zs.end(), custom_code.height - DoubleSlider::epsilon());
if (lower_b == print_zs.end())
continue;
double current_z = *lower_b;
double previous_z = lower_b == print_zs.begin() ? 0.0 : *(--lower_b);
// to avoid duplicate values, check adding values
if (cp_values.empty() ||
!(cp_values.back().first == previous_z && cp_values.back().second == current_z))
cp_values.push_back(std::pair<double, double>(previous_z, current_z));
}
const auto items_cnt = (int)cp_values.size();
if (items_cnt == 0) // There is no one color change, but there is/are some pause print or custom Gcode
{
cp_legend_items.push_back(I18N::translate_utf8(L("Default print color")));
cp_legend_items.push_back(I18N::translate_utf8(L("Pause print or custom G-code")));
colors = colors_in;
return;
}
const int color_cnt = (int)colors_in.size() / 4;
colors.resize(colors_in.size(), 0.0);
::memcpy((void*)(colors.data()), (const void*)(colors_in.data() + (color_cnt - 1) * 4), 4 * sizeof(float));
cp_legend_items.push_back(I18N::translate_utf8(L("Pause print or custom G-code")));
size_t color_pos = 4;
for (int i = items_cnt; i >= 0; --i, color_pos+=4)
{
// update colors for color print item
::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + i * 4), 4 * sizeof(float));
// create label for color print item
std::string id_str = std::to_string(i + 1) + ": ";
if (i == 0) {
cp_legend_items.push_back(id_str + (boost::format(I18N::translate_utf8(L("up to %.2f mm"))) % cp_values[0].first).str());
break;
}
if (i == items_cnt) {
cp_legend_items.push_back(id_str + (boost::format(I18N::translate_utf8(L("above %.2f mm"))) % cp_values[i - 1].second).str());
continue;
}
cp_legend_items.push_back(id_str + (boost::format(I18N::translate_utf8(L("%.2f - %.2f mm"))) % cp_values[i - 1].second % cp_values[i].first).str());
}
}
else
{
// colors = colors_in;
const int color_cnt = (int)colors_in.size() / 4;
colors.resize(colors_in.size(), 0.0);
::memcpy((void*)(colors.data()), (const void*)(colors_in.data()), 4 * extruders_cnt * sizeof(float));
size_t color_pos = 4 * extruders_cnt;
size_t color_in_pos = 4 * (color_cnt - 1);
for (unsigned int i = 0; i < extruders_cnt; ++i)
cp_legend_items.push_back((boost::format(I18N::translate_utf8(L("Extruder %d"))) % (i + 1)).str());
::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + color_in_pos), 4 * sizeof(float));
color_pos += 4;
color_in_pos -= 4;
cp_legend_items.push_back(I18N::translate_utf8(L("Pause print or custom G-code")));
int cnt = custom_gcode_per_height.size();
for (int i = cnt-1; i >= 0; --i)
if (custom_gcode_per_height[i].gcode == ColorChangeCode) {
::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + color_in_pos), 4 * sizeof(float));
color_pos += 4;
color_in_pos -= 4;
cp_legend_items.push_back((boost::format(I18N::translate_utf8(L("Color change for Extruder %d at %.2f mm"))) % custom_gcode_per_height[i].extruder % custom_gcode_per_height[i].height).str());
}
}
}
bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool compress)
bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors_in, const GLCanvas3D& canvas, bool compress)
{
reset();
// collects items to render
auto title = _(preview_data.get_legend_title());
std::vector<std::pair<double, double>> cp_legend_values;
fill_color_print_legend_values(preview_data, canvas, cp_legend_values);
std::vector<std::string> cp_legend_items;
std::vector<float> cp_colors;
const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, cp_legend_values);
if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
{
cp_legend_items.reserve(cp_colors.size());
fill_color_print_legend_items(canvas, tool_colors_in, cp_colors, cp_legend_items);
}
const std::vector<float>& tool_colors = preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint ? cp_colors : tool_colors_in;
const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, cp_legend_items);
unsigned int items_count = (unsigned int)items.size();
if (items_count == 0)
@ -1559,6 +1667,7 @@ bool GLCanvas3D::is_layers_editing_allowed() const
#if ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
void GLCanvas3D::reset_layer_height_profile()
{
wxGetApp().plater()->take_snapshot(_(L("Layer height profile-Reset")));
m_layers_editing.reset_layer_height_profile(*this);
m_layers_editing.state = LayersEditing::Completed;
m_dirty = true;
@ -1566,6 +1675,7 @@ void GLCanvas3D::reset_layer_height_profile()
void GLCanvas3D::adaptive_layer_height_profile(float cusp)
{
wxGetApp().plater()->take_snapshot(_(L("Layer height profile-Adaptive")));
m_layers_editing.adaptive_layer_height_profile(*this, cusp);
m_layers_editing.state = LayersEditing::Completed;
m_dirty = true;
@ -1573,6 +1683,7 @@ void GLCanvas3D::adaptive_layer_height_profile(float cusp)
void GLCanvas3D::smooth_layer_height_profile(const HeightProfileSmoothingParams& smoothing_params)
{
wxGetApp().plater()->take_snapshot(_(L("Layer height profile-Smooth all")));
m_layers_editing.smooth_layer_height_profile(*this, smoothing_params);
m_layers_editing.state = LayersEditing::Completed;
m_dirty = true;
@ -2408,7 +2519,7 @@ void GLCanvas3D::load_sla_preview()
}
}
void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values)
void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<Model::CustomGCode>& color_print_values)
{
const Print *print = this->fff_print();
if (print == nullptr)
@ -3136,6 +3247,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if ((m_layers_editing.state != LayersEditing::Unknown) && (layer_editing_object_idx != -1))
{
set_tooltip("");
if (m_layers_editing.state == LayersEditing::Editing)
_perform_layer_editing_action(&evt);
}
@ -3245,6 +3357,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_mouse.position = pos.cast<double>();
std::string tooltip = "";
if (tooltip.empty())
tooltip = m_layers_editing.get_tooltip(*this);
if (tooltip.empty())
tooltip = m_gizmos.get_tooltip();
@ -3810,7 +3925,7 @@ static void render_volumes_in_thumbnail(Shader& shader, const GLVolumePtrs& volu
camera.apply_projection(box);
if (transparent_background)
glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 0.0f));
glsafe(::glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
glsafe(::glEnable(GL_DEPTH_TEST));
@ -5210,7 +5325,7 @@ void GLCanvas3D::_load_print_toolpaths()
volume->indexed_vertex_array.finalize_geometry(m_initialized);
}
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values)
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<Model::CustomGCode>& color_print_values)
{
std::vector<float> tool_colors = _parse_colors(str_tool_colors);
@ -5222,11 +5337,14 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
bool has_infill;
bool has_support;
const std::vector<float>* tool_colors;
const std::vector<double>* color_print_values;
bool is_single_material_print;
int extruders_cnt;
const std::vector<Model::CustomGCode>* color_print_values;
static const float* color_perimeters() { static float color[4] = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow
static const float* color_infill() { static float color[4] = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish
static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
static const float* color_pause_or_custom_code() { static float color[4] = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray
// For cloring by a tool, return a parsed color.
bool color_by_tool() const { return tool_colors != nullptr; }
@ -5236,9 +5354,106 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
// For coloring by a color_print(M600), return a parsed color.
bool color_by_color_print() const { return color_print_values!=nullptr; }
const size_t color_print_color_idx_by_layer_idx(const size_t layer_idx) const {
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z + EPSILON);
const Model::CustomGCode value(layers[layer_idx]->print_z + EPSILON, "", 0, "");
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value);
return (it - color_print_values->begin()) % number_tools();
}
const size_t color_print_color_idx_by_layer_idx_and_extruder(const size_t layer_idx, const int extruder) const
{
const coordf_t print_z = layers[layer_idx]->print_z;
auto it = std::find_if(color_print_values->begin(), color_print_values->end(),
[print_z](const Model::CustomGCode& code)
{ return fabs(code.height - print_z) < EPSILON; });
if (it != color_print_values->end())
{
const std::string& code = it->gcode;
// pause print or custom Gcode
if (code == PausePrintCode ||
(code != ColorChangeCode && code != ExtruderChangeCode))
return number_tools()-1; // last color item is a gray color for pause print or custom G-code
// change tool (extruder)
if (code == ExtruderChangeCode)
return get_color_idx_for_tool_change(it, extruder);
// change color for current extruder
if (code == ColorChangeCode) {
int color_idx = get_color_idx_for_color_change(it, extruder);
if (color_idx >= 0)
return color_idx;
}
}
const Model::CustomGCode value(print_z + EPSILON, "", 0, "");
it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value);
while (it != color_print_values->begin())
{
--it;
// change color for current extruder
if (it->gcode == ColorChangeCode) {
int color_idx = get_color_idx_for_color_change(it, extruder);
if (color_idx >= 0)
return color_idx;
}
// change tool (extruder)
if (it->gcode == ExtruderChangeCode)
return get_color_idx_for_tool_change(it, extruder);
}
return std::min<int>(extruders_cnt - 1, std::max<int>(extruder - 1, 0));;
}
private:
int get_m600_color_idx(std::vector<Model::CustomGCode>::const_iterator it) const
{
int shift = 0;
while (it != color_print_values->begin()) {
--it;
if (it->gcode == ColorChangeCode)
shift++;
}
return extruders_cnt + shift;
}
int get_color_idx_for_tool_change(std::vector<Model::CustomGCode>::const_iterator it, const int extruder) const
{
const int current_extruder = it->extruder == 0 ? extruder : it->extruder;
if (number_tools() == extruders_cnt + 1) // there is no one "M600"
return std::min<int>(extruders_cnt - 1, std::max<int>(current_extruder - 1, 0));
auto it_n = it;
while (it_n != color_print_values->begin()) {
--it_n;
if (it_n->gcode == ColorChangeCode && it_n->extruder == current_extruder)
return get_m600_color_idx(it_n);
}
return std::min<int>(extruders_cnt - 1, std::max<int>(current_extruder - 1, 0));
}
int get_color_idx_for_color_change(std::vector<Model::CustomGCode>::const_iterator it, const int extruder) const
{
if (extruders_cnt == 1)
return get_m600_color_idx(it);
auto it_n = it;
bool is_tool_change = false;
while (it_n != color_print_values->begin()) {
--it_n;
if (it_n->gcode == ExtruderChangeCode) {
is_tool_change = true;
if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder))
return get_m600_color_idx(it);
break;
}
}
if (!is_tool_change && it->extruder == extruder)
return get_m600_color_idx(it);
return -1;
}
} ctxt;
ctxt.has_perimeters = print_object.is_step_done(posPerimeters);
@ -5246,6 +5461,8 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
ctxt.has_support = print_object.is_step_done(posSupportMaterial);
ctxt.tool_colors = tool_colors.empty() ? nullptr : &tool_colors;
ctxt.color_print_values = color_print_values.empty() ? nullptr : &color_print_values;
ctxt.is_single_material_print = this->fff_print()->extruders().size()==1;
ctxt.extruders_cnt = wxGetApp().extruders_edited_cnt();
ctxt.shifted_copies = &print_object.copies();
@ -5269,6 +5486,8 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
// Maximum size of an allocation block: 32MB / sizeof(float)
BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - start" << m_volumes.log_memory_info() << log_memory_info();
const bool is_selected_separate_extruder = m_selected_extruder > 0 && ctxt.color_by_color_print();
//FIXME Improve the heuristics for a grain size.
size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1));
tbb::spin_mutex new_volume_mutex;
@ -5286,32 +5505,18 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
const size_t volumes_cnt_initial = m_volumes.volumes.size();
tbb::parallel_for(
tbb::blocked_range<size_t>(0, ctxt.layers.size(), grain_size),
[&ctxt, &new_volume](const tbb::blocked_range<size_t>& range) {
[&ctxt, &new_volume, is_selected_separate_extruder, this](const tbb::blocked_range<size_t>& range) {
GLVolumePtrs vols;
std::vector<size_t> color_print_layer_to_glvolume;
auto volume = [&ctxt, &vols, &color_print_layer_to_glvolume, &range](size_t layer_idx, int extruder, int feature) -> GLVolume& {
return *vols[ctxt.color_by_color_print() ?
color_print_layer_to_glvolume[layer_idx - range.begin()] :
auto volume = [&ctxt, &vols, &color_print_layer_to_glvolume, &range](size_t layer_idx, int extruder, int feature) -> GLVolume& {
return *vols[ctxt.color_by_color_print()?
ctxt.color_print_color_idx_by_layer_idx_and_extruder(layer_idx, extruder) :
ctxt.color_by_tool() ?
std::min<int>(ctxt.number_tools() - 1, std::max<int>(extruder - 1, 0)) :
feature
];
};
if (ctxt.color_by_color_print()) {
// Create a map from the layer index to a GLVolume, which is initialized with the correct layer span color.
std::vector<int> color_print_tool_to_glvolume(ctxt.number_tools(), -1);
color_print_layer_to_glvolume.reserve(range.end() - range.begin());
vols.reserve(ctxt.number_tools());
for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++ idx_layer) {
int idx_tool = (int)ctxt.color_print_color_idx_by_layer_idx(idx_layer);
if (color_print_tool_to_glvolume[idx_tool] == -1) {
color_print_tool_to_glvolume[idx_tool] = (int)vols.size();
vols.emplace_back(new_volume(ctxt.color_tool(idx_tool)));
}
color_print_layer_to_glvolume.emplace_back(color_print_tool_to_glvolume[idx_tool]);
}
}
else if (ctxt.color_by_tool()) {
if (ctxt.color_by_color_print() || ctxt.color_by_tool()) {
for (size_t i = 0; i < ctxt.number_tools(); ++i)
vols.emplace_back(new_volume(ctxt.color_tool(i)));
}
@ -5322,6 +5527,26 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
vol->indexed_vertex_array.reserve(VERTEX_BUFFER_RESERVE_SIZE / 6);
for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++ idx_layer) {
const Layer *layer = ctxt.layers[idx_layer];
if (is_selected_separate_extruder)
{
bool at_least_one_has_correct_extruder = false;
for (const LayerRegion* layerm : layer->regions())
{
if (layerm->slices.surfaces.empty())
continue;
const PrintRegionConfig& cfg = layerm->region()->config();
if (cfg.perimeter_extruder.value == m_selected_extruder ||
cfg.infill_extruder.value == m_selected_extruder ||
cfg.solid_infill_extruder.value == m_selected_extruder ) {
at_least_one_has_correct_extruder = true;
break;
}
}
if (!at_least_one_has_correct_extruder)
continue;
}
for (GLVolume *vol : vols)
if (vol->print_zs.empty() || vol->print_zs.back() != layer->print_z) {
vol->print_zs.push_back(layer->print_z);
@ -5330,6 +5555,14 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
}
for (const Point &copy : *ctxt.shifted_copies) {
for (const LayerRegion *layerm : layer->regions()) {
if (is_selected_separate_extruder)
{
const PrintRegionConfig& cfg = layerm->region()->config();
if (cfg.perimeter_extruder.value != m_selected_extruder ||
cfg.infill_extruder.value != m_selected_extruder ||
cfg.solid_infill_extruder.value != m_selected_extruder)
continue;
}
if (ctxt.has_perimeters)
_3DScene::extrusionentity_to_verts(layerm->perimeters, float(layer->print_z), copy,
volume(idx_layer, layerm->region()->config().perimeter_extruder.value, 0));
@ -5613,11 +5846,8 @@ void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_dat
case GCodePreviewData::Extrusion::ColorPrint:
{
int color_cnt = (int)tool_colors.size() / 4;
int val = value > color_cnt ? color_cnt - 1 : value;
int val = int(value);
while (val >= color_cnt)
val -= color_cnt;
GCodePreviewData::Color color;
::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + val * 4), 4 * sizeof(float));
@ -5678,10 +5908,13 @@ void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_dat
BOOST_LOG_TRIVIAL(debug) << "Loading G-code extrusion paths - populate volumes" << m_volumes.log_memory_info() << log_memory_info();
// populates volumes
const bool is_selected_separate_extruder = m_selected_extruder > 0 && preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint;
for (const GCodePreviewData::Extrusion::Layer& layer : preview_data.extrusion.layers)
{
for (const GCodePreviewData::Extrusion::Path& path : layer.paths)
{
if (is_selected_separate_extruder && path.extruder_id != m_selected_extruder - 1)
continue;
std::vector<std::pair<float, GLVolume*>> &filters = roles_filters[size_t(path.extrusion_role)];
auto key = std::make_pair<float, GLVolume*>(Helper::path_filter(preview_data.extrusion.view_type, path), nullptr);
auto it_filter = std::lower_bound(filters.begin(), filters.end(), key);

View file

@ -179,7 +179,7 @@ private:
float m_object_max_z;
// Owned by LayersEditing.
SlicingParameters *m_slicing_parameters;
std::vector<coordf_t> m_layer_height_profile;
std::vector<double> m_layer_height_profile;
bool m_layer_height_profile_modified;
#if ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
@ -254,6 +254,8 @@ private:
float object_max_z() const { return m_object_max_z; }
std::string get_tooltip(const GLCanvas3D& canvas) const;
private:
bool is_initialized() const;
void generate_layer_height_texture();
@ -382,8 +384,10 @@ private:
public:
LegendTexture();
void fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas,
std::vector<std::pair<double, double>>& cp_legend_values);
void fill_color_print_legend_items(const GLCanvas3D& canvas,
const std::vector<float>& colors_in,
std::vector<float>& colors,
std::vector<std::string>& cp_legend_items);
bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool compress);
@ -473,6 +477,7 @@ private:
#endif // ENABLE_RENDER_STATISTICS
int m_imgui_undo_redo_hovered_pos{ -1 };
int m_selected_extruder;
public:
GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);
@ -586,7 +591,7 @@ public:
void load_gcode_preview(const GCodePreviewData& preview_data, const std::vector<std::string>& str_tool_colors);
void load_sla_preview();
void load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values);
void load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<Model::CustomGCode>& color_print_values);
void bind_event_handlers();
void unbind_event_handlers();
@ -625,6 +630,7 @@ public:
int get_move_volume_id() const { return m_mouse.drag.move_volume_idx; }
int get_first_hover_volume_idx() const { return m_hover_volume_idxs.empty() ? -1 : m_hover_volume_idxs.front(); }
void set_selected_extruder(int extruder) { m_selected_extruder = extruder;}
class WipeTowerInfo {
protected:
@ -748,7 +754,7 @@ private:
// Adds a new Slic3r::GUI::3DScene::Volume to $self->volumes,
// one for perimeters, one for infill and one for supports.
void _load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors,
const std::vector<double>& color_print_values);
const std::vector<Model::CustomGCode>& color_print_values);
// Create 3D thick extrusion lines for wipe tower extrusions
void _load_wipe_tower_toolpaths(const std::vector<std::string>& str_tool_colors);

View file

@ -895,10 +895,6 @@ void ObjectList::extruder_editing()
if (!item || !(m_objects_model->GetItemType(item) & (itVolume | itObject)))
return;
std::vector<wxBitmap*> icons = get_extruder_color_icons();
if (icons.empty())
return;
const int column_width = GetColumn(colExtruder)->GetWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X) + 5;
wxPoint pos = get_mouse_position_in_control();
@ -906,29 +902,10 @@ void ObjectList::extruder_editing()
pos.x = GetColumn(colName)->GetWidth() + GetColumn(colPrint)->GetWidth() + 5;
pos.y -= GetTextExtent("m").y;
if (!m_extruder_editor)
m_extruder_editor = new wxBitmapComboBox(this, wxID_ANY, wxEmptyString, pos, size,
0, nullptr, wxCB_READONLY);
else
{
m_extruder_editor->SetPosition(pos);
m_extruder_editor->SetMinSize(size);
m_extruder_editor->SetSize(size);
m_extruder_editor->Clear();
m_extruder_editor->Show();
}
apply_extruder_selector(&m_extruder_editor, this, L("default"), pos, size);
int i = 0;
for (wxBitmap* bmp : icons) {
if (i == 0) {
m_extruder_editor->Append(_(L("default")), *bmp);
++i;
}
m_extruder_editor->Append(wxString::Format("%d", i), *bmp);
++i;
}
m_extruder_editor->SetSelection(m_objects_model->GetExtruderNumber(item));
m_extruder_editor->Show();
auto set_extruder = [this]()
{
@ -940,6 +917,7 @@ void ObjectList::extruder_editing()
m_objects_model->SetExtruder(m_extruder_editor->GetString(selection), item);
m_extruder_editor->Hide();
update_extruder_in_config(item);
};
// to avoid event propagation to other sidebar items
@ -948,13 +926,6 @@ void ObjectList::extruder_editing()
set_extruder();
evt.StopPropagation();
});
/*
m_extruder_editor->Bind(wxEVT_KILL_FOCUS, [set_extruder](wxFocusEvent& evt)
{
set_extruder();
evt.Skip();
});*/
}
void ObjectList::copy()

View file

@ -243,11 +243,13 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
// Add Axes labels with icons
static const char axes[] = { 'X', 'Y', 'Z' };
// std::vector<wxString> axes_color = {"#990000", "#009900","#000099"};
for (size_t axis_idx = 0; axis_idx < sizeof(axes); axis_idx++) {
const char label = axes[axis_idx];
wxStaticText* axis_name = new wxStaticText(m_parent, wxID_ANY, wxString(label));
set_font_and_background_style(axis_name, wxGetApp().bold_font());
// axis_name->SetForegroundColour(wxColour(axes_color[axis_idx]));
sizer = new wxBoxSizer(wxHORIZONTAL);
// Under OSX we use font, smaller than default font, so

View file

@ -492,18 +492,23 @@ void Preview::show_hide_ui_elements(const std::string& what)
m_choice_view_type->Show(visible);
}
void Preview::reset_sliders()
void Preview::reset_sliders(bool reset_all)
{
m_enabled = false;
// reset_double_slider();
m_double_slider_sizer->Hide((size_t)0);
if (reset_all)
m_double_slider_sizer->Hide((size_t)0);
else
m_double_slider_sizer->GetItem(size_t(0))->GetSizer()->Hide(1);
}
void Preview::update_sliders(const std::vector<double>& layers_z, bool keep_z_range)
{
m_enabled = true;
update_double_slider(layers_z, keep_z_range);
m_double_slider_sizer->Show((size_t)0);
Layout();
}
@ -560,12 +565,12 @@ void Preview::on_checkbox_legend(wxCommandEvent& evt)
m_canvas_widget->Refresh();
}
void Preview::update_view_type()
void Preview::update_view_type(bool slice_completed)
{
const DynamicPrintConfig& config = wxGetApp().preset_bundle->project_config;
const wxString& choice = !config.option<ConfigOptionFloats>("colorprint_heights")->values.empty() &&
wxGetApp().extruders_edited_cnt()==1 ?
const wxString& choice = !wxGetApp().plater()->model().custom_gcode_per_height.empty() /*&&
(wxGetApp().extruders_edited_cnt()==1 || !slice_completed) */?
_(L("Color Print")) :
config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values.size() > 1 ?
_(L("Tool")) :
@ -583,6 +588,8 @@ void Preview::update_view_type()
void Preview::create_double_slider()
{
m_slider = new DoubleSlider(this, wxID_ANY, 0, 0, 0, 100);
m_slider->EnableTickManipulation(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptFFF);
m_double_slider_sizer->Add(m_slider, 0, wxEXPAND, 0);
// sizer, m_canvas_widget
@ -592,10 +599,11 @@ void Preview::create_double_slider()
Bind(wxCUSTOMEVT_TICKSCHANGED, [this](wxEvent&) {
wxGetApp().preset_bundle->project_config.option<ConfigOptionFloats>("colorprint_heights")->values = m_slider->GetTicksValues();
Model& model = wxGetApp().plater()->model();
model.custom_gcode_per_height = m_slider->GetTicksValues();
m_schedule_background_process();
update_view_type();
update_view_type(false);
reload_print();
});
@ -628,6 +636,24 @@ static int find_close_layer_idx(const std::vector<double>& zs, double &z, double
return -1;
}
void Preview::check_slider_values(std::vector<Model::CustomGCode>& ticks_from_model,
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(),
[layers_z](Model::CustomGCode val)
{
auto it = std::lower_bound(layers_z.begin(), layers_z.end(), val.height - DoubleSlider::epsilon());
return it == layers_z.end();
}),
ticks_from_model.end());
if (ticks_from_model.size() != old_size)
m_schedule_background_process();
}
void Preview::update_double_slider(const std::vector<double>& layers_z, bool keep_z_range)
{
// Save the initial slider span.
@ -643,8 +669,8 @@ void Preview::update_double_slider(const std::vector<double>& layers_z, bool kee
bool snap_to_min = force_sliders_full_range || m_slider->is_lower_at_min();
bool snap_to_max = force_sliders_full_range || m_slider->is_higher_at_max();
std::vector<double> &ticks_from_config = (wxGetApp().preset_bundle->project_config.option<ConfigOptionFloats>("colorprint_heights"))->values;
check_slider_values(ticks_from_config, layers_z);
std::vector<Model::CustomGCode> &ticks_from_model = wxGetApp().plater()->model().custom_gcode_per_height;
check_slider_values(ticks_from_model, layers_z);
m_slider->SetSliderValues(layers_z);
assert(m_slider->GetMinValue() == 0);
@ -666,33 +692,12 @@ void Preview::update_double_slider(const std::vector<double>& layers_z, bool kee
}
m_slider->SetSelectionSpan(idx_low, idx_high);
m_slider->SetTicksValues(ticks_from_config);
m_slider->SetTicksValues(ticks_from_model);
bool color_print_enable = (wxGetApp().plater()->printer_technology() == ptFFF);
if (color_print_enable) {
const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
if (cfg.opt<ConfigOptionFloats>("nozzle_diameter")->values.size() > 1)
color_print_enable = false;
}
m_slider->EnableTickManipulation(color_print_enable);
}
void Preview::check_slider_values(std::vector<double>& ticks_from_config,
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_config.size();
ticks_from_config.erase(std::remove_if(ticks_from_config.begin(), ticks_from_config.end(),
[layers_z](double val)
{
auto it = std::lower_bound(layers_z.begin(), layers_z.end(), val - DoubleSlider::epsilon());
return it == layers_z.end();
}),
ticks_from_config.end());
if (ticks_from_config.size() != old_size)
m_schedule_background_process();
m_slider->EnableTickManipulation(color_print_enable);
m_slider->SetManipulationState(wxGetApp().extruders_edited_cnt());
}
void Preview::reset_double_slider()
@ -753,7 +758,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
if (! has_layers)
{
reset_sliders();
reset_sliders(true);
m_canvas->reset_legend_texture();
m_canvas_widget->Refresh();
return;
@ -776,51 +781,30 @@ void Preview::load_print_as_fff(bool keep_z_range)
bool gcode_preview_data_valid = print->is_step_done(psGCodeExport) && ! m_gcode_preview_data->empty();
// Collect colors per extruder.
std::vector<std::string> colors;
std::vector<double> color_print_values = {};
std::vector<Model::CustomGCode> color_print_values = {};
// set color print values, if it si selected "ColorPrint" view type
if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
{
colors = GCodePreviewData::ColorPrintColors();
if (! gcode_preview_data_valid) {
//FIXME accessing full_config() is pretty expensive.
// Only initialize color_print_values for the initial preview, not for the full preview where the color_print_values is extracted from the G-code.
const auto& config = wxGetApp().preset_bundle->project_config;
color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
}
colors = wxGetApp().plater()->get_colors_for_color_print();
colors.push_back("#808080"); // gray color for pause print or custom G-code
if (!gcode_preview_data_valid)
color_print_values = wxGetApp().plater()->model().custom_gcode_per_height;
}
else if (gcode_preview_data_valid || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool) )
{
const ConfigOptionStrings* extruders_opt = dynamic_cast<const ConfigOptionStrings*>(m_config->option("extruder_colour"));
const ConfigOptionStrings* filamemts_opt = dynamic_cast<const ConfigOptionStrings*>(m_config->option("filament_colour"));
unsigned int colors_count = std::max((unsigned int)extruders_opt->values.size(), (unsigned int)filamemts_opt->values.size());
unsigned char rgb[3];
for (unsigned int i = 0; i < colors_count; ++i)
{
std::string color = m_config->opt_string("extruder_colour", i);
if (!PresetBundle::parse_color(color, rgb))
{
color = m_config->opt_string("filament_colour", i);
if (!PresetBundle::parse_color(color, rgb))
color = "#FFFFFF";
}
colors.emplace_back(color);
}
colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
color_print_values.clear();
}
if (IsShown())
{
m_canvas->set_selected_extruder(0);
if (gcode_preview_data_valid) {
// Load the real G-code preview.
m_canvas->load_gcode_preview(*m_gcode_preview_data, colors);
m_loaded = true;
} else {
// disable color change information for multi-material presets
if (wxGetApp().extruders_edited_cnt() > 1)
color_print_values.clear();
// Load the initial preview based on slices, not the final G-code.
m_canvas->load_preview(colors, color_print_values);
}
@ -829,7 +813,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
std::vector<double> zs = m_canvas->get_current_print_zs(true);
if (zs.empty()) {
// all layers filtered out
reset_sliders();
reset_sliders(true);
m_canvas_widget->Refresh();
} else
update_sliders(zs, keep_z_range);
@ -860,7 +844,7 @@ void Preview::load_print_as_sla()
n_layers = (unsigned int)zs.size();
if (n_layers == 0)
{
reset_sliders();
reset_sliders(true);
m_canvas_widget->Refresh();
}

View file

@ -5,6 +5,7 @@
#include "libslic3r/Point.hpp"
#include <string>
#include "libslic3r/Model.hpp"
class wxNotebook;
class wxGLCanvas;
@ -12,6 +13,7 @@ class wxBoxSizer;
class wxStaticText;
class wxChoice;
class wxComboCtrl;
class wxBitmapComboBox;
class wxCheckBox;
class DoubleSlider;
@ -101,7 +103,7 @@ class Preview : public wxPanel
bool m_loaded;
bool m_enabled;
DoubleSlider* m_slider {nullptr};
DoubleSlider* m_slider {nullptr};
public:
Preview(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, Model* model, DynamicPrintConfig* config,
@ -128,7 +130,7 @@ public:
void move_double_slider(wxKeyEvent& evt);
void edit_double_slider(wxKeyEvent& evt);
void update_view_type();
void update_view_type(bool slice_completed);
bool is_loaded() const { return m_loaded; }
@ -140,7 +142,7 @@ private:
void show_hide_ui_elements(const std::string& what);
void reset_sliders();
void reset_sliders(bool reset_all);
void update_sliders(const std::vector<double>& layers_z, bool keep_z_range = false);
void on_size(wxSizeEvent& evt);
@ -154,9 +156,9 @@ private:
// Create/Update/Reset double slider on 3dPreview
void create_double_slider();
void check_slider_values(std::vector<Model::CustomGCode> &ticks_from_model,
const std::vector<double> &layers_z);
void update_double_slider(const std::vector<double>& layers_z, bool keep_z_range = false);
void check_slider_values(std::vector<double> &ticks_from_config,
const std::vector<double> &layers_z);
void reset_double_slider();
// update DoubleSlider after keyDown in canvas
void update_double_slider_from_canvas(wxKeyEvent& event);

View file

@ -333,17 +333,16 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign
bool Mouse3DController::connect_device()
{
static const long long DETECTION_TIME = 2; // seconds
static const long long DETECTION_TIME_MS = 2000; // seconds
if (is_device_connected())
return false;
// check time since last detection took place
auto now = std::chrono::high_resolution_clock::now();
if (std::chrono::duration_cast<std::chrono::seconds>(now - m_last_time).count() < DETECTION_TIME)
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - m_last_time).count() < DETECTION_TIME_MS)
return false;
m_last_time = now;
m_last_time = std::chrono::high_resolution_clock::now();
// Enumerates devices
hid_device_info* devices = hid_enumerate(0, 0);

View file

@ -131,7 +131,7 @@ class Mouse3DController
std::string m_device_str;
bool m_running;
bool m_settings_dialog;
std::chrono::time_point<std::chrono::steady_clock> m_last_time;
std::chrono::time_point<std::chrono::high_resolution_clock> m_last_time;
public:
Mouse3DController();

View file

@ -2325,6 +2325,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
// and place the loaded config over the base.
config += std::move(config_loaded);
}
this->model.custom_gcode_per_height = model.custom_gcode_per_height;
}
if (load_config)
@ -2743,8 +2745,7 @@ void Plater::priv::reset()
// The hiding of the slicing results, if shown, is not taken care by the background process, so we do it here
this->sidebar->show_sliced_info_sizer(false);
auto& config = wxGetApp().preset_bundle->project_config;
config.option<ConfigOptionFloats>("colorprint_heights")->values.clear();
model.custom_gcode_per_height.clear();
}
void Plater::priv::mirror(Axis axis)
@ -2975,6 +2976,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
this->update_print_volume_state();
// Apply new config to the possibly running background task.
bool was_running = this->background_process.running();
this->background_process.set_force_update_print_regions(force_validation);
Print::ApplyStatus invalidated = this->background_process.apply(this->q->model(), wxGetApp().preset_bundle->full_config());
// Just redraw the 3D canvas without reloading the scene to consume the update of the layer height profile.
@ -3180,9 +3182,13 @@ void Plater::priv::reload_from_disk()
for (unsigned int idx : selected_volumes_idxs)
{
const GLVolume* v = selection.get_volume(idx);
int o_idx = v->object_idx();
int v_idx = v->volume_idx();
selected_volumes.push_back({ o_idx, v_idx });
if (v_idx >= 0)
{
int o_idx = v->object_idx();
if ((0 <= o_idx) && (o_idx < (int)model.objects.size()))
selected_volumes.push_back({ o_idx, v_idx });
}
}
std::sort(selected_volumes.begin(), selected_volumes.end());
selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end()), selected_volumes.end());
@ -4176,6 +4182,7 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator
// Disable layer editing before the Undo / Redo jump.
if (!new_variable_layer_editing_active && view3D->is_layers_editing_enabled())
view3D->get_canvas3d()->force_main_toolbar_left_action(view3D->get_canvas3d()->get_main_toolbar_item_id("layersediting"));
// Make a copy of the snapshot, undo/redo could invalidate the iterator
const UndoRedo::Snapshot snapshot_copy = *it_snapshot;
// Do the jump in time.
@ -4782,7 +4789,7 @@ void Plater::reslice()
p->show_action_buttons(true);
// update type of preview
p->preview->update_view_type();
p->preview->update_view_type(true);
}
void Plater::reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages)
@ -5061,6 +5068,9 @@ std::vector<std::string> Plater::get_extruder_colors_from_plater_config() const
return extruder_colors;
extruder_colors = (config->option<ConfigOptionStrings>("extruder_colour"))->values;
if (!wxGetApp().plater())
return extruder_colors;
const std::vector<std::string>& filament_colours = (p->config->option<ConfigOptionStrings>("filament_colour"))->values;
for (size_t i = 0; i < extruder_colors.size(); ++i)
if (extruder_colors[i] == "" && i < filament_colours.size())
@ -5069,6 +5079,17 @@ std::vector<std::string> Plater::get_extruder_colors_from_plater_config() const
return extruder_colors;
}
std::vector<std::string> Plater::get_colors_for_color_print() const
{
std::vector<std::string> colors = get_extruder_colors_from_plater_config();
for (const Model::CustomGCode& code : p->model.custom_gcode_per_height)
if (code.gcode == ColorChangeCode)
colors.push_back(code.color);
return colors;
}
wxString Plater::get_project_filename(const wxString& extension) const
{
return p->get_project_filename(extension);

View file

@ -223,6 +223,7 @@ public:
void on_activate();
const DynamicPrintConfig* get_plater_config() const;
std::vector<std::string> get_extruder_colors_from_plater_config() const;
std::vector<std::string> get_colors_for_color_print() const;
void update_object_menu();

View file

@ -11,6 +11,7 @@
#include <wx/statline.h>
#include <wx/dcclient.h>
#include <wx/numformatter.h>
#include <wx/colordlg.h>
#include <boost/algorithm/string/replace.hpp>
@ -22,9 +23,11 @@
#include "I18N.hpp"
#include "GUI_Utils.hpp"
#include "PresetBundle.hpp"
#include "ExtruderSequenceDialog.hpp"
#include "../Utils/MacDarkMode.hpp"
using Slic3r::GUI::from_u8;
using Slic3r::GUI::into_u8;
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
wxDEFINE_EVENT(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, wxCommandEvent);
@ -404,6 +407,23 @@ int em_unit(wxWindow* win)
return Slic3r::GUI::wxGetApp().em_unit();
}
static float get_svg_scale_factor(wxWindow *win)
{
#ifdef __APPLE__
// Note: win->GetContentScaleFactor() is not used anymore here because it tends to
// return bogus results quite often (such as 1.0 on Retina or even 0.0).
// We're using the max scaling factor across all screens because it's very likely to be good enough.
static float max_scaling_factor = NAN;
if (std::isnan(max_scaling_factor)) {
max_scaling_factor = Slic3r::GUI::mac_max_scaling_factor();
}
return win != nullptr ? max_scaling_factor : 1.0f;
#else
return 1.0f;
#endif
}
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/, const bool grayscale/* = false*/)
@ -449,7 +469,7 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr;
/*static*/ std::vector<wxBitmap*> get_extruder_color_icons()
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
{
// Create the bitmap with color bars.
std::vector<wxBitmap*> bmps;
@ -465,16 +485,18 @@ Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr;
* and scale them in respect to em_unit value
*/
const double em = Slic3r::GUI::wxGetApp().em_unit();
const int icon_width = lround(3.2 * em);
const int icon_width = lround((thin_icon ? 1 : 3.2) * em);
const int icon_height = lround(1.6 * em);
for (const std::string& color : colors)
{
wxBitmap* bitmap = m_bitmap_cache->find(color);
std::string bitmap_key = color + "-h" + std::to_string(icon_height) + "-w" + std::to_string(icon_width);
wxBitmap* bitmap = m_bitmap_cache->find(bitmap_key);
if (bitmap == nullptr) {
// Paint the color icon.
Slic3r::PresetBundle::parse_color(color, rgb);
bitmap = m_bitmap_cache->insert(color, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
bitmap = m_bitmap_cache->insert(bitmap_key, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
}
bmps.emplace_back(bitmap);
}
@ -483,16 +505,62 @@ Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr;
}
static wxBitmap get_extruder_color_icon(size_t extruder_idx)
static wxBitmap get_extruder_color_icon(size_t extruder_idx, bool thin_icon = false)
{
// Create the bitmap with color bars.
std::vector<wxBitmap*> bmps = get_extruder_color_icons();
std::vector<wxBitmap*> bmps = get_extruder_color_icons(thin_icon);
if (bmps.empty())
return wxNullBitmap;
return *bmps[extruder_idx >= bmps.size() ? 0 : extruder_idx];
}
void apply_extruder_selector(wxBitmapComboBox** ctrl,
wxWindow* parent,
const std::string& first_item/* = ""*/,
wxPoint pos/* = wxDefaultPosition*/,
wxSize size/* = wxDefaultSize*/,
bool use_thin_icon/* = false*/)
{
std::vector<wxBitmap*> icons = get_extruder_color_icons(use_thin_icon);
if (!*ctrl)
*ctrl = new wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, pos, size,
0, nullptr, wxCB_READONLY);
else
{
(*ctrl)->SetPosition(pos);
(*ctrl)->SetMinSize(size);
(*ctrl)->SetSize(size);
(*ctrl)->Clear();
}
if (first_item.empty())
(*ctrl)->Hide(); // to avoid unwanted rendering before layout (ExtruderSequenceDialog)
if (icons.empty() && !first_item.empty()) {
(*ctrl)->Append(_(first_item), wxNullBitmap);
return;
}
// For ObjectList we use short extruder name (just a number)
const bool use_full_item_name = dynamic_cast<Slic3r::GUI::ObjectList*>(parent) == nullptr;
int i = 0;
wxString str = _(L("Extruder"));
for (wxBitmap* bmp : icons) {
if (i == 0) {
if (!first_item.empty())
(*ctrl)->Append(_(first_item), *bmp);
++i;
}
(*ctrl)->Append(use_full_item_name ? wxString::Format("%s %d", str, i) : std::to_string(i), *bmp);
++i;
}
(*ctrl)->SetSelection(0);
}
// *****************************************************************************
// ----------------------------------------------------------------------------
// ObjectDataViewModelNode
@ -2230,6 +2298,8 @@ DoubleSlider::DoubleSlider( wxWindow *parent,
if (!is_osx)
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
const float scale_factor = get_svg_scale_factor(this);
m_bmp_thumb_higher = (style == wxSL_HORIZONTAL ? ScalableBitmap(this, "right_half_circle.png") : ScalableBitmap(this, "up_half_circle.png", 16, true));
m_bmp_thumb_lower = (style == wxSL_HORIZONTAL ? ScalableBitmap(this, "left_half_circle.png" ) : ScalableBitmap(this, "down_half_circle.png", 16, true));
m_thumb_size = m_bmp_thumb_lower.bmp().GetSize();
@ -2240,16 +2310,19 @@ DoubleSlider::DoubleSlider( wxWindow *parent,
m_bmp_del_tick_off = ScalableBitmap(this, "colorchange_delete_off.png");
m_tick_icon_dim = m_bmp_add_tick_on.bmp().GetSize().x;
m_bmp_one_layer_lock_on = ScalableBitmap(this, "one_layer_lock_on.png");
m_bmp_one_layer_lock_off = ScalableBitmap(this, "one_layer_lock_off.png");
m_bmp_one_layer_unlock_on = ScalableBitmap(this, "one_layer_unlock_on.png");
m_bmp_one_layer_unlock_off = ScalableBitmap(this, "one_layer_unlock_off.png");
m_lock_icon_dim = m_bmp_one_layer_lock_on.bmp().GetSize().x;
m_bmp_one_layer_lock_on = ScalableBitmap(this, "lock_closed");
m_bmp_one_layer_lock_off = ScalableBitmap(this, "lock_closed_f");
m_bmp_one_layer_unlock_on = ScalableBitmap(this, "lock_open");
m_bmp_one_layer_unlock_off = ScalableBitmap(this, "lock_open_f");
m_lock_icon_dim = int((float)m_bmp_one_layer_lock_on.bmp().GetSize().x / scale_factor);
m_bmp_revert = ScalableBitmap(this, "undo");
m_revert_icon_dim = m_bmp_revert.bmp().GetSize().x;
m_revert_icon_dim = int((float)m_bmp_revert.bmp().GetSize().x / scale_factor);
m_bmp_cog = ScalableBitmap(this, "cog");
m_cog_icon_dim = int((float)m_bmp_cog.bmp().GetSize().x / scale_factor);
m_selection = ssUndef;
m_pause_print_msg = _utf8(L("Place bearings in slots and resume"));
// slider events
Bind(wxEVT_PAINT, &DoubleSlider::OnPaint, this);
@ -2306,6 +2379,8 @@ void DoubleSlider::msw_rescale()
m_bmp_revert.msw_rescale();
m_revert_icon_dim = m_bmp_revert.bmp().GetSize().x;
m_bmp_cog.msw_rescale();
m_cog_icon_dim = m_bmp_cog.bmp().GetSize().x;
SLIDER_MARGIN = 4 + Slic3r::GUI::wxGetApp().em_unit();
@ -2453,41 +2528,45 @@ double DoubleSlider::get_double_value(const SelectedSlider& selection)
return m_values[selection == ssLower ? m_lower_value : m_higher_value];
}
std::vector<double> DoubleSlider::GetTicksValues() const
using t_custom_code = Slic3r::Model::CustomGCode;
std::vector<t_custom_code> DoubleSlider::GetTicksValues() const
{
std::vector<double> values;
std::vector<t_custom_code> values;
const int val_size = m_values.size();
if (!m_values.empty())
for (int tick : m_ticks) {
if (tick > val_size)
for (const TICK_CODE& tick : m_ticks_) {
if (tick.tick > val_size)
break;
values.push_back(m_values[tick]);
values.push_back(t_custom_code(m_values[tick.tick], tick.gcode, tick.extruder, tick.color));
}
return values;
}
void DoubleSlider::SetTicksValues(const std::vector<double>& heights)
void DoubleSlider::SetTicksValues(const std::vector<t_custom_code>& heights)
{
if (m_values.empty())
return;
const bool was_empty = m_ticks.empty();
const bool was_empty = m_ticks_.empty();
m_ticks.clear();
m_ticks_.clear();
for (auto h : heights) {
auto it = std::lower_bound(m_values.begin(), m_values.end(), h - epsilon());
auto it = std::lower_bound(m_values.begin(), m_values.end(), h.height - epsilon());
if (it == m_values.end())
continue;
m_ticks.insert(it-m_values.begin());
m_ticks_.insert(TICK_CODE(it-m_values.begin(), h.gcode, h.extruder, h.color));
}
if (!was_empty && m_ticks.empty())
if (!was_empty && m_ticks_.empty())
// Switch to the "Feature type"/"Tool" from the very beginning of a new object slicing after deleting of the old one
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
}
void DoubleSlider::get_lower_and_higher_position(int& lower_pos, int& higher_pos)
@ -2538,17 +2617,20 @@ void DoubleSlider::render()
// //higher slider:
// draw_thumb(dc, higher_pos, ssHigher);
// draw both sliders
draw_thumbs(dc, lower_pos, higher_pos);
//draw color print ticks
draw_ticks(dc);
// draw both sliders
draw_thumbs(dc, lower_pos, higher_pos);
//draw lock/unlock
draw_one_layer_icon(dc);
//draw revert bitmap (if it's shown)
draw_revert_icon(dc);
//draw cog bitmap (if it's shown)
draw_cog_icon(dc);
}
void DoubleSlider::draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end)
@ -2560,7 +2642,7 @@ void DoubleSlider::draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoin
return;
wxBitmap* icon = m_is_action_icon_focesed ? &m_bmp_add_tick_off.bmp() : &m_bmp_add_tick_on.bmp();
if (m_ticks.find(tick) != m_ticks.end())
if (m_ticks_.find(tick) != m_ticks_.end())
icon = m_is_action_icon_focesed ? &m_bmp_del_tick_off.bmp() : &m_bmp_del_tick_on.bmp();
wxCoord x_draw, y_draw;
@ -2703,14 +2785,26 @@ void DoubleSlider::draw_ticks(wxDC& dc)
int height, width;
get_size(&width, &height);
const wxCoord mid = is_horizontal() ? 0.5*height : 0.5*width;
for (auto tick : m_ticks)
for (auto tick : m_ticks_)
{
const wxCoord pos = get_position_from_value(tick);
const wxCoord pos = get_position_from_value(tick.tick);
is_horizontal() ? dc.DrawLine(pos, mid-14, pos, mid-9) :
dc.DrawLine(mid - 14, pos/* - 1*/, mid - 9, pos/* - 1*/);
is_horizontal() ? dc.DrawLine(pos, mid+14, pos, mid+9) :
dc.DrawLine(mid + 14, pos/* - 1*/, mid + 9, pos/* - 1*/);
// Draw icon for "Pause print" or "Custom Gcode"
if (tick.gcode != Slic3r::ColorChangeCode && tick.gcode != Slic3r::ExtruderChangeCode)
{
wxBitmap icon = create_scaled_bitmap(nullptr, tick.gcode == Slic3r::PausePrintCode ? "pause_print" : "edit_gcode");
wxCoord x_draw, y_draw;
is_horizontal() ? x_draw = pos - 0.5 * m_tick_icon_dim : y_draw = pos - 0.5 * m_tick_icon_dim;
is_horizontal() ? y_draw = mid + 22 : x_draw = mid + 22 ;
dc.DrawBitmap(icon, x_draw, y_draw);
}
}
}
@ -2735,34 +2829,34 @@ void DoubleSlider::draw_colored_band(wxDC& dc)
main_band.SetBottom(height - SLIDER_MARGIN + 1);
}
if (m_ticks.empty()) {
dc.SetPen(GetParent()->GetBackgroundColour());
dc.SetBrush(GetParent()->GetBackgroundColour());
dc.DrawRectangle(main_band);
return;
}
const std::vector<std::string>& colors = Slic3r::GCodePreviewData::ColorPrintColors();
const size_t colors_cnt = colors.size();
wxColour clr(colors[0]);
dc.SetPen(clr);
dc.SetBrush(clr);
dc.DrawRectangle(main_band);
size_t i = 1;
for (auto tick : m_ticks)
{
if (i == colors_cnt)
i = 0;
const wxCoord pos = get_position_from_value(tick);
is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) :
main_band.SetBottom(pos-1);
clr = wxColour(colors[i]);
auto draw_band = [](wxDC& dc, const wxColour& clr, const wxRect& band_rc) {
dc.SetPen(clr);
dc.SetBrush(clr);
dc.DrawRectangle(main_band);
dc.DrawRectangle(band_rc);
};
const std::vector<std::string>& colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
int colors_cnt = colors.size();
const wxColour bg_clr = GetParent()->GetBackgroundColour();
wxColour clr = m_state == msSingleExtruder ? wxColour(colors[0]) : bg_clr;
draw_band(dc, clr, main_band);
size_t i = 1;
for (auto tick : m_ticks_)
{
if ( (m_state == msSingleExtruder && tick.gcode != Slic3r::ColorChangeCode) ||
(m_state == msMultiExtruder && tick.gcode != Slic3r::ExtruderChangeCode) )
continue;
const wxCoord pos = get_position_from_value(tick.tick);
is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) :
main_band.SetBottom(pos - 1);
clr = (m_state == msMultiExtruder && tick.color.empty()) ? bg_clr :
m_state == msMultiExtruder ? wxColour(colors[std::min<int>(colors_cnt - 1, tick.extruder-1)]) : wxColour(tick.color);
draw_band(dc, clr, main_band);
i++;
}
}
@ -2788,7 +2882,7 @@ void DoubleSlider::draw_one_layer_icon(wxDC& dc)
void DoubleSlider::draw_revert_icon(wxDC& dc)
{
if (m_ticks.empty() || !m_is_enabled_tick_manipulation)
if (m_ticks_.empty() || !m_is_enabled_tick_manipulation)
return;
int width, height;
@ -2804,6 +2898,24 @@ void DoubleSlider::draw_revert_icon(wxDC& dc)
m_rect_revert_icon = wxRect(x_draw, y_draw, m_revert_icon_dim, m_revert_icon_dim);
}
void DoubleSlider::draw_cog_icon(wxDC& dc)
{
if (m_state != msMultiExtruder)
return;
int width, height;
get_size(&width, &height);
wxCoord x_draw, y_draw;
is_horizontal() ? x_draw = width-2 : x_draw = width - m_cog_icon_dim - 2;
is_horizontal() ? y_draw = height - m_cog_icon_dim - 2 : y_draw = height-2;
dc.DrawBitmap(m_bmp_cog.bmp(), x_draw, y_draw);
//update rect of the lock/unlock icon
m_rect_cog_icon = wxRect(x_draw, y_draw, m_cog_icon_dim, m_cog_icon_dim);
}
void DoubleSlider::update_thumb_rect(const wxCoord& begin_x, const wxCoord& begin_y, const SelectedSlider& selection)
{
const wxRect& rect = wxRect(begin_x, begin_y, m_thumb_size.x, m_thumb_size.y);
@ -2840,16 +2952,16 @@ bool DoubleSlider::is_point_in_rect(const wxPoint& pt, const wxRect& rect)
int DoubleSlider::is_point_near_tick(const wxPoint& pt)
{
for (auto tick : m_ticks) {
const wxCoord pos = get_position_from_value(tick);
for (auto tick : m_ticks_) {
const wxCoord pos = get_position_from_value(tick.tick);
if (is_horizontal()) {
if (pos - 4 <= pt.x && pt.x <= pos + 4)
return tick;
return tick.tick;
}
else {
if (pos - 4 <= pt.y && pt.y <= pos + 4)
return tick;
return tick.tick;
}
}
return -1;
@ -2901,9 +3013,13 @@ void DoubleSlider::OnLeftDown(wxMouseEvent& event)
m_selection == ssLower ? correct_lower_value() : correct_higher_value();
if (!m_selection) m_selection = ssHigher;
m_ticks.clear();
m_ticks_.clear();
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
}
else if (is_point_in_rect(pos, m_rect_cog_icon) && m_state == msMultiExtruder) {
// show dialog for set extruder sequence
m_edit_extruder_sequence = true;
}
else
detect_selected_slider(pos);
@ -2956,6 +3072,38 @@ void DoubleSlider::correct_higher_value()
m_lower_value = m_higher_value;
}
wxString DoubleSlider::get_tooltip(IconFocus icon_focus)
{
wxString tooltip(wxEmptyString);
if (m_is_one_layer_icon_focesed)
tooltip = _(L("One layer mode"));
if (icon_focus == ifRevert)
tooltip = _(L("Discard all custom changes"));
if (icon_focus == ifCog)
tooltip = _(L("Set extruder sequence for whole print"));
else if (m_is_action_icon_focesed)
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
const auto tick_code_it = m_ticks_.find(tick);
tooltip = tick_code_it == m_ticks_.end() ? (m_state == msSingleExtruder ?
_(L("For add color change use left mouse button click")) :
_(L("For add change extruder use left mouse button click"))) + "\n" +
_(L("For add another code use right mouse button click")) :
tick_code_it->gcode == Slic3r::ColorChangeCode ? ( m_state == msSingleExtruder ?
_(L("For Delete color change use left mouse button click\n"
"For Edit color use right mouse button click")) :
from_u8((boost::format(_utf8(L("Delete color change for Extruder %1%"))) % tick_code_it->extruder).str()) ):
// tick_code_it->gcode == Slic3r::PausePrintCode ? _(L("Delete pause")) :
tick_code_it->gcode == Slic3r::ExtruderChangeCode ?
from_u8((boost::format(_utf8(L("Delete extruder change to \"%1%\""))) % tick_code_it->extruder).str()) :
from_u8((boost::format(_utf8(L("For Delete \"%1%\" code use left mouse button click\n"
"For Edit \"%1%\" code use right mouse button click"))) % tick_code_it->gcode ).str());
}
return tooltip;
}
void DoubleSlider::OnMotion(wxMouseEvent& event)
{
bool action = false;
@ -2964,11 +3112,14 @@ void DoubleSlider::OnMotion(wxMouseEvent& event)
const wxPoint pos = event.GetLogicalPosition(dc);
m_is_one_layer_icon_focesed = is_point_in_rect(pos, m_rect_one_layer_icon);
bool is_revert_icon_focused = false;
IconFocus icon_focus = ifNone;
if (!m_is_left_down && !m_is_one_layer) {
m_is_action_icon_focesed = is_point_in_rect(pos, m_rect_tick_action);
is_revert_icon_focused = !m_ticks.empty() && is_point_in_rect(pos, m_rect_revert_icon);
if (!m_ticks_.empty() && is_point_in_rect(pos, m_rect_revert_icon))
icon_focus = ifRevert;
else if (is_point_in_rect(pos, m_rect_cog_icon))
icon_focus = ifCog;
}
else if (m_is_left_down || m_is_right_down) {
if (m_selection == ssLower) {
@ -2989,10 +3140,7 @@ void DoubleSlider::OnMotion(wxMouseEvent& event)
event.Skip();
// Set tooltips with information for each icon
const wxString tooltip = m_is_one_layer_icon_focesed ? _(L("One layer mode")) :
m_is_action_icon_focesed ? _(L("Add/Del color change")) :
is_revert_icon_focused ? _(L("Discard all color changes")) : "";
this->SetToolTip(tooltip);
this->SetToolTip(get_tooltip(icon_focus));
if (action)
{
@ -3009,6 +3157,55 @@ void DoubleSlider::OnLeftUp(wxMouseEvent& event)
return;
this->ReleaseMouse();
m_is_left_down = false;
if (m_show_context_menu)
{
if (m_state == msMultiExtruder)
{
wxMenu menu;
const int extruders_cnt = Slic3r::GUI::wxGetApp().extruders_edited_cnt();
if (extruders_cnt > 1)
{
/*
wxMenu* add_color_change_menu = new wxMenu();
for (int i = 1; i <= extruders_cnt; i++)
append_menu_item(add_color_change_menu, wxID_ANY, wxString::Format(_(L("Extruder %d")), i), "",
[this, i](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode, i); }, "", &menu);
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % Slic3r::ColorChangeCode).str());
wxMenuItem* add_color_change_menu_item = menu.AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "colorchange_add_off.png"));
*/
const int initial_extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
wxMenu* change_extruder_menu = new wxMenu();
for (int i = 0; i <= extruders_cnt; i++) {
const wxString item_name = i == 0 ? _(L("Default")) : wxString::Format(_(L("Extruder %d")), i);
append_menu_radio_item(change_extruder_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { change_extruder(i); }, &menu)->Check(i == initial_extruder);
}
wxMenuItem* change_extruder_menu_item = menu.AppendSubMenu(change_extruder_menu, _(L("Change extruder")), _(L("Use another extruder")));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "change_extruder"));
}
Slic3r::GUI::wxGetApp().plater()->PopupMenu(&menu);
}
else
add_code(Slic3r::ColorChangeCode);
m_show_context_menu = false;
}
if (m_edit_extruder_sequence) {
edit_extruder_sequence();
m_edit_extruder_sequence = false;
}
Refresh();
Update();
event.Skip();
@ -3059,21 +3256,36 @@ void DoubleSlider::action_tick(const TicksAction action)
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
if (action == taOnIcon) {
if (!m_ticks.insert(tick).second)
m_ticks.erase(tick);
const auto it = m_ticks_.find(tick);
if (it != m_ticks_.end()) // erase this tick
{
if (action == taAdd)
return;
m_ticks_.erase(TICK_CODE(tick));
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
return;
}
else {
const auto it = m_ticks.find(tick);
if (it == m_ticks.end() && action == taAdd)
m_ticks.insert(tick);
else if (it != m_ticks.end() && action == taDel)
m_ticks.erase(tick);
if (action == taDel)
return;
if (action == taAdd)
{
// OnChar() is called immediately after OnKeyDown(), which can cause call of add_code() twice.
// To avoid this case we should suppress second add_code() call.
if (m_suppress_add_code)
return;
m_suppress_add_code = true;
if (m_state != msMultiExtruder)
add_code(Slic3r::ColorChangeCode);
m_suppress_add_code = false;
return;
}
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
m_show_context_menu = true;
}
void DoubleSlider::OnWheel(wxMouseEvent& event)
@ -3148,6 +3360,27 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
this->CaptureMouse();
const wxClientDC dc(this);
wxPoint pos = event.GetLogicalPosition(dc);
if (is_point_in_rect(pos, m_rect_tick_action) && m_is_enabled_tick_manipulation)
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
// if on this Z doesn't exist tick
auto it = m_ticks_.find(tick);
if (it == m_ticks_.end())
{
// show context menu on OnRightUp()
m_show_context_menu = true;
return;
}
if (it->gcode != Slic3r::ExtruderChangeCode)
{
// show "Edit" and "Delete" menu on OnRightUp()
m_show_edit_menu = true;
return;
}
}
detect_selected_slider(event.GetLogicalPosition(dc));
if (!m_selection)
return;
@ -3157,13 +3390,29 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
else
m_lower_value = m_higher_value;
m_is_right_down = m_is_one_layer = true;
// set slider to "one layer" mode
m_is_right_down = m_is_one_layer = true;
Refresh();
Update();
event.Skip();
}
int DoubleSlider::get_extruder_for_tick(int tick)
{
if (m_ticks_.empty())
return 0;
auto it = m_ticks_.lower_bound(tick);
while (it != m_ticks_.begin()) {
--it;
if(it->gcode == Slic3r::ExtruderChangeCode)
return it->extruder;
}
return 0;
}
void DoubleSlider::OnRightUp(wxMouseEvent& event)
{
if (!HasCapture())
@ -3171,11 +3420,290 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
this->ReleaseMouse();
m_is_right_down = m_is_one_layer = false;
if (m_show_context_menu) {
wxMenu menu;
if (m_state == msMultiExtruder)
{
const int extruders_cnt = Slic3r::GUI::wxGetApp().extruders_edited_cnt();
if (extruders_cnt > 1)
{
const int initial_extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
wxMenu* change_extruder_menu = new wxMenu();
wxMenu* add_color_change_menu = new wxMenu();
for (int i = 0; i <= extruders_cnt; i++) {
const wxString item_name = i == 0 ? _(L("Default")) : wxString::Format(_(L("Extruder %d")), i);
append_menu_radio_item(change_extruder_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { change_extruder(i); }, &menu)->Check(i == initial_extruder);
if (i==0) // don't use M600 for default extruder, if multimaterial print is selected
continue;
append_menu_item(add_color_change_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode, i); }, "", &menu);
}
wxMenuItem* change_extruder_menu_item = menu.AppendSubMenu(change_extruder_menu, _(L("Change extruder")), _(L("Use another extruder")));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "change_extruder"));
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % Slic3r::ColorChangeCode).str());
wxMenuItem* add_color_change_menu_item = menu.AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "colorchange_add_off.png"));
}
}
else
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
[this](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode); }, "colorchange_add_off.png", &menu);
append_menu_item(&menu, wxID_ANY, _(L("Add pause print")) + " (M601)", "",
[this](wxCommandEvent&) { add_code(Slic3r::PausePrintCode); }, "pause_print", &menu);
append_menu_item(&menu, wxID_ANY, _(L("Add custom G-code")), "",
[this](wxCommandEvent&) { add_code(""); }, "edit_gcode", &menu);
Slic3r::GUI::wxGetApp().plater()->PopupMenu(&menu);
m_show_context_menu = false;
}
else if (m_show_edit_menu) {
wxMenu menu;
std::set<TICK_CODE>::iterator it = m_ticks_.find(m_selection == ssLower ? m_lower_value : m_higher_value);
const bool is_color_change = it->gcode == Slic3r::ColorChangeCode;
append_menu_item(&menu, wxID_ANY, it->gcode == Slic3r::ColorChangeCode ? _(L("Edit color")) :
it->gcode == Slic3r::PausePrintCode ? _(L("Edit pause print message")) :
_(L("Edit custom G-code")), "",
[this](wxCommandEvent&) { edit_tick(); }, "edit_uni", &menu);
append_menu_item(&menu, wxID_ANY, it->gcode == Slic3r::ColorChangeCode ? _(L("Delete color change")) :
it->gcode == Slic3r::PausePrintCode ? _(L("Delete pause print")) :
_(L("Delete custom G-code")), "",
[this](wxCommandEvent&) { action_tick(taDel); }, "colorchange_delete_off.png", &menu);
Slic3r::GUI::wxGetApp().plater()->PopupMenu(&menu);
m_show_edit_menu = false;
}
Refresh();
Update();
event.Skip();
}
static std::string get_new_color(const std::string& color)
{
wxColour clr(color);
if (!clr.IsOk())
clr = wxColour(0, 0, 0); // Don't set alfa to transparence
auto data = new wxColourData();
data->SetChooseFull(1);
data->SetColour(clr);
wxColourDialog dialog(nullptr, data);
dialog.CenterOnParent();
if (dialog.ShowModal() == wxID_OK)
return dialog.GetColourData().GetColour().GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
return "";
}
static std::string get_custom_code(const std::string& code_in, double height)
{
wxString msg_text = from_u8(_utf8(L("Enter custom G-code used on current layer"))) + " :";
wxString msg_header = from_u8((boost::format(_utf8(L("Custom Gcode on current layer (%1% mm)."))) % height).str());
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, code_in,
wxTextEntryDialogStyle | wxTE_MULTILINE);
if (dlg.ShowModal() != wxID_OK || dlg.GetValue().IsEmpty())
return "";
return dlg.GetValue().ToStdString();
}
static std::string get_pause_print_msg(const std::string& msg_in, double height)
{
wxString msg_text = from_u8(_utf8(L("Enter short message shown on Printer display during pause print"))) + " :";
wxString msg_header = from_u8((boost::format(_utf8(L("Message for pause print on current layer (%1% mm)."))) % height).str());
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, from_u8(msg_in),
wxTextEntryDialogStyle);
if (dlg.ShowModal() != wxID_OK || dlg.GetValue().IsEmpty())
return "";
return into_u8(dlg.GetValue());
}
void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
// if on this Z doesn't exist tick
auto it = m_ticks_.find(tick);
if (it == m_ticks_.end())
{
std::string color = "";
if (code == Slic3r::ColorChangeCode)
{
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
if (m_state == msSingleExtruder && !m_ticks_.empty()) {
auto before_tick_it = std::lower_bound(m_ticks_.begin(), m_ticks_.end(), tick);
while (before_tick_it != m_ticks_.begin()) {
--before_tick_it;
if (before_tick_it->gcode == Slic3r::ColorChangeCode) {
color = before_tick_it->color;
break;
}
}
if (color.empty())
color = colors[0];
}
else
color = colors[selected_extruder > 0 ? selected_extruder-1 : 0];
color = get_new_color(color);
if (color.empty())
return;
}
else if (code == Slic3r::PausePrintCode)
{
/* PausePrintCode doesn't need a color, so
* this field is used for save a short message shown on Printer display
* */
m_pause_print_msg = color = get_pause_print_msg(m_pause_print_msg, m_values[tick]);
}
else if (code.empty())
{
m_custom_gcode = code = get_custom_code(m_custom_gcode, m_values[tick]);
}
int extruder = 1;
if (m_state == msMultiExtruder) {
if (code == Slic3r::ColorChangeCode && selected_extruder >= 0)
extruder = selected_extruder;
else
extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
}
m_ticks_.insert(TICK_CODE(tick, code, extruder, color));
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
}
}
void DoubleSlider::edit_tick()
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
// if on this Z exists tick
std::set<TICK_CODE>::iterator it = m_ticks_.find(tick);
if (it != m_ticks_.end())
{
std::string edited_value;
if (it->gcode == Slic3r::ColorChangeCode)
edited_value = get_new_color(it->color);
else if (it->gcode == Slic3r::PausePrintCode)
edited_value = get_pause_print_msg(it->color, m_values[it->tick]);
else
edited_value = get_custom_code(it->gcode, m_values[it->tick]);
if (edited_value.empty())
return;
TICK_CODE changed_tick = *it;
if (it->gcode == Slic3r::ColorChangeCode || it->gcode == Slic3r::PausePrintCode) {
if (it->color == edited_value)
return;
changed_tick.color = edited_value;
}
else {
if (it->gcode == edited_value)
return;
changed_tick.gcode = edited_value;
}
m_ticks_.erase(it);
m_ticks_.insert(changed_tick);
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
}
}
void DoubleSlider::change_extruder(int extruder)
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
// if on this Y doesn't exist tick
if (m_ticks_.find(tick) == m_ticks_.end())
{
m_ticks_.insert(TICK_CODE(tick, Slic3r::ExtruderChangeCode, extruder, extruder == 0 ? "" : colors[extruder-1]));
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
}
}
void DoubleSlider::edit_extruder_sequence()
{
Slic3r::GUI::ExtruderSequenceDialog dlg(m_extruders_sequence);
if (dlg.ShowModal() != wxID_OK)
return;
const ExtrudersSequence& from_dlg_val = dlg.GetValue();
if (m_extruders_sequence == from_dlg_val)
return;
m_extruders_sequence = from_dlg_val;
auto it = m_ticks_.begin();
while (it != m_ticks_.end()) {
if (it->gcode == Slic3r::ExtruderChangeCode)
it = m_ticks_.erase(it);
else
++it;
}
int tick = 0;
double value = 0.0;
int extruder = 0;
const int extr_cnt = m_extruders_sequence.extruders.size();
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
while (tick <= m_max_value)
{
int cur_extruder = m_extruders_sequence.extruders[extruder];
m_ticks_.insert(TICK_CODE(tick, Slic3r::ExtruderChangeCode, cur_extruder + 1, colors[cur_extruder]));
extruder++;
if (extruder == extr_cnt)
extruder = 0;
if (m_extruders_sequence.is_mm_intervals)
{
value += m_extruders_sequence.interval_by_mm;
auto it = std::lower_bound(m_values.begin(), m_values.end(), value - epsilon());
if (it == m_values.end())
break;
tick = it - m_values.begin();
}
else
tick += m_extruders_sequence.interval_by_layers;
}
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
}
// ----------------------------------------------------------------------------
// LockButton

View file

@ -16,6 +16,7 @@
#include <vector>
#include <set>
#include <functional>
#include "libslic3r/Model.hpp"
namespace Slic3r {
enum class ModelVolumeType : int;
@ -48,6 +49,8 @@ wxMenuItem* append_menu_check_item(wxMenu* menu, int id, const wxString& string,
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
class wxDialog;
class wxBitmapComboBox;
void edit_tooltip(wxString& tooltip);
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids);
int em_unit(wxWindow* win);
@ -55,7 +58,13 @@ int em_unit(wxWindow* win);
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name,
const int px_cnt = 16, const bool is_horizontal = false, const bool grayscale = false);
std::vector<wxBitmap*> get_extruder_color_icons();
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon = false);
void apply_extruder_selector(wxBitmapComboBox** ctrl,
wxWindow* parent,
const std::string& first_item = "",
wxPoint pos = wxDefaultPosition,
wxSize size = wxDefaultSize,
bool use_thin_icon = false);
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
{
@ -749,6 +758,11 @@ enum TicksAction{
class DoubleSlider : public wxControl
{
enum IconFocus {
ifNone,
ifRevert,
ifCog
};
public:
DoubleSlider(
wxWindow *parent,
@ -794,8 +808,8 @@ public:
m_values = values;
}
void ChangeOneLayerLock();
std::vector<double> GetTicksValues() const;
void SetTicksValues(const std::vector<double>& heights);
std::vector<Slic3r::Model::CustomGCode> GetTicksValues() const;
void SetTicksValues(const std::vector<Slic3r::Model::CustomGCode> &heights);
void EnableTickManipulation(bool enable = true) {
m_is_enabled_tick_manipulation = enable;
}
@ -803,6 +817,18 @@ public:
EnableTickManipulation(false);
}
enum ManipulationState {
msSingleExtruder, // single extruder printer preset is selected
msMultiExtruder // multiple extruder printer preset is selected, and "Whole print" is selected
};
void SetManipulationState(ManipulationState state) {
m_state = state;
}
void SetManipulationState(int extruders_cnt) {
m_state = extruders_cnt ==1 ? msSingleExtruder : msMultiExtruder;
}
ManipulationState GetManipulationState() const { return m_state; }
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
bool is_one_layer() const { return m_is_one_layer; }
bool is_lower_at_min() const { return m_lower_value == m_min_value; }
@ -820,7 +846,12 @@ public:
void OnKeyUp(wxKeyEvent &event);
void OnChar(wxKeyEvent &event);
void OnRightDown(wxMouseEvent& event);
int get_extruder_for_tick(int tick);
void OnRightUp(wxMouseEvent& event);
void add_code(std::string code, int selected_extruder = -1);
void edit_tick();
void change_extruder(int extruder);
void edit_extruder_sequence();
protected:
@ -834,6 +865,7 @@ protected:
void draw_colored_band(wxDC& dc);
void draw_one_layer_icon(wxDC& dc);
void draw_revert_icon(wxDC& dc);
void draw_cog_icon(wxDC &dc);
void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection);
void draw_info_line_with_icon(wxDC& dc, const wxPoint& pos, SelectedSlider selection);
void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const;
@ -842,6 +874,7 @@ protected:
void detect_selected_slider(const wxPoint& pt);
void correct_lower_value();
void correct_higher_value();
wxString get_tooltip(IconFocus icon_focus);
void move_current_thumb(const bool condition);
void action_tick(const TicksAction action);
void enter_window(wxMouseEvent& event, const bool enter);
@ -876,6 +909,7 @@ private:
ScalableBitmap m_bmp_one_layer_unlock_on;
ScalableBitmap m_bmp_one_layer_unlock_off;
ScalableBitmap m_bmp_revert;
ScalableBitmap m_bmp_cog;
SelectedSlider m_selection;
bool m_is_left_down = false;
bool m_is_right_down = false;
@ -884,16 +918,25 @@ private:
bool m_is_action_icon_focesed = false;
bool m_is_one_layer_icon_focesed = false;
bool m_is_enabled_tick_manipulation = true;
bool m_show_context_menu = false;
bool m_show_edit_menu = false;
bool m_edit_extruder_sequence = false;
bool m_suppress_add_code = false;
ManipulationState m_state = msSingleExtruder;
std::string m_custom_gcode = "";
std::string m_pause_print_msg;
wxRect m_rect_lower_thumb;
wxRect m_rect_higher_thumb;
wxRect m_rect_tick_action;
wxRect m_rect_one_layer_icon;
wxRect m_rect_revert_icon;
wxRect m_rect_cog_icon;
wxSize m_thumb_size;
int m_tick_icon_dim;
int m_lock_icon_dim;
int m_revert_icon_dim;
int m_cog_icon_dim;
long m_style;
float m_label_koef = 1.0;
@ -912,6 +955,88 @@ private:
std::vector<wxPen*> m_segm_pens;
std::set<int> m_ticks;
std::vector<double> m_values;
struct TICK_CODE
{
TICK_CODE(int tick):tick(tick), gcode(Slic3r::ColorChangeCode), extruder(0), color("") {}
TICK_CODE(int tick, const std::string& code) :
tick(tick), gcode(code), extruder(0) {}
TICK_CODE(int tick, int extruder) :
tick(tick), gcode(Slic3r::ColorChangeCode), extruder(extruder) {}
TICK_CODE(int tick, const std::string& code, int extruder, const std::string& color) :
tick(tick), gcode(code), extruder(extruder), color(color) {}
bool operator<(const TICK_CODE& other) const { return other.tick > this->tick; }
bool operator>(const TICK_CODE& other) const { return other.tick < this->tick; }
TICK_CODE operator=(const TICK_CODE& other) const {
TICK_CODE ret_val(other.tick, other.gcode, other.extruder, other.color);
return ret_val;
}
int tick;
std::string gcode;
int extruder;
std::string color;
};
std::set<TICK_CODE> m_ticks_;
public:
struct ExtrudersSequence
{
bool is_mm_intervals;
double interval_by_mm;
int interval_by_layers;
std::vector<size_t> extruders;
ExtrudersSequence() :
is_mm_intervals(true),
interval_by_mm(3.0),
interval_by_layers(10),
extruders({ 0 }) {}
ExtrudersSequence(const ExtrudersSequence& other) :
is_mm_intervals(other.is_mm_intervals),
interval_by_mm(other.interval_by_mm),
interval_by_layers(other.interval_by_layers),
extruders(other.extruders) {}
ExtrudersSequence& operator=(const ExtrudersSequence& other) {
this->is_mm_intervals = other.is_mm_intervals;
this->interval_by_mm = other.interval_by_mm;
this->interval_by_layers= other.interval_by_layers;
this->extruders = other.extruders;
return *this;
}
bool operator==(const ExtrudersSequence& other) const
{
return (other.is_mm_intervals == this->is_mm_intervals ) &&
(other.interval_by_mm == this->interval_by_mm ) &&
(other.interval_by_layers == this->interval_by_layers ) &&
(other.extruders == this->extruders ) ;
}
bool operator!=(const ExtrudersSequence& other) const
{
return (other.is_mm_intervals != this->is_mm_intervals ) &&
(other.interval_by_mm != this->interval_by_mm ) &&
(other.interval_by_layers != this->interval_by_layers ) &&
(other.extruders != this->extruders ) ;
}
void add_extruder(size_t pos)
{
extruders.insert(extruders.begin() + pos+1, size_t(0));
}
void delete_extruder(size_t pos)
{
if (extruders.size() == 1)
return;// last item can't be deleted
extruders.erase(extruders.begin() + pos);
}
}
m_extruders_sequence;
};