From f78aa930d6bd089426742bc56a202c46e0bb95a9 Mon Sep 17 00:00:00 2001 From: Adrian Scripca Date: Tue, 16 May 2023 14:07:29 +0300 Subject: [PATCH] Starting to refactor the GUI --- CMakeLists.txt | 2 +- main.cpp | 1115 +----------------------------------------------- sender_app.cpp | 1029 ++++++++++++++++++++++++++++++++++++++++++++ sender_app.h | 144 +++++++ 4 files changed, 1177 insertions(+), 1113 deletions(-) create mode 100644 sender_app.cpp create mode 100644 sender_app.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a55905..b3fb063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/main.cpp b/main.cpp index 9b0a933..425afce 100644 --- a/main.cpp +++ b/main.cpp @@ -1,1114 +1,7 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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 -#include "grbl.h" -#include -#include -#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 -#include -#include // glm::vec3 -#include // glm::vec4 -#include // glm::mat4 -#include // glm::translate, glm::rotate, glm::scale -#include // glm::perspective -#include // glm::pi -#include - -using namespace nanogui; - -grbl::machine cnc{}; - -class SenderApp : public Screen { -public: - - Window *window; - grbl::jog_state jog; - TextBox *txt_status; - TextBox *txt_message; - nanogui::Color color_red = nanogui::Color(255, 0, 0, 255); - nanogui::Color color_green = nanogui::Color(0, 255, 0, 255); - int last_alarm = 0; - grbl::program pgm; - Button *btn_load_program, *btn_check_program, *btn_run_program; - - std::vector jog_distances = {"0.01", "0.1", "1", "10"}; - std::vector jog_feed_rates = {"5", "100", "500", "1000"}; - - 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 - - Widget *info_layer, *heightmap_layer; - TabWidget *tab_widget; - VScrollPanel *settings_vscroll; - Widget *settings_layer; - - VScrollPanel *parameters_vscroll; - Widget *parameters_layer; - TextBox *mpos_x_text, *mpos_y_text, *mpos_z_text; - ComboBox *cbo_work_offset, *cbo_tool, *cbo_jog_feed_rates, *cbo_jog_distance; - - ToolButton *btn_pin_door, *btn_pin_hold, *btn_pin_reset, *btn_pin_cycle_start; - ToolButton *btn_pin_limit_x, *btn_pin_limit_y, *btn_pin_limit_z, *btn_pin_probe; - - Button *btn_keyboard_jog; - std::stringstream dro_ss; - grbl::heightmap heightmap_grid; - - - SenderApp() : Screen(Vector2i(1024, 768), "GRBL Sender") { - inc_ref(); - - window = new Window(this, "Machine status"); - window->set_position(Vector2i(0, 0)); - window->set_layout(new BoxLayout(nanogui::Orientation::Vertical)); - - tab_widget = window->add(); - tab_widget->set_tabs_draggable(true); - tab_widget->set_callback([&](int index) { - tab_widget->set_selected_index(index); - }); - - info_layer = tab_widget->add(); - info_layer->set_layout(new GroupLayout(10, 20, 30, 0)); - info_layer->add