Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: compatible with U0 firmware #4

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 81 additions & 21 deletions src/slic3r/GUI/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,50 @@ void MachineObject::_parse_ams_status(int ams_status)
BOOST_LOG_TRIVIAL(trace) << "ams_debug: main = " << ams_status_main_int << ", sub = " << ams_status_sub;
}

bool MachineObject::is_need_upgrade_for_ams()
bool MachineObject::is_support_ams_mapping()
{
return false;
AppConfig* config = Slic3r::GUI::wxGetApp().app_config;
if (config) {
if (config->get("check_ams_version") == "0")
return false;
}
bool need_upgrade = false;
if (has_ams()) {
// compare ota version and ams version
auto ota_ver_it = module_vers.find("ota");
if (ota_ver_it != module_vers.end()) {
if (!MachineObject::is_support_ams_mapping_version("ota", ota_ver_it->second.sw_ver)) {
need_upgrade = true;
}
}
for (int i = 0; i < 4; i++) {
std::string ams_id = (boost::format("ams/%1%") % i).str();
auto ams_ver_it = module_vers.find(ams_id);
if (ams_ver_it != module_vers.end()) {
if (!MachineObject::is_support_ams_mapping_version("ams", ams_ver_it->second.sw_ver)) {
need_upgrade = true;
}
}
}
}
return !need_upgrade;
}

bool MachineObject::is_support_ams_mapping_version(std::string module, std::string version)
{
bool result = true;
if (module == "ota") {
if (version.compare("00.01.04.03") < 0)
return false;
}
else if (module == "ams") {
// omit ams version is empty
if (version.empty())
return true;
if (version.compare("00.00.04.10") < 0)
return false;
}
return result;
}

bool MachineObject::is_only_support_cloud_print()
Expand Down Expand Up @@ -571,6 +612,44 @@ int MachineObject::ams_filament_mapping(std::vector<FilamentInfo> filaments, std
}
}

// tray info list
std::vector<FilamentInfo> tray_info_list;
for (auto it = amsList.begin(); it != amsList.end(); it++) {
for (int i = 0; i < 4; i++) {
FilamentInfo info;
auto tray_it = it->second->trayList.find(std::to_string(i));
if (tray_it != it->second->trayList.end()) {
info.id = atoi(tray_it->first.c_str()) + atoi(it->first.c_str()) * 4;
info.tray_id = atoi(tray_it->first.c_str()) + atoi(it->first.c_str()) * 4;
info.color = tray_it->second->color;
info.type = tray_it->second->type;
}
else {
info.id = -1;
info.tray_id = -1;
}
tray_info_list.push_back(info);
}
}

// is_support_ams_mapping
if (!is_support_ams_mapping()) {
for (int i = 0; i < filaments.size(); i++) {
FilamentInfo info;
if (i < tray_info_list.size()) {
info.id = filaments[i].id;
info.tray_id = filaments[i].id;
info.color = tray_info_list[i].color;
info.type = tray_info_list[i].type;
} else {
info.id = filaments[i].id;
info.tray_id = -1;
}
result.push_back(info);
}
return 0;
}

// calc distance map
struct DisValue {
int tray_id;
Expand Down Expand Up @@ -648,25 +727,6 @@ int MachineObject::ams_filament_mapping(std::vector<FilamentInfo> filaments, std
}

try {
//ordering mapping
std::vector<FilamentInfo> tray_info_list;
for (auto it = amsList.begin(); it != amsList.end(); it++) {
for (int i = 0; i < 4; i++) {
FilamentInfo info;
auto tray_it = it->second->trayList.find(std::to_string(i));
if (tray_it != it->second->trayList.end()) {
info.id = atoi(tray_it->first.c_str()) + atoi(it->first.c_str()) * 4;
info.tray_id = atoi(tray_it->first.c_str()) + atoi(it->first.c_str()) * 4;
info.color = tray_it->second->color;
info.type = tray_it->second->type;
} else {
info.id = -1;
info.tray_id = -1;
}
tray_info_list.push_back(info);
}
}

// try to use ordering ams mapping
bool order_mapping_result = true;
for (int i = 0; i < filaments.size(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/DeviceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ class MachineObject
// parse amsStatusMain and ams_status_sub
void _parse_ams_status(int ams_status);
bool has_ams() { return ams_exist_bits != 0; }
bool is_need_upgrade_for_ams();
bool is_support_ams_mapping();
bool is_only_support_cloud_print();

static bool is_support_ams_mapping_version(std::string module, std::string version);

int ams_filament_mapping(std::vector<FilamentInfo> filaments, std::vector<FilamentInfo> &result, std::vector<int> exclude_id = std::vector<int>());
bool is_valid_mapping_result(std::vector<FilamentInfo>& result);
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ Sidebar::Sidebar(Plater *parent)

ScalableButton* add_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "add_filament");
add_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e){
// BBS: limit filament choices to 16
if (p->combos_filament.size() >= 16)
// BBS: limit filament choices to 4
if (p->combos_filament.size() >= 4)
return;

int filament_count = p->combos_filament.size() + 1;
Expand Down
56 changes: 34 additions & 22 deletions src/slic3r/GUI/SelectMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,9 @@ void SelectMachineDialog::show_status(PrintDialogStatus status)
update_print_status_msg(msg_text, true);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusAmsMappingByOrder) {
Enable_Send_Button(true);
Enable_Refresh_Button(true);
}
}

Expand Down Expand Up @@ -1469,7 +1472,10 @@ void SelectMachineDialog::on_ok(wxCommandEvent &event)
m_print_job->m_dev_ip = obj_->dev_ip;
m_print_job->m_access_code = obj_->access_code;
m_print_job->connection_type = obj_->connection_type();
m_print_job->task_ams_mapping = ams_mapping_array;
if (obj_->is_support_ams_mapping())
m_print_job->task_ams_mapping = ams_mapping_array;
else
m_print_job->task_ams_mapping = "";

if (obj_->has_sdcard()) {
m_print_job->has_sdcard = obj_->has_sdcard();
Expand Down Expand Up @@ -1758,6 +1764,12 @@ void SelectMachineDialog::on_timer(wxTimerEvent &event)
return;
}

if (!obj_->is_support_ams_mapping()) {
do_ams_mapping(obj_);
show_status(PrintDialogStatus::PrintStatusAmsMappingByOrder);
return;
}

// do ams mapping if no ams result
if (m_ams_mapping_result.empty()) {
do_ams_mapping(obj_);
Expand Down Expand Up @@ -1968,27 +1980,27 @@ void SelectMachineDialog::set_default()

// item->Layout();

item->Bind(wxEVT_LEFT_UP, [this, item, materials, extruder](wxMouseEvent &e) {
auto mouse_pos = ClientToScreen(e.GetPosition());
wxPoint rect = item->ClientToScreen(wxPoint(0, 0));

auto mapping = new AmsMapingPopup(this);
wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
pos.y += item->GetRect().height;
mapping->Position(pos, wxSize(0, 0));

// update ams data
DeviceManager *dev_manager = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev_manager) return;
MachineObject *obj_ = dev_manager->get_selected_machine();

if (obj_ && obj_->has_ams()) {
mapping->update_ams_data(obj_->amsList);
mapping->set_tag_texture(materials[extruder]);
mapping->Popup();
}
e.Skip();
});
//item->Bind(wxEVT_LEFT_UP, [this, item, materials, extruder](wxMouseEvent &e) {
// auto mouse_pos = ClientToScreen(e.GetPosition());
// wxPoint rect = item->ClientToScreen(wxPoint(0, 0));

// auto mapping = new AmsMapingPopup(this);
// wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
// pos.y += item->GetRect().height;
// mapping->Position(pos, wxSize(0, 0));

// // update ams data
// DeviceManager *dev_manager = Slic3r::GUI::wxGetApp().getDeviceManager();
// if (!dev_manager) return;
// MachineObject *obj_ = dev_manager->get_selected_machine();

// if (obj_ && obj_->has_ams()) {
// mapping->update_ams_data(obj_->amsList);
// mapping->set_tag_texture(materials[extruder]);
// mapping->Popup();
// }
// e.Skip();
//});

item->Bind(wxEVT_LEFT_DOWN, [this, item, extruder](wxMouseEvent &e) {
Freeze();
Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/SelectMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ enum PrintDialogStatus {
PrintStatusAmsMappingSuccess,
PrintStatusAmsMappingInvalid,
PrintStatusAmsMappingValid,
PrintStatusAmsMappingByOrder,
PrintStatusRefreshingMachineList,
PrintStatusSending,
PrintStatusSendingCanceled,
Expand Down Expand Up @@ -339,7 +340,7 @@ class SelectMachineDialog : public DPIDialog
void prepare_mode();
void sending_mode();
void finish_mode();

bool do_ams_mapping(MachineObject* obj_);
bool get_ams_mapping_result(std::string &mapping_array_str);
void prepare(int print_plate_idx);
Expand Down