mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
FIX: [STUDIO-1868] sdcard model files runnable
Change-Id: I3b644a5bbea5e936903f7308e3bf484e5203f92c
This commit is contained in:
parent
c58baa6b16
commit
8c1dce19d3
2 changed files with 64 additions and 33 deletions
|
@ -902,6 +902,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
// Version of the 3mf file
|
// Version of the 3mf file
|
||||||
unsigned int m_version;
|
unsigned int m_version;
|
||||||
bool m_check_version;
|
bool m_check_version;
|
||||||
|
bool m_load_model = false;
|
||||||
bool m_load_aux;
|
bool m_load_aux;
|
||||||
bool m_load_config;
|
bool m_load_config;
|
||||||
// backup & restore
|
// backup & restore
|
||||||
|
@ -1189,6 +1190,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
m_mm_painting_version = 0;
|
m_mm_painting_version = 0;
|
||||||
m_check_version = strategy & LoadStrategy::CheckVersion;
|
m_check_version = strategy & LoadStrategy::CheckVersion;
|
||||||
//BBS: auxiliary data
|
//BBS: auxiliary data
|
||||||
|
m_load_model = strategy & LoadStrategy::LoadModel;
|
||||||
m_load_aux = strategy & LoadStrategy::LoadAuxiliary;
|
m_load_aux = strategy & LoadStrategy::LoadAuxiliary;
|
||||||
m_load_restore = strategy & LoadStrategy::Restore;
|
m_load_restore = strategy & LoadStrategy::Restore;
|
||||||
m_load_config = strategy & LoadStrategy::LoadConfig;
|
m_load_config = strategy & LoadStrategy::LoadConfig;
|
||||||
|
@ -1352,6 +1354,10 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
|
|
||||||
if (m_thumbnail_middle.empty()) m_thumbnail_middle = m_thumbnail_path;
|
if (m_thumbnail_middle.empty()) m_thumbnail_middle = m_thumbnail_path;
|
||||||
if (m_thumbnail_small.empty()) m_thumbnail_small = m_thumbnail_path;
|
if (m_thumbnail_small.empty()) m_thumbnail_small = m_thumbnail_path;
|
||||||
|
if (!m_thumbnail_small.empty() && m_thumbnail_small.front() == '/')
|
||||||
|
m_thumbnail_small.erase(m_thumbnail_small.begin());
|
||||||
|
if (!m_thumbnail_middle.empty() && m_thumbnail_middle.front() == '/')
|
||||||
|
m_thumbnail_middle.erase(m_thumbnail_middle.begin());
|
||||||
m_model->model_info->metadata_items.emplace("Thumbnail", m_thumbnail_small);
|
m_model->model_info->metadata_items.emplace("Thumbnail", m_thumbnail_small);
|
||||||
m_model->model_info->metadata_items.emplace("Poster", m_thumbnail_middle);
|
m_model->model_info->metadata_items.emplace("Poster", m_thumbnail_middle);
|
||||||
|
|
||||||
|
@ -3465,7 +3471,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
Transform3d transform = bbs_get_transform_from_3mf_specs_string(bbs_get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR));
|
Transform3d transform = bbs_get_transform_from_3mf_specs_string(bbs_get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR));
|
||||||
int printable = bbs_get_attribute_value_bool(attributes, num_attributes, PRINTABLE_ATTR);
|
int printable = bbs_get_attribute_value_bool(attributes, num_attributes, PRINTABLE_ATTR);
|
||||||
|
|
||||||
return _create_object_instance(path, object_id, transform, printable, 1);
|
return !m_load_model || _create_object_instance(path, object_id, transform, printable, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _BBS_3MF_Importer::_handle_end_item()
|
bool _BBS_3MF_Importer::_handle_end_item()
|
||||||
|
@ -4047,6 +4053,8 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
||||||
|
|
||||||
bool _BBS_3MF_Importer::_handle_start_assemble_item(const char** attributes, unsigned int num_attributes)
|
bool _BBS_3MF_Importer::_handle_start_assemble_item(const char** attributes, unsigned int num_attributes)
|
||||||
{
|
{
|
||||||
|
if (!m_load_model) return true;
|
||||||
|
|
||||||
int object_id = bbs_get_attribute_value_int(attributes, num_attributes, OBJECT_ID_ATTR);
|
int object_id = bbs_get_attribute_value_int(attributes, num_attributes, OBJECT_ID_ATTR);
|
||||||
int instance_id = bbs_get_attribute_value_int(attributes, num_attributes, INSTANCEID_ATTR);
|
int instance_id = bbs_get_attribute_value_int(attributes, num_attributes, INSTANCEID_ATTR);
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,9 @@ void PrinterFileSystem::ListAllFiles()
|
||||||
list.push_back(ff);
|
list.push_back(ff);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}, [this](int result, FileList list) {
|
}, [this, type = m_file_type](int result, FileList list) {
|
||||||
|
if (type != m_file_type)
|
||||||
|
return 0;
|
||||||
m_file_list.swap(list);
|
m_file_list.swap(list);
|
||||||
std::sort(m_file_list.begin(), m_file_list.end());
|
std::sort(m_file_list.begin(), m_file_list.end());
|
||||||
auto iter1 = m_file_list.begin();
|
auto iter1 = m_file_list.begin();
|
||||||
|
@ -138,25 +140,27 @@ void PrinterFileSystem::ListAllFiles()
|
||||||
auto iter2 = list.begin();
|
auto iter2 = list.begin();
|
||||||
auto end2 = list.end();
|
auto end2 = list.end();
|
||||||
while (iter1 != end1 && iter2 != end2) {
|
while (iter1 != end1 && iter2 != end2) {
|
||||||
if (iter1->name == iter2->name) {
|
if (*iter1 < *iter2) {
|
||||||
iter1->thumbnail = iter2->thumbnail;
|
|
||||||
iter1->flags = iter2->flags;
|
|
||||||
if (!iter1->thumbnail.IsOk())
|
|
||||||
iter1->flags &= ~FF_THUMNAIL;
|
|
||||||
iter1->progress = iter2->progress;
|
|
||||||
iter1->local_path = iter2->local_path;
|
|
||||||
++iter1; ++iter2;
|
|
||||||
} else if (*iter1 < *iter2) {
|
|
||||||
++iter1;
|
++iter1;
|
||||||
} else if (*iter2 < *iter1) {
|
} else if (*iter2 < *iter1) {
|
||||||
++iter2;
|
++iter2;
|
||||||
} else {
|
} else {
|
||||||
|
if (iter1->path == iter2->path && iter1->name == iter2->name) {
|
||||||
|
iter1->thumbnail = iter2->thumbnail;
|
||||||
|
iter1->flags = iter2->flags;
|
||||||
|
if (!iter1->thumbnail.IsOk())
|
||||||
|
iter1->flags &= ~FF_THUMNAIL;
|
||||||
|
iter1->progress = iter2->progress;
|
||||||
|
iter1->local_path = iter2->local_path;
|
||||||
|
iter1->metadata = iter2->metadata;
|
||||||
|
}
|
||||||
++iter1;
|
++iter1;
|
||||||
++iter2;
|
++iter2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BuildGroups();
|
BuildGroups();
|
||||||
UpdateGroupSelect();
|
UpdateGroupSelect();
|
||||||
|
m_task_flags = 0;
|
||||||
m_status = Status::ListReady;
|
m_status = Status::ListReady;
|
||||||
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
|
||||||
SendChangedEvent(EVT_FILE_CHANGED);
|
SendChangedEvent(EVT_FILE_CHANGED);
|
||||||
|
@ -267,6 +271,7 @@ void PrinterFileSystem::FetchModel(size_t index, std::function<void(std::string
|
||||||
auto &file = m_file_list[index];
|
auto &file = m_file_list[index];
|
||||||
arr.push_back(file.path + "#_rel/.rels");
|
arr.push_back(file.path + "#_rel/.rels");
|
||||||
arr.push_back(file.path + "#3D/3dmodel.model");
|
arr.push_back(file.path + "#3D/3dmodel.model");
|
||||||
|
arr.push_back(file.path + "#Metadata/model_settings.config");
|
||||||
arr.push_back(file.path + "#Metadata/slice_info.config");
|
arr.push_back(file.path + "#Metadata/slice_info.config");
|
||||||
arr.push_back(file.path + "#Metadata/project_settings.config");
|
arr.push_back(file.path + "#Metadata/project_settings.config");
|
||||||
for (auto & meta : file.metadata) {
|
for (auto & meta : file.metadata) {
|
||||||
|
@ -626,6 +631,14 @@ void PrinterFileSystem::DownloadNextFile()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ThumbnailType
|
||||||
|
{
|
||||||
|
OldThumbnail = 0,
|
||||||
|
VideoThumbnail = 1,
|
||||||
|
ModelMetadata = 2,
|
||||||
|
ModelThumbnail = 3
|
||||||
|
};
|
||||||
|
|
||||||
void PrinterFileSystem::UpdateFocusThumbnail()
|
void PrinterFileSystem::UpdateFocusThumbnail()
|
||||||
{
|
{
|
||||||
m_task_flags &= ~FF_THUMNAIL;
|
m_task_flags &= ~FF_THUMNAIL;
|
||||||
|
@ -649,12 +662,12 @@ void PrinterFileSystem::UpdateFocusThumbnail()
|
||||||
if (names.empty() && paths.empty())
|
if (names.empty() && paths.empty())
|
||||||
return;
|
return;
|
||||||
m_task_flags |= FF_THUMNAIL;
|
m_task_flags |= FF_THUMNAIL;
|
||||||
UpdateFocusThumbnail2(std::make_shared<std::vector<File>>(paths), paths.empty() ? 0 : m_file_type == F_MODEL ? 2 : 1);
|
UpdateFocusThumbnail2(std::make_shared<std::vector<File>>(paths), paths.empty() ? OldThumbnail : m_file_type == F_MODEL ? ModelMetadata : VideoThumbnail);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrinterFileSystem::ParseThumbnail(File &file)
|
bool PrinterFileSystem::ParseThumbnail(File &file)
|
||||||
{
|
{
|
||||||
std::istringstream iss(file.local_path, std::ios::binary);
|
std::istringstream iss(file.local_path, std::ios::binary);
|
||||||
return ParseThumbnail(file, iss);
|
return ParseThumbnail(file, iss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,26 +712,27 @@ void PrinterFileSystem::UpdateFocusThumbnail2(std::shared_ptr<std::vector<File>>
|
||||||
{
|
{
|
||||||
json req;
|
json req;
|
||||||
json arr;
|
json arr;
|
||||||
if (type == 0) {
|
if (type == OldThumbnail) {
|
||||||
for (auto &file : *files) arr.push_back(file.name);
|
for (auto &file : *files) arr.push_back(file.name);
|
||||||
req["files"] = arr;
|
req["files"] = arr;
|
||||||
if (m_file_type == F_MODEL) {
|
|
||||||
for (auto &file : *files) arr.push_back(file.path);
|
|
||||||
}
|
|
||||||
for (auto &file : *files) arr.push_back(file.path);
|
|
||||||
} else {
|
} else {
|
||||||
if (type == 1) {
|
if (type == VideoThumbnail) {
|
||||||
for (auto &file : *files) arr.push_back(file.path + "#thumbnail");
|
for (auto &file : *files) arr.push_back(file.path + "#thumbnail");
|
||||||
} else if (type == 2) {
|
} else if (type == ModelMetadata) {
|
||||||
for (auto &file : *files) {
|
for (auto &file : *files) {
|
||||||
arr.push_back(file.path + "#_rel/.rels");
|
arr.push_back(file.path + "#_rels/.rels");
|
||||||
arr.push_back(file.path + "#3D/3dmodel.model");
|
arr.push_back(file.path + "#3D/3dmodel.model");
|
||||||
|
arr.push_back(file.path + "#Metadata/model_settings.config");
|
||||||
arr.push_back(file.path + "#Metadata/slice_info.config");
|
arr.push_back(file.path + "#Metadata/slice_info.config");
|
||||||
arr.push_back(file.path + "#Metadata/project_settings.config");
|
arr.push_back(file.path + "#Metadata/project_settings.config");
|
||||||
}
|
}
|
||||||
req["zip"] = true;
|
req["zip"] = true;
|
||||||
} else {
|
} else {
|
||||||
for (auto &file : *files) arr.push_back(file.path + "#" + file.metadata["Thumbnail"]);
|
for (auto &file : *files) {
|
||||||
|
auto thumbnail = file.metadata["Thumbnail"];
|
||||||
|
if (!thumbnail.empty())
|
||||||
|
arr.push_back(file.path + "#" + thumbnail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
req["paths"] = arr;
|
req["paths"] = arr;
|
||||||
}
|
}
|
||||||
|
@ -726,19 +740,25 @@ void PrinterFileSystem::UpdateFocusThumbnail2(std::shared_ptr<std::vector<File>>
|
||||||
SUB_FILE, req, [type](json const &resp, File &file, unsigned char const *data) -> int {
|
SUB_FILE, req, [type](json const &resp, File &file, unsigned char const *data) -> int {
|
||||||
// in work thread, continue recv
|
// in work thread, continue recv
|
||||||
// receive data
|
// receive data
|
||||||
wxString mimetype = resp.value("mimetype", "image/jpeg");
|
wxString mimetype = resp.value("mimetype", "");
|
||||||
std::string thumbnail = resp.value("thumbnail", "");
|
std::string thumbnail = resp.value("thumbnail", "");
|
||||||
std::string path = resp.value("path", "");
|
std::string path = resp.value("path", "");
|
||||||
boost::uint32_t size = resp["size"];
|
boost::uint32_t size = resp["size"];
|
||||||
file.name = thumbnail;
|
file.name = thumbnail;
|
||||||
file.path = path;
|
file.path = path;
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
if (type != 2) {
|
if (type == ModelMetadata) {
|
||||||
wxMemoryInputStream mis(data, size);
|
|
||||||
file.thumbnail = wxImage(mis, mimetype);
|
|
||||||
} else {
|
|
||||||
file.local_path = std::string((char *) data, size);
|
file.local_path = std::string((char *) data, size);
|
||||||
ParseThumbnail(file);
|
ParseThumbnail(file);
|
||||||
|
} else {
|
||||||
|
if (mimetype.empty()) {
|
||||||
|
if (!path.empty()) thumbnail = path;
|
||||||
|
auto n = thumbnail.find_last_of('.');
|
||||||
|
if (n != std::string::npos)
|
||||||
|
mimetype = "image/" + thumbnail.substr(n + 1);
|
||||||
|
}
|
||||||
|
wxMemoryInputStream mis(data, size);
|
||||||
|
file.thumbnail = wxImage(mis, mimetype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -751,7 +771,7 @@ void PrinterFileSystem::UpdateFocusThumbnail2(std::shared_ptr<std::vector<File>>
|
||||||
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); }) :
|
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; });
|
std::find_if(m_file_list.begin(), m_file_list.end(), [&path](auto &f) { return f.path == path; });
|
||||||
if (iter != m_file_list.end()) {
|
if (iter != m_file_list.end()) {
|
||||||
if (type == 2) {
|
if (type == ModelMetadata) {
|
||||||
if (!file.metadata.empty()) {
|
if (!file.metadata.empty()) {
|
||||||
iter->metadata = file.metadata;
|
iter->metadata = file.metadata;
|
||||||
int index = iter - m_file_list.begin();
|
int index = iter - m_file_list.begin();
|
||||||
|
@ -760,6 +780,9 @@ void PrinterFileSystem::UpdateFocusThumbnail2(std::shared_ptr<std::vector<File>>
|
||||||
if (iter != files->end())
|
if (iter != files->end())
|
||||||
iter->metadata = file.metadata;
|
iter->metadata = file.metadata;
|
||||||
}
|
}
|
||||||
|
auto thumbnail = iter->metadata["Thumbnail"];
|
||||||
|
if (thumbnail.empty())
|
||||||
|
iter->flags |= FF_THUMNAIL; // DOTO: retry on fail
|
||||||
} else {
|
} else {
|
||||||
iter->flags |= FF_THUMNAIL; // DOTO: retry on fail
|
iter->flags |= FF_THUMNAIL; // DOTO: retry on fail
|
||||||
if (file.thumbnail.IsOk()) {
|
if (file.thumbnail.IsOk()) {
|
||||||
|
@ -769,9 +792,9 @@ void PrinterFileSystem::UpdateFocusThumbnail2(std::shared_ptr<std::vector<File>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == 0) {
|
if (result != CONTINUE) {
|
||||||
if (type == 2)
|
if (type == ModelMetadata)
|
||||||
UpdateFocusThumbnail2(files, 3);
|
UpdateFocusThumbnail2(files, ModelThumbnail);
|
||||||
else
|
else
|
||||||
UpdateFocusThumbnail();
|
UpdateFocusThumbnail();
|
||||||
}
|
}
|
||||||
|
@ -974,8 +997,8 @@ void PrinterFileSystem::HandleResponse(boost::unique_lock<boost::mutex> &l, Bamb
|
||||||
json_end = end;
|
json_end = end;
|
||||||
std::string msg((char const *) sample.buffer, json_end - sample.buffer);
|
std::string msg((char const *) sample.buffer, json_end - sample.buffer);
|
||||||
json root;
|
json root;
|
||||||
// OutputDebugStringA(msg.c_str());
|
//OutputDebugStringA(msg.c_str());
|
||||||
// OutputDebugStringA("\n");
|
//OutputDebugStringA("\n");
|
||||||
std::istringstream iss(msg);
|
std::istringstream iss(msg);
|
||||||
int cmd = 0;
|
int cmd = 0;
|
||||||
int seq = -1;
|
int seq = -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue