Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_opengl_3_rebase

This commit is contained in:
enricoturri1966 2022-05-30 15:41:08 +02:00
commit a1eb8c5cbd
14 changed files with 230 additions and 28 deletions

2
.gitignore vendored
View File

@ -18,4 +18,4 @@ local-lib
build-linux/* build-linux/*
deps/build-linux/* deps/build-linux/*
**/.DS_Store **/.DS_Store
/.idea/ **/.idea/

View File

@ -1,7 +1,7 @@
#include <cassert> #include <cassert>
#include "PresetBundle.hpp"
#include "libslic3r.h" #include "libslic3r.h"
#include "PresetBundle.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Model.hpp" #include "Model.hpp"
#include "format.hpp" #include "format.hpp"
@ -453,6 +453,11 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, Preset::
presets.get_edited_preset().config.apply_only(presets.get_selected_preset().config, unselected_options); presets.get_edited_preset().config.apply_only(presets.get_selected_preset().config, unselected_options);
} }
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
if (type == Preset::TYPE_PRINTER)
copy_bed_model_and_texture_if_needed(presets.get_edited_preset().config);
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
presets.save_current_preset(new_name); presets.save_current_preset(new_name);
// Mark the print & filament enabled if they are compatible with the currently selected preset. // Mark the print & filament enabled if they are compatible with the currently selected preset.
@ -1860,4 +1865,32 @@ void PresetBundle::set_default_suppressed(bool default_suppressed)
printers.set_default_suppressed(default_suppressed); printers.set_default_suppressed(default_suppressed);
} }
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
void copy_bed_model_and_texture_if_needed(DynamicPrintConfig& config)
{
const boost::filesystem::path user_dir = boost::filesystem::absolute(boost::filesystem::path(data_dir()) / "printer").make_preferred();
const boost::filesystem::path res_dir = boost::filesystem::absolute(boost::filesystem::path(resources_dir()) / "profiles").make_preferred();
auto do_copy = [&user_dir, &res_dir](ConfigOptionString* cfg, const std::string& type) {
if (cfg == nullptr || cfg->value.empty())
return;
const boost::filesystem::path src_dir = boost::filesystem::absolute(boost::filesystem::path(cfg->value)).make_preferred().parent_path();
if (src_dir != user_dir && src_dir.parent_path() != res_dir) {
const std::string dst_value = (user_dir / boost::filesystem::path(cfg->value).filename()).string();
std::string error;
if (copy_file_inner(cfg->value, dst_value, error) == SUCCESS)
cfg->value = dst_value;
else {
BOOST_LOG_TRIVIAL(error) << "Copying from " << cfg->value << " to " << dst_value << " failed. Unable to set custom bed " << type << ". [" << error << "]";
cfg->value = "";
}
}
};
do_copy(config.option<ConfigOptionString>("bed_custom_texture"), "texture");
do_copy(config.option<ConfigOptionString>("bed_custom_model"), "model");
}
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
} // namespace Slic3r } // namespace Slic3r

View File

@ -178,6 +178,12 @@ private:
ENABLE_ENUM_BITMASK_OPERATORS(PresetBundle::LoadConfigBundleAttribute) ENABLE_ENUM_BITMASK_OPERATORS(PresetBundle::LoadConfigBundleAttribute)
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
// Copies bed texture and model files to 'data_dir()\printer' folder, if needed
// and updates the config accordingly
extern void copy_bed_model_and_texture_if_needed(DynamicPrintConfig& config);
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
} // namespace Slic3r } // namespace Slic3r
#endif /* slic3r_PresetBundle_hpp_ */ #endif /* slic3r_PresetBundle_hpp_ */

View File

@ -288,7 +288,7 @@ template<unsigned MAX_ITER>
struct RotfinderBoilerplate { struct RotfinderBoilerplate {
static constexpr unsigned MAX_TRIES = MAX_ITER; static constexpr unsigned MAX_TRIES = MAX_ITER;
int status = 0; int status = 0, prev_status = 0;
TriangleMesh mesh; TriangleMesh mesh;
unsigned max_tries; unsigned max_tries;
const RotOptimizeParams &params; const RotOptimizeParams &params;
@ -314,13 +314,20 @@ struct RotfinderBoilerplate {
RotfinderBoilerplate(const ModelObject &mo, const RotOptimizeParams &p) RotfinderBoilerplate(const ModelObject &mo, const RotOptimizeParams &p)
: mesh{get_mesh_to_rotate(mo)} : mesh{get_mesh_to_rotate(mo)}
, params{p}
, max_tries(p.accuracy() * MAX_TRIES) , max_tries(p.accuracy() * MAX_TRIES)
{ , params{p}
{}
void statusfn() {
int s = status * 100 / max_tries;
if (s != prev_status) {
params.statuscb()(s);
prev_status = s;
}
++status;
} }
void statusfn() { params.statuscb()(++status * 100.0 / max_tries); }
bool stopcond() { return ! params.statuscb()(-1); } bool stopcond() { return ! params.statuscb()(-1); }
}; };

View File

@ -79,6 +79,7 @@
#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1)
// Enable gizmo grabbers to share common models // Enable gizmo grabbers to share common models
#define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1)
// Enable copy of custom bed model and texture
#define ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE (1 && ENABLE_2_5_0_ALPHA1)
#endif // _prusaslicer_technologies_h_ #endif // _prusaslicer_technologies_h_

View File

@ -172,6 +172,7 @@ set(SLIC3R_GUI_SOURCES
GUI/Jobs/Worker.hpp GUI/Jobs/Worker.hpp
GUI/Jobs/BoostThreadWorker.hpp GUI/Jobs/BoostThreadWorker.hpp
GUI/Jobs/BoostThreadWorker.cpp GUI/Jobs/BoostThreadWorker.cpp
GUI/Jobs/UIThreadWorker.hpp
GUI/Jobs/BusyCursorJob.hpp GUI/Jobs/BusyCursorJob.hpp
GUI/Jobs/PlaterWorker.hpp GUI/Jobs/PlaterWorker.hpp
GUI/Jobs/ArrangeJob.hpp GUI/Jobs/ArrangeJob.hpp

View File

@ -2780,6 +2780,10 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
page_diams->apply_custom_config(*custom_config); page_diams->apply_custom_config(*custom_config);
page_temps->apply_custom_config(*custom_config); page_temps->apply_custom_config(*custom_config);
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
copy_bed_model_and_texture_if_needed(*custom_config);
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
const std::string profile_name = page_custom->profile_name(); const std::string profile_name = page_custom->profile_name();
preset_bundle->load_config_from_wizard(profile_name, *custom_config); preset_bundle->load_config_from_wizard(profile_name, *custom_config);
} }

View File

@ -1010,11 +1010,13 @@ void GCodeViewer::render()
render_toolpaths(); render_toolpaths();
render_shells(); render_shells();
float legend_height = 0.0f; float legend_height = 0.0f;
render_legend(legend_height); if (!m_layers.empty()) {
if (m_sequential_view.current.last != m_sequential_view.endpoints.last) { render_legend(legend_height);
m_sequential_view.marker.set_world_position(m_sequential_view.current_position); if (m_sequential_view.current.last != m_sequential_view.endpoints.last) {
m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); m_sequential_view.marker.set_world_position(m_sequential_view.current_position);
m_sequential_view.render(legend_height); m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset);
m_sequential_view.render(legend_height);
}
} }
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
render_statistics(); render_statistics();

View File

@ -954,7 +954,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
} }
GCodeViewer::EViewType gcode_view_type = m_canvas->get_gcode_view_preview_type(); GCodeViewer::EViewType gcode_view_type = m_canvas->get_gcode_view_preview_type();
bool gcode_preview_data_valid = !m_gcode_result->moves.empty(); bool gcode_preview_data_valid = !m_gcode_result->moves.empty() && !m_canvas->get_gcode_layers_zs().empty();
// Collect colors per extruder. // Collect colors per extruder.
std::vector<std::string> colors; std::vector<std::string> colors;

View File

@ -766,7 +766,9 @@ GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_fil
GLGizmoRotate(parent, GLGizmoRotate::X), GLGizmoRotate(parent, GLGizmoRotate::X),
GLGizmoRotate(parent, GLGizmoRotate::Y), GLGizmoRotate(parent, GLGizmoRotate::Y),
GLGizmoRotate(parent, GLGizmoRotate::Z) }) GLGizmoRotate(parent, GLGizmoRotate::Z) })
{} {
load_rotoptimize_state();
}
bool GLGizmoRotate3D::on_mouse(const wxMouseEvent &mouse_event) bool GLGizmoRotate3D::on_mouse(const wxMouseEvent &mouse_event)
{ {

View File

@ -40,6 +40,12 @@ class PlaterWorker: public Worker {
{ {
wxWakeUpIdle(); wxWakeUpIdle();
ctl.update_status(st, msg); ctl.update_status(st, msg);
// If the worker is not using additional threads, the UI
// is refreshed with this call. If the worker is running
// in it's own thread, the yield should not have any
// visible effects.
wxYieldIfNeeded();
} }
bool was_canceled() const override { return ctl.was_canceled(); } bool was_canceled() const override { return ctl.was_canceled(); }

View File

@ -0,0 +1,125 @@
#ifndef UITHREADWORKER_HPP
#define UITHREADWORKER_HPP
#include <deque>
#include <queue>
#include "Worker.hpp"
#include "ProgressIndicator.hpp"
namespace Slic3r { namespace GUI {
// Implementation of a worker which does not create any additional threads.
class UIThreadWorker : public Worker, private Job::Ctl {
std::queue<std::unique_ptr<Job>, std::deque<std::unique_ptr<Job>>> m_jobqueue;
std::shared_ptr<ProgressIndicator> m_progress;
bool m_running = false;
bool m_canceled = false;
void process_front()
{
std::unique_ptr<Job> job;
if (!m_jobqueue.empty()) {
job = std::move(m_jobqueue.front());
m_jobqueue.pop();
}
if (job) {
std::exception_ptr eptr;
m_running = true;
try {
job->process(*this);
} catch (...) {
eptr= std::current_exception();
}
job->finalize(m_canceled, eptr);
// Unhandled exceptions are rethrown without mercy.
if (eptr)
std::rethrow_exception(eptr);
m_running = false;
m_canceled = false;
}
}
protected:
// Implement Job::Ctl interface:
void update_status(int st, const std::string &msg = "") override
{
if (m_progress) {
m_progress->set_progress(st);
m_progress->set_status_text(msg.c_str());
}
}
bool was_canceled() const override { return m_canceled; }
std::future<void> call_on_main_thread(std::function<void()> fn) override
{
return std::async(std::launch::deferred, [fn]{ fn(); });
}
public:
explicit UIThreadWorker(std::shared_ptr<ProgressIndicator> pri,
const std::string & /*name*/ = "")
: m_progress{pri}
{
if (m_progress)
m_progress->set_cancel_callback([this]() { cancel(); });
}
UIThreadWorker() = default;
bool push(std::unique_ptr<Job> job) override
{
m_canceled = false;
if (job)
m_jobqueue.push(std::move(job));
return bool(job);
}
bool is_idle() const override { return !m_running && m_jobqueue.empty(); }
void cancel() override { m_canceled = true; }
void cancel_all() override
{
m_canceled = true;
process_front();
while (!m_jobqueue.empty())
m_jobqueue.pop();
}
void process_events() override {
while (!m_jobqueue.empty())
process_front();
}
bool wait_for_current_job(unsigned /*timeout_ms*/ = 0) override {
process_front();
return true;
}
bool wait_for_idle(unsigned /*timeout_ms*/ = 0) override {
process_events();
return true;
}
ProgressIndicator * get_pri() { return m_progress.get(); }
const ProgressIndicator * get_pri() const { return m_progress.get(); }
};
}} // namespace Slic3r::GUI
#endif // UITHREADWORKER_HPP

View File

@ -1648,6 +1648,9 @@ struct Plater::priv
// objects would be frozen for the user. In case of arrange, an animation // objects would be frozen for the user. In case of arrange, an animation
// could be shown, or with the optimize orientations, partial results // could be shown, or with the optimize orientations, partial results
// could be displayed. // could be displayed.
//
// UIThreadWorker can be used as a replacement for BoostThreadWorker if
// no additional worker threads are desired (useful for debugging or profiling)
PlaterWorker<BoostThreadWorker> m_worker; PlaterWorker<BoostThreadWorker> m_worker;
SLAImportDialog * m_sla_import_dlg; SLAImportDialog * m_sla_import_dlg;

View File

@ -4,10 +4,9 @@
#include <thread> #include <thread>
#include "slic3r/GUI/Jobs/BoostThreadWorker.hpp" #include "slic3r/GUI/Jobs/BoostThreadWorker.hpp"
#include "slic3r/GUI/Jobs/UIThreadWorker.hpp"
#include "slic3r/GUI/Jobs/ProgressIndicator.hpp" #include "slic3r/GUI/Jobs/ProgressIndicator.hpp"
//#include <boost/thread/thread.hpp>
struct Progress: Slic3r::ProgressIndicator { struct Progress: Slic3r::ProgressIndicator {
int range = 100; int range = 100;
int pr = 0; int pr = 0;
@ -19,17 +18,30 @@ struct Progress: Slic3r::ProgressIndicator {
int get_range() const override { return range; } int get_range() const override { return range; }
}; };
TEST_CASE("nullptr job should be ignored", "[Jobs]") { using TestClasses = std::tuple< Slic3r::GUI::UIThreadWorker, Slic3r::GUI::BoostThreadWorker >;
Slic3r::GUI::BoostThreadWorker worker{std::make_unique<Progress>()};
TEMPLATE_LIST_TEST_CASE("Empty worker should not do anything", "[Jobs]", TestClasses) {
TestType worker{std::make_unique<Progress>()};
REQUIRE(worker.is_idle());
worker.wait_for_current_job();
worker.process_events();
REQUIRE(worker.is_idle());
}
TEMPLATE_LIST_TEST_CASE("nullptr job should be ignored", "[Jobs]", TestClasses) {
TestType worker{std::make_unique<Progress>()};
worker.push(nullptr); worker.push(nullptr);
REQUIRE(worker.is_idle()); REQUIRE(worker.is_idle());
} }
TEST_CASE("State should not be idle while running a job", "[Jobs]") { TEMPLATE_LIST_TEST_CASE("State should not be idle while running a job", "[Jobs]", TestClasses) {
using namespace Slic3r; using namespace Slic3r;
using namespace Slic3r::GUI; using namespace Slic3r::GUI;
BoostThreadWorker worker{std::make_unique<Progress>(), "worker_thread"}; TestType worker{std::make_unique<Progress>(), "worker_thread"};
queue_job(worker, [&worker](Job::Ctl &ctl) { queue_job(worker, [&worker](Job::Ctl &ctl) {
ctl.call_on_main_thread([&worker] { ctl.call_on_main_thread([&worker] {
@ -42,11 +54,11 @@ TEST_CASE("State should not be idle while running a job", "[Jobs]") {
REQUIRE(worker.is_idle()); REQUIRE(worker.is_idle());
} }
TEST_CASE("Status messages should be received by the main thread during job execution", "[Jobs]") { TEMPLATE_LIST_TEST_CASE("Status messages should be received by the main thread during job execution", "[Jobs]", TestClasses) {
using namespace Slic3r; using namespace Slic3r;
using namespace Slic3r::GUI; using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>(); auto pri = std::make_shared<Progress>();
BoostThreadWorker worker{pri}; TestType worker{pri};
queue_job(worker, [](Job::Ctl &ctl){ queue_job(worker, [](Job::Ctl &ctl){
for (int s = 0; s <= 100; ++s) { for (int s = 0; s <= 100; ++s) {
@ -60,12 +72,12 @@ TEST_CASE("Status messages should be received by the main thread during job exec
REQUIRE(pri->statustxt == "Running"); REQUIRE(pri->statustxt == "Running");
} }
TEST_CASE("Cancellation should be recognized be the worker", "[Jobs]") { TEMPLATE_LIST_TEST_CASE("Cancellation should be recognized be the worker", "[Jobs]", TestClasses) {
using namespace Slic3r; using namespace Slic3r;
using namespace Slic3r::GUI; using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>(); auto pri = std::make_shared<Progress>();
BoostThreadWorker worker{pri}; TestType worker{pri};
queue_job( queue_job(
worker, worker,
@ -88,12 +100,12 @@ TEST_CASE("Cancellation should be recognized be the worker", "[Jobs]") {
REQUIRE(pri->pr != 100); REQUIRE(pri->pr != 100);
} }
TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]") { TEMPLATE_LIST_TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]", TestClasses) {
using namespace Slic3r; using namespace Slic3r;
using namespace Slic3r::GUI; using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>(); auto pri = std::make_shared<Progress>();
BoostThreadWorker worker{pri}; TestType worker{pri};
std::array<bool, 4> jobres = {false, false, false, false}; std::array<bool, 4> jobres = {false, false, false, false};
@ -125,12 +137,12 @@ TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]") {
REQUIRE(jobres[3] == false); REQUIRE(jobres[3] == false);
} }
TEST_CASE("Exception should be properly forwarded to finalize()", "[Jobs]") { TEMPLATE_LIST_TEST_CASE("Exception should be properly forwarded to finalize()", "[Jobs]", TestClasses) {
using namespace Slic3r; using namespace Slic3r;
using namespace Slic3r::GUI; using namespace Slic3r::GUI;
auto pri = std::make_shared<Progress>(); auto pri = std::make_shared<Progress>();
BoostThreadWorker worker{pri}; TestType worker{pri};
queue_job( queue_job(
worker, [](Job::Ctl &) { throw std::runtime_error("test"); }, worker, [](Job::Ctl &) { throw std::runtime_error("test"); },