Merge branch 'main' into dev/h2d-2

# Conflicts:
#	localization/i18n/list.txt
#	src/slic3r/GUI/CalibrationWizardPresetPage.cpp
#	src/slic3r/GUI/DeviceManager.cpp
#	src/slic3r/GUI/DeviceManager.hpp
#	src/slic3r/GUI/Printer/PrinterFileSystem.cpp
#	src/slic3r/GUI/Printer/PrinterFileSystem.h
#	src/slic3r/GUI/SelectMachine.hpp
#	src/slic3r/GUI/SendToPrinter.cpp
#	src/slic3r/GUI/SendToPrinter.hpp
#	src/slic3r/GUI/StatusPanel.hpp
#	src/slic3r/GUI/Widgets/AnimaController.cpp
This commit is contained in:
Noisyfox
2025-10-24 09:44:41 +08:00
36 changed files with 3565 additions and 80 deletions

View File

@@ -39,6 +39,7 @@ wxDEFINE_EVENT(EVT_FILE_CHANGED, wxCommandEvent);
wxDEFINE_EVENT(EVT_SELECT_CHANGED, wxCommandEvent);
wxDEFINE_EVENT(EVT_THUMBNAIL, wxCommandEvent);
wxDEFINE_EVENT(EVT_DOWNLOAD, wxCommandEvent);
wxDEFINE_EVENT(EVT_RAMDOWNLOAD, wxCommandEvent);
wxDEFINE_EVENT(EVT_MEDIA_ABILITY_CHANGED, wxCommandEvent);
wxDEFINE_EVENT(EVT_UPLOADING, wxCommandEvent);
wxDEFINE_EVENT(EVT_UPLOAD_CHANGED, wxCommandEvent);
@@ -271,6 +272,149 @@ struct PrinterFileSystem::Upload : Progress
boost::filesystem::ifstream ifs;
};
void PrinterFileSystem::GetPickImages(const std::vector<std::string> &local_paths, const std::vector<std::string> &targetpaths)
{
m_download_states.clear();
GetPickImage(1, local_paths[0], targetpaths[0]);
GetPickImage(2, local_paths[1], targetpaths[1]);
GetPickImage(3, local_paths[2], targetpaths[2]);
}
void PrinterFileSystem::GetPickImage(int id, const std::string &local_path, const std::string &targetpath)
{
json j;
j["sequence_id"] = id;
j["version"] = 1;
j["peer_host"] = "studio";
j["command"] = "get_project_file";
j["file_rel_path"] = targetpath;
std::string param = j.dump();
DownloadRamFile(16, local_path, param);
}
void PrinterFileSystem::DownloadRamFile(int index, const std::string &local_path, const std::string & param)
{
std::shared_ptr<Download> download(new Download);
download->local_path = local_path;
json req;
req["path"] = "mem:/" + std::to_string(index);
req["offset"] = 0;
req["mem_dl_param_size"] = param.size();
m_download_seq = SendRequest<Progress>(
FILE_DOWNLOAD, req,
[download](json const &resp, Progress &prog, unsigned char const *data) -> int {
size_t size = resp.value("size", 0);
prog.size = resp["offset"];
prog.total = resp["total"];
if (resp.contains("mem_dl_param_size")) {
size_t s = resp["mem_dl_param_size"].get<size_t>();
std::string json_str(reinterpret_cast<const char *>(data), s);
// OutputDebugStringA(json_str.c_str());
// OutputDebugStringA("\n");
json mem_dl_json = json::parse(json_str);
// download->mem_dl_param_size = size;
if (!mem_dl_json.contains("result") || mem_dl_json["result"] == 1 ) {
wxLogWarning("Download failed: result = 1");
return ERROR_JSON;
}
if(mem_dl_json.contains("size") && mem_dl_json["size"] == 0 )
return FILE_SIZE_ERR;
return CONTINUE;
}
if (prog.size == 0 ) {
download->ofs.open(download->local_path, std::ios::binary);
if (!download->ofs) {
download->error = last_system_error();
wxLogWarning("DownloadImageFromRam open error: %s\n", wxString::FromUTF8(download->error));
return FILE_OPEN_ERR;
}
}
download->ofs.write(reinterpret_cast<const char *>(data), size);
if (!download->ofs) {
download->error = last_system_error();
wxLogWarning("DownloadImageFromRam write error: %s\n", wxString::FromUTF8(download->error));
return FILE_READ_WRITE_ERR;
}
download->boost_md5.process_bytes(data, size);
prog.size += size;
download->total = prog.total;
download->size = prog.size;
if (prog.size < prog.total) {
return 0;
}
download->ofs.close();
std::string md5 = resp["file_md5"];
boost::uuids::detail::md5::digest_type digest;
download->boost_md5.get_digest(digest);
for (int i = 0; i < 4; ++i) digest[i] = boost::endian::endian_reverse(digest[i]);
std::string str_md5;
const auto char_digest = reinterpret_cast<const char *>(&digest[0]);
boost::algorithm::hex(char_digest, char_digest + sizeof(digest), std::back_inserter(str_md5));
if (!boost::iequals(str_md5, md5)) {
wxLogWarning("DownloadImageFromRam checksum error: %s != %s\n", str_md5, md5);
boost::system::error_code ec;
boost::filesystem::rename(download->local_path, download->local_path + ".tmp", ec);
return FILE_CHECK_ERR;
}
return SUCCESS;
},
[this, download](int result, Progress const &data) {
//OutputDebugStringA(std::to_string(result).c_str());
//OutputDebugStringA("\n");
if (result == CONTINUE) { return; }
std::string msg;
if (result == SUCCESS) {
if (std::filesystem::exists(download->local_path)) {
m_download_states.emplace_back(true);
BOOST_LOG_TRIVIAL(info) <<"DownloadImageFromRam finished: " << download->local_path << "result = " << result;
}else{
m_download_states.emplace_back(false);
BOOST_LOG_TRIVIAL(warning) <<"DownloadImageFromRam finished, but file not exist: " << download->local_path << "result = " << result;
}
} else if (result != CONTINUE) {
m_download_states.emplace_back(false);
BOOST_LOG_TRIVIAL(warning) << "DownloadImageFromRam failed: " << download->error << "result = " << result;
}
if(m_download_states.size() == 3){
if(m_download_states[0] && m_download_states[1] && m_download_states[2]){
SendChangedEvent(EVT_RAMDOWNLOAD, SUCCESS);
}else{
// FILE_NO_EXIST is not really error_code
SendChangedEvent(EVT_RAMDOWNLOAD, FILE_NO_EXIST);
}
}else{
BOOST_LOG_TRIVIAL(warning) << "m_download_states current size is : " << m_download_states.size();
}
},param);
}
void PrinterFileSystem::SendExistedFile(){
SendChangedEvent(EVT_RAMDOWNLOAD, SUCCESS);
}
void PrinterFileSystem::SendConnectFail(){
SendChangedEvent(EVT_RAMDOWNLOAD, ERROR_PIPE);
}
void PrinterFileSystem::DownloadFiles(size_t index, std::string const &path)
{
if (index == (size_t) -1) {
@@ -304,6 +448,10 @@ void PrinterFileSystem::DownloadFiles(size_t index, std::string const &path)
DownloadNextFile();
}
void PrinterFileSystem::DownloadCheckFiles(std::string const &path)
{
for (size_t i = 0; i < m_file_list.size(); ++i) {
@@ -1280,7 +1428,7 @@ void PrinterFileSystem::CancelUploadTask(bool send_cancel_req)
}
}
boost::uint32_t PrinterFileSystem::SendRequest(int type, json const &req, callback_t2 const &callback)
boost::uint32_t PrinterFileSystem::SendRequest(int type, json const &req, callback_t2 const &callback,const std::string& param)
{
if (m_session.tunnel == nullptr) {
Retry();
@@ -1294,6 +1442,13 @@ boost::uint32_t PrinterFileSystem::SendRequest(int type, json const &req, callba
root["req"] = req;
std::ostringstream oss;
oss << root;
if (!param.empty()) {
oss << "\n\n";
oss << param;
}
// OutputDebugStringA(oss.str().c_str());
// OutputDebugStringA("\n");
auto msg = oss.str();
boost::unique_lock l(m_mutex);
m_messages.push_back(msg);