Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ArcWelder/arc_welder.cpp')
-rw-r--r--ArcWelder/arc_welder.cpp78
1 files changed, 51 insertions, 27 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp
index 47a61f2..458b8e5 100644
--- a/ArcWelder/arc_welder.cpp
+++ b/ArcWelder/arc_welder.cpp
@@ -173,8 +173,10 @@ double arc_welder::get_time_elapsed(double start_clock, double end_clock)
return static_cast<double>(end_clock - start_clock) / CLOCKS_PER_SEC;
}
-void arc_welder::process()
+arc_welder_results arc_welder::process()
{
+ arc_welder_results results;
+
verbose_logging_enabled_ = p_logger_->is_log_level_enabled(logger_type_, VERBOSE);
debug_logging_enabled_ = p_logger_->is_log_level_enabled(logger_type_, DEBUG);
info_logging_enabled_ = p_logger_->is_log_level_enabled(logger_type_, INFO);
@@ -239,14 +241,20 @@ void arc_welder::process()
{
if ((lines_processed_ % read_lines_before_clock_check) == 0 && next_update_time < clock())
{
- long file_position = static_cast<long>(gcodeFile.tellg());
+ arc_welder_progress progress;
+ progress.gcodes_processed = gcodes_processed_;
+ progress.lines_processed = lines_processed_;
+ progress.points_compressed = points_compressed_;
+ progress.arcs_created = arcs_created_;
+ progress.target_file_size = static_cast<long>(output_file_.tellp());
+ progress.source_file_size = static_cast<long>(gcodeFile.tellg());
// ToDo: tellg does not do what I think it does, but why?
- long bytesRemaining = file_size_ - file_position;
- double percentProgress = static_cast<double>(file_position) / static_cast<double>(file_size_) * 100.0;
- double secondsElapsed = get_time_elapsed(start_clock, clock());
- double bytesPerSecond = static_cast<double>(file_position) / secondsElapsed;
- double secondsToComplete = bytesRemaining / bytesPerSecond;
- continue_processing = on_progress_(percentProgress, secondsElapsed, secondsToComplete, gcodes_processed_, lines_processed_, points_compressed_, arcs_created_);
+ long bytesRemaining = file_size_ - progress.source_file_size;
+ progress.percent_complete = static_cast<double>(progress.source_file_size) / static_cast<double>(file_size_) * 100.0;
+ progress.seconds_elapsed = get_time_elapsed(start_clock, clock());
+ double bytesPerSecond = static_cast<double>(progress.source_file_size) / progress.seconds_elapsed;
+ progress.seconds_remaining = bytesRemaining / bytesPerSecond;
+ continue_processing = on_progress_(progress);
next_update_time = get_next_update_time();
}
}
@@ -259,34 +267,48 @@ void arc_welder::process()
write_unwritten_gcodes_to_file();
output_file_.close();
+ results.success = continue_processing;
+ results.cancelled = !continue_processing;
+ results.progress.target_file_size = get_file_size(target_path_);
+
}
else
{
- p_logger_->log_exception(logger_type_, "Unable to open the output file for writing.");
+ results.success = false;
+ results.message = "Unable to open the target file for writing.";
+ p_logger_->log_exception(logger_type_, results.message);
}
gcodeFile.close();
}
else
{
- p_logger_->log_exception(logger_type_, "Unable to open the gcode file for processing.");
+ results.success = false;
+ results.message = "Unable to open the input file for processing.";
+ p_logger_->log_exception(logger_type_, results.message);
}
+
const clock_t end_clock = clock();
const double total_seconds = static_cast<double>(end_clock - start_clock) / CLOCKS_PER_SEC;
- on_progress_(100, total_seconds, 0, gcodes_processed_, lines_processed_, points_compressed_, arcs_created_);
+ results.progress.seconds_elapsed = total_seconds;
+ results.progress.gcodes_processed = gcodes_processed_;
+ results.progress.lines_processed = lines_processed_;
+ results.progress.points_compressed = points_compressed_;
+ results.progress.arcs_created = arcs_created_;
+ results.progress.source_file_size = file_size_;
+ return results;
}
-bool arc_welder::on_progress_(double percentComplete, double seconds_elapsed, double estimatedSecondsRemaining, int gcodesProcessed, int linesProcessed, int points_compressed, int arcs_created)
+bool arc_welder::on_progress_(arc_welder_progress progress)
{
if (progress_callback_ != NULL)
{
- return progress_callback_(percentComplete, seconds_elapsed, estimatedSecondsRemaining, gcodesProcessed, linesProcessed, points_compressed, arcs_created);
+ return progress_callback_(progress);
}
std::stringstream stream;
if (debug_logging_enabled_)
{
- stream << percentComplete << "% complete in " << seconds_elapsed << " seconds with " << estimatedSecondsRemaining << " seconds remaining. Gcodes Processed:" << gcodesProcessed << ", Current Line:" << linesProcessed << ", Points Compressed:" << points_compressed << ", ArcsCreated:" << arcs_created;
- p_logger_->log(logger_type_, DEBUG, stream.str());
+ p_logger_->log(logger_type_, DEBUG, progress.str());
}
return true;
@@ -299,6 +321,9 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
position* p_cur_pos = p_source_position_->get_current_position_ptr();
position* p_pre_pos = p_source_position_->get_previous_position_ptr();
+ extruder extruder_current = p_cur_pos->get_current_extruder();
+ extruder previous_extruder = p_pre_pos->get_current_extruder();
+ point p(p_cur_pos->x, p_cur_pos->y, p_cur_pos->z, extruder_current.e_relative);
//std::cout << lines_processed_ << " - " << cmd.gcode << ", CurrentEAbsolute: " << cur_extruder.e <<", ExtrusionLength: " << cur_extruder.extrusion_length << ", Retraction Length: " << cur_extruder.retraction_length << ", IsExtruding: " << cur_extruder.is_extruding << ", IsRetracting: " << cur_extruder.is_retracting << ".\n";
int lines_written = 0;
@@ -307,8 +332,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
bool arc_added = false;
bool clear_shapes = false;
- extruder extruder_current = p_cur_pos->get_current_extruder();
- point p(p_cur_pos->x, p_cur_pos->y, p_cur_pos->z, extruder_current.e_relative);
+
// We need to make sure the printer is using absolute xyz, is extruding, and the extruder axis mode is the same as that of the previous position
// TODO: Handle relative XYZ axis. This is possible, but maybe not so important.
@@ -319,8 +343,8 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
!p_cur_pos->is_relative &&
(
!waiting_for_arc_ ||
- (p_pre_pos->get_current_extruder().is_extruding && extruder_current.is_extruding) ||
- (p_pre_pos->get_current_extruder().is_retracting && extruder_current.is_retracting)
+ (previous_extruder.is_extruding && extruder_current.is_extruding) ||
+ (previous_extruder.is_retracting && extruder_current.is_retracting)
) &&
p_cur_pos->is_extruder_relative == p_pre_pos->is_extruder_relative &&
(!waiting_for_arc_ || p_pre_pos->f == p_cur_pos->f) &&
@@ -336,13 +360,13 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
}
write_unwritten_gcodes_to_file();
// add the previous point as the starting point for the current arc
- point previous_p(p_pre_pos->x, p_pre_pos->y, p_pre_pos->z, p_pre_pos->get_current_extruder().e_relative);
+ point previous_p(p_pre_pos->x, p_pre_pos->y, p_pre_pos->z, previous_extruder.e_relative);
// Don't add any extrusion, or you will over extrude!
//std::cout << "Trying to add first point (" << p.x << "," << p.y << "," << p.z << ")...";
current_arc_.try_add_point(previous_p, 0);
}
- double e_relative = p_cur_pos->get_current_extruder().e_relative;
+ double e_relative = extruder_current.e_relative;
int num_points = current_arc_.get_num_segments();
arc_added = current_arc_.try_add_point(p, e_relative);
if (arc_added)
@@ -391,15 +415,15 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
}
else if (
waiting_for_arc_ && !(
- (p_pre_pos->get_current_extruder().is_extruding && extruder_current.is_extruding) ||
- (p_pre_pos->get_current_extruder().is_retracting && extruder_current.is_retracting)
+ (previous_extruder.is_extruding && extruder_current.is_extruding) ||
+ (previous_extruder.is_retracting && extruder_current.is_retracting)
)
)
{
std::string message = "Extruding or retracting state changed, cannot add point to current arc: " + cmd.gcode;
if (verbose_logging_enabled_)
{
- extruder previous_extruder = p_pre_pos->get_current_extruder();
+
message.append(
" - Verbose Info\n\tCurrent Position Info - Absolute E:" + utilities::to_string(extruder_current.e) +
", Offset E:" + utilities::to_string(extruder_current.get_offset_e()) +
@@ -477,20 +501,19 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
{
unwritten_commands_.pop_back();
}
- // get the current absolute e coordinate of the previous position (the current position is not included in
- // the arc) so we can make any adjustments that are necessary.
+ // get the feedrate for the previous position
double current_f = p_pre_pos->f;
// IMPORTANT NOTE: p_cur_pos and p_pre_pos will NOT be usable beyond this point.
p_pre_pos = NULL;
p_cur_pos = NULL;
// Undo the previous updates that will be turned into the arc, including the current position
+ // (so not num_segments - 1, but num_segments)
for (int index = 0; index < current_arc_.get_num_segments(); index++)
{
undo_commands_.push_back(p_source_position_->get_current_position_ptr()->command);
p_source_position_->undo_update();
}
- //position * p_undo_positions = p_source_position_->undo_update(current_arc_.get_num_segments());
// Set the current feedrate if it is different, else set to 0 to indicate that no feedrate should be included
if(p_source_position_->get_current_position_ptr()->f == current_f)
@@ -558,6 +581,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end)
parsed_command cmd = undo_commands_.pop_back();
p_source_position_->update(undo_commands_[index], lines_processed_, gcodes_processed_, -1);
}
+ // Clear the undo commands (there should be one left)
undo_commands_.clear();
// Now clear the arc and flag the processor as not waiting for an arc
waiting_for_arc_ = false;