Code cleanup and techs removal - completed

This commit is contained in:
enricoturri1966 2024-02-19 14:13:36 +01:00 committed by Lukas Matena
parent 7bd60043d8
commit 539c155c59
20 changed files with 187 additions and 5823 deletions

View File

@ -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;

View File

@ -374,42 +374,6 @@ inline bool all_inside_vertices_normals_interleaved(const std::vector<float> &pa
return true;
}
#if !ENABLE_NEW_GCODE_VIEWER
bool BuildVolume::all_paths_inside_vertices_and_normals_interleaved(const std::vector<float>& paths, const Eigen::AlignedBox<float, 3>& paths_bbox, bool ignore_bottom) const
{
assert(paths.size() % 6 == 0);
static constexpr const double epsilon = BedEpsilon;
switch (m_type) {
case Type::Rectangle:
{
BoundingBox3Base<Vec3d> build_volume = this->bounding_volume().inflated(epsilon);
if (m_max_print_height == 0.0)
build_volume.max.z() = std::numeric_limits<double>::max();
if (ignore_bottom)
build_volume.min.z() = -std::numeric_limits<double>::max();
return build_volume.contains(paths_bbox.min().cast<double>()) && build_volume.contains(paths_bbox.max().cast<double>());
}
case Type::Circle:
{
const Vec2f c = unscaled<float>(m_circle.center);
const float r = unscaled<double>(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<double>()); }) :
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<double>()) && p.z() <= z; });
default:
return true;
}
}
#endif // !ENABLE_NEW_GCODE_VIEWER
std::string_view BuildVolume::type_name(Type type)
{
using namespace std::literals;

View File

@ -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<float>& paths, const Eigen::AlignedBox<float, 3>& bbox, bool ignore_bottom = true) const;
#endif // !ENABLE_NEW_GCODE_VIEWER
const std::pair<std::vector<Vec2d>, std::vector<Vec2d>>& top_bottom_convex_hull_decomposition_scene() const { return m_top_bottom_convex_hull_decomposition_scene; }
const std::pair<std::vector<Vec2d>, std::vector<Vec2d>>& top_bottom_convex_hull_decomposition_bed() const { return m_top_bottom_convex_hull_decomposition_bed; }

View File

@ -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<StopTime>();
curr.reset();
prev.reset();
gcode_time.reset();
blocks = std::vector<TimeBlock>();
g1_times_cache = std::vector<G1LinesCacheItem>();
#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<float>();
#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<GCodeProcessor::TimeBlock>& blocks)
@ -367,15 +277,8 @@ static void recalculate_trapezoids(std::vector<GCodeProcessor::TimeBlock>& 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<GCodeProcessor::TimeBlock>& 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<size_t>(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<size_t>(block.role)] += block_time;
gcode_time.cache += block_time;
moves_time[static_cast<size_t>(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<GCodeProcessorResult::MoveVertex>();
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<std::string>();
filament_diameters = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER);
filament_densities = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY);
filament_cost = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST);
custom_gcode_per_print_z = std::vector<CustomGCode::Item>();
spiral_vase_layers = std::vector<std::pair<float, std::pair<size_t, size_t>>>();
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<std::string>();
filament_diameters = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER);
filament_densities = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY);
filament_cost = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST);
custom_gcode_per_print_z = std::vector<CustomGCode::Item>();
spiral_vase_layers = std::vector<std::pair<float, std::pair<size_t, size_t>>>();
conflict_result = std::nullopt;
}
#endif // ENABLE_GCODE_VIEWER_STATISTICS
#endif // ENABLE_NEW_GCODE_VIEWER
const std::vector<std::pair<GCodeProcessor::EProducer, std::string>> GCodeProcessor::Producers = {
{ EProducer::PrusaSlicer, "generated by PrusaSlicer" },
@ -883,11 +717,7 @@ for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::
const ConfigOptionBool* spiral_vase = config.option<ConfigOptionBool>("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<ConfigOptionFloat>("z_offset");
if (z_offset != nullptr)
@ -1169,11 +999,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
const ConfigOptionBool* spiral_vase = config.option<ConfigOptionBool>("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<ConfigOptionFloat>("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<void()> 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<size_t>(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::milliseconds>(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<size_t>(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<size_t>(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<size_t>(mode)].travel_time)) : std::string("N/A");
}
#endif // !ENABLE_NEW_GCODE_VIEWER
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> GCodeProcessor::get_custom_gcode_times(PrintEstimatedStatistics::ETimeMode mode, bool include_remaining) const
{
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> ret;
@ -1617,34 +1400,6 @@ std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> GCodeProcesso
return ret;
}
#if !ENABLE_NEW_GCODE_VIEWER
std::vector<std::pair<EMoveType, float>> GCodeProcessor::get_moves_time(PrintEstimatedStatistics::ETimeMode mode) const
{
std::vector<std::pair<EMoveType, float>> ret;
if (mode < PrintEstimatedStatistics::ETimeMode::Count) {
for (size_t i = 0; i < m_time_processor.machines[static_cast<size_t>(mode)].moves_time.size(); ++i) {
float time = m_time_processor.machines[static_cast<size_t>(mode)].moves_time[i];
if (time > 0.0f)
ret.push_back({ static_cast<EMoveType>(i), time });
}
}
return ret;
}
std::vector<std::pair<GCodeExtrusionRole, float>> GCodeProcessor::get_roles_time(PrintEstimatedStatistics::ETimeMode mode) const
{
std::vector<std::pair<GCodeExtrusionRole, float>> ret;
if (mode < PrintEstimatedStatistics::ETimeMode::Count) {
for (size_t i = 0; i < m_time_processor.machines[static_cast<size_t>(mode)].roles_time.size(); ++i) {
float time = m_time_processor.machines[static_cast<size_t>(mode)].roles_time[i];
if (time > 0.0f)
ret.push_back({ static_cast<GCodeExtrusionRole>(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<size_t>(mode)].first_layer_time : 0.0f;
}
#else
std::vector<float> GCodeProcessor::get_layers_time(PrintEstimatedStatistics::ETimeMode mode) const
{
return (mode < PrintEstimatedStatistics::ETimeMode::Count) ?
m_time_processor.machines[static_cast<size_t>(mode)].layers_time :
std::vector<float>();
}
#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<std::optional<double>, 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<unsigned int>(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<unsigned int>(1, m_layer_id);
@ -3102,17 +2832,10 @@ void GCodeProcessor::process_G1(const std::array<std::optional<double>, 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<std::optional<double>, 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<float>(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<PrintEstimatedStatistics::ETimeMode>(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<float>(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<unsigned int>(1, m_layer_id) - 1,
#else
static_cast<float>(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<size_t>(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<size_t>(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<size_t>(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);

View File

@ -55,26 +55,11 @@ namespace Slic3r {
{
float time;
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> custom_gcode_times;
#if !ENABLE_NEW_GCODE_VIEWER
float travel_time;
std::vector<std::pair<EMoveType, float>> moves_times;
std::vector<std::pair<GCodeExtrusionRole, float>> roles_times;
std::vector<float> 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<float, static_cast<size_t>(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<CustomGCode::Item> custom_gcode_per_print_z;
#if ENABLE_NEW_GCODE_VIEWER
bool spiral_vase_mode;
#else
std::vector<std::pair<float, std::pair<size_t, size_t>>> 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<float> fan_speed;
std::optional<float> 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<TimeBlock> blocks;
std::vector<G1LinesCacheItem> g1_times_cache;
#if ENABLE_NEW_GCODE_VIEWER
float first_layer_time;
std::vector<ActualSpeedMove> actual_speed_moves;
#else
std::array<float, static_cast<size_t>(EMoveType::Count)> moves_time;
std::array<float, static_cast<size_t>(GCodeExtrusionRole::Count)> roles_time;
std::vector<float> 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<std::chrono::high_resolution_clock> 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<std::pair<CustomGCode::Type, std::pair<float, float>>> 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<std::pair<EMoveType, float>> get_moves_time(PrintEstimatedStatistics::ETimeMode mode) const;
std::vector<std::pair<GCodeExtrusionRole, float>> get_roles_time(PrintEstimatedStatistics::ETimeMode mode) const;
std::vector<float> 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);

View File

@ -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_

View File

@ -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.

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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 <libvgcode/include/Types.hpp>
#endif // ENABLE_NEW_GCODE_VIEWER
#include <cstdint>
#include <float.h>
@ -32,359 +30,6 @@ namespace GUI {
class GCodeViewer
{
using IBufferType = unsigned short;
using VertexBuffer = std::vector<float>;
using MultiVertexBuffer = std::vector<VertexBuffer>;
using IndexBuffer = std::vector<IBufferType>;
using MultiIndexBuffer = std::vector<IndexBuffer>;
using InstanceBuffer = std::vector<float>;
using InstanceIdBuffer = std::vector<size_t>;
using InstancesOffsets = std::vector<Vec3f>;
#if !ENABLE_NEW_GCODE_VIEWER
static const std::array<ColorRGBA, static_cast<size_t>(GCodeExtrusionRole::Count)> Extrusion_Role_Colors;
static const std::vector<ColorRGBA> Options_Colors;
static const std::vector<ColorRGBA> Travel_Colors;
static const std::vector<ColorRGBA> 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<unsigned int> vaos;
#endif // ENABLE_GL_CORE_PROFILE
// vbos id
std::vector<unsigned int> vbos;
// sizes of the buffers, in bytes, used in export to obj
std::vector<size_t> 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<Range> 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<size_t> 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_Path> 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<int>(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<unsigned int> sizes;
std::vector<size_t> 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<size_t>(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<IBuffer> 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<Path> paths;
std::vector<RenderPath> 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<size_t>(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<size_t>(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<Range, static_cast<size_t>(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<double> m_zs;
std::vector<Range> 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<double>();
m_ranges = std::vector<Range>();
}
size_t size() const { return m_zs.size(); }
bool empty() const { return m_zs.empty(); }
const std::vector<double>& get_zs() const { return m_zs; }
const std::vector<Range>& get_ranges() const { return m_ranges; }
std::vector<Range>& 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<unsigned int> 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<TBuffer> m_buffers{ static_cast<size_t>(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<ColorRGBA> m_tool_colors;
Layers m_layers;
std::array<unsigned int, 2> m_layers_z_range;
std::vector<GCodeExtrusionRole> m_roles;
std::vector<unsigned char> m_extruder_ids;
Extrusions m_extrusions;
#endif // !ENABLE_NEW_GCODE_VIEWER
size_t m_extruders_count;
std::vector<float> m_filament_diameters;
std::vector<float> 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<SequentialRangeCap, 2> m_sequential_range_caps;
std::array<std::vector<float>, static_cast<size_t>(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<CustomGCode::Item> 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<std::string>& str_tool_colors,
const std::vector<std::string>& 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<std::string>& 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<double> get_layers_zs() const {
const std::vector<float> zs = m_viewer.get_layers_zs();
std::vector<double> ret;
@ -1002,23 +316,17 @@ public:
return ret;
}
std::vector<float> get_layers_times() const { return m_viewer.get_layers_estimated_times(); }
#else
const std::vector<double>& 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<unsigned int, 2>& 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<CustomGCode::Item>& 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

File diff suppressed because it is too large Load Diff

View File

@ -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<float> 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<double> get_gcode_layers_zs() const;
std::vector<double> get_gcode_layers_zs() const { return m_gcode_viewer.get_layers_zs(); }
std::vector<float> get_gcode_layers_times() const { return m_gcode_viewer.get_layers_times(); }
const std::vector<float>& 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<double>& 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<double> get_volumes_print_zs(bool active_only) const;
#endif // ENABLE_NEW_GCODE_VIEWER
void set_volumes_z_range(const std::array<double, 2>& range);
void set_volumes_z_range(const std::array<double, 2>& range) { m_volumes.set_range(range[0] - 1e-6, range[1] + 1e-6); }
void set_toolpaths_z_range(const std::array<unsigned int, 2>& range);
#if !ENABLE_NEW_GCODE_VIEWER
std::vector<CustomGCode::Item>& 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<int> load_object(const ModelObject& model_object, int obj_idx, std::vector<int> 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<std::string>& str_tool_colors,
const std::vector<std::string>& 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<std::string>& str_tool_colors, const std::vector<std::string>& str_color_print_colors,
const std::vector<CustomGCode::Item>& color_print_values);
#else
void load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& 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<std::string>& str_tool_colors, const std::vector<CustomGCode::Item>& 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<std::string>& str_tool_colors, const std::vector<CustomGCode::Item>& 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<std::string>& 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

View File

@ -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()) {

View File

@ -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<double>& 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<double>& 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<int> visible_range_min, std::optional<int> 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<int>(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<double> values;
values.reserve(view.endpoints.last - view.endpoints.first + 1);
std::vector<double> 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<double>(i + 1);
alternate_values.back() = static_cast<double>(view.gcode_ids[i]);
continue;
}
else
last_gcode_id = view.gcode_ids[i];
}
values.emplace_back(static_cast<double>(i + 1));
alternate_values.emplace_back(static_cast<double>(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<std::string> colors;
std::vector<CustomGCode::Item> 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<double> 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<Item> 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<unsigned int>(m_moves_slider->GetLowerValueD() - 1.0), static_cast<unsigned int>(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

View File

@ -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<void()> 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<int> visible_range_min = std::nullopt, std::optional<int> 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();

View File

@ -73,10 +73,8 @@ static const std::map<const wchar_t, std::string> 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<const wchar_t, std::string> font_icons_large = {

View File

@ -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<std::string
} // namespace libvgcode
#endif // ENABLE_NEW_GCODE_VIEWER

View File

@ -5,7 +5,6 @@
#ifndef slic3r_LibVGCodeWrapper_hpp_
#define slic3r_LibVGCodeWrapper_hpp_
#if ENABLE_NEW_GCODE_VIEWER
#include "libslic3r/Color.hpp"
#include "libslic3r/GCode/GCodeProcessor.hpp"
#include "slic3r/GUI/GUI_Preview.hpp"
@ -68,6 +67,4 @@ extern GCodeInputData convert(const Slic3r::Print& print, const std::vector<std:
} // namespace libvgcode
#endif // ENABLE_NEW_GCODE_VIEWER
#endif // slic3r_LibVGCodeWrapper_hpp_

View File

@ -392,12 +392,7 @@ struct Plater::priv
bool init_collapse_toolbar();
void set_preview_layers_slider_values_range(int bottom, int top);
#if ENABLE_NEW_GCODE_VIEWER
void update_preview_moves_slider(std::optional<int> visible_range_min = std::nullopt, std::optional<int> 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<int> visible_range_min, std::optional<int> 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<size_t> Plater::load_files(const std::vector<fs::path>& 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<int> visible_range_min, std::optional<int> 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)
{

View File

@ -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<size_t> load_files(const std::vector<boost::filesystem::path>& 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<int> visible_range_min = std::nullopt, std::optional<int> 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();