Context menu is extended for multiple material printing

This commit is contained in:
YuSanka 2019-10-14 10:05:27 +02:00
parent 8e6bb7c20d
commit 5c2b5a167b
4 changed files with 125 additions and 34 deletions

View File

@ -836,8 +836,8 @@ GLCanvas3D::LegendTexture::LegendTexture()
void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas, void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas,
std::vector<std::pair<double, double>>& cp_legend_values) std::vector<std::pair<double, double>>& cp_legend_values)
{ {
if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint && if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint /*&&
wxGetApp().extruders_edited_cnt() == 1) // show color change legend only for single-material presets wxGetApp().extruders_edited_cnt() == 1*/) // show color change legend only for single-material presets
{ {
/* /*
// #ys_FIXME_COLOR // #ys_FIXME_COLOR

View File

@ -502,6 +502,8 @@ void Preview::update_sliders(const std::vector<double>& layers_z, bool keep_z_ra
m_enabled = true; m_enabled = true;
update_double_slider(layers_z, keep_z_range); update_double_slider(layers_z, keep_z_range);
m_double_slider_sizer->Show((size_t)0); m_double_slider_sizer->Show((size_t)0);
if (m_slider->GetManipulationState() != DoubleSlider::msMultiExtruder)
m_double_slider_sizer->GetItem(size_t(0))->GetSizer()->Hide((size_t)0);
Layout(); Layout();
} }
@ -572,8 +574,8 @@ void Preview::update_view_type()
_(L("Feature type")); _(L("Feature type"));
*/ */
const wxString& choice = !wxGetApp().plater()->model().custom_gcode_per_height.empty() && const wxString& choice = !wxGetApp().plater()->model().custom_gcode_per_height.empty()// &&
wxGetApp().extruders_edited_cnt()==1 ? /*wxGetApp().extruders_edited_cnt()==1*/ ?
_(L("Color Print")) : _(L("Color Print")) :
config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values.size() > 1 ? config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values.size() > 1 ?
_(L("Tool")) : _(L("Tool")) :
@ -591,9 +593,9 @@ void Preview::update_view_type()
void Preview::create_double_slider() void Preview::create_double_slider()
{ {
m_slider = new DoubleSlider(this, wxID_ANY, 0, 0, 0, 100); m_slider = new DoubleSlider(this, wxID_ANY, 0, 0, 0, 100);
m_double_slider_sizer->Add(m_slider, 0, wxEXPAND, 0); // #ys_FIXME_COLOR
// m_double_slider_sizer->Add(m_slider, 0, wxEXPAND, 0);
/*
auto extruder_selector = new wxComboBox(this, wxID_ANY); auto extruder_selector = new wxComboBox(this, wxID_ANY);
extruder_selector->Append("Whole print"); extruder_selector->Append("Whole print");
int extruder_cnt = wxGetApp().extruders_edited_cnt(); int extruder_cnt = wxGetApp().extruders_edited_cnt();
@ -610,7 +612,6 @@ void Preview::create_double_slider()
sizer->Add(m_slider, 1, wxEXPAND, 0); sizer->Add(m_slider, 1, wxEXPAND, 0);
m_double_slider_sizer->Add(sizer, 0, wxEXPAND, 0); m_double_slider_sizer->Add(sizer, 0, wxEXPAND, 0);
*/
// sizer, m_canvas_widget // sizer, m_canvas_widget
m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this); m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this);
@ -723,12 +724,25 @@ void Preview::update_double_slider(const std::vector<double>& layers_z, bool kee
m_slider->SetTicksValues_(ticks_from_model); m_slider->SetTicksValues_(ticks_from_model);
bool color_print_enable = (wxGetApp().plater()->printer_technology() == ptFFF); bool color_print_enable = (wxGetApp().plater()->printer_technology() == ptFFF);
// #ys_FIXME_COLOR
// 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);
m_slider->EnableTickManipulation(color_print_enable);
m_slider->SetManipulationState(DoubleSlider::msSingleExtruder);
if (color_print_enable) { if (color_print_enable) {
const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config; const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
if (cfg.opt<ConfigOptionFloats>("nozzle_diameter")->values.size() > 1) if (cfg.opt<ConfigOptionFloats>("nozzle_diameter")->values.size() > 1) {
color_print_enable = false; // ys_TODO : fill is_detected_one_extruder_print value
bool is_detected_one_extruder_print = wxGetApp().plater()->fff_print().extruders().size() == 1;
m_slider->SetManipulationState(is_detected_one_extruder_print ?
DoubleSlider::msMultiExtruderSimple : DoubleSlider::msMultiExtruder);
}
} }
m_slider->EnableTickManipulation(color_print_enable);
} }
// #ys_FIXME_COLOR // #ys_FIXME_COLOR
void Preview::check_slider_values(std::vector<double>& ticks_from_config, void Preview::check_slider_values(std::vector<double>& ticks_from_config,
@ -875,8 +889,8 @@ void Preview::load_print_as_fff(bool keep_z_range)
m_loaded = true; m_loaded = true;
} else { } else {
// disable color change information for multi-material presets // disable color change information for multi-material presets
if (wxGetApp().extruders_edited_cnt() > 1) // if (wxGetApp().extruders_edited_cnt() > 1) // #ys_FIXME_COLOR
color_print_values.clear(); // color_print_values.clear();
// Load the initial preview based on slices, not the final G-code. // Load the initial preview based on slices, not the final G-code.
m_canvas->load_preview(colors, color_print_values); m_canvas->load_preview(colors, color_print_values);

View File

@ -3042,6 +3042,28 @@ void DoubleSlider::correct_higher_value()
m_lower_value = m_higher_value; m_lower_value = m_higher_value;
} }
wxString DoubleSlider::get_tooltip(bool is_revert_icon_focused)
{
wxString tooltip(wxEmptyString);
if (m_is_one_layer_icon_focesed)
tooltip = _(L("One layer mode"));
if (is_revert_icon_focused)
tooltip = _(L("Discard all custom changes"));
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() ? _(L("Add color change")) :
tick_code_it->gcode == "M600" ? _(L("Delete color change")) :
tick_code_it->gcode == "M25" ? _(L("Delete pause")) :
tick_code_it->gcode == "tool_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;
}
void DoubleSlider::OnMotion(wxMouseEvent& event) void DoubleSlider::OnMotion(wxMouseEvent& event)
{ {
bool action = false; bool action = false;
@ -3081,22 +3103,7 @@ void DoubleSlider::OnMotion(wxMouseEvent& event)
// const wxString tooltip = m_is_one_layer_icon_focesed ? _(L("One layer mode")) : // const wxString tooltip = m_is_one_layer_icon_focesed ? _(L("One layer mode")) :
// m_is_action_icon_focesed ? _(L("Add/Del color change")) : // m_is_action_icon_focesed ? _(L("Add/Del color change")) :
// is_revert_icon_focused ? _(L("Discard all color changes")) : ""; // is_revert_icon_focused ? _(L("Discard all color changes")) : "";
wxString tooltip(wxEmptyString); this->SetToolTip(get_tooltip(is_revert_icon_focused));
if (m_is_one_layer_icon_focesed)
tooltip = _(L("One layer mode"));
if (is_revert_icon_focused)
tooltip = _(L("Discard all custom changes"));
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() ? _(L("Add color change")) :
tick_code_it->gcode == "M600" ? _(L("Delete color change")) :
tick_code_it->gcode == "M25" ? _(L("Delete pause")) :
from_u8((boost::format(_utf8(L("Delete \"%1%\" code"))) % tick_code_it->gcode).str());
}
this->SetToolTip(tooltip);
if (action) if (action)
{ {
@ -3298,6 +3305,20 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
event.Skip(); event.Skip();
} }
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;
}
}
return extruder;
}
void DoubleSlider::OnRightUp(wxMouseEvent& event) void DoubleSlider::OnRightUp(wxMouseEvent& event)
{ {
if (!HasCapture()) if (!HasCapture())
@ -3308,6 +3329,28 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
if (m_show_context_menu) { if (m_show_context_menu) {
wxMenu menu; wxMenu menu;
if (m_state == msMultiExtruderSimple)
{
const wxString name = _(L("Change extruder"));
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();
for (int i = 0; i <= extruders_cnt; i++) {
const wxString& item_name = i == 0 ? _(L("Default")) : wxString::Format("%d", i);
append_menu_radio_item(change_extruder_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { change_extruder(i); }, &menu)->Check(i == initial_extruder);
}
menu.AppendSubMenu(change_extruder_menu, name, _(L("Use another extruder")));
}
}
if (m_state != msMultiExtruderSimple)
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "", append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
[this](wxCommandEvent&) { add_code("M600"); }, "colorchange_add_off.png", &menu); [this](wxCommandEvent&) { add_code("M600"); }, "colorchange_add_off.png", &menu);
@ -3339,14 +3382,33 @@ void DoubleSlider::add_code(std::string code)
wxString msg_header = from_u8((boost::format(_utf8(L("Custom Gcode on current layer (%1% mm)."))) % m_values[tick]).str()); wxString msg_header = from_u8((boost::format(_utf8(L("Custom Gcode on current layer (%1% mm)."))) % m_values[tick]).str());
// get custom gcode // get custom gcode
wxString custom_code = wxGetTextFromUser(msg_text, msg_header); wxTextEntryDialog dlg(nullptr, msg_text, msg_header, wxEmptyString,
wxTextEntryDialogStyle | wxTE_MULTILINE);
if (custom_code.IsEmpty()) if (dlg.ShowModal() != wxID_OK || dlg.GetValue().IsEmpty())
return; return;
code = custom_code.c_str();
code = dlg.GetValue().c_str();
} }
m_ticks_.insert(TICK_CODE(tick, code)); int extruder = 0;
if (m_state == msMultiExtruderSimple)
extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value);
m_ticks_.insert(TICK_CODE(tick, code, extruder));
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
}
}
void DoubleSlider::change_extruder(int extruder)
{
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
// if on this Y doesn't exist tick
if (m_ticks_.find(tick) == m_ticks_.end())
{
m_ticks_.insert(TICK_CODE(tick, "tool_change", extruder));
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh(); Refresh();

View File

@ -806,6 +806,16 @@ public:
EnableTickManipulation(false); EnableTickManipulation(false);
} }
static enum ManipulationState {
msSingleExtruder, // single extruder printer preset is selected
msMultiExtruder, // multiple extruder printer preset is selected
msMultiExtruderSimple // multiple extruder printer preset is selected, but one-extruder print is detected
};
void SetManipulationState(ManipulationState state) {
m_state = state;
}
ManipulationState GetManipulationState() const { return m_state; }
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; } bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
bool is_one_layer() const { return m_is_one_layer; } bool is_one_layer() const { return m_is_one_layer; }
bool is_lower_at_min() const { return m_lower_value == m_min_value; } bool is_lower_at_min() const { return m_lower_value == m_min_value; }
@ -823,8 +833,10 @@ public:
void OnKeyUp(wxKeyEvent &event); void OnKeyUp(wxKeyEvent &event);
void OnChar(wxKeyEvent &event); void OnChar(wxKeyEvent &event);
void OnRightDown(wxMouseEvent& event); void OnRightDown(wxMouseEvent& event);
int get_extruder_for_tick(int tick);
void OnRightUp(wxMouseEvent& event); void OnRightUp(wxMouseEvent& event);
void add_code(std::string code); void add_code(std::string code);
void change_extruder(int extruder);
protected: protected:
@ -846,6 +858,7 @@ protected:
void detect_selected_slider(const wxPoint& pt); void detect_selected_slider(const wxPoint& pt);
void correct_lower_value(); void correct_lower_value();
void correct_higher_value(); void correct_higher_value();
wxString get_tooltip(bool is_revert_icon_focused);
void move_current_thumb(const bool condition); void move_current_thumb(const bool condition);
void action_tick(const TicksAction action); void action_tick(const TicksAction action);
void enter_window(wxMouseEvent& event, const bool enter); void enter_window(wxMouseEvent& event, const bool enter);
@ -889,6 +902,7 @@ private:
bool m_is_one_layer_icon_focesed = false; bool m_is_one_layer_icon_focesed = false;
bool m_is_enabled_tick_manipulation = true; bool m_is_enabled_tick_manipulation = true;
bool m_show_context_menu = false; bool m_show_context_menu = false;
ManipulationState m_state = msSingleExtruder;
wxRect m_rect_lower_thumb; wxRect m_rect_lower_thumb;
wxRect m_rect_higher_thumb; wxRect m_rect_higher_thumb;
@ -929,6 +943,7 @@ private:
tick(tick), gcode(code), extruder(extruder) {} tick(tick), gcode(code), extruder(extruder) {}
bool operator<(const TICK_CODE& other) const { return other.tick > this->tick; } bool operator<(const TICK_CODE& other) const { return other.tick > this->tick; }
bool operator>(const TICK_CODE& other) const { return other.tick < this->tick; }
int tick; int tick;
std::string gcode; std::string gcode;