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

parsed_command.cpp « GcodeProcessorLib - github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c1b8c190f5f916aca1ea3311ba10cb4196ded9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Gcode Processor Library
//
// Tools for parsing gcode and calculating printer state from parsed gcode commands.
//
// Copyright(C) 2021 - 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 "parsed_command.h"
#include <sstream>
#include <iomanip>
#include <stdlib.h>
parsed_command::parsed_command()
{
	
	command.reserve(8);
	gcode.reserve(128);
	comment.reserve(128);
	parameters.reserve(6);
	is_known_command = false;
	is_empty = true;
}

void parsed_command::clear()
{
	
	command.clear();
	gcode.clear();
	comment.clear();
	parameters.clear();
	is_known_command = false;
	is_empty = true;
}

std::string parsed_command::rewrite_gcode_string()
{
	std::stringstream stream;
	
	// add command
	stream << command;
	if (parameters.size() > 0)
	{
		for (unsigned int index = 0; index < parameters.size(); index++)
		{
			parsed_command_parameter p = parameters[index];
			
			stream << " " << p.name;
			switch (p.value_type)
			{
			case 'S':
				stream << p.string_value;
				break;
			case 'F':
				stream << p.double_value << std::fixed << std::setprecision(p.double_precision);
				break;
			case 'U':
				stream << std::setprecision(0) << p.unsigned_long_value;
				break;
			}
		}
	}
	if (comment.size() > 0)
	{
		stream << ";" << comment;
	}
	return stream.str();
}

std::string parsed_command::to_string()
{
	if (comment.size() > 0)
	{
		return gcode + ";" + comment;
	}
	return gcode;
}