diff --git a/.gitignore b/.gitignore index e257658..ae0b285 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ *.out *.app +/build/ +build/ \ No newline at end of file diff --git a/.vscode/browse.vc.db b/.vscode/browse.vc.db index b159240..7a3a68d 100644 Binary files a/.vscode/browse.vc.db and b/.vscode/browse.vc.db differ diff --git a/.vscode/browse.vc.db-shm b/.vscode/browse.vc.db-shm index cf6389b..5cc180e 100644 Binary files a/.vscode/browse.vc.db-shm and b/.vscode/browse.vc.db-shm differ diff --git a/.vscode/browse.vc.db-wal b/.vscode/browse.vc.db-wal index e69de29..73b7bb1 100644 Binary files a/.vscode/browse.vc.db-wal and b/.vscode/browse.vc.db-wal differ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a1e6f01..724acd3 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -16,7 +16,7 @@ "compilerPath": "/usr/bin/gcc", "cStandard": "${default}", "cppStandard": "${default}", - "compileCommands": "build/compile_commands.json", + "compileCommands": "./build/compile_commands.json", "browse": { "path": [ "${workspaceFolder}/**", diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a6913a..2e48d4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ set(SOURCES src/DataLoad.cpp src/BendDeduction.cpp src/FormingTool.cpp + src/BendAllowance.cpp ) # Create executable diff --git a/README.md b/README.md index ba98dda..340b09c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BendCalc -A C++ Bend calculator for sheet metal bending and forming calculations used in the sheet metal and forming and fabrication trades +A C++ Bend calculator application for sheet metal bending and forming calculations used in the sheet metal and forming and fabrication trades This calculators features include: @@ -9,4 +9,4 @@ This calculators features include: - Saving and Loading bend history/historical data for review and analysis, including to and from the machine (if applicable) - Calculating the required press tonnage required to complete bends and forming operations - Tool library. Store tool data including a tool library -- \ No newline at end of file +- Calcuating inside and outside setback diff --git a/ask.txt b/ask.txt new file mode 100644 index 0000000..4becc80 --- /dev/null +++ b/ask.txt @@ -0,0 +1,197 @@ +I am making a C++ program that is written in C++ 11 and uses CMake. It is meant for doing calculations for +bending sheet metal / sheetmetal for pressbrakes, press brakes, brakeforms, breakforms, brake forms, break forms, forming and forming machinery and metalforming machinery and sheetmetal forming machinery. + +The /BendCalc folder/directory includes: + +CMakeLists.txt data docs include LICENSE README.md src tests + +data is a directcory +docs is a directory +include is a directory +LICENSE is the project license +README.md is for GitHub +src is a directory +tests is a directory + +currently data is empty. this is the place for stored data to and from the machine (using a paralel or serial pot or inputted from the user or saved by this program + +docs is the documentation for the BendCalc program in markdown format. it contains + +BendAllowance.md BendDeduction.md KFactor.md Setback.md Tonnage.md + +include contains header files: + +BendAllowance.h DataLoad.h Deserializer.h Kfactor.h Setback.h +BendDeduction.h DataSave.h FormingTool.h Serializer.h Tonnage.h + +src contains the cpp files: + +BendAllowance.cpp DataLoad.cpp Deserializer.cpp Kfactor.cpp Serializer.cpp Tonnage.cpp +BendDeduction.cpp DataSave.cpp FormingTool.cpp main.cpp Setback.cpp + +main is the entrypoint to the program. the rest are classes. + +tests is currently empty and will be using google test + +CMakeLists.txt is currently + +cmake_minimum_required(VERSION 3.13.4) +project(BendCalc +VERSION 1.0.0 +DESCRIPTION "An application for " +HOMEPAGE_URL "https://gitea.eventhorizonstudio.io/gbowne1/BendCalc" +LANGUAGES CXX) + +include(CTest) +enable_testing() + +# Set C++ standard +set(CMAKE_CXX_STANDARD 11) + +set(CMAKE_BUILD_TYPE Debug) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +add_compile_options(-g -Wall -Wextra -Werror -pedantic) + +set(CMAKE_CXX_COMPILER /usr/bin/g++) + +# Source files +set(SOURCES + src/main.cpp + src/Tonnage.cpp + src/Setback.cpp + src/Serializer.cpp + src/Kfactor.cpp + src/Deserializer.cpp + src/DataSave.cpp + src/DataLoad.cpp + src/BendDeduction.cpp + src/FormingTool.cpp +) + +# Create executable +add_executable(bendcalc ${SOURCES}) + +# Include directories +target_include_directories(bendcalc PUBLIC include) + +and the main.cpp entrypoint file is + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../include/BendAllowance.h" +#include "../include/BendDeduction.h" +#include "../include/DataLoad.h" +#include "../include/DataSave.h" +#include "../include/Deserializer.h" +#include "../include/FormingTool.h" +#include "../include/Kfactor.h" +#include "../include/Serializer.h" +#include "../include/Setback.h" +#include "../include/Tonnage.h" + +int main() { + + DataLoad::loadDataFromCSV(/*fileName*/); + + std::cout << "Welcome to BendCalc - Metal Forming and Bending Operations Calculator\n"; + std::cout << "Select an operation:\n"; + std::cout << "1. Calculate Bend Deduction\n"; + std::cout << "2. Load Data\n"; + std::cout << "3. Save Data\n"; + std::cout << "4. Exit\n"; + std::cout << "Enter your choice: "; + + int choice; + std::cin >> choice; + + switch (choice) { + case 1: + // **Calculate Bend Deduction** + // Get user input for bend parameters + double bendAngleDegrees; + double insideRadius; + double materialThickness; + double kFactor; + + std::cout << "Enter bend angle (degrees): "; + std::cin >> bendAngleDegrees; + + std::cout << "Enter inside bend radius (mm): "; + std::cin >> insideRadius; + + std::cout << "Enter material thickness (mm): "; + std::cin >> materialThickness; + + std::cout << "Enter K-factor: "; + std::cin >> kFactor; + + // Create a BendDeduction object with user-provided values + BendDeduction bendCalculator(bendAngleDegrees, insideRadius, materialThickness, kFactor); + + // Call the object's method to calculate bend deduction + double bendDeduction = bendCalculator.calculateBendDeduction(); + + // Display the result + std::cout << "Bend Deduction: " << bendDeduction << " mm\n"; + break; + case 2: + // Call function to load data (implementation pending) // Load Data + std::string fileName; + std::cout << "Enter the CSV file name to load: "; + std::cin >> fileName; + + DataLoad::loadDataFromCSV(fileName); // Call the static method + + std::cout << "Data loaded (assuming successful parsing).\n"; + std::cout << "Data is already loaded.\n"; + break; + case 3: + // Save Data + std::string fileName; + std::string dataToSave; + + std::cout << "Enter the CSV file name to save: "; + std::cin >> fileName; + + std::cout << "Enter the data to save: "; + std::cin >> dataToSave; + + DataSave::saveDataToCSV(fileName, dataToSave); + + std::cout << "Data saved successfully.\n"; + break; + case 4: + std::cout << "Exiting...\n"; + return 0; + default: + std::cout << "Invalid choice. Please try again.\n"; + } + + return 0; +} + diff --git a/include/BendData.h b/include/BendData.h new file mode 100644 index 0000000..110abfc --- /dev/null +++ b/include/BendData.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace DataLoad { + struct BendData { + double bendAngleDegrees; + double insideRadius; + double materialThickness; + double kFactor; + }; +} \ No newline at end of file diff --git a/include/BendDeduction.h b/include/BendDeduction.h index 535a404..aa4913d 100644 --- a/include/BendDeduction.h +++ b/include/BendDeduction.h @@ -9,8 +9,8 @@ private: double kFactor; // K-factor public: - BendDeduction(double angleDegrees, double radius, double thickness, double k); + BendDeduction(double bendAngleDegrees, double radius, double thickness, double k); double calculateBendDeduction(); }; -#endif \ No newline at end of file +#endif diff --git a/include/DataLoad.h b/include/DataLoad.h index e69de29..cf9ef20 100644 --- a/include/DataLoad.h +++ b/include/DataLoad.h @@ -0,0 +1,13 @@ +#include "BendData.h" + +#ifndef DATALOAD_H +#define DATALOAD_H + +#include +#include + +namespace DataLoad { + void loadDataFromCSV(const std::string& fileName, BendData& bendData); +} + +#endif \ No newline at end of file diff --git a/include/DataSave.h b/include/DataSave.h index e69de29..b204088 100644 --- a/include/DataSave.h +++ b/include/DataSave.h @@ -0,0 +1,8 @@ +#ifndef DATASAVE_H +#define DATASAVE_H + +#include + +void saveDataToCSV(const std::string& fileName, const std::string& data); + +#endif \ No newline at end of file diff --git a/src/BendDeduction.cpp b/src/BendDeduction.cpp index eed51e4..9029500 100644 --- a/src/BendDeduction.cpp +++ b/src/BendDeduction.cpp @@ -1,25 +1,17 @@ +#include "../include/BendDeduction.h" #include -class BendDeduction { -private: - double bendAngleRadians; // Bend angle in radians - double insideRadius; // Inside radius of the bend - double materialThickness; // Thickness of the material - double kFactor; // K-factor +// Constructor to initialize the properties +BendDeduction::BendDeduction(double angleDegrees, double radius, double thickness, double k) + : bendAngleRadians(angleDegrees * M_PI / 180.0), // Convert degrees to radians + insideRadius(radius), + materialThickness(thickness), + kFactor(k) {} -public: - // Constructor to initialize the properties - BendDeduction(double angleDegrees, double radius, double thickness, double k) - : bendAngleRadians(angleDegrees * M_PI / 180.0), // Convert degrees to radians - insideRadius(radius), - materialThickness(thickness), - kFactor(k) {} - - // Method to calculate the bend deduction - double calculateBendDeduction() { - double ossb = (insideRadius + materialThickness) * tan(bendAngleRadians / 2.0); - double ba = (M_PI / 180.0) * bendAngleRadians * (insideRadius + kFactor * materialThickness); - double bd = 2 * ossb - ba; - return bd; - } -}; \ No newline at end of file +// Method to calculate the bend deduction +double BendDeduction::calculateBendDeduction() { + double ossb = (insideRadius + materialThickness) * tan(bendAngleRadians / 2.0); + double ba = (M_PI / 180.0) * bendAngleRadians * (insideRadius + kFactor * materialThickness); + double bd = 2 * ossb - ba; + return bd; +} diff --git a/src/DataLoad.cpp b/src/DataLoad.cpp index 1c61785..47bf656 100644 --- a/src/DataLoad.cpp +++ b/src/DataLoad.cpp @@ -1,17 +1,41 @@ +#include "../include/BendData.h" +#include "../include/DataLoad.h" #include #include #include +#include +#include -void loadDataFromCSV(const std::string& fileName) { +namespace DataLoad { + +void loadDataFromCSV(const std::string& fileName, BendData& bendData) { std::ifstream file(fileName); - if (file.is_open()) { - std::string line; - while (std::getline(file, line)) { - // Process the line, e.g., parse and store the data - std::cout << line << std::endl; // Example: Output the line - } - file.close(); - } else { + if (!file.is_open()) { std::cerr << "Failed to open the file: " << fileName << std::endl; + return; } + + std::string line; + while (std::getline(file, line)) { + std::stringstream ss(line); + std::string item; + std::vector data; + while (std::getline(ss, item, ',')) { + data.push_back(std::stod(item)); + } + + // Assuming the order of data in the CSV matches the fields in BendData + if (data.size() == 4) { + bendData.bendAngleDegrees = data[0]; + bendData.insideRadius = data[1]; + bendData.materialThickness = data[2]; + bendData.kFactor = data[3]; + } else { + std::cerr << "Unexpected number of items in line: " << line << std::endl; + } + } + + file.close(); +} + } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3a8c5e3..ae69a01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,87 +1,105 @@ -/* - * This file is part of . - * - * is free software: you can redistribute it and/or modify - * it under the terms of the as published by - * the , either version of the License, or - * (at your option) any later version. - * - * 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 - * for more details. - * - * You should have received a copy of the - * along with . If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include #include -#include #include +#include -#include "BendAllowance.h" -#include "BendDeduction.h" -#include "DataLoad.h" -#include "DataSave.h" -#include "Deserializer.h" -#include "FormingTool.h" -#include "Kfactor.h" -#include "Serializer.h" -#include "Setback.h" -#include "Tonnage.h" +#include "../include/BendData.h" +#include "../include/BendAllowance.h" +#include "../include/BendDeduction.h" +#include "../include/DataLoad.h" +#include "../include/DataSave.h" +#include "../include/Deserializer.h" +#include "../include/FormingTool.h" +#include "../include/Kfactor.h" +#include "../include/Serializer.h" +#include "../include/Setback.h" +#include "../include/Tonnage.h" -int main() { - std::cout << "Welcome to BendCalc - Metal Forming and Bending Operations Calculator\n"; - std::cout << "Select an operation:\n"; - std::cout << "1. Calculate Bend Deduction\n"; - std::cout << "2. Load Data\n"; - std::cout << "3. Save Data\n"; - std::cout << "4. Exit\n"; - std::cout << "Enter your choice: "; +int main() +{ + std::string fileName; + std::string dataToSave; - int choice; - std::cin >> choice; + // Welcome message + std::cout << "Welcome to BendCalc - Metal Forming and Bending Operations Calculator\n"; - switch (choice) { - case 1: - // Call function to calculate bend deduction - break; - case 2: - // Call function to load data - break; - case 3: - // Call function to save data - break; - case 4: - std::cout << "Exiting...\n"; - return 0; - default: - std::cout << "Invalid choice. Please try again.\n"; - } + // Main menu loop + while (true) + { + std::cout << "\nSelect an operation:\n"; + std::cout << "1. Calculate Bend Deduction\n"; + std::cout << "2. Load Data\n"; + std::cout << "3. Save Data\n"; + std::cout << "4. Exit\n"; + std::cout << "Enter your choice: "; - // Loop back to menu or exit based on user input - // Implement functionality for each case + int choice; + std::cin >> choice; - return 0; -} \ No newline at end of file + switch (choice) + { + case 1: + { + // Calculate Bend Deduction + std::cout << "Enter bend angle (degrees): "; + double bendAngleDegrees; + std::cin >> bendAngleDegrees; + + std::cout << "Enter inside bend radius (mm): "; + double insideRadius; + std::cin >> insideRadius; + + std::cout << "Enter material thickness (mm): "; + double materialThickness; + std::cin >> materialThickness; + + std::cout << "Enter K-factor: "; + double kFactor; + std::cin >> kFactor; + + BendDeduction bendCalculator(bendAngleDegrees, insideRadius, materialThickness, kFactor); + double bendDeduction = bendCalculator.calculateBendDeduction(); + std::cout << "Bend Deduction: " << bendDeduction << " mm\n"; + break; + } + case 2: + { + // Load Data + std::cout << "Enter the CSV file name to load: "; + std::cin >> fileName; + + DataLoad::BendData bendData; // Declare a BendData instance + DataLoad::loadDataFromCSV(fileName, bendData); // Pass the BendData instance + + std::cout << "Data loaded (assuming successful parsing).\n"; + break; + } + case 3: + { + // Save Data + std::cout << "Enter the CSV file name to save: "; + std::cin >> fileName; + std::cout << "Enter the data to save: "; + std::cin.ignore(); // Ignore the newline character left by std::cin >> fileName + std::getline(std::cin, dataToSave); + saveDataToCSV(fileName, dataToSave); + std::cout << "Data saved successfully.\n"; + break; + } + case 4: + { + // Exit + std::cout << "Exiting...\n"; + return 0; + } + default: + { + std::cout << "Invalid choice. Please try again.\n"; + break; + } + } + } + + return 0; // This line will never be reached due to the infinite loop above +} diff --git a/tests/DataLoadTest.cpp b/tests/DataLoadTest.cpp new file mode 100644 index 0000000..5f6b057 --- /dev/null +++ b/tests/DataLoadTest.cpp @@ -0,0 +1,16 @@ +#define DATA_LOAD_TEST_SOURCE DataLoadTest.cpp +#include "gtest/gtest.h" +#include "DataLoad.h" + +TEST(DataLoadTest, LoadsDataFromFile) { + const std::string testFile = "test_data.csv"; // Ensure this file exists and has the correct format + DataLoad::loadDataFromCSV(testFile); + + // Add assertions here to check if the data was loaded correctly +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} +