NEW:lan mode interaction optimization
Change-Id: I80eef918fe1ac4c8e306787bd7b9437262686e23
This commit is contained in:
parent
5a78f7ade1
commit
4a5c473058
10 changed files with 201 additions and 17 deletions
|
@ -108,6 +108,11 @@ ConnectPrinterDialog::ConnectPrinterDialog(wxWindow *parent, wxWindowID id, cons
|
|||
|
||||
ConnectPrinterDialog::~ConnectPrinterDialog() {}
|
||||
|
||||
void ConnectPrinterDialog::end_modal(wxStandardID id)
|
||||
{
|
||||
EndModal(id);
|
||||
}
|
||||
|
||||
void ConnectPrinterDialog::init_bitmap()
|
||||
{
|
||||
AppConfig *config = get_app_config();
|
||||
|
@ -144,6 +149,7 @@ void ConnectPrinterDialog::on_button_confirm(wxCommandEvent &event)
|
|||
}
|
||||
if (m_obj) {
|
||||
m_obj->set_access_code(code.ToStdString());
|
||||
wxGetApp().getDeviceManager()->set_selected_machine(m_obj->dev_id);
|
||||
}
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
|
||||
~ConnectPrinterDialog();
|
||||
|
||||
void end_modal(wxStandardID id);
|
||||
void init_bitmap();
|
||||
void set_machine_object(MachineObject* obj);
|
||||
void on_input_enter(wxCommandEvent& evt);
|
||||
|
|
|
@ -3330,6 +3330,7 @@ bool DeviceManager::set_selected_machine(std::string dev_id)
|
|||
m_agent->disconnect_printer();
|
||||
it->second->reset();
|
||||
it->second->connect();
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -3346,6 +3347,7 @@ bool DeviceManager::set_selected_machine(std::string dev_id)
|
|||
m_agent->disconnect_printer();
|
||||
it->second->reset();
|
||||
it->second->connect();
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,6 +388,9 @@ public:
|
|||
bool is_avaliable() { return bind_state == "free"; }
|
||||
time_t last_alive;
|
||||
bool m_is_online;
|
||||
bool m_lan_mode_connection_state{false};
|
||||
void set_lan_mode_connection_state(bool state) {m_lan_mode_connection_state = state;};
|
||||
bool get_lan_mode_connection_state() {return m_lan_mode_connection_state;};
|
||||
int parse_msg_count = 0;
|
||||
std::chrono::system_clock::time_point last_update_time; /* last received print data from machine */
|
||||
std::chrono::system_clock::time_point last_push_time; /* last received print push from machine */
|
||||
|
|
|
@ -1195,7 +1195,7 @@ void GUI_App::post_init()
|
|||
wxDEFINE_EVENT(EVT_ENTER_FORCE_UPGRADE, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_SHOW_NO_NEW_VERSION, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_SHOW_DIALOG, wxCommandEvent);
|
||||
|
||||
wxDEFINE_EVENT(EVT_CONNECT_LAN_MODE_PRINT, wxCommandEvent);
|
||||
IMPLEMENT_APP(GUI_App)
|
||||
|
||||
//BBS: remove GCodeViewer as seperate APP logic
|
||||
|
@ -1693,11 +1693,16 @@ void GUI_App::init_networking_callbacks()
|
|||
}
|
||||
/* request_pushing */
|
||||
MachineObject* obj = m_device_manager->get_my_machine(dev_id);
|
||||
wxCommandEvent event(EVT_CONNECT_LAN_MODE_PRINT);
|
||||
|
||||
if (obj) {
|
||||
|
||||
if (obj->is_lan_mode_printer()) {
|
||||
if (state == ConnectStatus::ConnectStatusOk) {
|
||||
obj->command_request_push_all();
|
||||
obj->command_get_version();
|
||||
event.SetInt(1);
|
||||
event.SetString(obj->dev_id);
|
||||
} else if (state == ConnectStatus::ConnectStatusFailed) {
|
||||
obj->set_access_code("");
|
||||
m_device_manager->set_selected_machine("");
|
||||
|
@ -1709,14 +1714,21 @@ void GUI_App::init_networking_callbacks()
|
|||
text = wxString::Format(_L("Connect %s failed! [SN:%s, code=%s]"), from_u8(obj->dev_name), obj->dev_id, msg);
|
||||
wxGetApp().show_dialog(text);
|
||||
}
|
||||
event.SetInt(0);
|
||||
} else if (state == ConnectStatus::ConnectStatusLost) {
|
||||
m_device_manager->set_selected_machine("");
|
||||
event.SetInt(0);
|
||||
BOOST_LOG_TRIVIAL(info) << "set_on_local_connect_fn: state = lost";
|
||||
} else {
|
||||
event.SetInt(0);
|
||||
BOOST_LOG_TRIVIAL(info) << "set_on_local_connect_fn: state = " << state;
|
||||
}
|
||||
|
||||
obj->set_lan_mode_connection_state(false);
|
||||
}
|
||||
}
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
@ -582,7 +582,7 @@ private:
|
|||
};
|
||||
|
||||
DECLARE_APP(GUI_App)
|
||||
|
||||
wxDECLARE_EVENT(EVT_CONNECT_LAN_MODE_PRINT, wxCommandEvent);
|
||||
} // GUI
|
||||
} // Slic3r
|
||||
|
||||
|
|
|
@ -1214,6 +1214,13 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater)
|
|||
Bind(EVT_UPDATE_USER_MACHINE_LIST, &SelectMachineDialog::update_printer_combobox, this);
|
||||
Bind(EVT_PRINT_JOB_CANCEL, &SelectMachineDialog::on_print_job_cancel, this);
|
||||
Bind(EVT_SET_FINISH_MAPPING, &SelectMachineDialog::on_set_finish_mapping, this);
|
||||
wxGetApp().Bind(EVT_CONNECT_LAN_MODE_PRINT, [this](wxCommandEvent& e) {
|
||||
if (e.GetInt() == 1) {
|
||||
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
|
||||
if (!dev) return;
|
||||
m_comboBox_printer->SetValue(dev->get_selected_machine()->dev_name);
|
||||
}
|
||||
});
|
||||
|
||||
m_panel_prepare->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
|
||||
check_fcous_state(this);
|
||||
|
@ -2257,6 +2264,7 @@ void SelectMachineDialog::update_user_printer()
|
|||
wxArrayString machine_list_name;
|
||||
std::map<std::string, MachineObject*> option_list;
|
||||
|
||||
//user machine list
|
||||
option_list = dev->get_my_machine_list();
|
||||
|
||||
// same machine only appear once
|
||||
|
@ -2265,6 +2273,27 @@ void SelectMachineDialog::update_user_printer()
|
|||
machine_list.push_back(it->second->dev_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//lan machine list
|
||||
auto lan_option_list = dev->get_local_machine_list();
|
||||
|
||||
for (auto elem : lan_option_list) {
|
||||
MachineObject* mobj = elem.second;
|
||||
|
||||
/* do not show printer bind state is empty */
|
||||
if (!mobj->is_avaliable()) continue;
|
||||
if (!mobj->is_online()) continue;
|
||||
if (!mobj->is_lan_mode_printer()) continue;
|
||||
/*if (mobj->is_in_printing()) {op->set_printer_state(PrinterState::BUSY);}*/
|
||||
|
||||
if (!mobj->has_access_right()) {
|
||||
option_list[mobj->dev_name] = mobj;
|
||||
machine_list.push_back(mobj->dev_name);
|
||||
}
|
||||
}
|
||||
|
||||
machine_list = sort_string(machine_list);
|
||||
for (auto tt = machine_list.begin(); tt != machine_list.end(); tt++) {
|
||||
for (auto it = option_list.begin(); it != option_list.end(); it++) {
|
||||
|
@ -2283,8 +2312,15 @@ void SelectMachineDialog::update_user_printer()
|
|||
m_comboBox_printer->Set(machine_list_name);
|
||||
|
||||
MachineObject* obj = dev->get_selected_machine();
|
||||
|
||||
if (obj) {
|
||||
m_printer_last_select = obj->dev_id;
|
||||
if (obj->is_lan_mode_printer() && !obj->has_access_right()) {
|
||||
m_printer_last_select = "";
|
||||
}
|
||||
else {
|
||||
m_printer_last_select = obj->dev_id;
|
||||
}
|
||||
|
||||
} else {
|
||||
m_printer_last_select = "";
|
||||
}
|
||||
|
@ -2292,20 +2328,36 @@ void SelectMachineDialog::update_user_printer()
|
|||
if (m_list.size() > 0) {
|
||||
// select a default machine
|
||||
if (m_printer_last_select.empty()) {
|
||||
m_printer_last_select = m_list[0]->dev_id;
|
||||
m_comboBox_printer->SetSelection(0);
|
||||
wxCommandEvent event(wxEVT_COMBOBOX);
|
||||
event.SetEventObject(m_comboBox_printer);
|
||||
wxPostEvent(m_comboBox_printer, event);
|
||||
}
|
||||
for (auto i = 0; i < m_list.size(); i++) {
|
||||
if (m_list[i]->dev_id == m_printer_last_select) {
|
||||
m_comboBox_printer->SetSelection(i);
|
||||
int def_selection = -1;
|
||||
for (int i = 0; i < m_list.size(); i++) {
|
||||
if (m_list[i]->is_lan_mode_printer() && !m_list[i]->has_access_right()) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
def_selection = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (def_selection >= 0) {
|
||||
m_printer_last_select = m_list[def_selection]->dev_id;
|
||||
m_comboBox_printer->SetSelection(def_selection);
|
||||
wxCommandEvent event(wxEVT_COMBOBOX);
|
||||
event.SetEventObject(m_comboBox_printer);
|
||||
wxPostEvent(m_comboBox_printer, event);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto i = 0; i < m_list.size(); i++) {
|
||||
if (m_list[i]->dev_id == m_printer_last_select) {
|
||||
|
||||
if (obj && !obj->get_lan_mode_connection_state()) {
|
||||
m_comboBox_printer->SetSelection(i);
|
||||
wxCommandEvent event(wxEVT_COMBOBOX);
|
||||
event.SetEventObject(m_comboBox_printer);
|
||||
wxPostEvent(m_comboBox_printer, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_printer_last_select = "";
|
||||
|
@ -2413,14 +2465,27 @@ void SelectMachineDialog::on_selection_changed(wxCommandEvent &event)
|
|||
MachineObject* obj = nullptr;
|
||||
for (int i = 0; i < m_list.size(); i++) {
|
||||
if (i == selection) {
|
||||
|
||||
//check lan mode machine
|
||||
if (m_list[i]->is_lan_mode_printer() && !m_list[i]->has_access_right()) {
|
||||
ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code"));
|
||||
dlg.set_machine_object(m_list[i]);
|
||||
auto res = dlg.ShowModal();
|
||||
m_printer_last_select = "";
|
||||
m_comboBox_printer->SetSelection(-1);
|
||||
m_comboBox_printer->Refresh();
|
||||
m_comboBox_printer->Update();
|
||||
}
|
||||
|
||||
m_printer_last_select = m_list[i]->dev_id;
|
||||
obj = m_list[i];
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "for send task, current printer id = " << m_printer_last_select << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj) {
|
||||
if (obj && !obj->get_lan_mode_connection_state()) {
|
||||
obj->command_get_version();
|
||||
obj->command_request_push_all();
|
||||
dev->set_selected_machine(m_printer_last_select);
|
||||
|
@ -2982,6 +3047,7 @@ bool SelectMachineDialog::Show(bool show)
|
|||
wxGetApp().reset_to_active();
|
||||
set_default();
|
||||
update_user_machine_list();
|
||||
//update_lan_machine_list();
|
||||
}
|
||||
|
||||
if (show) {
|
||||
|
@ -3004,6 +3070,70 @@ SelectMachineDialog::~SelectMachineDialog()
|
|||
delete confirm_dlg;
|
||||
}
|
||||
|
||||
void SelectMachineDialog::update_lan_machine_list()
|
||||
{
|
||||
DeviceManager* dev = wxGetApp().getDeviceManager();
|
||||
if (!dev) return;
|
||||
auto m_free_machine_list = dev->get_local_machine_list();
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup update_other_devices start";
|
||||
|
||||
for (auto& elem : m_free_machine_list) {
|
||||
MachineObject* mobj = elem.second;
|
||||
|
||||
/* do not show printer bind state is empty */
|
||||
if (!mobj->is_avaliable()) continue;
|
||||
if (!mobj->is_online()) continue;
|
||||
if (!mobj->is_lan_mode_printer()) continue;
|
||||
/*if (mobj->is_in_printing()) {op->set_printer_state(PrinterState::BUSY);}*/
|
||||
|
||||
if (mobj->has_access_right()) {
|
||||
auto b = mobj->dev_name;
|
||||
|
||||
// clear machine list
|
||||
|
||||
//m_comboBox_printer->Clear();
|
||||
std::vector<std::string> machine_list;
|
||||
wxArrayString machine_list_name;
|
||||
std::map<std::string, MachineObject*> option_list;
|
||||
|
||||
// same machine only appear once
|
||||
|
||||
/* machine_list = sort_string(machine_list);
|
||||
for (auto tt = machine_list.begin(); tt != machine_list.end(); tt++) {
|
||||
for (auto it = option_list.begin(); it != option_list.end(); it++) {
|
||||
if (it->second->dev_name == *tt) {
|
||||
m_list.push_back(it->second);
|
||||
wxString dev_name_text = from_u8(it->second->dev_name);
|
||||
if (it->second->is_lan_mode_printer()) {
|
||||
dev_name_text += "(LAN)";
|
||||
}
|
||||
machine_list_name.Add(dev_name_text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_comboBox_printer->Set(machine_list_name);
|
||||
|
||||
MachineObject* obj = dev->get_selected_machine();
|
||||
if (obj) {
|
||||
m_printer_last_select = obj->dev_id;
|
||||
}
|
||||
else {
|
||||
m_printer_last_select = "";
|
||||
}*/
|
||||
//op->set_printer_state(PrinterState::LOCK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "SelectMachineDialog update_lan_devices end";
|
||||
}
|
||||
|
||||
|
||||
EditDevNameDialog::EditDevNameDialog(Plater *plater /*= nullptr*/)
|
||||
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Modifying the device name"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
|
||||
{
|
||||
|
|
|
@ -355,12 +355,13 @@ protected:
|
|||
|
||||
public:
|
||||
SelectMachineDialog(Plater *plater = nullptr);
|
||||
void check_focus(wxWindow* window);
|
||||
void check_fcous_state(wxWindow* window);
|
||||
wxWindow* create_ams_checkbox(wxString title, wxWindow* parent, wxString tooltip);
|
||||
~SelectMachineDialog();
|
||||
|
||||
wxWindow *create_item_checkbox(wxString title, wxWindow *parent, wxString tooltip, std::string param);
|
||||
|
||||
void check_focus(wxWindow* window);
|
||||
void check_fcous_state(wxWindow* window);
|
||||
wxWindow *create_ams_checkbox(wxString title, wxWindow *parent, wxString tooltip);
|
||||
wxWindow* create_item_checkbox(wxString title, wxWindow* parent, wxString tooltip, std::string param);
|
||||
void update_select_layout(MachineObject *obj);
|
||||
void prepare_mode();
|
||||
void sending_mode();
|
||||
|
@ -430,6 +431,7 @@ protected:
|
|||
void Enable_Send_Button(bool en);
|
||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||
void update_user_machine_list();
|
||||
void update_lan_machine_list();
|
||||
wxImage * LoadImageFromBlob(const unsigned char *data, int size);
|
||||
std::vector<std::string> sort_string(std::vector<std::string> strArray);
|
||||
};
|
||||
|
|
|
@ -1419,6 +1419,33 @@ void StatusPanel::update(MachineObject *obj)
|
|||
m_tempCtrl_frame->Disable();
|
||||
}
|
||||
|
||||
if (!obj->dev_connection_type.empty()) {
|
||||
auto iter_connect_type = m_print_connect_types.find(obj->dev_id);
|
||||
if (iter_connect_type != m_print_connect_types.end()) {
|
||||
if (iter_connect_type->second != obj->dev_connection_type) {
|
||||
|
||||
//lan = > cloud
|
||||
if (iter_connect_type->second == "lan" && obj->dev_connection_type == "cloud") {
|
||||
wxString txt = _L("Disconnected from printer [%s] due to LAN mode disabled.Please reconnect the printer by logging in with your user account.");
|
||||
wxString msg = wxString::Format(txt,obj->dev_name);
|
||||
MessageDialog msg_wingow(nullptr, msg, wxEmptyString, wxICON_WARNING | wxOK);
|
||||
msg_wingow.ShowModal();
|
||||
m_print_connect_types[obj->dev_id] = obj->dev_connection_type;
|
||||
}
|
||||
|
||||
//cloud = > lan
|
||||
if (iter_connect_type->second == "cloud" && obj->dev_connection_type == "lan") {
|
||||
wxString txt = _L("Disconnected from printer [%s] due to LAN mode enabled.Please reconnect the printer by inputting Access Code which can be gotten from printer screen.");
|
||||
wxString msg = wxString::Format(txt, obj->dev_name);
|
||||
MessageDialog msg_wingow(nullptr, msg, wxEmptyString, wxICON_WARNING | wxOK);
|
||||
msg_wingow.ShowModal();
|
||||
m_print_connect_types[obj->dev_id] = obj->dev_connection_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_print_connect_types[obj->dev_id] = obj->dev_connection_type;
|
||||
}
|
||||
|
||||
update_error_message();
|
||||
}
|
||||
|
||||
|
|
|
@ -275,6 +275,7 @@ protected:
|
|||
boost::posix_time::ptime speed_dismiss_time;
|
||||
|
||||
std::map<wxString, wxImage> img_list; // key: url, value: wxBitmap png Image
|
||||
std::map<std::string, std::string> m_print_connect_types;
|
||||
std::vector<Button *> m_buttons;
|
||||
int last_status;
|
||||
void init_scaled_buttons();
|
||||
|
|
Loading…
Reference in a new issue