2019-12-16 10:02:54 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <utility>
|
|
|
|
#include <memory>
|
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
#include "Engine.hpp"
|
2019-12-19 00:55:46 +00:00
|
|
|
|
2019-12-16 10:02:54 +00:00
|
|
|
#include <GL/glew.h>
|
|
|
|
|
|
|
|
#include <opencsg/opencsg.h>
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include <wx/wxprec.h>
|
|
|
|
#ifndef WX_PRECOMP
|
2019-12-17 15:27:28 +00:00
|
|
|
#include <wx/wx.h>
|
2019-12-16 10:02:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <wx/slider.h>
|
|
|
|
#include <wx/tglbtn.h>
|
|
|
|
#include <wx/combobox.h>
|
2019-12-16 13:04:26 +00:00
|
|
|
#include <wx/spinctrl.h>
|
2019-12-17 09:19:46 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2019-12-16 10:02:54 +00:00
|
|
|
#include <wx/glcanvas.h>
|
2019-12-19 13:51:38 +00:00
|
|
|
#include <wx/cmdline.h>
|
2019-12-16 10:02:54 +00:00
|
|
|
|
|
|
|
#include "libslic3r/Model.hpp"
|
|
|
|
#include "libslic3r/Format/3mf.hpp"
|
|
|
|
#include "libslic3r/SLAPrint.hpp"
|
|
|
|
|
|
|
|
#include "slic3r/GUI/Job.hpp"
|
|
|
|
#include "slic3r/GUI/ProgressStatusBar.hpp"
|
|
|
|
|
|
|
|
using namespace Slic3r::GL;
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// The opengl rendering facility. Here we implement the rendering objects.
|
2019-12-19 13:51:38 +00:00
|
|
|
class Canvas: public wxGLCanvas
|
2019-12-17 09:19:46 +00:00
|
|
|
{
|
2019-12-19 15:10:34 +00:00
|
|
|
|
|
|
|
// Tell the CSGDisplay how to swap buffers and set the gl context.
|
2019-12-19 13:51:38 +00:00
|
|
|
class OCSGRenderer: public Slic3r::GL::CSGDisplay {
|
|
|
|
Canvas *m_canvas;
|
|
|
|
shptr<wxGLContext> m_context;
|
|
|
|
public:
|
|
|
|
|
|
|
|
OCSGRenderer(Canvas *c): m_canvas{c} {
|
|
|
|
auto ctx = new wxGLContext(m_canvas);
|
|
|
|
if (!ctx || !ctx->IsOK()) {
|
|
|
|
wxMessageBox("Could not create OpenGL context.", "Error",
|
|
|
|
wxOK | wxICON_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_context.reset(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_active(long w, long h) override
|
|
|
|
{
|
|
|
|
m_canvas->SetCurrent(*m_context);
|
|
|
|
Slic3r::GL::Display::set_active(w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxGLContext * context() { return m_context.get(); }
|
|
|
|
const wxGLContext * context() const { return m_context.get(); }
|
|
|
|
|
|
|
|
void swap_buffers() override { m_canvas->SwapBuffers(); }
|
|
|
|
|
|
|
|
~OCSGRenderer() override { m_scene_cache.clear(); }
|
|
|
|
};
|
2019-12-17 09:19:46 +00:00
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Create the OCSGDisplay for rendering with OpenCSG algorithms
|
2019-12-19 13:51:38 +00:00
|
|
|
shptr<OCSGRenderer> m_ocsgdisplay = std::make_shared<OCSGRenderer>(this);
|
2019-12-17 09:19:46 +00:00
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// One display is active at a time, the OCSGRenderer by default.
|
2019-12-19 13:51:38 +00:00
|
|
|
shptr<Slic3r::GL::Display> m_display = m_ocsgdisplay;
|
|
|
|
|
|
|
|
public:
|
2019-12-17 09:19:46 +00:00
|
|
|
|
|
|
|
template<class...Args>
|
|
|
|
Canvas(Args &&...args): wxGLCanvas(std::forward<Args>(args)...)
|
|
|
|
{
|
2019-12-18 15:24:41 +00:00
|
|
|
Bind(wxEVT_PAINT, [this](wxPaintEvent &) {
|
|
|
|
// This is required even though dc is not used otherwise.
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
|
|
|
// Set the OpenGL viewport according to the client size of this
|
|
|
|
// canvas. This is done here rather than in a wxSizeEvent handler
|
|
|
|
// because our OpenGL rendering context (and thus viewport
|
|
|
|
// setting) is used with multiple canvases: If we updated the
|
|
|
|
// viewport in the wxSizeEvent handler, changing the size of one
|
|
|
|
// canvas causes a viewport setting that is wrong when next
|
|
|
|
// another canvas is repainted.
|
|
|
|
const wxSize ClientSize = GetClientSize();
|
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
m_display->set_screen_size(ClientSize.x, ClientSize.y);
|
2019-12-18 15:24:41 +00:00
|
|
|
});
|
2019-12-17 09:19:46 +00:00
|
|
|
}
|
2019-12-19 13:51:38 +00:00
|
|
|
|
|
|
|
shptr<Slic3r::GL::Display> get_display() const { return m_display; }
|
|
|
|
void set_display(shptr<Slic3r::GL::Display> d) { m_display = d; }
|
|
|
|
|
|
|
|
shptr<Slic3r::GL::CSGDisplay> get_ocsg_display() const { return m_ocsgdisplay; }
|
2019-12-17 09:19:46 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Enumerate possible mouse events, we will record them.
|
2019-12-18 15:24:41 +00:00
|
|
|
enum EEvents { LCLK_U, RCLK_U, LCLK_D, RCLK_D, DDCLK, SCRL, MV };
|
|
|
|
struct Event
|
|
|
|
{
|
|
|
|
EEvents type;
|
|
|
|
long a, b;
|
|
|
|
Event(EEvents t, long x = 0, long y = 0) : type{t}, a{x}, b{y} {}
|
|
|
|
};
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Create a special mouse input adapter, which can store (record) the received
|
|
|
|
// mouse signals into a file and play back the stored events later.
|
2019-12-18 15:24:41 +00:00
|
|
|
class RecorderMouseInput: public MouseInput {
|
|
|
|
std::vector<Event> m_events;
|
|
|
|
bool m_recording = false, m_playing = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void left_click_down() override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(LCLK_D);
|
|
|
|
if (!m_playing) MouseInput::left_click_down();
|
|
|
|
}
|
|
|
|
void left_click_up() override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(LCLK_U);
|
|
|
|
if (!m_playing) MouseInput::left_click_up();
|
|
|
|
}
|
|
|
|
void right_click_down() override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(RCLK_D);
|
|
|
|
if (!m_playing) MouseInput::right_click_down();
|
|
|
|
}
|
|
|
|
void right_click_up() override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(RCLK_U);
|
|
|
|
if (!m_playing) MouseInput::right_click_up();
|
|
|
|
}
|
|
|
|
void double_click() override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(DDCLK);
|
|
|
|
if (!m_playing) MouseInput::double_click();
|
|
|
|
}
|
|
|
|
void scroll(long v, long d, WheelAxis wa) override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(SCRL, v, d);
|
|
|
|
if (!m_playing) MouseInput::scroll(v, d, wa);
|
|
|
|
}
|
|
|
|
void move_to(long x, long y) override
|
|
|
|
{
|
|
|
|
if (m_recording) m_events.emplace_back(MV, x, y);
|
|
|
|
if (!m_playing) MouseInput::move_to(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void save(std::ostream &stream)
|
|
|
|
{
|
|
|
|
for (const Event &evt : m_events)
|
|
|
|
stream << evt.type << " " << evt.a << " " << evt.b << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void load(std::istream &stream)
|
|
|
|
{
|
|
|
|
m_events.clear();
|
|
|
|
while (stream.good()) {
|
|
|
|
int type; long a, b;
|
|
|
|
stream >> type >> a >> b;
|
|
|
|
m_events.emplace_back(EEvents(type), a, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void record(bool r) { m_recording = r; if (r) m_events.clear(); }
|
|
|
|
|
|
|
|
void play()
|
|
|
|
{
|
|
|
|
m_playing = true;
|
|
|
|
for (const Event &evt : m_events) {
|
|
|
|
switch (evt.type) {
|
|
|
|
case LCLK_U: MouseInput::left_click_up(); break;
|
|
|
|
case LCLK_D: MouseInput::left_click_down(); break;
|
|
|
|
case RCLK_U: MouseInput::right_click_up(); break;
|
|
|
|
case RCLK_D: MouseInput::right_click_down(); break;
|
|
|
|
case DDCLK: MouseInput::double_click(); break;
|
|
|
|
case SCRL: MouseInput::scroll(evt.a, evt.b, WheelAxis::waVertical); break;
|
|
|
|
case MV: MouseInput::move_to(evt.a, evt.b); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSafeYield();
|
|
|
|
}
|
|
|
|
m_playing = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// The top level frame of the application.
|
2019-12-16 10:02:54 +00:00
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
2019-12-19 15:10:34 +00:00
|
|
|
// Instantiate the 3D engine.
|
2019-12-16 17:49:44 +00:00
|
|
|
shptr<Scene> m_scene; // Model
|
|
|
|
shptr<Canvas> m_canvas; // View
|
|
|
|
shptr<Controller> m_ctl; // Controller
|
2019-12-19 15:10:34 +00:00
|
|
|
|
|
|
|
// Add a status bar with progress indication.
|
2019-12-16 17:49:44 +00:00
|
|
|
shptr<Slic3r::GUI::ProgressStatusBar> m_stbar;
|
2019-12-18 15:24:41 +00:00
|
|
|
|
|
|
|
RecorderMouseInput m_mouse;
|
2019-12-16 10:02:54 +00:00
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// When loading a Model from 3mf and preparing it, we use a separate thread.
|
2019-12-16 10:02:54 +00:00
|
|
|
class SLAJob: public Slic3r::GUI::Job {
|
|
|
|
MyFrame *m_parent;
|
|
|
|
std::unique_ptr<Slic3r::SLAPrint> m_print;
|
|
|
|
std::string m_fname;
|
2019-12-18 15:24:41 +00:00
|
|
|
|
2019-12-16 10:02:54 +00:00
|
|
|
public:
|
2019-12-16 17:49:44 +00:00
|
|
|
SLAJob(MyFrame *frame, const std::string &fname)
|
2019-12-16 10:02:54 +00:00
|
|
|
: Slic3r::GUI::Job{frame->m_stbar}
|
|
|
|
, m_parent{frame}
|
|
|
|
, m_fname{fname}
|
2019-12-16 17:49:44 +00:00
|
|
|
{}
|
2019-12-19 15:10:34 +00:00
|
|
|
|
|
|
|
// Runs in separate thread
|
2019-12-16 17:49:44 +00:00
|
|
|
void process() override;
|
2019-12-16 10:02:54 +00:00
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
const std::string & get_project_fname() const { return m_fname; }
|
2019-12-16 10:02:54 +00:00
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
protected:
|
2019-12-19 15:10:34 +00:00
|
|
|
|
|
|
|
// Runs in the UI thread.
|
2019-12-16 10:02:54 +00:00
|
|
|
void finalize() override
|
|
|
|
{
|
2019-12-16 17:49:44 +00:00
|
|
|
m_parent->m_scene->set_print(std::move(m_print));
|
2019-12-16 10:02:54 +00:00
|
|
|
m_parent->m_stbar->set_status_text(
|
|
|
|
wxString::Format("Model %s loaded.", m_fname));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
uqptr<SLAJob> m_ui_job;
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// To keep track of the running average of measured fps values.
|
2019-12-19 14:26:04 +00:00
|
|
|
double m_fps_avg = 0.;
|
|
|
|
|
2019-12-16 10:02:54 +00:00
|
|
|
public:
|
2019-12-19 15:10:34 +00:00
|
|
|
MyFrame(const wxString & title,
|
|
|
|
const wxPoint & pos,
|
|
|
|
const wxSize & size,
|
|
|
|
const Slic3r::GL::CSGSettings &settings);
|
2019-12-16 10:02:54 +00:00
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Grab a 3mf and load (hollow it out) within the UI job.
|
2019-12-18 15:24:41 +00:00
|
|
|
void load_model(const std::string &fname) {
|
|
|
|
m_ui_job = std::make_unique<SLAJob>(this, fname);
|
|
|
|
m_ui_job->start();
|
2019-12-16 10:02:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Load a previously stored mouse event log and play it back.
|
2019-12-18 15:24:41 +00:00
|
|
|
void play_back_mouse(const std::string &events_fname)
|
2019-12-16 10:02:54 +00:00
|
|
|
{
|
2019-12-18 15:24:41 +00:00
|
|
|
std::fstream stream(events_fname, std::fstream::in);
|
|
|
|
|
|
|
|
if (stream.good()) {
|
|
|
|
std::string model_name;
|
|
|
|
std::getline(stream, model_name);
|
|
|
|
load_model(model_name);
|
2019-12-19 14:26:04 +00:00
|
|
|
|
|
|
|
int w, h;
|
|
|
|
stream >> w >> h;
|
|
|
|
SetSize(w, h);
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
m_mouse.load(stream);
|
|
|
|
m_mouse.play();
|
2019-12-16 10:02:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
Canvas * canvas() { return m_canvas.get(); }
|
|
|
|
const Canvas * canvas() const { return m_canvas.get(); }
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Bind the canvas mouse events to a class implementing MouseInput interface
|
2019-12-18 15:24:41 +00:00
|
|
|
void bind_canvas_events(MouseInput &msinput);
|
2019-12-19 14:26:04 +00:00
|
|
|
|
|
|
|
double get_fps_average() const { return m_fps_avg; }
|
2019-12-16 10:02:54 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 15:10:34 +00:00
|
|
|
// Possible OpenCSG configuration values. Will be used on the command line and
|
|
|
|
// on the UI widgets.
|
2019-12-19 13:51:38 +00:00
|
|
|
static const std::vector<wxString> CSG_ALGS = {"Auto", "Goldfeather", "SCS"};
|
|
|
|
static const std::vector<wxString> CSG_DEPTH = {"Off", "OcclusionQuery", "On"};
|
|
|
|
static const std::vector<wxString> CSG_OPT = { "Default", "ForceOn", "On", "Off" };
|
|
|
|
|
2019-12-16 10:02:54 +00:00
|
|
|
class App : public wxApp {
|
2019-12-19 13:51:38 +00:00
|
|
|
MyFrame *m_frame = nullptr;
|
2019-12-18 15:24:41 +00:00
|
|
|
|
2019-12-16 10:02:54 +00:00
|
|
|
public:
|
|
|
|
bool OnInit() override {
|
2019-12-18 15:24:41 +00:00
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
wxCmdLineParser parser(argc, argv);
|
2019-12-18 15:24:41 +00:00
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
parser.AddOption("p", "play", "play back file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
|
|
|
parser.AddOption("a", "algorithm", "OpenCSG algorithm [Auto|Goldfeather|SCS]", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
|
|
|
parser.AddOption("d", "depth", "OpenCSG depth strategy [Off|OcclusionQuery|On]", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
|
|
|
parser.AddOption("o", "optimization", "OpenCSG optimization strategy [Default|ForceOn|On|Off]", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
|
|
|
parser.AddOption("c", "convexity", "OpenCSG convexity parameter for generic meshes", wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
|
|
|
|
parser.AddSwitch("", "disable-csg", "Disable csg rendering", wxCMD_LINE_PARAM_OPTIONAL);
|
|
|
|
|
|
|
|
parser.Parse();
|
|
|
|
|
|
|
|
wxString fname;
|
|
|
|
bool is_play = parser.Found("play", &fname);
|
|
|
|
|
|
|
|
wxString alg;
|
|
|
|
parser.Found("algorithm", &alg);
|
|
|
|
|
|
|
|
wxString depth;
|
|
|
|
parser.Found("depth", &depth);
|
|
|
|
|
|
|
|
wxString opt;
|
|
|
|
parser.Found("optimization", &opt);
|
|
|
|
|
|
|
|
long convexity = 1;
|
|
|
|
parser.Found("convexity", &convexity);
|
2019-12-16 10:02:54 +00:00
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
bool csg_off = parser.Found("disable-csg");
|
|
|
|
|
|
|
|
auto get_idx = [](const wxString &a, const std::vector<wxString> &v) {
|
|
|
|
auto it = std::find(v.begin(), v.end(), a.ToStdString());
|
|
|
|
return it - v.begin();
|
|
|
|
};
|
|
|
|
|
|
|
|
Slic3r::GL::CSGSettings settings;
|
|
|
|
|
|
|
|
if (auto a = get_idx(alg, CSG_ALGS) < OpenCSG::AlgorithmUnused)
|
|
|
|
settings.set_algo(OpenCSG::Algorithm(a));
|
|
|
|
|
|
|
|
if (auto a = get_idx(depth, CSG_DEPTH) < OpenCSG::DepthComplexityAlgorithmUnused)
|
|
|
|
settings.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(a));
|
|
|
|
|
|
|
|
if (auto a = get_idx(opt, CSG_OPT) < OpenCSG::OptimizationUnused)
|
|
|
|
settings.set_optimization(OpenCSG::Optimization(a));
|
|
|
|
|
|
|
|
settings.set_convexity(unsigned(convexity));
|
|
|
|
settings.enable_csg(!csg_off);
|
|
|
|
|
|
|
|
m_frame = new MyFrame("PrusaSlicer OpenCSG Demo", wxDefaultPosition, wxSize(1024, 768), settings);
|
|
|
|
|
|
|
|
if (is_play) {
|
2019-12-18 15:24:41 +00:00
|
|
|
m_frame->Show( true );
|
2019-12-19 13:51:38 +00:00
|
|
|
m_frame->play_back_mouse(fname.ToStdString());
|
2019-12-18 15:24:41 +00:00
|
|
|
m_frame->Close( true );
|
2019-12-19 14:26:04 +00:00
|
|
|
std::cout << m_frame->get_fps_average() << std::endl;
|
2019-12-19 13:51:38 +00:00
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
} else m_frame->Show( true );
|
2019-12-16 10:02:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wxIMPLEMENT_APP(App);
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
|
|
|
const Slic3r::GL::CSGSettings &settings):
|
2019-12-16 14:36:43 +00:00
|
|
|
wxFrame(nullptr, wxID_ANY, title, pos, size)
|
|
|
|
{
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
menuFile->Append(wxID_OPEN);
|
|
|
|
menuFile->Append(wxID_EXIT);
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append( menuFile, "&File" );
|
|
|
|
SetMenuBar( menuBar );
|
|
|
|
|
|
|
|
m_stbar = std::make_shared<Slic3r::GUI::ProgressStatusBar>(this);
|
|
|
|
m_stbar->embed(this);
|
|
|
|
|
|
|
|
SetStatusText( "Welcome to wxWidgets!" );
|
|
|
|
|
|
|
|
int attribList[] =
|
|
|
|
{WX_GL_RGBA, WX_GL_DOUBLEBUFFER,
|
|
|
|
// RGB channels each should be allocated with 8 bit depth. One
|
|
|
|
// should almost certainly get these bit depths by default.
|
|
|
|
WX_GL_MIN_RED, 8, WX_GL_MIN_GREEN, 8, WX_GL_MIN_BLUE, 8,
|
|
|
|
// Requesting an 8 bit alpha channel. Interestingly, the NVIDIA
|
|
|
|
// drivers would most likely work with some alpha plane, but
|
|
|
|
// glReadPixels would not return the alpha channel on NVIDIA if
|
|
|
|
// not requested when the GL context is created.
|
|
|
|
WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8, WX_GL_STENCIL_SIZE, 8,
|
2019-12-19 00:55:46 +00:00
|
|
|
/*WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4,*/ 0};
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 17:49:44 +00:00
|
|
|
m_scene = std::make_shared<Scene>();
|
|
|
|
m_ctl = std::make_shared<Controller>();
|
|
|
|
m_ctl->set_scene(m_scene);
|
|
|
|
|
2019-12-16 14:36:43 +00:00
|
|
|
m_canvas = std::make_shared<Canvas>(this, wxID_ANY, attribList,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE);
|
2019-12-19 13:51:38 +00:00
|
|
|
|
|
|
|
m_canvas->get_ocsg_display()->apply_csgsettings(settings);
|
|
|
|
|
|
|
|
m_ctl->add_display(m_canvas->get_display());
|
2019-12-17 15:27:28 +00:00
|
|
|
|
2019-12-16 14:36:43 +00:00
|
|
|
wxPanel *control_panel = new wxPanel(this);
|
2019-12-17 15:27:28 +00:00
|
|
|
|
2019-12-16 14:36:43 +00:00
|
|
|
auto controlsizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
auto slider_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
auto console_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
auto slider = new wxSlider(control_panel, wxID_ANY, 0, 0, 100,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxSL_VERTICAL);
|
|
|
|
slider_sizer->Add(slider, 1, wxEXPAND);
|
|
|
|
|
|
|
|
auto ms_toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling");
|
|
|
|
console_sizer->Add(ms_toggle, 0, wxALL | wxEXPAND, 5);
|
|
|
|
|
|
|
|
auto csg_toggle = new wxToggleButton(control_panel, wxID_ANY, "CSG");
|
|
|
|
csg_toggle->SetValue(true);
|
|
|
|
console_sizer->Add(csg_toggle, 0, wxALL | wxEXPAND, 5);
|
|
|
|
|
|
|
|
auto add_combobox = [control_panel, console_sizer]
|
2019-12-19 13:51:38 +00:00
|
|
|
(const wxString &label, const std::vector<wxString> &list)
|
2019-12-16 14:36:43 +00:00
|
|
|
{
|
|
|
|
auto widget = new wxComboBox(control_panel, wxID_ANY, list[0],
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
int(list.size()), list.data());
|
|
|
|
|
|
|
|
auto sz = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0,
|
|
|
|
wxALL | wxALIGN_CENTER, 5);
|
|
|
|
sz->Add(widget, 1, wxALL | wxEXPAND, 5);
|
|
|
|
console_sizer->Add(sz, 0, wxEXPAND);
|
|
|
|
return widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto add_spinctl = [control_panel, console_sizer]
|
|
|
|
(const wxString &label, int initial, int min, int max)
|
|
|
|
{
|
|
|
|
auto widget = new wxSpinCtrl(
|
|
|
|
control_panel, wxID_ANY,
|
|
|
|
wxString::Format("%d", initial),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max,
|
|
|
|
initial);
|
|
|
|
|
|
|
|
auto sz = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0,
|
|
|
|
wxALL | wxALIGN_CENTER, 5);
|
|
|
|
sz->Add(widget, 1, wxALL | wxEXPAND, 5);
|
|
|
|
console_sizer->Add(sz, 0, wxEXPAND);
|
|
|
|
return widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto convexity_spin = add_spinctl("Convexity", CSGSettings::DEFAULT_CONVEXITY, 0, 100);
|
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
auto alg_select = add_combobox("Algorithm", CSG_ALGS);
|
|
|
|
auto depth_select = add_combobox("Depth Complexity", CSG_DEPTH);
|
|
|
|
auto optimization_select = add_combobox("Optimization", CSG_OPT);
|
2019-12-16 14:36:43 +00:00
|
|
|
depth_select->Disable();
|
|
|
|
|
2019-12-18 11:00:28 +00:00
|
|
|
auto fpstext = new wxStaticText(control_panel, wxID_ANY, "");
|
|
|
|
console_sizer->Add(fpstext, 0, wxALL, 5);
|
2019-12-19 14:26:04 +00:00
|
|
|
m_canvas->get_ocsg_display()->get_fps_counter().add_listener([this, fpstext](double fps) {
|
|
|
|
fpstext->SetLabel(wxString::Format("fps: %.2f", fps) );
|
|
|
|
m_fps_avg = 0.9 * m_fps_avg + 0.1 * fps;
|
2019-12-18 11:00:28 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
auto record_btn = new wxToggleButton(control_panel, wxID_ANY, "Record");
|
|
|
|
console_sizer->Add(record_btn, 0, wxALL | wxEXPAND, 5);
|
|
|
|
|
2019-12-16 14:36:43 +00:00
|
|
|
controlsizer->Add(slider_sizer, 0, wxEXPAND);
|
|
|
|
controlsizer->Add(console_sizer, 1, wxEXPAND);
|
|
|
|
|
|
|
|
control_panel->SetSizer(controlsizer);
|
|
|
|
|
|
|
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizer->Add(m_canvas.get(), 1, wxEXPAND);
|
|
|
|
sizer->Add(control_panel, 0, wxEXPAND);
|
|
|
|
SetSizer(sizer);
|
|
|
|
|
2019-12-19 13:51:38 +00:00
|
|
|
if (settings.get_algo() > 0) depth_select->Enable(true);
|
|
|
|
alg_select->SetSelection(settings.get_algo());
|
|
|
|
depth_select->SetSelection(settings.get_depth_algo());
|
|
|
|
optimization_select->SetSelection(settings.get_optimization());
|
|
|
|
convexity_spin->SetValue(int(settings.get_convexity()));
|
|
|
|
csg_toggle->SetValue(settings.is_enabled());
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent &){
|
|
|
|
RemoveChild(m_canvas.get());
|
|
|
|
m_canvas.reset();
|
|
|
|
Destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
Bind(wxEVT_MENU, [this](wxCommandEvent &) {
|
|
|
|
wxFileDialog dlg(this, "Select project file", wxEmptyString,
|
|
|
|
wxEmptyString, "*.3mf", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
|
|
|
|
|
|
|
|
if (dlg.ShowModal() == wxID_OK) load_model(dlg.GetPath().ToStdString());
|
|
|
|
}, wxID_OPEN);
|
|
|
|
|
2019-12-17 15:27:28 +00:00
|
|
|
Bind(wxEVT_MENU, [this](wxCommandEvent &) { Close(true); }, wxID_EXIT);
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
Bind(wxEVT_SHOW, [this, ms_toggle](wxShowEvent &) {
|
|
|
|
const wxSize ClientSize = GetClientSize();
|
2019-12-19 13:51:38 +00:00
|
|
|
m_canvas->get_display()->set_active(ClientSize.x, ClientSize.y);
|
2019-12-18 15:24:41 +00:00
|
|
|
enable_multisampling(ms_toggle->GetValue());
|
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
|
|
|
Bind(wxEVT_SLIDER, [this, slider](wxCommandEvent &) {
|
2019-12-16 17:49:44 +00:00
|
|
|
m_ctl->move_clip_plane(double(slider->GetValue()));
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 14:55:49 +00:00
|
|
|
ms_toggle->Bind(wxEVT_TOGGLEBUTTON, [this, ms_toggle](wxCommandEvent &){
|
2019-12-16 14:36:43 +00:00
|
|
|
enable_multisampling(ms_toggle->GetValue());
|
2019-12-19 13:51:38 +00:00
|
|
|
m_canvas->get_display()->repaint();
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 14:55:49 +00:00
|
|
|
csg_toggle->Bind(wxEVT_TOGGLEBUTTON, [this, csg_toggle](wxCommandEvent &){
|
2019-12-19 15:10:34 +00:00
|
|
|
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
|
|
|
stt.enable_csg(csg_toggle->GetValue());
|
|
|
|
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 14:55:49 +00:00
|
|
|
alg_select->Bind(wxEVT_COMBOBOX,
|
|
|
|
[this, alg_select, depth_select](wxCommandEvent &)
|
2019-12-16 14:36:43 +00:00
|
|
|
{
|
|
|
|
int sel = alg_select->GetSelection();
|
|
|
|
depth_select->Enable(sel > 0);
|
2019-12-19 15:10:34 +00:00
|
|
|
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
|
|
|
stt.set_algo(OpenCSG::Algorithm(sel));
|
|
|
|
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 14:55:49 +00:00
|
|
|
depth_select->Bind(wxEVT_COMBOBOX, [this, depth_select](wxCommandEvent &) {
|
2019-12-16 14:36:43 +00:00
|
|
|
int sel = depth_select->GetSelection();
|
2019-12-19 15:10:34 +00:00
|
|
|
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
|
|
|
stt.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(sel));
|
|
|
|
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 14:55:49 +00:00
|
|
|
optimization_select->Bind(wxEVT_COMBOBOX,
|
|
|
|
[this, optimization_select](wxCommandEvent &) {
|
2019-12-16 14:36:43 +00:00
|
|
|
int sel = optimization_select->GetSelection();
|
2019-12-19 15:10:34 +00:00
|
|
|
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
|
|
|
stt.set_optimization(OpenCSG::Optimization(sel));
|
|
|
|
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-16 14:55:49 +00:00
|
|
|
convexity_spin->Bind(wxEVT_SPINCTRL, [this, convexity_spin](wxSpinEvent &) {
|
2019-12-19 15:10:34 +00:00
|
|
|
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
2019-12-16 14:36:43 +00:00
|
|
|
int c = convexity_spin->GetValue();
|
|
|
|
|
|
|
|
if (c > 0) {
|
2019-12-19 15:10:34 +00:00
|
|
|
stt.set_convexity(unsigned(c));
|
|
|
|
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
2019-12-16 14:36:43 +00:00
|
|
|
}
|
2019-12-16 14:55:49 +00:00
|
|
|
});
|
2019-12-16 14:36:43 +00:00
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
record_btn->Bind(wxEVT_TOGGLEBUTTON, [this, record_btn](wxCommandEvent &) {
|
|
|
|
if (!m_ui_job) {
|
|
|
|
m_stbar->set_status_text("No project loaded!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (record_btn->GetValue()) {
|
2019-12-19 13:51:38 +00:00
|
|
|
if (auto c = m_canvas->get_display()->camera()) reset(*c);
|
2019-12-18 15:24:41 +00:00
|
|
|
m_ctl->on_scene_updated(*m_scene);
|
|
|
|
m_mouse.record(true);
|
|
|
|
} else {
|
|
|
|
m_mouse.record(false);
|
|
|
|
wxFileDialog dlg(this, "Select output file",
|
|
|
|
wxEmptyString, wxEmptyString, "*.events",
|
|
|
|
wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
|
|
|
|
|
|
|
if (dlg.ShowModal() == wxID_OK) {
|
|
|
|
std::fstream stream(dlg.GetPath().ToStdString(),
|
|
|
|
std::fstream::out);
|
|
|
|
|
|
|
|
if (stream.good()) {
|
|
|
|
stream << m_ui_job->get_project_fname() << "\n";
|
2019-12-19 14:26:04 +00:00
|
|
|
wxSize winsize = GetSize();
|
|
|
|
stream << winsize.x << " " << winsize.y << "\n";
|
2019-12-18 15:24:41 +00:00
|
|
|
m_mouse.save(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Do the repaint continuously
|
|
|
|
m_canvas->Bind(wxEVT_IDLE, [this](wxIdleEvent &evt) {
|
2019-12-19 13:51:38 +00:00
|
|
|
if (m_canvas->IsShown()) m_canvas->get_display()->repaint();
|
2019-12-18 15:24:41 +00:00
|
|
|
evt.RequestMore();
|
|
|
|
});
|
|
|
|
|
|
|
|
bind_canvas_events(m_mouse);
|
2019-12-16 17:49:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
void MyFrame::bind_canvas_events(MouseInput &ms)
|
2019-12-16 17:49:44 +00:00
|
|
|
{
|
2019-12-18 15:24:41 +00:00
|
|
|
m_canvas->Bind(wxEVT_MOUSEWHEEL, [&ms](wxMouseEvent &evt) {
|
|
|
|
ms.scroll(evt.GetWheelRotation(), evt.GetWheelDelta(),
|
|
|
|
evt.GetWheelAxis() == wxMOUSE_WHEEL_VERTICAL ?
|
|
|
|
Slic3r::GL::MouseInput::waVertical :
|
|
|
|
Slic3r::GL::MouseInput::waHorizontal);
|
2019-12-16 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
m_canvas->Bind(wxEVT_MOTION, [&ms](wxMouseEvent &evt) {
|
|
|
|
ms.move_to(evt.GetPosition().x, evt.GetPosition().y);
|
2019-12-16 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
m_canvas->Bind(wxEVT_RIGHT_DOWN, [&ms](wxMouseEvent & /*evt*/) {
|
|
|
|
ms.right_click_down();
|
2019-12-16 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
m_canvas->Bind(wxEVT_RIGHT_UP, [&ms](wxMouseEvent & /*evt*/) {
|
|
|
|
ms.right_click_up();
|
2019-12-16 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
m_canvas->Bind(wxEVT_LEFT_DOWN, [&ms](wxMouseEvent & /*evt*/) {
|
|
|
|
ms.left_click_down();
|
2019-12-16 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
m_canvas->Bind(wxEVT_LEFT_UP, [&ms](wxMouseEvent & /*evt*/) {
|
|
|
|
ms.left_click_up();
|
2019-12-16 17:49:44 +00:00
|
|
|
});
|
2019-12-18 15:24:41 +00:00
|
|
|
|
|
|
|
ms.add_listener(m_ctl);
|
2019-12-16 17:49:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::SLAJob::process()
|
|
|
|
{
|
2019-12-19 00:55:46 +00:00
|
|
|
using SlStatus = Slic3r::PrintBase::SlicingStatus;
|
2019-12-16 17:49:44 +00:00
|
|
|
|
|
|
|
Slic3r::DynamicPrintConfig cfg;
|
|
|
|
auto model = Slic3r::Model::read_from_file(m_fname, &cfg);
|
|
|
|
|
|
|
|
m_print = std::make_unique<Slic3r::SLAPrint>();
|
|
|
|
m_print->apply(model, cfg);
|
|
|
|
|
|
|
|
Slic3r::PrintBase::TaskParams params;
|
|
|
|
params.to_object_step = Slic3r::slaposHollowing;
|
|
|
|
m_print->set_task(params);
|
|
|
|
|
2019-12-19 00:55:46 +00:00
|
|
|
m_print->set_status_callback([this](const SlStatus &status) {
|
2019-12-16 17:49:44 +00:00
|
|
|
update_status(status.percent, status.text);
|
|
|
|
});
|
|
|
|
|
2019-12-18 15:24:41 +00:00
|
|
|
try {
|
|
|
|
m_print->process();
|
|
|
|
} catch(std::exception &e) {
|
|
|
|
update_status(0, wxString("Exception during processing: ") + e.what());
|
|
|
|
}
|
2019-12-16 14:36:43 +00:00
|
|
|
}
|
2019-12-17 15:27:28 +00:00
|
|
|
|
|
|
|
//int main() {}
|