From 04958af691abfebc8314b300b4d8676f074439a7 Mon Sep 17 00:00:00 2001 From: FormerLurker Date: Sun, 17 May 2020 17:36:56 -0500 Subject: Rewrite arc generation routine, add custom float to string function. --- GcodeProcessorLib/GcodeProcessorLib.vcxproj | 56 +++++++++++++++++++++++++++++ GcodeProcessorLib/array_list.h | 23 +++++++----- GcodeProcessorLib/gcode_position.cpp | 6 ++++ GcodeProcessorLib/gcode_position.h | 1 + GcodeProcessorLib/utilities.cpp | 48 +++++++++++++++++++++++++ GcodeProcessorLib/utilities.h | 1 + 6 files changed, 126 insertions(+), 9 deletions(-) (limited to 'GcodeProcessorLib') diff --git a/GcodeProcessorLib/GcodeProcessorLib.vcxproj b/GcodeProcessorLib/GcodeProcessorLib.vcxproj index aba91bd..ec6b6a7 100644 --- a/GcodeProcessorLib/GcodeProcessorLib.vcxproj +++ b/GcodeProcessorLib/GcodeProcessorLib.vcxproj @@ -17,6 +17,14 @@ Release x64 + + Remote_Pi + Win32 + + + Remote_Pi + x64 + 16.0 @@ -31,6 +39,12 @@ v142 Unicode + + StaticLibrary + true + v142 + Unicode + StaticLibrary false @@ -44,6 +58,12 @@ v142 Unicode + + StaticLibrary + true + v142 + Unicode + StaticLibrary false @@ -59,12 +79,18 @@ + + + + + + @@ -72,9 +98,15 @@ true + + true + true + + true + false @@ -93,6 +125,18 @@ true + + + Level3 + true + _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + Level3 @@ -105,6 +149,18 @@ true + + + Level3 + true + _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + Level3 diff --git a/GcodeProcessorLib/array_list.h b/GcodeProcessorLib/array_list.h index 94862f3..6e48f96 100644 --- a/GcodeProcessorLib/array_list.h +++ b/GcodeProcessorLib/array_list.h @@ -35,6 +35,7 @@ public: count_ = 0; items_ = new T[max_size_]; } + array_list(int max_size) { auto_grow_ = false; @@ -43,9 +44,11 @@ public: count_ = 0; items_ = new T[max_size]; } + virtual ~array_list() { delete[] items_; } + void resize(int max_size) { T* new_items = new T[max_size]; @@ -58,6 +61,7 @@ public: items_ = new_items; max_size_ = max_size; } + void push_front(T object) { if (count_ == max_size_) @@ -74,6 +78,7 @@ public: count_++; items_[front_index_] = object; } + void push_back(T object) { if (count_ == max_size_) @@ -89,6 +94,7 @@ public: items_[(front_index_ + count_ + max_size_) % max_size_] = object; count_++; } + T pop_front() { if (count_ == 0) @@ -111,34 +117,33 @@ public: return items_[--count_]; } - T& operator[](int index) - { - return items_[(front_index_ + index + max_size_) % max_size_]; - } - const T& operator[] (const int index) const + + T& operator[] (const int index) const { return items_[(front_index_ + index + max_size_) % max_size_]; } - const T get(int index) + T get(int index) const { return items_[(front_index_ + index + max_size_) % max_size_]; } - int count() const + int count() const { return count_; - } - int get_max_size() + + int get_max_size() const { return max_size_; } + void clear() { count_ = 0; front_index_ = 0; } + void copy(const array_list& source) { if (max_size_ < source.max_size_) diff --git a/GcodeProcessorLib/gcode_position.cpp b/GcodeProcessorLib/gcode_position.cpp index 7e56844..3ba1514 100644 --- a/GcodeProcessorLib/gcode_position.cpp +++ b/GcodeProcessorLib/gcode_position.cpp @@ -371,6 +371,12 @@ gcode_position::~gcode_position() delete_z_lift_heights_(); } +bool gcode_position::get_g90_91_influences_extruder() +{ + return g90_influences_extruder_; +} + + void gcode_position::set_num_extruders(int num_extruders) { delete_retraction_lengths_(); diff --git a/GcodeProcessorLib/gcode_position.h b/GcodeProcessorLib/gcode_position.h index e89f8df..521f0d3 100644 --- a/GcodeProcessorLib/gcode_position.h +++ b/GcodeProcessorLib/gcode_position.h @@ -146,6 +146,7 @@ public: position * get_current_position_ptr(); position * get_previous_position_ptr(); gcode_comment_processor* get_gcode_comment_processor(); + bool get_g90_91_influences_extruder(); private: gcode_position(const gcode_position &source); int position_buffer_size_; diff --git a/GcodeProcessorLib/utilities.cpp b/GcodeProcessorLib/utilities.cpp index 8844922..5e90768 100644 --- a/GcodeProcessorLib/utilities.cpp +++ b/GcodeProcessorLib/utilities.cpp @@ -123,6 +123,54 @@ std::string utilities::to_string(double value) return os.str(); } +char * utilities::to_string(double value, unsigned short precision, char * str) +{ + char reversed_int[20]; + + int char_count = 0, int_count = 0; + bool is_negative = false; + double integer_part, fractional_part; + fractional_part = std::abs(std::modf(value, &integer_part)); //Separate integer/fractional parts + if (value < 0) + { + str[char_count++] = '-'; + integer_part *= -1; + is_negative = true; + } + + if (integer_part == 0) + { + str[char_count++] = '0'; + } + else + { + while (integer_part > 0) //Convert integer part, if any + { + reversed_int[int_count++] = '0' + (int)std::fmod(integer_part, 10); + integer_part = std::floor(integer_part / 10); + } + } + int start = is_negative ? 1 : 0; + int end = char_count - start; + for (int i = 0; i < int_count; i++) + { + str[char_count++] = reversed_int[int_count - i - 1]; + } + if (precision > 0) + { + str[char_count++] = '.'; //Decimal point + + while (fractional_part > 0 && precision-- > 0) //Convert fractional part, if any + { + fractional_part *= 10; + fractional_part = std::modf(fractional_part, &integer_part); + str[char_count++] = '0' + (int)integer_part; + } + } + str[char_count] = 0; //String terminator + return str; +} + std::string utilities::ltrim(const std::string& s) { size_t start = s.find_first_not_of(WHITESPACE_); diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h index a109a98..db858ad 100644 --- a/GcodeProcessorLib/utilities.h +++ b/GcodeProcessorLib/utilities.h @@ -44,6 +44,7 @@ public: static double get_cartesian_distance(double x1, double y1, double x2, double y2); static double get_cartesian_distance(double x1, double y1, double z1, double x2, double y2, double z2); static std::string to_string(double value); + static char* to_string(double value, unsigned short precision, char* str); static std::string ltrim(const std::string& s); static std::string rtrim(const std::string& s); static std::string trim(const std::string& s); -- cgit v1.2.3