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-11-21 21:31:00 +0300
committerFormerLurker <hochgebe@gmail.com>2021-11-21 21:31:00 +0300
commit9b0afec63643275ecdc9005bfbbba20e359a7938 (patch)
treecc9153d01a15d3764dd99bd53e30b6a178c21835 /GcodeProcessorLib
parent4c193828056771381f7bfc6f04133bd1a45447ac (diff)
Make extrusion-rate-variance-percent optional (0 to disable). Add HTML box drawing for pretty statistics. Separate extrusion and retraction statistics for analyzation purposes, but keep combined statistics.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r--GcodeProcessorLib/logger.cpp26
-rw-r--r--GcodeProcessorLib/logger.h14
-rw-r--r--GcodeProcessorLib/utilities.cpp88
-rw-r--r--GcodeProcessorLib/utilities.h31
4 files changed, 132 insertions, 27 deletions
diff --git a/GcodeProcessorLib/logger.cpp b/GcodeProcessorLib/logger.cpp
index 3bde18e..6aa591a 100644
--- a/GcodeProcessorLib/logger.cpp
+++ b/GcodeProcessorLib/logger.cpp
@@ -36,7 +36,7 @@ logger::logger(std::vector<std::string> names, std::vector<int> levels) {
logger_names_[index] = names[index];
logger_levels_[index] = levels[index];
}
- set_log_level_by_value(NOSET);
+ set_log_level_by_value((int)log_levels::NOSET);
}
@@ -58,9 +58,9 @@ void logger::set_log_level_by_value(const int level_value)
}
}
-void logger::set_log_level(const int logger_type, const int log_level)
+void logger::set_log_level(const int logger_type, log_levels log_level)
{
- logger_levels_[logger_type] = log_level;
+ logger_levels_[logger_type] = (int)log_level;
}
std::string logger::get_log_level_name(std::string logger_name)
{
@@ -76,17 +76,17 @@ std::string logger::get_log_level_name(std::string logger_name)
return log_level_name;
}
-void logger::set_log_level(const int log_level)
+void logger::set_log_level(log_levels log_level)
{
for (int type_index = 0; type_index < num_loggers_; type_index++)
{
- logger_levels_[type_index] = log_level;
+ logger_levels_[type_index] = (int)log_level;
}
}
-int logger::get_log_level_value(const int log_level)
+int logger::get_log_level_value(log_levels log_level)
{
- return log_level_values[log_level];
+ return log_level_values[(int)log_level];
}
int logger::get_log_level_for_value(int log_level_value)
{
@@ -97,12 +97,12 @@ int logger::get_log_level_for_value(int log_level_value)
}
return 0;
}
-bool logger::is_log_level_enabled(const int logger_type, const int log_level)
+bool logger::is_log_level_enabled(const int logger_type, log_levels log_level)
{
- return logger_levels_[logger_type] <= log_level;
+ return logger_levels_[logger_type] <= (int)log_level;
}
-void logger::create_log_message(const int logger_type, const int log_level, const std::string& message, std::string& output)
+void logger::create_log_message(const int logger_type, log_levels log_level, const std::string& message, std::string& output)
{
// example message
// 2020-04-20 21:36:59,414 - arc_welder.__init__ - INFO - MESSAGE_GOES_HERE
@@ -116,7 +116,7 @@ void logger::create_log_message(const int logger_type, const int log_level, cons
// add a spacer
output.append(" - ");
// add the log level name
- output.append(log_level_names[log_level]);
+ output.append(log_level_names[(int)log_level]);
// add a spacer
output.append(" - ");
// add the message
@@ -128,12 +128,12 @@ void logger::log_exception(const int logger_type, const std::string& message)
log(logger_type, log_levels::ERROR, message, true);
}
-void logger::log(const int logger_type, const int log_level, const std::string& message)
+void logger::log(const int logger_type, log_levels log_level, const std::string& message)
{
log(logger_type, log_level, message, false);
}
-void logger::log(const int logger_type, const int log_level, const std::string& message, bool is_exception)
+void logger::log(const int logger_type, log_levels log_level, const std::string& message, bool is_exception)
{
// Make sure the loggers have been initialized
if (!loggers_created_)
diff --git a/GcodeProcessorLib/logger.h b/GcodeProcessorLib/logger.h
index f345097..8cbd5e3 100644
--- a/GcodeProcessorLib/logger.h
+++ b/GcodeProcessorLib/logger.h
@@ -46,18 +46,18 @@ public:
void set_log_level_by_value(const int logger_type, const int log_level_value);
void set_log_level_by_value(const int log_level_value);
- void set_log_level(const int logger_type, const int log_level);
- void set_log_level(const int log_level);
+ void set_log_level(const int logger_type, log_levels log_level);
+ void set_log_level(log_levels log_level);
std::string get_log_level_name(std::string logger_name);
- virtual void log(const int logger_type, const int log_level, const std::string& message);
- virtual void log(const int logger_type, const int log_level, const std::string& message, bool is_exception);
+ virtual void log(const int logger_type, log_levels log_level, const std::string& message);
+ virtual void log(const int logger_type, log_levels log_level, const std::string& message, bool is_exception);
virtual void log_exception(const int logger_type, const std::string& message);
- static int get_log_level_value(const int log_level);
+ static int get_log_level_value(log_levels log_level);
static int get_log_level_for_value(int log_level_value);
- virtual bool is_log_level_enabled(const int logger_type, const int log_level);
+ virtual bool is_log_level_enabled(const int logger_type, log_levels log_level);
protected:
- virtual void create_log_message(const int logger_type, const int log_level, const std::string& message, std::string& output);
+ virtual void create_log_message(const int logger_type, log_levels log_level, const std::string& message, std::string& output);
bool loggers_created_;
private:
diff --git a/GcodeProcessorLib/utilities.cpp b/GcodeProcessorLib/utilities.cpp
index c53ddf8..74fef46 100644
--- a/GcodeProcessorLib/utilities.cpp
+++ b/GcodeProcessorLib/utilities.cpp
@@ -23,6 +23,89 @@
#include "utilities.h"
namespace utilities {
+ // Box Drawing Consts
+ // String Consts
+ // Note: these ascii replacement characters must NOT appear in the text unless they will be replaced with box characters.
+ const char box_drawing::table_elements_replacement[8] = {char(128),char(129),char(130),char(131),char(132),char(133),char(134),char(135) };
+ //enum BoxElementEnum { HORIZONTAL = 0, VERTICAL = 1, UPPER_LEFT = 2, UPPER_RIGHT = 3, MIDDLE_LEFT = 4, MIDDLE_RIGHT = 5, LOWER_LEFT = 6, LOWER_RIGHT = 7 };
+ const std::string box_drawing::table_elements_ascii[8] = {"-","|","+" ,"+" ,"+" ,"+" ,"+" ,"+" };
+ const std::string box_drawing::table_elements_utf8[8] = { "\u2500","\u2502","\u250C" ,"\u2510" ,"\u251C" ,"\u2524" ,"\u2514" ,"\u2518" };
+ const std::string box_drawing::table_elements_html[8] = { "&#9472","&#9474", "&#9484","&#9488","&#9500","&#9508","&#9492","&#9496" };
+
+ box_drawing::box_drawing()
+ {
+ set_box_type(BoxEncodingEnum::ASCII);
+
+ width_ = 100;
+ }
+ box_drawing::box_drawing(BoxEncodingEnum encoding, int width)
+ {
+ set_box_type(encoding);
+ width_ = width;
+ }
+
+ void box_drawing::set_box_type(BoxEncodingEnum encoding)
+ {
+ box_encoding_ = encoding;
+ for (int index = 0; index < 8; index++)
+ {
+ switch (box_encoding_)
+ {
+ case BoxEncodingEnum::ASCII:
+ table_elements_[index] = table_elements_ascii[index];
+ break;
+ case BoxEncodingEnum::UTF8:
+ table_elements_[index] = table_elements_utf8[index];
+ break;
+ case BoxEncodingEnum::HTML:
+ table_elements_[index] = table_elements_html[index];
+ break;
+ default:
+ table_elements_[index] = table_elements_ascii[index];
+ }
+
+ }
+ }
+
+ void box_drawing::top(std::stringstream& stream)
+ {
+ stream << get_box_replacement_element(BoxElementEnum::UPPER_LEFT) << std::setw(width_) << std::setfill(get_box_replacement_element(BoxElementEnum::HORIZONTAL)) << "" << get_box_replacement_element(BoxElementEnum::UPPER_RIGHT) << "\n" << std::setfill(' ');
+ }
+
+ void box_drawing::row(std::stringstream& stream, std::string line)
+ {
+ stream << get_box_replacement_element(BoxElementEnum::VERTICAL) << line << get_box_replacement_element(BoxElementEnum::VERTICAL) << "\n" << std::setfill(' ');
+ }
+
+ void box_drawing::middle(std::stringstream& stream)
+ {
+ stream << get_box_replacement_element(BoxElementEnum::MIDDLE_LEFT) << std::setw(width_) << std::setfill(get_box_replacement_element(BoxElementEnum::HORIZONTAL)) << "" << get_box_replacement_element(BoxElementEnum::MIDDLE_RIGHT) << "\n" << std::setfill(' ');
+ }
+ void box_drawing::bottom(std::stringstream& stream)
+ {
+ stream << get_box_replacement_element(BoxElementEnum::LOWER_LEFT) << std::setw(width_) << std::setfill(get_box_replacement_element(BoxElementEnum::HORIZONTAL)) << "" << get_box_replacement_element(BoxElementEnum::LOWER_RIGHT) << "\n" << std::setfill(' ');
+ }
+
+ char box_drawing::get_box_replacement_element(BoxElementEnum element)
+ {
+ return table_elements_replacement[(int)element];
+ }
+
+ void box_drawing::make_replacements(std::string &box)
+ {
+ for (int index = 0; index < 8; index++)
+ {
+ char c = table_elements_replacement[index];
+ std::string search;
+ search += c;
+ box = utilities::replace(box, search, table_elements_[index]);
+ }
+
+ }
+
+
+
+
const std::string WHITESPACE_ = " \n\r\t\f\v";
const char GUID_RANGE[] = "0123456789abcdef";
const bool GUID_DASHES[] = { 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 };
@@ -504,11 +587,6 @@ double utilities::pow(int e, double x)
return std::pow(e, x);
}
-double utilities::pow(int e, int x)
-{
- return std::pow(e, x);
-}
-
double utilities::min(double x, double y)
{
return std::min(x, y);
diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h
index 88e8c40..1b7923f 100644
--- a/GcodeProcessorLib/utilities.h
+++ b/GcodeProcessorLib/utilities.h
@@ -147,7 +147,6 @@ namespace utilities{
double pow(int e, double x);
- double pow(int e, int x);
double min(double x, double y);
@@ -187,7 +186,35 @@ namespace utilities{
unsigned char rand_range(unsigned char min, unsigned char max);
int rand_range(int min, int max);
-
+
+
+ class box_drawing {
+
+ public:
+ enum BoxElementEnum { HORIZONTAL = 0, VERTICAL = 1, UPPER_LEFT = 2, UPPER_RIGHT = 3, MIDDLE_LEFT = 4, MIDDLE_RIGHT = 5, LOWER_LEFT = 6, LOWER_RIGHT = 7 };
+ enum BoxEncodingEnum {ASCII=0, UTF8=1, HTML=2};
+ box_drawing();
+ box_drawing(BoxEncodingEnum encoding, int width);
+ static const char table_elements_replacement[8];
+ static const std::string table_elements_ascii[8];
+ static const std::string table_elements_utf8[8];
+ static const std::string table_elements_html[8];
+ char get_box_replacement_element(BoxElementEnum element);
+ void top(std::stringstream& stream);
+ void row(std::stringstream& stream, std::string line);
+ void middle(std::stringstream& stream);
+ void bottom(std::stringstream& stream);
+ void set_box_type(BoxEncodingEnum encoding);
+ void make_replacements(std::string &box);
+
+ private:
+ std::string table_elements_[8];
+ BoxEncodingEnum box_encoding_;
+ std::string output_;
+ std::stringstream output_stream_;
+ int width_;
+
+ };
}
#endif \ No newline at end of file