diff options
author | FormerLurker <hochgebe@gmail.com> | 2020-05-18 01:36:56 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2020-05-18 01:36:56 +0300 |
commit | 04958af691abfebc8314b300b4d8676f074439a7 (patch) | |
tree | c1e4285681ec4362d34662a45534ef490c198c10 /GcodeProcessorLib | |
parent | f962acda6cfd7d12dd917803a2e92568dd0d00e2 (diff) |
Rewrite arc generation routine, add custom float to string function.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r-- | GcodeProcessorLib/GcodeProcessorLib.vcxproj | 56 | ||||
-rw-r--r-- | GcodeProcessorLib/array_list.h | 23 | ||||
-rw-r--r-- | GcodeProcessorLib/gcode_position.cpp | 6 | ||||
-rw-r--r-- | GcodeProcessorLib/gcode_position.h | 1 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.cpp | 48 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.h | 1 |
6 files changed, 126 insertions, 9 deletions
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 @@ <Configuration>Release</Configuration> <Platform>x64</Platform> </ProjectConfiguration> + <ProjectConfiguration Include="Remote_Pi|Win32"> + <Configuration>Remote_Pi</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Remote_Pi|x64"> + <Configuration>Remote_Pi</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> <VCProjectVersion>16.0</VCProjectVersion> @@ -31,6 +39,12 @@ <PlatformToolset>v142</PlatformToolset> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> @@ -44,6 +58,12 @@ <PlatformToolset>v142</PlatformToolset> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> @@ -59,12 +79,18 @@ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> @@ -72,9 +98,15 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <LinkIncremental>true</LinkIncremental> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <LinkIncremental>true</LinkIncremental> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <LinkIncremental>false</LinkIncremental> </PropertyGroup> @@ -93,6 +125,18 @@ <GenerateDebugInformation>true</GenerateDebugInformation> </Link> </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> <WarningLevel>Level3</WarningLevel> @@ -105,6 +149,18 @@ <GenerateDebugInformation>true</GenerateDebugInformation> </Link> </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Remote_Pi|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> <WarningLevel>Level3</WarningLevel> 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<T>& 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); |