Updated DoubleSlider band. Added smart color selection for M600

This commit is contained in:
YuSanka 2019-11-07 13:51:54 +01:00
parent c4a62819f4
commit 72852ffab5
6 changed files with 136 additions and 22 deletions

View File

@ -5296,13 +5296,13 @@ void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_dat
}
case GCodePreviewData::Extrusion::ColorPrint:
{
// int color_cnt = (int)tool_colors.size() / 4;
int color_cnt = (int)tool_colors.size() / 4;
// int val = int(value);
// while (val >= color_cnt)
// val -= color_cnt;
unsigned int val = unsigned int(value) >= INT_MAX ? tool_colors.size()*4 - 1 : value;
int val = value > color_cnt ? color_cnt - 1 : value;
GCodePreviewData::Color color;
::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + val * 4), 4 * sizeof(float));

View File

@ -887,12 +887,13 @@ void Preview::load_print_as_fff(bool keep_z_range)
// set color print values, if it si selected "ColorPrint" view type
if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
{
colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
color_print_values = wxGetApp().plater()->model().custom_gcode_per_height;
/* colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
for (const Model::CustomGCode& code : color_print_values)
if (code.gcode == "M600")
colors.push_back(code.color);
colors.push_back(code.color);*/
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)

View File

@ -4995,6 +4995,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 == "M600")
colors.push_back(code.color);
return colors;
}
wxString Plater::get_project_filename(const wxString& extension) const
{
return p->get_project_filename(extension);

View File

@ -221,6 +221,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

@ -2644,12 +2644,12 @@ 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);
@ -2827,6 +2827,18 @@ void DoubleSlider::draw_ticks(wxDC& dc)
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 "Extruder change"
if (tick.gcode != "M600" && tick.gcode != "tool_change")
{
wxBitmap icon = create_scaled_bitmap(nullptr, tick.gcode == "M601" ? "pause_add.png" : "add_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);
}
}
}
@ -2853,7 +2865,7 @@ void DoubleSlider::draw_colored_band(wxDC& dc)
// #ys_FIXME_COLOR
// if (m_ticks.empty()) {
if (m_ticks_.empty()) {
/*if (m_ticks_.empty()) {
dc.SetPen(GetParent()->GetBackgroundColour());
dc.SetBrush(GetParent()->GetBackgroundColour());
dc.DrawRectangle(main_band);
@ -2886,6 +2898,37 @@ void DoubleSlider::draw_colored_band(wxDC& dc)
dc.SetBrush(clr);
dc.DrawRectangle(main_band);
i++;
}*/
auto draw_band = [](wxDC& dc, const wxColour& clr, const wxRect& band_rc) {
dc.SetPen(clr);
dc.SetBrush(clr);
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 != "M600") ||
(m_state == msMultiExtruderWholePrint && tick.gcode != "tool_change") )
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 == msMultiExtruderWholePrint && tick.color.empty()) ? bg_clr :
m_state == msMultiExtruderWholePrint ? wxColour(colors[std::min<int>(colors_cnt - 1, tick.extruder-1)]) : wxColour(tick.color);
draw_band(dc, clr, main_band);
i++;
}
}
@ -3166,11 +3209,13 @@ wxString DoubleSlider::get_tooltip(IconFocus icon_focus)
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() ? _(L("Add color change")) :
tick_code_it->gcode == "M600" ? _(L("Delete color change")) :
// tick_code_it->gcode == "M600" ? _(L("Delete color change")) :
tick_code_it->gcode == "M600" ? ( m_state == msSingleExtruder ? _(L("Delete color change")) :
from_u8((boost::format(_utf8(L("Delete color change for Extruder %1%"))) % tick_code_it->extruder).str()) ):
tick_code_it->gcode == "M601" ? _(L("Delete pause")) :
tick_code_it->gcode == "tool_change" ? ( m_state == msSingleExtruder ? _(L("Delete color change")) :
from_u8((boost::format(_utf8(L("Delete extruder change to \"%1%\""))) % tick_code_it->extruder).str()) ) :
from_u8((boost::format(_utf8(L("Delete \"%1%\" code"))) % tick_code_it->gcode).str());
tick_code_it->gcode == "tool_change" ? //( m_state == msSingleExtruder ? _(L("Delete color change")) :
from_u8((boost::format(_utf8(L("Delete extruder change to \"%1%\""))) % tick_code_it->extruder).str()) /*) */:
from_u8((boost::format(_utf8(L("Delete \"%1%\" code"))) % tick_code_it->gcode).str());
}
return tooltip;
@ -3441,12 +3486,19 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
// if on this Y doesn't exist tick
// #ys_FIXME_COLOR
// if (m_ticks.find(tick) == m_ticks.end())
if (m_ticks_.find(tick) == m_ticks_.end())
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 == "M600")
{
// show "Edit color" or "Delete color change" menu on OnRightUp()
m_show_edit_color_menu = true;
return;
}
}
detect_selected_slider(event.GetLogicalPosition(dc));
@ -3469,15 +3521,17 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
int DoubleSlider::get_extruder_for_tick(int tick)
{
int extruder = 0;
if (!m_ticks_.empty()) {
auto tick_code_it = m_ticks_.lower_bound(tick);
if (tick_code_it != m_ticks_.begin()) {
--tick_code_it;
extruder = tick_code_it->extruder;
}
if (m_ticks_.empty())
return 0;
auto it = m_ticks_.lower_bound(tick);
while (it != m_ticks_.begin()) {
--it;
if(it->gcode == "tool_change")
return it->extruder;
}
return extruder;
return 0;
}
void DoubleSlider::OnRightUp(wxMouseEvent& event)
@ -3535,6 +3589,19 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
m_show_context_menu = false;
}
else if (m_show_edit_color_menu) {
wxMenu menu;
append_menu_item(&menu, wxID_ANY, _(L("Edit color")), "",
[this](wxCommandEvent&) { edit_color(); }, "change_extruder", &menu);
append_menu_item(&menu, wxID_ANY, _(L("Delete color change")), "",
[this](wxCommandEvent&) { action_tick(taDel); }, "colorchange_delete_off.png", &menu);
Slic3r::GUI::wxGetApp().plater()->PopupMenu(&menu);
m_show_edit_color_menu = false;
}
Refresh();
Update();
@ -3561,7 +3628,7 @@ static std::string get_new_color(const std::string& color)
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 Y doesn't exist tick
// if on this Z doesn't exist tick
auto it = m_ticks_.find(tick);
if (it == m_ticks_.end())
{
@ -3569,7 +3636,20 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
if (code == "M600")
{
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
color = get_new_color(colors[selected_extruder > 0 ? selected_extruder-1 : 0]);
if (m_state == msSingleExtruder && !m_ticks_.empty()) {
auto before_tick_it = std::lower_bound(m_ticks_.begin(), m_ticks_.end(), tick);
if (before_tick_it == m_ticks_.begin())
color = colors[0];
else {
--before_tick_it;
color = before_tick_it->color;
}
}
else
color = colors[selected_extruder > 0 ? selected_extruder-1 : 0];
color = get_new_color(color);
if (color.empty())
return;
}
@ -3606,6 +3686,25 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
}
}
void DoubleSlider::edit_color()
{
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 color = get_new_color(it->color);
if (color.empty())
return;
TICK_CODE changed_tick = *it;
changed_tick.color = color;
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;

View File

@ -854,6 +854,7 @@ public:
int get_extruder_for_tick(int tick);
void OnRightUp(wxMouseEvent& event);
void add_code(std::string code, int selected_extruder = -1);
void edit_color();
void change_extruder(int extruder);
protected:
@ -922,6 +923,7 @@ private:
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_color_menu = false;
bool m_suppress_add_code = false;
ManipulationState m_state = msSingleExtruder;
wxString m_custom_gcode = wxEmptyString;