2022-07-15 15:37:19 +00:00
|
|
|
#include "PrinterFileSystem.h"
|
|
|
|
#include "libslic3r/Utils.hpp"
|
2023-04-23 01:18:10 +00:00
|
|
|
#include "libslic3r/Format/bbs_3mf.hpp"
|
|
|
|
#include "libslic3r/Model.hpp"
|
2022-07-15 15:37:19 +00:00
|
|
|
|
2022-07-22 09:46:10 +00:00
|
|
|
#include "../../Utils/NetworkAgent.hpp"
|
2022-10-20 01:29:51 +00:00
|
|
|
#include "../BitmapCache.hpp"
|
2022-07-22 09:46:10 +00:00
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
#include <boost/algorithm/hex.hpp>
|
|
|
|
#include <boost/uuid/detail/md5.hpp>
|
2023-04-23 01:18:10 +00:00
|
|
|
#include <boost/regex.hpp>
|
2022-07-15 15:37:19 +00:00
|
|
|
|
|
|
|
#include "nlohmann/json.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2022-10-09 03:11:47 +00:00
|
|
|
#ifndef NDEBUG
|
2022-08-17 02:12:10 +00:00
|
|
|
//#define PRINTER_FILE_SYSTEM_TEST
|
2022-10-09 03:11:47 +00:00
|
|
|
#endif
|
2022-08-17 02:12:10 +00:00
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
wxDEFINE_EVENT(EVT_STATUS_CHANGED, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(EVT_MODE_CHANGED, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(EVT_FILE_CHANGED, wxCommandEvent);
|
2022-10-14 01:25:17 +00:00
|
|
|
wxDEFINE_EVENT(EVT_SELECT_CHANGED, wxCommandEvent);
|
2022-07-15 15:37:19 +00:00
|
|
|
wxDEFINE_EVENT(EVT_THUMBNAIL, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(EVT_DOWNLOAD, wxCommandEvent);
|
|
|
|
|
|
|
|
wxDEFINE_EVENT(EVT_FILE_CALLBACK, wxCommandEvent);
|
|
|
|
|
|
|
|
static wxBitmap default_thumbnail;
|
|
|
|
|
|
|
|
struct StaticBambuLib : BambuLib {
|
|
|
|
static StaticBambuLib & get();
|
2022-08-17 02:12:10 +00:00
|
|
|
static int Fake_Bambu_Create(Bambu_Tunnel*, char const*) { return -2; }
|
2022-07-15 15:37:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PrinterFileSystem::PrinterFileSystem()
|
|
|
|
: BambuLib(StaticBambuLib::get())
|
|
|
|
{
|
2022-11-17 02:50:14 +00:00
|
|
|
if (!default_thumbnail.IsOk()) {
|
2022-10-20 01:29:51 +00:00
|
|
|
default_thumbnail = *Slic3r::GUI::BitmapCache().load_svg("printer_file", 0, 0);
|
2022-11-17 02:50:14 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
default_thumbnail = wxBitmap(default_thumbnail.ConvertToImage(), -1, 1);
|
|
|
|
#endif
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
m_session.owner = this;
|
2022-08-17 02:12:10 +00:00
|
|
|
#ifdef PRINTER_FILE_SYSTEM_TEST
|
|
|
|
auto time = wxDateTime::Now();
|
2023-04-23 01:18:10 +00:00
|
|
|
wxString path = "D:\\work\\pic\\";
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
auto name = wxString::Format(L"gcode-%02d.3mf", i + 1);
|
|
|
|
m_file_list.push_back({name.ToUTF8().data(), "", time.GetTicks(), 26937, i < 5 ? FF_DOWNLOAD : 0, default_thumbnail, i * 34 - 35});
|
|
|
|
std::ifstream ifs((path + name).ToUTF8().data(), std::ios::binary);
|
|
|
|
if (ifs)
|
|
|
|
ParseThumbnail(m_file_list.back(), ifs);
|
|
|
|
time.Add(wxDateSpan::Days(-1));
|
|
|
|
}
|
|
|
|
m_file_list.swap(m_file_list_cache[{F_MODEL, ""}]);
|
|
|
|
time = wxDateTime::Now();
|
2022-10-14 01:25:17 +00:00
|
|
|
for (int i = 0; i < 100; ++i) {
|
2022-08-17 02:12:10 +00:00
|
|
|
auto name = wxString::Format(L"img-%03d.jpg", i + 1);
|
2023-04-23 01:18:10 +00:00
|
|
|
wxImage im(path + name);
|
|
|
|
m_file_list.push_back({name.ToUTF8().data(), "", time.GetTicks(), 26937, i < 20 ? FF_DOWNLOAD : 0, i > 3 ? im : default_thumbnail, i * 10 - 40 - 1});
|
2022-08-17 02:12:10 +00:00
|
|
|
time.Add(wxDateSpan::Days(-1));
|
|
|
|
}
|
2022-10-20 01:29:51 +00:00
|
|
|
m_file_list[0].thumbnail = default_thumbnail;
|
2023-04-23 01:18:10 +00:00
|
|
|
m_file_list.swap(m_file_list_cache[{F_TIMELAPSE, ""}]);
|
2022-08-17 02:12:10 +00:00
|
|
|
#endif
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrinterFileSystem::~PrinterFileSystem()
|
2022-09-27 05:11:01 +00:00
|
|
|
{
|
|
|
|
m_recv_thread.detach();
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
|
2023-04-23 01:18:10 +00:00
|
|
|
void PrinterFileSystem::SetFileType(FileType type, std::string const &storage)
|
2022-07-15 15:37:19 +00:00
|
|
|
{
|
2023-04-23 01:18:10 +00:00
|
|
|
if (m_file_type == type && m_file_storage == storage)
|
2022-07-15 15:37:19 +00:00
|
|
|
return;
|
2023-04-23 01:18:10 +00:00
|
|
|
assert(m_file_list_cache[std::make_pair(m_file_type, m_file_storage)].empty());
|
|
|
|
m_file_list.swap(m_file_list_cache[{m_file_type, m_file_storage}]);
|
|
|
|
std::swap(m_file_type, type);
|
|
|
|
m_file_storage = storage;
|
|
|
|
m_file_list.swap(m_file_list_cache[{m_file_type, m_file_storage}]);
|
2022-07-15 15:37:19 +00:00
|
|
|
m_lock_start = m_lock_end = 0;
|
2023-04-23 01:18:10 +00:00
|
|
|
BuildGroups();
|
2022-07-15 15:37:19 +00:00
|
|
|
SendChangedEvent(EVT_FILE_CHANGED);
|
2023-04-23 01:18:10 +00:00
|
|
|
if (type == F_INVALID_TYPE)
|
|
|
|
return;
|
2022-07-22 09:46:10 +00:00
|
|
|
m_status = Status::ListSyncing;
|
|
|
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
2022-07-15 15:37:19 +00:00
|
|
|
ListAllFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::SetGroupMode(GroupMode mode)
|
|
|
|
{
|
|
|
|
if (this->m_group_mode == mode)
|
|
|
|
return;
|
|
|
|
this->m_group_mode = mode;
|
|
|
|
m_lock_start = m_lock_end = 0;
|
2023-03-13 04:56:43 +00:00
|
|
|
UpdateGroupSelect();
|
2022-07-15 15:37:19 +00:00
|
|
|
SendChangedEvent(EVT_MODE_CHANGED);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t PrinterFileSystem::EnterSubGroup(size_t index)
|
|
|
|
{
|
|
|
|
if (m_group_mode == G_NONE)
|
|
|
|
return index;
|
|
|
|
index = m_group_mode == G_YEAR ? m_group_year[index] : m_group_month[index];
|
|
|
|
SetGroupMode((GroupMode)(m_group_mode - 1));
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::ListAllFiles()
|
|
|
|
{
|
|
|
|
json req;
|
2023-04-23 01:18:10 +00:00
|
|
|
char const * types[] {"timelapse","video", "model" };
|
|
|
|
req["type"] = types[m_file_type];
|
|
|
|
if (!m_file_storage.empty())
|
|
|
|
req["storage"] = m_file_storage;
|
2022-07-15 15:37:19 +00:00
|
|
|
req["notify"] = "DETAIL";
|
|
|
|
SendRequest<FileList>(LIST_INFO, req, [this](json const& resp, FileList & list, auto) {
|
|
|
|
json files = resp["file_lists"];
|
|
|
|
for (auto& f : files) {
|
2023-04-21 07:56:57 +00:00
|
|
|
std::string name = f["name"];
|
|
|
|
std::string path = f.value("path", "");
|
|
|
|
time_t time = f.value("time", 0);
|
2022-07-15 15:37:19 +00:00
|
|
|
boost::uint64_t size = f["size"];
|
2023-04-23 01:18:10 +00:00
|
|
|
File ff = {name, path, time, size, 0, default_thumbnail};
|
2022-07-15 15:37:19 +00:00
|
|
|
list.push_back(ff);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}, [this](int result, FileList list) {
|
|
|
|
m_file_list.swap(list);
|
|
|
|
std::sort(m_file_list.begin(), m_file_list.end());
|
|
|
|
auto iter1 = m_file_list.begin();
|
|
|
|
auto end1 = m_file_list.end();
|
|
|
|
auto iter2 = list.begin();
|
|
|
|
auto end2 = list.end();
|
|
|
|
while (iter1 != end1 && iter2 != end2) {
|
|
|
|
if (iter1->name == iter2->name) {
|
|
|
|
iter1->thumbnail = iter2->thumbnail;
|
|
|
|
iter1->flags = iter2->flags;
|
2022-10-19 07:08:46 +00:00
|
|
|
if (!iter1->thumbnail.IsOk())
|
|
|
|
iter1->flags &= ~FF_THUMNAIL;
|
2022-07-15 15:37:19 +00:00
|
|
|
iter1->progress = iter2->progress;
|
2023-04-21 07:56:57 +00:00
|
|
|
iter1->local_path = iter2->local_path;
|
2022-07-15 15:37:19 +00:00
|
|
|
++iter1; ++iter2;
|
|
|
|
} else if (*iter1 < *iter2) {
|
|
|
|
++iter1;
|
|
|
|
} else if (*iter2 < *iter1) {
|
|
|
|
++iter2;
|
|
|
|
} else {
|
|
|
|
++iter1;
|
|
|
|
++iter2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BuildGroups();
|
2023-03-13 04:56:43 +00:00
|
|
|
UpdateGroupSelect();
|
2022-07-15 15:37:19 +00:00
|
|
|
m_status = Status::ListReady;
|
2022-07-22 09:46:10 +00:00
|
|
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
2022-07-15 15:37:19 +00:00
|
|
|
SendChangedEvent(EVT_FILE_CHANGED);
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::DeleteFiles(size_t index)
|
|
|
|
{
|
|
|
|
if (index == size_t(-1)) {
|
|
|
|
size_t n = 0;
|
|
|
|
for (size_t i = 0; i < m_file_list.size(); ++i) {
|
|
|
|
auto &file = m_file_list[i];
|
|
|
|
if ((file.flags & FF_SELECT) != 0 && (file.flags & FF_DELETED) == 0) {
|
|
|
|
file.flags |= FF_DELETED;
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 07:57:27 +00:00
|
|
|
if (n == 0) return;
|
2022-07-15 15:37:19 +00:00
|
|
|
} else {
|
|
|
|
if (index >= m_file_list.size())
|
|
|
|
return;
|
|
|
|
auto &file = m_file_list[index];
|
|
|
|
if ((file.flags & FF_DELETED) != 0)
|
|
|
|
return;
|
|
|
|
file.flags |= FF_DELETED;
|
|
|
|
}
|
|
|
|
if ((m_task_flags & FF_DELETED) == 0)
|
|
|
|
DeleteFilesContinue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::DownloadFiles(size_t index, std::string const &path)
|
|
|
|
{
|
|
|
|
if (index == (size_t) -1) {
|
|
|
|
size_t n = 0;
|
|
|
|
for (size_t i = 0; i < m_file_list.size(); ++i) {
|
|
|
|
auto &file = m_file_list[i];
|
|
|
|
if ((file.flags & FF_SELECT) == 0) continue;
|
|
|
|
if ((file.flags & FF_DOWNLOAD) != 0 && file.progress >= 0) continue;
|
|
|
|
file.flags |= FF_DOWNLOAD;
|
|
|
|
file.progress = -1;
|
2023-04-21 07:56:57 +00:00
|
|
|
file.local_path = (boost::filesystem::path(path) / file.name).string();
|
2022-07-15 15:37:19 +00:00
|
|
|
++n;
|
|
|
|
}
|
|
|
|
if (n == 0) return;
|
|
|
|
} else {
|
|
|
|
if (index >= m_file_list.size())
|
|
|
|
return;
|
|
|
|
auto &file = m_file_list[index];
|
|
|
|
if ((file.flags & FF_DOWNLOAD) != 0 && file.progress >= 0)
|
|
|
|
return;
|
|
|
|
file.flags |= FF_DOWNLOAD;
|
|
|
|
file.progress = -1;
|
2023-04-21 07:56:57 +00:00
|
|
|
file.local_path = (boost::filesystem::path(path) / file.name).string();
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
if ((m_task_flags & FF_DOWNLOAD) == 0)
|
2022-10-09 03:11:47 +00:00
|
|
|
DownloadNextFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::DownloadCheckFiles(std::string const &path)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_file_list.size(); ++i) {
|
|
|
|
auto &file = m_file_list[i];
|
|
|
|
if ((file.flags & FF_DOWNLOAD) != 0 && file.progress >= 0) continue;
|
|
|
|
auto path2 = boost::filesystem::path(path) / file.name;
|
|
|
|
boost::system::error_code ec;
|
|
|
|
if (boost::filesystem::file_size(path2, ec) == file.size) {
|
|
|
|
file.flags |= FF_DOWNLOAD;
|
|
|
|
file.progress = 100;
|
2023-04-21 07:56:57 +00:00
|
|
|
file.local_path = path2.string();
|
2022-10-09 03:11:47 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-19 01:02:19 +00:00
|
|
|
bool PrinterFileSystem::DownloadCheckFile(size_t index)
|
|
|
|
{
|
|
|
|
if (index >= m_file_list.size()) return false;
|
|
|
|
auto &file = m_file_list[index];
|
|
|
|
if ((file.flags & FF_DOWNLOAD) == 0) return false;
|
2023-04-21 07:56:57 +00:00
|
|
|
if (!boost::filesystem::exists(file.local_path)) {
|
2022-10-19 01:02:19 +00:00
|
|
|
file.flags &= ~FF_DOWNLOAD;
|
|
|
|
file.progress = 0;
|
2023-04-21 07:56:57 +00:00
|
|
|
file.local_path.clear();
|
|
|
|
SendChangedEvent(EVT_DOWNLOAD, index, file.local_path);
|
2022-10-19 01:02:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
void PrinterFileSystem::DownloadCancel(size_t index)
|
|
|
|
{
|
|
|
|
if (index == (size_t) -1) return;
|
|
|
|
if (index >= m_file_list.size()) return;
|
|
|
|
auto &file = m_file_list[index];
|
|
|
|
if ((file.flags & FF_DOWNLOAD) == 0) return;
|
|
|
|
if (file.progress >= 0)
|
|
|
|
CancelRequest(m_download_seq);
|
2022-11-17 01:32:45 +00:00
|
|
|
else
|
|
|
|
file.flags &= ~FF_DOWNLOAD;
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 01:18:10 +00:00
|
|
|
void PrinterFileSystem::FetchModel(size_t index, std::function<void(std::string const &)> callback)
|
|
|
|
{
|
|
|
|
json req;
|
|
|
|
json arr;
|
|
|
|
if (index == (size_t) -1) return;
|
|
|
|
if (index >= m_file_list.size()) return;
|
|
|
|
auto &file = m_file_list[index];
|
|
|
|
arr.push_back(file.path + "#_rel/.rels");
|
|
|
|
arr.push_back(file.path + "#3D/3dmodel.model");
|
|
|
|
arr.push_back(file.path + "#Metadata/slice_info.config");
|
|
|
|
arr.push_back(file.path + "#Metadata/project_settings.config");
|
|
|
|
for (auto & meta : file.metadata) {
|
|
|
|
if (boost::algorithm::starts_with(meta.first, "plate_thumbnail_"))
|
|
|
|
arr.push_back(file.path + "#" + meta.second);
|
|
|
|
}
|
|
|
|
req["paths"] = arr;
|
|
|
|
SendRequest<File>(
|
|
|
|
SUB_FILE, req,
|
|
|
|
[](json const &resp, File &file, unsigned char const *data) -> int {
|
|
|
|
// in work thread, continue recv
|
|
|
|
// receive data
|
|
|
|
boost::uint32_t size = resp["size"];
|
|
|
|
if (size > 0) {
|
|
|
|
file.local_path = std::string((char *) data, size);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
[callback](int, File const &file) {
|
|
|
|
callback(file.local_path);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
size_t PrinterFileSystem::GetCount() const
|
|
|
|
{
|
|
|
|
if (m_group_mode == G_NONE)
|
|
|
|
return m_file_list.size();
|
|
|
|
return m_group_mode == G_YEAR ? m_group_year.size() : m_group_month.size();
|
|
|
|
}
|
|
|
|
|
2023-04-23 01:18:10 +00:00
|
|
|
std::string PrinterFileSystem::File::Metadata(std::string const &key, std::string const & dflt) const
|
|
|
|
{
|
|
|
|
auto iter = metadata.find(key);
|
|
|
|
return iter == metadata.end() || iter->second.empty() ? dflt : iter->second;
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
size_t PrinterFileSystem::GetIndexAtTime(boost::uint32_t time)
|
|
|
|
{
|
2023-04-21 07:56:57 +00:00
|
|
|
auto iter = std::upper_bound(m_file_list.begin(), m_file_list.end(), File{"", "", time});
|
2022-07-15 15:37:19 +00:00
|
|
|
size_t n = std::distance(m_file_list.begin(), iter) - 1;
|
|
|
|
if (m_group_mode == G_NONE) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
auto & group = m_group_mode == G_YEAR ? m_group_year : m_group_month;
|
|
|
|
auto iter2 = std::upper_bound(group.begin(), group.end(), n);
|
|
|
|
return std::distance(group.begin(), iter2) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::ToggleSelect(size_t index)
|
|
|
|
{
|
2023-03-13 04:56:43 +00:00
|
|
|
if (m_group_mode != G_NONE) {
|
|
|
|
size_t beg = m_group_mode == G_YEAR ? m_group_month[m_group_year[index]] : m_group_month[index];
|
|
|
|
size_t end_month = m_group_mode == G_YEAR ? ((index + 1) < m_group_year.size() ? m_group_year[index + 1] : m_group_month.size()) : index + 1;
|
|
|
|
size_t end = end_month < m_group_month.size() ? m_group_month[end_month] : m_file_list.size();
|
|
|
|
if ((m_group_flags[index] & FF_SELECT) == 0) {
|
|
|
|
for (int i = beg; i < end; ++i) {
|
|
|
|
if ((m_file_list[i].flags & FF_SELECT) == 0) {
|
|
|
|
m_file_list[i].flags |= FF_SELECT;
|
|
|
|
++m_select_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_group_flags[index] |= FF_SELECT;
|
|
|
|
} else {
|
|
|
|
for (int i = beg; i < end; ++i) {
|
|
|
|
if (m_file_list[i].flags & FF_SELECT) {
|
|
|
|
m_file_list[i].flags &= ~FF_SELECT;
|
|
|
|
--m_select_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_group_flags[index] &= ~FF_SELECT;
|
|
|
|
}
|
|
|
|
} else if (index < m_file_list.size()) {
|
2022-10-14 01:25:17 +00:00
|
|
|
m_file_list[index].flags ^= FF_SELECT;
|
|
|
|
if (m_file_list[index].flags & FF_SELECT)
|
|
|
|
++m_select_count;
|
|
|
|
else
|
|
|
|
--m_select_count;
|
|
|
|
}
|
|
|
|
SendChangedEvent(EVT_SELECT_CHANGED, m_select_count);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::SelectAll(bool select)
|
|
|
|
{
|
2022-10-14 01:25:17 +00:00
|
|
|
if (select) {
|
2022-07-15 15:37:19 +00:00
|
|
|
for (auto &f : m_file_list) f.flags |= FF_SELECT;
|
2022-10-14 01:25:17 +00:00
|
|
|
m_select_count = m_file_list.size();
|
2023-03-13 04:56:43 +00:00
|
|
|
for (auto &s : m_group_flags) s |= FF_SELECT;
|
2022-10-14 01:25:17 +00:00
|
|
|
} else {
|
2022-07-15 15:37:19 +00:00
|
|
|
for (auto &f : m_file_list) f.flags &= ~FF_SELECT;
|
2022-10-14 01:25:17 +00:00
|
|
|
m_select_count = 0;
|
2023-03-13 04:56:43 +00:00
|
|
|
for (auto &s : m_group_flags) s &= ~FF_SELECT;
|
2022-10-14 01:25:17 +00:00
|
|
|
}
|
|
|
|
SendChangedEvent(EVT_SELECT_CHANGED, m_select_count);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 01:25:17 +00:00
|
|
|
size_t PrinterFileSystem::GetSelectCount() const { return m_select_count; }
|
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
void PrinterFileSystem::SetFocusRange(size_t start, size_t count)
|
|
|
|
{
|
|
|
|
m_lock_start = start;
|
|
|
|
m_lock_end = start + count;
|
|
|
|
if (!m_stopped && (m_task_flags & FF_THUMNAIL) == 0)
|
|
|
|
UpdateFocusThumbnail();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrinterFileSystem::File const &PrinterFileSystem::GetFile(size_t index)
|
|
|
|
{
|
|
|
|
if (m_group_mode == G_NONE)
|
|
|
|
return m_file_list[index];
|
2023-03-13 04:56:43 +00:00
|
|
|
if (m_group_mode == G_YEAR) index = m_group_year[index];
|
|
|
|
return m_file_list[m_group_month[index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
PrinterFileSystem::File const &PrinterFileSystem::GetFile(size_t index, bool &select)
|
|
|
|
{
|
|
|
|
if (m_group_mode == G_NONE) {
|
|
|
|
select = m_file_list[index].IsSelect();
|
|
|
|
return m_file_list[index];
|
|
|
|
}
|
|
|
|
select = m_group_flags[index] & FF_SELECT;
|
2022-07-15 15:37:19 +00:00
|
|
|
if (m_group_mode == G_YEAR)
|
|
|
|
index = m_group_year[index];
|
|
|
|
return m_file_list[m_group_month[index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
int PrinterFileSystem::RecvData(std::function<int(Bambu_Sample& sample)> const & callback)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
while (true) {
|
|
|
|
Bambu_Sample sample;
|
2022-08-17 02:12:10 +00:00
|
|
|
result = Bambu_ReadSample(m_session.tunnel, &sample);
|
2022-07-15 15:37:19 +00:00
|
|
|
if (result == Bambu_success) {
|
|
|
|
result = callback(sample);
|
|
|
|
if (result == 1)
|
|
|
|
continue;
|
|
|
|
} else if (result == Bambu_would_block) {
|
|
|
|
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
|
|
|
continue;
|
|
|
|
} else if (result == Bambu_stream_end) {
|
|
|
|
result = 0;
|
|
|
|
} else {
|
|
|
|
result = ERROR_PIPE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-09-27 05:11:01 +00:00
|
|
|
void PrinterFileSystem::Attached()
|
|
|
|
{
|
|
|
|
boost::unique_lock lock(m_mutex);
|
|
|
|
m_recv_thread = std::move(boost::thread([w = weak_from_this()] {
|
|
|
|
boost::shared_ptr<PrinterFileSystem> s = w.lock();
|
|
|
|
if (s) s->RecvMessageThread();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
void PrinterFileSystem::Start()
|
|
|
|
{
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
if (!m_stopped) return;
|
|
|
|
m_stopped = false;
|
|
|
|
m_cond.notify_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::Retry()
|
|
|
|
{
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
m_cond.notify_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::SetUrl(std::string const &url)
|
|
|
|
{
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
m_messages.push_back(url);
|
|
|
|
m_cond.notify_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::Stop(bool quit)
|
|
|
|
{
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
if (quit) {
|
|
|
|
m_session.owner = nullptr;
|
2022-07-22 09:46:10 +00:00
|
|
|
} else if (m_stopped) {
|
|
|
|
return;
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
2022-07-22 09:46:10 +00:00
|
|
|
m_stopped = true;
|
2022-07-15 15:37:19 +00:00
|
|
|
m_cond.notify_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::BuildGroups()
|
|
|
|
{
|
|
|
|
if (m_file_list.empty())
|
|
|
|
return;
|
2022-08-30 10:39:29 +00:00
|
|
|
m_group_year.clear();
|
|
|
|
m_group_month.clear();
|
2022-07-15 15:37:19 +00:00
|
|
|
wxDateTime t = wxDateTime((time_t) m_file_list.front().time);
|
|
|
|
m_group_year.push_back(0);
|
|
|
|
m_group_month.push_back(0);
|
|
|
|
for (size_t i = 0; i < m_file_list.size(); ++i) {
|
|
|
|
wxDateTime s = wxDateTime((time_t) m_file_list[i].time);
|
|
|
|
if (s.GetYear() != t.GetYear()) {
|
|
|
|
m_group_year.push_back(m_group_month.size());
|
|
|
|
m_group_month.push_back(i);
|
|
|
|
} else if (s.GetMonth() != t.GetMonth()) {
|
|
|
|
m_group_month.push_back(i);
|
|
|
|
}
|
|
|
|
t = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 04:56:43 +00:00
|
|
|
void PrinterFileSystem::UpdateGroupSelect()
|
|
|
|
{
|
|
|
|
m_group_flags.clear();
|
|
|
|
int beg = 0;
|
|
|
|
if (m_group_mode != G_NONE) {
|
|
|
|
auto group = m_group_mode == G_YEAR ? m_group_year : m_group_month;
|
|
|
|
if (m_group_mode == G_YEAR)
|
|
|
|
for (auto &g : group) g = m_group_month[g];
|
|
|
|
m_group_flags.resize(group.size(), FF_SELECT);
|
|
|
|
for (int i = 0; i < m_file_list.size(); ++i) {
|
|
|
|
if ((m_file_list[i].flags & FF_SELECT) == 0) {
|
|
|
|
auto iter = std::upper_bound(group.begin(), group.end(), i);
|
|
|
|
m_group_flags[iter - group.begin() - 1] &= ~FF_SELECT;
|
|
|
|
if (iter == group.end()) break;
|
|
|
|
i = *iter - 1; // start from next group
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
void PrinterFileSystem::DeleteFilesContinue()
|
|
|
|
{
|
|
|
|
std::vector<size_t> indexes;
|
|
|
|
std::vector<std::string> names;
|
2023-04-21 07:56:57 +00:00
|
|
|
std::vector<std::string> paths;
|
2022-07-15 15:37:19 +00:00
|
|
|
for (size_t i = 0; i < m_file_list.size(); ++i)
|
2022-10-09 02:46:52 +00:00
|
|
|
if ((m_file_list[i].flags & FF_DELETED) && !m_file_list[i].name.empty()) {
|
2022-07-15 15:37:19 +00:00
|
|
|
indexes.push_back(i);
|
2023-04-21 07:56:57 +00:00
|
|
|
auto &file = m_file_list[i];
|
|
|
|
if (file.path.empty())
|
|
|
|
names.push_back(file.name);
|
|
|
|
else
|
|
|
|
paths.push_back(file.path);
|
|
|
|
if (names.size() >= 64 || paths.size() >= 64)
|
2022-07-15 15:37:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_task_flags &= ~FF_DELETED;
|
2023-04-21 07:56:57 +00:00
|
|
|
if (names.empty() && paths.empty())
|
2022-07-15 15:37:19 +00:00
|
|
|
return;
|
|
|
|
json req;
|
|
|
|
json arr;
|
2023-04-21 07:56:57 +00:00
|
|
|
if (paths.empty()) {
|
|
|
|
for (auto &name : names) arr.push_back(name);
|
|
|
|
req["delete"] = arr;
|
|
|
|
} else {
|
|
|
|
for (auto &path : paths) arr.push_back(path);
|
|
|
|
req["paths"] = arr;
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
m_task_flags |= FF_DELETED;
|
|
|
|
SendRequest<Void>(
|
2022-07-22 09:46:10 +00:00
|
|
|
FILE_DEL, req, nullptr,
|
2023-04-21 07:56:57 +00:00
|
|
|
[indexes, names = paths.empty() ? names : paths, bypath = !paths.empty(), this](int, Void const &) {
|
2022-07-15 15:37:19 +00:00
|
|
|
// TODO:
|
2022-10-09 02:46:52 +00:00
|
|
|
for (size_t i = indexes.size() - 1; i != size_t(-1); --i)
|
2023-04-21 07:56:57 +00:00
|
|
|
FileRemoved(indexes[i], names[i], bypath);
|
2022-10-09 03:11:47 +00:00
|
|
|
SendChangedEvent(EVT_FILE_CHANGED, indexes.size());
|
2022-07-15 15:37:19 +00:00
|
|
|
DeleteFilesContinue();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-09 03:11:47 +00:00
|
|
|
void PrinterFileSystem::DownloadNextFile()
|
2022-07-15 15:37:19 +00:00
|
|
|
{
|
|
|
|
size_t index = size_t(-1);
|
|
|
|
for (size_t i = 0; i < m_file_list.size(); ++i) {
|
|
|
|
if ((m_file_list[i].flags & FF_DOWNLOAD) != 0 && m_file_list[i].progress == -1) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_task_flags &= ~FF_DOWNLOAD;
|
|
|
|
if (index >= m_file_list.size())
|
|
|
|
return;
|
|
|
|
json req;
|
2023-04-21 07:56:57 +00:00
|
|
|
if (m_file_list[index].path.empty())
|
|
|
|
req["file"] = m_file_list[index].name;
|
|
|
|
else
|
|
|
|
req["path"] = m_file_list[index].path;
|
2022-07-15 15:37:19 +00:00
|
|
|
m_file_list[index].progress = 0;
|
|
|
|
SendChangedEvent(EVT_DOWNLOAD, index, m_file_list[index].name);
|
|
|
|
struct Download
|
|
|
|
{
|
2022-10-09 02:46:52 +00:00
|
|
|
size_t index;
|
|
|
|
std::string name;
|
|
|
|
std::string path;
|
2023-04-21 07:56:57 +00:00
|
|
|
std::string local_path;
|
2022-07-15 15:37:19 +00:00
|
|
|
boost::filesystem::ofstream ofs;
|
2022-10-09 02:46:52 +00:00
|
|
|
boost::uuids::detail::md5 boost_md5;
|
2022-07-15 15:37:19 +00:00
|
|
|
};
|
|
|
|
std::shared_ptr<Download> download(new Download);
|
|
|
|
download->index = index;
|
2023-04-21 07:56:57 +00:00
|
|
|
download->name = m_file_list[index].name;
|
|
|
|
download->path = m_file_list[index].path;
|
|
|
|
download->local_path = m_file_list[index].local_path;
|
2022-07-15 15:37:19 +00:00
|
|
|
m_task_flags |= FF_DOWNLOAD;
|
|
|
|
m_download_seq = SendRequest<Progress>(
|
|
|
|
FILE_DOWNLOAD, req,
|
2023-04-23 01:18:10 +00:00
|
|
|
[download](json const &resp, Progress &prog, unsigned char const *data) -> int {
|
2022-07-15 15:37:19 +00:00
|
|
|
// in work thread, continue recv
|
|
|
|
size_t size = resp["size"];
|
|
|
|
prog.size = resp["offset"];
|
|
|
|
prog.total = resp["total"];
|
|
|
|
if (prog.size == 0) {
|
2023-04-21 07:56:57 +00:00
|
|
|
download->ofs.open(download->local_path, std::ios::binary);
|
2022-07-15 15:37:19 +00:00
|
|
|
if (!download->ofs) return FILE_OPEN_ERR;
|
|
|
|
}
|
|
|
|
// receive data
|
|
|
|
download->ofs.write((char const *) data, size);
|
|
|
|
download->boost_md5.process_bytes(data, size);
|
|
|
|
prog.size += size;
|
|
|
|
if (prog.size < prog.total) { return CONTINUE; }
|
|
|
|
download->ofs.close();
|
|
|
|
int result = 0;
|
|
|
|
std::string md5 = resp["file_md5"];
|
|
|
|
// check size and md5
|
|
|
|
if (prog.size == prog.total) {
|
|
|
|
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)) result = FILE_CHECK_ERR;
|
|
|
|
} else {
|
|
|
|
result = FILE_SIZE_ERR;
|
|
|
|
}
|
|
|
|
if (result != 0) {
|
|
|
|
boost::system::error_code ec;
|
2023-04-21 07:56:57 +00:00
|
|
|
boost::filesystem::remove(download->local_path, ec);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
[this, download](int result, Progress const &data) {
|
2023-04-21 07:56:57 +00:00
|
|
|
if (download->index != size_t(-1))
|
|
|
|
download->index = FindFile(download->index, download->path.empty() ? download->name : download->path, !download->path.empty());
|
2022-10-09 02:46:52 +00:00
|
|
|
if (download->index != size_t(-1)) {
|
2022-07-15 15:37:19 +00:00
|
|
|
int progress = data.size * 100 / data.total;
|
|
|
|
auto & file = m_file_list[download->index];
|
|
|
|
if (result == ERROR_CANCEL)
|
|
|
|
file.flags &= ~FF_DOWNLOAD;
|
|
|
|
else if (file.progress != progress) {
|
|
|
|
file.progress = progress;
|
2023-04-21 07:56:57 +00:00
|
|
|
SendChangedEvent(EVT_DOWNLOAD, download->index, file.local_path, result);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-09 03:11:47 +00:00
|
|
|
if (result != CONTINUE) DownloadNextFile();
|
2022-07-15 15:37:19 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::UpdateFocusThumbnail()
|
|
|
|
{
|
|
|
|
m_task_flags &= ~FF_THUMNAIL;
|
|
|
|
if (m_lock_start >= m_file_list.size() || m_lock_start >= m_lock_end)
|
|
|
|
return;
|
|
|
|
size_t start = m_lock_start;
|
|
|
|
size_t end = std::min(m_lock_end, GetCount());
|
2023-04-23 01:18:10 +00:00
|
|
|
std::vector<File> names;
|
|
|
|
std::vector<File> paths;
|
2022-07-15 15:37:19 +00:00
|
|
|
for (; start < end; ++start) {
|
|
|
|
auto &file = GetFile(start);
|
|
|
|
if ((file.flags & FF_THUMNAIL) == 0) {
|
2023-04-21 07:56:57 +00:00
|
|
|
if (file.path.empty())
|
2023-04-23 01:18:10 +00:00
|
|
|
names.push_back({file.name, "", 0, 0, FF_THUMNAIL});
|
2023-04-21 07:56:57 +00:00
|
|
|
else
|
2023-04-23 01:18:10 +00:00
|
|
|
paths.push_back({"", file.path});
|
2023-04-21 07:56:57 +00:00
|
|
|
if (names.size() >= 5 || paths.size() >= 5)
|
2022-07-15 15:37:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-04-21 07:56:57 +00:00
|
|
|
if (names.empty() && paths.empty())
|
2022-07-15 15:37:19 +00:00
|
|
|
return;
|
2023-04-23 01:18:10 +00:00
|
|
|
m_task_flags |= FF_THUMNAIL;
|
|
|
|
UpdateFocusThumbnail2(std::make_shared<std::vector<File>>(paths), paths.empty() ? 0 : m_file_type == F_MODEL ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PrinterFileSystem::ParseThumbnail(File &file)
|
|
|
|
{
|
|
|
|
std::istringstream iss(file.local_path, std::ios::binary);
|
|
|
|
return ParseThumbnail(file, iss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string durationString(long duration)
|
|
|
|
{
|
|
|
|
static boost::regex rx("^0d(0h)?");
|
|
|
|
auto time = boost::format("%1%d%2%h%3%m") % (duration / 86400) % ((duration % 86400) / 3600) % ((duration % 3600) / 60);
|
|
|
|
return boost::regex_replace(time.str(), rx, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PrinterFileSystem::ParseThumbnail(File &file, std::istream &is)
|
|
|
|
{
|
|
|
|
Slic3r::DynamicPrintConfig config;
|
|
|
|
Slic3r::Model model;
|
|
|
|
Slic3r::PlateDataPtrs plate_data_list;
|
|
|
|
Slic3r::Semver file_version;
|
|
|
|
if (!Slic3r::load_gcode_3mf_from_stream(is, &config, &model, &plate_data_list, &file_version))
|
|
|
|
return false;
|
|
|
|
float time = 0.f;
|
|
|
|
float weight = 0.f;
|
|
|
|
for (auto &plate : plate_data_list) {
|
|
|
|
time += atof(plate->gcode_prediction.c_str());
|
|
|
|
weight += atof(plate->gcode_weight.c_str());
|
|
|
|
file.metadata.emplace("plate_thumbnail_" + std::to_string(plate->plate_index), plate->thumbnail_file);
|
|
|
|
}
|
|
|
|
file.metadata.emplace("Title", model.model_info->model_name);
|
|
|
|
file.metadata.emplace("Time", durationString(round(time)));
|
|
|
|
file.metadata.emplace("Weight", std::to_string(int(round(weight))));
|
|
|
|
auto thumbnail = model.model_info->metadata_items["Thumbnail"];
|
|
|
|
if (thumbnail.empty() && !plate_data_list.empty()) {
|
|
|
|
thumbnail = plate_data_list.front()->thumbnail_file;
|
|
|
|
if (thumbnail.empty()) {
|
|
|
|
thumbnail = plate_data_list.front()->gcode_file;
|
|
|
|
boost::algorithm::replace_all(thumbnail, ".gcode", ".png");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.metadata.emplace("Thumbnail", thumbnail);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::UpdateFocusThumbnail2(std::shared_ptr<std::vector<File>> files, int type)
|
|
|
|
{
|
2022-07-15 15:37:19 +00:00
|
|
|
json req;
|
|
|
|
json arr;
|
2023-04-23 01:18:10 +00:00
|
|
|
if (type == 0) {
|
|
|
|
for (auto &file : *files) arr.push_back(file.name);
|
2023-04-21 07:56:57 +00:00
|
|
|
req["files"] = arr;
|
2023-04-23 01:18:10 +00:00
|
|
|
if (m_file_type == F_MODEL) {
|
|
|
|
for (auto &file : *files) arr.push_back(file.path);
|
|
|
|
}
|
|
|
|
for (auto &file : *files) arr.push_back(file.path);
|
2023-04-21 07:56:57 +00:00
|
|
|
} else {
|
2023-04-23 01:18:10 +00:00
|
|
|
if (type == 1) {
|
|
|
|
for (auto &file : *files) arr.push_back(file.path + "#thumbnail");
|
|
|
|
} else if (type == 2) {
|
|
|
|
for (auto &file : *files) {
|
|
|
|
arr.push_back(file.path + "#_rel/.rels");
|
|
|
|
arr.push_back(file.path + "#3D/3dmodel.model");
|
|
|
|
arr.push_back(file.path + "#Metadata/slice_info.config");
|
|
|
|
arr.push_back(file.path + "#Metadata/project_settings.config");
|
|
|
|
}
|
|
|
|
req["zip"] = true;
|
|
|
|
} else {
|
|
|
|
for (auto &file : *files) arr.push_back(file.path + "#" + file.metadata["Thumbnail"]);
|
|
|
|
}
|
2023-04-21 07:56:57 +00:00
|
|
|
req["paths"] = arr;
|
|
|
|
}
|
2023-04-23 01:18:10 +00:00
|
|
|
SendRequest<File>(
|
|
|
|
SUB_FILE, req, [type](json const &resp, File &file, unsigned char const *data) -> int {
|
2022-07-15 15:37:19 +00:00
|
|
|
// in work thread, continue recv
|
|
|
|
// receive data
|
2023-04-23 01:18:10 +00:00
|
|
|
wxString mimetype = resp.value("mimetype", "image/jpeg");
|
|
|
|
std::string thumbnail = resp.value("thumbnail", "");
|
|
|
|
std::string path = resp.value("path", "");
|
|
|
|
boost::uint32_t size = resp["size"];
|
|
|
|
file.name = thumbnail;
|
|
|
|
file.path = path;
|
2022-08-30 10:39:29 +00:00
|
|
|
if (size > 0) {
|
2023-04-23 01:18:10 +00:00
|
|
|
if (type != 2) {
|
|
|
|
wxMemoryInputStream mis(data, size);
|
|
|
|
file.thumbnail = wxImage(mis, mimetype);
|
|
|
|
} else {
|
|
|
|
file.local_path = std::string((char *) data, size);
|
|
|
|
ParseThumbnail(file);
|
|
|
|
}
|
2022-08-30 10:39:29 +00:00
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
return 0;
|
|
|
|
},
|
2023-04-23 01:18:10 +00:00
|
|
|
[this, files, type](int result, File const &file) {
|
|
|
|
auto n = file.name.find_last_of('.');
|
|
|
|
auto name = n == std::string::npos ? file.name : file.name.substr(0, n);
|
|
|
|
n = file.path.find_last_of('#');
|
|
|
|
auto path = n == std::string::npos ? file.path : file.path.substr(0, n);
|
2023-04-21 07:56:57 +00:00
|
|
|
auto iter = path.empty() ? std::find_if(m_file_list.begin(), m_file_list.end(), [&name](auto &f) { return boost::algorithm::starts_with(f.name, name); }) :
|
|
|
|
std::find_if(m_file_list.begin(), m_file_list.end(), [&path](auto &f) { return f.path == path; });
|
2022-07-15 15:37:19 +00:00
|
|
|
if (iter != m_file_list.end()) {
|
2023-04-23 01:18:10 +00:00
|
|
|
if (type == 2) {
|
|
|
|
if (!file.metadata.empty()) {
|
|
|
|
iter->metadata = file.metadata;
|
|
|
|
int index = iter - m_file_list.begin();
|
|
|
|
SendChangedEvent(EVT_THUMBNAIL, index, file.name);
|
|
|
|
auto iter = std::find_if(files->begin(), files->end(), [&path](auto &f) { return f.path == path; });
|
|
|
|
if (iter != files->end())
|
|
|
|
iter->metadata = file.metadata;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
iter->flags |= FF_THUMNAIL; // DOTO: retry on fail
|
|
|
|
if (file.thumbnail.IsOk()) {
|
|
|
|
iter->thumbnail = file.thumbnail;
|
|
|
|
int index = iter - m_file_list.begin();
|
|
|
|
SendChangedEvent(EVT_THUMBNAIL, index, file.name);
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-23 01:18:10 +00:00
|
|
|
if (result == 0) {
|
|
|
|
if (type == 2)
|
|
|
|
UpdateFocusThumbnail2(files, 3);
|
|
|
|
else
|
|
|
|
UpdateFocusThumbnail();
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-21 07:56:57 +00:00
|
|
|
size_t PrinterFileSystem::FindFile(size_t index, std::string const &name, bool by_path)
|
2022-07-15 15:37:19 +00:00
|
|
|
{
|
2023-04-21 07:56:57 +00:00
|
|
|
if (index >= m_file_list.size() || (by_path ? m_file_list[index].path : m_file_list[index].name) != name) {
|
|
|
|
auto iter = std::find_if(m_file_list.begin(), m_file_list.end(),
|
|
|
|
[name, by_path](File &f) { return (by_path ? f.path : f.name) == name; });
|
2022-07-15 15:37:19 +00:00
|
|
|
if (iter == m_file_list.end()) return -1;
|
|
|
|
index = std::distance(m_file_list.begin(), iter);
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2023-04-21 07:56:57 +00:00
|
|
|
void PrinterFileSystem::FileRemoved(size_t index, std::string const &name, bool by_path)
|
2022-07-15 15:37:19 +00:00
|
|
|
{
|
2023-04-21 07:56:57 +00:00
|
|
|
index = FindFile(index, name, by_path);
|
2022-09-26 10:14:17 +00:00
|
|
|
if (index == size_t(-1))
|
|
|
|
return;
|
2022-07-15 15:37:19 +00:00
|
|
|
auto removeFromGroup = [](std::vector<size_t> &group, size_t index, int total) {
|
|
|
|
for (auto iter = group.begin(); iter != group.end(); ++iter) {
|
|
|
|
size_t index2 = -1;
|
|
|
|
if (*iter < index) continue;
|
|
|
|
if (*iter == index) {
|
|
|
|
auto iter2 = iter + 1;
|
|
|
|
if (iter2 == group.end() ? index == total - 1 : *iter2 == index + 1) {
|
|
|
|
index2 = std::distance(group.begin(), iter);
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
for (; iter != group.end(); ++iter) {
|
|
|
|
--*iter;
|
|
|
|
}
|
|
|
|
return index2;
|
|
|
|
}
|
|
|
|
return size_t(-1);
|
|
|
|
};
|
|
|
|
size_t index2 = removeFromGroup(m_group_month, index, m_file_list.size());
|
|
|
|
if (index2 < m_group_month.size()) {
|
|
|
|
int index3 = removeFromGroup(m_group_year, index, m_group_month.size());
|
2023-03-13 04:56:43 +00:00
|
|
|
if (index3 < m_group_year.size()) {
|
2022-07-15 15:37:19 +00:00
|
|
|
m_group_year.erase(m_group_year.begin() + index3);
|
2023-03-13 04:56:43 +00:00
|
|
|
if (m_group_mode == G_YEAR)
|
|
|
|
m_group_flags.erase(m_group_flags.begin() + index2);
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
m_group_month.erase(m_group_month.begin() + index2);
|
2023-03-13 04:56:43 +00:00
|
|
|
if (m_group_mode == G_MONTH)
|
|
|
|
m_group_flags.erase(m_group_flags.begin() + index2);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
m_file_list.erase(m_file_list.begin() + index);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CallbackEvent : wxCommandEvent
|
|
|
|
{
|
2022-07-22 09:46:10 +00:00
|
|
|
CallbackEvent(std::function<void(void)> const &callback, boost::weak_ptr<PrinterFileSystem> owner) : wxCommandEvent(EVT_FILE_CALLBACK), callback(callback), owner(owner) {}
|
|
|
|
~CallbackEvent(){ if (!owner.expired()) callback(); }
|
2022-07-15 15:37:19 +00:00
|
|
|
std::function<void(void)> const callback;
|
2022-07-22 09:46:10 +00:00
|
|
|
boost::weak_ptr<PrinterFileSystem> owner;
|
2022-07-15 15:37:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void PrinterFileSystem::PostCallback(std::function<void(void)> const& callback)
|
|
|
|
{
|
2022-07-22 09:46:10 +00:00
|
|
|
wxCommandEvent *e = new CallbackEvent(callback, boost::weak_ptr(shared_from_this()));
|
2022-07-15 15:37:19 +00:00
|
|
|
wxQueueEvent(this, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::SendChangedEvent(wxEventType type, size_t index, std::string const &str, long extra)
|
|
|
|
{
|
|
|
|
wxCommandEvent event(type);
|
|
|
|
event.SetEventObject(this);
|
|
|
|
event.SetInt(index);
|
|
|
|
if (!str.empty())
|
|
|
|
event.SetString(wxString::FromUTF8(str.c_str()));
|
|
|
|
event.SetExtraLong(extra);
|
2022-09-02 02:58:00 +00:00
|
|
|
if (wxThread::IsMain())
|
|
|
|
ProcessEventLocally(event);
|
|
|
|
else
|
|
|
|
wxPostEvent(this, event);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 02:12:10 +00:00
|
|
|
void PrinterFileSystem::DumpLog(void * thiz, int, tchar const *msg)
|
2022-07-15 15:37:19 +00:00
|
|
|
{
|
|
|
|
BOOST_LOG_TRIVIAL(info) << "PrinterFileSystem: " << msg;
|
2022-08-17 02:12:10 +00:00
|
|
|
static_cast<PrinterFileSystem*>(thiz)->Bambu_FreeLogMsg(msg);
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::uint32_t PrinterFileSystem::SendRequest(int type, json const &req, callback_t2 const &callback)
|
|
|
|
{
|
2022-08-17 02:12:10 +00:00
|
|
|
if (m_session.tunnel == nullptr) {
|
2022-07-15 15:37:19 +00:00
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
m_cond.notify_all();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
boost::uint32_t seq = m_sequence + m_callbacks.size();
|
|
|
|
json root;
|
|
|
|
root["cmdtype"] = type;
|
|
|
|
root["sequence"] = seq;
|
|
|
|
root["req"] = req;
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << root;
|
|
|
|
auto msg = oss.str();
|
|
|
|
//OutputDebugStringA(msg.c_str());
|
|
|
|
//OutputDebugStringA("\n");
|
|
|
|
BOOST_LOG_TRIVIAL(info) << "PrinterFileSystem::SendRequest: " << type << " msg: " << msg;
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
m_messages.push_back(msg);
|
|
|
|
m_callbacks.push_back(callback);
|
|
|
|
m_cond.notify_all();
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::InstallNotify(int type, callback_t2 const &callback)
|
|
|
|
{
|
|
|
|
type -= NOTIFY_FIRST;
|
|
|
|
if (m_notifies.size() <= size_t(type)) m_notifies.resize(type + 1);
|
|
|
|
m_notifies[type] = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::CancelRequest(boost::uint32_t seq)
|
|
|
|
{
|
|
|
|
json req;
|
|
|
|
json arr;
|
|
|
|
arr.push_back(seq);
|
|
|
|
req["tasks"] = arr;
|
|
|
|
SendRequest(TASK_CANCEL, req, [this](int result, json const &resp, unsigned char const *) {
|
|
|
|
if (result != 0) return;
|
|
|
|
json tasks = resp["tasks"];
|
|
|
|
std::deque<callback_t2> callbacks;
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
for (auto &f : tasks) {
|
|
|
|
boost::uint32_t seq = f;
|
|
|
|
seq -= m_sequence;
|
|
|
|
if (size_t(seq) >= m_callbacks.size()) continue;
|
|
|
|
auto & c = m_callbacks[seq];
|
|
|
|
if (c == nullptr) continue;
|
|
|
|
callbacks.push_back(c);
|
|
|
|
m_callbacks[seq] = callback_t2();
|
|
|
|
}
|
|
|
|
while (!m_callbacks.empty() && m_callbacks.front() == nullptr) {
|
|
|
|
m_callbacks.pop_front();
|
|
|
|
++m_sequence;
|
|
|
|
}
|
|
|
|
l.unlock();
|
|
|
|
for (auto &c : callbacks) c(ERROR_CANCEL, json(), nullptr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::RecvMessageThread()
|
|
|
|
{
|
|
|
|
Bambu_Sample sample;
|
|
|
|
boost::unique_lock l(m_mutex);
|
|
|
|
Reconnect(l, 0);
|
|
|
|
while (true) {
|
|
|
|
if (m_stopped && (m_session.owner == nullptr || (m_messages.empty() && m_callbacks.empty()))) {
|
|
|
|
Reconnect(l, 0); // Close and wait start again
|
|
|
|
if (m_session.owner == nullptr) {
|
2022-09-27 05:11:01 +00:00
|
|
|
// clear callbacks first
|
2022-07-15 15:37:19 +00:00
|
|
|
auto callbacks(std::move(m_callbacks));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m_messages.empty()) {
|
|
|
|
auto & msg = m_messages.front();
|
|
|
|
l.unlock();
|
2022-08-17 02:12:10 +00:00
|
|
|
int n = Bambu_SendMessage(m_session.tunnel, CTRL_TYPE, msg.c_str(), msg.length());
|
2022-07-15 15:37:19 +00:00
|
|
|
l.lock();
|
|
|
|
if (n == 0)
|
|
|
|
m_messages.pop_front();
|
|
|
|
else if (n != Bambu_would_block) {
|
|
|
|
Reconnect(l, n);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l.unlock();
|
2022-08-17 02:12:10 +00:00
|
|
|
int n = Bambu_ReadSample(m_session.tunnel, &sample);
|
2022-07-15 15:37:19 +00:00
|
|
|
l.lock();
|
|
|
|
if (n == 0) {
|
|
|
|
HandleResponse(l, sample);
|
2023-04-21 07:56:57 +00:00
|
|
|
} else if (n == Bambu_stream_end) {
|
|
|
|
Reconnect(l, 3);
|
2022-07-15 15:37:19 +00:00
|
|
|
} else if (n == Bambu_would_block) {
|
|
|
|
m_cond.timed_wait(l, boost::posix_time::milliseconds(m_messages.empty() && m_callbacks.empty() ? 1000 : 20));
|
|
|
|
} else {
|
|
|
|
Reconnect(l, n);
|
|
|
|
}
|
|
|
|
} // while
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::HandleResponse(boost::unique_lock<boost::mutex> &l, Bambu_Sample const &sample)
|
|
|
|
{
|
|
|
|
unsigned char const *end = sample.buffer + sample.size;
|
|
|
|
unsigned char const *json_end = (unsigned char const *) memchr(sample.buffer, '\n', sample.size);
|
|
|
|
while (json_end && json_end + 3 < end && json_end[1] != '\n') json_end = (unsigned char const *) memchr(json_end + 2, '\n', end - json_end - 2);
|
|
|
|
if (json_end)
|
|
|
|
json_end += 2;
|
|
|
|
else
|
|
|
|
json_end = end;
|
|
|
|
std::string msg((char const *) sample.buffer, json_end - sample.buffer);
|
|
|
|
json root;
|
|
|
|
// OutputDebugStringA(msg.c_str());
|
|
|
|
// OutputDebugStringA("\n");
|
|
|
|
std::istringstream iss(msg);
|
|
|
|
int cmd = 0;
|
|
|
|
int seq = -1;
|
|
|
|
int result = 0;
|
|
|
|
json resp;
|
|
|
|
try {
|
|
|
|
iss >> root;
|
|
|
|
if (!root["result"].is_null()) {
|
|
|
|
result = root["result"];
|
|
|
|
seq = root["sequence"];
|
|
|
|
resp = root["reply"];
|
|
|
|
} else {
|
|
|
|
// maybe notify
|
|
|
|
cmd = root["cmdtype"];
|
|
|
|
seq = root["sequence"];
|
|
|
|
resp = root["notify"];
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
result = ERROR_JSON;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cmd > 0) {
|
|
|
|
if (cmd < NOTIFY_FIRST) return;
|
|
|
|
cmd -= NOTIFY_FIRST;
|
|
|
|
if (size_t(cmd) >= m_notifies.size()) return;
|
|
|
|
auto n = m_notifies[cmd];
|
|
|
|
l.unlock();
|
|
|
|
n(result, resp, json_end);
|
|
|
|
l.lock();
|
|
|
|
} else {
|
|
|
|
seq -= m_sequence;
|
|
|
|
if (size_t(seq) >= m_callbacks.size()) return;
|
|
|
|
auto c = m_callbacks[seq];
|
|
|
|
if (c == nullptr) return;
|
|
|
|
if (result != CONTINUE) {
|
|
|
|
m_callbacks[seq] = callback_t2();
|
|
|
|
if (seq == 0) {
|
|
|
|
while (!m_callbacks.empty() && m_callbacks.front() == nullptr) {
|
|
|
|
m_callbacks.pop_front();
|
|
|
|
++m_sequence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l.unlock();
|
|
|
|
c(result, resp, json_end);
|
|
|
|
l.lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int result)
|
|
|
|
{
|
2022-08-17 02:12:10 +00:00
|
|
|
if (m_session.tunnel) {
|
|
|
|
auto tunnel = m_session.tunnel;
|
|
|
|
m_session.tunnel = nullptr;
|
2022-07-15 15:37:19 +00:00
|
|
|
l.unlock();
|
2022-08-17 02:12:10 +00:00
|
|
|
Bambu_Close(tunnel);
|
|
|
|
Bambu_Destroy(tunnel);
|
2022-07-15 15:37:19 +00:00
|
|
|
l.lock();
|
|
|
|
}
|
|
|
|
if (m_session.owner == nullptr)
|
|
|
|
return;
|
|
|
|
json r;
|
|
|
|
while (!m_callbacks.empty()) {
|
|
|
|
auto c = m_callbacks.front();
|
|
|
|
m_callbacks.pop_front();
|
|
|
|
++m_sequence;
|
|
|
|
if (c) c(result, r, nullptr);
|
|
|
|
}
|
|
|
|
m_messages.clear();
|
2022-07-22 09:46:10 +00:00
|
|
|
while (true) {
|
2022-07-15 15:37:19 +00:00
|
|
|
while (m_stopped) {
|
|
|
|
if (m_session.owner == nullptr)
|
|
|
|
return;
|
|
|
|
m_cond.wait(l);
|
|
|
|
}
|
|
|
|
m_status = Status::Initializing;
|
|
|
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
|
|
|
// wait for url
|
|
|
|
while (!m_stopped && m_messages.empty())
|
|
|
|
m_cond.wait(l);
|
|
|
|
if (m_stopped || m_messages.empty()) continue;
|
|
|
|
std::string url = m_messages.front();
|
|
|
|
m_messages.clear();
|
|
|
|
if (url.empty()) {
|
2022-09-07 06:03:53 +00:00
|
|
|
m_last_error = 1;
|
2022-07-15 15:37:19 +00:00
|
|
|
} else {
|
|
|
|
l.unlock();
|
|
|
|
m_status = Status::Connecting;
|
|
|
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
2022-08-17 02:12:10 +00:00
|
|
|
Bambu_Tunnel tunnel = nullptr;
|
|
|
|
int ret = Bambu_Create(&tunnel, url.c_str());
|
|
|
|
if (ret == 0) {
|
|
|
|
Bambu_SetLogger(tunnel, DumpLog, this);
|
|
|
|
ret = Bambu_Open(tunnel);
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
if (ret == 0)
|
2022-08-17 02:12:10 +00:00
|
|
|
ret = Bambu_StartStream(tunnel, false);
|
2022-07-15 15:37:19 +00:00
|
|
|
l.lock();
|
2023-05-05 02:32:00 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
m_session.tunnel = tunnel;
|
2022-07-15 15:37:19 +00:00
|
|
|
break;
|
2023-05-05 02:32:00 +00:00
|
|
|
}
|
|
|
|
if (tunnel) {
|
|
|
|
Bambu_Close(tunnel);
|
|
|
|
Bambu_Destroy(tunnel);
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
m_last_error = ret;
|
|
|
|
}
|
|
|
|
m_status = Status::Failed;
|
|
|
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
|
|
|
m_cond.timed_wait(l, boost::posix_time::seconds(10));
|
|
|
|
}
|
|
|
|
m_status = Status::ListSyncing;
|
|
|
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
2022-10-09 03:11:47 +00:00
|
|
|
#ifdef PRINTER_FILE_SYSTEM_TEST
|
|
|
|
PostCallback([this] { SendChangedEvent(EVT_FILE_CHANGED); });
|
|
|
|
#else
|
2022-07-15 15:37:19 +00:00
|
|
|
PostCallback([this] { ListAllFiles(); });
|
2022-08-17 02:12:10 +00:00
|
|
|
#endif
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#if defined(_MSC_VER) || defined(_WIN32)
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) || defined(_WIN32)
|
|
|
|
static HMODULE module = NULL;
|
|
|
|
#else
|
|
|
|
static void* module = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void* get_function(const char* name)
|
|
|
|
{
|
|
|
|
void* function = nullptr;
|
|
|
|
|
|
|
|
if (!module)
|
|
|
|
return function;
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) || defined(_WIN32)
|
|
|
|
function = GetProcAddress(module, name);
|
|
|
|
#else
|
|
|
|
function = dlsym(module, name);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!function) {
|
|
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", can not find function %1%") % name;
|
|
|
|
}
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_FUNC(x) lib.x = reinterpret_cast<decltype(lib.x)>(get_function(#x))
|
|
|
|
|
|
|
|
StaticBambuLib &StaticBambuLib::get()
|
|
|
|
{
|
|
|
|
static StaticBambuLib lib;
|
|
|
|
// first load the library
|
2023-01-29 12:27:01 +00:00
|
|
|
|
2022-08-17 02:12:10 +00:00
|
|
|
if (lib.Bambu_Open)
|
|
|
|
return lib;
|
2022-07-22 09:46:10 +00:00
|
|
|
|
|
|
|
if (!module) {
|
|
|
|
module = Slic3r::NetworkAgent::get_bambu_source_entry();
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
|
|
|
|
if (!module) {
|
|
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", can not Load Library";
|
|
|
|
}
|
2022-07-22 09:46:10 +00:00
|
|
|
|
2022-08-17 02:12:10 +00:00
|
|
|
GET_FUNC(Bambu_Create);
|
2022-07-15 15:37:19 +00:00
|
|
|
GET_FUNC(Bambu_Open);
|
|
|
|
GET_FUNC(Bambu_StartStream);
|
2023-01-29 12:27:01 +00:00
|
|
|
GET_FUNC(Bambu_GetStreamCount);
|
|
|
|
GET_FUNC(Bambu_GetStreamInfo);
|
2022-07-15 15:37:19 +00:00
|
|
|
GET_FUNC(Bambu_SendMessage);
|
|
|
|
GET_FUNC(Bambu_ReadSample);
|
|
|
|
GET_FUNC(Bambu_Close);
|
2022-08-17 02:12:10 +00:00
|
|
|
GET_FUNC(Bambu_Destroy);
|
|
|
|
GET_FUNC(Bambu_SetLogger);
|
2022-07-15 15:37:19 +00:00
|
|
|
GET_FUNC(Bambu_FreeLogMsg);
|
2022-07-22 09:46:10 +00:00
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
if (!lib.Bambu_Open)
|
2022-08-17 02:12:10 +00:00
|
|
|
lib.Bambu_Create = Fake_Bambu_Create;
|
2022-07-15 15:37:19 +00:00
|
|
|
return lib;
|
|
|
|
}
|
Add support for Bambu Lab X1 series live video stream on Linux.
wxWidgets on Linux uses GStreamer as its back-end for wxMediaCtrl, which
doesn't have a bambu: URI handler. On Windows, this is handled by a Windows
Media subsystem plugin, and on Mac, this is handled with a BambuPlayer
class. Luckily, the libBambuSource.so binary that is distributed with the
network plugin package already contains support for receiving h.264 data
from the network, and the API is the same as is used by the tiny
bambusource.exe binary on Windows; we glue this into a GStreamer source
plugin that registers a URI handler for bambu:.
To make this work, we make a few additional changes elsewhere. GStreamer
seems to have trouble rendering an Xv overlay onto a 32bpp X visual, but
Bambu Slicer seems to request a 32bpp visual for some background
transparency in the Notebook; it doesn't seem to use it in an interesting
way on Linux, though, so we remove that request for transparency to allow
Bambu Studio to render to a 24bpp visual. The media controller
infrastructure also makes a few assumptions about when sizing information
can be queried from a wxMediaCtrl backend that do not hold true on Linux; we
either fix those assumptions, or fake them out, as needed. We also make a
few changes needed to successfully compile C.
This has only been tested with the GStreamer backend for wxWidgets --
notably, not the GStreamer-play backend (these are, astonishingly, two
different things!). If you find that this seems not to work, consider
*un*installing the libgstreamer-plugins-bad1.0-dev package and then
rebuilding wxWidgets.
2023-01-10 09:40:39 +00:00
|
|
|
|
2023-01-29 12:27:01 +00:00
|
|
|
extern "C" BambuLib *bambulib_get() {
|
Add support for Bambu Lab X1 series live video stream on Linux.
wxWidgets on Linux uses GStreamer as its back-end for wxMediaCtrl, which
doesn't have a bambu: URI handler. On Windows, this is handled by a Windows
Media subsystem plugin, and on Mac, this is handled with a BambuPlayer
class. Luckily, the libBambuSource.so binary that is distributed with the
network plugin package already contains support for receiving h.264 data
from the network, and the API is the same as is used by the tiny
bambusource.exe binary on Windows; we glue this into a GStreamer source
plugin that registers a URI handler for bambu:.
To make this work, we make a few additional changes elsewhere. GStreamer
seems to have trouble rendering an Xv overlay onto a 32bpp X visual, but
Bambu Slicer seems to request a 32bpp visual for some background
transparency in the Notebook; it doesn't seem to use it in an interesting
way on Linux, though, so we remove that request for transparency to allow
Bambu Studio to render to a 24bpp visual. The media controller
infrastructure also makes a few assumptions about when sizing information
can be queried from a wxMediaCtrl backend that do not hold true on Linux; we
either fix those assumptions, or fake them out, as needed. We also make a
few changes needed to successfully compile C.
This has only been tested with the GStreamer backend for wxWidgets --
notably, not the GStreamer-play backend (these are, astonishingly, two
different things!). If you find that this seems not to work, consider
*un*installing the libgstreamer-plugins-bad1.0-dev package and then
rebuilding wxWidgets.
2023-01-10 09:40:39 +00:00
|
|
|
return &StaticBambuLib::get();
|
|
|
|
}
|