Fix for #6803 - Illegal character in filename when STL opened direct from CAD app
Follow-up to ea4e9b35a3
Win32 specific: Substitute slashes to back slashes in file paths
when loading model files (STLs, 3MFS ...)
This commit is contained in:
parent
b0c4a13ebd
commit
ab84da6c56
@ -1702,8 +1702,7 @@ void ObjectList::load_shape_object_from_gallery(const wxArrayString& input_files
|
|||||||
snapshot_label += ", " + wxString::FromUTF8(paths[i].filename().string().c_str());
|
snapshot_label += ", " + wxString::FromUTF8(paths[i].filename().string().c_str());
|
||||||
|
|
||||||
take_snapshot(snapshot_label);
|
take_snapshot(snapshot_label);
|
||||||
std::vector<size_t> res = wxGetApp().plater()->load_files(paths, true, false);
|
if (! wxGetApp().plater()->load_files(paths, true, false).empty())
|
||||||
if (!res.empty())
|
|
||||||
wxGetApp().mainframe->update_title();
|
wxGetApp().mainframe->update_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2221,7 +2221,14 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||||||
std::vector<size_t> obj_idxs;
|
std::vector<size_t> obj_idxs;
|
||||||
|
|
||||||
for (size_t i = 0; i < input_files.size(); ++i) {
|
for (size_t i = 0; i < input_files.size(); ++i) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
auto path = input_files[i];
|
||||||
|
// On Windows, we swap slashes to back slashes, see GH #6803 as read_from_file() does not understand slashes on Windows thus it assignes full path to names of loaded objects.
|
||||||
|
path.make_preferred();
|
||||||
|
#else // _WIN32
|
||||||
|
// Don't make a copy on Posix. Slash is a path separator, back slashes are not accepted as a substitute.
|
||||||
const auto &path = input_files[i];
|
const auto &path = input_files[i];
|
||||||
|
#endif // _WIN32
|
||||||
const auto filename = path.filename();
|
const auto filename = path.filename();
|
||||||
dlg.Update(static_cast<int>(100.0f * static_cast<float>(i) / static_cast<float>(input_files.size())), _L("Loading file") + ": " + from_path(filename));
|
dlg.Update(static_cast<int>(100.0f * static_cast<float>(i) / static_cast<float>(input_files.size())), _L("Loading file") + ": " + from_path(filename));
|
||||||
dlg.Fit();
|
dlg.Fit();
|
||||||
@ -2336,9 +2343,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||||||
else {
|
else {
|
||||||
model = Slic3r::Model::read_from_file(path.string(), nullptr, nullptr, only_if(load_config, Model::LoadAttribute::CheckVersion));
|
model = Slic3r::Model::read_from_file(path.string(), nullptr, nullptr, only_if(load_config, Model::LoadAttribute::CheckVersion));
|
||||||
for (auto obj : model.objects)
|
for (auto obj : model.objects)
|
||||||
if (obj->name.empty() ||
|
if (obj->name.empty())
|
||||||
obj->name.find_first_of("/") != std::string::npos) // When file is imported from Fusion360 the path containes "/" instead of "\\" (see https://github.com/prusa3d/PrusaSlicer/issues/6803)
|
|
||||||
// But read_from_file doesn't support that direction separator and as a result object name containes full path
|
|
||||||
obj->name = fs::path(obj->input_file).filename().string();
|
obj->name = fs::path(obj->input_file).filename().string();
|
||||||
}
|
}
|
||||||
} catch (const ConfigurationError &e) {
|
} catch (const ConfigurationError &e) {
|
||||||
@ -2457,7 +2462,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (load_model) {
|
if (load_model) {
|
||||||
wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string());
|
wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().make_preferred().string());
|
||||||
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames...
|
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames...
|
||||||
statusbar()->set_status_text(_L("Loaded"));
|
statusbar()->set_status_text(_L("Loaded"));
|
||||||
}
|
}
|
||||||
@ -4787,10 +4792,7 @@ void Plater::load_project(const wxString& filename)
|
|||||||
|
|
||||||
p->reset();
|
p->reset();
|
||||||
|
|
||||||
std::vector<fs::path> input_paths;
|
if (! load_files({ into_path(filename) }).empty()) {
|
||||||
input_paths.push_back(into_path(filename));
|
|
||||||
|
|
||||||
if (! load_files(input_paths).empty()) {
|
|
||||||
// At least one file was loaded.
|
// At least one file was loaded.
|
||||||
p->set_project_filename(filename);
|
p->set_project_filename(filename);
|
||||||
reset_project_dirty_initial_presets();
|
reset_project_dirty_initial_presets();
|
||||||
@ -4807,7 +4809,7 @@ void Plater::add_model(bool imperial_units/* = false*/)
|
|||||||
|
|
||||||
std::vector<fs::path> paths;
|
std::vector<fs::path> paths;
|
||||||
for (const auto &file : input_files)
|
for (const auto &file : input_files)
|
||||||
paths.push_back(into_path(file));
|
paths.emplace_back(into_path(file));
|
||||||
|
|
||||||
wxString snapshot_label;
|
wxString snapshot_label;
|
||||||
assert(! paths.empty());
|
assert(! paths.empty());
|
||||||
@ -4840,12 +4842,8 @@ void Plater::extract_config_from_project()
|
|||||||
wxString input_file;
|
wxString input_file;
|
||||||
wxGetApp().load_project(this, input_file);
|
wxGetApp().load_project(this, input_file);
|
||||||
|
|
||||||
if (input_file.empty())
|
if (! input_file.empty())
|
||||||
return;
|
load_files({ into_path(input_file) }, false, true);
|
||||||
|
|
||||||
std::vector<fs::path> input_paths;
|
|
||||||
input_paths.push_back(into_path(input_file));
|
|
||||||
load_files(input_paths, false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::load_gcode()
|
void Plater::load_gcode()
|
||||||
@ -5076,15 +5074,11 @@ bool Plater::load_files(const wxArrayString& filenames)
|
|||||||
}
|
}
|
||||||
case LoadType::LoadGeometry: {
|
case LoadType::LoadGeometry: {
|
||||||
Plater::TakeSnapshot snapshot(this, _L("Import Object"));
|
Plater::TakeSnapshot snapshot(this, _L("Import Object"));
|
||||||
std::vector<fs::path> in_paths;
|
load_files({ *it }, true, false);
|
||||||
in_paths.emplace_back(*it);
|
|
||||||
load_files(in_paths, true, false);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LoadType::LoadConfig: {
|
case LoadType::LoadConfig: {
|
||||||
std::vector<fs::path> in_paths;
|
load_files({ *it }, false, true);
|
||||||
in_paths.emplace_back(*it);
|
|
||||||
load_files(in_paths, false, true);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LoadType::Unknown : {
|
case LoadType::Unknown : {
|
||||||
|
Loading…
Reference in New Issue
Block a user