From 3a40565d03608c2440e772d58121ef16fc84744e Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Thu, 19 Sep 2019 09:09:11 +0200 Subject: [PATCH 1/6] Added tech ENABLE_ENHANCED_RELOAD_FROM_DISK 1) Reworked void Plater::priv::reload_from_disk() to be more general 2) Added source data to class ModelVolume 3) Modified .3mf import/export to save/load volume matrices and source data 4) Incremented .3mf version to 2 --- src/libslic3r/Format/3mf.cpp | 130 ++++++++++++++++++++- src/libslic3r/Model.cpp | 15 +++ src/libslic3r/Model.hpp | 37 +++++- src/libslic3r/Technologies.hpp | 7 ++ src/slic3r/GUI/GLCanvas3D.cpp | 148 +++++++++++++++--------- src/slic3r/GUI/GUI_ObjectList.cpp | 21 ++++ src/slic3r/GUI/GUI_ObjectList.hpp | 5 +- src/slic3r/GUI/Plater.cpp | 183 ++++++++++++++++++++++++++++++ src/slic3r/GUI/Plater.hpp | 6 + src/slic3r/GUI/Selection.cpp | 4 + 10 files changed, 496 insertions(+), 60 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 0f89e6193..fbec5b00b 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -31,7 +31,12 @@ 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 and volumes matrices 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/"; @@ -87,6 +92,15 @@ 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"; +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[] = @@ -148,11 +162,25 @@ 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); @@ -160,9 +188,13 @@ 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 @@ -176,6 +208,35 @@ Slic3r::Transform3d get_transform_from_string(const std::string& mat_str) return ret; } +#if ENABLE_ENHANCED_RELOAD_FROM_DISK +Slic3r::Transform3d get_transform_from_string(const std::string& mat_str) +{ + Slic3r::Transform3d ret = Slic3r::Transform3d::Identity(); + + if (mat_str.empty()) + // empty string means default identity matrix + return ret; + + std::vector<std::string> mat_elements_str; + boost::split(mat_elements_str, mat_str, boost::is_any_of(" "), boost::token_compress_on); + + unsigned int size = (unsigned int)mat_elements_str.size(); + if (size != 16) + // invalid data, return identity matrix + return ret; + + unsigned int i = 0; + for (unsigned int r = 0; r < 4; ++r) + { + for (unsigned int c = 0; c < 4; ++c) + { + ret(r, c) = ::atof(mat_elements_str[i++].c_str()); + } + } + return ret; +} +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK + float get_unit_factor(const std::string& unit) { const char* text = unit.c_str(); @@ -1375,7 +1436,11 @@ 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()) @@ -1421,7 +1486,11 @@ 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); @@ -1659,7 +1728,9 @@ namespace Slic3r { triangle_mesh.repair(); ModelVolume* volume = object.add_volume(std::move(triangle_mesh)); +#if !ENABLE_ENHANCED_RELOAD_FROM_DISK volume->center_geometry_after_creation(); +#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK volume->calculate_convex_hull(); // apply volume's name and config data @@ -1671,6 +1742,22 @@ 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 == MATRIX_KEY) + volume->set_transformation(Slic3r::Geometry::Transformation(get_transform_from_string(metadata.value))); + else if (metadata.key == SOURCE_FILE_KEY) + volume->source.input_file = metadata.value; + else if (metadata.key == SOURCE_OBJECT_ID_KEY) + volume->source.object_idx = ::atoi(metadata.value.c_str()); + else if (metadata.key == SOURCE_VOLUME_ID_KEY) + volume->source.volume_idx = ::atoi(metadata.value.c_str()); + else if (metadata.key == SOURCE_OFFSET_X_KEY) + volume->source.mesh_offset(0) = ::atof(metadata.value.c_str()); + else if (metadata.key == SOURCE_OFFSET_Y_KEY) + 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); } @@ -2056,8 +2143,19 @@ namespace Slic3r { vertices_count += (int)its.vertices.size(); +#if !ENABLE_ENHANCED_RELOAD_FROM_DISK const Transform3d& matrix = volume->get_matrix(); +#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + for (const Vec3f& v : its.vertices) + { + stream << " <" << VERTEX_TAG << " "; + stream << "x=\"" << v(0) << "\" "; + stream << "y=\"" << v(1) << "\" "; + stream << "z=\"" << v(2) << "\" />\n"; + } +#else for (size_t i = 0; i < its.vertices.size(); ++i) { stream << " <" << VERTEX_TAG << " "; @@ -2066,6 +2164,7 @@ namespace Slic3r { stream << "y=\"" << v(1) << "\" "; stream << "z=\"" << v(2) << "\" />\n"; } +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK } stream << " </" << VERTICES_TAG << ">\n"; @@ -2116,7 +2215,7 @@ namespace Slic3r { for (const BuildItem& item : build_items) { - stream << " <" << ITEM_TAG << " objectid=\"" << item.id << "\" transform =\""; + stream << " <" << ITEM_TAG << " " << OBJECTID_ATTR << "=\"" << item.id << "\" " << TRANSFORM_ATTR << "=\""; for (unsigned c = 0; c < 4; ++c) { for (unsigned r = 0; r < 3; ++r) @@ -2126,7 +2225,7 @@ namespace Slic3r { stream << " "; } } - stream << "\" printable =\"" << item.printable << "\" />\n"; + stream << "\" " << PRINTABLE_ATTR << "=\"" << item.printable << "\" />\n"; } stream << " </" << BUILD_TAG << ">\n"; @@ -2344,6 +2443,33 @@ 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(); + for (int r = 0; r < 4; ++r) + { + for (int c = 0; c < 4; ++c) + { + stream << matrix(r, c); + if ((r != 3) || (c != 3)) + stream << " "; + } + } + stream << "\"/>\n"; + + // stores volume's source data + if (!volume->source.input_file.empty()) + { + stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << SOURCE_FILE_KEY << "\" " << VALUE_ATTR << "=\"" << xml_escape(volume->source.input_file) << "\"/>\n"; + stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << SOURCE_OBJECT_ID_KEY << "\" " << VALUE_ATTR << "=\"" << volume->source.object_idx << "\"/>\n"; + stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << SOURCE_VOLUME_ID_KEY << "\" " << VALUE_ATTR << "=\"" << volume->source.volume_idx << "\"/>\n"; + stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << SOURCE_OFFSET_X_KEY << "\" " << VALUE_ATTR << "=\"" << volume->source.mesh_offset(0) << "\"/>\n"; + 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()) { diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 7526dd16a..d36f5b7ac 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -141,12 +141,14 @@ 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 o->input_file = input_file; } @@ -170,6 +172,11 @@ 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; } @@ -182,6 +189,11 @@ 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; } @@ -1554,6 +1566,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); } +//================================================================================================================================================================================================ + source.mesh_offset = shift; +//================================================================================================================================================================================================ } void ModelVolume::calculate_convex_hull() diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 19f032b1c..c91f72a95 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -392,6 +392,19 @@ 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 + { + std::string input_file; + int object_idx{ -1 }; + int volume_idx{ -1 }; + Vec3d mesh_offset{ Vec3d::Zero() }; + + 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); } @@ -529,7 +542,11 @@ 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()); @@ -537,7 +554,11 @@ 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()); @@ -558,8 +579,12 @@ private: } template<class Archive> void load(Archive &ar) { bool has_convex_hull; - ar(name, m_mesh, m_type, m_material_id, m_transformation, m_is_splittable, has_convex_hull); - cereal::load_by_value(ar, config); +#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) { cereal::load_optional(ar, m_convex_hull); @@ -571,8 +596,12 @@ private: } template<class Archive> void save(Archive &ar) const { bool has_convex_hull = m_convex_hull.get() != nullptr; - ar(name, m_mesh, m_type, m_material_id, m_transformation, m_is_splittable, has_convex_hull); - cereal::save_by_value(ar, config); +#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); } diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 51d092094..60ae17a82 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -32,4 +32,11 @@ #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_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index edb9c7830..60f76db3d 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1747,101 +1747,118 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re _set_current(); struct ModelVolumeState { - ModelVolumeState(const GLVolume *volume) : - model_volume(nullptr), geometry_id(volume->geometry_id), volume_idx(-1) {} - ModelVolumeState(const ModelVolume *model_volume, const ObjectID &instance_id, const GLVolume::CompositeID &composite_id) : - model_volume(model_volume), geometry_id(std::make_pair(model_volume->id().id, instance_id.id)), composite_id(composite_id), volume_idx(-1) {} - ModelVolumeState(const ObjectID &volume_id, const ObjectID &instance_id) : - model_volume(nullptr), geometry_id(std::make_pair(volume_id.id, instance_id.id)), volume_idx(-1) {} - bool new_geometry() const { return this->volume_idx == size_t(-1); } - const ModelVolume *model_volume; + ModelVolumeState(const GLVolume* volume) : + model_volume(nullptr), geometry_id(volume->geometry_id), volume_idx(-1) {} + ModelVolumeState(const ModelVolume* model_volume, const ObjectID& instance_id, const GLVolume::CompositeID& composite_id) : + model_volume(model_volume), geometry_id(std::make_pair(model_volume->id().id, instance_id.id)), composite_id(composite_id), volume_idx(-1) {} + ModelVolumeState(const ObjectID& volume_id, const ObjectID& instance_id) : + model_volume(nullptr), geometry_id(std::make_pair(volume_id.id, instance_id.id)), volume_idx(-1) {} + bool new_geometry() const { return this->volume_idx == size_t(-1); } + const ModelVolume* model_volume; // ObjectID of ModelVolume + ObjectID of ModelInstance // or timestamp of an SLAPrintObjectStep + ObjectID of ModelInstance std::pair<size_t, size_t> geometry_id; GLVolume::CompositeID composite_id; // Volume index in the new GLVolume vector. - size_t volume_idx; + size_t volume_idx; }; std::vector<ModelVolumeState> model_volume_state; - std::vector<ModelVolumeState> aux_volume_state; + std::vector<ModelVolumeState> aux_volume_state; + +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + struct GLVolumeState { + GLVolumeState() : + volume_idx(-1) {} + GLVolumeState(const GLVolume* volume, unsigned int volume_idx) : + composite_id(volume->composite_id), volume_idx(volume_idx) {} + + GLVolume::CompositeID composite_id; + // 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; - SLASteps sla_steps = { slaposSupportTree, slaposBasePool }; + typedef std::array<SLAPrintObjectStep, 2> SLASteps; + SLASteps sla_steps = { slaposSupportTree, slaposBasePool }; struct SLASupportState { - std::array<PrintStateBase::StateWithTimeStamp, std::tuple_size<SLASteps>::value> step; + std::array<PrintStateBase::StateWithTimeStamp, std::tuple_size<SLASteps>::value> step; }; // State of the sla_steps for all SLAPrintObjects. std::vector<SLASupportState> sla_support_state; 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; }; + auto model_volume_state_lower = [](const ModelVolumeState& m1, const ModelVolumeState& m2) { return m1.geometry_id < m2.geometry_id; }; - m_reload_delayed = ! m_canvas->IsShown() && ! refresh_immediately && ! force_full_scene_refresh; + m_reload_delayed = !m_canvas->IsShown() && !refresh_immediately && !force_full_scene_refresh; - PrinterTechnology printer_technology = m_process->current_printer_technology(); + PrinterTechnology printer_technology = m_process->current_printer_technology(); int volume_idx_wipe_tower_old = -1; // Release invalidated volumes to conserve GPU memory in case of delayed refresh (see m_reload_delayed). // First initialize model_volumes_new_sorted & model_instances_new_sorted. - for (int object_idx = 0; object_idx < (int)m_model->objects.size(); ++ object_idx) { - const ModelObject *model_object = m_model->objects[object_idx]; - for (int instance_idx = 0; instance_idx < (int)model_object->instances.size(); ++ instance_idx) { - const ModelInstance *model_instance = model_object->instances[instance_idx]; - for (int volume_idx = 0; volume_idx < (int)model_object->volumes.size(); ++ volume_idx) { - const ModelVolume *model_volume = model_object->volumes[volume_idx]; - model_volume_state.emplace_back(model_volume, model_instance->id(), GLVolume::CompositeID(object_idx, volume_idx, instance_idx)); + for (int object_idx = 0; object_idx < (int)m_model->objects.size(); ++object_idx) { + const ModelObject* model_object = m_model->objects[object_idx]; + for (int instance_idx = 0; instance_idx < (int)model_object->instances.size(); ++instance_idx) { + const ModelInstance* model_instance = model_object->instances[instance_idx]; + for (int volume_idx = 0; volume_idx < (int)model_object->volumes.size(); ++volume_idx) { + const ModelVolume* model_volume = model_object->volumes[volume_idx]; + model_volume_state.emplace_back(model_volume, model_instance->id(), GLVolume::CompositeID(object_idx, volume_idx, instance_idx)); } } } if (printer_technology == ptSLA) { - const SLAPrint *sla_print = this->sla_print(); - #ifndef NDEBUG + const SLAPrint* sla_print = this->sla_print(); +#ifndef NDEBUG // Verify that the SLAPrint object is synchronized with m_model. check_model_ids_equal(*m_model, sla_print->model()); - #endif /* NDEBUG */ +#endif /* NDEBUG */ sla_support_state.reserve(sla_print->objects().size()); - for (const SLAPrintObject *print_object : sla_print->objects()) { + for (const SLAPrintObject* print_object : sla_print->objects()) { SLASupportState state; - for (size_t istep = 0; istep < sla_steps.size(); ++ istep) { - state.step[istep] = print_object->step_state_with_timestamp(sla_steps[istep]); - if (state.step[istep].state == PrintStateBase::DONE) { - if (! print_object->has_mesh(sla_steps[istep])) + for (size_t istep = 0; istep < sla_steps.size(); ++istep) { + state.step[istep] = print_object->step_state_with_timestamp(sla_steps[istep]); + if (state.step[istep].state == PrintStateBase::DONE) { + if (!print_object->has_mesh(sla_steps[istep])) // Consider the DONE step without a valid mesh as invalid for the purpose // of mesh visualization. state.step[istep].state = PrintStateBase::INVALID; else - for (const ModelInstance *model_instance : print_object->model_object()->instances) - // Only the instances, which are currently printable, will have the SLA support structures kept. - // The instances outside the print bed will have the GLVolumes of their support structures released. - if (model_instance->is_printable()) + for (const ModelInstance* model_instance : print_object->model_object()->instances) + // Only the instances, which are currently printable, will have the SLA support structures kept. + // The instances outside the print bed will have the GLVolumes of their support structures released. + if (model_instance->is_printable()) aux_volume_state.emplace_back(state.step[istep].timestamp, model_instance->id()); } - } - sla_support_state.emplace_back(state); + } + sla_support_state.emplace_back(state); } } std::sort(model_volume_state.begin(), model_volume_state.end(), model_volume_state_lower); - std::sort(aux_volume_state .begin(), aux_volume_state .end(), model_volume_state_lower); + std::sort(aux_volume_state.begin(), aux_volume_state.end(), model_volume_state_lower); // Release all ModelVolume based GLVolumes not found in the current Model. - for (size_t volume_id = 0; volume_id < m_volumes.volumes.size(); ++ volume_id) { - GLVolume *volume = m_volumes.volumes[volume_id]; + for (size_t volume_id = 0; volume_id < m_volumes.volumes.size(); ++volume_id) { + GLVolume* volume = m_volumes.volumes[volume_id]; ModelVolumeState key(volume); - ModelVolumeState *mvs = nullptr; + ModelVolumeState* mvs = nullptr; if (volume->volume_idx() < 0) { - auto it = std::lower_bound(aux_volume_state.begin(), aux_volume_state.end(), key, model_volume_state_lower); + auto it = std::lower_bound(aux_volume_state.begin(), aux_volume_state.end(), key, model_volume_state_lower); if (it != aux_volume_state.end() && it->geometry_id == key.geometry_id) // This can be an SLA support structure that should not be rendered (in case someone used undo // to revert to before it was generated). We only reuse the volume if that's not the case. if (m_model->objects[volume->composite_id.object_id]->sla_points_status != sla::PointsStatus::NoPoints) mvs = &(*it); - } else { - auto it = std::lower_bound(model_volume_state.begin(), model_volume_state.end(), key, model_volume_state_lower); + } + else { + auto it = std::lower_bound(model_volume_state.begin(), model_volume_state.end(), key, model_volume_state_lower); if (it != model_volume_state.end() && it->geometry_id == key.geometry_id) - mvs = &(*it); + mvs = &(*it); } // Emplace instance ID of the volume. Both the aux volumes and model volumes share the same instance ID. // The wipe tower has its own wipe_tower_instance_id(). @@ -1854,19 +1871,27 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re assert(volume_idx_wipe_tower_old == -1); volume_idx_wipe_tower_old = (int)volume_id; } - if (! m_reload_delayed) + 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; - } else { +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + } +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK + } + else { // This GLVolume will be reused. volume->set_sla_shift_z(0.0); map_glvolume_old_to_new[volume_id] = glvolumes_new.size(); mvs->volume_idx = glvolumes_new.size(); glvolumes_new.emplace_back(volume); // Update color of the volume based on the current extruder. - if (mvs->model_volume != nullptr) { - int extruder_id = mvs->model_volume->extruder_id(); - if (extruder_id != -1) - volume->extruder_id = extruder_id; + if (mvs->model_volume != nullptr) { + int extruder_id = mvs->model_volume->extruder_id(); + if (extruder_id != -1) + volume->extruder_id = extruder_id; volume->is_modifier = !mvs->model_volume->is_model_part(); volume->set_color_from_model_volume(mvs->model_volume); @@ -1882,7 +1907,19 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re if (m_reload_delayed) return; - bool update_object_list = false; + 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) + { + const GLVolumeState& v = deleted_volumes[i]; + if (v.composite_id == id) + return v.volume_idx; + } + return (unsigned int)-1; + }; +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK if (m_volumes.volumes != glvolumes_new) update_object_list = true; @@ -1898,9 +1935,14 @@ 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; + update_object_list = true; } else { // Recycling an old GLVolume. GLVolume &existing_volume = *m_volumes.volumes[it->volume_idx]; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 49f0f6fa2..2ccdfbc42 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1466,6 +1466,14 @@ 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 { const wxString name = _(L("Change extruder")); @@ -1515,6 +1523,9 @@ 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); @@ -1538,6 +1549,9 @@ 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: @@ -1550,8 +1564,15 @@ 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); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 13d1106fc..87e2e5aa0 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -232,7 +232,10 @@ public: wxMenuItem* append_menu_item_printable(wxMenu* menu, wxWindow* parent); 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 ; + 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); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0dc7519e8..32ee6d57a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -10,6 +10,9 @@ #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> @@ -1905,6 +1908,9 @@ 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(); @@ -1941,7 +1947,9 @@ 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); @@ -2467,12 +2475,16 @@ 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 } +#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK update(); object_list_changed(); @@ -3092,6 +3104,111 @@ 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(); + + if (selection.is_wipe_tower()) + return; + + // struct to hold selected ModelVolumes by their indices + struct SelectedVolume + { + int object_idx; + int volume_idx; + + // operators needed by std::algorithms + bool operator < (const SelectedVolume& other) const { return (object_idx < other.object_idx) || ((object_idx == other.object_idx) && (volume_idx < other.volume_idx)); } + bool operator == (const SelectedVolume& other) const { return (object_idx == other.object_idx) && (volume_idx == other.volume_idx); } + }; + std::vector<SelectedVolume> selected_volumes; + + // collects selected ModelVolumes + const std::set<unsigned int>& selected_volumes_idxs = selection.get_volume_idxs(); + for (unsigned int idx : selected_volumes_idxs) + { + const GLVolume* v = selection.get_volume(idx); + int o_idx = v->object_idx(); + int v_idx = v->volume_idx(); + selected_volumes.push_back({ o_idx, v_idx }); + } + std::sort(selected_volumes.begin(), selected_volumes.end()); + selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end()), selected_volumes.end()); + + // collects paths of files to load + std::vector<fs::path> input_paths; + for (const SelectedVolume& v : selected_volumes) + { + const ModelVolume* volume = model.objects[v.object_idx]->volumes[v.volume_idx]; + if (!volume->source.input_file.empty() && boost::filesystem::exists(volume->source.input_file)) + input_paths.push_back(volume->source.input_file); + } + std::sort(input_paths.begin(), input_paths.end()); + input_paths.erase(std::unique(input_paths.begin(), input_paths.end()), input_paths.end()); + + // load one file at a time + for (size_t i = 0; i < input_paths.size(); ++i) + { + const auto& path = input_paths[i].string(); + Model new_model; + try + { + new_model = Model::read_from_file(path, nullptr, true, false); + for (ModelObject* model_object : new_model.objects) + { + model_object->center_around_origin(); + model_object->ensure_on_bed(); + } + } + catch (std::exception&) + { + // error while loading + view3D->get_canvas3d()->enable_render(true); + return; + } + + // update the selected volumes whose source is the current file + for (const SelectedVolume& old_v : selected_volumes) + { + ModelObject* old_model_object = model.objects[old_v.object_idx]; + ModelVolume* old_volume = old_model_object->volumes[old_v.volume_idx]; + int new_volume_idx = old_volume->source.volume_idx; + int new_object_idx = old_volume->source.object_idx; + + if (old_volume->source.input_file == path) + { + if (new_object_idx < (int)new_model.objects.size()) + { + ModelObject* new_model_object = new_model.objects[new_object_idx]; + if (new_volume_idx < (int)new_model_object->volumes.size()) + { + old_model_object->add_volume(*new_model_object->volumes[new_volume_idx]); + ModelVolume* new_volume = old_model_object->volumes.back(); + new_volume->set_new_unique_id(); + new_volume->config.apply(old_volume->config); + new_volume->set_type(old_volume->type()); + new_volume->set_transformation(old_volume->get_transformation()); + new_volume->translate(new_volume->get_transformation().get_matrix(true) * (new_volume->source.mesh_offset - old_volume->source.mesh_offset)); + std::swap(old_model_object->volumes[old_v.volume_idx], old_model_object->volumes.back()); + old_model_object->delete_volume(old_model_object->volumes.size() - 1); + } + } + } + } + } + + model.adjust_min_z(); + + // update 3D scene + update(); + + // 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); + } +#else Plater::TakeSnapshot snapshot(q, _(L("Reload from Disk"))); auto& selection = get_selection(); @@ -3113,6 +3230,7 @@ void Plater::priv::reload_from_disk() { // error while loading view3D->get_canvas3d()->enable_render(true); + m_update_objects_list_on_loading = true; return; } @@ -3174,6 +3292,7 @@ void Plater::priv::reload_from_disk() { 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*/) @@ -3587,6 +3706,11 @@ 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); } else { @@ -3613,8 +3737,13 @@ 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); }); @@ -3769,6 +3898,50 @@ 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 + struct SelectedVolume + { + int object_idx; + int volume_idx; + + // operators needed by std::algorithms + bool operator < (const SelectedVolume& other) const { return (object_idx < other.object_idx) || ((object_idx == other.object_idx) && (volume_idx < other.volume_idx)); } + bool operator == (const SelectedVolume& other) const { return (object_idx == other.object_idx) && (volume_idx == other.volume_idx); } + }; + std::vector<SelectedVolume> selected_volumes; + + const Selection& selection = get_selection(); + + // collects selected ModelVolumes + const std::set<unsigned int>& selected_volumes_idxs = selection.get_volume_idxs(); + for (unsigned int idx : selected_volumes_idxs) + { + const GLVolume* v = selection.get_volume(idx); + int o_idx = v->object_idx(); + int v_idx = v->volume_idx(); + selected_volumes.push_back({ o_idx, v_idx }); + } + std::sort(selected_volumes.begin(), selected_volumes.end()); + selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end()), selected_volumes.end()); + + // collects paths of files to load + std::vector<fs::path> paths; + for (const SelectedVolume& v : selected_volumes) + { + const ModelVolume* volume = model.objects[v.object_idx]->volumes[v.volume_idx]; + if (!volume->source.input_file.empty() && boost::filesystem::exists(volume->source.input_file)) + paths.push_back(volume->source.input_file); + } + std::sort(paths.begin(), paths.end()); + paths.erase(std::unique(paths.begin(), paths.end()), paths.end()); + + 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) { bool new_shape = bed.set_shape(shape, custom_texture, custom_model); @@ -4552,6 +4725,13 @@ 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 { return p->preview->get_canvas3d()->has_toolpaths_to_export(); @@ -5044,6 +5224,9 @@ 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(); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 0dc298566..f23259e47 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -183,6 +183,9 @@ 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(); @@ -246,6 +249,9 @@ 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(); diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 40fbbbac6..346f46e00 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -472,7 +472,11 @@ 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); From 74747226f70a77736866ce7c256a7b655d626efe Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Thu, 19 Sep 2019 12:39:59 +0200 Subject: [PATCH 2/6] ENABLE_ENHANCED_RELOAD_FROM_DISK 1) Modified .zip.amf import/export to save/load volume matrices and source data 2) Incremented .zip.amf version to 3 --- src/libslic3r/Format/3mf.cpp | 37 +++--------------- src/libslic3r/Format/AMF.cpp | 76 +++++++++++++++++++++++++++++++++++- src/libslic3r/Geometry.cpp | 33 ++++++++++++++++ src/libslic3r/Geometry.hpp | 3 ++ src/libslic3r/Model.cpp | 11 ++++-- src/libslic3r/Model.hpp | 4 ++ src/slic3r/GUI/Plater.cpp | 1 + 7 files changed, 130 insertions(+), 35 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index fbec5b00b..494da5fe6 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -32,7 +32,7 @@ namespace pt = boost::property_tree; // 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 and volumes matrices added to Metadata/Slic3r_PE_model.config file. +// 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; @@ -208,35 +208,6 @@ Slic3r::Transform3d get_transform_from_string(const std::string& mat_str) return ret; } -#if ENABLE_ENHANCED_RELOAD_FROM_DISK -Slic3r::Transform3d get_transform_from_string(const std::string& mat_str) -{ - Slic3r::Transform3d ret = Slic3r::Transform3d::Identity(); - - if (mat_str.empty()) - // empty string means default identity matrix - return ret; - - std::vector<std::string> mat_elements_str; - boost::split(mat_elements_str, mat_str, boost::is_any_of(" "), boost::token_compress_on); - - unsigned int size = (unsigned int)mat_elements_str.size(); - if (size != 16) - // invalid data, return identity matrix - return ret; - - unsigned int i = 0; - for (unsigned int r = 0; r < 4; ++r) - { - for (unsigned int c = 0; c < 4; ++c) - { - ret(r, c) = ::atof(mat_elements_str[i++].c_str()); - } - } - return ret; -} -#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK - float get_unit_factor(const std::string& unit) { const char* text = unit.c_str(); @@ -1744,7 +1715,11 @@ namespace Slic3r { volume->set_type(ModelVolume::type_from_string(metadata.value)); #if ENABLE_ENHANCED_RELOAD_FROM_DISK else if (metadata.key == MATRIX_KEY) - volume->set_transformation(Slic3r::Geometry::Transformation(get_transform_from_string(metadata.value))); + { + Slic3r::Geometry::Transformation transform; + transform.set_from_string(metadata.value); + volume->set_transformation(transform); + } else if (metadata.key == SOURCE_FILE_KEY) volume->source.input_file = metadata.value; else if (metadata.key == SOURCE_OBJECT_ID_KEY) diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 92c958d8a..3f85b4b60 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -12,6 +12,9 @@ #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" @@ -36,7 +39,12 @@ // 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"; @@ -568,7 +576,12 @@ void AMFParserContext::endElement(const char * /* name */) 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; @@ -664,6 +677,31 @@ 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]); + m_volume->set_transformation(transform); + } + else if (strcmp(opt_key, "source_file") == 0) { + m_volume->source.input_file = m_value[1]; + } + else if (strcmp(opt_key, "source_object_id") == 0) { + m_volume->source.object_idx = ::atoi(m_value[1].c_str()); + } + else if (strcmp(opt_key, "source_volume_id") == 0) { + m_volume->source.volume_idx = ::atoi(m_value[1].c_str()); + } + else if (strcmp(opt_key, "source_offset_x") == 0) { + m_volume->source.mesh_offset(0) = ::atof(m_value[1].c_str()); + } + else if (strcmp(opt_key, "source_offset_y") == 0) { + m_volume->source.mesh_offset(1) = ::atof(m_value[1].c_str()); + } + 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) { @@ -1029,6 +1067,18 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) if (! volume->mesh().has_shared_vertices()) throw std::runtime_error("store_amf() requires shared vertices"); const indexed_triangle_set &its = volume->mesh().its; +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + for (const Vec3f& v : its.vertices) + { + stream << " <vertex>\n"; + stream << " <coordinates>\n"; + stream << " <x>" << v(0) << "</x>\n"; + stream << " <y>" << v(1) << "</y>\n"; + stream << " <z>" << v(2) << "</z>\n"; + stream << " </coordinates>\n"; + stream << " </vertex>\n"; + } +#else const Transform3d& matrix = volume->get_matrix(); for (size_t i = 0; i < its.vertices.size(); ++i) { stream << " <vertex>\n"; @@ -1040,6 +1090,7 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) stream << " </coordinates>\n"; stream << " </vertex>\n"; } +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK num_vertices += (int)its.vertices.size(); } stream << " </vertices>\n"; @@ -1057,7 +1108,30 @@ 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"; - const indexed_triangle_set &its = volume->mesh().its; +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + stream << " <metadata type=\"slic3r.matrix\">"; + const Transform3d& matrix = volume->get_matrix(); + for (int r = 0; r < 4; ++r) + { + for (int c = 0; c < 4; ++c) + { + stream << matrix(r, c); + if ((r != 3) || (c != 3)) + stream << " "; + } + } + stream << "</metadata>\n"; + if (!volume->source.input_file.empty()) + { + stream << " <metadata type=\"slic3r.source_file\">" << xml_escape(volume->source.input_file) << "</metadata>\n"; + stream << " <metadata type=\"slic3r.source_object_id\">" << volume->source.object_idx << "</metadata>\n"; + stream << " <metadata type=\"slic3r.source_volume_id\">" << volume->source.volume_idx << "</metadata>\n"; + stream << " <metadata type=\"slic3r.source_offset_x\">" << volume->source.mesh_offset(0) << "</metadata>\n"; + 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"; for (int j = 0; j < 3; ++j) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index cc8a86a96..280233b2a 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -15,6 +15,11 @@ #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" #endif @@ -1376,6 +1381,34 @@ 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(); + + if (!transform_str.empty()) + { + std::vector<std::string> mat_elements_str; + boost::split(mat_elements_str, transform_str, boost::is_any_of(" "), boost::token_compress_on); + + unsigned int size = (unsigned int)mat_elements_str.size(); + if (size == 16) + { + unsigned int i = 0; + for (unsigned int r = 0; r < 4; ++r) + { + for (unsigned int c = 0; c < 4; ++c) + { + transform(r, c) = ::atof(mat_elements_str[i++].c_str()); + } + } + } + } + + set_from_transform(transform); +} +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK + void Transformation::reset() { m_offset = Vec3d::Zero(); diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index eec267322..43f791723 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -278,6 +278,9 @@ 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(); diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index d36f5b7ac..ffc4c2454 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1555,7 +1555,11 @@ 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())) @@ -1566,9 +1570,10 @@ 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); } -//================================================================================================================================================================================================ - source.mesh_offset = 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() diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index c91f72a95..6a9bc82fa 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -453,7 +453,11 @@ 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; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 32ee6d57a..4db8d6858 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3188,6 +3188,7 @@ void Plater::priv::reload_from_disk() new_volume->set_new_unique_id(); new_volume->config.apply(old_volume->config); new_volume->set_type(old_volume->type()); + new_volume->set_material_id(old_volume->material_id()); new_volume->set_transformation(old_volume->get_transformation()); new_volume->translate(new_volume->get_transformation().get_matrix(true) * (new_volume->source.mesh_offset - old_volume->source.mesh_offset)); std::swap(old_model_object->volumes[old_v.volume_idx], old_model_object->volumes.back()); From 5eb4692442ffae935a74f92dccbfe7aafe6e4364 Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Mon, 23 Sep 2019 12:33:21 +0200 Subject: [PATCH 3/6] ENABLE_ENHANCED_RELOAD_FROM_DISK -> Fixed export/import to/from .3mf to keep compatibility with 3rd part software. --- src/libslic3r/Format/3mf.cpp | 56 +++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 494da5fe6..6ce4ac4a5 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1674,6 +1674,23 @@ namespace Slic3r { return false; } +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + Slic3r::Geometry::Transformation transform; + if (m_version > 1) + { + // extract the volume transformation from the volume's metadata, if present + for (const Metadata& metadata : volume_data.metadata) + { + if (metadata.key == MATRIX_KEY) + { + transform.set_from_string(metadata.value); + break; + } + } + } + Transform3d inv_matrix = transform.get_matrix().inverse(); +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK + // splits volume out of imported geometry TriangleMesh triangle_mesh; stl_file &stl = triangle_mesh.stl; @@ -1691,7 +1708,16 @@ 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 } } @@ -1699,12 +1725,20 @@ namespace Slic3r { triangle_mesh.repair(); ModelVolume* volume = object.add_volume(std::move(triangle_mesh)); -#if !ENABLE_ENHANCED_RELOAD_FROM_DISK +#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 +#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) @@ -1714,12 +1748,6 @@ namespace Slic3r { 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 == MATRIX_KEY) - { - Slic3r::Geometry::Transformation transform; - transform.set_from_string(metadata.value); - volume->set_transformation(transform); - } else if (metadata.key == SOURCE_FILE_KEY) volume->source.input_file = metadata.value; else if (metadata.key == SOURCE_OBJECT_ID_KEY) @@ -2118,19 +2146,8 @@ namespace Slic3r { vertices_count += (int)its.vertices.size(); -#if !ENABLE_ENHANCED_RELOAD_FROM_DISK const Transform3d& matrix = volume->get_matrix(); -#endif // !ENABLE_ENHANCED_RELOAD_FROM_DISK -#if ENABLE_ENHANCED_RELOAD_FROM_DISK - for (const Vec3f& v : its.vertices) - { - stream << " <" << VERTEX_TAG << " "; - stream << "x=\"" << v(0) << "\" "; - stream << "y=\"" << v(1) << "\" "; - stream << "z=\"" << v(2) << "\" />\n"; - } -#else for (size_t i = 0; i < its.vertices.size(); ++i) { stream << " <" << VERTEX_TAG << " "; @@ -2139,7 +2156,6 @@ namespace Slic3r { stream << "y=\"" << v(1) << "\" "; stream << "z=\"" << v(2) << "\" />\n"; } -#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK } stream << " </" << VERTICES_TAG << ">\n"; From 1115e77b38ae974f67252524fc401282bec1209f Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Mon, 23 Sep 2019 13:54:49 +0200 Subject: [PATCH 4/6] ENABLE_ENHANCED_RELOAD_FROM_DISK -> Fixed export/import to/from .amf to keep compatibility with 3rd part software. --- src/libslic3r/Format/AMF.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 3f85b4b60..490a479d6 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -568,10 +568,30 @@ void AMFParserContext::endElement(const char * /* name */) stl.stats.number_of_facets = int(m_volume_facets.size() / 3); 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) + 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]); + if (m_version > 2) + // revert the vertices to the original mesh reference system + 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(); @@ -1067,18 +1087,6 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) if (! volume->mesh().has_shared_vertices()) throw std::runtime_error("store_amf() requires shared vertices"); const indexed_triangle_set &its = volume->mesh().its; -#if ENABLE_ENHANCED_RELOAD_FROM_DISK - for (const Vec3f& v : its.vertices) - { - stream << " <vertex>\n"; - stream << " <coordinates>\n"; - stream << " <x>" << v(0) << "</x>\n"; - stream << " <y>" << v(1) << "</y>\n"; - stream << " <z>" << v(2) << "</z>\n"; - stream << " </coordinates>\n"; - stream << " </vertex>\n"; - } -#else const Transform3d& matrix = volume->get_matrix(); for (size_t i = 0; i < its.vertices.size(); ++i) { stream << " <vertex>\n"; @@ -1090,7 +1098,6 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) stream << " </coordinates>\n"; stream << " </vertex>\n"; } -#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK num_vertices += (int)its.vertices.size(); } stream << " </vertices>\n"; From 2dc9949a4c129a448d0a5881ac2d2d165e2fea4c Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Mon, 23 Sep 2019 15:35:49 +0200 Subject: [PATCH 5/6] ENABLE_ENHANCED_RELOAD_FROM_DISK set as default --- src/libslic3r/Format/3mf.cpp | 47 ------------ src/libslic3r/Format/AMF.cpp | 20 ----- src/libslic3r/Geometry.cpp | 4 - src/libslic3r/Geometry.hpp | 2 - src/libslic3r/Model.cpp | 25 ++----- src/libslic3r/Model.hpp | 23 +----- src/libslic3r/Technologies.hpp | 7 -- src/slic3r/GUI/GLCanvas3D.cpp | 12 --- src/slic3r/GUI/GUI_ObjectList.cpp | 12 --- src/slic3r/GUI/GUI_ObjectList.hpp | 2 - src/slic3r/GUI/Plater.cpp | 117 +----------------------------- src/slic3r/GUI/Plater.hpp | 4 - src/slic3r/GUI/Selection.cpp | 4 - 13 files changed, 10 insertions(+), 269 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 6ce4ac4a5..47a8e5280 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -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()) diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 490a479d6..2b5638f57 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -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"; diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index 280233b2a..643e42f17 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -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() { diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 43f791723..c15ecbdfd 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -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(); diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index ffc4c2454..26973a5f5 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -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() diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 6a9bc82fa..410c2d3ef 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -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); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 60ae17a82..51d092094 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -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_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7a94b8238..ec79d0ec1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -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; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 7c9941bef..a59a1288e 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -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); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index c8d89cbe3..e1b0b7993 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -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); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 2819bcdf2..e9ea411e8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -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(); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 6ebecac44..d842e37f7 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -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(); diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 346f46e00..79df60464 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -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); From c1bb34cc4dc1fa491da40c5336eff0faa9992843 Mon Sep 17 00:00:00 2001 From: YuSanka <yusanka@gmail.com> Date: Wed, 9 Oct 2019 11:22:44 +0200 Subject: [PATCH 6/6] Some changing in implementation of emulate_kill_focus according to new code architecture. + Cleaning of the code from unused parts --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 435 +--------------------- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 7 +- 2 files changed, 23 insertions(+), 419 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 747cec0f9..0b3f2b098 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -120,9 +120,6 @@ static void set_font_and_background_style(wxWindow* win, const wxFont& font) ObjectManipulation::ObjectManipulation(wxWindow* parent) : OG_Settings(parent, true) -#ifndef __APPLE__ - , m_focused_option("") -#endif // __APPLE__ { m_manifold_warning_bmp = ScalableBitmap(parent, "exclamation"); @@ -415,292 +412,6 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : m_og->sizer->Add(m_main_grid_sizer, 1, wxEXPAND | wxALL, border); } -/* -ObjectManipulation::ObjectManipulation(wxWindow* parent) : - OG_Settings(parent, true) -#ifndef __APPLE__ - , m_focused_option("") -#endif // __APPLE__ -{ - m_manifold_warning_bmp = ScalableBitmap(parent, "exclamation"); - m_og->set_name(_(L("Object Manipulation"))); - m_og->label_width = 12;//125; - m_og->set_grid_vgap(5); - - m_og->m_on_change = std::bind(&ObjectManipulation::on_change, this, std::placeholders::_1, std::placeholders::_2); - m_og->m_fill_empty_value = std::bind(&ObjectManipulation::on_fill_empty_value, this, std::placeholders::_1); - - m_og->m_set_focus = [this](const std::string& opt_key) - { -#ifndef __APPLE__ - m_focused_option = opt_key; -#endif // __APPLE__ - - // needed to show the visual hints in 3D scene - wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, true); - }; - - ConfigOptionDef def; - - Line line = Line{ "Name", "Object name" }; - - auto manifold_warning_icon = [this](wxWindow* parent) { - m_fix_throught_netfab_bitmap = new wxStaticBitmap(parent, wxID_ANY, wxNullBitmap); - - if (is_windows10()) - m_fix_throught_netfab_bitmap->Bind(wxEVT_CONTEXT_MENU, [this](wxCommandEvent &e) - { - // if object/sub-object has no errors - if (m_fix_throught_netfab_bitmap->GetBitmap().GetRefData() == wxNullBitmap.GetRefData()) - return; - - wxGetApp().obj_list()->fix_through_netfabb(); - update_warning_icon_state(wxGetApp().obj_list()->get_mesh_errors_list()); - }); - - return m_fix_throught_netfab_bitmap; - }; - - line.near_label_widget = manifold_warning_icon; - def.label = ""; - def.gui_type = "legend"; - def.tooltip = L("Object name"); -#ifdef __APPLE__ - def.width = 20; -#else - def.width = 22; -#endif - def.set_default_value(new ConfigOptionString{ " " }); - line.append_option(Option(def, "object_name")); - m_og->append_line(line); - - const int field_width = 5; - - // Mirror button size: - const int mirror_btn_width = 3; - - // Legend for object modification - line = Line{ "", "" }; - def.label = ""; - def.type = coString; - def.width = field_width - mirror_btn_width; - - // Load bitmaps to be used for the mirroring buttons: - m_mirror_bitmap_on = ScalableBitmap(parent, "mirroring_on"); - m_mirror_bitmap_off = ScalableBitmap(parent, "mirroring_off"); - m_mirror_bitmap_hidden = ScalableBitmap(parent, "mirroring_transparent.png"); - - static const char axes[] = { 'X', 'Y', 'Z' }; - for (size_t axis_idx = 0; axis_idx < sizeof(axes); axis_idx++) { - const char label = axes[axis_idx]; - def.set_default_value(new ConfigOptionString{ std::string(" ") + label }); - Option option(def, std::string() + label + "_axis_legend"); - - // We will add a button to toggle mirroring to each axis: - auto mirror_button = [this, mirror_btn_width, axis_idx, label](wxWindow* parent) { - wxSize btn_size(em_unit(parent) * mirror_btn_width, em_unit(parent) * mirror_btn_width); - auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_off", wxEmptyString, btn_size, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW); - btn->SetToolTip(wxString::Format(_(L("Toggle %c axis mirroring")), (int)label)); - btn->SetBitmapDisabled_(m_mirror_bitmap_hidden); - - m_mirror_buttons[axis_idx].first = btn; - m_mirror_buttons[axis_idx].second = mbShown; - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(btn); - - btn->Bind(wxEVT_BUTTON, [this, axis_idx](wxCommandEvent &e) { - Axis axis = (Axis)(axis_idx + X); - if (m_mirror_buttons[axis_idx].second == mbHidden) - return; - - GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); - Selection& selection = canvas->get_selection(); - - if (selection.is_single_volume() || selection.is_single_modifier()) { - GLVolume* volume = const_cast<GLVolume*>(selection.get_volume(*selection.get_volume_idxs().begin())); - volume->set_volume_mirror(axis, -volume->get_volume_mirror(axis)); - } - else if (selection.is_single_full_instance()) { - for (unsigned int idx : selection.get_volume_idxs()){ - GLVolume* volume = const_cast<GLVolume*>(selection.get_volume(idx)); - volume->set_instance_mirror(axis, -volume->get_instance_mirror(axis)); - } - } - else - return; - - // Update mirroring at the GLVolumes. - selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); - selection.synchronize_unselected_volumes(); - // Copy mirroring values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. - canvas->do_mirror(L("Set Mirror")); - UpdateAndShow(true); - }); - - return sizer; - }; - - option.side_widget = mirror_button; - line.append_option(option); - } - line.near_label_widget = [this](wxWindow* parent) { - wxBitmapComboBox *combo = create_word_local_combo(parent); - combo->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent &evt) { this->set_world_coordinates(evt.GetSelection() != 1); }), combo->GetId()); - m_word_local_combo = combo; - return combo; - }; - m_og->append_line(line); - - auto add_og_to_object_settings = [this, field_width](const std::string& option_name, const std::string& sidetext) - { - Line line = { _(option_name), "" }; - ConfigOptionDef def; - def.type = coFloat; - def.set_default_value(new ConfigOptionFloat(0.0)); - def.width = field_width; - - if (option_name == "Scale") { - // Add "uniform scaling" button in front of "Scale" option - line.near_label_widget = [this](wxWindow* parent) { - auto btn = new LockButton(parent, wxID_ANY); - btn->Bind(wxEVT_BUTTON, [btn, this](wxCommandEvent &event){ - event.Skip(); - wxTheApp->CallAfter([btn, this]() { set_uniform_scaling(btn->IsLocked()); }); - }); - m_lock_bnt = btn; - return btn; - }; - // Add reset scale button - auto reset_scale_button = [this](wxWindow* parent) { - auto btn = new ScalableButton(parent, wxID_ANY, ScalableBitmap(parent, "undo")); - btn->SetToolTip(_(L("Reset scale"))); - m_reset_scale_button = btn; - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(btn, wxBU_EXACTFIT); - btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { - Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Reset scale"))); - change_scale_value(0, 100.); - change_scale_value(1, 100.); - change_scale_value(2, 100.); - }); - return sizer; - }; - line.append_widget(reset_scale_button); - } - else if (option_name == "Rotation") { - // Add reset rotation button - auto reset_rotation_button = [this](wxWindow* parent) { - auto btn = new ScalableButton(parent, wxID_ANY, ScalableBitmap(parent, "undo")); - btn->SetToolTip(_(L("Reset rotation"))); - m_reset_rotation_button = btn; - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(btn, wxBU_EXACTFIT); - btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { - GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); - Selection& selection = canvas->get_selection(); - - if (selection.is_single_volume() || selection.is_single_modifier()) { - GLVolume* volume = const_cast<GLVolume*>(selection.get_volume(*selection.get_volume_idxs().begin())); - volume->set_volume_rotation(Vec3d::Zero()); - } - else if (selection.is_single_full_instance()) { - for (unsigned int idx : selection.get_volume_idxs()){ - GLVolume* volume = const_cast<GLVolume*>(selection.get_volume(idx)); - volume->set_instance_rotation(Vec3d::Zero()); - } - } - else - return; - - // Update rotation at the GLVolumes. - selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); - selection.synchronize_unselected_volumes(); - // Copy rotation values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. - canvas->do_rotate(L("Reset Rotation")); - - UpdateAndShow(true); - }); - return sizer; - }; - line.append_widget(reset_rotation_button); - } - else if (option_name == "Position") { - // Add drop to bed button - auto drop_to_bed_button = [=](wxWindow* parent) { - auto btn = new ScalableButton(parent, wxID_ANY, ScalableBitmap(parent, "drop_to_bed")); - btn->SetToolTip(_(L("Drop to bed"))); - m_drop_to_bed_button = btn; - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(btn, wxBU_EXACTFIT); - btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent &e) { - // ??? - GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); - Selection& selection = canvas->get_selection(); - - if (selection.is_single_volume() || selection.is_single_modifier()) { - const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); - - const Geometry::Transformation& instance_trafo = volume->get_instance_transformation(); - Vec3d diff = m_cache.position - instance_trafo.get_matrix(true).inverse() * Vec3d(0., 0., get_volume_min_z(volume)); - - Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Drop to bed"))); - change_position_value(0, diff.x()); - change_position_value(1, diff.y()); - change_position_value(2, diff.z()); - } - }); - return sizer; - }; - line.append_widget(drop_to_bed_button); - } - // Add empty bmp (Its size have to be equal to PrusaLockButton) in front of "Size" option to label alignment - else if (option_name == "Size") { - line.near_label_widget = [this](wxWindow* parent) { - return new wxStaticBitmap(parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, - create_scaled_bitmap(m_parent, "one_layer_lock_on.png").GetSize()); - }; - } - - const std::string lower_name = boost::algorithm::to_lower_copy(option_name); - - for (const char *axis : { "_x", "_y", "_z" }) { - if (axis[1] == 'z') - def.sidetext = sidetext; - Option option = Option(def, lower_name + axis); - option.opt.full_width = true; - line.append_option(option); - } - - return line; - }; - - // Settings table - m_og->sidetext_width = 3; - m_og->append_line(add_og_to_object_settings(L("Position"), L("mm")), &m_move_Label); - m_og->append_line(add_og_to_object_settings(L("Rotation"), "°"), &m_rotate_Label); - m_og->append_line(add_og_to_object_settings(L("Scale"), "%"), &m_scale_Label); - m_og->append_line(add_og_to_object_settings(L("Size"), "mm")); - - // call back for a rescale of button "Set uniform scale" - m_og->rescale_near_label_widget = [this](wxWindow* win) { - // rescale lock icon - auto *ctrl = dynamic_cast<LockButton*>(win); - if (ctrl != nullptr) { - ctrl->msw_rescale(); - return; - } - - if (win == m_fix_throught_netfab_bitmap) - return; - - // rescale "place" of the empty icon (to correct layout of the "Size" and "Scale") - if (dynamic_cast<wxStaticBitmap*>(win) != nullptr) - win->SetMinSize(create_scaled_bitmap(m_parent, "one_layer_lock_on.png").GetSize()); - }; -} -*/ - - void ObjectManipulation::Show(const bool show) { if (show != IsShown()) { @@ -710,9 +421,9 @@ void ObjectManipulation::Show(const bool show) if (show && wxGetApp().get_mode() != comSimple) { // Show the label and the name of the STL in simple mode only. // Label "Name: " - /*m_og->get_grid_sizer()*/m_main_grid_sizer->Show(size_t(0), false); + m_main_grid_sizer->Show(size_t(0), false); // The actual name of the STL. - /*m_og->get_grid_sizer()*/m_main_grid_sizer->Show(size_t(1), false); + m_main_grid_sizer->Show(size_t(1), false); } } @@ -833,26 +544,6 @@ void ObjectManipulation::update_if_dirty() update_label(m_cache.rotate_label_string, m_new_rotate_label_string, m_rotate_Label); update_label(m_cache.scale_label_string, m_new_scale_label_string, m_scale_Label); - /* - char axis[2] = "x"; - for (int i = 0; i < 3; ++ i, ++ axis[0]) { - auto update = [this, i, &axis](Vec3d &cached, Vec3d &cached_rounded, const char *key, const Vec3d &new_value) { - wxString new_text = double_to_string(new_value(i), 2); - double new_rounded; - new_text.ToDouble(&new_rounded); - if (std::abs(cached_rounded(i) - new_rounded) > EPSILON) { - cached_rounded(i) = new_rounded; - m_og->set_value(std::string(key) + axis, new_text); - } - cached(i) = new_value(i); - }; - update(m_cache.position, m_cache.position_rounded, "position_", m_new_position); - update(m_cache.scale, m_cache.scale_rounded, "scale_", m_new_scale); - update(m_cache.size, m_cache.size_rounded, "size_", m_new_size); - update(m_cache.rotation, m_cache.rotation_rounded, "rotation_", m_new_rotation); - } - */ - enum ManipulationEditorKey { mePosition = 0, @@ -1007,17 +698,10 @@ void ObjectManipulation::update_mirror_buttons_visibility() #ifndef __APPLE__ void ObjectManipulation::emulate_kill_focus() { - if (m_focused_option.empty()) + if (!m_focused_editor) return; - // we need to use a copy because the value of m_focused_option is modified inside on_change() and on_fill_empty_value() - std::string option = m_focused_option; - - // see TextCtrl::propagate_value() - if (static_cast<wxTextCtrl*>(m_og->get_fieldc(option, 0)->getWindow())->GetValue().empty()) - on_fill_empty_value(option); - else - on_change(option, 0); + m_focused_editor->kill_focus(this); } #endif // __APPLE__ @@ -1156,40 +840,6 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const wxGetApp().plater()->canvas3D()->do_scale(L("Set Scale")); } -void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value) -{ - Field* field = m_og->get_field(opt_key); - bool enter_pressed = (field != nullptr) && field->get_enter_pressed(); - if (!enter_pressed) - { - // if the change does not come from the user pressing the ENTER key - // we need to hide the visual hints in 3D scene - wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false); - -#ifndef __APPLE__ - m_focused_option = ""; -#endif // __APPLE__ - } - else - // if the change comes from the user pressing the ENTER key, restore the key state - field->set_enter_pressed(false); - - if (!m_cache.is_valid()) - return; - - int axis = opt_key.back() - 'x'; - double new_value = boost::any_cast<double>(m_og->get_value(opt_key)); - - if (boost::starts_with(opt_key, "position_")) - change_position_value(axis, new_value); - else if (boost::starts_with(opt_key, "rotation_")) - change_rotation_value(axis, new_value); - else if (boost::starts_with(opt_key, "scale_")) - change_scale_value(axis, new_value); - else if (boost::starts_with(opt_key, "size_")) - change_size_value(axis, new_value); -} - void ObjectManipulation::on_change(const std::string& opt_key, int axis, double new_value) { if (!m_cache.is_valid()) @@ -1205,42 +855,6 @@ void ObjectManipulation::on_change(const std::string& opt_key, int axis, double change_size_value(axis, new_value); } -void ObjectManipulation::on_fill_empty_value(const std::string& opt_key) -{ - // needed to hide the visual hints in 3D scene - wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key, false); -#ifndef __APPLE__ - m_focused_option = ""; -#endif // __APPLE__ - - if (!m_cache.is_valid()) - return; - - const Vec3d *vec = nullptr; - Vec3d *rounded = nullptr; - if (boost::starts_with(opt_key, "position_")) { - vec = &m_cache.position; - rounded = &m_cache.position_rounded; - } else if (boost::starts_with(opt_key, "rotation_")) { - vec = &m_cache.rotation; - rounded = &m_cache.rotation_rounded; - } else if (boost::starts_with(opt_key, "scale_")) { - vec = &m_cache.scale; - rounded = &m_cache.scale_rounded; - } else if (boost::starts_with(opt_key, "size_")) { - vec = &m_cache.size; - rounded = &m_cache.size_rounded; - } else - assert(false); - - if (vec != nullptr) { - int axis = opt_key.back() - 'x'; - wxString new_text = double_to_string((*vec)(axis)); - m_og->set_value(opt_key, new_text); - new_text.ToDouble(&(*rounded)(axis)); - } -} - void ObjectManipulation::set_uniform_scaling(const bool new_value) { const Selection &selection = wxGetApp().plater()->canvas3D()->get_selection(); @@ -1338,43 +952,25 @@ ManipulationEditor::ManipulationEditor(ObjectManipulation* parent, parent->on_change(m_opt_key, m_axis, get_value()); }, this->GetId()); - this->Bind(wxEVT_KILL_FOCUS, [this, parent/*, edit_fn*/](wxFocusEvent& e) + this->Bind(wxEVT_KILL_FOCUS, [this, parent](wxFocusEvent& e) { - if (!m_enter_pressed) { - parent->on_change(m_opt_key, m_axis, get_value()); + parent->set_focused_editor(nullptr); - // if the change does not come from the user pressing the ENTER key - // we need to hide the visual hints in 3D scene - wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(m_full_opt_name, false); -// #ifndef __WXGTK__ -// /* Update data for next editor selection. -// * But under GTK it looks like there is no information about selected control at e.GetWindow(), -// * so we'll take it from wxEVT_LEFT_DOWN event -// * */ -// LayerRangeEditor* new_editor = dynamic_cast<LayerRangeEditor*>(e.GetWindow()); -// if (new_editor) -// new_editor->set_focus_data(); -// #endif // not __WXGTK__ - } + if (!m_enter_pressed) + kill_focus(parent); e.Skip(); }, this->GetId()); - this->Bind(wxEVT_SET_FOCUS, [this](wxFocusEvent& e) + this->Bind(wxEVT_SET_FOCUS, [this, parent](wxFocusEvent& e) { + parent->set_focused_editor(this); + // needed to show the visual hints in 3D scene wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(m_full_opt_name, true); e.Skip(); }, this->GetId()); -// #ifdef __WXGTK__ // Workaround! To take information about selectable range -// this->Bind(wxEVT_LEFT_DOWN, [this](wxEvent& e) -// { -// set_focus_data(); -// e.Skip(); -// }, this->GetId()); -// #endif //__WXGTK__ - this->Bind(wxEVT_CHAR, ([this](wxKeyEvent& event) { // select all text using Ctrl+A @@ -1417,5 +1013,14 @@ void ManipulationEditor::set_value(const wxString& new_value) SetValue(m_valid_value); } +void ManipulationEditor::kill_focus(ObjectManipulation* parent) +{ + parent->on_change(m_opt_key, m_axis, get_value()); + + // if the change does not come from the user pressing the ENTER key + // we need to hide the visual hints in 3D scene + wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(m_full_opt_name, false); +} + } //namespace GUI } //namespace Slic3r diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index e25aab678..7d53034b2 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -32,6 +32,7 @@ public: void msw_rescale(); void set_value(const wxString& new_value); + void kill_focus(ObjectManipulation *parent); private: double get_value(); @@ -118,7 +119,7 @@ class ObjectManipulation : public OG_Settings #ifndef __APPLE__ // Currently focused option name (empty if none) - std::string m_focused_option; + ManipulationEditor* m_focused_editor {nullptr}; #endif // __APPLE__ wxFlexGridSizer* m_main_grid_sizer; @@ -160,6 +161,7 @@ public: void update_warning_icon_state(const wxString& tooltip); void msw_rescale(); void on_change(const std::string& opt_key, int axis, double new_value); + void set_focused_editor(ManipulationEditor* focused_editor) { m_focused_editor = focused_editor; } private: void reset_settings_value(); @@ -176,9 +178,6 @@ private: void change_scale_value(int axis, double value); void change_size_value(int axis, double value); void do_scale(int axis, const Vec3d &scale) const; - - void on_change(t_config_option_key opt_key, const boost::any& value); - void on_fill_empty_value(const std::string& opt_key); }; }}