diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp
index 6306b0fb7c..dc10d38e7c 100644
--- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp
+++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp
@@ -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
///
+/// SVG file path
/// EmbossShape to create
-EmbossShape select_shape();
+EmbossShape select_shape(std::string_view filepath = "");
///
/// Create new embos data
///
/// Cancel for previous job
+/// SVG file path
/// Base data for emboss SVG
-DataBasePtr create_emboss_data_base(std::shared_ptr> &cancel);
+DataBasePtr create_emboss_data_base(std::shared_ptr> &cancel, std::string_view filepath = "");
///
/// 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(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> &cancel)
+DataBasePtr create_emboss_data_base(std::shared_ptr> &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
diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp
index 3b8fc961a2..4f50934cb3 100644
--- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp
+++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp
@@ -55,6 +55,15 @@ public:
/// True on succesfull start creation otherwise False
bool create_volume(ModelVolumeType volume_type); // first open file dialog
+ ///
+ /// Create volume from already selected svg file
+ ///
+ /// File path
+ /// Object part / Negative volume / Modifier
+ /// Position on screen where to create volume
+ /// True on succesfull start creation otherwise False
+ bool create_volume(std::string_view svg_file, ModelVolumeType volume_type = ModelVolumeType::MODEL_PART, const Vec2d &mouse_pos = Vec2d(nan, nan));
+
///
/// Check whether volume is object containing only emboss volume
///