mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-24 23:04:38 +08:00
Prepare Drag&drop svg file
This commit is contained in:
parent
1c80d4358a
commit
4db49f7882
@ -68,15 +68,17 @@ std::string choose_svg_file();
|
||||
/// Let user to choose file with (S)calable (V)ector (G)raphics - SVG.
|
||||
/// Than let select contour
|
||||
/// </summary>
|
||||
/// <param name="filepath">SVG file path</param>
|
||||
/// <returns>EmbossShape to create</returns>
|
||||
EmbossShape select_shape();
|
||||
EmbossShape select_shape(std::string_view filepath = "");
|
||||
|
||||
/// <summary>
|
||||
/// Create new embos data
|
||||
/// </summary>
|
||||
/// <param name="cancel">Cancel for previous job</param>
|
||||
/// <param name="filepath">SVG file path</param>
|
||||
/// <returns>Base data for emboss SVG</returns>
|
||||
DataBasePtr create_emboss_data_base(std::shared_ptr<std::atomic<bool>> &cancel);
|
||||
DataBasePtr create_emboss_data_base(std::shared_ptr<std::atomic<bool>> &cancel, std::string_view filepath = "");
|
||||
|
||||
/// <summary>
|
||||
/// Create symbol '?' as default shape
|
||||
@ -171,6 +173,13 @@ bool GLGizmoSVG::create_volume(ModelVolumeType volume_type)
|
||||
return start_create_volume_without_position(input, std::move(base));
|
||||
}
|
||||
|
||||
bool GLGizmoSVG::create_volume(std::string_view svg_file, ModelVolumeType volume_type, const Vec2d &mouse_pos)
|
||||
{
|
||||
CreateVolumeParams input = create_input(m_parent, m_raycast_manager, volume_type);
|
||||
DataBasePtr base = create_emboss_data_base(m_job_cancel, svg_file);
|
||||
return start_create_volume(input, std::move(base), mouse_pos);
|
||||
}
|
||||
|
||||
bool GLGizmoSVG::is_svg(const ModelVolume &volume) {
|
||||
return volume.emboss_shape.has_value();
|
||||
}
|
||||
@ -656,6 +665,7 @@ void GLGizmoSVG::draw_window()
|
||||
|
||||
if (ImGui::Button("change file")) {
|
||||
m_volume_shape.shapes_with_ids = select_shape().shapes_with_ids;
|
||||
init_texture(m_texture, *m_volume);
|
||||
// TODO: use setted scale
|
||||
process();
|
||||
}
|
||||
@ -1090,15 +1100,26 @@ ExPolygons default_shape()
|
||||
return shape;
|
||||
}
|
||||
|
||||
EmbossShape select_shape()
|
||||
namespace {
|
||||
void translate(ExPolygons &expolys, const Point &p) {
|
||||
for (ExPolygon &expoly : expolys)
|
||||
expoly.translate(p);
|
||||
}
|
||||
}
|
||||
|
||||
EmbossShape select_shape(std::string_view filepath)
|
||||
{
|
||||
EmbossShape shape;
|
||||
shape.projection.depth = 10.;
|
||||
shape.projection.use_surface = false;
|
||||
|
||||
shape.svg_file_path = choose_svg_file();
|
||||
if (shape.svg_file_path.empty())
|
||||
return {};
|
||||
if (filepath.empty()) {
|
||||
shape.svg_file_path = choose_svg_file();
|
||||
if (shape.svg_file_path.empty())
|
||||
return {};
|
||||
} else {
|
||||
shape.svg_file_path = filepath; // copy
|
||||
}
|
||||
|
||||
const char *unit_mm{"mm"};
|
||||
// common used DPI is 96 or 72
|
||||
@ -1113,20 +1134,25 @@ EmbossShape select_shape()
|
||||
float scale = static_cast<float>(1 / shape.scale);
|
||||
bool is_y_negative = true;
|
||||
ExPolygons expoly = to_expolygons(image, tesselation_tolerance, max_level, scale, is_y_negative);
|
||||
|
||||
|
||||
// Must contain some shapes !!!
|
||||
if (expoly.empty())
|
||||
expoly = default_shape();
|
||||
|
||||
// SVG is used as centered
|
||||
// Do not disturb user by settings of pivot position
|
||||
BoundingBox bb = get_extents(expoly);
|
||||
translate(expoly, -bb.center());
|
||||
|
||||
unsigned id = 0;
|
||||
shape.shapes_with_ids = {{id, expoly}};
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
DataBasePtr create_emboss_data_base(std::shared_ptr<std::atomic<bool>> &cancel)
|
||||
DataBasePtr create_emboss_data_base(std::shared_ptr<std::atomic<bool>> &cancel, std::string_view filepath)
|
||||
{
|
||||
EmbossShape shape = select_shape();
|
||||
EmbossShape shape = select_shape(filepath);
|
||||
|
||||
if (shape.shapes_with_ids.empty())
|
||||
// canceled selection of SVG file
|
||||
|
@ -55,6 +55,15 @@ public:
|
||||
/// <returns>True on succesfull start creation otherwise False</returns>
|
||||
bool create_volume(ModelVolumeType volume_type); // first open file dialog
|
||||
|
||||
/// <summary>
|
||||
/// Create volume from already selected svg file
|
||||
/// </summary>
|
||||
/// <param name="svg_file">File path</param>
|
||||
/// <param name="volume_type">Object part / Negative volume / Modifier</param>
|
||||
/// <param name="mouse_pos">Position on screen where to create volume</param>
|
||||
/// <returns>True on succesfull start creation otherwise False</returns>
|
||||
bool create_volume(std::string_view svg_file, ModelVolumeType volume_type = ModelVolumeType::MODEL_PART, const Vec2d &mouse_pos = Vec2d(nan, nan));
|
||||
|
||||
/// <summary>
|
||||
/// Check whether volume is object containing only emboss volume
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user