Added check for loaded STL file if it was saved in meters. Related to #4521 (Some files are imported in the wrong size)
This commit is contained in:
parent
a1e49e7f8c
commit
a86e7107a5
3 changed files with 37 additions and 1 deletions
src
|
@ -472,6 +472,29 @@ void Model::convert_from_imperial_units(bool only_small_volumes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Model::looks_like_saved_in_meters() const
|
||||||
|
{
|
||||||
|
if (this->objects.size() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (ModelObject* obj : this->objects)
|
||||||
|
if (obj->get_object_stl_stats().volume < 0.001) // 0.001 = 0.1*0.1*0.1;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::convert_from_meters(bool only_small_volumes)
|
||||||
|
{
|
||||||
|
double m_to_mm = 1000;
|
||||||
|
for (ModelObject* obj : this->objects)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Model::adjust_min_z()
|
void Model::adjust_min_z()
|
||||||
{
|
{
|
||||||
if (objects.empty())
|
if (objects.empty())
|
||||||
|
|
|
@ -1019,6 +1019,8 @@ public:
|
||||||
void convert_multipart_object(unsigned int max_extruders);
|
void convert_multipart_object(unsigned int max_extruders);
|
||||||
bool looks_like_imperial_units() const;
|
bool looks_like_imperial_units() const;
|
||||||
void convert_from_imperial_units(bool only_small_volumes);
|
void convert_from_imperial_units(bool only_small_volumes);
|
||||||
|
bool looks_like_saved_in_meters() const;
|
||||||
|
void convert_from_meters(bool only_small_volumes);
|
||||||
|
|
||||||
// Ensures that the min z of the model is not negative
|
// Ensures that the min z of the model is not negative
|
||||||
void adjust_min_z();
|
void adjust_min_z();
|
||||||
|
|
|
@ -2415,13 +2415,24 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||||
auto convert_from_imperial_units = [](Model& model, bool only_small_volumes) {
|
auto convert_from_imperial_units = [](Model& model, bool only_small_volumes) {
|
||||||
model.convert_from_imperial_units(only_small_volumes);
|
model.convert_from_imperial_units(only_small_volumes);
|
||||||
// wxGetApp().app_config->set("use_inches", "1");
|
// wxGetApp().app_config->set("use_inches", "1");
|
||||||
wxGetApp().sidebar().update_ui_from_settings();
|
// wxGetApp().sidebar().update_ui_from_settings();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!is_project_file) {
|
if (!is_project_file) {
|
||||||
if (imperial_units)
|
if (imperial_units)
|
||||||
// Convert even if the object is big.
|
// Convert even if the object is big.
|
||||||
convert_from_imperial_units(model, false);
|
convert_from_imperial_units(model, false);
|
||||||
|
else if (model.looks_like_saved_in_meters()) {
|
||||||
|
wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL(
|
||||||
|
"The object in file %s looks like saved in meters.\n"
|
||||||
|
"Should I consider it as a saved in meters and convert it?",
|
||||||
|
"Some objects in file %s look like saved in meters.\n"
|
||||||
|
"Should I consider them as a saved in meters and convert them?", model.objects.size()), from_path(filename)) + "\n",
|
||||||
|
_L("The object appears to be saved in meters"), wxICON_WARNING | wxYES | wxNO);
|
||||||
|
if (msg_dlg.ShowModal() == wxID_YES)
|
||||||
|
//FIXME up-scale only the small parts?
|
||||||
|
model.convert_from_meters(true);
|
||||||
|
}
|
||||||
else if (model.looks_like_imperial_units()) {
|
else if (model.looks_like_imperial_units()) {
|
||||||
wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL(
|
wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL(
|
||||||
"The object in file %s looks like saved in inches.\n"
|
"The object in file %s looks like saved in inches.\n"
|
||||||
|
|
Loading…
Add table
Reference in a new issue