459 :
460 wxDialog(parent, wxID_ANY,
_(
L(
"Flushing volumes for filament change")),
461 wxDefaultPosition, wxDefaultSize,
462 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
464{
465 wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
466 this->SetSizer(main_sizer);
467 this->SetBackgroundColour(*wxWHITE);
468 auto filament_count = wxGetApp().preset_bundle->physical_filament_config_indices().size();
469
470
471
472 wxSize max_scroll_size = { FromDIP(1000), FromDIP(500) };
473 wxSize table_size = { (int)(filament_count + 1) * FromDIP(60), (int)(filament_count + 1) * FromDIP(25) + FromDIP(2) };
474 wxSize scroll_size = { std::min(max_scroll_size.x, table_size.x), std::min(max_scroll_size.y, table_size.y) };
475
476
477
478 wxSize fixed_overhead = { FromDIP(100), FromDIP(325) };
479 wxSize applied_size = scroll_size + fixed_overhead;
480
481
482 wxSize scaled_screen_size = wxGetDisplaySize();
483 double scale_factor = wxDisplay().GetScaleFactor();
484 scaled_screen_size = { (int)(scaled_screen_size.x / scale_factor), (int)(scaled_screen_size.y / scale_factor) };
485 wxSize screen_margin = { FromDIP(40), FromDIP(60) };
486 scaled_screen_size -= screen_margin;
487
488 applied_size = { std::min(applied_size.x, scaled_screen_size.x), std::min(applied_size.y, scaled_screen_size.y) };
489
490
491 applied_size.x = std::max(applied_size.x, FromDIP(350));
492 applied_size.y = std::max(applied_size.y, FromDIP(450));
493 m_webview = wxWebView::New(
this, wxID_ANY,
494 wxEmptyString,
495 wxDefaultPosition,
496 applied_size,
497 wxWebViewBackendDefault,
498 wxNO_BORDER);
499
500 m_webview->AddScriptMessageHandler(
"wipingDialog");
501
502 const nlohmann::json page_strings = {
503
504 {
"from_to",
_u8L(
"from/to")},
505 };
508
509 fs::path filepath = fs::path(
resources_dir()) /
"web/flush/WipingDialog.html";
510 wxString filepath_str =
from_path(filepath);
511 wxFileName fn(filepath_str);
512 if(fn.FileExists()) {
514 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__<< "File exists and load url " << url.ToStdString();
516 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__<< "Successfully loaded url: " << url.ToStdString();
517 } else {
518 BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< "WipingDialog.html not exist at path: " << filepath.string();
519 }
520
521 main_sizer->SetSizeHints(this);
522 main_sizer->Fit(this);
523 CenterOnParent();
524 wxGetApp().UpdateDlgDarkUI(this);
525
526
527
528
529
530
531
532
533
534
535 m_webview->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, [
this](wxWebViewEvent& evt) {
536 std::string message = evt.GetString().ToStdString();
537 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__<< "Received message: " << message;
538 try {
539 json j = json::parse(message);
540 if (j["msg"].get<std::string>() == "init") {
543 CallAfter([table_obj_str, text_obj_str, this] {
544 wxString script1 = wxString::Format("buildTable(%s)", table_obj_str);
546 wxString script2 = wxString::Format("buildText(%s)", text_obj_str);
547 bool result =
m_webview->RunScript(script2);
548 if (!result) {
549 BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< "Failed to run buildText, retry without multi language";
550 wxString script3 = wxString::Format(
"buildText(%s)",
BuildTextObjStr(
false));
552 }
553 });
554 }
555 else if (j["msg"].get<std::string>() == "updateMatrix") {
556 int extruder_id = j["extruder_id"].get<int>();
560 obj["extruder_id"] = extruder_id;
561 CallAfter([obj, this] {
562 std::string flush_volume_matrix_str = obj["flush_volume_matrix"].dump();
563 std::string extruder_id_str = std::to_string(obj["extruder_id"].get<int>());
564 wxString script = wxString::Format("updateTable(%s,%s)", flush_volume_matrix_str, extruder_id_str);
566 });
567 }
568 else if (j["msg"].get<std::string>() == "storeData") {
569 int extruder_num = j["number_of_extruders"].get<int>();
570 std::vector<std::vector<double>> store_matrixs;
571 for (
auto iter = j[
"raw_matrix"].
begin(); iter != j[
"raw_matrix"].end(); ++iter) {
572 store_matrixs.emplace_back((*iter).get<std::vector<double>>());
573 }
574 std::vector<double>store_multipliers = j["flush_multiplier"].get<std::vector<double>>();
575 {
576 size_t cols_temp_matrix = 0;
577 if (!store_matrixs.empty()) { cols_temp_matrix = store_matrixs[0].size(); }
578 if (store_multipliers.size() == store_matrixs.size() && cols_temp_matrix>0)
579 {
580 for (size_t idx = 0; idx < store_multipliers.size(); ++idx) {
581 double m_max_flush_volume_t = (double)
m_max_flush_volume, m_store_multipliers=store_multipliers[idx];
582 std::transform(store_matrixs[idx].
begin(), store_matrixs[idx].
end(),
583 store_matrixs[idx].
begin(),
584 [m_max_flush_volume_t, m_store_multipliers](double inputx) {
585 return std::clamp(inputx, 0.0, m_max_flush_volume_t / m_store_multipliers);
586 });
587 }
588 }
589 }
590 this->
StoreFlushData(extruder_num, store_matrixs, store_multipliers);
592 this->Close();
593 }
594 else if (j["msg"].get<std::string>() == "quit") {
595 this->Close();
596 }
597 }
598 catch (...) {
599 BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< "Failed to parse json message: " << message;
600 }
601 });
602
603 m_webview->Bind(wxEVT_CHAR_HOOK, [
this](wxKeyEvent& e) {
604 if (e.GetKeyCode() == WXK_ESCAPE) {
605 if (IsModal()) EndModal(wxID_CANCEL);
606 else Close();
607 return;
608 }
609 e.Skip();
610 });
611}
#define _(s)
Definition 3mf.cpp:306
#define L(s)
Definition ExtrusionEntity.cpp:25
static std::vector< float > MatrixFlatten(const WipingDialog::VolumeMatrix &matrix)
Definition WipeTowerDialog.cpp:292
static std::string localized_strings_script(const nlohmann::json &strings)
Definition WebViewHostDialog.cpp:156
wxString BuildTextObjStr(bool multi_language=true)
Definition WipeTowerDialog.cpp:403
wxString BuildTableObjStr()
Definition WipeTowerDialog.cpp:335
bool m_submit_flag
Definition WipeTowerDialog.hpp:79
static VolumeMatrix CalcFlushingVolumes(int extruder_id)
Definition WipeTowerDialog.cpp:620
wxWebView * m_webview
Definition WipeTowerDialog.hpp:72
int m_max_flush_volume
Definition WipeTowerDialog.hpp:73
void StoreFlushData(int extruder_num, const std::vector< std::vector< double > > &flush_volume_vecs, const std::vector< double > &flush_multipliers)
Definition WipeTowerDialog.cpp:684
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:838
T * end(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:841
wxString from_path(const boost::filesystem::path &path)
Definition GUI.cpp:555
wxString file_url_from_path(const boost::filesystem::path &path)
Definition GUI.cpp:569
nlohmann::json json
Definition AssembleList.cpp:42
const std::string & resources_dir()
Definition utils.cpp:296
#define _u8L(s)
Definition I18N.hpp:11