mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 01:37:53 -06:00
FIX: fix saving wrong encoding to 3mf
Change-Id: Icebf770b3dde06216e427744de9377e3f0adda29 Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
5194e68ae4
commit
038a04175a
4 changed files with 67 additions and 27 deletions
|
@ -2757,31 +2757,31 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
check_painting_version(m_mm_painting_version, MM_PAINTING_VERSION,
|
check_painting_version(m_mm_painting_version, MM_PAINTING_VERSION,
|
||||||
_(L("The selected 3MF contains multi-material painted object using a newer version of BambuStudio and is not compatible.")));*/
|
_(L("The selected 3MF contains multi-material painted object using a newer version of BambuStudio and is not compatible.")));*/
|
||||||
} else if (m_curr_metadata_name == BBL_MODEL_ID_TAG) {
|
} else if (m_curr_metadata_name == BBL_MODEL_ID_TAG) {
|
||||||
m_model_id = m_curr_characters;
|
m_model_id = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_MODEL_NAME_TAG) {
|
} else if (m_curr_metadata_name == BBL_MODEL_NAME_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found model name = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found model name = " << m_curr_characters;
|
||||||
model_info.model_name = m_curr_characters;
|
model_info.model_name = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_DESIGNER_TAG) {
|
} else if (m_curr_metadata_name == BBL_DESIGNER_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer = " << m_curr_characters;
|
||||||
m_designer = m_curr_characters;
|
m_designer = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_DESIGNER_USER_ID_TAG) {
|
} else if (m_curr_metadata_name == BBL_DESIGNER_USER_ID_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_user_id = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_user_id = " << m_curr_characters;
|
||||||
m_designer_user_id = m_curr_characters;
|
m_designer_user_id = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_DESIGNER_COVER_FILE_TAG) {
|
} else if (m_curr_metadata_name == BBL_DESIGNER_COVER_FILE_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_cover = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_cover = " << m_curr_characters;
|
||||||
model_info.cover_file = m_curr_characters;
|
model_info.cover_file = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_DESCRIPTION_TAG) {
|
} else if (m_curr_metadata_name == BBL_DESCRIPTION_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found description = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found description = " << m_curr_characters;
|
||||||
model_info.description = m_curr_characters;
|
model_info.description = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_LICENSE_TAG) {
|
} else if (m_curr_metadata_name == BBL_LICENSE_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found license = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found license = " << m_curr_characters;
|
||||||
model_info.license = m_curr_characters;
|
model_info.license = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_COPYRIGHT_TAG) {
|
} else if (m_curr_metadata_name == BBL_COPYRIGHT_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found copyright = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found copyright = " << m_curr_characters;
|
||||||
model_info.copyright = m_curr_characters;
|
model_info.copyright = xml_unescape(m_curr_characters);
|
||||||
} else if (m_curr_metadata_name == BBL_REGION_TAG) {
|
} else if (m_curr_metadata_name == BBL_REGION_TAG) {
|
||||||
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found region = " << m_curr_characters;
|
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found region = " << m_curr_characters;
|
||||||
m_contry_code = m_curr_characters;
|
m_contry_code = xml_unescape(m_curr_characters);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -4363,6 +4363,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
reset_stream(stream);
|
reset_stream(stream);
|
||||||
|
@ -4413,27 +4414,29 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
model_id = project->project_model_id;
|
model_id = project->project_model_id;
|
||||||
region_code = project->project_country_code;
|
region_code = project->project_country_code;
|
||||||
}
|
}
|
||||||
|
if (!sub_model) {
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_MODEL_NAME_TAG << "\">" << xml_escape(name) << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESIGNER_TAG << "\">" << xml_escape(user_name) << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESIGNER_USER_ID_TAG << "\">" << user_id << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESIGNER_COVER_FILE_TAG << "\">" << xml_escape(design_cover) << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESCRIPTION_TAG << "\">" << xml_escape(description) << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_COPYRIGHT_TAG << "\">" << xml_escape(copyright) << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_LICENSE_TAG << "\">" << xml_escape(license) << "</" << METADATA_TAG << ">\n";
|
||||||
|
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_MODEL_NAME_TAG << "\">" << xml_escape(name) << "</" << METADATA_TAG << ">\n";
|
/* save model info */
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESIGNER_TAG << "\">" << xml_escape(user_name) << "</" << METADATA_TAG << ">\n";
|
if (!model_id.empty()) {
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESIGNER_USER_ID_TAG << "\">" << user_id << "</" << METADATA_TAG << ">\n";
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_MODEL_ID_TAG << "\">" << model_id << "</" << METADATA_TAG << ">\n";
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESIGNER_COVER_FILE_TAG << "\">" << xml_escape(design_cover) << "</" << METADATA_TAG << ">\n";
|
stream << " <" << METADATA_TAG << " name=\"" << BBL_REGION_TAG << "\">" << region_code << "</" << METADATA_TAG << ">\n";
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_DESCRIPTION_TAG << "\">" << xml_escape(description) << "</" << METADATA_TAG << ">\n";
|
}
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_COPYRIGHT_TAG << "\">" << xml_escape(copyright) << "</" << METADATA_TAG << ">\n";
|
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_LICENSE_TAG << "\">" << xml_escape(license) << "</" << METADATA_TAG << ">\n";
|
|
||||||
|
|
||||||
/* save model info */
|
std::string date = Slic3r::Utils::utc_timestamp(Slic3r::Utils::get_current_time_utc());
|
||||||
if (!model_id.empty()) {
|
// keep only the date part of the string
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_MODEL_ID_TAG << "\">" << model_id << "</" << METADATA_TAG << ">\n";
|
date = date.substr(0, 10);
|
||||||
stream << " <" << METADATA_TAG << " name=\"" << BBL_REGION_TAG << "\">" << region_code << "</" << METADATA_TAG << ">\n";
|
stream << " <" << METADATA_TAG << " name=\"CreationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"ModificationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
||||||
|
stream << " <" << METADATA_TAG << " name=\"Application\">" << SLIC3R_APP_KEY << "-" << SLIC3R_VERSION << "</" << METADATA_TAG << ">\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string date = Slic3r::Utils::utc_timestamp(Slic3r::Utils::get_current_time_utc());
|
|
||||||
// keep only the date part of the string
|
|
||||||
date = date.substr(0, 10);
|
|
||||||
stream << " <" << METADATA_TAG << " name=\"CreationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
|
||||||
stream << " <" << METADATA_TAG << " name=\"ModificationDate\">" << date << "</" << METADATA_TAG << ">\n";
|
|
||||||
stream << " <" << METADATA_TAG << " name=\"Application\">" << SLIC3R_APP_KEY << "-" << SLIC3R_VERSION << "</" << METADATA_TAG << ">\n";
|
|
||||||
stream << " <" << RESOURCES_TAG << ">\n";
|
stream << " <" << RESOURCES_TAG << ">\n";
|
||||||
std::string buf = stream.str();
|
std::string buf = stream.str();
|
||||||
if (! buf.empty() && ! mz_zip_writer_add_staged_data(&context, buf.data(), buf.size())) {
|
if (! buf.empty() && ! mz_zip_writer_add_staged_data(&context, buf.data(), buf.size())) {
|
||||||
|
|
|
@ -283,6 +283,7 @@ inline typename CONTAINER_TYPE::value_type& next_value_modulo(typename CONTAINER
|
||||||
}
|
}
|
||||||
|
|
||||||
extern std::string xml_escape(std::string text, bool is_marked = false);
|
extern std::string xml_escape(std::string text, bool is_marked = false);
|
||||||
|
extern std::string xml_unescape(std::string text);
|
||||||
|
|
||||||
|
|
||||||
#if defined __GNUC__ && __GNUC__ < 5 && !defined __clang__
|
#if defined __GNUC__ && __GNUC__ < 5 && !defined __clang__
|
||||||
|
|
|
@ -1182,6 +1182,42 @@ std::string xml_escape(std::string text, bool is_marked/* = false*/)
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string xml_unescape(std::string s)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
std::string::size_type i = 0;
|
||||||
|
std::string::size_type pos = 0;
|
||||||
|
while (i < s.size()) {
|
||||||
|
std::string rep;
|
||||||
|
if (s[i] == '&') {
|
||||||
|
if (s.substr(i, 4) == "<") {
|
||||||
|
ret += s.substr(pos, i - pos) + "<";
|
||||||
|
i += 4;
|
||||||
|
pos = i;
|
||||||
|
}
|
||||||
|
else if (s.substr(i, 4) == ">") {
|
||||||
|
ret += s.substr(pos, i - pos) + ">";
|
||||||
|
i += 4;
|
||||||
|
pos = i;
|
||||||
|
}
|
||||||
|
else if (s.substr(i, 5) == "&") {
|
||||||
|
ret += s.substr(pos, i - pos) + "&";
|
||||||
|
i += 5;
|
||||||
|
pos = i;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret += s.substr(pos);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
std::string format_memsize_MB(size_t n)
|
std::string format_memsize_MB(size_t n)
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
|
|
|
@ -364,7 +364,7 @@ void AuFile::on_set_cover()
|
||||||
{
|
{
|
||||||
if (wxGetApp().plater()->model().model_info == nullptr) { wxGetApp().plater()->model().model_info = std::make_shared<ModelInfo>(); }
|
if (wxGetApp().plater()->model().model_info == nullptr) { wxGetApp().plater()->model().model_info = std::make_shared<ModelInfo>(); }
|
||||||
|
|
||||||
wxGetApp().plater()->model().model_info->cover_file = m_file_name.ToStdString();
|
wxGetApp().plater()->model().model_info->cover_file = std::string(m_file_name.ToUTF8().data());
|
||||||
|
|
||||||
auto full_path = m_file_path.branch_path();
|
auto full_path = m_file_path.branch_path();
|
||||||
auto full_root_path = full_path.branch_path();
|
auto full_root_path = full_path.branch_path();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue