From a20a0bef672bd30d55324a899711470323bcb7fe Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 11 May 2016 06:52:22 -0400 Subject: [PATCH] First commit. --- .gitattributes | 22 +++ .gitignore | 71 +++++++++ CincyLib.sln | 20 +++ CincyLib/CincyLib.csproj | 59 +++++++ CincyLib/Laser/AssistGasType.cs | 13 ++ CincyLib/Laser/LaserWebPanel.cs | 234 ++++++++++++++++++++++++++++ CincyLib/Laser/MaterialLib.cs | 128 +++++++++++++++ CincyLib/Laser/MaterialLibReader.cs | 149 ++++++++++++++++++ CincyLib/Laser/PierceType.cs | 12 ++ CincyLib/Laser/ProductLog.cs | 118 ++++++++++++++ CincyLib/Laser/RampedPierceStep.cs | 15 ++ CincyLib/PressBrake/LowerTool.cs | 118 ++++++++++++++ CincyLib/PressBrake/ToolSet.cs | 59 +++++++ CincyLib/PressBrake/UpperTool.cs | 106 +++++++++++++ CincyLib/Properties/AssemblyInfo.cs | 35 +++++ CincyLib/SheetMetal.cs | 12 ++ 16 files changed, 1171 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 CincyLib.sln create mode 100644 CincyLib/CincyLib.csproj create mode 100644 CincyLib/Laser/AssistGasType.cs create mode 100644 CincyLib/Laser/LaserWebPanel.cs create mode 100644 CincyLib/Laser/MaterialLib.cs create mode 100644 CincyLib/Laser/MaterialLibReader.cs create mode 100644 CincyLib/Laser/PierceType.cs create mode 100644 CincyLib/Laser/ProductLog.cs create mode 100644 CincyLib/Laser/RampedPierceStep.cs create mode 100644 CincyLib/PressBrake/LowerTool.cs create mode 100644 CincyLib/PressBrake/ToolSet.cs create mode 100644 CincyLib/PressBrake/UpperTool.cs create mode 100644 CincyLib/Properties/AssemblyInfo.cs create mode 100644 CincyLib/SheetMetal.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f58edd4 --- /dev/null +++ b/.gitignore @@ -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*/ +[Tt]est[Rr]esult* diff --git a/CincyLib.sln b/CincyLib.sln new file mode 100644 index 0000000..489170a --- /dev/null +++ b/CincyLib.sln @@ -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 diff --git a/CincyLib/CincyLib.csproj b/CincyLib/CincyLib.csproj new file mode 100644 index 0000000..8afd814 --- /dev/null +++ b/CincyLib/CincyLib.csproj @@ -0,0 +1,59 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {5280FBF9-146F-4744-A635-1B99BA637419} + Library + Properties + CincyLib + CincyLib + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CincyLib/Laser/AssistGasType.cs b/CincyLib/Laser/AssistGasType.cs new file mode 100644 index 0000000..bf0eaaf --- /dev/null +++ b/CincyLib/Laser/AssistGasType.cs @@ -0,0 +1,13 @@ + +namespace CincyLib.Laser +{ + public enum AssistGasType + { + Oxygen, + Nitrogen, + Air, + Argon, + Helium, + Other + } +} diff --git a/CincyLib/Laser/LaserWebPanel.cs b/CincyLib/Laser/LaserWebPanel.cs new file mode 100644 index 0000000..6399ae0 --- /dev/null +++ b/CincyLib/Laser/LaserWebPanel.cs @@ -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 = ""; + 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 + } +} diff --git a/CincyLib/Laser/MaterialLib.cs b/CincyLib/Laser/MaterialLib.cs new file mode 100644 index 0000000..25272dd --- /dev/null +++ b/CincyLib/Laser/MaterialLib.cs @@ -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; } + + /// + /// Optional standoff (M45) + /// + public float NozzleStandoff2 { get; set; } + + public AssistGasType AssistGas { get; set; } + + public int AssistGasPressure1 { get; set; } + + /// + /// Optional assist gas pressure (M67) + /// + public int AssistGasPressure2 { get; set; } + + #endregion + + /// + /// Dynamic power control feedrate. + /// + public int DPCFeedrate { get; set; } + + /// + /// Dynamic power control minimum power. + /// + 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; + } + } +} diff --git a/CincyLib/Laser/MaterialLibReader.cs b/CincyLib/Laser/MaterialLibReader.cs new file mode 100644 index 0000000..7957540 --- /dev/null +++ b/CincyLib/Laser/MaterialLibReader.cs @@ -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; + } + } +} diff --git a/CincyLib/Laser/PierceType.cs b/CincyLib/Laser/PierceType.cs new file mode 100644 index 0000000..a0aa8ea --- /dev/null +++ b/CincyLib/Laser/PierceType.cs @@ -0,0 +1,12 @@ + +namespace CincyLib.Laser +{ + public enum PierceType + { + NoPierce = 0, + FixedDwellTime = 1, + RampedPower = 2, + Adaptive = 3, + MicroWeld = 4 + } +} diff --git a/CincyLib/Laser/ProductLog.cs b/CincyLib/Laser/ProductLog.cs new file mode 100644 index 0000000..21f6d1e --- /dev/null +++ b/CincyLib/Laser/ProductLog.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace CincyLib.Laser +{ + public class ProductLog + { + private ProductLog() + { + Records = new List(); + } + + public List 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(); + LibraryFiles = new List(); + } + + public DateTime Date { get; set; } + public string ProgramFile { get; set; } + public List LibraryFiles { get; set; } + public List CutRecords { get; set; } + } + + public class CutRecord + { + public TimeSpan CycleTime { get; set; } + public TimeSpan TotalTime { get; set; } + } +} diff --git a/CincyLib/Laser/RampedPierceStep.cs b/CincyLib/Laser/RampedPierceStep.cs new file mode 100644 index 0000000..564b7db --- /dev/null +++ b/CincyLib/Laser/RampedPierceStep.cs @@ -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); + } + } +} diff --git a/CincyLib/PressBrake/LowerTool.cs b/CincyLib/PressBrake/LowerTool.cs new file mode 100644 index 0000000..6d5384d --- /dev/null +++ b/CincyLib/PressBrake/LowerTool.cs @@ -0,0 +1,118 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Xml; + +namespace CincyLib.PressBrake +{ + public class LowerTool + { + /// + /// The name of the file + /// + 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()); + } + } +} diff --git a/CincyLib/PressBrake/ToolSet.cs b/CincyLib/PressBrake/ToolSet.cs new file mode 100644 index 0000000..c50a85a --- /dev/null +++ b/CincyLib/PressBrake/ToolSet.cs @@ -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") + "\""); + } + } +} diff --git a/CincyLib/PressBrake/UpperTool.cs b/CincyLib/PressBrake/UpperTool.cs new file mode 100644 index 0000000..977582e --- /dev/null +++ b/CincyLib/PressBrake/UpperTool.cs @@ -0,0 +1,106 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Xml; + +namespace CincyLib.PressBrake +{ + public class UpperTool + { + /// + /// The name of the file + /// + 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); + } + } +} diff --git a/CincyLib/Properties/AssemblyInfo.cs b/CincyLib/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f1381e5 --- /dev/null +++ b/CincyLib/Properties/AssemblyInfo.cs @@ -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")] diff --git a/CincyLib/SheetMetal.cs b/CincyLib/SheetMetal.cs new file mode 100644 index 0000000..cffd974 --- /dev/null +++ b/CincyLib/SheetMetal.cs @@ -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; + } + } +}