ENABLE_ENHANCED_RELOAD_FROM_DISK set as default

This commit is contained in:
Enrico Turri 2019-09-23 15:35:49 +02:00
parent 1115e77b38
commit 2dc9949a4c
13 changed files with 10 additions and 269 deletions

View file

@ -31,12 +31,8 @@ namespace pt = boost::property_tree;
// VERSION NUMBERS
// 0 : .3mf, files saved by older slic3r or other applications. No version definition in them.
// 1 : Introduction of 3mf versioning. No other change in data saved into 3mf files.
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// 2 : Meshes saved in their local system; Volumes' matrices and source data added to Metadata/Slic3r_PE_model.config file.
const unsigned int VERSION_3MF = 2;
#else
const unsigned int VERSION_3MF = 1;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
const char* SLIC3RPE_3MF_VERSION = "slic3rpe:Version3mf"; // definition of the metadata name saved into .model file
const std::string MODEL_FOLDER = "3D/";
@ -92,7 +88,6 @@ const char* VOLUME_TYPE = "volume";
const char* NAME_KEY = "name";
const char* MODIFIER_KEY = "modifier";
const char* VOLUME_TYPE_KEY = "volume_type";
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
const char* MATRIX_KEY = "matrix";
const char* SOURCE_FILE_KEY = "source_file";
const char* SOURCE_OBJECT_ID_KEY = "source_object_id";
@ -100,7 +95,6 @@ const char* SOURCE_VOLUME_ID_KEY = "source_volume_id";
const char* SOURCE_OFFSET_X_KEY = "source_offset_x";
const char* SOURCE_OFFSET_Y_KEY = "source_offset_y";
const char* SOURCE_OFFSET_Z_KEY = "source_offset_z";
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
const unsigned int VALID_OBJECT_TYPES_COUNT = 1;
const char* VALID_OBJECT_TYPES[] =
@ -162,25 +156,15 @@ bool get_attribute_value_bool(const char** attributes, unsigned int attributes_s
return (text != nullptr) ? (bool)::atoi(text) : true;
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
Slic3r::Transform3d get_transform_from_3mf_specs_string(const std::string& mat_str)
#else
Slic3r::Transform3d get_transform_from_string(const std::string& mat_str)
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
{
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// check: https://3mf.io/3d-manufacturing-format/ or https://github.com/3MFConsortium/spec_core/blob/master/3MF%20Core%20Specification.md
// to see how matrices are stored inside 3mf according to specifications
Slic3r::Transform3d ret = Slic3r::Transform3d::Identity();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
if (mat_str.empty())
// empty string means default identity matrix
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
return ret;
#else
return Slic3r::Transform3d::Identity();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
std::vector<std::string> mat_elements_str;
boost::split(mat_elements_str, mat_str, boost::is_any_of(" "), boost::token_compress_on);
@ -188,13 +172,8 @@ Slic3r::Transform3d get_transform_from_string(const std::string& mat_str)
unsigned int size = (unsigned int)mat_elements_str.size();
if (size != 12)
// invalid data, return identity matrix
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
return ret;
#else
return Slic3r::Transform3d::Identity();
Slic3r::Transform3d ret = Slic3r::Transform3d::Identity();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
unsigned int i = 0;
// matrices are stored into 3mf files as 4x3
// we need to transpose them
@ -1407,11 +1386,7 @@ namespace Slic3r {
bool _3MF_Importer::_handle_start_component(const char** attributes, unsigned int num_attributes)
{
int object_id = get_attribute_value_int(attributes, num_attributes, OBJECTID_ATTR);
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
Transform3d transform = get_transform_from_3mf_specs_string(get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR));
#else
Transform3d transform = get_transform_from_string(get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR));
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
IdToModelObjectMap::iterator object_item = m_objects.find(object_id);
if (object_item == m_objects.end())
@ -1457,11 +1432,7 @@ namespace Slic3r {
// see specifications
int object_id = get_attribute_value_int(attributes, num_attributes, OBJECTID_ATTR);
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
Transform3d transform = get_transform_from_3mf_specs_string(get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR));
#else
Transform3d transform = get_transform_from_string(get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR));
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
int printable = get_attribute_value_bool(attributes, num_attributes, PRINTABLE_ATTR);
return _create_object_instance(object_id, transform, printable, 1);
@ -1674,7 +1645,6 @@ namespace Slic3r {
return false;
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
Slic3r::Geometry::Transformation transform;
if (m_version > 1)
{
@ -1689,7 +1659,6 @@ namespace Slic3r {
}
}
Transform3d inv_matrix = transform.get_matrix().inverse();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
// splits volume out of imported geometry
TriangleMesh triangle_mesh;
@ -1708,16 +1677,12 @@ namespace Slic3r {
stl_facet& facet = stl.facet_start[i];
for (unsigned int v = 0; v < 3; ++v)
{
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
unsigned int tri_id = geometry.triangles[src_start_id + ii + v] * 3;
Vec3f vertex(geometry.vertices[tri_id + 0], geometry.vertices[tri_id + 1], geometry.vertices[tri_id + 2]);
if (m_version > 1)
// revert the vertices to the original mesh reference system
vertex = (inv_matrix * vertex.cast<double>()).cast<float>();
::memcpy(facet.vertex[v].data(), (const void*)vertex.data(), 3 * sizeof(float));
#else
::memcpy(facet.vertex[v].data(), (const void*)&geometry.vertices[geometry.triangles[src_start_id + ii + v] * 3], 3 * sizeof(float));
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
}
}
@ -1725,20 +1690,12 @@ namespace Slic3r {
triangle_mesh.repair();
ModelVolume* volume = object.add_volume(std::move(triangle_mesh));
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// apply the volume matrix taken from the metadata, if present
if (m_version > 1)
volume->set_transformation(transform);
#else
volume->center_geometry_after_creation();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
volume->calculate_convex_hull();
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// apply the remaining volume's metadata
#else
// apply volume's name and config data
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
for (const Metadata& metadata : volume_data.metadata)
{
if (metadata.key == NAME_KEY)
@ -1747,7 +1704,6 @@ namespace Slic3r {
volume->set_type(ModelVolumeType::PARAMETER_MODIFIER);
else if (metadata.key == VOLUME_TYPE_KEY)
volume->set_type(ModelVolume::type_from_string(metadata.value));
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
else if (metadata.key == SOURCE_FILE_KEY)
volume->source.input_file = metadata.value;
else if (metadata.key == SOURCE_OBJECT_ID_KEY)
@ -1760,7 +1716,6 @@ namespace Slic3r {
volume->source.mesh_offset(1) = ::atof(metadata.value.c_str());
else if (metadata.key == SOURCE_OFFSET_Z_KEY)
volume->source.mesh_offset(2) = ::atof(metadata.value.c_str());
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
else
volume->config.set_deserialize(metadata.key, metadata.value);
}
@ -2434,7 +2389,6 @@ namespace Slic3r {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << VOLUME_TYPE_KEY << "\" " <<
VALUE_ATTR << "=\"" << ModelVolume::type_to_string(volume->type()) << "\"/>\n";
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// stores volume's local matrix
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << MATRIX_KEY << "\" " << VALUE_ATTR << "=\"";
const Transform3d& matrix = volume->get_matrix();
@ -2459,7 +2413,6 @@ namespace Slic3r {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << SOURCE_OFFSET_Y_KEY << "\" " << VALUE_ATTR << "=\"" << volume->source.mesh_offset(1) << "\"/>\n";
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << SOURCE_OFFSET_Z_KEY << "\" " << VALUE_ATTR << "=\"" << volume->source.mesh_offset(2) << "\"/>\n";
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
// stores volume's config data
for (const std::string& key : volume->config.keys())

View file

@ -12,9 +12,7 @@
#include "../PrintConfig.hpp"
#include "../Utils.hpp"
#include "../I18N.hpp"
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
#include "../Geometry.hpp"
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
#include "AMF.hpp"
@ -39,12 +37,8 @@
// Added x and y components of rotation
// Added x, y and z components of scale
// Added x, y and z components of mirror
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// 3 : Meshes saved in their local system; Added volumes' matrices and source data
const unsigned int VERSION_AMF = 3;
#else
const unsigned int VERSION_AMF = 2;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
const char* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version";
const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config";
@ -569,18 +563,15 @@ void AMFParserContext::endElement(const char * /* name */)
stl.stats.original_num_facets = stl.stats.number_of_facets;
stl_allocate(&stl);
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
Slic3r::Geometry::Transformation transform;
if (m_version > 2)
transform = m_volume->get_transformation();
Transform3d inv_matrix = transform.get_matrix().inverse();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
for (size_t i = 0; i < m_volume_facets.size();) {
stl_facet &facet = stl.facet_start[i/3];
for (unsigned int v = 0; v < 3; ++v)
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
{
unsigned int tri_id = m_volume_facets[i++] * 3;
Vec3f vertex(m_object_vertices[tri_id + 0], m_object_vertices[tri_id + 1], m_object_vertices[tri_id + 2]);
@ -589,19 +580,12 @@ void AMFParserContext::endElement(const char * /* name */)
vertex = (inv_matrix * vertex.cast<double>()).cast<float>();
::memcpy((void*)facet.vertex[v].data(), (const void*)vertex.data(), 3 * sizeof(float));
}
#else
memcpy(facet.vertex[v].data(), &m_object_vertices[m_volume_facets[i ++] * 3], 3 * sizeof(float));
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
}
stl_get_size(&stl);
mesh.repair();
m_volume->set_mesh(std::move(mesh));
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// pass false if the mesh offset has been already taken from the data
m_volume->center_geometry_after_creation(m_volume->source.input_file.empty());
#else
m_volume->center_geometry_after_creation();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
m_volume->calculate_convex_hull();
m_volume_facets.clear();
m_volume = nullptr;
@ -697,7 +681,6 @@ void AMFParserContext::endElement(const char * /* name */)
} else if (strcmp(opt_key, "volume_type") == 0) {
m_volume->set_type(ModelVolume::type_from_string(m_value[1]));
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
else if (strcmp(opt_key, "matrix") == 0) {
Geometry::Transformation transform;
transform.set_from_string(m_value[1]);
@ -721,7 +704,6 @@ void AMFParserContext::endElement(const char * /* name */)
else if (strcmp(opt_key, "source_offset_z") == 0) {
m_volume->source.mesh_offset(2) = ::atof(m_value[1].c_str());
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
}
} else if (m_path.size() == 3) {
if (m_path[1] == NODE_TYPE_MATERIAL) {
@ -1115,7 +1097,6 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config)
if (volume->is_modifier())
stream << " <metadata type=\"slic3r.modifier\">1</metadata>\n";
stream << " <metadata type=\"slic3r.volume_type\">" << ModelVolume::type_to_string(volume->type()) << "</metadata>\n";
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
stream << " <metadata type=\"slic3r.matrix\">";
const Transform3d& matrix = volume->get_matrix();
for (int r = 0; r < 4; ++r)
@ -1137,7 +1118,6 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config)
stream << " <metadata type=\"slic3r.source_offset_y\">" << volume->source.mesh_offset(1) << "</metadata>\n";
stream << " <metadata type=\"slic3r.source_offset_z\">" << volume->source.mesh_offset(2) << "</metadata>\n";
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
const indexed_triangle_set &its = volume->mesh().its;
for (size_t i = 0; i < its.indices.size(); ++i) {
stream << " <triangle>\n";

View file

@ -15,10 +15,8 @@
#include <stack>
#include <vector>
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
#ifdef SLIC3R_DEBUG
#include "SVG.hpp"
@ -1381,7 +1379,6 @@ void Transformation::set_from_transform(const Transform3d& transform)
// std::cout << "something went wrong in extracting data from matrix" << std::endl;
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void Transformation::set_from_string(const std::string& transform_str)
{
Transform3d transform = Transform3d::Identity();
@ -1407,7 +1404,6 @@ void Transformation::set_from_string(const std::string& transform_str)
set_from_transform(transform);
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void Transformation::reset()
{

View file

@ -278,9 +278,7 @@ public:
void set_mirror(Axis axis, double mirror);
void set_from_transform(const Transform3d& transform);
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void set_from_string(const std::string& transform_str);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void reset();

View file

@ -141,14 +141,12 @@ Model Model::read_from_archive(const std::string& input_file, DynamicPrintConfig
for (ModelObject *o : model.objects)
{
#if !ENABLE_ENHANCED_RELOAD_FROM_DISK
if (boost::algorithm::iends_with(input_file, ".zip.amf"))
{
// we remove the .zip part of the extension to avoid it be added to filenames when exporting
o->input_file = boost::ireplace_last_copy(input_file, ".zip.", ".");
}
else
#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK
// if (boost::algorithm::iends_with(input_file, ".zip.amf"))
// {
// // we remove the .zip part of the extension to avoid it be added to filenames when exporting
// o->input_file = boost::ireplace_last_copy(input_file, ".zip.", ".");
// }
// else
o->input_file = input_file;
}
@ -172,11 +170,9 @@ ModelObject* Model::add_object(const char *name, const char *path, const Triangl
new_object->input_file = path;
ModelVolume *new_volume = new_object->add_volume(mesh);
new_volume->name = name;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
new_volume->source.input_file = path;
new_volume->source.object_idx = (int)this->objects.size() - 1;
new_volume->source.volume_idx = (int)new_object->volumes.size() - 1;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
new_object->invalidate_bounding_box();
return new_object;
}
@ -189,11 +185,9 @@ ModelObject* Model::add_object(const char *name, const char *path, TriangleMesh
new_object->input_file = path;
ModelVolume *new_volume = new_object->add_volume(std::move(mesh));
new_volume->name = name;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
new_volume->source.input_file = path;
new_volume->source.object_idx = (int)this->objects.size() - 1;
new_volume->source.volume_idx = (int)new_object->volumes.size() - 1;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
new_object->invalidate_bounding_box();
return new_object;
}
@ -1555,11 +1549,7 @@ bool ModelVolume::is_splittable() const
return m_is_splittable == 1;
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void ModelVolume::center_geometry_after_creation(bool update_source_offset)
#else
void ModelVolume::center_geometry_after_creation()
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
{
Vec3d shift = this->mesh().bounding_box().center();
if (!shift.isApprox(Vec3d::Zero()))
@ -1570,10 +1560,9 @@ void ModelVolume::center_geometry_after_creation()
const_cast<TriangleMesh*>(m_convex_hull.get())->translate(-(float)shift(0), -(float)shift(1), -(float)shift(2));
translate(shift);
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
if (update_source_offset)
source.mesh_offset = shift;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
}
void ModelVolume::calculate_convex_hull()

View file

@ -392,7 +392,6 @@ class ModelVolume final : public ObjectBase
{
public:
std::string name;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
// struct used by reload from disk command to recover data from disk
struct Source
{
@ -404,7 +403,7 @@ public:
template<class Archive> void serialize(Archive& ar) { ar(input_file, object_idx, volume_idx, mesh_offset); }
};
Source source;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
// The triangular model.
const TriangleMesh& mesh() const { return *m_mesh.get(); }
void set_mesh(const TriangleMesh &mesh) { m_mesh = std::make_shared<const TriangleMesh>(mesh); }
@ -453,11 +452,7 @@ public:
// Translates the mesh and the convex hull so that the origin of their vertices is in the center of this volume's bounding box.
// Attention! This method may only be called just after ModelVolume creation! It must not be called once the TriangleMesh of this ModelVolume is shared!
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void center_geometry_after_creation(bool update_source_offset = true);
#else
void center_geometry_after_creation();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void calculate_convex_hull();
const TriangleMesh& get_convex_hull() const;
@ -546,11 +541,7 @@ private:
// Copying an existing volume, therefore this volume will get a copy of the ID assigned.
ModelVolume(ModelObject *object, const ModelVolume &other) :
ObjectBase(other),
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
name(other.name), source(other.source), m_mesh(other.m_mesh), m_convex_hull(other.m_convex_hull), config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation)
#else
name(other.name), m_mesh(other.m_mesh), m_convex_hull(other.m_convex_hull), config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation)
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
{
assert(this->id().valid()); assert(this->config.id().valid()); assert(this->id() != this->config.id());
assert(this->id() == other.id() && this->config.id() == other.config.id());
@ -558,11 +549,7 @@ private:
}
// Providing a new mesh, therefore this volume will get a new unique ID assigned.
ModelVolume(ModelObject *object, const ModelVolume &other, const TriangleMesh &&mesh) :
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
name(other.name), source(other.source), m_mesh(new TriangleMesh(std::move(mesh))), config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation)
#else
name(other.name), m_mesh(new TriangleMesh(std::move(mesh))), config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation)
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
{
assert(this->id().valid()); assert(this->config.id().valid()); assert(this->id() != this->config.id());
assert(this->id() != other.id() && this->config.id() == other.config.id());
@ -583,11 +570,7 @@ private:
}
template<class Archive> void load(Archive &ar) {
bool has_convex_hull;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
ar(name, source, m_mesh, m_type, m_material_id, m_transformation, m_is_splittable, has_convex_hull);
#else
ar(name, m_mesh, m_type, m_material_id, m_transformation, m_is_splittable, has_convex_hull);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
cereal::load_by_value(ar, config);
assert(m_mesh);
if (has_convex_hull) {
@ -600,11 +583,7 @@ private:
}
template<class Archive> void save(Archive &ar) const {
bool has_convex_hull = m_convex_hull.get() != nullptr;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
ar(name, source, m_mesh, m_type, m_material_id, m_transformation, m_is_splittable, has_convex_hull);
#else
ar(name, m_mesh, m_type, m_material_id, m_transformation, m_is_splittable, has_convex_hull);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
cereal::save_by_value(ar, config);
if (has_convex_hull)
cereal::save_optional(ar, m_convex_hull);

View file

@ -32,11 +32,4 @@
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1)
//====================
// 2.2.0.alpha1 techs
//====================
#define ENABLE_2_2_0_ALPHA1 1
#define ENABLE_ENHANCED_RELOAD_FROM_DISK (1 && ENABLE_2_2_0_ALPHA1)
#endif // _technologies_h_

View file

@ -1765,7 +1765,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
std::vector<ModelVolumeState> model_volume_state;
std::vector<ModelVolumeState> aux_volume_state;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
struct GLVolumeState {
GLVolumeState() :
volume_idx(-1) {}
@ -1776,7 +1775,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
// Volume index in the old GLVolume vector.
size_t volume_idx;
};
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
// SLA steps to pull the preview meshes for.
typedef std::array<SLAPrintObjectStep, 2> SLASteps;
@ -1789,9 +1787,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
std::vector<size_t> instance_ids_selected;
std::vector<size_t> map_glvolume_old_to_new(m_volumes.volumes.size(), size_t(-1));
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
std::vector<GLVolumeState> deleted_volumes;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
std::vector<GLVolume*> glvolumes_new;
glvolumes_new.reserve(m_volumes.volumes.size());
auto model_volume_state_lower = [](const ModelVolumeState& m1, const ModelVolumeState& m2) { return m1.geometry_id < m2.geometry_id; };
@ -1872,14 +1868,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
volume_idx_wipe_tower_old = (int)volume_id;
}
if (!m_reload_delayed)
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
{
deleted_volumes.emplace_back(volume, volume_id);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
delete volume;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
}
else {
// This GLVolume will be reused.
@ -1909,7 +1901,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
bool update_object_list = false;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
auto find_old_volume_id = [&deleted_volumes](const GLVolume::CompositeID& id) -> unsigned int {
for (unsigned int i = 0; i < (unsigned int)deleted_volumes.size(); ++i)
{
@ -1919,7 +1910,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
}
return (unsigned int)-1;
};
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
if (m_volumes.volumes != glvolumes_new)
update_object_list = true;
@ -1935,11 +1925,9 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
assert(it != model_volume_state.end() && it->geometry_id == key.geometry_id);
if (it->new_geometry()) {
// New volume.
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
unsigned int old_id = find_old_volume_id(it->composite_id);
if (old_id != -1)
map_glvolume_old_to_new[old_id] = m_volumes.volumes.size();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by, m_initialized);
m_volumes.volumes.back()->geometry_id = key.geometry_id;
update_object_list = true;

View file

@ -1510,13 +1510,11 @@ void ObjectList::append_menu_item_export_stl(wxMenu* menu) const
menu->AppendSeparator();
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void ObjectList::append_menu_item_reload_from_disk(wxMenu* menu) const
{
append_menu_item(menu, wxID_ANY, _(L("Reload from disk")), _(L("Reload the selected volumes from disk")),
[this](wxCommandEvent&) { wxGetApp().plater()->reload_from_disk(); }, "", menu, []() { return wxGetApp().plater()->can_reload_from_disk(); }, wxGetApp().plater());
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void ObjectList::append_menu_item_change_extruder(wxMenu* menu) const
{
@ -1567,9 +1565,7 @@ void ObjectList::create_object_popupmenu(wxMenu *menu)
append_menu_items_osx(menu);
#endif // __WXOSX__
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_reload_from_disk(menu);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_export_stl(menu);
append_menu_item_fix_through_netfabb(menu);
append_menu_item_scale_selection_to_fit_print_volume(menu);
@ -1593,9 +1589,7 @@ void ObjectList::create_sla_object_popupmenu(wxMenu *menu)
append_menu_items_osx(menu);
#endif // __WXOSX__
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_reload_from_disk(menu);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_export_stl(menu);
append_menu_item_fix_through_netfabb(menu);
// rest of a object_sla_menu will be added later in:
@ -1608,15 +1602,9 @@ void ObjectList::create_part_popupmenu(wxMenu *menu)
append_menu_items_osx(menu);
#endif // __WXOSX__
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_reload_from_disk(menu);
#else
append_menu_item_fix_through_netfabb(menu);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_export_stl(menu);
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_fix_through_netfabb(menu);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item_split(menu);

View file

@ -234,9 +234,7 @@ public:
void append_menu_items_osx(wxMenu* menu);
wxMenuItem* append_menu_item_fix_through_netfabb(wxMenu* menu);
void append_menu_item_export_stl(wxMenu* menu) const;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void append_menu_item_reload_from_disk(wxMenu* menu) const;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void append_menu_item_change_extruder(wxMenu* menu) const;
void append_menu_item_delete(wxMenu* menu);
void append_menu_item_scale_selection_to_fit_print_volume(wxMenu* menu);

View file

@ -10,9 +10,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <boost/filesystem/path.hpp>
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
#include <boost/filesystem/operations.hpp>
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
#include <boost/log/trivial.hpp>
#include <wx/sizer.h>
@ -1910,9 +1908,7 @@ struct Plater::priv
bool can_fix_through_netfabb() const;
bool can_set_instance_to_object() const;
bool can_mirror() const;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
bool can_reload_from_disk() const;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void msw_rescale_object_menu();
@ -1949,9 +1945,6 @@ private:
* */
std::string m_last_fff_printer_profile_name;
std::string m_last_sla_printer_profile_name;
#if !ENABLE_ENHANCED_RELOAD_FROM_DISK
bool m_update_objects_list_on_loading{ true };
#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK
};
const std::regex Plater::priv::pattern_bundle(".*[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)", std::regex::icase);
@ -2477,16 +2470,9 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
_(L("Object too large?")));
}
#if !ENABLE_ENHANCED_RELOAD_FROM_DISK
if (m_update_objects_list_on_loading)
{
#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK
for (const size_t idx : obj_idxs) {
wxGetApp().obj_list()->add_object_to_list(idx);
}
#if !ENABLE_ENHANCED_RELOAD_FROM_DISK
for (const size_t idx : obj_idxs) {
wxGetApp().obj_list()->add_object_to_list(idx);
}
#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK
update();
object_list_changed();
@ -3110,7 +3096,6 @@ void Plater::priv::update_sla_scene()
void Plater::priv::reload_from_disk()
{
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
Plater::TakeSnapshot snapshot(q, _(L("Reload from disk")));
const Selection& selection = get_selection();
@ -3215,91 +3200,6 @@ void Plater::priv::reload_from_disk()
{
view3D->get_canvas3d()->update_instance_printable_state_for_object(i);
}
#else
Plater::TakeSnapshot snapshot(q, _(L("Reload from Disk")));
auto& selection = get_selection();
const auto obj_orig_idx = selection.get_object_idx();
if (selection.is_wipe_tower() || obj_orig_idx == -1) { return; }
int instance_idx = selection.get_instance_idx();
auto *object_orig = model.objects[obj_orig_idx];
std::vector<fs::path> input_paths(1, object_orig->input_file);
// disable render to avoid to show intermediate states
view3D->get_canvas3d()->enable_render(false);
// disable update of objects list while loading to avoid to show intermediate states
m_update_objects_list_on_loading = false;
const auto new_idxs = load_files(input_paths, true, false);
if (new_idxs.empty())
{
// error while loading
view3D->get_canvas3d()->enable_render(true);
m_update_objects_list_on_loading = true;
return;
}
for (const auto idx : new_idxs)
{
ModelObject *object = model.objects[idx];
object->config.apply(object_orig->config);
object->clear_instances();
for (const ModelInstance *instance : object_orig->instances)
{
object->add_instance(*instance);
}
for (const ModelVolume* v : object_orig->volumes)
{
if (v->is_modifier())
object->add_volume(*v);
}
Vec3d offset = object_orig->origin_translation - object->origin_translation;
if (object->volumes.size() == object_orig->volumes.size())
{
for (size_t i = 0; i < object->volumes.size(); i++)
{
object->volumes[i]->config.apply(object_orig->volumes[i]->config);
object->volumes[i]->translate(offset);
}
}
// XXX: Restore more: layer_height_ranges, layer_height_profile (?)
}
// re-enable update of objects list
m_update_objects_list_on_loading = true;
// puts the new objects into the list
for (const auto idx : new_idxs)
{
wxGetApp().obj_list()->add_object_to_list(idx);
}
remove(obj_orig_idx);
// new GLVolumes have been created at this point, so update their printable state
for (size_t i = 0; i < model.objects.size(); ++i)
{
view3D->get_canvas3d()->update_instance_printable_state_for_object(i);
}
// re-enable render
view3D->get_canvas3d()->enable_render(true);
// the previous call to remove() clears the selection
// select newly added objects
selection.clear();
for (const auto idx : new_idxs)
{
selection.add_instance((unsigned int)idx - 1, instance_idx, false);
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
}
void Plater::priv::fix_through_netfabb(const int obj_idx, const int vol_idx/* = -1*/)
@ -3724,10 +3624,8 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/
append_menu_item(menu, wxID_ANY, _(L("Delete")) + "\tDel", _(L("Remove the selected object")),
[this](wxCommandEvent&) { q->remove_selected(); }, "delete", nullptr, [this]() { return can_delete(); }, q);
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item(menu, wxID_ANY, _(L("Reload from disk")), _(L("Reload the selected volumes from disk")),
[this](wxCommandEvent&) { q->reload_from_disk(); }, "", menu, [this]() { return can_reload_from_disk(); }, q);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
sidebar->obj_list()->append_menu_item_export_stl(menu);
}
@ -3755,13 +3653,8 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/
wxMenuItem* menu_item_printable = sidebar->obj_list()->append_menu_item_printable(menu, q);
menu->AppendSeparator();
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item(menu, wxID_ANY, _(L("Reload from disk")), _(L("Reload the selected object from disk")),
[this](wxCommandEvent&) { reload_from_disk(); }, "", nullptr, [this]() { return can_reload_from_disk(); }, q);
#else
append_menu_item(menu, wxID_ANY, _(L("Reload from Disk")), _(L("Reload the selected file from Disk")),
[this](wxCommandEvent&) { reload_from_disk(); });
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
append_menu_item(menu, wxID_ANY, _(L("Export as STL")) + dots, _(L("Export the selected object as STL file")),
[this](wxCommandEvent&) { q->export_stl(false, true); });
@ -3916,7 +3809,6 @@ bool Plater::priv::can_mirror() const
return get_selection().is_from_single_instance();
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
bool Plater::priv::can_reload_from_disk() const
{
// struct to hold selected ModelVolumes by their indices
@ -3958,7 +3850,6 @@ bool Plater::priv::can_reload_from_disk() const
return !paths.empty();
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void Plater::priv::set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model)
{
@ -4743,12 +4634,10 @@ void Plater::export_3mf(const boost::filesystem::path& output_path)
}
}
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void Plater::reload_from_disk()
{
p->reload_from_disk();
}
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
bool Plater::has_toolpaths_to_export() const
{
@ -5247,9 +5136,7 @@ bool Plater::can_copy_to_clipboard() const
bool Plater::can_undo() const { return p->undo_redo_stack().has_undo_snapshot(); }
bool Plater::can_redo() const { return p->undo_redo_stack().has_redo_snapshot(); }
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
bool Plater::can_reload_from_disk() const { return p->can_reload_from_disk(); }
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
const UndoRedo::Stack& Plater::undo_redo_stack_main() const { return p->undo_redo_stack_main(); }
void Plater::enter_gizmos_stack() { p->enter_gizmos_stack(); }
void Plater::leave_gizmos_stack() { p->leave_gizmos_stack(); }

View file

@ -183,9 +183,7 @@ public:
void export_stl(bool extended = false, bool selection_only = false);
void export_amf();
void export_3mf(const boost::filesystem::path& output_path = boost::filesystem::path());
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
void reload_from_disk();
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
bool has_toolpaths_to_export() const;
void export_toolpaths_to_obj() const;
void reslice();
@ -250,9 +248,7 @@ public:
bool can_copy_to_clipboard() const;
bool can_undo() const;
bool can_redo() const;
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
bool can_reload_from_disk() const;
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
void msw_rescale();

View file

@ -472,11 +472,7 @@ void Selection::volumes_changed(const std::vector<size_t> &map_volume_old_to_new
for (unsigned int idx : m_list)
if (map_volume_old_to_new[idx] != size_t(-1)) {
unsigned int new_idx = (unsigned int)map_volume_old_to_new[idx];
#if ENABLE_ENHANCED_RELOAD_FROM_DISK
(*m_volumes)[new_idx]->selected = true;
#else
assert((*m_volumes)[new_idx]->selected);
#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
list_new.insert(new_idx);
}
m_list = std::move(list_new);