diff --git a/data/rofi/rofiworlds/complex_robot.json b/data/rofi/rofiworlds/complex_robot.json new file mode 100644 index 0000000000000000000000000000000000000000..18de723016668b0b4be694e334ec0a23d0d9fc0b --- /dev/null +++ b/data/rofi/rofiworlds/complex_robot.json @@ -0,0 +1,165 @@ +{ + "modules" : [ + { + "alpha" : -90, + "beta" : 0, + "gamma" : -83, + "id" : 2, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : -90, + "gamma" : -88, + "id" : 4, + "type" : "universal" + }, + { + "alpha" : -45, + "beta" : -34, + "gamma" : 34, + "id" : 0, + "type" : "universal" + }, + { + "alpha" : -90, + "beta" : -85, + "gamma" : 0, + "id" : 1, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 45, + "gamma" : -0, + "id" : 5, + "type" : "universal" + }, + { + "width" : 3, + "height" : 3, + "id" : 6, + "type" : "pad" + }, + { + "alpha" : 0, + "beta" : -79, + "gamma" : 0, + "id" : 3, + "type" : "universal" + } + ], + "spaceJoints" : [ + { + "point" : [ + -1.50364, + 1.8788, + -0.0393324 + ], + "joint" : { + "type" : "rigid", + "sourceToDestination" : [ + [ + 0.745908, + -0.463592, + 0.47823, + 0 + ], + [ + -0.172367, + 0.559193, + 0.810921, + 0 + ], + [ + -0.643359, + -0.687303, + 0.337199, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "positions" : [ + + ] + }, + "to" : { + "component" : 0, + "id" : 2 + } + } + ], + "moduleJoints" : [ + { + "from" : { + "id" : 1, + "connector" : "B-Z" + }, + "to" : { + "id" : 0, + "connector" : "B-Z" + }, + "orientation" : "West" + }, + { + "from" : { + "id" : 2, + "connector" : "B+X" + }, + "to" : { + "id" : 1, + "connector" : "A-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 3, + "connector" : "B-Z" + }, + "to" : { + "id" : 2, + "connector" : "B-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 4, + "connector" : "A-Z" + }, + "to" : { + "id" : 3, + "connector" : "B-X" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 5, + "connector" : "B-Z" + }, + "to" : { + "id" : 0, + "connector" : "A-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 6, + "connector" : 3 + }, + "to" : { + "id" : 5, + "connector" : "A-Z" + }, + "orientation" : "West" + } + ] + } \ No newline at end of file diff --git a/data/rofi/rofiworlds/loop.json b/data/rofi/rofiworlds/loop.json new file mode 100644 index 0000000000000000000000000000000000000000..cf117a7aa7d343110569e53c8cea0220926a83bc --- /dev/null +++ b/data/rofi/rofiworlds/loop.json @@ -0,0 +1,291 @@ +{ + "modules" : [ + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 5, + "type" : "universal" + }, + { + "alpha" : -90, + "beta" : 0, + "gamma" : 0, + "id" : 6, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 0, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 4, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 90, + "gamma" : 0, + "id" : 7, + "type" : "universal" + }, + { + "alpha" : -90, + "beta" : 0, + "gamma" : -0, + "id" : 1, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 2, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : -90, + "gamma" : 0, + "id" : 3, + "type" : "universal" + } + ], + "spaceJoints" : [ + { + "point" : [ + 2.17557e-06, + -1.96479, + 3.0346 + ], + "joint" : { + "type" : "rigid", + "sourceToDestination" : [ + [ + 1, + 2.11126e-07, + 3.6215e-07, + 0 + ], + [ + 3.5841e-07, + 0.0174526, + -0.999848, + 0 + ], + [ + -2.17414e-07, + 0.999848, + 0.0174526, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "positions" : [ + + ] + }, + "to" : { + "component" : 0, + "id" : 6 + } + }, + { + "point" : [ + 0.64881, + -5.34294, + 0 + ], + "joint" : { + "type" : "rigid", + "sourceToDestination" : [ + [ + 1, + 0, + 2.13163e-14, + 0 + ], + [ + -2.13163e-14, + 0, + 1, + 0 + ], + [ + 0, + -1, + 0, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "positions" : [ + + ] + }, + "to" : { + "component" : 0, + "id" : 5 + } + }, + { + "point" : [ + 1.79228, + -4.38025, + 0 + ], + "joint" : { + "type" : "rigid", + "sourceToDestination" : [ + [ + 1, + 0, + 2.13163e-14, + 0 + ], + [ + -2.13163e-14, + 0, + 1, + 0 + ], + [ + 0, + -1, + 0, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "positions" : [ + + ] + }, + "to" : { + "component" : 0, + "id" : 4 + } + }, + { + "point" : [ + 3.44712, + -1.74187, + 0 + ], + "joint" : { + "type" : "rigid", + "sourceToDestination" : [ + [ + 1, + 0, + 2.13163e-14, + 0 + ], + [ + -2.13163e-14, + 0, + 1, + 0 + ], + [ + 0, + -1, + 0, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "positions" : [ + + ] + }, + "to" : { + "component" : 0, + "id" : 2 + } + } + ], + "moduleJoints" : [ + { + "from" : { + "id" : 6, + "connector" : "B-Z" + }, + "to" : { + "id" : 3, + "connector" : "A-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 1, + "connector" : "B-Z" + }, + "to" : { + "id" : 3, + "connector" : "B-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 1, + "connector" : "A-Z" + }, + "to" : { + "id" : 0, + "connector" : "B-Z" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 6, + "connector" : "A-Z" + }, + "to" : { + "id" : 7, + "connector" : "A-Z" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 0, + "connector" : "A-Z" + }, + "to" : { + "id" : 7, + "connector" : "B-Z" + }, + "orientation" : "South" + } + ] + } \ No newline at end of file diff --git a/data/rofi/rofiworlds/loop2.json b/data/rofi/rofiworlds/loop2.json new file mode 100644 index 0000000000000000000000000000000000000000..5536e1613b7139472d9c920915c8472f248c95a5 --- /dev/null +++ b/data/rofi/rofiworlds/loop2.json @@ -0,0 +1,275 @@ +{ + "modules" : [ + { + "alpha" : -90, + "beta" : 0, + "gamma" : 0, + "id" : 6, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 5, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 0, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : -0, + "id" : 4, + "type" : "universal" + }, + { + "alpha" : -90, + "beta" : 0, + "gamma" : -0, + "id" : 1, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 90, + "gamma" : -0, + "id" : 7, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : -90, + "gamma" : 0, + "id" : 3, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : 0, + "id" : 2, + "type" : "universal" + }, + { + "alpha" : 90, + "beta" : 0, + "gamma" : -0, + "id" : 8, + "type" : "universal" + }, + { + "alpha" : 0, + "beta" : 0, + "gamma" : -0, + "id" : 9, + "type" : "universal" + } + ], + "spaceJoints" : [ + { + "point" : [ + 1.00015, + 2.00002, + 1.99997 + ], + "joint" : { + "type" : "rigid", + "sourceToDestination" : [ + [ + -1, + 3.16759e-08, + 8.2612e-05, + 0 + ], + [ + -3.25272e-08, + -1, + -1.0252e-05, + 0 + ], + [ + 8.2612e-05, + -1.03116e-05, + 1, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "positions" : [ + + ] + }, + "to" : { + "component" : 0, + "id" : 8 + } + } + ], + "moduleJoints" : [ + { + "from" : { + "id" : 6, + "connector" : "B-Z" + }, + "to" : { + "id" : 3, + "connector" : "A-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 6, + "connector" : "A-Z" + }, + "to" : { + "id" : 7, + "connector" : "A-Z" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 1, + "connector" : "B-Z" + }, + "to" : { + "id" : 3, + "connector" : "B-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 0, + "connector" : "A-Z" + }, + "to" : { + "id" : 7, + "connector" : "B-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 1, + "connector" : "A-Z" + }, + "to" : { + "id" : 0, + "connector" : "B-Z" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 3, + "connector" : "B-X" + }, + "to" : { + "id" : 5, + "connector" : "B+X" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 4, + "connector" : "B-Z" + }, + "to" : { + "id" : 5, + "connector" : "A-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 1, + "connector" : "B+X" + }, + "to" : { + "id" : 5, + "connector" : "A-X" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 2, + "connector" : "B+X" + }, + "to" : { + "id" : 3, + "connector" : "B+X" + }, + "orientation" : "West" + }, + { + "from" : { + "id" : 3, + "connector" : "A-X" + }, + "to" : { + "id" : 2, + "connector" : "A-X" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 8, + "connector" : "A-Z" + }, + "to" : { + "id" : 2, + "connector" : "A-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 6, + "connector" : "B+X" + }, + "to" : { + "id" : 8, + "connector" : "A+X" + }, + "orientation" : "North" + }, + { + "from" : { + "id" : 9, + "connector" : "B-Z" + }, + "to" : { + "id" : 8, + "connector" : "B-Z" + }, + "orientation" : "South" + }, + { + "from" : { + "id" : 0, + "connector" : "A-X" + }, + "to" : { + "id" : 9, + "connector" : "B+X" + }, + "orientation" : "West" + } + ] + } \ No newline at end of file diff --git a/src/edit/include/edit/editor.hpp b/src/edit/include/edit/editor.hpp index 82b58d42003950fd4856bf850c7f0a05d3e11d62..87761c92f570addceb9d6512f2e866919775e55f 100644 --- a/src/edit/include/edit/editor.hpp +++ b/src/edit/include/edit/editor.hpp @@ -58,6 +58,8 @@ public: bool save_rofiworld_prompt = false; bool save_rofiworld_visible = false; bool save_rofiworld_error = false; + bool save_rofiworld_use_current_name = true; + bool select_rofiworld_prompt = false; bool export_rofiworld_use_selected_space_joint = false; char name_buffer[256] = {0}; int module_id = 0; @@ -70,6 +72,8 @@ public: connector_ptr connector; voxel_ptr voxel; + rofiworld_ptr selected_rofiworld; + /* Ref. variables, need to be initialized in constructor */ phase &editor_phase; mode_I &editor_mode_I; @@ -86,6 +90,7 @@ public: module_ptr &selected_add_module; module_ptr &selected_module; rofiworld_ptr &rofiworld; + std::vector<rofiworld_ptr> &rofiworld_selection; bool &voxel_selected; bool &connector_selected; bool &primary_axis; @@ -114,7 +119,7 @@ public: UIData(phase &_editor_phase, mode_I &_editor_mode_I, mode_II &_editor_mode_II, build_mode_I &_editor_build_mode_I, build_mode_II &_editor_build_mode_II, state &_control_state, bool &_ui_visible, rofi::component &_chosen_component, rofi::connector_type &_chosen_con_type, std::vector<rofi::component> &_allowed_components, std::vector<module_ptr> &_modules, module_ptr &_selected_add_module, module_ptr &_selected_module, - rofiworld_ptr &_rofiworld, bool &_is_connecting_modules, bool &_can_connect_modules, + rofiworld_ptr &_rofiworld, std::vector<rofiworld_ptr> &_rofiworld_selection, bool &_is_connecting_modules, bool &_can_connect_modules, rofi::cardinal &_selected_cardinality, std::pair<connector_ptr, connector_ptr> &_selected_connectors, std::pair<module_ptr, module_ptr> &_selected_modules_connect, bool &_connector_selected, bool &_voxel_selected, bool &_is_moving_module, glm::vec3 &_module_position, int &_coordinate_space_selection, bool &_is_rotating_module, bool &_is_resetting_module_rotation, @@ -136,6 +141,7 @@ public: selected_add_module{_selected_add_module}, selected_module{_selected_module}, rofiworld{_rofiworld}, + rofiworld_selection{_rofiworld_selection}, is_connecting_modules{_is_connecting_modules}, can_connect_modules{_can_connect_modules}, selected_cardinality{_selected_cardinality}, @@ -205,7 +211,7 @@ class Editor char module_type_buffer[256] = {0}; UIData ui = UIData{editor_phase, editor_mode_I, editor_mode_II, editor_build_mode_I, editor_build_mode_II, control_state, ui_visible, - chosen_component, chosen_con_type, allowed_components, modules, selected_add_module, selected_module, rofiworld, + chosen_component, chosen_con_type, allowed_components, modules, selected_add_module, selected_module, rofiworld, rofiworld_selection, is_connecting_modules, can_connect_modules, selected_cardinality, selected_connectors, selected_modules_connect, connector_selected, voxel_selected, is_moving_module, module_position, coordinate_space_selection, is_rotating_module, is_resetting_module_rotation, module_rotation_angles, is_rotating_component, component_rotation_angle, @@ -232,7 +238,7 @@ class Editor std::vector<module_ptr> modules = import_saved_configurations_module(); rofiworld_ptr rofiworld = std::make_shared<rofi::RofiWorld>(); - std::map<std::string, rofiworld_ptr> rofiworld_selection; + std::vector<rofiworld_ptr> rofiworld_selection; module_ptr selected_add_module; module_ptr prev_selected_add_module; @@ -356,6 +362,7 @@ public: void manageUISaveModule(); void manageUISaveRofiWorld(); void manageUIImportRofiWorld(); + void manageUISelectRofiWorld(); bool checkModuleExport(const voxel_graph_ptr &voxel_graph, const build_mode_I build_mode); @@ -582,6 +589,8 @@ private: void pickSpaceJoint(rofiworld_ptr rofiworld, module_ptr module, std::set<module_ptr> &found_modules); connector_ptr pickSpaceJointUniversal(const module_ptr module); connector_ptr pickSpaceJointGeneric(const module_ptr module); + + void addToRofiWorlds(rofiworld_ptr rofiworld, const std::string name); }; } diff --git a/src/edit/src/editor.cpp b/src/edit/src/editor.cpp index e432e7a757bb55a88a0113a513fb46a3f8ba716e..37389e4c3d07f94bd4f3b1794beddbf696c0c749 100644 --- a/src/edit/src/editor.cpp +++ b/src/edit/src/editor.cpp @@ -53,6 +53,7 @@ void Editor::manageUI() manageUISaveRofiWorld(); manageUIImportRofiWorld(); + manageUISelectRofiWorld(); } void Editor::manageUISaveModule() @@ -122,22 +123,18 @@ void Editor::manageUISaveRofiWorld() bool exported = false; if (ui.save_rofiworld_prompt) { - // check valid - if (voxel_graph->empty() || detectCollision(true, rofiworld)) + // Not sure if there should be an invalid state here + if (false) { ui.save_rofiworld_error = true; ui.save_rofiworld_visible = true; - ui.export_file_prompt = false; } else { saved = true; ui.save_rofiworld_prompt = false; ui.save_rofiworld_error = false; - ui.export_file_prompt = false; - pickSpaceJoints(rofiworld, ui.export_rofiworld_use_selected_space_joint ? selected_module : nullptr); - export_rofiworld(rofiworld, selected_space_joints, ui.name_buffer); - // addToRofiWorlds(...); + addToRofiWorlds(rofiworld, ui.save_rofiworld_use_current_name ? rofiworld->getName() : std::string(ui.name_buffer)); } } @@ -164,32 +161,50 @@ void Editor::manageUIImportRofiWorld() if (editor_phase != phase::two) return; - if (ui.import_file_prompt) - { - const std::string rofiworlds_directory = "./data/rofi/rofiworlds/"; - auto imported_rofiworld = import_rofiworld(std::filesystem::path(rofiworlds_directory + std::string(ui.name_buffer) + std::string(".json"))); - if (imported_rofiworld) - { - for (const auto &module : imported_rofiworld->getModulesSet()) - setRoFIMesh(module->getParts()); + if (!ui.import_file_prompt) + return; - setRofiWorldNodeTreeToScene(rofiworld->getNodeTree(), imported_rofiworld->getNodeTree()); - rofiworld = imported_rofiworld; - voxel_graph = imported_rofiworld->getVoxelGraph(); + const std::string rofiworlds_directory = "./data/rofi/rofiworlds/"; + auto imported_rofiworld = import_rofiworld(std::filesystem::path(rofiworlds_directory + std::string(ui.name_buffer) + std::string(".json"))); + if (imported_rofiworld) + { + for (const auto &module : imported_rofiworld->getModulesSet()) + setRoFIMesh(module->getParts()); - ui.import_file_error = false; - ui.name_buffer[0] = '\0'; - resetBuildModeIIVariables(); - } - else - { - setError("Error: Cannot Import Configuration"); - ui.import_file_visible = true; - ui.import_file_error = true; - } + resetBuildModeIIVariables(); + setRofiWorldNodeTreeToScene(rofiworld->getNodeTree(), imported_rofiworld->getNodeTree()); + rofiworld = imported_rofiworld; + voxel_graph = imported_rofiworld->getVoxelGraph(); - ui.import_file_prompt = false; + ui.import_file_error = false; + ui.name_buffer[0] = '\0'; } + else + { + setError("Error: Cannot Import Configuration"); + ui.import_file_visible = true; + ui.import_file_error = true; + } + + ui.import_file_prompt = false; +} + +void Editor::manageUISelectRofiWorld() +{ + if (editor_phase != phase::two) + return; + + if (!ui.select_rofiworld_prompt || ui.selected_rofiworld == rofiworld) + return; + + resetBuildModeIIVariables(); + + setRofiWorldNodeTreeToScene(rofiworld->getNodeTree(), ui.selected_rofiworld->getNodeTree()); + rofiworld = ui.selected_rofiworld; + voxel_graph = ui.selected_rofiworld->getVoxelGraph(); + + + ui.select_rofiworld_prompt = false; } bool Editor::checkModuleExport(const voxel_graph_ptr &voxel_graph, const build_mode_I build_mode) @@ -214,6 +229,7 @@ bool Editor::checkModuleExport(const voxel_graph_ptr &voxel_graph, const build_m void Editor::resetBuildModeIIVariables() { selected_module = nullptr; + removeModuleFromScene(selected_add_module); selected_add_module = nullptr; prev_selected_add_module = nullptr; prev_rebuild_node = nullptr; @@ -1289,6 +1305,12 @@ void Editor::addToModules(std::string name, std::string type) modules.emplace_back(new_module); } +void Editor::addToRofiWorlds(rofiworld_ptr rofiworld, const std::string name) +{ + rofiworld->setName(name); + rofiworld_selection.emplace_back(rofiworld); +} + void Editor::removeFromModules(voxel_graph_ptr vg) { std::erase_if(modules, [&vg](const module_ptr &module) { return module->getParts() == vg; }); diff --git a/src/filein/src/rofiworld_loader.cpp b/src/filein/src/rofiworld_loader.cpp index 279bc40b7aa531369bcf9171237d519e50b42d43..bfc22b9484a8cb5fbd0395cc032488a069f9b4aa 100644 --- a/src/filein/src/rofiworld_loader.cpp +++ b/src/filein/src/rofiworld_loader.cpp @@ -263,7 +263,9 @@ void export_moduleJoint_orientation(boost::json::object &moduleJoint_object, con std::string orientation; - switch(Connector::get_mutual_orientation(from_con, to_con)) + const auto mutual_orientation = Connector::get_mutual_orientation(from_con, to_con); + + switch(mutual_orientation) { case North: orientation = "North"; @@ -309,7 +311,7 @@ rofiworld_ptr import_rofiworld(const std::filesystem::path file_path) std::cerr << "Cannot import RofiWorld. Invalid file path." << file_path << std::endl; return nullptr; } - + const auto json_object = read_file(file_path).as_object(); boost::json::array modules_array; @@ -335,6 +337,8 @@ rofiworld_ptr import_rofiworld(const std::filesystem::path file_path) import_moduleJoints(rofiworld, moduleJoints_array, spaceJoint_modules); + rofiworld->setName(std::move(file_path.stem().string())); + return rofiworld; } diff --git a/src/gui/include/gui/ui.hpp b/src/gui/include/gui/ui.hpp index 9f83c4e2f2f2a2b072cc100a3d0264c946f9710d..667c9078aebdb2586481d97976a0b240e82e32bc 100644 --- a/src/gui/include/gui/ui.hpp +++ b/src/gui/include/gui/ui.hpp @@ -30,6 +30,7 @@ void mode_I_menu_ui(const osi::Window &window, edit::UIData &data); void mode_II_menu_ui(const osi::Window &window, edit::UIData &data); void module_menu_ui(const osi::Window &window, edit::UIData &data); void rofiworld_menu_ui(const osi::Window &window, edit::UIData &data); +void rofiworld_selection_menu_ui(const osi::Window &window, edit::UIData &data); void file_menu_ui(const osi::Window &window, edit::UIData &data); void help_menu_ui(const osi::Window &window, edit::UIData &data); @@ -54,6 +55,7 @@ void module_rotation_drag(edit::UIData &data, glm::vec3 &euler_angles); void module_rotation_manual(edit::UIData &data, glm::vec3 &euler_angles); void component_rotation_ui(const osi::Window &window, edit::UIData &data); void save_module_ui(const osi::Window &window, edit::UIData &data); +void save_rofiworld_ui(const osi::Window &window, edit::UIData &data); void export_file_ui(const osi::Window &window, edit::UIData &data); void export_module_file_ui(const osi::Window &window, edit::UIData &data); void export_rofiworld_file_ui(const osi::Window &window, edit::UIData &data); diff --git a/src/gui/src/ui.cpp b/src/gui/src/ui.cpp index 01529aa7297f9481f33ccf1ef8561798d0fa37eb..b262a6a1cc3d8102ab7e9d3632f51438a5e449be 100644 --- a/src/gui/src/ui.cpp +++ b/src/gui/src/ui.cpp @@ -171,10 +171,36 @@ void module_menu_ui(const osi::Window &window, edit::UIData &data) void rofiworld_menu_ui(const osi::Window &window, edit::UIData &data) { - // TO DO - if (ImGui::MenuItem("Save RofiWorld")) + bool enabled = data.editor_mode_II == edit::mode_II::build + && std::find(data.rofiworld_selection.begin(), data.rofiworld_selection.end(), data.rofiworld) == data.rofiworld_selection.end(); + + if (ImGui::MenuItem("Save RofiWorld", NULL, false, enabled)) { - // data.save_rofiworld_visible = true; + data.save_rofiworld_visible = true; + } + + rofiworld_selection_menu_ui(window, data); +} + +void rofiworld_selection_menu_ui(const osi::Window &window, edit::UIData &data) +{ + + + if (ImGui::BeginMenu("Select RofiWorld", data.editor_mode_II == edit::mode_II::build)) + { + for (int i = 0; i < data.rofiworld_selection.size(); ++i) + { + const auto rw = data.rofiworld_selection[i]; + const auto label_string = rw->getName() + std::string("##RofiWorldSelection") + std::to_string(i); + const char* label = label_string.c_str(); + if (ImGui::MenuItem(label, NULL, data.rofiworld == rw)) + { + data.select_rofiworld_prompt = true; + data.selected_rofiworld = rw; + } + } + + ImGui::EndMenu(); } } @@ -264,6 +290,7 @@ void mode_II_build_ui(const osi::Window &window, edit::UIData &data) component_rotation_ui(window, data); export_file_ui(window, data); import_file_ui(window, data); + save_rofiworld_ui(window, data); } int build_mode_I_to_int(edit::build_mode_I mode) @@ -913,6 +940,8 @@ void save_module_ui(const osi::Window &window, edit::UIData &data) if (!data.save_module_visible) return; + ImGui::SetNextWindowPos(ImVec2(0, mode_toolbar_height * 3), ImGuiCond_Appearing, ImVec2(0.0f, 0.0f)); + if (!ImGui::Begin("Save Module Configuration", &data.save_module_visible, ImGuiWindowFlags_NoCollapse)) { ImGui::End(); @@ -943,6 +972,41 @@ void save_module_ui(const osi::Window &window, edit::UIData &data) ImGui::End(); } +void save_rofiworld_ui(const osi::Window &window, edit::UIData &data) +{ + if (!data.save_rofiworld_visible) + return; + + ImGui::SetNextWindowPos(ImVec2(0, mode_toolbar_height * 3), ImGuiCond_Appearing, ImVec2(0.0f, 0.0f)); + + if (!ImGui::Begin("Save RofiWorld Configuration", &data.save_rofiworld_visible, + ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::End(); + return; + } + + const auto flags = data.save_rofiworld_use_current_name + ? ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_ReadOnly + : ImGuiInputTextFlags_AutoSelectAll; + + ImGui::Text("RofiWorld Name:"); + ImGui::InputText("##ModuleNameInput", data.name_buffer, sizeof(data.name_buffer), flags); + + const auto label_string = "Use Current Name: " + data.rofiworld->getName() + "##SaveRofiWorldUseCurrentName"; + const auto label = label_string.c_str(); + ImGui::Checkbox(label, &data.save_rofiworld_use_current_name); + + if (ImGui::Button("Submit##SaveRofiWorldButton")) { + data.save_rofiworld_prompt = true; + data.save_rofiworld_visible = false; + } + + ImGui::End(); +} + void export_file_ui(const osi::Window &window, edit::UIData &data) { if (!data.export_file_visible) diff --git a/src/rofi/include/rofi/rofiworld.hpp b/src/rofi/include/rofi/rofiworld.hpp index 80ab2db86b6199579c704dff14e2b64642540116..cb6a2706126c1dd57a0e477747a06f6d4af32684 100644 --- a/src/rofi/include/rofi/rofiworld.hpp +++ b/src/rofi/include/rofi/rofiworld.hpp @@ -34,6 +34,10 @@ public: bool empty() const { return voxel_graph->empty() && node_tree.empty(); } + const std::string &getName() const { return name; } + void setName(const std::string &_name) { name = _name; } + void setName(const std::string &&_name) { name = _name; } + const std::vector<node_ptr> &getNodeTree() const { return node_tree; } voxel_graph_ptr getVoxelGraph() const { return voxel_graph; } diff --git a/src/rofi/src/connector.cpp b/src/rofi/src/connector.cpp index ff599ae206f53b9052d8b6bd387ce7ff2f21fb77..1c12088e740513e07ade5b665853f894800f2788 100644 --- a/src/rofi/src/connector.cpp +++ b/src/rofi/src/connector.cpp @@ -404,7 +404,9 @@ cardinal degree_to_cardinal(float degree_angle) // NOTE: This epsilon value is this large, because the editor refused to connect // connectors at an angle of 89.9989548 degrees, which I believe was a product // of the floating-point arithmetic - float epsilon = 0.01f; + // NOTE 2: It also computed an angle of 0.0279764552 from a valid imported configuration + + float epsilon = 0.05f; if (glm::epsilonEqual(degree_angle, 0.0f, epsilon)) return North; if (glm::epsilonEqual(degree_angle, 90.0f, epsilon))