diff --git a/src/imgui/imconfig.h b/src/imgui/imconfig.h index 47836b1c45..8045936c4c 100644 --- a/src/imgui/imconfig.h +++ b/src/imgui/imconfig.h @@ -153,10 +153,8 @@ namespace ImGui const wchar_t PlugMarker = 0x1C; const wchar_t DowelMarker = 0x1D; const wchar_t SnapMarker = 0x1E; -#if ENABLE_NEW_GCODE_VIEWER const wchar_t HorizontalHide = 0xB1; const wchar_t HorizontalShow = 0xB2; -#endif // ENABLE_NEW_GCODE_VIEWER // Do not forget use following letters only in wstring const wchar_t DocumentationButton = 0x2600; const wchar_t DocumentationHoverButton = 0x2601; diff --git a/src/libslic3r/BuildVolume.cpp b/src/libslic3r/BuildVolume.cpp index f585caeec9..e877439fe2 100644 --- a/src/libslic3r/BuildVolume.cpp +++ b/src/libslic3r/BuildVolume.cpp @@ -374,42 +374,6 @@ inline bool all_inside_vertices_normals_interleaved(const std::vector &pa return true; } -#if !ENABLE_NEW_GCODE_VIEWER -bool BuildVolume::all_paths_inside_vertices_and_normals_interleaved(const std::vector& paths, const Eigen::AlignedBox& paths_bbox, bool ignore_bottom) const -{ - assert(paths.size() % 6 == 0); - static constexpr const double epsilon = BedEpsilon; - switch (m_type) { - case Type::Rectangle: - { - BoundingBox3Base build_volume = this->bounding_volume().inflated(epsilon); - if (m_max_print_height == 0.0) - build_volume.max.z() = std::numeric_limits::max(); - if (ignore_bottom) - build_volume.min.z() = -std::numeric_limits::max(); - return build_volume.contains(paths_bbox.min().cast()) && build_volume.contains(paths_bbox.max().cast()); - } - case Type::Circle: - { - const Vec2f c = unscaled(m_circle.center); - const float r = unscaled(m_circle.radius) + float(epsilon); - const float r2 = sqr(r); - return m_max_print_height == 0.0 ? - all_inside_vertices_normals_interleaved(paths, [c, r2](Vec3f p) { return (to_2d(p) - c).squaredNorm() <= r2; }) : - all_inside_vertices_normals_interleaved(paths, [c, r2, z = m_max_print_height + epsilon](Vec3f p) { return (to_2d(p) - c).squaredNorm() <= r2 && p.z() <= z; }); - } - case Type::Convex: - //FIXME doing test on convex hull until we learn to do test on non-convex polygons efficiently. - case Type::Custom: - return m_max_print_height == 0.0 ? - all_inside_vertices_normals_interleaved(paths, [this](Vec3f p) { return Geometry::inside_convex_polygon(m_top_bottom_convex_hull_decomposition_bed, to_2d(p).cast()); }) : - all_inside_vertices_normals_interleaved(paths, [this, z = m_max_print_height + epsilon](Vec3f p) { return Geometry::inside_convex_polygon(m_top_bottom_convex_hull_decomposition_bed, to_2d(p).cast()) && p.z() <= z; }); - default: - return true; - } -} -#endif // !ENABLE_NEW_GCODE_VIEWER - std::string_view BuildVolume::type_name(Type type) { using namespace std::literals; diff --git a/src/libslic3r/BuildVolume.hpp b/src/libslic3r/BuildVolume.hpp index 382a22c921..e559fcd6a5 100644 --- a/src/libslic3r/BuildVolume.hpp +++ b/src/libslic3r/BuildVolume.hpp @@ -95,11 +95,6 @@ public: // Called on final G-code paths. //FIXME The test does not take the thickness of the extrudates into account! bool all_paths_inside(const GCodeProcessorResult& paths, const BoundingBoxf3& paths_bbox, bool ignore_bottom = true) const; -#if !ENABLE_NEW_GCODE_VIEWER - // Called on initial G-code preview on OpenGL vertex buffer interleaved normals and vertices. - bool all_paths_inside_vertices_and_normals_interleaved(const std::vector& paths, const Eigen::AlignedBox& bbox, bool ignore_bottom = true) const; -#endif // !ENABLE_NEW_GCODE_VIEWER - const std::pair, std::vector>& top_bottom_convex_hull_decomposition_scene() const { return m_top_bottom_convex_hull_decomposition_scene; } const std::pair, std::vector>& top_bottom_convex_hull_decomposition_bed() const { return m_top_bottom_convex_hull_decomposition_bed; } diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 11292e9148..3b256034a7 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -145,42 +145,16 @@ void GCodeProcessor::CpColor::reset() float GCodeProcessor::Trapezoid::acceleration_time(float entry_feedrate, float acceleration) const { -#if ENABLE_NEW_GCODE_VIEWER return acceleration_time_from_distance(entry_feedrate, acceleration_distance(), acceleration); -#else - return acceleration_time_from_distance(entry_feedrate, accelerate_until, acceleration); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -float GCodeProcessor::Trapezoid::cruise_time() const -{ - return (cruise_feedrate != 0.0f) ? cruise_distance() / cruise_feedrate : 0.0f; -} -#endif // !ENABLE_NEW_GCODE_VIEWER - float GCodeProcessor::Trapezoid::deceleration_time(float distance, float acceleration) const { -#if ENABLE_NEW_GCODE_VIEWER return acceleration_time_from_distance(cruise_feedrate, deceleration_distance(distance), -acceleration); -#else - return acceleration_time_from_distance(cruise_feedrate, distance - decelerate_after, -acceleration); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -float GCodeProcessor::Trapezoid::cruise_distance() const -{ - return decelerate_after - accelerate_until; -} -#endif // !ENABLE_NEW_GCODE_VIEWER - void GCodeProcessor::TimeBlock::calculate_trapezoid() { -#if !ENABLE_NEW_GCODE_VIEWER - trapezoid.cruise_feedrate = feedrate_profile.cruise; -#endif // !ENABLE_NEW_GCODE_VIEWER - float accelerate_distance = std::max(0.0f, estimated_acceleration_distance(feedrate_profile.entry, feedrate_profile.cruise, acceleration)); const float decelerate_distance = std::max(0.0f, estimated_acceleration_distance(feedrate_profile.cruise, feedrate_profile.exit, -acceleration)); float cruise_distance = distance - accelerate_distance - decelerate_distance; @@ -193,24 +167,13 @@ void GCodeProcessor::TimeBlock::calculate_trapezoid() cruise_distance = 0.0f; trapezoid.cruise_feedrate = speed_from_distance(feedrate_profile.entry, accelerate_distance, acceleration); } -#if ENABLE_NEW_GCODE_VIEWER else trapezoid.cruise_feedrate = feedrate_profile.cruise; -#endif // ENABLE_NEW_GCODE_VIEWER trapezoid.accelerate_until = accelerate_distance; trapezoid.decelerate_after = accelerate_distance + cruise_distance; } -#if !ENABLE_NEW_GCODE_VIEWER -float GCodeProcessor::TimeBlock::time() const -{ - return trapezoid.acceleration_time(feedrate_profile.entry, acceleration) + - trapezoid.cruise_time() + - trapezoid.deceleration_time(distance, acceleration); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - void GCodeProcessor::TimeMachine::State::reset() { feedrate = 0.0f; @@ -237,37 +200,17 @@ void GCodeProcessor::TimeMachine::reset() max_travel_acceleration = 0.0f; extrude_factor_override_percentage = 1.0f; time = 0.0f; -#if !ENABLE_NEW_GCODE_VIEWER - travel_time = 0.0f; -#endif // !ENABLE_NEW_GCODE_VIEWER stop_times = std::vector(); curr.reset(); prev.reset(); gcode_time.reset(); blocks = std::vector(); g1_times_cache = std::vector(); -#if ENABLE_NEW_GCODE_VIEWER first_layer_time = 0.0f; -#else - std::fill(moves_time.begin(), moves_time.end(), 0.0f); - std::fill(roles_time.begin(), roles_time.end(), 0.0f); - layers_time = std::vector(); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -void GCodeProcessor::TimeMachine::simulate_st_synchronize(float additional_time) -{ - if (!enabled) - return; - - calculate_time(0, additional_time); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - static void planner_forward_pass_kernel(const GCodeProcessor::TimeBlock& prev, GCodeProcessor::TimeBlock& curr) { -#if ENABLE_NEW_GCODE_VIEWER // // C:\prusa\firmware\Prusa-Firmware-Buddy\lib\Marlin\Marlin\src\module\planner.cpp // Line 954 @@ -286,28 +229,10 @@ static void planner_forward_pass_kernel(const GCodeProcessor::TimeBlock& prev, G curr.flags.recalculate = true; } } -#else - // If the previous block is an acceleration block, but it is not long enough to complete the - // full speed change within the block, we need to adjust the entry speed accordingly. Entry - // speeds have already been reset, maximized, and reverse planned by reverse planner. - // If nominal length is true, max junction speed is guaranteed to be reached. No need to recheck. - if (!prev.flags.nominal_length) { - if (prev.feedrate_profile.entry < curr.feedrate_profile.entry) { - const float entry_speed = std::min(curr.feedrate_profile.entry, max_allowable_speed(-prev.acceleration, prev.feedrate_profile.entry, prev.distance)); - - // Check for junction speed change - if (curr.feedrate_profile.entry != entry_speed) { - curr.feedrate_profile.entry = entry_speed; - curr.flags.recalculate = true; - } - } - } -#endif // ENABLE_NEW_GCODE_VIEWER } static void planner_reverse_pass_kernel(GCodeProcessor::TimeBlock& curr, const GCodeProcessor::TimeBlock& next) { -#if ENABLE_NEW_GCODE_VIEWER // // C:\prusa\firmware\Prusa-Firmware-Buddy\lib\Marlin\Marlin\src\module\planner.cpp // Line 857 @@ -335,21 +260,6 @@ static void planner_reverse_pass_kernel(GCodeProcessor::TimeBlock& curr, const G curr.flags.recalculate = true; } } -#else - // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising. - // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and - // check for maximum allowable speed reductions to ensure maximum possible planned speed. - if (curr.feedrate_profile.entry != curr.max_entry_speed) { - // If nominal length true, max junction speed is guaranteed to be reached. Only compute - // for max allowable speed if block is decelerating and nominal length is false. - if (!curr.flags.nominal_length && curr.max_entry_speed > next.feedrate_profile.entry) - curr.feedrate_profile.entry = std::min(curr.max_entry_speed, max_allowable_speed(-curr.acceleration, next.feedrate_profile.entry, curr.distance)); - else - curr.feedrate_profile.entry = curr.max_entry_speed; - - curr.flags.recalculate = true; - } -#endif // ENABLE_NEW_GCODE_VIEWER } static void recalculate_trapezoids(std::vector& blocks) @@ -367,15 +277,8 @@ static void recalculate_trapezoids(std::vector& block // Recalculate if current block entry or exit junction speed has changed. if (curr->flags.recalculate || next->flags.recalculate) { // NOTE: Entry and exit factors always > 0 by all previous logic operations. -#if ENABLE_NEW_GCODE_VIEWER curr->feedrate_profile.exit = next->feedrate_profile.entry; curr->calculate_trapezoid(); -#else - GCodeProcessor::TimeBlock block = *curr; - block.feedrate_profile.exit = next->feedrate_profile.entry; - block.calculate_trapezoid(); - curr->trapezoid = block.trapezoid; -#endif // ENABLE_NEW_GCODE_VIEWER curr->flags.recalculate = false; // Reset current only to ensure next trapezoid is computed } } @@ -383,24 +286,13 @@ static void recalculate_trapezoids(std::vector& block // Last/newest block in buffer. Always recalculated. if (next != nullptr) { -#if ENABLE_NEW_GCODE_VIEWER next->feedrate_profile.exit = next->safe_feedrate; next->calculate_trapezoid(); -#else - GCodeProcessor::TimeBlock block = *next; - block.feedrate_profile.exit = next->safe_feedrate; - block.calculate_trapezoid(); - next->trapezoid = block.trapezoid; -#endif // ENABLE_NEW_GCODE_VIEWER next->flags.recalculate = false; } } -#if ENABLE_NEW_GCODE_VIEWER void GCodeProcessor::TimeMachine::calculate_time(GCodeProcessorResult& result, PrintEstimatedStatistics::ETimeMode mode, size_t keep_last_n_blocks, float additional_time) -#else -void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, float additional_time) -#endif // ENABLE_NEW_GCODE_VIEWER { if (!enabled || blocks.size() < 2) return; @@ -427,7 +319,6 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, floa block_time += additional_time; time += block_time; -#if ENABLE_NEW_GCODE_VIEWER result.moves[block.move_id].time[static_cast(mode)] = block_time; gcode_time.cache += block_time; if (block.layer_id == 1) @@ -520,22 +411,6 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, floa std::nullopt }); } -#else - if (block.move_type == EMoveType::Travel) - travel_time += block_time; - else - roles_time[static_cast(block.role)] += block_time; - gcode_time.cache += block_time; - moves_time[static_cast(block.move_type)] += block_time; - if (block.layer_id >= layers_time.size()) { - const size_t curr_size = layers_time.size(); - layers_time.resize(block.layer_id); - for (size_t i = curr_size; i < layers_time.size(); ++i) { - layers_time[i] = 0.0f; - } - } - layers_time[block.layer_id - 1] += block_time; -#endif // ENABLE_NEW_GCODE_VIEWER g1_times_cache.push_back({ block.g1_line_id, block.remaining_internal_g1_lines, time }); // update times for remaining time to printer stop placeholders auto it_stop_time = std::lower_bound(stop_times.begin(), stop_times.end(), block.g1_line_id, @@ -644,7 +519,6 @@ void GCodeProcessor::UsedFilaments::process_caches(const GCodeProcessor* process process_role_cache(processor); } -#if ENABLE_NEW_GCODE_VIEWER void GCodeProcessorResult::reset() { is_binary_file = false; moves.clear(); @@ -663,46 +537,6 @@ void GCodeProcessorResult::reset() { spiral_vase_mode = false; conflict_result = std::nullopt; } -#else -#if ENABLE_GCODE_VIEWER_STATISTICS -void GCodeProcessorResult::reset() { - moves = std::vector(); - bed_shape = Pointfs(); - max_print_height = 0.0f; - z_offset = 0.0f; - settings_ids.reset(); - extruders_count = 0; - backtrace_enabled = false; - extruder_colors = std::vector(); - filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); - filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); - filament_cost = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST); - custom_gcode_per_print_z = std::vector(); - spiral_vase_layers = std::vector>>(); - conflict_result = std::nullopt; - time = 0; -} -#else -void GCodeProcessorResult::reset() { - is_binary_file = false; - moves.clear(); - lines_ends.clear(); - bed_shape = Pointfs(); - max_print_height = 0.0f; - z_offset = 0.0f; - settings_ids.reset(); - extruders_count = 0; - backtrace_enabled = false; - extruder_colors = std::vector(); - filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); - filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); - filament_cost = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST); - custom_gcode_per_print_z = std::vector(); - spiral_vase_layers = std::vector>>(); - conflict_result = std::nullopt; -} -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // ENABLE_NEW_GCODE_VIEWER const std::vector> GCodeProcessor::Producers = { { EProducer::PrusaSlicer, "generated by PrusaSlicer" }, @@ -883,11 +717,7 @@ for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode:: const ConfigOptionBool* spiral_vase = config.option("spiral_vase"); if (spiral_vase != nullptr) -#if ENABLE_NEW_GCODE_VIEWER m_result.spiral_vase_mode = spiral_vase->value; -#else - m_spiral_vase_active = spiral_vase->value; -#endif // ENABLE_NEW_GCODE_VIEWER const ConfigOptionFloat* z_offset = config.option("z_offset"); if (z_offset != nullptr) @@ -1169,11 +999,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) const ConfigOptionBool* spiral_vase = config.option("spiral_vase"); if (spiral_vase != nullptr) -#if ENABLE_NEW_GCODE_VIEWER m_result.spiral_vase_mode = spiral_vase->value; -#else - m_spiral_vase_active = spiral_vase->value; -#endif // ENABLE_NEW_GCODE_VIEWER const ConfigOptionFloat* z_offset = config.option("z_offset"); if (z_offset != nullptr) @@ -1244,9 +1070,6 @@ void GCodeProcessor::reset() m_options_z_corrector.reset(); -#if !ENABLE_NEW_GCODE_VIEWER - m_spiral_vase_active = false; -#endif // !ENABLE_NEW_GCODE_VIEWER m_kissslicer_toolchange_time_correction = 0.0f; m_single_extruder_multi_material = false; @@ -1291,12 +1114,6 @@ void GCodeProcessor::process_ascii_file(const std::string& filename, std::functi { CNumericLocalesSetter locales_setter; -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - m_start_time = std::chrono::high_resolution_clock::now(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER - // pre-processing // parse the gcode file to detect its producer { @@ -1370,12 +1187,6 @@ static void update_lines_ends_and_out_file_pos(const std::string& out_string, st void GCodeProcessor::process_binary_file(const std::string& filename, std::function cancel_callback) { -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - m_start_time = std::chrono::high_resolution_clock::now(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER - FilePtr file{ boost::nowide::fopen(filename.c_str(), "rb") }; if (file.f == nullptr) throw Slic3r::RuntimeError(format("Error opening file %1%", filename)); @@ -1514,12 +1325,6 @@ void GCodeProcessor::initialize(const std::string& filename) { assert(is_decimal_separator_point()); -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - m_start_time = std::chrono::high_resolution_clock::now(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER - // process gcode m_result.filename = filename; m_result.id = ++s_result_id; @@ -1545,17 +1350,12 @@ void GCodeProcessor::finalize(bool perform_post_process) } } -#if ENABLE_NEW_GCODE_VIEWER calculate_time(m_result); -#endif // ENABLE_NEW_GCODE_VIEWER // process the time blocks for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { TimeMachine& machine = m_time_processor.machines[i]; TimeMachine::CustomGCodeTime& gcode_time = machine.gcode_time; -#if !ENABLE_NEW_GCODE_VIEWER - machine.calculate_time(); -#endif // !ENABLE_NEW_GCODE_VIEWER if (gcode_time.needed && gcode_time.cache != 0.0f) gcode_time.times.push_back({ CustomGCode::ColorChange, gcode_time.cache }); } @@ -1573,11 +1373,6 @@ void GCodeProcessor::finalize(bool perform_post_process) if (perform_post_process) post_process(); -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - m_result.time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_start_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER } float GCodeProcessor::get_time(PrintEstimatedStatistics::ETimeMode mode) const @@ -1590,18 +1385,6 @@ std::string GCodeProcessor::get_time_dhm(PrintEstimatedStatistics::ETimeMode mod return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? short_time(get_time_dhms(m_time_processor.machines[static_cast(mode)].time)) : std::string("N/A"); } -#if !ENABLE_NEW_GCODE_VIEWER -float GCodeProcessor::get_travel_time(PrintEstimatedStatistics::ETimeMode mode) const -{ - return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? m_time_processor.machines[static_cast(mode)].travel_time : 0.0f; -} - -std::string GCodeProcessor::get_travel_time_dhm(PrintEstimatedStatistics::ETimeMode mode) const -{ - return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? short_time(get_time_dhms(m_time_processor.machines[static_cast(mode)].travel_time)) : std::string("N/A"); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - std::vector>> GCodeProcessor::get_custom_gcode_times(PrintEstimatedStatistics::ETimeMode mode, bool include_remaining) const { std::vector>> ret; @@ -1617,34 +1400,6 @@ std::vector>> GCodeProcesso return ret; } -#if !ENABLE_NEW_GCODE_VIEWER -std::vector> GCodeProcessor::get_moves_time(PrintEstimatedStatistics::ETimeMode mode) const -{ - std::vector> ret; - if (mode < PrintEstimatedStatistics::ETimeMode::Count) { - for (size_t i = 0; i < m_time_processor.machines[static_cast(mode)].moves_time.size(); ++i) { - float time = m_time_processor.machines[static_cast(mode)].moves_time[i]; - if (time > 0.0f) - ret.push_back({ static_cast(i), time }); - } - } - return ret; -} - -std::vector> GCodeProcessor::get_roles_time(PrintEstimatedStatistics::ETimeMode mode) const -{ - std::vector> ret; - if (mode < PrintEstimatedStatistics::ETimeMode::Count) { - for (size_t i = 0; i < m_time_processor.machines[static_cast(mode)].roles_time.size(); ++i) { - float time = m_time_processor.machines[static_cast(mode)].roles_time[i]; - if (time > 0.0f) - ret.push_back({ static_cast(i), time }); - } - } - return ret; -} -#endif // !ENABLE_NEW_GCODE_VIEWER - ConfigSubstitutions load_from_superslicer_gcode_file(const std::string& filename, DynamicPrintConfig& config, ForwardCompatibilitySubstitutionRule compatibility_rule) { // for reference, see: ConfigBase::load_from_gcode_file() @@ -1754,19 +1509,10 @@ void GCodeProcessor::apply_config_kissslicer(const std::string& filename) m_parser.reset(); } -#if ENABLE_NEW_GCODE_VIEWER float GCodeProcessor::get_first_layer_time(PrintEstimatedStatistics::ETimeMode mode) const { return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? m_time_processor.machines[static_cast(mode)].first_layer_time : 0.0f; } -#else -std::vector GCodeProcessor::get_layers_time(PrintEstimatedStatistics::ETimeMode mode) const -{ - return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? - m_time_processor.machines[static_cast(mode)].layers_time : - std::vector(); -} -#endif // ENABLE_NEW_GCODE_VIEWER void GCodeProcessor::apply_config_simplify3d(const std::string& filename) { @@ -2240,20 +1986,6 @@ void GCodeProcessor::process_tags(const std::string_view comment, bool producers // layer change tag if (comment == reserved_tag(ETags::Layer_Change)) { ++m_layer_id; -#if !ENABLE_NEW_GCODE_VIEWER - if (m_spiral_vase_active) { - if (m_result.moves.empty() || m_result.spiral_vase_layers.empty()) - // add a placeholder for layer height. the actual value will be set inside process_G1() method - m_result.spiral_vase_layers.push_back({ FLT_MAX, { 0, 0 } }); - else { - const size_t move_id = m_result.moves.size() - 1; - if (!m_result.spiral_vase_layers.empty()) - m_result.spiral_vase_layers.back().second.second = move_id; - // add a placeholder for layer height. the actual value will be set inside process_G1() method - m_result.spiral_vase_layers.push_back({ FLT_MAX, { move_id, move_id } }); - } - } -#endif // !ENABLE_NEW_GCODE_VIEWER return; } @@ -2973,9 +2705,7 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes block.role = m_extrusion_role; block.distance = distance; block.g1_line_id = m_g1_line_id; -#if ENABLE_NEW_GCODE_VIEWER block.move_id = static_cast(m_result.moves.size()); -#endif // ENABLE_NEW_GCODE_VIEWER block.remaining_internal_g1_lines = remaining_internal_g1_lines.has_value() ? *remaining_internal_g1_lines : 0; block.layer_id = std::max(1, m_layer_id); @@ -3102,17 +2832,10 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes prev = curr; blocks.push_back(block); - -#if !ENABLE_NEW_GCODE_VIEWER - if (blocks.size() > TimeProcessor::Planner::refresh_threshold) - machine.calculate_time(TimeProcessor::Planner::queue_size); -#endif // !ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER if (m_time_processor.machines[0].blocks.size() > TimeProcessor::Planner::refresh_threshold) calculate_time(m_result, TimeProcessor::Planner::queue_size); -#endif // ENABLE_NEW_GCODE_VIEWER if (m_seams_detector.is_active()) { // check for seam starting vertex @@ -3143,16 +2866,6 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]); } -#if !ENABLE_NEW_GCODE_VIEWER - if (m_spiral_vase_active && !m_result.spiral_vase_layers.empty()) { - if (m_result.spiral_vase_layers.back().first == FLT_MAX && delta_pos[Z] >= 0.0) - // replace layer height placeholder with correct value - m_result.spiral_vase_layers.back().first = static_cast(m_end_position[Z]); - if (!m_result.moves.empty()) - m_result.spiral_vase_layers.back().second.second = m_result.moves.size() - 1; - } -#endif // !ENABLE_NEW_GCODE_VIEWER - // store move store_move_vertex(type, origin == G1DiscretizationOrigin::G2G3); } @@ -3248,11 +2961,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc arc.end = Vec3d(end_position[X], end_position[Y], end_position[Z]); // radii -#if ENABLE_NEW_GCODE_VIEWER if (std::abs(arc.end_radius() - arc.start_radius()) > 0.001) { -#else - if (std::abs(arc.end_radius() - arc.start_radius()) > EPSILON) { -#endif // ENABLE_NEW_GCODE_VIEWER // what to do ??? } @@ -3321,7 +3030,6 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc process_G1(g1_axes, g1_feedrate, G1DiscretizationOrigin::G2G3, remaining_internal_g1_lines); }; -#if ENABLE_NEW_GCODE_VIEWER if (m_flavor == gcfMarlinFirmware) { // calculate arc segments // reference: @@ -3391,7 +3099,6 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc internal_only_g1_line(adjust_target(end_position, prev_target), arc.delta_z() != 0.0, (segments == 1) ? feedrate : std::nullopt, extrusion); } else { -#endif // ENABLE_NEW_GCODE_VIEWER // calculate arc segments // reference: // Prusa-Firmware\Firmware\motion_control.cpp - mc_arc() @@ -3410,15 +3117,9 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc const double theta_per_segment = arc.angle * inv_segment; const double z_per_segment = arc.delta_z() * inv_segment; const double extruder_per_segment = (extrusion.has_value()) ? *extrusion * inv_segment : 0.0; - -#if ENABLE_NEW_GCODE_VIEWER const double sq_theta_per_segment = sqr(theta_per_segment); const double cos_T = 1.0 - 0.5 * sq_theta_per_segment; const double sin_T = theta_per_segment - sq_theta_per_segment * theta_per_segment / 6.0f; -#else - const double cos_T = 1.0 - 0.5 * sqr(theta_per_segment); // Small angle approximation - const double sin_T = theta_per_segment; -#endif // ENABLE_NEW_GCODE_VIEWER AxisCoords prev_target = m_start_position; AxisCoords arc_target; @@ -3431,14 +3132,9 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc static const size_t N_ARC_CORRECTION = 25; Vec3d curr_rel_arc_start = arc.relative_start(); -#if ENABLE_NEW_GCODE_VIEWER size_t count = N_ARC_CORRECTION; -#else - size_t count = 0; -#endif // ENABLE_NEW_GCODE_VIEWER for (size_t i = 1; i < segments; ++i) { -#if ENABLE_NEW_GCODE_VIEWER if (count-- == 0) { const double cos_Ti = ::cos(i * theta_per_segment); const double sin_Ti = ::sin(i * theta_per_segment); @@ -3451,24 +3147,6 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc curr_rel_arc_start.x() = curr_rel_arc_start.x() * cos_T - curr_rel_arc_start.y() * sin_T; curr_rel_arc_start.y() = r_axisi; } -#else - if (count < N_ARC_CORRECTION) { - // Apply vector rotation matrix - const float r_axisi = curr_rel_arc_start.x() * sin_T + curr_rel_arc_start.y() * cos_T; - curr_rel_arc_start.x() = curr_rel_arc_start.x() * cos_T - curr_rel_arc_start.y() * sin_T; - curr_rel_arc_start.y() = r_axisi; - ++count; - } - else { - // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments. - // Compute exact location by applying transformation matrix from initial radius vector(=-offset). - const double cos_Ti = ::cos(i * theta_per_segment); - const double sin_Ti = ::sin(i * theta_per_segment); - curr_rel_arc_start.x() = -double(rel_center.x()) * cos_Ti + double(rel_center.y()) * sin_Ti; - curr_rel_arc_start.y() = -double(rel_center.x()) * sin_Ti - double(rel_center.y()) * cos_Ti; - count = 0; - } -#endif // ENABLE_NEW_GCODE_VIEWER // Update arc_target location arc_target[X] = arc.center.x() + curr_rel_arc_start.x(); @@ -3485,9 +3163,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc // Ensure last segment arrives at target location. m_start_position = m_end_position; // this is required because we are skipping the call to process_gcode_line() internal_only_g1_line(adjust_target(end_position, prev_target), arc.delta_z() != 0.0, (segments == 1) ? feedrate : std::nullopt, extrusion); -#if ENABLE_NEW_GCODE_VIEWER } -#endif // ENABLE_NEW_GCODE_VIEWER } void GCodeProcessor::process_G10(const GCodeReader::GCodeLine& line) @@ -4097,11 +3773,7 @@ void GCodeProcessor::post_process() char buf[128]; sprintf(buf, "(%s mode)", (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent"); binary_data.print_metadata.raw_data.emplace_back("estimated printing time " + std::string(buf), get_time_dhms(machine.time)); -#if ENABLE_NEW_GCODE_VIEWER binary_data.print_metadata.raw_data.emplace_back("estimated first layer printing time " + std::string(buf), get_time_dhms(machine.first_layer_time)); -#else - binary_data.print_metadata.raw_data.emplace_back("estimated first layer printing time " + std::string(buf), get_time_dhms(machine.layers_time.empty() ? 0.f : machine.layers_time.front())); -#endif // ENABLE_NEW_GCODE_VIEWER binary_data.printer_metadata.raw_data.emplace_back("estimated printing time " + std::string(buf), get_time_dhms(machine.time)); } } @@ -4258,13 +3930,8 @@ void GCodeProcessor::post_process() ++m_times_cache_id; } -#if ENABLE_NEW_GCODE_VIEWER if (it == m_machine.g1_times_cache.end() || it->id > g1_lines_counter) return ret; -#else - if (it->id > g1_lines_counter) - return ret; -#endif // ENABLE_NEW_GCODE_VIEWER // search for internal G1 lines if (GCodeReader::GCodeLine::cmd_is(line, "G2") || GCodeReader::GCodeLine::cmd_is(line, "G3")) { @@ -4486,15 +4153,9 @@ void GCodeProcessor::post_process() PrintEstimatedStatistics::ETimeMode mode = static_cast(i); if (mode == PrintEstimatedStatistics::ETimeMode::Normal || machine.enabled) { char buf[128]; -#if ENABLE_NEW_GCODE_VIEWER sprintf(buf, "; estimated first layer printing time (%s mode) = %s\n", (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", get_time_dhms(machine.first_layer_time).c_str()); -#else - sprintf(buf, "; estimated first layer printing time (%s mode) = %s\n", - (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", - get_time_dhms(machine.layers_time.empty() ? 0.f : machine.layers_time.front()).c_str()); -#endif // ENABLE_NEW_GCODE_VIEWER export_lines.append_line(buf); processed = true; } @@ -4793,20 +4454,14 @@ void GCodeProcessor::store_move_vertex(EMoveType type, bool internal_only) Vec3f(m_end_position[X], m_end_position[Y], m_end_position[Z] - m_z_offset) + m_extruder_offsets[m_extruder_id], static_cast(m_end_position[E] - m_start_position[E]), m_feedrate, -#if ENABLE_NEW_GCODE_VIEWER 0.0f, // actual feedrate -#endif // ENABLE_NEW_GCODE_VIEWER m_width, m_height, m_mm3_per_mm, m_fan_speed, m_extruder_temps[m_extruder_id], -#if ENABLE_NEW_GCODE_VIEWER - { 0.0f, 0.0f }, + { 0.0f, 0.0f }, // time std::max(1, m_layer_id) - 1, -#else - static_cast(m_result.moves.size()), -#endif // ENABLE_NEW_GCODE_VIEWER internal_only }); @@ -4950,11 +4605,9 @@ float GCodeProcessor::get_filament_unload_time(size_t extruder_id) void GCodeProcessor::process_custom_gcode_time(CustomGCode::Type code) { -#if ENABLE_NEW_GCODE_VIEWER //FIXME this simulates st_synchronize! is it correct? // The estimated time may be longer than the real print time. simulate_st_synchronize(); -#endif // ENABLE_NEW_GCODE_VIEWER for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { TimeMachine& machine = m_time_processor.machines[i]; if (!machine.enabled) @@ -4962,11 +4615,6 @@ void GCodeProcessor::process_custom_gcode_time(CustomGCode::Type code) TimeMachine::CustomGCodeTime& gcode_time = machine.gcode_time; gcode_time.needed = true; -#if !ENABLE_NEW_GCODE_VIEWER - //FIXME this simulates st_synchronize! is it correct? - // The estimated time may be longer than the real print time. - machine.simulate_st_synchronize(); -#endif // !ENABLE_NEW_GCODE_VIEWER if (gcode_time.cache != 0.0f) { gcode_time.times.push_back({ code, gcode_time.cache }); gcode_time.cache = 0.0f; @@ -4983,7 +4631,6 @@ void GCodeProcessor::process_filaments(CustomGCode::Type code) m_used_filaments.process_extruder_cache(m_extruder_id); } -#if ENABLE_NEW_GCODE_VIEWER void GCodeProcessor::calculate_time(GCodeProcessorResult& result, size_t keep_last_n_blocks, float additional_time) { // calculate times @@ -5048,14 +4695,6 @@ void GCodeProcessor::simulate_st_synchronize(float additional_time) { calculate_time(m_result, 0, additional_time); } -#else -void GCodeProcessor::simulate_st_synchronize(float additional_time) -{ - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - m_time_processor.machines[i].simulate_st_synchronize(additional_time); - } -} -#endif // ENABLE_NEW_GCODE_VIEWER void GCodeProcessor::update_estimated_statistics() { @@ -5063,12 +4702,6 @@ void GCodeProcessor::update_estimated_statistics() PrintEstimatedStatistics::Mode& data = m_result.print_statistics.modes[static_cast(mode)]; data.time = get_time(mode); data.custom_gcode_times = get_custom_gcode_times(mode, true); -#if !ENABLE_NEW_GCODE_VIEWER - data.travel_time = get_travel_time(mode); - data.moves_times = get_moves_time(mode); - data.roles_times = get_roles_time(mode); - data.layers_times = get_layers_time(mode); -#endif // !ENABLE_NEW_GCODE_VIEWER }; update_mode(PrintEstimatedStatistics::ETimeMode::Normal); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 012cf78f6b..e8327b10c5 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -55,26 +55,11 @@ namespace Slic3r { { float time; std::vector>> custom_gcode_times; -#if !ENABLE_NEW_GCODE_VIEWER - float travel_time; - std::vector> moves_times; - std::vector> roles_times; - std::vector layers_times; -#endif // !ENABLE_NEW_GCODE_VIEWER void reset() { time = 0.0f; custom_gcode_times.clear(); custom_gcode_times.shrink_to_fit(); -#if !ENABLE_NEW_GCODE_VIEWER - travel_time = 0.0f; - moves_times.clear(); - moves_times.shrink_to_fit(); - roles_times.clear(); - roles_times.shrink_to_fit(); - layers_times.clear(); - layers_times.shrink_to_fit(); -#endif // !ENABLE_NEW_GCODE_VIEWER } }; @@ -140,26 +125,18 @@ namespace Slic3r { Vec3f position{ Vec3f::Zero() }; // mm float delta_extruder{ 0.0f }; // mm float feedrate{ 0.0f }; // mm/s -#if ENABLE_NEW_GCODE_VIEWER float actual_feedrate{ 0.0f }; // mm/s -#endif // ENABLE_NEW_GCODE_VIEWER float width{ 0.0f }; // mm float height{ 0.0f }; // mm float mm3_per_mm{ 0.0f }; float fan_speed{ 0.0f }; // percentage float temperature{ 0.0f }; // Celsius degrees -#if ENABLE_NEW_GCODE_VIEWER std::array(PrintEstimatedStatistics::ETimeMode::Count)> time{ 0.0f, 0.0f }; // s unsigned int layer_id{ 0 }; -#else - float time{ 0.0f }; // s -#endif // ENABLE_NEW_GCODE_VIEWER bool internal_only{ false }; float volumetric_rate() const { return feedrate * mm3_per_mm; } -#if ENABLE_NEW_GCODE_VIEWER float actual_volumetric_rate() const { return actual_feedrate * mm3_per_mm; } -#endif // ENABLE_NEW_GCODE_VIEWER }; std::string filename; @@ -183,19 +160,10 @@ namespace Slic3r { PrintEstimatedStatistics print_statistics; std::vector custom_gcode_per_print_z; -#if ENABLE_NEW_GCODE_VIEWER bool spiral_vase_mode; -#else - std::vector>> spiral_vase_layers; -#endif // ENABLE_NEW_GCODE_VIEWER ConflictResultOpt conflict_result; -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - int64_t time{ 0 }; -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER void reset(); }; @@ -286,18 +254,12 @@ namespace Slic3r { float cruise_feedrate{ 0.0f }; // mm/sec float acceleration_time(float entry_feedrate, float acceleration) const; -#if ENABLE_NEW_GCODE_VIEWER float cruise_time() const { return (cruise_feedrate != 0.0f) ? cruise_distance() / cruise_feedrate : 0.0f; } float deceleration_time(float distance, float acceleration) const; float acceleration_distance() const { return accelerate_until; } float cruise_distance() const { return decelerate_after - accelerate_until; } float deceleration_distance(float distance) const { return distance - decelerate_after; } bool is_cruise_only(float distance) const { return std::abs(cruise_distance() - distance) < EPSILON; } -#else - float cruise_time() const; - float deceleration_time(float distance, float acceleration) const; - float cruise_distance() const; -#endif // ENABLE_NEW_GCODE_VIEWER }; struct TimeBlock @@ -310,9 +272,7 @@ namespace Slic3r { EMoveType move_type{ EMoveType::Noop }; GCodeExtrusionRole role{ GCodeExtrusionRole::None }; -#if ENABLE_NEW_GCODE_VIEWER unsigned int move_id{ 0 }; -#endif // ENABLE_NEW_GCODE_VIEWER unsigned int g1_line_id{ 0 }; unsigned int remaining_internal_g1_lines; unsigned int layer_id{ 0 }; @@ -327,14 +287,10 @@ namespace Slic3r { // Calculates this block's trapezoid void calculate_trapezoid(); -#if ENABLE_NEW_GCODE_VIEWER float time() const { return trapezoid.acceleration_time(feedrate_profile.entry, acceleration) + trapezoid.cruise_time() + trapezoid.deceleration_time(distance, acceleration); } -#else - float time() const; -#endif // ENABLE_NEW_GCODE_VIEWER }; private: @@ -366,7 +322,6 @@ namespace Slic3r { float elapsed_time; }; -#if ENABLE_NEW_GCODE_VIEWER struct ActualSpeedMove { unsigned int move_id{ 0 }; @@ -380,7 +335,6 @@ namespace Slic3r { std::optional fan_speed; std::optional temperature; }; -#endif // ENABLE_NEW_GCODE_VIEWER bool enabled; float acceleration; // mm/s^2 @@ -394,9 +348,6 @@ namespace Slic3r { float max_travel_acceleration; // mm/s^2 float extrude_factor_override_percentage; float time; // s -#if !ENABLE_NEW_GCODE_VIEWER - float travel_time; // s -#endif // !ENABLE_NEW_GCODE_VIEWER struct StopTime { unsigned int g1_line_id; @@ -410,24 +361,12 @@ namespace Slic3r { CustomGCodeTime gcode_time; std::vector blocks; std::vector g1_times_cache; -#if ENABLE_NEW_GCODE_VIEWER float first_layer_time; std::vector actual_speed_moves; -#else - std::array(EMoveType::Count)> moves_time; - std::array(GCodeExtrusionRole::Count)> roles_time; - std::vector layers_time; -#endif // ENABLE_NEW_GCODE_VIEWER void reset(); - // Simulates firmware st_synchronize() call -#if ENABLE_NEW_GCODE_VIEWER void calculate_time(GCodeProcessorResult& result, PrintEstimatedStatistics::ETimeMode mode, size_t keep_last_n_blocks = 0, float additional_time = 0.0f); -#else - void simulate_st_synchronize(float additional_time = 0.0f); - void calculate_time(size_t keep_last_n_blocks = 0, float additional_time = 0.0f); -#endif // ENABLE_NEW_GCODE_VIEWER }; struct TimeProcessor @@ -671,12 +610,6 @@ namespace Slic3r { SeamsDetector m_seams_detector; OptionsZCorrector m_options_z_corrector; size_t m_last_default_color_id; -#if !ENABLE_NEW_GCODE_VIEWER - bool m_spiral_vase_active; -#if ENABLE_GCODE_VIEWER_STATISTICS - std::chrono::time_point m_start_time; -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER float m_kissslicer_toolchange_time_correction; bool m_single_extruder_multi_material; @@ -746,19 +679,9 @@ namespace Slic3r { float get_time(PrintEstimatedStatistics::ETimeMode mode) const; std::string get_time_dhm(PrintEstimatedStatistics::ETimeMode mode) const; -#if !ENABLE_NEW_GCODE_VIEWER - float get_travel_time(PrintEstimatedStatistics::ETimeMode mode) const; - std::string get_travel_time_dhm(PrintEstimatedStatistics::ETimeMode mode) const; -#endif // !ENABLE_NEW_GCODE_VIEWER std::vector>> get_custom_gcode_times(PrintEstimatedStatistics::ETimeMode mode, bool include_remaining) const; -#if ENABLE_NEW_GCODE_VIEWER float get_first_layer_time(PrintEstimatedStatistics::ETimeMode mode) const; -#else - std::vector> get_moves_time(PrintEstimatedStatistics::ETimeMode mode) const; - std::vector> get_roles_time(PrintEstimatedStatistics::ETimeMode mode) const; - std::vector get_layers_time(PrintEstimatedStatistics::ETimeMode mode) const; -#endif // ENABLE_NEW_GCODE_VIEWER private: void apply_config(const DynamicPrintConfig& config); @@ -923,9 +846,7 @@ namespace Slic3r { void process_custom_gcode_time(CustomGCode::Type code); void process_filaments(CustomGCode::Type code); -#if ENABLE_NEW_GCODE_VIEWER void calculate_time(GCodeProcessorResult& result, size_t keep_last_n_blocks = 0, float additional_time = 0.0f); -#endif // ENABLE_NEW_GCODE_VIEWER // Simulates firmware st_synchronize() call void simulate_st_synchronize(float additional_time = 0.0f); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index cf66b010bb..946096b522 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -60,13 +60,9 @@ // Enable imgui dialog which allows to set the parameters used to export binarized gcode #define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW 0 -#define ENABLE_NEW_GCODE_VIEWER 1 // Enable imgui debug dialog for new gcode viewer (using libvgcode) -#define ENABLE_NEW_GCODE_VIEWER_DEBUG (0 && ENABLE_NEW_GCODE_VIEWER) +#define ENABLE_NEW_GCODE_VIEWER_DEBUG 0 // Enable extension of tool position imgui dialog to show actual speed profile #define ENABLE_ACTUAL_SPEED_DEBUG 1 -// Enable G-Code viewer statistics imgui dialog -#define ENABLE_GCODE_VIEWER_STATISTICS (0 && !ENABLE_NEW_GCODE_VIEWER) - #endif // _prusaslicer_technologies_h_ diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index bf9a590053..e3cd272dfc 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -26,9 +26,7 @@ extern void set_logging_level(unsigned int level); extern unsigned get_logging_level(); // Format memory allocated, separate thousands by comma. extern std::string format_memsize_MB(size_t n); -#if ENABLE_NEW_GCODE_VIEWER -std::string format_memsize(size_t bytes, unsigned int decimals = 1); -#endif // ENABLE_NEW_GCODE_VIEWER +extern std::string format_memsize(size_t bytes, unsigned int decimals = 1); // Return string to be added to the boost::log output to inform about the current process memory allocation. // The string is non-empty if the loglevel >= info (3) or ignore_loglevel==true. // Latter is used to get the memory info from SysInfoDialog. diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 5d28934da1..71c9bbccb3 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -1083,7 +1083,6 @@ std::string format_memsize_MB(size_t n) return out + "MB"; } -#if ENABLE_NEW_GCODE_VIEWER std::string format_memsize(size_t bytes, unsigned int decimals) { static constexpr const float kb = 1024.0f; @@ -1119,7 +1118,6 @@ std::string format_memsize(size_t bytes, unsigned int decimals) return std::to_string(bytes) + " bytes (" + std::string(buf) + "TB)"; } } -#endif // ENABLE_NEW_GCODE_VIEWER // Returns platform-specific string to be used as log output or parsed in SysInfoDialog. // The latter parses the string with (semi)colons as separators, it should look about as diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index ae5b4989f0..3f6769ea39 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -29,9 +29,7 @@ #include "GLToolbar.hpp" #include "GUI_Preview.hpp" #include "GUI_ObjectManipulation.hpp" -#if ENABLE_NEW_GCODE_VIEWER #include "MsgDialog.hpp" -#endif // ENABLE_NEW_GCODE_VIEWER #if ENABLE_ACTUAL_SPEED_DEBUG #define IMGUI_DEFINE_MATH_OPERATORS @@ -53,170 +51,22 @@ namespace Slic3r { namespace GUI { -#if !ENABLE_NEW_GCODE_VIEWER -static unsigned char buffer_id(EMoveType type) { - return static_cast(type) - static_cast(EMoveType::Retract); -} -static EMoveType buffer_type(unsigned char id) { - return static_cast(static_cast(EMoveType::Retract) + id); -} - -// Round to a bin with minimum two digits resolution. -// Equivalent to conversion to string with sprintf(buf, "%.2g", value) and conversion back to float, but faster. -static float round_to_bin(const float value) -{ -// assert(value >= 0); - constexpr float const scale [5] = { 100.f, 1000.f, 10000.f, 100000.f, 1000000.f }; - constexpr float const invscale [5] = { 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f }; - constexpr float const threshold[5] = { 0.095f, 0.0095f, 0.00095f, 0.000095f, 0.0000095f }; - // Scaling factor, pointer to the tables above. - int i = 0; - // While the scaling factor is not yet large enough to get two integer digits after scaling and rounding: - for (; value < threshold[i] && i < 4; ++ i) ; - // At least on MSVC std::round() calls a complex function, which is pretty expensive. - // our fast_round_up is much cheaper and it could be inlined. -// return std::round(value * scale[i]) * invscale[i]; - double a = value * scale[i]; - assert(std::abs(a) < double(std::numeric_limits::max())); - return fast_round_up(a) * invscale[i]; -} - -void GCodeViewer::VBuffer::reset() -{ - // release gpu memory - if (!vbos.empty()) { - glsafe(::glDeleteBuffers(static_cast(vbos.size()), static_cast(vbos.data()))); - vbos.clear(); - } - -#if ENABLE_GL_CORE_PROFILE - if (!vaos.empty()) { - glsafe(::glDeleteVertexArrays(static_cast(vaos.size()), static_cast(vaos.data()))); - vaos.clear(); - } -#endif // ENABLE_GL_CORE_PROFILE - - sizes.clear(); - count = 0; -} - -void GCodeViewer::InstanceVBuffer::Ranges::reset() -{ - for (Range& range : ranges) { - // release gpu memory - if (range.vbo > 0) - glsafe(::glDeleteBuffers(1, &range.vbo)); - } - - ranges.clear(); -} - -void GCodeViewer::InstanceVBuffer::reset() -{ - s_ids.clear(); - buffer.clear(); - render_ranges.reset(); -} - -void GCodeViewer::IBuffer::reset() -{ - // release gpu memory - if (ibo > 0) { - glsafe(::glDeleteBuffers(1, &ibo)); - ibo = 0; - } - - vbo = 0; - count = 0; -} - -bool GCodeViewer::Path::matches(const GCodeProcessorResult::MoveVertex& move, bool account_for_volumetric_rate) const -{ - auto matches_percent = [](float value1, float value2, float max_percent) { - return std::abs(value2 - value1) / value1 <= max_percent; - }; - - switch (move.type) - { - case EMoveType::Tool_change: - case EMoveType::Color_change: - case EMoveType::Pause_Print: - case EMoveType::Custom_GCode: - case EMoveType::Retract: - case EMoveType::Unretract: - case EMoveType::Seam: - case EMoveType::Extrude: { - // use rounding to reduce the number of generated paths - if (account_for_volumetric_rate) - return type == move.type && extruder_id == move.extruder_id && cp_color_id == move.cp_color_id && role == move.extrusion_role && - move.position.z() <= sub_paths.front().first.position.z() && feedrate == move.feedrate && fan_speed == move.fan_speed && - height == round_to_bin(move.height) && width == round_to_bin(move.width) && - matches_percent(volumetric_rate, move.volumetric_rate(), 0.001f); - else - return type == move.type && extruder_id == move.extruder_id && cp_color_id == move.cp_color_id && role == move.extrusion_role && - move.position.z() <= sub_paths.front().first.position.z() && feedrate == move.feedrate && fan_speed == move.fan_speed && - height == round_to_bin(move.height) && width == round_to_bin(move.width); - } - case EMoveType::Travel: { - return type == move.type && feedrate == move.feedrate && extruder_id == move.extruder_id && cp_color_id == move.cp_color_id; - } - default: { return false; } - } -} - -void GCodeViewer::TBuffer::Model::reset() -{ - instances.reset(); -} - -void GCodeViewer::TBuffer::reset() -{ - vertices.reset(); - for (IBuffer& buffer : indices) { - buffer.reset(); - } - - indices.clear(); - paths.clear(); - render_paths.clear(); - model.reset(); -} - -void GCodeViewer::TBuffer::add_path(const GCodeProcessorResult::MoveVertex& move, unsigned int b_id, size_t i_id, size_t s_id) -{ - Path::Endpoint endpoint = { b_id, i_id, s_id, move.position }; - // use rounding to reduce the number of generated paths - paths.push_back({ move.type, move.extrusion_role, move.delta_extruder, - round_to_bin(move.height), round_to_bin(move.width), - move.feedrate, move.fan_speed, move.temperature, - move.volumetric_rate(), move.extruder_id, move.cp_color_id, { { endpoint, endpoint } } }); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS void GCodeViewer::COG::render(bool fixed_screen_size) #else void GCodeViewer::COG::render() #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else -void GCodeViewer::COG::render() -#endif // ENABLE_NEW_GCODE_VIEWER { if (!m_visible) return; -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS fixed_screen_size = true; init(fixed_screen_size); #else init(); #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - init(); -#endif // ENABLE_NEW_GCODE_VIEWER GLShaderProgram* shader = wxGetApp().get_shader("toolpaths_cog"); if (shader == nullptr) @@ -228,15 +78,11 @@ void GCodeViewer::COG::render() const Camera& camera = wxGetApp().plater()->get_camera(); Transform3d model_matrix = Geometry::translation_transform(cog()) * Geometry::scale_transform(m_scale_factor); -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS if (fixed_screen_size) { #else if (m_fixed_screen_size) { #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - if (m_fixed_screen_size) { -#endif // ENABLE_NEW_GCODE_VIEWER const double inv_zoom = camera.get_inv_zoom(); model_matrix = model_matrix * Geometry::scale_transform(inv_zoom); } @@ -279,60 +125,6 @@ void GCodeViewer::COG::render() //ImGui::PopStyleVar(); } -#if !ENABLE_NEW_GCODE_VIEWER -float GCodeViewer::Extrusions::Range::step_size(EType type) const -{ - switch (type) - { - default: - case EType::Linear: { return (max > min) ? (max - min) / (static_cast(Range_Colors.size()) - 1.0f) : 0.0f; } - case EType::Logarithmic: { return (max > min && min > 0.0f) ? ::log(max / min) / (static_cast(Range_Colors.size()) - 1.0f) : 0.0f; } - } -} - -ColorRGBA GCodeViewer::Extrusions::Range::get_color_at(float value, EType type) const -{ - // Input value scaled to the colors range - float global_t = 0.0f; - const float step = step_size(type); - if (step > 0.0f) { - switch (type) - { - default: - case EType::Linear: { global_t = (value > min) ? (value - min) / step : 0.0f; break; } - case EType::Logarithmic: { global_t = (value > min && min > 0.0f) ? ::log(value / min) / step : 0.0f; break; } - } - } - - const size_t color_max_idx = Range_Colors.size() - 1; - - // Compute the two colors just below (low) and above (high) the input value - const size_t color_low_idx = std::clamp(static_cast(global_t), 0, color_max_idx); - const size_t color_high_idx = std::clamp(color_low_idx + 1, 0, color_max_idx); - - // Interpolate between the low and high colors to find exactly which color the input value should get - return lerp(Range_Colors[color_low_idx], Range_Colors[color_high_idx], global_t - static_cast(color_low_idx)); -} - -GCodeViewer::SequentialRangeCap::~SequentialRangeCap() { - if (ibo > 0) - glsafe(::glDeleteBuffers(1, &ibo)); -} - -void GCodeViewer::SequentialRangeCap::reset() { - if (ibo > 0) - glsafe(::glDeleteBuffers(1, &ibo)); - - buffer = nullptr; - ibo = 0; -#if ENABLE_GL_CORE_PROFILE - vao = 0; -#endif // ENABLE_GL_CORE_PROFILE - vbo = 0; - color = { 0.0f, 0.0f, 0.0f, 1.0f }; -} -#endif // !ENABLE_NEW_GCODE_VIEWER - #if ENABLE_ACTUAL_SPEED_DEBUG int GCodeViewer::SequentialView::ActualSpeedImguiWidget::plot(const char* label, const std::array& frame_size) { @@ -458,39 +250,8 @@ void GCodeViewer::SequentialView::Marker::render() shader->stop_using(); glsafe(::glDisable(GL_BLEND)); - -#if !ENABLE_NEW_GCODE_VIEWER - static float last_window_width = 0.0f; - static size_t last_text_length = 0; - - ImGuiWrapper& imgui = *wxGetApp().imgui(); - const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size(); - imgui.set_next_window_pos(0.5f * static_cast(cnv_size.get_width()), static_cast(cnv_size.get_height()), ImGuiCond_Always, 0.5f, 1.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - ImGui::SetNextWindowBgAlpha(0.25f); - imgui.begin(std::string("ToolPosition"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove); - imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Tool position") + ":"); - ImGui::SameLine(); - char buf[1024]; - const Vec3f position = m_world_position + m_world_offset + m_z_offset * Vec3f::UnitZ(); - sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", position.x(), position.y(), position.z()); - imgui.text(std::string(buf)); - - // force extra frame to automatically update window size - const float width = ImGui::GetWindowWidth(); - const size_t length = strlen(buf); - if (width != last_window_width || length != last_text_length) { - last_window_width = width; - last_text_length = length; - imgui.set_requires_extra_frame(); - } - - imgui.end(); - ImGui::PopStyleVar(); -#endif // !ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER static std::string to_string(libvgcode::EMoveType type) { switch (type) @@ -748,7 +509,6 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode ImGui::PopStyleVar(); } } -#endif // ENABLE_NEW_GCODE_VIEWER void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const GCodeProcessorResult& gcode_result) { @@ -830,7 +590,6 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s break; } } -#if ENABLE_NEW_GCODE_VIEWER size_t last_block_id = first_block_id; for (size_t i = last_block_id; i < cumulative_lines_counts.size(); ++i) { if (*m_cache_range.max <= cumulative_lines_counts[i]) { @@ -838,15 +597,6 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s break; } } -#else - size_t last_block_id = 0; - for (size_t i = 0; i < cumulative_lines_counts.size(); ++i) { - if (*m_cache_range.max <= cumulative_lines_counts[i]) { - last_block_id = i; - break; - } - } -#endif // ENABLE_NEW_GCODE_VIEWER assert(last_block_id >= first_block_id); FilePtr file(boost::nowide::fopen(m_filename.c_str(), "rb")); @@ -883,23 +633,11 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s } const size_t ref_id = (i == 0) ? 0 : i - 1; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#if ENABLE_NEW_GCODE_VIEWER const size_t first_line_id = (i == 0) ? *m_cache_range.min : (*m_cache_range.min > cumulative_lines_counts[ref_id]) ? *m_cache_range.min - cumulative_lines_counts[ref_id] : 1; const size_t last_line_id = (*m_cache_range.max <= cumulative_lines_counts[i]) ? (i == 0) ? *m_cache_range.max : *m_cache_range.max - cumulative_lines_counts[ref_id] : m_lines_ends[i].size(); assert(last_line_id >= first_line_id); -#else -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - const size_t first_line_id = (i == 0) ? *m_cache_range.min : - (*m_cache_range.min > cumulative_lines_counts[ref_id]) ? *m_cache_range.min - cumulative_lines_counts[ref_id] : 1; - const size_t last_line_id = (*m_cache_range.max <= cumulative_lines_counts[i]) ? - (i == 0) ? *m_cache_range.max : *m_cache_range.max - cumulative_lines_counts[ref_id] : m_lines_ends[i].size(); - assert(last_line_id >= first_line_id); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#endif // ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ for (size_t j = first_line_id; j <= last_line_id; ++j) { const size_t begin = (j == 1) ? 0 : m_lines_ends[i][j - 2]; @@ -921,9 +659,7 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s } } } -#if ENABLE_NEW_GCODE_VIEWER assert(m_lines_cache.size() == m_cache_range.size()); -#endif // ENABLE_NEW_GCODE_VIEWER }; static const ImVec4 LINE_NUMBER_COLOR = ImGuiWrapper::COL_ORANGE_LIGHT; @@ -1065,7 +801,6 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s } } -#if ENABLE_NEW_GCODE_VIEWER void GCodeViewer::SequentialView::render(float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id) { #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS @@ -1073,107 +808,14 @@ void GCodeViewer::SequentialView::render(float legend_height, const libvgcode::V #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS marker.render(); marker.render_position_window(viewer); -#else -void GCodeViewer::SequentialView::render(float legend_height) -{ - marker.render(); -#endif // ENABLE_NEW_GCODE_VIEWER float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height(); if (wxGetApp().is_editor()) bottom -= wxGetApp().plater()->get_view_toolbar().get_height(); -#if ENABLE_NEW_GCODE_VIEWER gcode_window.render(legend_height, bottom, gcode_id); -#else - gcode_window.render(legend_height, bottom, static_cast(gcode_ids[current.last])); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -const std::array(GCodeExtrusionRole::Count)> GCodeViewer::Extrusion_Role_Colors{ { - { 0.90f, 0.70f, 0.70f, 1.0f }, // GCodeExtrusionRole::None - { 1.00f, 0.90f, 0.30f, 1.0f }, // GCodeExtrusionRole::Perimeter - { 1.00f, 0.49f, 0.22f, 1.0f }, // GCodeExtrusionRole::ExternalPerimeter - { 0.12f, 0.12f, 1.00f, 1.0f }, // GCodeExtrusionRole::OverhangPerimeter - { 0.69f, 0.19f, 0.16f, 1.0f }, // GCodeExtrusionRole::InternalInfill - { 0.59f, 0.33f, 0.80f, 1.0f }, // GCodeExtrusionRole::SolidInfill - { 0.94f, 0.25f, 0.25f, 1.0f }, // GCodeExtrusionRole::TopSolidInfill - { 1.00f, 0.55f, 0.41f, 1.0f }, // GCodeExtrusionRole::Ironing - { 0.30f, 0.50f, 0.73f, 1.0f }, // GCodeExtrusionRole::BridgeInfill - { 1.00f, 1.00f, 1.00f, 1.0f }, // GCodeExtrusionRole::GapFill - { 0.00f, 0.53f, 0.43f, 1.0f }, // GCodeExtrusionRole::Skirt - { 0.00f, 1.00f, 0.00f, 1.0f }, // GCodeExtrusionRole::SupportMaterial - { 0.00f, 0.50f, 0.00f, 1.0f }, // GCodeExtrusionRole::SupportMaterialInterface - { 0.70f, 0.89f, 0.67f, 1.0f }, // GCodeExtrusionRole::WipeTower - { 0.37f, 0.82f, 0.58f, 1.0f }, // GCodeExtrusionRole::Custom -}}; - -const std::vector GCodeViewer::Options_Colors{ { - { 0.803f, 0.135f, 0.839f, 1.0f }, // Retractions - { 0.287f, 0.679f, 0.810f, 1.0f }, // Unretractions - { 0.900f, 0.900f, 0.900f, 1.0f }, // Seams - { 0.758f, 0.744f, 0.389f, 1.0f }, // ToolChanges - { 0.856f, 0.582f, 0.546f, 1.0f }, // ColorChanges - { 0.322f, 0.942f, 0.512f, 1.0f }, // PausePrints - { 0.886f, 0.825f, 0.262f, 1.0f } // CustomGCodes -}}; - -const std::vector GCodeViewer::Travel_Colors{ { - { 0.219f, 0.282f, 0.609f, 1.0f }, // Move - { 0.112f, 0.422f, 0.103f, 1.0f }, // Extrude - { 0.505f, 0.064f, 0.028f, 1.0f } // Retract -}}; - -#if 1 -// Normal ranges -const std::vector GCodeViewer::Range_Colors{ { - { 0.043f, 0.173f, 0.478f, 1.0f }, // bluish - { 0.075f, 0.349f, 0.522f, 1.0f }, - { 0.110f, 0.533f, 0.569f, 1.0f }, - { 0.016f, 0.839f, 0.059f, 1.0f }, - { 0.667f, 0.949f, 0.000f, 1.0f }, - { 0.988f, 0.975f, 0.012f, 1.0f }, - { 0.961f, 0.808f, 0.039f, 1.0f }, - { 0.890f, 0.533f, 0.125f, 1.0f }, - { 0.820f, 0.408f, 0.188f, 1.0f }, - { 0.761f, 0.322f, 0.235f, 1.0f }, - { 0.581f, 0.149f, 0.087f, 1.0f } // reddish -}}; -#else -// Detailed ranges -const std::vector GCodeViewer::Range_Colors{ { - { 0.043f, 0.173f, 0.478f, 1.0f }, // bluish - { 0.5f * (0.043f + 0.075f), 0.5f * (0.173f + 0.349f), 0.5f * (0.478f + 0.522f), 1.0f }, - { 0.075f, 0.349f, 0.522f, 1.0f }, - { 0.5f * (0.075f + 0.110f), 0.5f * (0.349f + 0.533f), 0.5f * (0.522f + 0.569f), 1.0f }, - { 0.110f, 0.533f, 0.569f, 1.0f }, - { 0.5f * (0.110f + 0.016f), 0.5f * (0.533f + 0.839f), 0.5f * (0.569f + 0.059f), 1.0f }, - { 0.016f, 0.839f, 0.059f, 1.0f }, - { 0.5f * (0.016f + 0.667f), 0.5f * (0.839f + 0.949f), 0.5f * (0.059f + 0.000f), 1.0f }, - { 0.667f, 0.949f, 0.000f, 1.0f }, - { 0.5f * (0.667f + 0.988f), 0.5f * (0.949f + 0.975f), 0.5f * (0.000f + 0.012f), 1.0f }, - { 0.988f, 0.975f, 0.012f, 1.0f }, - { 0.5f * (0.988f + 0.961f), 0.5f * (0.975f + 0.808f), 0.5f * (0.012f + 0.039f), 1.0f }, - { 0.961f, 0.808f, 0.039f, 1.0f }, - { 0.5f * (0.961f + 0.890f), 0.5f * (0.808f + 0.533f), 0.5f * (0.039f + 0.125f), 1.0f }, - { 0.890f, 0.533f, 0.125f, 1.0f }, - { 0.5f * (0.890f + 0.820f), 0.5f * (0.533f + 0.408f), 0.5f * (0.125f + 0.188f), 1.0f }, - { 0.820f, 0.408f, 0.188f, 1.0f }, - { 0.5f * (0.820f + 0.761f), 0.5f * (0.408f + 0.322f), 0.5f * (0.188f + 0.235f), 1.0f }, - { 0.761f, 0.322f, 0.235f, 1.0f }, - { 0.5f * (0.761f + 0.581f), 0.5f * (0.322f + 0.149f), 0.5f * (0.235f + 0.087f), 1.0f }, - { 0.581f, 0.149f, 0.087f, 1.0f } // reddishgit -} }; -#endif - -const ColorRGBA GCodeViewer::Wipe_Color = ColorRGBA::YELLOW(); -const ColorRGBA GCodeViewer::Neutral_Color = ColorRGBA::DARK_GRAY(); -#endif // !ENABLE_NEW_GCODE_VIEWER - GCodeViewer::GCodeViewer() { -#if !ENABLE_NEW_GCODE_VIEWER - m_extrusions.reset_role_visibility_flags(); -#endif // !ENABLE_NEW_GCODE_VIEWER m_shells.volumes.set_use_raycasters(false); } @@ -1182,73 +824,11 @@ void GCodeViewer::init() if (m_gl_data_initialized) return; -#if !ENABLE_NEW_GCODE_VIEWER - // initializes opengl data of TBuffers - for (size_t i = 0; i < m_buffers.size(); ++i) { - TBuffer& buffer = m_buffers[i]; - EMoveType type = buffer_type(i); - switch (type) - { - default: { break; } - case EMoveType::Tool_change: - case EMoveType::Color_change: - case EMoveType::Pause_Print: - case EMoveType::Custom_GCode: - case EMoveType::Retract: - case EMoveType::Unretract: - case EMoveType::Seam: { -#if !DISABLE_GCODEVIEWER_INSTANCED_MODELS - if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::InstancedModel; - buffer.shader = "gouraud_light_instanced"; - buffer.model.model.init_from(diamond(16)); - buffer.model.color = option_color(type); - buffer.model.instances.format = InstanceVBuffer::EFormat::InstancedModel; - } - else { -#endif // !DISABLE_GCODEVIEWER_INSTANCED_MODELS - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::BatchedModel; - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - buffer.shader = "gouraud_light"; - buffer.model.data = diamond(16); - buffer.model.color = option_color(type); - buffer.model.instances.format = InstanceVBuffer::EFormat::BatchedModel; -#if !DISABLE_GCODEVIEWER_INSTANCED_MODELS - } -#endif // !DISABLE_GCODEVIEWER_INSTANCED_MODELS - break; - } - case EMoveType::Wipe: - case EMoveType::Extrude: { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - buffer.shader = "gouraud_light"; - break; - } - case EMoveType::Travel: { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; - buffer.vertices.format = VBuffer::EFormat::Position; -#if ENABLE_GL_CORE_PROFILE - // on MAC using the geometry shader of dashed_thick_lines is too slow - buffer.shader = "flat"; -// buffer.shader = OpenGLManager::get_gl_info().is_core_profile() ? "dashed_thick_lines" : "flat"; -#else - buffer.shader = "flat"; -#endif // ENABLE_GL_CORE_PROFILE - break; - } - } - - set_toolpath_move_type_visible(EMoveType::Extrude, true); - } -#endif // !ENABLE_NEW_GCODE_VIEWER - // initializes tool marker m_sequential_view.marker.init(); m_gl_data_initialized = true; -#if ENABLE_NEW_GCODE_VIEWER try { m_viewer.init(reinterpret_cast(glGetString(GL_VERSION))); @@ -1259,10 +839,8 @@ void GCodeViewer::init() MessageDialog msg_dlg(wxGetApp().plater(), e.what(), _L("Error"), wxICON_ERROR | wxOK); msg_dlg.ShowModal(); } -#endif // ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const Print& print, const std::vector& str_tool_colors, const std::vector& str_color_print_colors) { @@ -1301,99 +879,97 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const // convert data from PrusaSlicer format to libvgcode format libvgcode::GCodeInputData data = libvgcode::convert(gcode_result, str_tool_colors, str_color_print_colors, m_viewer); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#define ENABLE_DATA_EXPORT 1 -#if ENABLE_DATA_EXPORT - auto extrusion_role_to_string = [](libvgcode::EGCodeExtrusionRole role) { - switch (role) { - case libvgcode::EGCodeExtrusionRole::None: { return "EGCodeExtrusionRole::None"; } - case libvgcode::EGCodeExtrusionRole::Perimeter: { return "EGCodeExtrusionRole::Perimeter"; } - case libvgcode::EGCodeExtrusionRole::ExternalPerimeter: { return "EGCodeExtrusionRole::ExternalPerimeter"; } - case libvgcode::EGCodeExtrusionRole::OverhangPerimeter: { return "EGCodeExtrusionRole::OverhangPerimeter"; } - case libvgcode::EGCodeExtrusionRole::InternalInfill: { return "EGCodeExtrusionRole::InternalInfill"; } - case libvgcode::EGCodeExtrusionRole::SolidInfill: { return "EGCodeExtrusionRole::SolidInfill"; } - case libvgcode::EGCodeExtrusionRole::TopSolidInfill: { return "EGCodeExtrusionRole::TopSolidInfill"; } - case libvgcode::EGCodeExtrusionRole::Ironing: { return "EGCodeExtrusionRole::Ironing"; } - case libvgcode::EGCodeExtrusionRole::BridgeInfill: { return "EGCodeExtrusionRole::BridgeInfill"; } - case libvgcode::EGCodeExtrusionRole::GapFill: { return "EGCodeExtrusionRole::GapFill"; } - case libvgcode::EGCodeExtrusionRole::Skirt: { return "EGCodeExtrusionRole::Skirt"; } - case libvgcode::EGCodeExtrusionRole::SupportMaterial: { return "EGCodeExtrusionRole::SupportMaterial"; } - case libvgcode::EGCodeExtrusionRole::SupportMaterialInterface: { return "EGCodeExtrusionRole::SupportMaterialInterface"; } - case libvgcode::EGCodeExtrusionRole::WipeTower: { return "EGCodeExtrusionRole::WipeTower"; } - case libvgcode::EGCodeExtrusionRole::Custom: { return "EGCodeExtrusionRole::Custom"; } - case libvgcode::EGCodeExtrusionRole::COUNT: { return "EGCodeExtrusionRole::COUNT"; } - } - }; - - auto move_type_to_string = [](libvgcode::EMoveType type) { - switch (type) { - case libvgcode::EMoveType::Noop: { return "EMoveType::Noop"; } - case libvgcode::EMoveType::Retract: { return "EMoveType::Retract"; } - case libvgcode::EMoveType::Unretract: { return "EMoveType::Unretract"; } - case libvgcode::EMoveType::Seam: { return "EMoveType::Seam"; } - case libvgcode::EMoveType::ToolChange: { return "EMoveType::ToolChange"; } - case libvgcode::EMoveType::ColorChange: { return "EMoveType::ColorChange"; } - case libvgcode::EMoveType::PausePrint: { return "EMoveType::PausePrint"; } - case libvgcode::EMoveType::CustomGCode: { return "EMoveType::CustomGCode"; } - case libvgcode::EMoveType::Travel: { return "EMoveType::Travel"; } - case libvgcode::EMoveType::Wipe: { return "EMoveType::Wipe"; } - case libvgcode::EMoveType::Extrude: { return "EMoveType::Extrude"; } - case libvgcode::EMoveType::COUNT: { return "EMoveType::COUNT"; } - } - }; - - FilePtr out{ boost::nowide::fopen("C:/prusa/slicer/test_output/spe1872/test.data", "wb") }; - if (out.f != nullptr) { - const size_t vertices_count = data.vertices.size(); - fwrite((void*)&vertices_count, 1, sizeof(size_t), out.f); - for (const libvgcode::PathVertex& v : data.vertices) { - fwrite((void*)&v.position[0], 1, sizeof(float), out.f); - fwrite((void*)&v.position[1], 1, sizeof(float), out.f); - fwrite((void*)&v.position[2], 1, sizeof(float), out.f); - fwrite((void*)&v.height, 1, sizeof(float), out.f); - fwrite((void*)&v.width, 1, sizeof(float), out.f); - fwrite((void*)&v.feedrate, 1, sizeof(float), out.f); - fwrite((void*)&v.actual_feedrate, 1, sizeof(float), out.f); - fwrite((void*)&v.mm3_per_mm, 1, sizeof(float), out.f); - fwrite((void*)&v.fan_speed, 1, sizeof(float), out.f); - fwrite((void*)&v.temperature, 1, sizeof(float), out.f); - fwrite((void*)&v.role, 1, sizeof(uint8_t), out.f); - fwrite((void*)&v.type, 1, sizeof(uint8_t), out.f); - fwrite((void*)&v.gcode_id, 1, sizeof(uint32_t), out.f); - fwrite((void*)&v.layer_id, 1, sizeof(uint32_t), out.f); - fwrite((void*)&v.extruder_id, 1, sizeof(uint32_t), out.f); - fwrite((void*)&v.color_id, 1, sizeof(uint32_t), out.f); - fwrite((void*)&v.times[0], 1, sizeof(float), out.f); - fwrite((void*)&v.times[1], 1, sizeof(float), out.f); -#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS - const float weight = v.weight; -#else - const float weight = 0.0f; -#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS - fwrite((void*)&weight, 1, sizeof(float), out.f); - } - - const uint8_t spiral_vase_mode = data.spiral_vase_mode ? 1 : 0; - fwrite((void*)&spiral_vase_mode, 1, sizeof(uint8_t), out.f); - - const size_t tool_colors_count = data.tools_colors.size(); - fwrite((void*)&tool_colors_count, 1, sizeof(size_t), out.f); - for (const libvgcode::Color& c : data.tools_colors) { - fwrite((void*)&c[0], 1, sizeof(uint8_t), out.f); - fwrite((void*)&c[1], 1, sizeof(uint8_t), out.f); - fwrite((void*)&c[2], 1, sizeof(uint8_t), out.f); - } - - const size_t color_print_colors_count = data.color_print_colors.size(); - fwrite((void*)&color_print_colors_count, 1, sizeof(size_t), out.f); - for (const libvgcode::Color& c : data.color_print_colors) { - fwrite((void*)&c[0], 1, sizeof(uint8_t), out.f); - fwrite((void*)&c[1], 1, sizeof(uint8_t), out.f); - fwrite((void*)&c[2], 1, sizeof(uint8_t), out.f); - } - } -#endif // ENABLE_DATA_EXPORT -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//#define ENABLE_DATA_EXPORT 1 +//#if ENABLE_DATA_EXPORT +// auto extrusion_role_to_string = [](libvgcode::EGCodeExtrusionRole role) { +// switch (role) { +// case libvgcode::EGCodeExtrusionRole::None: { return "EGCodeExtrusionRole::None"; } +// case libvgcode::EGCodeExtrusionRole::Perimeter: { return "EGCodeExtrusionRole::Perimeter"; } +// case libvgcode::EGCodeExtrusionRole::ExternalPerimeter: { return "EGCodeExtrusionRole::ExternalPerimeter"; } +// case libvgcode::EGCodeExtrusionRole::OverhangPerimeter: { return "EGCodeExtrusionRole::OverhangPerimeter"; } +// case libvgcode::EGCodeExtrusionRole::InternalInfill: { return "EGCodeExtrusionRole::InternalInfill"; } +// case libvgcode::EGCodeExtrusionRole::SolidInfill: { return "EGCodeExtrusionRole::SolidInfill"; } +// case libvgcode::EGCodeExtrusionRole::TopSolidInfill: { return "EGCodeExtrusionRole::TopSolidInfill"; } +// case libvgcode::EGCodeExtrusionRole::Ironing: { return "EGCodeExtrusionRole::Ironing"; } +// case libvgcode::EGCodeExtrusionRole::BridgeInfill: { return "EGCodeExtrusionRole::BridgeInfill"; } +// case libvgcode::EGCodeExtrusionRole::GapFill: { return "EGCodeExtrusionRole::GapFill"; } +// case libvgcode::EGCodeExtrusionRole::Skirt: { return "EGCodeExtrusionRole::Skirt"; } +// case libvgcode::EGCodeExtrusionRole::SupportMaterial: { return "EGCodeExtrusionRole::SupportMaterial"; } +// case libvgcode::EGCodeExtrusionRole::SupportMaterialInterface: { return "EGCodeExtrusionRole::SupportMaterialInterface"; } +// case libvgcode::EGCodeExtrusionRole::WipeTower: { return "EGCodeExtrusionRole::WipeTower"; } +// case libvgcode::EGCodeExtrusionRole::Custom: { return "EGCodeExtrusionRole::Custom"; } +// case libvgcode::EGCodeExtrusionRole::COUNT: { return "EGCodeExtrusionRole::COUNT"; } +// } +// }; +// +// auto move_type_to_string = [](libvgcode::EMoveType type) { +// switch (type) { +// case libvgcode::EMoveType::Noop: { return "EMoveType::Noop"; } +// case libvgcode::EMoveType::Retract: { return "EMoveType::Retract"; } +// case libvgcode::EMoveType::Unretract: { return "EMoveType::Unretract"; } +// case libvgcode::EMoveType::Seam: { return "EMoveType::Seam"; } +// case libvgcode::EMoveType::ToolChange: { return "EMoveType::ToolChange"; } +// case libvgcode::EMoveType::ColorChange: { return "EMoveType::ColorChange"; } +// case libvgcode::EMoveType::PausePrint: { return "EMoveType::PausePrint"; } +// case libvgcode::EMoveType::CustomGCode: { return "EMoveType::CustomGCode"; } +// case libvgcode::EMoveType::Travel: { return "EMoveType::Travel"; } +// case libvgcode::EMoveType::Wipe: { return "EMoveType::Wipe"; } +// case libvgcode::EMoveType::Extrude: { return "EMoveType::Extrude"; } +// case libvgcode::EMoveType::COUNT: { return "EMoveType::COUNT"; } +// } +// }; +// +// FilePtr out{ boost::nowide::fopen("C:/prusa/slicer/test_output/spe1872/test.data", "wb") }; +// if (out.f != nullptr) { +// const size_t vertices_count = data.vertices.size(); +// fwrite((void*)&vertices_count, 1, sizeof(size_t), out.f); +// for (const libvgcode::PathVertex& v : data.vertices) { +// fwrite((void*)&v.position[0], 1, sizeof(float), out.f); +// fwrite((void*)&v.position[1], 1, sizeof(float), out.f); +// fwrite((void*)&v.position[2], 1, sizeof(float), out.f); +// fwrite((void*)&v.height, 1, sizeof(float), out.f); +// fwrite((void*)&v.width, 1, sizeof(float), out.f); +// fwrite((void*)&v.feedrate, 1, sizeof(float), out.f); +// fwrite((void*)&v.actual_feedrate, 1, sizeof(float), out.f); +// fwrite((void*)&v.mm3_per_mm, 1, sizeof(float), out.f); +// fwrite((void*)&v.fan_speed, 1, sizeof(float), out.f); +// fwrite((void*)&v.temperature, 1, sizeof(float), out.f); +// fwrite((void*)&v.role, 1, sizeof(uint8_t), out.f); +// fwrite((void*)&v.type, 1, sizeof(uint8_t), out.f); +// fwrite((void*)&v.gcode_id, 1, sizeof(uint32_t), out.f); +// fwrite((void*)&v.layer_id, 1, sizeof(uint32_t), out.f); +// fwrite((void*)&v.extruder_id, 1, sizeof(uint32_t), out.f); +// fwrite((void*)&v.color_id, 1, sizeof(uint32_t), out.f); +// fwrite((void*)&v.times[0], 1, sizeof(float), out.f); +// fwrite((void*)&v.times[1], 1, sizeof(float), out.f); +//#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS +// const float weight = v.weight; +//#else +// const float weight = 0.0f; +//#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS +// fwrite((void*)&weight, 1, sizeof(float), out.f); +// } +// +// const uint8_t spiral_vase_mode = data.spiral_vase_mode ? 1 : 0; +// fwrite((void*)&spiral_vase_mode, 1, sizeof(uint8_t), out.f); +// +// const size_t tool_colors_count = data.tools_colors.size(); +// fwrite((void*)&tool_colors_count, 1, sizeof(size_t), out.f); +// for (const libvgcode::Color& c : data.tools_colors) { +// fwrite((void*)&c[0], 1, sizeof(uint8_t), out.f); +// fwrite((void*)&c[1], 1, sizeof(uint8_t), out.f); +// fwrite((void*)&c[2], 1, sizeof(uint8_t), out.f); +// } +// +// const size_t color_print_colors_count = data.color_print_colors.size(); +// fwrite((void*)&color_print_colors_count, 1, sizeof(size_t), out.f); +// for (const libvgcode::Color& c : data.color_print_colors) { +// fwrite((void*)&c[0], 1, sizeof(uint8_t), out.f); +// fwrite((void*)&c[1], 1, sizeof(uint8_t), out.f); +// fwrite((void*)&c[2], 1, sizeof(uint8_t), out.f); +// } +// } +//#endif // ENABLE_DATA_EXPORT // send data to the viewer m_viewer.reset_default_extrusion_roles_colors(); @@ -1433,21 +1009,6 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const m_contained_in_bed = wxGetApp().plater()->build_volume().all_paths_inside(gcode_result, m_paths_bounding_box); m_extruders_count = gcode_result.extruders_count; -#else -void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print & print) -{ - // avoid processing if called with the same gcode_result - if (m_last_result_id == gcode_result.id && - (m_last_view_type == m_view_type || (m_last_view_type != EViewType::VolumetricRate && m_view_type != EViewType::VolumetricRate))) - return; - - m_last_result_id = gcode_result.id; - m_last_view_type = m_view_type; - - // release gpu memory, if used - reset(); -#endif // ENABLE_NEW_GCODE_VIEWER - m_sequential_view.gcode_window.load_gcode(gcode_result); if (wxGetApp().is_gcode_viewer()) @@ -1456,18 +1017,10 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print & p m_max_print_height = gcode_result.max_print_height; m_z_offset = gcode_result.z_offset; -#if !ENABLE_NEW_GCODE_VIEWER - load_toolpaths(gcode_result); -#endif // !ENABLE_NEW_GCODE_VIEWER load_wipetower_shell(print); -#if ENABLE_NEW_GCODE_VIEWER if (m_viewer.get_layers_count() == 0) return; -#else - if (m_layers.empty()) - return; -#endif // ENABLE_NEW_GCODE_VIEWER m_settings_ids = gcode_result.settings_ids; m_filament_diameters = gcode_result.filament_diameters; @@ -1517,7 +1070,6 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print & p m_print_statistics = gcode_result.print_statistics; -#if ENABLE_NEW_GCODE_VIEWER PrintEstimatedStatistics::ETimeMode time_mode = convert(m_viewer.get_time_mode()); if (m_viewer.get_time_mode() != libvgcode::ETimeMode::Normal) { const float time = m_print_statistics.modes[static_cast(time_mode)].time; @@ -1525,25 +1077,12 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print & p short_time(get_time_dhms(time)) == short_time(get_time_dhms(m_print_statistics.modes[static_cast(PrintEstimatedStatistics::ETimeMode::Normal)].time))) m_viewer.set_time_mode(libvgcode::convert(PrintEstimatedStatistics::ETimeMode::Normal)); } -#else - if (m_time_estimate_mode != PrintEstimatedStatistics::ETimeMode::Normal) { - const float time = m_print_statistics.modes[static_cast(m_time_estimate_mode)].time; - if (time == 0.0f || - short_time(get_time_dhms(time)) == short_time(get_time_dhms(m_print_statistics.modes[static_cast(PrintEstimatedStatistics::ETimeMode::Normal)].time))) - m_time_estimate_mode = PrintEstimatedStatistics::ETimeMode::Normal; - } -#endif // ENABLE_NEW_GCODE_VIEWER m_conflict_result = gcode_result.conflict_result; if (m_conflict_result.has_value()) -#if ENABLE_NEW_GCODE_VIEWER m_conflict_result->layer = m_viewer.get_layer_id_at(static_cast(m_conflict_result->_height)); -#else - m_conflict_result->layer = m_layers.get_l_at(m_conflict_result->_height); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER void GCodeViewer::load_as_preview(libvgcode::GCodeInputData&& data) { m_loaded_as_preview = true; @@ -1561,84 +1100,6 @@ void GCodeViewer::load_as_preview(libvgcode::GCodeInputData&& data) const BoundingBoxf3 paths_bounding_box(libvgcode::convert(bbox[0]).cast(), libvgcode::convert(bbox[1]).cast()); m_contained_in_bed = wxGetApp().plater()->build_volume().all_paths_inside(GCodeProcessorResult(), paths_bounding_box); } -#else -void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors) -{ -#if ENABLE_GCODE_VIEWER_STATISTICS - auto start_time = std::chrono::high_resolution_clock::now(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - if (m_moves_count == 0) - return; - - wxBusyCursor busy; - - if (m_view_type == EViewType::Tool && !gcode_result.extruder_colors.empty()) - // update tool colors from config stored in the gcode - decode_colors(gcode_result.extruder_colors, m_tool_colors); - else - // update tool colors - decode_colors(str_tool_colors, m_tool_colors); - - ColorRGBA default_color; - decode_color("#FF8000", default_color); - - // ensure there are enough colors defined - while (m_tool_colors.size() < std::max(size_t(1), gcode_result.extruders_count)) - m_tool_colors.push_back(default_color); - - // update ranges for coloring / legend - m_extrusions.reset_ranges(); - for (size_t i = 0; i < m_moves_count; ++i) { - // skip first vertex - if (i == 0) - continue; - - const GCodeProcessorResult::MoveVertex& curr = gcode_result.moves[i]; - - switch (curr.type) - { - case EMoveType::Extrude: - { - m_extrusions.ranges.height.update_from(round_to_bin(curr.height)); - if (curr.extrusion_role != GCodeExtrusionRole::Custom || is_visible(GCodeExtrusionRole::Custom)) - m_extrusions.ranges.width.update_from(round_to_bin(curr.width)); - m_extrusions.ranges.fan_speed.update_from(curr.fan_speed); - m_extrusions.ranges.temperature.update_from(curr.temperature); - if (curr.extrusion_role != GCodeExtrusionRole::Custom || is_visible(GCodeExtrusionRole::Custom)) - m_extrusions.ranges.volumetric_rate.update_from(round_to_bin(curr.volumetric_rate())); - [[fallthrough]]; - } - case EMoveType::Travel: - { - if (m_buffers[buffer_id(curr.type)].visible) - m_extrusions.ranges.feedrate.update_from(curr.feedrate); - - break; - } - default: { break; } - } - } - - for (size_t i = 0; i < gcode_result.print_statistics.modes.size(); ++i) { - m_layers_times[i] = gcode_result.print_statistics.modes[i].layers_times; - } - - for (size_t i = 0; i < m_layers_times.size(); ++i) { - for (float time : m_layers_times[i]) { - m_extrusions.ranges.layer_time[i].update_from(time); - } - } - -#if ENABLE_GCODE_VIEWER_STATISTICS - m_statistics.refresh_time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - // update buffers' render paths - refresh_render_paths(false, false); - log_memory_used("Refreshed G-code extrusion paths, "); -} -#endif // ENABLE_NEW_GCODE_VIEWER void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig* config) { @@ -1648,14 +1109,7 @@ void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig* conf void GCodeViewer::reset() { -#if ENABLE_NEW_GCODE_VIEWER m_viewer.reset(); -#else - m_moves_count = 0; - for (TBuffer& buffer : m_buffers) { - buffer.reset(); - } -#endif // ENABLE_NEW_GCODE_VIEWER m_paths_bounding_box.reset(); m_max_bounding_box.reset(); @@ -1663,54 +1117,25 @@ void GCodeViewer::reset() m_z_offset = 0.0f; m_filament_diameters = std::vector(); m_filament_densities = std::vector(); -#if !ENABLE_NEW_GCODE_VIEWER - m_tool_colors = std::vector(); - m_extruder_ids = std::vector(); - m_extrusions.reset_ranges(); - m_layers.reset(); - m_layers_z_range = { 0, 0 }; - m_roles = std::vector(); - for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { - m_layers_times[i] = std::vector(); - } -#endif // !ENABLE_NEW_GCODE_VIEWER m_extruders_count = 0; m_print_statistics.reset(); m_custom_gcode_per_print_z = std::vector(); m_sequential_view.gcode_window.reset(); -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - m_statistics.reset_all(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER m_contained_in_bed = true; m_legend_resizer.reset(); } void GCodeViewer::render() { -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - m_statistics.reset_opengl(); - m_statistics.total_instances_gpu_size = 0; -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER - glsafe(::glEnable(GL_DEPTH_TEST)); render_shells(); -#if ENABLE_NEW_GCODE_VIEWER if (m_viewer.get_extrusion_roles().empty()) return; -#else - if (m_roles.empty()) - return; -#endif // ENABLE_NEW_GCODE_VIEWER render_toolpaths(); float legend_height = 0.0f; -#if ENABLE_NEW_GCODE_VIEWER if (m_viewer.get_layers_count() > 0) { render_legend(legend_height); if (m_viewer.get_view_enabled_range()[1] != m_viewer.get_view_visible_range()[1]) { @@ -1719,24 +1144,8 @@ void GCodeViewer::render() m_sequential_view.marker.set_z_offset(m_z_offset); m_sequential_view.render(legend_height, &m_viewer, curr_vertex.gcode_id); } -#else - if (!m_layers.empty()) { - render_legend(legend_height); - if (m_sequential_view.current.last != m_sequential_view.endpoints.last) { - m_sequential_view.marker.set_world_position(m_sequential_view.current_position); - m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); - m_sequential_view.marker.set_z_offset(m_z_offset); - m_sequential_view.render(legend_height); - } -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - render_statistics(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS if (is_legend_shown()) { ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); @@ -1771,26 +1180,20 @@ void GCodeViewer::render() imgui.end(); } #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#endif // ENABLE_NEW_GCODE_VIEWER } bool GCodeViewer::can_export_toolpaths() const { -#if ENABLE_NEW_GCODE_VIEWER const libvgcode::Interval& visible_range = m_viewer.get_view_visible_range(); for (size_t i = visible_range[0]; i <= visible_range[1]; ++i) { if (m_viewer.get_vertex_at(i).is_extrusion()) return true; } return false; -#else - return has_data() && m_buffers[buffer_id(EMoveType::Extrude)].render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle; -#endif // ENABLE_NEW_GCODE_VIEWER } void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned int last) { -#if ENABLE_NEW_GCODE_VIEWER m_viewer.set_view_visible_range(static_cast(first), static_cast(last)); const libvgcode::Interval& enabled_range = m_viewer.get_view_enabled_range(); wxGetApp().plater()->enable_preview_moves_slider(enabled_range[1] > enabled_range[0]); @@ -1847,124 +1250,14 @@ void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned in } } #endif // ENABLE_ACTUAL_SPEED_DEBUG -#else - auto is_visible = [this](unsigned int id) { - for (const TBuffer& buffer : m_buffers) { - if (buffer.visible) { - for (const Path& path : buffer.paths) { - if (path.sub_paths.front().first.s_id <= id && id <= path.sub_paths.back().last.s_id) - return true; - } - } - } - return false; - }; - - const int first_diff = static_cast(first) - static_cast(m_sequential_view.last_current.first); - const int last_diff = static_cast(last) - static_cast(m_sequential_view.last_current.last); - - unsigned int new_first = first; - unsigned int new_last = last; - - if (m_sequential_view.skip_invisible_moves) { - while (!is_visible(new_first)) { - if (first_diff > 0) - ++new_first; - else - --new_first; - } - - while (!is_visible(new_last)) { - if (last_diff > 0) - ++new_last; - else - --new_last; - } - } - - m_sequential_view.current.first = new_first; - m_sequential_view.current.last = new_last; - m_sequential_view.last_current = m_sequential_view.current; - - refresh_render_paths(true, true); - - if (new_first != first || new_last != last) - wxGetApp().plater()->update_preview_moves_slider(); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -bool GCodeViewer::is_toolpath_move_type_visible(EMoveType type) const -{ - size_t id = static_cast(buffer_id(type)); - return (id < m_buffers.size()) ? m_buffers[id].visible : false; -} - -void GCodeViewer::set_toolpath_move_type_visible(EMoveType type, bool visible) -{ - size_t id = static_cast(buffer_id(type)); - if (id < m_buffers.size()) - m_buffers[id].visible = visible; -} - -unsigned int GCodeViewer::get_options_visibility_flags() const -{ - auto set_flag = [](unsigned int flags, unsigned int flag, bool active) { - return active ? (flags | (1 << flag)) : flags; - }; - - unsigned int flags = 0; - flags = set_flag(flags, static_cast(Preview::OptionType::Travel), is_toolpath_move_type_visible(EMoveType::Travel)); - flags = set_flag(flags, static_cast(Preview::OptionType::Wipe), is_toolpath_move_type_visible(EMoveType::Wipe)); - flags = set_flag(flags, static_cast(Preview::OptionType::Retractions), is_toolpath_move_type_visible(EMoveType::Retract)); - flags = set_flag(flags, static_cast(Preview::OptionType::Unretractions), is_toolpath_move_type_visible(EMoveType::Unretract)); - flags = set_flag(flags, static_cast(Preview::OptionType::Seams), is_toolpath_move_type_visible(EMoveType::Seam)); - flags = set_flag(flags, static_cast(Preview::OptionType::ToolChanges), is_toolpath_move_type_visible(EMoveType::Tool_change)); - flags = set_flag(flags, static_cast(Preview::OptionType::ColorChanges), is_toolpath_move_type_visible(EMoveType::Color_change)); - flags = set_flag(flags, static_cast(Preview::OptionType::PausePrints), is_toolpath_move_type_visible(EMoveType::Pause_Print)); - flags = set_flag(flags, static_cast(Preview::OptionType::CustomGCodes), is_toolpath_move_type_visible(EMoveType::Custom_GCode)); - flags = set_flag(flags, static_cast(Preview::OptionType::CenterOfGravity), m_cog.is_visible()); - flags = set_flag(flags, static_cast(Preview::OptionType::Shells), m_shells.visible); - flags = set_flag(flags, static_cast(Preview::OptionType::ToolMarker), m_sequential_view.marker.is_visible()); - return flags; -} - -void GCodeViewer::set_options_visibility_from_flags(unsigned int flags) -{ - auto is_flag_set = [flags](unsigned int flag) { - return (flags & (1 << flag)) != 0; - }; - - set_toolpath_move_type_visible(EMoveType::Travel, is_flag_set(static_cast(Preview::OptionType::Travel))); - set_toolpath_move_type_visible(EMoveType::Wipe, is_flag_set(static_cast(Preview::OptionType::Wipe))); - set_toolpath_move_type_visible(EMoveType::Retract, is_flag_set(static_cast(Preview::OptionType::Retractions))); - set_toolpath_move_type_visible(EMoveType::Unretract, is_flag_set(static_cast(Preview::OptionType::Unretractions))); - set_toolpath_move_type_visible(EMoveType::Seam, is_flag_set(static_cast(Preview::OptionType::Seams))); - set_toolpath_move_type_visible(EMoveType::Tool_change, is_flag_set(static_cast(Preview::OptionType::ToolChanges))); - set_toolpath_move_type_visible(EMoveType::Color_change, is_flag_set(static_cast(Preview::OptionType::ColorChanges))); - set_toolpath_move_type_visible(EMoveType::Pause_Print, is_flag_set(static_cast(Preview::OptionType::PausePrints))); - set_toolpath_move_type_visible(EMoveType::Custom_GCode, is_flag_set(static_cast(Preview::OptionType::CustomGCodes))); - m_cog.set_visible(is_flag_set(static_cast(Preview::OptionType::CenterOfGravity))); - m_shells.visible = is_flag_set(static_cast(Preview::OptionType::Shells)); - m_sequential_view.marker.set_visible(is_flag_set(static_cast(Preview::OptionType::ToolMarker))); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - void GCodeViewer::set_layers_z_range(const std::array& layers_z_range) { -#if ENABLE_NEW_GCODE_VIEWER m_viewer.set_layers_view_range(static_cast(layers_z_range[0]), static_cast(layers_z_range[1])); wxGetApp().plater()->update_preview_moves_slider(); -#else - bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0]; - bool keep_sequential_current_last = layers_z_range[1] <= m_layers_z_range[1]; - m_layers_z_range = layers_z_range; - refresh_render_paths(keep_sequential_current_first, keep_sequential_current_last); - wxGetApp().plater()->update_preview_moves_slider(); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER class ToolpathsObjExporter { public: @@ -2265,7 +1558,6 @@ private: }; const float ToolpathsObjExporter::Cap_Rounding_Factor = 0.25f; -#endif // ENABLE_NEW_GCODE_VIEWER void GCodeViewer::export_toolpaths_to_obj(const char* filename) const { @@ -2277,1165 +1569,10 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const wxBusyCursor busy; -#if ENABLE_NEW_GCODE_VIEWER ToolpathsObjExporter exporter(m_viewer); exporter.export_to(filename); -#else - // the data needed is contained into the Extrude TBuffer - const TBuffer& t_buffer = m_buffers[buffer_id(EMoveType::Extrude)]; - if (!t_buffer.has_data()) - return; - - if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::Triangle) - return; - - // collect color information to generate materials - std::vector colors; - for (const RenderPath& path : t_buffer.render_paths) { - colors.push_back(path.color); - } - sort_remove_duplicates(colors); - - // save materials file - boost::filesystem::path mat_filename(filename); - mat_filename.replace_extension("mtl"); - - CNumericLocalesSetter locales_setter; - - FILE* fp = boost::nowide::fopen(mat_filename.string().c_str(), "w"); - if (fp == nullptr) { - BOOST_LOG_TRIVIAL(error) << "GCodeViewer::export_toolpaths_to_obj: Couldn't open " << mat_filename.string().c_str() << " for writing"; - return; - } - - fprintf(fp, "# G-Code Toolpaths Materials\n"); - fprintf(fp, "# Generated by %s-%s based on Slic3r\n", SLIC3R_APP_NAME, SLIC3R_VERSION); - - unsigned int colors_count = 1; - for (const ColorRGBA& color : colors) { - fprintf(fp, "\nnewmtl material_%d\n", colors_count++); - fprintf(fp, "Ka 1 1 1\n"); - fprintf(fp, "Kd %g %g %g\n", color.r(), color.g(), color.b()); - fprintf(fp, "Ks 0 0 0\n"); - } - - fclose(fp); - - // save geometry file - fp = boost::nowide::fopen(filename, "w"); - if (fp == nullptr) { - BOOST_LOG_TRIVIAL(error) << "GCodeViewer::export_toolpaths_to_obj: Couldn't open " << filename << " for writing"; - return; - } - - fprintf(fp, "# G-Code Toolpaths\n"); - fprintf(fp, "# Generated by %s-%s based on Slic3r\n", SLIC3R_APP_NAME, SLIC3R_VERSION); - fprintf(fp, "\nmtllib ./%s\n", mat_filename.filename().string().c_str()); - - const size_t floats_per_vertex = t_buffer.vertices.vertex_size_floats(); - - std::vector out_vertices; - std::vector out_normals; - - struct VerticesOffset - { - unsigned int vbo; - size_t offset; - }; - std::vector vertices_offsets; - vertices_offsets.push_back({ t_buffer.vertices.vbos.front(), 0 }); - - // get vertices/normals data from vertex buffers on gpu - for (size_t i = 0; i < t_buffer.vertices.vbos.size(); ++i) { - const size_t floats_count = t_buffer.vertices.sizes[i] / sizeof(float); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, t_buffer.vertices.vbos[i])); -#if ENABLE_OPENGL_ES - const VertexBuffer vertices = *static_cast(::glMapBufferRange(GL_ARRAY_BUFFER, 0, - static_cast(t_buffer.vertices.sizes[i]), GL_MAP_READ_BIT)); - glcheck(); - glsafe(::glUnmapBuffer(GL_ARRAY_BUFFER)); -#else - VertexBuffer vertices(floats_count); - glsafe(::glGetBufferSubData(GL_ARRAY_BUFFER, 0, static_cast(t_buffer.vertices.sizes[i]), static_cast(vertices.data()))); -#endif // ENABLE_OPENGL_ES - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - const size_t vertices_count = floats_count / floats_per_vertex; - for (size_t j = 0; j < vertices_count; ++j) { - const size_t base = j * floats_per_vertex; - out_vertices.push_back({ vertices[base + 0], vertices[base + 1], vertices[base + 2] }); - out_normals.push_back({ vertices[base + 3], vertices[base + 4], vertices[base + 5] }); - } - - if (i < t_buffer.vertices.vbos.size() - 1) - vertices_offsets.push_back({ t_buffer.vertices.vbos[i + 1], vertices_offsets.back().offset + vertices_count }); - } - - // save vertices to file - fprintf(fp, "\n# vertices\n"); - for (const Vec3f& v : out_vertices) { - fprintf(fp, "v %g %g %g\n", v.x(), v.y(), v.z()); - } - - // save normals to file - fprintf(fp, "\n# normals\n"); - for (const Vec3f& n : out_normals) { - fprintf(fp, "vn %g %g %g\n", n.x(), n.y(), n.z()); - } - - size_t i = 0; - for (const ColorRGBA& color : colors) { - // save material triangles to file - fprintf(fp, "\nusemtl material_%zu\n", i + 1); - fprintf(fp, "# triangles material %zu\n", i + 1); - - for (const RenderPath& render_path : t_buffer.render_paths) { - if (render_path.color != color) - continue; - - const IBuffer& ibuffer = t_buffer.indices[render_path.ibuffer_id]; - size_t vertices_offset = 0; - for (size_t j = 0; j < vertices_offsets.size(); ++j) { - const VerticesOffset& offset = vertices_offsets[j]; - if (offset.vbo == ibuffer.vbo) { - vertices_offset = offset.offset; - break; - } - } - - // get indices data from index buffer on gpu - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer.ibo)); - for (size_t j = 0; j < render_path.sizes.size(); ++j) { -#if ENABLE_OPENGL_ES - const IndexBuffer indices = *static_cast(::glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, - static_cast(render_path.offsets[j]), static_cast(render_path.sizes[j] * sizeof(IBufferType)), - GL_MAP_READ_BIT)); - glcheck(); - glsafe(::glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)); -#else - IndexBuffer indices(render_path.sizes[j]); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast(render_path.offsets[j]), - static_cast(render_path.sizes[j] * sizeof(IBufferType)), static_cast(indices.data()))); -#endif // ENABLE_OPENGL_ES - - const size_t triangles_count = render_path.sizes[j] / 3; - for (size_t k = 0; k < triangles_count; ++k) { - const size_t base = k * 3; - const size_t v1 = 1 + static_cast(indices[base + 0]) + vertices_offset; - const size_t v2 = 1 + static_cast(indices[base + 1]) + vertices_offset; - const size_t v3 = 1 + static_cast(indices[base + 2]) + vertices_offset; - if (v1 != v2) - // do not export dummy triangles - fprintf(fp, "f %zu//%zu %zu//%zu %zu//%zu\n", v1, v1, v2, v2, v3, v3); - } - } - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - ++i; - } - - fclose(fp); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if !ENABLE_NEW_GCODE_VIEWER -void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) -{ - // max index buffer size, in bytes - static const size_t IBUFFER_THRESHOLD_BYTES = 64 * 1024 * 1024; - - auto log_memory_usage = [this](const std::string& label, const std::vector& vertices, const std::vector& indices) { - int64_t vertices_size = 0; - for (const MultiVertexBuffer& buffers : vertices) { - for (const VertexBuffer& buffer : buffers) { - vertices_size += SLIC3R_STDVEC_MEMSIZE(buffer, float); - } - } - int64_t indices_size = 0; - for (const MultiIndexBuffer& buffers : indices) { - for (const IndexBuffer& buffer : buffers) { - indices_size += SLIC3R_STDVEC_MEMSIZE(buffer, IBufferType); - } - } - log_memory_used(label, vertices_size + indices_size); - }; - - // format data into the buffers to be rendered as lines - auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { - auto add_vertex = [&vertices](const GCodeProcessorResult::MoveVertex& vertex) { - // add position - vertices.push_back(vertex.position.x()); - vertices.push_back(vertex.position.y()); - vertices.push_back(vertex.position.z()); - }; - - // add previous vertex - add_vertex(prev); - // add current vertex - add_vertex(curr); - }; - auto add_indices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, TBuffer& buffer, - unsigned int ibuffer_id, IndexBuffer& indices, size_t move_id, bool account_for_volumetric_rate) { - if (buffer.paths.empty() || prev.type != curr.type || !buffer.paths.back().matches(curr, account_for_volumetric_rate)) { - // add starting index - indices.push_back(static_cast(indices.size())); - buffer.add_path(curr, ibuffer_id, indices.size() - 1, move_id - 1); - buffer.paths.back().sub_paths.front().first.position = prev.position; - } - - Path& last_path = buffer.paths.back(); - if (last_path.sub_paths.front().first.i_id != last_path.sub_paths.back().last.i_id) { - // add previous index - indices.push_back(static_cast(indices.size())); - } - - // add current index - indices.push_back(static_cast(indices.size())); - last_path.sub_paths.back().last = { ibuffer_id, indices.size() - 1, move_id, curr.position }; - }; - - // format data into the buffers to be rendered as solid - auto add_vertices_as_solid = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, TBuffer& buffer, - unsigned int vbuffer_id, VertexBuffer& vertices, size_t move_id, bool account_for_volumetric_rate) { - auto store_vertex = [](VertexBuffer& vertices, const Vec3f& position, const Vec3f& normal) { - // append position - vertices.push_back(position.x()); - vertices.push_back(position.y()); - vertices.push_back(position.z()); - // append normal - vertices.push_back(normal.x()); - vertices.push_back(normal.y()); - vertices.push_back(normal.z()); - }; - - if (buffer.paths.empty() || prev.type != curr.type || !buffer.paths.back().matches(curr, account_for_volumetric_rate)) { - buffer.add_path(curr, vbuffer_id, vertices.size(), move_id - 1); - buffer.paths.back().sub_paths.back().first.position = prev.position; - } - - Path& last_path = buffer.paths.back(); - - const Vec3f dir = (curr.position - prev.position).normalized(); - const Vec3f right = Vec3f(dir.y(), -dir.x(), 0.0f).normalized(); - const Vec3f left = -right; - const Vec3f up = right.cross(dir); - const Vec3f down = -up; - const float half_width = 0.5f * last_path.width; - const float half_height = 0.5f * last_path.height; - const Vec3f prev_pos = prev.position - half_height * up; - const Vec3f curr_pos = curr.position - half_height * up; - const Vec3f d_up = half_height * up; - const Vec3f d_down = -half_height * up; - const Vec3f d_right = half_width * right; - const Vec3f d_left = -half_width * right; - - // vertices 1st endpoint - if (last_path.vertices_count() == 1 || vertices.empty()) { - // 1st segment or restart into a new vertex buffer - // =============================================== - store_vertex(vertices, prev_pos + d_up, up); - store_vertex(vertices, prev_pos + d_right, right); - store_vertex(vertices, prev_pos + d_down, down); - store_vertex(vertices, prev_pos + d_left, left); - } - else { - // any other segment - // ================= - store_vertex(vertices, prev_pos + d_right, right); - store_vertex(vertices, prev_pos + d_left, left); - } - - // vertices 2nd endpoint - store_vertex(vertices, curr_pos + d_up, up); - store_vertex(vertices, curr_pos + d_right, right); - store_vertex(vertices, curr_pos + d_down, down); - store_vertex(vertices, curr_pos + d_left, left); - - last_path.sub_paths.back().last = { vbuffer_id, vertices.size(), move_id, curr.position }; - }; - auto add_indices_as_solid = [&](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, - const GCodeProcessorResult::MoveVertex* next, TBuffer& buffer, size_t& vbuffer_size, unsigned int ibuffer_id, - IndexBuffer& indices, size_t move_id, bool account_for_volumetric_rate) { - static Vec3f prev_dir; - static Vec3f prev_up; - static float sq_prev_length; - auto store_triangle = [](IndexBuffer& indices, IBufferType i1, IBufferType i2, IBufferType i3) { - indices.push_back(i1); - indices.push_back(i2); - indices.push_back(i3); - }; - auto append_dummy_cap = [store_triangle](IndexBuffer& indices, IBufferType id) { - store_triangle(indices, id, id, id); - store_triangle(indices, id, id, id); - }; - auto convert_vertices_offset = [](size_t vbuffer_size, const std::array& v_offsets) { - std::array ret = { - static_cast(static_cast(vbuffer_size) + v_offsets[0]), - static_cast(static_cast(vbuffer_size) + v_offsets[1]), - static_cast(static_cast(vbuffer_size) + v_offsets[2]), - static_cast(static_cast(vbuffer_size) + v_offsets[3]), - static_cast(static_cast(vbuffer_size) + v_offsets[4]), - static_cast(static_cast(vbuffer_size) + v_offsets[5]), - static_cast(static_cast(vbuffer_size) + v_offsets[6]), - static_cast(static_cast(vbuffer_size) + v_offsets[7]) - }; - return ret; - }; - auto append_starting_cap_triangles = [&](IndexBuffer& indices, const std::array& v_offsets) { - store_triangle(indices, v_offsets[0], v_offsets[2], v_offsets[1]); - store_triangle(indices, v_offsets[0], v_offsets[3], v_offsets[2]); - }; - auto append_stem_triangles = [&](IndexBuffer& indices, const std::array& v_offsets) { - store_triangle(indices, v_offsets[0], v_offsets[1], v_offsets[4]); - store_triangle(indices, v_offsets[1], v_offsets[5], v_offsets[4]); - store_triangle(indices, v_offsets[1], v_offsets[2], v_offsets[5]); - store_triangle(indices, v_offsets[2], v_offsets[6], v_offsets[5]); - store_triangle(indices, v_offsets[2], v_offsets[3], v_offsets[6]); - store_triangle(indices, v_offsets[3], v_offsets[7], v_offsets[6]); - store_triangle(indices, v_offsets[3], v_offsets[0], v_offsets[7]); - store_triangle(indices, v_offsets[0], v_offsets[4], v_offsets[7]); - }; - auto append_ending_cap_triangles = [&](IndexBuffer& indices, const std::array& v_offsets) { - store_triangle(indices, v_offsets[4], v_offsets[6], v_offsets[7]); - store_triangle(indices, v_offsets[4], v_offsets[5], v_offsets[6]); - }; - - if (buffer.paths.empty() || prev.type != curr.type || !buffer.paths.back().matches(curr, account_for_volumetric_rate)) { - buffer.add_path(curr, ibuffer_id, indices.size(), move_id - 1); - buffer.paths.back().sub_paths.back().first.position = prev.position; - } - - Path& last_path = buffer.paths.back(); - - const Vec3f dir = (curr.position - prev.position).normalized(); - const Vec3f right = Vec3f(dir.y(), -dir.x(), 0.0f).normalized(); - const Vec3f up = right.cross(dir); - const float sq_length = (curr.position - prev.position).squaredNorm(); - - const std::array first_seg_v_offsets = convert_vertices_offset(vbuffer_size, { 0, 1, 2, 3, 4, 5, 6, 7 }); - const std::array non_first_seg_v_offsets = convert_vertices_offset(vbuffer_size, { -4, 0, -2, 1, 2, 3, 4, 5 }); - const bool is_first_segment = (last_path.vertices_count() == 1); - if (is_first_segment || vbuffer_size == 0) { - // 1st segment or restart into a new vertex buffer - // =============================================== - if (is_first_segment) - // starting cap triangles - append_starting_cap_triangles(indices, first_seg_v_offsets); - // dummy triangles outer corner cap - append_dummy_cap(indices, vbuffer_size); - - // stem triangles - append_stem_triangles(indices, first_seg_v_offsets); - - vbuffer_size += 8; - } - else { - // any other segment - // ================= - float displacement = 0.0f; - const float cos_dir = prev_dir.dot(dir); - if (cos_dir > -0.9998477f) { - // if the angle between adjacent segments is smaller than 179 degrees - const Vec3f med_dir = (prev_dir + dir).normalized(); - const float half_width = 0.5f * last_path.width; - displacement = half_width * ::tan(::acos(std::clamp(dir.dot(med_dir), -1.0f, 1.0f))); - } - - const float sq_displacement = sqr(displacement); - const bool can_displace = displacement > 0.0f && sq_displacement < sq_prev_length && sq_displacement < sq_length; - - const bool is_right_turn = prev_up.dot(prev_dir.cross(dir)) <= 0.0f; - // whether the angle between adjacent segments is greater than 45 degrees - const bool is_sharp = cos_dir < 0.7071068f; - - bool right_displaced = false; - bool left_displaced = false; - - if (!is_sharp && can_displace) { - if (is_right_turn) - left_displaced = true; - else - right_displaced = true; - } - - // triangles outer corner cap - if (is_right_turn) { - if (left_displaced) - // dummy triangles - append_dummy_cap(indices, vbuffer_size); - else { - store_triangle(indices, vbuffer_size - 4, vbuffer_size + 1, vbuffer_size - 1); - store_triangle(indices, vbuffer_size + 1, vbuffer_size - 2, vbuffer_size - 1); - } - } - else { - if (right_displaced) - // dummy triangles - append_dummy_cap(indices, vbuffer_size); - else { - store_triangle(indices, vbuffer_size - 4, vbuffer_size - 3, vbuffer_size + 0); - store_triangle(indices, vbuffer_size - 3, vbuffer_size - 2, vbuffer_size + 0); - } - } - - // stem triangles - append_stem_triangles(indices, non_first_seg_v_offsets); - - vbuffer_size += 6; - } - - if (next != nullptr && (curr.type != next->type || !last_path.matches(*next, account_for_volumetric_rate))) - // ending cap triangles - append_ending_cap_triangles(indices, is_first_segment ? first_seg_v_offsets : non_first_seg_v_offsets); - - last_path.sub_paths.back().last = { ibuffer_id, indices.size() - 1, move_id, curr.position }; - prev_dir = dir; - prev_up = up; - sq_prev_length = sq_length; - }; - - // format data into the buffers to be rendered as instanced model - auto add_model_instance = [](const GCodeProcessorResult::MoveVertex& curr, InstanceBuffer& instances, InstanceIdBuffer& instances_ids, size_t move_id) { - // append position - instances.push_back(curr.position.x()); - instances.push_back(curr.position.y()); - instances.push_back(curr.position.z()); - // append width - instances.push_back(curr.width); - // append height - instances.push_back(curr.height); - - // append id - instances_ids.push_back(move_id); - }; - - // format data into the buffers to be rendered as batched model - auto add_vertices_as_model_batch = [](const GCodeProcessorResult::MoveVertex& curr, const GLModel::Geometry& data, VertexBuffer& vertices, InstanceBuffer& instances, InstanceIdBuffer& instances_ids, size_t move_id) { - const double width = static_cast(1.5f * curr.width); - const double height = static_cast(1.5f * curr.height); - - const Transform3d trafo = Geometry::translation_transform((curr.position - 0.5f * curr.height * Vec3f::UnitZ()).cast()) * - Geometry::scale_transform({ width, width, height }); - const Eigen::Matrix normal_matrix = trafo.matrix().template block<3, 3>(0, 0).inverse().transpose(); - - // append vertices - const size_t vertices_count = data.vertices_count(); - for (size_t i = 0; i < vertices_count; ++i) { - // append position - const Vec3d position = trafo * data.extract_position_3(i).cast(); - vertices.push_back(float(position.x())); - vertices.push_back(float(position.y())); - vertices.push_back(float(position.z())); - - // append normal - const Vec3d normal = normal_matrix * data.extract_normal_3(i).cast(); - vertices.push_back(float(normal.x())); - vertices.push_back(float(normal.y())); - vertices.push_back(float(normal.z())); - } - - // append instance position - instances.push_back(curr.position.x()); - instances.push_back(curr.position.y()); - instances.push_back(curr.position.z()); - // append instance id - instances_ids.push_back(move_id); - }; - - auto add_indices_as_model_batch = [](const GLModel::Geometry& data, IndexBuffer& indices, IBufferType base_index) { - const size_t indices_count = data.indices_count(); - for (size_t i = 0; i < indices_count; ++i) { - indices.push_back(static_cast(data.extract_index(i) + base_index)); - } - }; - -#if ENABLE_GCODE_VIEWER_STATISTICS - auto start_time = std::chrono::high_resolution_clock::now(); - m_statistics.results_size = SLIC3R_STDVEC_MEMSIZE(gcode_result.moves, GCodeProcessorResult::MoveVertex); - m_statistics.results_time = gcode_result.time; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - m_max_bounding_box.reset(); - - m_moves_count = gcode_result.moves.size(); - if (m_moves_count == 0) - return; - - m_extruders_count = gcode_result.extruders_count; - - unsigned int progress_count = 0; - static const unsigned int progress_threshold = 1000; - wxProgressDialog* progress_dialog = wxGetApp().is_gcode_viewer() ? - new wxProgressDialog(_L("Generating toolpaths"), "...", - 100, wxGetApp().mainframe, wxPD_AUTO_HIDE | wxPD_APP_MODAL) : nullptr; - - wxBusyCursor busy; - - // extract approximate paths bounding box from result - for (const GCodeProcessorResult::MoveVertex& move : gcode_result.moves) { - if (wxGetApp().is_gcode_viewer()) - // for the gcode viewer we need to take in account all moves to correctly size the printbed - m_paths_bounding_box.merge(move.position.cast()); - else { - if (move.type == EMoveType::Extrude && move.extrusion_role != GCodeExtrusionRole::Custom && move.width != 0.0f && move.height != 0.0f) - m_paths_bounding_box.merge(move.position.cast()); - } - } - - if (wxGetApp().is_editor()) - m_contained_in_bed = wxGetApp().plater()->build_volume().all_paths_inside(gcode_result, m_paths_bounding_box); - - m_cog.reset(); - - m_sequential_view.gcode_ids.clear(); - for (size_t i = 0; i < gcode_result.moves.size(); ++i) { - const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i]; - if (move.type != EMoveType::Seam) - m_sequential_view.gcode_ids.push_back(move.gcode_id); - } - - bool account_for_volumetric_rate = m_view_type == EViewType::VolumetricRate; - - std::vector vertices(m_buffers.size()); - std::vector indices(m_buffers.size()); - std::vector instances(m_buffers.size()); - std::vector instances_ids(m_buffers.size()); - std::vector instances_offsets(m_buffers.size()); - std::vector options_zs; - - std::vector biased_seams_ids; - - // toolpaths data -> extract vertices from result - for (size_t i = 0; i < m_moves_count; ++i) { - const GCodeProcessorResult::MoveVertex& curr = gcode_result.moves[i]; - if (curr.type == EMoveType::Seam) - biased_seams_ids.push_back(i - biased_seams_ids.size() - 1); - - const size_t move_id = i - biased_seams_ids.size(); - - // skip first vertex - if (i == 0) - continue; - - const GCodeProcessorResult::MoveVertex& prev = gcode_result.moves[i - 1]; - - if (curr.type == EMoveType::Extrude && - curr.extrusion_role != GCodeExtrusionRole::Skirt && - curr.extrusion_role != GCodeExtrusionRole::SupportMaterial && - curr.extrusion_role != GCodeExtrusionRole::SupportMaterialInterface && - curr.extrusion_role != GCodeExtrusionRole::WipeTower && - curr.extrusion_role != GCodeExtrusionRole::Custom) { - const Vec3d curr_pos = curr.position.cast(); - const Vec3d prev_pos = prev.position.cast(); - m_cog.add_segment(curr_pos, prev_pos, curr.mm3_per_mm * (curr_pos - prev_pos).norm()); - } - - // update progress dialog - ++progress_count; - if (progress_dialog != nullptr && progress_count % progress_threshold == 0) { - progress_dialog->Update(int(100.0f * float(i) / (2.0f * float(m_moves_count))), - _L("Generating vertex buffer") + ": " + wxNumberFormatter::ToString(100.0 * double(i) / double(m_moves_count), 0, wxNumberFormatter::Style_None) + "%"); - progress_dialog->Fit(); - progress_count = 0; - } - - const unsigned char id = buffer_id(curr.type); - TBuffer& t_buffer = m_buffers[id]; - MultiVertexBuffer& v_multibuffer = vertices[id]; - InstanceBuffer& inst_buffer = instances[id]; - InstanceIdBuffer& inst_id_buffer = instances_ids[id]; - InstancesOffsets& inst_offsets = instances_offsets[id]; - - // ensure there is at least one vertex buffer - if (v_multibuffer.empty()) - v_multibuffer.push_back(VertexBuffer()); - - // if adding the vertices for the current segment exceeds the threshold size of the current vertex buffer - // add another vertex buffer - size_t vertices_size_to_add = (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) ? t_buffer.model.data.vertices_size_bytes() : t_buffer.max_vertices_per_segment_size_bytes(); - if (v_multibuffer.back().size() * sizeof(float) > t_buffer.vertices.max_size_bytes() - vertices_size_to_add) { - v_multibuffer.push_back(VertexBuffer()); - if (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle) { - Path& last_path = t_buffer.paths.back(); - if (prev.type == curr.type && last_path.matches(curr, account_for_volumetric_rate)) - last_path.add_sub_path(prev, static_cast(v_multibuffer.size()) - 1, 0, move_id - 1); - } - } - - VertexBuffer& v_buffer = v_multibuffer.back(); - - switch (t_buffer.render_primitive_type) - { - case TBuffer::ERenderPrimitiveType::Line: { add_vertices_as_line(prev, curr, v_buffer); break; } - case TBuffer::ERenderPrimitiveType::Triangle: { add_vertices_as_solid(prev, curr, t_buffer, static_cast(v_multibuffer.size()) - 1, v_buffer, move_id, account_for_volumetric_rate); break; } - case TBuffer::ERenderPrimitiveType::InstancedModel: - { - add_model_instance(curr, inst_buffer, inst_id_buffer, move_id); - inst_offsets.push_back(prev.position - curr.position); -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.instances_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - break; - } - case TBuffer::ERenderPrimitiveType::BatchedModel: - { - add_vertices_as_model_batch(curr, t_buffer.model.data, v_buffer, inst_buffer, inst_id_buffer, move_id); - inst_offsets.push_back(prev.position - curr.position); -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.batched_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - break; - } - } - - // collect options zs for later use - if (curr.type == EMoveType::Pause_Print || curr.type == EMoveType::Custom_GCode) { - const float* const last_z = options_zs.empty() ? nullptr : &options_zs.back(); - if (last_z == nullptr || curr.position[2] < *last_z - EPSILON || *last_z + EPSILON < curr.position[2]) - options_zs.emplace_back(curr.position[2]); - } - } - - // smooth toolpaths corners for the given TBuffer using triangles - auto smooth_triangle_toolpaths_corners = [&gcode_result, &biased_seams_ids](const TBuffer& t_buffer, MultiVertexBuffer& v_multibuffer) { - auto extract_position_at = [](const VertexBuffer& vertices, size_t offset) { - return Vec3f(vertices[offset + 0], vertices[offset + 1], vertices[offset + 2]); - }; - auto update_position_at = [](VertexBuffer& vertices, size_t offset, const Vec3f& position) { - vertices[offset + 0] = position.x(); - vertices[offset + 1] = position.y(); - vertices[offset + 2] = position.z(); - }; - auto match_right_vertices = [&](const Path::Sub_Path& prev_sub_path, const Path::Sub_Path& next_sub_path, - size_t curr_s_id, size_t vertex_size_floats, const Vec3f& displacement_vec) { - if (&prev_sub_path == &next_sub_path) { // previous and next segment are both contained into to the same vertex buffer - VertexBuffer& vbuffer = v_multibuffer[prev_sub_path.first.b_id]; - // offset into the vertex buffer of the next segment 1st vertex - const size_t next_1st_offset = (prev_sub_path.last.s_id - curr_s_id) * 6 * vertex_size_floats; - // offset into the vertex buffer of the right vertex of the previous segment - const size_t prev_right_offset = prev_sub_path.last.i_id - next_1st_offset - 3 * vertex_size_floats; - // new position of the right vertices - const Vec3f shared_vertex = extract_position_at(vbuffer, prev_right_offset) + displacement_vec; - // update previous segment - update_position_at(vbuffer, prev_right_offset, shared_vertex); - // offset into the vertex buffer of the right vertex of the next segment - const size_t next_right_offset = next_sub_path.last.i_id - next_1st_offset; - // update next segment - update_position_at(vbuffer, next_right_offset, shared_vertex); - } - else { // previous and next segment are contained into different vertex buffers - VertexBuffer& prev_vbuffer = v_multibuffer[prev_sub_path.first.b_id]; - VertexBuffer& next_vbuffer = v_multibuffer[next_sub_path.first.b_id]; - // offset into the previous vertex buffer of the right vertex of the previous segment - const size_t prev_right_offset = prev_sub_path.last.i_id - 3 * vertex_size_floats; - // new position of the right vertices - const Vec3f shared_vertex = extract_position_at(prev_vbuffer, prev_right_offset) + displacement_vec; - // update previous segment - update_position_at(prev_vbuffer, prev_right_offset, shared_vertex); - // offset into the next vertex buffer of the right vertex of the next segment - const size_t next_right_offset = next_sub_path.first.i_id + 1 * vertex_size_floats; - // update next segment - update_position_at(next_vbuffer, next_right_offset, shared_vertex); - } - }; - auto match_left_vertices = [&](const Path::Sub_Path& prev_sub_path, const Path::Sub_Path& next_sub_path, - size_t curr_s_id, size_t vertex_size_floats, const Vec3f& displacement_vec) { - if (&prev_sub_path == &next_sub_path) { // previous and next segment are both contained into to the same vertex buffer - VertexBuffer& vbuffer = v_multibuffer[prev_sub_path.first.b_id]; - // offset into the vertex buffer of the next segment 1st vertex - const size_t next_1st_offset = (prev_sub_path.last.s_id - curr_s_id) * 6 * vertex_size_floats; - // offset into the vertex buffer of the left vertex of the previous segment - const size_t prev_left_offset = prev_sub_path.last.i_id - next_1st_offset - 1 * vertex_size_floats; - // new position of the left vertices - const Vec3f shared_vertex = extract_position_at(vbuffer, prev_left_offset) + displacement_vec; - // update previous segment - update_position_at(vbuffer, prev_left_offset, shared_vertex); - // offset into the vertex buffer of the left vertex of the next segment - const size_t next_left_offset = next_sub_path.last.i_id - next_1st_offset + 1 * vertex_size_floats; - // update next segment - update_position_at(vbuffer, next_left_offset, shared_vertex); - } - else { // previous and next segment are contained into different vertex buffers - VertexBuffer& prev_vbuffer = v_multibuffer[prev_sub_path.first.b_id]; - VertexBuffer& next_vbuffer = v_multibuffer[next_sub_path.first.b_id]; - // offset into the previous vertex buffer of the left vertex of the previous segment - const size_t prev_left_offset = prev_sub_path.last.i_id - 1 * vertex_size_floats; - // new position of the left vertices - const Vec3f shared_vertex = extract_position_at(prev_vbuffer, prev_left_offset) + displacement_vec; - // update previous segment - update_position_at(prev_vbuffer, prev_left_offset, shared_vertex); - // offset into the next vertex buffer of the left vertex of the next segment - const size_t next_left_offset = next_sub_path.first.i_id + 3 * vertex_size_floats; - // update next segment - update_position_at(next_vbuffer, next_left_offset, shared_vertex); - } - }; - - auto extract_move_id = [&biased_seams_ids](size_t id) { - size_t new_id = size_t(-1); - auto it = std::lower_bound(biased_seams_ids.begin(), biased_seams_ids.end(), id); - if (it == biased_seams_ids.end()) - new_id = id + biased_seams_ids.size(); - else { - if (it == biased_seams_ids.begin() && *it < id) - new_id = id; - else if (it != biased_seams_ids.begin()) - new_id = id + std::distance(biased_seams_ids.begin(), it); - } - return (new_id == size_t(-1)) ? id : new_id; - }; - - const size_t vertex_size_floats = t_buffer.vertices.vertex_size_floats(); - for (const Path& path : t_buffer.paths) { - // the two segments of the path sharing the current vertex may belong - // to two different vertex buffers - size_t prev_sub_path_id = 0; - size_t next_sub_path_id = 0; - const size_t path_vertices_count = path.vertices_count(); - const float half_width = 0.5f * path.width; - for (size_t j = 1; j < path_vertices_count - 1; ++j) { - const size_t curr_s_id = path.sub_paths.front().first.s_id + j; - const size_t move_id = extract_move_id(curr_s_id); - const Vec3f& prev = gcode_result.moves[move_id - 1].position; - const Vec3f& curr = gcode_result.moves[move_id].position; - const Vec3f& next = gcode_result.moves[move_id + 1].position; - - // select the subpaths which contains the previous/next segments - if (!path.sub_paths[prev_sub_path_id].contains(curr_s_id)) - ++prev_sub_path_id; - if (!path.sub_paths[next_sub_path_id].contains(curr_s_id + 1)) - ++next_sub_path_id; - const Path::Sub_Path& prev_sub_path = path.sub_paths[prev_sub_path_id]; - const Path::Sub_Path& next_sub_path = path.sub_paths[next_sub_path_id]; - - const Vec3f prev_dir = (curr - prev).normalized(); - const Vec3f prev_right = Vec3f(prev_dir.y(), -prev_dir.x(), 0.0f).normalized(); - const Vec3f prev_up = prev_right.cross(prev_dir); - - const Vec3f next_dir = (next - curr).normalized(); - - const bool is_right_turn = prev_up.dot(prev_dir.cross(next_dir)) <= 0.0f; - const float cos_dir = prev_dir.dot(next_dir); - // whether the angle between adjacent segments is greater than 45 degrees - const bool is_sharp = cos_dir < 0.7071068f; - - float displacement = 0.0f; - if (cos_dir > -0.9998477f) { - // if the angle between adjacent segments is smaller than 179 degrees - const Vec3f med_dir = (prev_dir + next_dir).normalized(); - displacement = half_width * ::tan(::acos(std::clamp(next_dir.dot(med_dir), -1.0f, 1.0f))); - } - - const float sq_prev_length = (curr - prev).squaredNorm(); - const float sq_next_length = (next - curr).squaredNorm(); - const float sq_displacement = sqr(displacement); - const bool can_displace = displacement > 0.0f && sq_displacement < sq_prev_length && sq_displacement < sq_next_length; - - if (can_displace) { - // displacement to apply to the vertices to match - const Vec3f displacement_vec = displacement * prev_dir; - // matches inner corner vertices - if (is_right_turn) - match_right_vertices(prev_sub_path, next_sub_path, curr_s_id, vertex_size_floats, -displacement_vec); - else - match_left_vertices(prev_sub_path, next_sub_path, curr_s_id, vertex_size_floats, -displacement_vec); - - if (!is_sharp) { - // matches outer corner vertices - if (is_right_turn) - match_left_vertices(prev_sub_path, next_sub_path, curr_s_id, vertex_size_floats, displacement_vec); - else - match_right_vertices(prev_sub_path, next_sub_path, curr_s_id, vertex_size_floats, displacement_vec); - } - } - } - } - }; - -#if ENABLE_GCODE_VIEWER_STATISTICS - auto load_vertices_time = std::chrono::high_resolution_clock::now(); - m_statistics.load_vertices = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - // smooth toolpaths corners for TBuffers using triangles - for (size_t i = 0; i < m_buffers.size(); ++i) { - const TBuffer& t_buffer = m_buffers[i]; - if (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle) - smooth_triangle_toolpaths_corners(t_buffer, vertices[i]); - } - - // dismiss, no more needed - std::vector().swap(biased_seams_ids); - - for (MultiVertexBuffer& v_multibuffer : vertices) { - for (VertexBuffer& v_buffer : v_multibuffer) { - v_buffer.shrink_to_fit(); - } - } - - // move the wipe toolpaths half height up to render them on proper position - MultiVertexBuffer& wipe_vertices = vertices[buffer_id(EMoveType::Wipe)]; - for (VertexBuffer& v_buffer : wipe_vertices) { - for (size_t i = 2; i < v_buffer.size(); i += 3) { - v_buffer[i] += 0.5f * GCodeProcessor::Wipe_Height; - } - } - - // send vertices data to gpu, where needed - for (size_t i = 0; i < m_buffers.size(); ++i) { - TBuffer& t_buffer = m_buffers[i]; - if (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { - const InstanceBuffer& inst_buffer = instances[i]; - if (!inst_buffer.empty()) { - t_buffer.model.instances.buffer = inst_buffer; - t_buffer.model.instances.s_ids = instances_ids[i]; - t_buffer.model.instances.offsets = instances_offsets[i]; - } - } - else { - if (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { - const InstanceBuffer& inst_buffer = instances[i]; - if (!inst_buffer.empty()) { - t_buffer.model.instances.buffer = inst_buffer; - t_buffer.model.instances.s_ids = instances_ids[i]; - t_buffer.model.instances.offsets = instances_offsets[i]; - } - } - const MultiVertexBuffer& v_multibuffer = vertices[i]; - for (const VertexBuffer& v_buffer : v_multibuffer) { - const size_t size_elements = v_buffer.size(); - const size_t size_bytes = size_elements * sizeof(float); - const size_t vertices_count = size_elements / t_buffer.vertices.vertex_size_floats(); - t_buffer.vertices.count += vertices_count; - -#if ENABLE_GCODE_VIEWER_STATISTICS - m_statistics.total_vertices_gpu_size += static_cast(size_bytes); - m_statistics.max_vbuffer_gpu_size = std::max(m_statistics.max_vbuffer_gpu_size, static_cast(size_bytes)); - ++m_statistics.vbuffers_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - -#if ENABLE_GL_CORE_PROFILE - GLuint vao_id = 0; - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) { - glsafe(::glGenVertexArrays(1, &vao_id)); - glsafe(::glBindVertexArray(vao_id)); - } -#endif // ENABLE_GL_CORE_PROFILE - - GLuint vbo_id = 0; - glsafe(::glGenBuffers(1, &vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, size_bytes, v_buffer.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) { - glsafe(::glBindVertexArray(0)); - t_buffer.vertices.vaos.push_back(static_cast(vao_id)); - } -#endif // ENABLE_GL_CORE_PROFILE - t_buffer.vertices.vbos.push_back(static_cast(vbo_id)); - t_buffer.vertices.sizes.push_back(size_bytes); - } - } - } - -#if ENABLE_GCODE_VIEWER_STATISTICS - auto smooth_vertices_time = std::chrono::high_resolution_clock::now(); - m_statistics.smooth_vertices = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - load_vertices_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - log_memory_usage("Loaded G-code generated vertex buffers ", vertices, indices); - - // dismiss vertices data, no more needed - std::vector().swap(vertices); - std::vector().swap(instances); - std::vector().swap(instances_ids); - - // toolpaths data -> extract indices from result - // paths may have been filled while extracting vertices, - // so reset them, they will be filled again while extracting indices - for (TBuffer& buffer : m_buffers) { - buffer.paths.clear(); - } - - // variable used to keep track of the current vertex buffers index and size - using CurrVertexBuffer = std::pair; - std::vector curr_vertex_buffers(m_buffers.size(), { 0, 0 }); - -#if ENABLE_GL_CORE_PROFILE - // variable used to keep track of the vertex buffers ids - using VIndexList = std::vector; - std::vector vao_indices(m_buffers.size()); - std::vector vbo_indices(m_buffers.size()); -#else - // variable used to keep track of the vertex buffers ids - using VboIndexList = std::vector; - std::vector vbo_indices(m_buffers.size()); -#endif // ENABLE_GL_CORE_PROFILE - - size_t seams_count = 0; - - for (size_t i = 0; i < m_moves_count; ++i) { - const GCodeProcessorResult::MoveVertex& curr = gcode_result.moves[i]; - if (curr.type == EMoveType::Seam) - ++seams_count; - - const size_t move_id = i - seams_count; - - // skip first vertex - if (i == 0) - continue; - - const GCodeProcessorResult::MoveVertex& prev = gcode_result.moves[i - 1]; - const GCodeProcessorResult::MoveVertex* next = nullptr; - if (i < m_moves_count - 1) - next = &gcode_result.moves[i + 1]; - - ++progress_count; - if (progress_dialog != nullptr && progress_count % progress_threshold == 0) { - progress_dialog->Update(int(100.0f * float(m_moves_count + i) / (2.0f * float(m_moves_count))), - _L("Generating index buffers") + ": " + wxNumberFormatter::ToString(100.0 * double(i) / double(m_moves_count), 0, wxNumberFormatter::Style_None) + "%"); - progress_dialog->Fit(); - progress_count = 0; - } - - const unsigned char id = buffer_id(curr.type); - TBuffer& t_buffer = m_buffers[id]; - MultiIndexBuffer& i_multibuffer = indices[id]; - CurrVertexBuffer& curr_vertex_buffer = curr_vertex_buffers[id]; -#if ENABLE_GL_CORE_PROFILE - VIndexList& vao_index_list = vao_indices[id]; - VIndexList& vbo_index_list = vbo_indices[id]; -#else - VboIndexList& vbo_index_list = vbo_indices[id]; -#endif // ENABLE_GL_CORE_PROFILE - - // ensure there is at least one index buffer - if (i_multibuffer.empty()) { - i_multibuffer.push_back(IndexBuffer()); -#if ENABLE_GL_CORE_PROFILE - if (!t_buffer.vertices.vaos.empty() && OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]); - - if (!t_buffer.vertices.vbos.empty()) - vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]); -#else - if (!t_buffer.vertices.vbos.empty()) - vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]); -#endif // ENABLE_GL_CORE_PROFILE - } - - // if adding the indices for the current segment exceeds the threshold size of the current index buffer - // create another index buffer - size_t indiced_size_to_add = (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) ? t_buffer.model.data.indices_size_bytes() : t_buffer.max_indices_per_segment_size_bytes(); - if (i_multibuffer.back().size() * sizeof(IBufferType) >= IBUFFER_THRESHOLD_BYTES - indiced_size_to_add) { - i_multibuffer.push_back(IndexBuffer()); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]); -#endif // ENABLE_GL_CORE_PROFILE - vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]); - if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) { - Path& last_path = t_buffer.paths.back(); - last_path.add_sub_path(prev, static_cast(i_multibuffer.size()) - 1, 0, move_id - 1); - } - } - - // if adding the vertices for the current segment exceeds the threshold size of the current vertex buffer - // create another index buffer - size_t vertices_size_to_add = (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) ? t_buffer.model.data.vertices_size_bytes() : t_buffer.max_vertices_per_segment_size_bytes(); - if (curr_vertex_buffer.second * t_buffer.vertices.vertex_size_bytes() > t_buffer.vertices.max_size_bytes() - vertices_size_to_add) { - i_multibuffer.push_back(IndexBuffer()); - - ++curr_vertex_buffer.first; - curr_vertex_buffer.second = 0; -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]); -#endif // ENABLE_GL_CORE_PROFILE - vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]); - - if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) { - Path& last_path = t_buffer.paths.back(); - last_path.add_sub_path(prev, static_cast(i_multibuffer.size()) - 1, 0, move_id - 1); - } - } - - IndexBuffer& i_buffer = i_multibuffer.back(); - - switch (t_buffer.render_primitive_type) - { - case TBuffer::ERenderPrimitiveType::Line: { - add_indices_as_line(prev, curr, t_buffer, static_cast(i_multibuffer.size()) - 1, i_buffer, move_id, account_for_volumetric_rate); - curr_vertex_buffer.second += t_buffer.max_vertices_per_segment(); - break; - } - case TBuffer::ERenderPrimitiveType::Triangle: { - add_indices_as_solid(prev, curr, next, t_buffer, curr_vertex_buffer.second, static_cast(i_multibuffer.size()) - 1, i_buffer, move_id, account_for_volumetric_rate); - break; - } - case TBuffer::ERenderPrimitiveType::BatchedModel: { - add_indices_as_model_batch(t_buffer.model.data, i_buffer, curr_vertex_buffer.second); - curr_vertex_buffer.second += t_buffer.model.data.vertices_count(); - break; - } - default: { break; } - } - } - - for (MultiIndexBuffer& i_multibuffer : indices) { - for (IndexBuffer& i_buffer : i_multibuffer) { - i_buffer.shrink_to_fit(); - } - } - - // toolpaths data -> send indices data to gpu - for (size_t i = 0; i < m_buffers.size(); ++i) { - TBuffer& t_buffer = m_buffers[i]; - if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::InstancedModel) { - const MultiIndexBuffer& i_multibuffer = indices[i]; - for (const IndexBuffer& i_buffer : i_multibuffer) { - const size_t size_elements = i_buffer.size(); - const size_t size_bytes = size_elements * sizeof(IBufferType); - - // stores index buffer informations into TBuffer - t_buffer.indices.push_back(IBuffer()); - IBuffer& ibuf = t_buffer.indices.back(); - ibuf.count = size_elements; -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - ibuf.vao = vao_indices[i][t_buffer.indices.size() - 1]; -#endif // ENABLE_GL_CORE_PROFILE - ibuf.vbo = vbo_indices[i][t_buffer.indices.size() - 1]; - -#if ENABLE_GCODE_VIEWER_STATISTICS - m_statistics.total_indices_gpu_size += static_cast(size_bytes); - m_statistics.max_ibuffer_gpu_size = std::max(m_statistics.max_ibuffer_gpu_size, static_cast(size_bytes)); - ++m_statistics.ibuffers_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - glsafe(::glGenBuffers(1, &ibuf.ibo)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuf.ibo)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, size_bytes, i_buffer.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - } - } - - if (progress_dialog != nullptr) { - progress_dialog->Update(100, ""); - progress_dialog->Fit(); - } - -#if ENABLE_GCODE_VIEWER_STATISTICS - for (const TBuffer& buffer : m_buffers) { - m_statistics.paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.paths, Path); - } - - auto update_segments_count = [&](EMoveType type, int64_t& count) { - unsigned int id = buffer_id(type); - const MultiIndexBuffer& buffers = indices[id]; - int64_t indices_count = 0; - for (const IndexBuffer& buffer : buffers) { - indices_count += buffer.size(); - } - const TBuffer& t_buffer = m_buffers[id]; - if (t_buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle) - indices_count -= static_cast(12 * t_buffer.paths.size()); // remove the starting + ending caps = 4 triangles - - count += indices_count / t_buffer.indices_per_segment(); - }; - - update_segments_count(EMoveType::Travel, m_statistics.travel_segments_count); - update_segments_count(EMoveType::Wipe, m_statistics.wipe_segments_count); - update_segments_count(EMoveType::Extrude, m_statistics.extrude_segments_count); - - m_statistics.load_indices = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - smooth_vertices_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - log_memory_usage("Loaded G-code generated indices buffers ", vertices, indices); - - // dismiss indices data, no more needed - std::vector().swap(indices); - - // layers zs / roles / extruder ids -> extract from result - size_t last_travel_s_id = 0; - size_t first_travel_s_id = 0; - seams_count = 0; - for (size_t i = 0; i < m_moves_count; ++i) { - const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i]; - if (move.type == EMoveType::Seam) - ++seams_count; - - const size_t move_id = i - seams_count; - - if (move.type == EMoveType::Extrude) { - // layers zs/ranges - const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back(); - const double z = static_cast(move.position.z()); - if (move.extrusion_role != GCodeExtrusionRole::Custom && - (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z)) { - // start a new layer - const size_t start_it = (m_layers.empty() && first_travel_s_id != 0) ? first_travel_s_id : last_travel_s_id; - m_layers.append(z, { start_it, move_id }); - } - else if (!m_layers.empty() && !move.internal_only) - // update last layer - m_layers.get_ranges().back().last = move_id; - - // extruder ids - m_extruder_ids.emplace_back(move.extruder_id); - // roles - if (i > 0) - m_roles.emplace_back(move.extrusion_role); - } - else if (move.type == EMoveType::Travel) { - if (move_id - last_travel_s_id > 1 && !m_layers.empty()) - m_layers.get_ranges().back().last = move_id; - else if (m_layers.empty() && first_travel_s_id == 0) - first_travel_s_id = move_id; - last_travel_s_id = move_id; - } - } - - // roles -> remove duplicates - sort_remove_duplicates(m_roles); - m_roles.shrink_to_fit(); - - // extruder ids -> remove duplicates - sort_remove_duplicates(m_extruder_ids); - m_extruder_ids.shrink_to_fit(); - - // replace layers for spiral vase mode - if (!gcode_result.spiral_vase_layers.empty()) { - m_layers.reset(); - for (const auto& layer : gcode_result.spiral_vase_layers) { - m_layers.append(layer.first, { layer.second.first, layer.second.second }); - } - } - - // set layers z range - if (!m_layers.empty()) - m_layers_z_range = { 0, static_cast(m_layers.size() - 1) }; - - // change color of paths whose layer contains option points - if (!options_zs.empty()) { - TBuffer& extrude_buffer = m_buffers[buffer_id(EMoveType::Extrude)]; - for (Path& path : extrude_buffer.paths) { - const float z = path.sub_paths.front().first.position.z(); - if (std::find_if(options_zs.begin(), options_zs.end(), [z](float f) { return f - EPSILON <= z && z <= f + EPSILON; }) != options_zs.end()) - path.cp_color_id = 255 - path.cp_color_id; - } - } - -#if ENABLE_GCODE_VIEWER_STATISTICS - m_statistics.load_time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - if (progress_dialog != nullptr) - progress_dialog->Destroy(); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - void GCodeViewer::load_shells(const Print& print) { m_shells.volumes.clear(); @@ -3538,11 +1675,7 @@ void GCodeViewer::load_wipetower_shell(const Print& print) // adds wipe tower's volume const double max_z = print.objects()[0]->model_object()->get_model()->max_z(); const PrintConfig& config = print.config(); -#if ENABLE_NEW_GCODE_VIEWER const size_t extruders_count = get_extruders_count(); -#else - const size_t extruders_count = config.nozzle_diameter.size(); -#endif // ENABLE_NEW_GCODE_VIEWER if (extruders_count > 1 && config.wipe_tower && !config.complete_objects) { const WipeTowerData& wipe_tower_data = print.wipe_tower_data(extruders_count); const float depth = wipe_tower_data.depth; @@ -3562,590 +1695,6 @@ void GCodeViewer::load_wipetower_shell(const Print& print) } } -#if !ENABLE_NEW_GCODE_VIEWER -void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const -{ -#if ENABLE_GCODE_VIEWER_STATISTICS - auto start_time = std::chrono::high_resolution_clock::now(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - auto extrusion_color = [this](const Path& path) { - ColorRGBA color; - switch (m_view_type) - { - case EViewType::FeatureType: { color = Extrusion_Role_Colors[static_cast(path.role)]; break; } - case EViewType::Height: { color = m_extrusions.ranges.height.get_color_at(path.height); break; } - case EViewType::Width: { color = m_extrusions.ranges.width.get_color_at(path.width); break; } - case EViewType::Feedrate: { color = m_extrusions.ranges.feedrate.get_color_at(path.feedrate); break; } - case EViewType::FanSpeed: { color = m_extrusions.ranges.fan_speed.get_color_at(path.fan_speed); break; } - case EViewType::Temperature: { color = m_extrusions.ranges.temperature.get_color_at(path.temperature); break; } - case EViewType::LayerTimeLinear: - case EViewType::LayerTimeLogarithmic: { - if (!m_layers_times.empty() && m_layers.size() == m_layers_times.front().size()) { - const Path::Sub_Path& sub_path = path.sub_paths.front(); - double z = static_cast(sub_path.first.position.z()); - const std::vector& zs = m_layers.get_zs(); - const std::vector& ranges = m_layers.get_ranges(); - size_t time_mode_id = static_cast(m_time_estimate_mode); - for (size_t i = 0; i < zs.size(); ++i) { - if (std::abs(zs[i] - z) < EPSILON) { - if (ranges[i].contains(sub_path.first.s_id)) { - color = m_extrusions.ranges.layer_time[time_mode_id].get_color_at(m_layers_times[time_mode_id][i], - (m_view_type == EViewType::LayerTimeLinear) ? Extrusions::Range::EType::Linear : Extrusions::Range::EType::Logarithmic); - break; - } - } - } - } - break; - } - case EViewType::VolumetricRate: { color = m_extrusions.ranges.volumetric_rate.get_color_at(path.volumetric_rate); break; } - case EViewType::Tool: { color = m_tool_colors[path.extruder_id]; break; } - case EViewType::ColorPrint: { - if (path.cp_color_id >= static_cast(m_tool_colors.size())) - color = ColorRGBA::GRAY(); - else - color = m_tool_colors[path.cp_color_id]; - - break; - } - default: { color = ColorRGBA::WHITE(); break; } - } - - return color; - }; - - auto travel_color = [](const Path& path) { - return (path.delta_extruder < 0.0f) ? Travel_Colors[2] /* Retract */ : - ((path.delta_extruder > 0.0f) ? Travel_Colors[1] /* Extrude */ : - Travel_Colors[0] /* Move */); - }; - - auto is_in_layers_range = [this](const Path& path, size_t min_id, size_t max_id) { - auto in_layers_range = [this, min_id, max_id](size_t id) { - return m_layers.get_range_at(min_id).first <= id && id <= m_layers.get_range_at(max_id).last; - }; - - return in_layers_range(path.sub_paths.front().first.s_id) && in_layers_range(path.sub_paths.back().last.s_id); - }; - - auto is_travel_in_layers_range = [this](size_t path_id, size_t min_id, size_t max_id) { - const TBuffer& buffer = m_buffers[buffer_id(EMoveType::Travel)]; - if (path_id >= buffer.paths.size()) - return false; - - Path path = buffer.paths[path_id]; - size_t first = path_id; - size_t last = path_id; - - // check adjacent paths - while (first > 0) { - const Path& ref_path = buffer.paths[first - 1]; - if (!path.sub_paths.front().first.position.isApprox(ref_path.sub_paths.back().last.position) || - path.role != ref_path.role) - break; - - path.sub_paths.front().first = ref_path.sub_paths.front().first; - --first; - } - while (last < buffer.paths.size() - 1) { - const Path& ref_path = buffer.paths[last + 1]; - if (!path.sub_paths.back().last.position.isApprox(ref_path.sub_paths.front().first.position) || - path.role != ref_path.role) - break; - - path.sub_paths.back().last = ref_path.sub_paths.back().last; - ++last; - } - - const size_t min_s_id = m_layers.get_range_at(min_id).first; - const size_t max_s_id = m_layers.get_range_at(max_id).last; - - const bool top_layer_shown = max_id == m_layers.size() - 1; - - return (min_s_id <= path.sub_paths.front().first.s_id && path.sub_paths.front().first.s_id <= max_s_id) || // the leading vertex is contained - (min_s_id <= path.sub_paths.back().last.s_id && path.sub_paths.back().last.s_id <= max_s_id) || // the trailing vertex is contained - (top_layer_shown && max_s_id < path.sub_paths.front().first.s_id); // the leading vertex is above the top layer and the top layer is shown - }; - -#if ENABLE_GCODE_VIEWER_STATISTICS - Statistics* statistics = const_cast(&m_statistics); - statistics->render_paths_size = 0; - statistics->models_instances_size = 0; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - const bool top_layer_only = get_app_config()->get_bool("seq_top_layer_only"); - - SequentialView::Endpoints global_endpoints = { m_moves_count , 0 }; - SequentialView::Endpoints top_layer_endpoints = global_endpoints; - SequentialView* sequential_view = const_cast(&m_sequential_view); - if (top_layer_only || !keep_sequential_current_first) sequential_view->current.first = 0; - if (!keep_sequential_current_last) sequential_view->current.last = m_moves_count; - - // first pass: collect visible paths and update sequential view data - std::vector> paths; - for (size_t b = 0; b < m_buffers.size(); ++b) { - TBuffer& buffer = const_cast(m_buffers[b]); - // reset render paths - buffer.render_paths.clear(); - - if (!buffer.visible) - continue; - - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel || - buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { - for (size_t id : buffer.model.instances.s_ids) { - if (id < m_layers.get_range_at(m_layers_z_range[0]).first || m_layers.get_range_at(m_layers_z_range[1]).last < id) - continue; - - global_endpoints.first = std::min(global_endpoints.first, id); - global_endpoints.last = std::max(global_endpoints.last, id); - - if (top_layer_only) { - if (id < m_layers.get_range_at(m_layers_z_range[1]).first || m_layers.get_range_at(m_layers_z_range[1]).last < id) - continue; - - top_layer_endpoints.first = std::min(top_layer_endpoints.first, id); - top_layer_endpoints.last = std::max(top_layer_endpoints.last, id); - } - } - } - else { - for (size_t i = 0; i < buffer.paths.size(); ++i) { - const Path& path = buffer.paths[i]; - if (path.type == EMoveType::Travel) { - if (!is_travel_in_layers_range(i, m_layers_z_range[0], m_layers_z_range[1])) - continue; - } - else if (!is_in_layers_range(path, m_layers_z_range[0], m_layers_z_range[1])) - continue; - - if (path.type == EMoveType::Extrude && !is_visible(path)) - continue; - - // store valid path - for (size_t j = 0; j < path.sub_paths.size(); ++j) { - paths.push_back({ static_cast(b), path.sub_paths[j].first.b_id, static_cast(i), static_cast(j) }); - } - - global_endpoints.first = std::min(global_endpoints.first, path.sub_paths.front().first.s_id); - global_endpoints.last = std::max(global_endpoints.last, path.sub_paths.back().last.s_id); - - if (top_layer_only) { - if (path.type == EMoveType::Travel) { - if (is_travel_in_layers_range(i, m_layers_z_range[1], m_layers_z_range[1])) { - top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.sub_paths.front().first.s_id); - top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.sub_paths.back().last.s_id); - } - } - else if (is_in_layers_range(path, m_layers_z_range[1], m_layers_z_range[1])) { - top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.sub_paths.front().first.s_id); - top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.sub_paths.back().last.s_id); - } - } - } - } - } - - // update current sequential position - sequential_view->current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(sequential_view->current.first, global_endpoints.first, global_endpoints.last) : global_endpoints.first; - sequential_view->current.last = keep_sequential_current_last ? std::clamp(sequential_view->current.last, global_endpoints.first, global_endpoints.last) : global_endpoints.last; - - // get the world position from the vertex buffer - bool found = false; - for (const TBuffer& buffer : m_buffers) { - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel || - buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { - for (size_t i = 0; i < buffer.model.instances.s_ids.size(); ++i) { - if (buffer.model.instances.s_ids[i] == m_sequential_view.current.last) { - size_t offset = i * buffer.model.instances.instance_size_floats(); - sequential_view->current_position.x() = buffer.model.instances.buffer[offset + 0]; - sequential_view->current_position.y() = buffer.model.instances.buffer[offset + 1]; - sequential_view->current_position.z() = buffer.model.instances.buffer[offset + 2]; - sequential_view->current_offset = buffer.model.instances.offsets[i]; - found = true; - break; - } - } - } - else { - // searches the path containing the current position - for (const Path& path : buffer.paths) { - if (path.contains(m_sequential_view.current.last)) { - const int sub_path_id = path.get_id_of_sub_path_containing(m_sequential_view.current.last); - if (sub_path_id != -1) { - const Path::Sub_Path& sub_path = path.sub_paths[sub_path_id]; - unsigned int offset = static_cast(m_sequential_view.current.last - sub_path.first.s_id); - if (offset > 0) { - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Line) - offset = 2 * offset - 1; - else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle) { - unsigned int indices_count = buffer.indices_per_segment(); - offset = indices_count * (offset - 1) + (indices_count - 2); - if (sub_path_id == 0) - offset += 6; // add 2 triangles for starting cap - } - } - offset += static_cast(sub_path.first.i_id); - - // gets the vertex index from the index buffer on gpu - const IBuffer& i_buffer = buffer.indices[sub_path.first.b_id]; - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); -#if ENABLE_OPENGL_ES - IBufferType index = *static_cast(::glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, - static_cast(offset * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), - GL_MAP_READ_BIT)); - glcheck(); - glsafe(::glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)); -#else - IBufferType index = 0; - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast(offset * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&index))); -#endif // ENABLE_OPENGL_ES - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - // gets the position from the vertices buffer on gpu - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); -#if ENABLE_OPENGL_ES - sequential_view->current_position = *static_cast(::glMapBufferRange(GL_ARRAY_BUFFER, - static_cast(index * buffer.vertices.vertex_size_bytes()), - static_cast(buffer.vertices.position_size_bytes()), GL_MAP_READ_BIT)); - glcheck(); - glsafe(::glUnmapBuffer(GL_ARRAY_BUFFER)); -#else - glsafe(::glGetBufferSubData(GL_ARRAY_BUFFER, static_cast(index * buffer.vertices.vertex_size_bytes()), static_cast(3 * sizeof(float)), static_cast(sequential_view->current_position.data()))); -#endif // ENABLE_OPENGL_ES - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - - sequential_view->current_offset = Vec3f::Zero(); - found = true; - break; - } - } - } - } - - if (found) - break; - } - - // second pass: filter paths by sequential data and collect them by color - RenderPath* render_path = nullptr; - for (const auto& [tbuffer_id, ibuffer_id, path_id, sub_path_id] : paths) { - TBuffer& buffer = const_cast(m_buffers[tbuffer_id]); - const Path& path = buffer.paths[path_id]; - const Path::Sub_Path& sub_path = path.sub_paths[sub_path_id]; - if (m_sequential_view.current.last < sub_path.first.s_id || sub_path.last.s_id < m_sequential_view.current.first) - continue; - - ColorRGBA color; - switch (path.type) - { - case EMoveType::Tool_change: - case EMoveType::Color_change: - case EMoveType::Pause_Print: - case EMoveType::Custom_GCode: - case EMoveType::Retract: - case EMoveType::Unretract: - case EMoveType::Seam: { color = option_color(path.type); break; } - case EMoveType::Extrude: { - if (!top_layer_only || - m_sequential_view.current.last == global_endpoints.last || - is_in_layers_range(path, m_layers_z_range[1], m_layers_z_range[1])) - color = extrusion_color(path); - else - color = Neutral_Color; - - break; - } - case EMoveType::Travel: { - if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_travel_in_layers_range(path_id, m_layers_z_range[1], m_layers_z_range[1])) - color = (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path); - else - color = Neutral_Color; - - break; - } - case EMoveType::Wipe: { color = Wipe_Color; break; } - default: { color = { 0.0f, 0.0f, 0.0f, 1.0f }; break; } - } - - RenderPath key{ tbuffer_id, color, static_cast(ibuffer_id), path_id }; - if (render_path == nullptr || !RenderPathPropertyEqual()(*render_path, key)) { - buffer.render_paths.emplace_back(key); - render_path = const_cast(&buffer.render_paths.back()); - } - - unsigned int delta_1st = 0; - if (sub_path.first.s_id < m_sequential_view.current.first && m_sequential_view.current.first <= sub_path.last.s_id) - delta_1st = static_cast(m_sequential_view.current.first - sub_path.first.s_id); - - unsigned int size_in_indices = 0; - switch (buffer.render_primitive_type) - { - case TBuffer::ERenderPrimitiveType::Line: - case TBuffer::ERenderPrimitiveType::Triangle: { - unsigned int segments_count = std::min(m_sequential_view.current.last, sub_path.last.s_id) - std::max(m_sequential_view.current.first, sub_path.first.s_id); - size_in_indices = buffer.indices_per_segment() * segments_count; - break; - } - default: { break; } - } - - if (size_in_indices == 0) - continue; - - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle) { - if (sub_path_id == 0 && delta_1st == 0) - size_in_indices += 6; // add 2 triangles for starting cap - if (sub_path_id == path.sub_paths.size() - 1 && path.sub_paths.back().last.s_id <= m_sequential_view.current.last) - size_in_indices += 6; // add 2 triangles for ending cap - if (delta_1st > 0) - size_in_indices -= 6; // remove 2 triangles for corner cap - } - - render_path->sizes.push_back(size_in_indices); - - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Triangle) { - delta_1st *= buffer.indices_per_segment(); - if (delta_1st > 0) { - delta_1st += 6; // skip 2 triangles for corner cap - if (sub_path_id == 0) - delta_1st += 6; // skip 2 triangles for starting cap - } - } - - render_path->offsets.push_back(static_cast((sub_path.first.i_id + delta_1st) * sizeof(IBufferType))); - -#if 0 - // check sizes and offsets against index buffer size on gpu - GLint buffer_size; - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer->indices[render_path->ibuffer_id].ibo)); - glsafe(::glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &buffer_size)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - if (render_path->offsets.back() + render_path->sizes.back() * sizeof(IBufferType) > buffer_size) - BOOST_LOG_TRIVIAL(error) << "GCodeViewer::refresh_render_paths: Invalid render path data"; -#endif - } - - // Removes empty render paths and sort. - for (size_t b = 0; b < m_buffers.size(); ++b) { - TBuffer* buffer = const_cast(&m_buffers[b]); - buffer->render_paths.erase(std::remove_if(buffer->render_paths.begin(), buffer->render_paths.end(), - [](const auto &path){ return path.sizes.empty() || path.offsets.empty(); }), - buffer->render_paths.end()); - } - - // second pass: for buffers using instanced and batched models, update the instances render ranges - for (size_t b = 0; b < m_buffers.size(); ++b) { - TBuffer& buffer = const_cast(m_buffers[b]); - if (buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::InstancedModel && - buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) - continue; - - buffer.model.instances.render_ranges.reset(); - - if (!buffer.visible || buffer.model.instances.s_ids.empty()) - continue; - - buffer.model.instances.render_ranges.ranges.push_back({ 0, 0, 0, buffer.model.color }); - bool has_second_range = top_layer_only && m_sequential_view.current.last != m_sequential_view.global.last; - if (has_second_range) - buffer.model.instances.render_ranges.ranges.push_back({ 0, 0, 0, Neutral_Color }); - - if (m_sequential_view.current.first <= buffer.model.instances.s_ids.back() && buffer.model.instances.s_ids.front() <= m_sequential_view.current.last) { - for (size_t id : buffer.model.instances.s_ids) { - if (has_second_range) { - if (id < m_sequential_view.endpoints.first) { - ++buffer.model.instances.render_ranges.ranges.front().offset; - if (id <= m_sequential_view.current.first) - ++buffer.model.instances.render_ranges.ranges.back().offset; - else - ++buffer.model.instances.render_ranges.ranges.back().count; - } - else if (id <= m_sequential_view.current.last) - ++buffer.model.instances.render_ranges.ranges.front().count; - else - break; - } - else { - if (id <= m_sequential_view.current.first) - ++buffer.model.instances.render_ranges.ranges.front().offset; - else if (id <= m_sequential_view.current.last) - ++buffer.model.instances.render_ranges.ranges.front().count; - else - break; - } - } - } - } - - // set sequential data to their final value - sequential_view->endpoints = top_layer_only ? top_layer_endpoints : global_endpoints; - sequential_view->current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(sequential_view->current.first, sequential_view->endpoints.first, sequential_view->endpoints.last) : sequential_view->endpoints.first; - sequential_view->global = global_endpoints; - - // updates sequential range caps - std::array* sequential_range_caps = const_cast*>(&m_sequential_range_caps); - (*sequential_range_caps)[0].reset(); - (*sequential_range_caps)[1].reset(); - - if (m_sequential_view.current.first != m_sequential_view.current.last) { - for (const auto& [tbuffer_id, ibuffer_id, path_id, sub_path_id] : paths) { - TBuffer& buffer = const_cast(m_buffers[tbuffer_id]); - if (buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::Triangle) - continue; - - const Path& path = buffer.paths[path_id]; - const Path::Sub_Path& sub_path = path.sub_paths[sub_path_id]; - if (m_sequential_view.current.last <= sub_path.first.s_id || sub_path.last.s_id <= m_sequential_view.current.first) - continue; - - // update cap for first endpoint of current range - if (m_sequential_view.current.first > sub_path.first.s_id) { - SequentialRangeCap& cap = (*sequential_range_caps)[0]; - const IBuffer& i_buffer = buffer.indices[ibuffer_id]; - cap.buffer = &buffer; -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - cap.vao = i_buffer.vao; -#endif // ENABLE_GL_CORE_PROFILE - cap.vbo = i_buffer.vbo; - - // calculate offset into the index buffer - unsigned int offset = sub_path.first.i_id; - offset += 6; // add 2 triangles for corner cap - offset += static_cast(m_sequential_view.current.first - sub_path.first.s_id) * buffer.indices_per_segment(); - if (sub_path_id == 0) - offset += 6; // add 2 triangles for starting cap - - // extract indices from index buffer - std::array indices{ 0, 0, 0, 0, 0, 0 }; - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); -#if ENABLE_OPENGL_ES - IBufferType* index_ptr = static_cast(::glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, - static_cast(offset * sizeof(IBufferType)), static_cast(14 * sizeof(IBufferType)), - GL_MAP_READ_BIT)); - glcheck(); - indices[0] = *(index_ptr + 0); - indices[1] = *(index_ptr + 7); - indices[2] = *(index_ptr + 1); - indices[4] = *(index_ptr + 13); - glsafe(::glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)); -#else - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 0) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[0]))); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 7) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[1]))); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 1) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[2]))); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 13) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[4]))); -#endif // ENABLE_OPENGL_ES - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - indices[3] = indices[0]; - indices[5] = indices[1]; - - // send indices to gpu - glsafe(::glGenBuffers(1, &cap.ibo)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cap.ibo)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(IBufferType), indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - // extract color from render path - size_t offset_bytes = offset * sizeof(IBufferType); - for (const RenderPath& render_path : buffer.render_paths) { - if (render_path.ibuffer_id == ibuffer_id) { - for (size_t j = 0; j < render_path.offsets.size(); ++j) { - if (render_path.contains(offset_bytes)) { - cap.color = render_path.color; - break; - } - } - } - } - } - - // update cap for last endpoint of current range - if (m_sequential_view.current.last < sub_path.last.s_id) { - SequentialRangeCap& cap = (*sequential_range_caps)[1]; - const IBuffer& i_buffer = buffer.indices[ibuffer_id]; - cap.buffer = &buffer; -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - cap.vao = i_buffer.vao; -#endif // ENABLE_GL_CORE_PROFILE - cap.vbo = i_buffer.vbo; - - // calculate offset into the index buffer - unsigned int offset = sub_path.first.i_id; - offset += 6; // add 2 triangles for corner cap - offset += static_cast(m_sequential_view.current.last - 1 - sub_path.first.s_id) * buffer.indices_per_segment(); - if (sub_path_id == 0) - offset += 6; // add 2 triangles for starting cap - - // extract indices from index buffer - std::array indices{ 0, 0, 0, 0, 0, 0 }; - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); -#if ENABLE_OPENGL_ES - IBufferType* index_ptr = static_cast(::glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, - static_cast(offset * sizeof(IBufferType)), static_cast(17 * sizeof(IBufferType)), - GL_MAP_READ_BIT)); - glcheck(); - indices[0] = *(index_ptr + 2); - indices[1] = *(index_ptr + 4); - indices[2] = *(index_ptr + 10); - indices[5] = *(index_ptr + 16); - glsafe(::glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)); -#else - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 2) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[0]))); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 4) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[1]))); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 10) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[2]))); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast((offset + 16) * sizeof(IBufferType)), static_cast(sizeof(IBufferType)), static_cast(&indices[5]))); -#endif // ENABLE_OPENGL_ES - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - indices[3] = indices[0]; - indices[4] = indices[2]; - - // send indices to gpu - glsafe(::glGenBuffers(1, &cap.ibo)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cap.ibo)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(IBufferType), indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - // extract color from render path - size_t offset_bytes = offset * sizeof(IBufferType); - for (const RenderPath& render_path : buffer.render_paths) { - if (render_path.ibuffer_id == ibuffer_id) { - for (size_t j = 0; j < render_path.offsets.size(); ++j) { - if (render_path.contains(offset_bytes)) { - cap.color = render_path.color; - break; - } - } - } - } - } - - if ((*sequential_range_caps)[0].is_renderable() && (*sequential_range_caps)[1].is_renderable()) - break; - } - } - - wxGetApp().plater()->enable_preview_moves_slider(!paths.empty()); - -#if ENABLE_GCODE_VIEWER_STATISTICS - for (const TBuffer& buffer : m_buffers) { - statistics->render_paths_size += SLIC3R_STDUNORDEREDSET_MEMSIZE(buffer.render_paths, RenderPath); - for (const RenderPath& path : buffer.render_paths) { - statistics->render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.sizes, unsigned int); - statistics->render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t); - } - statistics->models_instances_size += SLIC3R_STDVEC_MEMSIZE(buffer.model.instances.buffer, float); - statistics->models_instances_size += SLIC3R_STDVEC_MEMSIZE(buffer.model.instances.s_ids, size_t); - statistics->models_instances_size += SLIC3R_STDVEC_MEMSIZE(buffer.model.instances.render_ranges.ranges, InstanceVBuffer::Ranges::Range); - } - statistics->refresh_paths_time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start_time).count(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS -} -#endif // !ENABLE_NEW_GCODE_VIEWER - -#if ENABLE_NEW_GCODE_VIEWER void GCodeViewer::render_toolpaths() { const Camera& camera = wxGetApp().plater()->get_camera(); @@ -4331,337 +1880,6 @@ void GCodeViewer::render_toolpaths() } #endif // ENABLE_NEW_GCODE_VIEWER_DEBUG } -#else -void GCodeViewer::render_toolpaths() -{ - const Camera& camera = wxGetApp().plater()->get_camera(); -#if !ENABLE_GL_CORE_PROFILE - const double zoom = camera.get_zoom(); -#endif // !ENABLE_GL_CORE_PROFILE - - auto render_as_lines = [ -#if ENABLE_GCODE_VIEWER_STATISTICS - this -#endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { - for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { - const RenderPath& path = *it; - // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. - assert(! path.sizes.empty()); - assert(! path.offsets.empty()); - shader.set_uniform(uniform_color, path.color); -#if ENABLE_GL_CORE_PROFILE - const Camera& camera = wxGetApp().plater()->get_camera(); - const std::array& viewport = camera.get_viewport(); - const float zoom = float(camera.get_zoom()); - shader.set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader.set_uniform("width", (zoom < 5.0f) ? 0.5f : (0.5f + 5.0f * (zoom - 5.0f) / (100.0f - 5.0f))); - shader.set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE - -#if ENABLE_OPENGL_ES - for (size_t i = 0; i < path.sizes.size(); ++i) { - glsafe(::glDrawElements(GL_LINES, (GLsizei)path.sizes[i], GL_UNSIGNED_SHORT, (const void*)path.offsets[i])); - } -#else - glsafe(::glMultiDrawElements(GL_LINES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); -#endif // ENABLE_OPENGL_ES -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.gl_multi_lines_calls_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - } - }; - - auto render_as_triangles = [ -#if ENABLE_GCODE_VIEWER_STATISTICS - this -#endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { - for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { - const RenderPath& path = *it; - // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. - assert(! path.sizes.empty()); - assert(! path.offsets.empty()); - shader.set_uniform(uniform_color, path.color); -#if ENABLE_OPENGL_ES - for (size_t i = 0; i < path.sizes.size(); ++i) { - glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)path.sizes[i], GL_UNSIGNED_SHORT, (const void*)path.offsets[i])); - } -#else - glsafe(::glMultiDrawElements(GL_TRIANGLES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); -#endif // ENABLE_OPENGL_ES -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.gl_multi_triangles_calls_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - } - }; - - auto render_as_instanced_model = [ -#if ENABLE_GCODE_VIEWER_STATISTICS - this -#endif // ENABLE_GCODE_VIEWER_STATISTICS - ](TBuffer& buffer, GLShaderProgram & shader) { - for (auto& range : buffer.model.instances.render_ranges.ranges) { - if (range.vbo == 0 && range.count > 0) { - glsafe(::glGenBuffers(1, &range.vbo)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, range.vbo)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, range.count * buffer.model.instances.instance_size_bytes(), (const void*)&buffer.model.instances.buffer[range.offset * buffer.model.instances.instance_size_floats()], GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } - - if (range.vbo > 0) { - buffer.model.model.set_color(range.color); - buffer.model.model.render_instanced(range.vbo, range.count); -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.gl_instanced_models_calls_count; - m_statistics.total_instances_gpu_size += static_cast(range.count * buffer.model.instances.instance_size_bytes()); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - } - } - }; - -#if ENABLE_GCODE_VIEWER_STATISTICS - auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) { -#else - auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) { -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - struct Range - { - unsigned int first; - unsigned int last; - bool intersects(const Range& other) const { return (other.last < first || other.first > last) ? false : true; } - }; - Range buffer_range = { 0, 0 }; - const size_t indices_per_instance = buffer.model.data.indices_count(); - - for (size_t j = 0; j < buffer.indices.size(); ++j) { - const IBuffer& i_buffer = buffer.indices[j]; - buffer_range.last = buffer_range.first + i_buffer.count / indices_per_instance; -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(i_buffer.vao)); -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableVertexAttribArray(position_id)); - } - const bool has_normals = buffer.vertices.normal_size_floats() > 0; - if (has_normals) { - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - } - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); - - for (auto& range : buffer.model.instances.render_ranges.ranges) { - const Range range_range = { range.offset, range.offset + range.count }; - if (range_range.intersects(buffer_range)) { - shader.set_uniform("uniform_color", range.color); - const unsigned int offset = (range_range.first > buffer_range.first) ? range_range.first - buffer_range.first : 0; - const size_t offset_bytes = static_cast(offset) * indices_per_instance * sizeof(IBufferType); - const Range render_range = { std::max(range_range.first, buffer_range.first), std::min(range_range.last, buffer_range.last) }; - const size_t count = static_cast(render_range.last - render_range.first) * indices_per_instance; - if (count > 0) { - glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)count, GL_UNSIGNED_SHORT, (const void*)offset_bytes)); -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.gl_batched_models_calls_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - } - } - } - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE - - buffer_range.first = buffer_range.last; - } - }; - - auto line_width = [](double zoom) { - return (zoom < 5.0) ? 1.0 : (1.0 + 5.0 * (zoom - 5.0) / (100.0 - 5.0)); - }; - - const unsigned char begin_id = buffer_id(EMoveType::Retract); - const unsigned char end_id = buffer_id(EMoveType::Count); - - for (unsigned char i = begin_id; i < end_id; ++i) { - TBuffer& buffer = m_buffers[i]; - if (!buffer.visible || !buffer.has_data()) - continue; - - GLShaderProgram* shader = wxGetApp().get_shader(buffer.shader.c_str()); - if (shader == nullptr) - continue; - - shader->start_using(); - - shader->set_uniform("view_model_matrix", camera.get_view_matrix()); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); - - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { - shader->set_uniform("emission_factor", 0.25f); - render_as_instanced_model(buffer, *shader); - shader->set_uniform("emission_factor", 0.0f); - } - else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { - shader->set_uniform("emission_factor", 0.25f); - const int position_id = shader->get_attrib_location("v_position"); - const int normal_id = shader->get_attrib_location("v_normal"); - render_as_batched_model(buffer, *shader, position_id, normal_id); - shader->set_uniform("emission_factor", 0.0f); - } - else { - shader->set_uniform("emission_factor", 0.15f); - const int position_id = shader->get_attrib_location("v_position"); - const int normal_id = shader->get_attrib_location("v_normal"); - const int uniform_color = shader->get_uniform_location("uniform_color"); - - auto it_path = buffer.render_paths.begin(); - for (unsigned int ibuffer_id = 0; ibuffer_id < static_cast(buffer.indices.size()); ++ibuffer_id) { - const IBuffer& i_buffer = buffer.indices[ibuffer_id]; - // Skip all paths with ibuffer_id < ibuffer_id. - for (; it_path != buffer.render_paths.end() && it_path->ibuffer_id < ibuffer_id; ++it_path); - if (it_path == buffer.render_paths.end() || it_path->ibuffer_id > ibuffer_id) - // Not found. This shall not happen. - continue; - -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(i_buffer.vao)); -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableVertexAttribArray(position_id)); - } - const bool has_normals = buffer.vertices.normal_size_floats() > 0; - if (has_normals) { - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - } - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); - - // Render all elements with it_path->ibuffer_id == ibuffer_id, possible with varying colors. - switch (buffer.render_primitive_type) - { - case TBuffer::ERenderPrimitiveType::Line: { -#if ENABLE_GL_CORE_PROFILE - if (!OpenGLManager::get_gl_info().is_core_profile()) - glsafe(::glLineWidth(static_cast(line_width(camera.get_zoom())))); -#else - glsafe(::glLineWidth(static_cast(line_width(zoom)))); -#endif // ENABLE_GL_CORE_PROFILE - render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color); - break; - } - case TBuffer::ERenderPrimitiveType::Triangle: { - render_as_triangles(it_path, buffer.render_paths.end(), *shader, uniform_color); - break; - } - default: { break; } - } - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE - } - } - - shader->stop_using(); - } - -#if ENABLE_GCODE_VIEWER_STATISTICS - auto render_sequential_range_cap = [this, &camera] -#else - auto render_sequential_range_cap = [&camera] -#endif // ENABLE_GCODE_VIEWER_STATISTICS - (const SequentialRangeCap& cap) { - const TBuffer* buffer = cap.buffer; - GLShaderProgram* shader = wxGetApp().get_shader(buffer->shader.c_str()); - if (shader == nullptr) - return; - - shader->start_using(); - - shader->set_uniform("view_model_matrix", camera.get_view_matrix()); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); - - const int position_id = shader->get_attrib_location("v_position"); - const int normal_id = shader->get_attrib_location("v_normal"); - -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(cap.vao)); -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, buffer->vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); - glsafe(::glEnableVertexAttribArray(position_id)); - } - const bool has_normals = buffer->vertices.normal_size_floats() > 0; - if (has_normals) { - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, buffer->vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - } - - shader->set_uniform("uniform_color", cap.color); - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cap.ibo)); - glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)cap.indices_count(), GL_UNSIGNED_SHORT, nullptr)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.gl_triangles_calls_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE - - shader->stop_using(); - }; - - for (unsigned int i = 0; i < 2; ++i) { - if (m_sequential_range_caps[i].is_renderable()) - render_sequential_range_cap(m_sequential_range_caps[i]); - } -} -#endif // ENABLE_NEW_GCODE_VIEWER void GCodeViewer::render_shells() { @@ -4682,13 +1900,8 @@ void GCodeViewer::render_shells() void GCodeViewer::render_legend(float& legend_height) { -#if ENABLE_NEW_GCODE_VIEWER if (!is_legend_shown()) return; -#else - if (!m_legend_enabled) - return; -#endif // ENABLE_NEW_GCODE_VIEWER const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size(); @@ -4710,19 +1923,12 @@ void GCodeViewer::render_legend(float& legend_height) Line }; -#if ENABLE_NEW_GCODE_VIEWER const PrintEstimatedStatistics::Mode& time_mode = m_print_statistics.modes[static_cast(m_viewer.get_time_mode())]; const libvgcode::EViewType curr_view_type = m_viewer.get_view_type(); const int curr_view_type_i = static_cast(curr_view_type); bool show_estimated_time = time_mode.time > 0.0f && (curr_view_type == libvgcode::EViewType::FeatureType || curr_view_type == libvgcode::EViewType::LayerTimeLinear || curr_view_type == libvgcode::EViewType::LayerTimeLogarithmic || (curr_view_type == libvgcode::EViewType::ColorPrint && !time_mode.custom_gcode_times.empty())); -#else - const PrintEstimatedStatistics::Mode& time_mode = m_print_statistics.modes[static_cast(m_time_estimate_mode)]; - bool show_estimated_time = time_mode.time > 0.0f && (m_view_type == EViewType::FeatureType || - m_view_type == EViewType::LayerTimeLinear || m_view_type == EViewType::LayerTimeLogarithmic || - (m_view_type == EViewType::ColorPrint && !time_mode.custom_gcode_times.empty())); -#endif // ENABLE_NEW_GCODE_VIEWER const float icon_size = ImGui::GetTextLineHeight(); const float percent_bar_size = 2.0f * ImGui::GetTextLineHeight(); @@ -4837,23 +2043,13 @@ void GCodeViewer::render_legend(float& legend_height) ImGui::PopStyleVar(); }; -#if ENABLE_NEW_GCODE_VIEWER auto append_range = [append_item](const libvgcode::ColorRange& range, unsigned int decimals) { auto append_range_item = [append_item, &range](int i, float value, unsigned int decimals) { -#else - auto append_range = [append_item](const Extrusions::Range& range, unsigned int decimals) { - auto append_range_item = [append_item](int i, float value, unsigned int decimals) { -#endif // ENABLE_NEW_GCODE_VIEWER char buf[1024]; ::sprintf(buf, "%.*f", decimals, value); -#if ENABLE_NEW_GCODE_VIEWER append_item(EItemType::Rect, libvgcode::convert(range.get_palette()[i]), buf); -#else - append_item(EItemType::Rect, Range_Colors[i], buf); -#endif // ENABLE_NEW_GCODE_VIEWER }; -#if ENABLE_NEW_GCODE_VIEWER std::vector values = range.get_values(); if (values.size() == 1) // single item use case @@ -4868,42 +2064,16 @@ void GCodeViewer::render_legend(float& legend_height) append_range_item(i, values[i], decimals); } } -#else - if (range.count == 1) - // single item use case - append_range_item(0, range.min, decimals); - else if (range.count == 2) { - // two items use case - append_range_item(static_cast(Range_Colors.size()) - 1, range.max, decimals); - append_range_item(0, range.min, decimals); - } - else { - const float step_size = range.step_size(); - for (int i = static_cast(Range_Colors.size()) - 1; i >= 0; --i) { - append_range_item(i, range.min + static_cast(i) * step_size, decimals); - } - } -#endif // ENABLE_NEW_GCODE_VIEWER }; -#if ENABLE_NEW_GCODE_VIEWER auto append_time_range = [append_item](const libvgcode::ColorRange& range) { auto append_range_item = [append_item, &range](int i, float value) { -#else - auto append_time_range = [append_item](const Extrusions::Range& range, Extrusions::Range::EType type) { - auto append_range_item = [append_item](int i, float value) { -#endif // ENABLE_NEW_GCODE_VIEWER std::string str_value = get_time_dhms(value); if (str_value == "0s") str_value = "< 1s"; -#if ENABLE_NEW_GCODE_VIEWER append_item(EItemType::Rect, libvgcode::convert(range.get_palette()[i]), str_value); -#else - append_item(EItemType::Rect, Range_Colors[i], str_value); -#endif // ENABLE_NEW_GCODE_VIEWER }; -#if ENABLE_NEW_GCODE_VIEWER std::vector values = range.get_values(); if (values.size() == 1) // single item use case @@ -4918,29 +2088,6 @@ void GCodeViewer::render_legend(float& legend_height) append_range_item(i, values[i]); } } -#else - if (range.count == 1) - // single item use case - append_range_item(0, range.min); - else if (range.count == 2) { - // two items use case - append_range_item(static_cast(Range_Colors.size()) - 1, range.max); - append_range_item(0, range.min); - } - else { - float step_size = range.step_size(type); - for (int i = static_cast(Range_Colors.size()) - 1; i >= 0; --i) { - float value = 0.0f; - switch (type) - { - default: - case Extrusions::Range::EType::Linear: { value = range.min + static_cast(i) * step_size; break; } - case Extrusions::Range::EType::Logarithmic: { value = ::exp(::log(range.min) + static_cast(i) * step_size); break; } - } - append_range_item(i, value); - } - } -#endif // ENABLE_NEW_GCODE_VIEWER }; auto append_headers = [&imgui](const std::array& texts, const std::array& offsets) { @@ -4982,14 +2129,9 @@ void GCodeViewer::render_legend(float& legend_height) if (item.type != ColorChange) continue; -#if ENABLE_NEW_GCODE_VIEWER const std::vector zs = m_viewer.get_layers_zs(); auto lower_b = std::lower_bound(zs.begin(), zs.end(), static_cast(item.print_z - Slic3r::DoubleSlider::epsilon())); -#else - const std::vector zs = m_layers.get_zs(); - auto lower_b = std::lower_bound(zs.begin(), zs.end(), item.print_z - Slic3r::DoubleSlider::epsilon()); -#endif // ENABLE_NEW_GCODE_VIEWER if (lower_b == zs.end()) continue; @@ -5027,17 +2169,10 @@ void GCodeViewer::render_legend(float& legend_height) return _u8L("from") + " " + std::string(buf1) + " " + _u8L("to") + " " + std::string(buf2) + " " + _u8L("mm"); }; -#if ENABLE_NEW_GCODE_VIEWER auto role_time_and_percent = [this, time_mode](libvgcode::EGCodeExtrusionRole role) { const float time = m_viewer.get_extrusion_role_estimated_time(role); return std::make_pair(time, time / time_mode.time); }; -#else - auto role_time_and_percent = [time_mode](GCodeExtrusionRole role) { - auto it = std::find_if(time_mode.roles_times.begin(), time_mode.roles_times.end(), [role](const std::pair& item) { return role == item.first; }); - return (it != time_mode.roles_times.end()) ? std::make_pair(it->second, it->second / time_mode.time) : std::make_pair(0.0f, 0.0f); - }; -#endif // ENABLE_NEW_GCODE_VIEWER auto used_filament_per_role = [this, imperial_units](GCodeExtrusionRole role) { auto it = m_print_statistics.used_filaments_per_role.find(role); @@ -5048,7 +2183,6 @@ void GCodeViewer::render_legend(float& legend_height) return std::make_pair(it->second.first * koef, it->second.second); }; -#if ENABLE_NEW_GCODE_VIEWER auto toggle_extrusion_role_visibility = [this](libvgcode::EGCodeExtrusionRole role) { const libvgcode::Interval view_visible_range = m_viewer.get_view_visible_range(); const libvgcode::Interval view_enabled_range = m_viewer.get_view_enabled_range(); @@ -5062,7 +2196,6 @@ void GCodeViewer::render_legend(float& legend_height) wxGetApp().plater()->update_preview_moves_slider(view_visible_range_min, view_visible_range_max); wxGetApp().plater()->get_current_canvas3D()->set_as_dirty(); }; -#endif // ENABLE_NEW_GCODE_VIEWER // data used to properly align items in columns when showing time std::array offsets = { 0.0f, 0.0f, 0.0f, 0.0f }; @@ -5073,7 +2206,6 @@ void GCodeViewer::render_legend(float& legend_height) std::vector used_filaments_g; float max_time_percent = 0.0f; -#if ENABLE_NEW_GCODE_VIEWER if (curr_view_type == libvgcode::EViewType::FeatureType) { // calculate offsets to align time/percentage data const std::vector& roles = m_viewer.get_extrusion_roles(); @@ -5082,23 +2214,10 @@ void GCodeViewer::render_legend(float& legend_height) if (static_cast(role) < libvgcode::GCODE_EXTRUSION_ROLES_COUNT) { labels.push_back(_u8L(gcode_extrusion_role_to_string(convert(role)))); auto [time, percent] = role_time_and_percent(role); -#else - if (m_view_type == EViewType::FeatureType) { - // calculate offsets to align time/percentage data - for (GCodeExtrusionRole role : m_roles) { - assert(role < GCodeExtrusionRole::Count); - if (role < GCodeExtrusionRole::Count) { - labels.push_back(_u8L(gcode_extrusion_role_to_string(role))); - auto [time, percent] = role_time_and_percent(role); -#endif // ENABLE_NEW_GCODE_VIEWER times.push_back((time > 0.0f) ? short_time_ui(get_time_dhms(time)) : ""); percents.push_back(percent); max_time_percent = std::max(max_time_percent, percent); -#if ENABLE_NEW_GCODE_VIEWER auto [used_filament_m, used_filament_g] = used_filament_per_role(convert(role)); -#else - auto [used_filament_m, used_filament_g] = used_filament_per_role(role); -#endif // ENABLE_NEW_GCODE_VIEWER used_filaments_m.push_back(used_filament_m); used_filaments_g.push_back(used_filament_g); } @@ -5134,7 +2253,6 @@ void GCodeViewer::render_legend(float& legend_height) return ret; }; -#if ENABLE_NEW_GCODE_VIEWER if (curr_view_type == libvgcode::EViewType::Tool) { // calculate used filaments data const size_t extruders_count = get_extruders_count(); @@ -5142,13 +2260,6 @@ void GCodeViewer::render_legend(float& legend_height) used_filaments_g = std::vector(extruders_count, 0.0); const std::vector& used_extruders_ids = m_viewer.get_used_extruders_ids(); for (uint8_t extruder_id : used_extruders_ids) { -#else - if (m_view_type == EViewType::Tool) { - // calculate used filaments data - used_filaments_m = std::vector(m_extruders_count, 0.0); - used_filaments_g = std::vector(m_extruders_count, 0.0); - for (size_t extruder_id : m_extruder_ids) { -#endif // ENABLE_NEW_GCODE_VIEWER if (m_print_statistics.volumes_per_extruder.find(extruder_id) == m_print_statistics.volumes_per_extruder.end()) continue; double volume = m_print_statistics.volumes_per_extruder.at(extruder_id); @@ -5171,18 +2282,12 @@ void GCodeViewer::render_legend(float& legend_height) // selection section bool view_type_changed = false; -#if ENABLE_NEW_GCODE_VIEWER int new_view_type_i = curr_view_type_i; -#else - int old_view_type = static_cast(get_view_type()); - int view_type = old_view_type; -#endif // ENABLE_NEW_GCODE_VIEWER ImGui::PushStyleColor(ImGuiCol_FrameBg, { 0.1f, 0.1f, 0.1f, 0.8f }); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, { 0.2f, 0.2f, 0.2f, 0.8f }); std::vector view_options; std::vector view_options_id; -#if ENABLE_NEW_GCODE_VIEWER const std::vector layers_times = get_layers_times(); if (!layers_times.empty() && layers_times.size() == m_viewer.get_layers_count()) { view_options = { _u8L("Feature type"), _u8L("Height (mm)"), _u8L("Width (mm)"), _u8L("Speed (mm/s)"), _u8L("Actual speed (mm/s)"), @@ -5201,16 +2306,8 @@ void GCodeViewer::render_legend(float& legend_height) static_cast(libvgcode::EViewType::LayerTimeLogarithmic), static_cast(libvgcode::EViewType::Tool), static_cast(libvgcode::EViewType::ColorPrint) }; -#else - if (!m_layers_times.empty() && m_layers.size() == m_layers_times.front().size()) { - view_options = { _u8L("Feature type"), _u8L("Height (mm)"), _u8L("Width (mm)"), _u8L("Speed (mm/s)"), _u8L("Fan speed (%)"), - _u8L("Temperature (°C)"), _u8L("Volumetric flow rate (mm³/s)"), _u8L("Layer time (linear)"), _u8L("Layer time (logarithmic)"), - _u8L("Tool"), _u8L("Color Print") }; - view_options_id = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; -#endif // ENABLE_NEW_GCODE_VIEWER } else { -#if ENABLE_NEW_GCODE_VIEWER view_options = { _u8L("Feature type"), _u8L("Height (mm)"), _u8L("Width (mm)"), _u8L("Speed (mm/s)"), _u8L("Actual speed (mm/s)"), _u8L("Fan speed (%)"), _u8L("Temperature (°C)"), _u8L("Volumetric flow rate (mm³/s)"), _u8L("Actual volumetric flow rate (mm³/s)"), _u8L("Tool"), _u8L("Color Print") }; @@ -5228,28 +2325,13 @@ void GCodeViewer::render_legend(float& legend_height) if (new_view_type_i == static_cast(libvgcode::EViewType::LayerTimeLinear) || new_view_type_i == static_cast(libvgcode::EViewType::LayerTimeLogarithmic)) new_view_type_i = 0; -#else - view_options = { _u8L("Feature type"), _u8L("Height (mm)"), _u8L("Width (mm)"), _u8L("Speed (mm/s)"), _u8L("Fan speed (%)"), - _u8L("Temperature (°C)"), _u8L("Volumetric flow rate (mm³/s)"), _u8L("Tool"), _u8L("Color Print") }; - view_options_id = { 0, 1, 2, 3, 4, 5, 6, 9, 10 }; - if (view_type == 7 || view_type == 8) - view_type = 0; -#endif // ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER auto new_view_type_it = std::find(view_options_id.begin(), view_options_id.end(), new_view_type_i); int new_view_type_id = (new_view_type_it == view_options_id.end()) ? 0 : std::distance(view_options_id.begin(), new_view_type_it); if (imgui.combo(std::string(), view_options, new_view_type_id, ImGuiComboFlags_HeightLargest, 0.0f, -1.0f)) new_view_type_i = view_options_id[new_view_type_id]; -#else - auto view_type_it = std::find(view_options_id.begin(), view_options_id.end(), view_type); - int view_type_id = (view_type_it == view_options_id.end()) ? 0 : std::distance(view_options_id.begin(), view_type_it); - if (imgui.combo(std::string(), view_options, view_type_id, ImGuiComboFlags_HeightLargest, 0.0f, -1.0f)) - view_type = view_options_id[view_type_id]; -#endif // ENABLE_NEW_GCODE_VIEWER ImGui::PopStyleColor(2); -#if ENABLE_NEW_GCODE_VIEWER if (curr_view_type_i != new_view_type_i) { enable_view_type_cache_load(false); set_view_type(static_cast(new_view_type_i)); @@ -5269,36 +2351,13 @@ void GCodeViewer::render_legend(float& legend_height) append_headers({ "", _u8L("Used filament"), "", "" }, offsets); else ImGui::Separator(); -#else - if (old_view_type != view_type) { - set_view_type(static_cast(view_type)); - wxGetApp().plater()->set_keep_current_preview_type(true); - wxGetApp().plater()->refresh_print(); - view_type_changed = true; - } - - // extrusion paths section -> title - if (m_view_type == EViewType::FeatureType) - append_headers({ "", _u8L("Time"), _u8L("Percentage"), _u8L("Used filament") }, offsets); - else if (m_view_type == EViewType::Tool) - append_headers({ "", _u8L("Used filament"), "", "" }, offsets); - else - ImGui::Separator(); -#endif // ENABLE_NEW_GCODE_VIEWER if (!view_type_changed) { // extrusion paths section -> items -#if ENABLE_NEW_GCODE_VIEWER switch (new_view_type) { case libvgcode::EViewType::FeatureType: -#else - switch (m_view_type) { - case EViewType::FeatureType: -#endif // ENABLE_NEW_GCODE_VIEWER - { -#if ENABLE_NEW_GCODE_VIEWER const float travels_time = m_viewer.get_travels_estimated_time(); max_time_percent = std::max(max_time_percent, travels_time / time_mode.time); const std::vector& roles = m_viewer.get_extrusion_roles(); @@ -5313,41 +2372,14 @@ void GCodeViewer::render_legend(float& legend_height) visible, times[i], percents[i], max_time_percent, offsets, used_filaments_m[i], used_filaments_g[i], [role, toggle_extrusion_role_visibility]() { toggle_extrusion_role_visibility(role); } ); -#else - max_time_percent = std::max(max_time_percent, time_mode.travel_time / time_mode.time); - for (size_t i = 0; i < m_roles.size(); ++i) { - GCodeExtrusionRole role = m_roles[i]; - if (role >= GCodeExtrusionRole::Count) - continue; - - const bool visible = is_visible(role); - - append_item(EItemType::Rect, Extrusion_Role_Colors[static_cast(role)], labels[i], - visible, times[i], percents[i], max_time_percent, offsets, used_filaments_m[i], used_filaments_g[i], - [this, role, visible]() { - m_extrusions.role_visibility_flags = visible ? m_extrusions.role_visibility_flags & ~(1 << int(role)) : m_extrusions.role_visibility_flags | (1 << int(role)); - // update buffers' render paths - refresh_render_paths(false, false); - wxGetApp().plater()->update_preview_moves_slider(); - wxGetApp().plater()->get_current_canvas3D()->set_as_dirty(); - } - ); -#endif // ENABLE_NEW_GCODE_VIEWER } -#if ENABLE_NEW_GCODE_VIEWER if (m_viewer.is_option_visible(libvgcode::EOptionType::Travels)) append_item(EItemType::Line, libvgcode::convert(m_viewer.get_option_color(libvgcode::EOptionType::Travels)), _u8L("Travel"), true, short_time_ui(get_time_dhms(travels_time)), travels_time / time_mode.time, max_time_percent, offsets, 0.0f, 0.0f); -#else - if (m_buffers[buffer_id(EMoveType::Travel)].visible) - append_item(EItemType::Line, Travel_Colors[0], _u8L("Travel"), true, short_time_ui(get_time_dhms(time_mode.travel_time)), - time_mode.travel_time / time_mode.time, max_time_percent, offsets, 0.0f, 0.0f); -#endif // ENABLE_NEW_GCODE_VIEWER break; } -#if ENABLE_NEW_GCODE_VIEWER case libvgcode::EViewType::Height: { append_range(m_viewer.get_color_range(libvgcode::EViewType::Height), 3); break; } case libvgcode::EViewType::Width: { append_range(m_viewer.get_color_range(libvgcode::EViewType::Width), 3); break; } case libvgcode::EViewType::Speed: { append_range(m_viewer.get_color_range(libvgcode::EViewType::Speed), 1); break; } @@ -5368,68 +2400,29 @@ void GCodeViewer::render_legend(float& legend_height) } break; } - case libvgcode::EViewType::ColorPrint: -#else - case EViewType::Height: { append_range(m_extrusions.ranges.height, 3); break; } - case EViewType::Width: { append_range(m_extrusions.ranges.width, 3); break; } - case EViewType::Feedrate: { append_range(m_extrusions.ranges.feedrate, 1); break; } - case EViewType::FanSpeed: { append_range(m_extrusions.ranges.fan_speed, 0); break; } - case EViewType::Temperature: { append_range(m_extrusions.ranges.temperature, 0); break; } - case EViewType::VolumetricRate: { append_range(m_extrusions.ranges.volumetric_rate, 3); break; } - case EViewType::LayerTimeLinear: { append_time_range(m_extrusions.ranges.layer_time[static_cast(m_time_estimate_mode)], Extrusions::Range::EType::Linear); break; } - case EViewType::LayerTimeLogarithmic: { append_time_range(m_extrusions.ranges.layer_time[static_cast(m_time_estimate_mode)], Extrusions::Range::EType::Logarithmic); break; } - case EViewType::Tool: { - // shows only extruders actually used - for (unsigned char extruder_id : m_extruder_ids) { - if (used_filaments_m[extruder_id] > 0.0 && used_filaments_g[extruder_id] > 0.0) - append_item(EItemType::Rect, m_tool_colors[extruder_id], _u8L("Extruder") + " " + std::to_string(extruder_id + 1), - true, "", 0.0f, 0.0f, offsets, used_filaments_m[extruder_id], used_filaments_g[extruder_id]); - } - break; - } - case EViewType::ColorPrint: -#endif // ENABLE_NEW_GCODE_VIEWER - { + case libvgcode::EViewType::ColorPrint: { const std::vector& custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_custom_gcode_per_print_z; size_t total_items = 1; -#if ENABLE_NEW_GCODE_VIEWER const std::vector& used_extruders_ids = m_viewer.get_used_extruders_ids(); for (uint8_t extruder_id : used_extruders_ids) { total_items += color_print_ranges(extruder_id, custom_gcode_per_print_z).size(); } -#else - for (unsigned char i : m_extruder_ids) { - total_items += color_print_ranges(i, custom_gcode_per_print_z).size(); - } -#endif // ENABLE_NEW_GCODE_VIEWER const bool need_scrollable = static_cast(total_items) * icon_size + (static_cast(total_items) - 1.0f) * ImGui::GetStyle().ItemSpacing.y > child_height; // add scrollable region, if needed if (need_scrollable) ImGui::BeginChild("color_prints", { -1.0f, child_height }, false); -#if ENABLE_NEW_GCODE_VIEWER if (get_extruders_count() == 1) { // single extruder use case -#else - if (m_extruders_count == 1) { // single extruder use case -#endif // ENABLE_NEW_GCODE_VIEWER const std::vector>> cp_values = color_print_ranges(0, custom_gcode_per_print_z); const int items_cnt = static_cast(cp_values.size()); if (items_cnt == 0) // There are no color changes, but there are some pause print or custom Gcode -#if ENABLE_NEW_GCODE_VIEWER append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors().front()), _u8L("Default color")); -#else - append_item(EItemType::Rect, m_tool_colors.front(), _u8L("Default color")); -#endif // ENABLE_NEW_GCODE_VIEWER else { for (int i = items_cnt; i >= 0; --i) { // create label for color change item if (i == 0) { -#if ENABLE_NEW_GCODE_VIEWER append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors().front()), upto_label(cp_values.front().second.first)); -#else - append_item(EItemType::Rect, m_tool_colors[0], upto_label(cp_values.front().second.first)); -#endif // ENABLE_NEW_GCODE_VIEWER break; } else if (i == items_cnt) { @@ -5442,38 +2435,21 @@ void GCodeViewer::render_legend(float& legend_height) } else { // multi extruder use case // shows only extruders actually used -#if ENABLE_NEW_GCODE_VIEWER const std::vector& used_extruders_ids = m_viewer.get_used_extruders_ids(); for (uint8_t extruder_id : used_extruders_ids) { const std::vector>> cp_values = color_print_ranges(extruder_id, custom_gcode_per_print_z); -#else - for (unsigned char i : m_extruder_ids) { - const std::vector>> cp_values = color_print_ranges(i, custom_gcode_per_print_z); -#endif // ENABLE_NEW_GCODE_VIEWER const int items_cnt = static_cast(cp_values.size()); if (items_cnt == 0) // There are no color changes, but there are some pause print or custom Gcode -#if ENABLE_NEW_GCODE_VIEWER append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors()[extruder_id]), _u8L("Extruder") + " " + std::to_string(extruder_id + 1) + " " + _u8L("default color")); -#else - append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1) + " " + _u8L("default color")); -#endif // ENABLE_NEW_GCODE_VIEWER else { for (int j = items_cnt; j >= 0; --j) { // create label for color change item -#if ENABLE_NEW_GCODE_VIEWER std::string label = _u8L("Extruder") + " " + std::to_string(extruder_id + 1); -#else - std::string label = _u8L("Extruder") + " " + std::to_string(i + 1); -#endif // ENABLE_NEW_GCODE_VIEWER if (j == 0) { label += " " + upto_label(cp_values.front().second.first); -#if ENABLE_NEW_GCODE_VIEWER append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors()[extruder_id]), label); -#else - append_item(EItemType::Rect, m_tool_colors[i], label); -#endif // ENABLE_NEW_GCODE_VIEWER break; } else if (j == items_cnt) { @@ -5498,11 +2474,7 @@ void GCodeViewer::render_legend(float& legend_height) } // partial estimated printing time section -#if ENABLE_NEW_GCODE_VIEWER if (new_view_type == libvgcode::EViewType::ColorPrint) { -#else - if (m_view_type == EViewType::ColorPrint) { -#endif // ENABLE_NEW_GCODE_VIEWER using Times = std::pair; using TimesList = std::vector>; @@ -5528,16 +2500,10 @@ void GCodeViewer::render_legend(float& legend_height) PartialTimes items; std::vector custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_custom_gcode_per_print_z; -#if ENABLE_NEW_GCODE_VIEWER const size_t extruders_count = get_extruders_count(); std::vector last_color(extruders_count); for (size_t i = 0; i < extruders_count; ++i) { last_color[i] = libvgcode::convert(m_viewer.get_tool_colors()[i]); -#else - std::vector last_color(m_extruders_count); - for (size_t i = 0; i < m_extruders_count; ++i) { - last_color[i] = m_tool_colors[i]; -#endif // ENABLE_NEW_GCODE_VIEWER } int last_extruder_id = 1; int color_change_idx = 0; @@ -5702,11 +2668,7 @@ void GCodeViewer::render_legend(float& legend_height) } has_settings |= has_filament_settings; bool show_settings = wxGetApp().is_gcode_viewer(); -#if ENABLE_NEW_GCODE_VIEWER show_settings &= (new_view_type == libvgcode::EViewType::FeatureType || new_view_type == libvgcode::EViewType::Tool); -#else - show_settings &= (m_view_type == EViewType::FeatureType || m_view_type == EViewType::Tool); -#endif // ENABLE_NEW_GCODE_VIEWER show_settings &= has_settings; if (show_settings) { ImGui::Spacing(); @@ -5730,7 +2692,6 @@ void GCodeViewer::render_legend(float& legend_height) add_strings_row_to_table(_u8L("Print settings") + ":", ImGuiWrapper::COL_ORANGE_LIGHT, trim_text_if_needed(m_settings_ids.print), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE())); if (!m_settings_ids.filament.empty()) { -#if ENABLE_NEW_GCODE_VIEWER const std::vector& used_extruders_ids = m_viewer.get_used_extruders_ids(); for (uint8_t extruder_id : used_extruders_ids) { if (extruder_id < static_cast(m_settings_ids.filament.size()) && !m_settings_ids.filament[extruder_id].empty()) { @@ -5740,45 +2701,21 @@ void GCodeViewer::render_legend(float& legend_height) trim_text_if_needed(m_settings_ids.filament[extruder_id]), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE())); } } -#else - for (unsigned char i : m_extruder_ids) { - if (i < static_cast(m_settings_ids.filament.size()) && !m_settings_ids.filament[i].empty()) { - std::string txt = _u8L("Filament"); - txt += (m_extruder_ids.size() == 1) ? ":" : " " + std::to_string(i + 1); - add_strings_row_to_table(txt, ImGuiWrapper::COL_ORANGE_LIGHT, - trim_text_if_needed(m_settings_ids.filament[i]), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE())); - } - } -#endif // ENABLE_NEW_GCODE_VIEWER } ImGui::EndTable(); } } -#if ENABLE_NEW_GCODE_VIEWER if (new_view_type == libvgcode::EViewType::Width || new_view_type == libvgcode::EViewType::VolumetricFlowRate || new_view_type == libvgcode::EViewType::ActualVolumetricFlowRate) { const std::vector& roles = m_viewer.get_extrusion_roles(); const auto custom_it = std::find(roles.begin(), roles.end(), libvgcode::EGCodeExtrusionRole::Custom); if (custom_it != roles.end()) { const bool custom_visible = m_viewer.is_extrusion_role_visible((libvgcode::EGCodeExtrusionRole)GCodeExtrusionRole::Custom); -#else - if (m_view_type == EViewType::Width || m_view_type == EViewType::VolumetricRate) { - const auto custom_it = std::find(m_roles.begin(), m_roles.end(), GCodeExtrusionRole::Custom); - if (custom_it != m_roles.end()) { - const bool custom_visible = is_visible(GCodeExtrusionRole::Custom); -#endif // ENABLE_NEW_GCODE_VIEWER const wxString btn_text = custom_visible ? _L("Hide Custom G-code") : _L("Show Custom G-code"); ImGui::Separator(); - if (imgui.button(btn_text, ImVec2(-1.0f, 0.0f), true)) { -#if ENABLE_NEW_GCODE_VIEWER + if (imgui.button(btn_text, ImVec2(-1.0f, 0.0f), true)) toggle_extrusion_role_visibility(libvgcode::EGCodeExtrusionRole::Custom); -#else - m_extrusions.role_visibility_flags = custom_visible ? m_extrusions.role_visibility_flags & ~(1 << int(GCodeExtrusionRole::Custom)) : - m_extrusions.role_visibility_flags | (1 << int(GCodeExtrusionRole::Custom)); - wxGetApp().plater()->refresh_print(); -#endif // ENABLE_NEW_GCODE_VIEWER - } } } @@ -5786,7 +2723,6 @@ void GCodeViewer::render_legend(float& legend_height) if (show_estimated_time) { ImGui::Spacing(); std::string time_title = _u8L("Estimated printing times"); -#if ENABLE_NEW_GCODE_VIEWER auto can_show_mode_button = [this](libvgcode::ETimeMode mode) { std::vector time_strs; for (size_t i = 0; i < m_print_statistics.modes.size(); ++i) { @@ -5799,37 +2735,13 @@ void GCodeViewer::render_legend(float& legend_height) } return time_strs.size() > 1; }; -#else - auto can_show_mode_button = [this](PrintEstimatedStatistics::ETimeMode mode) { - bool show = false; - if (m_print_statistics.modes.size() > 1 && m_print_statistics.modes[static_cast(mode)].roles_times.size() > 0) { - for (size_t i = 0; i < m_print_statistics.modes.size(); ++i) { - if (i != static_cast(mode) && - m_print_statistics.modes[i].time > 0.0f && - short_time(get_time_dhms(m_print_statistics.modes[static_cast(mode)].time)) != short_time(get_time_dhms(m_print_statistics.modes[i].time))) { - show = true; - break; - } - } - } - return show; - }; -#endif // ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER const libvgcode::ETimeMode time_mode_id = m_viewer.get_time_mode(); if (can_show_mode_button(time_mode_id)) { switch (time_mode_id) { case libvgcode::ETimeMode::Normal: { time_title += " [" + _u8L("Normal mode") + "]"; break; } case libvgcode::ETimeMode::Stealth: { time_title += " [" + _u8L("Stealth mode") + "]"; break; } -#else - if (can_show_mode_button(m_time_estimate_mode)) { - switch (m_time_estimate_mode) - { - case PrintEstimatedStatistics::ETimeMode::Normal: { time_title += " [" + _u8L("Normal mode") + "]"; break; } - case PrintEstimatedStatistics::ETimeMode::Stealth: { time_title += " [" + _u8L("Stealth mode") + "]"; break; } -#endif // ENABLE_NEW_GCODE_VIEWER default: { assert(false); break; } } } @@ -5837,17 +2749,10 @@ void GCodeViewer::render_legend(float& legend_height) imgui.title(time_title + ":"); if (ImGui::BeginTable("Times", 2)) { -#if ENABLE_NEW_GCODE_VIEWER const std::vector layers_times = get_layers_times(); if (!layers_times.empty()) add_strings_row_to_table(_u8L("First layer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT, short_time_ui(get_time_dhms(layers_times.front())), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE())); -#else - if (!time_mode.layers_times.empty()) { - add_strings_row_to_table(_u8L("First layer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT, - short_time_ui(get_time_dhms(time_mode.layers_times.front())), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE())); - } -#endif // ENABLE_NEW_GCODE_VIEWER add_strings_row_to_table(_u8L("Total") + ":", ImGuiWrapper::COL_ORANGE_LIGHT, short_time_ui(get_time_dhms(time_mode.time)), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE())); @@ -5855,26 +2760,15 @@ void GCodeViewer::render_legend(float& legend_height) ImGui::EndTable(); } -#if ENABLE_NEW_GCODE_VIEWER auto show_mode_button = [this, &imgui, can_show_mode_button](const wxString& label, libvgcode::ETimeMode mode) { -#else - auto show_mode_button = [this, &imgui, can_show_mode_button](const wxString& label, PrintEstimatedStatistics::ETimeMode mode) { -#endif // ENABLE_NEW_GCODE_VIEWER - if (can_show_mode_button(mode)) { + if (can_show_mode_button(mode)) { if (imgui.button(label)) { -#if ENABLE_NEW_GCODE_VIEWER m_viewer.set_time_mode(mode); -#else - m_time_estimate_mode = mode; - if (m_view_type == EViewType::LayerTimeLinear || m_view_type == EViewType::LayerTimeLogarithmic) - refresh_render_paths(false, false); -#endif // ENABLE_NEW_GCODE_VIEWER imgui.set_requires_extra_frame(); } } }; -#if ENABLE_NEW_GCODE_VIEWER switch (time_mode_id) { case libvgcode::ETimeMode::Normal: { show_mode_button(_L("Show stealth mode"), libvgcode::ETimeMode::Stealth); @@ -5884,29 +2778,13 @@ void GCodeViewer::render_legend(float& legend_height) show_mode_button(_L("Show normal mode"), libvgcode::ETimeMode::Normal); break; } -#else - switch (m_time_estimate_mode) { - case PrintEstimatedStatistics::ETimeMode::Normal: { - show_mode_button(_L("Show stealth mode"), PrintEstimatedStatistics::ETimeMode::Stealth); - break; - } - case PrintEstimatedStatistics::ETimeMode::Stealth: { - show_mode_button(_L("Show normal mode"), PrintEstimatedStatistics::ETimeMode::Normal); - break; - } -#endif // ENABLE_NEW_GCODE_VIEWER default : { assert(false); break; } } } // toolbar section -#if ENABLE_NEW_GCODE_VIEWER auto toggle_button = [this, &imgui, icon_size](Preview::OptionType type, const std::string& name, -#else - auto toggle_button = [this, &imgui, icon_size](Preview::OptionType type, const std::string& name, -#endif // ENABLE_NEW_GCODE_VIEWER std::function draw_callback) { -#if ENABLE_NEW_GCODE_VIEWER bool active = false; #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS active = (type == Preview::OptionType::Shells) ? m_shells.visible : m_viewer.is_option_visible(libvgcode::convert(type)); @@ -5919,22 +2797,8 @@ void GCodeViewer::render_legend(float& legend_height) default: { active = m_viewer.is_option_visible(libvgcode::convert(type)); break; } } #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - auto is_flag_set = [](unsigned int flags, unsigned int flag) { - return (flags & (1 << flag)) != 0; - }; - - auto set_flag = [](unsigned int flags, unsigned int flag, bool active) { - return active ? (flags | (1 << flag)) : (flags & ~(1 << flag)); - }; - - unsigned int flags = get_options_visibility_flags(); - unsigned int flag = static_cast(type); - bool active = is_flag_set(flags, flag); -#endif // ENABLE_NEW_GCODE_VIEWER if (imgui.draw_radio_button(name, 1.5f * icon_size, active, draw_callback)) { -#if ENABLE_NEW_GCODE_VIEWER // check whether we need to keep the current visible range libvgcode::Interval view_visible_range = m_viewer.get_view_visible_range(); const libvgcode::Interval view_enabled_range = m_viewer.get_view_enabled_range(); @@ -5964,20 +2828,6 @@ void GCodeViewer::render_legend(float& legend_height) std::optional view_visible_range_min = keep_visible_range ? std::optional{ static_cast(view_visible_range[0]) } : std::nullopt; std::optional view_visible_range_max = keep_visible_range ? std::optional{ static_cast(view_visible_range[1]) } : std::nullopt; wxGetApp().plater()->update_preview_moves_slider(view_visible_range_min, view_visible_range_max); -#else - unsigned int new_flags = set_flag(flags, flag, !active); - set_options_visibility_from_flags(new_flags); - - const unsigned int diff_flags = flags ^ new_flags; - if (m_view_type == GCodeViewer::EViewType::Feedrate && is_flag_set(diff_flags, static_cast(Preview::OptionType::Travel))) - wxGetApp().plater()->refresh_print(); - else { - bool keep_first = m_sequential_view.current.first != m_sequential_view.global.first; - bool keep_last = m_sequential_view.current.last != m_sequential_view.global.last; - wxGetApp().plater()->get_current_canvas3D()->refresh_gcode_preview_render_paths(keep_first, keep_last); - } - wxGetApp().plater()->update_preview_moves_slider(); -#endif // ENABLE_NEW_GCODE_VIEWER } if (ImGui::IsItemHovered()) { @@ -6056,144 +2906,5 @@ void GCodeViewer::render_legend(float& legend_height) ImGui::PopStyleVar(); } -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS -void GCodeViewer::render_statistics() -{ - static const float offset = 275.0f; - - ImGuiWrapper& imgui = *wxGetApp().imgui(); - - auto add_time = [&imgui](const std::string& label, int64_t time) { - imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); - ImGui::SameLine(offset); - imgui.text(std::to_string(time) + " ms (" + get_time_dhms(static_cast(time) * 0.001f) + ")"); - }; - - auto add_memory = [&imgui](const std::string& label, int64_t memory) { - auto format_string = [memory](const std::string& units, float value) { - return std::to_string(memory) + " bytes (" + - Slic3r::float_to_string_decimal_point(float(memory) * value, 3) - + " " + units + ")"; - }; - - static const float kb = 1024.0f; - static const float inv_kb = 1.0f / kb; - static const float mb = 1024.0f * kb; - static const float inv_mb = 1.0f / mb; - static const float gb = 1024.0f * mb; - static const float inv_gb = 1.0f / gb; - imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); - ImGui::SameLine(offset); - if (static_cast(memory) < mb) - imgui.text(format_string("KB", inv_kb)); - else if (static_cast(memory) < gb) - imgui.text(format_string("MB", inv_mb)); - else - imgui.text(format_string("GB", inv_gb)); - }; - - auto add_counter = [&imgui](const std::string& label, int64_t counter) { - imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); - ImGui::SameLine(offset); - imgui.text(std::to_string(counter)); - }; - - imgui.set_next_window_pos(0.5f * wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width(), 0.0f, ImGuiCond_Once, 0.5f, 0.0f); - ImGui::SetNextWindowSizeConstraints({ 300.0f, 100.0f }, { 600.0f, 900.0f }); - imgui.begin(std::string("GCodeViewer Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); - ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); - - if (ImGui::CollapsingHeader("Time")) { - add_time(std::string("GCodeProcessor:"), m_statistics.results_time); - - ImGui::Separator(); - add_time(std::string("Load:"), m_statistics.load_time); - add_time(std::string(" Load vertices:"), m_statistics.load_vertices); - add_time(std::string(" Smooth vertices:"), m_statistics.smooth_vertices); - add_time(std::string(" Load indices:"), m_statistics.load_indices); - add_time(std::string("Refresh:"), m_statistics.refresh_time); - add_time(std::string("Refresh paths:"), m_statistics.refresh_paths_time); - } - - if (ImGui::CollapsingHeader("OpenGL calls")) { - add_counter(std::string("Multi GL_LINES:"), m_statistics.gl_multi_lines_calls_count); - add_counter(std::string("Multi GL_TRIANGLES:"), m_statistics.gl_multi_triangles_calls_count); - add_counter(std::string("GL_TRIANGLES:"), m_statistics.gl_triangles_calls_count); - ImGui::Separator(); - add_counter(std::string("Instanced models:"), m_statistics.gl_instanced_models_calls_count); - add_counter(std::string("Batched models:"), m_statistics.gl_batched_models_calls_count); - } - - if (ImGui::CollapsingHeader("CPU memory")) { - add_memory(std::string("GCodeProcessor results:"), m_statistics.results_size); - - ImGui::Separator(); - add_memory(std::string("Paths:"), m_statistics.paths_size); - add_memory(std::string("Render paths:"), m_statistics.render_paths_size); - add_memory(std::string("Models instances:"), m_statistics.models_instances_size); - } - - if (ImGui::CollapsingHeader("GPU memory")) { - add_memory(std::string("Vertices:"), m_statistics.total_vertices_gpu_size); - add_memory(std::string("Indices:"), m_statistics.total_indices_gpu_size); - add_memory(std::string("Instances:"), m_statistics.total_instances_gpu_size); - ImGui::Separator(); - add_memory(std::string("Max VBuffer:"), m_statistics.max_vbuffer_gpu_size); - add_memory(std::string("Max IBuffer:"), m_statistics.max_ibuffer_gpu_size); - } - - if (ImGui::CollapsingHeader("Other")) { - add_counter(std::string("Travel segments count:"), m_statistics.travel_segments_count); - add_counter(std::string("Wipe segments count:"), m_statistics.wipe_segments_count); - add_counter(std::string("Extrude segments count:"), m_statistics.extrude_segments_count); - add_counter(std::string("Instances count:"), m_statistics.instances_count); - add_counter(std::string("Batched count:"), m_statistics.batched_count); - ImGui::Separator(); - add_counter(std::string("VBuffers count:"), m_statistics.vbuffers_count); - add_counter(std::string("IBuffers count:"), m_statistics.ibuffers_count); - } - - imgui.end(); -} -#endif // ENABLE_GCODE_VIEWER_STATISTICS - -void GCodeViewer::log_memory_used(const std::string& label, int64_t additional) const -{ - if (Slic3r::get_logging_level() >= 5) { - int64_t paths_size = 0; - int64_t render_paths_size = 0; - for (const TBuffer& buffer : m_buffers) { - paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.paths, Path); - render_paths_size += SLIC3R_STDUNORDEREDSET_MEMSIZE(buffer.render_paths, RenderPath); - for (const RenderPath& path : buffer.render_paths) { - render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.sizes, unsigned int); - render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t); - } - } - int64_t layers_size = SLIC3R_STDVEC_MEMSIZE(m_layers.get_zs(), double); - layers_size += SLIC3R_STDVEC_MEMSIZE(m_layers.get_ranges(), Layers::Range); - BOOST_LOG_TRIVIAL(trace) << label - << "(" << format_memsize_MB(additional + paths_size + render_paths_size + layers_size) << ");" - << log_memory_info(); - } -} - -ColorRGBA GCodeViewer::option_color(EMoveType move_type) const -{ - switch (move_type) - { - case EMoveType::Tool_change: { return Options_Colors[static_cast(EOptionsColors::ToolChanges)]; } - case EMoveType::Color_change: { return Options_Colors[static_cast(EOptionsColors::ColorChanges)]; } - case EMoveType::Pause_Print: { return Options_Colors[static_cast(EOptionsColors::PausePrints)]; } - case EMoveType::Custom_GCode: { return Options_Colors[static_cast(EOptionsColors::CustomGCodes)]; } - case EMoveType::Retract: { return Options_Colors[static_cast(EOptionsColors::Retractions)]; } - case EMoveType::Unretract: { return Options_Colors[static_cast(EOptionsColors::Unretractions)]; } - case EMoveType::Seam: { return Options_Colors[static_cast(EOptionsColors::Seams)]; } - default: { return { 0.0f, 0.0f, 0.0f, 1.0f }; } - } -} -#endif // !ENABLE_NEW_GCODE_VIEWER - } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index f5849c2f4d..1f1aa81e68 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -12,11 +12,9 @@ #include "libslic3r/GCode/GCodeProcessor.hpp" #include "GLModel.hpp" -#if ENABLE_NEW_GCODE_VIEWER #include "LibVGCode/LibVGCodeWrapper.hpp" // needed for tech VGCODE_ENABLE_COG_AND_TOOL_MARKERS #include -#endif // ENABLE_NEW_GCODE_VIEWER #include #include @@ -32,359 +30,6 @@ namespace GUI { class GCodeViewer { - using IBufferType = unsigned short; - using VertexBuffer = std::vector; - using MultiVertexBuffer = std::vector; - using IndexBuffer = std::vector; - using MultiIndexBuffer = std::vector; - using InstanceBuffer = std::vector; - using InstanceIdBuffer = std::vector; - using InstancesOffsets = std::vector; - -#if !ENABLE_NEW_GCODE_VIEWER - static const std::array(GCodeExtrusionRole::Count)> Extrusion_Role_Colors; - static const std::vector Options_Colors; - static const std::vector Travel_Colors; - static const std::vector Range_Colors; - static const ColorRGBA Wipe_Color; - static const ColorRGBA Neutral_Color; - - enum class EOptionsColors : unsigned char - { - Retractions, - Unretractions, - Seams, - ToolChanges, - ColorChanges, - PausePrints, - CustomGCodes - }; - - // vbo buffer containing vertices data used to render a specific toolpath type - struct VBuffer - { - enum class EFormat : unsigned char - { - // vertex format: 3 floats -> position.x|position.y|position.z - Position, - // vertex format: 4 floats -> position.x|position.y|position.z|normal.x - PositionNormal1, - // vertex format: 6 floats -> position.x|position.y|position.z|normal.x|normal.y|normal.z - PositionNormal3 - }; - - EFormat format{ EFormat::Position }; -#if ENABLE_GL_CORE_PROFILE - // vaos id - std::vector vaos; -#endif // ENABLE_GL_CORE_PROFILE - // vbos id - std::vector vbos; - // sizes of the buffers, in bytes, used in export to obj - std::vector sizes; - // count of vertices, updated after data are sent to gpu - size_t count{ 0 }; - - size_t data_size_bytes() const { return count * vertex_size_bytes(); } - // We set 65536 as max count of vertices inside a vertex buffer to allow - // to use unsigned short in place of unsigned int for indices in the index buffer, to save memory - size_t max_size_bytes() const { return 65536 * vertex_size_bytes(); } - - size_t vertex_size_floats() const { return position_size_floats() + normal_size_floats(); } - size_t vertex_size_bytes() const { return vertex_size_floats() * sizeof(float); } - - size_t position_offset_floats() const { return 0; } - size_t position_offset_bytes() const { return position_offset_floats() * sizeof(float); } - - size_t position_size_floats() const { return 3; } - size_t position_size_bytes() const { return position_size_floats() * sizeof(float); } - - size_t normal_offset_floats() const { - assert(format == EFormat::PositionNormal1 || format == EFormat::PositionNormal3); - return position_size_floats(); - } - size_t normal_offset_bytes() const { return normal_offset_floats() * sizeof(float); } - - size_t normal_size_floats() const { - switch (format) - { - case EFormat::PositionNormal1: { return 1; } - case EFormat::PositionNormal3: { return 3; } - default: { return 0; } - } - } - size_t normal_size_bytes() const { return normal_size_floats() * sizeof(float); } - - void reset(); - }; - - // buffer containing instances data used to render a toolpaths using instanced or batched models - // instance record format: - // instanced models: 5 floats -> position.x|position.y|position.z|width|height (which are sent to the shader as -> vec3 (offset) + vec2 (scales) in GLModel::render_instanced()) - // batched models: 3 floats -> position.x|position.y|position.z - struct InstanceVBuffer - { - // ranges used to render only subparts of the intances - struct Ranges - { - struct Range - { - // offset in bytes of the 1st instance to render - unsigned int offset; - // count of instances to render - unsigned int count; - // vbo id - unsigned int vbo{ 0 }; - // Color to apply to the instances - ColorRGBA color; - }; - - std::vector ranges; - - void reset(); - }; - - enum class EFormat : unsigned char - { - InstancedModel, - BatchedModel - }; - - EFormat format; - - // cpu-side buffer containing all instances data - InstanceBuffer buffer; - // indices of the moves for all instances - std::vector s_ids; - // position offsets, used to show the correct value of the tool position - InstancesOffsets offsets; - Ranges render_ranges; - - size_t data_size_bytes() const { return s_ids.size() * instance_size_bytes(); } - - size_t instance_size_floats() const { - switch (format) - { - case EFormat::InstancedModel: { return 5; } - case EFormat::BatchedModel: { return 3; } - default: { return 0; } - } - } - size_t instance_size_bytes() const { return instance_size_floats() * sizeof(float); } - - void reset(); - }; - - // ibo buffer containing indices data (for lines/triangles) used to render a specific toolpath type - struct IBuffer - { -#if ENABLE_GL_CORE_PROFILE - // id of the associated vertex array buffer - unsigned int vao{ 0 }; -#endif // ENABLE_GL_CORE_PROFILE - // id of the associated vertex buffer - unsigned int vbo{ 0 }; - // ibo id - unsigned int ibo{ 0 }; - // count of indices, updated after data are sent to gpu - size_t count{ 0 }; - - void reset(); - }; - - // Used to identify different toolpath sub-types inside a IBuffer - struct Path - { - struct Endpoint - { - // index of the buffer in the multibuffer vector - // the buffer type may change: - // it is the vertex buffer while extracting vertices data, - // the index buffer while extracting indices data - unsigned int b_id{ 0 }; - // index into the buffer - size_t i_id{ 0 }; - // move id - size_t s_id{ 0 }; - Vec3f position{ Vec3f::Zero() }; - }; - - struct Sub_Path - { - Endpoint first; - Endpoint last; - - bool contains(size_t s_id) const { - return first.s_id <= s_id && s_id <= last.s_id; - } - }; - - EMoveType type{ EMoveType::Noop }; - GCodeExtrusionRole role{ GCodeExtrusionRole::None }; - float delta_extruder{ 0.0f }; - float height{ 0.0f }; - float width{ 0.0f }; - float feedrate{ 0.0f }; - float fan_speed{ 0.0f }; - float temperature{ 0.0f }; - float volumetric_rate{ 0.0f }; - unsigned char extruder_id{ 0 }; - unsigned char cp_color_id{ 0 }; - std::vector sub_paths; - - bool matches(const GCodeProcessorResult::MoveVertex& move, bool account_for_volumetric_rate) const; - size_t vertices_count() const { - return sub_paths.empty() ? 0 : sub_paths.back().last.s_id - sub_paths.front().first.s_id + 1; - } - bool contains(size_t s_id) const { - return sub_paths.empty() ? false : sub_paths.front().first.s_id <= s_id && s_id <= sub_paths.back().last.s_id; - } - int get_id_of_sub_path_containing(size_t s_id) const { - if (sub_paths.empty()) - return -1; - else { - for (int i = 0; i < static_cast(sub_paths.size()); ++i) { - if (sub_paths[i].contains(s_id)) - return i; - } - return -1; - } - } - void add_sub_path(const GCodeProcessorResult::MoveVertex& move, unsigned int b_id, size_t i_id, size_t s_id) { - Endpoint endpoint = { b_id, i_id, s_id, move.position }; - sub_paths.push_back({ endpoint , endpoint }); - } - }; - - // Used to batch the indices needed to render the paths - struct RenderPath - { - // Index of the parent tbuffer - unsigned char tbuffer_id; - // Render path property - ColorRGBA color; - // Index of the buffer in TBuffer::indices - unsigned int ibuffer_id; - // Render path content - // Index of the path in TBuffer::paths - unsigned int path_id; - std::vector sizes; - std::vector offsets; // use size_t because we need an unsigned integer whose size matches pointer's size (used in the call glMultiDrawElements()) - bool contains(size_t offset) const { - for (size_t i = 0; i < offsets.size(); ++i) { - if (offsets[i] <= offset && offset <= offsets[i] + static_cast(sizes[i] * sizeof(IBufferType))) - return true; - } - return false; - } - }; - struct RenderPathPropertyLower { - bool operator() (const RenderPath &l, const RenderPath &r) const { - if (l.tbuffer_id < r.tbuffer_id) - return true; - if (l.color < r.color) - return true; - else if (l.color > r.color) - return false; - return l.ibuffer_id < r.ibuffer_id; - } - }; - struct RenderPathPropertyEqual { - bool operator() (const RenderPath &l, const RenderPath &r) const { - return l.tbuffer_id == r.tbuffer_id && l.ibuffer_id == r.ibuffer_id && l.color == r.color; - } - }; - - // buffer containing data for rendering a specific toolpath type - struct TBuffer - { - enum class ERenderPrimitiveType : unsigned char - { - Line, - Triangle, - InstancedModel, - BatchedModel - }; - - ERenderPrimitiveType render_primitive_type; - - // buffers for point, line and triangle primitive types - VBuffer vertices; - std::vector indices; - - struct Model - { - GLModel model; - ColorRGBA color; - InstanceVBuffer instances; - GLModel::Geometry data; - - void reset(); - }; - - // contain the buffer for model primitive types - Model model; - - std::string shader; - std::vector paths; - std::vector render_paths; - bool visible{ false }; - - void reset(); - - // b_id index of buffer contained in this->indices - // i_id index of first index contained in this->indices[b_id] - // s_id index of first vertex contained in this->vertices - void add_path(const GCodeProcessorResult::MoveVertex& move, unsigned int b_id, size_t i_id, size_t s_id); - - unsigned int max_vertices_per_segment() const { - switch (render_primitive_type) - { - case ERenderPrimitiveType::Line: { return 2; } - case ERenderPrimitiveType::Triangle: { return 8; } - default: { return 0; } - } - } - - size_t max_vertices_per_segment_size_floats() const { return vertices.vertex_size_floats() * static_cast(max_vertices_per_segment()); } - size_t max_vertices_per_segment_size_bytes() const { return max_vertices_per_segment_size_floats() * sizeof(float); } - unsigned int indices_per_segment() const { - switch (render_primitive_type) - { - case ERenderPrimitiveType::Line: { return 2; } - case ERenderPrimitiveType::Triangle: { return 30; } // 3 indices x 10 triangles - default: { return 0; } - } - } - size_t indices_per_segment_size_bytes() const { return static_cast(indices_per_segment() * sizeof(IBufferType)); } - unsigned int max_indices_per_segment() const { - switch (render_primitive_type) - { - case ERenderPrimitiveType::Line: { return 2; } - case ERenderPrimitiveType::Triangle: { return 36; } // 3 indices x 12 triangles - default: { return 0; } - } - } - size_t max_indices_per_segment_size_bytes() const { return max_indices_per_segment() * sizeof(IBufferType); } - - bool has_data() const { - switch (render_primitive_type) - { - case ERenderPrimitiveType::Line: - case ERenderPrimitiveType::Triangle: { - return !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0; - } - case ERenderPrimitiveType::InstancedModel: { return model.model.is_initialized() && !model.instances.buffer.empty(); } - case ERenderPrimitiveType::BatchedModel: { - return !model.data.vertices.empty() && !model.data.indices.empty() && - !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0; - } - default: { return false; } - } - } - }; -#endif // !ENABLE_NEW_GCODE_VIEWER - // helper to render shells struct Shells { @@ -398,29 +43,20 @@ class GCodeViewer { GLModel m_model; bool m_visible{ false }; -#if ENABLE_NEW_GCODE_VIEWER #if !VGCODE_ENABLE_COG_AND_TOOL_MARKERS // whether or not to render the model with fixed screen size bool m_fixed_screen_size{ true }; #endif // !VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - // whether or not to render the model with fixed screen size - bool m_fixed_screen_size{ true }; -#endif // ENABLE_NEW_GCODE_VIEWER float m_scale_factor{ 1.0f }; double m_total_mass{ 0.0 }; Vec3d m_total_position{ Vec3d::Zero() }; public: -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS void render(bool fixed_screen_size); #else void render(); #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - void render(); -#endif // ENABLE_NEW_GCODE_VIEWER void reset() { m_total_position = Vec3d::Zero(); @@ -431,272 +67,32 @@ class GCodeViewer void set_visible(bool visible) { m_visible = visible; } void add_segment(const Vec3d& v1, const Vec3d& v2, double mass) { -#if ENABLE_NEW_GCODE_VIEWER if (mass > 0.0) { -#else - assert(mass > 0.0); -#endif // ENABLE_NEW_GCODE_VIEWER m_total_position += mass * 0.5 * (v1 + v2); m_total_mass += mass; -#if ENABLE_NEW_GCODE_VIEWER } -#endif // ENABLE_NEW_GCODE_VIEWER } Vec3d cog() const { return (m_total_mass > 0.0) ? (Vec3d)(m_total_position / m_total_mass) : Vec3d::Zero(); } private: -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS void init(bool fixed_screen_size) { #else void init() { #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - void init() { -#endif // ENABLE_NEW_GCODE_VIEWER if (m_model.is_initialized()) return; -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS const float radius = fixed_screen_size ? 10.0f : 1.0f; #else const float radius = m_fixed_screen_size ? 10.0f : 1.0f; #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#else - const float radius = m_fixed_screen_size ? 10.0f : 1.0f; -#endif // ENABLE_NEW_GCODE_VIEWER m_model.init_from(smooth_sphere(32, radius)); } }; -#if !ENABLE_NEW_GCODE_VIEWER - // helper to render extrusion paths - struct Extrusions - { - struct Range - { - enum class EType : unsigned char - { - Linear, - Logarithmic - }; - - float min; - float max; - unsigned int count; - - Range() { reset(); } - - void update_from(const float value) { - if (value != max && value != min) - ++count; - min = std::min(min, value); - max = std::max(max, value); - } - void reset() { min = FLT_MAX; max = -FLT_MAX; count = 0; } - - float step_size(EType type = EType::Linear) const; - ColorRGBA get_color_at(float value, EType type = EType::Linear) const; - }; - - struct Ranges - { - // Color mapping by layer height. - Range height; - // Color mapping by extrusion width. - Range width; - // Color mapping by feedrate. - Range feedrate; - // Color mapping by fan speed. - Range fan_speed; - // Color mapping by volumetric extrusion rate. - Range volumetric_rate; - // Color mapping by extrusion temperature. - Range temperature; - // Color mapping by layer time. - std::array(PrintEstimatedStatistics::ETimeMode::Count)> layer_time; - - void reset() { - height.reset(); - width.reset(); - feedrate.reset(); - fan_speed.reset(); - volumetric_rate.reset(); - temperature.reset(); - for (auto& range : layer_time) { - range.reset(); - } - } - }; - - unsigned int role_visibility_flags{ 0 }; - Ranges ranges; - - void reset_role_visibility_flags() { - role_visibility_flags = 0; - for (uint32_t i = 0; i < uint32_t(GCodeExtrusionRole::Count); ++i) { - role_visibility_flags |= 1 << i; - } - } - - void reset_ranges() { ranges.reset(); } - }; - - class Layers - { - public: - struct Range - { - size_t first{ 0 }; - size_t last{ 0 }; - - bool operator == (const Range& other) const { return first == other.first && last == other.last; } - bool operator != (const Range& other) const { return !operator==(other); } - bool contains(size_t id) const { return first <= id && id <= last; } - }; - - private: - std::vector m_zs; - std::vector m_ranges; - - public: - void append(double z, const Range& range) { - m_zs.emplace_back(z); - m_ranges.emplace_back(range); - } - - void reset() { - m_zs = std::vector(); - m_ranges = std::vector(); - } - - size_t size() const { return m_zs.size(); } - bool empty() const { return m_zs.empty(); } - const std::vector& get_zs() const { return m_zs; } - const std::vector& get_ranges() const { return m_ranges; } - std::vector& get_ranges() { return m_ranges; } - double get_z_at(unsigned int id) const { return (id < m_zs.size()) ? m_zs[id] : 0.0; } - Range get_range_at(unsigned int id) const { return (id < m_ranges.size()) ? m_ranges[id] : Range(); } - int get_l_at(double z) const { - auto iter = std::upper_bound(m_zs.begin(), m_zs.end(), z); - return std::distance(m_zs.begin(), iter); - } - - bool operator != (const Layers& other) const { - if (m_zs != other.m_zs) - return true; - if (m_ranges != other.m_ranges) - return true; - return false; - } - }; - - // used to render the toolpath caps of the current sequential range - // (i.e. when sliding on the horizontal slider) - struct SequentialRangeCap - { - TBuffer* buffer{ nullptr }; -#if ENABLE_GL_CORE_PROFILE - unsigned int vao{ 0 }; -#endif // ENABLE_GL_CORE_PROFILE - unsigned int vbo{ 0 }; - unsigned int ibo{ 0 }; - ColorRGBA color; - - ~SequentialRangeCap(); - bool is_renderable() const { return buffer != nullptr; } - void reset(); - size_t indices_count() const { return 6; } - }; - -#if ENABLE_GCODE_VIEWER_STATISTICS - struct Statistics - { - // time - int64_t results_time{ 0 }; - int64_t load_time{ 0 }; - int64_t load_vertices{ 0 }; - int64_t smooth_vertices{ 0 }; - int64_t load_indices{ 0 }; - int64_t refresh_time{ 0 }; - int64_t refresh_paths_time{ 0 }; - // opengl calls - int64_t gl_multi_lines_calls_count{ 0 }; - int64_t gl_multi_triangles_calls_count{ 0 }; - int64_t gl_triangles_calls_count{ 0 }; - int64_t gl_instanced_models_calls_count{ 0 }; - int64_t gl_batched_models_calls_count{ 0 }; - // memory - int64_t results_size{ 0 }; - int64_t total_vertices_gpu_size{ 0 }; - int64_t total_indices_gpu_size{ 0 }; - int64_t total_instances_gpu_size{ 0 }; - int64_t max_vbuffer_gpu_size{ 0 }; - int64_t max_ibuffer_gpu_size{ 0 }; - int64_t paths_size{ 0 }; - int64_t render_paths_size{ 0 }; - int64_t models_instances_size{ 0 }; - // other - int64_t travel_segments_count{ 0 }; - int64_t wipe_segments_count{ 0 }; - int64_t extrude_segments_count{ 0 }; - int64_t instances_count{ 0 }; - int64_t batched_count{ 0 }; - int64_t vbuffers_count{ 0 }; - int64_t ibuffers_count{ 0 }; - - void reset_all() { - reset_times(); - reset_opengl(); - reset_sizes(); - reset_others(); - } - - void reset_times() { - results_time = 0; - load_time = 0; - load_vertices = 0; - smooth_vertices = 0; - load_indices = 0; - refresh_time = 0; - refresh_paths_time = 0; - } - - void reset_opengl() { - gl_multi_lines_calls_count = 0; - gl_multi_triangles_calls_count = 0; - gl_triangles_calls_count = 0; - gl_instanced_models_calls_count = 0; - gl_batched_models_calls_count = 0; - } - - void reset_sizes() { - results_size = 0; - total_vertices_gpu_size = 0; - total_indices_gpu_size = 0; - total_instances_gpu_size = 0; - max_vbuffer_gpu_size = 0; - max_ibuffer_gpu_size = 0; - paths_size = 0; - render_paths_size = 0; - models_instances_size = 0; - } - - void reset_others() { - travel_segments_count = 0; - wipe_segments_count = 0; - extrude_segments_count = 0; - instances_count = 0; - batched_count = 0; - vbuffers_count = 0; - ibuffers_count = 0; - } - }; -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER - public: struct SequentialView { @@ -760,9 +156,7 @@ public: void set_visible(bool visible) { m_visible = visible; } void render(); -#if ENABLE_NEW_GCODE_VIEWER void render_position_window(const libvgcode::Viewer* viewer); -#endif // ENABLE_NEW_GCODE_VIEWER }; class GCodeWindow @@ -812,59 +206,15 @@ public: void add_gcode_line_to_lines_cache(const std::string& src); }; -#if !ENABLE_NEW_GCODE_VIEWER - struct Endpoints - { - size_t first{ 0 }; - size_t last{ 0 }; - }; - - bool skip_invisible_moves{ false }; - Endpoints endpoints; - Endpoints current; - Endpoints last_current; - Endpoints global; - Vec3f current_position{ Vec3f::Zero() }; - Vec3f current_offset{ Vec3f::Zero() }; -#endif // !ENABLE_NEW_GCODE_VIEWER Marker marker; GCodeWindow gcode_window; -#if ENABLE_NEW_GCODE_VIEWER void render(float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id); -#else - std::vector gcode_ids; - - void render(float legend_height); -#endif // ENABLE_NEW_GCODE_VIEWER }; -#if !ENABLE_NEW_GCODE_VIEWER - enum class EViewType : unsigned char - { - FeatureType, - Height, - Width, - Feedrate, - FanSpeed, - Temperature, - VolumetricRate, - LayerTimeLinear, - LayerTimeLogarithmic, - Tool, - ColorPrint, - Count - }; -#endif // !ENABLE_NEW_GCODE_VIEWER - private: bool m_gl_data_initialized{ false }; unsigned int m_last_result_id{ 0 }; -#if !ENABLE_NEW_GCODE_VIEWER - EViewType m_last_view_type{ EViewType::Count }; - size_t m_moves_count{ 0 }; - std::vector m_buffers{ static_cast(EMoveType::Extrude) }; -#endif // !ENABLE_NEW_GCODE_VIEWER // bounding box of toolpaths BoundingBoxf3 m_paths_bounding_box; // bounding box of shells @@ -873,21 +223,12 @@ private: BoundingBoxf3 m_max_bounding_box; float m_max_print_height{ 0.0f }; float m_z_offset{ 0.0f }; -#if !ENABLE_NEW_GCODE_VIEWER - std::vector m_tool_colors; - Layers m_layers; - std::array m_layers_z_range; - std::vector m_roles; - std::vector m_extruder_ids; - Extrusions m_extrusions; -#endif // !ENABLE_NEW_GCODE_VIEWER size_t m_extruders_count; std::vector m_filament_diameters; std::vector m_filament_densities; SequentialView m_sequential_view; Shells m_shells; COG m_cog; -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS // whether or not to render the cog model with fixed screen size bool m_cog_marker_fixed_screen_size{ true }; @@ -904,10 +245,6 @@ private: libvgcode::EViewType value{ libvgcode::EViewType::FeatureType }; }; ViewTypeCache m_view_type_cache; -#else - EViewType m_view_type{ EViewType::FeatureType }; - bool m_legend_enabled{ true }; -#endif // ENABLE_NEW_GCODE_VIEWER struct LegendResizer { @@ -916,14 +253,6 @@ private: }; LegendResizer m_legend_resizer; PrintEstimatedStatistics m_print_statistics; -#if !ENABLE_NEW_GCODE_VIEWER - PrintEstimatedStatistics::ETimeMode m_time_estimate_mode{ PrintEstimatedStatistics::ETimeMode::Normal }; - std::array m_sequential_range_caps; - std::array, static_cast(PrintEstimatedStatistics::ETimeMode::Count)> m_layers_times; -#if ENABLE_GCODE_VIEWER_STATISTICS - Statistics m_statistics; -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // !ENABLE_NEW_GCODE_VIEWER GCodeProcessorResult::SettingsIds m_settings_ids; std::vector m_custom_gcode_per_print_z; @@ -932,10 +261,8 @@ private: ConflictResultOpt m_conflict_result; -#if ENABLE_NEW_GCODE_VIEWER libvgcode::Viewer m_viewer; bool m_loaded_as_preview{ false }; -#endif // ENABLE_NEW_GCODE_VIEWER public: GCodeViewer(); @@ -944,21 +271,13 @@ public: void init(); // extract rendering data from the given parameters -#if ENABLE_NEW_GCODE_VIEWER void load_as_gcode(const GCodeProcessorResult& gcode_result, const Print& print, const std::vector& str_tool_colors, const std::vector& str_color_print_colors); void load_as_preview(libvgcode::GCodeInputData&& data); -#else - void load(const GCodeProcessorResult& gcode_result, const Print& print); - // recalculate ranges in dependence of what is visible and sets tool/print colors - void refresh(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors); - void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const; -#endif // ENABLE_NEW_GCODE_VIEWER void update_shells_color_by_extruder(const DynamicPrintConfig* config); void reset(); void render(); -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS void render_cog() { if (!m_loaded_as_preview && m_viewer.get_layers_count() > 0) @@ -971,10 +290,6 @@ public: } #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS bool has_data() const { return !m_viewer.get_extrusion_roles().empty(); } -#else - void render_cog() { m_cog.render(); } - bool has_data() const { return !m_roles.empty(); } -#endif // ENABLE_NEW_GCODE_VIEWER bool can_export_toolpaths() const; @@ -994,7 +309,6 @@ public: return m_max_bounding_box; } -#if ENABLE_NEW_GCODE_VIEWER std::vector get_layers_zs() const { const std::vector zs = m_viewer.get_layers_zs(); std::vector ret; @@ -1002,23 +316,17 @@ public: return ret; } std::vector get_layers_times() const { return m_viewer.get_layers_estimated_times(); } -#else - const std::vector& get_layers_zs() const { return m_layers.get_zs(); } -#endif // ENABLE_NEW_GCODE_VIEWER const SequentialView& get_sequential_view() const { return m_sequential_view; } void update_sequential_view_current(unsigned int first, unsigned int last); -#if ENABLE_NEW_GCODE_VIEWER const libvgcode::Interval& get_gcode_view_full_range() const { return m_viewer.get_view_full_range(); } const libvgcode::Interval& get_gcode_view_enabled_range() const { return m_viewer.get_view_enabled_range(); } const libvgcode::Interval& get_gcode_view_visible_range() const { return m_viewer.get_view_visible_range(); } const libvgcode::PathVertex& get_gcode_vertex_at(size_t id) const { return m_viewer.get_vertex_at(id); } -#endif // ENABLE_NEW_GCODE_VIEWER bool is_contained_in_bed() const { return m_contained_in_bed; } -#if ENABLE_NEW_GCODE_VIEWER void set_view_type(libvgcode::EViewType type) { m_viewer.set_view_type((m_view_type_cache.load && m_view_type_cache.value != type) ? m_view_type_cache.value : type); const libvgcode::EViewType view_type = get_view_type(); @@ -1031,31 +339,11 @@ public: void enable_view_type_cache_write(bool enable) { m_view_type_cache.write = enable; } bool is_view_type_cache_load_enabled() const { return m_view_type_cache.load; } bool is_view_type_cache_write_enabled() const { return m_view_type_cache.write; } -#else - EViewType get_view_type() const { return m_view_type; } - void set_view_type(EViewType type) { - if (type == EViewType::Count) - type = EViewType::FeatureType; - - m_view_type = type; - } - bool is_toolpath_move_type_visible(EMoveType type) const; - void set_toolpath_move_type_visible(EMoveType type, bool visible); - unsigned int get_toolpath_role_visibility_flags() const { return m_extrusions.role_visibility_flags; } - void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; } - unsigned int get_options_visibility_flags() const; - void set_options_visibility_from_flags(unsigned int flags); -#endif // ENABLE_NEW_GCODE_VIEWER void set_layers_z_range(const std::array& layers_z_range); -#if ENABLE_NEW_GCODE_VIEWER bool is_legend_shown() const { return m_legend_visible && m_legend_enabled; } void show_legend(bool show) { m_legend_visible = show; } void enable_legend(bool enable) { m_legend_enabled = enable; } -#else - bool is_legend_enabled() const { return m_legend_enabled; } - void enable_legend(bool enable) { m_legend_enabled = enable; } -#endif // ENABLE_NEW_GCODE_VIEWER void set_force_shells_visible(bool visible) { m_shells.force_visible = visible; } @@ -1063,9 +351,6 @@ public: void toggle_gcode_window_visibility() { m_sequential_view.gcode_window.toggle_visibility(); } -#if !ENABLE_NEW_GCODE_VIEWER - std::vector& get_custom_gcode_per_print_z() { return m_custom_gcode_per_print_z; } -#endif // !ENABLE_NEW_GCODE_VIEWER size_t get_extruders_count() { return m_extruders_count; } void invalidate_legend() { m_legend_resizer.reset(); } @@ -1074,32 +359,16 @@ public: void load_shells(const Print& print); -#if ENABLE_NEW_GCODE_VIEWER #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS float get_cog_marker_scale_factor() const { return m_viewer.get_cog_marker_scale_factor(); } void set_cog_marker_scale_factor(float factor) { return m_viewer.set_cog_marker_scale_factor(factor); } #endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS -#endif // ENABLE_NEW_GCODE_VIEWER private: -#if !ENABLE_NEW_GCODE_VIEWER - void load_toolpaths(const GCodeProcessorResult& gcode_result); -#endif // !ENABLE_NEW_GCODE_VIEWER void load_wipetower_shell(const Print& print); void render_toolpaths(); void render_shells(); void render_legend(float& legend_height); -#if !ENABLE_NEW_GCODE_VIEWER -#if ENABLE_GCODE_VIEWER_STATISTICS - void render_statistics(); -#endif // ENABLE_GCODE_VIEWER_STATISTICS - bool is_visible(GCodeExtrusionRole role) const { - return role < GCodeExtrusionRole::Count && (m_extrusions.role_visibility_flags & (1 << int(role))) != 0; - } - bool is_visible(const Path& path) const { return is_visible(path.role); } - void log_memory_used(const std::string& label, int64_t additional = 0) const; - ColorRGBA option_color(EMoveType move_type) const; -#endif // !ENABLE_NEW_GCODE_VIEWER }; } // namespace GUI diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 2bb1bf060b..30622434c1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -89,11 +89,6 @@ static const Slic3r::ColorRGBA DEFAULT_BG_LIGHT_COLOR = { 0.753f, 0.753f, 0.753f static const Slic3r::ColorRGBA ERROR_BG_DARK_COLOR = { 0.478f, 0.192f, 0.039f, 1.0f }; static const Slic3r::ColorRGBA ERROR_BG_LIGHT_COLOR = { 0.753f, 0.192f, 0.039f, 1.0f }; -#if !ENABLE_NEW_GCODE_VIEWER -// Number of floats -static constexpr const size_t MAX_VERTEX_BUFFER_SIZE = 131072 * 6; // 3.15MB -#endif // !ENABLE_NEW_GCODE_VIEWER - #define SHOW_IMGUI_DEMO_WINDOW #ifdef SHOW_IMGUI_DEMO_WINDOW static bool show_imgui_demo_window = false; @@ -176,16 +171,6 @@ bool GLCanvas3D::LayersEditing::is_allowed() const return wxGetApp().get_shader("variable_layer_height") != nullptr && m_z_texture_id > 0; } -bool GLCanvas3D::LayersEditing::is_enabled() const -{ - return m_enabled; -} - -void GLCanvas3D::LayersEditing::set_enabled(bool enabled) -{ - m_enabled = is_allowed() && enabled; -} - float GLCanvas3D::LayersEditing::s_overlay_window_width; void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) @@ -624,7 +609,7 @@ void GLCanvas3D::LayersEditing::generate_layer_height_texture() *m_slicing_parameters, Slic3r::generate_object_layers(*m_slicing_parameters, m_layer_height_profile), m_layers_texture.data.data(), m_layers_texture.height, m_layers_texture.width, level_of_detail_2nd_level); - m_layers_texture.valid = true; + m_layers_texture.valid = true; } void GLCanvas3D::LayersEditing::accept_changes(GLCanvas3D& canvas) @@ -642,8 +627,8 @@ void GLCanvas3D::LayersEditing::accept_changes(GLCanvas3D& canvas) void GLCanvas3D::LayersEditing::update_slicing_parameters() { - if (m_slicing_parameters == nullptr) { - m_slicing_parameters = new SlicingParameters(); + if (m_slicing_parameters == nullptr) { + m_slicing_parameters = new SlicingParameters(); *m_slicing_parameters = PrintObject::slicing_parameters(*m_config, *m_model_object, m_object_max_z); } } @@ -664,23 +649,6 @@ const Point GLCanvas3D::Mouse::Drag::Invalid_2D_Point(INT_MAX, INT_MAX); const Vec3d GLCanvas3D::Mouse::Drag::Invalid_3D_Point(DBL_MAX, DBL_MAX, DBL_MAX); const int GLCanvas3D::Mouse::Drag::MoveThresholdPx = 5; -GLCanvas3D::Mouse::Drag::Drag() - : start_position_2D(Invalid_2D_Point) - , start_position_3D(Invalid_3D_Point) - , move_volume_idx(-1) - , move_requires_threshold(false) - , move_start_threshold_position_2D(Invalid_2D_Point) -{ -} - -GLCanvas3D::Mouse::Mouse() - : dragging(false) - , position(DBL_MAX, DBL_MAX) - , scene_position(DBL_MAX, DBL_MAX, DBL_MAX) - , ignore_left_up(false) -{ -} - void GLCanvas3D::Labels::render(const std::vector& sorted_instances) const { if (!m_enabled || !is_shown()) @@ -1319,41 +1287,39 @@ bool GLCanvas3D::is_arrange_alignment_enabled() const } GLCanvas3D::GLCanvas3D(wxGLCanvas *canvas, Bed3D &bed) - : m_canvas(canvas), - m_context(nullptr), - m_bed(bed) + : m_canvas(canvas) + , m_context(nullptr) + , m_bed(bed) #if ENABLE_RETINA_GL - , - m_retina_helper(nullptr) -#endif - , - m_in_render(false), - m_main_toolbar(GLToolbar::Normal, "Main"), - m_undoredo_toolbar(GLToolbar::Normal, "Undo_Redo"), - m_gizmos(*this), - m_use_clipping_planes(false), - m_sidebar_field(""), - m_extra_frame_requested(false), - m_config(nullptr), - m_process(nullptr), - m_model(nullptr), - m_dirty(true), - m_initialized(false), - m_apply_zoom_to_volumes_filter(false), - m_picking_enabled(false), - m_moving_enabled(false), - m_dynamic_background_enabled(false), - m_multisample_allowed(false), - m_moving(false), - m_tab_down(false), - m_cursor_type(Standard), - m_reload_delayed(false), - m_render_sla_auxiliaries(true), - m_labels(*this), - m_slope(m_volumes), - m_sla_view(*this), - m_arrange_settings_db{wxGetApp().app_config}, - m_arrange_settings_dialog{wxGetApp().imgui(), &m_arrange_settings_db} + , m_retina_helper(nullptr) +#endif // ENABLE_RETINA_GL + , m_in_render(false) + , m_main_toolbar(GLToolbar::Normal, "Main") + , m_undoredo_toolbar(GLToolbar::Normal, "Undo_Redo") + , m_gizmos(*this) + , m_use_clipping_planes(false) + , m_sidebar_field("") + , m_extra_frame_requested(false) + , m_config(nullptr) + , m_process(nullptr) + , m_model(nullptr) + , m_dirty(true) + , m_initialized(false) + , m_apply_zoom_to_volumes_filter(false) + , m_picking_enabled(false) + , m_moving_enabled(false) + , m_dynamic_background_enabled(false) + , m_multisample_allowed(false) + , m_moving(false) + , m_tab_down(false) + , m_cursor_type(Standard) + , m_reload_delayed(false) + , m_render_sla_auxiliaries(true) + , m_labels(*this) + , m_slope(m_volumes) + , m_sla_view(*this) + , m_arrange_settings_db{wxGetApp().app_config} + , m_arrange_settings_dialog{wxGetApp().imgui(), &m_arrange_settings_db} { if (m_canvas != nullptr) { m_timer.SetOwner(m_canvas); @@ -1425,16 +1391,6 @@ bool GLCanvas3D::init() return true; } -void GLCanvas3D::set_as_dirty() -{ - m_dirty = true; -} - -unsigned int GLCanvas3D::get_volumes_count() const -{ - return (unsigned int)m_volumes.volumes.size(); -} - void GLCanvas3D::reset_volumes() { if (!m_initialized) @@ -1460,11 +1416,6 @@ ModelInstanceEPrintVolumeState GLCanvas3D::check_volumes_outside_state(bool sele return state; } -void GLCanvas3D::check_volumes_outside_state(GLVolumeCollection& volumes) const -{ - check_volumes_outside_state(volumes, nullptr, false); -} - bool GLCanvas3D::check_volumes_outside_state(GLVolumeCollection& volumes, ModelInstanceEPrintVolumeState* out_state, bool selection_only) const { auto volume_below = [](GLVolume& volume) -> bool @@ -1676,11 +1627,6 @@ void GLCanvas3D::set_config(const DynamicPrintConfig* config) } } -void GLCanvas3D::set_process(BackgroundSlicingProcess *process) -{ - m_process = process; -} - void GLCanvas3D::set_model(Model* model) { m_model = model; @@ -1720,16 +1666,6 @@ BoundingBoxf3 GLCanvas3D::scene_bounding_box() const return bb; } -bool GLCanvas3D::is_layers_editing_enabled() const -{ - return m_layers_editing.is_enabled(); -} - -bool GLCanvas3D::is_layers_editing_allowed() const -{ - return m_layers_editing.is_allowed(); -} - void GLCanvas3D::reset_layer_height_profile() { wxGetApp().plater()->take_snapshot(_L("Variable layer height - Reset")); @@ -1754,64 +1690,12 @@ void GLCanvas3D::smooth_layer_height_profile(const HeightProfileSmoothingParams& m_dirty = true; } -bool GLCanvas3D::is_reload_delayed() const -{ - return m_reload_delayed; -} - void GLCanvas3D::enable_layers_editing(bool enable) { m_layers_editing.set_enabled(enable); set_as_dirty(); } -#if !ENABLE_NEW_GCODE_VIEWER -void GLCanvas3D::enable_legend_texture(bool enable) -{ - m_gcode_viewer.enable_legend(enable); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - -void GLCanvas3D::enable_picking(bool enable) -{ - m_picking_enabled = enable; -} - -void GLCanvas3D::enable_moving(bool enable) -{ - m_moving_enabled = enable; -} - -void GLCanvas3D::enable_gizmos(bool enable) -{ - m_gizmos.set_enabled(enable); -} - -void GLCanvas3D::enable_selection(bool enable) -{ - m_selection.set_enabled(enable); -} - -void GLCanvas3D::enable_main_toolbar(bool enable) -{ - m_main_toolbar.set_enabled(enable); -} - -void GLCanvas3D::enable_undoredo_toolbar(bool enable) -{ - m_undoredo_toolbar.set_enabled(enable); -} - -void GLCanvas3D::enable_dynamic_background(bool enable) -{ - m_dynamic_background_enabled = enable; -} - -void GLCanvas3D::allow_multisample(bool allow) -{ - m_multisample_allowed = allow; -} - void GLCanvas3D::zoom_to_bed() { BoundingBoxf3 box = m_bed.build_volume().bounding_volume(); @@ -2108,11 +1992,6 @@ void GLCanvas3D::deselect_all() post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); } -void GLCanvas3D::delete_selected() -{ - m_selection.erase(); -} - void GLCanvas3D::ensure_on_bed(unsigned int object_idx, bool allow_negative_z) { if (allow_negative_z) @@ -2141,43 +2020,6 @@ void GLCanvas3D::ensure_on_bed(unsigned int object_idx, bool allow_negative_z) } } - -#if ENABLE_NEW_GCODE_VIEWER -std::vector GLCanvas3D::get_gcode_layers_zs() const -#else -const std::vector& GLCanvas3D::get_gcode_layers_zs() const -#endif // ENABLE_NEW_GCODE_VIEWER -{ - return m_gcode_viewer.get_layers_zs(); -} - -#if !ENABLE_NEW_GCODE_VIEWER -std::vector GLCanvas3D::get_volumes_print_zs(bool active_only) const -{ - return m_volumes.get_current_print_zs(active_only); -} - -void GLCanvas3D::set_gcode_options_visibility_from_flags(unsigned int flags) -{ - m_gcode_viewer.set_options_visibility_from_flags(flags); -} - -void GLCanvas3D::set_toolpath_role_visibility_flags(unsigned int flags) -{ - m_gcode_viewer.set_toolpath_role_visibility_flags(flags); -} - -void GLCanvas3D::set_toolpath_view_type(GCodeViewer::EViewType type) -{ - m_gcode_viewer.set_view_type(type); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - -void GLCanvas3D::set_volumes_z_range(const std::array& range) -{ - m_volumes.set_range(range[0] - 1e-6, range[1] + 1e-6); -} - void GLCanvas3D::set_toolpaths_z_range(const std::array& range) { if (m_gcode_viewer.has_data()) @@ -2687,7 +2529,6 @@ void GLCanvas3D::load_gcode_shells() m_gcode_viewer.set_force_shells_visible(true); } -#if ENABLE_NEW_GCODE_VIEWER void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors, const std::vector& str_color_print_colors) { @@ -2697,32 +2538,15 @@ void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, co m_gcode_viewer.set_view_type(m_gcode_viewer.get_view_type()); m_gcode_viewer.load_as_gcode(gcode_result, *this->fff_print(), str_tool_colors, str_color_print_colors); m_gcode_layers_times_cache = m_gcode_viewer.get_layers_times(); -#else -void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors) -{ - m_gcode_viewer.load(gcode_result, *this->fff_print()); -#endif // ENABLE_NEW_GCODE_VIEWER if (wxGetApp().is_editor()) { _set_warning_notification_if_needed(EWarning::ToolpathOutside); _set_warning_notification_if_needed(EWarning::GCodeConflict); } -#if !ENABLE_NEW_GCODE_VIEWER - m_gcode_viewer.refresh(gcode_result, str_tool_colors); -#endif // !ENABLE_NEW_GCODE_VIEWER set_as_dirty(); request_extra_frame(); } -#if !ENABLE_NEW_GCODE_VIEWER -void GLCanvas3D::refresh_gcode_preview_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) -{ - m_gcode_viewer.refresh_render_paths(keep_sequential_current_first, keep_sequential_current_last); - set_as_dirty(); - request_extra_frame(); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - void GLCanvas3D::load_sla_preview() { const SLAPrint* print = sla_print(); @@ -2737,12 +2561,8 @@ void GLCanvas3D::load_sla_preview() } } -#if ENABLE_NEW_GCODE_VIEWER void GLCanvas3D::load_preview(const std::vector& str_tool_colors, const std::vector& str_color_print_colors, const std::vector& color_print_values) -#else -void GLCanvas3D::load_preview(const std::vector& str_tool_colors, const std::vector& color_print_values) -#endif // ENABLE_NEW_GCODE_VIEWER { const Print *print = this->fff_print(); if (print == nullptr) @@ -2750,7 +2570,6 @@ void GLCanvas3D::load_preview(const std::vector& str_tool_colors, c _set_current(); -#if ENABLE_NEW_GCODE_VIEWER libvgcode::GCodeInputData data = libvgcode::convert(*print, str_tool_colors, str_color_print_colors, color_print_values, static_cast(wxGetApp().extruders_edited_cnt())); @@ -2760,17 +2579,6 @@ void GLCanvas3D::load_preview(const std::vector& str_tool_colors, c m_gcode_viewer.enable_view_type_cache_load(false); m_gcode_viewer.set_view_type(libvgcode::EViewType::FeatureType); m_gcode_viewer.load_as_preview(std::move(data)); -#else - // Release OpenGL data before generating new data. - this->reset_volumes(); - - const BuildVolume& build_volume = m_bed.build_volume(); - _load_print_toolpaths(build_volume); - _load_wipe_tower_toolpaths(build_volume, str_tool_colors); - for (const PrintObject* object : print->objects()) - _load_print_object_toolpaths(*object, build_volume, str_tool_colors, color_print_values); -#endif // ENABLE_NEW_GCODE_VIEWER - m_gcode_viewer.set_force_shells_visible(false); _set_warning_notification_if_needed(EWarning::ToolpathOutside); } @@ -2838,11 +2646,6 @@ void GLCanvas3D::unbind_event_handlers() m_event_handlers_bound = false; } } - -void GLCanvas3D::on_size(wxSizeEvent& evt) -{ - m_dirty = true; -} void GLCanvas3D::on_idle(wxIdleEvent& evt) { @@ -3194,9 +2997,8 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) const int keyCode = evt.GetKeyCode(); auto imgui = wxGetApp().imgui(); - if (imgui->update_key_data(evt)) { + if (imgui->update_key_data(evt)) render(); - } else { if (!m_gizmos.on_key(evt)) { if (evt.GetEventType() == wxEVT_KEY_UP) { @@ -4537,11 +4339,6 @@ void GLCanvas3D::set_cursor(ECursorType type) } } -void GLCanvas3D::msw_rescale() -{ - m_gcode_viewer.invalidate_legend(); -} - void GLCanvas3D::update_tooltip_for_settings_item_in_main_toolbar() { std::string new_tooltip = _u8L("Switch to Settings") + @@ -4552,16 +4349,6 @@ void GLCanvas3D::update_tooltip_for_settings_item_in_main_toolbar() m_main_toolbar.set_tooltip(get_main_toolbar_item_id("settings"), new_tooltip); } -bool GLCanvas3D::has_toolpaths_to_export() const -{ - return m_gcode_viewer.can_export_toolpaths(); -} - -void GLCanvas3D::export_toolpaths_to_obj(const char* filename) const -{ - m_gcode_viewer.export_toolpaths_to_obj(filename); -} - void GLCanvas3D::mouse_up_cleanup() { m_moving = false; @@ -4801,7 +4588,6 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) bool GLCanvas3D::_render_arrange_menu(float pos_x) { m_arrange_settings_dialog.render(pos_x, m_main_toolbar.get_height()); - return true; } @@ -6017,7 +5803,7 @@ void GLCanvas3D::_render_bed(const Transform3d& view_matrix, const Transform3d& void GLCanvas3D::_render_bed_axes() { - m_bed.render_axes(); + m_bed.render_axes(); } void GLCanvas3D::_render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom) @@ -6136,16 +5922,6 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) m_camera_clipping_plane = ClippingPlane::ClipsNothing(); } -void GLCanvas3D::_render_gcode() -{ - m_gcode_viewer.render(); -} - -void GLCanvas3D::_render_gcode_cog() -{ - m_gcode_viewer.render_cog(); -} - void GLCanvas3D::_render_selection() { float scale_factor = 1.0; @@ -6185,13 +5961,6 @@ void GLCanvas3D::_render_sequential_clearance() m_sequential_print_clearance.render(); } -#if ENABLE_RENDER_SELECTION_CENTER -void GLCanvas3D::_render_selection_center() -{ - m_selection.render_center(m_gizmos.is_dragging()); -} -#endif // ENABLE_RENDER_SELECTION_CENTER - void GLCanvas3D::_check_and_update_toolbar_icon_scale() { // Don't update a toolbar scale, when we are on a Preview @@ -6305,11 +6074,6 @@ void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const glsafe(::glEnable(GL_CULL_FACE)); } -void GLCanvas3D::_render_current_gizmo() const -{ - m_gizmos.render_current_gizmo(); -} - void GLCanvas3D::_render_gizmos_overlay() { #if ENABLE_RETINA_GL @@ -6599,11 +6363,6 @@ void GLCanvas3D::_render_sla_slices() } } -void GLCanvas3D::_render_selection_sidebar_hints() -{ - m_selection.render_sidebar_hints(m_sidebar_field); -} - void GLCanvas3D::_update_volumes_hover_state() { // skip update if the Gizmo Measure is active @@ -6731,578 +6490,6 @@ Vec3d GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos) return (std::abs(ray.unit_vector().z()) < EPSILON) ? ray.a : ray.intersect_plane(0.0); } -void GLCanvas3D::_start_timer() -{ - m_timer.Start(100, wxTIMER_CONTINUOUS); -} - -void GLCanvas3D::_stop_timer() -{ - m_timer.Stop(); -} - -#if !ENABLE_NEW_GCODE_VIEWER -void GLCanvas3D::_load_print_toolpaths(const BuildVolume &build_volume) -{ - const Print *print = this->fff_print(); - if (print == nullptr) - return; - - if (! print->is_step_done(psSkirtBrim)) - return; - - if (!print->has_skirt() && !print->has_brim()) - return; - - const ColorRGBA color = ColorRGBA::GREENISH(); - - // number of skirt layers - size_t total_layer_count = 0; - for (const PrintObject* print_object : print->objects()) { - total_layer_count = std::max(total_layer_count, print_object->total_layer_count()); - } - size_t skirt_height = print->has_infinite_skirt() ? total_layer_count : std::min(print->config().skirt_height.value, total_layer_count); - if (skirt_height == 0 && print->has_brim()) - skirt_height = 1; - - // Get first skirt_height layers. - //FIXME This code is fishy. It may not work for multiple objects with different layering due to variable layer height feature. - // This is not critical as this is just an initial preview. - const PrintObject* highest_object = *std::max_element(print->objects().begin(), print->objects().end(), [](auto l, auto r){ return l->layers().size() < r->layers().size(); }); - std::vector print_zs; - print_zs.reserve(skirt_height * 2); - for (size_t i = 0; i < std::min(skirt_height, highest_object->layers().size()); ++ i) - print_zs.emplace_back(float(highest_object->layers()[i]->print_z)); - // Only add skirt for the raft layers. - for (size_t i = 0; i < std::min(skirt_height, std::min(highest_object->slicing_parameters().raft_layers(), highest_object->support_layers().size())); ++ i) - print_zs.emplace_back(float(highest_object->support_layers()[i]->print_z)); - sort_remove_duplicates(print_zs); - skirt_height = std::min(skirt_height, print_zs.size()); - print_zs.erase(print_zs.begin() + skirt_height, print_zs.end()); - - GLVolume* volume = m_volumes.new_toolpath_volume(color); - GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; - for (size_t i = 0; i < skirt_height; ++ i) { - volume->print_zs.emplace_back(print_zs[i]); - volume->offsets.emplace_back(init_data.indices_count()); - if (i == 0) - _3DScene::extrusionentity_to_verts(print->brim(), print_zs[i], Point(0, 0), init_data); - _3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), init_data); - // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. - if (init_data.vertices_size_bytes() >= MAX_VERTEX_BUFFER_SIZE) { - volume->model.init_from(std::move(init_data)); - volume->is_outside = !contains(build_volume, volume->model); - volume = m_volumes.new_toolpath_volume(volume->color); - init_data = GLModel::Geometry(); - } - } - init_data = GLModel::Geometry(); - if (init_data.is_empty()) { - delete volume; - m_volumes.volumes.pop_back(); - } - else { - volume->model.init_from(std::move(init_data)); - volume->is_outside = !contains(build_volume, volume->model); - } -} - -void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const BuildVolume& build_volume, const std::vector& str_tool_colors, const std::vector& color_print_values) -{ - std::vector tool_colors; - decode_colors(str_tool_colors, tool_colors); - - struct Ctxt - { - const PrintInstances *shifted_copies; - std::vector layers; - bool has_perimeters; - bool has_infill; - bool has_support; - const std::vector* tool_colors; - bool is_single_material_print; - int extruders_cnt; - const std::vector* color_print_values; - - static ColorRGBA color_perimeters() { return ColorRGBA::YELLOW(); } - static ColorRGBA color_infill() { return ColorRGBA::REDISH(); } - static ColorRGBA color_support() { return ColorRGBA::GREENISH(); } - static ColorRGBA color_pause_or_custom_code() { return ColorRGBA::GRAY(); } - - // For cloring by a tool, return a parsed color. - bool color_by_tool() const { return tool_colors != nullptr; } - size_t number_tools() const { return color_by_tool() ? tool_colors->size() : 0; } - const ColorRGBA& color_tool(size_t tool) const { return (*tool_colors)[tool]; } - - // For coloring by a color_print(M600), return a parsed color. - bool color_by_color_print() const { return color_print_values!=nullptr; } - const size_t color_print_color_idx_by_layer_idx(const size_t layer_idx) const { - const CustomGCode::Item value{layers[layer_idx]->print_z + EPSILON, CustomGCode::Custom, 0, ""}; - auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value); - return (it - color_print_values->begin()) % number_tools(); - } - - const size_t color_print_color_idx_by_layer_idx_and_extruder(const size_t layer_idx, const int extruder) const - { - const coordf_t print_z = layers[layer_idx]->print_z; - - auto it = std::find_if(color_print_values->begin(), color_print_values->end(), - [print_z](const CustomGCode::Item& code) - { return fabs(code.print_z - print_z) < EPSILON; }); - if (it != color_print_values->end()) { - CustomGCode::Type type = it->type; - // pause print or custom Gcode - if (type == CustomGCode::PausePrint || - (type != CustomGCode::ColorChange && type != CustomGCode::ToolChange)) - return number_tools()-1; // last color item is a gray color for pause print or custom G-code - - // change tool (extruder) - if (type == CustomGCode::ToolChange) - return get_color_idx_for_tool_change(it, extruder); - // change color for current extruder - if (type == CustomGCode::ColorChange) { - int color_idx = get_color_idx_for_color_change(it, extruder); - if (color_idx >= 0) - return color_idx; - } - } - - const CustomGCode::Item value{print_z + EPSILON, CustomGCode::Custom, 0, ""}; - it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value); - while (it != color_print_values->begin()) { - --it; - // change color for current extruder - if (it->type == CustomGCode::ColorChange) { - int color_idx = get_color_idx_for_color_change(it, extruder); - if (color_idx >= 0) - return color_idx; - } - // change tool (extruder) - if (it->type == CustomGCode::ToolChange) - return get_color_idx_for_tool_change(it, extruder); - } - - return std::min(extruders_cnt - 1, std::max(extruder - 1, 0));; - } - - private: - int get_m600_color_idx(std::vector::const_iterator it) const - { - int shift = 0; - while (it != color_print_values->begin()) { - --it; - if (it->type == CustomGCode::ColorChange) - shift++; - } - return extruders_cnt + shift; - } - - int get_color_idx_for_tool_change(std::vector::const_iterator it, const int extruder) const - { - const int current_extruder = it->extruder == 0 ? extruder : it->extruder; - if (number_tools() == size_t(extruders_cnt + 1)) // there is no one "M600" - return std::min(extruders_cnt - 1, std::max(current_extruder - 1, 0)); - - auto it_n = it; - while (it_n != color_print_values->begin()) { - --it_n; - if (it_n->type == CustomGCode::ColorChange && it_n->extruder == current_extruder) - return get_m600_color_idx(it_n); - } - - return std::min(extruders_cnt - 1, std::max(current_extruder - 1, 0)); - } - - int get_color_idx_for_color_change(std::vector::const_iterator it, const int extruder) const - { - if (extruders_cnt == 1) - return get_m600_color_idx(it); - - auto it_n = it; - bool is_tool_change = false; - while (it_n != color_print_values->begin()) { - --it_n; - if (it_n->type == CustomGCode::ToolChange) { - is_tool_change = true; - if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder)) - return get_m600_color_idx(it); - break; - } - } - if (!is_tool_change && it->extruder == extruder) - return get_m600_color_idx(it); - - return -1; - } - - } ctxt; - - ctxt.has_perimeters = print_object.is_step_done(posPerimeters); - ctxt.has_infill = print_object.is_step_done(posInfill); - ctxt.has_support = print_object.is_step_done(posSupportMaterial); - ctxt.tool_colors = tool_colors.empty() ? nullptr : &tool_colors; - ctxt.color_print_values = color_print_values.empty() ? nullptr : &color_print_values; - ctxt.is_single_material_print = this->fff_print()->extruders().size()==1; - ctxt.extruders_cnt = wxGetApp().extruders_edited_cnt(); - - ctxt.shifted_copies = &print_object.instances(); - - // order layers by print_z - { - size_t nlayers = 0; - if (ctxt.has_perimeters || ctxt.has_infill) - nlayers = print_object.layers().size(); - if (ctxt.has_support) - nlayers += print_object.support_layers().size(); - ctxt.layers.reserve(nlayers); - } - if (ctxt.has_perimeters || ctxt.has_infill) - for (const Layer *layer : print_object.layers()) - ctxt.layers.emplace_back(layer); - if (ctxt.has_support) - for (const Layer *layer : print_object.support_layers()) - ctxt.layers.emplace_back(layer); - std::sort(ctxt.layers.begin(), ctxt.layers.end(), [](const Layer *l1, const Layer *l2) { return l1->print_z < l2->print_z; }); - - // Maximum size of an allocation block: 32MB / sizeof(float) - BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - start" << m_volumes.log_memory_info() << log_memory_info(); - - const bool is_selected_separate_extruder = m_selected_extruder > 0 && ctxt.color_by_color_print(); - - //FIXME Improve the heuristics for a grain size. - size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1)); - tbb::spin_mutex new_volume_mutex; - auto new_volume = [this, &new_volume_mutex](const ColorRGBA& color) { - // Allocate the volume before locking. - GLVolume *volume = new GLVolume(color); - volume->is_extrusion_path = true; - // to prevent sending data to gpu (in the main thread) while - // editing the model geometry - volume->model.disable_render(); - tbb::spin_mutex::scoped_lock lock; - // Lock by ROII, so if the emplace_back() fails, the lock will be released. - lock.acquire(new_volume_mutex); - m_volumes.volumes.emplace_back(volume); - lock.release(); - return volume; - }; - const size_t volumes_cnt_initial = m_volumes.volumes.size(); - // Limit the number of threads as the code below does not scale well due to memory pressure. - // (most of the time is spent in malloc / free / memmove) - // Not using all the threads leaves some of the threads to G-code generator. - tbb::task_arena limited_arena(std::min(tbb::this_task_arena::max_concurrency(), 4)); - limited_arena.execute([&ctxt, grain_size, &new_volume, is_selected_separate_extruder, this]{ - tbb::parallel_for( - tbb::blocked_range(0, ctxt.layers.size(), grain_size), - [&ctxt, &new_volume, is_selected_separate_extruder, this](const tbb::blocked_range& range) { - GLVolumePtrs vols; - std::vector geometries; - auto select_geometry = [&ctxt, &geometries](size_t layer_idx, int extruder, int feature) -> GLModel::Geometry& { - return geometries[ctxt.color_by_color_print() ? - ctxt.color_print_color_idx_by_layer_idx_and_extruder(layer_idx, extruder) : - ctxt.color_by_tool() ? - std::min(ctxt.number_tools() - 1, std::max(extruder - 1, 0)) : - feature - ]; - }; - if (ctxt.color_by_color_print() || ctxt.color_by_tool()) { - for (size_t i = 0; i < ctxt.number_tools(); ++i) { - vols.emplace_back(new_volume(ctxt.color_tool(i))); - geometries.emplace_back(GLModel::Geometry()); - } - } - else { - vols = { new_volume(ctxt.color_perimeters()), new_volume(ctxt.color_infill()), new_volume(ctxt.color_support()) }; - geometries = { GLModel::Geometry(), GLModel::Geometry(), GLModel::Geometry() }; - } - - assert(vols.size() == geometries.size()); - for (GLModel::Geometry& g : geometries) { - g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; - } - for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++ idx_layer) { - const Layer *layer = ctxt.layers[idx_layer]; - - if (is_selected_separate_extruder) { - bool at_least_one_has_correct_extruder = false; - for (const LayerRegion* layerm : layer->regions()) { - if (layerm->slices().empty()) - continue; - const PrintRegionConfig& cfg = layerm->region().config(); - if (cfg.perimeter_extruder.value == m_selected_extruder || - cfg.infill_extruder.value == m_selected_extruder || - cfg.solid_infill_extruder.value == m_selected_extruder ) { - at_least_one_has_correct_extruder = true; - break; - } - } - if (!at_least_one_has_correct_extruder) - continue; - } - - for (size_t i = 0; i < vols.size(); ++i) { - GLVolume* vol = vols[i]; - if (vol->print_zs.empty() || vol->print_zs.back() != layer->print_z) { - vol->print_zs.emplace_back(layer->print_z); - vol->offsets.emplace_back(geometries[i].indices_count()); - } - } - - for (const PrintInstance &instance : *ctxt.shifted_copies) { - const Point © = instance.shift; - for (const LayerRegion *layerm : layer->regions()) { - if (is_selected_separate_extruder) { - const PrintRegionConfig& cfg = layerm->region().config(); - if (cfg.perimeter_extruder.value != m_selected_extruder || - cfg.infill_extruder.value != m_selected_extruder || - cfg.solid_infill_extruder.value != m_selected_extruder) - continue; - } - if (ctxt.has_perimeters) - _3DScene::extrusionentity_to_verts(layerm->perimeters(), float(layer->print_z), copy, - select_geometry(idx_layer, layerm->region().config().perimeter_extruder.value, 0)); - if (ctxt.has_infill) { - for (const ExtrusionEntity *ee : layerm->fills()) { - // fill represents infill extrusions of a single island. - const auto *fill = dynamic_cast(ee); - if (! fill->entities.empty()) - _3DScene::extrusionentity_to_verts(*fill, float(layer->print_z), copy, - select_geometry(idx_layer, fill->entities.front()->role().is_solid_infill() ? - layerm->region().config().solid_infill_extruder : - layerm->region().config().infill_extruder, 1)); - } - } - } - if (ctxt.has_support) { - const SupportLayer *support_layer = dynamic_cast(layer); - if (support_layer) { - for (const ExtrusionEntity *extrusion_entity : support_layer->support_fills.entities) - _3DScene::extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy, - select_geometry(idx_layer, (extrusion_entity->role() == ExtrusionRole::SupportMaterial) ? - support_layer->object()->config().support_material_extruder : - support_layer->object()->config().support_material_interface_extruder, 2)); - } - } - } - // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. - for (size_t i = 0; i < vols.size(); ++i) { - GLVolume &vol = *vols[i]; - if (geometries[i].vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { - vol.model.init_from(std::move(geometries[i])); - vols[i] = new_volume(vol.color); - } - } - } - - for (size_t i = 0; i < vols.size(); ++i) { - if (!geometries[i].is_empty()) - vols[i]->model.init_from(std::move(geometries[i])); - } - }); - }); // task arena - - BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - finalizing results" << m_volumes.log_memory_info() << log_memory_info(); - // Remove empty volumes from the newly added volumes. - { - for (auto ptr_it = m_volumes.volumes.begin() + volumes_cnt_initial; ptr_it != m_volumes.volumes.end(); ++ptr_it) - if ((*ptr_it)->empty()) { - delete *ptr_it; - *ptr_it = nullptr; - } - m_volumes.volumes.erase(std::remove(m_volumes.volumes.begin() + volumes_cnt_initial, m_volumes.volumes.end(), nullptr), m_volumes.volumes.end()); - } - for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) { - GLVolume* v = m_volumes.volumes[i]; - v->is_outside = !contains(build_volume, v->model); - // We are done editinig the model, now it can be sent to gpu - v->model.enable_render(); - } - - BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); -} - -void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, const std::vector& str_tool_colors) -{ - const Print *print = this->fff_print(); - if (print == nullptr || print->wipe_tower_data().tool_changes.empty()) - return; - - if (!print->is_step_done(psWipeTower)) - return; - - std::vector tool_colors; - decode_colors(str_tool_colors, tool_colors); - - struct Ctxt - { - const Print *print; - const std::vector *tool_colors; - Vec2f wipe_tower_pos; - float wipe_tower_angle; - - static ColorRGBA color_support() { return ColorRGBA::GREENISH(); } - - // For cloring by a tool, return a parsed color. - bool color_by_tool() const { return tool_colors != nullptr; } - size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() : 0; } - const ColorRGBA& color_tool(size_t tool) const { return (*tool_colors)[tool]; } - int volume_idx(int tool, int feature) const { - return this->color_by_tool() ? std::min(this->number_tools() - 1, std::max(tool, 0)) : feature; - } - - const std::vector& tool_change(size_t idx) { - const auto &tool_changes = print->wipe_tower_data().tool_changes; - return priming.empty() ? - ((idx == tool_changes.size()) ? final : tool_changes[idx]) : - ((idx == 0) ? priming : (idx == tool_changes.size() + 1) ? final : tool_changes[idx - 1]); - } - std::vector priming; - std::vector final; - } ctxt; - - ctxt.print = print; - ctxt.tool_colors = tool_colors.empty() ? nullptr : &tool_colors; - if (print->wipe_tower_data().priming && print->config().single_extruder_multi_material_priming) - for (int i=0; i<(int)print->wipe_tower_data().priming.get()->size(); ++i) - ctxt.priming.emplace_back(print->wipe_tower_data().priming.get()->at(i)); - if (print->wipe_tower_data().final_purge) - ctxt.final.emplace_back(*print->wipe_tower_data().final_purge.get()); - - ctxt.wipe_tower_angle = ctxt.print->config().wipe_tower_rotation_angle.value/180.f * PI; - ctxt.wipe_tower_pos = Vec2f(ctxt.print->config().wipe_tower_x.value, ctxt.print->config().wipe_tower_y.value); - - BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - start" << m_volumes.log_memory_info() << log_memory_info(); - - //FIXME Improve the heuristics for a grain size. - size_t n_items = print->wipe_tower_data().tool_changes.size() + (ctxt.priming.empty() ? 0 : 1); - size_t grain_size = std::max(n_items / 128, size_t(1)); - tbb::spin_mutex new_volume_mutex; - auto new_volume = [this, &new_volume_mutex](const ColorRGBA& color) { - auto *volume = new GLVolume(color); - volume->is_extrusion_path = true; - // to prevent sending data to gpu (in the main thread) while - // editing the model geometry - volume->model.disable_render(); - tbb::spin_mutex::scoped_lock lock; - lock.acquire(new_volume_mutex); - m_volumes.volumes.emplace_back(volume); - lock.release(); - return volume; - }; - - const size_t volumes_cnt_initial = m_volumes.volumes.size(); - std::vector volumes_per_thread(n_items); - tbb::parallel_for(tbb::blocked_range(0, n_items, grain_size), - [&ctxt, &new_volume](const tbb::blocked_range& range) { - // Bounding box of this slab of a wipe tower. - GLVolumePtrs vols; - std::vector geometries; - if (ctxt.color_by_tool()) { - for (size_t i = 0; i < ctxt.number_tools(); ++i) { - vols.emplace_back(new_volume(ctxt.color_tool(i))); - geometries.emplace_back(GLModel::Geometry()); - } - } - else { - vols = { new_volume(ctxt.color_support()) }; - geometries = { GLModel::Geometry() }; - } - - assert(vols.size() == geometries.size()); - for (GLModel::Geometry& g : geometries) { - g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; - } - for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++idx_layer) { - const std::vector &layer = ctxt.tool_change(idx_layer); - for (size_t i = 0; i < vols.size(); ++i) { - GLVolume &vol = *vols[i]; - if (vol.print_zs.empty() || vol.print_zs.back() != layer.front().print_z) { - vol.print_zs.emplace_back(layer.front().print_z); - vol.offsets.emplace_back(geometries[i].indices_count()); - } - } - for (const WipeTower::ToolChangeResult &extrusions : layer) { - for (size_t i = 1; i < extrusions.extrusions.size();) { - const WipeTower::Extrusion &e = extrusions.extrusions[i]; - if (e.width == 0.) { - ++i; - continue; - } - size_t j = i + 1; - if (ctxt.color_by_tool()) - for (; j < extrusions.extrusions.size() && extrusions.extrusions[j].tool == e.tool && extrusions.extrusions[j].width > 0.f; ++j); - else - for (; j < extrusions.extrusions.size() && extrusions.extrusions[j].width > 0.f; ++j); - size_t n_lines = j - i; - Lines lines; - std::vector widths; - std::vector heights; - lines.reserve(n_lines); - widths.reserve(n_lines); - heights.assign(n_lines, extrusions.layer_height); - WipeTower::Extrusion e_prev = extrusions.extrusions[i-1]; - - if (!extrusions.priming) { // wipe tower extrusions describe the wipe tower at the origin with no rotation - e_prev.pos = Eigen::Rotation2Df(ctxt.wipe_tower_angle) * e_prev.pos; - e_prev.pos += ctxt.wipe_tower_pos; - } - - for (; i < j; ++i) { - WipeTower::Extrusion e = extrusions.extrusions[i]; - assert(e.width > 0.f); - if (!extrusions.priming) { - e.pos = Eigen::Rotation2Df(ctxt.wipe_tower_angle) * e.pos; - e.pos += ctxt.wipe_tower_pos; - } - - lines.emplace_back(Point::new_scale(e_prev.pos.x(), e_prev.pos.y()), Point::new_scale(e.pos.x(), e.pos.y())); - widths.emplace_back(e.width); - - e_prev = e; - } - - _3DScene::thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z, - geometries[ctxt.volume_idx(e.tool, 0)]); - } - } - } - for (size_t i = 0; i < vols.size(); ++i) { - GLVolume &vol = *vols[i]; - if (geometries[i].vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { - vol.model.init_from(std::move(geometries[i])); - vols[i] = new_volume(vol.color); - } - } - - for (size_t i = 0; i < vols.size(); ++i) { - if (!geometries[i].is_empty()) - vols[i]->model.init_from(std::move(geometries[i])); - } - }); - - BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - finalizing results" << m_volumes.log_memory_info() << log_memory_info(); - // Remove empty volumes from the newly added volumes. - { - for (auto ptr_it = m_volumes.volumes.begin() + volumes_cnt_initial; ptr_it != m_volumes.volumes.end(); ++ptr_it) { - if ((*ptr_it)->empty()) { - delete* ptr_it; - *ptr_it = nullptr; - } - } - m_volumes.volumes.erase(std::remove(m_volumes.volumes.begin() + volumes_cnt_initial, m_volumes.volumes.end(), nullptr), m_volumes.volumes.end()); - } - for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) { - GLVolume* v = m_volumes.volumes[i]; - v->is_outside = !contains(build_volume, v->model); - // We are done editing the model, now it can be sent to gpu - v->model.enable_render(); - } - - BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); -} -#endif // !ENABLE_NEW_GCODE_VIEWER - // While it looks like we can call // this->reload_scene(true, true) // the two functions are quite different: @@ -7359,11 +6546,6 @@ void GLCanvas3D::_load_sla_shells() update_volumes_colors_by_extruder(); } -void GLCanvas3D::_update_sla_shells_outside_state() -{ - check_volumes_outside_state(); -} - void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning) { _set_current(); @@ -7656,11 +6838,6 @@ void GLCanvas3D::WipeTowerInfo::apply_wipe_tower(Vec2d pos, double rot) wxGetApp().get_tab(Preset::TYPE_PRINT)->load_config(cfg); } -void GLCanvas3D::WipeTowerInfo::apply_wipe_tower() const -{ - apply_wipe_tower(m_pos, m_rotation); -} - void GLCanvas3D::RenderTimer::Notify() { wxPostEvent((wxEvtHandler*)GetOwner(), RenderTimerEvent( EVT_GLCANVAS_RENDER_TIMER, *this)); @@ -7676,11 +6853,6 @@ void GLCanvas3D::GizmoHighlighterTimer::Notify() wxPostEvent((wxEvtHandler*)GetOwner(), GizmoHighlighterTimerEvent(EVT_GLCANVAS_GIZMO_HIGHLIGHTER_TIMER, *this)); } -void GLCanvas3D::ToolbarHighlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID_ANY*/) -{ - m_timer.SetOwner(owner, timerid); -} - void GLCanvas3D::ToolbarHighlighter::init(GLToolbarItem* toolbar_item, GLCanvas3D* canvas) { if (m_timer.IsRunning()) @@ -7698,9 +6870,9 @@ void GLCanvas3D::ToolbarHighlighter::invalidate() { m_timer.Stop(); - if (m_toolbar_item) { + if (m_toolbar_item) m_toolbar_item->set_highlight(GLToolbarItem::EHighlightState::NotHighlighted); - } + m_toolbar_item = nullptr; m_blink_counter = 0; m_render_arrow = false; @@ -7725,11 +6897,6 @@ void GLCanvas3D::ToolbarHighlighter::blink() invalidate(); } -void GLCanvas3D::GizmoHighlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID_ANY*/) -{ - m_timer.SetOwner(owner, timerid); -} - void GLCanvas3D::GizmoHighlighter::init(GLGizmosManager* manager, GLGizmosManager::EType gizmo, GLCanvas3D* canvas) { if (m_timer.IsRunning()) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 76c312960f..b5d9c4955f 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -278,8 +278,8 @@ class GLCanvas3D bool is_allowed() const; - bool is_enabled() const; - void set_enabled(bool enabled); + bool is_enabled() const { return m_enabled; } + void set_enabled(bool enabled) { m_enabled = is_allowed() && enabled; } void render_overlay(const GLCanvas3D& canvas); void render_volumes(const GLCanvas3D& canvas, const GLVolumeCollection& volumes); @@ -319,23 +319,18 @@ class GLCanvas3D static const Vec3d Invalid_3D_Point; static const int MoveThresholdPx; - Point start_position_2D; - Vec3d start_position_3D; - int move_volume_idx; - bool move_requires_threshold; - Point move_start_threshold_position_2D; - - public: - Drag(); + Point start_position_2D{ Invalid_2D_Point }; + Vec3d start_position_3D{ Invalid_3D_Point }; + int move_volume_idx{ -1 }; + bool move_requires_threshold{ false }; + Point move_start_threshold_position_2D{ Invalid_2D_Point }; }; - bool dragging; - Vec2d position; - Vec3d scene_position; + bool dragging{ false }; + Vec2d position{ DBL_MAX, DBL_MAX }; + Vec3d scene_position{ DBL_MAX, DBL_MAX, DBL_MAX }; + bool ignore_left_up{ false }; Drag drag; - bool ignore_left_up; - - Mouse(); void set_start_position_2D_as_invalid() { drag.start_position_2D = Drag::Invalid_2D_Point; } void set_start_position_3D_as_invalid() { drag.start_position_3D = Drag::Invalid_3D_Point; } @@ -597,10 +592,8 @@ private: ArrangeSettingsDb_AppCfg m_arrange_settings_db; ArrangeSettingsDialogImgui m_arrange_settings_dialog; -#if ENABLE_NEW_GCODE_VIEWER // used to show layers times on the layers slider when pre-gcode view is active std::vector m_gcode_layers_times_cache; -#endif // ENABLE_NEW_GCODE_VIEWER public: @@ -646,7 +639,7 @@ private: struct ToolbarHighlighter { - void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY); + void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY) { m_timer.SetOwner(owner, timerid); } void init(GLToolbarItem* toolbar_item, GLCanvas3D* canvas); void blink(); void invalidate(); @@ -661,7 +654,7 @@ private: struct GizmoHighlighter { - void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY); + void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY) { m_timer.SetOwner(owner, timerid); } void init(GLGizmosManager* manager, GLGizmosManager::EType gizmo, GLCanvas3D* canvas); void blink(); void invalidate(); @@ -720,15 +713,15 @@ public: m_scene_raycaster.set_gizmos_on_top(value); } - void set_as_dirty(); + void set_as_dirty() { m_dirty = true; } void requires_check_outside_state() { m_requires_check_outside_state = true; } - unsigned int get_volumes_count() const; + unsigned int get_volumes_count() const { return (unsigned int)m_volumes.volumes.size(); } const GLVolumeCollection& get_volumes() const { return m_volumes; } void reset_volumes(); ModelInstanceEPrintVolumeState check_volumes_outside_state(bool selection_only = true) const; // update the is_outside state of all the volumes contained in the given collection - void check_volumes_outside_state(GLVolumeCollection& volumes) const; + void check_volumes_outside_state(GLVolumeCollection& volumes) const { check_volumes_outside_state(volumes, nullptr, false); } private: // returns true if all the volumes are completely contained in the print volume @@ -739,15 +732,11 @@ public: void init_gcode_viewer() { m_gcode_viewer.init(); } void reset_gcode_toolpaths() { m_gcode_viewer.reset(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } -#if ENABLE_NEW_GCODE_VIEWER void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } const libvgcode::Interval& get_gcode_view_full_range() const { return m_gcode_viewer.get_gcode_view_full_range(); } const libvgcode::Interval& get_gcode_view_enabled_range() const { return m_gcode_viewer.get_gcode_view_enabled_range(); } const libvgcode::Interval& get_gcode_view_visible_range() const { return m_gcode_viewer.get_gcode_view_visible_range(); } const libvgcode::PathVertex& get_gcode_vertex_at(size_t id) const { return m_gcode_viewer.get_gcode_vertex_at(id); } -#else - void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } -#endif // ENABLE_NEW_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, const ModelVolume* mv = nullptr); @@ -756,7 +745,7 @@ public: void set_config(const DynamicPrintConfig* config); const DynamicPrintConfig *config() const { return m_config; } - void set_process(BackgroundSlicingProcess* process); + void set_process(BackgroundSlicingProcess* process) { m_process = process; } void set_model(Model* model); const Model* get_model() const { return m_model; } @@ -791,29 +780,26 @@ public: BoundingBoxf3 volumes_bounding_box() const; BoundingBoxf3 scene_bounding_box() const; - bool is_layers_editing_enabled() const; - bool is_layers_editing_allowed() const; + bool is_layers_editing_enabled() const { return m_layers_editing.is_enabled(); } + bool is_layers_editing_allowed() const { return m_layers_editing.is_allowed(); } void reset_layer_height_profile(); void adaptive_layer_height_profile(float quality_factor); void smooth_layer_height_profile(const HeightProfileSmoothingParams& smoothing_params); - bool is_reload_delayed() const; + bool is_reload_delayed() const { return m_reload_delayed; } void enable_layers_editing(bool enable); -#if !ENABLE_NEW_GCODE_VIEWER - void enable_legend_texture(bool enable); -#endif // !ENABLE_NEW_GCODE_VIEWER - void enable_picking(bool enable); - void enable_moving(bool enable); - void enable_gizmos(bool enable); - void enable_selection(bool enable); - void enable_main_toolbar(bool enable); - void enable_undoredo_toolbar(bool enable); - void enable_dynamic_background(bool enable); + void enable_picking(bool enable) { m_picking_enabled = enable; } + void enable_moving(bool enable) { m_moving_enabled = enable; } + void enable_gizmos(bool enable) { m_gizmos.set_enabled(enable); } + void enable_selection(bool enable) { m_selection.set_enabled(enable); } + void enable_main_toolbar(bool enable) { m_main_toolbar.set_enabled(enable); } + void enable_undoredo_toolbar(bool enable) { m_undoredo_toolbar.set_enabled(enable); } + void enable_dynamic_background(bool enable) { m_dynamic_background_enabled = enable; } void enable_labels(bool enable) { m_labels.enable(enable); } void enable_slope(bool enable) { m_slope.enable(enable); } - void allow_multisample(bool allow); + void allow_multisample(bool allow) { m_multisample_allowed = allow; } void zoom_to_bed(); void zoom_to_volumes(); @@ -835,31 +821,15 @@ public: void select_all(); void deselect_all(); - void delete_selected(); + void delete_selected() { m_selection.erase(); } void ensure_on_bed(unsigned int object_idx, bool allow_negative_z); -#if ENABLE_NEW_GCODE_VIEWER - std::vector get_gcode_layers_zs() const; + std::vector get_gcode_layers_zs() const { return m_gcode_viewer.get_layers_zs(); } std::vector get_gcode_layers_times() const { return m_gcode_viewer.get_layers_times(); } const std::vector& get_gcode_layers_times_cache() const { return m_gcode_layers_times_cache; } void reset_gcode_layers_times_cache() { m_gcode_layers_times_cache.clear(); } -#else - 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; - unsigned int get_gcode_options_visibility_flags() const { return m_gcode_viewer.get_options_visibility_flags(); } - void set_gcode_options_visibility_from_flags(unsigned int flags); - unsigned int get_toolpath_role_visibility_flags() const { return m_gcode_viewer.get_toolpath_role_visibility_flags(); } - void set_toolpath_role_visibility_flags(unsigned int flags); - void set_toolpath_view_type(GCodeViewer::EViewType type); - std::vector get_volumes_print_zs(bool active_only) const; -#endif // ENABLE_NEW_GCODE_VIEWER - void set_volumes_z_range(const std::array& range); + void set_volumes_z_range(const std::array& range) { m_volumes.set_range(range[0] - 1e-6, range[1] + 1e-6); } void set_toolpaths_z_range(const std::array& range); -#if !ENABLE_NEW_GCODE_VIEWER - std::vector& get_custom_gcode_per_print_z() { return m_gcode_viewer.get_custom_gcode_per_print_z(); } -#endif // !ENABLE_NEW_GCODE_VIEWER size_t get_gcode_extruders_count() { return m_gcode_viewer.get_extruders_count(); } std::vector load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs); @@ -870,7 +840,6 @@ public: void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false); void load_gcode_shells(); -#if ENABLE_NEW_GCODE_VIEWER void load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors, const std::vector& str_color_print_colors); void set_gcode_view_type(libvgcode::EViewType type) { return m_gcode_viewer.set_view_type(type); } @@ -882,19 +851,11 @@ public: void load_preview(const std::vector& str_tool_colors, const std::vector& str_color_print_colors, const std::vector& color_print_values); -#else - void load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors); - void refresh_gcode_preview_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last); - 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(); } - - void load_preview(const std::vector& str_tool_colors, const std::vector& color_print_values); -#endif // ENABLE_NEW_GCODE_VIEWER void load_sla_preview(); void bind_event_handlers(); void unbind_event_handlers(); - void on_size(wxSizeEvent& evt); + void on_size(wxSizeEvent& evt) { m_dirty = true; } void on_idle(wxIdleEvent& evt); void on_char(wxKeyEvent& evt); void on_key(wxKeyEvent& evt); @@ -952,7 +913,7 @@ public: inline const Vec2d bb_size() const { return m_bb.size(); } inline const BoundingBoxf& bounding_box() const { return m_bb; } - void apply_wipe_tower() const; + void apply_wipe_tower() const { apply_wipe_tower(m_pos, m_rotation); } static void apply_wipe_tower(Vec2d pos, double rot); }; @@ -967,7 +928,7 @@ public: double get_size_proportional_to_max_bed_size(double factor) const; void set_cursor(ECursorType type); - void msw_rescale(); + void msw_rescale() { m_gcode_viewer.invalidate_legend(); } void request_extra_frame() { m_extra_frame_requested = true; } @@ -979,21 +940,16 @@ public: void force_main_toolbar_right_action(int item_id) { m_main_toolbar.force_right_action(item_id, *this); } void update_tooltip_for_settings_item_in_main_toolbar(); - bool has_toolpaths_to_export() const; - void export_toolpaths_to_obj(const char* filename) const; + bool has_toolpaths_to_export() const { return m_gcode_viewer.can_export_toolpaths(); } + void export_toolpaths_to_obj(const char* filename) const { m_gcode_viewer.export_toolpaths_to_obj(filename); } void mouse_up_cleanup(); bool are_labels_shown() const { return m_labels.is_shown(); } void show_labels(bool show) { m_labels.show(show); } -#if ENABLE_NEW_GCODE_VIEWER bool is_legend_shown() const { return m_gcode_viewer.is_legend_shown(); } void show_legend(bool show) { m_gcode_viewer.show_legend(show); m_dirty = true; } -#else - bool is_legend_shown() const { return m_gcode_viewer.is_legend_enabled(); } - void show_legend(bool show) { m_gcode_viewer.enable_legend(show); m_dirty = true; } -#endif // ENABLE_NEW_GCODE_VIEWER bool is_using_slope() const { return m_slope.is_used(); } void use_slope(bool use) { m_slope.use(use); } @@ -1086,17 +1042,17 @@ private: void _render_bed_axes(); void _render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom); void _render_objects(GLVolumeCollection::ERenderType type); - void _render_gcode(); - void _render_gcode_cog(); + void _render_gcode() { m_gcode_viewer.render(); } + void _render_gcode_cog() { m_gcode_viewer.render_cog(); } void _render_selection(); void _render_sequential_clearance(); #if ENABLE_RENDER_SELECTION_CENTER - void _render_selection_center(); + void _render_selection_center() { m_selection.render_center(m_gizmos.is_dragging()); } #endif // ENABLE_RENDER_SELECTION_CENTER void _check_and_update_toolbar_icon_scale(); void _render_overlays(); void _render_volumes_for_picking(const Camera& camera) const; - void _render_current_gizmo() const; + void _render_current_gizmo() const { m_gizmos.render_current_gizmo(); } void _render_gizmos_overlay(); void _render_main_toolbar(); void _render_undoredo_toolbar(); @@ -1106,7 +1062,7 @@ private: void _render_camera_target(); #endif // ENABLE_SHOW_CAMERA_TARGET void _render_sla_slices(); - void _render_selection_sidebar_hints(); + void _render_selection_sidebar_hints() { m_selection.render_sidebar_hints(m_sidebar_field); } bool _render_undo_redo_stack(const bool is_undo, float pos_x); bool _render_arrange_menu(float pos_x); void _render_thumbnail_internal(ThumbnailData& thumbnail_data, const ThumbnailsParams& thumbnail_params, const GLVolumeCollection& volumes, Camera::EType camera_type); @@ -1128,25 +1084,12 @@ private: // Convert the screen space coordinate to world coordinate on the bed. Vec3d _mouse_to_bed_3d(const Point& mouse_pos); - void _start_timer(); - void _stop_timer(); - -#if !ENABLE_NEW_GCODE_VIEWER - // Create 3D thick extrusion lines for a skirt and brim. - // Adds a new Slic3r::GUI::3DScene::Volume to volumes, updates collision with the build_volume. - void _load_print_toolpaths(const BuildVolume &build_volume); - // Create 3D thick extrusion lines for object forming extrusions. - // Adds a new Slic3r::GUI::3DScene::Volume to $self->volumes, - // one for perimeters, one for infill and one for supports, updates collision with the build_volume. - void _load_print_object_toolpaths(const PrintObject& print_object, const BuildVolume &build_volume, - const std::vector& str_tool_colors, const std::vector& color_print_values); - // Create 3D thick extrusion lines for wipe tower extrusions, updates collision with the build_volume. - void _load_wipe_tower_toolpaths(const BuildVolume &build_volume, const std::vector& str_tool_colors); -#endif // !ENABLE_NEW_GCODE_VIEWER + void _start_timer() { m_timer.Start(100, wxTIMER_CONTINUOUS); } + void _stop_timer() { m_timer.Stop(); } // Load SLA objects and support structures for objects, for which the slaposSliceSupports step has been finished. void _load_sla_shells(); - void _update_sla_shells_outside_state(); + void _update_sla_shells_outside_state() { check_volumes_outside_state(); } void _set_warning_notification_if_needed(EWarning warning); // generates a warning notification containing the given message diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index e69568614b..9fb30fbed8 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2653,7 +2653,7 @@ void GUI_App::open_preferences(const std::string& highlight_option /*= std::stri recreate_GUI(_L("Restart application") + dots); if (mainframe->preferences_dialog->seq_top_layer_only_changed()) - this->plater_->refresh_print(); + this->plater_->reload_print(); #ifdef _WIN32 if (is_editor()) { diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 2650bfb0d4..3860fde96f 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -228,11 +228,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Model* model) m_canvas->set_config(m_config); m_canvas->set_model(model); m_canvas->set_process(m_process); -#if ENABLE_NEW_GCODE_VIEWER m_canvas->show_legend(true); -#else - m_canvas->enable_legend_texture(true); -#endif // ENABLE_NEW_GCODE_VIEWER m_canvas->enable_dynamic_background(true); m_layers_slider_sizer = create_layers_slider_sizer(); @@ -318,7 +314,6 @@ void Preview::load_print(bool keep_z_range) Layout(); } -#if ENABLE_NEW_GCODE_VIEWER void Preview::reload_print() { if (!IsShown()) @@ -327,44 +322,6 @@ void Preview::reload_print() m_loaded = false; load_print(); } -#else -void Preview::reload_print(bool keep_volumes) -{ -#ifdef __linux__ - // We are getting mysterious crashes on Linux in gtk due to OpenGL context activation GH #1874 #1955. - // So we are applying a workaround here: a delayed release of OpenGL vertex buffers. - if (!IsShown()) - { - m_volumes_cleanup_required = !keep_volumes; - return; - } -#endif /* __linux__ */ - if ( -#ifdef __linux__ - m_volumes_cleanup_required || -#endif /* __linux__ */ - !keep_volumes) - { - m_canvas->reset_volumes(); - m_loaded = false; -#ifdef __linux__ - m_volumes_cleanup_required = false; -#endif /* __linux__ */ - } - - load_print(); -} -#endif // ENABLE_NEW_GCODE_VIEWER - -void Preview::refresh_print() -{ - m_loaded = false; - - if (!IsShown()) - return; - - load_print(true); -} void Preview::msw_rescale() { @@ -376,7 +333,7 @@ void Preview::msw_rescale() get_canvas3d()->msw_rescale(); // rescale legend - refresh_print(); + reload_print(); } void Preview::sys_color_changed() @@ -461,11 +418,7 @@ wxBoxSizer* Preview::create_layers_slider_sizer() m_schedule_background_process(); m_keep_current_preview_type = false; -#if ENABLE_NEW_GCODE_VIEWER reload_print(); -#else - reload_print(false); -#endif // ENABLE_NEW_GCODE_VIEWER }); return sizer; @@ -539,11 +492,7 @@ void Preview::update_layers_slider(const std::vector& layers_z, bool kee ticks_info_from_model = plater->model().custom_gcode_per_print_z; else { ticks_info_from_model.mode = CustomGCode::Mode::SingleExtruder; -#if ENABLE_NEW_GCODE_VIEWER ticks_info_from_model.gcodes = m_gcode_result->custom_gcode_per_print_z; -#else - ticks_info_from_model.gcodes = m_canvas->get_custom_gcode_per_print_z(); -#endif // ENABLE_NEW_GCODE_VIEWER } check_layers_slider_values(ticks_info_from_model.gcodes, layers_z); @@ -575,14 +524,8 @@ void Preview::update_layers_slider(const std::vector& layers_z, bool kee m_layers_slider->SetDrawMode(sla_print_technology, sequential_print); if (sla_print_technology) m_layers_slider->SetLayersTimes(plater->sla_print().print_statistics().layers_times); - else { - auto print_mode_stat = m_gcode_result->print_statistics.modes.front(); -#if ENABLE_NEW_GCODE_VIEWER - m_layers_slider->SetLayersTimes(m_canvas->get_gcode_layers_times_cache(), print_mode_stat.time); -#else - m_layers_slider->SetLayersTimes(print_mode_stat.layers_times, print_mode_stat.time); -#endif // ENABLE_NEW_GCODE_VIEWER - } + else + m_layers_slider->SetLayersTimes(m_canvas->get_gcode_layers_times_cache(), m_gcode_result->print_statistics.modes.front().time); // check if ticks_info_from_model contains ColorChange g-code bool color_change_already_exists = false; @@ -742,13 +685,8 @@ void Preview::update_layers_slider_from_canvas(wxKeyEvent& event) event.Skip(); } -#if ENABLE_NEW_GCODE_VIEWER void Preview::update_moves_slider(std::optional visible_range_min, std::optional visible_range_max) -#else -void Preview::update_moves_slider() -#endif // ENABLE_NEW_GCODE_VIEWER { -#if ENABLE_NEW_GCODE_VIEWER if (m_gcode_result->moves.empty()) return; @@ -800,41 +738,6 @@ void Preview::update_moves_slider() m_moves_slider->SetSliderAlternateValues(alternate_values); m_moves_slider->SetMaxValue(static_cast(values.size()) - 1); m_moves_slider->SetSelectionSpan(span_min_id, span_max_id); -#else - const GCodeViewer::SequentialView& view = m_canvas->get_gcode_sequential_view(); - // this should not be needed, but it is here to try to prevent rambling crashes on Mac Asan - if (view.endpoints.last < view.endpoints.first) - return; - - assert(view.endpoints.first <= view.current.first && view.current.first <= view.endpoints.last); - assert(view.endpoints.first <= view.current.last && view.current.last <= view.endpoints.last); - - std::vector values; - values.reserve(view.endpoints.last - view.endpoints.first + 1); - std::vector alternate_values; - alternate_values.reserve(view.endpoints.last - view.endpoints.first + 1); - unsigned int last_gcode_id = view.gcode_ids[view.endpoints.first]; - for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i) { - if (i > view.endpoints.first) { - // skip consecutive moves with same gcode id (resulting from processing G2 and G3 lines) - if (last_gcode_id == view.gcode_ids[i]) { - values.back() = static_cast(i + 1); - alternate_values.back() = static_cast(view.gcode_ids[i]); - continue; - } - else - last_gcode_id = view.gcode_ids[i]; - } - - values.emplace_back(static_cast(i + 1)); - alternate_values.emplace_back(static_cast(view.gcode_ids[i])); - } - - m_moves_slider->SetSliderValues(values); - m_moves_slider->SetSliderAlternateValues(alternate_values); - m_moves_slider->SetMaxValue(int(values.size()) - 1); - m_moves_slider->SetSelectionSpan(values.front() - 1 - view.endpoints.first, values.back() - 1 - view.endpoints.first); -#endif // ENABLE_NEW_GCODE_VIEWER } void Preview::enable_moves_slider(bool enable) @@ -876,9 +779,7 @@ void Preview::load_print_as_fff(bool keep_z_range) } if (wxGetApp().is_editor() && !has_layers) { -#if ENABLE_NEW_GCODE_VIEWER m_canvas->reset_gcode_layers_times_cache(); -#endif // ENABLE_NEW_GCODE_VIEWER hide_layers_slider(); m_left_sizer->Hide(m_bottom_toolbar_panel); m_left_sizer->Layout(); @@ -887,7 +788,6 @@ void Preview::load_print_as_fff(bool keep_z_range) return; } -#if ENABLE_NEW_GCODE_VIEWER libvgcode::EViewType gcode_view_type = m_canvas->get_gcode_view_type(); const bool gcode_preview_data_valid = !m_gcode_result->moves.empty(); const bool is_pregcode_preview = !gcode_preview_data_valid && wxGetApp().is_editor(); @@ -900,44 +800,16 @@ void Preview::load_print_as_fff(bool keep_z_range) color_print_colors = wxGetApp().plater()->get_colors_for_color_print(m_gcode_result); color_print_colors.push_back("#808080"); // gray color for pause print or custom G-code } -#else - GCodeViewer::EViewType gcode_view_type = m_canvas->get_gcode_view_preview_type(); - const bool gcode_preview_data_valid = !m_gcode_result->moves.empty(); - - // Collect colors per extruder. - std::vector colors; - std::vector color_print_values = {}; - if (gcode_view_type == GCodeViewer::EViewType::ColorPrint) { - colors = wxGetApp().plater()->get_colors_for_color_print(m_gcode_result); - - if (!gcode_preview_data_valid) { - if (wxGetApp().is_editor()) - color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes; - else - color_print_values = m_canvas->get_custom_gcode_per_print_z(); - colors.push_back("#808080"); // gray color for pause print or custom G-code - } - } - else if (gcode_preview_data_valid || gcode_view_type == GCodeViewer::EViewType::Tool) { - colors = wxGetApp().plater()->get_extruder_colors_from_plater_config(m_gcode_result); - color_print_values.clear(); - } -#endif // ENABLE_NEW_GCODE_VIEWER std::vector zs; if (IsShown()) { m_canvas->set_selected_extruder(0); if (gcode_preview_data_valid) { -#if ENABLE_NEW_GCODE_VIEWER // Load the real G-code preview. m_canvas->load_gcode_preview(*m_gcode_result, tool_colors, color_print_colors); // the view type may have been changed by the call m_canvas->load_gcode_preview() gcode_view_type = m_canvas->get_gcode_view_type(); -#else - // Load the real G-code preview. - m_canvas->load_gcode_preview(*m_gcode_result, colors); -#endif // ENABLE_NEW_GCODE_VIEWER m_left_sizer->Layout(); Refresh(); zs = m_canvas->get_gcode_layers_zs(); @@ -945,26 +817,16 @@ void Preview::load_print_as_fff(bool keep_z_range) m_left_sizer->Show(m_bottom_toolbar_panel); m_loaded = true; } -#if ENABLE_NEW_GCODE_VIEWER else if (is_pregcode_preview) { // Load the initial preview based on slices, not the final G-code. m_canvas->load_preview(tool_colors, color_print_colors, color_print_values); // the view type has been changed by the call m_canvas->load_gcode_preview() if (gcode_view_type == libvgcode::EViewType::ColorPrint && !color_print_values.empty()) m_canvas->set_gcode_view_type(gcode_view_type); -#else - else if (wxGetApp().is_editor()) { - // Load the initial preview based on slices, not the final G-code. - m_canvas->load_preview(colors, color_print_values); -#endif // ENABLE_NEW_GCODE_VIEWER m_left_sizer->Hide(m_bottom_toolbar_panel); m_left_sizer->Layout(); Refresh(); -#if ENABLE_NEW_GCODE_VIEWER zs = m_canvas->get_gcode_layers_zs(); -#else - zs = m_canvas->get_volumes_print_zs(true); -#endif // ENABLE_NEW_GCODE_VIEWER } else { m_left_sizer->Hide(m_bottom_toolbar_panel); @@ -975,38 +837,20 @@ void Preview::load_print_as_fff(bool keep_z_range) if (!zs.empty() && !m_keep_current_preview_type) { const unsigned int number_extruders = wxGetApp().is_editor() ? (unsigned int)print->extruders().size() : m_canvas->get_gcode_extruders_count(); -#if ENABLE_NEW_GCODE_VIEWER const bool contains_color_gcodes = std::any_of(std::begin(color_print_values), std::end(color_print_values), [](auto const& item) { return item.type == CustomGCode::Type::ColorChange; }); const libvgcode::EViewType choice = contains_color_gcodes ? libvgcode::EViewType::ColorPrint : (number_extruders > 1) ? libvgcode::EViewType::Tool : libvgcode::EViewType::FeatureType; -#else - const std::vector gcodes = wxGetApp().is_editor() ? - wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : - m_canvas->get_custom_gcode_per_print_z(); - const bool contains_color_gcodes = std::any_of(std::begin(gcodes), std::end(gcodes), - [](auto const& item) { return item.type == CustomGCode::Type::ColorChange || item.type == CustomGCode::Type::ToolChange; }); - const GCodeViewer::EViewType choice = contains_color_gcodes ? - GCodeViewer::EViewType::ColorPrint : - (number_extruders > 1) ? GCodeViewer::EViewType::Tool : GCodeViewer::EViewType::FeatureType; -#endif // ENABLE_NEW_GCODE_VIEWER if (choice != gcode_view_type) { -#if ENABLE_NEW_GCODE_VIEWER const bool gcode_view_type_cache_load = m_canvas->is_gcode_view_type_cache_load_enabled(); if (gcode_view_type_cache_load) m_canvas->enable_gcode_view_type_cache_load(false); m_canvas->set_gcode_view_type(choice); if (gcode_view_type_cache_load) m_canvas->enable_gcode_view_type_cache_load(true); -#else - m_canvas->set_gcode_view_preview_type(choice); -#endif // ENABLE_NEW_GCODE_VIEWER if (wxGetApp().is_gcode_viewer()) m_keep_current_preview_type = true; -#if !ENABLE_NEW_GCODE_VIEWER - refresh_print(); -#endif // !ENABLE_NEW_GCODE_VIEWER } } @@ -1080,12 +924,8 @@ void Preview::on_layers_slider_scroll_changed(wxCommandEvent& event) 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)); -#if ENABLE_NEW_GCODE_VIEWER m_canvas->set_as_dirty(); m_canvas->request_extra_frame(); -#else - m_canvas->render(); -#endif // ENABLE_NEW_GCODE_VIEWER } } // namespace GUI diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 9974adfac6..6141318845 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -89,14 +89,6 @@ class Preview : public wxPanel BackgroundSlicingProcess* m_process; GCodeProcessorResult* m_gcode_result; -#if !ENABLE_NEW_GCODE_VIEWER -#ifdef __linux__ - // We are getting mysterious crashes on Linux in gtk due to OpenGL context activation GH #1874 #1955. - // So we are applying a workaround here. - bool m_volumes_cleanup_required { false }; -#endif /* __linux__ */ -#endif // !ENABLE_NEW_GCODE_VIEWER - // Calling this function object forces Plater::schedule_background_process. std::function m_schedule_background_process; @@ -140,12 +132,7 @@ public: void load_gcode_shells(); void load_print(bool keep_z_range = false); -#if ENABLE_NEW_GCODE_VIEWER void reload_print(); -#else - void reload_print(bool keep_volumes = false); -#endif // ENABLE_NEW_GCODE_VIEWER - void refresh_print(); void msw_rescale(); void sys_color_changed(); @@ -155,11 +142,7 @@ public: bool is_loaded() const { return m_loaded; } -#if ENABLE_NEW_GCODE_VIEWER void update_moves_slider(std::optional visible_range_min = std::nullopt, std::optional visible_range_max = std::nullopt); -#else - void update_moves_slider(); -#endif // ENABLE_NEW_GCODE_VIEWER void enable_moves_slider(bool enable); void move_moves_slider(wxKeyEvent& evt); void hide_layers_slider(); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 013a417c16..342c0f20a8 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -73,10 +73,8 @@ static const std::map font_icons = { {ImGui::PlugMarker , "plug" }, {ImGui::DowelMarker , "dowel" }, {ImGui::SnapMarker , "snap" }, -#if ENABLE_NEW_GCODE_VIEWER {ImGui::HorizontalHide , "horizontal_hide" }, {ImGui::HorizontalShow , "horizontal_show" }, -#endif // ENABLE_NEW_GCODE_VIEWER }; static const std::map font_icons_large = { diff --git a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp index 97647a4e72..1434f159ac 100644 --- a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp +++ b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp @@ -5,7 +5,6 @@ #include "libslic3r/libslic3r.h" #include "LibVGCodeWrapper.hpp" -#if ENABLE_NEW_GCODE_VIEWER #include "libslic3r/Print.hpp" #include "libslic3r/Color.hpp" @@ -771,4 +770,3 @@ GCodeInputData convert(const Slic3r::Print& print, const std::vector visible_range_min = std::nullopt, std::optional visible_range_max = std::nullopt); -#else - void update_preview_moves_slider(); -#endif // ENABLE_NEW_GCODE_VIEWER void enable_preview_moves_slider(bool enable); void reset_gcode_toolpaths(); @@ -2707,11 +2702,7 @@ void Plater::priv::set_current_panel(wxPanel* panel) q->reslice(); } // keeps current gcode preview, if any -#if ENABLE_NEW_GCODE_VIEWER preview->reload_print(); -#else - preview->reload_print(true); -#endif // ENABLE_NEW_GCODE_VIEWER } preview->set_as_dirty(); @@ -3324,17 +3315,10 @@ void Plater::priv::set_preview_layers_slider_values_range(int bottom, int top) preview->set_layers_slider_values_range(bottom, top); } -#if ENABLE_NEW_GCODE_VIEWER void Plater::priv::update_preview_moves_slider(std::optional visible_range_min, std::optional visible_range_max) { preview->update_moves_slider(visible_range_min, visible_range_max); } -#else -void Plater::priv::update_preview_moves_slider() -{ - preview->update_moves_slider(); -} -#endif // ENABLE_NEW_GCODE_VIEWER void Plater::priv::enable_preview_moves_slider(bool enable) { @@ -4024,11 +4008,7 @@ void Plater::load_gcode(const wxString& filename) // cleanup view before to start loading/processing p->gcode_result.reset(); reset_gcode_toolpaths(); -#if ENABLE_NEW_GCODE_VIEWER p->preview->reload_print(); -#else - p->preview->reload_print(false); -#endif // ENABLE_NEW_GCODE_VIEWER p->get_current_canvas3D()->render(); wxBusyCursor wait; @@ -4049,11 +4029,7 @@ void Plater::load_gcode(const wxString& filename) // show results try { -#if ENABLE_NEW_GCODE_VIEWER p->preview->reload_print(); -#else - p->preview->reload_print(false); -#endif // ENABLE_NEW_GCODE_VIEWER } catch (const std::exception&) { @@ -4061,11 +4037,7 @@ void Plater::load_gcode(const wxString& filename) p->gcode_result.reset(); reset_gcode_toolpaths(); set_default_bed_shape(); -#if ENABLE_NEW_GCODE_VIEWER p->preview->reload_print(); -#else - p->preview->reload_print(false); -#endif // ENABLE_NEW_GCODE_VIEWER p->get_current_canvas3D()->render(); MessageDialog(this, _L("The selected file") + ":\n" + filename + "\n" + _L("does not contain valid gcode."), wxString(GCODEVIEWER_APP_NAME) + " - " + _L("Error while loading .gcode file"), wxOK | wxICON_WARNING | wxCENTRE).ShowModal(); @@ -4276,9 +4248,9 @@ void Plater::convert_gcode_to_binary() msg_dlg.ShowModal(); } -void Plater::refresh_print() +void Plater::reload_print() { - p->preview->refresh_print(); + p->preview->reload_print(); } std::vector Plater::load_files(const std::vector& input_files, bool load_model, bool load_config, bool imperial_units /*= false*/) { return p->load_files(input_files, load_model, load_config, imperial_units); } @@ -5807,11 +5779,7 @@ void Plater::reslice() if (clean_gcode_toolpaths) reset_gcode_toolpaths(); -#if ENABLE_NEW_GCODE_VIEWER p->preview->reload_print(); -#else - p->preview->reload_print(!clean_gcode_toolpaths); -#endif // ENABLE_NEW_GCODE_VIEWER } void Plater::reslice_until_step_inner(int step, const ModelObject &object, bool postpone_error_messages) @@ -6233,9 +6201,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config) p->reset_gcode_toolpaths(); p->view3D->get_canvas3d()->reset_sequential_print_clearance(); p->view3D->get_canvas3d()->set_sla_view_type(GLCanvas3D::ESLAViewType::Original); -#if ENABLE_NEW_GCODE_VIEWER p->preview->get_canvas3d()->reset_volumes(); -#endif // ENABLE_NEW_GCODE_VIEWER } else if (opt_key == "bed_shape" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") { bed_shape_changed = true; @@ -6813,17 +6779,10 @@ void Plater::set_preview_layers_slider_values_range(int bottom, int top) p->set_preview_layers_slider_values_range(bottom, top); } -#if ENABLE_NEW_GCODE_VIEWER void Plater::update_preview_moves_slider(std::optional visible_range_min, std::optional visible_range_max) { p->update_preview_moves_slider(visible_range_min, visible_range_max); } -#else -void Plater::update_preview_moves_slider() -{ - p->update_preview_moves_slider(); -} -#endif // ENABLE_NEW_GCODE_VIEWER void Plater::enable_preview_moves_slider(bool enable) { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 3e1f6d19eb..eec067d612 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -108,7 +108,7 @@ public: void reload_gcode_from_disk(); void convert_gcode_to_ascii(); void convert_gcode_to_binary(); - void refresh_print(); + void reload_print(); std::vector load_files(const std::vector& input_files, bool load_model = true, bool load_config = true, bool imperial_units = false); // To be called when providing a list of files to the GUI slic3r on command line. @@ -336,11 +336,7 @@ public: void set_preview_layers_slider_values_range(int bottom, int top); -#if ENABLE_NEW_GCODE_VIEWER void update_preview_moves_slider(std::optional visible_range_min = std::nullopt, std::optional visible_range_max = std::nullopt); -#else - void update_preview_moves_slider(); -#endif // ENABLE_NEW_GCODE_VIEWER void enable_preview_moves_slider(bool enable); void reset_gcode_toolpaths();