From 20547f58c1dee6da93a684fdbe28431dba7db94e Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Wed, 11 Sep 2024 10:03:52 +0800 Subject: [PATCH] NEW:Unified SVG import entrance jira: none Change-Id: Ieabad4379765202383b09af905ad59a53d9abd5a --- src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp | 9 +++++ src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp | 1 + src/slic3r/GUI/Jobs/EmbossJob.cpp | 6 ++-- src/slic3r/GUI/Plater.cpp | 52 ++++++++++++++++++---------- src/slic3r/GUI/Plater.hpp | 4 +-- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index 78bf78793..b96d5420e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -452,6 +452,15 @@ bool GLGizmoSVG::create_volume(std::string_view svg_file, const Vec2d &mouse_pos return start_create_volume(input, std::move(base), mouse_pos); } +bool GLGizmoSVG::create_volume(std::string_view svg_file, ModelVolumeType volume_type) +{ + Emboss::CreateVolumeParams input = create_input(m_parent, volume_type); + Emboss::DataBasePtr base = create_emboss_data_base(m_job_cancel, volume_type, svg_file); + if (!base) + return false; // Uninterpretable svg + return start_create_volume_without_position(input, std::move(base)); +} + bool GLGizmoSVG::is_svg_object(const ModelVolume &volume) { if (!volume.emboss_shape.has_value()) return false; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp index 7f344a1a3..41072c8e4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp @@ -45,6 +45,7 @@ public: bool create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos); // first open file dialog //by rigth menu bool create_volume(std::string_view svg_file, const Vec2d &mouse_pos, ModelVolumeType volume_type = ModelVolumeType::MODEL_PART); + bool create_volume(std::string_view svg_file, ModelVolumeType volume_type = ModelVolumeType::MODEL_PART); /// /// Check whether volume is object containing only emboss volume /// diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 7c83980c1..614ba6a06 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -315,7 +315,8 @@ UpdateJob::UpdateJob(DataUpdate &&input) : m_input(std::move(input)) {} void UpdateJob::process(Ctl &ctl) { - if (!check(m_input)) throw JobException("Bad input data for EmbossUpdateJob."); + if (!check(m_input)) + throw JobException("Bad input data for EmbossUpdateJob."); m_result = try_create_mesh(*m_input.base); if (was_canceled(ctl, *m_input.base)) @@ -366,7 +367,8 @@ void UpdateJob::update_volume(ModelVolume *volume, TriangleMesh &&mesh, const Da CreateObjectJob::CreateObjectJob(DataCreateObject &&input) : m_input(std::move(input)) {} void CreateObjectJob::process(Ctl &ctl) { - if (!check(m_input)) return throw JobException("Bad input data for EmbossCreateObjectJob."); + if (!check(m_input)) + throw JobException("Bad input data for EmbossCreateObjectJob."); // can't create new object with using surface if (m_input.base->shape.projection.use_surface) m_input.base->shape.projection.use_surface = false; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 26090bc26..41dcc3475 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -10407,7 +10407,7 @@ void ProjectDropDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } -bool Plater::emboss_svg(const wxString &svg_file) +bool Plater::emboss_svg(const wxString &svg_file, bool from_toolbar_or_file_menu) { std::string svg_file_str = into_u8(svg_file); GLCanvas3D *canvas = canvas3D(); @@ -10420,14 +10420,35 @@ bool Plater::emboss_svg(const wxString &svg_file) if (svg == nullptr) return false; // Refresh hover state to find surface point under mouse - wxMouseEvent evt(wxEVT_MOTION); - auto mouse_drop_position =canvas->get_local_mouse_position(); - evt.SetPosition(wxPoint(mouse_drop_position.x(), mouse_drop_position.y())); - canvas->on_mouse(evt); // call render where is call GLCanvas3D::_picking_pass() - return svg->create_volume(svg_file_str, mouse_drop_position, ModelVolumeType::MODEL_PART); + if (from_toolbar_or_file_menu) { + return svg->create_volume(svg_file_str, ModelVolumeType::MODEL_PART); + } else { + wxMouseEvent evt(wxEVT_MOTION); + auto mouse_drop_position = canvas->get_local_mouse_position(); + evt.SetPosition(wxPoint(mouse_drop_position.x(), mouse_drop_position.y())); + canvas->on_mouse(evt); // call render where is call GLCanvas3D::_picking_pass() + return svg->create_volume(svg_file_str, mouse_drop_position, ModelVolumeType::MODEL_PART); + } } -//BBS: remove GCodeViewer as seperate APP logic +bool Plater::load_svg(const wxArrayString &filenames, bool from_toolbar_or_file_menu) +{ + // When only one .svg file is dropped on scene + if (filenames.size() == 1) { + const wxString &filename = filenames.Last(); + const wxString file_extension = filename.substr(filename.length() - 4); + if (file_extension.CmpNoCase(".svg") == 0) { + // BBS: GUI refactor: move sidebar to the left + /* const wxPoint offset = GetPosition() + p->current_panel->GetPosition(); + Vec2d mouse_position(x - offset.x, y - offset.y);*/ + // Scale for retina displays + // canvas->apply_retina_scale(mouse_position); + return emboss_svg(filename, from_toolbar_or_file_menu); + } + } + return false; +} + //BBS: remove GCodeViewer as seperate APP logic bool Plater::load_files(const wxArrayString& filenames) { const std::regex pattern_drop(".*[.](stp|step|stl|oltp|obj|amf|3mf|svg)", std::regex::icase); @@ -10436,18 +10457,8 @@ bool Plater::load_files(const wxArrayString& filenames) std::vector normal_paths; std::vector gcode_paths; - // When only one .svg file is dropped on scene - if (filenames.size() == 1) { - const wxString &filename = filenames.Last(); - const wxString file_extension = filename.substr(filename.length() - 4); - if (file_extension.CmpNoCase(".svg") == 0) { - // BBS: GUI refactor: move sidebar to the left - /* const wxPoint offset = GetPosition() + p->current_panel->GetPosition(); - Vec2d mouse_position(x - offset.x, y - offset.y);*/ - // Scale for retina displays - //canvas->apply_retina_scale(mouse_position); - return emboss_svg(filename); - } + if (load_svg(filenames)) { + return true; } for (const auto& filename : filenames) { @@ -10689,6 +10700,9 @@ void Plater::add_file() case LoadFilesType::SingleOther: { Plater::TakeSnapshot snapshot(this, snapshot_label); + if (load_svg(input_files,true)) { + return; + } if (!load_files(paths, LoadStrategy::LoadModel, false).empty()) { if (get_project_name() == _L("Untitled") && paths.size() > 0) { p->set_project_filename(wxString::FromUTF8(paths[0].string())); diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 6dbfb44f6..a2a96ce42 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -288,9 +288,9 @@ public: // To be called when providing a list of files to the GUI slic3r on command line. std::vector load_files(const std::vector& input_files, LoadStrategy strategy = LoadStrategy::LoadModel | LoadStrategy::LoadConfig, bool ask_multi = false); // to be called on drag and drop - bool emboss_svg(const wxString &svg_file); + bool emboss_svg(const wxString &svg_file, bool from_toolbar_or_file_menu = false); + bool load_svg(const wxArrayString &filenames, bool from_toolbar_or_file_menu = false); bool load_files(const wxArrayString& filenames); - const wxString& get_last_loaded_gcode() const { return m_last_loaded_gcode; } void update(bool conside_update_flag = false, bool force_background_processing_update = false);