diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 5d27d2b..a01701c 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -749,6 +749,10 @@ void MainFrame::init_tabpanel() #else m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxBookCtrlEvent& e) { #endif + //B45 + #if defined(__WIN32__) || defined(__WXMAC__) + m_printer_view->PauseButton(); + #endif if (int old_selection = e.GetOldSelection(); old_selection != wxNOT_FOUND && old_selection < static_cast(m_tabpanel->GetPageCount())) { Tab* old_tab = dynamic_cast(m_tabpanel->GetPage(old_selection)); @@ -893,9 +897,9 @@ void MainFrame::create_preset_tabs() #endif m_tabpanel->AddPage(m_guide_view, _L("Guide")); //B45 - m_tabpanel->Bind(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED, &MainFrame::OnTabPanelSelectionChanged, this); - - + // #if defined(__WIN32__) + // m_tabpanel->Bind(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED, &MainFrame::OnTabPanelSelectionChanged, this); + // #endif } void MainFrame::add_created_tab(Tab* panel, const std::string& bmp_name /*= ""*/) @@ -2108,12 +2112,12 @@ void MainFrame::select_tab(Tab* tab) } //B45 -void MainFrame::OnTabPanelSelectionChanged(wxCommandEvent &event) -{ +// void MainFrame::OnTabPanelSelectionChanged(wxCommandEvent &event) +// { - m_printer_view->PauseButton(); - event.Skip(); -} +// m_printer_view->PauseButton(); +// event.Skip(); +// } @@ -2196,11 +2200,13 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) std::regex ipRegex(R"(\b(?:\d{1,3}\.){3}\d{1,3}\b)"); bool isValidIPAddress = std::regex_match(host.ToStdString(), ipRegex); - + wxStringTokenizer tokenizer2((data->name), " 0.", wxTOKEN_RET_EMPTY); + wxString machine_type = tokenizer2.GetNextToken(); + machine_type += " "+ tokenizer2.GetNextToken(); DynamicPrintConfig *cfg_t = &(printer->config); if (isValidIPAddress) { m_printer_view->AddButton( - data->fullname, "Name: " + data->fullname + "\nIp: " + host, + printer->name, host, machine_type, (data->fullname), [host, this](wxMouseEvent &event) { wxString formattedHost = wxString::Format("http://%s", host); if (!host.Lower().starts_with("http")) @@ -2212,9 +2218,10 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) (data->selected), cfg_t); } } - m_printer_view->ResumeButton(); - + #if defined(__WIN32__) || defined(__WXMAC__) + m_printer_view->ResumeButton(); + #endif if (const DynamicPrintConfig *cfg = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config(); cfg) { diff --git a/src/slic3r/GUI/PrinterWebView.cpp b/src/slic3r/GUI/PrinterWebView.cpp index 0bbe1f8..c2a7b8c 100644 --- a/src/slic3r/GUI/PrinterWebView.cpp +++ b/src/slic3r/GUI/PrinterWebView.cpp @@ -23,6 +23,7 @@ wxBEGIN_EVENT_TABLE(MachineListButton, wxButton) EVT_PAINT(MachineListButton::On EVT_LEAVE_WINDOW(MachineListButton::OnMouseLeave) EVT_LEFT_DOWN(MachineListButton::OnMouseLeftDown) EVT_LEFT_UP(MachineListButton::OnMouseLeftUp) wxEND_EVENT_TABLE() + void MachineListButton::OnPaint(wxPaintEvent &event) { wxPaintDC dc(this); @@ -32,6 +33,11 @@ void MachineListButton::OnPaint(wxPaintEvent &event) dc.SetFont(wxFont(15, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); dc.SetTextForeground(wxColour(230, 230, 230)); dc.DrawText(m_name_text, 10 , 10); + //wxSize textSize = dc.GetTextExtent(m_name_text); + //int x = (dc.GetSize().GetWidth() - textSize.GetWidth()) / 2; + //int y = (dc.GetSize().GetHeight() - textSize.GetHeight()) / 2; + + //dc.DrawText(m_name_text, x, y); } else { dc.DrawBitmap(m_bitmap, 10, (GetSize().GetHeight() - m_bitmap.GetHeight()) / 2, true); @@ -95,7 +101,11 @@ PrinterWebView::PrinterWebView(wxWindow *parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) { - int leftsizerWidth = 300; + #if defined(__WIN32__) || defined(__WXMAC__) + int leftsizerWidth = 300; + #else + int leftsizerWidth = 210; + #endif topsizer = new wxBoxSizer(wxHORIZONTAL); leftScrolledWindow = new wxScrolledWindow(this, wxID_ANY); leftScrolledWindow->SetBackgroundColour(wxColour(45, 45, 48)); @@ -103,31 +113,38 @@ PrinterWebView::PrinterWebView(wxWindow *parent) wxFont font(wxFontInfo().Bold()); wxBoxSizer *titlesizer = new wxBoxSizer(wxHORIZONTAL); - wxStaticText *text = new wxStaticText(leftScrolledWindow, wxID_ANY, "MACHINE LIST", wxDefaultPosition, wxDefaultSize); - text->SetForegroundColour(wxColour(255, 255, 255)); - text->SetFont(wxFont(wxFontInfo(18).Bold())); - titlesizer->Add(text, wxSizerFlags().Align(wxALIGN_LEFT).Border(wxALL, 5)); + text_static = new wxStaticText(leftScrolledWindow, wxID_ANY, "MACHINE LIST", wxDefaultPosition, wxDefaultSize); + text_static->SetForegroundColour(wxColour(255, 255, 255)); + text_static->SetFont(wxFont(wxFontInfo(18).Bold())); + #if defined __linux__ + text_static->SetMinSize(wxSize(200, 40)); + text_static->SetFont(wxFont(wxFontInfo(12).Bold())); + #endif + + titlesizer->Add(text_static, wxSizerFlags().Align(wxALIGN_LEFT).Border(wxALL, 5)); titlesizer->AddStretchSpacer(); //wxBU_EXACTFIT wxBORDER_NONE - wxButton *refresh_button = new wxButton(leftScrolledWindow, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE); - refresh_button->SetBackgroundColour(leftScrolledWindow->GetBackgroundColour()); - refresh_button->SetForegroundColour(leftScrolledWindow->GetBackgroundColour()); + #if defined(__WIN32__) || defined(__WXMAC__) + wxButton *refresh_button = new wxButton(leftScrolledWindow, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE); + refresh_button->SetBackgroundColour(leftScrolledWindow->GetBackgroundColour()); + refresh_button->SetForegroundColour(leftScrolledWindow->GetBackgroundColour()); - refresh_button->SetMinSize(wxSize(40, -1)); - refresh_button->SetBitmap(*get_bmp_bundle("refresh-line", 20)); - //leftsizer->Add(button2, wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL, 2)); - titlesizer->Add(refresh_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2)); - refresh_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnRightButtonClick, this); + refresh_button->SetMinSize(wxSize(40, -1)); + refresh_button->SetBitmap(*get_bmp_bundle("refresh-line", 20)); + //leftsizer->Add(button2, wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL, 2)); + titlesizer->Add(refresh_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2)); + refresh_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnRightButtonClick, this); - arrow_button = new wxButton(leftScrolledWindow, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE); - arrow_button->SetFont(font); - arrow_button->SetBackgroundColour(leftScrolledWindow->GetBackgroundColour()); - arrow_button->SetForegroundColour(leftScrolledWindow->GetBackgroundColour()); - arrow_button->SetMinSize(wxSize(40, -1)); - arrow_button->SetBitmap(*get_bmp_bundle("arrow-left-s-line", 20)); - // leftsizer->Add(arrow_button, wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_TOP).Border(wxALL, 2)); - titlesizer->Add(arrow_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2)); - arrow_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnLeftButtonClick, this); + arrow_button = new wxButton(leftScrolledWindow, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE); + arrow_button->SetFont(font); + arrow_button->SetBackgroundColour(leftScrolledWindow->GetBackgroundColour()); + arrow_button->SetForegroundColour(leftScrolledWindow->GetBackgroundColour()); + arrow_button->SetMinSize(wxSize(40, -1)); + arrow_button->SetBitmap(*get_bmp_bundle("arrow-left-s-line", 20)); + // leftsizer->Add(arrow_button, wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_TOP).Border(wxALL, 2)); + titlesizer->Add(arrow_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2)); + arrow_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnLeftButtonClick, this); + #endif titlesizer->Layout(); @@ -173,38 +190,38 @@ PrinterWebView::PrinterWebView(wxWindow *parent) -void PrinterWebView::AddButton(const wxString & buttonText, - const wxString & moreInfo, +void PrinterWebView::AddButton(const wxString & device_name, + const wxString & ip, + const wxString & machine_type, + const wxString & fullname, const std::function &handler, bool isSelected, DynamicPrintConfig * cfg_t) { + wxString Machine_Name = Machine_Name.Format("%s%s", machine_type, "_thumbnail"); - wxStringTokenizer tokenizer(moreInfo, " "); - - - tokenizer.GetNextToken(); - wxString Name = tokenizer.GetNextToken(); - tokenizer.GetNextToken(); - wxString Machine_Type = tokenizer.GetNextToken(); - wxString Machine_Count = tokenizer.GetNextToken(); - tokenizer.GetNextToken(); - tokenizer.GetNextToken(); - wxString Machine_IP = tokenizer.GetNextToken(); - wxString Machine_Name = Machine_Name.Format("%s %s%s", Machine_Type, Machine_Count, "_thumbnail"); - - MachineListButton *customButton = new MachineListButton(leftScrolledWindow, wxID_ANY, buttonText, wxDefaultPosition, wxDefaultSize, wxBORDER_DOUBLE, + MachineListButton *customButton = new MachineListButton(leftScrolledWindow, wxID_ANY, device_name, + fullname, + wxDefaultPosition, + wxDefaultSize, wxBU_LEFT, wxDefaultValidator, wxButtonNameStr, isSelected); - customButton->SetMinSize(wxSize(80, -1)); - customButton->SetBitmap(*get_bmp_bundle(std::string(Machine_Name.mb_str()), 80)); + //customButton->SetMinSize(wxSize(80, -1)); + #if defined(__WIN32__) || defined(__WXMAC__) + customButton->SetBitmap(*get_bmp_bundle(std::string(Machine_Name.mb_str()), 80)); + #endif customButton->SetBitMap(get_bmp_bundle(std::string(Machine_Name.mb_str()), 80)->GetBitmapFor(this)); - customButton->SetNameText(Name); - customButton->SetIPText(Machine_IP); + customButton->SetForegroundColour(wxColour(255, 255, 255)); + customButton->SetNameText(device_name); + customButton->SetIPText(ip); customButton->SetStateText("standby"); customButton->SetProgressText("(0%)"); - customButton->SetMinSize(wxSize(200, -1)); + //customButton->SetMinSize(wxSize(200, -1)); customButton->SetClickHandler(handler); - customButton->SetStatusThread(std::move(customButton->CreatThread(buttonText, cfg_t))); + #if defined(__WIN32__) || defined(__WXMAC__) + customButton->SetStatusThread(std::move(customButton->CreatThread(device_name,ip, cfg_t))); + #else + customButton->SetSize(wxSize(200, -1)); + #endif customButton->SetSimpleMode(false); leftsizer->Add(customButton, wxSizerFlags().Border(wxALL, 1).Expand()); @@ -272,20 +289,26 @@ void PrinterWebView::OnLeftButtonClick(wxCommandEvent &event) m_isSimpleMode = !m_isSimpleMode; if (!m_isSimpleMode) { + leftsizer->SetMinSize(wxSize(300, -1)); leftScrolledWindow->SetMinSize(wxSize(300, -1)); arrow_button->SetBitmap(*get_bmp_bundle("arrow-left-s-line", 20)); + text_static->SetFont(wxFont(wxFontInfo(18).Bold())); for (MachineListButton *button : m_buttons) { button->SetBitmap(*get_bmp_bundle(std::string("X-MAX 3_thumbnail"), 80)); button->SetSimpleMode(m_isSimpleMode); + button->SetSize(wxSize(300, -1)); + } } else { arrow_button->SetBitmap(*get_bmp_bundle("arrow-right-s-line", 20)); - - leftScrolledWindow->SetMinSize(wxSize(260, -1)); + leftsizer->SetMinSize(wxSize(210, -1)); + leftScrolledWindow->SetMinSize(wxSize(210, -1)); + text_static->SetFont(wxFont(wxFontInfo(12).Bold())); for (MachineListButton *button : m_buttons) { button->SetBitmap(*get_bmp_bundle(std::string("X-MAX 3_thumbnail"), 30)); button->SetSimpleMode(m_isSimpleMode); + button->SetSize(wxSize(200, -1)); } } @@ -295,6 +318,7 @@ void PrinterWebView::OnLeftButtonClick(wxCommandEvent &event) leftScrolledWindow->Layout(); topsizer->Layout(); + //UpdateLayout(); } void PrinterWebView::OnRightButtonClick(wxCommandEvent &event) @@ -306,18 +330,18 @@ void PrinterWebView::OnRightButtonClick(wxCommandEvent &event) -void PrinterWebView::SendRecentList(int images) -{ - boost::property_tree::wptree req; - boost::property_tree::wptree data; - //wxGetApp().mainframe->get_recent_projects(data, images); - req.put(L"sequence_id", ""); - req.put(L"command", L"studio_set_mallurl"); - //req.put_child(L"response", data); - std::wostringstream oss; - pt::write_json(oss, req, false); - RunScript(wxString::Format("window.postMessage(%s)", oss.str())); -} +//void PrinterWebView::SendRecentList(int images) +//{ +// boost::property_tree::wptree req; +// boost::property_tree::wptree data; +// //wxGetApp().mainframe->get_recent_projects(data, images); +// req.put(L"sequence_id", ""); +// req.put(L"command", L"studio_set_mallurl"); +// //req.put_child(L"response", data); +// std::wostringstream oss; +// pt::write_json(oss, req, false); +// RunScript(wxString::Format("window.postMessage(%s)", oss.str())); +//} @@ -328,7 +352,7 @@ void PrinterWebView::OnScriptMessage(wxWebViewEvent &evt) //std::string response = wxGetApp().handle_web_request(evt.GetString().ToUTF8().data()); //if (response.empty()) // return; - SendRecentList(1); + //SendRecentList(1); ///* remove \n in response string */ //response.erase(std::remove(response.begin(), response.end(), '\n'), response.end()); //if (!response.empty()) { diff --git a/src/slic3r/GUI/PrinterWebView.hpp b/src/slic3r/GUI/PrinterWebView.hpp index 97f75bb..13b82fc 100644 --- a/src/slic3r/GUI/PrinterWebView.hpp +++ b/src/slic3r/GUI/PrinterWebView.hpp @@ -26,8 +26,12 @@ #include //B35 +//B45 #if defined __linux__ #include +#include +#include +#include #endif //B45 @@ -43,6 +47,7 @@ public: MachineListButton(wxWindow * parent, wxWindowID id, const wxString & label, + const wxString &fullname, const wxPoint & pos = wxDefaultPosition, const wxSize & size = wxDefaultSize, long style = wxBORDER_DOUBLE, @@ -51,7 +56,7 @@ public: bool isSelected = false) : wxButton(parent, id, label, pos, size, style, validator, name) { - full_label = label; + full_label = fullname; m_isSelected = isSelected; if (isSelected) SetBackgroundColour(wxColour(100, 100, 105)); @@ -128,10 +133,10 @@ public: void OnMouseLeftUp(wxMouseEvent &event); void OnClickHandler(wxCommandEvent &event); void SetStatusThread(std::thread thread) { m_statusThread = std::move(thread); } - std::thread CreatThread(const wxString &buttonText, DynamicPrintConfig *cfg_t) + std::thread CreatThread(const wxString &buttonText, const wxString &ip, DynamicPrintConfig *cfg_t) { - std::thread thread([this, buttonText, cfg_t]() { + std::thread thread([this, buttonText,ip, cfg_t]() { std::unique_ptr printhost(PrintHost::get_print_host(cfg_t)); if (!printhost) { BOOST_LOG_TRIVIAL(error) << ("Could not get a valid Printer Host reference"); @@ -139,24 +144,26 @@ public: } wxString msg; std::string state = "standby"; - float progress = 0; + float progress = 0; while (true) { if (!m_pauseThread) { state = printhost->get_status(msg); if (state == "offline") { - //BOOST_LOG_TRIVIAL(error) << boost::format("%1%Got state: %2%") % buttonText % state; + BOOST_LOG_TRIVIAL(info) << boost::format("%1%Got state: %2%") % buttonText % state; + SetStateText(state); m_pauseThread = true; } BOOST_LOG_TRIVIAL(info) << boost::format("%1%Got state: %2%") % buttonText % state; SetStateText(state); + if (state == "printing") { progress = (printhost->get_progress(msg)) * 100; int progressInt = static_cast(progress); - SetStateText(state); SetProgressText(wxString::Format(wxT("(%d%%)"), progressInt)); + BOOST_LOG_TRIVIAL(info) << boost::format("%1%Got progress: %2%") % buttonText % progress; - } - ; + } + } else std::this_thread::sleep_for(std::chrono::seconds(3)); if (m_stopThread) @@ -212,13 +219,15 @@ public: void OnScroll(wxScrollWinEvent &event); //B45 - void SendRecentList(int images); + //void SendRecentList(int images); void SetButtons(std::vector buttons); - void AddButton(const wxString & buttonText, - const wxString & moreInfo, - const std::function &handler, - bool isOnline, - DynamicPrintConfig * cfg_t); + void AddButton(const wxString & device_name, + const wxString & ip, + const wxString & machine_type, + const wxString & fullname, + const std::function &handler, + bool isSelected, + DynamicPrintConfig * cfg_t); void DeleteButton(); void PauseButton(); void ResumeButton(); @@ -231,6 +240,7 @@ private: bool m_isSimpleMode = false; wxButton *arrow_button; + wxStaticText * text_static; wxScrolledWindow * leftScrolledWindow;