ENH:add 'reset' button in AmsMapingPopup
jira: STUDIO-10009 Change-Id: Ia924ae9cbe0bec33f1b37af12633a9cb64836182
This commit is contained in:
parent
d77848fa9f
commit
3b8aa5993d
|
@ -72,9 +72,15 @@ void MaterialItem::allow_paint_dropdown(bool flag) {
|
|||
}
|
||||
}
|
||||
|
||||
void MaterialItem::set_ams_info(wxColour col, wxString txt, int ctype, std::vector<wxColour> cols)
|
||||
void MaterialItem::set_ams_info(wxColour col, wxString txt, int ctype, std::vector<wxColour> cols, bool record_back_info)
|
||||
{
|
||||
auto need_refresh = false;
|
||||
if (record_back_info) {
|
||||
m_back_ams_cols = cols;
|
||||
m_back_ams_ctype = ctype;
|
||||
m_back_ams_coloul = col;
|
||||
m_back_ams_name = txt;
|
||||
}
|
||||
if (m_ams_cols != cols) { m_ams_cols = cols; need_refresh = true; }
|
||||
if (m_ams_ctype != ctype) { m_ams_ctype = ctype; need_refresh = true; }
|
||||
if (m_ams_coloul != col) { m_ams_coloul = col; need_refresh = true;}
|
||||
|
@ -82,6 +88,13 @@ void MaterialItem::set_ams_info(wxColour col, wxString txt, int ctype, std::vect
|
|||
if (need_refresh) { Refresh();}
|
||||
}
|
||||
|
||||
void MaterialItem::reset_ams_info() {
|
||||
m_ams_name = "-";
|
||||
m_ams_coloul = wxColour(0xEE, 0xEE, 0xEE);
|
||||
m_ams_cols.clear();
|
||||
m_ams_ctype = 0;
|
||||
}
|
||||
|
||||
void MaterialItem::disable()
|
||||
{
|
||||
if (IsEnabled()) {
|
||||
|
@ -330,6 +343,10 @@ void MaterialItem::doRender(wxDC& dc)
|
|||
}
|
||||
}
|
||||
|
||||
void MaterialItem::reset_valid_info() {
|
||||
set_ams_info(m_back_ams_coloul, m_back_ams_name, m_back_ams_ctype, m_back_ams_cols);
|
||||
}
|
||||
|
||||
MaterialSyncItem::MaterialSyncItem(wxWindow *parent, wxColour mcolour, wxString mname) : MaterialItem(parent, mcolour, mname)
|
||||
{
|
||||
|
||||
|
@ -560,6 +577,8 @@ AmsMapingPopup::AmsMapingPopup(wxWindow *parent, bool use_in_sync_dialog) :
|
|||
m_sizer_ams = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_sizer_ams_left = new wxBoxSizer(wxVERTICAL);
|
||||
m_sizer_ams_right = new wxBoxSizer(wxVERTICAL);
|
||||
//m_sizer_ams_left_horizonal = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_sizer_ams_right_horizonal = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_sizer_ams_basket_left = new wxBoxSizer(wxVERTICAL);
|
||||
m_sizer_ams_basket_right = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
|
@ -633,7 +652,26 @@ AmsMapingPopup::AmsMapingPopup(wxWindow *parent, bool use_in_sync_dialog) :
|
|||
m_right_tips->SetBackgroundColour(*wxWHITE);
|
||||
m_right_tips->SetFont(::Label::Body_13);
|
||||
m_right_tips->SetLabel(m_right_tip_text);
|
||||
m_sizer_ams_right->Add(m_right_tips, 0, wxEXPAND | wxBOTTOM, FromDIP(8));
|
||||
m_sizer_ams_right_horizonal->Add(m_right_tips, 0, wxEXPAND | wxBOTTOM, FromDIP(8));
|
||||
|
||||
StateColor cancel_btn_bd_(std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Normal));
|
||||
StateColor cancel_btn_text(std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Normal));
|
||||
StateColor cancel_btn_bg(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(wxColour(255, 255, 255), StateColor::Normal));
|
||||
m_reset_btn = new Button(m_right_marea_panel, _L("Reset"));
|
||||
m_reset_btn->SetMinSize(wxSize(FromDIP(50), FromDIP(20)));
|
||||
m_reset_btn->SetCornerRadius(FromDIP(10));
|
||||
m_reset_btn->SetBackgroundColor(cancel_btn_bg);
|
||||
m_reset_btn->SetBorderColor(cancel_btn_bd_);
|
||||
m_reset_btn->SetTextColor(cancel_btn_text);
|
||||
m_reset_btn->SetId(wxID_CANCEL);
|
||||
m_reset_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](wxCommandEvent &e) { reset_ams_info(); });
|
||||
m_sizer_ams_right_horizonal->AddStretchSpacer();
|
||||
m_sizer_ams_right_horizonal->Add(m_reset_btn, 0, wxEXPAND | wxBOTTOM, FromDIP(8));
|
||||
m_reset_btn->Hide();
|
||||
m_sizer_ams_right_horizonal->AddSpacer(FromDIP(10));
|
||||
|
||||
m_sizer_ams_right->Add(m_sizer_ams_right_horizonal, 0, wxEXPAND, 0);
|
||||
m_right_split_ams_sizer = create_split_sizer(m_right_marea_panel, _L("Right AMS"));
|
||||
m_sizer_ams_right->Add(m_right_split_ams_sizer, 0, wxEXPAND, 0);
|
||||
m_sizer_ams_right->Add(m_sizer_ams_basket_right, 0, wxEXPAND|wxTOP, FromDIP(8));
|
||||
|
@ -674,6 +712,21 @@ AmsMapingPopup::AmsMapingPopup(wxWindow *parent, bool use_in_sync_dialog) :
|
|||
});
|
||||
}
|
||||
|
||||
void AmsMapingPopup::reset_ams_info()
|
||||
{
|
||||
if (m_reset_callback) {
|
||||
m_reset_callback(m_material_index);
|
||||
}
|
||||
}
|
||||
|
||||
void AmsMapingPopup::set_reset_callback(ResetCallback callback) {
|
||||
m_reset_callback = callback;
|
||||
}
|
||||
|
||||
void AmsMapingPopup::show_reset_button() {
|
||||
m_reset_btn->Show();
|
||||
}
|
||||
|
||||
void AmsMapingPopup::set_sizer_title(wxBoxSizer *sizer, wxString text) {
|
||||
if (!sizer) { return; }
|
||||
wxSizerItemList items = sizer->GetChildren();
|
||||
|
|
|
@ -83,10 +83,16 @@ public:
|
|||
wxColour m_material_coloul;
|
||||
wxString m_material_name;
|
||||
|
||||
//info
|
||||
wxColour m_ams_coloul;
|
||||
wxString m_ams_name;
|
||||
int m_ams_ctype = 0;
|
||||
std::vector<wxColour> m_ams_cols = std::vector<wxColour>();
|
||||
//reset
|
||||
wxColour m_back_ams_coloul;
|
||||
wxString m_back_ams_name;
|
||||
int m_back_ams_ctype = 0;
|
||||
std::vector<wxColour> m_back_ams_cols = std::vector<wxColour>();
|
||||
|
||||
ScalableBitmap m_arraw_bitmap_gray;
|
||||
ScalableBitmap m_arraw_bitmap_white;
|
||||
|
@ -101,7 +107,8 @@ public:
|
|||
|
||||
void msw_rescale();
|
||||
void allow_paint_dropdown(bool flag);
|
||||
void set_ams_info(wxColour col, wxString txt, int ctype=0, std::vector<wxColour> cols= std::vector<wxColour>());
|
||||
void set_ams_info(wxColour col, wxString txt, int ctype=0, std::vector<wxColour> cols= std::vector<wxColour>(),bool record_back_info = false);
|
||||
void reset_ams_info();
|
||||
|
||||
void disable();
|
||||
void enable();
|
||||
|
@ -114,6 +121,7 @@ public:
|
|||
virtual void render(wxDC &dc);
|
||||
void match(bool mat);
|
||||
virtual void doRender(wxDC &dc);
|
||||
virtual void reset_valid_info();
|
||||
};
|
||||
|
||||
class MaterialSyncItem : public MaterialItem
|
||||
|
@ -125,7 +133,7 @@ public:
|
|||
void render(wxDC &dc) override;
|
||||
void doRender(wxDC &dc) override;
|
||||
void set_material_index_str(std::string str);
|
||||
|
||||
const std::string &get_material_index_str() { return m_material_index; }
|
||||
private:
|
||||
std::string m_material_index;
|
||||
};
|
||||
|
@ -193,6 +201,7 @@ public:
|
|||
wxBoxSizer *m_sizer_ams{nullptr};
|
||||
wxBoxSizer *m_sizer_ams_left{nullptr};
|
||||
wxBoxSizer *m_sizer_ams_right{nullptr};
|
||||
wxBoxSizer *m_sizer_ams_right_horizonal{nullptr};
|
||||
wxBoxSizer* m_sizer_ams_basket_left{ nullptr };
|
||||
wxBoxSizer* m_sizer_ams_basket_right{ nullptr };
|
||||
wxBoxSizer *m_sizer_list{nullptr};
|
||||
|
@ -207,6 +216,7 @@ public:
|
|||
wxBoxSizer * m_right_split_ams_sizer{nullptr};
|
||||
Label * m_left_tips{nullptr};
|
||||
Label * m_right_tips{nullptr};
|
||||
Button * m_reset_btn{nullptr};
|
||||
wxString m_single_tip_text;
|
||||
wxString m_left_tip_text;
|
||||
wxString m_right_tip_text;
|
||||
|
@ -232,6 +242,17 @@ public:
|
|||
void set_parent_item(wxWindow* item) {m_parent_item = item;};
|
||||
void set_show_type(ShowType type) { m_show_type = type; };
|
||||
std::vector<TrayData> parse_ams_mapping(std::map<std::string, Ams*> amsList);
|
||||
|
||||
using ResetCallback = std::function<void(const std::string&)>;
|
||||
void reset_ams_info();
|
||||
void set_reset_callback(ResetCallback callback);
|
||||
void show_reset_button();
|
||||
void set_material_index_str(std::string str) { m_material_index = str; }
|
||||
const std::string &get_material_index_str() { return m_material_index; }
|
||||
|
||||
private:
|
||||
ResetCallback m_reset_callback{nullptr};
|
||||
std::string m_material_index;
|
||||
};
|
||||
|
||||
class AmsMapingTipPopup : public PopupWindow
|
||||
|
|
|
@ -1294,16 +1294,16 @@ void SyncAmsInfoDialog::finish_mode()
|
|||
|
||||
void SyncAmsInfoDialog::sync_ams_mapping_result(std::vector<FilamentInfo> &result)
|
||||
{
|
||||
m_back_ams_mapping_result = result;
|
||||
if (result.empty()) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "ams_mapping result is empty";
|
||||
for (auto it = m_materialList.begin(); it != m_materialList.end(); it++) {
|
||||
wxString ams_id = "Ext";
|
||||
wxColour ams_col = wxColour(0xCE, 0xCE, 0xCE);
|
||||
it->second->item->set_ams_info(ams_col, ams_id);
|
||||
it->second->item->set_ams_info(ams_col, ams_id, true); // sync_ams_mapping_result
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto f = result.begin(); f != result.end(); f++) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "ams_mapping f id = " << f->id << ", tray_id = " << f->tray_id << ", color = " << f->color << ", type = " << f->type;
|
||||
|
||||
|
@ -1336,7 +1336,7 @@ void SyncAmsInfoDialog::sync_ams_mapping_result(std::vector<FilamentInfo> &resul
|
|||
}
|
||||
std::vector<wxColour> cols;
|
||||
for (auto col : f->colors) { cols.push_back(AmsTray::decode_color(col)); }
|
||||
m->set_ams_info(ams_col, ams_id, f->ctype, cols);
|
||||
m->set_ams_info(ams_col, ams_id, f->ctype, cols,true);//sync_ams_mapping_result
|
||||
break;
|
||||
}
|
||||
iter++;
|
||||
|
@ -2328,7 +2328,7 @@ void SyncAmsInfoDialog::on_set_finish_mapping(wxCommandEvent &evt)
|
|||
auto m = item->item;
|
||||
if (item->id == m_current_filament_id) {
|
||||
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
|
||||
m->set_ams_info(ams_colour, selection_data_arr[4], ctype, material_cols);
|
||||
m->set_ams_info(ams_colour, selection_data_arr[4], ctype, material_cols);//finish
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
@ -2905,9 +2905,26 @@ void SyncAmsInfoDialog::reset_ams_material()
|
|||
int id = iter->first;
|
||||
Material * item = iter->second;
|
||||
auto m = item->item;
|
||||
wxString ams_id = "-";
|
||||
wxColour ams_col = wxColour(0xEE, 0xEE, 0xEE);
|
||||
m->set_ams_info(ams_col, ams_id);
|
||||
m->reset_ams_info();
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void SyncAmsInfoDialog::reset_one_ams_material(const std::string& index_str)
|
||||
{
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material *item = iter->second;
|
||||
auto m = dynamic_cast<MaterialSyncItem*> (item->item);
|
||||
if (m && m->get_material_index_str() == index_str) {
|
||||
m->reset_valid_info();
|
||||
int index = std::atoi(index_str.c_str()) - 1;
|
||||
if (index >=0 && index < m_back_ams_mapping_result.size()) {
|
||||
m_ams_mapping_result[index] = m_back_ams_mapping_result[index];
|
||||
}
|
||||
break;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
@ -3136,12 +3153,13 @@ void SyncAmsInfoDialog::reset_and_sync_ams_list()
|
|||
item = new MaterialSyncItem(m_filament_panel, colour_rgb, _L(display_materials[extruder]));
|
||||
m_sizer_ams_mapping->Add(item, 0, wxALL, FromDIP(5));
|
||||
}
|
||||
item->set_material_index_str(std::to_string(item_index));
|
||||
auto item_index_str = std::to_string(item_index);
|
||||
item->set_material_index_str(item_index_str);
|
||||
item_index++;
|
||||
|
||||
contronal_index++;
|
||||
item->Bind(wxEVT_LEFT_UP, [this, item, materials, extruder](wxMouseEvent &e) {});
|
||||
item->Bind(wxEVT_LEFT_DOWN, [this, item, materials, extruder](wxMouseEvent &e) {
|
||||
item->Bind(wxEVT_LEFT_DOWN, [this, item, materials, extruder, item_index_str](wxMouseEvent &e) {
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
|
@ -3177,6 +3195,12 @@ void SyncAmsInfoDialog::reset_and_sync_ams_list()
|
|||
if (obj_ && m_checkbox_list["use_ams"]->getValue() == "on" && obj_->dev_id == m_printer_last_select) {
|
||||
m_mapping_popup.set_parent_item(item);
|
||||
m_mapping_popup.set_current_filament_id(extruder);
|
||||
m_mapping_popup.set_material_index_str(item_index_str);
|
||||
m_mapping_popup.show_reset_button();
|
||||
auto reset_call_back = [this](const std::string &item_index_str) {
|
||||
reset_one_ams_material(item_index_str);
|
||||
};
|
||||
m_mapping_popup.set_reset_callback(reset_call_back);
|
||||
m_mapping_popup.set_tag_texture(materials[extruder]);
|
||||
m_mapping_popup.set_send_win(this);
|
||||
m_mapping_popup.update(obj_);
|
||||
|
@ -3364,7 +3388,7 @@ void SyncAmsInfoDialog::generate_override_fix_ams_list()
|
|||
for (auto col : m_ams_combo_info.ams_multi_color_filment[index]) {
|
||||
cols.push_back(decode_ams_color(col));
|
||||
}
|
||||
it->second->item->set_ams_info(ams_color, ams_id, 0, cols);
|
||||
it->second->item->set_ams_info(ams_color, ams_id, 0, cols);//generate_override_fix_ams_list
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ class SyncAmsInfoDialog : public DPIDialog
|
|||
std::vector<MachineObject *> m_list;
|
||||
std::vector<FilamentInfo> m_filaments;
|
||||
std::vector<FilamentInfo> m_ams_mapping_result;
|
||||
std::vector<FilamentInfo> m_back_ams_mapping_result;
|
||||
std::vector<int> m_filaments_map;
|
||||
// SendModeSwitchButton* m_mode_print {nullptr};
|
||||
// SendModeSwitchButton* m_mode_send {nullptr};
|
||||
|
@ -170,6 +171,7 @@ public:
|
|||
void reset_timeout();
|
||||
void update_user_printer();
|
||||
void reset_ams_material();
|
||||
void reset_one_ams_material(const std::string & index_str);
|
||||
void update_show_status();
|
||||
void update_printer_combobox(wxCommandEvent &event);
|
||||
void on_cancel(wxCloseEvent &event);
|
||||
|
|
Loading…
Reference in New Issue