Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::Repetier Class Reference

#include <src/slic3r/Utils/Repetier.hpp>

+ Inheritance diagram for Slic3r::Repetier:
+ Collaboration diagram for Slic3r::Repetier:

Public Types

typedef Http::ProgressFn ProgressFn
 
typedef std::function< void(wxString)> ErrorFn
 
typedef std::function< void(wxString, wxString)> InfoFn
 

Public Member Functions

 Repetier (DynamicPrintConfig *config)
 
 ~Repetier () override=default
 
const char * get_name () const override
 
bool test (wxString &curl_msg) const override
 
wxString get_test_ok_msg () const override
 
wxString get_test_failed_msg (wxString &msg) const override
 
bool upload (PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override
 
bool has_auto_discovery () const override
 
bool can_test () const override
 
PrintHostPostUploadActions get_post_upload_actions () const override
 
bool supports_multiple_printers () const override
 
std::string get_host () const override
 
bool get_groups (wxArrayString &groups) const override
 
bool get_printers (wxArrayString &printers) const override
 
virtual bool get_storage (wxArrayString &, wxArrayString &) const
 

Static Public Member Functions

static PrintHostget_print_host (DynamicPrintConfig *config)
 

Protected Member Functions

virtual wxString format_error (const std::string &body, const std::string &error, unsigned status) const
 

Private Member Functions

void set_auth (Http &http) const
 
std::string make_url (const std::string &path) const
 

Private Attributes

std::string host
 
std::string apikey
 
std::string cafile
 
std::string port
 

Detailed Description

Member Typedef Documentation

◆ ErrorFn

typedef std::function<void(wxString )> Slic3r::PrintHost::ErrorFn
inherited

◆ InfoFn

typedef std::function<void(wxString , wxString )> Slic3r::PrintHost::InfoFn
inherited

◆ ProgressFn

Constructor & Destructor Documentation

◆ Repetier()

Slic3r::Repetier::Repetier ( DynamicPrintConfig config)
29 :
30 host(config->opt_string("print_host")),
31 apikey(config->opt_string("printhost_apikey")),
32 cafile(config->opt_string("printhost_cafile")),
33 port(config->opt_string("printhost_port"))
34{}
std::string cafile
Definition Repetier.hpp:39
std::string host
Definition Repetier.hpp:37
std::string apikey
Definition Repetier.hpp:38
std::string port
Definition Repetier.hpp:40

◆ ~Repetier()

Slic3r::Repetier::~Repetier ( )
overridedefault

Member Function Documentation

◆ can_test()

bool Slic3r::Repetier::can_test ( ) const
inlineoverridevirtual

Implements Slic3r::PrintHost.

28{ return true; }

◆ format_error()

wxString Slic3r::PrintHost::format_error ( const std::string &  body,
const std::string &  error,
unsigned  status 
) const
protectedvirtualinherited
67{
68 if (status != 0) {
69 auto wxbody = wxString::FromUTF8(body.data());
70 return wxString::Format("HTTP %u: %s", status, wxbody);
71 } else {
72 return wxString::FromUTF8(error.data());
73 }
74}
static char error[256]
Definition tga.cpp:50

References error.

Referenced by Slic3r::Duet::connect(), Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::put_inner(), Slic3r::Duet::start_print(), Slic3r::AstroBox::test(), Slic3r::FlashAir::test(), Slic3r::Moonraker::test(), Slic3r::OctoPrint::test(), Slic3r::PrusaLink::test(), test(), Slic3r::PrusaLink::test_with_method_check(), Slic3r::AstroBox::upload(), Slic3r::Duet::upload(), Slic3r::FlashAir::upload(), Slic3r::MKS::upload(), Slic3r::Moonraker::upload(), upload(), and Slic3r::OctoPrint::upload_inner_with_host().

+ Here is the caller graph for this function:

◆ get_groups()

bool Slic3r::Repetier::get_groups ( wxArrayString &  groups) const
overridevirtual

Reimplemented from Slic3r::PrintHost.

202{
203 bool res = true;
204
205 const char *name = get_name();
206 auto url = make_url((boost::format("printer/api/%1%") % port).str());
207
208 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get groups at: %2%") % name % url;
209
210 auto http = Http::get(std::move(url));
211 set_auth(http);
212 http.form_add("a", "listModelGroups");
213 http.on_error([&](std::string body, std::string error, unsigned status) {
214 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
215 })
216 .on_complete([&](std::string body, unsigned) {
217 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got groups: %2%") % name % body;
218
219 try {
220 std::stringstream ss(body);
221 pt::ptree ptree;
222 pt::read_json(ss, ptree);
223
224 BOOST_FOREACH(boost::property_tree::ptree::value_type &v, ptree.get_child("groupNames.")) {
225 if (v.second.data() == "#") {
226 groups.push_back(_L("Default"));
227 } else {
228 // Is it safe to assume that the data are utf-8 encoded?
229 groups.push_back(GUI::from_u8(v.second.data()));
230 }
231 }
232 }
233 catch (const std::exception &) {
234 //msg = "Could not parse server response";
235 res = false;
236 }
237 })
238 .perform_sync();
239
240 return res;
241}
static Http get(std::string url)
Definition Http.cpp:607
const char * get_name() const override
Definition Repetier.cpp:36
std::string make_url(const std::string &path) const
Definition Repetier.cpp:188
void set_auth(Http &http) const
Definition Repetier.cpp:179
wxString from_u8(const std::string &str)
Definition GUI.cpp:437
#define _L(s)
Definition I18N.hpp:3

References _L, error, Slic3r::GUI::from_u8(), Slic3r::Http::get(), get_name(), make_url(), port, and set_auth().

+ Here is the call graph for this function:

◆ get_host()

std::string Slic3r::Repetier::get_host ( ) const
inlineoverridevirtual

Implements Slic3r::PrintHost.

31{ return host; }

References host.

◆ get_name()

const char * Slic3r::Repetier::get_name ( ) const
overridevirtual

Implements Slic3r::PrintHost.

36{ return "Repetier"; }

Referenced by get_groups(), get_printers(), test(), and upload().

+ Here is the caller graph for this function:

◆ get_post_upload_actions()

PrintHostPostUploadActions Slic3r::Repetier::get_post_upload_actions ( ) const
inlineoverridevirtual

◆ get_print_host()

PrintHost * Slic3r::PrintHost::get_print_host ( DynamicPrintConfig config)
staticinherited
35{
37
38 {
39 const auto opt = config->option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
40 if (opt != nullptr) {
41 tech = opt->value;
42 }
43 }
44
45 if (tech == ptFFF) {
46 const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
47 const auto host_type = opt != nullptr ? opt->value : htOctoPrint;
48
49 switch (host_type) {
50 case htOctoPrint: return new OctoPrint(config);
51 case htDuet: return new Duet(config);
52 case htFlashAir: return new FlashAir(config);
53 case htAstroBox: return new AstroBox(config);
54 case htRepetier: return new Repetier(config);
55 case htPrusaLink: return new PrusaLink(config);
56 case htPrusaConnect: return new PrusaConnect(config);
57 case htMKS: return new MKS(config);
58 case htMoonraker: return new Moonraker(config);
59 default: return nullptr;
60 }
61 } else {
62 return new SL1Host(config);
63 }
64}
PrinterTechnology
Definition Config.hpp:205
@ ptFFF
Definition Config.hpp:207
@ htMoonraker
Definition PrintConfig.hpp:47
@ htPrusaLink
Definition PrintConfig.hpp:47
@ htRepetier
Definition PrintConfig.hpp:47
@ htMKS
Definition PrintConfig.hpp:47
@ htPrusaConnect
Definition PrintConfig.hpp:47
@ htDuet
Definition PrintConfig.hpp:47
@ htOctoPrint
Definition PrintConfig.hpp:47
@ htFlashAir
Definition PrintConfig.hpp:47
@ htAstroBox
Definition PrintConfig.hpp:47
ConfigOptionEnum< PrinterTechnology >
Definition PrintConfig.hpp:1079

References Slic3r::htAstroBox, Slic3r::htDuet, Slic3r::htFlashAir, Slic3r::htMKS, Slic3r::htMoonraker, Slic3r::htOctoPrint, Slic3r::htPrusaConnect, Slic3r::htPrusaLink, Slic3r::htRepetier, Slic3r::ConfigBase::option(), Slic3r::ptFFF, and Slic3r::ConfigOptionSingle< T >::value.

Referenced by Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), Slic3r::GUI::PhysicalPrinterDialog::update_printers(), and Slic3r::GUI::PhysicalPrinterDialog::update_printhost_buttons().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_printers()

bool Slic3r::Repetier::get_printers ( wxArrayString &  printers) const
overridevirtual

Reimplemented from Slic3r::PrintHost.

244{
245 const char *name = get_name();
246
247 bool res = true;
248 auto url = make_url("printer/list");
249
250 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: List printers at: %2%") % name % url;
251
252 auto http = Http::get(std::move(url));
253 set_auth(http);
254
255 http.on_error([&](std::string body, std::string error, unsigned status) {
256 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error listing printers: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
257 res = false;
258 })
259 .on_complete([&](std::string body, unsigned http_status) {
260 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got printers: %2%, HTTP status: %3%") % name % body % http_status;
261
262 if (http_status != 200)
263 throw HostNetworkError(GUI::format(_L("HTTP status: %1%\nMessage body: \"%2%\""), http_status, body));
264
265 std::stringstream ss(body);
266 pt::ptree ptree;
267 try {
268 pt::read_json(ss, ptree);
269 } catch (const pt::ptree_error &err) {
270 throw HostNetworkError(GUI::format(_L("Parsing of host response failed.\nMessage body: \"%1%\"\nError: \"%2%\""), body, err.what()));
271 }
272
273 const auto error = ptree.get_optional<std::string>("error");
274 if (error)
275 throw HostNetworkError(*error);
276
277 try {
278 BOOST_FOREACH(boost::property_tree::ptree::value_type &v, ptree.get_child("data.")) {
279 const auto port = v.second.get<std::string>("slug");
280 printers.push_back(Slic3r::GUI::from_u8(port));
281 }
282 } catch (const std::exception &err) {
283 throw HostNetworkError(GUI::format(_L("Enumeration of host printers failed.\nMessage body: \"%1%\"\nError: \"%2%\""), body, err.what()));
284 }
285 })
286 .perform_sync();
287
288 return res;
289}
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:56

References _L, error, Slic3r::GUI::format(), Slic3r::GUI::from_u8(), Slic3r::Http::get(), get_name(), make_url(), port, and set_auth().

+ Here is the call graph for this function:

◆ get_storage()

virtual bool Slic3r::PrintHost::get_storage ( wxArrayString &  ,
wxArrayString &   
) const
inlinevirtualinherited

Reimplemented in Slic3r::PrusaLink, and Slic3r::PrusaConnect.

69{ return false; }

◆ get_test_failed_msg()

wxString Slic3r::Repetier::get_test_failed_msg ( wxString &  msg) const
overridevirtual

Implements Slic3r::PrintHost.

107{
108 return GUI::format_wxstr("%s: %s\n\n%s"
109 , _L("Could not connect to Repetier")
110 , msg
111 , _L("Note: Repetier version at least 0.90.0 is required."));
112}
wxString format_wxstr(const char *fmt, TArgs &&... args)
Definition format.hpp:42

References _L, and Slic3r::GUI::format_wxstr().

+ Here is the call graph for this function:

◆ get_test_ok_msg()

wxString Slic3r::Repetier::get_test_ok_msg ( ) const
overridevirtual

Implements Slic3r::PrintHost.

102{
103 return _(L("Connection to Repetier works correctly."));
104}
#define _(msgid)
Definition getopt.c:87
#define L(s)
Definition I18N.hpp:18

References _, and L.

◆ has_auto_discovery()

bool Slic3r::Repetier::has_auto_discovery ( ) const
inlineoverridevirtual

Implements Slic3r::PrintHost.

27{ return false; }

◆ make_url()

std::string Slic3r::Repetier::make_url ( const std::string &  path) const
private
189{
190 if (host.find("http://") == 0 || host.find("https://") == 0) {
191 if (host.back() == '/') {
192 return (boost::format("%1%%2%") % host % path).str();
193 } else {
194 return (boost::format("%1%/%2%") % host % path).str();
195 }
196 } else {
197 return (boost::format("http://%1%/%2%") % host % path).str();
198 }
199}

References host.

Referenced by get_groups(), get_printers(), test(), and upload().

+ Here is the caller graph for this function:

◆ set_auth()

void Slic3r::Repetier::set_auth ( Http http) const
private
180{
181 http.header("X-Api-Key", apikey);
182
183 if (! cafile.empty()) {
184 http.ca_file(cafile);
185 }
186}

References apikey, Slic3r::Http::ca_file(), cafile, and Slic3r::Http::header().

Referenced by get_groups(), get_printers(), test(), and upload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ supports_multiple_printers()

bool Slic3r::Repetier::supports_multiple_printers ( ) const
inlineoverridevirtual

Reimplemented from Slic3r::PrintHost.

30{ return true; }

◆ test()

bool Slic3r::Repetier::test ( wxString &  curl_msg) const
overridevirtual

Implements Slic3r::PrintHost.

57{
58 // Since the request is performed synchronously here,
59 // it is ok to refer to `msg` from within the closure
60
61 const char *name = get_name();
62
63 bool res = true;
64 auto url = make_url("printer/info");
65
66 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: List version at: %2%") % name % url;
67
68 auto http = Http::get(std::move(url));
69 set_auth(http);
70
71 http.on_error([&](std::string body, std::string error, unsigned status) {
72 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
73 res = false;
74 msg = format_error(body, error, status);
75 })
76 .on_complete([&](std::string body, unsigned) {
77 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got version: %2%") % name % body;
78
79 try {
80 std::stringstream ss(body);
81 pt::ptree ptree;
82 pt::read_json(ss, ptree);
83
84 const auto text = ptree.get_optional<std::string>("name");
85 const auto soft = ptree.get_optional<std::string>("software");
86 res = validate_repetier(text, soft);
87 if (! res) {
88 msg = GUI::format_wxstr(_L("Mismatched type of print host: %s"), (soft ? *soft : (text ? *text : "Repetier")));
89 }
90 }
91 catch (const std::exception &) {
92 res = false;
93 msg = "Could not parse server response";
94 }
95 })
96 .perform_sync();
97
98 return res;
99}
virtual wxString format_error(const std::string &body, const std::string &error, unsigned status) const
Definition PrintHost.cpp:66
static bool validate_repetier(const boost::optional< std::string > &name, const boost::optional< std::string > &soft)
Definition Repetier.cpp:40

References _L, error, Slic3r::PrintHost::format_error(), Slic3r::GUI::format_wxstr(), Slic3r::Http::get(), get_name(), make_url(), set_auth(), and Slic3r::validate_repetier().

Referenced by upload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ upload()

bool Slic3r::Repetier::upload ( PrintHostUpload  upload_data,
ProgressFn  prorgess_fn,
ErrorFn  error_fn,
InfoFn  info_fn 
) const
overridevirtual

Implements Slic3r::PrintHost.

115{
116 const char *name = get_name();
117
118 const auto upload_filename = upload_data.upload_path.filename();
119 const auto upload_parent_path = upload_data.upload_path.parent_path();
120
121 wxString test_msg;
122 if (! test(test_msg)) {
123 error_fn(std::move(test_msg));
124 return false;
125 }
126
127 bool res = true;
128
129 auto url = upload_data.post_action == PrintHostPostUploadAction::StartPrint
130 ? make_url((boost::format("printer/job/%1%") % port).str())
131 : make_url((boost::format("printer/model/%1%") % port).str());
132
133 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3%, filename: %4%, path: %5%, print: %6%, group: %7%")
134 % name
135 % upload_data.source_path
136 % url
137 % upload_filename.string()
138 % upload_parent_path.string()
139 % (upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "true" : "false")
140 % upload_data.group;
141
142 auto http = Http::post(std::move(url));
143 set_auth(http);
144
145 if (! upload_data.group.empty() && upload_data.group != _u8L("Default")) {
146 http.form_add("group", upload_data.group);
147 }
148
149 if(upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
150 http.form_add("name", upload_filename.string());
151 http.form_add("autostart", "true"); // See https://github.com/prusa3d/PrusaSlicer/issues/7807#issuecomment-1235519371
152 }
153
154 http.form_add("a", "upload")
155 .form_add_file("filename", upload_data.source_path.string(), upload_filename.string())
156 .on_complete([&](std::string body, unsigned status) {
157 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: File uploaded: HTTP %2%: %3%") % name % status % body;
158 })
159 .on_error([&](std::string body, std::string error, unsigned status) {
160 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error uploading file: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
161 error_fn(format_error(body, error, status));
162 res = false;
163 })
164 .on_progress([&](Http::Progress progress, bool &cancel) {
165 prorgess_fn(std::move(progress), cancel);
166 if (cancel) {
167 // Upload was canceled
168 BOOST_LOG_TRIVIAL(info) << "Repetier: Upload canceled";
169 res = false;
170 }
171 })
172 .perform_sync();
173
174 return res;
175}
#define _u8L(s)
macro used to mark string used at localization, return same string
Definition SLAPrint.cpp:29
static Http post(std::string url)
Definition Http.cpp:612
bool test(wxString &curl_msg) const override
Definition Repetier.cpp:56
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44
Definition args.hpp:18

References _u8L, error, Slic3r::PrintHost::format_error(), get_name(), Slic3r::PrintHostUpload::group, make_url(), port, Slic3r::Http::post(), Slic3r::PrintHostUpload::post_action, set_auth(), Slic3r::PrintHostUpload::source_path, Slic3r::StartPrint, test(), and Slic3r::PrintHostUpload::upload_path.

+ Here is the call graph for this function:

Member Data Documentation

◆ apikey

std::string Slic3r::Repetier::apikey
private

Referenced by set_auth().

◆ cafile

std::string Slic3r::Repetier::cafile
private

Referenced by set_auth().

◆ host

std::string Slic3r::Repetier::host
private

Referenced by get_host(), and make_url().

◆ port

std::string Slic3r::Repetier::port
private

Referenced by get_groups(), get_printers(), and upload().


The documentation for this class was generated from the following files: