OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::NozzleListTable Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/MultiNozzleSync.hpp>

Inheritance diagram for Slic3r::GUI::NozzleListTable:
Collaboration diagram for Slic3r::GUI::NozzleListTable:

Public Member Functions

 NozzleListTable (wxWindow *parent)
int GetSelectIdx ()
void SetOptions (const std::vector< NozzleOption > &options, int default_select)

Private Member Functions

wxString BuildTableObjStr ()
wxString BuildTextObjStr ()
void SendSelectionChangedEvent ()

Private Attributes

std::vector< NozzleOption > m_nozzle_options
wxWebView * m_web_view
int m_selected_idx

Detailed Description

Constructor & Destructor Documentation

◆ NozzleListTable()

Slic3r::GUI::NozzleListTable::NozzleListTable ( wxWindow * parent)
669 : wxPanel(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize ,wxNO_BORDER)
670{
671 m_web_view = wxWebView::New(this, wxID_ANY, wxEmptyString, wxDefaultPosition,wxDefaultSize,wxString::FromAscii(wxWebViewBackendDefault),wxNO_BORDER);
672 m_web_view->AddScriptMessageHandler("nozzleListTable");
673 m_web_view->EnableContextMenu(false);
674 fs::path filepath = fs::path(resources_dir()) / "web/flush/NozzleListTable.html";
675 wxString url = file_url_from_path(filepath);
676 m_web_view->LoadURL(url);
677
678 auto sizer = new wxBoxSizer(wxVERTICAL);
679 sizer->AddStretchSpacer(0);
680 sizer->Add(m_web_view, 1, wxEXPAND);
681 sizer->AddStretchSpacer(0);
682 SetSizer(sizer);
683 Layout();
684
685 m_web_view->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, [this](wxWebViewEvent& evt) {
686 std::string message = evt.GetString().ToStdString();
687 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << "Received message: " << message;
688 try {
689 json j = json::parse(message);
690 if (j["msg"].get<std::string>() == "init") {
691 auto table_obj_str = BuildTableObjStr();
692 auto text_obj_str = BuildTextObjStr();
693 CallAfter([table_obj_str, text_obj_str, this] {
694 wxString script1 = wxString::Format("initText(%s)", text_obj_str);
695 m_web_view->RunScript(script1);
696 wxString script2 = wxString::Format("initTable(%s)", table_obj_str);
697 m_web_view->RunScript(script2);
698 });
699 }
700 else if (j["msg"].get<std::string>() == "updateList") {
701 auto table_obj_str = BuildTableObjStr();
702
703 CallAfter([table_obj_str, this] {
704 wxString script1 = wxString::Format("updateTable(%s)", table_obj_str);
705 m_web_view->RunScript(script1);
706 });
707
708 }
709 else if (j["msg"].get<std::string>() == "onSelect") {
710 int idx = j["index"].get<int>();
711 m_selected_idx = idx;
713 }
714 else if (j["msg"].get<std::string>() == "layout") {
715 int height = j["height"].get<int>();
716 int width = j["width"].get<int>();
717 wxSize table_size = wxSize(-1, FromDIP(height));
718 m_web_view->SetSize(table_size);
719 m_web_view->SetMaxSize(table_size);
720 m_web_view->SetMinSize(table_size);
721 this->Layout();
722 this->GetParent()->Layout();
723 this->GetParent()->Fit();
724 }
725 }
726 catch (...) {
727 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Failed to parse json message: " << message;
728 }
729 });
730
731 wxGetApp().UpdateDarkUIWin(this);
732}
wxString BuildTableObjStr()
Definition MultiNozzleSync.cpp:734
int m_selected_idx
Definition MultiNozzleSync.hpp:156
wxWebView * m_web_view
Definition MultiNozzleSync.hpp:154
wxString BuildTextObjStr()
Definition MultiNozzleSync.cpp:766
void SendSelectionChangedEvent()
Definition MultiNozzleSync.cpp:759
wxString file_url_from_path(const boost::filesystem::path &path)
Definition GUI.cpp:569
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
nlohmann::json json
Definition AssembleList.cpp:42
const std::string & resources_dir()
Definition utils.cpp:296

References BuildTableObjStr(), BuildTextObjStr(), Slic3r::GUI::file_url_from_path(), m_selected_idx, m_web_view, Slic3r::resources_dir(), and SendSelectionChangedEvent().

Here is the call graph for this function:

Member Function Documentation

◆ BuildTableObjStr()

wxString Slic3r::GUI::NozzleListTable::BuildTableObjStr ( )
private
735{
736 json obj;
737 obj["darkmode"] = wxGetApp().dark_mode();
738 obj["data"] = json::array();
739 for(size_t idx = 0; idx < m_nozzle_options.size(); ++idx){
740 const auto& option = m_nozzle_options[idx];
741 json json_opt;
742 json_opt["diameter"] = option.diameter;
743 json_opt["is_selected"] = idx == m_selected_idx;
744 json_opt["darkmode"] = wxGetApp().dark_mode();
745
746 json extruders = json::object();
747 for (const auto& [extruderId, nozzleInfo] : option.extruder_nozzle_stats) {
748 nlohmann::json nozzleData;
749 nozzleData["type"] = "";
750 nozzleData["count"] = std::accumulate(nozzleInfo.begin(), nozzleInfo.end(), 0, [](int val, auto elem) {return val + elem.second; });
751 extruders[std::to_string(extruderId)] = nozzleData;
752 }
753 json_opt["extruders"] = extruders;
754 obj["data"].push_back(json_opt);
755 }
756 return wxString::FromUTF8(obj.dump().c_str());
757}
std::vector< NozzleOption > m_nozzle_options
Definition MultiNozzleSync.hpp:150

References m_nozzle_options, and m_selected_idx.

Referenced by NozzleListTable(), and SetOptions().

Here is the caller graph for this function:

◆ BuildTextObjStr()

wxString Slic3r::GUI::NozzleListTable::BuildTextObjStr ( )
private
767{
768 wxString nozzle_selection = _L("Nozzle Selection");
769 wxString nozzle_list = _L("Available Nozzles");
770 std::string pt = wxGetApp().preset_bundle->printers.get_edited_preset().get_printer_type(wxGetApp().preset_bundle);
773 wxString highflow = _L(get_nozzle_volume_type_string(nvtHighFlow));
774 wxString standard = _L(get_nozzle_volume_type_string(nvtStandard));
775
776 wxString text_obj = "{";
777 text_obj += wxString::Format("\"nozzle_selection_label\":\"%s\",", nozzle_selection);
778 text_obj += wxString::Format("\"nozzle_list_label\":\"%s\",", nozzle_list);
779 text_obj += wxString::Format("\"left_label\":\"%s\",", Left);
780 text_obj += wxString::Format("\"right_label\":\"%s\",", Right);
781 text_obj += wxString::Format("\"highflow_label\":\"%s\",", highflow);
782 text_obj += wxString::Format("\"standard_label\":\"%s\",", standard);
783 text_obj += wxString::Format("\"language\":\"%s\"", wxGetApp().app_config->get_language_code());
784 text_obj += "}";
785
786 return text_obj;
787}
#define DEPUTY_EXTRUDER_ID
Definition DevDefs.h:102
#define MAIN_EXTRUDER_ID
Definition DevDefs.h:101
#define _L(s)
Definition OBJ.cpp:34
static std::string get_toolhead_display_name(const std::string &type_str, int ext_id, ToolHeadComponent component, ToolHeadNameCase name_case=ToolHeadNameCase::TitleCase, bool short_name=false)
Definition DevConfigUtil.cpp:379
@ Right
Definition GLToolbar.hpp:462
@ Left
Definition GLToolbar.hpp:462
@ nvtHighFlow
Definition PrintConfig.hpp:620
@ nvtStandard
Definition PrintConfig.hpp:619
@ Extruder
Definition DevConfigUtil.h:34
std::string get_nozzle_volume_type_string(NozzleVolumeType nozzle_volume_type)
Definition PrintConfig.cpp:860
@ TitleCase
Definition DevConfigUtil.h:41

References _L, DEPUTY_EXTRUDER_ID, Slic3r::Extruder, Slic3r::get_nozzle_volume_type_string(), Slic3r::DevPrinterConfigUtil::get_toolhead_display_name(), Slic3r::GUI::Left, MAIN_EXTRUDER_ID, Slic3r::nvtHighFlow, Slic3r::nvtStandard, Slic3r::GUI::Right, and Slic3r::TitleCase.

Referenced by NozzleListTable().

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

◆ GetSelectIdx()

int Slic3r::GUI::NozzleListTable::GetSelectIdx ( )

◆ SendSelectionChangedEvent()

void Slic3r::GUI::NozzleListTable::SendSelectionChangedEvent ( )
private
760{
761 wxCommandEvent event(EVT_NOZZLE_SELECTED, GetId());
762 event.SetInt(m_selected_idx);
763 event.SetEventObject(this);
764 ProcessWindowEvent(event);
765}

References m_selected_idx.

Referenced by NozzleListTable().

Here is the caller graph for this function:

◆ SetOptions()

void Slic3r::GUI::NozzleListTable::SetOptions ( const std::vector< NozzleOption > & options,
int default_select )
790{
791 m_nozzle_options = options;
792 m_selected_idx = default_select;
793 auto table_obj_str = BuildTableObjStr();
794 wxString script1 = wxString::Format("updateTable(%s)", table_obj_str);
795 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "update table " << script1;
796
797#if 1
798 m_web_view->RunScript(script1);
799#else
800 CallAfter([script1, this]() {
801 m_web_view->RunScript(script1);
802 });
803#endif
804}

References BuildTableObjStr(), m_nozzle_options, m_selected_idx, and m_web_view.

Here is the call graph for this function:

Member Data Documentation

◆ m_nozzle_options

std::vector<NozzleOption> Slic3r::GUI::NozzleListTable::m_nozzle_options
private

Referenced by BuildTableObjStr(), and SetOptions().

◆ m_selected_idx

int Slic3r::GUI::NozzleListTable::m_selected_idx
private

◆ m_web_view

wxWebView* Slic3r::GUI::NozzleListTable::m_web_view
private

Referenced by NozzleListTable(), and SetOptions().


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