Merge branch 'master' into lm_tm_hollowing

This commit is contained in:
Lukas Matena 2020-01-06 12:41:29 +01:00
commit 0551411c48
82 changed files with 2066 additions and 462 deletions

View file

@ -113,6 +113,8 @@ set(SLIC3R_GUI_SOURCES
GUI/WipeTowerDialog.hpp
GUI/RammingChart.cpp
GUI/RammingChart.hpp
GUI/RemovableDriveManager.cpp
GUI/RemovableDriveManager.hpp
GUI/BonjourDialog.cpp
GUI/BonjourDialog.hpp
GUI/ButtonsDescription.cpp
@ -153,6 +155,8 @@ set(SLIC3R_GUI_SOURCES
Utils/Duet.hpp
Utils/FlashAir.cpp
Utils/FlashAir.hpp
Utils/AstroBox.cpp
Utils/AstroBox.hpp
Utils/PrintHost.cpp
Utils/PrintHost.hpp
Utils/Bonjour.cpp
@ -170,7 +174,12 @@ if (APPLE)
list(APPEND SLIC3R_GUI_SOURCES
Utils/RetinaHelperImpl.mm
Utils/MacDarkMode.mm
GUI/RemovableDriveManagerMM.mm
GUI/RemovableDriveManagerMM.h
)
#DK
FIND_LIBRARY(DISKARBITRATION_LIBRARY DiskArbitration)
endif ()
add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES})
@ -178,6 +187,11 @@ add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES})
encoding_check(libslic3r_gui)
target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi)
#DK
if(APPLE)
target_link_libraries(libslic3r_gui ${DISKARBITRATION_LIBRARY})
endif()
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
endif ()

View file

@ -205,7 +205,7 @@ size_t Index::load(const boost::filesystem::path &path)
#endif
++ idx_line;
// Skip the initial white spaces.
char *key = left_trim(const_cast<char*>(line.data()));
char *key = left_trim(line.data());
if (*key == '#')
// Skip a comment line.
continue;

View file

@ -271,7 +271,11 @@ void AppConfig::set_recent_projects(const std::vector<std::string>& recent_proje
}
}
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed)
#else
void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone)
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
@ -283,6 +287,9 @@ void AppConfig::set_mouse_device(const std::string& name, double translation_spe
it->second["translation_deadzone"] = std::to_string(translation_deadzone);
it->second["rotation_speed"] = std::to_string(rotation_speed);
it->second["rotation_deadzone"] = std::to_string(rotation_deadzone);
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
it->second["zoom_speed"] = std::to_string(zoom_speed);
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
}
bool AppConfig::get_mouse_device_translation_speed(const std::string& name, double& speed)
@ -345,6 +352,23 @@ bool AppConfig::get_mouse_device_rotation_deadzone(const std::string& name, floa
return true;
}
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
bool AppConfig::get_mouse_device_zoom_speed(const std::string& name, double& speed)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find("zoom_speed");
if (it_val == it->second.end())
return false;
speed = (float)::atof(it_val->second.c_str());
return true;
}
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
void AppConfig::update_config_dir(const std::string &dir)
{
this->set("recent", "config_directory", dir);
@ -357,6 +381,7 @@ void AppConfig::update_skein_dir(const std::string &dir)
std::string AppConfig::get_last_output_dir(const std::string &alt) const
{
const auto it = m_storage.find("");
if (it != m_storage.end()) {
const auto it2 = it->second.find("last_output_path");

View file

@ -131,11 +131,18 @@ public:
std::vector<std::string> get_recent_projects() const;
void set_recent_projects(const std::vector<std::string>& recent_projects);
void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone);
bool get_mouse_device_translation_speed(const std::string& name, double& speed);
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed);
#else
void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone);
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
bool get_mouse_device_translation_speed(const std::string& name, double& speed);
bool get_mouse_device_translation_deadzone(const std::string& name, double& deadzone);
bool get_mouse_device_rotation_speed(const std::string& name, float& speed);
bool get_mouse_device_rotation_deadzone(const std::string& name, float& deadzone);
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
bool get_mouse_device_zoom_speed(const std::string& name, double& speed);
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
static const std::string SECTION_FILAMENTS;
static const std::string SECTION_MATERIALS;

View file

@ -34,6 +34,7 @@
#include <boost/nowide/cstdio.hpp>
#include "I18N.hpp"
#include "GUI.hpp"
#include "RemovableDriveManager.hpp"
namespace Slic3r {
@ -107,7 +108,7 @@ void BackgroundSlicingProcess::process_fff()
//FIXME localize the messages
// Perform the final post-processing of the export path by applying the print statistics over the file name.
std::string export_path = m_fff_print->print_statistics().finalize_output_path(m_export_path);
if (copy_file(m_temp_output_path, export_path) != 0)
if (copy_file(m_temp_output_path, export_path, GUI::RemovableDriveManager::get_instance().is_path_on_removable_drive(export_path)) != 0)
throw std::runtime_error(_utf8(L("Copying of the temporary G-code to the output G-code failed. Maybe the SD card is write locked?")));
m_print->set_status(95, _utf8(L("Running post-processing scripts")));
run_post_process_scripts(export_path, m_fff_print->config());

View file

@ -338,7 +338,7 @@ void Camera::debug_render() const
float fov = (float)get_fov();
float gui_scale = (float)get_gui_scale();
ImGui::InputText("Type", const_cast<char*>(type.data()), type.length(), ImGuiInputTextFlags_ReadOnly);
ImGui::InputText("Type", type.data(), type.length(), ImGuiInputTextFlags_ReadOnly);
ImGui::Separator();
ImGui::InputFloat3("Position", position.data(), "%.6f", ImGuiInputTextFlags_ReadOnly);
ImGui::InputFloat3("Target", target.data(), "%.6f", ImGuiInputTextFlags_ReadOnly);

View file

@ -1605,7 +1605,27 @@ void ConfigWizard::priv::on_3rdparty_install(const VendorProfile *vendor, bool i
load_pages();
}
bool ConfigWizard::priv::check_material_config(Technology technology)
bool ConfigWizard::priv::on_bnt_finish()
{
/* When Filaments or Sla Materials pages are activated,
* materials for this pages are automaticaly updated and presets are reloaded.
*
* But, if _Finish_ button was clicked without activation of those pages
* (for example, just some printers were added/deleted),
* than last changes wouldn't be updated for filaments/materials.
* SO, do that before close of Wizard
*/
update_materials(T_ANY);
if (any_fff_selected)
page_filaments->reload_presets();
if (any_sla_selected)
page_sla_materials->reload_presets();
// check, that there is selected at least one filament/material
return check_materials_in_config(T_ANY);
}
bool ConfigWizard::priv::check_materials_in_config(Technology technology)
{
const auto exist_preset = [this](const std::string& section, const Materials& materials)
{
@ -1899,16 +1919,15 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
// check, that there is selected at least one filament/material
ConfigWizardPage* active_page = this->p->index->active_page();
if ( (active_page == p->page_filaments || active_page == p->page_sla_materials)
&& !p->check_material_config(dynamic_cast<PageMaterials*>(active_page)->materials->technology))
&& !p->check_materials_in_config(dynamic_cast<PageMaterials*>(active_page)->materials->technology))
return;
this->p->index->go_next();
});
p->btn_finish->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &)
{
if (!p->check_material_config(T_ANY))
return;
this->EndModal(wxID_OK);
if (p->on_bnt_finish())
this->EndModal(wxID_OK);
});
p->btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) {

View file

@ -489,7 +489,8 @@ struct ConfigWizard::priv
void on_printer_pick(PagePrinters *page, const PrinterPickerEvent &evt);
void on_3rdparty_install(const VendorProfile *vendor, bool install);
bool check_material_config(Technology technology);
bool on_bnt_finish();
bool check_materials_in_config(Technology technology);
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
// #ys_FIXME_alise
void update_presets_in_config(const std::string& section, const std::string& alias_key, bool add);

View file

@ -142,7 +142,7 @@ bool GLShader::load_from_file(const char* fragment_shader_filename, const char*
int file_length = (int)vs.tellg();
vs.seekg(0, vs.beg);
std::string vertex_shader(file_length, '\0');
vs.read(const_cast<char*>(vertex_shader.data()), file_length);
vs.read(vertex_shader.data(), file_length);
if (!vs.good())
return false;
@ -156,7 +156,7 @@ bool GLShader::load_from_file(const char* fragment_shader_filename, const char*
file_length = (int)fs.tellg();
fs.seekg(0, fs.beg);
std::string fragment_shader(file_length, '\0');
fs.read(const_cast<char*>(fragment_shader.data()), file_length);
fs.read(fragment_shader.data(), file_length);
if (!fs.good())
return false;

View file

@ -46,6 +46,7 @@
#include "SysInfoDialog.hpp"
#include "KBShortcutsDialog.hpp"
#include "UpdateDialogs.hpp"
#include "RemovableDriveManager.hpp"
#ifdef __WXMSW__
#include <Shlobj.h>
@ -261,6 +262,8 @@ bool GUI_App::on_init_inner()
m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg()));
RemovableDriveManager::get_instance().init();
Bind(wxEVT_IDLE, [this](wxIdleEvent& event)
{
if (! plater_)
@ -271,6 +274,10 @@ bool GUI_App::on_init_inner()
this->obj_manipul()->update_if_dirty();
#if !__APPLE__
RemovableDriveManager::get_instance().update(wxGetLocalTime(), true);
#endif
// Preset updating & Configwizard are done after the above initializations,
// and after MainFrame is created & shown.
// The extra CallAfter() is needed because of Mac, where this is the only way
@ -298,6 +305,7 @@ bool GUI_App::on_init_inner()
preset_updater->slic3r_update_notify();
preset_updater->sync(preset_bundle);
});
}
});

View file

@ -2931,6 +2931,7 @@ bool ObjectList::edit_layer_range(const t_layer_height_range& range, coordf_t la
layer_height <= get_max_layer_height(extruder_idx))
{
config->set_key_value("layer_height", new ConfigOptionFloat(layer_height));
changed_object(obj_idx);
return true;
}
@ -2952,6 +2953,7 @@ bool ObjectList::edit_layer_range(const t_layer_height_range& range, const t_lay
ranges.erase(range);
ranges[new_range] = config;
changed_object(obj_idx);
wxDataViewItem root_item = m_objects_model->GetLayerRootItem(m_objects_model->GetItemById(obj_idx));
// To avoid update selection after deleting of a selected item (under GTK)

View file

@ -341,11 +341,6 @@ void Preview::set_number_extruders(unsigned int number_extruders)
}
}
void Preview::set_canvas_as_dirty()
{
m_canvas->set_as_dirty();
}
void Preview::set_enabled(bool enabled)
{
m_enabled = enabled;

View file

@ -116,7 +116,6 @@ public:
void set_as_dirty();
void set_number_extruders(unsigned int number_extruders);
void set_canvas_as_dirty();
void set_enabled(bool enabled);
void bed_shape_changed();
void select_view(const std::string& direction);

View file

@ -57,13 +57,19 @@ const double Mouse3DController::State::DefaultTranslationScale = 2.5;
const double Mouse3DController::State::MaxTranslationDeadzone = 0.2;
const double Mouse3DController::State::DefaultTranslationDeadzone = 0.5 * Mouse3DController::State::MaxTranslationDeadzone;
const float Mouse3DController::State::DefaultRotationScale = 1.0f;
const float Mouse3DController::State::MaxRotationDeadzone = (float)Mouse3DController::State::MaxTranslationDeadzone;
const float Mouse3DController::State::MaxRotationDeadzone = 0.2f;
const float Mouse3DController::State::DefaultRotationDeadzone = 0.5f * Mouse3DController::State::MaxRotationDeadzone;
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
const double Mouse3DController::State::DefaultZoomScale = 0.1;
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
Mouse3DController::State::State()
: m_buttons_enabled(false)
, m_translation_params(DefaultTranslationScale, DefaultTranslationDeadzone)
, m_rotation_params(DefaultRotationScale, DefaultRotationDeadzone)
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
, m_zoom_params(DefaultZoomScale, 0.0)
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
, m_mouse_wheel_counter(0)
#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
, m_translation_queue_max_size(0)
@ -112,7 +118,7 @@ void Mouse3DController::State::append_button(unsigned int id)
bool Mouse3DController::State::process_mouse_wheel()
{
if (m_mouse_wheel_counter == 0)
if (m_mouse_wheel_counter.load() == 0)
return false;
else if (!m_rotation.queue.empty())
{
@ -120,7 +126,7 @@ bool Mouse3DController::State::process_mouse_wheel()
return true;
}
m_mouse_wheel_counter = 0;
m_mouse_wheel_counter.store(0);
return true;
}
@ -149,7 +155,13 @@ bool Mouse3DController::State::apply(Camera& camera)
if (has_translation())
{
const Vec3d& translation = m_translation.queue.front();
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(2) * camera.get_dir_up()));
if (translation(1) != 0.0)
camera.update_zoom(m_zoom_params.scale * translation(1) / std::abs(translation(1)));
#else
camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(1) * camera.get_dir_forward() + translation(2) * camera.get_dir_up()));
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
m_translation.queue.pop();
ret = true;
}
@ -229,8 +241,6 @@ bool Mouse3DController::apply(Camera& camera)
if (!m_initialized)
return false;
std::lock_guard<std::mutex> lock(m_mutex);
// check if the user unplugged the device
if (!m_running && is_device_connected())
{
@ -311,20 +321,30 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign
ImGui::PopStyleColor();
float translation_scale = (float)m_state.get_translation_scale() / State::DefaultTranslationScale;
if (imgui.slider_float(_(L("Translation")) + "##1", &translation_scale, 0.5f, 2.0f, "%.1f"))
if (imgui.slider_float(_(L("Translation")) + "##1", &translation_scale, 0.2f, 5.0f, "%.1f"))
m_state.set_translation_scale(State::DefaultTranslationScale * (double)translation_scale);
float rotation_scale = m_state.get_rotation_scale() / State::DefaultRotationScale;
if (imgui.slider_float(_(L("Rotation")) + "##1", &rotation_scale, 0.5f, 2.0f, "%.1f"))
if (imgui.slider_float(_(L("Rotation")) + "##1", &rotation_scale, 0.2f, 5.0f, "%.1f"))
m_state.set_rotation_scale(State::DefaultRotationScale * rotation_scale);
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
float zoom_scale = m_state.get_zoom_scale() / State::DefaultZoomScale;
if (imgui.slider_float(_(L("Zoom")), &zoom_scale, 0.2f, 5.0f, "%.1f"))
m_state.set_zoom_scale(State::DefaultZoomScale * zoom_scale);
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
ImGui::Separator();
ImGui::PushStyleColor(ImGuiCol_Text, color);
imgui.text(_(L("Deadzone:")));
ImGui::PopStyleColor();
float translation_deadzone = (float)m_state.get_translation_deadzone();
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
if (imgui.slider_float(_(L("Translation")) + "/" + _(L("Zoom")), &translation_deadzone, 0.0f, (float)State::MaxTranslationDeadzone, "%.2f"))
#else
if (imgui.slider_float(_(L("Translation")) + "##2", &translation_deadzone, 0.0f, (float)State::MaxTranslationDeadzone, "%.2f"))
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
m_state.set_translation_deadzone((double)translation_deadzone);
float rotation_deadzone = m_state.get_rotation_deadzone();
@ -393,7 +413,7 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign
bool Mouse3DController::connect_device()
{
static const long long DETECTION_TIME_MS = 2000; // seconds
static const long long DETECTION_TIME_MS = 2000; // two seconds
if (is_device_connected())
return false;
@ -619,30 +639,36 @@ bool Mouse3DController::connect_device()
hid_get_product_string(m_device, product.data(), 1024);
m_device_str += "/" + boost::nowide::narrow(product.data());
BOOST_LOG_TRIVIAL(info) << "Connected device: " << m_device_str;
#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
std::cout << std::endl << "Connected device:" << std::endl;
std::cout << "Manufacturer/product: " << m_device_str << std::endl;
std::cout << "Manufacturer id.....: " << vendor_id << " (" << std::hex << vendor_id << std::dec << ")" << std::endl;
std::cout << "Product id..........: " << product_id << " (" << std::hex << product_id << std::dec << ")" << std::endl;
std::cout << "Path................: '" << path << "'" << std::endl;
#endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
BOOST_LOG_TRIVIAL(info) << "Connected 3DConnexion device:";
BOOST_LOG_TRIVIAL(info) << "Manufacturer/product: " << m_device_str;
BOOST_LOG_TRIVIAL(info) << "Manufacturer id.....: " << vendor_id << " (" << std::hex << vendor_id << std::dec << ")";
BOOST_LOG_TRIVIAL(info) << "Product id..........: " << product_id << " (" << std::hex << product_id << std::dec << ")";
if (!path.empty())
BOOST_LOG_TRIVIAL(info) << "Path................: '" << path << "'";
// get device parameters from the config, if present
double translation_speed = 1.0;
float rotation_speed = 1.0;
double translation_deadzone = State::DefaultTranslationDeadzone;
float rotation_deadzone = State::DefaultRotationDeadzone;
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
double zoom_speed = 1.0;
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
wxGetApp().app_config->get_mouse_device_translation_speed(m_device_str, translation_speed);
wxGetApp().app_config->get_mouse_device_translation_deadzone(m_device_str, translation_deadzone);
wxGetApp().app_config->get_mouse_device_rotation_speed(m_device_str, rotation_speed);
wxGetApp().app_config->get_mouse_device_rotation_deadzone(m_device_str, rotation_deadzone);
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
wxGetApp().app_config->get_mouse_device_zoom_speed(m_device_str, zoom_speed);
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
// clamp to valid values
m_state.set_translation_scale(State::DefaultTranslationScale * std::max(0.5, std::min(2.0, translation_speed)));
m_state.set_translation_deadzone(std::max(0.0, std::min(State::MaxTranslationDeadzone, translation_deadzone)));
m_state.set_rotation_scale(State::DefaultRotationScale * std::max(0.5f, std::min(2.0f, rotation_speed)));
m_state.set_rotation_deadzone(std::max(0.0f, std::min(State::MaxRotationDeadzone, rotation_deadzone)));
m_state.set_translation_scale(State::DefaultTranslationScale * std::clamp(translation_speed, 0.2, 5.0));
m_state.set_translation_deadzone(std::clamp(translation_deadzone, 0.0, State::MaxTranslationDeadzone));
m_state.set_rotation_scale(State::DefaultRotationScale * std::clamp(rotation_speed, 0.2f, 5.0f));
m_state.set_rotation_deadzone(std::clamp(rotation_deadzone, 0.0f, State::MaxRotationDeadzone));
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
m_state.set_zoom_scale(State::DefaultZoomScale * std::clamp(zoom_speed, 0.2, 5.0));
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
}
#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
else
@ -668,8 +694,13 @@ void Mouse3DController::disconnect_device()
m_thread.join();
// Store current device parameters into the config
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
wxGetApp().app_config->set_mouse_device(m_device_str, m_state.get_translation_scale() / State::DefaultTranslationScale, m_state.get_translation_deadzone(),
m_state.get_rotation_scale() / State::DefaultRotationScale, m_state.get_rotation_deadzone(), m_state.get_zoom_scale() / State::DefaultZoomScale);
#else
wxGetApp().app_config->set_mouse_device(m_device_str, m_state.get_translation_scale() / State::DefaultTranslationScale, m_state.get_translation_deadzone(),
m_state.get_rotation_scale() / State::DefaultRotationScale, m_state.get_rotation_deadzone());
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
wxGetApp().app_config->save();
// Close the 3Dconnexion device
@ -697,7 +728,6 @@ void Mouse3DController::run()
collect_input();
}
}
void Mouse3DController::collect_input()
{
DataPacket packet = { 0 };
@ -712,8 +742,6 @@ void Mouse3DController::collect_input()
if (!wxGetApp().IsActive())
return;
std::lock_guard<std::mutex> lock(m_mutex);
bool updated = false;
if (res == 7)
@ -729,8 +757,11 @@ void Mouse3DController::collect_input()
#endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
if (updated)
{
wxGetApp().plater()->set_current_canvas_as_dirty();
// ask for an idle event to update 3D scene
wxWakeUpIdle();
}
}
bool Mouse3DController::handle_packet(const DataPacket& packet)

View file

@ -33,6 +33,9 @@ class Mouse3DController
static const float DefaultRotationScale;
static const float MaxRotationDeadzone;
static const float DefaultRotationDeadzone;
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
static const double DefaultZoomScale;
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
private:
template <typename Number>
@ -64,6 +67,9 @@ class Mouse3DController
CustomParameters<double> m_translation_params;
CustomParameters<float> m_rotation_params;
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
CustomParameters<float> m_zoom_params;
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
// When the 3Dconnexion driver is running the system gets, by default, mouse wheel events when rotations around the X axis are detected.
// We want to filter these out because we are getting the data directly from the device, bypassing the driver, and those mouse wheel events interfere
@ -72,7 +78,7 @@ class Mouse3DController
// Mouse3DController::collect_input() through the call to the append_rotation() method
// GLCanvas3D::on_mouse_wheel() through the call to the process_mouse_wheel() method
// GLCanvas3D::on_idle() through the call to the apply() method
unsigned int m_mouse_wheel_counter;
std::atomic<unsigned int> m_mouse_wheel_counter;
#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
size_t m_translation_queue_max_size;
@ -99,6 +105,11 @@ class Mouse3DController
float get_rotation_scale() const { return m_rotation_params.scale; }
void set_rotation_scale(float scale) { m_rotation_params.scale = scale; }
#if ENABLE_3DCONNEXION_Y_AS_ZOOM
double get_zoom_scale() const { return m_zoom_params.scale; }
void set_zoom_scale(double scale) { m_zoom_params.scale = scale; }
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
double get_translation_deadzone() const { return m_translation_params.deadzone; }
void set_translation_deadzone(double deadzone) { m_translation_params.deadzone = deadzone; }
@ -128,7 +139,6 @@ class Mouse3DController
bool m_initialized;
mutable State m_state;
std::mutex m_mutex;
std::thread m_thread;
hid_device* m_device;
std::string m_device_str;
@ -151,7 +161,7 @@ public:
bool is_device_connected() const { return m_device != nullptr; }
bool is_running() const { return m_running; }
bool process_mouse_wheel() { std::lock_guard<std::mutex> lock(m_mutex); return m_state.process_mouse_wheel(); }
bool process_mouse_wheel() { return m_state.process_mouse_wheel(); }
bool apply(Camera& camera);

View file

@ -80,6 +80,7 @@
#include "../Utils/FixModelByWin10.hpp"
#include "../Utils/UndoRedo.hpp"
#include "../Utils/Thread.hpp"
#include "RemovableDriveManager.hpp"
#include <wx/glcanvas.h> // Needs to be last because reasons :-/
#include "WipeTowerDialog.hpp"
@ -701,7 +702,8 @@ struct Sidebar::priv
wxButton *btn_export_gcode;
wxButton *btn_reslice;
wxButton *btn_send_gcode;
ScalableButton *btn_send_gcode;
ScalableButton *btn_remove_device;
priv(Plater *plater) : plater(plater) {}
~priv();
@ -850,22 +852,47 @@ Sidebar::Sidebar(Plater *parent)
// Buttons underneath the scrolled area
auto init_btn = [this](wxButton **btn, wxString label) {
// rescalable bitmap buttons "Send to printer" and "Remove device"
auto init_scalable_btn = [this](ScalableButton** btn, const std::string& icon_name, wxString tooltip = wxEmptyString)
{
#ifdef __APPLE__
int bmp_px_cnt = 16;
#else
int bmp_px_cnt = 32;
#endif //__APPLE__
ScalableBitmap bmp = ScalableBitmap(this, icon_name, bmp_px_cnt);
*btn = new ScalableButton(this, wxID_ANY, bmp, "", wxBU_EXACTFIT);
(*btn)->SetToolTip(tooltip);
(*btn)->Hide();
};
init_scalable_btn(&p->btn_send_gcode , "export_gcode", _(L("Send to printer")));
init_scalable_btn(&p->btn_remove_device, "cross" , _(L("Remove device")));
// regular buttons "Slice now" and "Export G-code"
const int scaled_height = p->btn_remove_device->GetBitmapHeight() + 4;
auto init_btn = [this](wxButton **btn, wxString label, const int button_height) {
*btn = new wxButton(this, wxID_ANY, label, wxDefaultPosition,
wxDefaultSize, wxBU_EXACTFIT);
wxSize(-1, button_height), wxBU_EXACTFIT);
(*btn)->SetFont(wxGetApp().bold_font());
};
init_btn(&p->btn_send_gcode, _(L("Send to printer")));
p->btn_send_gcode->Hide();
init_btn(&p->btn_export_gcode, _(L("Export G-code")) + dots);
init_btn(&p->btn_reslice, _(L("Slice now")));
init_btn(&p->btn_export_gcode, _(L("Export G-code")) + dots , scaled_height);
init_btn(&p->btn_reslice , _(L("Slice now")) , scaled_height);
enable_buttons(false);
auto *btns_sizer = new wxBoxSizer(wxVERTICAL);
auto* complect_btns_sizer = new wxBoxSizer(wxHORIZONTAL);
complect_btns_sizer->Add(p->btn_export_gcode, 1, wxEXPAND);
complect_btns_sizer->Add(p->btn_send_gcode);
complect_btns_sizer->Add(p->btn_remove_device);
btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, margin_5);
btns_sizer->Add(p->btn_send_gcode, 0, wxEXPAND | wxTOP, margin_5);
btns_sizer->Add(p->btn_export_gcode, 0, wxEXPAND | wxTOP, margin_5);
btns_sizer->Add(complect_btns_sizer, 0, wxEXPAND | wxTOP, margin_5);
auto *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(p->scrolled, 1, wxEXPAND);
@ -884,6 +911,7 @@ Sidebar::Sidebar(Plater *parent)
p->plater->select_view_3D("Preview");
});
p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->send_gcode(); });
p->btn_remove_device->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->eject_drive(); });
}
Sidebar::~Sidebar() {}
@ -1029,6 +1057,12 @@ void Sidebar::msw_rescale()
p->object_info->msw_rescale();
p->btn_send_gcode->msw_rescale();
p->btn_remove_device->msw_rescale();
const int scaled_height = p->btn_remove_device->GetBitmap().GetHeight() + 4;
p->btn_export_gcode->SetMinSize(wxSize(-1, scaled_height));
p->btn_reslice ->SetMinSize(wxSize(-1, scaled_height));
p->scrolled->Layout();
}
@ -1257,11 +1291,13 @@ void Sidebar::enable_buttons(bool enable)
p->btn_reslice->Enable(enable);
p->btn_export_gcode->Enable(enable);
p->btn_send_gcode->Enable(enable);
p->btn_remove_device->Enable(enable);
}
bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); }
bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); }
bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); }
bool Sidebar::show_disconnect(bool show)const { return p->btn_remove_device->Show(show); }
bool Sidebar::is_multifilament()
{
@ -1736,6 +1772,8 @@ struct Plater::priv
bool is_preview_loaded() const { return preview->is_loaded(); }
bool is_view3D_shown() const { return current_panel == view3D; }
void set_current_canvas_as_dirty();
#if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX
bool init_view_toolbar();
#endif // ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX
@ -3140,6 +3178,7 @@ void Plater::priv::update_fff_scene()
this->preview->reload_print();
// In case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth:
view3D->reload_scene(true);
}
void Plater::priv::update_sla_scene()
@ -3308,17 +3347,26 @@ void Plater::priv::reload_from_disk()
new_volume->config.apply(old_volume->config);
new_volume->set_type(old_volume->type());
new_volume->set_material_id(old_volume->material_id());
#if ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE
new_volume->set_transformation(old_volume->get_transformation() * old_volume->source.transform);
#else
new_volume->set_transformation(old_volume->get_transformation());
#endif // ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE
new_volume->translate(new_volume->get_transformation().get_matrix(true) * (new_volume->source.mesh_offset - old_volume->source.mesh_offset));
new_volume->source.input_file = path;
std::swap(old_model_object->volumes[old_v.volume_idx], old_model_object->volumes.back());
old_model_object->delete_volume(old_model_object->volumes.size() - 1);
#if ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE
old_model_object->ensure_on_bed();
#endif // ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE
}
}
}
}
#if !ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE
model.adjust_min_z();
#endif // !ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE
// update 3D scene
update();
@ -3412,7 +3460,7 @@ void Plater::priv::set_current_panel(wxPanel* panel)
// keeps current gcode preview, if any
preview->reload_print(true);
preview->set_canvas_as_dirty();
preview->set_as_dirty();
view_toolbar.select_item("Preview");
}
@ -3553,6 +3601,7 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt)
break;
default: break;
}
if (canceled) {
if (wxGetApp().get_mode() == comSimple)
@ -3561,6 +3610,16 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt)
}
else if (wxGetApp().get_mode() == comSimple)
show_action_buttons(false);
if(!canceled && RemovableDriveManager::get_instance().get_is_writing())
{
//if (!RemovableDriveManager::get_instance().is_last_drive_removed())
//{
RemovableDriveManager::get_instance().set_is_writing(false);
show_action_buttons(false);
//}
}
}
void Plater::priv::on_layer_editing_toggled(bool enable)
@ -3914,6 +3973,14 @@ bool Plater::priv::complit_init_part_menu()
return true;
}
void Plater::priv::set_current_canvas_as_dirty()
{
if (current_panel == view3D)
view3D->set_as_dirty();
else if (current_panel == preview)
preview->set_as_dirty();
}
#if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX
bool Plater::priv::init_view_toolbar()
#else
@ -4027,7 +4094,11 @@ bool Plater::priv::can_reload_from_disk() const
const GLVolume* v = selection.get_volume(idx);
int v_idx = v->volume_idx();
if (v_idx >= 0)
selected_volumes.push_back({ v->object_idx(), v_idx });
{
int o_idx = v->object_idx();
if ((0 <= o_idx) && (o_idx < (int)model.objects.size()))
selected_volumes.push_back({ o_idx, v_idx });
}
}
std::sort(selected_volumes.begin(), selected_volumes.end());
selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end()), selected_volumes.end());
@ -4129,20 +4200,23 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const
wxWindowUpdateLocker noUpdater(sidebar);
const auto prin_host_opt = config->option<ConfigOptionString>("print_host");
const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty();
bool disconnect_shown = !RemovableDriveManager::get_instance().is_last_drive_removed() ; // #dk_FIXME
// when a background processing is ON, export_btn and/or send_btn are showing
if (wxGetApp().app_config->get("background_processing") == "1")
{
if (sidebar->show_reslice(false) |
sidebar->show_export(true) |
sidebar->show_send(send_gcode_shown))
sidebar->show_send(send_gcode_shown) |
sidebar->show_disconnect(disconnect_shown))
sidebar->Layout();
}
else
{
if (sidebar->show_reslice(is_ready_to_slice) |
sidebar->show_export(!is_ready_to_slice) |
sidebar->show_send(send_gcode_shown && !is_ready_to_slice))
sidebar->show_send(send_gcode_shown && !is_ready_to_slice) |
sidebar->show_disconnect(disconnect_shown && !is_ready_to_slice))
sidebar->Layout();
}
}
@ -4383,7 +4457,7 @@ void Sidebar::set_btn_label(const ActionButtonType btn_type, const wxString& lab
{
case ActionButtonType::abReslice: p->btn_reslice->SetLabelText(label); break;
case ActionButtonType::abExport: p->btn_export_gcode->SetLabelText(label); break;
case ActionButtonType::abSendGCode: p->btn_send_gcode->SetLabelText(label); break;
case ActionButtonType::abSendGCode: /*p->btn_send_gcode->SetLabelText(label);*/ break;
}
}
@ -4673,7 +4747,13 @@ void Plater::export_gcode()
}
default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string()));
auto start_dir = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string());
if (GUI::RemovableDriveManager::get_instance().update())
{
if (!RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir))
{
start_dir = RemovableDriveManager::get_instance().get_drive_path();
}
}
wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save SL1 file as:")),
start_dir,
from_path(default_output_file.filename()),
@ -4688,7 +4768,22 @@ void Plater::export_gcode()
output_path = std::move(path);
}
if (! output_path.empty())
{
std::string path = output_path.string();
p->export_gcode(std::move(output_path), PrintHostJob());
RemovableDriveManager::get_instance().update(0, false);
RemovableDriveManager::get_instance().set_last_save_path(path);
RemovableDriveManager::get_instance().verify_last_save_path();
if(!RemovableDriveManager::get_instance().is_last_drive_removed())
{
RemovableDriveManager::get_instance().set_is_writing(true);
RemovableDriveManager::get_instance().erase_callbacks();
RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this));
}
}
}
void Plater::export_stl(bool extended, bool selection_only)
@ -4973,6 +5068,27 @@ void Plater::send_gcode()
}
}
void Plater::eject_drive()
{
RemovableDriveManager::get_instance().update(0, true);
//RemovableDriveManager::get_instance().erase_callbacks();
//RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this));
RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path());
}
void Plater::drive_ejected_callback()
{
if (RemovableDriveManager::get_instance().get_did_eject())
{
RemovableDriveManager::get_instance().set_did_eject(false);
wxString message = "Unmounting succesesful. The device " + RemovableDriveManager::get_instance().get_last_save_name() + "(" + RemovableDriveManager::get_instance().get_last_save_path() + ")" + " can now be safely removed from the computer.";
wxMessageBox(message);
}
p->show_action_buttons(false);
}
void Plater::take_snapshot(const std::string &snapshot_name) { p->take_snapshot(snapshot_name); }
void Plater::take_snapshot(const wxString &snapshot_name) { p->take_snapshot(snapshot_name); }
void Plater::suppress_snapshots() { p->suppress_snapshots(); }
@ -5253,6 +5369,11 @@ BoundingBoxf Plater::bed_shape_bb() const
return p->bed_shape_bb();
}
void Plater::set_current_canvas_as_dirty()
{
p->set_current_canvas_as_dirty();
}
PrinterTechnology Plater::printer_technology() const
{
return p->printer_technology;

View file

@ -119,6 +119,7 @@ public:
bool show_reslice(bool show) const;
bool show_export(bool show) const;
bool show_send(bool show) const;
bool show_disconnect(bool show)const;
bool is_multifilament();
void update_mode();
@ -202,6 +203,8 @@ public:
void suppress_background_process(const bool stop_background_process) ;
void fix_through_netfabb(const int obj_idx, const int vol_idx = -1);
void send_gcode();
void eject_drive();
void drive_ejected_callback();
void take_snapshot(const std::string &snapshot_name);
void take_snapshot(const wxString &snapshot_name);
@ -238,6 +241,8 @@ public:
GLCanvas3D* canvas3D();
BoundingBoxf bed_shape_bb() const;
void set_current_canvas_as_dirty();
PrinterTechnology printer_technology() const;
void set_printer_technology(PrinterTechnology printer_technology);

View file

@ -594,6 +594,7 @@ void PresetCollection::reset(bool delete_files)
m_presets.erase(m_presets.begin() + m_num_default_presets, m_presets.end());
this->select_preset(0);
}
m_map_system_profile_renamed.clear();
}
void PresetCollection::add_default_preset(const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name)
@ -707,6 +708,11 @@ Preset& PresetCollection::load_external_preset(
// Is there a preset already loaded with the name stored inside the config?
std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
bool found = it != m_presets.end() && it->name == original_name;
if (! found) {
// Try to match the original_name against the "renamed_from" profile names of loaded system profiles.
it = this->find_preset_renamed(original_name);
found = it != m_presets.end();
}
if (found && profile_print_params_same(it->config, cfg)) {
// The preset exists and it matches the values stored inside config.
if (select)
@ -876,24 +882,27 @@ const Preset* PresetCollection::get_selected_preset_parent() const
if (this->get_selected_idx() == -1)
// This preset collection has no preset activated yet. Only the get_edited_preset() is valid.
return nullptr;
// const std::string &inherits = this->get_edited_preset().inherits();
// if (inherits.empty())
// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
std::string inherits = this->get_edited_preset().inherits();
if (inherits.empty())
{
if (this->get_selected_preset().is_system || this->get_selected_preset().is_default)
return &this->get_selected_preset();
if (this->get_selected_preset().is_external)
const Preset &selected_preset = this->get_selected_preset();
if (selected_preset.is_system || selected_preset.is_default)
return &selected_preset;
const Preset &edited_preset = this->get_edited_preset();
const std::string &inherits = edited_preset.inherits();
const Preset *preset = nullptr;
if (inherits.empty()) {
if (selected_preset.is_external)
return nullptr;
inherits = m_type != Preset::Type::TYPE_PRINTER ? "- default -" :
this->get_edited_preset().printer_technology() == ptFFF ?
"- default FFF -" : "- default SLA -" ;
preset = &this->default_preset(m_type == Preset::Type::TYPE_PRINTER && edited_preset.printer_technology() == ptSLA ? 1 : 0);
} else
preset = this->find_preset(inherits, false);
if (preset == nullptr) {
// Resolve the "renamed_from" field.
assert(! inherits.empty());
auto it = this->find_preset_renamed(inherits);
if (it != m_presets.end())
preset = &(*it);
}
const Preset* preset = this->find_preset(inherits, false);
return (preset == nullptr/* || preset->is_default*/ || preset->is_external) ? nullptr : preset;
}
@ -904,6 +913,11 @@ const Preset* PresetCollection::get_preset_parent(const Preset& child) const
// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
return nullptr;
const Preset* preset = this->find_preset(inherits, false);
if (preset == nullptr) {
auto it = this->find_preset_renamed(inherits);
if (it != m_presets.end())
preset = &(*it);
}
return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset;
}
@ -1406,6 +1420,17 @@ std::vector<std::string> PresetCollection::merge_presets(PresetCollection &&othe
return duplicates;
}
void PresetCollection::update_map_system_profile_renamed()
{
m_map_system_profile_renamed.clear();
for (Preset &preset : m_presets)
for (const std::string &renamed_from : preset.renamed_from) {
const auto [it, success] = m_map_system_profile_renamed.insert(std::pair<std::string, std::string>(renamed_from, preset.name));
if (! success)
BOOST_LOG_TRIVIAL(error) << boost::format("Preset name \"%1%\" was marked as renamed from \"%2%\", though preset name \"%3%\" was marked as renamed from \"%2%\" as well.") % preset.name % renamed_from % it->second;
}
}
std::string PresetCollection::name() const
{
switch (this->type()) {

View file

@ -163,6 +163,10 @@ public:
// Alias of the preset
std::string alias = "";
// List of profile names, from which this profile was renamed at some point of time.
// This list is then used to match profiles by their names when loaded from .gcode, .3mf, .amf,
// and to match the "inherits" field of user profiles with updated system profiles.
std::vector<std::string> renamed_from;
void save();
@ -333,7 +337,8 @@ public:
// The parent preset may be a system preset or a user preset, which will be
// reflected by the UI.
const Preset* get_selected_preset_parent() const;
// get parent preset for some child preset
// Get parent preset for a child preset, based on the "inherits" field of a child,
// where the "inherits" profile name is searched for in both m_presets and m_map_system_profile_renamed.
const Preset* get_preset_parent(const Preset& child) const;
// Return the selected preset including the user modifications.
Preset& get_edited_preset() { return m_edited_preset; }
@ -465,6 +470,9 @@ protected:
// Merge one vendor's presets with the other vendor's presets, report duplicates.
std::vector<std::string> merge_presets(PresetCollection &&other, const VendorMap &new_vendors);
// Update m_map_system_profile_renamed from loaded system profiles.
void update_map_system_profile_renamed();
private:
PresetCollection();
PresetCollection(const PresetCollection &other);
@ -490,6 +498,14 @@ private:
}
std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
std::deque<Preset>::iterator find_preset_renamed(const std::string &name) {
auto it_renamed = m_map_system_profile_renamed.find(name);
auto it = (it_renamed == m_map_system_profile_renamed.end()) ? m_presets.end() : this->find_preset_internal(it_renamed->second);
assert((it_renamed == m_map_system_profile_renamed.end()) || (it != m_presets.end() && it->name == it_renamed->second));
return it;
}
std::deque<Preset>::const_iterator find_preset_renamed(const std::string &name) const
{ return const_cast<PresetCollection*>(this)->find_preset_renamed(name); }
size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, bool unselect_if_incompatible);
@ -501,6 +517,8 @@ private:
// Use deque to force the container to allocate an object per each entry,
// so that the addresses of the presets don't change during resizing of the container.
std::deque<Preset> m_presets;
// Map from old system profile name to a current system profile name.
std::map<std::string, std::string> m_map_system_profile_renamed;
// Initially this preset contains a copy of the selected preset. Later on, this copy may be modified by the user.
Preset m_edited_preset;
// Selected preset.

View file

@ -288,6 +288,11 @@ std::string PresetBundle::load_system_presets()
// No config bundle loaded, reset.
this->reset(false);
}
this->prints .update_map_system_profile_renamed();
this->sla_prints .update_map_system_profile_renamed();
this->filaments .update_map_system_profile_renamed();
this->sla_materials.update_map_system_profile_renamed();
this->printers .update_map_system_profile_renamed();
return errors_cummulative;
}
@ -555,9 +560,11 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
while (filament_configs.size() < num_extruders)
filament_configs.emplace_back(&this->filaments.first_visible().config);
for (const DynamicPrintConfig *cfg : filament_configs) {
compatible_printers_condition.emplace_back(Preset::compatible_printers_condition(*const_cast<DynamicPrintConfig*>(cfg)));
compatible_prints_condition .emplace_back(Preset::compatible_prints_condition(*const_cast<DynamicPrintConfig*>(cfg)));
inherits .emplace_back(Preset::inherits(*const_cast<DynamicPrintConfig*>(cfg)));
// The compatible_prints/printers_condition() returns a reference to configuration key, which may not yet exist.
DynamicPrintConfig &cfg_rw = *const_cast<DynamicPrintConfig*>(cfg);
compatible_printers_condition.emplace_back(Preset::compatible_printers_condition(cfg_rw));
compatible_prints_condition .emplace_back(Preset::compatible_prints_condition(cfg_rw));
inherits .emplace_back(Preset::inherits(cfg_rw));
}
// Option values to set a ConfigOptionVector from.
std::vector<const ConfigOption*> filament_opts(num_extruders, nullptr);
@ -1132,7 +1139,6 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
PresetCollection *presets = nullptr;
std::vector<std::string> *loaded = nullptr;
std::string preset_name;
std::string alias_name;
if (boost::starts_with(section.first, "print:")) {
presets = &this->prints;
loaded = &loaded_prints;
@ -1141,12 +1147,6 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
presets = &this->filaments;
loaded = &loaded_filaments;
preset_name = section.first.substr(9);
for (const auto& item : section.second)
if (boost::starts_with(item.first, "alias")) {
alias_name = item.second.data();
break;
}
} else if (boost::starts_with(section.first, "sla_print:")) {
presets = &this->sla_prints;
loaded = &loaded_sla_prints;
@ -1155,9 +1155,6 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
presets = &this->sla_materials;
loaded = &loaded_sla_materials;
preset_name = section.first.substr(13);
int end_pos = preset_name.find_first_of("0.");
alias_name = preset_name.substr(0, end_pos-1);
} else if (boost::starts_with(section.first, "printer:")) {
presets = &this->printers;
loaded = &loaded_printers;
@ -1213,19 +1210,32 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
// Load the print, filament or printer preset.
const DynamicPrintConfig *default_config = nullptr;
DynamicPrintConfig config;
std::string alias_name;
std::vector<std::string> renamed_from;
auto parse_config_section = [&section, &alias_name, &renamed_from, &path](DynamicPrintConfig &config) {
for (auto &kvp : section.second) {
if (kvp.first == "alias")
alias_name = kvp.second.data();
else if (kvp.first == "renamed_from") {
if (! unescape_strings_cstyle(kvp.second.data(), renamed_from)) {
BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The preset \"" <<
section.first << "\" contains invalid \"renamed_from\" key, which is being ignored.";
}
}
config.set_deserialize(kvp.first, kvp.second.data());
}
};
if (presets == &this->printers) {
// Select the default config based on the printer_technology field extracted from kvp.
DynamicPrintConfig config_src;
for (auto &kvp : section.second)
config_src.set_deserialize(kvp.first, kvp.second.data());
parse_config_section(config_src);
default_config = &presets->default_preset_for(config_src).config;
config = *default_config;
config.apply(config_src);
} else {
default_config = &presets->default_preset().config;
config = *default_config;
for (auto &kvp : section.second)
config.set_deserialize(kvp.first, kvp.second.data());
parse_config_section(config);
}
Preset::normalize(config);
// Report configuration fields, which are misplaced into a wrong group.
@ -1304,12 +1314,22 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
loaded.vendor = vendor_profile;
}
// next step of an preset name aliasing
int end_pos = preset_name.find_first_of("@");
if (end_pos != std::string::npos)
alias_name = preset_name.substr(0, end_pos - 1);
loaded.alias = alias_name.empty() ? preset_name : alias_name;
// Derive the profile logical name aka alias from the preset name if the alias was not stated explicitely.
if (alias_name.empty()) {
int end_pos = preset_name.find_first_of("@");
if (end_pos != std::string::npos) {
alias_name = preset_name.substr(0, end_pos);
if (renamed_from.empty())
// Add the preset name with the '@' character removed into the "renamed_from" list.
renamed_from.emplace_back(alias_name + preset_name.substr(end_pos + 1));
boost::trim_right(alias_name);
}
}
if (alias_name.empty())
loaded.alias = preset_name;
else
loaded.alias = std::move(alias_name);
loaded.renamed_from = std::move(renamed_from);
++ presets_loaded;
}

View file

@ -0,0 +1,590 @@
#include "RemovableDriveManager.hpp"
#include <iostream>
#include "boost/nowide/convert.hpp"
#if _WIN32
#include <windows.h>
#include <tchar.h>
#include <winioctl.h>
#include <shlwapi.h>
#include <Dbt.h>
GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72,
0x8a,0x6d,0xb5,0x4c,0x2b,0x4f,0xc8,0x35 };
#else
//linux includes
#include <errno.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <glob.h>
#include <pwd.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/convenience.hpp>
#endif
namespace Slic3r {
namespace GUI {
#if _WIN32
INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void RemovableDriveManager::search_for_drives()
{
m_current_drives.clear();
//get logical drives flags by letter in alphabetical order
DWORD drives_mask = GetLogicalDrives();
for (size_t i = 0; i < 26; i++)
{
if(drives_mask & (1 << i))
{
std::string path (1,(char)('A' + i));
path+=":";
UINT drive_type = GetDriveTypeA(path.c_str());
// DRIVE_REMOVABLE on W are sd cards and usb thumbnails (not usb harddrives)
if (drive_type == DRIVE_REMOVABLE)
{
// get name of drive
std::wstring wpath = boost::nowide::widen(path);//std::wstring(path.begin(), path.end());
std::wstring volume_name;
volume_name.resize(1024);
std::wstring file_system_name;
file_system_name.resize(1024);
LPWSTR lp_volume_name_buffer = new wchar_t;
BOOL error = GetVolumeInformationW(wpath.c_str(), &volume_name[0], sizeof(volume_name), NULL, NULL, NULL, &file_system_name[0], sizeof(file_system_name));
if(error != 0)
{
volume_name.erase(std::find(volume_name.begin(), volume_name.end(), '\0'), volume_name.end());
/*
if (volume_name == L"")
{
volume_name = L"REMOVABLE DRIVE";
}
*/
if (file_system_name != L"")
{
ULARGE_INTEGER free_space;
GetDiskFreeSpaceExA(path.c_str(), &free_space, NULL, NULL);
if (free_space.QuadPart > 0)
{
path += "\\";
m_current_drives.push_back(DriveData(boost::nowide::narrow(volume_name), path));
}
}
}
}
}
}
}
void RemovableDriveManager::eject_drive(const std::string &path)
{
if(m_current_drives.empty())
return;
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
if ((*it).path == path)
{
// get handle to device
std::string mpath = "\\\\.\\" + path;
mpath = mpath.substr(0, mpath.size() - 1);
HANDLE handle = CreateFileA(mpath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
if (handle == INVALID_HANDLE_VALUE)
{
std::cerr << "Ejecting " << mpath << " failed " << GetLastError() << " \n";
return;
}
DWORD deviceControlRetVal(0);
//these 3 commands should eject device safely but they dont, the device does disappear from file explorer but the "device was safely remove" notification doesnt trigger.
//sd cards does trigger WM_DEVICECHANGE messege, usb drives dont
DeviceIoControl(handle, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr);
DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr);
// some implemenatations also calls IOCTL_STORAGE_MEDIA_REMOVAL here but it returns error to me
BOOL error = DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &deviceControlRetVal, nullptr);
if (error == 0)
{
CloseHandle(handle);
std::cerr << "Ejecting " << mpath << " failed " << deviceControlRetVal << " " << GetLastError() << " \n";
return;
}
CloseHandle(handle);
m_did_eject = true;
m_current_drives.erase(it);
break;
}
}
}
bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path)
{
if (m_current_drives.empty())
return false;
std::size_t found = path.find_last_of("\\");
std::string new_path = path.substr(0, found);
int letter = PathGetDriveNumberA(new_path.c_str());
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
char drive = (*it).path[0];
if (drive == ('A' + letter))
return true;
}
return false;
}
std::string RemovableDriveManager::get_drive_from_path(const std::string& path)
{
std::size_t found = path.find_last_of("\\");
std::string new_path = path.substr(0, found);
int letter = PathGetDriveNumberA(new_path.c_str());
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
char drive = (*it).path[0];
if (drive == ('A' + letter))
return (*it).path;
}
return "";
}
void RemovableDriveManager::register_window()
{
//creates new unvisible window that is recieving callbacks from system
// structure to register
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndClass.hInstance = reinterpret_cast<HINSTANCE>(GetModuleHandle(0));
wndClass.lpfnWndProc = reinterpret_cast<WNDPROC>(WinProcCallback);//this is callback
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hIcon = LoadIcon(0, IDI_APPLICATION);
wndClass.hbrBackground = CreateSolidBrush(RGB(192, 192, 192));
wndClass.hCursor = LoadCursor(0, IDC_ARROW);
wndClass.lpszClassName = L"PrusaSlicer_aux_class";
wndClass.lpszMenuName = NULL;
wndClass.hIconSm = wndClass.hIcon;
if(!RegisterClassEx(&wndClass))
{
DWORD err = GetLastError();
return;
}
HWND hWnd = CreateWindowEx(
WS_EX_NOACTIVATE,
L"PrusaSlicer_aux_class",
L"PrusaSlicer_aux_wnd",
WS_DISABLED, // style
CW_USEDEFAULT, 0,
640, 480,
NULL, NULL,
GetModuleHandle(NULL),
NULL);
if(hWnd == NULL)
{
DWORD err = GetLastError();
}
//ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
}
INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// here we need to catch messeges about device removal
// problem is that when ejecting usb (how is it implemented above) there is no messege dispached. Only after physical removal of the device.
//uncomment register_window() in init() to register and comment update() in GUI_App.cpp (only for windows!) to stop recieving periodical updates
LRESULT lRet = 1;
static HDEVNOTIFY hDeviceNotify;
switch (message)
{
case WM_CREATE:
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = WceusbshGUID;
hDeviceNotify = RegisterDeviceNotification(hWnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
break;
case WM_DEVICECHANGE:
{
// here is the important
if(wParam == DBT_DEVICEREMOVECOMPLETE)
{
- RemovableDriveManager::get_instance().update(0, true);
}
}
break;
default:
// Send all other messages on to the default windows handler.
lRet = DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return lRet;
}
#else
void RemovableDriveManager::search_for_drives()
{
m_current_drives.clear();
#if __APPLE__
// if on macos obj-c class will enumerate
if(m_rdmmm)
{
m_rdmmm->list_devices();
}
#else
//search /media/* folder
search_path("/media/*", "/media");
//search /Volumes/* folder (OSX)
//search_path("/Volumes/*", "/Volumes");
std::string path(std::getenv("USER"));
std::string pp(path);
//std::cout << "user: "<< path << "\n";
//if program is run with sudo, we have to search for all users
// but do we want that?
/*
if(path == "root"){
while (true) {
passwd* entry = getpwent();
if (!entry) {
break;
}
path = entry->pw_name;
pp = path;
//search /media/USERNAME/* folder
pp = "/media/"+pp;
path = "/media/" + path + "/*";
search_path(path, pp);
//search /run/media/USERNAME/* folder
path = "/run" + path;
pp = "/run"+pp;
search_path(path, pp);
}
endpwent();
}else
*/
{
//search /media/USERNAME/* folder
pp = "/media/"+pp;
path = "/media/" + path + "/*";
search_path(path, pp);
//search /run/media/USERNAME/* folder
path = "/run" + path;
pp = "/run"+pp;
search_path(path, pp);
}
#endif
}
void RemovableDriveManager::search_path(const std::string &path,const std::string &parent_path)
{
glob_t globbuf;
globbuf.gl_offs = 2;
int error = glob(path.c_str(), GLOB_TILDE, NULL, &globbuf);
if(error == 0)
{
for(size_t i = 0; i < globbuf.gl_pathc; i++)
{
inspect_file(globbuf.gl_pathv[i], parent_path);
}
}else
{
//if error - path probably doesnt exists so function just exits
//std::cout<<"glob error "<< error<< "\n";
}
globfree(&globbuf);
}
void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path)
{
//confirms if the file is removable drive and adds it to vector
//if not same file system - could be removable drive
if(!compare_filesystem_id(path, parent_path))
{
//free space
boost::filesystem::space_info si = boost::filesystem::space(path);
//std::cout << "Free space: " << fs_si.free << "Available space: " << fs_si.available << " " << path << '\n';
if(si.available != 0)
{
//user id
struct stat buf;
stat(path.c_str(), &buf);
uid_t uid = buf.st_uid;
std::string username(std::getenv("USER"));
struct passwd *pw = getpwuid(uid);
if (pw != 0 && pw->pw_name == username)
m_current_drives.push_back(DriveData(boost::filesystem::basename(boost::filesystem::path(path)), path));
}
}
}
bool RemovableDriveManager::compare_filesystem_id(const std::string &path_a, const std::string &path_b)
{
struct stat buf;
stat(path_a.c_str() ,&buf);
dev_t id_a = buf.st_dev;
stat(path_b.c_str() ,&buf);
dev_t id_b = buf.st_dev;
return id_a == id_b;
}
void RemovableDriveManager::eject_drive(const std::string &path)
{
if (m_current_drives.empty())
return;
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
if((*it).path == path)
{
std::string correct_path(path);
for (size_t i = 0; i < correct_path.size(); ++i)
{
if(correct_path[i]==' ')
{
correct_path = correct_path.insert(i,1,'\\');
i++;
}
}
std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n";
// there is no usable command in c++ so terminal command is used instead
// but neither triggers "succesful safe removal messege"
std::string command = "";
#if __APPLE__
//m_rdmmm->eject_device(path);
command = "diskutil unmount ";
#else
command = "umount ";
#endif
command += correct_path;
int err = system(command.c_str());
if(err)
{
std::cerr<<"Ejecting failed\n";
return;
}
m_did_eject = true;
m_current_drives.erase(it);
break;
}
}
}
bool RemovableDriveManager::is_path_on_removable_drive(const std::string &path)
{
if (m_current_drives.empty())
return false;
std::size_t found = path.find_last_of("/");
std::string new_path = path.substr(0,found);
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
if(compare_filesystem_id(new_path, (*it).path))
return true;
}
return false;
}
std::string RemovableDriveManager::get_drive_from_path(const std::string& path)
{
std::size_t found = path.find_last_of("/");
std::string new_path = path.substr(0, found);
//check if same filesystem
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
if (compare_filesystem_id(new_path, (*it).path))
return (*it).path;
}
return "";
}
#endif
RemovableDriveManager::RemovableDriveManager():
m_drives_count(0),
m_last_update(0),
m_last_save_path(""),
m_last_save_name(""),
m_last_save_path_verified(false),
m_is_writing(false),
m_did_eject(false)
#if __APPLE__
, m_rdmmm(new RDMMMWrapper())
#endif
{}
RemovableDriveManager::~RemovableDriveManager()
{
#if __APPLE__
delete m_rdmmm;
#endif
}
void RemovableDriveManager::init()
{
//add_callback([](void) { RemovableDriveManager::get_instance().print(); });
#if _WIN32
//register_window();
#elif __APPLE__
m_rdmmm->register_window();
#endif
update(0, true);
}
bool RemovableDriveManager::update(const long time,const bool check)
{
if(time != 0) //time = 0 is forced update
{
long diff = m_last_update - time;
if(diff <= -2)
{
m_last_update = time;
}else
{
return false; // return value shouldnt matter if update didnt run
}
}
search_for_drives();
if (m_drives_count != m_current_drives.size())
{
if (check)check_and_notify();
m_drives_count = m_current_drives.size();
}
return !m_current_drives.empty();
}
bool RemovableDriveManager::is_drive_mounted(const std::string &path)
{
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
if ((*it).path == path)
{
return true;
}
}
return false;
}
std::string RemovableDriveManager::get_drive_path()
{
if (m_current_drives.size() == 0)
{
reset_last_save_path();
return "";
}
if (m_last_save_path_verified)
return m_last_save_path;
return m_current_drives.back().path;
}
std::string RemovableDriveManager::get_last_save_path()
{
if (!m_last_save_path_verified)
return "";
return m_last_save_path;
}
std::string RemovableDriveManager::get_last_save_name()
{
return m_last_save_name;
}
std::vector<DriveData> RemovableDriveManager::get_all_drives()
{
return m_current_drives;
}
void RemovableDriveManager::check_and_notify()
{
if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path_verified && !is_drive_mounted(m_last_save_path))
{
for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
{
(*it)();
}
}
}
void RemovableDriveManager::add_callback(std::function<void()> callback)
{
m_callbacks.push_back(callback);
}
void RemovableDriveManager::erase_callbacks()
{
m_callbacks.clear();
}
void RemovableDriveManager::set_last_save_path(const std::string& path)
{
m_last_save_path_verified = false;
m_last_save_path = path;
}
void RemovableDriveManager::verify_last_save_path()
{
std::string last_drive = get_drive_from_path(m_last_save_path);
if (last_drive != "")
{
m_last_save_path_verified = true;
m_last_save_path = last_drive;
m_last_save_name = get_drive_name(last_drive);
}else
{
reset_last_save_path();
}
}
std::string RemovableDriveManager::get_drive_name(const std::string& path)
{
if (m_current_drives.size() == 0)
return "";
for (auto it = m_current_drives.begin(); it != m_current_drives.end(); ++it)
{
if ((*it).path == path)
{
return (*it).name;
}
}
return "";
}
bool RemovableDriveManager::is_last_drive_removed()
{
//std::cout<<"is last: "<<m_last_save_path;
//m_drives_count = m_current_drives.size();
if(!m_last_save_path_verified)
{
//std::cout<<"\n";
return true;
}
bool r = !is_drive_mounted(m_last_save_path);
if (r) reset_last_save_path();
//std::cout<<" "<< r <<"\n";
return r;
}
bool RemovableDriveManager::is_last_drive_removed_with_update(const long time)
{
update(time, false);
return is_last_drive_removed();
}
void RemovableDriveManager::reset_last_save_path()
{
m_last_save_path_verified = false;
m_last_save_path = "";
m_last_save_name = "";
}
void RemovableDriveManager::set_is_writing(const bool b)
{
m_is_writing = b;
if (b)
{
m_did_eject = false;
}
}
bool RemovableDriveManager::get_is_writing()
{
return m_is_writing;
}
bool RemovableDriveManager::get_did_eject()
{
return m_did_eject;
}
void RemovableDriveManager::set_did_eject(const bool b)
{
m_did_eject = b;
}
}}//namespace Slicer::Gui

View file

@ -0,0 +1,110 @@
#ifndef slic3r_GUI_RemovableDriveManager_hpp_
#define slic3r_GUI_RemovableDriveManager_hpp_
#include <vector>
#include <string>
#include <functional>
namespace Slic3r {
namespace GUI {
#if __APPLE__
class RDMMMWrapper;
#endif
struct DriveData
{
std::string name;
std::string path;
DriveData(std::string n, std::string p):name(n),path(p){}
};
class RemovableDriveManager
{
#if __APPLE__
friend class RDMMMWrapper;
#endif
public:
static RemovableDriveManager& get_instance()
{
static RemovableDriveManager instance;
return instance;
}
RemovableDriveManager(RemovableDriveManager const&) = delete;
void operator=(RemovableDriveManager const&) = delete;
~RemovableDriveManager();
//call only once. on apple register for unmnount callbacks. on windows register for device notification is prepared but not called (eject usb drive on widnows doesnt trigger the callback, sdc ard does), also enumerates devices for first time so init shoud be called on linux too.
void init();
//update() searches for removable devices, returns false if empty. /time = 0 is forced update, time expects wxGetLocalTime()
bool update(const long time = 0,const bool check = false);
bool is_drive_mounted(const std::string &path);
void eject_drive(const std::string &path);
//returns path to last drive which was used, if none was used, returns device that was enumerated last
std::string get_last_save_path();
std::string get_last_save_name();
//returns path to last drive which was used, if none was used, returns empty string
std::string get_drive_path();
std::vector<DriveData> get_all_drives();
bool is_path_on_removable_drive(const std::string &path);
// callback will notify only if device with last save path was removed
void add_callback(std::function<void()> callback);
// erases all callbacks added by add_callback()
void erase_callbacks();
// marks one of the eveices in vector as last used
void set_last_save_path(const std::string &path);
void verify_last_save_path();
bool is_last_drive_removed();
// param as update()
bool is_last_drive_removed_with_update(const long time = 0);
void set_is_writing(const bool b);
bool get_is_writing();
bool get_did_eject();
void set_did_eject(const bool b);
std::string get_drive_name(const std::string& path);
private:
RemovableDriveManager();
void search_for_drives();
//triggers callbacks if last used drive was removed
void check_and_notify();
//returns drive path (same as path in DriveData) if exists otherwise empty string ""
std::string get_drive_from_path(const std::string& path);
void reset_last_save_path();
std::vector<DriveData> m_current_drives;
std::vector<std::function<void()>> m_callbacks;
size_t m_drives_count;
long m_last_update;
std::string m_last_save_path;
bool m_last_save_path_verified;
std::string m_last_save_name;
bool m_is_writing;//on device
bool m_did_eject;
#if _WIN32
//registers for notifications by creating invisible window
void register_window();
#else
#if __APPLE__
RDMMMWrapper * m_rdmmm;
#endif
void search_path(const std::string &path, const std::string &parent_path);
bool compare_filesystem_id(const std::string &path_a, const std::string &path_b);
void inspect_file(const std::string &path, const std::string &parent_path);
#endif
};
// apple wrapper for RemovableDriveManagerMM which searches for drives and/or ejects them
#if __APPLE__
class RDMMMWrapper
{
public:
RDMMMWrapper();
~RDMMMWrapper();
void register_window();
void list_devices();
void eject_device(const std::string &path);
void log(const std::string &msg);
protected:
void *m_imp;
//friend void RemovableDriveManager::inspect_file(const std::string &path, const std::string &parent_path);
};
#endif
}}
#endif

View file

@ -0,0 +1,10 @@
#import <Cocoa/Cocoa.h>
@interface RemovableDriveManagerMM : NSObject
-(instancetype) init;
-(void) add_unmount_observer;
-(void) on_device_unmount: (NSNotification*) notification;
-(NSArray*) list_dev;
-(void)eject_drive:(NSString *)path;
@end

View file

@ -0,0 +1,157 @@
#import "RemovableDriveManager.hpp"
#import "RemovableDriveManagerMM.h"
#import <AppKit/AppKit.h>
#import <DiskArbitration/DiskArbitration.h>
@implementation RemovableDriveManagerMM
-(instancetype) init
{
self = [super init];
if(self)
{
}
return self;
}
-(void) on_device_unmount: (NSNotification*) notification
{
NSLog(@"on device change");
Slic3r::GUI::RemovableDriveManager::get_instance().update(0,true);
}
-(void) add_unmount_observer
{
NSLog(@"add unmount observer");
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidMountNotification object:nil];
}
-(NSArray*) list_dev
{
// DEPRICATED:
//NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
//return devices;
NSArray *mountedRemovableMedia = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:nil options:NSVolumeEnumerationSkipHiddenVolumes];
NSMutableArray *result = [NSMutableArray array];
for(NSURL *volURL in mountedRemovableMedia)
{
int err = 0;
DADiskRef disk;
DASessionRef session;
CFDictionaryRef descDict;
session = DASessionCreate(NULL);
if (session == NULL) {
err = EINVAL;
}
if (err == 0) {
disk = DADiskCreateFromVolumePath(NULL,session,(CFURLRef)volURL);
if (session == NULL) {
err = EINVAL;
}
}
if (err == 0) {
descDict = DADiskCopyDescription(disk);
if (descDict == NULL) {
err = EINVAL;
}
}
if (err == 0) {
CFTypeRef mediaEjectableKey = CFDictionaryGetValue(descDict,kDADiskDescriptionMediaEjectableKey);
BOOL ejectable = [mediaEjectableKey boolValue];
CFTypeRef deviceProtocolName = CFDictionaryGetValue(descDict,kDADiskDescriptionDeviceProtocolKey);
CFTypeRef deviceModelKey = CFDictionaryGetValue(descDict, kDADiskDescriptionDeviceModelKey);
if (mediaEjectableKey != NULL)
{
BOOL op = ejectable && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceModelKey, CFSTR("SD Card Reader")));
//!CFEqual(deviceModelKey, CFSTR("Disk Image"));
//
if (op) {
[result addObject:volURL.path];
}
}
}
if (descDict != NULL) {
CFRelease(descDict);
}
}
return result;
}
-(void)eject_drive:(NSString *)path
{
DADiskRef disk;
DASessionRef session;
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
int err = 0;
session = DASessionCreate(NULL);
if (session == NULL) {
err = EINVAL;
}
if (err == 0) {
disk = DADiskCreateFromVolumePath(NULL,session,(CFURLRef)url);
}
if( err == 0)
{
DADiskUnmount(disk, kDADiskUnmountOptionDefault,
NULL, NULL);
}
if (disk != NULL) {
CFRelease(disk);
}
if (session != NULL) {
CFRelease(session);
}
}
namespace Slic3r {
namespace GUI {
RDMMMWrapper::RDMMMWrapper():m_imp(nullptr){
m_imp = [[RemovableDriveManagerMM alloc] init];
}
RDMMMWrapper::~RDMMMWrapper()
{
if(m_imp)
{
[m_imp release];
}
}
void RDMMMWrapper::register_window()
{
if(m_imp)
{
[m_imp add_unmount_observer];
}
}
void RDMMMWrapper::list_devices()
{
if(m_imp)
{
NSArray* devices = [m_imp list_dev];
for (NSString* volumePath in devices)
{
NSLog(@"%@", volumePath);
Slic3r::GUI::RemovableDriveManager::get_instance().inspect_file(std::string([volumePath UTF8String]), "/Volumes");
}
}
}
void RDMMMWrapper::log(const std::string &msg)
{
NSLog(@"%s", msg.c_str());
}
void RDMMMWrapper::eject_device(const std::string &path)
{
if(m_imp)
{
NSString * pth = [NSString stringWithCString:path.c_str()
encoding:[NSString defaultCStringEncoding]];
[m_imp eject_drive:pth];
}
}
}}//namespace Slicer::GUI
/*
*/
@end

View file

@ -13,6 +13,7 @@
#include <wx/numformatter.h>
#include <wx/colordlg.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/nowide/cstdio.hpp>
@ -433,17 +434,17 @@ static std::string icon_name_respected_to_mode(const std::string& bmp_name_in)
#else
const std::string folder = "white/";
#endif
std::string bmp_name = Slic3r::GUI::wxGetApp().dark_mode() ? folder + bmp_name_in : bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
FILE* fp = NULL;
fp = boost::nowide::fopen(Slic3r::var(bmp_name + ".svg").c_str(), "rb");
if (!fp)
{
bmp_name = bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
if (fp) fclose(fp);
}
std::string bmp_name;
if (Slic3r::GUI::wxGetApp().dark_mode()) {
bmp_name = folder + bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
if (! boost::filesystem::exists(Slic3r::var(bmp_name + ".svg")))
bmp_name.clear();
}
if (bmp_name.empty()) {
bmp_name = bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
}
return bmp_name;
}
@ -3960,8 +3961,10 @@ ScalableButton::ScalableButton( wxWindow * parent,
const ScalableBitmap& bitmap,
const wxString& label /*= wxEmptyString*/,
long style /*= wxBU_EXACTFIT | wxNO_BORDER*/) :
m_parent(parent),
m_current_icon_name(bitmap.name()),
m_parent(parent)
m_px_cnt(bitmap.px_cnt()),
m_is_horizontal(bitmap.is_horizontal())
{
Create(parent, id, label, wxDefaultPosition, wxDefaultSize, style);
#ifdef __WXMSW__
@ -3984,11 +3987,17 @@ void ScalableButton::SetBitmapDisabled_(const ScalableBitmap& bmp)
m_disabled_icon_name = bmp.name();
}
int ScalableButton::GetBitmapHeight()
{
const float scale_factor = get_svg_scale_factor(m_parent);
return int((float)GetBitmap().GetHeight() / scale_factor);
}
void ScalableButton::msw_rescale()
{
SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name));
SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name, m_px_cnt, m_is_horizontal));
if (!m_disabled_icon_name.empty())
SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name));
SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name, m_px_cnt, m_is_horizontal));
if (m_width > 0 || m_height>0)
{

View file

@ -730,6 +730,9 @@ public:
wxBitmap& bmp() { return m_bmp; }
const std::string& name() const{ return m_icon_name; }
int px_cnt()const {return m_px_cnt;}
bool is_horizontal()const {return m_is_horizontal;}
private:
wxWindow* m_parent{ nullptr };
wxBitmap m_bmp = wxBitmap();
@ -1096,6 +1099,7 @@ public:
void SetBitmap_(const ScalableBitmap& bmp);
void SetBitmapDisabled_(const ScalableBitmap &bmp);
int GetBitmapHeight();
void msw_rescale();
@ -1105,6 +1109,10 @@ private:
std::string m_disabled_icon_name = "";
int m_width {-1}; // should be multiplied to em_unit
int m_height{-1}; // should be multiplied to em_unit
// bitmap dimensions
int m_px_cnt{ 16 };
bool m_is_horizontal{ false };
};

View file

@ -0,0 +1,170 @@
#include "AstroBox.hpp"
#include <algorithm>
#include <sstream>
#include <exception>
#include <boost/format.hpp>
#include <boost/log/trivial.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <wx/progdlg.h>
#include "libslic3r/PrintConfig.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "Http.hpp"
namespace fs = boost::filesystem;
namespace pt = boost::property_tree;
namespace Slic3r {
AstroBox::AstroBox(DynamicPrintConfig *config) :
host(config->opt_string("print_host")),
apikey(config->opt_string("printhost_apikey")),
cafile(config->opt_string("printhost_cafile"))
{}
const char* AstroBox::get_name() const { return "AstroBox"; }
bool AstroBox::test(wxString &msg) const
{
// Since the request is performed synchronously here,
// it is ok to refer to `msg` from within the closure
const char *name = get_name();
bool res = true;
auto url = make_url("api/version");
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get version at: %2%") % name % url;
auto http = Http::get(std::move(url));
set_auth(http);
http.on_error([&](std::string body, std::string error, unsigned status) {
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
res = false;
msg = format_error(body, error, status);
})
.on_complete([&, this](std::string body, unsigned) {
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got version: %2%") % name % body;
try {
std::stringstream ss(body);
pt::ptree ptree;
pt::read_json(ss, ptree);
if (! ptree.get_optional<std::string>("api")) {
res = false;
return;
}
const auto text = ptree.get_optional<std::string>("text");
res = validate_version_text(text);
if (! res) {
msg = wxString::Format(_(L("Mismatched type of print host: %s")), text ? *text : "AstroBox");
}
}
catch (const std::exception &) {
res = false;
msg = "Could not parse server response";
}
})
.perform_sync();
return res;
}
wxString AstroBox::get_test_ok_msg () const
{
return _(L("Connection to AstroBox works correctly."));
}
wxString AstroBox::get_test_failed_msg (wxString &msg) const
{
return wxString::Format("%s: %s\n\n%s",
_(L("Could not connect to AstroBox")), msg, _(L("Note: AstroBox version at least 1.1.0 is required.")));
}
bool AstroBox::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const
{
const char *name = get_name();
const auto upload_filename = upload_data.upload_path.filename();
const auto upload_parent_path = upload_data.upload_path.parent_path();
wxString test_msg;
if (! test(test_msg)) {
error_fn(std::move(test_msg));
return false;
}
bool res = true;
auto url = make_url("api/files/local");
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3%, filename: %4%, path: %5%, print: %6%")
% name
% upload_data.source_path
% url
% upload_filename.string()
% upload_parent_path.string()
% upload_data.start_print;
auto http = Http::post(std::move(url));
set_auth(http);
http.form_add("print", upload_data.start_print ? "true" : "false")
.form_add("path", upload_parent_path.string()) // XXX: slashes on windows ???
.form_add_file("file", upload_data.source_path.string(), upload_filename.string())
.on_complete([&](std::string body, unsigned status) {
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: File uploaded: HTTP %2%: %3%") % name % status % body;
})
.on_error([&](std::string body, std::string error, unsigned status) {
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error uploading file: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
error_fn(format_error(body, error, status));
res = false;
})
.on_progress([&](Http::Progress progress, bool &cancel) {
prorgess_fn(std::move(progress), cancel);
if (cancel) {
// Upload was canceled
BOOST_LOG_TRIVIAL(info) << "AstroBox: Upload canceled";
res = false;
}
})
.perform_sync();
return res;
}
bool AstroBox::validate_version_text(const boost::optional<std::string> &version_text) const
{
return version_text ? boost::starts_with(*version_text, "AstroBox") : true;
}
void AstroBox::set_auth(Http &http) const
{
http.header("X-Api-Key", apikey);
if (! cafile.empty()) {
http.ca_file(cafile);
}
}
std::string AstroBox::make_url(const std::string &path) const
{
if (host.find("http://") == 0 || host.find("https://") == 0) {
if (host.back() == '/') {
return (boost::format("%1%%2%") % host % path).str();
} else {
return (boost::format("%1%/%2%") % host % path).str();
}
} else {
return (boost::format("http://%1%/%2%") % host % path).str();
}
}
}

View file

@ -0,0 +1,46 @@
#ifndef slic3r_AstroBox_hpp_
#define slic3r_AstroBox_hpp_
#include <string>
#include <wx/string.h>
#include <boost/optional.hpp>
#include "PrintHost.hpp"
namespace Slic3r {
class DynamicPrintConfig;
class Http;
class AstroBox : public PrintHost
{
public:
AstroBox(DynamicPrintConfig *config);
~AstroBox() override = default;
const char* get_name() const override;
bool test(wxString &curl_msg) const override;
wxString get_test_ok_msg () const override;
wxString get_test_failed_msg (wxString &msg) const override;
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const override;
bool has_auto_discovery() const override { return true; }
bool can_test() const override { return true; }
bool can_start_print() const override { return true; }
std::string get_host() const override { return host; }
protected:
bool validate_version_text(const boost::optional<std::string> &version_text) const;
private:
std::string host;
std::string apikey;
std::string cafile;
void set_auth(Http &http) const;
std::string make_url(const std::string &path) const;
};
}
#endif

View file

@ -32,8 +32,6 @@ Duet::Duet(DynamicPrintConfig *config) :
password(config->opt_string("printhost_apikey"))
{}
Duet::~Duet() {}
const char* Duet::get_name() const { return "Duet"; }
bool Duet::test(wxString &msg) const
@ -111,21 +109,6 @@ bool Duet::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn e
return res;
}
bool Duet::has_auto_discovery() const
{
return false;
}
bool Duet::can_test() const
{
return true;
}
bool Duet::can_start_print() const
{
return true;
}
bool Duet::connect(wxString &msg) const
{
bool res = false;

View file

@ -6,10 +6,8 @@
#include "PrintHost.hpp"
namespace Slic3r {
class DynamicPrintConfig;
class Http;
@ -17,18 +15,18 @@ class Duet : public PrintHost
{
public:
Duet(DynamicPrintConfig *config);
virtual ~Duet();
~Duet() override = default;
virtual const char* get_name() const;
const char* get_name() const override;
virtual bool test(wxString &curl_msg) const;
virtual wxString get_test_ok_msg () const;
virtual wxString get_test_failed_msg (wxString &msg) const;
virtual bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const;
virtual bool has_auto_discovery() const;
virtual bool can_test() const;
virtual bool can_start_print() const;
virtual std::string get_host() const { return host; }
bool test(wxString &curl_msg) const override;
wxString get_test_ok_msg() const override;
wxString get_test_failed_msg(wxString &msg) const override;
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const override;
bool has_auto_discovery() const override { return false; }
bool can_test() const override { return true; }
bool can_start_print() const override { return true; }
std::string get_host() const override { return host; }
private:
std::string host;
@ -44,7 +42,6 @@ private:
int get_err_code_from_body(const std::string &body) const;
};
}
#endif

View file

@ -30,8 +30,6 @@ FlashAir::FlashAir(DynamicPrintConfig *config) :
host(config->opt_string("print_host"))
{}
FlashAir::~FlashAir() {}
const char* FlashAir::get_name() const { return "FlashAir"; }
bool FlashAir::test(wxString &msg) const
@ -150,21 +148,6 @@ bool FlashAir::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
return res;
}
bool FlashAir::has_auto_discovery() const
{
return false;
}
bool FlashAir::can_test() const
{
return true;
}
bool FlashAir::can_start_print() const
{
return false;
}
std::string FlashAir::timestamp_str() const
{
auto t = std::time(nullptr);

View file

@ -9,7 +9,6 @@
namespace Slic3r {
class DynamicPrintConfig;
class Http;
@ -17,18 +16,18 @@ class FlashAir : public PrintHost
{
public:
FlashAir(DynamicPrintConfig *config);
virtual ~FlashAir();
~FlashAir() override = default;
virtual const char* get_name() const;
const char* get_name() const override;
virtual bool test(wxString &curl_msg) const;
virtual wxString get_test_ok_msg () const;
virtual wxString get_test_failed_msg (wxString &msg) const;
virtual bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const;
virtual bool has_auto_discovery() const;
virtual bool can_test() const;
virtual bool can_start_print() const;
virtual std::string get_host() const { return host; }
bool test(wxString &curl_msg) const override;
wxString get_test_ok_msg() const override;
wxString get_test_failed_msg(wxString &msg) const override;
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const override;
bool has_auto_discovery() const override { return false; }
bool can_test() const override { return true; }
bool can_start_print() const override { return false; }
std::string get_host() const override { return host; }
private:
std::string host;
@ -38,7 +37,6 @@ private:
std::string make_url(const std::string &path, const std::string &arg, const std::string &val) const;
};
}
#endif

View file

@ -28,8 +28,6 @@ OctoPrint::OctoPrint(DynamicPrintConfig *config) :
cafile(config->opt_string("printhost_cafile"))
{}
OctoPrint::~OctoPrint() {}
const char* OctoPrint::get_name() const { return "OctoPrint"; }
bool OctoPrint::test(wxString &msg) const
@ -142,21 +140,6 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro
return res;
}
bool OctoPrint::has_auto_discovery() const
{
return true;
}
bool OctoPrint::can_test() const
{
return true;
}
bool OctoPrint::can_start_print() const
{
return true;
}
bool OctoPrint::validate_version_text(const boost::optional<std::string> &version_text) const
{
return version_text ? boost::starts_with(*version_text, "OctoPrint") : true;
@ -186,9 +169,6 @@ std::string OctoPrint::make_url(const std::string &path) const
// SL1Host
SL1Host::~SL1Host() {}
const char* SL1Host::get_name() const { return "SL1Host"; }
wxString SL1Host::get_test_ok_msg () const
@ -201,15 +181,9 @@ wxString SL1Host::get_test_failed_msg (wxString &msg) const
return wxString::Format("%s: %s", _(L("Could not connect to Prusa SLA")), msg);
}
bool SL1Host::can_start_print() const
{
return false;
}
bool SL1Host::validate_version_text(const boost::optional<std::string> &version_text) const
{
return version_text ? boost::starts_with(*version_text, "Prusa SLA") : false;
}
}

View file

@ -10,7 +10,6 @@
namespace Slic3r {
class DynamicPrintConfig;
class Http;
@ -18,18 +17,18 @@ class OctoPrint : public PrintHost
{
public:
OctoPrint(DynamicPrintConfig *config);
virtual ~OctoPrint();
~OctoPrint() override = default;
virtual const char* get_name() const;
const char* get_name() const;
virtual bool test(wxString &curl_msg) const;
virtual wxString get_test_ok_msg () const;
virtual wxString get_test_failed_msg (wxString &msg) const;
virtual bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const;
virtual bool has_auto_discovery() const;
virtual bool can_test() const;
virtual bool can_start_print() const;
virtual std::string get_host() const { return host; }
bool test(wxString &curl_msg) const override;
wxString get_test_ok_msg () const override;
wxString get_test_failed_msg (wxString &msg) const override;
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const override;
bool has_auto_discovery() const override { return true; }
bool can_test() const override { return true; }
bool can_start_print() const override { return true; }
std::string get_host() const override { return host; }
protected:
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
@ -43,23 +42,22 @@ private:
std::string make_url(const std::string &path) const;
};
class SL1Host: public OctoPrint
{
public:
SL1Host(DynamicPrintConfig *config) : OctoPrint(config) {}
virtual ~SL1Host();
~SL1Host() override = default;
virtual const char* get_name() const;
const char* get_name() const override;
wxString get_test_ok_msg() const override;
wxString get_test_failed_msg(wxString &msg) const override;
bool can_start_print() const override { return false; }
virtual wxString get_test_ok_msg () const;
virtual wxString get_test_failed_msg (wxString &msg) const;
virtual bool can_start_print() const ;
protected:
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
bool validate_version_text(const boost::optional<std::string> &version_text) const override;
};
}
#endif

View file

@ -15,6 +15,7 @@
#include "OctoPrint.hpp"
#include "Duet.hpp"
#include "FlashAir.hpp"
#include "AstroBox.hpp"
#include "../GUI/PrintHostDialogs.hpp"
namespace fs = boost::filesystem;
@ -45,6 +46,7 @@ PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config)
case htOctoPrint: return new OctoPrint(config);
case htDuet: return new Duet(config);
case htFlashAir: return new FlashAir(config);
case htAstroBox: return new AstroBox(config);
default: return nullptr;
}
} else {