Skip to content

Commit

Permalink
Moved target machine name to end of header (#1971)
Browse files Browse the repository at this point in the history
  • Loading branch information
jellespijker authored Oct 23, 2023
2 parents d07570e + 21ee763 commit f1e7499
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ std::string GCodeExport::getFileHeader(
break;
default:
prefix << ";FLAVOR:" << flavorToString(flavor) << new_line;
prefix << ";TARGET_MACHINE.NAME:" << transliterate(machine_name) << new_line;
prefix << ";TIME:" << ((print_time) ? static_cast<int>(*print_time) : 6666) << new_line;
if (flavor == EGCodeFlavor::ULTIGCODE)
{
Expand Down Expand Up @@ -309,6 +308,7 @@ std::string GCodeExport::getFileHeader(
prefix << ";MAXX:" << INT2MM(total_bounding_box.max.x) << new_line;
prefix << ";MAXY:" << INT2MM(total_bounding_box.max.y) << new_line;
prefix << ";MAXZ:" << INT2MM(total_bounding_box.max.z) << new_line;
prefix << ";TARGET_MACHINE.NAME:" << transliterate(machine_name) << new_line;
}

return prefix.str();
Expand Down
66 changes: 38 additions & 28 deletions tests/GCodeExportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// CuraEngine is released under the terms of the AGPLv3 or higher

#include "gcodeExport.h" // The unit under test.

#include "Application.h" // To set up a slice with settings.
#include "RetractionConfig.h" // For extruder switch tests.
#include "Slice.h" // To set up a slice with settings.
#include "WipeScriptConfig.h" // For wipe script tests.
#include "arcus/MockCommunication.h" // To prevent calls to any missing Communication class.
#include "utils/Coord_t.h"
#include "utils/Date.h" // To check the Griffin header.

#include <gtest/gtest.h>

// NOLINTBEGIN(*-magic-numbers)
Expand Down Expand Up @@ -101,12 +103,13 @@ TEST_F(GCodeExportTest, CommentMultiLine)
"You can honestly say\n"
"You made on that day\n"
"A Chilean chinchilla's chin chilly");
EXPECT_EQ(std::string(";If you catch a chinchilla in Chile\n"
";And cut off its beard, willy-nilly\n"
";You can honestly say\n"
";You made on that day\n"
";A Chilean chinchilla's chin chilly\n"),
output.str())
EXPECT_EQ(
std::string(";If you catch a chinchilla in Chile\n"
";And cut off its beard, willy-nilly\n"
";You can honestly say\n"
";You made on that day\n"
";A Chilean chinchilla's chin chilly\n"),
output.str())
<< "Each line must be preceded by a semicolon.";
}

Expand All @@ -115,10 +118,11 @@ TEST_F(GCodeExportTest, CommentMultiple)
gcode.writeComment("Thunderbolt and lightning");
gcode.writeComment("Very very frightening me");
gcode.writeComment(" - Galileo (1638)");
EXPECT_EQ(std::string(";Thunderbolt and lightning\n"
";Very very frightening me\n"
"; - Galileo (1638)\n"),
output.str())
EXPECT_EQ(
std::string(";Thunderbolt and lightning\n"
";Very very frightening me\n"
"; - Galileo (1638)\n"),
output.str())
<< "Semicolon before each line, and newline in between.";
}

Expand Down Expand Up @@ -328,9 +332,10 @@ TEST_F(GCodeExportTest, HeaderUltiGCode)

std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used);

EXPECT_EQ(result,
";FLAVOR:UltiGCode\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n;TIME:1337\n;MATERIAL:100\n;MATERIAL2:200\n;NOZZLE_DIAMETER:0.4\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;"
"MAXY:1\n;MAXZ:1\n");
EXPECT_EQ(
result,
";FLAVOR:UltiGCode\n;TIME:1337\n;MATERIAL:100\n;MATERIAL2:200\n;NOZZLE_DIAMETER:0.4\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;"
"MAXY:1\n;MAXZ:1\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n");
}

TEST_F(GCodeExportTest, HeaderRepRap)
Expand All @@ -347,9 +352,10 @@ TEST_F(GCodeExportTest, HeaderRepRap)

std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used);

EXPECT_EQ(result,
";FLAVOR:RepRap\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n;TIME:1337\n;Filament used: 0.02m, 0.05m\n;Layer height: "
"0.123\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;MAXY:1\n;MAXZ:1\n");
EXPECT_EQ(
result,
";FLAVOR:RepRap\n;TIME:1337\n;Filament used: 0.02m, 0.05m\n;Layer height: "
"0.123\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;MAXY:1\n;MAXZ:1\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n");
}

TEST_F(GCodeExportTest, HeaderMarlin)
Expand All @@ -366,9 +372,10 @@ TEST_F(GCodeExportTest, HeaderMarlin)

std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used);

EXPECT_EQ(result,
";FLAVOR:Marlin\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n;TIME:1337\n;Filament used: 0.02m, 0.05m\n;Layer height: "
"0.123\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;MAXY:1\n;MAXZ:1\n");
EXPECT_EQ(
result,
";FLAVOR:Marlin\n;TIME:1337\n;Filament used: 0.02m, 0.05m\n;Layer height: "
"0.123\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;MAXY:1\n;MAXZ:1\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n");
}

TEST_F(GCodeExportTest, HeaderMarlinVolumetric)
Expand All @@ -383,9 +390,10 @@ TEST_F(GCodeExportTest, HeaderMarlinVolumetric)

std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used);

EXPECT_EQ(result,
";FLAVOR:Marlin(Volumetric)\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n;TIME:1337\n;Filament used: 100mm3, 200mm3\n;Layer height: "
"0.123\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;MAXY:1\n;MAXZ:1\n");
EXPECT_EQ(
result,
";FLAVOR:Marlin(Volumetric)\n;TIME:1337\n;Filament used: 100mm3, 200mm3\n;Layer height: "
"0.123\n;MINX:0\n;MINY:0\n;MINZ:0\n;MAXX:1\n;MAXY:1\n;MAXZ:1\n;TARGET_MACHINE.NAME:Your favourite 3D printer\n");
}

/*
Expand All @@ -405,8 +413,9 @@ TEST_F(GCodeExportTest, EVsMmVolumetric)
"area of the filament to convert the volume to a length.";

constexpr double mm_input = 33.0;
EXPECT_EQ(gcode.mmToE(mm_input), mm_input * filament_area) << "Since the input mm is linear but the E output must be volumetric, we need to multiply by the cross-sectional area to convert "
"length to volume.";
EXPECT_EQ(gcode.mmToE(mm_input), mm_input * filament_area)
<< "Since the input mm is linear but the E output must be volumetric, we need to multiply by the cross-sectional area to convert "
"length to volume.";

constexpr double e_input = 100.0;
EXPECT_EQ(gcode.eToMm3(e_input, 0), e_input) << "Since the E is volumetric and mm3 is also volumetric, the output needs to be the same.";
Expand All @@ -431,8 +440,9 @@ TEST_F(GCodeExportTest, EVsMmLinear)
}

constexpr double mm3_input = 33.0;
EXPECT_EQ(gcode.mm3ToE(mm3_input), mm3_input / filament_area) << "Since the input mm3 is volumetric but the E output must be linear, we need to divide by the cross-sectional area to convert "
"volume to length.";
EXPECT_EQ(gcode.mm3ToE(mm3_input), mm3_input / filament_area)
<< "Since the input mm3 is volumetric but the E output must be linear, we need to divide by the cross-sectional area to convert "
"volume to length.";

constexpr double e_input = 100.0;
EXPECT_EQ(gcode.eToMm3(e_input, 0), e_input * filament_area) << "Since the input E is linear but the output must be volumetric, we "
Expand Down Expand Up @@ -492,7 +502,7 @@ TEST_F(GCodeExportTest, WriteZHopStartCustomSpeed)
Application::getInstance().current_slice->scene.extruders[gcode.current_extruder].settings.add("speed_z_hop", "1"); // 60mm/min.
gcode.current_layer_z = 2000;
constexpr coord_t hop_height = 3000;
constexpr Velocity speed { 4.0 }; // 240 mm/min.
constexpr Velocity speed{ 4.0 }; // 240 mm/min.
gcode.writeZhopStart(hop_height, speed);
EXPECT_EQ(std::string("G1 F240 Z5\n"), output.str()) << "Custom provided speed should be used.";
}
Expand Down Expand Up @@ -520,7 +530,7 @@ TEST_F(GCodeExportTest, WriteZHopEndCustomSpeed)
Application::getInstance().current_slice->scene.extruders[gcode.current_extruder].settings.add("speed_z_hop", "1");
gcode.current_layer_z = 2000;
gcode.is_z_hopped = 3000;
constexpr Velocity speed { 4.0 }; // 240 mm/min.
constexpr Velocity speed{ 4.0 }; // 240 mm/min.
gcode.writeZhopEnd(speed);
EXPECT_EQ(std::string("G1 F240 Z2\n"), output.str()) << "Custom provided speed should be used.";
}
Expand Down

0 comments on commit f1e7499

Please sign in to comment.