Skip to content

Commit

Permalink
Merge pull request #21 from prusa3d/et_dev
Browse files Browse the repository at this point in the history
Et dev
  • Loading branch information
enricoturri1966 authored Sep 6, 2023
2 parents 6b4e4f9 + d1fdab1 commit e1f55ff
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
18 changes: 12 additions & 6 deletions src/LibBGCode/cmd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ bool parse_args(int argc, const char* argv[], std::string& src_filename, bool& s

size_t pos = arguments[1].find_last_of(".");
if (pos == std::string::npos) {
std::cout << "Invalid filename " << arguments[1] << " (required .gcode extension)\n";
std::cout << "Invalid filename " << arguments[1] << " (required extensions: .gcode or .bgcode or .bgc)\n";
return false;
}
const std::string_view extension = arguments[1].substr(pos);
if (extension != ".gcode" && extension != ".GCODE") {
std::cout << "Found invalid extension '" << extension << "' (required .gcode extension)\n";
if (extension != ".gcode" && extension != ".GCODE" &&
extension != ".bgcode" && extension != ".BGCODE" &&
extension != ".bgc" && extension != ".BGC") {
std::cout << "Found invalid extension '" << extension << "' (required extensions: .gcode or .bgcode or .bgc)\n";
return false;
}
src_filename = arguments[1];
Expand Down Expand Up @@ -173,9 +175,13 @@ int main(int argc, const char* argv[])
}
ScopedFile scoped_src_file(src_file);

const std::string src_stem = src_filename.substr(0, src_filename.find_last_of("."));
const std::string dst = src_is_binary ? "_ascii" : "_binary";
const std::string dst_filename = src_stem + dst + ".gcode";
const size_t pos = src_filename.find_last_of(".");
const std::string src_stem = src_filename.substr(0, pos);
const std::string src_extension = (pos != std::string::npos) ? src_filename.substr(pos) : "";
const std::string dst_extension = src_is_binary ?
(src_extension == ".gcode") ? ".1.gcode" : ".gcode" :
(src_extension == ".bgcode") ? ".1.bgcode" : ".bgcode";
const std::string dst_filename = src_stem + dst_extension;

// Open destination file
FILE* dst_file = boost::nowide::fopen(dst_filename.c_str(), "wb");
Expand Down
12 changes: 6 additions & 6 deletions tests/convert/convert_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ TEST_CASE("Convert from binary to ascii", "[Convert]")
{
std::cout << "\nTEST: Convert from binary to ascii\n";

const std::string src_filename = std::string(TEST_DATA_DIR) + "/mini_cube_binary.gcode";
const std::string dst_filename = std::string(TEST_DATA_DIR) + "/mini_cube_binary_converted.gcode";
const std::string check_filename = std::string(TEST_DATA_DIR) + "/mini_cube_binary_ascii.gcode";
const std::string src_filename = std::string(TEST_DATA_DIR) + "/mini_cube_b.bgcode";
const std::string dst_filename = std::string(TEST_DATA_DIR) + "/mini_cube_b.gcode";
const std::string check_filename = std::string(TEST_DATA_DIR) + "/mini_cube_b_ref.bgcode";

// convert from binary to ascii
binary_to_ascii(src_filename, dst_filename);
Expand All @@ -123,8 +123,8 @@ TEST_CASE("Convert from ascii to binary", "[Convert]")
std::cout << "\nTEST: Convert from ascii to binary\n";

// convert from ascii to binary
const std::string ab_src_filename = std::string(TEST_DATA_DIR) + "/mini_cube_ascii.gcode";
const std::string ab_dst_filename = std::string(TEST_DATA_DIR) + "/mini_cube_ascii_converted.gcode";
const std::string ab_src_filename = std::string(TEST_DATA_DIR) + "/mini_cube_a.gcode";
const std::string ab_dst_filename = std::string(TEST_DATA_DIR) + "/mini_cube_a.bgcode";
BinarizerConfig config;
config.checksum = EChecksumType::CRC32;
config.compression.file_metadata = ECompressionType::None;
Expand All @@ -138,7 +138,7 @@ TEST_CASE("Convert from ascii to binary", "[Convert]")

// convert back from binary to ascii
const std::string ba_src_filename = ab_dst_filename;
const std::string ba_dst_filename = std::string(TEST_DATA_DIR) + "/mini_cube_ascii_converted_converted.gcode";
const std::string ba_dst_filename = std::string(TEST_DATA_DIR) + "/mini_cube_a_final.gcode";
binary_to_ascii(ba_src_filename, ba_dst_filename);

// compare results
Expand Down
4 changes: 2 additions & 2 deletions tests/core/core_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static std::string thumbnail_format_as_string(EThumbnailFormat type)

TEST_CASE("File transversal", "[Core]")
{
const std::string filename = std::string(TEST_DATA_DIR) + "/mini_cube_binary.gcode";
const std::string filename = std::string(TEST_DATA_DIR) + "/mini_cube_b.bgcode";
std::cout << "\nTEST: File transversal\n";
std::cout << "File:" << filename << "\n";

Expand Down Expand Up @@ -161,7 +161,7 @@ static std::string thumbnail_format_as_string(EThumbnailFormat type)

TEST_CASE("Search for GCode blocks", "[Core]")
{
const std::string filename = std::string(TEST_DATA_DIR) + "/mini_cube_binary.gcode";
const std::string filename = std::string(TEST_DATA_DIR) + "/mini_cube_b.bgcode";
std::cout << "\nTEST: Search for GCode blocks\n";
std::cout << "File:" << filename << "\n";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e1f55ff

Please sign in to comment.