mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-26 18:21:18 -06:00
Start Simulation for Duet
Author: Martin Loidl <martin.loidl@gmail.com>
* PrintHost can now return a set of possible actions to be done after a
upload is finished
* Added new Button for starting a simulation after upload
* Duet Hosts are now able to start a simulation after upload instead of
starting a print
* removed now unneeded config key 'printhost_print'
This commit is contained in:
parent
03a6a46dce
commit
8967ee57ed
15 changed files with 97 additions and 71 deletions
|
|
@ -115,11 +115,11 @@ bool AstroBox::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
|
|||
% url
|
||||
% upload_filename.string()
|
||||
% upload_parent_path.string()
|
||||
% upload_data.start_print;
|
||||
% (upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "true" : "false");
|
||||
|
||||
auto http = Http::post(std::move(url));
|
||||
set_auth(http);
|
||||
http.form_add("print", upload_data.start_print ? "true" : "false")
|
||||
http.form_add("print", upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "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) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public:
|
|||
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; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint; }
|
||||
std::string get_host() const override { return host; }
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ bool Duet::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn e
|
|||
bool dsf = (connectionType == ConnectionType::dsf);
|
||||
|
||||
auto upload_cmd = get_upload_url(upload_data.upload_path.string(), connectionType);
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Duet: Uploading file %1%, filepath: %2%, print: %3%, command: %4%")
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Duet: Uploading file %1%, filepath: %2%, post_action: %3%, command: %4%")
|
||||
% upload_data.source_path
|
||||
% upload_data.upload_path
|
||||
% upload_data.start_print
|
||||
% int(upload_data.post_action)
|
||||
% upload_cmd;
|
||||
|
||||
auto http = (dsf ? Http::put(std::move(upload_cmd)) : Http::post(std::move(upload_cmd)));
|
||||
|
|
@ -87,9 +87,15 @@ bool Duet::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn e
|
|||
BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Request completed but error code was received: %1%") % err_code;
|
||||
error_fn(format_error(body, L("Unknown error occured"), 0));
|
||||
res = false;
|
||||
} else if (upload_data.start_print) {
|
||||
} else if (upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
|
||||
wxString errormsg;
|
||||
res = start_print(errormsg, upload_data.upload_path.string(), connectionType);
|
||||
res = start_print(errormsg, upload_data.upload_path.string(), connectionType, false);
|
||||
if (! res) {
|
||||
error_fn(std::move(errormsg));
|
||||
}
|
||||
} else if (upload_data.post_action == PrintHostPostUploadAction::StartSimulation) {
|
||||
wxString errormsg;
|
||||
res = start_print(errormsg, upload_data.upload_path.string(), connectionType, true);
|
||||
if (! res) {
|
||||
error_fn(std::move(errormsg));
|
||||
}
|
||||
|
|
@ -230,7 +236,7 @@ std::string Duet::timestamp_str() const
|
|||
return std::string(buffer);
|
||||
}
|
||||
|
||||
bool Duet::start_print(wxString &msg, const std::string &filename, ConnectionType connectionType) const
|
||||
bool Duet::start_print(wxString &msg, const std::string &filename, ConnectionType connectionType, bool simulationMode) const
|
||||
{
|
||||
assert(connectionType != ConnectionType::error);
|
||||
|
||||
|
|
@ -240,14 +246,18 @@ bool Duet::start_print(wxString &msg, const std::string &filename, ConnectionTyp
|
|||
auto url = dsf
|
||||
? (boost::format("%1%machine/code")
|
||||
% get_base_url()).str()
|
||||
: (boost::format("%1%rr_gcode?gcode=M32%%20\"0:/gcodes/%2%\"")
|
||||
: (boost::format(simulationMode
|
||||
? "%1%rr_gcode?gcode=M37%%20P\"0:/gcodes/%2%\""
|
||||
: "%1%rr_gcode?gcode=M32%%20\"0:/gcodes/%2%\"")
|
||||
% get_base_url()
|
||||
% Http::url_encode(filename)).str();
|
||||
|
||||
auto http = (dsf ? Http::post(std::move(url)) : Http::get(std::move(url)));
|
||||
if (dsf) {
|
||||
http.set_post_body(
|
||||
(boost::format("M32 \"0:/gcodes/%1%\"")
|
||||
(boost::format(simulationMode
|
||||
? "M37 P\"0:/gcodes/%1%\""
|
||||
: "M32 \"0:/gcodes/%1%\"")
|
||||
% filename).str()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
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; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint | PrintHostPostUploadAction::StartSimulation; }
|
||||
std::string get_host() const override { return host; }
|
||||
|
||||
private:
|
||||
|
|
@ -39,7 +39,7 @@ private:
|
|||
std::string timestamp_str() const;
|
||||
ConnectionType connect(wxString &msg) const;
|
||||
void disconnect(ConnectionType connectionType) const;
|
||||
bool start_print(wxString &msg, const std::string &filename, ConnectionType connectionType) const;
|
||||
bool start_print(wxString &msg, const std::string &filename, ConnectionType connectionType, bool simulationMode) const;
|
||||
int get_err_code_from_body(const std::string &body) const;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public:
|
|||
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; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint; }
|
||||
std::string get_host() const override { return host; }
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ bool MKS::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn er
|
|||
BOOST_LOG_TRIVIAL(info) << boost::format("MKS: Uploading file %1%, filepath: %2%, print: %3%, command: %4%")
|
||||
% upload_data.source_path
|
||||
% upload_data.upload_path
|
||||
% upload_data.start_print
|
||||
% (upload_data.post_action == PrintHostPostUploadAction::StartPrint)
|
||||
% upload_cmd;
|
||||
|
||||
auto http = Http::post(std::move(upload_cmd));
|
||||
|
|
@ -85,7 +85,7 @@ bool MKS::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn er
|
|||
error_fn(format_error(body, L("Unknown error occured"), 0));
|
||||
res = false;
|
||||
}
|
||||
else if (upload_data.start_print) {
|
||||
else if (upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
|
||||
wxString errormsg;
|
||||
res = start_print(errormsg, upload_data.upload_path.string());
|
||||
if (!res) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
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; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint; }
|
||||
std::string get_host() const override { return m_host; }
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -137,11 +137,11 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro
|
|||
% url
|
||||
% upload_filename.string()
|
||||
% upload_parent_path.string()
|
||||
% upload_data.start_print;
|
||||
% (upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "true" : "false");
|
||||
|
||||
auto http = Http::post(std::move(url));
|
||||
set_auth(http);
|
||||
http.form_add("print", upload_data.start_print ? "true" : "false")
|
||||
http.form_add("print", upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "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) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public:
|
|||
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; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint; }
|
||||
std::string get_host() const override { return m_host; }
|
||||
const std::string& get_apikey() const { return m_apikey; }
|
||||
const std::string& get_cafile() const { return m_cafile; }
|
||||
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
wxString get_test_ok_msg() const override;
|
||||
wxString get_test_failed_msg(wxString &msg) const override;
|
||||
bool can_start_print() const override { return false; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return {}; }
|
||||
|
||||
protected:
|
||||
bool validate_version_text(const boost::optional<std::string> &version_text) const override;
|
||||
|
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
wxString get_test_ok_msg() const override;
|
||||
wxString get_test_failed_msg(wxString& msg) const override;
|
||||
bool can_start_print() const override { return true; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint; }
|
||||
|
||||
protected:
|
||||
bool validate_version_text(const boost::optional<std::string>& version_text) const override;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@
|
|||
#define slic3r_PrintHost_hpp_
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <wx/string.h>
|
||||
|
||||
#include <libslic3r/enum_bitmask.hpp>
|
||||
#include "Http.hpp"
|
||||
|
||||
class wxArrayString;
|
||||
|
|
@ -16,6 +18,13 @@ namespace Slic3r {
|
|||
|
||||
class DynamicPrintConfig;
|
||||
|
||||
enum class PrintHostPostUploadAction {
|
||||
None,
|
||||
StartPrint,
|
||||
StartSimulation
|
||||
};
|
||||
using PrintHostPostUploadActions = enum_bitmask<PrintHostPostUploadAction>;
|
||||
ENABLE_ENUM_BITMASK_OPERATORS(PrintHostPostUploadAction);
|
||||
|
||||
struct PrintHostUpload
|
||||
{
|
||||
|
|
@ -24,10 +33,9 @@ struct PrintHostUpload
|
|||
|
||||
std::string group;
|
||||
|
||||
bool start_print = false;
|
||||
PrintHostPostUploadAction post_action { PrintHostPostUploadAction::None };
|
||||
};
|
||||
|
||||
|
||||
class PrintHost
|
||||
{
|
||||
public:
|
||||
|
|
@ -44,7 +52,7 @@ public:
|
|||
virtual bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const = 0;
|
||||
virtual bool has_auto_discovery() const = 0;
|
||||
virtual bool can_test() const = 0;
|
||||
virtual bool can_start_print() const = 0;
|
||||
virtual PrintHostPostUploadActions get_post_upload_actions() const = 0;
|
||||
// A print host usually does not support multiple printers, with the exception of Repetier server.
|
||||
virtual bool supports_multiple_printers() const { return false; }
|
||||
virtual std::string get_host() const = 0;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,9 @@ bool Repetier::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
|
|||
|
||||
bool res = true;
|
||||
|
||||
auto url = upload_data.start_print?make_url((boost::format("printer/job/%1%") % port).str()):make_url((boost::format("printer/model/%1%") % port).str());
|
||||
auto url = upload_data.post_action == PrintHostPostUploadAction::StartPrint
|
||||
? make_url((boost::format("printer/job/%1%") % port).str())
|
||||
: make_url((boost::format("printer/model/%1%") % port).str());
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3%, filename: %4%, path: %5%, print: %6%, group: %7%")
|
||||
% name
|
||||
|
|
@ -115,17 +117,17 @@ bool Repetier::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
|
|||
% url
|
||||
% upload_filename.string()
|
||||
% upload_parent_path.string()
|
||||
% upload_data.start_print
|
||||
% (upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "true" : "false")
|
||||
% upload_data.group;
|
||||
|
||||
auto http = Http::post(std::move(url));
|
||||
set_auth(http);
|
||||
|
||||
|
||||
if (! upload_data.group.empty() && upload_data.group != _utf8(L("Default"))) {
|
||||
http.form_add("group", upload_data.group);
|
||||
}
|
||||
|
||||
if(upload_data.start_print) {
|
||||
|
||||
if(upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
|
||||
http.form_add("name", upload_filename.string());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "PrintHost.hpp"
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class DynamicPrintConfig;
|
||||
|
|
@ -27,7 +26,7 @@ public:
|
|||
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; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const { return PrintHostPostUploadAction::StartPrint; }
|
||||
bool supports_multiple_printers() const override { return true; }
|
||||
std::string get_host() const override { return host; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue