Merge branch 'master' into fs_QuadricEdgeCollapse

This commit is contained in:
Filip Sykala 2021-07-20 08:22:06 +02:00
commit bc3da9973b
21 changed files with 207 additions and 186 deletions

View file

@ -31,7 +31,6 @@ struct SlopeDetection
uniform vec4 uniform_color; uniform vec4 uniform_color;
uniform SlopeDetection slope; uniform SlopeDetection slope;
uniform bool sinking;
#ifdef ENABLE_ENVIRONMENT_MAP #ifdef ENABLE_ENVIRONMENT_MAP
uniform sampler2D environment_tex; uniform sampler2D environment_tex;
@ -51,11 +50,6 @@ varying float world_pos_z;
varying float world_normal_z; varying float world_normal_z;
varying vec3 eye_normal; varying vec3 eye_normal;
vec3 sinking_color(vec3 color)
{
return (mod(model_pos.x + model_pos.y + model_pos.z, BANDS_WIDTH) < (0.5 * BANDS_WIDTH)) ? mix(color, ZERO, 0.6666) : color;
}
uniform bool compute_triangle_normals_in_fs; uniform bool compute_triangle_normals_in_fs;
void main() void main()
@ -97,9 +91,6 @@ void main()
} }
// if the fragment is outside the print volume -> use darker color // if the fragment is outside the print volume -> use darker color
color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(color, ZERO, 0.3333) : color;
// if the object is sinking, shade it with inclined bands or white around world z = 0
if (sinking)
color = (abs(world_pos_z) < 0.05) ? WHITE : sinking_color(color);
#ifdef ENABLE_ENVIRONMENT_MAP #ifdef ENABLE_ENVIRONMENT_MAP
if (use_environment_tex) if (use_environment_tex)
gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal_fs).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity_fs.x, alpha); gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal_fs).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity_fs.x, alpha);

View file

@ -65,8 +65,8 @@ void TriangleSelector::Triangle::set_division(int sides_to_split, int special_si
assert(sides_to_split >= 0 && sides_to_split <= 3); assert(sides_to_split >= 0 && sides_to_split <= 3);
assert(special_side_idx >= 0 && special_side_idx < 3); assert(special_side_idx >= 0 && special_side_idx < 3);
assert(sides_to_split == 1 || sides_to_split == 2 || special_side_idx == 0); assert(sides_to_split == 1 || sides_to_split == 2 || special_side_idx == 0);
this->number_of_splits = sides_to_split; this->number_of_splits = char(sides_to_split);
this->special_side_idx = special_side_idx; this->special_side_idx = char(special_side_idx);
} }
inline bool is_point_inside_triangle(const Vec3f &pt, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3) inline bool is_point_inside_triangle(const Vec3f &pt, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3)
@ -167,8 +167,7 @@ void TriangleSelector::select_patch(const Vec3f& hit, int facet_start,
if (! visited[facet]) { if (! visited[facet]) {
if (select_triangle(facet, new_state, triangle_splitting)) { if (select_triangle(facet, new_state, triangle_splitting)) {
// add neighboring facets to list to be proccessed later // add neighboring facets to list to be proccessed later
for (int n=0; n<3; ++n) { for (int neighbor_idx : m_mesh->stl.neighbors_start[facet].neighbor) {
int neighbor_idx = m_mesh->stl.neighbors_start[facet].neighbor[n];
if (neighbor_idx >=0 && (m_cursor.type == SPHERE || faces_camera(neighbor_idx))) if (neighbor_idx >=0 && (m_cursor.type == SPHERE || faces_camera(neighbor_idx)))
facets_to_check.push_back(neighbor_idx); facets_to_check.push_back(neighbor_idx);
} }
@ -182,6 +181,11 @@ void TriangleSelector::select_patch(const Vec3f& hit, int facet_start,
void TriangleSelector::seed_fill_select_triangles(const Vec3f &hit, int facet_start, float seed_fill_angle) void TriangleSelector::seed_fill_select_triangles(const Vec3f &hit, int facet_start, float seed_fill_angle)
{ {
assert(facet_start < m_orig_size_indices); assert(facet_start < m_orig_size_indices);
// Recompute seed fill only if the cursor is pointing on facet unselected by seed fill.
if (int start_facet_idx = select_unsplit_triangle(hit, facet_start); start_facet_idx >= 0 && m_triangles[start_facet_idx].is_selected_by_seed_fill())
return;
this->seed_fill_unselect_all_triangles(); this->seed_fill_unselect_all_triangles();
std::vector<bool> visited(m_triangles.size(), false); std::vector<bool> visited(m_triangles.size(), false);
@ -308,13 +312,15 @@ std::vector<int> TriangleSelector::neighboring_triangles(const int first_facet_i
void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_start, bool propagate) void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_start, bool propagate)
{ {
this->seed_fill_unselect_all_triangles(); int start_facet_idx = select_unsplit_triangle(hit, facet_start);
// Recompute bucket fill only if the cursor is pointing on facet unselected by bucket fill.
int start_facet_idx = select_unsplit_triangle(hit, facet_start); if (start_facet_idx == -1 || m_triangles[start_facet_idx].is_selected_by_seed_fill())
EnforcerBlockerType start_facet_state = m_triangles[start_facet_idx].get_state();
if (start_facet_idx == -1)
return; return;
assert(!m_triangles[start_facet_idx].is_split());
EnforcerBlockerType start_facet_state = m_triangles[start_facet_idx].get_state();
this->seed_fill_unselect_all_triangles();
if (!propagate) { if (!propagate) {
m_triangles[start_facet_idx].select_by_seed_fill(); m_triangles[start_facet_idx].select_by_seed_fill();
return; return;
@ -332,12 +338,15 @@ void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_
if (!visited[current_facet]) { if (!visited[current_facet]) {
m_triangles[current_facet].select_by_seed_fill(); m_triangles[current_facet].select_by_seed_fill();
for(int neighbor_idx : all_level_neighbors[current_facet]) { for (int neighbor_idx : all_level_neighbors[current_facet]) {
if(!m_triangles[neighbor_idx].is_split()) { if (neighbor_idx < 0 || visited[neighbor_idx])
if(m_triangles[neighbor_idx].get_state() == start_facet_state) continue;
if (!m_triangles[neighbor_idx].is_split()) {
if (m_triangles[neighbor_idx].get_state() == start_facet_state)
facet_queue.push(neighbor_idx); facet_queue.push(neighbor_idx);
} else { } else {
for(int neighbor_facet_idx : neighboring_triangles(neighbor_idx, current_facet, start_facet_state)) for (int neighbor_facet_idx : neighboring_triangles(neighbor_idx, current_facet, start_facet_state))
facet_queue.push(neighbor_facet_idx); facet_queue.push(neighbor_facet_idx);
} }
} }
@ -475,7 +484,7 @@ int TriangleSelector::triangle_midpoint_or_allocate(int itriangle, int vertexi,
Vec3f c = 0.5f * (m_vertices[vertexi].v + m_vertices[vertexj].v); Vec3f c = 0.5f * (m_vertices[vertexi].v + m_vertices[vertexj].v);
#ifdef EXPENSIVE_DEBUG_CHECKS #ifdef EXPENSIVE_DEBUG_CHECKS
// Verify that the vertex is really a new one. // Verify that the vertex is really a new one.
auto it = std::find_if(m_vertices.begin(), m_vertices.end(), [this, c](const Vertex &v) { auto it = std::find_if(m_vertices.begin(), m_vertices.end(), [c](const Vertex &v) {
return v.ref_cnt > 0 && (v.v - c).norm() < EPSILON; }); return v.ref_cnt > 0 && (v.v - c).norm() < EPSILON; });
assert(it == m_vertices.end()); assert(it == m_vertices.end());
#endif // EXPENSIVE_DEBUG_CHECKS #endif // EXPENSIVE_DEBUG_CHECKS
@ -774,10 +783,9 @@ void TriangleSelector::split_triangle(int facet_idx, const Vec3i &neighbors)
} }
} }
std::array<double, 3> sides; std::array<double, 3> sides = {(*pts[2] - *pts[1]).squaredNorm(),
sides = { (*pts[2]-*pts[1]).squaredNorm(), (*pts[0] - *pts[2]).squaredNorm(),
(*pts[0]-*pts[2]).squaredNorm(), (*pts[1] - *pts[0]).squaredNorm()};
(*pts[1]-*pts[0]).squaredNorm() };
boost::container::small_vector<int, 3> sides_to_split; boost::container::small_vector<int, 3> sides_to_split;
int side_to_keep = -1; int side_to_keep = -1;
@ -795,7 +803,7 @@ void TriangleSelector::split_triangle(int facet_idx, const Vec3i &neighbors)
// Save how the triangle will be split. Second argument makes sense only for one // Save how the triangle will be split. Second argument makes sense only for one
// or two split sides, otherwise the value is ignored. // or two split sides, otherwise the value is ignored.
tr->set_division(sides_to_split.size(), tr->set_division(int(sides_to_split.size()),
sides_to_split.size() == 2 ? side_to_keep : sides_to_split[0]); sides_to_split.size() == 2 ? side_to_keep : sides_to_split[0]);
perform_split(facet_idx, neighbors, old_type); perform_split(facet_idx, neighbors, old_type);
@ -1023,12 +1031,12 @@ void TriangleSelector::reset()
for (const stl_vertex& vert : m_mesh->its.vertices) for (const stl_vertex& vert : m_mesh->its.vertices)
m_vertices.emplace_back(vert); m_vertices.emplace_back(vert);
m_triangles.reserve(m_mesh->its.indices.size()); m_triangles.reserve(m_mesh->its.indices.size());
for (size_t i=0; i<m_mesh->its.indices.size(); ++i) { for (size_t i = 0; i < m_mesh->its.indices.size(); ++i) {
const stl_triangle_vertex_indices& ind = m_mesh->its.indices[i]; const stl_triangle_vertex_indices &ind = m_mesh->its.indices[i];
push_triangle(ind[0], ind[1], ind[2], i); push_triangle(ind[0], ind[1], ind[2], int(i));
} }
m_orig_size_vertices = m_vertices.size(); m_orig_size_vertices = int(m_vertices.size());
m_orig_size_indices = m_triangles.size(); m_orig_size_indices = int(m_triangles.size());
} }
@ -1409,7 +1417,7 @@ void TriangleSelector::deserialize(const std::pair<std::vector<std::pair<int, in
for (auto [triangle_id, ibit] : data.first) { for (auto [triangle_id, ibit] : data.first) {
assert(triangle_id < int(m_triangles.size())); assert(triangle_id < int(m_triangles.size()));
assert(ibit < data.second.size()); assert(ibit < int(data.second.size()));
auto next_nibble = [&data, &ibit = ibit]() { auto next_nibble = [&data, &ibit = ibit]() {
int n = 0; int n = 0;
for (int i = 0; i < 4; ++ i) for (int i = 0; i < 4; ++ i)
@ -1495,7 +1503,7 @@ bool TriangleSelector::has_facets(const std::pair<std::vector<std::pair<int, int
for (const std::pair<int, int> &triangle_id_and_ibit : data.first) { for (const std::pair<int, int> &triangle_id_and_ibit : data.first) {
int ibit = triangle_id_and_ibit.second; int ibit = triangle_id_and_ibit.second;
assert(ibit < data.second.size()); assert(ibit < int(data.second.size()));
auto next_nibble = [&data, &ibit = ibit]() { auto next_nibble = [&data, &ibit = ibit]() {
int n = 0; int n = 0;
for (int i = 0; i < 4; ++ i) for (int i = 0; i < 4; ++ i)
@ -1553,7 +1561,7 @@ void TriangleSelector::seed_fill_apply_on_triangles(EnforcerBlockerType new_stat
for (Triangle &triangle : m_triangles) for (Triangle &triangle : m_triangles)
if (triangle.is_split() && triangle.valid()) { if (triangle.is_split() && triangle.valid()) {
size_t facet_idx = &triangle - &m_triangles.front(); size_t facet_idx = &triangle - &m_triangles.front();
remove_useless_children(facet_idx); remove_useless_children(int(facet_idx));
} }
} }
@ -1567,7 +1575,7 @@ TriangleSelector::Cursor::Cursor(
{ {
Vec3d sf = Geometry::Transformation(trafo_).get_scaling_factor(); Vec3d sf = Geometry::Transformation(trafo_).get_scaling_factor();
if (is_approx(sf(0), sf(1)) && is_approx(sf(1), sf(2))) { if (is_approx(sf(0), sf(1)) && is_approx(sf(1), sf(2))) {
radius_sqr = std::pow(radius_world / sf(0), 2); radius_sqr = float(std::pow(radius_world / sf(0), 2));
uniform_scaling = true; uniform_scaling = true;
} }
else { else {

View file

@ -14,9 +14,10 @@ namespace GUI {
Bed_2D::Bed_2D(wxWindow* parent) : Bed_2D::Bed_2D(wxWindow* parent) :
wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(25 * wxGetApp().em_unit(), -1), wxTAB_TRAVERSAL) wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(25 * wxGetApp().em_unit(), -1), wxTAB_TRAVERSAL)
{ {
SetBackgroundStyle(wxBG_STYLE_PAINT); // to avoid assert message after wxAutoBufferedPaintDC
#ifdef __APPLE__ #ifdef __APPLE__
m_user_drawn_background = false; m_user_drawn_background = false;
#else
SetBackgroundStyle(wxBG_STYLE_PAINT); // to avoid assert message after wxAutoBufferedPaintDC
#endif /*__APPLE__*/ #endif /*__APPLE__*/
} }

View file

@ -286,21 +286,21 @@ void GLIndexedVertexArray::render(
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
} }
const float GLVolume::SELECTED_COLOR[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; const std::array<float, 4> GLVolume::SELECTED_COLOR = { 0.0f, 1.0f, 0.0f, 1.0f };
const float GLVolume::HOVER_SELECT_COLOR[4] = { 0.4f, 0.9f, 0.1f, 1.0f }; const std::array<float, 4> GLVolume::HOVER_SELECT_COLOR = { 0.4f, 0.9f, 0.1f, 1.0f };
const float GLVolume::HOVER_DESELECT_COLOR[4] = { 1.0f, 0.75f, 0.75f, 1.0f }; const std::array<float, 4> GLVolume::HOVER_DESELECT_COLOR = { 1.0f, 0.75f, 0.75f, 1.0f };
const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f }; const std::array<float, 4> GLVolume::OUTSIDE_COLOR = { 0.0f, 0.38f, 0.8f, 1.0f };
const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f }; const std::array<float, 4> GLVolume::SELECTED_OUTSIDE_COLOR = { 0.19f, 0.58f, 1.0f, 1.0f };
const float GLVolume::DISABLED_COLOR[4] = { 0.25f, 0.25f, 0.25f, 1.0f }; const std::array<float, 4> GLVolume::DISABLED_COLOR = { 0.25f, 0.25f, 0.25f, 1.0f };
const float GLVolume::MODEL_COLOR[4][4] = { const std::array<float, 4> GLVolume::SLA_SUPPORT_COLOR = { 0.75f, 0.75f, 0.75f, 1.0f };
const std::array<float, 4> GLVolume::SLA_PAD_COLOR = { 0.0f, 0.2f, 0.0f, 1.0f };
const std::array<float, 4> GLVolume::NEUTRAL_COLOR = { 0.9f, 0.9f, 0.9f, 1.0f };
const std::array<std::array<float, 4>, 4> GLVolume::MODEL_COLOR = { {
{ 1.0f, 1.0f, 0.0f, 1.f }, { 1.0f, 1.0f, 0.0f, 1.f },
{ 1.0f, 0.5f, 0.5f, 1.f }, { 1.0f, 0.5f, 0.5f, 1.f },
{ 0.5f, 1.0f, 0.5f, 1.f }, { 0.5f, 1.0f, 0.5f, 1.f },
{ 0.5f, 0.5f, 1.0f, 1.f } { 0.5f, 0.5f, 1.0f, 1.f }
}; } };
const float GLVolume::SLA_SUPPORT_COLOR[4] = { 0.75f, 0.75f, 0.75f, 1.0f };
const float GLVolume::SLA_PAD_COLOR[4] = { 0.0f, 0.2f, 0.0f, 1.0f };
const float GLVolume::NEUTRAL_COLOR[4] = { 0.9f, 0.9f, 0.9f, 1.0f };
GLVolume::GLVolume(float r, float g, float b, float a) GLVolume::GLVolume(float r, float g, float b, float a)
: m_transformed_bounding_box_dirty(true) : m_transformed_bounding_box_dirty(true)
@ -326,24 +326,18 @@ GLVolume::GLVolume(float r, float g, float b, float a)
, tverts_range(0, size_t(-1)) , tverts_range(0, size_t(-1))
, qverts_range(0, size_t(-1)) , qverts_range(0, size_t(-1))
{ {
color[0] = r; color = { r, g, b, a };
color[1] = g; set_render_color(color);
color[2] = b;
color[3] = a;
set_render_color(r, g, b, a);
} }
void GLVolume::set_render_color(float r, float g, float b, float a) void GLVolume::set_render_color(float r, float g, float b, float a)
{ {
render_color[0] = r; render_color = { r, g, b, a };
render_color[1] = g;
render_color[2] = b;
render_color[3] = a;
} }
void GLVolume::set_render_color(const float* rgba, unsigned int size) void GLVolume::set_render_color(const std::array<float, 4>& rgba)
{ {
::memcpy((void*)render_color, (const void*)rgba, (size_t)(std::min((unsigned int)4, size) * sizeof(float))); render_color = rgba;
} }
void GLVolume::set_render_color() void GLVolume::set_render_color()
@ -358,35 +352,35 @@ void GLVolume::set_render_color()
#else #else
if (is_outside && shader_outside_printer_detection_enabled) if (is_outside && shader_outside_printer_detection_enabled)
#endif // ENABLE_ALLOW_NEGATIVE_Z #endif // ENABLE_ALLOW_NEGATIVE_Z
set_render_color(OUTSIDE_COLOR, 4); set_render_color(OUTSIDE_COLOR);
else { else {
if (force_native_color) if (force_native_color)
set_render_color(color, 4); set_render_color(color);
else else
set_render_color(NEUTRAL_COLOR, 4); set_render_color(NEUTRAL_COLOR);
} }
} }
else { else {
if (hover == HS_Select) if (hover == HS_Select)
set_render_color(HOVER_SELECT_COLOR, 4); set_render_color(HOVER_SELECT_COLOR);
else if (hover == HS_Deselect) else if (hover == HS_Deselect)
set_render_color(HOVER_DESELECT_COLOR, 4); set_render_color(HOVER_DESELECT_COLOR);
else if (selected) else if (selected)
#if ENABLE_ALLOW_NEGATIVE_Z #if ENABLE_ALLOW_NEGATIVE_Z
set_render_color(outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR, 4); set_render_color(outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR);
#else #else
set_render_color(is_outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR, 4); set_render_color(is_outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR);
#endif // ENABLE_ALLOW_NEGATIVE_Z #endif // ENABLE_ALLOW_NEGATIVE_Z
else if (disabled) else if (disabled)
set_render_color(DISABLED_COLOR, 4); set_render_color(DISABLED_COLOR);
#if ENABLE_ALLOW_NEGATIVE_Z #if ENABLE_ALLOW_NEGATIVE_Z
else if (outside && shader_outside_printer_detection_enabled) else if (outside && shader_outside_printer_detection_enabled)
#else #else
else if (is_outside && shader_outside_printer_detection_enabled) else if (is_outside && shader_outside_printer_detection_enabled)
#endif // ENABLE_ALLOW_NEGATIVE_Z #endif // ENABLE_ALLOW_NEGATIVE_Z
set_render_color(OUTSIDE_COLOR, 4); set_render_color(OUTSIDE_COLOR);
else else
set_render_color(color, 4); set_render_color(color);
} }
if (!printable) { if (!printable) {
@ -399,29 +393,29 @@ void GLVolume::set_render_color()
render_color[3] = color[3]; render_color[3] = color[3];
} }
void GLVolume::set_color_from_model_volume(const ModelVolume *model_volume) void GLVolume::set_color_from_model_volume(const ModelVolume& model_volume)
{ {
if (model_volume->is_negative_volume()) { if (model_volume.is_negative_volume()) {
color[0] = 0.2f; color[0] = 0.2f;
color[1] = 0.2f; color[1] = 0.2f;
color[2] = 0.2f; color[2] = 0.2f;
} }
else if (model_volume->is_modifier()) { else if (model_volume.is_modifier()) {
color[0] = 0.2f; color[0] = 0.2f;
color[1] = 1.0f; color[1] = 1.0f;
color[2] = 0.2f; color[2] = 0.2f;
} }
else if (model_volume->is_support_blocker()) { else if (model_volume.is_support_blocker()) {
color[0] = 1.0f; color[0] = 1.0f;
color[1] = 0.2f; color[1] = 0.2f;
color[2] = 0.2f; color[2] = 0.2f;
} }
else if (model_volume->is_support_enforcer()) { else if (model_volume.is_support_enforcer()) {
color[0] = 0.2f; color[0] = 0.2f;
color[1] = 0.2f; color[1] = 0.2f;
color[2] = 1.0f; color[2] = 1.0f;
} }
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; color[3] = model_volume.is_model_part() ? 1.f : 0.5f;
} }
Transform3d GLVolume::world_matrix() const Transform3d GLVolume::world_matrix() const
@ -571,22 +565,11 @@ int GLVolumeCollection::load_object_volume(
const int extruder_id = model_volume->extruder_id(); const int extruder_id = model_volume->extruder_id();
const ModelInstance *instance = model_object->instances[instance_idx]; const ModelInstance *instance = model_object->instances[instance_idx];
const TriangleMesh &mesh = model_volume->mesh(); const TriangleMesh &mesh = model_volume->mesh();
float color[4]; std::array<float, 4> color = GLVolume::MODEL_COLOR[((color_by == "volume") ? volume_idx : obj_idx) % 4];
memcpy(color, GLVolume::MODEL_COLOR[((color_by == "volume") ? volume_idx : obj_idx) % 4], sizeof(float) * 3);
/* if (model_volume->is_support_blocker()) {
color[0] = 1.0f;
color[1] = 0.2f;
color[2] = 0.2f;
} else if (model_volume->is_support_enforcer()) {
color[0] = 0.2f;
color[1] = 0.2f;
color[2] = 1.0f;
}
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; */
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; color[3] = model_volume->is_model_part() ? 1.f : 0.5f;
this->volumes.emplace_back(new GLVolume(color)); this->volumes.emplace_back(new GLVolume(color));
GLVolume& v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
v.set_color_from_model_volume(model_volume); v.set_color_from_model_volume(*model_volume);
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
v.indexed_vertex_array.load_mesh(mesh, true); v.indexed_vertex_array.load_mesh(mesh, true);
#else #else
@ -664,7 +647,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
height = 0.1f; height = 0.1f;
TriangleMesh mesh; TriangleMesh mesh;
float color[4] = { 0.5f, 0.5f, 0.0f, 1.f }; std::array<float, 4> color = { 0.5f, 0.5f, 0.0f, 1.0f };
// In case we don't know precise dimensions of the wipe tower yet, we'll draw // In case we don't know precise dimensions of the wipe tower yet, we'll draw
// the box with different color with one side jagged: // the box with different color with one side jagged:
@ -712,8 +695,8 @@ int GLVolumeCollection::load_wipe_tower_preview(
brim_mesh.translate(-brim_width, -brim_width, 0.f); brim_mesh.translate(-brim_width, -brim_width, 0.f);
mesh.merge(brim_mesh); mesh.merge(brim_mesh);
this->volumes.emplace_back(new GLVolume(color)); volumes.emplace_back(new GLVolume(color));
GLVolume& v = *this->volumes.back(); GLVolume& v = *volumes.back();
v.indexed_vertex_array.load_mesh(mesh); v.indexed_vertex_array.load_mesh(mesh);
v.indexed_vertex_array.finalize_geometry(opengl_initialized); v.indexed_vertex_array.finalize_geometry(opengl_initialized);
v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0)); v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0));
@ -723,17 +706,17 @@ int GLVolumeCollection::load_wipe_tower_preview(
v.geometry_id.second = wipe_tower_instance_id().id; v.geometry_id.second = wipe_tower_instance_id().id;
v.is_wipe_tower = true; v.is_wipe_tower = true;
v.shader_outside_printer_detection_enabled = !size_unknown; v.shader_outside_printer_detection_enabled = !size_unknown;
return int(this->volumes.size() - 1); return int(volumes.size() - 1);
} }
GLVolume* GLVolumeCollection::new_toolpath_volume(const float *rgba, size_t reserve_vbo_floats) GLVolume* GLVolumeCollection::new_toolpath_volume(const std::array<float, 4>& rgba, size_t reserve_vbo_floats)
{ {
GLVolume *out = new_nontoolpath_volume(rgba, reserve_vbo_floats); GLVolume *out = new_nontoolpath_volume(rgba, reserve_vbo_floats);
out->is_extrusion_path = true; out->is_extrusion_path = true;
return out; return out;
} }
GLVolume* GLVolumeCollection::new_nontoolpath_volume(const float *rgba, size_t reserve_vbo_floats) GLVolume* GLVolumeCollection::new_nontoolpath_volume(const std::array<float, 4>& rgba, size_t reserve_vbo_floats)
{ {
GLVolume *out = new GLVolume(rgba); GLVolume *out = new GLVolume(rgba);
out->is_extrusion_path = false; out->is_extrusion_path = false;
@ -812,15 +795,11 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func); GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
for (GLVolumeWithIdAndZ& volume : to_render) { for (GLVolumeWithIdAndZ& volume : to_render) {
volume.first->set_render_color(); volume.first->set_render_color();
shader->set_uniform("uniform_color", volume.first->render_color, 4); shader->set_uniform("uniform_color", volume.first->render_color);
shader->set_uniform("print_box.actived", volume.first->shader_outside_printer_detection_enabled); shader->set_uniform("print_box.actived", volume.first->shader_outside_printer_detection_enabled);
shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix()); shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix());
shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower); shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower);
shader->set_uniform("slope.volume_world_normal_matrix", static_cast<Matrix3f>(volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>())); shader->set_uniform("slope.volume_world_normal_matrix", static_cast<Matrix3f>(volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>()));
#if ENABLE_ALLOW_NEGATIVE_Z
shader->set_uniform("sinking", volume.first->is_sinking());
#endif // ENABLE_ALLOW_NEGATIVE_Z
volume.first->render(); volume.first->render();
} }

View file

@ -236,16 +236,16 @@ private:
class GLVolume { class GLVolume {
public: public:
static const float SELECTED_COLOR[4]; static const std::array<float, 4> SELECTED_COLOR;
static const float HOVER_SELECT_COLOR[4]; static const std::array<float, 4> HOVER_SELECT_COLOR;
static const float HOVER_DESELECT_COLOR[4]; static const std::array<float, 4> HOVER_DESELECT_COLOR;
static const float OUTSIDE_COLOR[4]; static const std::array<float, 4> OUTSIDE_COLOR;
static const float SELECTED_OUTSIDE_COLOR[4]; static const std::array<float, 4> SELECTED_OUTSIDE_COLOR;
static const float DISABLED_COLOR[4]; static const std::array<float, 4> DISABLED_COLOR;
static const float MODEL_COLOR[4][4]; static const std::array<float, 4> SLA_SUPPORT_COLOR;
static const float SLA_SUPPORT_COLOR[4]; static const std::array<float, 4> SLA_PAD_COLOR;
static const float SLA_PAD_COLOR[4]; static const std::array<float, 4> NEUTRAL_COLOR;
static const float NEUTRAL_COLOR[4]; static const std::array<std::array<float, 4>, 4> MODEL_COLOR;
enum EHoverState : unsigned char enum EHoverState : unsigned char
{ {
@ -255,7 +255,7 @@ public:
}; };
GLVolume(float r = 1.f, float g = 1.f, float b = 1.f, float a = 1.f); GLVolume(float r = 1.f, float g = 1.f, float b = 1.f, float a = 1.f);
GLVolume(const float *rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {} GLVolume(const std::array<float, 4>& rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {}
private: private:
Geometry::Transformation m_instance_transformation; Geometry::Transformation m_instance_transformation;
@ -276,9 +276,10 @@ private:
public: public:
// Color of the triangles / quads held by this volume. // Color of the triangles / quads held by this volume.
float color[4]; std::array<float, 4> color;
// Color used to render this volume. // Color used to render this volume.
float render_color[4]; std::array<float, 4> render_color;
struct CompositeID { struct CompositeID {
CompositeID(int object_id, int volume_id, int instance_id) : object_id(object_id), volume_id(volume_id), instance_id(instance_id) {} CompositeID(int object_id, int volume_id, int instance_id) : object_id(object_id), volume_id(volume_id), instance_id(instance_id) {}
CompositeID() : object_id(-1), volume_id(-1), instance_id(-1) {} CompositeID() : object_id(-1), volume_id(-1), instance_id(-1) {}
@ -362,11 +363,11 @@ public:
} }
void set_render_color(float r, float g, float b, float a); void set_render_color(float r, float g, float b, float a);
void set_render_color(const float* rgba, unsigned int size); void set_render_color(const std::array<float, 4>& rgba);
// Sets render color in dependence of current state // Sets render color in dependence of current state
void set_render_color(); void set_render_color();
// set color according to model volume // set color according to model volume
void set_color_from_model_volume(const ModelVolume *model_volume); void set_color_from_model_volume(const ModelVolume& model_volume);
const Geometry::Transformation& get_instance_transformation() const { return m_instance_transformation; } const Geometry::Transformation& get_instance_transformation() const { return m_instance_transformation; }
void set_instance_transformation(const Geometry::Transformation& transformation) { m_instance_transformation = transformation; set_bounding_boxes_as_dirty(); } void set_instance_transformation(const Geometry::Transformation& transformation) { m_instance_transformation = transformation; set_bounding_boxes_as_dirty(); }
@ -542,8 +543,8 @@ public:
int load_wipe_tower_preview( int load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized); int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized);
GLVolume* new_toolpath_volume(const float *rgba, size_t reserve_vbo_floats = 0); GLVolume* new_toolpath_volume(const std::array<float, 4>& rgba, size_t reserve_vbo_floats = 0);
GLVolume* new_nontoolpath_volume(const float *rgba, size_t reserve_vbo_floats = 0); GLVolume* new_nontoolpath_volume(const std::array<float, 4>& rgba, size_t reserve_vbo_floats = 0);
// Render the volumes by OpenGL. // Render the volumes by OpenGL.
void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const; void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;

View file

@ -166,7 +166,7 @@ int BitmapComboBox::Append(const wxString& item)
//2. But then set width to 0 value for no using of bitmap left and right spacing //2. But then set width to 0 value for no using of bitmap left and right spacing
//3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct //3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct
wxBitmap bitmap(1, this->GetFont().GetPixelSize().y + 2); wxBitmap bitmap(1, int(1.6 * wxGetApp().em_unit() + 1));
bitmap.SetWidth(0); bitmap.SetWidth(0);
OnAddBitmap(bitmap); OnAddBitmap(bitmap);
@ -260,6 +260,21 @@ void BitmapComboBox::DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED(
dc.DrawRectangle(rect); dc.DrawRectangle(rect);
} }
} }
void BitmapComboBox::Rescale()
{
// Next workaround: To correct scaling of a BitmapCombobox
// we need to refill control with new bitmaps
const wxString selection = this->GetValue();
std::vector<wxString> items;
for (size_t i = 0; i < GetCount(); i++)
items.push_back(GetString(i));
this->Clear();
for (const wxString& item : items)
Append(item);
this->SetValue(selection);
}
#endif #endif
}} }}

View file

@ -54,6 +54,8 @@ void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const overrid
#ifdef _WIN32 #ifdef _WIN32
bool MSWOnDraw(WXDRAWITEMSTRUCT* item) override; bool MSWOnDraw(WXDRAWITEMSTRUCT* item) override;
void DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED(item), int flags) const; void DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED(item), int flags) const;
public:
void Rescale();
#endif #endif
}; };

View file

@ -1296,6 +1296,9 @@ void Choice::msw_rescale()
field->SetValue(selection) : field->SetValue(selection) :
field->SetSelection(idx); field->SetSelection(idx);
#else #else
#ifdef _WIN32
field->Rescale();
#endif
auto size = wxSize(def_width_wider() * m_em_unit, wxDefaultCoord); auto size = wxSize(def_width_wider() * m_em_unit, wxDefaultCoord);
if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit); if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit);
if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit); if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit);

View file

@ -1881,7 +1881,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
volume->extruder_id = extruder_id; volume->extruder_id = extruder_id;
volume->is_modifier = !mvs->model_volume->is_model_part(); volume->is_modifier = !mvs->model_volume->is_model_part();
volume->set_color_from_model_volume(mvs->model_volume); volume->set_color_from_model_volume(*mvs->model_volume);
// updates volumes transformations // updates volumes transformations
volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_transformation()); volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_transformation());
@ -5710,7 +5710,7 @@ void GLCanvas3D::_load_print_toolpaths()
if (!print->has_skirt() && !print->has_brim()) if (!print->has_skirt() && !print->has_brim())
return; return;
const float color[] = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish const std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish
// number of skirt layers // number of skirt layers
size_t total_layer_count = 0; size_t total_layer_count = 0;
@ -5756,7 +5756,7 @@ void GLCanvas3D::_load_print_toolpaths()
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<CustomGCode::Item>& color_print_values) void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<CustomGCode::Item>& color_print_values)
{ {
std::vector<float> tool_colors = _parse_colors(str_tool_colors); std::vector<std::array<float, 4>> tool_colors = _parse_colors(str_tool_colors);
struct Ctxt struct Ctxt
{ {
@ -5765,20 +5765,20 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
bool has_perimeters; bool has_perimeters;
bool has_infill; bool has_infill;
bool has_support; bool has_support;
const std::vector<float>* tool_colors; const std::vector<std::array<float, 4>>* tool_colors;
bool is_single_material_print; bool is_single_material_print;
int extruders_cnt; int extruders_cnt;
const std::vector<CustomGCode::Item>* color_print_values; const std::vector<CustomGCode::Item>* color_print_values;
static const float* color_perimeters() { static float color[4] = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow static const std::array<float, 4>& color_perimeters() { static std::array<float, 4> color = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow
static const float* color_infill() { static float color[4] = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish static const std::array<float, 4>& color_infill() { static std::array<float, 4> color = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish
static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish static const std::array<float, 4>& color_support() { static std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
static const float* color_pause_or_custom_code() { static float color[4] = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray static const std::array<float, 4>& color_pause_or_custom_code() { static std::array<float, 4> color = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray
// For cloring by a tool, return a parsed color. // For cloring by a tool, return a parsed color.
bool color_by_tool() const { return tool_colors != nullptr; } bool color_by_tool() const { return tool_colors != nullptr; }
size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; } size_t number_tools() const { return color_by_tool() ? tool_colors->size() : 0; }
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; } const std::array<float, 4>& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
// For coloring by a color_print(M600), return a parsed color. // For coloring by a color_print(M600), return a parsed color.
bool color_by_color_print() const { return color_print_values!=nullptr; } bool color_by_color_print() const { return color_print_values!=nullptr; }
@ -5918,8 +5918,8 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
//FIXME Improve the heuristics for a grain size. //FIXME Improve the heuristics for a grain size.
size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1)); size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1));
tbb::spin_mutex new_volume_mutex; tbb::spin_mutex new_volume_mutex;
auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* { auto new_volume = [this, &new_volume_mutex](const std::array<float, 4>& color) {
// Allocate the volume before locking. // Allocate the volume before locking.
GLVolume *volume = new GLVolume(color); GLVolume *volume = new GLVolume(color);
volume->is_extrusion_path = true; volume->is_extrusion_path = true;
tbb::spin_mutex::scoped_lock lock; tbb::spin_mutex::scoped_lock lock;
@ -6056,23 +6056,22 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector<std::string>& str_
if (!print->is_step_done(psWipeTower)) if (!print->is_step_done(psWipeTower))
return; return;
std::vector<float> tool_colors = _parse_colors(str_tool_colors); std::vector<std::array<float, 4>> tool_colors = _parse_colors(str_tool_colors);
struct Ctxt struct Ctxt
{ {
const Print *print; const Print *print;
const std::vector<float> *tool_colors; const std::vector<std::array<float, 4>>* tool_colors;
Vec2f wipe_tower_pos; Vec2f wipe_tower_pos;
float wipe_tower_angle; float wipe_tower_angle;
static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish static const std::array<float, 4>& color_support() { static std::array<float, 4> color = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish
// For cloring by a tool, return a parsed color. // For cloring by a tool, return a parsed color.
bool color_by_tool() const { return tool_colors != nullptr; } bool color_by_tool() const { return tool_colors != nullptr; }
size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; } size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() : 0; }
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; } const std::array<float, 4>& color_tool(size_t tool) const { return (*tool_colors)[tool]; }
int volume_idx(int tool, int feature) const int volume_idx(int tool, int feature) const {
{
return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(tool, 0)) : feature; return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(tool, 0)) : feature;
} }
@ -6103,7 +6102,7 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector<std::string>& str_
size_t n_items = print->wipe_tower_data().tool_changes.size() + (ctxt.priming.empty() ? 0 : 1); size_t n_items = print->wipe_tower_data().tool_changes.size() + (ctxt.priming.empty() ? 0 : 1);
size_t grain_size = std::max(n_items / 128, size_t(1)); size_t grain_size = std::max(n_items / 128, size_t(1));
tbb::spin_mutex new_volume_mutex; tbb::spin_mutex new_volume_mutex;
auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* { auto new_volume = [this, &new_volume_mutex](const std::array<float, 4>& color) {
auto *volume = new GLVolume(color); auto *volume = new GLVolume(color);
volume->is_extrusion_path = true; volume->is_extrusion_path = true;
tbb::spin_mutex::scoped_lock lock; tbb::spin_mutex::scoped_lock lock;
@ -6219,7 +6218,7 @@ void GLCanvas3D::_load_sla_shells()
return; return;
auto add_volume = [this](const SLAPrintObject &object, int volume_id, const SLAPrintObject::Instance& instance, auto add_volume = [this](const SLAPrintObject &object, int volume_id, const SLAPrintObject::Instance& instance,
const TriangleMesh &mesh, const float color[4], bool outside_printer_detection_enabled) { const TriangleMesh& mesh, const std::array<float, 4>& color, bool outside_printer_detection_enabled) {
m_volumes.volumes.emplace_back(new GLVolume(color)); m_volumes.volumes.emplace_back(new GLVolume(color));
GLVolume& v = *m_volumes.volumes.back(); GLVolume& v = *m_volumes.volumes.back();
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
@ -6230,8 +6229,8 @@ void GLCanvas3D::_load_sla_shells()
v.indexed_vertex_array.finalize_geometry(m_initialized); v.indexed_vertex_array.finalize_geometry(m_initialized);
v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled; v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled;
v.composite_id.volume_id = volume_id; v.composite_id.volume_id = volume_id;
v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0)); v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0.0));
v.set_instance_rotation(Vec3d(0.0, 0.0, (double)instance.rotation)); v.set_instance_rotation({ 0.0, 0.0, (double)instance.rotation });
v.set_instance_mirror(X, object.is_left_handed() ? -1. : 1.); v.set_instance_mirror(X, object.is_left_handed() ? -1. : 1.);
v.set_convex_hull(mesh.convex_hull_3d()); v.set_convex_hull(mesh.convex_hull_3d());
}; };
@ -6252,9 +6251,8 @@ void GLCanvas3D::_load_sla_shells()
} }
double shift_z = obj->get_current_elevation(); double shift_z = obj->get_current_elevation();
for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) { for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) {
GLVolume& v = *m_volumes.volumes[i];
// apply shift z // apply shift z
v.set_sla_shift_z(shift_z); m_volumes.volumes[i]->set_sla_shift_z(shift_z);
} }
} }
@ -6265,7 +6263,7 @@ void GLCanvas3D::_update_toolpath_volumes_outside_state()
{ {
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
for (GLVolume* volume : m_volumes.volumes) { for (GLVolume* volume : m_volumes.volumes) {
volume->is_outside = ((test_volume.radius() > 0.0) && volume->is_extrusion_path) ? !test_volume.contains(volume->bounding_box()) : false; volume->is_outside = (test_volume.radius() > 0.0 && volume->is_extrusion_path) ? !test_volume.contains(volume->bounding_box()) : false;
} }
} }
@ -6273,7 +6271,7 @@ void GLCanvas3D::_update_sla_shells_outside_state()
{ {
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
for (GLVolume* volume : m_volumes.volumes) { for (GLVolume* volume : m_volumes.volumes) {
volume->is_outside = ((test_volume.radius() > 0.0) && volume->shader_outside_printer_detection_enabled) ? !test_volume.contains(volume->transformed_convex_hull_bounding_box()) : false; volume->is_outside = (test_volume.radius() > 0.0 && volume->shader_outside_printer_detection_enabled) ? !test_volume.contains(volume->transformed_convex_hull_bounding_box()) : false;
} }
} }
@ -6294,11 +6292,11 @@ void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning)
_set_warning_notification(warning, show); _set_warning_notification(warning, show);
} }
std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors) std::vector<std::array<float, 4>> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
{ {
static const float INV_255 = 1.0f / 255.0f; static const float INV_255 = 1.0f / 255.0f;
std::vector<float> output(colors.size() * 4, 1.0f); std::vector<std::array<float, 4>> output(colors.size(), { 1.0f, 1.0f, 1.0f, 1.0f });
for (size_t i = 0; i < colors.size(); ++i) { for (size_t i = 0; i < colors.size(); ++i) {
const std::string& color = colors[i]; const std::string& color = colors[i];
const char* c = color.data() + 1; const char* c = color.data() + 1;
@ -6309,7 +6307,7 @@ std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& col
if (digit1 == -1 || digit2 == -1) if (digit1 == -1 || digit2 == -1)
break; break;
output[i * 4 + j] = float(digit1 * 16 + digit2) * INV_255; output[i][j] = float(digit1 * 16 + digit2) * INV_255;
} }
} }
} }

View file

@ -907,7 +907,7 @@ private:
float get_overlay_window_width() { return LayersEditing::get_overlay_window_width(); } float get_overlay_window_width() { return LayersEditing::get_overlay_window_width(); }
static std::vector<float> _parse_colors(const std::vector<std::string>& colors); static std::vector<std::array<float, 4>> _parse_colors(const std::vector<std::string>& colors);
}; };
} // namespace GUI } // namespace GUI

View file

@ -2670,11 +2670,16 @@ void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& it
if (item->type&itVolume) if (item->type&itVolume)
{ {
m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item->obj_idx, item->sub_obj_idx)); m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item->obj_idx, item->sub_obj_idx));
if ((*m_objects)[item->obj_idx]->volumes.size() == 1 && ModelObject* obj = object(item->obj_idx);
(*m_objects)[item->obj_idx]->config.has("extruder")) if (obj->volumes.size() == 1) {
{ wxDataViewItem parent = m_objects_model->GetItemById(item->obj_idx);
const wxString extruder = wxString::Format("%d", (*m_objects)[item->obj_idx]->config.extruder()); if (obj->config.has("extruder")) {
m_objects_model->SetExtruder(extruder, m_objects_model->GetItemById(item->obj_idx)); const wxString extruder = wxString::Format("%d", obj->config.extruder());
m_objects_model->SetExtruder(extruder, parent);
}
// If last volume item with warning was deleted, unmark object item
if (obj->get_mesh_errors_count() == 0)
m_objects_model->DeleteWarningIcon(parent);
} }
wxGetApp().plater()->canvas3D()->ensure_on_bed(item->obj_idx); wxGetApp().plater()->canvas3D()->ensure_on_bed(item->obj_idx);
} }

View file

@ -106,6 +106,9 @@ void msw_rescale_word_local_combo(choice_ctrl* combo)
combo->SetValue(selection); combo->SetValue(selection);
#else #else
#ifdef _WIN32
combo->Rescale();
#endif
combo->SetMinSize(wxSize(15 * wxGetApp().em_unit(), -1)); combo->SetMinSize(wxSize(15 * wxGetApp().em_unit(), -1));
#endif #endif
} }

View file

@ -402,6 +402,10 @@ void Preview::refresh_print()
void Preview::msw_rescale() void Preview::msw_rescale()
{ {
#ifdef _WIN32
m_choice_view_type->Rescale();
m_choice_view_type->SetMinSize(m_choice_view_type->GetSize());
#endif
// rescale slider // rescale slider
if (m_layers_slider != nullptr) m_layers_slider->msw_rescale(); if (m_layers_slider != nullptr) m_layers_slider->msw_rescale();
if (m_moves_slider != nullptr) m_moves_slider->msw_rescale(); if (m_moves_slider != nullptr) m_moves_slider->msw_rescale();

View file

@ -179,8 +179,8 @@ static void add_lock(wxImage& image)
size_t beg_x = width - lock_width; size_t beg_x = width - lock_width;
size_t beg_y = height - lock_height; size_t beg_y = height - lock_height;
for (size_t x = 0; x < lock_width; ++x) { for (size_t x = 0; x < (size_t)lock_width; ++x) {
for (size_t y = 0; y < lock_height; ++y) { for (size_t y = 0; y < (size_t)lock_height; ++y) {
const size_t lock_idx = (x + y * lock_width); const size_t lock_idx = (x + y * lock_width);
if (lock_a_data && lock_a_data[lock_idx] == 0) if (lock_a_data && lock_a_data[lock_idx] == 0)
continue; continue;

View file

@ -17,13 +17,20 @@ ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, bool add_mode_buttons/* = fal
SetDoubleBuffered(true); SetDoubleBuffered(true);
#endif //__WINDOWS__ #endif //__WINDOWS__
int em = em_unit(this);// Slic3r::GUI::wxGetApp().em_unit();
m_btn_margin = std::lround(0.3 * em);
m_line_margin = std::lround(0.1 * em);
m_sizer = new wxBoxSizer(wxHORIZONTAL); m_sizer = new wxBoxSizer(wxHORIZONTAL);
this->SetSizer(m_sizer); this->SetSizer(m_sizer);
m_buttons_sizer = new wxFlexGridSizer(4, m_btn_margin, m_btn_margin);
m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);
if (add_mode_buttons) { if (add_mode_buttons) {
m_mode_sizer = new ModeSizer(this, int(0.5 * em_unit(this))); m_mode_sizer = new ModeSizer(this, m_btn_margin);
m_sizer->AddStretchSpacer(20); m_sizer->AddStretchSpacer(20);
m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin);
} }
this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this); this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this);
@ -53,12 +60,12 @@ void ButtonsListCtrl::OnPaint(wxPaintEvent&)
const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg; const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg;
dc.SetPen(clr); dc.SetPen(clr);
dc.SetBrush(clr); dc.SetBrush(clr);
dc.DrawRectangle(pos.x, sz.y - 3, size.x, 3); dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);
} }
dc.SetPen(btn_marker_color); dc.SetPen(btn_marker_color);
dc.SetBrush(btn_marker_color); dc.SetBrush(btn_marker_color);
dc.DrawRectangle(1, sz.y - 1, sz.x, 1); dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin);
} }
void ButtonsListCtrl::UpdateMode() void ButtonsListCtrl::UpdateMode()
@ -71,6 +78,14 @@ void ButtonsListCtrl::Rescale()
m_mode_sizer->msw_rescale(); m_mode_sizer->msw_rescale();
for (ScalableButton* btn : m_pageButtons) for (ScalableButton* btn : m_pageButtons)
btn->msw_rescale(); btn->msw_rescale();
int em = em_unit(this);
m_btn_margin = std::lround(0.3 * em);
m_line_margin = std::lround(0.1 * em);
m_buttons_sizer->SetVGap(m_btn_margin);
m_buttons_sizer->SetHGap(m_btn_margin);
m_sizer->Layout();
} }
void ButtonsListCtrl::SetSelection(int sel) void ButtonsListCtrl::SetSelection(int sel)
@ -95,7 +110,7 @@ bool ButtonsListCtrl::InsertPage(size_t n, const wxString& text, bool bSelect/*
}); });
Slic3r::GUI::wxGetApp().UpdateDarkUI(btn); Slic3r::GUI::wxGetApp().UpdateDarkUI(btn);
m_pageButtons.insert(m_pageButtons.begin() + n, btn); m_pageButtons.insert(m_pageButtons.begin() + n, btn);
m_sizer->Insert(n, new wxSizerItem(btn, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3)); m_buttons_sizer->Insert(n, new wxSizerItem(btn));
m_sizer->Layout(); m_sizer->Layout();
return true; return true;
} }
@ -104,7 +119,7 @@ void ButtonsListCtrl::RemovePage(size_t n)
{ {
ScalableButton* btn = m_pageButtons[n]; ScalableButton* btn = m_pageButtons[n];
m_pageButtons.erase(m_pageButtons.begin() + n); m_pageButtons.erase(m_pageButtons.begin() + n);
m_sizer->Remove(n); m_buttons_sizer->Remove(n);
btn->Reparent(nullptr); btn->Reparent(nullptr);
btn->Destroy(); btn->Destroy();
m_sizer->Layout(); m_sizer->Layout();

View file

@ -29,9 +29,12 @@ public:
private: private:
wxWindow* m_parent; wxWindow* m_parent;
wxFlexGridSizer* m_buttons_sizer;
wxBoxSizer* m_sizer; wxBoxSizer* m_sizer;
std::vector<ScalableButton*> m_pageButtons; std::vector<ScalableButton*> m_pageButtons;
int m_selection {-1}; int m_selection {-1};
int m_btn_margin;
int m_line_margin;
ModeSizer* m_mode_sizer {nullptr}; ModeSizer* m_mode_sizer {nullptr};
}; };

View file

@ -747,6 +747,10 @@ void ConfigOptionsGroup::sys_color_changed()
wxGetApp().UpdateDarkUI(extra_col); wxGetApp().UpdateDarkUI(extra_col);
} }
if (custom_ctrl)
wxGetApp().UpdateDarkUI(custom_ctrl);
#endif
auto update = [](wxSizer* sizer) { auto update = [](wxSizer* sizer) {
for (wxSizerItem* item : sizer->GetChildren()) for (wxSizerItem* item : sizer->GetChildren())
if (item->IsWindow()) { if (item->IsWindow()) {
@ -768,10 +772,6 @@ void ConfigOptionsGroup::sys_color_changed()
update(line.extra_widget_sizer); update(line.extra_widget_sizer);
} }
if (custom_ctrl)
wxGetApp().UpdateDarkUI(custom_ctrl);
#endif
// update undo buttons : rescale bitmaps // update undo buttons : rescale bitmaps
for (const auto& field : m_fields) for (const auto& field : m_fields)
field.second->sys_color_changed(); field.second->sys_color_changed();

View file

@ -709,29 +709,12 @@ void TabPrinter::msw_rescale()
{ {
Tab::msw_rescale(); Tab::msw_rescale();
// rescale missed options_groups
const std::vector<PageShp>& pages = m_printer_technology == ptFFF ? m_pages_sla : m_pages_fff;
for (auto page : pages)
page->msw_rescale();
if (m_reset_to_filament_color) if (m_reset_to_filament_color)
m_reset_to_filament_color->msw_rescale(); m_reset_to_filament_color->msw_rescale();
Layout(); Layout();
} }
void TabPrinter::sys_color_changed()
{
Tab::sys_color_changed();
// update missed options_groups
const std::vector<PageShp>& pages = m_printer_technology == ptFFF ? m_pages_sla : m_pages_fff;
for (auto page : pages)
page->sys_color_changed();
Layout();
}
void TabSLAMaterial::init_options_list() void TabSLAMaterial::init_options_list()
{ {
if (!m_options_list.empty()) if (!m_options_list.empty())

View file

@ -485,7 +485,6 @@ public:
void on_preset_loaded() override; void on_preset_loaded() override;
void init_options_list() override; void init_options_list() override;
void msw_rescale() override; void msw_rescale() override;
void sys_color_changed() override;
#if ENABLE_PROJECT_DIRTY_STATE #if ENABLE_PROJECT_DIRTY_STATE
bool supports_printer_technology(const PrinterTechnology /* tech */) const override { return true; } bool supports_printer_technology(const PrinterTechnology /* tech */) const override { return true; }
#else #else

View file

@ -694,7 +694,9 @@ void ModeButton::focus_button(const bool focus)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 0*/) : ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 0*/) :
wxFlexGridSizer(3, 0, hgap) wxFlexGridSizer(3, 0, hgap),
m_parent(parent),
m_hgap_unscaled((double)(hgap)/em_unit(parent))
{ {
SetFlexibleDirection(wxHORIZONTAL); SetFlexibleDirection(wxHORIZONTAL);
@ -739,6 +741,7 @@ void ModeSizer::set_items_border(int border)
void ModeSizer::msw_rescale() void ModeSizer::msw_rescale()
{ {
this->SetHGap(std::lround(m_hgap_unscaled * em_unit(m_parent)));
for (size_t m = 0; m < m_mode_btns.size(); m++) for (size_t m = 0; m < m_mode_btns.size(); m++)
m_mode_btns[m]->msw_rescale(); m_mode_btns[m]->msw_rescale();
} }
@ -886,6 +889,8 @@ bool ScalableButton::SetBitmap_(const std::string& bmp_name)
wxBitmap bmp = create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt); wxBitmap bmp = create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt);
SetBitmap(bmp); SetBitmap(bmp);
SetBitmapCurrent(bmp); SetBitmapCurrent(bmp);
SetBitmapPressed(bmp);
SetBitmapFocus(bmp);
if (m_use_default_disabled_bitmap) if (m_use_default_disabled_bitmap)
SetBitmapDisabled(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt, true)); SetBitmapDisabled(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt, true));
return true; return true;
@ -917,7 +922,11 @@ void ScalableButton::msw_rescale()
Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border); Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border);
if (!m_current_icon_name.empty()) { if (!m_current_icon_name.empty()) {
SetBitmap(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt)); wxBitmap bmp = create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt);
SetBitmap(bmp);
SetBitmapCurrent(bmp);
SetBitmapPressed(bmp);
SetBitmapFocus(bmp);
if (!m_disabled_icon_name.empty()) if (!m_disabled_icon_name.empty())
SetBitmapDisabled(create_scaled_bitmap(m_disabled_icon_name, m_parent, m_px_cnt)); SetBitmapDisabled(create_scaled_bitmap(m_disabled_icon_name, m_parent, m_px_cnt));
else if (m_use_default_disabled_bitmap) else if (m_use_default_disabled_bitmap)

View file

@ -315,6 +315,8 @@ public:
private: private:
std::vector<ModeButton*> m_mode_btns; std::vector<ModeButton*> m_mode_btns;
wxWindow* m_parent {nullptr};
double m_hgap_unscaled;
}; };