diff --git a/main.cpp b/main.cpp index 4f31365..99fa1be 100644 --- a/main.cpp +++ b/main.cpp @@ -459,10 +459,10 @@ public: TextBox *txt_heightmap_from_x, *txt_heightmap_from_y; TextBox *txt_heightmap_to_x, *txt_heightmap_to_y; - TextBox *txt_grid_res; + TextBox *txt_heightmap_res; TextBox *txt_clearance_height, *txt_start_probing_at, *txt_max_negative_z, *txt_final_z_height; - void save_heightmap(const grbl::heightmap& grid, std::string path) { + static void save_heightmap(const grbl::heightmap& grid, std::string path) { std::ofstream out(path); if (out) { out << "from_x:" << grid.from_x << std::endl; @@ -477,6 +477,50 @@ public: } } + grbl::heightmap load_heightmap(std::string path) { + grbl::heightmap result{}; + + std::ifstream in_file(path); + if (in_file) { + float from_x, from_y; + float to_x, to_y; + float resolution; + size_t probe_location = 0; + + for (std::string line; std::getline(in_file, line);) { + auto pieces = split_string(line, ":"); + if (pieces[0] == "from_x") { + from_x = std::stof(pieces[1]); + } else if (pieces[0] == "from_y") { + from_y = std::stof(pieces[1]); + } else if (pieces[0] == "to_x") { + to_x = std::stof(pieces[1]); + } else if (pieces[0] == "to_y") { + to_y = std::stof(pieces[1]); + } else if (pieces[0] == "resolution") { + resolution = std::stof(pieces[1]); + } else if (pieces[0] == "probes") { + result = grbl::heightmap::from_params(from_x, from_y, to_x, to_y, resolution); + } else { + result.vertices[probe_location].x = std::stof(pieces[0]); + result.vertices[probe_location].y = std::stof(pieces[1]); + result.vertices[probe_location].z = std::stof(pieces[2]); + probe_location++; + } + } + } + + return result; + } + + void fill_heightmap_from_grid(const grbl::heightmap& grid) { + txt_heightmap_from_x->set_value(std::to_string(grid.from_x)); + txt_heightmap_from_y->set_value(std::to_string(grid.from_y)); + txt_heightmap_to_x->set_value(std::to_string(grid.to_x)); + txt_heightmap_to_y->set_value(std::to_string(grid.to_y)); + txt_heightmap_res->set_value(std::to_string(grid.resolution)); + } + void add_heightmap_markup() { heightmap_layer->add