diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f6ec0bd586..cd82878c2a 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -352,20 +352,16 @@ bool GLCanvas3D::LayersEditing::is_initialized() const std::string GLCanvas3D::LayersEditing::get_tooltip(const GLCanvas3D& canvas) const { std::string ret; - if (m_enabled && (m_layer_height_profile.size() >= 4)) - { + if (m_enabled && m_layer_height_profile.size() >= 4) { float z = get_cursor_z_relative(canvas); - if (z != -1000.0f) - { + if (z != -1000.0f) { z *= m_object_max_z; float h = 0.0f; - for (size_t i = m_layer_height_profile.size() - 2; i >= 2; i -= 2) - { + for (size_t i = m_layer_height_profile.size() - 2; i >= 2; i -= 2) { float zi = m_layer_height_profile[i]; float zi_1 = m_layer_height_profile[i - 2]; - if ((zi_1 <= z) && (z <= zi)) - { + if (zi_1 <= z && z <= zi) { float dz = zi - zi_1; h = (dz != 0.0f) ? lerp(m_layer_height_profile[i - 1], m_layer_height_profile[i + 1], (z - zi_1) / dz) : m_layer_height_profile[i + 1]; break; @@ -809,11 +805,9 @@ bool GLCanvas3D::WarningTexture::generate(const std::string& msg_utf8, const GLC // prepare buffer std::vector data(4 * m_width * m_height, 0); const unsigned char *src = image.GetData(); - for (int h = 0; h < m_height; ++h) - { + for (int h = 0; h < m_height; ++h) { unsigned char* dst = data.data() + 4 * h * m_width; - for (int w = 0; w < m_width; ++w) - { + for (int w = 0; w < m_width; ++w) { *dst++ = 255; if (red_colored) { *dst++ = 72; // 204 @@ -848,8 +842,7 @@ void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const if (m_warnings.empty()) return; - if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) - { + if (m_id > 0 && m_original_width > 0 && m_original_height > 0 && m_width > 0 && m_height > 0) { const Size& cnv_size = canvas.get_canvas_size(); float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); float left = (-0.5f * (float)m_original_width) * inv_zoom; @@ -880,367 +873,6 @@ void GLCanvas3D::WarningTexture::msw_rescale(const GLCanvas3D& canvas) generate(m_msg_text, canvas, true, m_is_colored_red); } -#if !ENABLE_GCODE_VIEWER -const unsigned char GLCanvas3D::LegendTexture::Squares_Border_Color[3] = { 64, 64, 64 }; -const unsigned char GLCanvas3D::LegendTexture::Default_Background_Color[3] = { (unsigned char)(DEFAULT_BG_LIGHT_COLOR[0] * 255.0f), (unsigned char)(DEFAULT_BG_LIGHT_COLOR[1] * 255.0f), (unsigned char)(DEFAULT_BG_LIGHT_COLOR[2] * 255.0f) }; -const unsigned char GLCanvas3D::LegendTexture::Error_Background_Color[3] = { (unsigned char)(ERROR_BG_LIGHT_COLOR[0] * 255.0f), (unsigned char)(ERROR_BG_LIGHT_COLOR[1] * 255.0f), (unsigned char)(ERROR_BG_LIGHT_COLOR[2] * 255.0f) }; -const unsigned char GLCanvas3D::LegendTexture::Opacity = 255; - -GLCanvas3D::LegendTexture::LegendTexture() - : GUI::GLTexture() - , m_original_width(0) - , m_original_height(0) -{ -} - -void GLCanvas3D::LegendTexture::fill_color_print_legend_items( const GLCanvas3D& canvas, - const std::vector& colors_in, - std::vector& colors, - std::vector& cp_legend_items) -{ - std::vector custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes; - - const int extruders_cnt = wxGetApp().extruders_edited_cnt(); - if (extruders_cnt == 1) - { - if (custom_gcode_per_print_z.empty()) { - cp_legend_items.emplace_back(I18N::translate_utf8(L("Default print color"))); - colors = colors_in; - return; - } - std::vector> cp_values; - cp_values.reserve(custom_gcode_per_print_z.size()); - - std::vector print_zs = canvas.get_current_print_zs(true); - for (auto custom_code : custom_gcode_per_print_z) - { - if (custom_code.type != CustomGCode::ColorChange) - continue; - auto lower_b = std::lower_bound(print_zs.begin(), print_zs.end(), custom_code.print_z - Slic3r::DoubleSlider::epsilon()); - - if (lower_b == print_zs.end()) - continue; - - double current_z = *lower_b; - double previous_z = lower_b == print_zs.begin() ? 0.0 : *(--lower_b); - - // to avoid duplicate values, check adding values - if (cp_values.empty() || - !(cp_values.back().first == previous_z && cp_values.back().second == current_z)) - cp_values.emplace_back(std::pair(previous_z, current_z)); - } - - const auto items_cnt = (int)cp_values.size(); - if (items_cnt == 0) // There is no one color change, but there is/are some pause print or custom Gcode - { - cp_legend_items.emplace_back(I18N::translate_utf8(L("Default print color"))); - cp_legend_items.emplace_back(I18N::translate_utf8(L("Pause print or custom G-code"))); - colors = colors_in; - return; - } - - const int color_cnt = (int)colors_in.size() / 4; - colors.resize(colors_in.size(), 0.0); - - ::memcpy((void*)(colors.data()), (const void*)(colors_in.data() + (color_cnt - 1) * 4), 4 * sizeof(float)); - cp_legend_items.emplace_back(I18N::translate_utf8(L("Pause print or custom G-code"))); - size_t color_pos = 4; - - for (int i = items_cnt; i >= 0; --i, color_pos+=4) - { - // update colors for color print item - ::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + i * 4), 4 * sizeof(float)); - - // create label for color print item - std::string id_str = std::to_string(i + 1) + ": "; - - if (i == 0) { - cp_legend_items.emplace_back(id_str + (boost::format(I18N::translate_utf8(L("up to %.2f mm"))) % cp_values[0].first).str()); - break; - } - if (i == items_cnt) { - cp_legend_items.emplace_back(id_str + (boost::format(I18N::translate_utf8(L("above %.2f mm"))) % cp_values[i - 1].second).str()); - continue; - } - - cp_legend_items.emplace_back(id_str + (boost::format(I18N::translate_utf8(L("%.2f - %.2f mm"))) % cp_values[i - 1].second % cp_values[i].first).str()); - } - } - else - { - // colors = colors_in; - const int color_cnt = (int)colors_in.size() / 4; - colors.resize(colors_in.size(), 0.0); - - ::memcpy((void*)(colors.data()), (const void*)(colors_in.data()), 4 * extruders_cnt * sizeof(float)); - size_t color_pos = 4 * extruders_cnt; - size_t color_in_pos = 4 * (color_cnt - 1); - - for (unsigned int i = 0; i < (unsigned int)extruders_cnt; ++i) - cp_legend_items.emplace_back((boost::format(I18N::translate_utf8(L("Extruder %d"))) % (i + 1)).str()); - - ::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + color_in_pos), 4 * sizeof(float)); - color_pos += 4; - color_in_pos -= 4; - cp_legend_items.emplace_back(I18N::translate_utf8(L("Pause print or custom G-code"))); - - int cnt = custom_gcode_per_print_z.size(); - int color_change_idx = color_cnt - extruders_cnt; - for (int i = cnt-1; i >= 0; --i) - if (custom_gcode_per_print_z[i].type == CustomGCode::ColorChange) { - ::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + color_in_pos), 4 * sizeof(float)); - color_pos += 4; - color_in_pos -= 4; - - // create label for color change item - std::string id_str = std::to_string(color_change_idx--) + ": "; - - cp_legend_items.emplace_back(id_str + (boost::format(I18N::translate_utf8(L("Color change for Extruder %d at %.2f mm"))) % custom_gcode_per_print_z[i].extruder % custom_gcode_per_print_z[i].print_z).str()); - } - } -} - -bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector& tool_colors_in, const GLCanvas3D& canvas, bool compress) -{ - reset(); - - // collects items to render - auto title = _(preview_data.get_legend_title()); - - std::vector cp_legend_items; - std::vector cp_colors; - - if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint) - { - cp_legend_items.reserve(cp_colors.size()); - fill_color_print_legend_items(canvas, tool_colors_in, cp_colors, cp_legend_items); - } - - const std::vector& tool_colors = preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint ? cp_colors : tool_colors_in; - const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, cp_legend_items); - - unsigned int items_count = (unsigned int)items.size(); - if (items_count == 0) - // nothing to render, return - return false; - - wxMemoryDC memDC; - wxMemoryDC mask_memDC; - - // calculate scaling - const float scale_gl = canvas.get_canvas_size().get_scale_factor(); -#if ENABLE_RETINA_GL - // For non-visible or non-created window getBackingScaleFactor function return 0.0 value. - // And using of the zero scale causes a crash, when we trying to draw text to the (0,0) rectangle - if (scale_gl <= 0.0f) - return false; -#endif - const float scale = scale_gl * wxGetApp().em_unit()*0.1; // get scale from em_unit() value, because of get_scale_factor() return 1 - const int scaled_square = std::floor((float)Px_Square * scale); - const int scaled_title_offset = Px_Title_Offset * scale; - const int scaled_text_offset = Px_Text_Offset * scale; - const int scaled_square_contour = Px_Square_Contour * scale; - const int scaled_border = Px_Border * scale; - -#ifdef __WXMSW__ - // set scaled application normal font as default font - wxFont font = wxGetApp().normal_font(); - - // Disabling ClearType works, but the font returned is very different (much thicker) from the default. -// msw_disable_cleartype(font); -// bool cleartype = is_font_cleartype(font); -#else - // select default font - wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Scale(scale_gl); -// bool cleartype = false; -#endif /* __WXMSW__ */ - - memDC.SetFont(font); - mask_memDC.SetFont(font); - - // calculates texture size - wxCoord w, h; - memDC.GetTextExtent(title, &w, &h); - int title_width = (int)w; - int title_height = (int)h; - - int max_text_width = 0; - int max_text_height = 0; - for (const GCodePreviewData::LegendItem& item : items) - { - memDC.GetTextExtent(GUI::from_u8(item.text), &w, &h); - max_text_width = std::max(max_text_width, (int)w); - max_text_height = std::max(max_text_height, (int)h); - } - - m_original_width = std::max(2 * scaled_border + title_width, 2 * (scaled_border + scaled_square_contour) + scaled_square + scaled_text_offset + max_text_width); - m_original_height = 2 * (scaled_border + scaled_square_contour) + title_height + scaled_title_offset + items_count * scaled_square; - if (items_count > 1) - m_original_height += (items_count - 1) * scaled_square_contour; - - m_width = (int)next_highest_power_of_2((uint32_t)m_original_width); - m_height = (int)next_highest_power_of_2((uint32_t)m_original_height); - - // generates bitmap - wxBitmap bitmap(m_width, m_height); - wxBitmap mask(m_width, m_height); - - memDC.SelectObject(bitmap); - mask_memDC.SelectObject(mask); - - memDC.SetBackground(wxBrush(*wxBLACK)); - mask_memDC.SetBackground(wxBrush(*wxBLACK)); - - memDC.Clear(); - mask_memDC.Clear(); - - // draw title - memDC.SetTextForeground(*wxWHITE); - mask_memDC.SetTextForeground(*wxRED); - - int title_x = scaled_border; - int title_y = scaled_border; - memDC.DrawText(title, title_x, title_y); - mask_memDC.DrawText(title, title_x, title_y); - - // draw icons contours as background - int squares_contour_x = scaled_border; - int squares_contour_y = scaled_border + title_height + scaled_title_offset; - int squares_contour_width = scaled_square + 2 * scaled_square_contour; - int squares_contour_height = items_count * scaled_square + 2 * scaled_square_contour; - if (items_count > 1) - squares_contour_height += (items_count - 1) * scaled_square_contour; - - wxColour color(Squares_Border_Color[0], Squares_Border_Color[1], Squares_Border_Color[2]); - wxPen pen(color); - wxBrush brush(color); - memDC.SetPen(pen); - memDC.SetBrush(brush); - memDC.DrawRectangle(wxRect(squares_contour_x, squares_contour_y, squares_contour_width, squares_contour_height)); - - // draw items (colored icon + text) - int icon_x = squares_contour_x + scaled_square_contour; - int icon_x_inner = icon_x + 1; - int icon_y = squares_contour_y + scaled_square_contour; - int icon_y_step = scaled_square + scaled_square_contour; - - int text_x = icon_x + scaled_square + scaled_text_offset; - int text_y_offset = (scaled_square - max_text_height) / 2; - - int px_inner_square = scaled_square - 2; - - for (const GCodePreviewData::LegendItem& item : items) - { - // draw darker icon perimeter - const std::vector& item_color_bytes = item.color.as_bytes(); - wxImage::HSVValue dark_hsv = wxImage::RGBtoHSV(wxImage::RGBValue(item_color_bytes[0], item_color_bytes[1], item_color_bytes[2])); - dark_hsv.value *= 0.75; - wxImage::RGBValue dark_rgb = wxImage::HSVtoRGB(dark_hsv); - color.Set(dark_rgb.red, dark_rgb.green, dark_rgb.blue, item_color_bytes[3]); - pen.SetColour(color); - brush.SetColour(color); - memDC.SetPen(pen); - memDC.SetBrush(brush); - memDC.DrawRectangle(wxRect(icon_x, icon_y, scaled_square, scaled_square)); - - // draw icon interior - color.Set(item_color_bytes[0], item_color_bytes[1], item_color_bytes[2], item_color_bytes[3]); - pen.SetColour(color); - brush.SetColour(color); - memDC.SetPen(pen); - memDC.SetBrush(brush); - memDC.DrawRectangle(wxRect(icon_x_inner, icon_y + 1, px_inner_square, px_inner_square)); - - // draw text - mask_memDC.DrawText(GUI::from_u8(item.text), text_x, icon_y + text_y_offset); - - // update y - icon_y += icon_y_step; - } - - memDC.SelectObject(wxNullBitmap); - mask_memDC.SelectObject(wxNullBitmap); - - // Convert the bitmap into a linear data ready to be loaded into the GPU. - wxImage image = bitmap.ConvertToImage(); - wxImage mask_image = mask.ConvertToImage(); - - // prepare buffer - std::vector data(4 * m_width * m_height, 0); - const unsigned char *src_image = image.GetData(); - const unsigned char *src_mask = mask_image.GetData(); - for (int h = 0; h < m_height; ++h) - { - int hh = h * m_width; - unsigned char* px_ptr = data.data() + 4 * hh; - for (int w = 0; w < m_width; ++w) - { - if (w >= squares_contour_x && w < squares_contour_x + squares_contour_width && - h >= squares_contour_y && h < squares_contour_y + squares_contour_height) { - // Color palette, use the color verbatim. - *px_ptr++ = *src_image++; - *px_ptr++ = *src_image++; - *px_ptr++ = *src_image++; - *px_ptr++ = 255; - } else { - // Text or background - unsigned char alpha = *src_mask; - // Compensate the white color for the 50% opacity reduction at the character edges. - //unsigned char color = (unsigned char)floor(alpha * 255.f / (128.f + 0.5f * alpha)); - unsigned char color = alpha; - *px_ptr++ = color; - *px_ptr++ = color; // *src_mask ++; - *px_ptr++ = color; // *src_mask ++; - *px_ptr++ = 128 + (alpha / 2); // (alpha > 0) ? 255 : 128; - src_image += 3; - } - src_mask += 3; - } - } - - // sends buffer to gpu - glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); - glsafe(::glGenTextures(1, &m_id)); - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id)); - if (compress && GLEW_EXT_texture_compression_s3tc) - glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data())); - else - glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data())); - glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); - glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); - - return true; -} - -void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const -{ - if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) - { - const Size& cnv_size = canvas.get_canvas_size(); - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom; - float top = (0.5f * (float)cnv_size.get_height()) * inv_zoom; - float right = left + (float)m_original_width * inv_zoom; - float bottom = top - (float)m_original_height * inv_zoom; - - float uv_left = 0.0f; - float uv_top = 0.0f; - float uv_right = (float)m_original_width / (float)m_width; - float uv_bottom = (float)m_original_height / (float)m_height; - - GLTexture::Quad_UVs uvs; - uvs.left_top = { uv_left, uv_top }; - uvs.left_bottom = { uv_left, uv_bottom }; - uvs.right_bottom = { uv_right, uv_bottom }; - uvs.right_top = { uv_right, uv_top }; - - GLTexture::render_sub_texture(m_id, left, right, bottom, top, uvs); - } -} -#endif // !ENABLE_GCODE_VIEWER - void GLCanvas3D::Labels::render(const std::vector& sorted_instances) const { if (!m_enabled || !is_shown()) @@ -1355,8 +987,7 @@ void GLCanvas3D::Labels::render(const std::vector& sorted_ ImGui::AlignTextToFramePadding(); imgui.text(owner.label); - if (!owner.print_order.empty()) - { + if (!owner.print_order.empty()) { ImGui::Separator(); float po_len = imgui.calc_text_size(owner.print_order).x; ImGui::SetCursorPosX(0.5f * (win_w - po_len)); @@ -1378,8 +1009,7 @@ void GLCanvas3D::Tooltip::set_text(const std::string& text) { // If the mouse is inside an ImGUI dialog, then the tooltip is suppressed. const std::string &new_text = m_in_imgui ? std::string() : text; - if (m_text != new_text) - { + if (m_text != new_text) { if (m_text.empty()) m_start_time = std::chrono::steady_clock::now(); @@ -1448,11 +1078,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent); -#if ENABLE_GCODE_VIEWER wxDEFINE_EVENT(EVT_GLCANVAS_MOVE_LAYERS_SLIDER, wxKeyEvent); -#else -wxDEFINE_EVENT(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, wxKeyEvent); -#endif // ENABLE_GCODE_VIEWER wxDEFINE_EVENT(EVT_GLCANVAS_EDIT_COLOR_CHANGE, wxKeyEvent); wxDEFINE_EVENT(EVT_GLCANVAS_JUMP_TO, wxKeyEvent); wxDEFINE_EVENT(EVT_GLCANVAS_UNDO, SimpleEvent); @@ -1484,9 +1110,6 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) , m_dirty(true) , m_initialized(false) , m_apply_zoom_to_volumes_filter(false) -#if !ENABLE_GCODE_VIEWER - , m_legend_texture_enabled(false) -#endif // !ENABLE_GCODE_VIEWER , m_picking_enabled(false) , m_moving_enabled(false) , m_dynamic_background_enabled(false) @@ -1684,12 +1307,10 @@ void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject void GLCanvas3D::update_instance_printable_state_for_object(const size_t obj_idx) { ModelObject* model_object = m_model->objects[obj_idx]; - for (int inst_idx = 0; inst_idx < (int)model_object->instances.size(); ++inst_idx) - { + for (int inst_idx = 0; inst_idx < (int)model_object->instances.size(); ++inst_idx) { ModelInstance* instance = model_object->instances[inst_idx]; - for (GLVolume* volume : m_volumes.volumes) - { + for (GLVolume* volume : m_volumes.volumes) { if ((volume->object_idx() == (int)obj_idx) && (volume->instance_idx() == inst_idx)) volume->printable = instance->printable; } @@ -1739,8 +1360,7 @@ void GLCanvas3D::refresh_camera_scene_box() BoundingBoxf3 GLCanvas3D::volumes_bounding_box() const { BoundingBoxf3 bb; - for (const GLVolume* volume : m_volumes.volumes) - { + for (const GLVolume* volume : m_volumes.volumes) { if (!m_apply_zoom_to_volumes_filter || ((volume != nullptr) && volume->zoom_to_volumes)) bb.merge(volume->transformed_bounding_box()); } @@ -1751,8 +1371,7 @@ BoundingBoxf3 GLCanvas3D::scene_bounding_box() const { BoundingBoxf3 bb = volumes_bounding_box(); bb.merge(wxGetApp().plater()->get_bed().get_bounding_box(true)); - if (m_config != nullptr) - { + if (m_config != nullptr) { double h = m_config->opt_float("max_print_height"); bb.min(2) = std::min(bb.min(2), -h); bb.max(2) = std::max(bb.max(2), h); @@ -1773,7 +1392,7 @@ bool GLCanvas3D::is_layers_editing_allowed() const void GLCanvas3D::reset_layer_height_profile() { - wxGetApp().plater()->take_snapshot(_(L("Variable layer height - Reset"))); + wxGetApp().plater()->take_snapshot(_L("Variable layer height - Reset")); m_layers_editing.reset_layer_height_profile(*this); m_layers_editing.state = LayersEditing::Completed; m_dirty = true; @@ -1781,7 +1400,7 @@ void GLCanvas3D::reset_layer_height_profile() void GLCanvas3D::adaptive_layer_height_profile(float quality_factor) { - wxGetApp().plater()->take_snapshot(_(L("Variable layer height - Adaptive"))); + wxGetApp().plater()->take_snapshot(_L("Variable layer height - Adaptive")); m_layers_editing.adaptive_layer_height_profile(*this, quality_factor); m_layers_editing.state = LayersEditing::Completed; m_dirty = true; @@ -1789,7 +1408,7 @@ void GLCanvas3D::adaptive_layer_height_profile(float quality_factor) void GLCanvas3D::smooth_layer_height_profile(const HeightProfileSmoothingParams& smoothing_params) { - wxGetApp().plater()->take_snapshot(_(L("Variable layer height - Smooth all"))); + wxGetApp().plater()->take_snapshot(_L("Variable layer height - Smooth all")); m_layers_editing.smooth_layer_height_profile(*this, smoothing_params); m_layers_editing.state = LayersEditing::Completed; m_dirty = true; @@ -1804,8 +1423,7 @@ void GLCanvas3D::enable_layers_editing(bool enable) { m_layers_editing.set_enabled(enable); const Selection::IndicesList& idxs = m_selection.get_volume_idxs(); - for (unsigned int idx : idxs) - { + for (unsigned int idx : idxs) { GLVolume* v = m_volumes.volumes[idx]; if (v->is_modifier) v->force_transparent = enable; @@ -1816,11 +1434,7 @@ void GLCanvas3D::enable_layers_editing(bool enable) void GLCanvas3D::enable_legend_texture(bool enable) { -#if ENABLE_GCODE_VIEWER m_gcode_viewer.enable_legend(enable); -#else - m_legend_texture_enabled = enable; -#endif // ENABLE_GCODE_VIEWER } void GLCanvas3D::enable_picking(bool enable) @@ -1882,12 +1496,10 @@ void GLCanvas3D::zoom_to_selection() _zoom_to_box(m_selection.get_bounding_box()); } -#if ENABLE_GCODE_VIEWER void GLCanvas3D::zoom_to_gcode() { _zoom_to_box(m_gcode_viewer.get_paths_bounding_box(), 1.05); } -#endif // ENABLE_GCODE_VIEWER void GLCanvas3D::select_view(const std::string& direction) { @@ -1904,8 +1516,7 @@ void GLCanvas3D::update_volumes_colors_by_extruder() void GLCanvas3D::render() { - if (m_in_render) - { + if (m_in_render) { // if called recursively, return m_dirty = true; return; @@ -1929,17 +1540,14 @@ void GLCanvas3D::render() auto start_time = std::chrono::high_resolution_clock::now(); #endif // ENABLE_RENDER_STATISTICS - if (wxGetApp().plater()->get_bed().get_shape().empty()) - { + if (wxGetApp().plater()->get_bed().get_shape().empty()) { // this happens at startup when no data is still saved under <>\AppData\Roaming\Slic3rPE post_event(SimpleEvent(EVT_GLCANVAS_UPDATE_BED_SHAPE)); return; } #if ENABLE_ENVIRONMENT_MAP -#if ENABLE_GCODE_VIEWER if (wxGetApp().is_editor()) -#endif // ENABLE_GCODE_VIEWER wxGetApp().plater()->init_environment_texture(); #endif // ENABLE_ENVIRONMENT_MAP @@ -1951,8 +1559,7 @@ void GLCanvas3D::render() Camera& camera = wxGetApp().plater()->get_camera(); camera.apply_viewport(0, 0, std::max(10u, (unsigned int)cnv_size.get_width()), std::max(10u, (unsigned int)cnv_size.get_height())); - if (camera.requires_zoom_to_bed) - { + if (camera.requires_zoom_to_bed) { zoom_to_bed(); _resize((unsigned int)cnv_size.get_width(), (unsigned int)cnv_size.get_height()); camera.requires_zoom_to_bed = false; @@ -1968,8 +1575,7 @@ void GLCanvas3D::render() wxGetApp().imgui()->new_frame(); - if (m_picking_enabled) - { + if (m_picking_enabled) { if (m_rectangle_selection.is_dragging()) // picking pass using rectangle selection _rectangular_selection_picking_pass(); @@ -1979,18 +1585,15 @@ void GLCanvas3D::render() } #if ENABLE_RENDER_PICKING_PASS - if (!m_picking_enabled || !m_show_picking_texture) - { + if (!m_picking_enabled || !m_show_picking_texture) { #endif // ENABLE_RENDER_PICKING_PASS // draw scene glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); _render_background(); _render_objects(); -#if ENABLE_GCODE_VIEWER if (!m_main_toolbar.is_enabled()) _render_gcode(); -#endif // ENABLE_GCODE_VIEWER _render_sla_slices(); _render_selection(); _render_bed(!camera.is_looking_downward(), true); @@ -2002,10 +1605,8 @@ void GLCanvas3D::render() // we need to set the mouse's scene position here because the depth buffer // could be invalidated by the following gizmo render methods // this position is used later into on_mouse() to drag the objects -#if ENABLE_GCODE_VIEWER if (m_picking_enabled) -#endif // ENABLE_GCODE_VIEWER - m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast()); + m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast()); _render_current_gizmo(); _render_selection_sidebar_hints(); @@ -2051,8 +1652,7 @@ void GLCanvas3D::render() // Negative coordinate means out of the window, likely because the window was deactivated. // In that case the tooltip should be hidden. - if (m_mouse.position.x() >= 0. && m_mouse.position.y() >= 0.) - { + if (m_mouse.position.x() >= 0. && m_mouse.position.y() >= 0.) { if (tooltip.empty()) tooltip = m_layers_editing.get_tooltip(*this); @@ -2126,10 +1726,8 @@ void GLCanvas3D::ensure_on_bed(unsigned int object_idx) typedef std::map, double> InstancesToZMap; InstancesToZMap instances_min_z; - for (GLVolume* volume : m_volumes.volumes) - { - if ((volume->object_idx() == (int)object_idx) && !volume->is_modifier) - { + for (GLVolume* volume : m_volumes.volumes) { + if (volume->object_idx() == (int)object_idx && !volume->is_modifier) { double min_z = volume->transformed_convex_hull_bounding_box().min(2); std::pair instance = std::make_pair(volume->object_idx(), volume->instance_idx()); InstancesToZMap::iterator it = instances_min_z.find(instance); @@ -2140,8 +1738,7 @@ void GLCanvas3D::ensure_on_bed(unsigned int object_idx) } } - for (GLVolume* volume : m_volumes.volumes) - { + for (GLVolume* volume : m_volumes.volumes) { std::pair instance = std::make_pair(volume->object_idx(), volume->instance_idx()); InstancesToZMap::iterator it = instances_min_z.find(instance); if (it != instances_min_z.end()) @@ -2150,7 +1747,6 @@ void GLCanvas3D::ensure_on_bed(unsigned int object_idx) } -#if ENABLE_GCODE_VIEWER const std::vector& GLCanvas3D::get_gcode_layers_zs() const { return m_gcode_viewer.get_layers_zs(); @@ -2186,24 +1782,11 @@ void GLCanvas3D::set_toolpaths_z_range(const std::array& range) if (m_gcode_viewer.has_data()) m_gcode_viewer.set_layers_z_range(range); } -#else -std::vector GLCanvas3D::get_current_print_zs(bool active_only) const -{ - return m_volumes.get_current_print_zs(active_only); -} - -void GLCanvas3D::set_toolpaths_range(double low, double high) -{ - m_volumes.set_range(low, high); -} -#endif // ENABLE_GCODE_VIEWER std::vector GLCanvas3D::load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs) { - if (instance_idxs.empty()) - { - for (unsigned int i = 0; i < model_object.instances.size(); ++i) - { + if (instance_idxs.empty()) { + for (unsigned int i = 0; i < model_object.instances.size(); ++i) { instance_idxs.emplace_back(i); } } @@ -2212,8 +1795,7 @@ std::vector GLCanvas3D::load_object(const ModelObject& model_object, int ob std::vector GLCanvas3D::load_object(const Model& model, int obj_idx) { - if ((0 <= obj_idx) && (obj_idx < (int)model.objects.size())) - { + if (0 <= obj_idx && obj_idx < (int)model.objects.size()) { const ModelObject* model_object = model.objects[obj_idx]; if (model_object != nullptr) return load_object(*model_object, obj_idx, std::vector()); @@ -2237,7 +1819,7 @@ void GLCanvas3D::mirror_selection(Axis axis) // 5) Out of bed collision status & message overlay (texture) void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_refresh) { - if ((m_canvas == nullptr) || (m_config == nullptr) || (m_model == nullptr)) + if (m_canvas == nullptr || m_config == nullptr || m_model == nullptr) return; if (!m_initialized) @@ -2536,16 +2118,14 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re volume->set_sla_shift_z(shift_zs[volume->object_idx()]); } - if (printer_technology == ptFFF && m_config->has("nozzle_diameter")) - { + if (printer_technology == ptFFF && m_config->has("nozzle_diameter")) { // Should the wipe tower be visualized ? unsigned int extruders_count = (unsigned int)dynamic_cast(m_config->option("nozzle_diameter"))->values.size(); bool wt = dynamic_cast(m_config->option("wipe_tower"))->value; bool co = dynamic_cast(m_config->option("complete_objects"))->value; - if ((extruders_count > 1) && wt && !co) - { + if ((extruders_count > 1) && wt && !co) { // Height of a print (Show at least a slab) double height = std::max(m_model->bounding_box().max(2), 10.0); @@ -2586,8 +2166,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); // checks for geometry outside the print volume to render it accordingly - if (!m_volumes.empty()) - { + if (!m_volumes.empty()) { ModelInstanceEPrintVolumeState state; const bool contained_min_one = m_volumes.check_outside_state(m_config, &state); @@ -2600,8 +2179,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, contained_min_one && !m_model->objects.empty() && state != ModelInstancePVS_Partly_Outside)); } - else - { + else { _set_warning_texture(WarningTexture::ObjectOutside, false); _set_warning_texture(WarningTexture::ObjectClashed, false); _set_warning_texture(WarningTexture::SlaSupportsOutside, false); @@ -2610,8 +2188,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re refresh_camera_scene_box(); - if (m_selection.is_empty()) - { + if (m_selection.is_empty()) { // If no object is selected, deactivate the active gizmo, if any // Otherwise it may be shown after cleaning the scene (if it was active while the objects were deleted) m_gizmos.reset_all_states(); @@ -2642,40 +2219,6 @@ static void reserve_new_volume_finalize_old_volume(GLVolume& vol_new, GLVolume& vol_old.finalize_geometry(gl_initialized); } -#if !ENABLE_GCODE_VIEWER -static void load_gcode_retractions(const GCodePreviewData::Retraction& retractions, GLCanvas3D::GCodePreviewVolumeIndex::EType extrusion_type, GLVolumeCollection &volumes, GLCanvas3D::GCodePreviewVolumeIndex &volume_index, bool gl_initialized) -{ - // nothing to render, return - if (retractions.positions.empty()) - return; - - volume_index.first_volumes.emplace_back(extrusion_type, 0, (unsigned int)volumes.volumes.size()); - - GLVolume *volume = volumes.new_nontoolpath_volume(retractions.color.rgba.data(), VERTEX_BUFFER_RESERVE_SIZE); - - GCodePreviewData::Retraction::PositionsList copy(retractions.positions); - std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2) { return p1.position(2) < p2.position(2); }); - - for (const GCodePreviewData::Retraction::Position& position : copy) - { - volume->print_zs.emplace_back(unscale(position.position(2))); - volume->offsets.emplace_back(volume->indexed_vertex_array.quad_indices.size()); - volume->offsets.emplace_back(volume->indexed_vertex_array.triangle_indices.size()); - - _3DScene::point3_to_verts(position.position, position.width, position.height, *volume); - - // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. - if (volume->indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { - GLVolume &vol = *volume; - volume = volumes.new_nontoolpath_volume(vol.color); - reserve_new_volume_finalize_old_volume(*volume, vol, gl_initialized); - } - } - volume->indexed_vertex_array.finalize_geometry(gl_initialized); -} -#endif // !ENABLE_GCODE_VIEWER - -#if ENABLE_GCODE_VIEWER void GLCanvas3D::load_gcode_preview(const GCodeProcessor::Result& gcode_result) { m_gcode_viewer.load(gcode_result, *this->fff_print(), m_initialized); @@ -2689,82 +2232,11 @@ void GLCanvas3D::refresh_gcode_preview(const GCodeProcessor::Result& gcode_resul set_as_dirty(); request_extra_frame(); } -#else -void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const std::vector& str_tool_colors) -{ - const Print *print = this->fff_print(); - if ((m_canvas != nullptr) && (print != nullptr)) - { - _set_current(); - - std::vector tool_colors = _parse_colors(str_tool_colors); - - if (m_volumes.empty()) - { - m_gcode_preview_volume_index.reset(); - - _load_gcode_extrusion_paths(preview_data, tool_colors); - _load_gcode_travel_paths(preview_data, tool_colors); - load_gcode_retractions(preview_data.retraction, GCodePreviewVolumeIndex::Retraction, m_volumes, m_gcode_preview_volume_index, m_initialized); - load_gcode_retractions(preview_data.unretraction, GCodePreviewVolumeIndex::Unretraction, m_volumes, m_gcode_preview_volume_index, m_initialized); - - if (!m_volumes.empty()) - { - // Remove empty volumes from both m_volumes, update m_gcode_preview_volume_index. - { - size_t idx_volume_src = 0; - size_t idx_volume_dst = 0; - size_t idx_volume_index_src = 0; - size_t idx_volume_index_dst = 0; - size_t idx_volume_of_this_type_last = (idx_volume_index_src + 1 == m_gcode_preview_volume_index.first_volumes.size()) ? m_volumes.volumes.size() : m_gcode_preview_volume_index.first_volumes[idx_volume_index_src + 1].id; - size_t idx_volume_of_this_type_first_new = 0; - for (;;) { - if (idx_volume_src == idx_volume_of_this_type_last) { - if (idx_volume_of_this_type_first_new < idx_volume_dst) { - // There are some volumes of this type left, therefore their entry in the index has to be maintained. - if (idx_volume_index_dst < idx_volume_index_src) - m_gcode_preview_volume_index.first_volumes[idx_volume_index_dst] = m_gcode_preview_volume_index.first_volumes[idx_volume_index_src]; - m_gcode_preview_volume_index.first_volumes[idx_volume_index_dst].id = idx_volume_of_this_type_first_new; - ++ idx_volume_index_dst; - } - if (idx_volume_of_this_type_last == m_volumes.volumes.size()) - break; - ++ idx_volume_index_src; - idx_volume_of_this_type_last = (idx_volume_index_src + 1 == m_gcode_preview_volume_index.first_volumes.size()) ? m_volumes.volumes.size() : m_gcode_preview_volume_index.first_volumes[idx_volume_index_src + 1].id; - idx_volume_of_this_type_first_new = idx_volume_dst; - if (idx_volume_src == idx_volume_of_this_type_last) - // Empty sequence of volumes for the current index item. - continue; - } - if (! m_volumes.volumes[idx_volume_src]->print_zs.empty()) - m_volumes.volumes[idx_volume_dst ++] = m_volumes.volumes[idx_volume_src]; - ++ idx_volume_src; - } - m_volumes.volumes.erase(m_volumes.volumes.begin() + idx_volume_dst, m_volumes.volumes.end()); - m_gcode_preview_volume_index.first_volumes.erase(m_gcode_preview_volume_index.first_volumes.begin() + idx_volume_index_dst, m_gcode_preview_volume_index.first_volumes.end()); - } - - _load_fff_shells(); - } - _update_toolpath_volumes_outside_state(); - } - - _update_gcode_volumes_visibility(preview_data); - _show_warning_texture_if_needed(WarningTexture::ToolpathOutside); - - if (m_volumes.empty()) - reset_legend_texture(); - else - _generate_legend_texture(preview_data, tool_colors); - } -} -#endif // ENABLE_GCODE_VIEWER void GLCanvas3D::load_sla_preview() { const SLAPrint* print = this->sla_print(); - if ((m_canvas != nullptr) && (print != nullptr)) - { + if (m_canvas != nullptr && print != nullptr) { _set_current(); // Release OpenGL data before generating new data. this->reset_volumes(); @@ -2792,16 +2264,6 @@ void GLCanvas3D::load_preview(const std::vector& str_tool_colors, c _update_toolpath_volumes_outside_state(); _show_warning_texture_if_needed(WarningTexture::ToolpathOutside); -#if !ENABLE_GCODE_VIEWER - if (color_print_values.empty()) - reset_legend_texture(); - else { - auto preview_data = GCodePreviewData(); - preview_data.extrusion.view_type = GCodePreviewData::Extrusion::ColorPrint; - const std::vector tool_colors = _parse_colors(str_tool_colors); - _generate_legend_texture(preview_data, tool_colors); - } -#endif // !ENABLE_GCODE_VIEWER } void GLCanvas3D::bind_event_handlers() @@ -3061,7 +2523,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) case 'i': { _update_camera_zoom(1.0); break; } case 'K': case 'k': { wxGetApp().plater()->get_camera().select_next_type(); m_dirty = true; break; } -#if ENABLE_GCODE_VIEWER case 'L': case 'l': { if (!m_main_toolbar.is_enabled()) { @@ -3071,7 +2532,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) } break; } -#endif // ENABLE_GCODE_VIEWER case 'O': case 'o': { _update_camera_zoom(-1.0); break; } #if ENABLE_RENDER_PICKING_PASS @@ -3083,7 +2543,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) } #endif // ENABLE_RENDER_PICKING_PASS case 'Z': -#if ENABLE_GCODE_VIEWER case 'z': { if (!m_selection.is_empty()) @@ -3097,9 +2556,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) break; } -#else - case 'z': { m_selection.is_empty() ? zoom_to_volumes() : zoom_to_selection(); break; } -#endif // ENABLE_GCODE_VIEWER default: { evt.Skip(); break; } } } @@ -3212,8 +2668,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) double multiplier = slow ? 1.0 : 10.0; Vec3d displacement; - if (camera_space) - { + if (camera_space) { Eigen::Matrix inv_view_3x3 = wxGetApp().plater()->get_camera().get_view_matrix().inverse().matrix().block(0, 0, 3, 3); displacement = multiplier * (inv_view_3x3 * direction); displacement(2) = 0.0; @@ -3234,8 +2689,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) } else { - if (!m_gizmos.on_key(evt)) - { + if (!m_gizmos.on_key(evt)) { if (evt.GetEventType() == wxEVT_KEY_UP) { if (m_tab_down && keyCode == WXK_TAB && !evt.HasAnyModifiers()) { // Enable switching between 3D and Preview with Tab @@ -3246,12 +2700,10 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) // Collapse side-panel with Shift+Tab post_event(SimpleEvent(EVT_GLCANVAS_COLLAPSE_SIDEBAR)); } - else if (keyCode == WXK_SHIFT) - { + else if (keyCode == WXK_SHIFT) { translationProcessor.process(evt); - if (m_picking_enabled && m_rectangle_selection.is_dragging()) - { + if (m_picking_enabled && m_rectangle_selection.is_dragging()) { _update_selection_from_hover(); m_rectangle_selection.stop_dragging(); m_mouse.ignore_left_up = true; @@ -3259,10 +2711,8 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) } // set_cursor(Standard); } - else if (keyCode == WXK_ALT) - { - if (m_picking_enabled && m_rectangle_selection.is_dragging()) - { + else if (keyCode == WXK_ALT) { + if (m_picking_enabled && m_rectangle_selection.is_dragging()) { _update_selection_from_hover(); m_rectangle_selection.stop_dragging(); m_mouse.ignore_left_up = true; @@ -3299,8 +2749,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) } else if (evt.GetEventType() == wxEVT_KEY_DOWN) { m_tab_down = keyCode == WXK_TAB && !evt.HasAnyModifiers(); - if (keyCode == WXK_SHIFT) - { + if (keyCode == WXK_SHIFT) { translationProcessor.process(evt); if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) @@ -3309,8 +2758,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) // set_cursor(Cross); } } - else if (keyCode == WXK_ALT) - { + else if (keyCode == WXK_ALT) { if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) { m_mouse.ignore_left_up = false; @@ -3319,8 +2767,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) } else if (keyCode == WXK_CONTROL) m_dirty = true; - else if (m_gizmos.is_enabled() && !m_selection.is_empty()) - { + else if (m_gizmos.is_enabled() && !m_selection.is_empty()) { auto do_rotate = [this](double angle_z_rad) { m_selection.start_dragging(); m_selection.rotate(Vec3d(0.0, 0.0, angle_z_rad), TransformationType(TransformationType::World_Relative_Joint)); @@ -3337,20 +2784,14 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) default: { break; } } } - else if (!m_gizmos.is_enabled()) - { + else if (!m_gizmos.is_enabled()) { // DoubleSlider navigation in Preview if (keyCode == WXK_LEFT || keyCode == WXK_RIGHT || keyCode == WXK_UP || - keyCode == WXK_DOWN) - { + keyCode == WXK_DOWN) { if (dynamic_cast(m_canvas->GetParent()) != nullptr) -#if ENABLE_GCODE_VIEWER post_event(wxKeyEvent(EVT_GLCANVAS_MOVE_LAYERS_SLIDER, evt)); -#else - post_event(wxKeyEvent(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, evt)); -#endif // ENABLE_GCODE_VIEWER } } } @@ -3400,14 +2841,11 @@ void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt) #endif /* __WXMSW__ */ // Performs layers editing updates, if enabled - if (is_layers_editing_enabled()) - { + if (is_layers_editing_enabled()) { int object_idx_selected = m_selection.get_object_idx(); - if (object_idx_selected != -1) - { + if (object_idx_selected != -1) { // A volume is selected. Test, whether hovering over a layer thickness bar. - if (m_layers_editing.bar_rect_contains(*this, (float)evt.GetX(), (float)evt.GetY())) - { + if (m_layers_editing.bar_rect_contains(*this, (float)evt.GetX(), (float)evt.GetY())) { // Adjust the width of the selection. m_layers_editing.band_width = std::max(std::min(m_layers_editing.band_width * (1.0f + 0.1f * (float)evt.GetWheelRotation() / (float)evt.GetWheelDelta()), 10.0f), 1.5f); if (m_canvas != nullptr) @@ -3868,13 +3306,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (m_selection.is_empty()) m_gizmos.reset_all_states(); -#if ENABLE_GCODE_VIEWER m_dirty = true; -#else - // Only refresh if picking is enabled, in that case the objects may get highlighted if the mouse cursor hovers over. - //if (m_picking_enabled) - m_dirty = true; -#endif // ENABLE_GCODE_VIEWER } else evt.Skip(); @@ -3935,17 +3367,6 @@ Vec2d GLCanvas3D::get_local_mouse_position() const return Vec2d(factor * mouse_pos.x, factor * mouse_pos.y); } -#if !ENABLE_GCODE_VIEWER -void GLCanvas3D::reset_legend_texture() -{ - if (m_legend_texture.get_id() != 0) - { - _set_current(); - m_legend_texture.reset(); - } -} -#endif // !ENABLE_GCODE_VIEWER - void GLCanvas3D::set_tooltip(const std::string& tooltip) const { if (m_canvas != nullptr) @@ -4234,13 +3655,8 @@ void GLCanvas3D::update_ui_from_settings() } #endif // ENABLE_RETINA_GL -#if ENABLE_GCODE_VIEWER if (wxGetApp().is_editor()) wxGetApp().plater()->enable_collapse_toolbar(wxGetApp().app_config->get("show_collapse_button") == "1"); -#else - bool enable_collapse = wxGetApp().app_config->get("show_collapse_button") == "1"; - wxGetApp().plater()->get_collapse_toolbar().set_enabled(enable_collapse); -#endif // ENABLE_GCODE_VIEWER } GLCanvas3D::WipeTowerInfo GLCanvas3D::get_wipe_tower_info() const @@ -4304,20 +3720,12 @@ void GLCanvas3D::update_tooltip_for_settings_item_in_main_toolbar() bool GLCanvas3D::has_toolpaths_to_export() const { -#if ENABLE_GCODE_VIEWER return m_gcode_viewer.has_data(); -#else - return m_volumes.has_toolpaths_to_export(); -#endif // ENABLE_GCODE_VIEWER } void GLCanvas3D::export_toolpaths_to_obj(const char* filename) const { -#if ENABLE_GCODE_VIEWER m_gcode_viewer.export_toolpaths_to_obj(filename); -#else - m_volumes.export_toolpaths_to_obj(filename); -#endif // ENABLE_GCODE_VIEWER } void GLCanvas3D::mouse_up_cleanup() @@ -5150,10 +4558,8 @@ BoundingBoxf3 GLCanvas3D::_max_bounding_box(bool include_gizmos, bool include_be bb.merge(wxGetApp().plater()->get_bed().get_bounding_box(include_bed_model)); -#if ENABLE_GCODE_VIEWER if (!m_main_toolbar.is_enabled()) bb.merge(m_gcode_viewer.get_max_bounding_box()); -#endif // ENABLE_GCODE_VIEWER return bb; } @@ -5314,7 +4720,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass() const _update_volumes_hover_state(); } -#if ENABLE_GCODE_VIEWER static BoundingBoxf3 print_volume(const DynamicPrintConfig& config) { // tolerance to avoid false detection at bed edges @@ -5331,11 +4736,9 @@ static BoundingBoxf3 print_volume(const DynamicPrintConfig& config) } return ret; } -#endif // ENABLE_GCODE_VIEWER void GLCanvas3D::_render_background() const { -#if ENABLE_GCODE_VIEWER bool use_error_color = false; if (wxGetApp().is_editor()) { use_error_color = m_dynamic_background_enabled && @@ -5348,7 +4751,6 @@ void GLCanvas3D::_render_background() const use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_paths_bounding_box()) : false; } } -#endif // ENABLE_GCODE_VIEWER glsafe(::glPushMatrix()); glsafe(::glLoadIdentity()); @@ -5360,11 +4762,7 @@ void GLCanvas3D::_render_background() const glsafe(::glDisable(GL_DEPTH_TEST)); ::glBegin(GL_QUADS); -#if ENABLE_GCODE_VIEWER if (use_error_color) -#else - if (m_dynamic_background_enabled && _is_any_volume_outside()) -#endif // ENABLE_GCODE_VIEWER ::glColor3fv(ERROR_BG_DARK_COLOR); else ::glColor3fv(DEFAULT_BG_DARK_COLOR); @@ -5372,12 +4770,8 @@ void GLCanvas3D::_render_background() const ::glVertex2f(-1.0f, -1.0f); ::glVertex2f(1.0f, -1.0f); -#if ENABLE_GCODE_VIEWER if (use_error_color) -#else - if (m_dynamic_background_enabled && _is_any_volume_outside()) -#endif // ENABLE_GCODE_VIEWER -::glColor3fv(ERROR_BG_LIGHT_COLOR); + ::glColor3fv(ERROR_BG_LIGHT_COLOR); else ::glColor3fv(DEFAULT_BG_LIGHT_COLOR); @@ -5475,12 +4869,10 @@ void GLCanvas3D::_render_objects() const m_camera_clipping_plane = ClippingPlane::ClipsNothing(); } -#if ENABLE_GCODE_VIEWER void GLCanvas3D::_render_gcode() const { m_gcode_viewer.render(); } -#endif // ENABLE_GCODE_VIEWER void GLCanvas3D::_render_selection() const { @@ -5562,9 +4954,6 @@ void GLCanvas3D::_render_overlays() const _render_gizmos_overlay(); _render_warning_texture(); -#if !ENABLE_GCODE_VIEWER - _render_legend_texture(); -#endif // !ENABLE_GCODE_VIEWER // main toolbar and undoredo toolbar need to be both updated before rendering because both their sizes are needed // to correctly place them @@ -5607,16 +4996,6 @@ void GLCanvas3D::_render_warning_texture() const m_warning_texture.render(*this); } -#if !ENABLE_GCODE_VIEWER -void GLCanvas3D::_render_legend_texture() const -{ - if (!m_legend_texture_enabled) - return; - - m_legend_texture.render(*this); -} -#endif // !ENABLE_GCODE_VIEWER - void GLCanvas3D::_render_volumes_for_picking() const { static const GLfloat INV_255 = 1.0f / 255.0f; @@ -6563,336 +5942,6 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector& str_ BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); } -#if !ENABLE_GCODE_VIEWER -static inline int hex_digit_to_int(const char c) -{ - return - (c >= '0' && c <= '9') ? int(c - '0') : - (c >= 'A' && c <= 'F') ? int(c - 'A') + 10 : - (c >= 'a' && c <= 'f') ? int(c - 'a') + 10 : -1; -} - -void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, const std::vector& tool_colors) -{ - BOOST_LOG_TRIVIAL(debug) << "Loading G-code extrusion paths - start" << m_volumes.log_memory_info() << log_memory_info(); - - // helper functions to select data in dependence of the extrusion view type - struct Helper - { - static float path_filter(GCodePreviewData::Extrusion::EViewType type, const GCodePreviewData::Extrusion::Path& path) - { - switch (type) - { - case GCodePreviewData::Extrusion::FeatureType: - // The role here is used for coloring. - return (float)path.extrusion_role; - case GCodePreviewData::Extrusion::Height: - return path.height; - case GCodePreviewData::Extrusion::Width: - return path.width; - case GCodePreviewData::Extrusion::Feedrate: - return path.feedrate; - case GCodePreviewData::Extrusion::FanSpeed: - return path.fan_speed; - case GCodePreviewData::Extrusion::VolumetricRate: - return path.feedrate * path.mm3_per_mm; - case GCodePreviewData::Extrusion::Tool: - return (float)path.extruder_id; - case GCodePreviewData::Extrusion::ColorPrint: - return (float)path.cp_color_id; - default: - return 0.0f; - } - - return 0.0f; - } - - static Color path_color(const GCodePreviewData& data, const std::vector& tool_colors, float value) - { - switch (data.extrusion.view_type) - { - case GCodePreviewData::Extrusion::FeatureType: - return data.get_extrusion_role_color((ExtrusionRole)(int)value); - case GCodePreviewData::Extrusion::Height: - return data.get_height_color(value); - case GCodePreviewData::Extrusion::Width: - return data.get_width_color(value); - case GCodePreviewData::Extrusion::Feedrate: - return data.get_feedrate_color(value); - case GCodePreviewData::Extrusion::FanSpeed: - return data.get_fan_speed_color(value); - case GCodePreviewData::Extrusion::VolumetricRate: - return data.get_volumetric_rate_color(value); - case GCodePreviewData::Extrusion::Tool: - { - Color color; - ::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data() + (unsigned int)value * 4), 4 * sizeof(float)); - return color; - } - case GCodePreviewData::Extrusion::ColorPrint: - { - int color_cnt = (int)tool_colors.size() / 4; - int val = value > color_cnt ? color_cnt - 1 : value; - - Color color; - ::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data() + val * 4), 4 * sizeof(float)); - - return color; - } - default: - return Color{}; - } - - return Color{}; - } - }; - - size_t initial_volumes_count = m_volumes.volumes.size(); - size_t initial_volume_index_count = m_gcode_preview_volume_index.first_volumes.size(); - - try - { - BOOST_LOG_TRIVIAL(debug) << "Loading G-code extrusion paths - create volumes" << m_volumes.log_memory_info() << log_memory_info(); - - // detects filters - size_t vertex_buffer_prealloc_size = 0; - std::vector>> roles_filters; - { - std::vector num_paths_per_role(size_t(erCount), 0); - for (const GCodePreviewData::Extrusion::Layer &layer : preview_data.extrusion.layers) - for (const GCodePreviewData::Extrusion::Path &path : layer.paths) - ++ num_paths_per_role[size_t(path.extrusion_role)]; - std::vector> roles_values; - roles_values.assign(size_t(erCount), std::vector()); - for (size_t i = 0; i < roles_values.size(); ++ i) - roles_values[i].reserve(num_paths_per_role[i]); - for (const GCodePreviewData::Extrusion::Layer& layer : preview_data.extrusion.layers) - for (const GCodePreviewData::Extrusion::Path &path : layer.paths) - roles_values[size_t(path.extrusion_role)].emplace_back(Helper::path_filter(preview_data.extrusion.view_type, path)); - roles_filters.reserve(size_t(erCount)); - size_t num_buffers = 0; - for (std::vector &values : roles_values) { - sort_remove_duplicates(values); - num_buffers += values.size(); - } - if (num_buffers == 0) - // nothing to render, return - return; - vertex_buffer_prealloc_size = (uint64_t(num_buffers) * uint64_t(VERTEX_BUFFER_RESERVE_SIZE) < VERTEX_BUFFER_RESERVE_SIZE_SUM_MAX) ? - VERTEX_BUFFER_RESERVE_SIZE : next_highest_power_of_2(VERTEX_BUFFER_RESERVE_SIZE_SUM_MAX / num_buffers) / 2; - for (std::vector &values : roles_values) { - size_t role = &values - &roles_values.front(); - roles_filters.emplace_back(); - if (! values.empty()) { - m_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Extrusion, role, (unsigned int)m_volumes.volumes.size()); - for (const float value : values) - roles_filters.back().emplace_back(value, m_volumes.new_toolpath_volume(Helper::path_color(preview_data, tool_colors, value).rgba.data(), vertex_buffer_prealloc_size)); - } - } - } - - BOOST_LOG_TRIVIAL(debug) << "Loading G-code extrusion paths - populate volumes" << m_volumes.log_memory_info() << log_memory_info(); - - // populates volumes - const bool is_selected_separate_extruder = m_selected_extruder > 0 && preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint; - for (const GCodePreviewData::Extrusion::Layer& layer : preview_data.extrusion.layers) - { - for (const GCodePreviewData::Extrusion::Path& path : layer.paths) - { - if (is_selected_separate_extruder && path.extruder_id != m_selected_extruder - 1) - continue; - std::vector> &filters = roles_filters[size_t(path.extrusion_role)]; - auto key = std::make_pair(Helper::path_filter(preview_data.extrusion.view_type, path), nullptr); - auto it_filter = std::lower_bound(filters.begin(), filters.end(), key); - assert(it_filter != filters.end() && key.first == it_filter->first); - - GLVolume& vol = *it_filter->second; - vol.print_zs.emplace_back(layer.z); - vol.offsets.emplace_back(vol.indexed_vertex_array.quad_indices.size()); - vol.offsets.emplace_back(vol.indexed_vertex_array.triangle_indices.size()); - - _3DScene::extrusionentity_to_verts(path.polyline, path.width, path.height, layer.z, vol); - } - // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. - for (std::vector> &filters : roles_filters) { - unsigned int role = (unsigned int)(&filters - &roles_filters.front()); - for (std::pair &filter : filters) - if (filter.second->indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { - if (m_gcode_preview_volume_index.first_volumes.back().type != GCodePreviewVolumeIndex::Extrusion || m_gcode_preview_volume_index.first_volumes.back().flag != role) - m_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Extrusion, role, (unsigned int)m_volumes.volumes.size()); - GLVolume& vol = *filter.second; - filter.second = m_volumes.new_toolpath_volume(vol.color); - reserve_new_volume_finalize_old_volume(*filter.second, vol, m_initialized, vertex_buffer_prealloc_size); - } - } - } - - // Finalize volumes and sends geometry to gpu - for (std::vector> &filters : roles_filters) - for (std::pair &filter : filters) - filter.second->indexed_vertex_array.finalize_geometry(m_initialized); - - BOOST_LOG_TRIVIAL(debug) << "Loading G-code extrusion paths - end" << m_volumes.log_memory_info() << log_memory_info(); - } - catch (const std::bad_alloc & /* err */) - { - // an error occourred - restore to previous state and return - GLVolumePtrs::iterator begin = m_volumes.volumes.begin() + initial_volumes_count; - GLVolumePtrs::iterator end = m_volumes.volumes.end(); - for (GLVolumePtrs::iterator it = begin; it < end; ++it) - delete *it; - m_volumes.volumes.erase(begin, end); - m_gcode_preview_volume_index.first_volumes.erase(m_gcode_preview_volume_index.first_volumes.begin() + initial_volume_index_count, m_gcode_preview_volume_index.first_volumes.end()); - BOOST_LOG_TRIVIAL(debug) << "Loading G-code extrusion paths - failed on low memory" << m_volumes.log_memory_info() << log_memory_info(); - //FIXME rethrow bad_alloc? - } -} - -template -inline void travel_paths_internal( - // input - const GCodePreviewData &preview_data, - // accessors - FUNC_VALUE func_value, FUNC_COLOR func_color, - // output - GLVolumeCollection &volumes, bool gl_initialized) - -{ - // colors travels by type - std::vector> by_type; - { - std::vector values; - values.reserve(preview_data.travel.polylines.size()); - for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) - values.emplace_back(func_value(polyline)); - sort_remove_duplicates(values); - by_type.reserve(values.size()); - // creates a new volume for each feedrate - for (TYPE type : values) - by_type.emplace_back(type, volumes.new_nontoolpath_volume(func_color(type).rgba.data(), VERTEX_BUFFER_RESERVE_SIZE)); - } - - // populates volumes - std::pair key(0.f, nullptr); - for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) - { - key.first = func_value(polyline); - auto it = std::lower_bound(by_type.begin(), by_type.end(), key, [](const std::pair& l, const std::pair& r) { return l.first < r.first; }); - assert(it != by_type.end() && it->first == func_value(polyline)); - - GLVolume& vol = *it->second; - vol.print_zs.emplace_back(unscale(polyline.polyline.bounding_box().min(2))); - vol.offsets.emplace_back(vol.indexed_vertex_array.quad_indices.size()); - vol.offsets.emplace_back(vol.indexed_vertex_array.triangle_indices.size()); - - _3DScene::polyline3_to_verts(polyline.polyline, preview_data.travel.width, preview_data.travel.height, vol); - - // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. - if (vol.indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { - it->second = volumes.new_nontoolpath_volume(vol.color); - reserve_new_volume_finalize_old_volume(*it->second, vol, gl_initialized); - } - } - - for (auto &feedrate : by_type) - feedrate.second->finalize_geometry(gl_initialized); -} - -void GLCanvas3D::_load_gcode_travel_paths(const GCodePreviewData& preview_data, const std::vector& tool_colors) -{ - // nothing to render, return - if (preview_data.travel.polylines.empty()) - return; - - size_t initial_volumes_count = m_volumes.volumes.size(); - size_t volume_index_allocated = false; - - try { - m_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Travel, 0, (unsigned int)initial_volumes_count); - volume_index_allocated = true; - - switch (preview_data.extrusion.view_type) - { - case GCodePreviewData::Extrusion::Feedrate: - travel_paths_internal(preview_data, - [](const GCodePreviewData::Travel::Polyline &polyline) { return polyline.feedrate; }, - [&preview_data](const float feedrate) -> const Color { return preview_data.get_feedrate_color(feedrate); }, - m_volumes, m_initialized); - break; - case GCodePreviewData::Extrusion::Tool: - travel_paths_internal(preview_data, - [](const GCodePreviewData::Travel::Polyline &polyline) { return polyline.extruder_id; }, - [&tool_colors](const unsigned int extruder_id) -> const Color { assert((extruder_id + 1) * 4 <= tool_colors.size()); return Color(tool_colors.data() + extruder_id * 4); }, - m_volumes, m_initialized); - break; - default: - travel_paths_internal(preview_data, - [](const GCodePreviewData::Travel::Polyline &polyline) { return polyline.type; }, - [&preview_data](const unsigned int type) -> const Color& { return preview_data.travel.type_colors[type]; }, - m_volumes, m_initialized); - break; - } - } catch (const std::bad_alloc & /* ex */) { - // an error occourred - restore to previous state and return - GLVolumePtrs::iterator begin = m_volumes.volumes.begin() + initial_volumes_count; - GLVolumePtrs::iterator end = m_volumes.volumes.end(); - for (GLVolumePtrs::iterator it = begin; it < end; ++it) - delete *it; - m_volumes.volumes.erase(begin, end); - if (volume_index_allocated) - m_gcode_preview_volume_index.first_volumes.pop_back(); - //FIXME report the memory issue? - } -} - -void GLCanvas3D::_load_fff_shells() -{ - size_t initial_volumes_count = m_volumes.volumes.size(); - m_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Shell, 0, (unsigned int)initial_volumes_count); - - const Print *print = this->fff_print(); - if (print->objects().empty()) - // nothing to render, return - return; - - // adds objects' volumes - int object_id = 0; - for (const PrintObject* obj : print->objects()) - { - const ModelObject* model_obj = obj->model_object(); - - std::vector instance_ids(model_obj->instances.size()); - for (int i = 0; i < (int)model_obj->instances.size(); ++i) - { - instance_ids[i] = i; - } - - m_volumes.load_object(model_obj, object_id, instance_ids, "object", m_initialized); - - ++object_id; - } - - if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptFFF) { - // adds wipe tower's volume - double max_z = print->objects()[0]->model_object()->get_model()->bounding_box().max(2); - const PrintConfig& config = print->config(); - size_t extruders_count = config.nozzle_diameter.size(); - if ((extruders_count > 1) && config.wipe_tower && !config.complete_objects) { - - const DynamicPrintConfig &print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - double layer_height = print_config.opt_float("layer_height"); - double first_layer_height = print_config.get_abs_value("first_layer_height", layer_height); - double nozzle_diameter = print->config().nozzle_diameter.values[0]; - float depth = print->wipe_tower_data(extruders_count, first_layer_height, nozzle_diameter).depth; - float brim_width = print->wipe_tower_data(extruders_count, first_layer_height, nozzle_diameter).brim_width; - - m_volumes.load_wipe_tower_preview(1000, config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, - !print->is_step_done(psWipeTower), brim_width, m_initialized); - } - } -} -#endif // !ENABLE_GCODE_VIEWER - // While it looks like we can call // this->reload_scene(true, true) // the two functions are quite different: @@ -6949,136 +5998,25 @@ void GLCanvas3D::_load_sla_shells() update_volumes_colors_by_extruder(); } -#if !ENABLE_GCODE_VIEWER -void GLCanvas3D::_update_gcode_volumes_visibility(const GCodePreviewData& preview_data) -{ - unsigned int size = (unsigned int)m_gcode_preview_volume_index.first_volumes.size(); - for (unsigned int i = 0; i < size; ++i) - { - GLVolumePtrs::iterator begin = m_volumes.volumes.begin() + m_gcode_preview_volume_index.first_volumes[i].id; - GLVolumePtrs::iterator end = (i + 1 < size) ? m_volumes.volumes.begin() + m_gcode_preview_volume_index.first_volumes[i + 1].id : m_volumes.volumes.end(); - - for (GLVolumePtrs::iterator it = begin; it != end; ++it) - { - GLVolume* volume = *it; - - switch (m_gcode_preview_volume_index.first_volumes[i].type) - { - case GCodePreviewVolumeIndex::Extrusion: - { - if ((ExtrusionRole)m_gcode_preview_volume_index.first_volumes[i].flag == erCustom) - volume->zoom_to_volumes = false; - - volume->is_active = preview_data.extrusion.is_role_flag_set((ExtrusionRole)m_gcode_preview_volume_index.first_volumes[i].flag); - break; - } - case GCodePreviewVolumeIndex::Travel: - { - volume->is_active = preview_data.travel.is_visible; - volume->zoom_to_volumes = false; - break; - } - case GCodePreviewVolumeIndex::Retraction: - { - volume->is_active = preview_data.retraction.is_visible; - volume->zoom_to_volumes = false; - break; - } - case GCodePreviewVolumeIndex::Unretraction: - { - volume->is_active = preview_data.unretraction.is_visible; - volume->zoom_to_volumes = false; - break; - } - case GCodePreviewVolumeIndex::Shell: - { - volume->is_active = preview_data.shell.is_visible; - volume->color[3] = 0.25f; - volume->zoom_to_volumes = false; - break; - } - default: - { - volume->is_active = false; - volume->zoom_to_volumes = false; - break; - } - } - } - } -} -#endif // !ENABLE_GCODE_VIEWER - void GLCanvas3D::_update_toolpath_volumes_outside_state() { -#if ENABLE_GCODE_VIEWER BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); -#else - // tolerance to avoid false detection at bed edges - static const double tolerance_x = 0.05; - static const double tolerance_y = 0.05; - - BoundingBoxf3 print_volume; - if (m_config != nullptr) - { - const ConfigOptionPoints* opt = dynamic_cast(m_config->option("bed_shape")); - if (opt != nullptr) - { - BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - print_volume = BoundingBoxf3(Vec3d(unscale(bed_box_2D.min(0)) - tolerance_x, unscale(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale(bed_box_2D.max(0)) + tolerance_x, unscale(bed_box_2D.max(1)) + tolerance_y, m_config->opt_float("max_print_height"))); - // Allow the objects to protrude below the print bed - print_volume.min(2) = -1e10; - } - } -#endif // ENABLE_GCODE_VIEWER - - for (GLVolume* volume : m_volumes.volumes) - { -#if ENABLE_GCODE_VIEWER + 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; -#else - volume->is_outside = ((print_volume.radius() > 0.0) && volume->is_extrusion_path) ? !print_volume.contains(volume->bounding_box()) : false; -#endif // ENABLE_GCODE_VIEWER } } void GLCanvas3D::_update_sla_shells_outside_state() { -#if ENABLE_GCODE_VIEWER BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); -#else - // tolerance to avoid false detection at bed edges - static const double tolerance_x = 0.05; - static const double tolerance_y = 0.05; - - BoundingBoxf3 print_volume; - if (m_config != nullptr) - { - const ConfigOptionPoints* opt = dynamic_cast(m_config->option("bed_shape")); - if (opt != nullptr) - { - BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - print_volume = BoundingBoxf3(Vec3d(unscale(bed_box_2D.min(0)) - tolerance_x, unscale(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale(bed_box_2D.max(0)) + tolerance_x, unscale(bed_box_2D.max(1)) + tolerance_y, m_config->opt_float("max_print_height"))); - // Allow the objects to protrude below the print bed - print_volume.min(2) = -1e10; - } - } -#endif // ENABLE_GCODE_VIEWER - - for (GLVolume* volume : m_volumes.volumes) - { -#if ENABLE_GCODE_VIEWER + 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; -#else - volume->is_outside = ((print_volume.radius() > 0.0) && volume->shader_outside_printer_detection_enabled) ? !print_volume.contains(volume->transformed_convex_hull_bounding_box()) : false; -#endif // ENABLE_GCODE_VIEWER } } void GLCanvas3D::_show_warning_texture_if_needed(WarningTexture::Warning warning) { _set_current(); -#if ENABLE_GCODE_VIEWER bool show = false; if (!m_volumes.empty()) show = _is_any_volume_outside(); @@ -7091,9 +6029,6 @@ void GLCanvas3D::_show_warning_texture_if_needed(WarningTexture::Warning warning } } _set_warning_texture(warning, show); -#else - _set_warning_texture(warning, _is_any_volume_outside()); -#endif // ENABLE_GCODE_VIEWER } std::vector GLCanvas3D::_parse_colors(const std::vector& colors) @@ -7121,13 +6056,6 @@ std::vector GLCanvas3D::_parse_colors(const std::vector& col return output; } -#if !ENABLE_GCODE_VIEWER -void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors) -{ - m_legend_texture.generate(preview_data, tool_colors, *this, true); -} -#endif // !ENABLE_GCODE_VIEWER - void GLCanvas3D::_set_warning_texture(WarningTexture::Warning warning, bool state) { m_warning_texture.activate(warning, state, *this); @@ -7135,8 +6063,7 @@ void GLCanvas3D::_set_warning_texture(WarningTexture::Warning warning, bool stat bool GLCanvas3D::_is_any_volume_outside() const { - for (const GLVolume* volume : m_volumes.volumes) - { + for (const GLVolume* volume : m_volumes.volumes) { if ((volume != nullptr) && volume->is_outside) return true; } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index cc3971c179..0975e59a00 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -12,10 +12,8 @@ #include "GUI_ObjectLayers.hpp" #include "GLSelectionRectangle.hpp" #include "MeshUtils.hpp" -#if ENABLE_GCODE_VIEWER #include "libslic3r/GCode/GCodeProcessor.hpp" #include "GCodeViewer.hpp" -#endif // ENABLE_GCODE_VIEWER #include "libslic3r/Slicing.hpp" @@ -39,9 +37,6 @@ namespace Slic3r { struct Camera; class BackgroundSlicingProcess; -#if !ENABLE_GCODE_VIEWER -class GCodePreviewData; -#endif // !ENABLE_GCODE_VIEWER struct ThumbnailData; class ModelObject; class ModelInstance; @@ -108,11 +103,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent); -#if ENABLE_GCODE_VIEWER wxDECLARE_EVENT(EVT_GLCANVAS_MOVE_LAYERS_SLIDER, wxKeyEvent); -#else -wxDECLARE_EVENT(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, wxKeyEvent); -#endif // ENABLE_GCODE_VIEWER wxDECLARE_EVENT(EVT_GLCANVAS_EDIT_COLOR_CHANGE, wxKeyEvent); wxDECLARE_EVENT(EVT_GLCANVAS_JUMP_TO, wxKeyEvent); wxDECLARE_EVENT(EVT_GLCANVAS_UNDO, SimpleEvent); @@ -127,37 +118,6 @@ class GLCanvas3D { static const double DefaultCameraZoomToBoxMarginFactor; -public: -#if !ENABLE_GCODE_VIEWER - struct GCodePreviewVolumeIndex - { - enum EType - { - Extrusion, - Travel, - Retraction, - Unretraction, - Shell, - Num_Geometry_Types - }; - - struct FirstVolume - { - EType type; - unsigned int flag; - // Index of the first volume in a GLVolumeCollection. - unsigned int id; - - FirstVolume(EType type, unsigned int flag, unsigned int id) : type(type), flag(flag), id(id) {} - }; - - std::vector first_volumes; - - void reset() { first_volumes.clear(); } - }; -#endif // !ENABLE_GCODE_VIEWER - -private: class LayersEditing { public: @@ -355,35 +315,6 @@ private: bool generate(const std::string& msg, const GLCanvas3D& canvas, bool compress, bool red_colored = false); }; -#if !ENABLE_GCODE_VIEWER - class LegendTexture : public GUI::GLTexture - { - static const int Px_Title_Offset = 5; - static const int Px_Text_Offset = 5; - static const int Px_Square = 20; - static const int Px_Square_Contour = 1; - static const int Px_Border = Px_Square / 2; - static const unsigned char Squares_Border_Color[3]; - static const unsigned char Default_Background_Color[3]; - static const unsigned char Error_Background_Color[3]; - static const unsigned char Opacity; - - int m_original_width; - int m_original_height; - - public: - LegendTexture(); - void fill_color_print_legend_items(const GLCanvas3D& canvas, - const std::vector& colors_in, - std::vector& colors, - std::vector& cp_legend_items); - - bool generate(const GCodePreviewData& preview_data, const std::vector& tool_colors, const GLCanvas3D& canvas, bool compress); - - void render(const GLCanvas3D& canvas) const; - }; -#endif // !ENABLE_GCODE_VIEWER - #if ENABLE_RENDER_STATISTICS struct RenderStats { @@ -457,9 +388,6 @@ private: std::unique_ptr m_retina_helper; #endif bool m_in_render; -#if !ENABLE_GCODE_VIEWER - LegendTexture m_legend_texture; -#endif // !ENABLE_GCODE_VIEWER WarningTexture m_warning_texture; wxTimer m_timer; LayersEditing m_layers_editing; @@ -478,9 +406,7 @@ private: bool m_event_handlers_bound{ false }; mutable GLVolumeCollection m_volumes; -#if ENABLE_GCODE_VIEWER GCodeViewer m_gcode_viewer; -#endif // ENABLE_GCODE_VIEWER Selection m_selection; const DynamicPrintConfig* m_config; @@ -492,9 +418,6 @@ private: bool m_initialized; bool m_apply_zoom_to_volumes_filter; mutable std::vector m_hover_volume_idxs; -#if !ENABLE_GCODE_VIEWER - bool m_legend_texture_enabled; -#endif // !ENABLE_GCODE_VIEWER bool m_picking_enabled; bool m_moving_enabled; bool m_dynamic_background_enabled; @@ -512,10 +435,6 @@ private: bool m_reload_delayed; -#if !ENABLE_GCODE_VIEWER - GCodePreviewVolumeIndex m_gcode_preview_volume_index; -#endif // !ENABLE_GCODE_VIEWER - #if ENABLE_RENDER_PICKING_PASS bool m_show_picking_texture; #endif // ENABLE_RENDER_PICKING_PASS @@ -554,11 +473,9 @@ public: void reset_volumes(); int check_volumes_outside_state() const; -#if ENABLE_GCODE_VIEWER void reset_gcode_toolpaths() { m_gcode_viewer.reset(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } -#endif // ENABLE_GCODE_VIEWER void toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1); void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1); @@ -622,9 +539,7 @@ public: void zoom_to_bed(); void zoom_to_volumes(); void zoom_to_selection(); -#if ENABLE_GCODE_VIEWER void zoom_to_gcode(); -#endif // ENABLE_GCODE_VIEWER void select_view(const std::string& direction); void update_volumes_colors_by_extruder(); @@ -641,7 +556,6 @@ public: void delete_selected(); void ensure_on_bed(unsigned int object_idx); -#if ENABLE_GCODE_VIEWER bool is_gcode_legend_enabled() const { return m_gcode_viewer.is_legend_enabled(); } GCodeViewer::EViewType get_gcode_view_type() const { return m_gcode_viewer.get_view_type(); } const std::vector& get_gcode_layers_zs() const; @@ -653,9 +567,6 @@ public: void set_toolpath_view_type(GCodeViewer::EViewType type); void set_volumes_z_range(const std::array& range); void set_toolpaths_z_range(const std::array& range); -#else - std::vector get_current_print_zs(bool active_only) const; -#endif // ENABLE_GCODE_VIEWER void set_toolpaths_range(double low, double high); std::vector load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs); @@ -665,14 +576,10 @@ public: void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false); -#if ENABLE_GCODE_VIEWER void load_gcode_preview(const GCodeProcessor::Result& gcode_result); void refresh_gcode_preview(const GCodeProcessor::Result& gcode_result, const std::vector& str_tool_colors); void set_gcode_view_preview_type(GCodeViewer::EViewType type) { return m_gcode_viewer.set_view_type(type); } GCodeViewer::EViewType get_gcode_view_preview_type() const { return m_gcode_viewer.get_view_type(); } -#else - void load_gcode_preview(const GCodePreviewData& preview_data, const std::vector& str_tool_colors); -#endif // ENABLE_GCODE_VIEWER void load_sla_preview(); void load_preview(const std::vector& str_tool_colors, const std::vector& color_print_values); void bind_event_handlers(); @@ -691,10 +598,6 @@ public: Size get_canvas_size() const; Vec2d get_local_mouse_position() const; -#if !ENABLE_GCODE_VIEWER - void reset_legend_texture(); -#endif // !ENABLE_GCODE_VIEWER - void set_tooltip(const std::string& tooltip) const; // the following methods add a snapshot to the undo/redo stack, unless the given string is empty @@ -792,9 +695,7 @@ private: void _render_background() const; void _render_bed(bool bottom, bool show_axes) const; void _render_objects() const; -#if ENABLE_GCODE_VIEWER void _render_gcode() const; -#endif // ENABLE_GCODE_VIEWER void _render_selection() const; #if ENABLE_RENDER_SELECTION_CENTER void _render_selection_center() const; @@ -802,9 +703,6 @@ private: void _check_and_update_toolbar_icon_scale() const; void _render_overlays() const; void _render_warning_texture() const; -#if !ENABLE_GCODE_VIEWER - void _render_legend_texture() const; -#endif // !ENABLE_GCODE_VIEWER void _render_volumes_for_picking() const; void _render_current_gizmo() const; void _render_gizmos_overlay() const; @@ -852,29 +750,12 @@ private: // Create 3D thick extrusion lines for wipe tower extrusions void _load_wipe_tower_toolpaths(const std::vector& str_tool_colors); -#if !ENABLE_GCODE_VIEWER - // generates gcode extrusion paths geometry - void _load_gcode_extrusion_paths(const GCodePreviewData& preview_data, const std::vector& tool_colors); - // generates gcode travel paths geometry - void _load_gcode_travel_paths(const GCodePreviewData& preview_data, const std::vector& tool_colors); - // generates objects and wipe tower geometry - void _load_fff_shells(); -#endif // !ENABLE_GCODE_VIEWER // Load SLA objects and support structures for objects, for which the slaposSliceSupports step has been finished. void _load_sla_shells(); -#if !ENABLE_GCODE_VIEWER - // sets gcode geometry visibility according to user selection - void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data); -#endif // !ENABLE_GCODE_VIEWER void _update_toolpath_volumes_outside_state(); void _update_sla_shells_outside_state(); void _show_warning_texture_if_needed(WarningTexture::Warning warning); -#if !ENABLE_GCODE_VIEWER - // generates the legend texture in dependence of the current shown view type - void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors); -#endif // !ENABLE_GCODE_VIEWER - // generates a warning texture containing the given message void _set_warning_texture(WarningTexture::Warning warning, bool state); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 637231aae5..8091792e04 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -10,9 +10,7 @@ #include "libslic3r/PresetBundle.hpp" #include "DoubleSlider.hpp" #include "Plater.hpp" -#if ENABLE_GCODE_VIEWER #include "MainFrame.hpp" -#endif // ENABLE_GCODE_VIEWER #include #include @@ -168,62 +166,33 @@ void View3D::render() m_canvas->set_as_dirty(); } -#if ENABLE_GCODE_VIEWER Preview::Preview( wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process, GCodeProcessor::Result* gcode_result, std::function schedule_background_process_func) -#else -Preview::Preview( - wxWindow* parent, Model* model, DynamicPrintConfig* config, - BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function schedule_background_process_func) -#endif // ENABLE_GCODE_VIEWER : m_canvas_widget(nullptr) , m_canvas(nullptr) -#if ENABLE_GCODE_VIEWER , m_left_sizer(nullptr) , m_layers_slider_sizer(nullptr) , m_bottom_toolbar_panel(nullptr) -#else - , m_double_slider_sizer(nullptr) -#endif // ENABLE_GCODE_VIEWER , m_label_view_type(nullptr) , m_choice_view_type(nullptr) , m_label_show(nullptr) , m_combochecklist_features(nullptr) -#if ENABLE_GCODE_VIEWER , m_combochecklist_features_pos(0) , m_combochecklist_options(nullptr) -#else - , m_checkbox_travel(nullptr) - , m_checkbox_retractions(nullptr) - , m_checkbox_unretractions(nullptr) - , m_checkbox_shells(nullptr) - , m_checkbox_legend(nullptr) -#endif // ENABLE_GCODE_VIEWER , m_config(config) , m_process(process) -#if ENABLE_GCODE_VIEWER , m_gcode_result(gcode_result) -#else - , m_gcode_preview_data(gcode_preview_data) -#endif // ENABLE_GCODE_VIEWER , m_number_extruders(1) , m_preferred_color_mode("feature") , m_loaded(false) -#if !ENABLE_GCODE_VIEWER - , m_enabled(false) -#endif // !ENABLE_GCODE_VIEWER , m_schedule_background_process(schedule_background_process_func) #ifdef __linux__ , m_volumes_cleanup_required(false) #endif // __linux__ { - if (init(parent, model)) { -#if !ENABLE_GCODE_VIEWER - show_hide_ui_elements("none"); -#endif // !ENABLE_GCODE_VIEWER + if (init(parent, model)) load_print(); - } } bool Preview::init(wxWindow* parent, Model* model) @@ -231,14 +200,12 @@ bool Preview::init(wxWindow* parent, Model* model) if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */)) return false; -#if ENABLE_GCODE_VIEWER // to match the background of the sliders #ifdef _WIN32 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); #else SetBackgroundColour(GetParent()->GetBackgroundColour()); #endif // _WIN32 -#endif // ENABLE_GCODE_VIEWER m_canvas_widget = OpenGLManager::create_wxglcanvas(*this); if (m_canvas_widget == nullptr) @@ -253,20 +220,11 @@ bool Preview::init(wxWindow* parent, Model* model) m_canvas->enable_legend_texture(true); m_canvas->enable_dynamic_background(true); -#if ENABLE_GCODE_VIEWER m_layers_slider_sizer = create_layers_slider_sizer(); m_bottom_toolbar_panel = new wxPanel(this); m_label_view_type = new wxStaticText(m_bottom_toolbar_panel, wxID_ANY, _L("View")); m_choice_view_type = new wxChoice(m_bottom_toolbar_panel, wxID_ANY); -#else - m_double_slider_sizer = new wxBoxSizer(wxHORIZONTAL); - create_double_slider(); - - m_label_view_type = new wxStaticText(this, wxID_ANY, _L("View")); - - m_choice_view_type = new wxChoice(this, wxID_ANY); -#endif // ENABLE_GCODE_VIEWER m_choice_view_type->Append(_L("Feature type")); m_choice_view_type->Append(_L("Height")); m_choice_view_type->Append(_L("Width")); @@ -277,22 +235,12 @@ bool Preview::init(wxWindow* parent, Model* model) m_choice_view_type->Append(_L("Color Print")); m_choice_view_type->SetSelection(0); -#if ENABLE_GCODE_VIEWER m_label_show = new wxStaticText(m_bottom_toolbar_panel, wxID_ANY, _L("Show")); -#else - m_label_show = new wxStaticText(this, wxID_ANY, _L("Show")); -#endif // ENABLE_GCODE_VIEWER m_combochecklist_features = new wxComboCtrl(); -#if ENABLE_GCODE_VIEWER m_combochecklist_features->Create(m_bottom_toolbar_panel, wxID_ANY, _L("Feature types"), wxDefaultPosition, wxDefaultSize, wxCB_READONLY); -#else - m_combochecklist_features->Create(this, wxID_ANY, _L("Feature types"), wxDefaultPosition, wxDefaultSize, wxCB_READONLY); -#endif // ENABLE_GCODE_VIEWER std::string feature_items = GUI::into_u8( -#if ENABLE_GCODE_VIEWER _L("Unknown") + "|1|" + -#endif // ENABLE_GCODE_VIEWER _L("Perimeter") + "|1|" + _L("External perimeter") + "|1|" + _L("Overhang perimeter") + "|1|" + @@ -310,7 +258,6 @@ bool Preview::init(wxWindow* parent, Model* model) ); Slic3r::GUI::create_combochecklist(m_combochecklist_features, GUI::into_u8(_L("Feature types")), feature_items); -#if ENABLE_GCODE_VIEWER m_combochecklist_options = new wxComboCtrl(); m_combochecklist_options->Create(m_bottom_toolbar_panel, wxID_ANY, _L("Options"), wxDefaultPosition, wxDefaultSize, wxCB_READONLY); std::string options_items = GUI::into_u8( @@ -324,18 +271,9 @@ bool Preview::init(wxWindow* parent, Model* model) get_option_type_string(OptionType::Shells) + "|0|" + get_option_type_string(OptionType::ToolMarker) + "|1|" + get_option_type_string(OptionType::Legend) + "|1" -); + ); Slic3r::GUI::create_combochecklist(m_combochecklist_options, GUI::into_u8(_L("Options")), options_items); -#else - m_checkbox_travel = new wxCheckBox(this, wxID_ANY, _L("Travel")); - m_checkbox_retractions = new wxCheckBox(this, wxID_ANY, _L("Retractions")); - m_checkbox_unretractions = new wxCheckBox(this, wxID_ANY, _L("Deretractions")); - m_checkbox_shells = new wxCheckBox(this, wxID_ANY, _L("Shells")); - m_checkbox_legend = new wxCheckBox(this, wxID_ANY, _L("Legend")); - m_checkbox_legend->SetValue(true); -#endif // ENABLE_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER m_left_sizer = new wxBoxSizer(wxVERTICAL); m_left_sizer->Add(m_canvas_widget, 1, wxALL | wxEXPAND, 0); @@ -366,32 +304,6 @@ bool Preview::init(wxWindow* parent, Model* model) wxBoxSizer* main_sizer = new wxBoxSizer(wxHORIZONTAL); main_sizer->Add(m_left_sizer, 1, wxALL | wxEXPAND, 0); main_sizer->Add(right_sizer, 0, wxALL | wxEXPAND, 0); -#else - wxBoxSizer* top_sizer = new wxBoxSizer(wxHORIZONTAL); - top_sizer->Add(m_canvas_widget, 1, wxALL | wxEXPAND, 0); - top_sizer->Add(m_double_slider_sizer, 0, wxEXPAND, 0); - - wxBoxSizer* bottom_sizer = new wxBoxSizer(wxHORIZONTAL); - bottom_sizer->Add(m_label_view_type, 0, wxALIGN_CENTER_VERTICAL, 5); - bottom_sizer->Add(m_choice_view_type, 0, wxEXPAND | wxALL, 5); - bottom_sizer->AddSpacer(10); - bottom_sizer->Add(m_label_show, 0, wxALIGN_CENTER_VERTICAL, 5); - bottom_sizer->Add(m_combochecklist_features, 0, wxEXPAND | wxALL, 5); - bottom_sizer->AddSpacer(20); - bottom_sizer->Add(m_checkbox_travel, 0, wxEXPAND | wxALL, 5); - bottom_sizer->AddSpacer(10); - bottom_sizer->Add(m_checkbox_retractions, 0, wxEXPAND | wxALL, 5); - bottom_sizer->AddSpacer(10); - bottom_sizer->Add(m_checkbox_unretractions, 0, wxEXPAND | wxALL, 5); - bottom_sizer->AddSpacer(10); - bottom_sizer->Add(m_checkbox_shells, 0, wxEXPAND | wxALL, 5); - bottom_sizer->AddSpacer(20); - bottom_sizer->Add(m_checkbox_legend, 0, wxEXPAND | wxALL, 5); - - wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL); - main_sizer->Add(top_sizer, 1, wxALL | wxEXPAND, 0); - main_sizer->Add(bottom_sizer, 0, wxALL | wxEXPAND, 0); -#endif // ENABLE_GCODE_VIEWER SetSizer(main_sizer); SetMinSize(GetSize()); @@ -399,26 +311,6 @@ bool Preview::init(wxWindow* parent, Model* model) bind_event_handlers(); -#if !ENABLE_GCODE_VIEWER - // sets colors for gcode preview extrusion roles - std::vector extrusion_roles_colors = { - "Perimeter", "FFFF66", - "External perimeter", "FFA500", - "Overhang perimeter", "0000FF", - "Internal infill", "B1302A", - "Solid infill", "D732D7", - "Top solid infill", "FF1A1A", - "Bridge infill", "9999FF", - "Gap fill", "FFFFFF", - "Skirt", "845321", - "Support material", "00FF00", - "Support material interface", "008000", - "Wipe tower", "B3E3AB", - "Custom", "28CC94" - }; - m_gcode_preview_data->set_extrusion_paths_colors(extrusion_roles_colors); -#endif // !ENABLE_GCODE_VIEWER - return true; } @@ -441,31 +333,18 @@ void Preview::set_as_dirty() void Preview::set_number_extruders(unsigned int number_extruders) { - if (m_number_extruders != number_extruders) - { + if (m_number_extruders != number_extruders) { m_number_extruders = number_extruders; int tool_idx = m_choice_view_type->FindString(_(L("Tool"))); int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type m_choice_view_type->SetSelection(type); -#if ENABLE_GCODE_VIEWER - if ((0 <= type) && (type < static_cast(GCodeViewer::EViewType::Count))) + if (0 <= type && (type < static_cast(GCodeViewer::EViewType::Count))) m_canvas->set_gcode_view_preview_type(static_cast(type)); -#else - if ((0 <= type) && (type < (int)GCodePreviewData::Extrusion::Num_View_Types)) - m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; -#endif // ENABLE_GCODE_VIEWER m_preferred_color_mode = (type == tool_idx) ? "tool_or_feature" : "feature"; } } -#if !ENABLE_GCODE_VIEWER -void Preview::set_enabled(bool enabled) -{ - m_enabled = enabled; -} -#endif // !ENABLE_GCODE_VIEWER - void Preview::bed_shape_changed() { if (m_canvas != nullptr) @@ -491,9 +370,7 @@ void Preview::load_print(bool keep_z_range) else if (tech == ptSLA) load_print_as_sla(); -#if ENABLE_GCODE_VIEWER update_bottom_toolbar(); -#endif // ENABLE_GCODE_VIEWER Layout(); } @@ -515,9 +392,6 @@ void Preview::reload_print(bool keep_volumes) !keep_volumes) { m_canvas->reset_volumes(); -#if !ENABLE_GCODE_VIEWER - m_canvas->reset_legend_texture(); -#endif // !ENABLE_GCODE_VIEWER m_loaded = false; #ifdef __linux__ m_volumes_cleanup_required = false; @@ -540,12 +414,8 @@ void Preview::refresh_print() void Preview::msw_rescale() { // rescale slider -#if ENABLE_GCODE_VIEWER if (m_layers_slider != nullptr) m_layers_slider->msw_rescale(); if (m_moves_slider != nullptr) m_moves_slider->msw_rescale(); -#else - if (m_slider) m_slider->msw_rescale(); -#endif // ENABLE_GCODE_VIEWER // rescale warning legend on the canvas get_canvas3d()->msw_rescale(); @@ -556,55 +426,26 @@ void Preview::msw_rescale() void Preview::jump_layers_slider(wxKeyEvent& evt) { -#if ENABLE_GCODE_VIEWER if (m_layers_slider) m_layers_slider->OnChar(evt); -#else - if (m_slider) - m_slider->OnKeyDown(evt); -#endif // ENABLE_GCODE_VIEWER } -#if ENABLE_GCODE_VIEWER void Preview::move_layers_slider(wxKeyEvent& evt) { if (m_layers_slider != nullptr) m_layers_slider->OnKeyDown(evt); } -#else -void Preview::move_double_slider(wxKeyEvent& evt) -{ - if (m_slider) - m_slider->OnKeyDown(evt); -} -#endif // ENABLE_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER void Preview::edit_layers_slider(wxKeyEvent& evt) { if (m_layers_slider != nullptr) m_layers_slider->OnChar(evt); } -#else -void Preview::edit_double_slider(wxKeyEvent& evt) -{ - if (m_slider) - m_slider->OnChar(evt); -} -#endif // ENABLE_GCODE_VIEWER void Preview::bind_event_handlers() { this->Bind(wxEVT_SIZE, &Preview::on_size, this); m_choice_view_type->Bind(wxEVT_CHOICE, &Preview::on_choice_view_type, this); m_combochecklist_features->Bind(wxEVT_CHECKLISTBOX, &Preview::on_combochecklist_features, this); -#if ENABLE_GCODE_VIEWER m_combochecklist_options->Bind(wxEVT_CHECKLISTBOX, &Preview::on_combochecklist_options, this); m_moves_slider->Bind(wxEVT_SCROLL_CHANGED, &Preview::on_moves_slider_scroll_changed, this); -#else - m_checkbox_travel->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_travel, this); - m_checkbox_retractions->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_retractions, this); - m_checkbox_unretractions->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_unretractions, this); - m_checkbox_shells->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_shells, this); - m_checkbox_legend->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_legend, this); -#endif // ENABLE_GCODE_VIEWER } void Preview::unbind_event_handlers() @@ -612,76 +453,15 @@ void Preview::unbind_event_handlers() this->Unbind(wxEVT_SIZE, &Preview::on_size, this); m_choice_view_type->Unbind(wxEVT_CHOICE, &Preview::on_choice_view_type, this); m_combochecklist_features->Unbind(wxEVT_CHECKLISTBOX, &Preview::on_combochecklist_features, this); -#if ENABLE_GCODE_VIEWER m_combochecklist_options->Unbind(wxEVT_CHECKLISTBOX, &Preview::on_combochecklist_options, this); m_moves_slider->Unbind(wxEVT_SCROLL_CHANGED, &Preview::on_moves_slider_scroll_changed, this); -#else - m_checkbox_travel->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_travel, this); - m_checkbox_retractions->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_retractions, this); - m_checkbox_unretractions->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_unretractions, this); - m_checkbox_shells->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_shells, this); - m_checkbox_legend->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_legend, this); -#endif // ENABLE_GCODE_VIEWER } -#if !ENABLE_GCODE_VIEWER -void Preview::show_hide_ui_elements(const std::string& what) -{ - bool enable = (what == "full"); - m_label_show->Enable(enable); - m_combochecklist_features->Enable(enable); - m_checkbox_travel->Enable(enable); - m_checkbox_retractions->Enable(enable); - m_checkbox_unretractions->Enable(enable); - m_checkbox_shells->Enable(enable); - m_checkbox_legend->Enable(enable); - - enable = (what != "none"); - m_label_view_type->Enable(enable); - m_choice_view_type->Enable(enable); - - bool visible = (what != "none"); - m_label_show->Show(visible); - m_combochecklist_features->Show(visible); - m_checkbox_travel->Show(visible); - m_checkbox_retractions->Show(visible); - m_checkbox_unretractions->Show(visible); - m_checkbox_shells->Show(visible); - m_checkbox_legend->Show(visible); - m_label_view_type->Show(visible); - m_choice_view_type->Show(visible); -} -#endif // !ENABLE_GCODE_VIEWER - -#if ENABLE_GCODE_VIEWER void Preview::hide_layers_slider() { m_layers_slider_sizer->Hide((size_t)0); Layout(); } -#else -void Preview::reset_sliders(bool reset_all) -{ - m_enabled = false; - // reset_double_slider(); - if (reset_all) - m_double_slider_sizer->Hide((size_t)0); - else - m_double_slider_sizer->GetItem(size_t(0))->GetSizer()->Hide(1); -} -#endif // ENABLE_GCODE_VIEWER - -#if !ENABLE_GCODE_VIEWER -void Preview::update_sliders(const std::vector& layers_z, bool keep_z_range) -{ - m_enabled = true; - update_double_slider(layers_z, keep_z_range); - - m_double_slider_sizer->Show((size_t)0); - - Layout(); -} -#endif // !ENABLE_GCODE_VIEWER void Preview::on_size(wxSizeEvent& evt) { @@ -693,31 +473,19 @@ void Preview::on_choice_view_type(wxCommandEvent& evt) { m_preferred_color_mode = (m_choice_view_type->GetStringSelection() == L("Tool")) ? "tool" : "feature"; int selection = m_choice_view_type->GetCurrentSelection(); -#if ENABLE_GCODE_VIEWER if (0 <= selection && selection < static_cast(GCodeViewer::EViewType::Count)) m_canvas->set_toolpath_view_type(static_cast(selection)); refresh_print(); -#else - if ((0 <= selection) && (selection < (int)GCodePreviewData::Extrusion::Num_View_Types)) - m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)selection; - - reload_print(); -#endif // ENABLE_GCODE_VIEWER } void Preview::on_combochecklist_features(wxCommandEvent& evt) { unsigned int flags = Slic3r::GUI::combochecklist_get_flags(m_combochecklist_features); -#if ENABLE_GCODE_VIEWER m_canvas->set_toolpath_role_visibility_flags(flags); -#else - m_gcode_preview_data->extrusion.role_flags = flags; -#endif // ENABLE_GCODE_VIEWER refresh_print(); } -#if ENABLE_GCODE_VIEWER void Preview::on_combochecklist_options(wxCommandEvent& evt) { auto xored = [](unsigned int flags1, unsigned int flags2, unsigned int flag) { @@ -742,39 +510,6 @@ void Preview::on_combochecklist_options(wxCommandEvent& evt) else m_canvas->set_as_dirty(); } -#else -void Preview::on_checkbox_travel(wxCommandEvent& evt) -{ - m_gcode_preview_data->travel.is_visible = m_checkbox_travel->IsChecked(); - m_gcode_preview_data->ranges.feedrate.set_mode(GCodePreviewData::FeedrateKind::TRAVEL, m_gcode_preview_data->travel.is_visible); - // Rather than refresh, reload print so that speed color ranges get recomputed (affected by travel visibility) - reload_print(); -} - -void Preview::on_checkbox_retractions(wxCommandEvent& evt) -{ - m_gcode_preview_data->retraction.is_visible = m_checkbox_retractions->IsChecked(); - refresh_print(); -} - -void Preview::on_checkbox_unretractions(wxCommandEvent& evt) -{ - m_gcode_preview_data->unretraction.is_visible = m_checkbox_unretractions->IsChecked(); - refresh_print(); -} - -void Preview::on_checkbox_shells(wxCommandEvent& evt) -{ - m_gcode_preview_data->shell.is_visible = m_checkbox_shells->IsChecked(); - refresh_print(); -} - -void Preview::on_checkbox_legend(wxCommandEvent& evt) -{ - m_canvas->enable_legend_texture(m_checkbox_legend->IsChecked()); - m_canvas_widget->Refresh(); -} -#endif // ENABLE_GCODE_VIEWER void Preview::update_view_type(bool keep_volumes) { @@ -790,49 +525,34 @@ void Preview::update_view_type(bool keep_volumes) int type = m_choice_view_type->FindString(choice); if (m_choice_view_type->GetSelection() != type) { m_choice_view_type->SetSelection(type); -#if ENABLE_GCODE_VIEWER - if ((0 <= type) && (type < static_cast(GCodeViewer::EViewType::Count))) + if (0 <= type && type < static_cast(GCodeViewer::EViewType::Count)) m_canvas->set_gcode_view_preview_type(static_cast(type)); -#else - if (0 <= type && type < (int)GCodePreviewData::Extrusion::Num_View_Types) - m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; -#endif // ENABLE_GCODE_VIEWER m_preferred_color_mode = "feature"; } -#if ENABLE_GCODE_VIEWER reload_print(keep_volumes); -#else - reload_print(); -#endif // ENABLE_GCODE_VIEWER } -#if ENABLE_GCODE_VIEWER void Preview::update_bottom_toolbar() { combochecklist_set_flags(m_combochecklist_features, m_canvas->get_toolpath_role_visibility_flags()); combochecklist_set_flags(m_combochecklist_options, m_canvas->get_gcode_options_visibility_flags()); // updates visibility of features combobox - if (m_bottom_toolbar_panel->IsShown()) - { + if (m_bottom_toolbar_panel->IsShown()) { wxSizer* sizer = m_bottom_toolbar_panel->GetSizer(); bool show = !m_canvas->is_gcode_legend_enabled() || m_canvas->get_gcode_view_type() != GCodeViewer::EViewType::FeatureType; - if (show) - { - if (sizer->GetItem(m_combochecklist_features) == nullptr) - { + if (show) { + if (sizer->GetItem(m_combochecklist_features) == nullptr) { sizer->Insert(m_combochecklist_features_pos, m_combochecklist_features, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5); sizer->Show(m_combochecklist_features); sizer->Layout(); Refresh(); } } - else - { - if (sizer->GetItem(m_combochecklist_features) != nullptr) - { + else { + if (sizer->GetItem(m_combochecklist_features) != nullptr) { sizer->Hide(m_combochecklist_features); sizer->Detach(m_combochecklist_features); sizer->Layout(); @@ -841,9 +561,7 @@ void Preview::update_bottom_toolbar() } } } -#endif // ENABLE_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER wxBoxSizer* Preview::create_layers_slider_sizer() { wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); @@ -875,37 +593,6 @@ wxBoxSizer* Preview::create_layers_slider_sizer() return sizer; } -#else -void Preview::create_double_slider() -{ - m_slider = new DoubleSlider::Control(this, wxID_ANY, 0, 0, 0, 100); - - bool sla_print_technology = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA; - bool sequential_print = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects"); - m_slider->SetDrawMode(sla_print_technology, sequential_print); - - m_double_slider_sizer->Add(m_slider, 0, wxEXPAND, 0); - - - // sizer, m_canvas_widget - m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this); - m_canvas_widget->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& event) { - if (event.GetKeyCode() == WXK_SHIFT) - m_slider->UseDefaultColors(true); - event.Skip(); - }); - - m_slider->Bind(wxEVT_SCROLL_CHANGED, &Preview::on_sliders_scroll_changed, this); - - Bind(DoubleSlider::wxCUSTOMEVT_TICKSCHANGED, [this](wxEvent&) { - Model& model = wxGetApp().plater()->model(); - model.custom_gcode_per_print_z = m_slider->GetTicksValues(); - m_schedule_background_process(); - - update_view_type(false); - }); -} -#endif // ENABLE_GCODE_VIEWER // Find an index of a value in a sorted vector, which is in . // Returns -1 if there is no such member. @@ -934,12 +621,7 @@ static int find_close_layer_idx(const std::vector& zs, double &z, double return -1; } -#if ENABLE_GCODE_VIEWER void Preview::check_layers_slider_values(std::vector& ticks_from_model, const std::vector& layers_z) -#else -void Preview::check_slider_values(std::vector& ticks_from_model, - const std::vector& layers_z) -#endif // ENABLE_GCODE_VIEWER { // All ticks that would end up outside the slider range should be erased. // TODO: this should be placed into more appropriate part of code, @@ -956,7 +638,6 @@ void Preview::check_slider_values(std::vector& ticks_from_mod m_schedule_background_process(); } -#if ENABLE_GCODE_VIEWER void Preview::update_layers_slider(const std::vector& layers_z, bool keep_z_range) { // Save the initial slider span. @@ -1009,64 +690,8 @@ void Preview::update_layers_slider(const std::vector& layers_z, bool kee m_layers_slider_sizer->Show((size_t)0); Layout(); } -#else -void Preview::update_double_slider(const std::vector & layers_z, bool keep_z_range) -{ - // Save the initial slider span. - double z_low = m_slider->GetLowerValueD(); - double z_high = m_slider->GetHigherValueD(); - bool was_empty = m_slider->GetMaxValue() == 0; - bool force_sliders_full_range = was_empty; - if (!keep_z_range) - { - bool span_changed = layers_z.empty() || std::abs(layers_z.back() - m_slider->GetMaxValueD()) > DoubleSlider::epsilon()/*1e-6*/; - force_sliders_full_range |= span_changed; - } - bool snap_to_min = force_sliders_full_range || m_slider->is_lower_at_min(); - bool snap_to_max = force_sliders_full_range || m_slider->is_higher_at_max(); - - // Detect and set manipulation mode for double slider - update_double_slider_mode(); - - CustomGCode::Info& ticks_info_from_model = wxGetApp().plater()->model().custom_gcode_per_print_z; - check_slider_values(ticks_info_from_model.gcodes, layers_z); - - m_slider->SetSliderValues(layers_z); - assert(m_slider->GetMinValue() == 0); - m_slider->SetMaxValue(layers_z.empty() ? 0 : layers_z.size() - 1); - - int idx_low = 0; - int idx_high = m_slider->GetMaxValue(); - if (!layers_z.empty()) { - if (!snap_to_min) { - int idx_new = find_close_layer_idx(layers_z, z_low, DoubleSlider::epsilon()/*1e-6*/); - if (idx_new != -1) - idx_low = idx_new; - } - if (!snap_to_max) { - int idx_new = find_close_layer_idx(layers_z, z_high, DoubleSlider::epsilon()/*1e-6*/); - if (idx_new != -1) - idx_high = idx_new; - } - } - m_slider->SetSelectionSpan(idx_low, idx_high); - - m_slider->SetTicksValues(ticks_info_from_model); - - bool sla_print_technology = wxGetApp().plater()->printer_technology() == ptSLA; - bool sequential_print = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects"); - m_slider->SetDrawMode(sla_print_technology, sequential_print); - - m_slider->SetExtruderColors(wxGetApp().plater()->get_extruder_colors_from_plater_config()); -} -#endif // ENABLE_GCODE_VIEWER - -#if ENABLE_GCODE_VIEWER void Preview::update_layers_slider_mode() -#else -void Preview::update_double_slider_mode() -#endif // ENABLE_GCODE_VIEWER { // true -> single-extruder printer profile OR // multi-extruder printer profile , but whole model is printed by only one extruder @@ -1115,28 +740,15 @@ void Preview::update_double_slider_mode() } } -#if ENABLE_GCODE_VIEWER m_layers_slider->SetModeAndOnlyExtruder(one_extruder_printed_model, only_extruder); -#else - m_slider->SetModeAndOnlyExtruder(one_extruder_printed_model, only_extruder); -#endif // ENABLE_GCODE_VIEWER } -#if ENABLE_GCODE_VIEWER void Preview::reset_layers_slider() { m_layers_slider->SetHigherValue(0); m_layers_slider->SetLowerValue(0); } -#else -void Preview::reset_double_slider() -{ - m_slider->SetHigherValue(0); - m_slider->SetLowerValue(0); -} -#endif // ENABLE_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER void Preview::update_layers_slider_from_canvas(wxKeyEvent& event) { if (event.HasModifiers()) { @@ -1185,42 +797,12 @@ void Preview::enable_moves_slider(bool enable) m_moves_slider->Refresh(); } } -#else -void Preview::update_double_slider_from_canvas(wxKeyEvent & event) -{ - if (event.HasModifiers()) { - event.Skip(); - return; - } - - const auto key = event.GetKeyCode(); - - if (key == 'U' || key == 'D') { - const int new_pos = key == 'U' ? m_slider->GetHigherValue() + 1 : m_slider->GetHigherValue() - 1; - m_slider->SetHigherValue(new_pos); - if (event.ShiftDown() || m_slider->is_one_layer()) m_slider->SetLowerValue(m_slider->GetHigherValue()); - } - else if (key == 'L') { - m_checkbox_legend->SetValue(!m_checkbox_legend->GetValue()); - auto evt = wxCommandEvent(); - on_checkbox_legend(evt); - } - else if (key == 'S') - m_slider->ChangeOneLayerLock(); - else if (key == WXK_SHIFT) - m_slider->UseDefaultColors(false); - else - event.Skip(); -} -#endif // ENABLE_GCODE_VIEWER void Preview::load_print_as_fff(bool keep_z_range) { -#if ENABLE_GCODE_VIEWER if (wxGetApp().mainframe == nullptr || wxGetApp().is_recreating_gui()) // avoid processing while mainframe is being constructed return; -#endif // ENABLE_GCODE_VIEWER if (m_loaded || m_process->current_printer_technology() != ptFFF) return; @@ -1245,17 +827,11 @@ void Preview::load_print_as_fff(bool keep_z_range) } } -#if ENABLE_GCODE_VIEWER if (wxGetApp().is_editor() && !has_layers) { hide_layers_slider(); m_left_sizer->Hide(m_bottom_toolbar_panel); m_left_sizer->Layout(); Refresh(); -#else - if (! has_layers) { - reset_sliders(true); - m_canvas->reset_legend_texture(); -#endif // ENABLE_GCODE_VIEWER m_canvas_widget->Refresh(); return; } @@ -1267,100 +843,58 @@ void Preview::load_print_as_fff(bool keep_z_range) int tool_idx = m_choice_view_type->FindString(_L("Tool")); int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type m_choice_view_type->SetSelection(type); -#if ENABLE_GCODE_VIEWER if (0 <= type && type < static_cast(GCodeViewer::EViewType::Count)) m_canvas->set_gcode_view_preview_type(static_cast(type)); -#else - if ((0 <= type) && (type < (int)GCodePreviewData::Extrusion::Num_View_Types)) - m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; -#endif // ENABLE_GCODE_VIEWER // If the->SetSelection changed the following line, revert it to "decide yourself". m_preferred_color_mode = "tool_or_feature"; } -#if ENABLE_GCODE_VIEWER GCodeViewer::EViewType gcode_view_type = m_canvas->get_gcode_view_preview_type(); bool gcode_preview_data_valid = !m_gcode_result->moves.empty(); -#else - bool gcode_preview_data_valid = print->is_step_done(psGCodeExport) && ! m_gcode_preview_data->empty(); -#endif // ENABLE_GCODE_VIEWER // Collect colors per extruder. std::vector colors; std::vector color_print_values = {}; // set color print values, if it si selected "ColorPrint" view type -#if ENABLE_GCODE_VIEWER if (gcode_view_type == GCodeViewer::EViewType::ColorPrint) { colors = wxGetApp().plater()->get_colors_for_color_print(m_gcode_result); -#else - if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint) { - colors = wxGetApp().plater()->get_colors_for_color_print(); - colors.push_back("#808080"); // gray color for pause print or custom G-code -#endif // ENABLE_GCODE_VIEWER if (!gcode_preview_data_valid) { color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes; -#if ENABLE_GCODE_VIEWER colors.push_back("#808080"); // gray color for pause print or custom G-code -#endif // ENABLE_GCODE_VIEWER } } -#if ENABLE_GCODE_VIEWER else if (gcode_preview_data_valid || gcode_view_type == GCodeViewer::EViewType::Tool) { colors = wxGetApp().plater()->get_extruder_colors_from_plater_config(m_gcode_result); -#else - else if (gcode_preview_data_valid || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool) ) { - colors = wxGetApp().plater()->get_extruder_colors_from_plater_config(); -#endif // ENABLE_GCODE_VIEWER color_print_values.clear(); } if (IsShown()) { -#if ENABLE_GCODE_VIEWER std::vector zs; -#endif // ENABLE_GCODE_VIEWER m_canvas->set_selected_extruder(0); if (gcode_preview_data_valid) { // Load the real G-code preview. -#if ENABLE_GCODE_VIEWER m_canvas->load_gcode_preview(*m_gcode_result); m_canvas->refresh_gcode_preview(*m_gcode_result, colors); m_left_sizer->Show(m_bottom_toolbar_panel); m_left_sizer->Layout(); Refresh(); zs = m_canvas->get_gcode_layers_zs(); -#else - m_canvas->load_gcode_preview(*m_gcode_preview_data, colors); -#endif // ENABLE_GCODE_VIEWER m_loaded = true; } else { // Load the initial preview based on slices, not the final G-code. m_canvas->load_preview(colors, color_print_values); -#if ENABLE_GCODE_VIEWER m_left_sizer->Hide(m_bottom_toolbar_panel); m_left_sizer->Layout(); Refresh(); zs = m_canvas->get_volumes_print_zs(true); -#endif // ENABLE_GCODE_VIEWER } -#if !ENABLE_GCODE_VIEWER - show_hide_ui_elements(gcode_preview_data_valid ? "full" : "simple"); - std::vector zs = m_canvas->get_current_print_zs(true); -#endif // !ENABLE_GCODE_VIEWER if (zs.empty()) { // all layers filtered out -#if ENABLE_GCODE_VIEWER hide_layers_slider(); -#else - reset_sliders(true); -#endif // ENABLE_GCODE_VIEWER m_canvas_widget->Refresh(); } else -#if ENABLE_GCODE_VIEWER update_layers_slider(zs, keep_z_range); -#else - update_sliders(zs, keep_z_range); -#endif // ENABLE_GCODE_VIEWER } } @@ -1375,8 +909,7 @@ void Preview::load_print_as_sla() std::vector zs; double initial_layer_height = print->material_config().initial_layer_height.value; for (const SLAPrintObject* obj : print->objects()) - if (obj->is_step_done(slaposSliceSupports) && !obj->get_slice_index().empty()) - { + if (obj->is_step_done(slaposSliceSupports) && !obj->get_slice_index().empty()) { auto low_coord = obj->get_slice_index().front().print_level(); for (auto& rec : obj->get_slice_index()) zs.emplace_back(initial_layer_height + (rec.print_level() - low_coord) * SCALING_FACTOR); @@ -1386,74 +919,43 @@ void Preview::load_print_as_sla() m_canvas->reset_clipping_planes_cache(); n_layers = (unsigned int)zs.size(); - if (n_layers == 0) - { -#if ENABLE_GCODE_VIEWER + if (n_layers == 0) { hide_layers_slider(); -#else - reset_sliders(true); -#endif // ENABLE_GCODE_VIEWER m_canvas_widget->Refresh(); } - if (IsShown()) - { + if (IsShown()) { m_canvas->load_sla_preview(); -#if ENABLE_GCODE_VIEWER m_left_sizer->Hide(m_bottom_toolbar_panel); m_left_sizer->Hide(m_bottom_toolbar_panel); m_left_sizer->Layout(); Refresh(); -#else - show_hide_ui_elements("none"); -#endif // ENABLE_GCODE_VIEWER if (n_layers > 0) -#if ENABLE_GCODE_VIEWER update_layers_slider(zs); -#else - update_sliders(zs); -#endif // ENABLE_GCODE_VIEWER m_loaded = true; } } -#if ENABLE_GCODE_VIEWER void Preview::on_layers_slider_scroll_changed(wxCommandEvent& event) -#else -void Preview::on_sliders_scroll_changed(wxCommandEvent& event) -#endif // ENABLE_GCODE_VIEWER { if (IsShown()) { PrinterTechnology tech = m_process->current_printer_technology(); if (tech == ptFFF) { -#if ENABLE_GCODE_VIEWER m_canvas->set_volumes_z_range({ m_layers_slider->GetLowerValueD(), m_layers_slider->GetHigherValueD() }); m_canvas->set_toolpaths_z_range({ static_cast(m_layers_slider->GetLowerValue()), static_cast(m_layers_slider->GetHigherValue()) }); m_canvas->set_as_dirty(); -#else - m_canvas->set_toolpaths_range(m_slider->GetLowerValueD() - 1e-6, m_slider->GetHigherValueD() + 1e-6); - m_canvas->render(); - m_canvas->set_use_clipping_planes(false); -#endif // ENABLE_GCODE_VIEWER } else if (tech == ptSLA) { -#if ENABLE_GCODE_VIEWER m_canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), -m_layers_slider->GetLowerValueD())); m_canvas->set_clipping_plane(1, ClippingPlane(-Vec3d::UnitZ(), m_layers_slider->GetHigherValueD())); m_canvas->set_use_clipping_planes(m_layers_slider->GetHigherValue() != 0); -#else - m_canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), -m_slider->GetLowerValueD())); - m_canvas->set_clipping_plane(1, ClippingPlane(-Vec3d::UnitZ(), m_slider->GetHigherValueD())); - m_canvas->set_use_clipping_planes(m_slider->GetHigherValue() != 0); -#endif // ENABLE_GCODE_VIEWER m_canvas->render(); } } } -#if ENABLE_GCODE_VIEWER void Preview::on_moves_slider_scroll_changed(wxCommandEvent& event) { m_canvas->update_gcode_sequential_view_current(static_cast(m_moves_slider->GetLowerValueD() - 1.0), static_cast(m_moves_slider->GetHigherValueD() - 1.0)); @@ -1477,7 +979,6 @@ wxString Preview::get_option_type_string(OptionType type) const default: { return ""; } } } -#endif // ENABLE_GCODE_VIEWER } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 5ad70a1ac7..76fef117ee 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -7,9 +7,7 @@ #include "libslic3r/CustomGCode.hpp" #include -#if ENABLE_GCODE_VIEWER #include "libslic3r/GCode/GCodeProcessor.hpp" -#endif // ENABLE_GCODE_VIEWER class wxNotebook; class wxGLCanvas; @@ -25,9 +23,6 @@ namespace Slic3r { class DynamicPrintConfig; class Print; class BackgroundSlicingProcess; -#if !ENABLE_GCODE_VIEWER -class GCodePreviewData; -#endif // !ENABLE_GCODE_VIEWER class Model; namespace DoubleSlider { @@ -83,35 +78,19 @@ class Preview : public wxPanel { wxGLCanvas* m_canvas_widget; GLCanvas3D* m_canvas; -#if ENABLE_GCODE_VIEWER wxBoxSizer* m_left_sizer; wxBoxSizer* m_layers_slider_sizer; wxPanel* m_bottom_toolbar_panel; -#else - wxBoxSizer* m_double_slider_sizer; -#endif // ENABLE_GCODE_VIEWER wxStaticText* m_label_view_type; wxChoice* m_choice_view_type; wxStaticText* m_label_show; wxComboCtrl* m_combochecklist_features; -#if ENABLE_GCODE_VIEWER size_t m_combochecklist_features_pos; wxComboCtrl* m_combochecklist_options; -#else - wxCheckBox* m_checkbox_travel; - wxCheckBox* m_checkbox_retractions; - wxCheckBox* m_checkbox_unretractions; - wxCheckBox* m_checkbox_shells; - wxCheckBox* m_checkbox_legend; -#endif // ENABLE_GCODE_VIEWER DynamicPrintConfig* m_config; BackgroundSlicingProcess* m_process; -#if ENABLE_GCODE_VIEWER GCodeProcessor::Result* m_gcode_result; -#else - GCodePreviewData* m_gcode_preview_data; -#endif // ENABLE_GCODE_VIEWER #ifdef __linux__ // We are getting mysterious crashes on Linux in gtk due to OpenGL context activation GH #1874 #1955. @@ -126,19 +105,11 @@ class Preview : public wxPanel std::string m_preferred_color_mode; bool m_loaded; -#if !ENABLE_GCODE_VIEWER - bool m_enabled; -#endif // !ENABLE_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER DoubleSlider::Control* m_layers_slider{ nullptr }; DoubleSlider::Control* m_moves_slider{ nullptr }; -#else - DoubleSlider::Control* m_slider {nullptr}; -#endif // ENABLE_GCODE_VIEWER public: -#if ENABLE_GCODE_VIEWER enum class OptionType : unsigned int { Travel, @@ -153,12 +124,8 @@ public: Legend }; -Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process, - GCodeProcessor::Result* gcode_result, std::function schedule_background_process = []() {}); -#else -Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config, - BackgroundSlicingProcess* process, GCodePreviewData* gcode_preview_data, std::function schedule_background_process = []() {}); -#endif // ENABLE_GCODE_VIEWER + Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config, BackgroundSlicingProcess* process, + GCodeProcessor::Result* gcode_result, std::function schedule_background_process = []() {}); virtual ~Preview(); wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; } @@ -167,9 +134,6 @@ Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config, void set_as_dirty(); void set_number_extruders(unsigned int number_extruders); -#if !ENABLE_GCODE_VIEWER - void set_enabled(bool enabled); -#endif // !ENABLE_GCODE_VIEWER void bed_shape_changed(); void select_view(const std::string& direction); void set_drop_target(wxDropTarget* target); @@ -180,24 +144,17 @@ Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config, void msw_rescale(); void jump_layers_slider(wxKeyEvent& evt); -#if ENABLE_GCODE_VIEWER void move_layers_slider(wxKeyEvent& evt); void edit_layers_slider(wxKeyEvent& evt); -#else - void move_double_slider(wxKeyEvent& evt); - void edit_double_slider(wxKeyEvent& evt); -#endif // ENABLE_GCODE_VIEWER void update_view_type(bool keep_volumes); bool is_loaded() const { return m_loaded; } -#if ENABLE_GCODE_VIEWER void update_bottom_toolbar(); void update_moves_slider(); void enable_moves_slider(bool enable); void hide_layers_slider(); -#endif // ENABLE_GCODE_VIEWER private: bool init(wxWindow* parent, Model* model); @@ -205,27 +162,11 @@ private: void bind_event_handlers(); void unbind_event_handlers(); -#if !ENABLE_GCODE_VIEWER - void show_hide_ui_elements(const std::string& what); - - void reset_sliders(bool reset_all); - void update_sliders(const std::vector& layers_z, bool keep_z_range = false); -#endif // !ENABLE_GCODE_VIEWER - void on_size(wxSizeEvent& evt); void on_choice_view_type(wxCommandEvent& evt); void on_combochecklist_features(wxCommandEvent& evt); -#if ENABLE_GCODE_VIEWER void on_combochecklist_options(wxCommandEvent& evt); -#else - void on_checkbox_travel(wxCommandEvent& evt); - void on_checkbox_retractions(wxCommandEvent& evt); - void on_checkbox_unretractions(wxCommandEvent& evt); - void on_checkbox_shells(wxCommandEvent& evt); - void on_checkbox_legend(wxCommandEvent& evt); -#endif // ENABLE_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER // Create/Update/Reset double slider on 3dPreview wxBoxSizer* create_layers_slider_sizer(); void check_layers_slider_values(std::vector& ticks_from_model, @@ -235,28 +176,13 @@ private: void update_layers_slider_mode(); // update vertical DoubleSlider after keyDown in canvas void update_layers_slider_from_canvas(wxKeyEvent& event); -#else - // Create/Update/Reset double slider on 3dPreview - void create_double_slider(); - void check_slider_values(std::vector& ticks_from_model, - const std::vector& layers_z); - void reset_double_slider(); - void update_double_slider(const std::vector& layers_z, bool keep_z_range = false); - void update_double_slider_mode(); - // update DoubleSlider after keyDown in canvas - void update_double_slider_from_canvas(wxKeyEvent& event); -#endif // ENABLE_GCODE_VIEWER void load_print_as_fff(bool keep_z_range = false); void load_print_as_sla(); -#if ENABLE_GCODE_VIEWER void on_layers_slider_scroll_changed(wxCommandEvent& event); void on_moves_slider_scroll_changed(wxCommandEvent& event); wxString get_option_type_string(OptionType type) const; -#else - void on_sliders_scroll_changed(wxCommandEvent& event); -#endif // ENABLE_GCODE_VIEWER }; } // namespace GUI