Files
QIDISlicer/src/slic3r/GUI/PrinterWebView.hpp

249 lines
7.1 KiB
C++
Raw Normal View History

2023-06-10 10:14:12 +08:00
#ifndef slic3r_PrinterWebView_hpp_
#define slic3r_PrinterWebView_hpp_
#include "wx/artprov.h"
#include "wx/cmdline.h"
#include "wx/notifmsg.h"
#include "wx/settings.h"
#include "wx/webview.h"
#if wxUSE_WEBVIEW_EDGE
#include "wx/msw/webview_edge.h"
#endif
#include "wx/webviewarchivehandler.h"
#include "wx/webviewfshandler.h"
#include "wx/numdlg.h"
#include "wx/infobar.h"
#include "wx/filesys.h"
#include "wx/fs_arc.h"
#include "wx/fs_mem.h"
#include "wx/stdpaths.h"
#include <wx/panel.h>
#include <wx/tbarbase.h>
#include "wx/textctrl.h"
#include <wx/timer.h>
2023-09-11 11:10:12 +08:00
//B35
#if defined __linux__
#include <boost/log/trivial.hpp>
#endif
2023-11-27 11:29:19 +08:00
//B45
#include "PrintHostDialogs.hpp"
#include <wx/tokenzr.h>
2023-06-10 10:14:12 +08:00
namespace Slic3r {
namespace GUI {
2023-11-27 11:29:19 +08:00
class MachineListButton : public wxButton
{
public:
MachineListButton(wxWindow * parent,
wxWindowID id,
const wxString & label,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = wxBORDER_DOUBLE,
const wxValidator &validator = wxDefaultValidator,
const wxString & name = wxButtonNameStr,
bool isSelected = false)
: wxButton(parent, id, label, pos, size, style, validator, name)
{
full_label = label;
m_isSelected = isSelected;
if (isSelected)
SetBackgroundColour(wxColour(100, 100, 105));
else
SetBackgroundColour(wxColour(67, 67, 71));
//Bind(wxEVT_BUTTON, &MachineListButton::OnMouseLeftUp, this);
}
wxString getLabel() { return full_label; }
wxString getIPLabel() { return m_ip_text; }
void SetBitMap(const wxBitmap &bitmap)
{
m_bitmap = bitmap;
Refresh();
}
void SetNameText(const wxString &text)
{
m_name_text = text;
Refresh();
}
void SetIPText(const wxString &text)
{
m_ip_text = text;
Refresh();
}
void SetStateText(const wxString &text)
{
m_state_text = text;
Refresh();
}
void SetProgressText(const wxString &text)
{
m_progress_text = text;
Refresh();
}
void SetSelect(bool isselectd)
{
m_isSelected = isselectd;
if (m_isSelected)
SetBackgroundColour(wxColour(100, 100, 105));
else
SetBackgroundColour(wxColour(67, 67, 71));
Refresh();
}
void SetSimpleMode(bool issimplemode)
{
m_isSimpleMode = issimplemode;
//if (m_isSelected)
// SetBackgroundColour(wxColour(100, 100, 105));
//else
// SetBackgroundColour(wxColour(67, 67, 71));
Refresh();
}
void SetClickHandler(const std::function<void(wxMouseEvent &)> &handler) { m_handlerl = handler; }
void PauseStatusThread() { m_pauseThread = true; }
void ResumeStatusThread() { m_pauseThread = false; }
void StopStatusThread()
{
m_stopThread = true;
if (m_statusThread.joinable()) {
m_statusThread.join();
}
}
void OnPaint(wxPaintEvent &event);
void OnMouseEnter(wxMouseEvent &event);
void OnMouseLeave(wxMouseEvent &event);
void OnMouseLeftDown(wxMouseEvent &event);
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 thread([this, buttonText, cfg_t]() {
std::unique_ptr<PrintHost> printhost(PrintHost::get_print_host(cfg_t));
if (!printhost) {
BOOST_LOG_TRIVIAL(error) << ("Could not get a valid Printer Host reference");
return;
}
wxString msg;
std::string state = "standby";
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;
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<int>(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)
break;
}
});
return thread;
}
private:
std::atomic<bool> m_stopThread{false};
std::atomic<bool> m_pauseThread{false};
bool m_isSimpleMode;
bool m_isSelected;
std::thread m_statusThread;
wxBitmap m_bitmap;
bool m_isHovered;
wxString full_label;
wxString m_name_text;
wxString m_ip_text;
wxString m_state_text;
wxString m_progress_text;
std::function<void(wxMouseEvent &)> m_handlerl;
wxDECLARE_EVENT_TABLE();
//wxDECLARE_EVENT_TABLE();
};
2023-06-10 10:14:12 +08:00
class PrinterWebView : public wxPanel {
public:
PrinterWebView(wxWindow *parent);
virtual ~PrinterWebView();
void load_url(wxString& url);
void UpdateState();
void OnClose(wxCloseEvent& evt);
2023-11-27 11:29:19 +08:00
//B45
void OnLeftButtonClick(wxCommandEvent &event);
void OnRightButtonClick(wxCommandEvent &event);
void RunScript(const wxString &javascript);
//void OnScriptMessageReceived(wxWebViewEvent &event);
void OnScriptMessage(wxWebViewEvent &evt);
void UpdateLayout();
void OnScroll(wxScrollWinEvent &event);
//B45
void SendRecentList(int images);
void SetButtons(std::vector<MachineListButton *> buttons);
void AddButton(const wxString & buttonText,
const wxString & moreInfo,
const std::function<void(wxMouseEvent &)> &handler,
bool isOnline,
DynamicPrintConfig * cfg_t);
void DeleteButton();
void PauseButton();
void ResumeButton();
std::vector<MachineListButton *> GetButton() { return m_buttons; };
2023-06-10 10:14:12 +08:00
private:
2023-11-27 11:29:19 +08:00
//B45
wxBoxSizer *leftsizer;
wxBoxSizer *topsizer;
bool m_isSimpleMode = false;
wxButton *arrow_button;
wxScrolledWindow * leftScrolledWindow;
std::vector<MachineListButton *> m_buttons;
2023-06-10 10:14:12 +08:00
wxWebView* m_browser;
long m_zoomFactor;
// DECLARE_EVENT_TABLE()
};
} // GUI
} // Slic3r
#endif /* slic3r_Tab_hpp_ */