Merge: Snapmaker Orca 2.1.2

This commit is contained in:
xiaoyeliu
2025-11-17 10:04:25 +08:00
parent 737948be1f
commit e89263e51a
1147 changed files with 668188 additions and 15290 deletions
+62 -7
View File
@@ -1276,16 +1276,16 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
// Read a 64k block from the end of the G-code.
boost::nowide::ifstream ifs(file);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": before parse_file %1%") % file.c_str();
// Look for Slic3r or OrcaSlicer header.
// Look for Slic3r or Snapmaker_Orca header.
// Look for the header across the whole file as the G-code may have been extended at the start by a post-processing script or the user.
//BBS
bool has_delimiters = true;
{
//BBS
std::string bambuslicer_gcode_header = "; OrcaSlicer";
std::string bambuslicer_gcode_header = "; Snapmaker_Orca";
std::string orcaslicer_gcode_header = std::string("; generated by ");
orcaslicer_gcode_header += SLIC3R_APP_NAME;
std::string Snapmaker_Orca_gcode_header = std::string("; generated by ");
Snapmaker_Orca_gcode_header += SLIC3R_APP_NAME;
std::string header;
bool header_found = false;
@@ -1297,7 +1297,7 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
line_c = skip_whitespaces(line_c);
// BBS
if (strncmp(bambuslicer_gcode_header.c_str(), line_c, strlen(bambuslicer_gcode_header.c_str())) == 0 ||
strncmp(orcaslicer_gcode_header.c_str(), line_c, strlen(orcaslicer_gcode_header.c_str())) == 0) {
strncmp(Snapmaker_Orca_gcode_header.c_str(), line_c, strlen(Snapmaker_Orca_gcode_header.c_str())) == 0) {
header_found = true;
break;
}
@@ -1324,11 +1324,66 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
bool begin_found = false;
bool end_found = false;
std::string line;
while (std::getline(ifs, line))
if (line.rfind("; CONFIG_BLOCK_START",0)==0) {
int thumbnail_id = 0;
while (std::getline(ifs, line)) {
// 找到缩略图开始标记
if (line.find("; THUMBNAIL_BLOCK_START") != std::string::npos) {
std::string thumb_content = "";
int width = 0;
int height = 0;
int data_size = 0;
// 跳过空行
std::getline(ifs, line);
std::getline(ifs, line);
// 读取缩略图信息行
std::getline(ifs, line);
if (line.find("; thumbnail begin") != std::string::npos) {
// 解析宽度、高度和数据大小
// 格式: "; thumbnail begin 48x48 1144"
sscanf(line.c_str(), "; thumbnail begin %dx%d %d", &width, &height, &data_size);
// 读取Base64编码的数据
std::string base64_data;
while (std::getline(ifs, line)) {
if (line.find("; thumbnail end") != std::string::npos) {
break;
}
// 移除行首的 "; "
if (line.substr(0, 2) == "; ") {
base64_data += line.substr(2);
}
}
thumb_content = base64_data;
this->set_deserialize("thumb" + std::to_string(thumbnail_id++), thumb_content, substitutions_ctxt);
}
// 读取到块结束标记
while (std::getline(ifs, line)) {
if (line.find("; THUMBNAIL_BLOCK_END") != std::string::npos) {
break;
}
}
/*if (thumbnail_id == 2)
break;*/
}
}
ifs.clear(); // 清除可能的 EOF 标志
ifs.seekg(0);
while (std::getline(ifs, line)) {
if (line.rfind("; CONFIG_BLOCK_START", 0) == 0) {
begin_found = true;
break;
}
}
if (!begin_found) {
//BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << format("Configuration block closing tag \"; CONFIG_BLOCK_START\" not found when reading %1%", file);
throw Slic3r::RuntimeError(format("Config tag \"; CONFIG_BLOCK_START\" not found"));