NEW:new fialment load/unload process

jira:[none]

Change-Id: Ie0076d5c7ec619414121c1f6d37876aaa4e044c1
(cherry picked from commit 5d9a7eaadcd5ab6dc2f18e65000ead81e7e8adb6)
This commit is contained in:
tao wang
2024-12-04 09:38:34 +08:00
committed by Noisyfox
parent 27780819e1
commit 21b67d993f
12 changed files with 765 additions and 171 deletions

View File

@@ -106,8 +106,8 @@ enum FilamentStep {
STEP_CUT_FILAMENT,
STEP_PULL_CURR_FILAMENT,
STEP_PUSH_NEW_FILAMENT,
STEP_GRAB_NEW_FILAMENT,
STEP_PURGE_OLD_FILAMENT,
STEP_FEED_FILAMENT,
STEP_CONFIRM_EXTRUDED,
STEP_CHECK_POSITION,
STEP_COUNT,

View File

@@ -0,0 +1,223 @@
#include "FilamentLoad.hpp"
#include "Label.hpp"
#include "../BitmapCache.hpp"
#include "../I18N.hpp"
#include "../GUI_App.hpp"
#include <wx/simplebook.h>
#include <wx/dcgraph.h>
#include <boost/log/trivial.hpp>
#include "CalibUtils.hpp"
namespace Slic3r {
namespace GUI {
FilamentLoad::FilamentLoad(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
: wxSimplebook(parent, wxID_ANY, pos, size)
{
SetBackgroundColour(*wxWHITE);
m_filament_load_steps = new FilamentStepIndicator(this, wxID_ANY);
m_filament_unload_steps = new ::FilamentStepIndicator(this, wxID_ANY);
m_filament_vt_load_steps = new ::FilamentStepIndicator(this, wxID_ANY);
this->AddPage(m_filament_load_steps, wxEmptyString, false);
this->AddPage(m_filament_unload_steps, wxEmptyString, false);
this->AddPage(m_filament_vt_load_steps, wxEmptyString, false);
//UpdateStepCtrl(false);
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_IDLE] = _L("Idling...");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE] = _L("Heat the nozzle");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CUT_FILAMENT] = _L("Cut filament");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PULL_CURR_FILAMENT] = _L("Pull back current filament");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PUSH_NEW_FILAMENT] = _L("Push new filament into extruder");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_GRAB_NEW_FILAMENT] = _L("Grab new filament");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PURGE_OLD_FILAMENT] = _L("Purge old filament");
//FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_FEED_FILAMENT] = _L("Feed Filament");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CONFIRM_EXTRUDED] = _L("Confirm extruded");
FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CHECK_POSITION] = _L("Check filament location");
}
void FilamentLoad::SetFilamentStep(FilamentStep item_idx, FilamentStepType f_type)
{
if (item_idx == FilamentStep::STEP_IDLE) {
m_filament_load_steps->Idle();
m_filament_unload_steps->Idle();
m_filament_vt_load_steps->Idle();
this->Hide();
return;
}
this->Show();
wxString step_str = wxEmptyString;
if (item_idx < FilamentStep::STEP_COUNT) {
step_str = FILAMENT_CHANGE_STEP_STRING[item_idx];
}
auto step_control = m_filament_load_steps;
if (f_type == FilamentStepType::STEP_TYPE_LOAD) {
step_control = m_filament_load_steps;
if (item_idx > 0 && item_idx < FilamentStep::STEP_COUNT) {
if (this->GetSelection() != 0) {
this->SetSelection(0);
}
m_filament_load_steps->SelectItem(m_filament_load_steps->GetItemUseText(step_str));
}
else {
m_filament_load_steps->Idle();
this->Hide();
this->Layout();
}
}
else if (f_type == FilamentStepType::STEP_TYPE_UNLOAD) {
step_control = m_filament_unload_steps;
if (item_idx > 0 && item_idx < FilamentStep::STEP_COUNT) {
if (GetSelection() != 1) {
this->SetSelection(1);
this->Layout();
}
m_filament_unload_steps->SelectItem(m_filament_unload_steps->GetItemUseText(step_str));
}
else {
m_filament_unload_steps->Idle();
this->Hide();
this->Layout();
}
}
else if (f_type == FilamentStepType::STEP_TYPE_VT_LOAD) {
step_control = m_filament_vt_load_steps;
this->SetSelection(2);
this->Layout();
if (item_idx > 0 && item_idx < FilamentStep::STEP_COUNT) {
if (item_idx == STEP_CONFIRM_EXTRUDED) {
m_filament_vt_load_steps->SelectItem(2);
}
else {
m_filament_vt_load_steps->SelectItem(m_filament_vt_load_steps->GetItemUseText(step_str));
}
}
else {
m_filament_vt_load_steps->Idle();
this->Hide();
this->Layout();
}
}
else {
step_control = m_filament_load_steps;
if (item_idx > 0 && item_idx < FilamentStep::STEP_COUNT) {
SetSelection(0);
m_filament_load_steps->SelectItem(m_filament_load_steps->GetItemUseText(step_str));
}
else {
m_filament_load_steps->Idle();
this->Hide();
this->Layout();
}
}
wxString slot_info = L"Ams-";
slot_info = slot_info + std::to_string(m_ams_id);
slot_info = slot_info + L'-';
slot_info = slot_info + std::to_string(m_slot_id);
slot_info = slot_info + L" Slot";
step_control->SetSlotInformation(slot_info);
}
void FilamentLoad::UpdateStepCtrl(bool is_extrusion_exist) {
m_filament_load_steps->DeleteAllItems();
m_filament_unload_steps->DeleteAllItems();
m_filament_vt_load_steps->DeleteAllItems();
is_extrusion = true; //Forgot what it means, need to update dynamically
if (m_ams_model == AMSModel::GENERIC_AMS || m_ext_model == AMSModel::GENERIC_AMS) {
if (is_extrusion) {
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CUT_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PULL_CURR_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PUSH_NEW_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PURGE_OLD_FILAMENT]);
}
else {
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PUSH_NEW_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PURGE_OLD_FILAMENT]);
}
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PUSH_NEW_FILAMENT]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_GRAB_NEW_FILAMENT]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PURGE_OLD_FILAMENT]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CUT_FILAMENT]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PULL_CURR_FILAMENT]);
}
if (m_ams_model == AMSModel::AMS_LITE || m_ext_model == AMSModel::AMS_LITE) {
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CHECK_POSITION]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CUT_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PULL_CURR_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PUSH_NEW_FILAMENT]);
m_filament_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PURGE_OLD_FILAMENT]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CHECK_POSITION]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CUT_FILAMENT]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PULL_CURR_FILAMENT]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PUSH_NEW_FILAMENT]);
m_filament_vt_load_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PURGE_OLD_FILAMENT]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_HEAT_NOZZLE]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CHECK_POSITION]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_CUT_FILAMENT]);
m_filament_unload_steps->AppendItem(FILAMENT_CHANGE_STEP_STRING[FilamentStep::STEP_PULL_CURR_FILAMENT]);
}
}
void FilamentLoad::show_nofilament_mode(bool show)
{
m_filament_load_steps->DeleteAllItems();
m_filament_unload_steps->DeleteAllItems();
m_filament_vt_load_steps->DeleteAllItems();
m_filament_load_steps->Idle();
m_filament_unload_steps->Idle();
m_filament_vt_load_steps->Idle();
this->Layout();
Refresh();
/*if (!show)
{
m_filament_load_steps->Idle();
m_filament_unload_steps->Idle();
m_filament_vt_load_steps->Idle();
}
else {
this->Show();
this->Layout();
}*/
}
void FilamentLoad::set_min_size(const wxSize& minSize) {
this->SetMinSize(minSize);
m_filament_load_steps->SetMinSize(minSize);
m_filament_unload_steps->SetMinSize(minSize);
m_filament_vt_load_steps->SetMinSize(minSize);
}
void FilamentLoad::set_max_size(const wxSize& minSize) {
this->SetMaxSize(minSize);
m_filament_load_steps->SetMaxSize(minSize);
m_filament_unload_steps->SetMaxSize(minSize);
m_filament_vt_load_steps->SetMaxSize(minSize);
}
void FilamentLoad::set_background_color(const wxColour& colour) {
m_filament_load_steps->SetBackgroundColour(colour);
m_filament_unload_steps->SetBackgroundColour(colour);
m_filament_vt_load_steps->SetBackgroundColour(colour);
}
}} // namespace Slic3r::GUI

View File

@@ -0,0 +1,60 @@
#ifndef slic3r_GUI_FILAMENTLOAD_hpp_
#define slic3r_GUI_FILAMENTLOAD_hpp_
#include "../wxExtensions.hpp"
#include "StaticBox.hpp"
#include "StepCtrl.hpp"
#include "AMSControl.hpp"
#include "../DeviceManager.hpp"
#include "slic3r/GUI/Event.hpp"
#include "slic3r/GUI/AmsMappingPopup.hpp"
#include <wx/simplebook.h>
#include <wx/hyperlink.h>
#include <wx/animate.h>
#include <wx/dynarray.h>
namespace Slic3r { namespace GUI {
class FilamentLoad : public wxSimplebook
{
public:
FilamentLoad(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
protected:
::FilamentStepIndicator* m_filament_load_steps = { nullptr };
::FilamentStepIndicator* m_filament_unload_steps = { nullptr };
::FilamentStepIndicator* m_filament_vt_load_steps = { nullptr };
int m_ams_id = { 1 };
int m_slot_id = { 1 };
bool is_extrusion = false;
public:
std::map<FilamentStep, wxString> FILAMENT_CHANGE_STEP_STRING;
AMSModel m_ams_model{ AMSModel::GENERIC_AMS };
AMSModel m_ext_model{ AMSModel::AMS_LITE };
AMSModel m_is_none_ams_mode{ AMSModel::AMS_LITE };
void SetAmsModel(AMSModel mode, AMSModel ext_mode) { m_ams_model = mode; m_ext_model = ext_mode; };
void SetFilamentStep(FilamentStep item_idx, FilamentStepType f_type);
void ShowFilamentTip(bool hasams = true);
void UpdateStepCtrl(bool is_extrusion_exist);
void show_nofilament_mode(bool show);
void updateID(int ams_id, int slot_id) { m_ams_id = ams_id; m_slot_id = slot_id; };
void SetExt(bool ext) { is_extrusion = ext; };
void set_min_size(const wxSize& minSize);
void set_max_size(const wxSize& maxSize);
void set_background_color(const wxColour& colour);
};
}}
#endif // !slic3r_GUI_filamentload_hpp_

View File

@@ -351,3 +351,134 @@ void StepIndicator::doRender(wxDC &dc)
circleY += itemWidth;
}
}
/* FilamentStepIndicator */
FilamentStepIndicator::FilamentStepIndicator(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
: StepCtrlBase(parent, id, pos, size, style)
, bmp_ok(this, "step_ok", 12)
{
static Slic3r::GUI::BitmapCache cache;
bmp_extruder = *cache.load_png("filament_load_extruder", FromDIP(300), FromDIP(200), false, false);
SetFont(Label::Body_12);
font_tip = Label::Body_12;
clr_bar = 0xE1E1E1;
clr_step = StateColor(
std::make_pair(0xACACAC, (int)StateColor::Disabled),
std::make_pair(0x00AE42, 0));
clr_text = StateColor(
std::make_pair(0xACACAC, (int)StateColor::Disabled),
std::make_pair(0x323A3D, (int)StateColor::Checked),
std::make_pair(0x6B6B6B, 0));
clr_tip = *wxWHITE;
StaticBox::border_width = 0;
radius = 9;
bar_width = 0;
}
void FilamentStepIndicator::Rescale()
{
bmp_ok.msw_rescale();
radius = bmp_ok.GetBmpHeight() / 2;
bar_width = bmp_ok.GetBmpHeight() / 20;
if (bar_width < 2) bar_width = 2;
}
void FilamentStepIndicator::SelectNext() { SelectItem(step + 1); }
void FilamentStepIndicator::doRender(wxDC& dc)
{
if (steps.empty()) return;
StaticBox::doRender(dc);
wxSize size = GetSize();
int states = state_handler.states();
if (!IsEnabled()) {
states = clr_step.Disabled;
}
dc.SetFont(::Label::Head_16);
dc.SetTextForeground(wxColour(0, 174, 66));
int circleX = 20;
int circleY = 20;
wxSize sz = dc.GetTextExtent(L"Loading");
dc.DrawText(L"Loading", circleX, circleY);
dc.SetFont(::Label::Body_13);
dc.DrawText(m_slot_information, circleX + sz.GetWidth() + FromDIP(5), circleY + FromDIP(3));
dc.DrawBitmap(bmp_extruder, FromDIP(250), circleY);
circleY += sz.y;
int textWidth = size.x - radius * 5;
dc.SetFont(GetFont());
wxString firstLine;
if (step == 0) dc.SetFont(GetFont().Bold());
wxSize firstLineSize = Label::split_lines(dc, textWidth, steps.front(), firstLine);
wxString lastLine;
if (step == steps.size() - 1) dc.SetFont(GetFont().Bold());
wxSize lastLineSize = Label::split_lines(dc, textWidth, steps.back(), lastLine);
int firstPadding = std::max(0, firstLineSize.y / 2 - radius);
int lastPadding = std::max(0, lastLineSize.y / 2 - radius);
int itemWidth = radius * 3;
// Draw thin bar stick
dc.SetPen(wxPen(clr_bar.colorForStates(states)));
dc.SetBrush(wxBrush(clr_bar.colorForStates(states)));
//dc.DrawRectangle(rcBar);
circleX += radius;
circleY += radius * 3 + firstPadding;
dc.SetPen(wxPen(clr_step.colorForStates(states)));
dc.SetBrush(wxBrush(clr_step.colorForStates(states)));
for (int i = 0; i < steps.size(); ++i) {
bool disabled = step > i;
bool checked = step == i;
// Draw circle point & texts in it
dc.DrawEllipse(circleX - radius, circleY - radius, radius * 2, radius * 2);
// Draw content ( icon or text ) in circle
if (disabled) {
wxSize sz = bmp_ok.GetBmpSize();
dc.DrawBitmap(bmp_ok.bmp(), circleX - sz.x / 2, circleY - sz.y / 2);
}
else {
dc.SetFont(font_tip);
dc.SetTextForeground(clr_tip.colorForStates(states));
auto tip = tips[i];
if (tip.IsEmpty()) tip.append(1, wchar_t(L'0' + i + 1));
wxSize sz = dc.GetTextExtent(tip);
dc.DrawText(tip, circleX - sz.x / 2, circleY - sz.y / 2 + 1);
}
// Draw step text
dc.SetTextForeground(clr_text.colorForStates(states
| (disabled ? StateColor::Disabled : checked ? StateColor::Checked : 0)));
dc.SetFont(checked ? GetFont().Bold() : GetFont());
wxString text;
wxSize textSize;
if (i == 0) {
text = firstLine;
textSize = firstLineSize;
}
else if (i == steps.size() - 1) {
text = lastLine;
textSize = lastLineSize;
}
else {
textSize = Label::split_lines(dc, textWidth, steps[i], text);
}
dc.DrawText(text, circleX + radius * 1.5, circleY - (textSize.y / 2));
circleY += itemWidth;
}
}
void FilamentStepIndicator::SetSlotInformation(wxString slot) {
this->m_slot_information = slot;
}

View File

@@ -103,4 +103,28 @@ private:
void doRender(wxDC &dc) override;
};
class FilamentStepIndicator : public StepCtrlBase
{
ScalableBitmap bmp_ok;
wxBitmap bmp_extruder;
wxString m_slot_information = "";
public:
FilamentStepIndicator(wxWindow* parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0);
virtual void Rescale();
void SelectNext();
void SetSlotInformation(wxString slot);
private:
void doRender(wxDC& dc) override;
};
#endif // !slic3r_GUI_StepCtrlBase_hpp_