Starting to refactor the GUI

This commit is contained in:
2023-05-16 14:07:29 +03:00
parent 6776e22ab4
commit f78aa930d6
4 changed files with 1177 additions and 1113 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(TESTS grbl_test.cpp heightmap_test.cpp)
set(TERJE terje/gcode.cpp terje/gcode.h terje/gcode_parser.h terje/gcode_parser.cpp terje/machine.h terje/machine.cpp terje/grbl.h terje/grbl.cpp terje/comms.h terje/comms.cpp terje/telnet.h terje/telnet.cpp terje/measure_view_model.h terje/measure_view_model.cpp)
set(SENDER_GRBL_SRC grbl.h grbl.cpp grbl_communication.h grbl_communication.cpp grbl_machine.h grbl_machine.cpp string_utils.h render.h render.cpp heightmap.h heightmap.cpp gcode_parser.h gcode_parser.cpp gcode_commands.h gcode_commands.cpp)
set(SENDER_GRBL_SRC grbl.h grbl.cpp grbl_communication.h grbl_communication.cpp grbl_machine.h grbl_machine.cpp string_utils.h render.h render.cpp heightmap.h heightmap.cpp gcode_parser.h gcode_parser.cpp gcode_commands.h gcode_commands.cpp sender_app.h sender_app.cpp)
add_executable(sender main.cpp ${TESTS} ${TERJE} ${SENDER_GRBL_SRC})
target_link_libraries(sender nanogui GL gtest gtest_main)
+3 -1112
View File
File diff suppressed because it is too large Load Diff
+1029
View File
File diff suppressed because it is too large Load Diff
+144
View File
@@ -0,0 +1,144 @@
#pragma once
#include <nanogui/opengl.h>
#include <nanogui/screen.h>
#include <nanogui/window.h>
#include <nanogui/layout.h>
#include <nanogui/label.h>
#include <nanogui/button.h>
#include <nanogui/popupbutton.h>
#include <nanogui/progressbar.h>
#include <nanogui/messagedialog.h>
#include <nanogui/texture.h>
#include <nanogui/textarea.h>
#include <nanogui/textbox.h>
#include <nanogui/tabwidget.h>
#include <nanogui/shader.h>
#include <nanogui/renderpass.h>
#include <iostream>
#include <memory>
#include "grbl_machine.h"
#include "render.h"
#include "glm/glm.hpp"
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#if defined(_MSC_VER)
# pragma warning (disable: 4505) // don't warn about dead code in stb_image.h
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wunused-function"
#endif
#include <stb_image.h>
#include "grbl.h"
#include <gtest/gtest.h>
#include <regex>
#include "grbl_machine.h"
#include "string_utils.h"
#include "render.h"
#include "glm/gtx/quaternion.hpp"
#include "nanogui/nanogui.h"
#include "glm/gtc/matrix_inverse.hpp"
#include "heightmap.h"
#include <glm/ext/quaternion_float.hpp>
#include <glm/ext/quaternion_trigonometric.hpp>
#include <glm/vec3.hpp> // glm::vec3
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale
#include <glm/ext/matrix_clip_space.hpp> // glm::perspective
#include <glm/ext/scalar_constants.hpp> // glm::pi
#include <fstream>
class SenderApp : public nanogui::Screen {
public:
SenderApp();
private:
void add_z_probe_markup();
void add_work_parameters_markup();
void add_status_markup();
void add_jogging_markup();
void add_dro_markup();
void add_program_extents();
void add_heightmap_markup();
void add_pins_markup();
static void save_heightmap(const grbl::heightmap &grid, std::string path);
grbl::heightmap load_heightmap(std::string path);
void update_dro();
void update_grid();
void refresh_offset();
void fill_heightmap_controls_from_grid(const grbl::heightmap &grid) const;
void fill_heightmap_from_model() const;
void fill_in_parameters();
void fill_in_settings();
void init_program_geometry();
void set_program_extents() const;
bool resize_event(const nanogui::Vector2i &size) override;
bool keyboard_event(int key, int scancode, int action, int modifiers) override;
bool mouse_motion_event(const nanogui::Vector2i &p,
const nanogui::Vector2i &rel,
int button,
int modifiers) override;
bool scroll_event(const nanogui::Vector2i &p, const nanogui::Vector2f &rel) override;
void draw(NVGcontext *ctx) override;
void draw_contents() override;
grbl::machine cnc{};
private:
nanogui::TextBox *txt_min_z = nullptr, *txt_feed = nullptr;
nanogui::TextBox *txt_heightmap_from_x = nullptr, *txt_heightmap_from_y = nullptr;
nanogui::TextBox *txt_heightmap_to_x = nullptr, *txt_heightmap_to_y = nullptr;
nanogui::TextBox *txt_heightmap_res = nullptr;
nanogui::TextBox *txt_clearance_height = nullptr, *txt_start_probing_at = nullptr, *txt_max_negative_z = nullptr, *txt_final_z_height = nullptr;
nanogui::Window *window = nullptr;
nanogui::TextBox *txt_status = nullptr;
nanogui::TextBox *txt_message = nullptr;
nanogui::Color color_red = nanogui::Color(255, 0, 0, 255);
nanogui::Color color_green = nanogui::Color(0, 255, 0, 255);
nanogui::Button *btn_load_program = nullptr, *btn_check_program = nullptr, *btn_run_program = nullptr;
nanogui::Widget *info_layer = nullptr, *heightmap_layer = nullptr;
nanogui::TabWidget *tab_widget = nullptr;
nanogui::VScrollPanel *settings_vscroll = nullptr;
nanogui::Widget *settings_layer = nullptr;
nanogui::VScrollPanel *parameters_vscroll = nullptr;
nanogui::Widget *parameters_layer = nullptr;
nanogui::TextBox *mpos_x_text = nullptr, *mpos_y_text = nullptr, *mpos_z_text = nullptr;
nanogui::ComboBox *cbo_work_offset = nullptr, *cbo_tool = nullptr, *cbo_jog_feed_rates = nullptr, *cbo_jog_distance = nullptr;
nanogui::ToolButton *btn_pin_door = nullptr, *btn_pin_hold = nullptr, *btn_pin_reset = nullptr, *btn_pin_cycle_start = nullptr;
nanogui::ToolButton *btn_pin_limit_x = nullptr, *btn_pin_limit_y = nullptr, *btn_pin_limit_z = nullptr, *btn_pin_probe = nullptr;
nanogui::Button *btn_keyboard_jog = nullptr;
std::stringstream dro_ss;
grbl::heightmap heightmap_grid;
nanogui::TextBox *extents_min_x = nullptr, *extents_max_x = nullptr;
nanogui::TextBox *extents_min_y = nullptr, *extents_max_y = nullptr;
nanogui::TextBox *extents_min_z = nullptr, *extents_max_z = nullptr;
nanogui::ProgressBar *m_progress = nullptr;
nanogui::ref<nanogui::RenderPass> m_render_pass;
using ImageHolder = std::unique_ptr<uint8_t[], void (*)(void *)>;
std::vector<std::pair<nanogui::ref<nanogui::Texture>, ImageHolder>> m_images;
std::vector<std::string> jog_distances = {"0.01", "0.1", "1", "10"};
std::vector<std::string> jog_feed_rates = {"5", "100", "500", "1000"};
int last_alarm = 0;
grbl::program pgm{};
grbl::realtime_status_report last_report;
grbl::jog_state jog;
grbl::program_renderer renderer{};
glm::vec3 cam_target = glm::vec3(0);
glm::vec3 cam_pan = glm::vec3(0);
float cam_zoom = 0;
glm::quat cam_src_rotation = glm::quat(1.0, 0.0, 0.0, 0.0); // identity quaternion
};