fixing up the broken BendCalc

This commit is contained in:
Gregory Kenneth Bowne 2024-07-26 21:42:13 -07:00
parent 5ba3bc24d0
commit ac20038626
16 changed files with 397 additions and 114 deletions

2
.gitignore vendored
View File

@ -32,3 +32,5 @@
*.out *.out
*.app *.app
/build/
build/

BIN
.vscode/browse.vc.db vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -16,7 +16,7 @@
"compilerPath": "/usr/bin/gcc", "compilerPath": "/usr/bin/gcc",
"cStandard": "${default}", "cStandard": "${default}",
"cppStandard": "${default}", "cppStandard": "${default}",
"compileCommands": "build/compile_commands.json", "compileCommands": "./build/compile_commands.json",
"browse": { "browse": {
"path": [ "path": [
"${workspaceFolder}/**", "${workspaceFolder}/**",

View File

@ -31,6 +31,7 @@ set(SOURCES
src/DataLoad.cpp src/DataLoad.cpp
src/BendDeduction.cpp src/BendDeduction.cpp
src/FormingTool.cpp src/FormingTool.cpp
src/BendAllowance.cpp
) )
# Create executable # Create executable

View File

@ -1,6 +1,6 @@
# BendCalc # 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: 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) - 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 - Calculating the required press tonnage required to complete bends and forming operations
- Tool library. Store tool data including a tool library - Tool library. Store tool data including a tool library
- - Calcuating inside and outside setback

197
ask.txt Normal file
View File

@ -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 <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <chrono>
#include <cmath>
#include <condition_variable>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <memory>
#include <mutex>
#include <random>
#include <regex>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
#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;
}

12
include/BendData.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <string>
namespace DataLoad {
struct BendData {
double bendAngleDegrees;
double insideRadius;
double materialThickness;
double kFactor;
};
}

View File

@ -9,7 +9,7 @@ private:
double kFactor; // K-factor double kFactor; // K-factor
public: public:
BendDeduction(double angleDegrees, double radius, double thickness, double k); BendDeduction(double bendAngleDegrees, double radius, double thickness, double k);
double calculateBendDeduction(); double calculateBendDeduction();
}; };

View File

@ -0,0 +1,13 @@
#include "BendData.h"
#ifndef DATALOAD_H
#define DATALOAD_H
#include <string>
#include <vector>
namespace DataLoad {
void loadDataFromCSV(const std::string& fileName, BendData& bendData);
}
#endif

View File

@ -0,0 +1,8 @@
#ifndef DATASAVE_H
#define DATASAVE_H
#include <string>
void saveDataToCSV(const std::string& fileName, const std::string& data);
#endif

View File

@ -1,25 +1,17 @@
#include "../include/BendDeduction.h"
#include <cmath> #include <cmath>
class BendDeduction { // Constructor to initialize the properties
private: BendDeduction::BendDeduction(double angleDegrees, double radius, double thickness, double k)
double bendAngleRadians; // Bend angle in radians : bendAngleRadians(angleDegrees * M_PI / 180.0), // Convert degrees to radians
double insideRadius; // Inside radius of the bend insideRadius(radius),
double materialThickness; // Thickness of the material materialThickness(thickness),
double kFactor; // K-factor kFactor(k) {}
public: // Method to calculate the bend deduction
// Constructor to initialize the properties double BendDeduction::calculateBendDeduction() {
BendDeduction(double angleDegrees, double radius, double thickness, double k) double ossb = (insideRadius + materialThickness) * tan(bendAngleRadians / 2.0);
: bendAngleRadians(angleDegrees * M_PI / 180.0), // Convert degrees to radians double ba = (M_PI / 180.0) * bendAngleRadians * (insideRadius + kFactor * materialThickness);
insideRadius(radius), double bd = 2 * ossb - ba;
materialThickness(thickness), return bd;
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;
}
};

View File

@ -1,17 +1,41 @@
#include "../include/BendData.h"
#include "../include/DataLoad.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <sstream>
#include <vector>
void loadDataFromCSV(const std::string& fileName) { namespace DataLoad {
void loadDataFromCSV(const std::string& fileName, BendData& bendData) {
std::ifstream file(fileName); std::ifstream file(fileName);
if (file.is_open()) { 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 {
std::cerr << "Failed to open the file: " << fileName << std::endl; 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<double> 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();
}
} }

View File

@ -1,87 +1,105 @@
/*
* This file is part of <project name>.
*
* <project name> is free software: you can redistribute it and/or modify
* it under the terms of the <license name> as published by
* the <license organization>, either version <license version> of the License, or
* (at your option) any later version.
*
* <project name> 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
* <license name> for more details.
*
* You should have received a copy of the <license name>
* along with <project name>. If not, see <license URL>.
*/
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <chrono>
#include <cmath>
#include <condition_variable>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream> #include <iostream>
#include <iterator> #include <fstream>
#include <memory>
#include <mutex>
#include <random>
#include <regex>
#include <sstream>
#include <string> #include <string>
#include <thread>
#include <vector> #include <vector>
#include <sstream>
#include "BendAllowance.h" #include "../include/BendData.h"
#include "BendDeduction.h" #include "../include/BendAllowance.h"
#include "DataLoad.h" #include "../include/BendDeduction.h"
#include "DataSave.h" #include "../include/DataLoad.h"
#include "Deserializer.h" #include "../include/DataSave.h"
#include "FormingTool.h" #include "../include/Deserializer.h"
#include "Kfactor.h" #include "../include/FormingTool.h"
#include "Serializer.h" #include "../include/Kfactor.h"
#include "Setback.h" #include "../include/Serializer.h"
#include "Tonnage.h" #include "../include/Setback.h"
#include "../include/Tonnage.h"
int main() { int main()
std::cout << "Welcome to BendCalc - Metal Forming and Bending Operations Calculator\n"; {
std::cout << "Select an operation:\n"; std::string fileName;
std::cout << "1. Calculate Bend Deduction\n"; std::string dataToSave;
std::cout << "2. Load Data\n";
std::cout << "3. Save Data\n";
std::cout << "4. Exit\n";
std::cout << "Enter your choice: ";
int choice; // Welcome message
std::cin >> choice; std::cout << "Welcome to BendCalc - Metal Forming and Bending Operations Calculator\n";
switch (choice) { // Main menu loop
case 1: while (true)
// Call function to calculate bend deduction {
break; std::cout << "\nSelect an operation:\n";
case 2: std::cout << "1. Calculate Bend Deduction\n";
// Call function to load data std::cout << "2. Load Data\n";
break; std::cout << "3. Save Data\n";
case 3: std::cout << "4. Exit\n";
// Call function to save data std::cout << "Enter your choice: ";
break;
case 4:
std::cout << "Exiting...\n";
return 0;
default:
std::cout << "Invalid choice. Please try again.\n";
}
// Loop back to menu or exit based on user input int choice;
// Implement functionality for each case std::cin >> choice;
return 0; 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
} }

16
tests/DataLoadTest.cpp Normal file
View File

@ -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();
}