mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 12:41:20 -06:00 
			
		
		
		
	PrintHost: Fix host type configuration, refactor, fix #1687
This commit is contained in:
		
							parent
							
								
									bd725a47f4
								
							
						
					
					
						commit
						857b68a82a
					
				
					 10 changed files with 80 additions and 55 deletions
				
			
		|  | @ -34,6 +34,8 @@ Duet::Duet(DynamicPrintConfig *config) : | |||
| 
 | ||||
| Duet::~Duet() {} | ||||
| 
 | ||||
| const char* Duet::get_name() const { return "Duet"; } | ||||
| 
 | ||||
| bool Duet::test(wxString &msg) const | ||||
| { | ||||
| 	bool connected = connect(msg); | ||||
|  |  | |||
|  | @ -19,6 +19,8 @@ public: | |||
| 	Duet(DynamicPrintConfig *config); | ||||
| 	virtual ~Duet(); | ||||
| 
 | ||||
| 	virtual const char* get_name() const; | ||||
| 
 | ||||
| 	virtual bool test(wxString &curl_msg) const; | ||||
| 	virtual wxString get_test_ok_msg () const; | ||||
| 	virtual wxString get_test_failed_msg (wxString &msg) const; | ||||
|  |  | |||
|  | @ -29,25 +29,29 @@ OctoPrint::OctoPrint(DynamicPrintConfig *config) : | |||
| 
 | ||||
| OctoPrint::~OctoPrint() {} | ||||
| 
 | ||||
| const char* OctoPrint::get_name() const { return "OctoPrint"; } | ||||
| 
 | ||||
| bool OctoPrint::test(wxString &msg) const | ||||
| { | ||||
|     // Since the request is performed synchronously here,
 | ||||
|     // it is ok to refer to `msg` from within the closure
 | ||||
| 
 | ||||
|     const char *name = get_name(); | ||||
| 
 | ||||
|     bool res = true; | ||||
|     auto url = make_url("api/version"); | ||||
| 
 | ||||
|     BOOST_LOG_TRIVIAL(info) << boost::format("Octoprint: Get version at: %1%") % url; | ||||
|     BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get version at: %2%") % name % url; | ||||
| 
 | ||||
|     auto http = Http::get(std::move(url)); | ||||
|     set_auth(http); | ||||
|     http.on_error([&](std::string body, std::string error, unsigned status) { | ||||
|             BOOST_LOG_TRIVIAL(error) << boost::format("Octoprint: Error getting version: %1%, HTTP %2%, body: `%3%`") % error % status % body; | ||||
|             BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body; | ||||
|             res = false; | ||||
|             msg = format_error(body, error, status); | ||||
|         }) | ||||
|         .on_complete([&, this](std::string body, unsigned) { | ||||
|             BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: Got version: %1%") % body; | ||||
|             BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got version: %2%") % name % body; | ||||
| 
 | ||||
|             try { | ||||
|                 std::stringstream ss(body); | ||||
|  | @ -88,6 +92,8 @@ wxString OctoPrint::get_test_failed_msg (wxString &msg) const | |||
| 
 | ||||
| bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn) const | ||||
| { | ||||
|     const char *name = get_name(); | ||||
| 
 | ||||
|     const auto upload_filename = upload_data.upload_path.filename(); | ||||
|     const auto upload_parent_path = upload_data.upload_path.parent_path(); | ||||
| 
 | ||||
|  | @ -101,7 +107,8 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro | |||
| 
 | ||||
|     auto url = make_url("api/files/local"); | ||||
| 
 | ||||
|     BOOST_LOG_TRIVIAL(info) << boost::format("Octoprint: Uploading file %1% at %2%, filename: %3%, path: %4%, print: %5%") | ||||
|     BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3%, filename: %4%, path: %5%, print: %6%") | ||||
|         % name | ||||
|         % upload_data.source_path | ||||
|         % url | ||||
|         % upload_filename.string() | ||||
|  | @ -114,10 +121,10 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro | |||
|         .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) { | ||||
|             BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: File uploaded: HTTP %1%: %2%") % status % body; | ||||
|             BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: File uploaded: HTTP %2%: %3%") % name % status % body; | ||||
|         }) | ||||
|         .on_error([&](std::string body, std::string error, unsigned status) { | ||||
|             BOOST_LOG_TRIVIAL(error) << boost::format("Octoprint: Error uploading file: %1%, HTTP %2%, body: `%3%`") % error % status % body; | ||||
|             BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error uploading file: %2%, HTTP %3%, body: `%4%`") % name % error % status % body; | ||||
|             error_fn(format_error(body, error, status)); | ||||
|             res = false; | ||||
|         }) | ||||
|  | @ -177,26 +184,28 @@ std::string OctoPrint::make_url(const std::string &path) const | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| // SLAHost
 | ||||
| // SL1Host
 | ||||
| 
 | ||||
| SLAHost::~SLAHost() {} | ||||
| SL1Host::~SL1Host() {} | ||||
| 
 | ||||
| wxString SLAHost::get_test_ok_msg () const | ||||
| const char* SL1Host::get_name() const { return "SL1Host"; } | ||||
| 
 | ||||
| wxString SL1Host::get_test_ok_msg () const | ||||
| { | ||||
|     return _(L("Connection to Prusa SLA works correctly.")); | ||||
| } | ||||
| 
 | ||||
| wxString SLAHost::get_test_failed_msg (wxString &msg) const | ||||
| wxString SL1Host::get_test_failed_msg (wxString &msg) const | ||||
| { | ||||
|     return wxString::Format("%s: %s", _(L("Could not connect to Prusa SLA")), msg); | ||||
| } | ||||
| 
 | ||||
| bool SLAHost::can_start_print() const | ||||
| bool SL1Host::can_start_print() const | ||||
| { | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool SLAHost::validate_version_text(const boost::optional<std::string> &version_text) const | ||||
| bool SL1Host::validate_version_text(const boost::optional<std::string> &version_text) const | ||||
| { | ||||
|     return version_text ? boost::starts_with(*version_text, "Prusa SLA") : false; | ||||
| } | ||||
|  |  | |||
|  | @ -20,6 +20,8 @@ public: | |||
|     OctoPrint(DynamicPrintConfig *config); | ||||
|     virtual ~OctoPrint(); | ||||
| 
 | ||||
|     virtual const char* get_name() const; | ||||
| 
 | ||||
|     virtual bool test(wxString &curl_msg) const; | ||||
|     virtual wxString get_test_ok_msg () const; | ||||
|     virtual wxString get_test_failed_msg (wxString &msg) const; | ||||
|  | @ -42,11 +44,13 @@ private: | |||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class SLAHost: public OctoPrint | ||||
| class SL1Host: public OctoPrint | ||||
| { | ||||
| public: | ||||
|     SLAHost(DynamicPrintConfig *config) : OctoPrint(config) {} | ||||
|     virtual ~SLAHost(); | ||||
|     SL1Host(DynamicPrintConfig *config) : OctoPrint(config) {} | ||||
|     virtual ~SL1Host(); | ||||
| 
 | ||||
|     virtual const char* get_name() const; | ||||
| 
 | ||||
|     virtual wxString get_test_ok_msg () const; | ||||
|     virtual wxString get_test_failed_msg (wxString &msg) const; | ||||
|  |  | |||
|  | @ -25,16 +25,28 @@ namespace Slic3r { | |||
| 
 | ||||
| PrintHost::~PrintHost() {} | ||||
| 
 | ||||
| PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config, Slic3r::PrinterTechnology pt_fallback) | ||||
| PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config) | ||||
| { | ||||
|     const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type"); | ||||
|     const auto host_type = opt != nullptr ? opt->value : (pt_fallback == ptFFF ? htOctoPrint : htSL1); | ||||
|     PrinterTechnology tech = ptFFF; | ||||
| 
 | ||||
|     switch (host_type) { | ||||
|         case htOctoPrint: return new OctoPrint(config); | ||||
|         case htDuet:      return new Duet(config); | ||||
|         case htSL1:       return new SLAHost(config); | ||||
|         default:          return nullptr; | ||||
|     { | ||||
|         const auto opt = config->option<ConfigOptionEnum<PrinterTechnology>>("printer_technology"); | ||||
|         if (opt != nullptr) { | ||||
|             tech = opt->value; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if (tech == ptFFF) { | ||||
|         const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type"); | ||||
|         const auto host_type = opt != nullptr ? opt->value : htOctoPrint; | ||||
| 
 | ||||
|         switch (host_type) { | ||||
|             case htOctoPrint: return new OctoPrint(config); | ||||
|             case htDuet:      return new Duet(config); | ||||
|             default:          return nullptr; | ||||
|         } | ||||
|     } else { | ||||
|         return new SL1Host(config); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,7 +8,6 @@ | |||
| 
 | ||||
| #include <wx/string.h> | ||||
| 
 | ||||
| #include "libslic3r/PrintConfig.hpp" | ||||
| #include "Http.hpp" | ||||
| 
 | ||||
| 
 | ||||
|  | @ -33,6 +32,8 @@ public: | |||
|     typedef Http::ProgressFn ProgressFn; | ||||
|     typedef std::function<void(wxString /* error */)> ErrorFn; | ||||
| 
 | ||||
|     virtual const char* get_name() const = 0; | ||||
| 
 | ||||
|     virtual bool test(wxString &curl_msg) const = 0; | ||||
|     virtual wxString get_test_ok_msg () const = 0; | ||||
|     virtual wxString get_test_failed_msg (wxString &msg) const = 0; | ||||
|  | @ -42,7 +43,7 @@ public: | |||
|     virtual bool can_start_print() const = 0; | ||||
|     virtual std::string get_host() const = 0; | ||||
| 
 | ||||
|     static PrintHost* get_print_host(DynamicPrintConfig *config, Slic3r::PrinterTechnology pt_fallback = ptFFF); | ||||
|     static PrintHost* get_print_host(DynamicPrintConfig *config); | ||||
| 
 | ||||
| protected: | ||||
|     virtual wxString format_error(const std::string &body, const std::string &error, unsigned status) const; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vojtech Kral
						Vojtech Kral