From 7bd8b3b8925f02b57a4be38b318d91112fce1227 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 31 Jan 2022 14:26:31 +0100 Subject: [PATCH] #7791 - Fixed reload from disk command for plain (non zipped) amf files --- src/libslic3r/Format/AMF.cpp | 36 +++++++++++++++++++++++------------- src/slic3r/GUI/Plater.cpp | 22 +++++++++++++++------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 235cdecb5..a8b66b15b 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -283,25 +283,28 @@ void AMFParserContext::startElement(const char *name, const char **atts) m_value[0] = type; node_type_new = NODE_TYPE_METADATA; } - } else if (strcmp(name, "material") == 0) { + } + else if (strcmp(name, "material") == 0) { const char *material_id = get_attribute(atts, "id"); m_material = m_model.add_material((material_id == nullptr) ? "_" : material_id); node_type_new = NODE_TYPE_MATERIAL; - } else if (strcmp(name, "object") == 0) { + } + else if (strcmp(name, "object") == 0) { const char *object_id = get_attribute(atts, "id"); if (object_id == nullptr) this->stop(); else { assert(m_object_vertices.empty()); m_object = m_model.add_object(); + m_object->name = std::string(object_id); m_object_instances_map[object_id].idx = int(m_model.objects.size())-1; node_type_new = NODE_TYPE_OBJECT; } - } else if (strcmp(name, "constellation") == 0) { - node_type_new = NODE_TYPE_CONSTELLATION; - } else if (strcmp(name, "custom_gcodes_per_height") == 0) { - node_type_new = NODE_TYPE_CUSTOM_GCODE; } + else if (strcmp(name, "constellation") == 0) + node_type_new = NODE_TYPE_CONSTELLATION; + else if (strcmp(name, "custom_gcodes_per_height") == 0) + node_type_new = NODE_TYPE_CUSTOM_GCODE; break; case 2: if (strcmp(name, "metadata") == 0) { @@ -309,12 +312,14 @@ void AMFParserContext::startElement(const char *name, const char **atts) m_value[0] = get_attribute(atts, "type"); node_type_new = NODE_TYPE_METADATA; } - } else if (strcmp(name, "layer_config_ranges") == 0 && m_path[1] == NODE_TYPE_OBJECT) + } + else if (strcmp(name, "layer_config_ranges") == 0 && m_path[1] == NODE_TYPE_OBJECT) node_type_new = NODE_TYPE_LAYER_CONFIG; else if (strcmp(name, "mesh") == 0) { if (m_path[1] == NODE_TYPE_OBJECT) node_type_new = NODE_TYPE_MESH; - } else if (strcmp(name, "instance") == 0) { + } + else if (strcmp(name, "instance") == 0) { if (m_path[1] == NODE_TYPE_CONSTELLATION) { const char *object_id = get_attribute(atts, "objectid"); if (object_id == nullptr) @@ -910,12 +915,17 @@ bool load_amf_file(const char *path, DynamicPrintConfig *config, ConfigSubstitut if (result) ctx.endDocument(); - for (ModelObject* o : model->objects) - { - for (ModelVolume* v : o->volumes) - { - if (v->source.input_file.empty() && (v->type() == ModelVolumeType::MODEL_PART)) + for (ModelObject* o : model->objects) { + unsigned int counter = 0; + for (ModelVolume* v : o->volumes) { + ++counter; + if (v->source.input_file.empty() && v->type() == ModelVolumeType::MODEL_PART) v->source.input_file = path; + if (v->name.empty()) { + v->name = o->name; + if (o->volumes.size() > 1) + v->name += "_" + std::to_string(counter); + } } } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index db41c18ec..a6447745c 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3691,12 +3691,20 @@ void Plater::priv::reload_from_disk() if (has_source || has_name) { int new_volume_idx = -1; int new_object_idx = -1; -// if (has_source) { -// // take idxs from source -// new_volume_idx = old_volume->source.volume_idx; -// new_object_idx = old_volume->source.object_idx; -// } -// else { + bool match_found = false; + // take idxs from the matching volume + if (has_source && old_volume->source.object_idx < int(new_model.objects.size())) { + const ModelObject* obj = new_model.objects[old_volume->source.object_idx]; + if (old_volume->source.volume_idx < int(obj->volumes.size())) { + if (obj->volumes[old_volume->source.volume_idx]->name == old_volume->name) { + new_volume_idx = old_volume->source.volume_idx; + new_object_idx = old_volume->source.object_idx; + match_found = true; + } + } + } + + if (!match_found && has_name) { // take idxs from the 1st matching volume for (size_t o = 0; o < new_model.objects.size(); ++o) { ModelObject* obj = new_model.objects[o]; @@ -3712,7 +3720,7 @@ void Plater::priv::reload_from_disk() if (found) break; } -// } + } if (new_object_idx < 0 || int(new_model.objects.size()) <= new_object_idx) { fail_list.push_back(from_u8(has_source ? old_volume->source.input_file : old_volume->name));