FIX: fix plate name encoding issue

Change-Id: Ia89b2c5bbb4519ed938ae23ff124719cfe6203de
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li 2023-06-20 11:54:31 +08:00 committed by Lane.Wei
parent 869a3046aa
commit 14cb2449c6
11 changed files with 45 additions and 55 deletions

View File

@ -2044,7 +2044,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
} }
plate_data_list[it->first-1]->locked = it->second->locked; plate_data_list[it->first-1]->locked = it->second->locked;
plate_data_list[it->first-1]->plate_index = it->second->plate_index-1; plate_data_list[it->first-1]->plate_index = it->second->plate_index-1;
plate_data_list[it->first - 1]->plate_name = it->second->plate_name; plate_data_list[it->first-1]->plate_name = it->second->plate_name;
plate_data_list[it->first-1]->obj_inst_map = it->second->obj_inst_map; plate_data_list[it->first-1]->obj_inst_map = it->second->obj_inst_map;
plate_data_list[it->first-1]->gcode_file = (m_load_restore || it->second->gcode_file.empty()) ? it->second->gcode_file : m_backup_path + "/" + it->second->gcode_file; plate_data_list[it->first-1]->gcode_file = (m_load_restore || it->second->gcode_file.empty()) ? it->second->gcode_file : m_backup_path + "/" + it->second->gcode_file;
plate_data_list[it->first-1]->gcode_prediction = it->second->gcode_prediction; plate_data_list[it->first-1]->gcode_prediction = it->second->gcode_prediction;
@ -3831,7 +3831,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
m_curr_plater->plate_index = atoi(value.c_str()); m_curr_plater->plate_index = atoi(value.c_str());
} }
else if (key == PLATER_NAME_ATTR) { else if (key == PLATER_NAME_ATTR) {
m_curr_plater->plate_name = xml_unescape(encode_path(value.c_str())); m_curr_plater->plate_name = xml_unescape(value.c_str());
} }
else if (key == LOCK_ATTR) else if (key == LOCK_ATTR)
{ {
@ -6997,7 +6997,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
stream << " <" << PLATE_TAG << ">\n"; stream << " <" << PLATE_TAG << ">\n";
//plate index //plate index
stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << PLATERID_ATTR << "\" " << VALUE_ATTR << "=\"" << plate_data->plate_index + 1 << "\"/>\n"; stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << PLATERID_ATTR << "\" " << VALUE_ATTR << "=\"" << plate_data->plate_index + 1 << "\"/>\n";
stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << PLATER_NAME_ATTR << "\" " << VALUE_ATTR << "=\"" << xml_escape(decode_path(plate_data->plate_name.c_str())) << "\"/>\n"; stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << PLATER_NAME_ATTR << "\" " << VALUE_ATTR << "=\"" << xml_escape(plate_data->plate_name.c_str()) << "\"/>\n";
stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << LOCK_ATTR << "\" " << VALUE_ATTR << "=\"" << std::boolalpha<< plate_data->locked<< "\"/>\n"; stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << LOCK_ATTR << "\" " << VALUE_ATTR << "=\"" << std::boolalpha<< plate_data->locked<< "\"/>\n";
ConfigOption* bed_type_opt = plate_data->config.option("curr_bed_type"); ConfigOption* bed_type_opt = plate_data->config.option("curr_bed_type");
t_config_enum_names bed_type_names = ConfigOptionEnum<BedType>::get_enum_names(); t_config_enum_names bed_type_names = ConfigOptionEnum<BedType>::get_enum_names();

View File

@ -552,7 +552,7 @@ protected:
bool m_no_check = false; bool m_no_check = false;
// current plate name // current plate name
std::string m_plate_name; std::string m_plate_name; // utf8 string
// Callback to be evoked regularly to update state of the UI thread. // Callback to be evoked regularly to update state of the UI thread.
status_callback_type m_status_callback; status_callback_type m_status_callback;

View File

@ -571,6 +571,19 @@ inline std::string get_bbl_remain_time_dhms(float time_in_secs)
bool bbl_calc_md5(std::string &filename, std::string &md5_out); bool bbl_calc_md5(std::string &filename, std::string &md5_out);
inline std::string filter_characters(const std::string& str, const std::string& filterChars)
{
std::string filteredStr = str;
auto removeFunc = [&filterChars](char ch) {
return filterChars.find(ch) != std::string::npos;
};
filteredStr.erase(std::remove_if(filteredStr.begin(), filteredStr.end(), removeFunc), filteredStr.end());
return filteredStr;
}
} // namespace Slic3r } // namespace Slic3r
#if WIN32 #if WIN32

View File

@ -483,7 +483,7 @@ bool GLTexture::generate_from_text(const std::string &text_str, wxFont &font, wx
return false; return false;
} }
wxString msg = text_str; wxString msg = from_u8(text_str);
wxMemoryDC memDC; wxMemoryDC memDC;
memDC.SetFont(font); memDC.SetFont(font);

View File

@ -455,14 +455,12 @@ wxBitmap& ObjectDataViewModel::GetWarningBitmap(const std::string& warning_icon_
wxDataViewItem ObjectDataViewModel::AddPlate(PartPlate* part_plate, wxString name, bool refresh) wxDataViewItem ObjectDataViewModel::AddPlate(PartPlate* part_plate, wxString name, bool refresh)
{ {
int plate_idx = part_plate ? part_plate->get_index() : -1; int plate_idx = part_plate ? part_plate->get_index() : -1;
wxString plate_name = name; wxString plate_name;
if (plate_name == "") { if (name.empty()) {
plate_name = _L("Plate"); plate_name = _L("Plate");
std::string plate_CustomName = part_plate ? part_plate->get_plate_name() : ""; plate_name += wxString::Format(" %d", plate_idx + 1);
if (plate_CustomName.length() > 0) { if (!part_plate->get_plate_name().empty()) {
plate_name << " " << plate_idx + 1 << " (" << plate_CustomName << ")"; plate_name += wxString(" (", wxConvUTF8) + from_u8(part_plate->get_plate_name()) + wxString(")", wxConvUTF8);
} else {
plate_name << " " << plate_idx + 1;
} }
} }
auto plate_node = new ObjectDataViewModelNode(part_plate, plate_name); auto plate_node = new ObjectDataViewModelNode(part_plate, plate_name);

View File

@ -149,7 +149,7 @@ private:
DynamicPrintConfig m_config; DynamicPrintConfig m_config;
// part plate name // part plate name
std::string m_name; std::string m_name; // utf8 string
bool m_name_change = false; bool m_name_change = false;
GeometryBuffer m_plate_name_icon; GeometryBuffer m_plate_name_icon;
mutable unsigned int m_plate_name_vbo_id{0}; mutable unsigned int m_plate_name_vbo_id{0};

View File

@ -6690,9 +6690,15 @@ wxString Plater::priv::get_project_filename(const wxString& extension) const
wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool only_filename, bool export_all) wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool only_filename, bool export_all)
{ {
std::string plate_index_str = ""; wxString curr_project_name = m_project_name;
std::string plate_index_str = "";
std::string plate_name = partplate_list.get_curr_plate()->get_plate_name();
// remove unsupported characters in filename
curr_project_name = from_u8(filter_characters(curr_project_name.ToUTF8().data(), "<>[]:/\\|?*\""));
plate_name = filter_characters(plate_name, "<>[]:/\\|?*\"");
auto plate_name = partplate_list.get_curr_plate()->get_plate_name();
if (!plate_name.empty()) if (!plate_name.empty())
plate_index_str = (boost::format("_%1%") % plate_name).str(); plate_index_str = (boost::format("_%1%") % plate_name).str();
else if (partplate_list.get_plate_count() > 1) else if (partplate_list.get_plate_count() > 1)
@ -6701,24 +6707,24 @@ wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool
if (!m_project_folder.empty()) { if (!m_project_folder.empty()) {
if (!only_filename) { if (!only_filename) {
if (export_all) { if (export_all) {
auto full_filename = m_project_folder / std::string((m_project_name + extension).mb_str(wxConvUTF8)); auto full_filename = m_project_folder / std::string((curr_project_name + extension).mb_str(wxConvUTF8));
return from_path(full_filename); return from_path(full_filename);
} else { } else {
auto full_filename = m_project_folder / std::string((m_project_name + plate_index_str + extension).mb_str(wxConvUTF8)); auto full_filename = m_project_folder / std::string((curr_project_name + from_u8(plate_index_str) + extension).mb_str(wxConvUTF8));
return from_path(full_filename); return from_path(full_filename);
} }
} else { } else {
if (export_all) if (export_all)
return m_project_name + wxString(plate_index_str) + extension; return curr_project_name + extension;
else else
return m_project_name + extension; return curr_project_name + from_u8(plate_index_str) + extension;
} }
} else { } else {
if (only_filename) { if (only_filename) {
if (export_all) if (export_all)
return m_project_name + extension; return curr_project_name + extension;
else else
return m_project_name + wxString(plate_index_str) + extension; return curr_project_name + from_u8(plate_index_str) + extension;
} }
else else
return ""; return "";
@ -9876,7 +9882,6 @@ void Plater::export_gcode_3mf(bool export_all)
//BBS replace gcode extension to .gcode.3mf //BBS replace gcode extension to .gcode.3mf
default_output_file = default_output_file.replace_extension(".gcode.3mf"); default_output_file = default_output_file.replace_extension(".gcode.3mf");
default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string(),true));
//Get a last save path //Get a last save path
start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), false); start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), false);
@ -11914,7 +11919,8 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
else else
dlg.sync_print_seq(0); dlg.sync_print_seq(0);
dlg.set_plate_name(curr_plate->get_plate_name()); wxString curr_plate_name = from_u8(curr_plate->get_plate_name());
dlg.set_plate_name(curr_plate_name);
dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index, &dlg](wxCommandEvent& e) { dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index, &dlg](wxCommandEvent& e) {
PartPlate *curr_plate = p->partplate_list.get_curr_plate(); PartPlate *curr_plate = p->partplate_list.get_curr_plate();
@ -11941,7 +11947,8 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
}); });
dlg.ShowModal(); dlg.ShowModal();
curr_plate->set_plate_name(dlg.get_plate_name().ToStdString()); wxString dlg_plate_name = dlg.get_plate_name();
curr_plate->set_plate_name(dlg_plate_name.ToUTF8().data());
this->schedule_background_process(); this->schedule_background_process();
} }

View File

@ -3318,19 +3318,6 @@ void SelectMachineDialog::set_flow_calibration_state(bool state)
} }
} }
std::string SelectMachineDialog::filter_characters(const std::string& str, const std::string& filterChars)
{
std::string filteredStr = str;
auto removeFunc = [&filterChars](char ch) {
return filterChars.find(ch) != std::string::npos;
};
filteredStr.erase(std::remove_if(filteredStr.begin(), filteredStr.end(), removeFunc), filteredStr.end());
return filteredStr;
}
void SelectMachineDialog::set_default() void SelectMachineDialog::set_default()
{ {
if (m_print_type == PrintFromType::FROM_NORMAL) { if (m_print_type == PrintFromType::FROM_NORMAL) {
@ -3365,7 +3352,7 @@ void SelectMachineDialog::set_default()
m_current_project_name = wxString::FromUTF8(filename_path.filename().string()); m_current_project_name = wxString::FromUTF8(filename_path.filename().string());
//unsupported character filter //unsupported character filter
m_current_project_name = filter_characters(m_current_project_name.ToStdString(), "<>[]:/\\|?*\""); m_current_project_name = from_u8(filter_characters(m_current_project_name.ToUTF8().data(), "<>[]:/\\|?*\""));
m_rename_text->SetLabelText(m_current_project_name); m_rename_text->SetLabelText(m_current_project_name);
m_rename_normal_panel->Layout(); m_rename_normal_panel->Layout();

View File

@ -455,7 +455,6 @@ public:
wxWindow* create_item_checkbox(wxString title, wxWindow* parent, wxString tooltip, std::string param); wxWindow* create_item_checkbox(wxString title, wxWindow* parent, wxString tooltip, std::string param);
wxImage * LoadImageFromBlob(const unsigned char *data, int size); wxImage * LoadImageFromBlob(const unsigned char *data, int size);
PrintDialogStatus get_status() { return m_print_status; } PrintDialogStatus get_status() { return m_print_status; }
std::string filter_characters(const std::string& str, const std::string& filterChars);
std::vector<std::string> sort_string(std::vector<std::string> strArray); std::vector<std::string> sort_string(std::vector<std::string> strArray);
}; };

View File

@ -1211,19 +1211,6 @@ void SendToPrinterDialog::on_dpi_changed(const wxRect &suggested_rect)
Refresh(); Refresh();
} }
std::string SendToPrinterDialog::filter_characters(const std::string& str, const std::string& filterChars)
{
std::string filteredStr = str;
auto removeFunc = [&filterChars](char ch) {
return filterChars.find(ch) != std::string::npos;
};
filteredStr.erase(std::remove_if(filteredStr.begin(), filteredStr.end(), removeFunc), filteredStr.end());
return filteredStr;
}
void SendToPrinterDialog::set_default() void SendToPrinterDialog::set_default()
{ {
//project name //project name
@ -1244,7 +1231,7 @@ void SendToPrinterDialog::set_default()
m_current_project_name = wxString::FromUTF8(filename_path.filename().string()); m_current_project_name = wxString::FromUTF8(filename_path.filename().string());
//unsupported character filter //unsupported character filter
m_current_project_name = filter_characters(m_current_project_name.ToStdString(), "<>[]:/\\|?*\""); m_current_project_name = from_u8(filter_characters(m_current_project_name.ToUTF8().data(), "<>[]:/\\|?*\""));
m_rename_text->SetLabelText(m_current_project_name); m_rename_text->SetLabelText(m_current_project_name);
m_rename_normal_panel->Layout(); m_rename_normal_panel->Layout();

View File

@ -152,7 +152,6 @@ public:
void show_print_failed_info(bool show, int code = 0, wxString description = wxEmptyString, wxString extra = wxEmptyString); void show_print_failed_info(bool show, int code = 0, wxString description = wxEmptyString, wxString extra = wxEmptyString);
void update_print_error_info(int code, std::string msg, std::string extra); void update_print_error_info(int code, std::string msg, std::string extra);
wxString format_text(wxString& m_msg); wxString format_text(wxString& m_msg);
std::string filter_characters(const std::string& str, const std::string& filterChars);
std::vector<std::string> sort_string(std::vector<std::string> strArray); std::vector<std::string> sort_string(std::vector<std::string> strArray);
}; };