Merge remote-tracking branch 'remotes/origin/master' into vb_print_regions

This commit is contained in:
Vojtech Bubnik 2021-05-26 14:38:34 +02:00
commit 0d081c90f0
46 changed files with 521 additions and 265 deletions

View file

@ -2,8 +2,10 @@
#include "libslic3r/Utils.hpp"
#include "AppConfig.hpp"
#include "Exception.hpp"
#include "LocalesUtils.hpp"
#include "Thread.hpp"
#include <utility>
#include <vector>
#include <stdexcept>
@ -376,7 +378,8 @@ void AppConfig::set_recent_projects(const std::vector<std::string>& recent_proje
}
}
void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed, bool swap_yz)
void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone,
float rotation_speed, float rotation_deadzone, double zoom_speed, bool swap_yz)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
@ -384,11 +387,11 @@ void AppConfig::set_mouse_device(const std::string& name, double translation_spe
it = m_storage.insert(std::map<std::string, std::map<std::string, std::string>>::value_type(key, std::map<std::string, std::string>())).first;
it->second.clear();
it->second["translation_speed"] = std::to_string(translation_speed);
it->second["translation_deadzone"] = std::to_string(translation_deadzone);
it->second["rotation_speed"] = std::to_string(rotation_speed);
it->second["rotation_deadzone"] = std::to_string(rotation_deadzone);
it->second["zoom_speed"] = std::to_string(zoom_speed);
it->second["translation_speed"] = float_to_string_decimal_point(translation_speed);
it->second["translation_deadzone"] = float_to_string_decimal_point(translation_deadzone);
it->second["rotation_speed"] = float_to_string_decimal_point(rotation_speed);
it->second["rotation_deadzone"] = float_to_string_decimal_point(rotation_deadzone);
it->second["zoom_speed"] = float_to_string_decimal_point(zoom_speed);
it->second["swap_yz"] = swap_yz ? "1" : "0";
}

View file

@ -196,6 +196,6 @@ private:
bool m_legacy_datadir;
};
}; // namespace Slic3r
} // namespace Slic3r
#endif /* slic3r_AppConfig_hpp_ */

View file

@ -1,5 +1,4 @@
#include "Arrange.hpp"
#include "SVG.hpp"
#include "BoundingBox.hpp"

View file

@ -126,6 +126,8 @@ add_library(libslic3r STATIC
Line.hpp
LibraryCheck.cpp
LibraryCheck.hpp
LocalesUtils.cpp
LocalesUtils.hpp
Model.cpp
Model.hpp
ModelArrange.hpp

View file

@ -1,6 +1,8 @@
#include "Config.hpp"
#include "format.hpp"
#include "Utils.hpp"
#include "LocalesUtils.hpp"
#include <assert.h>
#include <fstream>
#include <iostream>
@ -462,7 +464,7 @@ void ConfigBase::set(const std::string &opt_key, double value, bool create)
switch (opt->type()) {
case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
case coString: static_cast<ConfigOptionString*>(opt)->value = std::to_string(value); break;
case coString: static_cast<ConfigOptionString*>(opt)->value = float_to_string_decimal_point(value); break;
default: throw BadOptionTypeException("Configbase::set() - conversion from float not possible");
}
}

View file

@ -1863,10 +1863,10 @@ public:
SetDeserializeItem(const std::string &opt_key, const bool value, bool append = false) : opt_key(opt_key), opt_value(value ? "1" : "0"), append(append) {}
SetDeserializeItem(const char *opt_key, const int value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const int value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const char *opt_key, const float value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const float value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const char *opt_key, const double value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const double value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const char *opt_key, const float value, bool append = false) : opt_key(opt_key), opt_value(float_to_string_decimal_point(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const float value, bool append = false) : opt_key(opt_key), opt_value(float_to_string_decimal_point(value)), append(append) {}
SetDeserializeItem(const char *opt_key, const double value, bool append = false) : opt_key(opt_key), opt_value(float_to_string_decimal_point(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const double value, bool append = false) : opt_key(opt_key), opt_value(float_to_string_decimal_point(value)), append(append) {}
std::string opt_key; std::string opt_value; bool append = false;
};
// May throw BadOptionTypeException() if the operation fails.

View file

@ -2,6 +2,7 @@
#include "../Exception.hpp"
#include "../Model.hpp"
#include "../Utils.hpp"
#include "../LocalesUtils.hpp"
#include "../GCode.hpp"
#include "../Geometry.hpp"
#include "../GCode/ThumbnailData.hpp"
@ -2408,6 +2409,7 @@ namespace Slic3r {
};
auto format_coordinate = [](float f, char *buf) -> char* {
assert(is_decimal_separator_point());
#if EXPORT_3MF_USE_SPIRIT_KARMA_FP
// Slightly faster than sprintf("%.9g"), but there is an issue with the karma floating point formatter,
// https://github.com/boostorg/spirit/pull/586
@ -2575,6 +2577,7 @@ namespace Slic3r {
bool _3MF_Exporter::_add_layer_height_profile_file_to_archive(mz_zip_archive& archive, Model& model)
{
assert(is_decimal_separator_point());
std::string out = "";
char buffer[1024];
@ -2666,6 +2669,7 @@ namespace Slic3r {
bool _3MF_Exporter::_add_sla_support_points_file_to_archive(mz_zip_archive& archive, Model& model)
{
assert(is_decimal_separator_point());
std::string out = "";
char buffer[1024];
@ -2700,6 +2704,7 @@ namespace Slic3r {
bool _3MF_Exporter::_add_sla_drain_holes_file_to_archive(mz_zip_archive& archive, Model& model)
{
assert(is_decimal_separator_point());
const char *const fmt = "object_id=%d|";
std::string out;
@ -2750,6 +2755,7 @@ namespace Slic3r {
bool _3MF_Exporter::_add_print_config_file_to_archive(mz_zip_archive& archive, const DynamicPrintConfig &config)
{
assert(is_decimal_separator_point());
char buffer[1024];
sprintf(buffer, "; %s\n\n", header_slic3r_generated().c_str());
std::string out = buffer;
@ -2926,6 +2932,9 @@ bool load_3mf(const char* path, DynamicPrintConfig* config, Model* model, bool c
if (path == nullptr || config == nullptr || model == nullptr)
return false;
// All import should use "C" locales for number formatting.
CNumericLocalesSetter locales_setter;
_3MF_Importer importer;
bool res = importer.load_model_from_file(path, *model, *config, check_version);
importer.log_errors();
@ -2934,6 +2943,9 @@ bool load_3mf(const char* path, DynamicPrintConfig* config, Model* model, bool c
bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data, bool zip64)
{
// All export should use "C" locales for number formatting.
CNumericLocalesSetter locales_setter;
if (path == nullptr || model == nullptr)
return false;

View file

@ -15,6 +15,7 @@
#include "../I18N.hpp"
#include "../Geometry.hpp"
#include "../CustomGCode.hpp"
#include "../LocalesUtils.hpp"
#include "AMF.hpp"
@ -498,6 +499,7 @@ void AMFParserContext::characters(const XML_Char *s, int len)
void AMFParserContext::endElement(const char * /* name */)
{
assert(is_decimal_separator_point());
switch (m_path.back()) {
// Constellation transformation:
@ -1052,6 +1054,8 @@ bool load_amf_archive(const char* path, DynamicPrintConfig* config, Model* model
// If config is not a null pointer, updates it if the amf file/archive contains config data
bool load_amf(const char* path, DynamicPrintConfig* config, Model* model, bool check_version)
{
CNumericLocalesSetter locales_setter; // use "C" locales and point as a decimal separator
if (boost::iends_with(path, ".amf.xml"))
// backward compatibility with older slic3r output
return load_amf_file(path, config, model);
@ -1251,40 +1255,25 @@ bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config,
stream << " </object>\n";
if (!object->instances.empty()) {
for (ModelInstance *instance : object->instances) {
char buf[512];
::sprintf(buf,
" <instance objectid=\"%zu\">\n"
" <deltax>%lf</deltax>\n"
" <deltay>%lf</deltay>\n"
" <deltaz>%lf</deltaz>\n"
" <rx>%lf</rx>\n"
" <ry>%lf</ry>\n"
" <rz>%lf</rz>\n"
" <scalex>%lf</scalex>\n"
" <scaley>%lf</scaley>\n"
" <scalez>%lf</scalez>\n"
" <mirrorx>%lf</mirrorx>\n"
" <mirrory>%lf</mirrory>\n"
" <mirrorz>%lf</mirrorz>\n"
" <printable>%d</printable>\n"
" </instance>\n",
object_id,
instance->get_offset(X),
instance->get_offset(Y),
instance->get_offset(Z),
instance->get_rotation(X),
instance->get_rotation(Y),
instance->get_rotation(Z),
instance->get_scaling_factor(X),
instance->get_scaling_factor(Y),
instance->get_scaling_factor(Z),
instance->get_mirror(X),
instance->get_mirror(Y),
instance->get_mirror(Z),
instance->printable);
std::stringstream buf;
buf << " <instance objectid=\"" << object_id << "\">\n"
<< " <deltax>" << instance->get_offset(X) << "</deltax>\n"
<< " <deltay>" << instance->get_offset(Y) << "</deltay>\n"
<< " <deltaz>" << instance->get_offset(Z) << "</deltaz>\n"
<< " <rx>" << instance->get_rotation(X) << "</rx>\n"
<< " <ry>" << instance->get_rotation(Y) << "</ry>\n"
<< " <rz>" << instance->get_rotation(Z) << "</rz>\n"
<< " <scalex>" << instance->get_scaling_factor(X) << "</scalex>\n"
<< " <scaley>" << instance->get_scaling_factor(Y) << "</scaley>\n"
<< " <scalez>" << instance->get_scaling_factor(Z) << "</scalez>\n"
<< " <mirrorx>" << instance->get_mirror(X) << "</mirrorx>\n"
<< " <mirrory>" << instance->get_mirror(Y) << "</mirrory>\n"
<< " <mirrorz>" << instance->get_mirror(Z) << "</mirrorz>\n"
<< " <printable>" << instance->printable << "</printable>\n"
<< " </instance>\n";
//FIXME missing instance->scaling_factor
instances.append(buf);
instances.append(buf.str());
}
}
}

View file

@ -13,6 +13,6 @@ extern bool load_amf(const char* path, DynamicPrintConfig* config, Model* model,
// The model could be modified during the export process if meshes are not repaired or have no shared vertices
extern bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources);
}; // namespace Slic3r
} // namespace Slic3r
#endif /* slic3r_Format_AMF_hpp_ */

View file

@ -345,6 +345,7 @@ std::string get_cfg_value(const DynamicPrintConfig &cfg, const std::string &key)
void fill_iniconf(ConfMap &m, const SLAPrint &print)
{
CNumericLocalesSetter locales_setter; // for to_string
auto &cfg = print.full_print_config();
m["layerHeight"] = get_cfg_value(cfg, "layer_height");
m["expTime"] = get_cfg_value(cfg, "exposure_time");

View file

@ -6,6 +6,8 @@
#include "objparser.hpp"
#include "libslic3r/LocalesUtils.hpp"
namespace ObjParser {
static bool obj_parseline(const char *line, ObjData &data)
@ -15,6 +17,8 @@ static bool obj_parseline(const char *line, ObjData &data)
if (*line == 0)
return true;
assert(Slic3r::is_decimal_separator_point());
// Ignore whitespaces at the beginning of the line.
//FIXME is this a good idea?
EATWS();
@ -322,6 +326,8 @@ static bool obj_parseline(const char *line, ObjData &data)
bool objparse(const char *path, ObjData &data)
{
Slic3r::CNumericLocalesSetter locales_setter;
FILE *pFile = boost::nowide::fopen(path, "rt");
if (pFile == 0)
return false;
@ -365,6 +371,8 @@ bool objparse(const char *path, ObjData &data)
bool objparse(std::istream &stream, ObjData &data)
{
Slic3r::CNumericLocalesSetter locales_setter;
try {
char buf[65536 * 2];
size_t len = 0;

View file

@ -12,6 +12,7 @@
#include "Utils.hpp"
#include "ClipperUtils.hpp"
#include "libslic3r.h"
#include "LocalesUtils.hpp"
#include <algorithm>
#include <cstdlib>
@ -750,6 +751,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re
std::string path_tmp(path);
path_tmp += ".tmp";
CNumericLocalesSetter c_locales_setter;
FILE *file = boost::nowide::fopen(path_tmp.c_str(), "wb");
if (file == nullptr)
throw Slic3r::RuntimeError(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n");
@ -981,6 +983,7 @@ namespace DoExport {
double filament_weight = extruded_volume * extruder.filament_density() * 0.001;
double filament_cost = filament_weight * extruder.filament_cost() * 0.001;
auto append = [&extruder](std::pair<std::string, unsigned int> &dst, const char *tmpl, double value) {
assert(is_decimal_separator_point());
while (dst.second < extruder.id()) {
// Fill in the non-printing extruders with zeros.
dst.first += (dst.second > 0) ? ", 0" : "0";
@ -1620,7 +1623,7 @@ void GCode::print_machine_envelope(FILE *file, Print &print)
int(print.config().machine_max_acceleration_retracting.values.front() + 0.5),
travel_acc);
assert(is_decimal_separator_point());
fprintf(file, "M205 X%.2lf Y%.2lf Z%.2lf E%.2lf ; sets the jerk limits, mm/sec\n",
print.config().machine_max_jerk_x.values.front(),
print.config().machine_max_jerk_y.values.front(),
@ -1984,6 +1987,7 @@ void GCode::process_layer(
}
std::string gcode;
assert(is_decimal_separator_point()); // for the sprintfs
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
@ -2826,6 +2830,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
// so, if the last role was erWipeTower we force export of GCodeProcessor::Height_Tag lines
bool last_was_wipe_tower = (m_last_processor_extrusion_role == erWipeTower);
char buf[64];
assert(is_decimal_separator_point());
if (path.role() != m_last_processor_extrusion_role) {
m_last_processor_extrusion_role = path.role();

View file

@ -357,6 +357,8 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
for (; *c == ' ' || *c == '\t'; ++ c);
if (*c == 0 || *c == ';')
break;
assert(is_decimal_separator_point()); // for atof
// Parse the axis.
size_t axis = (*c >= 'X' && *c <= 'Z') ? (*c - 'X') :
(*c == extrusion_axis) ? 3 : (*c == 'F') ? 4 : size_t(-1);
@ -454,6 +456,7 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
line.type = CoolingLine::TYPE_G4;
size_t pos_S = sline.find('S', 3);
size_t pos_P = sline.find('P', 3);
assert(is_decimal_separator_point()); // for atof
line.time = line.time_max = float(
(pos_S > 0) ? atof(sline.c_str() + pos_S + 1) :
(pos_P > 0) ? atof(sline.c_str() + pos_P + 1) * 0.001 : 0.);

View file

@ -1,6 +1,7 @@
#include "libslic3r/libslic3r.h"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Print.hpp"
#include "libslic3r/LocalesUtils.hpp"
#include "GCodeProcessor.hpp"
#include <boost/log/trivial.hpp>
@ -465,9 +466,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
};
auto format_time_float = [](float time) {
char time_str[64];
sprintf(time_str, "%.2f", time);
return std::string(time_str);
return Slic3r::float_to_string_decimal_point(time, 2);
};
auto format_line_M73_stop_float = [format_time_float](const std::string& mask, float time) {
@ -671,7 +670,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
std::string time_float_str = format_time_float(time_in_last_minute(it_stop->elapsed_time - it->elapsed_time));
std::string next_time_float_str = format_time_float(time_in_last_minute(it_stop->elapsed_time - next_it->elapsed_time));
is_last |= (std::stof(time_float_str) > 0.0f && std::stof(next_time_float_str) == 0.0f);
is_last |= (string_to_double_decimal_point(time_float_str) > 0. && string_to_double_decimal_point(next_time_float_str) == 0.);
}
if (is_last) {
@ -1374,7 +1373,7 @@ void GCodeProcessor::apply_config_simplify3d(const std::string& filename)
if (pos != cmt.npos) {
pos = cmt.find(',', pos);
if (pos != cmt.npos) {
out = std::stod(cmt.substr(pos + 1));
out = string_to_double_decimal_point(cmt.substr(pos+1));
return true;
}
}
@ -1524,9 +1523,9 @@ template<typename T>
else if constexpr (std::is_same_v<T, long>)
out = std::stol(str, &read);
else if constexpr (std::is_same_v<T, float>)
out = std::stof(str, &read);
out = string_to_double_decimal_point(str, &read);
else if constexpr (std::is_same_v<T, double>)
out = std::stod(str, &read);
out = string_to_double_decimal_point(str, &read);
return str.size() == read;
} catch (...) {
return false;

View file

@ -4,6 +4,7 @@
#include "../libslic3r.h"
#include "../PrintConfig.hpp"
#include "../LocalesUtils.hpp"
#include "PressureEqualizer.hpp"
@ -158,7 +159,7 @@ static inline int parse_int(const char *&line)
static inline float parse_float(const char *&line)
{
char *endptr = NULL;
float result = strtof(line, &endptr);
float result = string_to_double_decimal_point(line, &endptr);
if (endptr == NULL || !is_ws_or_eol(*endptr))
throw Slic3r::RuntimeError("PressureEqualizer: Error parsing a float");
line = endptr;

View file

@ -4,9 +4,12 @@
#include <iostream>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include "GCodeProcessor.hpp"
#include "BoundingBox.hpp"
#include "LocalesUtils.hpp"
namespace Slic3r
@ -30,29 +33,27 @@ public:
m_filpar(filament_parameters)
{
// adds tag for analyzer:
char buf[64];
std::ostringstream str;
#if ENABLE_VALIDATE_CUSTOM_GCODE
sprintf(buf, ";%s%f\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height).c_str(), m_layer_height); // don't rely on GCodeAnalyzer knowing the layer height - it knows nothing at priming
m_gcode += buf;
sprintf(buf, ";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), ExtrusionEntity::role_to_string(erWipeTower).c_str());
str << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height) << m_layer_height << "\n"; // don't rely on GCodeAnalyzer knowing the layer height - it knows nothing at priming
str << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role) << ExtrusionEntity::role_to_string(erWipeTower) << "\n";
#else
sprintf(buf, ";%s%f\n", GCodeProcessor::Height_Tag.c_str(), m_layer_height); // don't rely on GCodeAnalyzer knowing the layer height - it knows nothing at priming
m_gcode += buf;
sprintf(buf, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(erWipeTower).c_str());
str << ";" << GCodeProcessor::Height_Tag << m_layer_height << "\n"; // don't rely on GCodeAnalyzer knowing the layer height - it knows nothing at priming
str << ";" << GCodeProcessor::Extrusion_Role_Tag << ExtrusionEntity::role_to_string(erWipeTower) << "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
m_gcode += buf;
m_gcode += str.str();
change_analyzer_line_width(line_width);
}
WipeTowerWriter& change_analyzer_line_width(float line_width) {
// adds tag for analyzer:
char buf[64];
std::stringstream str;
#if ENABLE_VALIDATE_CUSTOM_GCODE
sprintf(buf, ";%s%f\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width).c_str(), line_width);
str << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width) << line_width << "\n";
#else
sprintf(buf, ";%s%f\n", GCodeProcessor::Width_Tag.c_str(), line_width);
str << ";" << GCodeProcessor::Width_Tag << line_width << "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
m_gcode += buf;
m_gcode += str.str();
return *this;
}
@ -61,9 +62,9 @@ public:
static const float area = float(M_PI) * 1.75f * 1.75f / 4.f;
float mm3_per_mm = (len == 0.f ? 0.f : area * e / len);
// adds tag for processor:
char buf[64];
sprintf(buf, ";%s%f\n", GCodeProcessor::Mm3_Per_Mm_Tag.c_str(), mm3_per_mm);
m_gcode += buf;
std::stringstream str;
str << ";" << GCodeProcessor::Mm3_Per_Mm_Tag << mm3_per_mm << "\n";
m_gcode += str.str();
return *this;
}
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
@ -325,9 +326,7 @@ public:
{
if (time==0.f)
return *this;
char buf[128];
sprintf(buf, "G4 S%.3f\n", time);
m_gcode += buf;
m_gcode += "G4 S" + Slic3r::float_to_string_decimal_point(time, 3) + "\n";
return *this;
}
@ -443,37 +442,29 @@ private:
const std::vector<WipeTower::FilamentParameters>& m_filpar;
std::string set_format_X(float x)
{
char buf[64];
sprintf(buf, " X%.3f", x);
m_current_pos.x() = x;
return buf;
{
m_current_pos.x() = x;
return " X" + Slic3r::float_to_string_decimal_point(x, 3);
}
std::string set_format_Y(float y) {
char buf[64];
sprintf(buf, " Y%.3f", y);
m_current_pos.y() = y;
return buf;
m_current_pos.y() = y;
return " Y" + Slic3r::float_to_string_decimal_point(y, 3);
}
std::string set_format_Z(float z) {
char buf[64];
sprintf(buf, " Z%.3f", z);
return buf;
return " Z" + Slic3r::float_to_string_decimal_point(z, 3);
}
std::string set_format_E(float e) {
char buf[64];
sprintf(buf, " E%.4f", e);
return buf;
return " E" + Slic3r::float_to_string_decimal_point(e, 4);
}
std::string set_format_F(float f) {
char buf[64];
sprintf(buf, " F%d", int(floor(f + 0.5f)));
m_current_feedrate = f;
return buf;
char buf[64];
sprintf(buf, " F%d", int(floor(f + 0.5f)));
m_current_feedrate = f;
return buf;
}
WipeTowerWriter& operator=(const WipeTowerWriter &rhs);
@ -959,8 +950,8 @@ void WipeTower::toolchange_Change(
// postprocessor that we absolutely want to have this in the gcode, even if it thought it is the same as before.
Vec2f current_pos = writer.pos_rotated();
writer.feedrate(m_travel_speed * 60.f) // see https://github.com/prusa3d/PrusaSlicer/issues/5483
.append(std::string("G1 X") + std::to_string(current_pos.x())
+ " Y" + std::to_string(current_pos.y())
.append(std::string("G1 X") + Slic3r::float_to_string_decimal_point(current_pos.x())
+ " Y" + Slic3r::float_to_string_decimal_point(current_pos.y())
+ never_skip_tag() + "\n");
// The toolchange Tn command will be inserted later, only in case that the user does
@ -1310,11 +1301,10 @@ static WipeTower::ToolChangeResult merge_tcr(WipeTower::ToolChangeResult& first,
{
assert(first.new_tool == second.initial_tool);
WipeTower::ToolChangeResult out = first;
if (first.end_pos != second.start_pos) {
char buf[2048]; // Add a travel move from tc1.end_pos to tc2.start_pos.
sprintf(buf, "G1 X%.3f Y%.3f F7200\n", second.start_pos.x(), second.start_pos.y());
out.gcode += buf;
}
if (first.end_pos != second.start_pos)
out.gcode += "G1 X" + Slic3r::float_to_string_decimal_point(second.start_pos.x(), 3)
+ " Y" + Slic3r::float_to_string_decimal_point(second.start_pos.y(), 3)
+ " F7200\n";
out.gcode += second.gcode;
out.extrusions.insert(out.extrusions.end(), second.extrusions.begin(), second.extrusions.end());
out.end_pos = second.end_pos;

View file

@ -6,6 +6,8 @@
#include <iostream>
#include <iomanip>
#include "LocalesUtils.hpp"
#include <Shiny/Shiny.h>
namespace Slic3r {
@ -25,6 +27,7 @@ void GCodeReader::apply_config(const DynamicPrintConfig &config)
const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command)
{
PROFILE_FUNC();
CNumericLocalesSetter locales_setter; // for strtod
// command and args
const char *c = ptr;
@ -150,6 +153,7 @@ bool GCodeReader::GCodeLine::has(char axis) const
bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
{
CNumericLocalesSetter locales_setter; // for strtod
const char *c = m_raw.c_str();
// Skip the whitespaces.
c = skip_whitespaces(c);

View file

@ -0,0 +1,76 @@
#include "LocalesUtils.hpp"
#include <stdexcept>
namespace Slic3r {
CNumericLocalesSetter::CNumericLocalesSetter()
{
#ifdef _WIN32
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
m_orig_numeric_locale = std::setlocale(LC_NUMERIC, nullptr);
std::setlocale(LC_NUMERIC, "C");
#else
m_original_locale = uselocale((locale_t)0);
m_new_locale = duplocale(m_original_locale);
m_new_locale = newlocale(LC_NUMERIC_MASK, "C", m_new_locale);
uselocale(m_new_locale);
#endif
}
CNumericLocalesSetter::~CNumericLocalesSetter()
{
#ifdef _WIN32
std::setlocale(LC_NUMERIC, m_orig_numeric_locale.data());
#else
uselocale(m_original_locale);
freelocale(m_new_locale);
#endif
}
bool is_decimal_separator_point()
{
char str[5] = "";
sprintf(str, "%.1f", 0.5f);
return str[1] == '.';
}
double string_to_double_decimal_point(const std::string& str, size_t* pos /* = nullptr*/)
{
double out;
std::istringstream stream(str);
if (! (stream >> out))
throw std::invalid_argument("string_to_double_decimal_point conversion failed.");
if (pos) {
if (stream.eof())
*pos = str.size();
else
*pos = stream.tellg();
}
return out;
}
std::string float_to_string_decimal_point(double value, int precision/* = -1*/)
{
assert(is_decimal_separator_point());
std::stringstream buf;
if (precision >= 0)
buf << std::fixed << std::setprecision(precision);
buf << value;
return buf.str();
}
//std::string float_to_string_decimal_point(float value, int precision/* = -1*/)
//{
// return float_to_string_decimal_point(double(value), precision);
//}
} // namespace Slic3r

View file

@ -0,0 +1,47 @@
#ifndef slic3r_LocalesUtils_hpp_
#define slic3r_LocalesUtils_hpp_
#include <string>
#include <clocale>
#include <iomanip>
#include <cassert>
#ifdef __APPLE__
#include <xlocale.h>
#endif
namespace Slic3r {
// RAII wrapper that sets LC_NUMERIC to "C" on construction
// and restores the old value on destruction.
class CNumericLocalesSetter {
public:
CNumericLocalesSetter();
~CNumericLocalesSetter();
private:
#ifdef _WIN32
std::string m_orig_numeric_locale;
#else
locale_t m_original_locale;
locale_t m_new_locale;
#endif
};
// A function to check that current C locale uses decimal point as a separator.
// Intended mostly for asserts.
bool is_decimal_separator_point();
// A substitute for std::to_string that works according to
// C++ locales, not C locale. Meant to be used when we need
// to be sure that decimal point is used as a separator.
// (We use user C locales and "C" C++ locales in most of the code.)
std::string float_to_string_decimal_point(double value, int precision = -1);
//std::string float_to_string_decimal_point(float value, int precision = -1);
double string_to_double_decimal_point(const std::string& str, size_t* pos = nullptr);
} // namespace Slic3r
#endif // slic3r_LocalesUtils_hpp_

View file

@ -1,3 +1,4 @@
#include "libslic3r.h"
#include "Exception.hpp"
#include "Model.hpp"
#include "ModelArrange.hpp"
@ -889,35 +890,22 @@ BoundingBoxf3 ModelObject::instance_bounding_box(size_t instance_idx, bool dont_
// Calculate 2D convex hull of of a projection of the transformed printable volumes into the XY plane.
// This method is cheap in that it does not make any unnecessary copy of the volume meshes.
// This method is used by the auto arrange function.
#if ENABLE_ALLOW_NEGATIVE_Z
Polygon ModelObject::convex_hull_2d(const Transform3d& trafo_instance) const
{
Points pts;
for (const ModelVolume* v : volumes) {
if (v->is_model_part())
append(pts, its_convex_hull_2d_above(v->mesh().its, (trafo_instance * v->get_matrix()).cast<float>(), 0.0f).points);
}
return Geometry::convex_hull(std::move(pts));
}
#else
Polygon ModelObject::convex_hull_2d(const Transform3d &trafo_instance) const
{
Points pts;
for (const ModelVolume *v : this->volumes)
if (v->is_model_part()) {
#if ENABLE_ALLOW_NEGATIVE_Z
const Transform3d trafo = trafo_instance * v->get_matrix();
const TriangleMesh& hull_3d = v->get_convex_hull();
const indexed_triangle_set& its = hull_3d.its;
if (its.vertices.empty()) {
// Using the STL faces.
const stl_file& stl = hull_3d.stl;
for (const stl_facet& facet : stl.facet_start) {
for (size_t j = 0; j < 3; ++j) {
const Vec3d p = trafo * facet.vertex[j].cast<double>();
if (p.z() >= 0.0)
pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y())));
}
}
}
else {
// Using the shared vertices should be a bit quicker than using the STL faces.
for (size_t i = 0; i < its.vertices.size(); ++i) {
const Vec3d p = trafo * its.vertices[i].cast<double>();
if (p.z() >= 0.0)
pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y())));
}
}
#else
Transform3d trafo = trafo_instance * v->get_matrix();
const indexed_triangle_set &its = v->mesh().its;
if (its.vertices.empty()) {
@ -935,10 +923,10 @@ Polygon ModelObject::convex_hull_2d(const Transform3d &trafo_instance) const
pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y())));
}
}
#endif // ENABLE_ALLOW_NEGATIVE_Z
}
return Geometry::convex_hull(std::move(pts));
}
#endif // ENABLE_ALLOW_NEGATIVE_Z
void ModelObject::center_around_origin(bool include_modifiers)
{

View file

@ -11,6 +11,8 @@
#include <Eigen/Geometry>
#include "LocalesUtils.hpp"
namespace Slic3r {
class BoundingBox;
@ -88,10 +90,10 @@ inline Vec3d unscale(coord_t x, coord_t y, coord_t z) { return Vec3d(unscale<d
inline Vec3d unscale(const Vec3crd &pt) { return Vec3d(unscale<double>(pt.x()), unscale<double>(pt.y()), unscale<double>(pt.z())); }
inline Vec3d unscale(const Vec3d &pt) { return Vec3d(unscale<double>(pt.x()), unscale<double>(pt.y()), unscale<double>(pt.z())); }
inline std::string to_string(const Vec2crd &pt) { return std::string("[") + std::to_string(pt.x()) + ", " + std::to_string(pt.y()) + "]"; }
inline std::string to_string(const Vec2d &pt) { return std::string("[") + std::to_string(pt.x()) + ", " + std::to_string(pt.y()) + "]"; }
inline std::string to_string(const Vec3crd &pt) { return std::string("[") + std::to_string(pt.x()) + ", " + std::to_string(pt.y()) + ", " + std::to_string(pt.z()) + "]"; }
inline std::string to_string(const Vec3d &pt) { return std::string("[") + std::to_string(pt.x()) + ", " + std::to_string(pt.y()) + ", " + std::to_string(pt.z()) + "]"; }
inline std::string to_string(const Vec2crd &pt) { return std::string("[") + float_to_string_decimal_point(pt.x()) + ", " + float_to_string_decimal_point(pt.y()) + "]"; }
inline std::string to_string(const Vec2d &pt) { return std::string("[") + float_to_string_decimal_point(pt.x()) + ", " + float_to_string_decimal_point(pt.y()) + "]"; }
inline std::string to_string(const Vec3crd &pt) { return std::string("[") + float_to_string_decimal_point(pt.x()) + ", " + float_to_string_decimal_point(pt.y()) + ", " + float_to_string_decimal_point(pt.z()) + "]"; }
inline std::string to_string(const Vec3d &pt) { return std::string("[") + float_to_string_decimal_point(pt.x()) + ", " + float_to_string_decimal_point(pt.y()) + ", " + float_to_string_decimal_point(pt.z()) + "]"; }
std::vector<Vec3f> transform(const std::vector<Vec3f>& points, const Transform3f& t);
Pointf3s transform(const Pointf3s& points, const Transform3d& t);

View file

@ -166,8 +166,8 @@ struct FaceHash {
Vec<3, int64_t> c = a.cross(b) + (pts[0] + pts[1] + pts[2]) / 3;
// Return a concatenated string representation of the coordinates
return std::to_string(c(0)) + std::to_string(c(1)) + std::to_string(c(2));
};
return float_to_string_decimal_point(c(0)) + float_to_string_decimal_point(c(1)) + float_to_string_decimal_point(c(2));
}
FaceHash(const indexed_triangle_set &its)
{

View file

@ -611,7 +611,7 @@ TriangleMesh TriangleMesh::convex_hull_3d() const
return output_mesh;
}
std::vector<ExPolygons> TriangleMesh::slice(const std::vector<double> &z)
std::vector<ExPolygons> TriangleMesh::slice(const std::vector<double> &z) const
{
// convert doubles to floats
std::vector<float> z_f(z.begin(), z.end());
@ -911,16 +911,16 @@ void its_collect_mesh_projection_points_above(const indexed_triangle_set &its, c
all_pts.reserve(all_pts.size() + its.indices.size() * 3);
for (const stl_triangle_vertex_indices &tri : its.indices) {
const Vec3f pts[3] = { transform_fn(its.vertices[tri(0)]), transform_fn(its.vertices[tri(1)]), transform_fn(its.vertices[tri(2)]) };
int iprev = 3;
int iprev = 2;
for (int iedge = 0; iedge < 3; ++ iedge) {
const Vec3f &p1 = pts[iprev];
const Vec3f &p2 = pts[iedge];
if ((p1.z() < z && p2.z() > z) || (p2.z() < z && p1.z() > z)) {
// Edge crosses the z plane. Calculate intersection point with the plane.
float t = z / (p2.z() - p1.z());
all_pts.emplace_back(scaled<coord_t>(p1.x() + (p2.x() - p1.x()) * t), scaled<coord_t>(p2.x() + (p2.y() - p2.y()) * t));
float t = (z - p1.z()) / (p2.z() - p1.z());
all_pts.emplace_back(scaled<coord_t>(p1.x() + (p2.x() - p1.x()) * t), scaled<coord_t>(p1.y() + (p2.y() - p1.y()) * t));
}
if (p2.z() > z)
if (p2.z() >= z)
all_pts.emplace_back(scaled<coord_t>(p2.x()), scaled<coord_t>(p2.y()));
iprev = iedge;
}

View file

@ -65,7 +65,7 @@ public:
// Returns the convex hull of this TriangleMesh
TriangleMesh convex_hull_3d() const;
// Slice this mesh at the provided Z levels and return the vector
std::vector<ExPolygons> slice(const std::vector<double>& z);
std::vector<ExPolygons> slice(const std::vector<double>& z) const;
void reset_repair_stats();
bool needed_repair() const;
void require_shared_vertices();

View file

@ -23,6 +23,8 @@
#endif
#include <assert.h>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_guard.hpp>
#if defined(SLIC3R_DEBUG) || defined(SLIC3R_DEBUG_SLICE_PROCESSING)
#include "SVG.hpp"