mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 03:07:55 -06:00
Mdel preview renders the actual colors of the filaments based on the filaments currently loaded in the AMS
Ported from BambuStudio
This commit is contained in:
parent
4590c765c6
commit
27f140fb18
20 changed files with 1441 additions and 400 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <miniz.h>
|
||||
#include <algorithm>
|
||||
#include "Plater.hpp"
|
||||
#include "Notebook.hpp"
|
||||
#include "BitmapCache.hpp"
|
||||
#include "BindDialog.hpp"
|
||||
|
||||
|
@ -1825,6 +1826,10 @@ void SelectMachineDialog::sync_ams_mapping_result(std::vector<FilamentInfo> &res
|
|||
iter++;
|
||||
}
|
||||
}
|
||||
auto tab_index = (MainFrame::TabPosition) dynamic_cast<Notebook *>(wxGetApp().tab_panel())->GetSelection();
|
||||
if (tab_index == MainFrame::TabPosition::tp3DEditor || tab_index == MainFrame::TabPosition::tpPreview) {
|
||||
updata_thumbnail_data_after_connected_printer();
|
||||
}
|
||||
}
|
||||
|
||||
void print_ams_mapping_result(std::vector<FilamentInfo>& result)
|
||||
|
@ -1843,7 +1848,7 @@ void print_ams_mapping_result(std::vector<FilamentInfo>& result)
|
|||
bool SelectMachineDialog::do_ams_mapping(MachineObject *obj_)
|
||||
{
|
||||
if (!obj_) return false;
|
||||
|
||||
obj_->get_ams_colors(m_cur_colors_in_thumbnail);
|
||||
// try color and type mapping
|
||||
int result = obj_->ams_filament_mapping(m_filaments, m_ams_mapping_result);
|
||||
if (result == 0) {
|
||||
|
@ -2574,6 +2579,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
|
|||
if (!obj_->nozzle_type.empty() && (m_print_type == PrintFromType::FROM_NORMAL)) {
|
||||
if (!is_same_nozzle_diameters(tag_nozzle_type, nozzle_diameter)) {
|
||||
has_slice_warnings = true;
|
||||
is_printing_block = true;
|
||||
|
||||
wxString nozzle_in_preset = wxString::Format(_L("nozzle in preset: %s %s"),nozzle_diameter, "");
|
||||
wxString nozzle_in_printer = wxString::Format(_L("nozzle memorized: %.2f %s"), obj_->nozzle_diameter, "");
|
||||
|
@ -2945,6 +2951,14 @@ void SelectMachineDialog::on_set_finish_mapping(wxCommandEvent &evt)
|
|||
BOOST_LOG_TRIVIAL(info) << "The ams mapping selection result: data is " << selection_data;
|
||||
|
||||
if (selection_data_arr.size() == 6) {
|
||||
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
|
||||
int old_filament_id = (int) wxAtoi(selection_data_arr[5]);
|
||||
if (m_print_type == PrintFromType::FROM_NORMAL) {//todo:support sd card
|
||||
change_default_normal(old_filament_id, ams_colour);
|
||||
final_deal_edge_pixels_data(m_preview_thumbnail_data);
|
||||
set_default_normal(m_preview_thumbnail_data); // do't reset ams
|
||||
}
|
||||
|
||||
int ctype = 0;
|
||||
std::vector<wxColour> material_cols;
|
||||
std::vector<std::string> tray_cols;
|
||||
|
@ -3350,8 +3364,6 @@ void SelectMachineDialog::on_selection_changed(wxCommandEvent &event)
|
|||
|
||||
show_status(PrintDialogStatus::PrintStatusInit);
|
||||
|
||||
reset_ams_material();
|
||||
|
||||
update_show_status();
|
||||
}
|
||||
|
||||
|
@ -3926,20 +3938,399 @@ void SelectMachineDialog::set_default()
|
|||
m_checkbox_list["use_ams"]->SetValue(true);
|
||||
|
||||
if (m_print_type == PrintFromType::FROM_NORMAL) {
|
||||
set_default_normal();
|
||||
reset_and_sync_ams_list();
|
||||
set_default_normal(m_plater->get_partplate_list().get_curr_plate()->thumbnail_data);
|
||||
}
|
||||
else if (m_print_type == PrintFromType::FROM_SDCARD_VIEW) {
|
||||
//todo:unify_deal_thumbnail_data(input_data, no_light_data);this include m_print_type = PrintFromType::FROM_SDCARD_VIEW
|
||||
//and notice update_page_turn_state(true)
|
||||
set_default_from_sdcard();
|
||||
}
|
||||
|
||||
|
||||
Layout();
|
||||
Fit();
|
||||
}
|
||||
|
||||
void SelectMachineDialog::set_default_normal()
|
||||
void SelectMachineDialog::reset_and_sync_ams_list()
|
||||
{
|
||||
// for black list
|
||||
std::vector<std::string> materials;
|
||||
std::vector<std::string> brands;
|
||||
std::vector<std::string> display_materials;
|
||||
std::vector<std::string> m_filaments_id;
|
||||
auto preset_bundle = wxGetApp().preset_bundle;
|
||||
|
||||
for (auto filament_name : preset_bundle->filament_presets) {
|
||||
for (int f_index = 0; f_index < preset_bundle->filaments.size(); f_index++) {
|
||||
PresetCollection *filament_presets = &wxGetApp().preset_bundle->filaments;
|
||||
Preset * preset = &filament_presets->preset(f_index);
|
||||
|
||||
if (preset && filament_name.compare(preset->name) == 0) {
|
||||
std::string display_filament_type;
|
||||
std::string filament_type = preset->config.get_filament_type(display_filament_type);
|
||||
std::string m_filament_id = preset->filament_id;
|
||||
display_materials.push_back(display_filament_type);
|
||||
materials.push_back(filament_type);
|
||||
m_filaments_id.push_back(m_filament_id);
|
||||
|
||||
std::string m_vendor_name = "";
|
||||
auto vendor = dynamic_cast<ConfigOptionStrings *>(preset->config.option("filament_vendor"));
|
||||
if (vendor && (vendor->values.size() > 0)) {
|
||||
std::string vendor_name = vendor->values[0];
|
||||
m_vendor_name = vendor_name;
|
||||
}
|
||||
brands.push_back(m_vendor_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto extruders = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders();
|
||||
BitmapCache bmcache;
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material *item = iter->second;
|
||||
item->item->Destroy();
|
||||
delete item;
|
||||
iter++;
|
||||
}
|
||||
|
||||
m_sizer_material->Clear();
|
||||
m_materialList.clear();
|
||||
m_filaments.clear();
|
||||
|
||||
for (auto i = 0; i < extruders.size(); i++) {
|
||||
auto extruder = extruders[i] - 1;
|
||||
auto colour = wxGetApp().preset_bundle->project_config.opt_string("filament_colour", (unsigned int) extruder);
|
||||
unsigned char rgb[4];
|
||||
bmcache.parse_color4(colour, rgb);
|
||||
|
||||
auto colour_rgb = wxColour((int) rgb[0], (int) rgb[1], (int) rgb[2], (int) rgb[3]);
|
||||
if (extruder >= materials.size() || extruder < 0 || extruder >= display_materials.size()) continue;
|
||||
|
||||
MaterialItem *item = new MaterialItem(m_scrollable_region, colour_rgb, _L(display_materials[extruder]));
|
||||
m_sizer_material->Add(item, 0, wxALL, FromDIP(4));
|
||||
|
||||
item->Bind(wxEVT_LEFT_UP, [this, item, materials, extruder](wxMouseEvent &e) {});
|
||||
item->Bind(wxEVT_LEFT_DOWN, [this, item, materials, extruder](wxMouseEvent &e) {
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material * item = iter->second;
|
||||
MaterialItem *m = item->item;
|
||||
m->on_normal();
|
||||
iter++;
|
||||
}
|
||||
|
||||
m_current_filament_id = extruder;
|
||||
item->on_selected();
|
||||
|
||||
auto mouse_pos = ClientToScreen(e.GetPosition());
|
||||
wxPoint rect = item->ClientToScreen(wxPoint(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_->is_support_ams_mapping()) {
|
||||
if (m_mapping_popup.IsShown()) return;
|
||||
wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
|
||||
pos.y += item->GetRect().height;
|
||||
m_mapping_popup.Move(pos);
|
||||
|
||||
if (obj_ && obj_->has_ams() && m_checkbox_list["use_ams"]->GetValue() && obj_->dev_id == m_printer_last_select) {
|
||||
m_mapping_popup.set_parent_item(item);
|
||||
m_mapping_popup.set_current_filament_id(extruder);
|
||||
m_mapping_popup.set_tag_texture(materials[extruder]);
|
||||
m_mapping_popup.update_ams_data(obj_->amsList);
|
||||
m_mapping_popup.Popup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Material *material_item = new Material();
|
||||
material_item->id = extruder;
|
||||
material_item->item = item;
|
||||
m_materialList[i] = material_item;
|
||||
|
||||
// build for ams mapping
|
||||
if (extruder < materials.size() && extruder >= 0) {
|
||||
FilamentInfo info;
|
||||
info.id = extruder;
|
||||
info.type = materials[extruder];
|
||||
info.brand = brands[extruder];
|
||||
info.filament_id = m_filaments_id[extruder];
|
||||
info.color = wxString::Format("#%02X%02X%02X%02X", colour_rgb.Red(), colour_rgb.Green(), colour_rgb.Blue(), colour_rgb.Alpha()).ToStdString();
|
||||
m_filaments.push_back(info);
|
||||
}
|
||||
}
|
||||
|
||||
if (extruders.size() <= 4) {
|
||||
m_sizer_material->SetCols(extruders.size());
|
||||
} else {
|
||||
m_sizer_material->SetCols(4);
|
||||
}
|
||||
|
||||
// reset_ams_material();//show "-"
|
||||
}
|
||||
|
||||
void SelectMachineDialog::clone_thumbnail_data() {
|
||||
//record preview_colors
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
if (m_preview_colors_in_thumbnail.size() != m_materialList.size()) {
|
||||
m_preview_colors_in_thumbnail.resize(m_materialList.size());
|
||||
}
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material * item = iter->second;
|
||||
MaterialItem *m = item->item;
|
||||
m_preview_colors_in_thumbnail[id] = m->m_material_coloul;
|
||||
if (item->id < m_cur_colors_in_thumbnail.size()) {
|
||||
m_cur_colors_in_thumbnail[item->id] = m->m_ams_coloul;
|
||||
}
|
||||
else {//exist empty or unrecognized type ams in machine
|
||||
m_cur_colors_in_thumbnail.resize(item->id + 1);
|
||||
m_cur_colors_in_thumbnail[item->id] = m->m_ams_coloul;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
//copy data
|
||||
auto &data = m_cur_input_thumbnail_data;
|
||||
m_preview_thumbnail_data.reset();
|
||||
m_preview_thumbnail_data.set(data.width, data.height);
|
||||
if (data.width > 0 && data.height > 0) {
|
||||
for (unsigned int r = 0; r < data.height; ++r) {
|
||||
unsigned int rr = (data.height - 1 - r) * data.width;
|
||||
for (unsigned int c = 0; c < data.width; ++c) {
|
||||
unsigned char *origin_px = (unsigned char *) data.pixels.data() + 4 * (rr + c);
|
||||
unsigned char *new_px = (unsigned char *) m_preview_thumbnail_data.pixels.data() + 4 * (rr + c);
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
new_px[i] = origin_px[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//record_edge_pixels_data
|
||||
record_edge_pixels_data();
|
||||
}
|
||||
|
||||
void SelectMachineDialog::record_edge_pixels_data()
|
||||
{
|
||||
auto is_not_in_preview_colors = [this](unsigned char r, unsigned char g , unsigned char b , unsigned char a) {
|
||||
for (size_t i = 0; i < m_preview_colors_in_thumbnail.size(); i++) {
|
||||
wxColour render_color = adjust_color_for_render(m_preview_colors_in_thumbnail[i]);
|
||||
if (render_color.Red() == r && render_color.Green() == g && render_color.Blue() == b /*&& render_color.Alpha() == a*/) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
ThumbnailData &data = m_cur_no_light_thumbnail_data;
|
||||
ThumbnailData &origin_data = m_cur_input_thumbnail_data;
|
||||
if (data.width > 0 && data.height > 0) {
|
||||
m_edge_pixels.resize(data.width * data.height);
|
||||
for (unsigned int r = 0; r < data.height; ++r) {
|
||||
unsigned int rr = (data.height - 1 - r) * data.width;
|
||||
for (unsigned int c = 0; c < data.width; ++c) {
|
||||
unsigned char *no_light_px = (unsigned char *) data.pixels.data() + 4 * (rr + c);
|
||||
unsigned char *origin_px = (unsigned char *) origin_data.pixels.data() + 4 * (rr + c);
|
||||
m_edge_pixels[r * data.width + c] = false;
|
||||
if (origin_px[3] > 0) {
|
||||
if (is_not_in_preview_colors(no_light_px[0], no_light_px[1], no_light_px[2], origin_px[3])) {
|
||||
m_edge_pixels[r * data.width + c] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxColour SelectMachineDialog::adjust_color_for_render(const wxColour &color)
|
||||
{
|
||||
ColorRGBA _temp_color_color(color.Red() / 255.0f, color.Green() / 255.0f, color.Blue() / 255.0f, color.Alpha() / 255.0f);
|
||||
auto _temp_color_color_ = adjust_color_for_rendering(_temp_color_color);
|
||||
wxColour render_color((int) (_temp_color_color_[0] * 255.0f), (int) (_temp_color_color_[1] * 255.0f), (int) (_temp_color_color_[2] * 255.0f),
|
||||
(int) (_temp_color_color_[3] * 255.0f));
|
||||
return render_color;
|
||||
}
|
||||
|
||||
void SelectMachineDialog::final_deal_edge_pixels_data(ThumbnailData &data)
|
||||
{
|
||||
if (data.width > 0 && data.height > 0 && m_edge_pixels.size() >0 ) {
|
||||
for (unsigned int r = 0; r < data.height; ++r) {
|
||||
unsigned int rr = (data.height - 1 - r) * data.width;
|
||||
bool exist_rr_up = r >= 1 ? true : false;
|
||||
bool exist_rr_down = r <= data.height - 2 ? true : false;
|
||||
unsigned int rr_up = exist_rr_up ? (data.height - 1 - (r - 1)) * data.width : 0;
|
||||
unsigned int rr_down = exist_rr_down ? (data.height - 1 - (r + 1)) * data.width : 0;
|
||||
for (unsigned int c = 0; c < data.width; ++c) {
|
||||
bool exist_c_left = c >= 1 ? true : false;
|
||||
bool exist_c_right = c <= data.width - 2 ? true : false;
|
||||
unsigned int c_left = exist_c_left ? c - 1 : 0;
|
||||
unsigned int c_right = exist_c_right ? c + 1 : 0;
|
||||
unsigned char *cur_px = (unsigned char *) data.pixels.data() + 4 * (rr + c);
|
||||
unsigned char *relational_pxs[8] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
|
||||
if (exist_rr_up && exist_c_left) { relational_pxs[0] = (unsigned char *) data.pixels.data() + 4 * (rr_up + c_left); }
|
||||
if (exist_rr_up) { relational_pxs[1] = (unsigned char *) data.pixels.data() + 4 * (rr_up + c); }
|
||||
if (exist_rr_up && exist_c_right) { relational_pxs[2] = (unsigned char *) data.pixels.data() + 4 * (rr_up + c_right); }
|
||||
if (exist_c_left) { relational_pxs[3] = (unsigned char *) data.pixels.data() + 4 * (rr + c_left); }
|
||||
if (exist_c_right) { relational_pxs[4] = (unsigned char *) data.pixels.data() + 4 * (rr + c_right); }
|
||||
if (exist_rr_down && exist_c_left) { relational_pxs[5] = (unsigned char *) data.pixels.data() + 4 * (rr_down + c_left); }
|
||||
if (exist_rr_down) { relational_pxs[6] = (unsigned char *) data.pixels.data() + 4 * (rr_down + c); }
|
||||
if (exist_rr_down && exist_c_right) { relational_pxs[7] = (unsigned char *) data.pixels.data() + 4 * (rr_down + c_right); }
|
||||
if (cur_px[3] > 0 && m_edge_pixels[r * data.width + c]) {
|
||||
int rgba_sum[4] = {0, 0, 0, 0};
|
||||
int valid_count = 0;
|
||||
for (size_t k = 0; k < 8; k++) {
|
||||
if (relational_pxs[k]) {
|
||||
if (k == 0 && m_edge_pixels[(r - 1) * data.width + c_left]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 1 && m_edge_pixels[(r - 1) * data.width + c]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 2 && m_edge_pixels[(r - 1) * data.width + c_right]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 3 && m_edge_pixels[r * data.width + c_left]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 4 && m_edge_pixels[r * data.width + c_right]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 5 && m_edge_pixels[(r + 1) * data.width + c_left]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 6 && m_edge_pixels[(r + 1) * data.width + c]) {
|
||||
continue;
|
||||
}
|
||||
if (k == 7 && m_edge_pixels[(r + 1) * data.width + c_right]) {
|
||||
continue;
|
||||
}
|
||||
for (size_t m = 0; m < 4; m++) {
|
||||
rgba_sum[m] += relational_pxs[k][m];
|
||||
}
|
||||
valid_count++;
|
||||
}
|
||||
}
|
||||
if (valid_count > 0) {
|
||||
for (size_t m = 0; m < 4; m++) {
|
||||
cur_px[m] = std::clamp(int(rgba_sum[m] / (float)valid_count), 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SelectMachineDialog::updata_thumbnail_data_after_connected_printer()
|
||||
{
|
||||
// change thumbnail_data
|
||||
ThumbnailData &input_data = m_plater->get_partplate_list().get_curr_plate()->thumbnail_data;
|
||||
ThumbnailData &no_light_data = m_plater->get_partplate_list().get_curr_plate()->no_light_thumbnail_data;
|
||||
if (input_data.width == 0 || input_data.height == 0 || no_light_data.width == 0 || no_light_data.height == 0) {
|
||||
wxGetApp().plater()->update_all_plate_thumbnails(false);
|
||||
}
|
||||
unify_deal_thumbnail_data(input_data, no_light_data);
|
||||
}
|
||||
|
||||
void SelectMachineDialog::unify_deal_thumbnail_data(ThumbnailData &input_data, ThumbnailData &no_light_data) {
|
||||
if (input_data.width == 0 || input_data.height == 0 || no_light_data.width == 0 || no_light_data.height == 0) {
|
||||
BOOST_LOG_TRIVIAL(error) << "SelectMachineDialog::no_light_data is empty,error";
|
||||
return;
|
||||
}
|
||||
m_cur_input_thumbnail_data = input_data;
|
||||
m_cur_no_light_thumbnail_data = no_light_data;
|
||||
clone_thumbnail_data();
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
bool is_connect_printer = true;
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material * item = iter->second;
|
||||
MaterialItem *m = item->item;
|
||||
if (m->m_ams_name == "-") {
|
||||
is_connect_printer = false;
|
||||
break;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
if (is_connect_printer) {
|
||||
change_default_normal(-1, wxColour());
|
||||
final_deal_edge_pixels_data(m_preview_thumbnail_data);
|
||||
set_default_normal(m_preview_thumbnail_data);
|
||||
}
|
||||
}
|
||||
|
||||
void SelectMachineDialog::change_default_normal(int old_filament_id, wxColour temp_ams_color)
|
||||
{
|
||||
if (m_cur_colors_in_thumbnail.size() == 0) {
|
||||
BOOST_LOG_TRIVIAL(error) << "SelectMachineDialog::change_default_normal:error:m_cur_colors_in_thumbnail.size() == 0";
|
||||
return;
|
||||
}
|
||||
if (old_filament_id >= 0) {
|
||||
if (old_filament_id < m_cur_colors_in_thumbnail.size()) {
|
||||
m_cur_colors_in_thumbnail[old_filament_id] = temp_ams_color;
|
||||
}
|
||||
else {
|
||||
BOOST_LOG_TRIVIAL(error) << "SelectMachineDialog::change_default_normal:error:old_filament_id > m_cur_colors_in_thumbnail.size()";
|
||||
return;
|
||||
}
|
||||
}
|
||||
ThumbnailData& data = m_cur_input_thumbnail_data;
|
||||
ThumbnailData& no_light_data = m_cur_no_light_thumbnail_data;
|
||||
if (data.width > 0 && data.height > 0 && data.width == no_light_data.width && data.height == no_light_data.height) {
|
||||
for (unsigned int r = 0; r < data.height; ++r) {
|
||||
unsigned int rr = (data.height - 1 - r) * data.width;
|
||||
for (unsigned int c = 0; c < data.width; ++c) {
|
||||
unsigned char *no_light_px = (unsigned char *) no_light_data.pixels.data() + 4 * (rr + c);
|
||||
unsigned char *origin_px = (unsigned char *) data.pixels.data() + 4 * (rr + c);
|
||||
unsigned char *new_px = (unsigned char *) m_preview_thumbnail_data.pixels.data() + 4 * (rr + c);
|
||||
if (origin_px[3] > 0 && m_edge_pixels[r * data.width + c] == false) {
|
||||
auto filament_id = 255 - no_light_px[3];
|
||||
if (filament_id >= m_cur_colors_in_thumbnail.size()) {
|
||||
continue;
|
||||
}
|
||||
wxColour temp_ams_color_in_loop = m_cur_colors_in_thumbnail[filament_id];
|
||||
wxColour ams_color = adjust_color_for_render(temp_ams_color_in_loop);
|
||||
//change color
|
||||
new_px[3] = origin_px[3]; // alpha
|
||||
int origin_rgb = origin_px[0] + origin_px[1] + origin_px[2];
|
||||
int no_light_px_rgb = no_light_px[0] + no_light_px[1] + no_light_px[2];
|
||||
unsigned char i = 0;
|
||||
if (origin_rgb >= no_light_px_rgb) {//Brighten up
|
||||
unsigned char cur_single_color = ams_color.Red();
|
||||
new_px[i] = std::clamp(cur_single_color + (origin_px[i] - no_light_px[i]), 0, 255);
|
||||
i++;
|
||||
cur_single_color = ams_color.Green();
|
||||
new_px[i] = std::clamp(cur_single_color + (origin_px[i] - no_light_px[i]), 0, 255);
|
||||
i++;
|
||||
cur_single_color = ams_color.Blue();
|
||||
new_px[i] = std::clamp(cur_single_color + (origin_px[i] - no_light_px[i]), 0, 255);
|
||||
} else {//Dimming
|
||||
float ratio = origin_rgb / (float) no_light_px_rgb;
|
||||
unsigned char cur_single_color = ams_color.Red();
|
||||
new_px[i] = std::clamp((int)(cur_single_color * ratio), 0, 255);
|
||||
i++;
|
||||
cur_single_color = ams_color.Green();
|
||||
new_px[i] = std::clamp((int) (cur_single_color * ratio), 0, 255);
|
||||
i++;
|
||||
cur_single_color = ams_color.Blue();
|
||||
new_px[i] = std::clamp((int) (cur_single_color * ratio), 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
BOOST_LOG_TRIVIAL(error) << "SelectMachineDialog::change_defa:no_light_data is empty,error";
|
||||
}
|
||||
}
|
||||
|
||||
void SelectMachineDialog::set_default_normal(const ThumbnailData &data)
|
||||
{
|
||||
update_page_turn_state(false);
|
||||
ThumbnailData& data = m_plater->get_partplate_list().get_curr_plate()->thumbnail_data;
|
||||
if (data.is_valid()) {
|
||||
wxImage image(data.width, data.height);
|
||||
image.InitAlpha();
|
||||
|
@ -3955,135 +4346,6 @@ void SelectMachineDialog::set_default_normal()
|
|||
m_thumbnailPanel->set_thumbnail(image);
|
||||
}
|
||||
|
||||
//for black list
|
||||
std::vector<std::string> materials;
|
||||
std::vector<std::string> brands;
|
||||
std::vector<std::string> display_materials;
|
||||
std::vector<std::string> m_filaments_id;
|
||||
|
||||
|
||||
auto preset_bundle = wxGetApp().preset_bundle;
|
||||
|
||||
for (auto filament_name : preset_bundle->filament_presets) {
|
||||
for (int f_index = 0; f_index < preset_bundle->filaments.size(); f_index++) {
|
||||
PresetCollection* filament_presets = &wxGetApp().preset_bundle->filaments;
|
||||
Preset* preset = &filament_presets->preset(f_index);
|
||||
|
||||
if (preset && filament_name.compare(preset->name) == 0) {
|
||||
std::string display_filament_type;
|
||||
std::string filament_type = preset->config.get_filament_type(display_filament_type);
|
||||
std::string m_filament_id=preset->filament_id;
|
||||
display_materials.push_back(display_filament_type);
|
||||
materials.push_back(filament_type);
|
||||
m_filaments_id.push_back(m_filament_id);
|
||||
|
||||
std::string m_vendor_name = "";
|
||||
auto vendor = dynamic_cast<ConfigOptionStrings*> (preset->config.option("filament_vendor"));
|
||||
if (vendor && (vendor->values.size() > 0)) {
|
||||
std::string vendor_name = vendor->values[0];
|
||||
m_vendor_name = vendor_name;
|
||||
}
|
||||
brands.push_back(m_vendor_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//init MaterialItem
|
||||
auto extruders = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders();
|
||||
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material* item = iter->second;
|
||||
item->item->Destroy();
|
||||
delete item;
|
||||
iter++;
|
||||
}
|
||||
|
||||
m_sizer_material->Clear();
|
||||
m_materialList.clear();
|
||||
m_filaments.clear();
|
||||
|
||||
for (auto i = 0; i < extruders.size(); i++) {
|
||||
auto extruder = extruders[i] - 1;
|
||||
auto colour = wxGetApp().preset_bundle->project_config.opt_string("filament_colour", (unsigned int) extruder);
|
||||
ColorRGBA rgb;
|
||||
decode_color(colour, rgb);
|
||||
|
||||
auto colour_rgb = wxColour((int) rgb.r_uchar(), (int) rgb.g_uchar(), (int) rgb.b_uchar(), (int) rgb.a_uchar());
|
||||
if (extruder >= materials.size() || extruder < 0 || extruder >= display_materials.size())
|
||||
continue;
|
||||
|
||||
MaterialItem* item = new MaterialItem(m_scrollable_region, colour_rgb, _L(display_materials[extruder]));
|
||||
m_sizer_material->Add(item, 0, wxALL, FromDIP(4));
|
||||
|
||||
item->Bind(wxEVT_LEFT_UP, [this, item, materials, extruder](wxMouseEvent& e) {});
|
||||
item->Bind(wxEVT_LEFT_DOWN, [this, item, materials, extruder](wxMouseEvent& e) {
|
||||
MaterialHash::iterator iter = m_materialList.begin();
|
||||
while (iter != m_materialList.end()) {
|
||||
int id = iter->first;
|
||||
Material* item = iter->second;
|
||||
MaterialItem* m = item->item;
|
||||
m->on_normal();
|
||||
iter++;
|
||||
}
|
||||
|
||||
m_current_filament_id = extruder;
|
||||
item->on_selected();
|
||||
|
||||
|
||||
auto mouse_pos = ClientToScreen(e.GetPosition());
|
||||
wxPoint rect = item->ClientToScreen(wxPoint(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_->is_support_ams_mapping()) {
|
||||
if (m_mapping_popup.IsShown()) return;
|
||||
wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
|
||||
pos.y += item->GetRect().height;
|
||||
m_mapping_popup.Move(pos);
|
||||
|
||||
if (obj_ &&
|
||||
obj_->has_ams() &&
|
||||
m_checkbox_list["use_ams"]->GetValue() &&
|
||||
obj_->dev_id == m_printer_last_select)
|
||||
{
|
||||
m_mapping_popup.set_parent_item(item);
|
||||
m_mapping_popup.set_current_filament_id(extruder);
|
||||
m_mapping_popup.set_tag_texture(materials[extruder]);
|
||||
m_mapping_popup.update_ams_data(obj_->amsList);
|
||||
m_mapping_popup.Popup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Material* material_item = new Material();
|
||||
material_item->id = extruder;
|
||||
material_item->item = item;
|
||||
m_materialList[i] = material_item;
|
||||
|
||||
// build for ams mapping
|
||||
if (extruder < materials.size() && extruder >= 0) {
|
||||
FilamentInfo info;
|
||||
info.id = extruder;
|
||||
info.type = materials[extruder];
|
||||
info.brand = brands[extruder];
|
||||
info.filament_id=m_filaments_id[extruder];
|
||||
info.color = wxString::Format("#%02X%02X%02X%02X", colour_rgb.Red(), colour_rgb.Green(), colour_rgb.Blue(), colour_rgb.Alpha()).ToStdString();
|
||||
m_filaments.push_back(info);
|
||||
}
|
||||
}
|
||||
|
||||
if (extruders.size() <= 4) {
|
||||
m_sizer_material->SetCols(extruders.size());
|
||||
}
|
||||
else {
|
||||
m_sizer_material->SetCols(4);
|
||||
}
|
||||
|
||||
m_scrollable_region->Layout();
|
||||
m_scrollable_region->Fit();
|
||||
|
||||
|
@ -4112,10 +4374,6 @@ void SelectMachineDialog::set_default_normal()
|
|||
m_scrollable_view->SetScrollRate(0, 0);
|
||||
}
|
||||
#endif // __WXOSX_MAC__
|
||||
|
||||
|
||||
reset_ams_material();
|
||||
|
||||
// basic info
|
||||
auto aprint_stats = m_plater->get_partplate_list().get_current_fff_print().print_statistics();
|
||||
wxString time;
|
||||
|
@ -4149,7 +4407,7 @@ void SelectMachineDialog::set_default_from_sdcard()
|
|||
image = image.Rescale(FromDIP(256), FromDIP(256));
|
||||
m_thumbnailPanel->set_thumbnail(image);
|
||||
}
|
||||
|
||||
|
||||
//for black list
|
||||
std::vector<std::string> materials;
|
||||
std::vector<std::string> brands;
|
||||
|
@ -4556,9 +4814,10 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
|
|||
Fit();
|
||||
}
|
||||
|
||||
void ThumbnailPanel::set_thumbnail(wxImage img)
|
||||
void ThumbnailPanel::set_thumbnail(wxImage &img)
|
||||
{
|
||||
m_bitmap = img;
|
||||
m_brightness_value = get_brightness_value(img);
|
||||
m_bitmap = img;
|
||||
//Paint the background bitmap to the thumbnail bitmap with wxMemoryDC
|
||||
wxMemoryDC dc;
|
||||
bitmap_with_background.Create(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
|
||||
|
@ -4577,7 +4836,7 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
|
|||
|
||||
void ThumbnailPanel::render(wxDC& dc) {
|
||||
|
||||
if (wxGetApp().dark_mode()) {
|
||||
if (wxGetApp().dark_mode() && m_brightness_value < SHOW_BACKGROUND_BITMAP_PIXEL_THRESHOLD) {
|
||||
#ifdef __WXMSW__
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bmp(GetSize());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue