From 41f29c9f0919ac53412428635ccda2e2009d5e81 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 15 May 2019 12:30:06 +0200 Subject: [PATCH 1/3] Fix of #2237 --- src/slic3r/GUI/Field.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index e3a9bb2c7..e7bdd1e6b 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -520,8 +520,14 @@ void SpinCtrl::BUILD() { // Forcibly set the input value for SpinControl, since the value // inserted from the clipboard is not updated under OSX - if (tmp_value > -9999) - dynamic_cast(window)->SetValue(tmp_value); + if (tmp_value > -9999) { + wxSpinCtrl* spin = dynamic_cast(window); + spin->SetValue(tmp_value); + + // But in SetValue() is executed m_text_ctrl->SelectAll(), so + // discard this selection and set insertion point to the end of string + spin->GetText()->SetInsertionPointEnd(); + } #endif }), temp->GetId()); From d0fd8a4a29266c2b080580b648882aaf4ea75117 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 15 May 2019 14:09:16 +0200 Subject: [PATCH 2/3] Follow-up of f54fd10897cae193a783622af85d56e5e1293a86 -> Project name stored with no extension, updated after drag and drop of .3mf or .amf files and used by export g-code and send g-code commands --- src/slic3r/GUI/MainFrame.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 64 +++++++++++++++++++++++++----------- src/slic3r/GUI/Plater.hpp | 4 ++- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 4b625a73a..296776da4 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -382,7 +382,7 @@ void MainFrame::init_menubar() [this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, menu_icon("open"), nullptr, [this](){return m_plater != nullptr; }, this); append_menu_item(fileMenu, wxID_ANY, _(L("&Save Project")) + "\tCtrl+S", _(L("Save current project file")), - [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(into_path(m_plater->get_project_filename())); }, menu_icon("save"), nullptr, + [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(into_path(m_plater->get_project_filename(".3mf"))); }, menu_icon("save"), nullptr, [this](){return m_plater != nullptr && can_save(); }, this); append_menu_item(fileMenu, wxID_ANY, _(L("Save Project &as")) + dots + "\tCtrl+Alt+S", _(L("Save current project file as")), [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(); }, menu_icon("save"), nullptr, diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 948b4948e..ea6dd3c09 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1171,7 +1171,26 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &fi } } + // FIXME: when drag and drop is done on a .3mf or a .amf file we should clear the plater for consistence with the open project command + // (the following call to plater->load_files() will load the config data, if present) + plater->load_files(paths); + + // because right now the plater is not cleared, we set the project file (from the latest imported .3mf or .amf file) + // only if not set yet + if (plater->get_project_filename().empty()) + { + for (std::vector::const_reverse_iterator it = paths.rbegin(); it != paths.rend(); ++it) + { + std::string filename = (*it).filename().string(); + if (boost::algorithm::iends_with(filename, ".3mf") || boost::algorithm::iends_with(filename, ".amf")) + { + plater->set_project_filename(from_path(*it)); + break; + } + } + } + return true; } @@ -1341,7 +1360,9 @@ struct Plater::priv void msw_rescale_object_menu(); - const wxString& get_project_filename() const; + // returns the path to project file with the given extension (none if extension == wxEmptyString) + // extension should contain the leading dot, i.e.: ".3mf" + wxString get_project_filename(const wxString& extension = wxEmptyString) const; void set_project_filename(const wxString& filename); private: @@ -1358,6 +1379,7 @@ private: void update_fff_scene(); void update_sla_scene(); + // path to project file stored with no extension wxString m_project_filename; }; @@ -1936,7 +1958,7 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type) fs::path output_file; if (file_type == FT_3MF) // for 3mf take the path from the project filename, if any - output_file = into_path(get_project_filename()); + output_file = into_path(get_project_filename(".3mf")); if (output_file.empty()) { @@ -2941,22 +2963,19 @@ void Plater::priv::msw_rescale_object_menu() msw_rescale_menu(dynamic_cast(menu)); } -const wxString& Plater::priv::get_project_filename() const +wxString Plater::priv::get_project_filename(const wxString& extension) const { - return m_project_filename; + return m_project_filename.empty() ? wxEmptyString : m_project_filename + extension; } void Plater::priv::set_project_filename(const wxString& filename) { - std::string copy = into_u8(filename); - if (boost::algorithm::iends_with(copy, ".zip.amf")) - // we remove the .zip part of the extension - copy = boost::ireplace_last_copy(copy, ".zip.", "."); - - // we force 3mf extension - boost::filesystem::path full_path(copy); - if (!full_path.empty()) - full_path.replace_extension("3mf"); + boost::filesystem::path full_path = into_path(filename); + // remove extension + while (full_path.has_extension()) + { + full_path.replace_extension(""); + } m_project_filename = from_path(full_path); wxGetApp().mainframe->update_title(); @@ -3473,8 +3492,9 @@ void Plater::export_gcode() unsigned int state = this->p->update_restart_background_process(false, false); if (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) return; - default_output_file = this->p->background_process.current_print()->output_filepath(""); - } catch (const std::exception &ex) { + default_output_file = this->p->background_process.current_print()->output_filepath(into_path(get_project_filename()).string()); + } + catch (const std::exception &ex) { show_error(this, ex.what()); return; } @@ -3717,8 +3737,9 @@ void Plater::send_gcode() unsigned int state = this->p->update_restart_background_process(false, false); if (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) return; - default_output_file = this->p->background_process.current_print()->output_filepath(""); - } catch (const std::exception &ex) { + default_output_file = this->p->background_process.current_print()->output_filepath(into_path(get_project_filename(".3mf")).string()); + } + catch (const std::exception &ex) { show_error(this, ex.what()); return; } @@ -3832,9 +3853,14 @@ void Plater::on_activate() } } -const wxString& Plater::get_project_filename() const +wxString Plater::get_project_filename(const wxString& extension) const { - return p->get_project_filename(); + return p->get_project_filename(extension); +} + +void Plater::set_project_filename(const wxString& filename) +{ + return p->set_project_filename(filename); } bool Plater::is_export_gcode_scheduled() const diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index d4d4b3d18..bc6d4b942 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -184,7 +184,9 @@ public: void update_object_menu(); - const wxString& get_project_filename() const; + wxString get_project_filename(const wxString& extension = wxEmptyString) const; + void set_project_filename(const wxString& filename); + bool is_export_gcode_scheduled() const; int get_selected_object_idx(); From 0298e9077f8669bcb71aa4d8dd7f03a1fcdbe27c Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 15 May 2019 14:55:51 +0200 Subject: [PATCH 3/3] Fix build of d0fd8a4a29266c2b080580b648882aaf4ea75117 on OsX and Linux --- src/slic3r/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ea6dd3c09..c63ae73f2 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2965,7 +2965,7 @@ void Plater::priv::msw_rescale_object_menu() wxString Plater::priv::get_project_filename(const wxString& extension) const { - return m_project_filename.empty() ? wxEmptyString : m_project_filename + extension; + return m_project_filename.empty() ? "" : m_project_filename + extension; } void Plater::priv::set_project_filename(const wxString& filename)