From 31967d0d1d971f8082e13f5ef6d52cbba30bb1b3 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Mon, 12 Nov 2018 17:35:57 +0100 Subject: [PATCH] support generation when support point is added or removed. Rendering interface for SLA supports --- src/libslic3r/SLAPrint.cpp | 5 +++++ src/libslic3r/SLAPrint.hpp | 37 ++++++++++++++++++++++++++++++++++++- src/slic3r/GUI/GLGizmo.cpp | 10 ++++++++++ src/slic3r/GUI/Plater.cpp | 22 +++++++++++++++++++++- src/slic3r/GUI/Plater.hpp | 4 ++++ 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 213c3a5c6..a585f544e 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -196,6 +196,11 @@ void SLAPrint::process() } } +void SLAPrint::render_supports(SLASupportRenderer &renderer) +{ + std::cout << "Would show the SLA supports" << std::endl; +} + SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object): Inherited(print), m_model_object(model_object), diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index b5289c0f2..4e6627eec 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -23,6 +23,7 @@ enum SLAPrintObjectStep { }; class SLAPrint; +class GLCanvas; using _SLAPrintObjectBase = PrintObjectBaseWithState; @@ -35,6 +36,7 @@ private: // Prevents erroneous use by other classes. public: const ModelObject* model_object() const { return m_model_object; } ModelObject* model_object() { return m_model_object; } + TriangleMesh support_mesh() const; // I refuse to grantee copying (Tamas) SLAPrintObject(const SLAPrintObject&) = delete; @@ -78,6 +80,37 @@ private: std::unique_ptr m_supportdata; }; +using PrintObjects = std::vector; + +class TriangleMesh; + +class SLASupportRenderer { +public: + + virtual ~SLASupportRenderer() {} + + enum Buttons { + LEFT, RIGHT, MIDDLE + }; + + enum MType { + ENGAGE, RELEASE, HOVER + }; + + struct MouseEvt { + Buttons button; MType type; + }; + + using ClickCb = std::function; + using Mesh = TriangleMesh; + + virtual void add_pillar(const Mesh&, ClickCb on_mouse_evt) = 0; + virtual void add_head(const Mesh&, ClickCb on_mouse_evt) = 0; + virtual void add_bridge(const Mesh&, ClickCb on_mouse_evt) = 0; + virtual void add_junction(const Mesh&, ClickCb on_mouse_evt) = 0; + virtual void add_pad(const Mesh&, ClickCb on_mouse_evt) = 0; +}; + /** * @brief This class is the high level FSM for the SLA printing process. * @@ -108,11 +141,13 @@ public: ApplyStatus apply(const Model &model, const DynamicPrintConfig &config) override; void process() override; + void render_supports(SLASupportRenderer& renderer); + private: Model m_model; SLAPrinterConfig m_printer_config; SLAMaterialConfig m_material_config; - std::vector m_objects; + PrintObjects m_objects; friend SLAPrintObject; }; diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index bf022ba6a..d0161bb87 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -2,6 +2,7 @@ #include "GLGizmo.hpp" #include "GUI.hpp" +#include "GUI_App.hpp" #include "../../libslic3r/Utils.hpp" @@ -1663,6 +1664,9 @@ void GLGizmoSlaSupports::clicked_on_object(const Vec2d& mouse_position) m_grabbers.push_back(Grabber()); m_grabbers.back().center = new_pos.cast(); m_model_object->sla_support_points.push_back(new_pos); + + // This should trigger the support generation + wxGetApp().plater()->reslice(); } catch (...) {} } @@ -1672,12 +1676,18 @@ void GLGizmoSlaSupports::delete_current_grabber(bool delete_all) if (delete_all) { m_grabbers.clear(); m_model_object->sla_support_points.clear(); + + // This should trigger the support generation + wxGetApp().plater()->reslice(); } else if (m_hover_id != -1) { m_grabbers.erase(m_grabbers.begin() + m_hover_id); m_model_object->sla_support_points.erase(m_model_object->sla_support_points.begin() + m_hover_id); m_hover_id = -1; + + // This should trigger the support generation + wxGetApp().plater()->reslice(); } } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 60c4a9a99..22dbd8c70 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -965,7 +965,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : background_process.set_sliced_event(EVT_SLICING_COMPLETED); background_process.set_finished_event(EVT_PROCESS_COMPLETED); // Default printer technology for default config. - background_process.select_technology(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology()); + background_process.select_technology(q->printer_technology()); // Register progress callback from the Print class to the Platter. print.set_status_callback([this](int percent, const std::string &message) { wxCommandEvent event(EVT_PROGRESS_BAR); @@ -1786,6 +1786,21 @@ void Plater::priv::on_process_completed(wxCommandEvent &evt) // refresh preview if (this->preview != nullptr) this->preview->reload_print(); + + // TODO: this needs to be implemented somehow + if(q->printer_technology() == PrinterTechnology::ptSLA) { + + class Renderer: public SLASupportRenderer { + public: + void add_pillar(const Mesh&, ClickCb ) override {} + void add_head(const Mesh&, ClickCb) override {} + void add_bridge(const Mesh&, ClickCb) override {} + void add_junction(const Mesh&, ClickCb) override {} + void add_pad(const Mesh&, ClickCb) override {} + } renderer; + + sla_print.render_supports(renderer); + } } void Plater::priv::on_layer_editing_toggled(bool enable) @@ -2331,6 +2346,11 @@ wxGLCanvas* Plater::canvas3D() return p->canvas3D; } +PrinterTechnology Plater::printer_technology() const +{ + return wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology(); +} + void Plater::changed_object(int obj_idx) { if (obj_idx < 0) diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index f858a7f25..d11aaa74b 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -18,6 +18,8 @@ namespace Slic3r { class Model; class Print; +class SLAPrint; + namespace GUI { class MainFrame; @@ -133,6 +135,8 @@ public: int get_selected_object_idx(); wxGLCanvas* canvas3D(); + + PrinterTechnology printer_technology() const; private: struct priv; std::unique_ptr p;