NEW:Unified SVG import entrance

jira: none

Change-Id: Ieabad4379765202383b09af905ad59a53d9abd5a
This commit is contained in:
zhou.xu 2024-09-11 10:03:52 +08:00 committed by Lane.Wei
parent a557bbe758
commit 20547f58c1
5 changed files with 49 additions and 23 deletions

View File

@ -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;

View File

@ -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);
/// <summary>
/// Check whether volume is object containing only emboss volume
/// </summary>

View File

@ -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;

View File

@ -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<fs::path> normal_paths;
std::vector<fs::path> 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()));

View File

@ -288,9 +288,9 @@ public:
// To be called when providing a list of files to the GUI slic3r on command line.
std::vector<size_t> load_files(const std::vector<std::string>& 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);