mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 04:12:01 +08:00
Drag&Drop .svg file to plater
This commit is contained in:
parent
4db49f7882
commit
2cc881ba18
@ -103,6 +103,7 @@
|
||||
#include "MsgDialog.hpp"
|
||||
#include "ProjectDirtyStateManager.hpp"
|
||||
#include "Gizmos/GLGizmoSimplify.hpp" // create suggestion notification
|
||||
#include "Gizmos/GLGizmoSVG.hpp" // Drop SVG file
|
||||
#include "Gizmos/GLGizmoCut.hpp"
|
||||
#include "FileArchiveDialog.hpp"
|
||||
|
||||
@ -1616,6 +1617,29 @@ private:
|
||||
Plater& m_plater;
|
||||
};
|
||||
|
||||
namespace {
|
||||
bool emboss_svg(Plater& plater, const wxString &svg_file, const Vec2d& mouse_drop_position)
|
||||
{
|
||||
std::string svg_file_str = svg_file.ToStdString();
|
||||
GLCanvas3D* canvas = plater.canvas3D();
|
||||
if (canvas == nullptr)
|
||||
return false;
|
||||
auto base_svg = canvas->get_gizmos_manager().get_gizmo(GLGizmosManager::Svg);
|
||||
if (base_svg == nullptr)
|
||||
return false;
|
||||
GLGizmoSVG* svg = dynamic_cast<GLGizmoSVG *>(base_svg);
|
||||
if (svg == nullptr)
|
||||
return false;
|
||||
|
||||
// Refresh hover state to find surface point under mouse
|
||||
wxMouseEvent evt(wxEVT_MOTION);
|
||||
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, ModelVolumeType::MODEL_PART, mouse_drop_position);
|
||||
}
|
||||
}
|
||||
|
||||
bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames)
|
||||
{
|
||||
#ifdef WIN32
|
||||
@ -1627,6 +1651,14 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &fi
|
||||
m_mainframe.select_tab(size_t(0));
|
||||
if (wxGetApp().is_editor())
|
||||
m_plater.select_view_3D("3D");
|
||||
|
||||
// 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)
|
||||
return emboss_svg(m_plater, filename, Vec2d(x, y));
|
||||
}
|
||||
bool res = m_plater.load_files(filenames);
|
||||
m_mainframe.update_title();
|
||||
return res;
|
||||
|
Loading…
x
Reference in New Issue
Block a user