NEW: display plate index when printing a task

JIRA: STUDIO-2689

display on the thumbnail of the current task

Change-Id: I5f1f46c56e9d1e9120a66d491551908dfad099d6
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li 2023-11-09 11:26:49 +08:00 committed by Lane.Wei
parent 9588de0de2
commit 16cee32990
4 changed files with 49 additions and 36 deletions

View File

@ -2511,6 +2511,7 @@ void MachineObject::reset()
dev_connection_name = "";
subscribe_counter = 3;
job_id_ = "";
m_plate_index = -1;
// reset print_json
json empty_j;
@ -3179,6 +3180,7 @@ int MachineObject::parse_json(std::string payload)
if (idx_start > 0 && idx_end > idx_start) {
try {
plate_index = atoi(m_gcode_file.substr(idx_start, idx_end - idx_start).c_str());
this->m_plate_index = plate_index;
}
catch (...) {
;
@ -4724,7 +4726,6 @@ void MachineObject::update_slice_info(std::string project_id, std::string profil
plate_index = plate_idx;
}
else {
std::string subtask_json;
unsigned http_code = 0;
std::string http_body;
@ -4785,36 +4786,8 @@ void MachineObject::update_slice_info(std::string project_id, std::string profil
BOOST_LOG_TRIVIAL(error) << "task_info: get subtask id failed!";
}
}
//if (plate_index >= 0) {
// std::string slice_json;
// m_agent->get_slice_info(project_id, profile_id, plate_index, &slice_json);
// if (slice_json.empty()) return;
// //parse json
// try {
// json j = json::parse(slice_json);
// if (!j["prediction"].is_null())
// slice_info->prediction = j["prediction"].get<int>();
// if (!j["weight"].is_null())
// slice_info->weight = j["weight"].get<float>();
// if (!j["thumbnail"].is_null()) {
// //slice_info->thumbnail_url = j["thumbnail"]["url"].get<std::string>();
// BOOST_LOG_TRIVIAL(trace) << "slice_info: thumbnail url=" << slice_info->thumbnail_url;
// }
// if (!j["filaments"].is_null()) {
// for (auto filament : j["filaments"]) {
// FilamentInfo f;
// f.color = filament["color"].get<std::string>();
// f.type = filament["type"].get<std::string>();
// f.used_g = stof(filament["used_g"].get<std::string>());
// f.used_m = stof(filament["used_m"].get<std::string>());
// slice_info->filaments_info.push_back(f);
// }
// }
// } catch(...) {
// ;
// }
//}
this->m_plate_index = plate_index;
});
}
}

View File

@ -768,7 +768,7 @@ public:
bool is_makeworld_subtask();
int plate_index { -1 };
int m_plate_index { -1 };
std::string m_gcode_file;
int gcode_file_prepare_percent = 0;
BBLSubTask* subtask_;

View File

@ -147,6 +147,8 @@ PrintingTaskPanel::PrintingTaskPanel(wxWindow* parent, PrintingTaskType type)
m_type = type;
create_panel(this);
SetBackgroundColour(*wxWHITE);
m_bitmap_thumbnail->Bind(wxEVT_PAINT, &PrintingTaskPanel::paint, this);
}
PrintingTaskPanel::~PrintingTaskPanel()
@ -539,6 +541,18 @@ void PrintingTaskPanel::create_panel(wxWindow* parent)
parent->Fit();
}
void PrintingTaskPanel::paint(wxPaintEvent&)
{
wxPaintDC dc(m_bitmap_thumbnail);
dc.DrawBitmap(m_thumbnail_bmp_display, wxPoint(0, 0));
dc.SetTextForeground(*wxBLACK);
dc.SetFont(Label::Body_12);
if (m_plate_index >= 0) {
wxString plate_id_str = wxString::Format("%d", m_plate_index);
dc.DrawText(plate_id_str, wxPoint(4, 4));
}
}
void PrintingTaskPanel::set_has_reted_text(bool has_rated)
{
if (has_rated) {
@ -593,7 +607,8 @@ void PrintingTaskPanel::show_error_msg(wxString msg)
void PrintingTaskPanel::reset_printing_value()
{
m_bitmap_thumbnail->SetBitmap(m_thumbnail_placeholder.bmp());
this->set_thumbnail_img(m_thumbnail_placeholder.bmp());
this->set_plate_index(-1);
}
void PrintingTaskPanel::enable_pause_resume_button(bool enable, std::string type)
@ -727,6 +742,16 @@ void PrintingTaskPanel::show_profile_info(bool show, wxString profile /*= wxEmpt
}
}
void PrintingTaskPanel::set_thumbnail_img(const wxBitmap& bmp)
{
m_thumbnail_bmp_display = bmp;
}
void PrintingTaskPanel::set_plate_index(int plate_idx)
{
m_plate_index = plate_idx;
}
void PrintingTaskPanel::market_scoring_show()
{
m_score_staticline->Show();
@ -1844,14 +1869,20 @@ void StatusPanel::on_webrequest_state(wxWebRequestEvent &evt)
wxImage img(*evt.GetResponse().GetStream());
img_list.insert(std::make_pair(m_request_url, img));
wxImage resize_img = img.Scale(m_project_task_panel->get_bitmap_thumbnail()->GetSize().x, m_project_task_panel->get_bitmap_thumbnail()->GetSize().y, wxIMAGE_QUALITY_HIGH);
m_project_task_panel->get_bitmap_thumbnail()->SetBitmap(resize_img);
m_project_task_panel->set_thumbnail_img(resize_img);
if (obj) {
m_project_task_panel->set_plate_index(obj->m_plate_index);
} else {
m_project_task_panel->set_plate_index(-1);
}
task_thumbnail_state = ThumbnailState::TASK_THUMBNAIL;
break;
}
case wxWebRequest::State_Failed:
case wxWebRequest::State_Cancelled:
case wxWebRequest::State_Unauthorized: {
m_project_task_panel->get_bitmap_thumbnail()->SetBitmap(m_thumbnail_brokenimg.bmp());
m_project_task_panel->set_thumbnail_img(m_thumbnail_brokenimg.bmp());
m_project_task_panel->set_plate_index(-1);
task_thumbnail_state = ThumbnailState::BROKEN_IMG;
break;
}
@ -2928,7 +2959,12 @@ void StatusPanel::update_cloud_subtask(MachineObject *obj)
if (it != img_list.end()) {
img = it->second;
wxImage resize_img = img.Scale(m_project_task_panel->get_bitmap_thumbnail()->GetSize().x, m_project_task_panel->get_bitmap_thumbnail()->GetSize().y);
m_project_task_panel->get_bitmap_thumbnail()->SetBitmap(resize_img);
m_project_task_panel->set_thumbnail_img(resize_img);
if (this->obj) {
m_project_task_panel->set_plate_index(obj->m_plate_index);
} else {
m_project_task_panel->set_plate_index(-1);
}
task_thumbnail_state = ThumbnailState::TASK_THUMBNAIL;
BOOST_LOG_TRIVIAL(trace) << "web_request: use cache image";
} else {
@ -2963,7 +2999,6 @@ void StatusPanel::reset_printing_values()
m_project_task_panel->update_stage_value(wxEmptyString, 0);
m_project_task_panel->update_progress_percent(NA_STR, wxEmptyString);
m_project_task_panel->market_scoring_hide();
m_project_task_panel->get_request_failed_panel()->Hide();
update_basic_print_data(false);

View File

@ -160,6 +160,7 @@ public:
private:
MachineObject* m_obj;
ScalableBitmap m_thumbnail_placeholder;
wxBitmap m_thumbnail_bmp_display;
ScalableBitmap m_bitmap_use_time;
ScalableBitmap m_bitmap_use_weight;
@ -181,6 +182,7 @@ private:
wxStaticText * m_has_rated_prompt;
wxStaticText * m_request_failed_info;
wxStaticBitmap* m_bitmap_thumbnail;
int m_plate_index { -1 };
wxStaticBitmap* m_bitmap_static_use_time;
wxStaticBitmap* m_bitmap_static_use_weight;
ScalableButton* m_button_pause_resume;
@ -219,6 +221,8 @@ public:
void update_layers_num(bool show, wxString num = wxEmptyString);
void show_priting_use_info(bool show, wxString time = wxEmptyString, wxString weight = wxEmptyString);
void show_profile_info(bool show, wxString profile = wxEmptyString);
void set_thumbnail_img(const wxBitmap& bmp);
void set_plate_index(int plate_idx = -1);
void market_scoring_show();
void market_scoring_hide();
@ -236,6 +240,7 @@ public:
bool get_star_count_dirty() { return m_star_count_dirty; }
void set_star_count_dirty(bool dirty) { m_star_count_dirty = dirty; }
void set_has_reted_text(bool has_rated);
void paint(wxPaintEvent&);
};