Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/slic3r/GUI/DoubleSlider.cpp')
-rw-r--r--src/slic3r/GUI/DoubleSlider.cpp1141
1 files changed, 738 insertions, 403 deletions
diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp
index 7318153ef..8a2257274 100644
--- a/src/slic3r/GUI/DoubleSlider.cpp
+++ b/src/slic3r/GUI/DoubleSlider.cpp
@@ -1,10 +1,14 @@
-#include "wxExtensions.hpp"
-#include "libslic3r/GCode/PreviewData.hpp"
+#include "libslic3r/libslic3r.h"
+#include "DoubleSlider.hpp"
+#include "libslic3r/GCode.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
+#include "Plater.hpp"
#include "I18N.hpp"
#include "ExtruderSequenceDialog.hpp"
#include "libslic3r/Print.hpp"
+#include "libslic3r/AppConfig.hpp"
+#include "GUI_Utils.hpp"
#include <wx/button.h>
#include <wx/dialog.h>
@@ -14,22 +18,35 @@
#include <wx/bmpcbox.h>
#include <wx/statline.h>
#include <wx/dcclient.h>
-#include <wx/numformatter.h>
#include <wx/colordlg.h>
#include <cmath>
#include <boost/algorithm/string/replace.hpp>
#include "Field.hpp"
+#include "format.hpp"
+#include "NotificationManager.hpp"
namespace Slic3r {
using GUI::from_u8;
using GUI::into_u8;
+using GUI::format_wxstr;
namespace DoubleSlider {
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
+static std::string gcode(Type type)
+{
+ const PrintConfig& config = GUI::wxGetApp().plater()->fff_print().config();
+ switch (type) {
+ case ColorChange: return config.color_change_gcode;
+ case PausePrint: return config.pause_print_gcode;
+ case Template: return config.template_custom_gcode;
+ default: return "";
+ }
+}
+
Control::Control( wxWindow *parent,
wxWindowID id,
int lowerValue,
@@ -46,7 +63,8 @@ Control::Control( wxWindow *parent,
m_higher_value (higherValue),
m_min_value(minValue),
m_max_value(maxValue),
- m_style(style == wxSL_HORIZONTAL || style == wxSL_VERTICAL ? style: wxSL_HORIZONTAL)
+ m_style(style == wxSL_HORIZONTAL || style == wxSL_VERTICAL ? style: wxSL_HORIZONTAL),
+ m_extra_style(style == wxSL_VERTICAL ? wxSL_AUTOTICKS | wxSL_VALUE_LABEL : 0)
{
#ifdef __WXOSX__
is_osx = true;
@@ -54,8 +72,8 @@ Control::Control( wxWindow *parent,
if (!is_osx)
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
- m_bmp_thumb_higher = (style == wxSL_HORIZONTAL ? ScalableBitmap(this, "right_half_circle.png") : ScalableBitmap(this, "thumb_up"));
- m_bmp_thumb_lower = (style == wxSL_HORIZONTAL ? ScalableBitmap(this, "left_half_circle.png" ) : ScalableBitmap(this, "thumb_down"));
+ m_bmp_thumb_higher = (style == wxSL_HORIZONTAL ? ScalableBitmap(this, "thumb_right") : ScalableBitmap(this, "thumb_up"));
+ m_bmp_thumb_lower = (style == wxSL_HORIZONTAL ? ScalableBitmap(this, "thumb_left") : ScalableBitmap(this, "thumb_down"));
m_thumb_size = m_bmp_thumb_lower.GetBmpSize();
m_bmp_add_tick_on = ScalableBitmap(this, "colorchange_add");
@@ -107,14 +125,13 @@ Control::Control( wxWindow *parent,
m_line_pens = { &DARK_GREY_PEN, &GREY_PEN, &LIGHT_GREY_PEN };
m_segm_pens = { &DARK_ORANGE_PEN, &ORANGE_PEN, &LIGHT_ORANGE_PEN };
- const wxFont& font = GetFont();
- m_font = is_osx ? font.Smaller().Smaller() : font.Smaller();
+ m_font = GetFont();
+ this->SetMinSize(get_min_size());
}
void Control::msw_rescale()
{
- const wxFont& font = GUI::wxGetApp().normal_font();
- m_font = is_osx ? font.Smaller().Smaller() : font.Smaller();
+ m_font = GUI::wxGetApp().normal_font();
m_bmp_thumb_higher.msw_rescale();
m_bmp_thumb_lower .msw_rescale();
@@ -152,8 +169,7 @@ int Control::GetActiveValue() const
wxSize Control::get_min_size() const
{
- const int min_side = GUI::wxGetApp().em_unit() * ( is_horizontal() ? (is_osx ? 8 : 6) : 10 );
-
+ const int min_side = GUI::wxGetApp().em_unit() * ( is_horizontal() ? 5 : 11 );
return wxSize(min_side, min_side);
}
@@ -213,6 +229,12 @@ void Control::SetMaxValue(const int max_value)
Update();
}
+void Control::SetSliderValues(const std::vector<double>& values)
+{
+ m_values = values;
+ m_ruler.count = std::count(m_values.begin(), m_values.end(), m_values.front());
+}
+
void Control::draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos)
{
int width;
@@ -229,8 +251,7 @@ void Control::draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_p
wxCoord segm_end_x = is_horizontal() ? higher_pos : width*0.5 - 1;
wxCoord segm_end_y = is_horizontal() ? height*0.5 - 1 : higher_pos-1;
- for (size_t id = 0; id < m_line_pens.size(); id++)
- {
+ for (size_t id = 0; id < m_line_pens.size(); id++) {
dc.SetPen(*m_line_pens[id]);
dc.DrawLine(line_beg_x, line_beg_y, line_end_x, line_end_y);
dc.SetPen(*m_segm_pens[id]);
@@ -257,16 +278,18 @@ wxCoord Control::get_position_from_value(const int value)
return wxCoord(SLIDER_MARGIN + int(val*step + 0.5));
}
-wxSize Control::get_size()
+wxSize Control::get_size() const
{
int w, h;
get_size(&w, &h);
return wxSize(w, h);
}
-void Control::get_size(int *w, int *h)
+void Control::get_size(int* w, int* h) const
{
GetSize(w, h);
+ if (m_draw_mode == dmSequentialGCodeView)
+ return; // we have no more icons for drawing
is_horizontal() ? *w -= m_lock_icon_dim : *h -= m_lock_icon_dim;
}
@@ -281,18 +304,17 @@ double Control::get_double_value(const SelectedSlider& selection)
return m_values[selection == ssLower ? m_lower_value : m_higher_value];
}
-using t_custom_code = CustomGCode::Item;
-CustomGCode::Info Control::GetTicksValues() const
+Info Control::GetTicksValues() const
{
- CustomGCode::Info custom_gcode_per_print_z;
- std::vector<t_custom_code>& values = custom_gcode_per_print_z.gcodes;
+ Info custom_gcode_per_print_z;
+ std::vector<CustomGCode::Item>& values = custom_gcode_per_print_z.gcodes;
const int val_size = m_values.size();
if (!m_values.empty())
for (const TickCode& tick : m_ticks.ticks) {
if (tick.tick > val_size)
break;
- values.emplace_back(t_custom_code{m_values[tick.tick], tick.gcode, tick.extruder, tick.color});
+ values.emplace_back(CustomGCode::Item{ m_values[tick.tick], tick.type, tick.extruder, tick.color, tick.extra });
}
if (m_force_mode_apply)
@@ -301,10 +323,9 @@ CustomGCode::Info Control::GetTicksValues() const
return custom_gcode_per_print_z;
}
-void Control::SetTicksValues(const CustomGCode::Info& custom_gcode_per_print_z)
+void Control::SetTicksValues(const Info& custom_gcode_per_print_z)
{
- if (m_values.empty())
- {
+ if (m_values.empty()) {
m_ticks.mode = m_mode;
return;
}
@@ -312,14 +333,14 @@ void Control::SetTicksValues(const CustomGCode::Info& custom_gcode_per_print_z)
const bool was_empty = m_ticks.empty();
m_ticks.ticks.clear();
- const std::vector<t_custom_code>& heights = custom_gcode_per_print_z.gcodes;
+ const std::vector<CustomGCode::Item>& heights = custom_gcode_per_print_z.gcodes;
for (auto h : heights) {
auto it = std::lower_bound(m_values.begin(), m_values.end(), h.print_z - epsilon());
if (it == m_values.end())
continue;
- m_ticks.ticks.emplace(TickCode{int(it-m_values.begin()), h.gcode, h.extruder, h.color});
+ m_ticks.ticks.emplace(TickCode{int(it-m_values.begin()), h.type, h.extruder, h.color, h.extra});
}
if (!was_empty && m_ticks.empty())
@@ -333,6 +354,24 @@ void Control::SetTicksValues(const CustomGCode::Info& custom_gcode_per_print_z)
Update();
}
+void Control::SetLayersTimes(const std::vector<float>& layers_times)
+{
+ m_layers_times.clear();
+ if (layers_times.empty())
+ return;
+ m_layers_times.resize(layers_times.size(), 0.0);
+ m_layers_times[0] = layers_times[0];
+ for (size_t i = 1; i < layers_times.size(); i++)
+ m_layers_times[i] = m_layers_times[i - 1] + layers_times[i];
+}
+
+void Control::SetLayersTimes(const std::vector<double>& layers_times)
+{
+ m_layers_times = layers_times;
+ for (size_t i = 1; i < m_layers_times.size(); i++)
+ m_layers_times[i] += m_layers_times[i - 1];
+}
+
void Control::SetDrawMode(bool is_sla_print, bool is_sequential_print)
{
m_draw_mode = is_sla_print ? dmSlaPrint :
@@ -342,14 +381,14 @@ void Control::SetDrawMode(bool is_sla_print, bool is_sequential_print)
void Control::SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder)
{
- m_mode = !is_one_extruder_printed_model ? t_mode::MultiExtruder :
- only_extruder < 0 ? t_mode::SingleExtruder :
- t_mode::MultiAsSingle;
+ m_mode = !is_one_extruder_printed_model ? MultiExtruder :
+ only_extruder < 0 ? SingleExtruder :
+ MultiAsSingle;
if (!m_ticks.mode)
m_ticks.mode = m_mode;
m_only_extruder = only_extruder;
- UseDefaultColors(m_mode == t_mode::SingleExtruder);
+ UseDefaultColors(m_mode == SingleExtruder);
}
void Control::SetExtruderColors( const std::vector<std::string>& extruder_colors)
@@ -384,7 +423,11 @@ void Control::draw_focus_rect()
void Control::render()
{
+#ifdef _WIN32
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+#else
SetBackgroundColour(GetParent()->GetBackgroundColour());
+#endif // _WIN32
draw_focus_rect();
wxPaintDC dc(this);
@@ -397,32 +440,40 @@ void Control::render()
// and only in a case of no-empty m_values
draw_colored_band(dc);
- // draw line
- draw_scroll_line(dc, lower_pos, higher_pos);
+ if (m_extra_style & wxSL_AUTOTICKS)
+ draw_ruler(dc);
+
+ if (!m_render_as_disabled) {
+ // draw line
+ draw_scroll_line(dc, lower_pos, higher_pos);
- //draw color print ticks
- draw_ticks(dc);
+ // draw color print ticks
+ draw_ticks(dc);
- // draw both sliders
- draw_thumbs(dc, lower_pos, higher_pos);
+ // draw both sliders
+ draw_thumbs(dc, lower_pos, higher_pos);
- //draw lock/unlock
- draw_one_layer_icon(dc);
+ // draw lock/unlock
+ draw_one_layer_icon(dc);
- //draw revert bitmap (if it's shown)
- draw_revert_icon(dc);
+ // draw revert bitmap (if it's shown)
+ draw_revert_icon(dc);
- //draw cog bitmap (if it's shown)
- draw_cog_icon(dc);
+ // draw cog bitmap (if it's shown)
+ draw_cog_icon(dc);
- //draw mouse position
- draw_tick_on_mouse_position(dc);
+ // draw mouse position
+ draw_tick_on_mouse_position(dc);
+ }
}
void Control::draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end)
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
+ if (!m_enable_action_icon)
+ return;
+
// suppress add tick on first layer
if (tick == 0)
return;
@@ -507,7 +558,7 @@ void Control::draw_tick_on_mouse_position(wxDC& dc)
}
tick = get_value_from_position(m_moving_pos);
- if (tick >= m_max_value || tick <= m_min_value || tick == m_higher_value || tick == m_lower_value)
+ if (tick > m_max_value || tick < m_min_value || tick == m_higher_value || tick == m_lower_value)
return;
wxCoord new_pos = get_position_from_value(tick);
@@ -516,9 +567,57 @@ void Control::draw_tick_on_mouse_position(wxDC& dc)
//draw info line
dc.SetPen(LIGHT_GREY_PEN);
draw_ticks(dc, pos);
+
+ if (m_extra_style & wxSL_VALUE_LABEL) {
+ wxColour old_clr = dc.GetTextForeground();
+ dc.SetTextForeground(GREY_PEN.GetColour());
+ draw_tick_text(dc, pos, tick, ltEstimatedTime, false);
+ dc.SetTextForeground(old_clr);
+ }
+}
+
+static std::string short_and_splitted_time(const std::string& time)
+{
+ // Parse the dhms time format.
+ int days = 0;
+ int hours = 0;
+ int minutes = 0;
+ int seconds = 0;
+ if (time.find('d') != std::string::npos)
+ ::sscanf(time.c_str(), "%dd %dh %dm %ds", &days, &hours, &minutes, &seconds);
+ else if (time.find('h') != std::string::npos)
+ ::sscanf(time.c_str(), "%dh %dm %ds", &hours, &minutes, &seconds);
+ else if (time.find('m') != std::string::npos)
+ ::sscanf(time.c_str(), "%dm %ds", &minutes, &seconds);
+ else if (time.find('s') != std::string::npos)
+ ::sscanf(time.c_str(), "%ds", &seconds);
+
+ // Format the dhm time.
+ char buffer[64];
+ if (days > 0)
+ ::sprintf(buffer, "%dd%dh\n%dm", days, hours, minutes);
+ else if (hours > 0) {
+ if (hours < 10 && minutes < 10 && seconds < 10)
+ ::sprintf(buffer, "%dh%dm%ds", hours, minutes, seconds);
+ else if (hours > 10 && minutes > 10 && seconds > 10)
+ ::sprintf(buffer, "%dh\n%dm\n%ds", hours, minutes, seconds);
+ else if (minutes < 10 && seconds > 10 || minutes > 10 && seconds < 10)
+ ::sprintf(buffer, "%dh\n%dm%ds", hours, minutes, seconds);
+ else
+ ::sprintf(buffer, "%dh%dm\n%ds", hours, minutes, seconds);
+ }
+ else if (minutes > 0) {
+ if (minutes > 10 && seconds > 10)
+ ::sprintf(buffer, "%dm\n%ds", minutes, seconds);
+ else
+ ::sprintf(buffer, "%dm%ds", minutes, seconds);
+ }
+ else
+ ::sprintf(buffer, "%ds", seconds);
+ return buffer;
}
-wxString Control::get_label(int tick) const
+wxString Control::get_label(int tick, LabelType label_type/* = ltHeightWithLayer*/) const
{
const int value = tick;
@@ -527,55 +626,68 @@ wxString Control::get_label(int tick) const
if (value >= m_values.size())
return "ErrVal";
- const wxString str = m_values.empty() ?
- wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None) :
- wxNumberFormatter::ToString(m_values[value], 2, wxNumberFormatter::Style_None);
- return from_u8((boost::format("%1%\n(%2%)") % str % (m_values.empty() ? value : value+1)).str());
+ if (m_draw_mode == dmSequentialGCodeView)
+ return wxString::Format("%d", static_cast<unsigned int>(m_values[value]));
+ else {
+ if (label_type == ltEstimatedTime) {
+ return (value < m_layers_times.size()) ? short_and_splitted_time(get_time_dhms(m_layers_times[value])) : "";
+ }
+ wxString str = m_values.empty() ?
+ wxString::Format("%.*f", 2, m_label_koef * value) :
+ wxString::Format("%.*f", 2, m_values[value]);
+ if (label_type == ltHeight)
+ return str;
+ if (label_type == ltHeightWithLayer)
+ return format_wxstr("%1%\n(%2%)", str, m_values.empty() ? value : value + 1);
+ }
+
+ return wxEmptyString;
}
-void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, bool right_side/*=true*/) const
+void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, LabelType label_type/* = ltHeight*/, bool right_side/*=true*/) const
{
wxCoord text_width, text_height;
- const wxString label = get_label(tick);
+ const wxString label = get_label(tick, label_type);
dc.GetMultiLineTextExtent(label, &text_width, &text_height);
wxPoint text_pos;
- if (right_side)
- text_pos = is_horizontal() ? wxPoint(pos.x + 1, pos.y + m_thumb_size.x) :
- wxPoint(pos.x + m_thumb_size.x+1, pos.y - 0.5*text_height - 1);
+ if (right_side) {
+ if (is_horizontal()) {
+ int width;
+ int height;
+ get_size(&width, &height);
+
+ int x_right = pos.x + 1 + text_width;
+ int xx = (x_right < width) ? pos.x + 1 : pos.x - text_width - 1;
+ text_pos = wxPoint(xx, pos.y + m_thumb_size.x / 2 + 1);
+ }
+ else
+ text_pos = wxPoint(pos.x + m_thumb_size.x + 1, pos.y - 0.5 * text_height - 1);
+ }
+ else {
+ if (is_horizontal()) {
+ int x = pos.x - text_width - 1;
+ int xx = (x > 0) ? x : pos.x + 1;
+ text_pos = wxPoint(xx, pos.y - m_thumb_size.x / 2 - text_height - 1);
+ }
+ else
+ text_pos = wxPoint(std::max(2, pos.x - text_width - 1 - m_thumb_size.x), pos.y - 0.5 * text_height + 1);
+ }
+
+ if (label_type == ltEstimatedTime)
+ dc.DrawLabel(label, wxRect(text_pos, wxSize(text_width, text_height)), wxALIGN_RIGHT);
else
- text_pos = is_horizontal() ? wxPoint(pos.x - text_width - 1, pos.y - m_thumb_size.x - text_height) :
- wxPoint(pos.x - text_width - 1 - m_thumb_size.x, pos.y - 0.5*text_height + 1);
- dc.DrawText(label, text_pos);
+ dc.DrawText(label, text_pos);
}
void Control::draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const
{
- draw_tick_text(dc, pos, selection == ssLower ? m_lower_value : m_higher_value, selection == ssLower);
+ draw_tick_text(dc, pos, selection == ssLower ? m_lower_value : m_higher_value, ltHeightWithLayer, selection == ssLower);
}
void Control::draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection)
{
- wxCoord x_draw, y_draw;
- if (selection == ssLower) {
- if (is_horizontal()) {
- x_draw = pos.x - m_thumb_size.x;
- y_draw = pos.y - int(0.5*m_thumb_size.y);
- }
- else {
- x_draw = pos.x - int(0.5*m_thumb_size.x);
- y_draw = pos.y - int(0.5*m_thumb_size.y);
- }
- }
- else{
- if (is_horizontal()) {
- x_draw = pos.x;
- y_draw = pos.y - int(0.5*m_thumb_size.y);
- }
- else {
- x_draw = pos.x - int(0.5*m_thumb_size.x);
- y_draw = pos.y - int(0.5*m_thumb_size.y);
- }
- }
+ wxCoord x_draw = pos.x - int(0.5 * m_thumb_size.x);
+ wxCoord y_draw = pos.y - int(0.5 * m_thumb_size.y);
dc.DrawBitmap(selection == ssLower ? m_bmp_thumb_lower.bmp() : m_bmp_thumb_higher.bmp(), x_draw, y_draw);
// Update thumb rect
@@ -623,6 +735,15 @@ void Control::draw_thumbs(wxDC& dc, const wxCoord& lower_pos, const wxCoord& hig
draw_thumb_text(dc, pos_l, ssLower);
}
+void Control::draw_ticks_pair(wxDC& dc, wxCoord pos, wxCoord mid, int tick_len)
+{
+ int mid_space = 9;
+ is_horizontal() ? dc.DrawLine(pos, mid - (mid_space + tick_len), pos, mid - mid_space) :
+ dc.DrawLine(mid - (mid_space + tick_len), pos, mid - mid_space, pos);
+ is_horizontal() ? dc.DrawLine(pos, mid + (mid_space + tick_len), pos, mid + mid_space) :
+ dc.DrawLine(mid + (mid_space + tick_len), pos, mid + mid_space, pos);
+};
+
void Control::draw_ticks(wxDC& dc)
{
if (m_draw_mode == dmSlaPrint)
@@ -632,14 +753,14 @@ void Control::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.ticks)
- {
- const wxCoord pos = get_position_from_value(tick.tick);
+ for (auto tick : m_ticks.ticks) {
+ if (tick.tick >= m_values.size()) {
+ // The case when OnPaint is called before m_ticks.ticks data are updated (specific for the vase mode)
+ break;
+ }
- 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*/);
+ const wxCoord pos = get_position_from_value(tick.tick);
+ draw_ticks_pair(dc, pos, mid, 7);
// if current tick if focused, we should to use a specific "focused" icon
bool focused_tick = m_moving_pos != wxDefaultPosition && tick.tick == get_tick_near_point(m_moving_pos);
@@ -650,18 +771,17 @@ void Control::draw_ticks(wxDC& dc)
// if we have non-regular draw mode, all ticks should be marked with error icon
if (m_draw_mode != dmRegular)
icon_name = focused_tick ? "error_tick_f" : "error_tick";
- else if (tick.gcode == ColorChangeCode || tick.gcode == ToolChangeCode) {
+ else if (tick.type == ColorChange || tick.type == ToolChange) {
if (m_ticks.is_conflict_tick(tick, m_mode, m_only_extruder, m_values[tick.tick]))
icon_name = focused_tick ? "error_tick_f" : "error_tick";
}
- else if (tick.gcode == PausePrintCode)
+ else if (tick.type == PausePrint)
icon_name = focused_tick ? "pause_print_f" : "pause_print";
else
icon_name = focused_tick ? "edit_gcode_f" : "edit_gcode";
// Draw icon for "Pause print", "Custom Gcode" or conflict tick
- if (!icon_name.empty())
- {
+ if (!icon_name.empty()) {
wxBitmap icon = create_scaled_bitmap(icon_name);
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;
@@ -679,7 +799,7 @@ std::string Control::get_color_for_tool_change_tick(std::set<TickCode>::const_it
auto it_n = it;
while (it_n != m_ticks.ticks.begin()) {
--it_n;
- if (it_n->gcode == ColorChangeCode && it_n->extruder == current_extruder)
+ if (it_n->type == ColorChange && it_n->extruder == current_extruder)
return it_n->color;
}
@@ -693,13 +813,13 @@ std::string Control::get_color_for_color_change_tick(std::set<TickCode>::const_i
bool is_tool_change = false;
while (it_n != m_ticks.ticks.begin()) {
--it_n;
- if (it_n->gcode == ToolChangeCode) {
+ if (it_n->type == ToolChange) {
is_tool_change = true;
if (it_n->extruder == it->extruder)
return it->color;
break;
}
- if (it_n->gcode == ColorChangeCode && it_n->extruder == it->extruder)
+ if (it_n->type == ColorChange && it_n->extruder == it->extruder)
return it->color;
}
if (!is_tool_change && it->extruder == def_extruder)
@@ -737,28 +857,31 @@ void Control::draw_colored_band(wxDC& dc)
wxRect main_band = get_colored_band_rect();
// don't color a band for MultiExtruder mode
- if (m_ticks.empty() || m_mode == t_mode::MultiExtruder)
- {
+ if (m_ticks.empty() || m_mode == MultiExtruder) {
+#ifdef _WIN32
+ draw_band(dc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), main_band);
+#else
draw_band(dc, GetParent()->GetBackgroundColour(), main_band);
+#endif // _WIN32
return;
}
- const int default_color_idx = m_mode==t_mode::MultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0;
+ const int default_color_idx = m_mode==MultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0;
draw_band(dc, wxColour(m_extruder_colors[default_color_idx]), main_band);
std::set<TickCode>::const_iterator tick_it = m_ticks.ticks.begin();
while (tick_it != m_ticks.ticks.end())
{
- if ( (m_mode == t_mode::SingleExtruder && tick_it->gcode == ColorChangeCode ) ||
- (m_mode == t_mode::MultiAsSingle && (tick_it->gcode == ToolChangeCode || tick_it->gcode == ColorChangeCode)) )
+ if ( (m_mode == SingleExtruder && tick_it->type == ColorChange ) ||
+ (m_mode == MultiAsSingle && (tick_it->type == ToolChange || tick_it->type == ColorChange)) )
{
const wxCoord pos = get_position_from_value(tick_it->tick);
is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) :
main_band.SetBottom(pos - 1);
- const std::string clr_str = m_mode == t_mode::SingleExtruder ? tick_it->color :
- tick_it->gcode == ToolChangeCode ?
+ const std::string clr_str = m_mode == SingleExtruder ? tick_it->color :
+ tick_it->type == ToolChange ?
get_color_for_tool_change_tick(tick_it) :
get_color_for_color_change_tick(tick_it);
@@ -769,8 +892,141 @@ void Control::draw_colored_band(wxDC& dc)
}
}
+void Control::Ruler::update(wxWindow* win, const std::vector<double>& values, double scroll_step)
+{
+ int DPI = GUI::get_dpi_for_window(win);
+ int pixels_per_sm = lround((double)(DPI) * 5.0/25.4);
+
+ if (lround(scroll_step) > pixels_per_sm) {
+ long_step = -1.0;
+ return;
+ }
+
+ int pow = -2;
+ int step = 0;
+ auto end_it = count == 1 ? values.end() : values.begin() + lround(values.size() / count);
+
+ while (pow < 3) {
+ int tick = 0;
+ for (int istep : {1, 2, 5}) {
+ double val = (double)istep * std::pow(10,pow);
+ auto val_it = std::lower_bound(values.begin(), end_it, val - epsilon());
+
+ if (val_it == values.end())
+ break;
+ int tick = val_it - values.begin();
+
+ // find next tick with istep
+ val *= 2;
+ val_it = std::lower_bound(values.begin(), end_it, val - epsilon());
+ // count of short ticks between ticks
+ int short_ticks_cnt = val_it == values.end() ? tick : val_it - values.begin() - tick;
+
+ if (lround(short_ticks_cnt * scroll_step) > pixels_per_sm) {
+ step = istep;
+ // there couldn't be more then 10 short ticks between ticks
+ short_step = 0.1 * short_ticks_cnt;
+ break;
+ }
+ }
+ if (step > 0)
+ break;
+ pow++;
+ }
+
+ long_step = step == 0 ? -1.0 : (double)step* std::pow(10, pow);
+}
+
+void Control::draw_ruler(wxDC& dc)
+{
+ m_ruler.update(this->GetParent(), m_values, get_scroll_step());
+
+ int height, width;
+ get_size(&width, &height);
+ const wxCoord mid = is_horizontal() ? 0.5 * height : 0.5 * width;
+
+ dc.SetPen(GREY_PEN);
+ wxColour old_clr = dc.GetTextForeground();
+ dc.SetTextForeground(GREY_PEN.GetColour());
+
+ if (m_ruler.long_step < 0)
+ for (int tick = 1; tick < m_values.size(); tick++) {
+ wxCoord pos = get_position_from_value(tick);
+ draw_ticks_pair(dc, pos, mid, 5);
+ draw_tick_text(dc, wxPoint(mid, pos), tick);
+ }
+ else {
+ auto draw_short_ticks = [this, mid](wxDC& dc, double& current_tick, int max_tick) {
+ while (current_tick < max_tick) {
+ wxCoord pos = get_position_from_value(lround(current_tick));
+ draw_ticks_pair(dc, pos, mid, 2);
+ current_tick += m_ruler.short_step;
+ if (current_tick > m_max_value)
+ break;
+ }
+ };
+
+ double short_tick;
+ int tick = 0;
+ double value = 0.0;
+ int sequence = 0;
+
+ int prev_y_pos = -1;
+ wxCoord label_height = dc.GetMultiLineTextExtent("0").y - 2;
+ int values_size = (int)m_values.size();
+
+ while (tick <= m_max_value) {
+ value += m_ruler.long_step;
+ if (value > m_values.back() && sequence < m_ruler.count) {
+ value = m_ruler.long_step;
+ for (; tick < values_size; tick++)
+ if (m_values[tick] < value)
+ break;
+ // short ticks from the last tick to the end of current sequence
+ draw_short_ticks(dc, short_tick, tick);
+ sequence++;
+ }
+ short_tick = tick;
+
+ for (; tick < values_size; tick++) {
+ if (m_values[tick] == value)
+ break;
+ if (m_values[tick] > value) {
+ if (tick > 0)
+ tick--;
+ break;
+ }
+ }
+ if (tick > m_max_value)
+ break;
+
+ wxCoord pos = get_position_from_value(tick);
+ draw_ticks_pair(dc, pos, mid, 5);
+ if (prev_y_pos < 0 || prev_y_pos - pos >= label_height) {
+ draw_tick_text(dc, wxPoint(mid, pos), tick);
+ prev_y_pos = pos;
+ }
+
+ draw_short_ticks(dc, short_tick, tick);
+
+ if (value == m_values.back() && sequence < m_ruler.count) {
+ value = 0.0;
+ sequence++;
+ tick++;
+ }
+ }
+ // short ticks from the last tick to the end
+ draw_short_ticks(dc, short_tick, m_max_value);
+ }
+
+ dc.SetTextForeground(old_clr);
+}
+
void Control::draw_one_layer_icon(wxDC& dc)
{
+ if (m_draw_mode == dmSequentialGCodeView)
+ return;
+
const wxBitmap& icon = m_is_one_layer ?
m_focus == fiOneLayerIcon ? m_bmp_one_layer_lock_off.bmp() : m_bmp_one_layer_lock_on.bmp() :
m_focus == fiOneLayerIcon ? m_bmp_one_layer_unlock_off.bmp() : m_bmp_one_layer_unlock_on.bmp();
@@ -808,12 +1064,21 @@ void Control::draw_revert_icon(wxDC& dc)
void Control::draw_cog_icon(wxDC& dc)
{
+ if (m_draw_mode == dmSequentialGCodeView)
+ 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;
+ if (m_draw_mode == dmSequentialGCodeView) {
+ is_horizontal() ? x_draw = width - 2 : x_draw = 0.5 * width - 0.5 * m_cog_icon_dim;
+ is_horizontal() ? y_draw = 0.5 * height - 0.5 * m_cog_icon_dim : y_draw = height - 2;
+ }
+ else {
+ 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);
@@ -821,9 +1086,12 @@ void Control::draw_cog_icon(wxDC& dc)
m_rect_cog_icon = wxRect(x_draw, y_draw, m_cog_icon_dim, m_cog_icon_dim);
}
-void Control::update_thumb_rect(const wxCoord& begin_x, const wxCoord& begin_y, const SelectedSlider& selection)
+void Control::update_thumb_rect(const wxCoord begin_x, const wxCoord begin_y, const SelectedSlider& selection)
{
- const wxRect& rect = wxRect(begin_x, begin_y + (selection == ssLower ? int(m_thumb_size.y * 0.5) : 0), m_thumb_size.x, int(m_thumb_size.y*0.5));
+ const wxRect rect = is_horizontal() ?
+ wxRect(begin_x + (selection == ssHigher ? m_thumb_size.x / 2 : 0), begin_y, m_thumb_size.x / 2, m_thumb_size.y) :
+ wxRect(begin_x, begin_y + (selection == ssLower ? m_thumb_size.y / 2 : 0), m_thumb_size.x, m_thumb_size.y / 2);
+
if (selection == ssLower)
m_rect_lower_thumb = rect;
else
@@ -841,10 +1109,17 @@ int Control::get_value_from_position(const wxCoord x, const wxCoord y)
return int(m_min_value + double(height - SLIDER_MARGIN - y) / step + 0.5);
}
+bool Control::is_lower_thumb_editable()
+{
+ if (m_draw_mode == dmSequentialGCodeView)
+ return Slic3r::GUI::get_app_config()->get("seq_top_layer_only") == "0";
+ return true;
+}
+
bool Control::detect_selected_slider(const wxPoint& pt)
{
if (is_point_in_rect(pt, m_rect_lower_thumb))
- m_selection = ssLower;
+ m_selection = is_lower_thumb_editable() ? ssLower : ssUndef;
else if(is_point_in_rect(pt, m_rect_higher_thumb))
m_selection = ssHigher;
else
@@ -904,8 +1179,7 @@ void Control::OnLeftDown(wxMouseEvent& event)
m_mouse = maOneLayerIconClick;
else if (is_point_in_rect(pos, m_rect_cog_icon))
m_mouse = maCogIconClick;
- else if (m_draw_mode == dmRegular)
- {
+ else if (m_draw_mode == dmRegular) {
if (is_point_in_rect(pos, m_rect_tick_action)) {
auto it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
m_mouse = it == m_ticks.ticks.end() ? maAddTick : maDeleteTick;
@@ -947,17 +1221,24 @@ wxString Control::get_tooltip(int tick/*=-1*/)
if (m_focus == fiNone)
return "";
if (m_focus == fiOneLayerIcon)
- return _(L("One layer mode"));
+ return _L("One layer mode");
if (m_focus == fiRevertIcon)
- return _(L("Discard all custom changes"));
+ return _L("Discard all custom changes");
if (m_focus == fiCogIcon)
- return m_mode == t_mode::MultiAsSingle ?
- GUI::from_u8((boost::format(_utf8(L("Jump to height %s or "
- "Set extruder sequence for the entire print"))) % " (Shift + G)\n").str()) :
- _(L("Jump to height")) + " (Shift + G)";
+ {
+ if (m_draw_mode == dmSequentialGCodeView)
+ return _L("Jump to move") + " (Shift + G)";
+ else
+ return m_mode == MultiAsSingle ?
+ GUI::from_u8((boost::format(_u8L("Jump to height %s\n"
+ "Set ruler mode\n"
+ "or Set extruder sequence for the entire print")) % "(Shift + G)").str()) :
+ GUI::from_u8((boost::format(_u8L("Jump to height %s\n"
+ "or Set ruler mode")) % "(Shift + G)").str());
+ }
if (m_focus == fiColorBand)
- return m_mode != t_mode::SingleExtruder ? "" :
- _(L("Edit current color - Right click the colored slider segment"));
+ return m_mode != SingleExtruder ? "" :
+ _L("Edit current color - Right click the colored slider segment");
if (m_draw_mode == dmSlaPrint)
return ""; // no drawn ticks and no tooltips for them in SlaPrinting mode
@@ -967,10 +1248,10 @@ wxString Control::get_tooltip(int tick/*=-1*/)
if (tick_code_it == m_ticks.ticks.end() && m_focus == fiActionIcon) // tick doesn't exist
{
// Show mode as a first string of tooltop
- tooltip = " " + _(L("Print mode")) + ": ";
- tooltip += (m_mode == t_mode::SingleExtruder ? CustomGCode::SingleExtruderMode :
- m_mode == t_mode::MultiAsSingle ? CustomGCode::MultiAsSingleMode :
- CustomGCode::MultiExtruderMode );
+ tooltip = " " + _L("Print mode") + ": ";
+ tooltip += (m_mode == SingleExtruder ? SingleExtruderMode :
+ m_mode == MultiAsSingle ? MultiAsSingleMode :
+ MultiExtruderMode );
tooltip += "\n\n";
/* Note: just on OSX!!!
@@ -980,68 +1261,70 @@ wxString Control::get_tooltip(int tick/*=-1*/)
* */
// Show list of actions with new tick
- tooltip += ( m_mode == t_mode::MultiAsSingle ?
- _(L("Add extruder change - Left click")) :
- m_mode == t_mode::SingleExtruder ?
- _(L("Add color change - Left click for predefined color or "
- "Shift + Left click for custom color selection")) :
- _(L("Add color change - Left click")) ) + " " +
- _(L("or press \"+\" key")) + "\n" + (
- is_osx ?
- _(L("Add another code - Ctrl + Left click")) :
- _(L("Add another code - Right click")) );
+ tooltip += ( m_mode == MultiAsSingle ?
+ _L("Add extruder change - Left click") :
+ m_mode == SingleExtruder ?
+ _L("Add color change - Left click for predefined color or "
+ "Shift + Left click for custom color selection") :
+ _L("Add color change - Left click") ) + " " +
+ _L("or press \"+\" key") + "\n" + (
+ is_osx ?
+ _L("Add another code - Ctrl + Left click") :
+ _L("Add another code - Right click") );
}
if (tick_code_it != m_ticks.ticks.end()) // tick exists
{
if (m_draw_mode == dmSequentialFffPrint)
- return _(L("The sequential print is on.\n"
+ return _L("The sequential print is on.\n"
"It's impossible to apply any custom G-code for objects printing sequentually.\n"
- "This code won't be processed during G-code generation."));
-
+ "This code won't be processed during G-code generation.");
+
// Show custom Gcode as a first string of tooltop
tooltip = " ";
- tooltip += tick_code_it->gcode == ColorChangeCode ? ( m_mode == t_mode::SingleExtruder ?
- from_u8((boost::format(_utf8(L("Color change (\"%1%\")"))) % tick_code_it->gcode ).str()) :
- from_u8((boost::format(_utf8(L("Color change (\"%1%\") for Extruder %2%"))) %
- tick_code_it->gcode % tick_code_it->extruder).str()) ) :
- tick_code_it->gcode == PausePrintCode ?
- from_u8((boost::format(_utf8(L("Pause print (\"%1%\")"))) % tick_code_it->gcode ).str()) :
- tick_code_it->gcode == ToolChangeCode ?
- from_u8((boost::format(_utf8(L("Extruder (tool) is changed to Extruder \"%1%\""))) %
- tick_code_it->extruder ).str()) :
- from_u8(tick_code_it->gcode);
+ tooltip +=
+ tick_code_it->type == ColorChange ?
+ (m_mode == SingleExtruder ?
+ format_wxstr(_L("Color change (\"%1%\")"), gcode(ColorChange)) :
+ format_wxstr(_L("Color change (\"%1%\") for Extruder %2%"), gcode(ColorChange), tick_code_it->extruder)) :
+ tick_code_it->type == PausePrint ?
+ format_wxstr(_L("Pause print (\"%1%\")"), gcode(PausePrint)) :
+ tick_code_it->type == Template ?
+ format_wxstr(_L("Custom template (\"%1%\")"), gcode(Template)) :
+ tick_code_it->type == ToolChange ?
+ format_wxstr(_L("Extruder (tool) is changed to Extruder \"%1%\""), tick_code_it->extruder) :
+ from_u8(tick_code_it->extra);// tick_code_it->type == Custom
// If tick is marked as a conflict (exclamation icon),
// we should to explain why
ConflictType conflict = m_ticks.is_conflict_tick(*tick_code_it, m_mode, m_only_extruder, m_values[tick]);
if (conflict != ctNone)
- tooltip += "\n\n" + _(L("Note")) + "! ";
+ tooltip += "\n\n" + _L("Note") + "! ";
if (conflict == ctModeConflict)
- tooltip += _(L("G-code associated to this tick mark is in a conflict with print mode.\n"
- "Editing it will cause changes of Slider data."));
+ tooltip += _L("G-code associated to this tick mark is in a conflict with print mode.\n"
+ "Editing it will cause changes of Slider data.");
else if (conflict == ctMeaninglessColorChange)
- tooltip += _(L("There is a color change for extruder that won't be used till the end of print job.\n"
- "This code won't be processed during G-code generation."));
+ tooltip += _L("There is a color change for extruder that won't be used till the end of print job.\n"
+ "This code won't be processed during G-code generation.");
else if (conflict == ctMeaninglessToolChange)
- tooltip += _(L("There is an extruder change set to the same extruder.\n"
- "This code won't be processed during G-code generation."));
+ tooltip += _L("There is an extruder change set to the same extruder.\n"
+ "This code won't be processed during G-code generation.");
else if (conflict == ctRedundant)
- tooltip += _(L("There is a color change for extruder that has not been used before.\n"
- "Check your settings to avoid redundant color changes."));
+ tooltip += _L("There is a color change for extruder that has not been used before.\n"
+ "Check your settings to avoid redundant color changes.");
// Show list of actions with existing tick
if (m_focus == fiActionIcon)
- tooltip += "\n\n" + _(L("Delete tick mark - Left click or press \"-\" key")) + "\n" + (
+ tooltip += "\n\n" + _L("Delete tick mark - Left click or press \"-\" key") + "\n" + (
is_osx ?
- _(L("Edit tick mark - Ctrl + Left click")) :
- _(L("Edit tick mark - Right click")) );
+ _L("Edit tick mark - Ctrl + Left click") :
+ _L("Edit tick mark - Right click") );
}
return tooltip;
}
-int Control::get_edited_tick_for_position(const wxPoint pos, const std::string& gcode /*= ColorChangeCode*/)
+int Control::get_edited_tick_for_position(const wxPoint pos, Type type /*= ColorChange*/)
{
if (m_ticks.empty())
return -1;
@@ -1051,7 +1334,7 @@ int Control::get_edited_tick_for_position(const wxPoint pos, const std::string&
while (it != m_ticks.ticks.begin()) {
--it;
- if (it->gcode == gcode)
+ if (it->type == type)
return it->tick;
}
@@ -1065,8 +1348,7 @@ void Control::OnMotion(wxMouseEvent& event)
const wxPoint pos = event.GetLogicalPosition(wxClientDC(this));
int tick = -1;
- if (!m_is_left_down && !m_is_right_down)
- {
+ if (!m_is_left_down && !m_is_right_down) {
if (is_point_in_rect(pos, m_rect_one_layer_icon))
m_focus = fiOneLayerIcon;
else if (is_point_in_rect(pos, m_rect_tick_action)) {
@@ -1077,9 +1359,13 @@ void Control::OnMotion(wxMouseEvent& event)
m_focus = fiRevertIcon;
else if (is_point_in_rect(pos, m_rect_cog_icon))
m_focus = fiCogIcon;
- else if (m_mode == t_mode::SingleExtruder && is_point_in_rect(pos, get_colored_band_rect()) &&
+ else if (m_mode == SingleExtruder && is_point_in_rect(pos, get_colored_band_rect()) &&
get_edited_tick_for_position(pos) >= 0 )
m_focus = fiColorBand;
+ else if (is_point_in_rect(pos, m_rect_lower_thumb))
+ m_focus = fiLowerThumb;
+ else if (is_point_in_rect(pos, m_rect_higher_thumb))
+ m_focus = fiHigherThumb;
else {
m_focus = fiTick;
tick = get_tick_near_point(pos);
@@ -1108,8 +1394,7 @@ void Control::OnMotion(wxMouseEvent& event)
// Set tooltips with information for each icon
this->SetToolTip(get_tooltip(tick));
- if (action)
- {
+ if (action) {
wxCommandEvent e(wxEVT_SCROLL_CHANGED);
e.SetEventObject(this);
e.SetString("moving");
@@ -1120,35 +1405,33 @@ void Control::OnMotion(wxMouseEvent& event)
void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current_code/* = false*/)
{
const int extruders_cnt = GUI::wxGetApp().extruders_edited_cnt();
- if (extruders_cnt > 1)
- {
+ if (extruders_cnt > 1) {
std::array<int, 2> active_extruders = get_active_extruders_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
std::vector<wxBitmap*> icons = get_extruder_color_icons(true);
wxMenu* change_extruder_menu = new wxMenu();
- for (int i = 1; i <= extruders_cnt; i++)
- {
+ for (int i = 1; i <= extruders_cnt; i++) {
const bool is_active_extruder = i == active_extruders[0] || i == active_extruders[1];
- const wxString item_name = wxString::Format(_(L("Extruder %d")), i) +
- (is_active_extruder ? " (" + _(L("active")) + ")" : "");
+ const wxString item_name = wxString::Format(_L("Extruder %d"), i) +
+ (is_active_extruder ? " (" + _L("active") + ")" : "");
- if (m_mode == t_mode::MultiAsSingle)
+ if (m_mode == MultiAsSingle)
append_menu_item(change_extruder_menu, wxID_ANY, item_name, "",
- [this, i](wxCommandEvent&) { add_code_as_tick(ToolChangeCode, i); }, *icons[i-1], menu,
+ [this, i](wxCommandEvent&) { add_code_as_tick(ToolChange, i); }, *icons[i-1], menu,
[is_active_extruder]() { return !is_active_extruder; }, GUI::wxGetApp().plater());
}
- const wxString change_extruder_menu_name = m_mode == t_mode::MultiAsSingle ?
- (switch_current_code ? _(L("Switch code to Change extruder")) : _(L("Change extruder")) ) :
- _(L("Change extruder (N/A)"));
+ const wxString change_extruder_menu_name = m_mode == MultiAsSingle ?
+ (switch_current_code ? _L("Switch code to Change extruder") : _L("Change extruder") ) :
+ _L("Change extruder (N/A)");
- wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _(L("Use another extruder")));
+ wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _L("Use another extruder"));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(active_extruders[1] > 0 ? "edit_uni" : "change_extruder"));
GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) {
- enable_menu_item(evt, [this]() {return m_mode == t_mode::MultiAsSingle; }, change_extruder_menu_item, this); },
+ enable_menu_item(evt, [this]() {return m_mode == MultiAsSingle; }, change_extruder_menu_item, this); },
change_extruder_menu_item->GetId());
}
}
@@ -1156,28 +1439,26 @@ void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current
void Control::append_add_color_change_menu_item(wxMenu* menu, bool switch_current_code/* = false*/)
{
const int extruders_cnt = GUI::wxGetApp().extruders_edited_cnt();
- if (extruders_cnt > 1)
- {
+ if (extruders_cnt > 1) {
int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
std::set<int> used_extruders_for_tick = m_ticks.get_used_extruders_for_tick(tick, m_only_extruder, m_values[tick]);
wxMenu* add_color_change_menu = new wxMenu();
- for (int i = 1; i <= extruders_cnt; i++)
- {
+ for (int i = 1; i <= extruders_cnt; i++) {
const bool is_used_extruder = used_extruders_for_tick.empty() ? true : // #ys_FIXME till used_extruders_for_tick doesn't filled correct for mmMultiExtruder
used_extruders_for_tick.find(i) != used_extruders_for_tick.end();
- const wxString item_name = wxString::Format(_(L("Extruder %d")), i) +
- (is_used_extruder ? " (" + _(L("used")) + ")" : "");
+ const wxString item_name = wxString::Format(_L("Extruder %d"), i) +
+ (is_used_extruder ? " (" + _L("used") + ")" : "");
append_menu_item(add_color_change_menu, wxID_ANY, item_name, "",
- [this, i](wxCommandEvent&) { add_code_as_tick(ColorChangeCode, i); }, "", menu,
+ [this, i](wxCommandEvent&) { add_code_as_tick(ColorChange, i); }, "", menu,
[]() { return true; }, GUI::wxGetApp().plater());
}
const wxString menu_name = switch_current_code ?
- from_u8((boost::format(_utf8(L("Switch code to Color change (%1%) for:"))) % ColorChangeCode).str()) :
- from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % ColorChangeCode).str());
+ format_wxstr(_L("Switch code to Color change (%1%) for:"), gcode(ColorChange)) :
+ format_wxstr(_L("Add color change (%1%) for:"), gcode(ColorChange));
wxMenuItem* add_color_change_menu_item = menu->AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap("colorchange_add_m"));
}
@@ -1201,10 +1482,7 @@ void Control::OnLeftUp(wxMouseEvent& event)
add_current_tick();
break;
case maCogIconClick :
- if (m_mode == t_mode::MultiAsSingle && m_draw_mode == dmRegular)
- show_cog_icon_context_menu();
- else
- jump_to_print_z();
+ show_cog_icon_context_menu();
break;
case maOneLayerIconClick:
switch_one_layer_mode();
@@ -1243,6 +1521,19 @@ void Control::move_current_thumb(const bool condition)
if (is_horizontal())
delta *= -1;
+ // accelerators
+ int accelerator = 0;
+ if (wxGetKeyState(WXK_SHIFT))
+ accelerator += 5;
+ if (wxGetKeyState(WXK_CONTROL))
+ accelerator += 5;
+ if (accelerator > 0)
+ delta *= accelerator;
+
+#if ENABLE_ARROW_KEYS_WITH_SLIDERS
+ if (m_selection == ssUndef) m_selection = ssHigher;
+#endif // ENABLE_ARROW_KEYS_WITH_SLIDERS
+
if (m_selection == ssLower) {
m_lower_value -= delta;
correct_lower_value();
@@ -1262,8 +1553,7 @@ void Control::move_current_thumb(const bool condition)
void Control::OnWheel(wxMouseEvent& event)
{
// Set nearest to the mouse thumb as a selected, if there is not selected thumb
- if (m_selection == ssUndef)
- {
+ if (m_selection == ssUndef) {
const wxPoint& pt = event.GetLogicalPosition(wxClientDC(this));
if (is_horizontal())
@@ -1276,42 +1566,73 @@ void Control::OnWheel(wxMouseEvent& event)
ssLower : ssHigher;
}
- move_current_thumb(event.GetWheelRotation() > 0);
+ if (m_selection == ssLower && !is_lower_thumb_editable())
+ m_selection = ssUndef;
+
+ move_current_thumb((m_draw_mode == dmSequentialGCodeView) ? event.GetWheelRotation() < 0 : event.GetWheelRotation() > 0);
}
void Control::OnKeyDown(wxKeyEvent &event)
{
const int key = event.GetKeyCode();
- if (key == WXK_NUMPAD_ADD) {
+ if (m_draw_mode != dmSequentialGCodeView && key == WXK_NUMPAD_ADD) {
// OnChar() is called immediately after OnKeyDown(), which can cause call of add_tick() twice.
// To avoid this case we should suppress second add_tick() call.
m_ticks.suppress_plus(true);
add_current_tick(true);
}
- else if (key == 390 || key == WXK_DELETE || key == WXK_BACK) {
+ else if (m_draw_mode != dmSequentialGCodeView && (key == WXK_NUMPAD_SUBTRACT || key == WXK_DELETE || key == WXK_BACK)) {
// OnChar() is called immediately after OnKeyDown(), which can cause call of delete_tick() twice.
// To avoid this case we should suppress second delete_tick() call.
m_ticks.suppress_minus(true);
delete_current_tick();
}
- else if (event.GetKeyCode() == WXK_SHIFT)
+ else if (m_draw_mode != dmSequentialGCodeView && event.GetKeyCode() == WXK_SHIFT)
UseDefaultColors(false);
- else if (is_horizontal())
- {
- if (key == WXK_LEFT || key == WXK_RIGHT)
- move_current_thumb(key == WXK_LEFT);
- else if (key == WXK_UP || key == WXK_DOWN) {
- m_selection = key == WXK_UP ? ssHigher : ssLower;
- Refresh();
+ else if (is_horizontal()) {
+ if (m_is_focused) {
+ if (key == WXK_LEFT || key == WXK_RIGHT)
+ move_current_thumb(key == WXK_LEFT);
+ else if (key == WXK_UP || key == WXK_DOWN) {
+#if ENABLE_ARROW_KEYS_WITH_SLIDERS
+ if (key == WXK_DOWN)
+ m_selection = ssHigher;
+ else if (key == WXK_UP && is_lower_thumb_editable())
+ m_selection = ssLower;
+#else
+ if (key == WXK_UP)
+ m_selection = ssHigher;
+ else if (key == WXK_DOWN && is_lower_thumb_editable())
+ m_selection = ssLower;
+#endif // ENABLE_ARROW_KEYS_WITH_SLIDERS
+ Refresh();
+ }
+ }
+#if ENABLE_ARROW_KEYS_WITH_SLIDERS
+ else {
+ if (key == WXK_LEFT || key == WXK_RIGHT)
+ move_current_thumb(key == WXK_LEFT);
}
+#endif // ENABLE_ARROW_KEYS_WITH_SLIDERS
}
else {
- if (key == WXK_LEFT || key == WXK_RIGHT) {
- m_selection = key == WXK_LEFT ? ssHigher : ssLower;
- Refresh();
+ if (m_is_focused) {
+ if (key == WXK_LEFT || key == WXK_RIGHT) {
+ if (key == WXK_LEFT)
+ m_selection = ssHigher;
+ else if (key == WXK_RIGHT && is_lower_thumb_editable())
+ m_selection = ssLower;
+ Refresh();
+ }
+ else if (key == WXK_UP || key == WXK_DOWN)
+ move_current_thumb(key == WXK_UP);
+ }
+#if ENABLE_ARROW_KEYS_WITH_SLIDERS
+ else {
+ if (key == WXK_UP || key == WXK_DOWN)
+ move_current_thumb(key == WXK_UP);
}
- else if (key == WXK_UP || key == WXK_DOWN)
- move_current_thumb(key == WXK_UP);
+#endif // ENABLE_ARROW_KEYS_WITH_SLIDERS
}
event.Skip(); // !Needed to have EVT_CHAR generated as well
@@ -1332,16 +1653,18 @@ void Control::OnKeyUp(wxKeyEvent &event)
void Control::OnChar(wxKeyEvent& event)
{
const int key = event.GetKeyCode();
- if (key == '+' && !m_ticks.suppressed_plus()) {
- add_current_tick(true);
- m_ticks.suppress_plus(false);
- }
- else if (key == '-' && !m_ticks.suppressed_minus()) {
- delete_current_tick();
- m_ticks.suppress_minus(false);
+ if (m_draw_mode != dmSequentialGCodeView) {
+ if (key == '+' && !m_ticks.suppressed_plus()) {
+ add_current_tick(true);
+ m_ticks.suppress_plus(false);
+ }
+ else if (key == '-' && !m_ticks.suppressed_minus()) {
+ delete_current_tick();
+ m_ticks.suppress_minus(false);
+ }
}
if (key == 'G')
- jump_to_print_z();
+ jump_to_value();
}
void Control::OnRightDown(wxMouseEvent& event)
@@ -1353,15 +1676,14 @@ void Control::OnRightDown(wxMouseEvent& event)
m_mouse = maNone;
if (m_draw_mode == dmRegular) {
- if (is_point_in_rect(pos, m_rect_tick_action))
- {
+ if (is_point_in_rect(pos, m_rect_tick_action)) {
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
m_mouse = m_ticks.ticks.find(TickCode{ tick }) == m_ticks.ticks.end() ?
maAddMenu : maEditMenu;
}
- else if (m_mode == t_mode::SingleExtruder && !detect_selected_slider(pos) && is_point_in_rect(pos, get_colored_band_rect()))
+ else if (m_mode == SingleExtruder && !detect_selected_slider(pos) && is_point_in_rect(pos, get_colored_band_rect()))
m_mouse = maForceColorEdit;
- else if (m_mode == t_mode::MultiAsSingle && is_point_in_rect(pos, m_rect_cog_icon))
+ else if (m_mode == MultiAsSingle && is_point_in_rect(pos, m_rect_cog_icon))
m_mouse = maCogIconMenu;
}
if (m_mouse != maNone || !detect_selected_slider(pos))
@@ -1382,11 +1704,11 @@ void Control::OnRightDown(wxMouseEvent& event)
// Get active extruders for tick.
// Means one current extruder for not existing tick OR
-// 2 extruders - for existing tick (extruder before ToolChangeCode and extruder of current existing tick)
+// 2 extruders - for existing tick (extruder before ToolChange and extruder of current existing tick)
// Use those values to disable selection of active extruders
std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
{
- int default_initial_extruder = m_mode == t_mode::MultiAsSingle ? std::max<int>(1, m_only_extruder) : 1;
+ int default_initial_extruder = m_mode == MultiAsSingle ? std::max<int>(1, m_only_extruder) : 1;
std::array<int, 2> extruders = { default_initial_extruder, -1 };
if (m_ticks.empty())
return extruders;
@@ -1398,7 +1720,7 @@ std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
while (it != m_ticks.ticks.begin()) {
--it;
- if(it->gcode == ToolChangeCode) {
+ if(it->type == ToolChange) {
extruders[0] = it->extruder;
break;
}
@@ -1409,12 +1731,11 @@ std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
// Get used extruders for tick.
// Means all extruders(tools) which will be used during printing from current tick to the end
-std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extruder, double print_z, t_mode force_mode/* = t_mode::Undef*/) const
+std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extruder, double print_z, Mode force_mode/* = Undef*/) const
{
- t_mode e_mode = !force_mode ? mode : force_mode;
+ Mode e_mode = !force_mode ? mode : force_mode;
- if (e_mode == t_mode::MultiExtruder)
- {
+ if (e_mode == MultiExtruder) {
// #ys_FIXME: get tool ordering from _correct_ place
const ToolOrdering& tool_ordering = GUI::wxGetApp().plater()->fff_print().get_tool_ordering();
@@ -1424,8 +1745,7 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
std::set<int> used_extruders;
auto it_layer_tools = std::lower_bound(tool_ordering.begin(), tool_ordering.end(), LayerTools(print_z));
- for (; it_layer_tools != tool_ordering.end(); ++it_layer_tools)
- {
+ for (; it_layer_tools != tool_ordering.end(); ++it_layer_tools) {
const std::vector<unsigned>& extruders = it_layer_tools->extruders;
for (const auto& extruder : extruders)
used_extruders.emplace(extruder+1);
@@ -1434,15 +1754,15 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
return used_extruders;
}
- const int default_initial_extruder = e_mode == t_mode::MultiAsSingle ? std::max(only_extruder, 1) : 1;
- if (ticks.empty() || e_mode == t_mode::SingleExtruder)
+ const int default_initial_extruder = e_mode == MultiAsSingle ? std::max(only_extruder, 1) : 1;
+ if (ticks.empty() || e_mode == SingleExtruder)
return {default_initial_extruder};
std::set<int> used_extruders;
auto it_start = ticks.lower_bound(TickCode{tick});
auto it = it_start;
- if (it == ticks.begin() && it->gcode == ToolChangeCode &&
+ if (it == ticks.begin() && it->type == ToolChange &&
tick != it->tick ) // In case of switch of ToolChange to ColorChange, when tick exists,
// we shouldn't change color for extruder, which will be deleted
{
@@ -1453,7 +1773,7 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
while (it != ticks.begin()) {
--it;
- if (it->gcode == ToolChangeCode && tick != it->tick) {
+ if (it->type == ToolChange && tick != it->tick) {
used_extruders.emplace(it->extruder);
break;
}
@@ -1463,7 +1783,7 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
used_extruders.emplace(default_initial_extruder);
for (it = it_start; it != ticks.end(); ++it)
- if (it->gcode == ToolChangeCode && tick != it->tick)
+ if (it->type == ToolChange && tick != it->tick)
used_extruders.emplace(it->extruder);
return used_extruders;
@@ -1473,9 +1793,9 @@ void Control::show_add_context_menu()
{
wxMenu menu;
- if (m_mode == t_mode::SingleExtruder) {
- append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
- [this](wxCommandEvent&) { add_code_as_tick(ColorChangeCode); }, "colorchange_add_m", &menu);
+ if (m_mode == SingleExtruder) {
+ append_menu_item(&menu, wxID_ANY, _L("Add color change") + " (" + gcode(ColorChange) + ")", "",
+ [this](wxCommandEvent&) { add_code_as_tick(ColorChange); }, "colorchange_add_m", &menu);
UseDefaultColors(false);
}
@@ -1484,11 +1804,16 @@ void Control::show_add_context_menu()
append_add_color_change_menu_item(&menu);
}
- append_menu_item(&menu, wxID_ANY, _(L("Add pause print")) + " (M601)", "",
- [this](wxCommandEvent&) { add_code_as_tick(PausePrintCode); }, "pause_print", &menu);
+ if (!gcode(PausePrint).empty())
+ append_menu_item(&menu, wxID_ANY, _L("Add pause print") + " (" + gcode(PausePrint) + ")", "",
+ [this](wxCommandEvent&) { add_code_as_tick(PausePrint); }, "pause_print", &menu);
- append_menu_item(&menu, wxID_ANY, _(L("Add custom G-code")), "",
- [this](wxCommandEvent&) { add_code_as_tick(""); }, "edit_gcode", &menu);
+ if (!gcode(Template).empty())
+ append_menu_item(&menu, wxID_ANY, _L("Add custom template") + " (" + gcode(Template) + ")", "",
+ [this](wxCommandEvent&) { add_code_as_tick(Template); }, "edit_gcode", &menu);
+
+ append_menu_item(&menu, wxID_ANY, _L("Add custom G-code"), "",
+ [this](wxCommandEvent&) { add_code_as_tick(Custom); }, "edit_gcode", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu);
}
@@ -1499,24 +1824,24 @@ void Control::show_edit_context_menu()
std::set<TickCode>::iterator it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
- if (it->gcode == ToolChangeCode) {
- if (m_mode == t_mode::MultiAsSingle)
+ if (it->type == ToolChange) {
+ if (m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu);
append_add_color_change_menu_item(&menu, true);
}
else
- append_menu_item(&menu, wxID_ANY, it->gcode == ColorChangeCode ? _(L("Edit color")) :
- it->gcode == PausePrintCode ? _(L("Edit pause print message")) :
- _(L("Edit custom G-code")), "",
+ append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _L("Edit color") :
+ it->type == PausePrint ? _L("Edit pause print message") :
+ _L("Edit custom G-code"), "",
[this](wxCommandEvent&) { edit_tick(); }, "edit_uni", &menu);
- if (it->gcode == ColorChangeCode && m_mode == t_mode::MultiAsSingle)
+ if (it->type == ColorChange && m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu, true);
- append_menu_item(&menu, wxID_ANY, it->gcode == ColorChangeCode ? _(L("Delete color change")) :
- it->gcode == ToolChangeCode ? _(L("Delete tool change")) :
- it->gcode == PausePrintCode ? _(L("Delete pause print")) :
- _(L("Delete custom G-code")), "",
+ append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _L("Delete color change") :
+ it->type == ToolChange ? _L("Delete tool change") :
+ it->type == PausePrint ? _L("Delete pause print") :
+ _L("Delete custom G-code"), "",
[this](wxCommandEvent&) { delete_current_tick();}, "colorchange_del_f", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu);
@@ -1526,11 +1851,30 @@ void Control::show_cog_icon_context_menu()
{
wxMenu menu;
- append_menu_item(&menu, wxID_ANY, _(L("Jump to height")) + " (Shift+G)", "",
- [this](wxCommandEvent&) { jump_to_print_z(); }, "", &menu);
+ append_menu_item(&menu, wxID_ANY, _L("Jump to height") + " (Shift+G)", "",
+ [this](wxCommandEvent&) { jump_to_value(); }, "", & menu);
+
+ wxMenu* ruler_mode_menu = new wxMenu();
+ if (ruler_mode_menu) {
+ append_menu_check_item(ruler_mode_menu, wxID_ANY, _L("None"), _L("Hide ruler"),
+ [this](wxCommandEvent&) { if (m_extra_style != 0) m_extra_style = 0; }, ruler_mode_menu,
+ []() { return true; }, [this]() { return m_extra_style == 0; }, GUI::wxGetApp().plater());
+
+ append_menu_check_item(ruler_mode_menu, wxID_ANY, _L("Show object height"), _L("Show object height on the ruler"),
+ [this](wxCommandEvent&) { m_extra_style & wxSL_AUTOTICKS ? m_extra_style &= wxSL_AUTOTICKS : m_extra_style |= wxSL_AUTOTICKS; }, ruler_mode_menu,
+ []() { return true; }, [this]() { return m_extra_style & wxSL_AUTOTICKS; }, GUI::wxGetApp().plater());
- append_menu_item(&menu, wxID_ANY, _(L("Set extruder sequence for the entire print")), "",
- [this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu);
+ append_menu_check_item(ruler_mode_menu, wxID_ANY, _L("Show estimated print time"), _L("Show estimated print time on the ruler"),
+ [this](wxCommandEvent&) { m_extra_style & wxSL_VALUE_LABEL ? m_extra_style &= wxSL_VALUE_LABEL : m_extra_style |= wxSL_VALUE_LABEL; }, ruler_mode_menu,
+ []() { return true; }, [this]() { return m_extra_style & wxSL_VALUE_LABEL; }, GUI::wxGetApp().plater());
+
+ append_submenu(&menu, ruler_mode_menu, wxID_ANY, _L("Ruler mode"), _L("Set ruler mode"), "",
+ [this]() { return true; }, this);
+ }
+
+ if (m_mode == MultiAsSingle && m_draw_mode == dmRegular)
+ append_menu_item(&menu, wxID_ANY, _L("Set extruder sequence for the entire print"), "",
+ [this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu);
}
@@ -1542,8 +1886,7 @@ void Control::OnRightUp(wxMouseEvent& event)
this->ReleaseMouse();
m_is_right_down = m_is_one_layer = false;
- if (m_mouse == maForceColorEdit)
- {
+ if (m_mouse == maForceColorEdit) {
wxPoint pos = event.GetLogicalPosition(wxClientDC(this));
int edited_tick = get_edited_tick_for_position(pos);
if (edited_tick >= 0)
@@ -1596,17 +1939,18 @@ static void upgrade_text_entry_dialog(wxTextEntryDialog* dlg, double min = -1.0,
if (!textctrl)
return;
+ textctrl->SetInsertionPointEnd();
+
wxButton* btn_OK = static_cast<wxButton*>(dlg->FindWindowById(wxID_OK));
btn_OK->Bind(wxEVT_UPDATE_UI, [textctrl, min, max](wxUpdateUIEvent& evt)
{
bool disable = textctrl->IsEmpty();
- if (!disable && min >= 0.0 && max >= 0.0)
- {
+ if (!disable && min >= 0.0 && max >= 0.0) {
double value = -1.0;
if (!textctrl->GetValue().ToCDouble(&value)) // input value couldn't be converted to double
disable = true;
else
- disable = value < min || value > max; // is input value is out of valid range ?
+ disable = value < min - epsilon() || value > max + epsilon(); // is input value is out of valid range ?
}
evt.Enable(!disable);
@@ -1615,8 +1959,8 @@ static void upgrade_text_entry_dialog(wxTextEntryDialog* dlg, double min = -1.0,
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 G-code on current layer (%1% mm)."))) % height).str());
+ wxString msg_text = _L("Enter custom G-code used on current layer") + ":";
+ wxString msg_header = format_wxstr(_L("Custom G-code on current layer (%1% mm)."), height);
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, code_in,
@@ -1631,8 +1975,8 @@ static std::string get_custom_code(const std::string& code_in, double height)
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 when a print is paused"))) + ":";
- wxString msg_header = from_u8((boost::format(_utf8(L("Message for pause print on current layer (%1% mm)."))) % height).str());
+ wxString msg_text = _L("Enter short message shown on Printer display when a print is paused") + ":";
+ wxString msg_header = format_wxstr(_L("Message for pause print on current layer (%1% mm)."), height);
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, from_u8(msg_in),
@@ -1645,11 +1989,11 @@ static std::string get_pause_print_msg(const std::string& msg_in, double height)
return into_u8(dlg.GetValue());
}
-static double get_print_z_to_jump(double active_print_z, double min_z, double max_z)
+static double get_value_to_jump(double active_value, double min_z, double max_z, DrawMode mode)
{
- wxString msg_text = _(L("Enter the height you want to jump to")) + ":";
- wxString msg_header = _(L("Jump to height"));
- wxString msg_in = GUI::double_to_string(active_print_z);
+ wxString msg_text = (mode == dmSequentialGCodeView) ? _L("Enter the move you want to jump to") + ":" : _L("Enter the height you want to jump to") + ":";
+ wxString msg_header = (mode == dmSequentialGCodeView) ? _L("Jump to move") : _L("Jump to height");
+ wxString msg_in = GUI::double_to_string(active_value);
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, msg_in, wxTextEntryDialogStyle);
@@ -1662,32 +2006,35 @@ static double get_print_z_to_jump(double active_print_z, double min_z, double ma
return dlg.GetValue().ToCDouble(&value) ? value : -1.0;
}
-void Control::add_code_as_tick(std::string code, int selected_extruder/* = -1*/)
+void Control::add_code_as_tick(Type type, int selected_extruder/* = -1*/)
{
if (m_selection == ssUndef)
return;
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
- if ( !check_ticks_changed_event(code) )
+ if ( !check_ticks_changed_event(type) )
return;
+ if (type == ColorChange && gcode(ColorChange).empty())
+ GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::EmptyColorChangeCode);
+
const int extruder = selected_extruder > 0 ? selected_extruder : std::max<int>(1, m_only_extruder);
const auto it = m_ticks.ticks.find(TickCode{ tick });
if ( it == m_ticks.ticks.end() ) {
// try to add tick
- if (!m_ticks.add_tick(tick, code, extruder, m_values[tick]))
+ if (!m_ticks.add_tick(tick, type, extruder, m_values[tick]))
return;
}
- else if (code == ToolChangeCode || code == ColorChangeCode) {
- // try to switch tick code to ToolChangeCode or ColorChangeCode accordingly
- if (!m_ticks.switch_code_for_tick(it, code, extruder))
+ else if (type == ToolChange || type == ColorChange) {
+ // try to switch tick code to ToolChange or ColorChange accordingly
+ if (!m_ticks.switch_code_for_tick(it, type, extruder))
return;
}
else
return;
- post_ticks_changed_event(code);
+ post_ticks_changed_event(type);
}
void Control::add_current_tick(bool call_from_keyboard /*= false*/)
@@ -1698,16 +2045,16 @@ void Control::add_current_tick(bool call_from_keyboard /*= false*/)
auto it = m_ticks.ticks.find(TickCode{ tick });
if (it != m_ticks.ticks.end() || // this tick is already exist
- !check_ticks_changed_event(m_mode == t_mode::MultiAsSingle ? ToolChangeCode : ColorChangeCode))
+ !check_ticks_changed_event(m_mode == MultiAsSingle ? ToolChange : ColorChange))
return;
- if (m_mode == t_mode::SingleExtruder)
- add_code_as_tick(ColorChangeCode);
+ if (m_mode == SingleExtruder)
+ add_code_as_tick(ColorChange);
else
{
wxMenu menu;
- if (m_mode == t_mode::MultiAsSingle)
+ if (m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu);
else
append_add_color_change_menu_item(&menu);
@@ -1716,8 +2063,7 @@ void Control::add_current_tick(bool call_from_keyboard /*= false*/)
/* Menu position will be calculated from mouse click position, but...
* if function is called from keyboard (pressing "+"), we should to calculate it
* */
- if (call_from_keyboard)
- {
+ if (call_from_keyboard) {
int width, height;
get_size(&width, &height);
@@ -1740,12 +2086,12 @@ void Control::delete_current_tick()
auto it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
if (it == m_ticks.ticks.end() ||
- !check_ticks_changed_event(it->gcode))
+ !check_ticks_changed_event(it->type))
return;
- const std::string code = it->gcode;
+ Type type = it->type;
m_ticks.ticks.erase(it);
- post_ticks_changed_event(code);
+ post_ticks_changed_event(type);
}
void Control::edit_tick(int tick/* = -1*/)
@@ -1755,12 +2101,12 @@ void Control::edit_tick(int tick/* = -1*/)
const std::set<TickCode>::iterator it = m_ticks.ticks.find(TickCode{ tick });
if (it == m_ticks.ticks.end() ||
- !check_ticks_changed_event(it->gcode))
+ !check_ticks_changed_event(it->type))
return;
- const std::string code = it->gcode;
+ Type type = it->type;
if (m_ticks.edit_tick(it, m_values[it->tick]))
- post_ticks_changed_event(code);
+ post_ticks_changed_event(type);
}
// switch on/off one layer mode
@@ -1772,7 +2118,7 @@ void Control::switch_one_layer_mode()
SetHigherValue(m_max_value);
}
m_selection == ssLower ? correct_lower_value() : correct_higher_value();
- if (!m_selection) m_selection = ssHigher;
+ if (m_selection == ssUndef) m_selection = ssHigher;
}
// discard all custom changes on DoubleSlider
@@ -1782,7 +2128,7 @@ void Control::discard_all_thicks()
SetHigherValue(m_max_value);
m_selection == ssLower ? correct_lower_value() : correct_higher_value();
- if (!m_selection) m_selection = ssHigher;
+ if (m_selection == ssUndef) m_selection = ssHigher;
m_ticks.ticks.clear();
post_ticks_changed_event();
@@ -1796,26 +2142,21 @@ void Control::move_current_thumb_to_pos(wxPoint pos)
const int tick_val = get_tick_near_point(pos);
const int mouse_val = tick_val >= 0 && m_draw_mode == dmRegular ? tick_val :
get_value_from_position(pos);
- if (mouse_val >= 0)
- {
- // if (abs(mouse_val - m_lower_value) < abs(mouse_val - m_higher_value)) {
- // if (mouse_val <= m_lower_value) {
+ if (mouse_val >= 0) {
if (m_selection == ssLower) {
SetLowerValue(mouse_val);
correct_lower_value();
- // m_selection = ssLower;
}
- else {
+ else { // even m_selection is ssUndef, upper thumb should be selected
SetHigherValue(mouse_val);
correct_higher_value();
- m_selection = ssHigher;
}
}
}
void Control::edit_extruder_sequence()
{
- if (!check_ticks_changed_event(ToolChangeCode))
+ if (!check_ticks_changed_event(ToolChange))
return;
GUI::ExtruderSequenceDialog dlg(m_extruders_sequence);
@@ -1823,7 +2164,7 @@ void Control::edit_extruder_sequence()
return;
m_extruders_sequence = dlg.GetValue();
- m_ticks.erase_all_ticks_with_code(ToolChangeCode);
+ m_ticks.erase_all_ticks_with_code(ToolChange);
int tick = 0;
double value = 0.0;
@@ -1836,13 +2177,12 @@ void Control::edit_extruder_sequence()
bool meaningless_tick = tick == 0.0 && cur_extruder == extruder;
if (!meaningless_tick)
- m_ticks.ticks.emplace(TickCode{tick, ToolChangeCode, cur_extruder + 1, m_extruder_colors[cur_extruder]});
+ m_ticks.ticks.emplace(TickCode{tick, ToolChange,cur_extruder + 1, m_extruder_colors[cur_extruder]});
extruder++;
if (extruder == extr_cnt)
extruder = 0;
- if (m_extruders_sequence.is_mm_intervals)
- {
+ if (m_extruders_sequence.is_mm_intervals) {
value += m_extruders_sequence.interval_by_mm;
auto val_it = std::lower_bound(m_values.begin(), m_values.end(), value - epsilon());
@@ -1855,17 +2195,17 @@ void Control::edit_extruder_sequence()
tick += m_extruders_sequence.interval_by_layers;
}
- post_ticks_changed_event(ToolChangeCode);
+ post_ticks_changed_event(ToolChange);
}
-void Control::jump_to_print_z()
+void Control::jump_to_value()
{
- double print_z = get_print_z_to_jump(m_values[m_selection == ssLower ? m_lower_value : m_higher_value],
- m_values[m_min_value], m_values[m_max_value]);
- if (print_z < 0)
+ double value = get_value_to_jump(m_values[m_selection == ssLower ? m_lower_value : m_higher_value],
+ m_values[m_min_value], m_values[m_max_value], m_draw_mode);
+ if (value < 0.0)
return;
- auto it = std::lower_bound(m_values.begin(), m_values.end(), print_z - epsilon());
+ auto it = std::lower_bound(m_values.begin(), m_values.end(), value - epsilon());
int tick_value = it - m_values.begin();
if (m_selection == ssLower)
@@ -1874,64 +2214,63 @@ void Control::jump_to_print_z()
SetHigherValue(tick_value);
}
-void Control::post_ticks_changed_event(const std::string& gcode /*= ""*/)
+void Control::post_ticks_changed_event(Type type /*= Custom*/)
{
- m_force_mode_apply = (gcode.empty() || gcode == ColorChangeCode || gcode == ToolChangeCode);
+// m_force_mode_apply = type != ToolChange; // It looks like this condition is no needed now. Leave it for the testing
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
}
-bool Control::check_ticks_changed_event(const std::string& gcode)
+bool Control::check_ticks_changed_event(Type type)
{
if ( m_ticks.mode == m_mode ||
- (gcode != ColorChangeCode && gcode != ToolChangeCode) ||
- (m_ticks.mode == t_mode::SingleExtruder && m_mode == t_mode::MultiAsSingle) || // All ColorChanges will be applied for 1st extruder
- (m_ticks.mode == t_mode::MultiExtruder && m_mode == t_mode::MultiAsSingle) ) // Just mark ColorChanges for all unused extruders
+ (type != ColorChange && type != ToolChange) ||
+ (m_ticks.mode == SingleExtruder && m_mode == MultiAsSingle) || // All ColorChanges will be applied for 1st extruder
+ (m_ticks.mode == MultiExtruder && m_mode == MultiAsSingle) ) // Just mark ColorChanges for all unused extruders
return true;
- if ((m_ticks.mode == t_mode::SingleExtruder && m_mode == t_mode::MultiExtruder ) ||
- (m_ticks.mode == t_mode::MultiExtruder && m_mode == t_mode::SingleExtruder) )
+ if ((m_ticks.mode == SingleExtruder && m_mode == MultiExtruder ) ||
+ (m_ticks.mode == MultiExtruder && m_mode == SingleExtruder) )
{
- if (!m_ticks.has_tick_with_code(ColorChangeCode))
+ if (!m_ticks.has_tick_with_code(ColorChange))
return true;
- wxString message = (m_ticks.mode == t_mode::SingleExtruder ?
- _(L("The last color change data was saved for a single extruder printing.")) :
- _(L("The last color change data was saved for a multi extruder printing."))
+ wxString message = (m_ticks.mode == SingleExtruder ?
+ _L("The last color change data was saved for a single extruder printing.") :
+ _L("The last color change data was saved for a multi extruder printing.")
) + "\n" +
- _(L("Your current changes will delete all saved color changes.")) + "\n\n\t" +
- _(L("Are you sure you want to continue?"));
+ _L("Your current changes will delete all saved color changes.") + "\n\n\t" +
+ _L("Are you sure you want to continue?");
- wxMessageDialog msg(this, message, _(L("Notice")), wxYES_NO);
+ wxMessageDialog msg(this, message, _L("Notice"), wxYES_NO);
if (msg.ShowModal() == wxID_YES) {
- m_ticks.erase_all_ticks_with_code(ColorChangeCode);
- post_ticks_changed_event(ColorChangeCode);
+ m_ticks.erase_all_ticks_with_code(ColorChange);
+ post_ticks_changed_event(ColorChange);
}
return false;
}
- // m_ticks_mode == t_mode::MultiAsSingle
- if( m_ticks.has_tick_with_code(ToolChangeCode) )
- {
- wxString message = m_mode == t_mode::SingleExtruder ? (
- _(L("The last color change data was saved for a multi extruder printing.")) + "\n\n" +
- _(L("Select YES if you want to delete all saved tool changes, \n"
- "NO if you want all tool changes switch to color changes, \n"
- "or CANCEL to leave it unchanged.")) + "\n\n\t" +
- _(L("Do you want to delete all saved tool changes?"))
- ) : ( // t_mode::MultiExtruder
- _(L("The last color change data was saved for a multi extruder printing with tool changes for whole print.")) + "\n\n" +
- _(L("Your current changes will delete all saved extruder (tool) changes.")) + "\n\n\t" +
- _(L("Are you sure you want to continue?")) ) ;
-
- wxMessageDialog msg(this, message, _(L("Notice")), wxYES_NO | (m_mode == t_mode::SingleExtruder ? wxCANCEL : 0));
+ // m_ticks_mode == MultiAsSingle
+ if( m_ticks.has_tick_with_code(ToolChange) ) {
+ wxString message = m_mode == SingleExtruder ? (
+ _L("The last color change data was saved for a multi extruder printing.") + "\n\n" +
+ _L("Select YES if you want to delete all saved tool changes, \n"
+ "NO if you want all tool changes switch to color changes, \n"
+ "or CANCEL to leave it unchanged.") + "\n\n\t" +
+ _L("Do you want to delete all saved tool changes?")
+ ): ( // MultiExtruder
+ _L("The last color change data was saved for a multi extruder printing with tool changes for whole print.") + "\n\n" +
+ _L("Your current changes will delete all saved extruder (tool) changes.") + "\n\n\t" +
+ _L("Are you sure you want to continue?") ) ;
+
+ wxMessageDialog msg(this, message, _L("Notice"), wxYES_NO | (m_mode == SingleExtruder ? wxCANCEL : 0));
const int answer = msg.ShowModal();
if (answer == wxID_YES) {
- m_ticks.erase_all_ticks_with_code(ToolChangeCode);
- post_ticks_changed_event(ToolChangeCode);
+ m_ticks.erase_all_ticks_with_code(ToolChange);
+ post_ticks_changed_event(ToolChange);
}
- else if (m_mode == t_mode::SingleExtruder && answer == wxID_NO) {
- m_ticks.switch_code(ToolChangeCode, ColorChangeCode);
- post_ticks_changed_event(ColorChangeCode);
+ else if (m_mode == SingleExtruder && answer == wxID_NO) {
+ m_ticks.switch_code(ToolChange, ColorChange);
+ post_ticks_changed_event(ColorChange);
}
return false;
}
@@ -1939,11 +2278,10 @@ bool Control::check_ticks_changed_event(const std::string& gcode)
return true;
}
-std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& code, const int extruder)
+std::string TickCodeInfo::get_color_for_tick(TickCode tick, Type type, const int extruder)
{
- if (mode == t_mode::SingleExtruder && code == ColorChangeCode && m_use_default_colors)
- {
- const std::vector<std::string>& colors = GCodePreviewData::ColorPrintColors();
+ if (mode == SingleExtruder && type == ColorChange && m_use_default_colors) {
+ const std::vector<std::string>& colors = ColorPrintColors::get();
if (ticks.empty())
return colors[0];
m_default_color_idx++;
@@ -1953,14 +2291,12 @@ std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& c
std::string color = (*m_colors)[extruder - 1];
- if (code == ColorChangeCode)
- {
- if (!ticks.empty())
- {
+ if (type == ColorChange) {
+ if (!ticks.empty()) {
auto before_tick_it = std::lower_bound(ticks.begin(), ticks.end(), tick );
while (before_tick_it != ticks.begin()) {
--before_tick_it;
- if (before_tick_it->gcode == ColorChangeCode && before_tick_it->extruder == extruder) {
+ if (before_tick_it->type == ColorChange && before_tick_it->extruder == extruder) {
color = before_tick_it->color;
break;
}
@@ -1972,63 +2308,65 @@ std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& c
return color;
}
-bool TickCodeInfo::add_tick(const int tick, std::string& code, const int extruder, double print_z)
+bool TickCodeInfo::add_tick(const int tick, Type type, const int extruder, double print_z)
{
std::string color;
- if (code.empty()) // custom Gcode
+ std::string extra;
+ if (type == Custom) // custom Gcode
{
- code = get_custom_code(custom_gcode, print_z);
- if (code.empty())
+ extra = get_custom_code(custom_gcode, print_z);
+ if (extra.empty())
return false;
- custom_gcode = code;
+ custom_gcode = extra;
}
- else if (code == PausePrintCode)
- {
- /* PausePrintCode doesn't need a color, so
- * this field is used for save a short message shown on Printer display
- * */
- color = get_pause_print_msg(pause_print_msg, print_z);
- if (color.empty())
+ else if (type == PausePrint) {
+ extra = get_pause_print_msg(pause_print_msg, print_z);
+ if (extra.empty())
return false;
- pause_print_msg = color;
+ pause_print_msg = extra;
}
- else
- {
- color = get_color_for_tick(TickCode{ tick }, code, extruder);
+ else {
+ color = get_color_for_tick(TickCode{ tick }, type, extruder);
if (color.empty())
return false;
}
- if (mode == t_mode::SingleExtruder)
+ if (mode == SingleExtruder)
m_use_default_colors = true;
- ticks.emplace(TickCode{ tick, code, extruder, color });
+ ticks.emplace(TickCode{ tick, type, extruder, color, extra });
return true;
}
bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z)
{
std::string edited_value;
- if (it->gcode == ColorChangeCode)
+ if (it->type == ColorChange)
edited_value = get_new_color(it->color);
- else if (it->gcode == PausePrintCode)
- edited_value = get_pause_print_msg(it->color, print_z);
+ else if (it->type == PausePrint)
+ edited_value = get_pause_print_msg(it->extra, print_z);
else
- edited_value = get_custom_code(it->gcode, print_z);
+ edited_value = get_custom_code(it->type == Template ? gcode(Template) : it->extra, print_z);
if (edited_value.empty())
return false;
TickCode changed_tick = *it;
- if (it->gcode == ColorChangeCode || it->gcode == PausePrintCode) {
+ if (it->type == ColorChange) {
if (it->color == edited_value)
return false;
changed_tick.color = edited_value;
}
- else {
- if (it->gcode == edited_value)
+ else if (it->type == Template) {
+ if (gcode(Template) == edited_value)
return false;
- changed_tick.gcode = edited_value;
+ changed_tick.extra = edited_value;
+ changed_tick.type = Custom;
+ }
+ else if (it->type == Custom || it->type == PausePrint) {
+ if (it->extra == edited_value)
+ return false;
+ changed_tick.extra = edited_value;
}
ticks.erase(it);
@@ -2037,13 +2375,12 @@ bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z)
return true;
}
-void TickCodeInfo::switch_code(const std::string& code_from, const std::string& code_to)
+void TickCodeInfo::switch_code(Type type_from, Type type_to)
{
for (auto it{ ticks.begin() }, end{ ticks.end() }; it != end; )
- if (it->gcode == code_from)
- {
+ if (it->type == type_from) {
TickCode tick = *it;
- tick.gcode = code_to;
+ tick.type = type_to;
tick.extruder = 1;
ticks.erase(it);
it = ticks.emplace(tick).first;
@@ -2052,14 +2389,14 @@ void TickCodeInfo::switch_code(const std::string& code_from, const std::string&
++it;
}
-bool TickCodeInfo::switch_code_for_tick(std::set<TickCode>::iterator it, const std::string& code_to, const int extruder)
+bool TickCodeInfo::switch_code_for_tick(std::set<TickCode>::iterator it, Type type_to, const int extruder)
{
- const std::string color = get_color_for_tick(*it, code_to, extruder);
+ const std::string color = get_color_for_tick(*it, type_to, extruder);
if (color.empty())
return false;
- TickCode changed_tick = *it;
- changed_tick.gcode = code_to;
+ TickCode changed_tick = *it;
+ changed_tick.type = type_to;
changed_tick.extruder = extruder;
changed_tick.color = color;
@@ -2069,37 +2406,36 @@ bool TickCodeInfo::switch_code_for_tick(std::set<TickCode>::iterator it, const s
return true;
}
-void TickCodeInfo::erase_all_ticks_with_code(const std::string& gcode)
+void TickCodeInfo::erase_all_ticks_with_code(Type type)
{
for (auto it{ ticks.begin() }, end{ ticks.end() }; it != end; ) {
- if (it->gcode == gcode)
+ if (it->type == type)
it = ticks.erase(it);
else
++it;
}
}
-bool TickCodeInfo::has_tick_with_code(const std::string& gcode)
+bool TickCodeInfo::has_tick_with_code(Type type)
{
for (const TickCode& tick : ticks)
- if (tick.gcode == gcode)
+ if (tick.type == type)
return true;
return false;
}
-ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mode, int only_extruder, double print_z)
+ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, Mode out_mode, int only_extruder, double print_z)
{
- if ((tick.gcode == ColorChangeCode && (
- (mode == t_mode::SingleExtruder && out_mode == t_mode::MultiExtruder ) ||
- (mode == t_mode::MultiExtruder && out_mode == t_mode::SingleExtruder) )) ||
- (tick.gcode == ToolChangeCode &&
- (mode == t_mode::MultiAsSingle && out_mode != t_mode::MultiAsSingle)) )
+ if ((tick.type == ColorChange && (
+ (mode == SingleExtruder && out_mode == MultiExtruder ) ||
+ (mode == MultiExtruder && out_mode == SingleExtruder) )) ||
+ (tick.type == ToolChange &&
+ (mode == MultiAsSingle && out_mode != MultiAsSingle)) )
return ctModeConflict;
// check ColorChange tick
- if (tick.gcode == ColorChangeCode)
- {
+ if (tick.type == ColorChange) {
// We should mark a tick as a "MeaninglessColorChange",
// if it has a ColorChange for unused extruder from current print to end of the print
std::set<int> used_extruders_for_tick = get_used_extruders_for_tick(tick.tick, only_extruder, print_z, out_mode);
@@ -2109,15 +2445,15 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
// We should mark a tick as a "Redundant",
// if it has a ColorChange for extruder that has not been used before
- if (mode == t_mode::MultiAsSingle && tick.extruder != std::max<int>(only_extruder, 1) )
+ if (mode == MultiAsSingle && tick.extruder != std::max<int>(only_extruder, 1) )
{
auto it = ticks.lower_bound( tick );
- if (it == ticks.begin() && it->gcode == ToolChangeCode && tick.extruder == it->extruder)
+ if (it == ticks.begin() && it->type == ToolChange && tick.extruder == it->extruder)
return ctNone;
while (it != ticks.begin()) {
--it;
- if (it->gcode == ToolChangeCode && tick.extruder == it->extruder)
+ if (it->type == ToolChange && tick.extruder == it->extruder)
return ctNone;
}
@@ -2126,8 +2462,7 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
}
// check ToolChange tick
- if (mode == t_mode::MultiAsSingle && tick.gcode == ToolChangeCode)
- {
+ if (mode == MultiAsSingle && tick.type == ToolChange) {
// We should mark a tick as a "MeaninglessToolChange",
// if it has a ToolChange to the same extruder
auto it = ticks.find(tick);
@@ -2136,7 +2471,7 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
while (it != ticks.begin()) {
--it;
- if (it->gcode == ToolChangeCode)
+ if (it->type == ToolChange)
return tick.extruder == it->extruder ? ctMeaninglessToolChange : ctNone;
}
}