Skip to content

Commit

Permalink
Added check for loaded STL file if it was saved in meters. Related to #…
Browse files Browse the repository at this point in the history
…4521 (Some files are imported in the wrong size)
  • Loading branch information
YuSanka committed Feb 9, 2021
1 parent a1e49e7 commit a86e710
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/libslic3r/Model.cpp
Expand Up @@ -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()
{
if (objects.empty())
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Model.hpp
Expand Up @@ -1019,6 +1019,8 @@ class Model final : public ObjectBase
void convert_multipart_object(unsigned int max_extruders);
bool looks_like_imperial_units() const;
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
void adjust_min_z();
Expand Down
13 changes: 12 additions & 1 deletion src/slic3r/GUI/Plater.cpp
Expand Up @@ -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) {
model.convert_from_imperial_units(only_small_volumes);
// wxGetApp().app_config->set("use_inches", "1");
wxGetApp().sidebar().update_ui_from_settings();
// wxGetApp().sidebar().update_ui_from_settings();
};

if (!is_project_file) {
if (imperial_units)
// Convert even if the object is big.
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()) {
wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL(
"The object in file %s looks like saved in inches.\n"
Expand Down

0 comments on commit a86e710

Please sign in to comment.