mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-25 01:31:14 -06:00
SPE-1103 Added menu items for the conversation of the volumes from/to meters
Related to #4521
This commit is contained in:
parent
8049dd1f72
commit
e664100bf6
8 changed files with 84 additions and 42 deletions
|
|
@ -115,6 +115,7 @@ static constexpr const char* SOURCE_OFFSET_X_KEY = "source_offset_x";
|
|||
static constexpr const char* SOURCE_OFFSET_Y_KEY = "source_offset_y";
|
||||
static constexpr const char* SOURCE_OFFSET_Z_KEY = "source_offset_z";
|
||||
static constexpr const char* SOURCE_IN_INCHES = "source_in_inches";
|
||||
static constexpr const char* SOURCE_IN_METERS = "source_in_meters";
|
||||
|
||||
const unsigned int VALID_OBJECT_TYPES_COUNT = 1;
|
||||
const char* VALID_OBJECT_TYPES[] =
|
||||
|
|
@ -1913,6 +1914,8 @@ namespace Slic3r {
|
|||
volume->source.mesh_offset(2) = ::atof(metadata.value.c_str());
|
||||
else if (metadata.key == SOURCE_IN_INCHES)
|
||||
volume->source.is_converted_from_inches = metadata.value == "1";
|
||||
else if (metadata.key == SOURCE_IN_METERS)
|
||||
volume->source.is_converted_from_meters = metadata.value == "1";
|
||||
else
|
||||
volume->config.set_deserialize(metadata.key, metadata.value);
|
||||
}
|
||||
|
|
@ -2822,6 +2825,8 @@ namespace Slic3r {
|
|||
}
|
||||
if (volume->source.is_converted_from_inches)
|
||||
stream << prefix << SOURCE_IN_INCHES << "\" " << VALUE_ATTR << "=\"1\"/>\n";
|
||||
if (volume->source.is_converted_from_meters)
|
||||
stream << prefix << SOURCE_IN_METERS << "\" " << VALUE_ATTR << "=\"1\"/>\n";
|
||||
}
|
||||
|
||||
// stores volume's config data
|
||||
|
|
|
|||
|
|
@ -798,6 +798,9 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
else if (strcmp(opt_key, "source_in_inches") == 0) {
|
||||
m_volume->source.is_converted_from_inches = m_value[1] == "1";
|
||||
}
|
||||
else if (strcmp(opt_key, "source_in_meters") == 0) {
|
||||
m_volume->source.is_converted_from_meters = m_value[1] == "1";
|
||||
}
|
||||
}
|
||||
} else if (m_path.size() == 3) {
|
||||
if (m_path[1] == NODE_TYPE_MATERIAL) {
|
||||
|
|
@ -1232,6 +1235,8 @@ bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config,
|
|||
}
|
||||
if (volume->source.is_converted_from_inches)
|
||||
stream << " <metadata type=\"slic3r.source_in_inches\">1</metadata>\n";
|
||||
if (volume->source.is_converted_from_meters)
|
||||
stream << " <metadata type=\"slic3r.source_in_meters\">1</metadata>\n";
|
||||
stream << std::setprecision(std::numeric_limits<float>::max_digits10);
|
||||
const indexed_triangle_set &its = volume->mesh().its;
|
||||
for (size_t i = 0; i < its.indices.size(); ++i) {
|
||||
|
|
|
|||
|
|
@ -491,7 +491,7 @@ void Model::convert_from_meters(bool only_small_volumes)
|
|||
if (! only_small_volumes || obj->get_object_stl_stats().volume < 0.001) { // 0.001 = 0.1*0.1*0.1;
|
||||
obj->scale_mesh_after_creation(Vec3d(m_to_mm, m_to_mm, m_to_mm));
|
||||
for (ModelVolume* v : obj->volumes)
|
||||
v->source.is_converted_from_inches = true;
|
||||
v->source.is_converted_from_meters = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1046,13 +1046,14 @@ void ModelObject::scale_mesh_after_creation(const Vec3d &versor)
|
|||
this->invalidate_bounding_box();
|
||||
}
|
||||
|
||||
void ModelObject::convert_units(ModelObjectPtrs& new_objects, bool from_imperial, std::vector<int> volume_idxs)
|
||||
void ModelObject::convert_units(ModelObjectPtrs& new_objects, ConversionType conv_type, std::vector<int> volume_idxs)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace) << "ModelObject::convert_units - start";
|
||||
|
||||
ModelObject* new_object = new_clone(*this);
|
||||
|
||||
double koef = from_imperial ? 25.4 : 0.0393700787;
|
||||
double koef = conv_type == ConversionType::CONV_FROM_INCH ? 25.4 : conv_type == ConversionType::CONV_TO_INCH ? 0.0393700787 :
|
||||
conv_type == ConversionType::CONV_FROM_METER ? 1000 : conv_type == ConversionType::CONV_TO_METER ? 0.001 : 1;
|
||||
const Vec3d versor = Vec3d(koef, koef, koef);
|
||||
|
||||
new_object->set_model(nullptr);
|
||||
|
|
@ -1080,6 +1081,8 @@ void ModelObject::convert_units(ModelObjectPtrs& new_objects, bool from_imperial
|
|||
vol->source.input_file = volume->source.input_file;
|
||||
vol->source.object_idx = (int)new_objects.size();
|
||||
vol->source.volume_idx = vol_idx;
|
||||
vol->source.is_converted_from_inches = volume->source.is_converted_from_inches;
|
||||
vol->source.is_converted_from_meters = volume->source.is_converted_from_meters;
|
||||
|
||||
vol->supported_facets.assign(volume->supported_facets);
|
||||
vol->seam_facets.assign(volume->seam_facets);
|
||||
|
|
@ -1091,7 +1094,10 @@ void ModelObject::convert_units(ModelObjectPtrs& new_objects, bool from_imperial
|
|||
std::find(volume_idxs.begin(), volume_idxs.end(), vol_idx) != volume_idxs.end())) {
|
||||
vol->scale_geometry_after_creation(versor);
|
||||
vol->set_offset(versor.cwiseProduct(volume->get_offset()));
|
||||
vol->source.is_converted_from_inches = from_imperial;
|
||||
if (conv_type == ConversionType::CONV_FROM_INCH || conv_type == ConversionType::CONV_TO_INCH)
|
||||
vol->source.is_converted_from_inches = conv_type == ConversionType::CONV_FROM_INCH;
|
||||
if (conv_type == ConversionType::CONV_FROM_METER || conv_type == ConversionType::CONV_TO_METER)
|
||||
vol->source.is_converted_from_meters = conv_type == ConversionType::CONV_FROM_METER;
|
||||
}
|
||||
else
|
||||
vol->set_offset(volume->get_offset());
|
||||
|
|
@ -1841,6 +1847,14 @@ void ModelVolume::convert_from_imperial_units()
|
|||
this->source.is_converted_from_inches = true;
|
||||
}
|
||||
|
||||
void ModelVolume::convert_from_meters()
|
||||
{
|
||||
double m_to_mm = 1000;
|
||||
this->scale_geometry_after_creation(Vec3d(m_to_mm, m_to_mm, m_to_mm));
|
||||
this->set_offset(Vec3d(0, 0, 0));
|
||||
this->source.is_converted_from_meters = true;
|
||||
}
|
||||
|
||||
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
mesh->transform(get_matrix(dont_translate));
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace cereal {
|
|||
}
|
||||
|
||||
namespace Slic3r {
|
||||
enum class ConversionType;
|
||||
|
||||
class Model;
|
||||
class ModelInstance;
|
||||
|
|
@ -325,7 +326,7 @@ public:
|
|||
|
||||
// This method could only be called before the meshes of this ModelVolumes are not shared!
|
||||
void scale_mesh_after_creation(const Vec3d& versor);
|
||||
void convert_units(ModelObjectPtrs&new_objects, bool from_imperial, std::vector<int> volume_idxs);
|
||||
void convert_units(ModelObjectPtrs&new_objects, ConversionType conv_type, std::vector<int> volume_idxs);
|
||||
|
||||
size_t materials_count() const;
|
||||
size_t facets_count() const;
|
||||
|
|
@ -495,6 +496,13 @@ enum class EnforcerBlockerType : int8_t {
|
|||
BLOCKER = 2
|
||||
};
|
||||
|
||||
enum class ConversionType : int {
|
||||
CONV_TO_INCH,
|
||||
CONV_FROM_INCH,
|
||||
CONV_TO_METER,
|
||||
CONV_FROM_METER,
|
||||
};
|
||||
|
||||
class FacetsAnnotation final : public ObjectWithTimestamp {
|
||||
public:
|
||||
// Assign the content if the timestamp differs, don't assign an ObjectID.
|
||||
|
|
@ -553,11 +561,12 @@ public:
|
|||
Vec3d mesh_offset{ Vec3d::Zero() };
|
||||
Geometry::Transformation transform;
|
||||
bool is_converted_from_inches = false;
|
||||
bool is_converted_from_meters = false;
|
||||
|
||||
template<class Archive> void serialize(Archive& ar) {
|
||||
//FIXME Vojtech: Serialize / deserialize only if the Source is set.
|
||||
// likely testing input_file or object_idx would be sufficient.
|
||||
ar(input_file, object_idx, volume_idx, mesh_offset, transform, is_converted_from_inches);
|
||||
ar(input_file, object_idx, volume_idx, mesh_offset, transform, is_converted_from_inches, is_converted_from_meters);
|
||||
}
|
||||
};
|
||||
Source source;
|
||||
|
|
@ -657,6 +666,7 @@ public:
|
|||
void set_mirror(const Vec3d& mirror) { m_transformation.set_mirror(mirror); }
|
||||
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); }
|
||||
void convert_from_imperial_units();
|
||||
void convert_from_meters();
|
||||
|
||||
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.get_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue