mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Print host: Check OctoPrint vs SLA
This commit is contained in:
parent
2548253d59
commit
0ac4d13015
5 changed files with 65 additions and 30 deletions
|
@ -1551,7 +1551,7 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
|
||||||
|
|
||||||
auto printhost_browse = [this, optgroup] (wxWindow* parent) {
|
auto printhost_browse = [this, optgroup] (wxWindow* parent) {
|
||||||
|
|
||||||
// TODO: SLA
|
// TODO: SLA Bonjour
|
||||||
|
|
||||||
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
|
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
|
||||||
|
@ -1562,6 +1562,7 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
|
||||||
BonjourDialog dialog(parent);
|
BonjourDialog dialog(parent);
|
||||||
if (dialog.show_and_lookup()) {
|
if (dialog.show_and_lookup()) {
|
||||||
optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
|
optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
|
||||||
|
// FIXME: emit killfocus on the edit widget
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,12 @@ public:
|
||||||
Duet(DynamicPrintConfig *config);
|
Duet(DynamicPrintConfig *config);
|
||||||
virtual ~Duet();
|
virtual ~Duet();
|
||||||
|
|
||||||
bool test(wxString &curl_msg) const;
|
virtual bool test(wxString &curl_msg) const;
|
||||||
wxString get_test_ok_msg () const;
|
virtual wxString get_test_ok_msg () const;
|
||||||
wxString get_test_failed_msg (wxString &msg) const;
|
virtual wxString get_test_failed_msg (wxString &msg) const;
|
||||||
bool upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const;
|
virtual bool upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const;
|
||||||
bool has_auto_discovery() const;
|
virtual bool has_auto_discovery() const;
|
||||||
bool can_test() const;
|
virtual bool can_test() const;
|
||||||
virtual std::string get_host() const { return host; }
|
virtual std::string get_host() const { return host; }
|
||||||
private:
|
private:
|
||||||
std::string host;
|
std::string host;
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#include "OctoPrint.hpp"
|
#include "OctoPrint.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <sstream>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/log/trivial.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 <wx/progdlg.h>
|
||||||
|
|
||||||
|
@ -12,6 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
namespace pt = boost::property_tree;
|
||||||
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
@ -41,11 +46,29 @@ bool OctoPrint::test(wxString &msg) const
|
||||||
res = false;
|
res = false;
|
||||||
msg = format_error(body, error, status);
|
msg = format_error(body, error, status);
|
||||||
})
|
})
|
||||||
.on_complete([&](std::string body, unsigned) {
|
.on_complete([&, this](std::string body, unsigned) {
|
||||||
BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: Got version: %1%") % body;
|
BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: Got version: %1%") % body;
|
||||||
|
|
||||||
// TODO: parse body, call validate_version_text
|
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("Mismatched type of print host: %s", text ? *text : "OctoPrint");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
res = false;
|
||||||
|
msg = "Could not parse server response";
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.perform_sync();
|
.perform_sync();
|
||||||
|
|
||||||
|
@ -71,7 +94,7 @@ bool OctoPrint::upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn
|
||||||
wxString test_msg;
|
wxString test_msg;
|
||||||
if (! test(test_msg)) {
|
if (! test(test_msg)) {
|
||||||
|
|
||||||
// TODO:
|
// FIXME:
|
||||||
|
|
||||||
// auto errormsg = wxString::Format("%s: %s", errortitle, test_msg);
|
// auto errormsg = wxString::Format("%s: %s", errortitle, test_msg);
|
||||||
// GUI::show_error(&progress_dialog, std::move(errormsg));
|
// GUI::show_error(&progress_dialog, std::move(errormsg));
|
||||||
|
@ -125,10 +148,9 @@ bool OctoPrint::can_test() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OctoPrint::validate_version_text(const std::string &version_text)
|
bool OctoPrint::validate_version_text(const boost::optional<std::string> &version_text) const
|
||||||
{
|
{
|
||||||
// FIXME
|
return version_text ? boost::starts_with(*version_text, "OctoPrint") : true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OctoPrint::set_auth(Http &http) const
|
void OctoPrint::set_auth(Http &http) const
|
||||||
|
@ -164,14 +186,23 @@ wxString OctoPrint::format_error(const std::string &body, const std::string &err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SL1
|
// SLAHost
|
||||||
|
|
||||||
SL1Host::~SL1Host() {}
|
SLAHost::~SLAHost() {}
|
||||||
|
|
||||||
bool SL1Host::validate_version_text(const std::string &version_text)
|
wxString SLAHost::get_test_ok_msg () const
|
||||||
{
|
{
|
||||||
// FIXME
|
return wxString::Format("%s", _(L("Connection to Prusa SLA works correctly.")));
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
wxString SLAHost::get_test_failed_msg (wxString &msg) const
|
||||||
|
{
|
||||||
|
return wxString::Format("%s: %s", _(L("Could not connect to Prusa SLA")), msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SLAHost::validate_version_text(const boost::optional<std::string> &version_text) const
|
||||||
|
{
|
||||||
|
return version_text ? boost::starts_with(*version_text, "Prusa SLA") : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
#include "PrintHost.hpp"
|
#include "PrintHost.hpp"
|
||||||
|
|
||||||
|
@ -19,16 +20,16 @@ public:
|
||||||
OctoPrint(DynamicPrintConfig *config);
|
OctoPrint(DynamicPrintConfig *config);
|
||||||
virtual ~OctoPrint();
|
virtual ~OctoPrint();
|
||||||
|
|
||||||
bool test(wxString &curl_msg) const;
|
virtual bool test(wxString &curl_msg) const;
|
||||||
wxString get_test_ok_msg () const;
|
virtual wxString get_test_ok_msg () const;
|
||||||
wxString get_test_failed_msg (wxString &msg) const;
|
virtual wxString get_test_failed_msg (wxString &msg) const;
|
||||||
bool upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const;
|
virtual bool upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const;
|
||||||
bool has_auto_discovery() const;
|
virtual bool has_auto_discovery() const;
|
||||||
bool can_test() const;
|
virtual bool can_test() const;
|
||||||
virtual std::string get_host() const { return host; }
|
virtual std::string get_host() const { return host; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool validate_version_text(const std::string &version_text);
|
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string host;
|
std::string host;
|
||||||
|
@ -41,14 +42,16 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SL1Host: public OctoPrint
|
class SLAHost: public OctoPrint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SL1Host(DynamicPrintConfig *config) : OctoPrint(config) {}
|
SLAHost(DynamicPrintConfig *config) : OctoPrint(config) {}
|
||||||
virtual ~SL1Host();
|
virtual ~SLAHost();
|
||||||
|
|
||||||
|
virtual wxString get_test_ok_msg () const;
|
||||||
|
virtual wxString get_test_failed_msg (wxString &msg) const;
|
||||||
protected:
|
protected:
|
||||||
virtual bool validate_version_text(const std::string &version_text);
|
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config)
|
||||||
|
|
||||||
switch (opt->value) {
|
switch (opt->value) {
|
||||||
case htOctoPrint: return new OctoPrint(config);
|
case htOctoPrint: return new OctoPrint(config);
|
||||||
case htSL1: return new SL1Host(config);
|
|
||||||
case htDuet: return new Duet(config);
|
case htDuet: return new Duet(config);
|
||||||
|
case htSL1: return new SLAHost(config);
|
||||||
default: return nullptr;
|
default: return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue