Various Emboss improvements from PS (#4039)

* Fix: invalid distance from surface when load from 3mf

Cherry-picked from prusa3d/PrusaSlicer@e1d9393e51

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Apply rotation angle given by style for new text object
Turn off feature 'use_surface' for new text object

Cherry-picked from prusa3d/PrusaSlicer@1cb156c815

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Store/Load align and per_glyph in Slicer.ini for text style

Cherry-picked from prusa3d/PrusaSlicer@fe16f5bdd1

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Store undo/redo snap after stop input-sliding

Cherry-picked from prusa3d/PrusaSlicer@fb4e4710e7

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Initialize SvgFile object in optional different way.

Cherry-picked from prusa3d/PrusaSlicer@0ff255eadc

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* SPE-2103
Make snap-shot to undo/redo stack only on release slider

Connected with attributes:
Text/advanced(char gap, line gap, boldness, skew ratio)
SVG(size)

Also change range for Boldness. VRT font-Ascent.
(different font may have different slider value range)

Fix line gap (it was denied when per glyph was false)

Cherry-picked from prusa3d/PrusaSlicer@ee3546b186

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

---------

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>
Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
Noisyfox 2024-02-13 23:56:48 +08:00 committed by GitHub
parent 291cfe1d4a
commit 2d140f92ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 217 additions and 72 deletions

View file

@ -55,6 +55,14 @@ GLGizmoSVG::GLGizmoSVG(GLCanvas3D &parent)
// Private functions to create emboss volume
namespace{
// TRN - Title in Undo/Redo stack after rotate with SVG around emboss axe
const std::string rotation_snapshot_name = L("SVG rotate");
// NOTE: Translation is made in "m_parent.do_rotate()"
// TRN - Title in Undo/Redo stack after move with SVG along emboss axe - From surface
const std::string move_snapshot_name = L("SVG move");
// NOTE: Translation is made in "m_parent.do_translate()"
// Variable keep limits for variables
const struct Limits
{
@ -537,7 +545,7 @@ void GLGizmoSVG::on_stop_dragging()
// apply rotation
// TRN This is an item label in the undo-redo stack.
m_parent.do_rotate(L("SVG-Rotate"));
m_parent.do_rotate(rotation_snapshot_name);
m_rotate_start_angle.reset();
volume_transformation_changed();
@ -1264,8 +1272,7 @@ void GLGizmoSVG::calculate_scale() {
float GLGizmoSVG::get_scale_for_tolerance(){
return std::max(m_scale_width.value_or(1.f), m_scale_height.value_or(1.f)); }
bool GLGizmoSVG::process()
{
bool GLGizmoSVG::process(bool make_snapshot) {
// no volume is selected -> selection from right panel
assert(m_volume != nullptr);
if (m_volume == nullptr)
@ -1286,7 +1293,7 @@ bool GLGizmoSVG::process()
EmbossShape shape = m_volume_shape; // copy
auto base = std::make_unique<DataBase>(m_volume->name, m_job_cancel, std::move(shape));
base->is_outside = m_volume->type() == ModelVolumeType::MODEL_PART;
DataUpdate data{std::move(base), m_volume_id};
DataUpdate data{std::move(base), m_volume_id, make_snapshot};
return start_update_volume(std::move(data), *m_volume, m_parent.get_selection(), m_raycast_manager);
}
@ -1492,8 +1499,9 @@ void GLGizmoSVG::draw_filename(){
std::string new_path = choose_svg_file();
if (!new_path.empty()) {
file_changed = true;
m_volume_shape.svg_file = {}; // clear data
m_volume_shape.svg_file->path = new_path;
EmbossShape::SvgFile svg_file_new;
svg_file_new.path = new_path;
m_volume_shape.svg_file = svg_file_new; // clear data
}
} else if (ImGui::IsItemHovered()) {
tooltip = _u8L("Change to another .svg file");
@ -1689,6 +1697,8 @@ void GLGizmoSVG::draw_size()
};
std::optional<Vec3d> new_relative_scale;
bool make_snap = false;
if (m_keep_ratio) {
std::stringstream ss;
ss << std::setprecision(2) << std::fixed << width << " x " << height << " " << (use_inch ? "in" : "mm");
@ -1707,6 +1717,8 @@ void GLGizmoSVG::draw_size()
new_relative_scale = Vec3d(width_ratio, width_ratio, 1.);
}
}
if (m_imgui->get_last_slider_status().deactivated_after_edit)
make_snap = true; // only last change of slider make snap
} else {
ImGuiInputTextFlags flags = 0;
@ -1726,6 +1738,7 @@ void GLGizmoSVG::draw_size()
if (is_valid_scale_ratio(width_ratio)) {
m_scale_width = m_scale_width.value_or(1.f) * width_ratio;
new_relative_scale = Vec3d(width_ratio, 1., 1.);
make_snap = true;
}
}
if (ImGui::IsItemHovered())
@ -1739,6 +1752,7 @@ void GLGizmoSVG::draw_size()
if (is_valid_scale_ratio(height_ratio)) {
m_scale_height = m_scale_height.value_or(1.f) * height_ratio;
new_relative_scale = Vec3d(1., height_ratio, 1.);
make_snap = true;
}
}
if (ImGui::IsItemHovered())
@ -1760,6 +1774,7 @@ void GLGizmoSVG::draw_size()
if (can_reset) {
if (reset_button(m_icons)) {
new_relative_scale = Vec3d(1./m_scale_width.value_or(1.f), 1./m_scale_height.value_or(1.f), 1.);
make_snap = true;
} else if (ImGui::IsItemHovered())
m_imgui->tooltip(_u8L("Reset scale"), m_gui_cfg->max_tooltip_width);
}
@ -1773,20 +1788,25 @@ void GLGizmoSVG::draw_size()
};
selection_transform(selection, selection_scale_fnc);
m_parent.do_scale(L("Resize"));
std::string snap_name; // Empty mean do not store on undo/redo stack
m_parent.do_scale(snap_name);
wxGetApp().obj_manipul()->set_dirty();
// should be the almost same
calculate_scale();
NSVGimage *img = m_volume_shape.svg_file->image.get();
const NSVGimage *img = m_volume_shape.svg_file->image.get();
assert(img != NULL);
if (img != NULL){
NSVGLineParams params{get_tesselation_tolerance(get_scale_for_tolerance())};
m_volume_shape.shapes_with_ids = create_shape_with_ids(*img, params);
m_volume_shape.final_shape = {}; // reset cache for final shape
process();
if (!make_snap) // Be carefull: Last change may be without change of scale
process(false);
}
}
if (make_snap)
process(); // make undo/redo snap-shot
}
void GLGizmoSVG::draw_use_surface()
@ -1842,18 +1862,20 @@ void GLGizmoSVG::draw_distance()
if (m_imgui->slider_optional_float("##distance", m_distance, min_distance, max_distance, "%.2f mm", 1.f, false, move_tooltip))
is_moved = true;
}
bool can_reset = m_distance.has_value();
if (can_reset) {
bool is_stop_sliding = m_imgui->get_last_slider_status().deactivated_after_edit;
bool is_reseted = false;
if (m_distance.has_value()) {
if (reset_button(m_icons)) {
m_distance.reset();
is_moved = true;
is_reseted = true;
} else if (ImGui::IsItemHovered())
m_imgui->tooltip(_u8L("Reset distance"), m_gui_cfg->max_tooltip_width);
}
if (is_moved)
do_local_z_move(m_parent, m_distance.value_or(.0f) - prev_distance);
if (is_moved || is_reseted)
do_local_z_move(m_parent.get_selection(), m_distance.value_or(.0f) - prev_distance);
if (is_stop_sliding || is_reseted)
m_parent.do_move(move_snapshot_name);
}
void GLGizmoSVG::draw_rotation()
@ -1876,7 +1898,7 @@ void GLGizmoSVG::draw_rotation()
double diff_angle = angle_rad - angle;
do_local_z_rotate(m_parent, diff_angle);
do_local_z_rotate(m_parent.get_selection(), diff_angle);
// calc angle after rotation
m_angle = calc_angle(m_parent.get_selection());
@ -1885,20 +1907,28 @@ void GLGizmoSVG::draw_rotation()
if (m_volume->emboss_shape->projection.use_surface)
process();
}
bool is_stop_sliding = m_imgui->get_last_slider_status().deactivated_after_edit;
// Reset button
bool is_reseted = false;
if (m_angle.has_value()) {
if (reset_button(m_icons)) {
do_local_z_rotate(m_parent, -(*m_angle));
do_local_z_rotate(m_parent.get_selection(), -(*m_angle));
m_angle.reset();
// recalculate for surface cut
if (m_volume->emboss_shape->projection.use_surface)
process();
is_reseted = true;
} else if (ImGui::IsItemHovered())
m_imgui->tooltip(_u8L("Reset rotation"), m_gui_cfg->max_tooltip_width);
}
// Apply rotation on model (backend)
if (is_stop_sliding || is_reseted)
m_parent.do_rotate(rotation_snapshot_name);
// Keep up - lock button icon
if (!m_volume->is_the_only_one_part()) {
ImGui::SameLine(m_gui_cfg->lock_offset);