First commit.

This commit is contained in:
aj
2016-05-11 06:52:22 -04:00
commit a20a0bef67
16 changed files with 1171 additions and 0 deletions

22
.gitattributes vendored Normal file
View File

@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

71
.gitignore vendored Normal file
View File

@@ -0,0 +1,71 @@
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
#ignore thumbnails created by windows
#Ignore files build by Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/

20
CincyLib.sln Normal file
View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C# Express 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CincyLib", "CincyLib\CincyLib.csproj", "{5280FBF9-146F-4744-A635-1B99BA637419}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5280FBF9-146F-4744-A635-1B99BA637419}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5280FBF9-146F-4744-A635-1B99BA637419}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5280FBF9-146F-4744-A635-1B99BA637419}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5280FBF9-146F-4744-A635-1B99BA637419}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

59
CincyLib/CincyLib.csproj Normal file
View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5280FBF9-146F-4744-A635-1B99BA637419}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CincyLib</RootNamespace>
<AssemblyName>CincyLib</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Laser\LaserWebPanel.cs" />
<Compile Include="Laser\ProductLog.cs" />
<Compile Include="SheetMetal.cs" />
<Compile Include="Laser\AssistGasType.cs" />
<Compile Include="Laser\MaterialLib.cs" />
<Compile Include="Laser\MaterialLibReader.cs" />
<Compile Include="Laser\PierceType.cs" />
<Compile Include="Laser\RampedPierceStep.cs" />
<Compile Include="PressBrake\LowerTool.cs" />
<Compile Include="PressBrake\ToolSet.cs" />
<Compile Include="PressBrake\UpperTool.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,13 @@

namespace CincyLib.Laser
{
public enum AssistGasType
{
Oxygen,
Nitrogen,
Air,
Argon,
Helium,
Other
}
}

View File

@@ -0,0 +1,234 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace CincyLib.Laser
{
public class LaserWebPanel
{
public string CurrentProgram { get; set; }
public CNCMode CurrentMode { get; set; }
public CNCRunStatus CurrentStatus { get; set; }
public LaserMains LaserMains { get; set; }
public HighVoltage HighVoltage { get; set; }
public string[] SystemAlarms { get; set; }
public string[] LaserAlarms { get; set; }
public string[] FYIMessages { get; set; }
public bool Update(Stream stream)
{
try
{
var reader = new LaserWebPanelReader(this);
return reader.Read(stream);
}
catch { }
return false;
}
public bool Update(Uri uri)
{
try
{
var reader = new LaserWebPanelReader(this);
return reader.Read(uri);
}
catch { }
return false;
}
public bool Update(string url)
{
try
{
var reader = new LaserWebPanelReader(this);
return reader.Read(new Uri(url));
}
catch { }
return false;
}
}
internal class LaserWebPanelReader
{
public readonly LaserWebPanel LaserWebPanel;
public LaserWebPanelReader()
{
LaserWebPanel = new LaserWebPanel();
}
public LaserWebPanelReader(LaserWebPanel lwp)
{
LaserWebPanel = lwp;
}
public bool Read(Stream stream)
{
try
{
var reader = new StreamReader(stream);
var responseString = reader.ReadToEnd();
reader.Close();
var doc = new XmlDocument();
doc.LoadXml(responseString);
LaserWebPanel.CurrentProgram = doc.DocumentElement.SelectSingleNode("/Refresh/ProgramName").InnerText;
LaserWebPanel.SystemAlarms = doc.DocumentElement.SelectSingleNode("/Refresh/SystemAlarms").InnerText.Replace("\r", "").Split('\n');
LaserWebPanel.LaserAlarms = doc.DocumentElement.SelectSingleNode("/Refresh/LaserAlarms").InnerText.Replace("\r", "").Split('\n');
LaserWebPanel.FYIMessages = doc.DocumentElement.SelectSingleNode("/Refresh/FYIMessages").InnerText.Replace("\r", "").Split('\n');
int mode;
var cncModeString = doc.DocumentElement.SelectSingleNode("/Refresh/CNCMode").InnerText;
if (int.TryParse(cncModeString, out mode))
LaserWebPanel.CurrentMode = GetCNCMode(mode);
int status;
var cncRunStatusString = doc.DocumentElement.SelectSingleNode("/Refresh/CNCRunStatus").InnerText;
if (int.TryParse(cncRunStatusString, out status))
LaserWebPanel.CurrentStatus = GetCNCRunStatus(status);
int mains;
var laserMainsString = doc.DocumentElement.SelectSingleNode("/Refresh/LaserMains").InnerText;
if (int.TryParse(laserMainsString, out mains))
LaserWebPanel.LaserMains = GetLaserMains(mains);
int hv;
var highVoltageString = doc.DocumentElement.SelectSingleNode("/Refresh/HighVoltage").InnerText;
if (int.TryParse(highVoltageString, out hv))
LaserWebPanel.HighVoltage = GetHighVoltage(hv);
return true;
}
catch { }
return false;
}
public bool Read(Uri uri)
{
try
{
var refreshUri = new Uri(uri, "refresh.aspx");
var request = WebRequest.Create(refreshUri.ToString());
request.Method = "POST";
using (var stream = request.GetRequestStream())
{
var postData = "<Refresh><CNCMode/><CNCRunStatus/><ProgramName/><SystemAlarms/><LaserAlarms/><FYIMessages/><LaserMains/><HighVoltage/></Refresh>";
var byteData = Encoding.ASCII.GetBytes(postData);
stream.Write(byteData, 0, byteData.Length);
}
var response = (HttpWebResponse)request.GetResponse();
return Read(response.GetResponseStream());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return false;
}
private static CNCMode GetCNCMode(int i)
{
switch (i)
{
case 0: return CNCMode.Auto;
case 1: return CNCMode.Jog;
case 2: return CNCMode.Home;
default: return CNCMode.Auto;
}
}
private static CNCRunStatus GetCNCRunStatus(int i)
{
switch (i)
{
case 0: return CNCRunStatus.NoProgramLoaded;
case 1: return CNCRunStatus.Stopped;
case 2: return CNCRunStatus.ReadyToRun;
case 3: return CNCRunStatus.Running;
case 4: return CNCRunStatus.Finished;
case 5: return CNCRunStatus.Unknown;
default: return CNCRunStatus.NoProgramLoaded;
}
}
private static LaserMains GetLaserMains(int i)
{
switch (i)
{
case 0: return LaserMains.Locked;
case 1: return LaserMains.Off;
case 2: return LaserMains.On;
default: return LaserMains.Off;
}
}
private static HighVoltage GetHighVoltage(int i)
{
switch (i)
{
case 0: return HighVoltage.Locked;
case 1: return HighVoltage.Off;
case 2: return HighVoltage.On;
default: return HighVoltage.Off;
}
}
}
public enum CNCMode
{
Auto,
Jog,
Home
}
public enum CNCRunStatus
{
[Description("No Program Loaded")]
NoProgramLoaded,
Stopped,
[Description("Ready To Run")]
ReadyToRun,
Running,
Finished,
Unknown
}
public enum LaserMains
{
Locked,
Off,
On
}
public enum HighVoltage
{
Locked,
Off,
On
}
}

View File

@@ -0,0 +1,128 @@
using System.Linq;
namespace CincyLib.Laser
{
public class MaterialLib
{
public MaterialLib()
{
const int MaxSteps = 20;
RampedPierceSteps = new RampedPierceStep[MaxSteps];
}
public string Name { get; set; }
public string Machine { get; set; }
#region Pierce
public PierceType PierceType { get; set; }
public float PierceDwell { get; set; }
public int PiercePower { get; set; }
public int PierceFrequency { get; set; }
public int PierceDutyCycle { get; set; }
public float PierceZHoldDistance { get; set; }
public float PierceNozzleStandoffRampFrom { get; set; }
//public float PierceNozzleStandoffRampTo { get; set; }
public AssistGasType PierceAssistGas { get; set; }
public int PierceAssistGasPressure { get; set; }
public bool UsePartCoolantOnPierce { get; set; }
public int RampedPierceStartPower { get; set; }
public float RampedPierceCoolingTime { get; set; }
public RampedPierceStep[] RampedPierceSteps;
public float PierceTime()
{
switch (PierceType)
{
case PierceType.NoPierce:
return 0;
case PierceType.FixedDwellTime:
return PierceDwell;
case PierceType.RampedPower:
return RampedPierceSteps.Sum(step => step.Time) + RampedPierceCoolingTime;
}
return 0;
}
#endregion
#region Cut
public int Power { get; set; }
public int Frequency { get; set; }
public int DutyCycle { get; set; }
public int Feedrate { get; set; }
//public float PreCutDwell { get; set; } // seconds
public float KerfWidth { get; set; } // inches
//public float PowerBurstTime { get; set; } // seconds
public bool DynamicPowerControl { get; set; }
public bool DynamicAssistGas { get; set; }
public bool UsePartCoolantOnCut { get; set; }
public float NozzleStandoff1 { get; set; }
/// <summary>
/// Optional standoff (M45)
/// </summary>
public float NozzleStandoff2 { get; set; }
public AssistGasType AssistGas { get; set; }
public int AssistGasPressure1 { get; set; }
/// <summary>
/// Optional assist gas pressure (M67)
/// </summary>
public int AssistGasPressure2 { get; set; }
#endregion
/// <summary>
/// Dynamic power control feedrate.
/// </summary>
public int DPCFeedrate { get; set; }
/// <summary>
/// Dynamic power control minimum power.
/// </summary>
public int DPCMinPower { get; set; }
//public FocusingLensType FocusingLens { get; set; }
//public NozzleTipType NozzleTip { get; set; }
public string Notes { get; set; }
public static MaterialLib Load(string libfile)
{
var reader = new MaterialLibReader();
return reader.Read(libfile) ? reader.MaterialLib : null;
}
}
}

View File

@@ -0,0 +1,149 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace CincyLib.Laser
{
internal sealed class MaterialLibReader
{
public readonly MaterialLib MaterialLib;
public MaterialLibReader()
{
MaterialLib = new MaterialLib();
}
public MaterialLibReader(MaterialLib materiallib)
{
MaterialLib = materiallib;
}
public bool Read(string file)
{
Stream stream = null;
MaterialLib.Name = Path.GetFileNameWithoutExtension(file);
var success = false;
try
{
stream = File.OpenRead(file);
success = Read(stream);
}
catch (SystemException ex)
{
Debug.WriteLine(ex.Message);
}
finally
{
if (stream != null)
stream.Close();
}
return success;
}
public bool Read(Stream stream)
{
var success = false;
try
{
var reader = new BinaryReader(stream);
MaterialLib.Machine = reader.ReadString();
MaterialLib.PierceDwell = reader.ReadSingle();
reader.BaseStream.Seek(2, SeekOrigin.Current);
MaterialLib.PiercePower = reader.ReadInt16();
MaterialLib.PierceFrequency = reader.ReadInt16();
MaterialLib.PierceDutyCycle = reader.ReadInt16();
if (reader.ReadInt16() == 1)
MaterialLib.PierceType = PierceType.RampedPower;
MaterialLib.PierceNozzleStandoffRampFrom = reader.ReadSingle();
MaterialLib.RampedPierceCoolingTime = reader.ReadSingle();
MaterialLib.UsePartCoolantOnPierce = Convert.ToBoolean(reader.ReadInt16());
MaterialLib.PierceAssistGas = (AssistGasType)reader.ReadInt16();
MaterialLib.PierceAssistGasPressure = reader.ReadInt16();
reader.BaseStream.Seek(6, SeekOrigin.Current);
MaterialLib.Power = reader.ReadInt16();
MaterialLib.Frequency = reader.ReadInt16();
MaterialLib.DutyCycle = reader.ReadInt16();
MaterialLib.DynamicPowerControl = Convert.ToBoolean(reader.ReadInt16());
MaterialLib.DPCFeedrate = reader.ReadInt16();
MaterialLib.DPCMinPower = reader.ReadInt16();
reader.BaseStream.Seek(4, SeekOrigin.Current);
MaterialLib.NozzleStandoff1 = reader.ReadSingle();
MaterialLib.KerfWidth = reader.ReadSingle();
reader.BaseStream.Seek(2, SeekOrigin.Current);
MaterialLib.AssistGas = (AssistGasType)reader.ReadInt16();
MaterialLib.AssistGasPressure1 = reader.ReadInt16();
MaterialLib.AssistGasPressure2 = reader.ReadInt16();
MaterialLib.DynamicAssistGas = Convert.ToBoolean(reader.ReadInt16());
reader.BaseStream.Seek(4, SeekOrigin.Current);
var steps = reader.ReadInt16();
reader.BaseStream.Seek(4, SeekOrigin.Current);
MaterialLib.RampedPierceStartPower = reader.ReadInt16();
MaterialLib.RampedPierceSteps = new RampedPierceStep[20];
for (int i = 0; i < steps; ++i)
{
MaterialLib.RampedPierceSteps[i] = new RampedPierceStep();
MaterialLib.RampedPierceSteps[i].Time = reader.ReadSingle();
MaterialLib.RampedPierceSteps[i].Power = reader.ReadInt16();
}
var remaining = MaterialLib.RampedPierceSteps.Length - steps;
reader.BaseStream.Seek(6 * remaining, SeekOrigin.Current);
int length = reader.ReadByte();
if (length == 0xFF)
{
var second = reader.ReadByte();
var third = reader.ReadByte();
length = length * third + second + third;
}
MaterialLib.Notes = Encoding.ASCII.GetString(reader.ReadBytes(length));
reader.BaseStream.Seek(4, SeekOrigin.Current);
MaterialLib.Feedrate = reader.ReadInt16();
if (MaterialLib.PierceType != PierceType.RampedPower)
{
if (reader.BaseStream.Length < reader.BaseStream.Position + 527)
{
MaterialLib.PierceType = MaterialLib.PierceDwell == 0
? PierceType.NoPierce
: PierceType.FixedDwellTime;
}
else
{
reader.BaseStream.Seek(527, SeekOrigin.Current);
MaterialLib.PierceType = (PierceType)reader.ReadInt16();
}
}
success = true;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return success;
}
}
}

View File

@@ -0,0 +1,12 @@

namespace CincyLib.Laser
{
public enum PierceType
{
NoPierce = 0,
FixedDwellTime = 1,
RampedPower = 2,
Adaptive = 3,
MicroWeld = 4
}
}

View File

@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace CincyLib.Laser
{
public class ProductLog
{
private ProductLog()
{
Records = new List<Record>();
}
public List<Record> Records { get; set; }
public static ProductLog Load(string file)
{
var log = new ProductLog();
var reader = new StreamReader(file);
Record curRecord = null;
string line = null;
while ((line = reader.ReadLine()) != null)
{
int splitIndex = line.IndexOf("Program");
if (splitIndex == -1)
continue;
curRecord = new Record();
log.Records.Add(curRecord);
var dateString = line.Remove(splitIndex - 1);
curRecord.Date = DateTime.Parse(dateString);
var programString = line.Substring(splitIndex + 8);
curRecord.ProgramFile = ReadBetweenQuotes(programString);
while (!string.IsNullOrEmpty(line = reader.ReadLine()))
{
var ws = LeadingWhitespaceCount(line);
if (ws != 4)
break;
if (line[4] == '\'')
{
var libFile = ReadBetweenQuotes(line);
if (libFile != null)
curRecord.LibraryFiles.Add(libFile);
}
else
{
var cutRecord = new CutRecord();
var cycleString = line.Substring(15, 13);
cutRecord.CycleTime = TimeSpan.Parse(cycleString);
var totalString = line.Substring(34);
cutRecord.TotalTime = TimeSpan.Parse(totalString);
curRecord.CutRecords.Add(cutRecord);
}
}
}
return log;
}
private static int LeadingWhitespaceCount(string text)
{
for (int i = 0; i < text.Length; i++)
{
if (text[i] != ' ')
return i;
}
return text.Length;
}
private static string ReadBetweenQuotes(string text)
{
var startIndex = text.IndexOf('\'');
if (startIndex == -1)
return null;
var endIndex = text.IndexOf('\'', startIndex + 1);
if (endIndex == -1)
return null;
return text.Substring(startIndex + 1, endIndex - startIndex - 1);
}
}
public class Record
{
public Record()
{
CutRecords = new List<CutRecord>();
LibraryFiles = new List<string>();
}
public DateTime Date { get; set; }
public string ProgramFile { get; set; }
public List<string> LibraryFiles { get; set; }
public List<CutRecord> CutRecords { get; set; }
}
public class CutRecord
{
public TimeSpan CycleTime { get; set; }
public TimeSpan TotalTime { get; set; }
}
}

View File

@@ -0,0 +1,15 @@

namespace CincyLib.Laser
{
public struct RampedPierceStep
{
public float Time;
public int Power;
public override string ToString()
{
return string.Format("[RampedPierceStep: Time:{0}, Power:{1}", Time, Power);
}
}
}

View File

@@ -0,0 +1,118 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace CincyLib.PressBrake
{
public class LowerTool
{
/// <summary>
/// The name of the file
/// </summary>
public string Name;
public string ToolName;
public int Type;
public double Length;
public double Height;
public double Clearance;
public double MaxLoad;
public double Angle;
public double Radius;
public double VOpening;
public double Offset;
public double BendRadius()
{
return VOpening * 0.15625;
}
public static LowerTool Load(string xmlpath)
{
var lowerTool = new LowerTool();
var reader = XmlReader.Create(xmlpath);
try
{
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "LowerTool":
lowerTool.Name = Path.GetFileNameWithoutExtension(xmlpath);
lowerTool.ToolName = reader.GetAttribute("ToolName");
int type;
int.TryParse(reader.GetAttribute("Type"), out type);
lowerTool.Type = type;
double length;
double.TryParse(reader.GetAttribute("Length"), out length);
lowerTool.Length = length;
double height;
double.TryParse(reader.GetAttribute("Height"), out height);
lowerTool.Height = height;
double clearance;
double.TryParse(reader.GetAttribute("Clearance"), out clearance);
lowerTool.Clearance = clearance;
double maxload;
double.TryParse(reader.GetAttribute("MaxLoad"), out maxload);
lowerTool.MaxLoad = maxload;
double angle;
double.TryParse(reader.GetAttribute("Angle"), out angle);
lowerTool.Angle = angle;
double radius;
double.TryParse(reader.GetAttribute("Radius"), out radius);
lowerTool.Radius = radius;
double vopening;
double.TryParse(reader.GetAttribute("VeeOpening"), out vopening);
lowerTool.VOpening = vopening;
double offset;
double.TryParse(reader.GetAttribute("Offset"), out offset);
lowerTool.Offset = offset;
break;
}
}
}
}
catch (SystemException ex)
{
Debug.WriteLine("Error loading: " + xmlpath);
Debug.WriteLine(ex.Message);
}
finally
{
if (reader != null)
reader.Close();
}
return lowerTool;
}
public void Print()
{
Console.WriteLine(Name);
Console.WriteLine(" Length: {0}", Length);
Console.WriteLine(" Angle: {0}", Angle);
Console.WriteLine(" Radius: {0}", Radius);
Console.WriteLine(" V-Opening: {0}", VOpening);
Console.WriteLine(" Height: {0}", Height);
Console.WriteLine(" Clearance: {0}", Clearance);
Console.WriteLine(" MaxLoad: {0}", MaxLoad);
Console.WriteLine(" Offset: {0}", Offset);
Console.WriteLine(" Type: {0}", Type);
Console.WriteLine(" Bend Radius: {0}", BendRadius());
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
namespace CincyLib.PressBrake
{
public class ToolSet
{
private LowerTool lowerTool;
private UpperTool upperTool;
public ToolSet(LowerTool lt, UpperTool ut)
{
lowerTool = lt;
upperTool = ut;
}
public bool IsValid()
{
if (upperTool.Angle > lowerTool.Angle)
return false;
return true;
}
public double BendRadius()
{
double r1 = lowerTool.BendRadius();
double r2 = upperTool.Radius;
return r1 > r2 ? r1 : r2;
}
public double BendLength()
{
double r1 = lowerTool.Length;
double r2 = upperTool.Length;
return r1 > r2 ? r1 : r2;
}
public double MinFlangeLength()
{
var thickness = BendRadius();
var radius = thickness;
var outsideRadius = radius + thickness;
var length2bend = lowerTool.VOpening * 0.5 + 0.0625;
var bendlength = SheetMetal.BendLength(thickness, radius, 90.0, 0.42);
return length2bend - (bendlength * 0.5) + outsideRadius;
}
public void Print()
{
Console.WriteLine("{0} / {1}", lowerTool.Name, upperTool.Name);
Console.WriteLine(" Generates an inside radius of: {0}", BendRadius().ToString("n3") + "\"");
Console.WriteLine(" Usable on materials less than or equal to: {0}", BendRadius().ToString("n3") + "\"");
Console.WriteLine(" Capable of bends greater than or equal to: {0}", lowerTool.Angle.ToString("n0") + " degrees");
Console.WriteLine(" Capable of bends up to: {0} long", BendLength().ToString("n3") + "\"");
Console.WriteLine(" Minimum 90 degree flange length: {0}", MinFlangeLength().ToString("n3") + "\"");
}
}
}

View File

@@ -0,0 +1,106 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace CincyLib.PressBrake
{
public class UpperTool
{
/// <summary>
/// The name of the file
/// </summary>
public string Name;
public string ToolName;
public double Length;
public double Angle;
public double Radius;
public double Height;
public double Clearance;
public double MaxLoad;
public double Offset;
public int Type;
public static UpperTool Load(string xmlpath)
{
var upperTool = new UpperTool();
var reader = XmlReader.Create(xmlpath);
try
{
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "UpperTool":
upperTool.Name = Path.GetFileNameWithoutExtension(xmlpath);
upperTool.ToolName = reader.GetAttribute("ToolName");
int type;
int.TryParse(reader.GetAttribute("Type"), out type);
upperTool.Type = type;
double length;
double.TryParse(reader.GetAttribute("Length"), out length);
upperTool.Length = length;
double height;
double.TryParse(reader.GetAttribute("Height"), out height);
upperTool.Height = height;
double clearance;
double.TryParse(reader.GetAttribute("Clearance"), out clearance);
upperTool.Clearance = clearance;
double maxload;
double.TryParse(reader.GetAttribute("MaxLoad"), out maxload);
upperTool.MaxLoad = maxload;
double angle;
double.TryParse(reader.GetAttribute("Angle"), out angle);
upperTool.Angle = angle;
double radius;
double.TryParse(reader.GetAttribute("Radius"), out radius);
upperTool.Radius = radius;
double offset;
double.TryParse(reader.GetAttribute("Offset"), out offset);
upperTool.Offset = offset;
break;
}
}
}
}
catch (SystemException ex)
{
Debug.WriteLine("Error loading: " + xmlpath);
Debug.WriteLine(ex.Message);
}
finally
{
if (reader != null)
reader.Close();
}
return upperTool;
}
public void Print()
{
Console.WriteLine(Name);
Console.WriteLine(" Length: {0}", Length);
Console.WriteLine(" Angle: {0}", Angle);
Console.WriteLine(" Radius: {0}", Radius);
Console.WriteLine(" Height: {0}", Height);
Console.WriteLine(" Clearance: {0}", Clearance);
Console.WriteLine(" MaxLoad: {0}", MaxLoad);
Console.WriteLine(" Offset: {0}", Offset);
Console.WriteLine(" Type: {0}", Type);
}
}
}

View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CincyLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CincyLib")]
[assembly: AssemblyCopyright("Copyright © AJ Isaacs 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("70319b57-7057-4aff-aaaa-c2c52dee7689")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

12
CincyLib/SheetMetal.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
namespace CincyLib
{
public static class SheetMetal
{
public static double BendLength(double thickness, double radius, double angle, double kfactor)
{
return (radius + thickness * kfactor) * 2.0 * Math.PI * angle / 360.0;
}
}
}