ENH:move get_extruders_colors api to plater class

jira: none
Change-Id: I8c2b31d4963b01cb193b7f2a2a3650cf7252ebc5
This commit is contained in:
zhou.xu 2024-12-30 12:24:58 +08:00 committed by lane.wei
parent 1e712f19c9
commit 3eeabc0722
7 changed files with 28 additions and 45 deletions

View File

@ -70,25 +70,6 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char
}
#endif // HAS_GLSAFE
// BBS
std::vector<std::array<float, 4>> get_extruders_colors()
{
unsigned char rgba_color[4] = {};
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
std::vector<std::array<float, 4>> colors_out(colors.size());
for (const std::string &color : colors) {
Slic3r::GUI::BitmapCache::parse_color4(color, rgba_color);
size_t color_idx = &color - &colors.front();
colors_out[color_idx] = {
float(rgba_color[0]) / 255.f,
float(rgba_color[1]) / 255.f,
float(rgba_color[2]) / 255.f,
float(rgba_color[3]) / 255.f,
};
}
return colors_out;
}
float FullyTransparentMaterialThreshold = 0.1f;
float FullTransparentModdifiedToFixAlpha = 0.3f;
const float BlackThreshold = 0.2f;
@ -838,7 +819,7 @@ void GLVolume::render(bool with_outline, const std::array<float, 4>& body_color)
if (mv->mmu_segmentation_facets.empty())
break;
std::vector<std::array<float, 4>> colors = get_extruders_colors();
std::vector<std::array<float, 4>> colors = GUI::wxGetApp().plater()->get_extruders_colors();
if (colors.size() == 1) {
break;
}
@ -866,7 +847,7 @@ void GLVolume::render(bool with_outline, const std::array<float, 4>& body_color)
if (color_volume) {
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
std::vector<std::array<float, 4>> colors = get_extruders_colors();
std::vector<std::array<float, 4>> colors = GUI::wxGetApp().plater()->get_extruders_colors();
//when force_transparent, we need to keep the alpha
if (force_native_color && (render_color[3] < 1.0)) {
@ -1448,7 +1429,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
if (height == 0.0f)
height = 0.1f;
std::vector<std::array<float, 4>> extruder_colors = get_extruders_colors();
std::vector<std::array<float, 4>> extruder_colors = GUI::wxGetApp().plater()->get_extruders_colors();
std::vector<std::array<float, 4>> colors;
GUI::PartPlateList& ppl = GUI::wxGetApp().plater()->get_partplate_list();
std::vector<int> plate_extruders = ppl.get_plate(plate_idx)->get_extruders(true);

View File

@ -31,7 +31,6 @@
#define glsafe(cmd) cmd
#define glcheck()
#endif // HAS_GLSAFE
extern std::vector<std::array<float, 4>> get_extruders_colors();
extern float FullyTransparentMaterialThreshold;
extern float FullTransparentModdifiedToFixAlpha;
extern std::array<float, 4> adjust_color_for_rendering(const std::array<float, 4> &colors);

View File

@ -2203,7 +2203,7 @@ void GLCanvas3D::render_thumbnail(ThumbnailData & thumbnail_data,
bool ban_light)
{
GLShaderProgram* shader = wxGetApp().get_shader("thumbnail");
std::vector<std::array<float, 4>> colors = ::get_extruders_colors();
std::vector<std::array<float, 4>> colors = wxGetApp().plater()->get_extruders_colors();
const auto fb_type = Slic3r::GUI::OpenGLManager::get_framebuffers_type();
BOOST_LOG_TRIVIAL(info) << boost::format("framebuffer_type: %1%") % Slic3r::GUI::OpenGLManager::framebuffer_type_to_string(fb_type).c_str();
switch (fb_type)

View File

@ -62,21 +62,6 @@ bool GLGizmoMmuSegmentation::on_is_activable() const
return !selection.is_empty() && (selection.is_single_full_instance() || selection.is_any_volume());
}
//BBS: use the global one in 3DScene.cpp
/*static std::vector<std::array<float, 4>> get_extruders_colors()
{
unsigned char rgb_color[3] = {};
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
std::vector<std::array<float, 4>> colors_out(colors.size());
for (const std::string &color : colors) {
Slic3r::GUI::BitmapCache::parse_color(color, rgb_color);
size_t color_idx = &color - &colors.front();
colors_out[color_idx] = {float(rgb_color[0]) / 255.f, float(rgb_color[1]) / 255.f, float(rgb_color[2]) / 255.f, 1.f};
}
return colors_out;
}*/
static std::vector<int> get_extruder_id_for_volumes(const ModelObject &model_object)
{
std::vector<int> extruders_idx;
@ -93,7 +78,7 @@ static std::vector<int> get_extruder_id_for_volumes(const ModelObject &model_obj
void GLGizmoMmuSegmentation::init_extruders_data()
{
m_extruders_colors = get_extruders_colors();
m_extruders_colors = wxGetApp().plater()->get_extruders_colors();
size_t n_extruder_colors = std::min((size_t) EnforcerBlockerType::ExtruderMax, m_extruders_colors.size());
if (n_extruder_colors == 2 || m_selected_extruder_idx >= n_extruder_colors) {
m_selected_extruder_idx = n_extruder_colors - 1;
@ -236,8 +221,7 @@ void GLGizmoMmuSegmentation::set_painter_gizmo_data(const Selection &selection)
// Reinitialize triangle selectors because of change of extruder count need also change the size of GLIndexedVertexArray
if (prev_extruders_count != wxGetApp().filaments_cnt())
this->init_model_triangle_selectors();
}
else if (get_extruders_colors() != m_extruders_colors) {
} else if (wxGetApp().plater()->get_extruders_colors() != m_extruders_colors) {
this->init_extruders_data();
this->update_triangle_selectors_colors();
}
@ -976,7 +960,7 @@ void GLGizmoMmuSegmentation::update_from_model_object(bool first_update)
// Extruder colors need to be reloaded before calling init_model_triangle_selectors to render painted triangles
// using colors from loaded 3MF and not from printer profile in Slicer.
if (int prev_extruders_count = int(m_extruders_colors.size());
prev_extruders_count != wxGetApp().filaments_cnt() || get_extruders_colors() != m_extruders_colors)
prev_extruders_count != wxGetApp().filaments_cnt() || wxGetApp().plater()->get_extruders_colors() != m_extruders_colors)
this->init_extruders_data();
this->init_model_triangle_selectors();

View File

@ -801,7 +801,7 @@ void ObjColorPanel::generate_thumbnail()
if (m_deal_thumbnail_flag && m_obj_in_out.model->objects.size() == 1) {
auto mo = m_obj_in_out.model->objects[0];
mo->add_instance();
std::vector<std::array<float, 4>> colors = ::get_extruders_colors();
std::vector<std::array<float, 4>> colors = GUI::wxGetApp().plater()->get_extruders_colors();
for (size_t i = 0; i < m_new_add_final_colors.size(); i++) {
std::array<float, 4> temp_color;
temp_color[0] = m_new_add_final_colors[i].Red() /255.f;

View File

@ -14253,7 +14253,25 @@ void Plater::on_filaments_delete(size_t num_filaments, size_t filament_id, int r
}
}
void Plater::on_bed_type_change(BedType bed_type, bool is_gcode_file) {
std::vector<std::array<float, 4>> Plater::get_extruders_colors()
{
unsigned char rgba_color[4] = {};
std::vector<std::string> colors = get_extruder_colors_from_plater_config();
std::vector<std::array<float, 4>> colors_out(colors.size());
for (const std::string &color : colors) {
Slic3r::GUI::BitmapCache::parse_color4(color, rgba_color);
size_t color_idx = &color - &colors.front();
colors_out[color_idx] = {
float(rgba_color[0]) / 255.f,
float(rgba_color[1]) / 255.f,
float(rgba_color[2]) / 255.f,
float(rgba_color[3]) / 255.f,
};
}
return colors_out;
}
void Plater::on_bed_type_change(BedType bed_type, bool is_gcode_file) {
sidebar().set_is_gcode_file(is_gcode_file);
sidebar().on_bed_type_change(bed_type);
}

View File

@ -444,6 +444,7 @@ public:
void on_filaments_change(size_t extruders_count);
void on_filaments_delete(size_t extruders_count, size_t filament_id, int replace_filament_id = -1);
std::vector<std::array<float, 4>> get_extruders_colors();
// BBS
void on_bed_type_change(BedType bed_type,bool is_gcode_file = false);