mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-26 11:27:41 +00:00
Compare commits
2 Commits
nightly-bu
...
hanif/cli-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fae1099b90 | ||
|
|
9f1d72e557 |
@@ -6516,10 +6516,20 @@ int CLI::run(int argc, char **argv)
|
|||||||
plate_data->nozzle_diameters = nozzle_diameter_str;
|
plate_data->nozzle_diameters = nozzle_diameter_str;
|
||||||
|
|
||||||
for (auto it = plate_data->slice_filaments_info.begin(); it != plate_data->slice_filaments_info.end(); it++) {
|
for (auto it = plate_data->slice_filaments_info.begin(); it != plate_data->slice_filaments_info.end(); it++) {
|
||||||
|
// ConfigOptionVector::get_at() falls back to values.front() when the index is out of
|
||||||
|
// range, but that is undefined behavior when values is empty outright (e.g. filament_ids
|
||||||
|
// is never populated on a from-scratch slice with no --load-filaments) - guard every
|
||||||
|
// get_at() here on the vector actually having an entry at it->id before calling it.
|
||||||
|
bool valid_id = it->id >= 0;
|
||||||
std::string display_filament_type;
|
std::string display_filament_type;
|
||||||
it->type = m_print_config.get_filament_type(display_filament_type, it->id);
|
if (valid_id && filament_types && static_cast<size_t>(it->id) < filament_types->values.size())
|
||||||
it->color = filament_color ? filament_color->get_at(it->id) : "#FFFFFF";
|
it->type = m_print_config.get_filament_type(display_filament_type, it->id);
|
||||||
it->filament_id = filament_id?filament_id->get_at(it->id):"";
|
it->color = (valid_id && filament_color && static_cast<size_t>(it->id) < filament_color->values.size()) ?
|
||||||
|
filament_color->get_at(it->id) :
|
||||||
|
"#FFFFFF";
|
||||||
|
it->filament_id = (valid_id && filament_id && static_cast<size_t>(it->id) < filament_id->values.size()) ?
|
||||||
|
filament_id->get_at(it->id) :
|
||||||
|
"";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plate_data->plate_thumbnail.is_valid()) {
|
if (!plate_data->plate_thumbnail.is_valid()) {
|
||||||
@@ -7311,6 +7321,10 @@ bool CLI::setup(int argc, char **argv)
|
|||||||
m_config.option(optdef.first, true);
|
m_config.option(optdef.first, true);
|
||||||
|
|
||||||
set_data_dir(m_config.opt_string("datadir"));
|
set_data_dir(m_config.opt_string("datadir"));
|
||||||
|
if (!data_dir().empty() && !boost::filesystem::exists(data_dir())) {
|
||||||
|
boost::nowide::cerr << "Could not create data directory: " << data_dir() << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//FIXME Validating at this stage most likely does not make sense, as the config is not fully initialized yet.
|
//FIXME Validating at this stage most likely does not make sense, as the config is not fully initialized yet.
|
||||||
if (!validity.empty()) {
|
if (!validity.empty()) {
|
||||||
@@ -7423,6 +7437,10 @@ bool CLI::export_models(IO::ExportFormat format, std::string path_dir)
|
|||||||
for (ModelObject* model_object : model.objects)
|
for (ModelObject* model_object : model.objects)
|
||||||
{
|
{
|
||||||
const std::string path = this->output_filepath(*model_object, index++, format, path_dir);
|
const std::string path = this->output_filepath(*model_object, index++, format, path_dir);
|
||||||
|
if (path.empty()) {
|
||||||
|
boost::nowide::cerr << "Could not create output directory for STL export" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
success = Slic3r::store_stl(path.c_str(), model_object, true);
|
success = Slic3r::store_stl(path.c_str(), model_object, true);
|
||||||
if (success)
|
if (success)
|
||||||
BOOST_LOG_TRIVIAL(info) << "Model successfully exported to " << path << std::endl;
|
BOOST_LOG_TRIVIAL(info) << "Model successfully exported to " << path << std::endl;
|
||||||
@@ -7548,8 +7566,19 @@ std::string CLI::output_filepath(const ModelObject &object, unsigned int index,
|
|||||||
output_path = subdir + "/"+file_name;
|
output_path = subdir + "/"+file_name;
|
||||||
|
|
||||||
boost::filesystem::path subdir_path(subdir);
|
boost::filesystem::path subdir_path(subdir);
|
||||||
if (!boost::filesystem::exists(subdir_path))
|
if (!boost::filesystem::exists(subdir_path)) {
|
||||||
boost::filesystem::create_directory(subdir_path);
|
try {
|
||||||
|
boost::filesystem::create_directories(subdir_path);
|
||||||
|
} catch (const boost::filesystem::filesystem_error &ex) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed to create output directory " << subdir_path.string() << ": " << ex.what();
|
||||||
|
}
|
||||||
|
if (!boost::filesystem::exists(subdir_path)) {
|
||||||
|
// Directory creation failed and won't succeed on a retry (same path, same cause) -
|
||||||
|
// signal failure now instead of letting every object in the model repeat the same
|
||||||
|
// doomed attempt and fail with a less specific "export failed" error later.
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
}
|
||||||
return output_path;
|
return output_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -310,7 +310,11 @@ void set_data_dir(const std::string &dir)
|
|||||||
{
|
{
|
||||||
g_data_dir = dir;
|
g_data_dir = dir;
|
||||||
if (!g_data_dir.empty() && !boost::filesystem::exists(g_data_dir)) {
|
if (!g_data_dir.empty() && !boost::filesystem::exists(g_data_dir)) {
|
||||||
boost::filesystem::create_directory(g_data_dir);
|
try {
|
||||||
|
boost::filesystem::create_directories(g_data_dir);
|
||||||
|
} catch (const boost::filesystem::filesystem_error &ex) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "set_data_dir: failed to create data directory " << g_data_dir << ": " << ex.what();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user