From 5eb4453aed430b3c5f336030c9a6eeb6e8ed18eb Mon Sep 17 00:00:00 2001 From: FormerLurker Date: Sun, 8 Nov 2020 12:27:34 -0600 Subject: Code cleanup. Rename exe files for console and inverse processor app. Implement #15 and #16. --- .../ArcWelderInverseProcessor.cpp | 212 +++++++++++++++++++-- .../ArcWelderInverseProcessor.h | 6 +- .../ArcWelderInverseProcessor.vcxproj | 5 +- ArcWelderInverseProcessor/CMakeLists.txt | 10 +- 4 files changed, 216 insertions(+), 17 deletions(-) (limited to 'ArcWelderInverseProcessor') diff --git a/ArcWelderInverseProcessor/ArcWelderInverseProcessor.cpp b/ArcWelderInverseProcessor/ArcWelderInverseProcessor.cpp index 38da205..752f129 100644 --- a/ArcWelderInverseProcessor/ArcWelderInverseProcessor.cpp +++ b/ArcWelderInverseProcessor/ArcWelderInverseProcessor.cpp @@ -22,21 +22,211 @@ // You can contact the author at the following email address: // FormerLurker@pm.me //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#if _MSC_VER > 1200 +#define _CRT_SECURE_NO_DEPRECATE +#endif -#include -#include #include "inverse_processor.h" #include "ArcWelderInverseProcessor.h" +#include +#include +#include +#include +#include "gcode_position.h" +#include "logger.h" +#include "version.h" +#include "utilities.h" +#include +#define DEFAULT_ARG_DOUBLE_PRECISION 4 int main(int argc, char* argv[]) { - std::string info = "Arc Welder: Inverse Processor v0.1.rc1.dev0\nConverts G2/G3 commands to G1/G2 commands.\nCopyright(C) 2020 - Brad Hochgesang\n"; - std::cout << info; - TestInverseProcessor(SIX_SPEED_TEST, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode"); -} + std::string info = "Arc Straightener - Converts G2/G3 commands to G1/G2 commands.."; -static void TestInverseProcessor(std::string source_path, std::string target_path) -{ - inverse_processor processor(source_path, target_path, false, 50); - processor.process(); -} \ No newline at end of file + info.append("\nVersion: ").append(GIT_TAGGED_VERSION).append(" (branch:").append(GIT_BRANCH).append(", hash: )").append(GIT_COMMIT_HASH); + info.append("\nBuilt on ").append(BUILD_DATE); + info.append("\n").append("Copyright(C) ").append(COPYRIGHT_DATE).append(" - ").append(AUTHOR); + + std::stringstream arg_description_stream; + arg_description_stream << std::fixed << std::setprecision(5); + + std::string source_file_path; + std::string target_file_path; + bool overwrite_source_file = false; + bool g90_g91_influences_extruder; + + std::string log_level_string; + std::string log_level_string_default = "INFO"; + int log_level_value; + // Extract arguments + try { + // Define the command line object + TCLAP::CmdLine cmd(info, '=', GIT_TAGGED_VERSION); + + // Define Arguments + + // + TCLAP::UnlabeledValueArg source_arg("source", "The source gcode file to convert.", true, "", "path to source gcode file"); + + // + TCLAP::UnlabeledValueArg target_arg("target", "The target gcode file containing the converted code. If this is not supplied, the source path will be used and the source file will be overwritten.", false, "", "path to target gcode file"); + + // -g --g90-influences-extruder + arg_description_stream.clear(); + arg_description_stream.str(""); + arg_description_stream << "If supplied, G90/G91 influences the extruder axis. Default Value: " << DEFAULT_G90_G91_INFLUENCES_EXTRUDER; + TCLAP::SwitchArg g90_arg("g", "g90-influences-extruder", arg_description_stream.str(), false); + + // -l --log-level + std::vector log_levels_vector; + log_levels_vector.push_back("NOSET"); + log_levels_vector.push_back("VERBOSE"); + log_levels_vector.push_back("DEBUG"); + log_levels_vector.push_back("INFO"); + log_levels_vector.push_back("WARNING"); + log_levels_vector.push_back("ERROR"); + log_levels_vector.push_back("CRITICAL"); + log_levels_vector.push_back(""); + TCLAP::ValuesConstraint log_levels_constraint(log_levels_vector); + arg_description_stream.clear(); + arg_description_stream.str(""); + arg_description_stream << "Sets console log level. Default Value: " << log_level_string_default; + TCLAP::ValueArg log_level_arg("l", "log-level", arg_description_stream.str(), false, log_level_string_default, &log_levels_constraint); + + // Add all arguments + cmd.add(source_arg); + cmd.add(target_arg); + cmd.add(g90_arg); + cmd.add(log_level_arg); + + // Parse the argv array. + cmd.parse(argc, argv); + + // Get the value parsed by each arg. + source_file_path = source_arg.getValue(); + target_file_path = target_arg.getValue(); + + if (target_file_path.size() == 0) + { + target_file_path = source_file_path; + } + g90_g91_influences_extruder = g90_arg.getValue(); + + log_level_string = log_level_arg.getValue(); + log_level_value = -1; + + for (unsigned int log_name_index = 0; log_name_index < log_level_names_size; log_name_index++) + { + if (log_level_string == log_level_names[log_name_index]) + { + log_level_value = log_level_values[log_name_index]; + break; + } + } + if (log_level_value == -1) + { + // TODO: Does this work? + throw new TCLAP::ArgException("Unknown log level"); + } + + } + // catch argument exceptions + catch (TCLAP::ArgException& e) + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + return 1; + } + + // Ensure the log level name is valid + + std::vector log_names; + log_names.push_back("arc_welder.gcode_conversion"); + std::vector log_levels; + log_levels.push_back(log_levels::DEBUG); + logger* p_logger = new logger(log_names, log_levels); + p_logger->set_log_level_by_value(log_level_value); + + std::stringstream log_messages; + std::string temp_file_path = ""; + log_messages << std::fixed << std::setprecision(DEFAULT_ARG_DOUBLE_PRECISION); + if (source_file_path == target_file_path) + { + overwrite_source_file = true; + if (!utilities::get_temp_file_path_for_file(source_file_path, temp_file_path)) + { + log_messages << "The source and target path are the same, but a temporary file path could not be created. Is the path empty?"; + p_logger->log(0, INFO, log_messages.str()); + log_messages.clear(); + log_messages.str(""); + } + + // create a uuid with a tmp extension for the temporary file + + log_messages << "Source and target path are the same. The source file will be overwritten. Temporary file path: " << target_file_path; + p_logger->log(0, INFO, log_messages.str()); + log_messages.clear(); + log_messages.str(""); + } + log_messages << "Processing Gcode\n"; + log_messages << "\tSource File Path : " << source_file_path << "\n"; + if (overwrite_source_file) + { + log_messages << "\tTarget File Path (overwrite) : " << target_file_path << "\n"; + log_messages << "\tTemporary File Path : " << temp_file_path << "\n"; + } + else + { + log_messages << "\tTarget File File : " << target_file_path << "\n"; + } + + log_messages << "\tLog Level : " << log_level_string << "\n"; + p_logger->log(0, INFO, log_messages.str()); + + if (overwrite_source_file) + { + target_file_path = temp_file_path; + } + + inverse_processor processor(source_file_path, target_file_path, g90_g91_influences_extruder, 50); + processor.process(); + // Todo: get some results! + if (true) + { + log_messages.clear(); + log_messages.str(""); + log_messages << "Target file at '" << target_file_path << "' created."; + + if (overwrite_source_file) + { + log_messages.clear(); + log_messages.str(""); + log_messages << "Deleting the original source file at '" << source_file_path << "'."; + p_logger->log(0, INFO, log_messages.str()); + log_messages.clear(); + log_messages.str(""); + std::remove(source_file_path.c_str()); + log_messages << "Renaming temporary file at '" << target_file_path << "' to '" << source_file_path << "'."; + p_logger->log(0, INFO, log_messages.str()); + std::rename(target_file_path.c_str(), source_file_path.c_str()); + } + /* + log_messages.clear(); + log_messages.str(""); + log_messages << std::endl << results.progress.segment_statistics.str(); + p_logger->log(0, INFO, log_messages.str()); + */ + log_messages.clear(); + log_messages.str(""); + log_messages << "Process completed successfully."; + p_logger->log(0, INFO, log_messages.str()); + } + else + { + log_messages.clear(); + log_messages.str(""); + log_messages << "File processing failed."; + p_logger->log(0, INFO, log_messages.str()); + } + return 0; + +} diff --git a/ArcWelderInverseProcessor/ArcWelderInverseProcessor.h b/ArcWelderInverseProcessor/ArcWelderInverseProcessor.h index 5647357..95433f7 100644 --- a/ArcWelderInverseProcessor/ArcWelderInverseProcessor.h +++ b/ArcWelderInverseProcessor/ArcWelderInverseProcessor.h @@ -24,9 +24,10 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #pragma once #include -static void TestInverseProcessor(std::string source_path, std::string target_path); - +#define DEFAULT_G90_G91_INFLUENCES_EXTRUDER false +/* +static void TestInverseProcessor(std::string source_path, std::string target_path); static std::string ANTI_STUTTER_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\5x5_cylinder_2000Fn_0.2mm_PLA_MK2.5MMU2_4m.gcode"; static std::string BENCHY_GCODE = "C:\\Users\\Brad\\Documents\\3DPrinter\\Calibration\\Benchy\\3DBenchy_0.2mm_PLA_MK2.5MMU2.gcode"; static std::string BENCHY_CURA_RELATIVE_E_NOWIPE = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\3DBenchy_CuraRelative_Gyroid_0.2mm.gcode"; @@ -53,3 +54,4 @@ static std::string SIX_SPEED_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\Anti static std::string ISSUE_MIMUPREFERIDA = "C:\\Users\\Brad\\Documents\\AntiStutter\\Issues\\MIMUPREFERIDA\\TESTSTUTTER.gcode"; static std::string ISSUE_PRICKLYPEAR = "C:\\Users\\Brad\\Documents\\AntiStutter\\Issues\\PricklyPear\\Barbarian.gcode"; static std::string ISSUE_PRICKLYPEAR_LAYER_0_114 = "C:\\Users\\Brad\\Documents\\AntiStutter\\Issues\\PricklyPear\\Layers0_114.gcode"; +*/ \ No newline at end of file diff --git a/ArcWelderInverseProcessor/ArcWelderInverseProcessor.vcxproj b/ArcWelderInverseProcessor/ArcWelderInverseProcessor.vcxproj index ad7ff6f..934f466 100644 --- a/ArcWelderInverseProcessor/ArcWelderInverseProcessor.vcxproj +++ b/ArcWelderInverseProcessor/ArcWelderInverseProcessor.vcxproj @@ -113,7 +113,7 @@ false - $(SolutionDir)\GcodeProcessorLib\;$(SolutionDir)\ArcWelder\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + $(SolutionDir)\GcodeProcessorLib\;$(SolutionDir)\ArcWelder\;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\TCLAP\ false @@ -214,6 +214,9 @@ {31478bae-104b-4cc3-9876-42fa90cbd5fe} + + {38302600-81a7-45bb-a199-3360d6594365} + diff --git a/ArcWelderInverseProcessor/CMakeLists.txt b/ArcWelderInverseProcessor/CMakeLists.txt index f2c1c5b..b6b4938 100644 --- a/ArcWelderInverseProcessor/CMakeLists.txt +++ b/ArcWelderInverseProcessor/CMakeLists.txt @@ -6,14 +6,18 @@ project(ArcWelderInverseProcessor C CXX) add_definitions(${GcodeProcessorLib_DEFINITIONS} ${ArcWelder_DEFINITIONS}) # Include the GcodeProcessorLib and ArcWelder's directories -include_directories(${GcodeProcessorLib_INCLUDE_DIRS} ${ArcWelder_INCLUDE_DIRS}) +include_directories(${GcodeProcessorLib_INCLUDE_DIRS} ${ArcWelder_INCLUDE_DIRS} ${TCLAP_INCLUDE_DIRS}) # include sourcelist.cmake, which contains our source list and exposes it as the # ArcWelderConsoleSources variable include(sourcelist.cmake) # Add an executable our ArcWelderConsoleSources variable from our sourcelist file -add_executable(${PROJECT_NAME} ${ArcWelderInverseProcessorSources}) +add_executable( + ${PROJECT_NAME} + ${ArcWelderInverseProcessorSources} +) +set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "ArcStraightener") install( TARGETS ${PROJECT_NAME} @@ -22,4 +26,4 @@ install( # specify linking to the GcodeProcessorLib and ArcWelder libraries -target_link_libraries(${PROJECT_NAME} GcodeProcessorLib ArcWelder) +target_link_libraries(${PROJECT_NAME} TCLAP GcodeProcessorLib ArcWelder) -- cgit v1.2.3