#7791 - Fixed reload from disk command for plain (non zipped) amf files
This commit is contained in:
parent
08abdc27a0
commit
7bd8b3b892
@ -283,25 +283,28 @@ void AMFParserContext::startElement(const char *name, const char **atts)
|
|||||||
m_value[0] = type;
|
m_value[0] = type;
|
||||||
node_type_new = NODE_TYPE_METADATA;
|
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");
|
const char *material_id = get_attribute(atts, "id");
|
||||||
m_material = m_model.add_material((material_id == nullptr) ? "_" : material_id);
|
m_material = m_model.add_material((material_id == nullptr) ? "_" : material_id);
|
||||||
node_type_new = NODE_TYPE_MATERIAL;
|
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");
|
const char *object_id = get_attribute(atts, "id");
|
||||||
if (object_id == nullptr)
|
if (object_id == nullptr)
|
||||||
this->stop();
|
this->stop();
|
||||||
else {
|
else {
|
||||||
assert(m_object_vertices.empty());
|
assert(m_object_vertices.empty());
|
||||||
m_object = m_model.add_object();
|
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;
|
m_object_instances_map[object_id].idx = int(m_model.objects.size())-1;
|
||||||
node_type_new = NODE_TYPE_OBJECT;
|
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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (strcmp(name, "metadata") == 0) {
|
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");
|
m_value[0] = get_attribute(atts, "type");
|
||||||
node_type_new = NODE_TYPE_METADATA;
|
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;
|
node_type_new = NODE_TYPE_LAYER_CONFIG;
|
||||||
else if (strcmp(name, "mesh") == 0) {
|
else if (strcmp(name, "mesh") == 0) {
|
||||||
if (m_path[1] == NODE_TYPE_OBJECT)
|
if (m_path[1] == NODE_TYPE_OBJECT)
|
||||||
node_type_new = NODE_TYPE_MESH;
|
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) {
|
if (m_path[1] == NODE_TYPE_CONSTELLATION) {
|
||||||
const char *object_id = get_attribute(atts, "objectid");
|
const char *object_id = get_attribute(atts, "objectid");
|
||||||
if (object_id == nullptr)
|
if (object_id == nullptr)
|
||||||
@ -910,12 +915,17 @@ bool load_amf_file(const char *path, DynamicPrintConfig *config, ConfigSubstitut
|
|||||||
if (result)
|
if (result)
|
||||||
ctx.endDocument();
|
ctx.endDocument();
|
||||||
|
|
||||||
for (ModelObject* o : model->objects)
|
for (ModelObject* o : model->objects) {
|
||||||
{
|
unsigned int counter = 0;
|
||||||
for (ModelVolume* v : o->volumes)
|
for (ModelVolume* v : o->volumes) {
|
||||||
{
|
++counter;
|
||||||
if (v->source.input_file.empty() && (v->type() == ModelVolumeType::MODEL_PART))
|
if (v->source.input_file.empty() && v->type() == ModelVolumeType::MODEL_PART)
|
||||||
v->source.input_file = path;
|
v->source.input_file = path;
|
||||||
|
if (v->name.empty()) {
|
||||||
|
v->name = o->name;
|
||||||
|
if (o->volumes.size() > 1)
|
||||||
|
v->name += "_" + std::to_string(counter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3691,12 +3691,20 @@ void Plater::priv::reload_from_disk()
|
|||||||
if (has_source || has_name) {
|
if (has_source || has_name) {
|
||||||
int new_volume_idx = -1;
|
int new_volume_idx = -1;
|
||||||
int new_object_idx = -1;
|
int new_object_idx = -1;
|
||||||
// if (has_source) {
|
bool match_found = false;
|
||||||
// // take idxs from source
|
// take idxs from the matching volume
|
||||||
// new_volume_idx = old_volume->source.volume_idx;
|
if (has_source && old_volume->source.object_idx < int(new_model.objects.size())) {
|
||||||
// new_object_idx = old_volume->source.object_idx;
|
const ModelObject* obj = new_model.objects[old_volume->source.object_idx];
|
||||||
// }
|
if (old_volume->source.volume_idx < int(obj->volumes.size())) {
|
||||||
// else {
|
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
|
// take idxs from the 1st matching volume
|
||||||
for (size_t o = 0; o < new_model.objects.size(); ++o) {
|
for (size_t o = 0; o < new_model.objects.size(); ++o) {
|
||||||
ModelObject* obj = new_model.objects[o];
|
ModelObject* obj = new_model.objects[o];
|
||||||
@ -3712,7 +3720,7 @@ void Plater::priv::reload_from_disk()
|
|||||||
if (found)
|
if (found)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (new_object_idx < 0 || int(new_model.objects.size()) <= new_object_idx) {
|
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));
|
fail_list.push_back(from_u8(has_source ? old_volume->source.input_file : old_volume->name));
|
||||||
|
Loading…
Reference in New Issue
Block a user