From 65a245af4147bd253f6baeb55ec6b4ab6893943c Mon Sep 17 00:00:00 2001 From: sunsets <845944018@qq.com> Date: Fri, 15 Sep 2023 19:25:28 +0800 Subject: [PATCH] num_text --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 82 ++++++++++++++++++++- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 7 +- src/slic3r/GUI/Plater.cpp | 94 ++++++++++++++----------- src/slic3r/GUI/Plater.hpp | 3 +- 4 files changed, 141 insertions(+), 45 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index c5590b1..5c6b44f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -42,6 +42,7 @@ #include #include // measure enumeration of fonts + // uncomment for easier debug //#define ALLOW_DEBUG_MODE #ifdef ALLOW_DEBUG_MODE @@ -202,6 +203,8 @@ static void find_closest_volume(const Selection &selection, /// Screen coordinat, where to create new object laying on bed static void start_create_object_job(DataBase &emboss_data, const Vec2d &coor); + + // Loaded icons enum // Have to match order of files in function GLGizmoEmboss::init_icons() enum class IconType : unsigned { @@ -241,6 +244,77 @@ static bool apply_camera_dir(const Camera &camera, GLCanvas3D &canvas); } // namespace priv +//B34 +void GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos, std::string str) +{ + if (!init_create(volume_type)) + return; + + // select position by camera position and view direction + const Selection &selection = m_parent.get_selection(); + int object_idx = selection.get_object_idx(); + + Size s = m_parent.get_canvas_size(); + + Vec2d screen_center(s.get_width() / 2., s.get_height() / 2.); + DataBase emboss_data = priv::create_emboss_data_base(str, m_style_manager, m_job_cancel); + const ModelObjectPtrs &objects = selection.get_model()->objects; + bool is_simple_mode = wxGetApp().get_mode() == comSimple; + // No selected object so create new object + if (selection.is_empty() || object_idx < 0 || static_cast(object_idx) >= objects.size() || is_simple_mode) { + // create Object on center of screen + // when ray throw center of screen not hit bed it create object on center of bed + priv::start_create_object_job(emboss_data, screen_center); + return; + } + + // create volume inside of selected object + Vec2d coor; + const GLVolume *vol = nullptr; + const Camera & camera = wxGetApp().plater()->get_camera(); + priv::find_closest_volume(selection, screen_center, camera, objects, &coor, &vol); + + // there is no point on surface so no use of surface will be applied + FontProp &prop = emboss_data.text_configuration.style.prop; + if (prop.use_surface) + prop.use_surface = false; + + + Plater *plater = wxGetApp().plater(); + // Transformation is inspired add generic volumes in ObjectList::load_generic_subobject + const ModelObject *obj = objects[vol->object_idx()]; + BoundingBoxf3 instance_bb = obj->instance_bounding_box(vol->instance_idx()); + + size_t vol_id = obj->volumes[vol->volume_idx()]->id().id; + + auto cond = RaycastManager::AllowVolumes({vol_id}); + + RaycastManager::Meshes meshes = create_meshes(m_parent, cond); + m_raycast_manager.actualize(*obj, &cond, &meshes); + std::optional hit = ray_from_camera(m_raycast_manager, coor, camera, &cond); + + Transform3d surface_trmat = create_transformation_onto_surface(Vec3d(mouse_pos.x(), mouse_pos.y(), 0.2), + hit->normal, + priv::up_limit); + emboss_data.text_configuration.style.prop.emboss = 0.2; + emboss_data.text_configuration.style.prop.size_in_mm = 7; + + const FontProp &font_prop = emboss_data.text_configuration.style.prop; + apply_transformation(font_prop, surface_trmat); + Transform3d instance = vol->get_instance_transformation().get_matrix(); + Transform3d volume_trmat = instance.inverse() * surface_trmat; + start_create_volume_job(obj, volume_trmat, emboss_data, volume_type); + +} + + + + + +void GLGizmoEmboss::change_height(double height) { + set_height(); +} + void GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mouse_pos) { if (!init_create(volume_type)) @@ -273,6 +347,9 @@ void GLGizmoEmboss::create_volume(ModelVolumeType volume_type) int object_idx = selection.get_object_idx(); Size s = m_parent.get_canvas_size(); + + + Vec2d screen_center(s.get_width() / 2., s.get_height() / 2.); DataBase emboss_data = priv::create_emboss_data_base(m_text, m_style_manager, m_job_cancel); const ModelObjectPtrs &objects = selection.get_model()->objects; @@ -2769,6 +2846,7 @@ bool GLGizmoEmboss::set_height() { return true; } + void GLGizmoEmboss::draw_height(bool use_inch) { float &value = m_style_manager.get_style().prop.size_in_mm; @@ -2777,6 +2855,7 @@ void GLGizmoEmboss::draw_height(bool use_inch) const char *size_format = use_inch ? "%.2f in" : "%.1f mm"; const std::string revert_text_size = _u8L("Revert text size."); const std::string& name = m_gui_cfg->translations.height; + if (rev_input_mm(name, value, stored, revert_text_size, 0.1f, 1.f, size_format, use_inch, m_scale_height)) if (set_height()) process(); @@ -3543,7 +3622,8 @@ bool priv::start_create_volume_on_surface_job( return false; // Create result volume transformation - Transform3d surface_trmat = create_transformation_onto_surface(hit->position, hit->normal, priv::up_limit); + Transform3d surface_trmat = create_transformation_onto_surface(hit->position, hit->normal, + priv::up_limit); const FontProp &font_prop = emboss_data.text_configuration.style.prop; apply_transformation(font_prop, surface_trmat); Transform3d instance = gl_volume->get_instance_transformation().get_matrix(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 3189178..6aaf3c3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -34,18 +34,22 @@ class GLGizmoEmboss : public GLGizmoBase public: GLGizmoEmboss(GLCanvas3D& parent); + //B34 + void create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos, std::string m_text); + /// /// Create new embossed text volume by type on position of mouse /// /// Object part / Negative volume / Modifier /// Define position of new volume void create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos); - /// /// Create new text without given position /// /// Object part / Negative volume / Modifier void create_volume(ModelVolumeType volume_type); + //B34 + void change_height(double height); /// /// Handle pressing of shortcut @@ -110,6 +114,7 @@ private: void draw_height(bool use_inch); void draw_depth(bool use_inch); + // call after set m_style_manager.get_style().prop.size_in_mm bool set_height(); // call after set m_style_manager.get_style().prop.emboss diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index dcbac2b..9f499a2 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2292,6 +2292,7 @@ Plater::priv::~priv() void Plater::priv::update(unsigned int flags) { + // the following line, when enabled, causes flickering on NVIDIA graphics cards // wxWindowUpdateLocker freeze_guard(q); if (get_config_bool("autocenter")) @@ -5409,7 +5410,7 @@ void Plater::calib_flowrate_coarse() std::string message = _u8L("NOTICE: The calibration function modifies some parameters. After calibration, record the best value and restore the other parameters."); get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message); } - +//B34 void Plater::calib_flowrate_fine(const double target_extrusion_multiplier) { new_project(); @@ -5440,8 +5441,6 @@ void Plater::calib_flowrate_fine(const double target_extrusion_multiplier) std::string message = _u8L("NOTICE: The calibration function modifies some parameters. After calibration, record the best value and restore the other parameters."); get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message); } - - //B34 void Plater::calib_pa_line(const double StartPA, double EndPA, double PAStep) { @@ -5454,9 +5453,10 @@ void Plater::calib_pa_line(const double StartPA, double EndPA, double PAStep) load_files(model_path, true, false, false); // Check step count + double interval = 4.62; const Vec2d plate_center = build_volume().bed_center(); double count = floor((EndPA - StartPA) / PAStep); - double max_count = floor(plate_center.y() / 2.5) - 2; + double max_count = floor(plate_center.y() / interval *2) - 2; if (count > max_count) { count = max_count; } @@ -5468,14 +5468,14 @@ void Plater::calib_pa_line(const double StartPA, double EndPA, double PAStep) // Position aided model sidebar().obj_manipul()->on_change("position", 0, plate_center.x() - 50); sidebar().obj_manipul()->set_uniform_scaling(false); - sidebar().obj_manipul()->on_change("size", 1, count * 5); + sidebar().obj_manipul()->on_change("size", 1, count * interval); double pa_first_layer_height = print_config->get_abs_value("first_layer_height"); sidebar().obj_manipul()->on_change("size", 2, pa_first_layer_height); sidebar().obj_manipul()->set_uniform_scaling(true); //B34 Get parameter double start_x = plate_center.x() - 40; - double start_y = plate_center.y() - count * 2.5; + double start_y = plate_center.y() - count * interval / 2; const double speed_fast = print_config->get_abs_value("external_perimeter_speed") * 60; const double speed_slow = speed_fast * 0.8; const double line_short = 20; @@ -5504,48 +5504,32 @@ void Plater::calib_pa_line(const double StartPA, double EndPA, double PAStep) const double e_step = print_config->get_abs_value("layer_height") * pa_external_perimeter_extrusion_width * 0.4; - //B34 Add Text - GLCanvas3D * canvas = wxGetApp().plater()->canvas3D(); - GLGizmosManager &mng = canvas->get_gizmos_manager(); - GLGizmoBase * gizmo = mng.get_gizmo(GLGizmosManager::Emboss); - GLGizmoEmboss * emboss = dynamic_cast(gizmo); - assert(emboss != nullptr); - if (emboss == nullptr) - return; - - ModelVolumeType volume_type = ModelVolumeType::MODEL_PART; - // no selected object means create new object - if (volume_type == ModelVolumeType::INVALID) - volume_type = ModelVolumeType::MODEL_PART; - - emboss->create_volume(volume_type, Vec2d(plate_center.x() - 10, plate_center.y() - count * 2.5), "0.0"); - //dynamic_cast(mng.get_gizmo(GLGizmosManager::Emboss)) - // ->create_volume(volume_type, Vec2d(plate_center.x() - 20, plate_center.y() - count * 2.5), "1.0"); - //dynamic_cast(mng.get_gizmo(GLGizmosManager::Emboss)) - // ->create_volume(volume_type, Vec2d(plate_center.x() - 20, plate_center.y() - count * 2.5), "2.0"); - //dynamic_cast(mng.get_gizmo(GLGizmosManager::Emboss)) - // ->create_volume(volume_type, Vec2d(plate_center.x() - 20, plate_center.y() - count * 2.5), "3.0"); - //model().objects[0]->scale(2); - + std::string num_str = double_to_str(StartPA + (count-1) * PAStep) ; + for (int i = 1; i < count/2; i++) { + num_str += "\n" + double_to_str(StartPA + (count - 1 - i * 2) * PAStep) ; + } + add_num_text(num_str, Vec2d(plate_center.x() - 50, plate_center.y())); + //add_num_text("2.0"); + // add_num_text("1.0", Vec2d(100, 200)); //B34 Generate line gcode std::stringstream gcode; gcode << move_to(Vec2d(start_x + 80, start_y), pa_travel_speed); gcode << move_to(pa_layer_height); - gcode << move_to(Vec2d(start_x + 80, start_y + count * 5), speed_fast, count * 5 * e_step); + gcode << move_to(Vec2d(start_x + 80, start_y + count * interval), speed_fast, count * interval * e_step); for (int i = 0; i <= count; i++) { gcode << set_pressure_advance(StartPA + i * PAStep); - gcode << move_to(Vec2d(start_x, start_y + i * 5), pa_travel_speed); - gcode << move_to(Vec2d(start_x + line_short, start_y + i * 5), speed_fast, line_short * e_step); - gcode << move_to(Vec2d(start_x + line_short + line_long, start_y + i * 5), speed_slow, line_long * e_step); - gcode << move_to(Vec2d(start_x + line_short + line_long + line_short, start_y + i * 5), speed_fast, line_short * e_step); + gcode << move_to(Vec2d(start_x, start_y + i * interval), pa_travel_speed); + gcode << move_to(Vec2d(start_x + line_short, start_y + i * interval), speed_fast, line_short * e_step); + gcode << move_to(Vec2d(start_x + line_short + line_long, start_y + i * interval), speed_slow, line_long * e_step); + gcode << move_to(Vec2d(start_x + line_short + line_long + line_short, start_y + i * interval), speed_fast, line_short * e_step); } gcode << set_pressure_advance(0); - gcode << move_to(Vec2d(start_x + line_short, start_y + count * 5 + 1), pa_travel_speed); - gcode << move_to(Vec2d(start_x + line_short, start_y + count * 5 + 3), speed_fast, 2 * e_step); - gcode << move_to(Vec2d(start_x + line_short + line_long, start_y + count * 5 + 1), pa_travel_speed); - gcode << move_to(Vec2d(start_x + line_short + line_long, start_y + count * 5 + 3), speed_fast, 2 * e_step); + gcode << move_to(Vec2d(start_x + line_short, start_y + count * interval + 1), pa_travel_speed); + gcode << move_to(Vec2d(start_x + line_short, start_y + count * interval + 3), speed_fast, 2 * e_step); + gcode << move_to(Vec2d(start_x + line_short + line_long, start_y + count * interval + 1), pa_travel_speed); + gcode << move_to(Vec2d(start_x + line_short + line_long, start_y + count * interval + 3), speed_fast, 2 * e_step); // Set and load end gcode auto pa_end_gcode = printer_config->opt_string("end_gcode"); @@ -5562,7 +5546,7 @@ void Plater::calib_pa_line(const double StartPA, double EndPA, double PAStep) get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message); } - +//B34 void Plater::calib_pa_pattern(const double StartPA, double EndPA, double PAStep) { new_project(); @@ -5607,11 +5591,11 @@ void Plater::calib_pa_pattern(const double StartPA, double EndPA, double PAStep) pa_external_perimeter_extrusion_width = pa_extrusion_width * pa_external_perimeter_extrusion_width; } - const double step_spacing = 5; + const double step_spacing = 4.62; double line_spacing = pa_external_perimeter_extrusion_width - pa_layer_height * (1 - M_PI / 4); const double m_wall_side_length{64.0}; - double max_count = floor(plate_center.y() - line_spacing - m_wall_side_length / (2 * step_spacing)) - 3; + double max_count = floor((plate_center.y() * 2 - 2 * line_spacing - m_wall_side_length / 2) / step_spacing) - 3; if (count > max_count) { count = max_count; } @@ -5635,6 +5619,15 @@ void Plater::calib_pa_pattern(const double StartPA, double EndPA, double PAStep) std::stringstream gcode; gcode << move_to(pa_layer_height); + + //B34 Add Num + std::string num_str = double_to_str(StartPA + 1 * PAStep); + for (int i = 1; i < count / 2; i++) { + num_str += "\n" + double_to_str(StartPA + (1 + i * 2) * PAStep); + } + + add_num_text(num_str, Vec2d(plate_center.x() - 50, plate_center.y() + m_wall_side_length / 4)); + // Draw Box for (int i = 0; i < 3; i++) { gcode << move_to(Vec2d(start_x + i * line_spacing, start_y - i * line_spacing), pa_travel_speed); @@ -5713,7 +5706,6 @@ void Plater::calib_pa_tower(const double StartPA, double EndPA, double PAStep) std::string message = _u8L("NOTICE: The calibration function modifies some parameters. After calibration, record the best value and restore the other parameters."); get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message); } - //B34 std::string Plater::move_to(const Vec2d &point, double speed) { @@ -5743,6 +5735,24 @@ std::string Plater::set_pressure_advance(double pa) return gcode.str(); } +void Plater::add_num_text(std::string num, Vec2d posotion) +{ + GLCanvas3D * canvas = wxGetApp().plater()->canvas3D(); + GLGizmosManager &mng = canvas->get_gizmos_manager(); + GLGizmoBase * gizmo = mng.get_gizmo(GLGizmosManager::Emboss); + GLGizmoEmboss * emboss = dynamic_cast(gizmo); + assert(emboss != nullptr); + if (emboss == nullptr) + return; + + ModelVolumeType volume_type = ModelVolumeType::MODEL_PART; + // no selected object means create new object + if (volume_type == ModelVolumeType::INVALID) + volume_type = ModelVolumeType::MODEL_PART; + + emboss->create_volume(volume_type, posotion, num); +} + diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index ff52650..381c59d 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -178,7 +178,7 @@ public: std::string move_to(const Vec2d &point, double speed, double e); std::string move_to(double height); std::string set_pressure_advance(double pa); - + void add_num_text(std::string num, Vec2d posotion); void new_project(); void load_project(); @@ -208,6 +208,7 @@ public: FORCE_BACKGROUND_PROCESSING_UPDATE = 2, POSTPONE_VALIDATION_ERROR_MESSAGE = 4, }; + void update(unsigned int flags = 0); // Get the worker handling the UI jobs (arrange, fill bed, etc...)