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:
authorFormerLurker <hochgebe@gmail.com>2021-07-02 22:24:47 +0300
committerFormerLurker <hochgebe@gmail.com>2021-07-02 22:24:47 +0300
commit18d1e992d3773485d2b7b05ffaec1ea00b16c777 (patch)
tree42983ee7c351d32d38afb437642ed9f9e861a024 /GcodeProcessorLib
parent65768d59a9ed785ddb740fc6df67d2912d2a5bdf (diff)
Add support for variable line widths.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r--GcodeProcessorLib/GcodeProcessorLib.vcxproj2
-rw-r--r--GcodeProcessorLib/GcodeProcessorLib.vcxproj.filters12
-rw-r--r--GcodeProcessorLib/array_list.cpp22
-rw-r--r--GcodeProcessorLib/circular_buffer.cpp22
-rw-r--r--GcodeProcessorLib/circular_buffer.h108
-rw-r--r--GcodeProcessorLib/gcode_position.cpp107
-rw-r--r--GcodeProcessorLib/gcode_position.h8
-rw-r--r--GcodeProcessorLib/position.cpp4
-rw-r--r--GcodeProcessorLib/position.h1
-rw-r--r--GcodeProcessorLib/utilities.cpp19
-rw-r--r--GcodeProcessorLib/utilities.h3
11 files changed, 175 insertions, 133 deletions
diff --git a/GcodeProcessorLib/GcodeProcessorLib.vcxproj b/GcodeProcessorLib/GcodeProcessorLib.vcxproj
index 956df18..778d3f3 100644
--- a/GcodeProcessorLib/GcodeProcessorLib.vcxproj
+++ b/GcodeProcessorLib/GcodeProcessorLib.vcxproj
@@ -210,8 +210,6 @@
<ClInclude Include="version.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="array_list.cpp" />
- <ClCompile Include="circular_buffer.cpp" />
<ClCompile Include="extruder.cpp" />
<ClCompile Include="fpconv.cpp" />
<ClCompile Include="gcode_comment_processor.cpp" />
diff --git a/GcodeProcessorLib/GcodeProcessorLib.vcxproj.filters b/GcodeProcessorLib/GcodeProcessorLib.vcxproj.filters
index 60b8ca9..3aed5ba 100644
--- a/GcodeProcessorLib/GcodeProcessorLib.vcxproj.filters
+++ b/GcodeProcessorLib/GcodeProcessorLib.vcxproj.filters
@@ -18,9 +18,6 @@
<ClInclude Include="array_list.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="circular_buffer.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="extruder.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -54,14 +51,11 @@
<ClInclude Include="fpconv.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="circular_buffer.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="array_list.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="circular_buffer.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="extruder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/GcodeProcessorLib/array_list.cpp b/GcodeProcessorLib/array_list.cpp
deleted file mode 100644
index b2e46ea..0000000
--- a/GcodeProcessorLib/array_list.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Gcode Processor Library
-//
-// Tools for parsing gcode and calculating printer state from parsed gcode commands.
-//
-// Copyright(C) 2020 - Brad Hochgesang
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// This program is free software : you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published
-// by the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
-// GNU Affero General Public License for more details.
-//
-//
-// You can contact the author at the following email address:
-// FormerLurker@pm.me
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-#include "array_list.h" \ No newline at end of file
diff --git a/GcodeProcessorLib/circular_buffer.cpp b/GcodeProcessorLib/circular_buffer.cpp
deleted file mode 100644
index c17c240..0000000
--- a/GcodeProcessorLib/circular_buffer.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Gcode Processor Library
-//
-// Tools for parsing gcode and calculating printer state from parsed gcode commands.
-//
-// Copyright(C) 2020 - Brad Hochgesang
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// This program is free software : you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published
-// by the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
-// GNU Affero General Public License for more details.
-//
-//
-// You can contact the author at the following email address:
-// FormerLurker@pm.me
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-#include "circular_buffer.h" \ No newline at end of file
diff --git a/GcodeProcessorLib/circular_buffer.h b/GcodeProcessorLib/circular_buffer.h
index 0312a29..97f25ab 100644
--- a/GcodeProcessorLib/circular_buffer.h
+++ b/GcodeProcessorLib/circular_buffer.h
@@ -1,7 +1,9 @@
+#pragma once
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Gcode Processor Library
//
// Tools for parsing gcode and calculating printer state from parsed gcode commands.
+
//
// Copyright(C) 2020 - Brad Hochgesang
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -19,6 +21,7 @@
// You can contact the author at the following email address:
// FormerLurker@pm.me
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
#pragma once
#include <exception>
template <typename T>
@@ -32,6 +35,7 @@ public:
count_ = 0;
items_ = new T[max_size_];
}
+
circular_buffer(int max_size)
{
max_size_ = max_size;
@@ -39,13 +43,24 @@ public:
count_ = 0;
items_ = new T[max_size];
}
+
virtual ~circular_buffer() {
delete[] items_;
}
+
+ void initialize(T object)
+ {
+ for (int index = 0; index < max_size_; index++)
+ {
+ push_back(object);
+ }
+ count_ = 0;
+ front_index_ = 0;
+ }
+
void resize(int max_size)
{
T* new_items = new T[max_size];
- int count = count_;
for (int index = 0; index < count_; index++)
{
new_items[index] = items_[(front_index_ + index + max_size_) % max_size_];
@@ -55,12 +70,61 @@ public:
items_ = new_items;
max_size_ = max_size;
}
+
+ void resize(int max_size, T object)
+ {
+ T* new_items = new T[max_size];
+ for (int index = 0; index < count_; index++)
+ {
+ new_items[index] = items_[(front_index_ + index + max_size_) % max_size_];
+ }
+ // Initialize the rest of the entries
+ for (int index = count_; index < max_size; index++)
+ {
+ new_items[index] = object;
+ }
+ front_index_ = 0;
+ delete[] items_;
+ items_ = new_items;
+ max_size_ = max_size;
+ }
+
+ inline int get_index_position(int index) const
+ {
+ int index_position = index + front_index_ + max_size_;
+ while (index_position >= max_size_)
+ {
+ index_position = index_position - max_size_;
+ }
+ return index_position;
+ }
+
void push_front(T object)
{
- front_index_ = (front_index_ - 1 + max_size_) % max_size_;
- count_++;
+ //front_index_ = (front_index_ - 1 + max_size_) % max_size_;
+ front_index_ -= 1;
+ if (front_index_ < 0)
+ {
+ front_index_ = max_size_ - 1;
+ }
+ if (count_ != max_size_)
+ {
+ count_++;
+ }
items_[front_index_] = object;
}
+
+ void push_back(T object)
+ {
+ int pos = get_index_position(count_);
+ items_[pos] = object;
+ count_++;
+ if (count_ != max_size_)
+ {
+ count_++;
+ }
+ }
+
T& pop_front()
{
if (count_ == 0)
@@ -69,30 +133,55 @@ public:
}
int prev_start = front_index_;
- front_index_ = (front_index_ + 1 + max_size_) % max_size_;
+
+ front_index_ += 1;
+ if (front_index_ >= max_size_)
+ {
+ front_index_ = 0;
+ }
count_--;
return items_[prev_start];
}
- T& get(int index)
+ T& pop_back()
{
- return items_[(front_index_ + index + max_size_) % max_size_];
+ if (count_ == 0)
+ {
+ throw std::exception();
+ }
+ int pos = get_index_position(count_ - 1);
+ count_--;
+ return items_[pos];
}
- int count()
+ T& operator[] (int index) const
{
- return count_;
+ //int opos = get_index_position(index);
+ return items_[get_index_position(index)];
+ }
+
+ T& get(int index) const
+ {
+ int opos = get_index_position(index);
+ return items_[opos];
+ }
+ 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 circular_buffer<T>& source)
{
if (max_size_ < source.max_size_)
@@ -106,7 +195,6 @@ public:
}
front_index_ = source.front_index_;
count_ = source.count_;
-
}
protected:
diff --git a/GcodeProcessorLib/gcode_position.cpp b/GcodeProcessorLib/gcode_position.cpp
index fc469cd..444a879 100644
--- a/GcodeProcessorLib/gcode_position.cpp
+++ b/GcodeProcessorLib/gcode_position.cpp
@@ -206,10 +206,9 @@ void gcode_position_args::delete_y_firmware_offsets()
}
}
-gcode_position::gcode_position()
+gcode_position::gcode_position() : positions_(50), initial_position_(1)
{
position_buffer_size_ = 50;
- positions_ = new position[position_buffer_size_];
autodetect_position_ = false;
home_x_ = 0;
home_y_ = 0;
@@ -247,23 +246,19 @@ gcode_position::gcode_position()
z_max_ = 0;
is_circular_bed_ = false;
- cur_pos_ = -1;
- num_pos_ = 0;
- for(int index = 0; index < position_buffer_size_; index ++)
- {
- position initial_pos(num_extruders_);
- initial_pos.set_xyz_axis_mode(xyz_axis_default_mode_);
- initial_pos.set_e_axis_mode(e_axis_default_mode_);
- initial_pos.set_units_default(units_default_);
- add_position(initial_pos);
- }
- num_pos_ = 0;
+
+ position initial_pos(num_extruders_);
+ initial_pos.set_xyz_axis_mode(xyz_axis_default_mode_);
+ initial_pos.set_e_axis_mode(e_axis_default_mode_);
+ initial_pos.set_units_default(units_default_);
+
+ positions_.initialize(initial_pos);
+ initial_position_ = initial_pos;
}
-gcode_position::gcode_position(gcode_position_args args)
+gcode_position::gcode_position(gcode_position_args args) : positions_(args.position_buffer_size)
{
position_buffer_size_ = args.position_buffer_size;
- positions_ = new position[args.position_buffer_size] ;
autodetect_position_ = args.autodetect_position;
home_x_ = args.home_x;
home_y_ = args.home_y;
@@ -330,9 +325,6 @@ gcode_position::gcode_position(gcode_position_args args)
z_max_ = args.z_max;
is_circular_bed_ = args.is_circular_bed;
-
- cur_pos_ = -1;
- num_pos_ = 0;
num_extruders_ = args.num_extruders;
// Configure the initial position
@@ -346,15 +338,11 @@ gcode_position::gcode_position(gcode_position_args args)
initial_pos.p_extruders[index].x_firmware_offset = args.x_firmware_offsets[index];
initial_pos.p_extruders[index].y_firmware_offset = args.y_firmware_offsets[index];
}
-
- for (int index = 0; index < position_buffer_size_; index++)
- {
-
- add_position(initial_pos);
- }
- num_pos_ = 0;
+ positions_.initialize(initial_pos);
+ initial_position_ = initial_pos;
}
+
gcode_position::gcode_position(const gcode_position &source)
{
// Private copy constructor - you can't copy this class
@@ -362,11 +350,7 @@ gcode_position::gcode_position(const gcode_position &source)
gcode_position::~gcode_position()
{
- if (positions_ != NULL)
- {
- delete [] positions_;
- positions_ = NULL;
- }
+
delete_retraction_lengths_();
delete_z_lift_heights_();
}
@@ -376,7 +360,6 @@ bool gcode_position::get_g90_91_influences_extruder()
return g90_influences_extruder_;
}
-
void gcode_position::set_num_extruders(int num_extruders)
{
delete_retraction_lengths_();
@@ -413,32 +396,44 @@ void gcode_position::delete_z_lift_heights_()
int gcode_position::get_num_positions()
{
- return num_pos_;
+ return positions_.count();
+}
+
+int gcode_position::get_max_positions()
+{
+ return positions_.get_max_size();
+}
+
+void gcode_position::grow_max_positions(int size)
+{
+ int current_size = positions_.get_max_size();
+ if (size < current_size)
+ {
+ return;
+ }
+ positions_.resize(size, initial_position_);
+
}
void gcode_position::add_position(position& pos)
{
- cur_pos_ = (cur_pos_+1) % position_buffer_size_;
- positions_[cur_pos_] = pos;
- if (num_pos_ < position_buffer_size_)
- num_pos_++;
+ positions_.push_front(pos);
}
void gcode_position::add_position(parsed_command& cmd)
{
- const int prev_pos = cur_pos_;
- cur_pos_ = (cur_pos_+1) % position_buffer_size_;
- positions_[cur_pos_] = positions_[prev_pos];
- positions_[cur_pos_].reset_state();
- positions_[cur_pos_].command = cmd;
- positions_[cur_pos_].is_empty = false;
- if (num_pos_ < position_buffer_size_)
- num_pos_++;
+
+ position current_position = positions_[0];
+ current_position.reset_state();
+ current_position.command = cmd;
+ current_position.is_empty = false;
+ positions_.push_front(current_position);
+
}
position gcode_position::get_position(int index)
{
- return positions_[(cur_pos_ - index + position_buffer_size_) % position_buffer_size_];
+ return positions_[index];
}
position gcode_position::get_current_position()
@@ -453,7 +448,7 @@ position gcode_position::get_previous_position()
position * gcode_position::get_position_ptr(int index)
{
- return &positions_[(cur_pos_ - index + position_buffer_size_) % position_buffer_size_];
+ return &positions_[index];
}
position * gcode_position::get_current_position_ptr()
@@ -697,11 +692,7 @@ void gcode_position::update(parsed_command& command, const long file_line_number
void gcode_position::undo_update()
{
- if (num_pos_ != 0)
- {
- cur_pos_ = (cur_pos_ - 1 + position_buffer_size_) % position_buffer_size_;
- num_pos_--;
- }
+ positions_.pop_front();
}
position* gcode_position::undo_update(int num_updates)
@@ -715,21 +706,9 @@ position* gcode_position::undo_update(int num_updates)
// add the positions we will undo to the array
for (int index = 0; index < num_updates; index++)
{
- p_undo_positions[index] = get_position(index);
- }
-
- if (num_pos_ < num_updates)
- {
- num_pos_ = 0;
- cur_pos_ = 0;
- }
- else
- {
- cur_pos_ = (cur_pos_ - num_updates + position_buffer_size_) % position_buffer_size_;
- num_pos_ -= num_updates;
+ p_undo_positions[index] = positions_.pop_front();
}
return p_undo_positions;
-
}
// Private Members
diff --git a/GcodeProcessorLib/gcode_position.h b/GcodeProcessorLib/gcode_position.h
index 521f0d3..5930cf6 100644
--- a/GcodeProcessorLib/gcode_position.h
+++ b/GcodeProcessorLib/gcode_position.h
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
#include <map>
+#include "circular_buffer.h"
#include "gcode_parser.h"
#include "position.h"
#include "gcode_comment_processor.h"
@@ -139,6 +140,8 @@ public:
void undo_update();
position * undo_update(int num_updates);
int get_num_positions();
+ int get_max_positions();
+ void grow_max_positions(int size);
position get_position(int index);
position get_current_position();
position get_previous_position();
@@ -149,10 +152,9 @@ public:
bool get_g90_91_influences_extruder();
private:
gcode_position(const gcode_position &source);
+ position initial_position_;
int position_buffer_size_;
- position* positions_;
- int cur_pos_;
- int num_pos_;
+ circular_buffer<position> positions_;
void add_position(parsed_command &);
void add_position(position &);
bool autodetect_position_;
diff --git a/GcodeProcessorLib/position.cpp b/GcodeProcessorLib/position.cpp
index 6a85801..8fcd8cd 100644
--- a/GcodeProcessorLib/position.cpp
+++ b/GcodeProcessorLib/position.cpp
@@ -356,6 +356,10 @@ position& position::operator=(const position& pos) {
return *this;
}
+bool position::is_travel()
+{
+ return is_xyz_travel || is_xy_travel;
+}
void position::set_num_extruders(int num_extruders_)
{
if (num_extruders_ == num_extruders)
diff --git a/GcodeProcessorLib/position.h b/GcodeProcessorLib/position.h
index 0958cd5..5059d5f 100644
--- a/GcodeProcessorLib/position.h
+++ b/GcodeProcessorLib/position.h
@@ -102,5 +102,6 @@ struct position
void set_e_axis_mode(const std::string& e_axis_default_mode);
void set_units_default(const std::string& units_default);
bool can_take_snapshot();
+ bool is_travel()
};
#endif \ No newline at end of file
diff --git a/GcodeProcessorLib/utilities.cpp b/GcodeProcessorLib/utilities.cpp
index 041f91f..b5a09a6 100644
--- a/GcodeProcessorLib/utilities.cpp
+++ b/GcodeProcessorLib/utilities.cpp
@@ -24,6 +24,7 @@
#include <sstream>
#include <iostream>
#include <iomanip>
+#include <algorithm>
#include "fpconv.h"
const std::string utilities::WHITESPACE_ = " \n\r\t\f\v";
@@ -320,4 +321,20 @@ std::string utilities::dtos(double x, unsigned char precision)
}
*/
return buffer;
-} \ No newline at end of file
+}
+
+bool utilities::case_insensitive_compare_char(char& c1, char& c2)
+{
+ if (c1 == c2)
+ return true;
+ else if (std::toupper(c1) == std::toupper(c2))
+ return true;
+ return false;
+}
+/*
+ * Case Insensitive String Comparision
+ */
+bool utilities::case_insensitive_compare(std::string& str1, std::string& str2)
+{
+ return ((str1.size() == str2.size()) && std::equal(str1.begin(), str1.end(), str2.begin(), &utilities::case_insensitive_compare_char));
+}
diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h
index b41d6f6..33afd51 100644
--- a/GcodeProcessorLib/utilities.h
+++ b/GcodeProcessorLib/utilities.h
@@ -41,6 +41,9 @@ 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 bool case_insensitive_compare_char(char& c1, char& c2);
+ static bool case_insensitive_compare(std::string& str1, std::string& str2);
static std::string to_string(double value);
static std::string to_string(int value);
static std::string ltrim(const std::string& s);