mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-08 00:01:09 +00:00
perf: speed up G-code export by up to 8% via cheaper G-code text building (#16108)
This commit is contained in:
@@ -454,6 +454,65 @@ TEST_CASE("EXTRUDER_LIMIT per-extruder clamping and max fallback", "[GCodeWriter
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Acceleration and velocity limit commands print their values in general notation", "[GCodeWriter]")
|
||||
{
|
||||
enum class Command { Print, Travel, KlipperLimits };
|
||||
struct Case
|
||||
{
|
||||
GCodeFlavor flavor;
|
||||
Command command;
|
||||
unsigned int acceleration;
|
||||
double jerk;
|
||||
bool comments;
|
||||
std::vector<std::string> present;
|
||||
std::vector<std::string> absent;
|
||||
};
|
||||
// accel_to_decel_factor is 50%, so ACCEL_TO_DECEL is half the acceleration.
|
||||
const Case c = GENERATE(values<Case>({
|
||||
{gcfKlipper, Command::KlipperLimits, 2000000, 25. / 3., false,
|
||||
{"SET_VELOCITY_LIMIT ACCEL=2000000 ", "ACCEL_TO_DECEL=1e+06 ", "SQUARE_CORNER_VELOCITY=8.33333\n"}, {}},
|
||||
{gcfKlipper, Command::KlipperLimits, 12345, 0., false, {"ACCEL=12345 ", "ACCEL_TO_DECEL=6172.5\n"}, {"SQUARE_CORNER_VELOCITY"}},
|
||||
{gcfKlipper, Command::KlipperLimits, 0, 0.25, true, {"SQUARE_CORNER_VELOCITY=0.25 ", "; adjust VELOCITY_LIMIT"}, {"ACCEL"}},
|
||||
{gcfKlipper, Command::Print, 3001, 0., true, {"ACCEL=3001 ", "ACCEL_TO_DECEL=1500.5 ", "; adjust ACCEL_TO_DECEL", "; adjust acceleration"}, {}},
|
||||
{gcfMarlinFirmware, Command::Print, 2500, 0., false, {"M204 P2500\n"}, {}},
|
||||
{gcfMarlinFirmware, Command::Travel, 7000, 0., false, {"M204 T7000\n"}, {}},
|
||||
{gcfRepRapFirmware, Command::Travel, 7000, 0., true, {"M204 T7000 ", "; adjust acceleration"}, {}},
|
||||
{gcfMarlinLegacy, Command::Print, 2500, 0., false, {"M204 S2500\n"}, {}},
|
||||
{gcfRepetier, Command::Print, 2500, 0., false, {"M201 X2500 Y2500\n"}, {}},
|
||||
{gcfRepetier, Command::Travel, 7000, 0., false, {"M202 X7000 Y7000\n"}, {}},
|
||||
}));
|
||||
|
||||
struct CommentGuard
|
||||
{
|
||||
bool saved = GCodeWriter::full_gcode_comment;
|
||||
~CommentGuard() { GCodeWriter::full_gcode_comment = saved; }
|
||||
} comment_guard;
|
||||
GCodeWriter::full_gcode_comment = c.comments;
|
||||
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_key_value("gcode_flavor", new ConfigOptionEnum<GCodeFlavor>(c.flavor));
|
||||
config.set_key_value("accel_to_decel_enable", new ConfigOptionBool(true));
|
||||
config.set_key_value("accel_to_decel_factor", new ConfigOptionPercent(50));
|
||||
for (const char *limit : {"machine_max_acceleration_extruding", "machine_max_acceleration_travel", "machine_max_acceleration_x",
|
||||
"machine_max_acceleration_y", "machine_max_jerk_x", "machine_max_jerk_y"}) {
|
||||
std::vector<double> &values = config.option<ConfigOptionFloats>(limit)->values;
|
||||
std::fill(values.begin(), values.end(), 0.);
|
||||
}
|
||||
PrintConfig print_config;
|
||||
print_config.apply(config, true);
|
||||
GCodeWriter writer;
|
||||
writer.apply_print_config(print_config);
|
||||
|
||||
const std::string line = c.command == Command::Print ? writer.set_print_acceleration(c.acceleration) :
|
||||
c.command == Command::Travel ? writer.set_travel_acceleration(c.acceleration) :
|
||||
writer.set_accel_and_jerk(c.acceleration, c.jerk);
|
||||
INFO(line);
|
||||
for (const std::string &token : c.present)
|
||||
CHECK_THAT(line, Catch::Matchers::ContainsSubstring(token));
|
||||
for (const std::string &token : c.absent)
|
||||
CHECK_THAT(line, !Catch::Matchers::ContainsSubstring(token));
|
||||
}
|
||||
|
||||
SCENARIO("Extruder reads the injected config column", "[GCodeWriter][H2C]") {
|
||||
GIVEN("A writer whose per-variant arrays hold three columns for two filaments") {
|
||||
GCodeWriter writer;
|
||||
|
||||
Reference in New Issue
Block a user