120{
121 PrintParams params;
122 std::string msg;
123 int curr_percent = 10;
124 NetworkAgent* agent = wxGetApp().getAgent();
125 AppConfig* config = wxGetApp().app_config;
126 int result = -1;
127 std::string http_body;
128
130 msg =
_u8L(
"Sending print job over LAN");
131 }
132 else {
133 msg =
_u8L(
"Sending print job through cloud service");
134 }
135
136 ctl.call_on_main_thread([
this] {
prepare(); }).wait();
137 ctl.update_status(0, msg);
138
139
140
141
143 PrintParams verify_params;
145 verify_params.username = agent->default_lan_username();
150 verify_params.project_name = "verify_job";
151 verify_params.filename =
job_data._temp_path.string();
153
154 int verify_result = agent->start_send_gcode_to_sdcard(verify_params, nullptr, nullptr, nullptr);
155 if (verify_result != 0) {
156 BOOST_LOG_TRIVIAL(error) << "send_job: access code / ip verification failed, result = " << verify_result;
159 return;
163 return;
164 }
165 }
166
167 LifecycleEventContext start_ctx;
170 start_ctx.source = "send_job";
173
174 int total_plate_num =
m_plater->get_partplate_list().get_plate_count();
175
176 PartPlate* plate =
m_plater->get_partplate_list().get_plate(
job_data.plate_idx);
177 if (plate == nullptr) {
179
180 for (int index = 0; index < total_plate_num; index++)
181 {
182 PartPlate* plate_n =
m_plater->get_partplate_list().get_plate(index);
183 if (plate_n && plate_n->is_valid_gcode_file())
184 {
185 plate = plate_n;
186 break;
187 }
188 }
189 }
190 else {
191 plate =
m_plater->get_partplate_list().get_curr_plate();
192 }
193 if (plate == nullptr) {
194 BOOST_LOG_TRIVIAL(error) <<
"can not find plate with valid gcode file when sending to print, plate_index="<<
job_data.plate_idx;
196 return;
197 }
198 }
199
200
201 if (!plate->is_valid_gcode_file()) {
203 return;
204 }
205
206 if (ctl.was_canceled()) {
208 return;
209 }
210
211 std::string project_name = wxGetApp().plater()->get_project_name().ToUTF8().data();
212 int curr_plate_idx = 0;
214 curr_plate_idx =
job_data.plate_idx + 1;
216 curr_plate_idx =
m_plater->get_partplate_list().get_curr_plate_index() + 1;
217
220 params.preset_name = wxGetApp().preset_bundle->prints.get_selected_preset_name();
221
222 if (wxGetApp().
plater()->using_exported_file())
223 params.filename = wxGetApp().plater()->get_3mf_filename();
224 else
225 params.filename =
job_data._3mf_path.string();
226
227
228 params.config_filename =
job_data._3mf_config_path.string();
229
230 params.plate_index = curr_plate_idx;
234
235
237 params.username = agent->default_lan_username();
241 std::string msg_text;
242
244 20,
245 30,
246 99,
247 99,
248 99,
249 100,
250 100
251 };
252
253 auto update_fn = [this, &ctl,
254 &msg, &curr_percent, StagePercentPoint](int stage, int code, std::string info) {
257 msg =
_u8L(
"Sending G-code file over LAN");
258 } else {
259 msg =
_u8L(
"Sending G-code file to SD card");
260 }
261 }
263 if (code >= 0 && code <= 100 && !info.empty()) {
265 msg =
_u8L(
"Sending G-code file over LAN");
266 }
267 else {
268 msg =
_u8L(
"Sending G-code file to SD card");
269 }
270 if (!info.empty()) {
271 msg +=
format(
"(%s)", info);
272 }
273 }
274 }
276 msg =
format(
_u8L(
"Successfully sent. Close current page in %s s"), info);
277 }
278 else {
280 msg =
_u8L(
"Sending G-code file over LAN");
281 }
282 else {
283 msg =
_u8L(
"Sending G-code file over LAN");
284 }
285 }
286
287
289 curr_percent = StagePercentPoint[stage];
291 (code > 0 && code <= 100)) {
292 curr_percent = (StagePercentPoint[stage + 1] - StagePercentPoint[stage]) * code / 100 + StagePercentPoint[stage];
293 }
294 }
295
296
300 }
303 }
306 }
307 else {
309 }
310 }
311 else {
312 ctl.update_status(curr_percent, msg);
313 }
314 };
315
316 auto cancel_fn = [&ctl]() {
317 return ctl.was_canceled();
318 };
319
320
321 if (params.connection_type != "lan") {
322 if (params.dev_ip.empty())
323 params.comments = "no_ip";
325 params.comments = "low_version";
327 params.comments = "no_sdcard";
328 else if (params.password.empty())
329 params.comments = "no_password";
330
331 if (!params.password.empty()
332 && !params.dev_ip.empty()
333 && this->has_sdcard) {
334
335 BOOST_LOG_TRIVIAL(info) << "send_job: try to send gcode to printer";
336 ctl.update_status(curr_percent,
_u8L(
"Sending G-code file over LAN"));
337 result = agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn, nullptr);
339 params.comments = "upload_failed";
340 } else {
341 params.comments = (boost::format("failed(%1%)") % result).str();
342 }
343 if (result < 0) {
344
345 BOOST_LOG_TRIVIAL(info) << "send_job: try to send gcode file to printer";
346 ctl.update_status(curr_percent,
_u8L(
"Sending G-code file over LAN"));
347 }
348 } else {
349 BOOST_LOG_TRIVIAL(info) << "send_job: try to send gcode file to printer";
350 ctl.update_status(curr_percent,
_u8L(
"Sending G-code file over LAN"));
351 }
352 } else {
355 ctl.update_status(curr_percent,
_u8L(
"Storage needs to be inserted before sending to printer."));
356 return;
359
360 ctl.update_status(curr_percent,
_u8L(
"Sending G-code file over LAN, but the Storage in the printer is abnormal and print-issues may be caused by this."));
361 result = agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn, nullptr);
362 break;
363 }
364 ctl.update_status(curr_percent,
_u8L(
"The Storage in the printer is abnormal. Please replace it with a normal Storage before sending to printer."));
365 return;
367 ctl.update_status(curr_percent,
_u8L(
"The Storage in the printer is read-only. Please replace it with a normal Storage before sending to printer."));
368 return;
370 ctl.update_status(curr_percent,
_u8L(
"Sending G-code file over LAN"));
371 result = agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn, nullptr);
372 break;
373 default:
374 ctl.update_status(curr_percent,
_u8L(
"Encountered an unknown error with the Storage status. Please try again."));
375 return;
376 }
377 }
378
379 if (ctl.was_canceled()) {
381 return;
382 }
383
384 if (result < 0) {
385 curr_percent = -1;
386
389 }
392 }
395 }
398 }
401 }
404 }
405 else {
407 }
408
410 ctl.show_error_info(msg_text, 0, "", "");
411 }
412 BOOST_LOG_TRIVIAL(error) << "send_job: failed, result = " << result;
413
414 }
415 else {
416 BOOST_LOG_TRIVIAL(error) << "send_job: send ok.";
418 evt->SetString(
from_u8(params.project_name));
421 }
422}
#define PLATE_ALL_IDX
Definition PartPlate.hpp:57
#define PLATE_CURRENT_IDX
Definition PartPlate.hpp:56
#define BAMBU_NETWORK_ERR_PRINT_LP_UPLOAD_FTP_FAILED
Definition bambu_networking.hpp:89
#define BAMBU_NETWORK_ERR_PRINT_SP_GET_NOTIFICATION_TIMEOUT
Definition bambu_networking.hpp:76
#define BAMBU_NETWORK_ERR_FTP_UPLOAD_FAILED
Definition bambu_networking.hpp:36
#define BAMBU_NETWORK_ERR_CANCELED
Definition bambu_networking.hpp:34
#define BAMBU_NETWORK_ERR_PRINT_SP_FILE_OVER_SIZE
Definition bambu_networking.hpp:80
#define BAMBU_NETWORK_ERR_PRINT_SP_CHECK_MD5_FAILED
Definition bambu_networking.hpp:73
#define BAMBU_NETWORK_ERR_PRINT_SG_UPLOAD_FTP_FAILED
Definition bambu_networking.hpp:93
#define BAMBU_NETWORK_ERR_PRINT_WR_FILE_NOT_EXIST
Definition bambu_networking.hpp:65
#define BAMBU_NETWORK_ERR_PRINT_WR_GET_NOTIFICATION_TIMEOUT
Definition bambu_networking.hpp:61
#define BAMBU_NETWORK_ERR_PRINT_SP_FILE_NOT_EXIST
Definition bambu_networking.hpp:78
#define BAMBU_NETWORK_ERR_PRINT_WR_FILE_OVER_SIZE
Definition bambu_networking.hpp:59
#define BAMBU_NETWORK_ERR_PRINT_WR_CHECK_MD5_FAILED
Definition bambu_networking.hpp:57
@ HAS_SDCARD_NORMAL
Definition DevStorage.h:19
@ HAS_SDCARD_ABNORMAL
Definition DevStorage.h:20
@ HAS_SDCARD_READONLY
Definition DevStorage.h:21
@ NO_SDCARD
Definition DevStorage.h:18
bool m_local_use_ssl
Definition SendJob.hpp:49
bool task_use_ams
Definition SendJob.hpp:52
std::string m_dev_ip
Definition SendJob.hpp:42
bool has_sdcard
Definition SendJob.hpp:51
void prepare()
Definition SendJob.cpp:56
DevStorage::SdcardState sdcard_state
Definition SendJob.hpp:54
bool m_is_check_mode
Definition SendJob.hpp:30
std::string task_ams_mapping
Definition SendJob.hpp:45
bool cloud_print_only
Definition SendJob.hpp:50
std::string m_access_code
Definition SendJob.hpp:43
std::string connection_type
Definition SendJob.hpp:46
bool m_local_use_ssl_for_ftp
Definition SendJob.hpp:48
static auto upload_ftp_failed_str
Definition PrintJob.cpp:55
static auto desc_file_too_large
Definition PrintJob.cpp:58
static Plater * plater()
Definition GUI_Factories.cpp:400
static auto desc_fail_not_exist
Definition PrintJob.cpp:59
static auto printjob_cancel_str
Definition PrintJob.cpp:48
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
static auto file_over_size_str
Definition PrintJob.cpp:52
static auto desc_network_error
Definition PrintJob.cpp:57
static auto print_canceled_str
Definition PrintJob.cpp:53
static auto failed_in_cloud_service_str
Definition PrintJob.cpp:50
static auto timeout_to_upload_str
Definition PrintJob.cpp:49
static auto file_is_not_exists_str
Definition PrintJob.cpp:51
static auto desc_upload_ftp_failed
Definition PrintJob.cpp:61
static auto check_gcode_failed_str
Definition PrintJob.cpp:47
static auto send_print_failed_str
Definition PrintJob.cpp:54
@ PrintingStageCreate
Definition bambu_networking.hpp:148
@ PrintingStageFinished
Definition bambu_networking.hpp:154
@ PrintingStageUpload
Definition bambu_networking.hpp:149
@ PrintingStageERROR
Definition bambu_networking.hpp:155
@ SendJobStarted
Definition LifecycleEvents.hpp:62
#define _u8L(s)
Definition I18N.hpp:11