Compare commits

...

7 Commits

38 changed files with 911 additions and 1 deletions

2
.gitignore vendored
View File

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

BIN
.vscode/browse.vc.db vendored Normal file

Binary file not shown.

BIN
.vscode/browse.vc.db-shm vendored Normal file

Binary file not shown.

BIN
.vscode/browse.vc.db-wal vendored Normal file

Binary file not shown.

34
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -0,0 +1,34 @@
{
"env": {
"myDefaultIncludePath": [
"${workspaceFolder}/StarshipAscension/include"
],
"myCompilerPath": "/usr/bin/gcc"
},
"configurations": [
{
"name": "linux-gcc-x64",
"intelliSenseMode": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"compileCommands": "./build/compile_commands.json",
"browse": {
"path": [
"${workspaceFolder}/**",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
},
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}

24
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/gbowne1/Documents/BendCalc",
"program": "/home/gbowne1/Documents/BendCalc/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

41
CMakeLists.txt Normal file
View File

@@ -0,0 +1,41 @@
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
src/BendAllowance.cpp
)
# Create executable
add_executable(bendcalc ${SOURCES})
# Include directories
target_include_directories(bendcalc PUBLIC include)

View File

@@ -1,3 +1,12 @@
# 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:
- Calculating K-factor
- Calculating bend allowance(s)
- 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
- 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;
}

14
docs/BendAllowance.md Normal file
View File

@@ -0,0 +1,14 @@
# Calculating Bend Allowance
Calculating bend allowance involves considering several key factors:
Bend Angle (α): The angle at which the sheet metal is bent.
Inside Radius (R): The radius of the bend where the material is not deformed.
Material Thickness (T): The thickness of the sheet metal being bent.
K-factor (K): A value that represents the position of the neutral axis (where the material is neither stretched nor compressed) relative to the material thickness. It varies based on the material properties and the bending radius
The formula for calculating bend allowance (BA) is given as:
[ BA = \alpha \times (\pi \times R + \frac{K \times T}{2}) ]
This formula takes into account the bend angle, the inside radius, the thickness of the material, and the K-factor to determine the arc length of bending measured along the neutral axis of the metal plate 14. Once the bend allowance is calculated, it is added to the flat length to determine the required sheet metal length needed to form the desired workpiece

39
docs/BendDeduction.md Normal file
View File

@@ -0,0 +1,39 @@
# Bend Deduction
Bend Deduction Calculation
The V die opening is used to calculate the bend deduction, which is the reduction in size of the workpiece due to the bending process. This calculation involves the V die opening to ensure that the workpiece's size is reduced appropriately for the intended application.
[ BD = \frac{2 \times \tan(\frac{\theta}{2}) \times R \times T}{1 - \cos(\theta)} ]
Where:
( BD ) is the bend deduction.
( \theta ) is the bend angle in radians.
( R ) is the inside radius of the bend.
( T ) is the thickness of the material.
Calculating bend deduction involves several factors:
Bend Angle (α): The angle at which the sheet metal is bent.
Inside Radius (R): The radius of the bend where the material is not deformed.
Material Thickness (T): The thickness of the sheet metal being bent.
K-factor (K): A value representing the position of the neutral axis relative to the material thickness. It varies based on the material properties and the bending radius
The K-factor is used to calculate the bend allowance and is also relevant when calculating bend deduction. It helps determine the length of the metal plate stretched during the bending process and is a fundamental value for determining the bending allowance and bending deduction
Additionally, when calculating bend deduction, it's important to note that the neutral axis shifts towards the inside surface of the bend during the bending process. This shift, combined with the material's properties and the bending radius, affects the amount of elongation that occurs during bending, which is taken into account when calculating bend deduction
Bend deduction is a crucial concept in sheet metal fabrication, allowing for accurate prediction of the final size of a part after bending. It accounts for the material's stretch and compression during the bending process. The formula provided for calculating bend deduction is not standard and seems to be a misunderstanding. Instead, bend deduction is typically calculated using the bend allowance and the outside setback (OSSB). The correct approach involves understanding several key factors:
Bend Angle (θθ): The angle to which the metal is bent.
Inside Radius (R): The radius on the inside of the bend, where the material undergoes compression.
Material Thickness (T): The thickness of the sheet metal being bent.
K-Factor (K): A coefficient that represents the location of the neutral axis (the layer within the material that does not experience tension or compression during bending) relative to the thickness of the material. This factor varies based on material properties and bending operations.
The bend deduction (BD) can be calculated using the formula: BD=2×OSSBBABD=2×OSSBBA where:
OSSB (Outside Setback) is calculated based on the material thickness, inside radius, and bend angle.
Bend Allowance (BA) is the arc length of the bend along the neutral axis. It accounts for the material stretch in the bending area and is calculated using the formula that incorporates the K-factor, bend angle, inside radius, and material thickness.
The K-factor is instrumental in determining the bend allowance and, subsequently, the bend deduction. It influences how the neutral axis shifts during bending, affecting the material's elongation and the final dimensions of the bent part.

0
docs/KFactor.md Normal file
View File

33
docs/Setback.md Normal file
View File

@@ -0,0 +1,33 @@
In the context of sheet metal forming and pressing, setback refers to the distance between the edge of the sheet and the tangent point of the bend radius. There are two types of setback: inside setback and outside setback.
The factors involved in calculating setback include:
- Bend Angle (α): The angle at which the sheet metal is bent. Changes in the bend angle will affect the setback
- Inside Radius (R): The radius of the bend where the material is not deformed. The setback is affected by changes in the inside radius
- Sheet Thickness (T): The thickness of the sheet metal being bent. Sheet thickness contributes to the overall setback
For outside setback, which is the distance from the tangent point of the radius to the outside bend vertex of the flange, the formula is as follows:
[ Outside \space Setback = T + \sqrt{R^2 - \left(\frac{T}{\sin(\alpha)}\right)^2} ]
The above formula assumes that the bend angle is less than 90 degrees. For a 90-degree bend angle, the setback value is simply the bend radius plus the sheet thickness
By knowing the values of outside setback and bend deduction, we can obtain the bend allowance. The sum of bend deduction and bend allowance is equal to two times the outside setback
Setback is a term used in sheet metal forming to describe the distance from the edge of the sheet to the tangent point of the bend radius. There are two types of setback: inside setback (ISSB) and outside setback (OSSB). These are important for calculating the flat pattern layout of a part before bending.
Inside Setback (ISSB)
Inside setback is the distance from the inside surface of the sheet metal to the tangent point of the bend radius. It is a measure of how much the material compresses on the inside of the bend.
Outside Setback (OSSB)
Outside setback is the distance from the tangent point of the bend radius to the outside bend vertex of the flange. It is a measure of how much the material stretches on the outside of the bend.
Factors Affecting Setback Calculation
Bend Angle (αα): The angle to which the metal is bent. The bend angle affects the setback because it changes the arc length of the bend.
Inside Radius (R): The radius of the bend on the inside of the material. The inside radius affects the setback because it determines how much the material compresses.
Sheet Thickness (T): The thickness of the sheet metal being bent. The thickness contributes to the overall setback because it affects the position of the neutral axis.
Calculating Outside Setback
For outside setback, the formula is: Outside Setback=T+R2(Tsin(α))2Outside Setback=T+R2(sin(α)T)2
This formula assumes that the bend angle is less than 90 degrees. For a 90-degree bend angle, the setback value is simply the bend radius plus the sheet thickness.
Relationship Between Setback, Bend Deduction, and Bend Allowance
The bend deduction (BD) and bend allowance (BA) are related to the setbacks. The bend deduction is the amount of material that must be subtracted from the total length of the flat pattern to achieve the correct size after bending. The bend allowance is the length of the neutral axis through the bend. The sum of the bend deduction and bend allowance is equal to two times the outside setback: BD+BA=2×OSSBBD+BA=2×OSSB

33
docs/Tonnage.md Normal file
View File

@@ -0,0 +1,33 @@
# Inputs for calculating the Bend Angle Tonnage required
- Material Type: Aluminum or Steel
- Tensile Strength (if known) in Mpa
- Material Thickness in inches, The material thickness plays a significant role in determining the internal radius, especially in air forming where the radius is produced as a percentage of the die opening width. For example, with 0.125-in.-thick material, the minimum inside bend radius is 63 percent of the material thickness, which would be 0.063 in.
- K-Factor
- V die opening (print suggested v opening of 8x material thickness) in inches
The V die opening is typically described by its width and height, but for calculations involving tonnage and bend angles, both the width and height are considered. It affects the tonnage of the press brake, which is the maximum amount of metal that the press brake can handle at once without overheating or damaging the machine. Tonnage calculations take into account the V die opening size to ensure that the press brake can safely accommodate the workload
Width (V-die width): This is the horizontal dimension of the V die opening. It affects the bend radius and the amount of material removed from the radius. The V-die width is used in calculations such as the 20 percent rule, which states that the inside radius produced is equal to a percentage of the V-die opening factored by material type
Height (V-die height): This is the vertical dimension of the V die opening. It affects the tonnage of the press brake and the force required to bend the material. A larger V-die height indicates a greater tonnage requirement, which can affect the strength of the press brake and the time required to complete the bending operation.
- Desired bend radii/radius
When determining the internal radius of a bend, the V die opening is essential. It helps to calculate the internal radius produced by the press brake, which is often a percentage of the V die opening factored by material type. The internal radius is often determined as a percentage of the V die opening width, with the percentage varying depending on the material type. For instance, for 304 stainless steel, it might be 20-22 percent of the die opening.
- Minimum flange dimensions width and length
The V die opening is also used to determine the minimum flange, which is the smallest diameter of the corner radius that can be achieved by the press brake. The V die opening size helps to define the limits of the press brake's capabilities
## Formula for tonnage
{[(575 × Material thickness squared) / Die width] / 12} × Material factor
## Conversion output
- P in kN/mt and convert to Tons (lb^2/i)

4
include/BendAllowance.h Normal file
View File

@@ -0,0 +1,4 @@
/*
* This file is the header file for the BendAllowance.cpp
*
*/

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;
};
}

16
include/BendDeduction.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef BENDDUCTION_H
#define BENDDUCTION_H
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
public:
BendDeduction(double bendAngleDegrees, double radius, double thickness, double k);
double calculateBendDeduction();
};
#endif

13
include/DataLoad.h Normal file
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

8
include/DataSave.h Normal file
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

12
include/Deserializer.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef DESERIALIZER_H
#define DESERIALIZER_H
#include <string>
#include <fstream>
class Deserializer {
public:
static bool deserializeData(const std::string& filename, std::string& data);
};
#endif

31
include/FormingTool.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef FORMINGTOOL_H
#define FORMINGTOOL_H
#include <string>
#include <ostream>
#include <iostream>
#include <fstream>
class FormingTool {
public:
FormingTool(const std::string &toolType, double toolSize, const std::string &materialType);
std::string getToolType() const;
double getToolSize() const;
std::string getMaterialType() const;
double getToolRadius() const;
void setToolType(const std::string &toolType);
void setToolSize(double toolSize);
void setMaterialType(const std::string &materialType);
void setToolRadius(double radius);
void useTool();
void serialize(std::ofstream &ofs) const;
void deserialize(std::ifstream &ifs);
private:
std::string m_toolType;
double m_toolSize;
std::string m_materialType;
double m_toolRadius;
};
#endif // FORMINGTOOL_H

7
include/Kfactor.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef KFACTOR_H
#define KFACTOR_H
// Function declaration for calculating the K-factor
double calculateKFactor(double neutralAxisLocation, double materialThickness);
#endif

12
include/Serializer.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef SERIALIZER_H
#define SERIALIZER_H
#include <string>
#include <fstream>
class Serializer {
public:
static bool serializeData(const std::string& filename, const std::string& data);
};
#endif

0
include/Setback.h Normal file
View File

7
include/Tonnage.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef TONNAGE_H
#define TONNAGE_H
// Function declaration for calculating the press brake tonnage
double calculateTonnage(double materialThickness, double bendLength, double dieOpeningWidth, double materialFactor, double methodFactor, double multipleBendToolingFactor);
#endif

0
src/BendAllowance.cpp Normal file
View File

17
src/BendDeduction.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "../include/BendDeduction.h"
#include <cmath>
// 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) {}
// 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;
}

41
src/DataLoad.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "../include/BendData.h"
#include "../include/DataLoad.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
namespace DataLoad {
void loadDataFromCSV(const std::string& fileName, BendData& bendData) {
std::ifstream file(fileName);
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<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();
}
}

13
src/DataSave.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include <iostream>
#include <fstream>
#include <string>
void saveDataToCSV(const std::string& fileName, const std::string& data) {
std::ofstream file(fileName, std::ios::app);
if (file.is_open()) {
file << data << "\n";
file.close();
} else {
std::cerr << "Failed to open the file: " << fileName << std::endl;
}
}

16
src/Deserializer.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include "Deserializer.h"
bool Deserializer::deserializeData(const std::string& filename, std::string& data) {
std::ifstream file(filename, std::ios::binary);
if (file.is_open()) {
file.seekg(0, std::ios::end);
std::streampos fileSize = file.tellg();
file.seekg(0, std::ios::beg);
data.resize(fileSize);
file.read(&data[0], fileSize);
file.close();
return true;
}
return false;
}

65
src/FormingTool.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "FormingTool.h"
#include "Deserializer.h"
#include "Serializer.h"
#include <iostream>
#include <ostream>
FormingTool::FormingTool(const std::string &toolType, double toolSize, const std::string &materialType)
: m_toolType(toolType), m_toolSize(toolSize), m_materialType(materialType), m_toolRadius(0.0) // Assuming default value for radius
{
}
double FormingTool::getToolRadius() const
{
return m_toolRadius;
}
double FormingTool::getToolSize() const
{
return m_toolSize;
}
std::string FormingTool::getToolType() const
{
return m_toolType;
}
std::string FormingTool::getMaterialType() const
{
return m_materialType;
}
void FormingTool::setToolRadius(double radius)
{
m_toolRadius = radius;
}
void FormingTool::setToolSize(double toolSize)
{
m_toolSize = toolSize;
}
void FormingTool::setToolType(const std::string &toolType)
{
m_toolType = toolType;
}
void FormingTool::setMaterialType(const std::string &materialType)
{
m_materialType = materialType;
}
void FormingTool::useTool()
{
std::cout << "Using " << m_toolType << " of size " << m_toolSize << std::endl;
}
void FormingTool::serialize(std::ofstream &ofs) const
{
ofs << m_toolType << " " << m_toolSize << std::endl;
}
void FormingTool::deserialize(std::ifstream &ifs)
{
ifs >> m_toolType >> m_toolSize;
}

11
src/Kfactor.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include "Kfactor.h"
#include <cmath> // Required for the pi constant
// Constants
const double PI = 3.14159265358979323846;
// Function definition for calculating the K-factor
double calculateKFactor(double bendAllowance, double bendingAngle, double materialThickness, double innerRadius) {
double kFactor = (180.0 * bendAllowance) / (PI * bendingAngle * materialThickness) - (innerRadius / materialThickness);
return kFactor;
}

11
src/Serializer.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include "Serializer.h"
bool Serializer::serializeData(const std::string& filename, const std::string& data) {
std::ofstream file(filename, std::ios::binary);
if (file.is_open()) {
file.write(data.c_str(), data.size());
file.close();
return true;
}
return false;
}

0
src/Setback.cpp Normal file
View File

8
src/Tonnage.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include "Tonnage.h"
#include <cmath>
// Function definition for calculating the press brake tonnage
double calculateTonnage(double materialThickness, double bendLength, double dieOpeningWidth, double materialFactor, double methodFactor, double multipleBendToolingFactor) {
double formingTonnage = (575 * pow(materialThickness, 2) / (dieOpeningWidth / 12)) * bendLength * materialFactor * methodFactor * multipleBendToolingFactor;
return formingTonnage;
}

105
src/main.cpp Normal file
View File

@@ -0,0 +1,105 @@
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#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::string fileName;
std::string dataToSave;
// Welcome message
std::cout << "Welcome to BendCalc - Metal Forming and Bending Operations Calculator\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: ";
int choice;
std::cin >> choice;
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();
}