diff --git a/ExportDXF/Bend.cs b/ExportDXF/Bend.cs new file mode 100644 index 0000000..295434a --- /dev/null +++ b/ExportDXF/Bend.cs @@ -0,0 +1,14 @@ +namespace ExportDXF +{ + class Bend + { + public BendDirection Direction { get; set; } + + public double ParallelBendAngle { get; set; } + + public double Angle { get; set; } + + public double X { get; set; } + public double Y { get; set; } + } +} diff --git a/ExportDXF/BendDirection.cs b/ExportDXF/BendDirection.cs new file mode 100644 index 0000000..6c5ac6a --- /dev/null +++ b/ExportDXF/BendDirection.cs @@ -0,0 +1,8 @@ +namespace ExportDXF +{ + enum BendDirection + { + Up, + Down + } +} diff --git a/ExportDXF/BendOrientation.cs b/ExportDXF/BendOrientation.cs new file mode 100644 index 0000000..ab675f1 --- /dev/null +++ b/ExportDXF/BendOrientation.cs @@ -0,0 +1,9 @@ +namespace ExportDXF +{ + enum BendOrientation + { + Vertical, + Horizontal, + Unknown + } +} diff --git a/ExportDXF/Bounds.cs b/ExportDXF/Bounds.cs new file mode 100644 index 0000000..1987a21 --- /dev/null +++ b/ExportDXF/Bounds.cs @@ -0,0 +1,30 @@ +namespace ExportDXF +{ + class Bounds + { + public double X { get; set; } + public double Y { get; set; } + public double Width { get; set; } + public double Height { get; set; } + + public double Left + { + get { return X; } + } + + public double Right + { + get { return X + Width; } + } + + public double Bottom + { + get { return Y; } + } + + public double Top + { + get { return Y + Height; } + } + } +} diff --git a/ExportDXF/ExportDXF.csproj b/ExportDXF/ExportDXF.csproj index abff4f5..5c63235 100644 --- a/ExportDXF/ExportDXF.csproj +++ b/ExportDXF/ExportDXF.csproj @@ -75,6 +75,14 @@ + + + + + + + + Form diff --git a/ExportDXF/Forms/MainForm.cs b/ExportDXF/Forms/MainForm.cs index 5df1b85..c288398 100644 --- a/ExportDXF/Forms/MainForm.cs +++ b/ExportDXF/Forms/MainForm.cs @@ -6,15 +6,12 @@ using System.ComponentModel; using System.Drawing; using System.IO; using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace ExportDXF.Forms { - public partial class MainForm : Form + public partial class MainForm : Form { private SldWorks sldWorks; private BackgroundWorker worker; @@ -490,512 +487,4 @@ namespace ExportDXF.Forms get { return Path.Combine(Application.StartupPath, "Templates", "Blank.drwdot"); } } } - - public static class Helper - { - public static Feature GetFeatureByTypeName(this ModelDoc2 model, string featureName) - { - var feature = model.FirstFeature() as Feature; - - while (feature != null) - { - if (feature.GetTypeName() == featureName) - return feature; - - feature = feature.GetNextFeature() as Feature; - } - - return feature; - } - - public static List GetAllFeaturesByTypeName(this ModelDoc2 model, string featureName) - { - var feature = model.FirstFeature() as Feature; - var list = new List(); - - while (feature != null) - { - if (feature.GetTypeName() == featureName) - list.Add(feature); - - feature = feature.GetNextFeature() as Feature; - } - - return list; - } - - public static bool HasFlatPattern(this ModelDoc2 model) - { - return model.GetBendState() != (int)swSMBendState_e.swSMBendStateNone; - } - - public static bool IsSheetMetal(this ModelDoc2 model) - { - if (model is PartDoc == false) - return false; - - if (model.HasFlatPattern() == false) - return false; - - return true; - } - - public static bool IsPart(this ModelDoc2 model) - { - return model is PartDoc; - } - - public static bool IsDrawing(this ModelDoc2 model) - { - return model is DrawingDoc; - } - - public static bool IsAssembly(this ModelDoc2 model) - { - return model is AssemblyDoc; - } - - public static string GetTitle(this Component2 component) - { - var model = component.GetModelDoc2() as ModelDoc2; - return model.GetTitle(); - } - - public static void AppendText(this RichTextBox box, string text, Color color) - { - box.SelectionStart = box.TextLength; - box.SelectionLength = 0; - - box.SelectionColor = color; - box.AppendText(text); - box.SelectionColor = box.ForeColor; - } - - public static string ToReadableFormat(this TimeSpan ts) - { - var s = new StringBuilder(); - - if (ts.TotalHours >= 1) - { - var hrs = ts.Hours + ts.Days * 24.0; - - s.Append(string.Format("{0}hrs ", hrs)); - s.Append(string.Format("{0}min ", ts.Minutes)); - s.Append(string.Format("{0}sec", ts.Seconds)); - } - else if (ts.TotalMinutes >= 1) - { - s.Append(string.Format("{0}min ", ts.Minutes)); - s.Append(string.Format("{0}sec", ts.Seconds)); - } - else - { - s.Append(string.Format("{0} seconds", ts.Seconds)); - } - - return s.ToString(); - } - - public static string GetNumWithSuffix(int i) - { - if (i >= 11 && i <= 13) - return i.ToString() + "th"; - - var j = i % 10; - - switch (j) - { - case 1: return i.ToString() + "st"; - case 2: return i.ToString() + "nd"; - case 3: return i.ToString() + "rd"; - default: return i.ToString() + "th"; - } - } - - public static int IndexOfColumnType(this TableAnnotation table, swTableColumnTypes_e columnType) - { - for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) - { - var currentColumnType = (swTableColumnTypes_e)table.GetColumnType(columnIndex); - - if (currentColumnType == columnType) - return columnIndex; - } - - return -1; - } - - public static int IndexOfColumnTitle(this TableAnnotation table, string columnTitle) - { - var lowercaseColumnTitle = columnTitle.ToLower(); - - for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) - { - var currentColumnType = table.GetColumnTitle(columnIndex); - - if (currentColumnType.ToLower() == lowercaseColumnTitle) - return columnIndex; - } - - return -1; - } - } - - public class Item - { - public string Name { get; set; } - - public int Quantity { get; set; } - - public Component2 Component { get; set; } - } - - public interface IViewFlipDecider - { - bool ShouldFlip(SolidWorks.Interop.sldworks.View view); - } - - public class ViewFlipDecider : IViewFlipDecider - { - public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) - { - var orientation = GetOrientation(view); - var bounds = GetBounds(view); - var bends = GetBends(view); - - var up = bends.Where(b => b.Direction == BendDirection.Up).ToList(); - var down = bends.Where(b => b.Direction == BendDirection.Down).ToList(); - - if (down.Count == 0) - return false; - - if (up.Count == 0) - return true; - - var bend = ClosestToBounds(bounds, bends); - - return bend.Direction == BendDirection.Down; - } - - private static Bounds GetBounds(SolidWorks.Interop.sldworks.View view) - { - var outline = view.GetOutline() as double[]; - - var minX = outline[0] / 0.0254; - var minY = outline[1] / 0.0254; - var maxX = outline[2] / 0.0254; - var maxY = outline[3] / 0.0254; - - var width = Math.Abs(minX) + Math.Abs(maxX); - var height = Math.Abs(minY) + Math.Abs(maxY); - - return new Bounds - { - X = minX, - Y = minY, - Width = width, - Height = height - }; - } - - private static Bend ClosestToBounds(Bounds bounds, IList bends) - { - var hBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Horizontal).ToList(); - var vBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Vertical).ToList(); - - Bend minVBend = null; - double minVBendDist = double.MaxValue; - - foreach (var bend in vBends) - { - double distFromLft = Math.Abs(bend.X - bounds.Left); - double distFromRgt = Math.Abs(bounds.Right - bend.X); - - double minDist = Math.Min(distFromLft, distFromRgt); - - if (minDist < minVBendDist) - { - minVBendDist = minDist; - minVBend = bend; - } - } - - Bend minHBend = null; - double minHBendDist = double.MaxValue; - - foreach (var bend in hBends) - { - double distFromBtm = Math.Abs(bend.Y - bounds.Bottom); - double distFromTop = Math.Abs(bounds.Top - bend.Y); - - double minDist = Math.Min(distFromBtm, distFromTop); - - if (minDist < minHBendDist) - { - minHBendDist = minDist; - minHBend = bend; - } - } - - return minHBendDist < minVBendDist ? minHBend : minVBend; - } - - private static Bend SmallestYCoordinate(IList bends) - { - double dist = double.MaxValue; - int index = -1; - - for (int i = 0; i < bends.Count; i++) - { - var bend = bends[i]; - - if (bend.Y < dist) - { - dist = bend.Y; - index = i; - } - } - - return index == -1 ? null : bends[index]; - } - - private static Bend SmallestXCoordinate(IList bends) - { - double dist = double.MaxValue; - int index = -1; - - for (int i = 0; i < bends.Count; i++) - { - var bend = bends[i]; - - if (bend.X < dist) - { - dist = bend.X; - index = i; - } - } - - return index == -1 ? null : bends[index]; - } - - private static BendDirection GetBendDirection(Note note) - { - var txt = note.GetText(); - - return txt.ToUpper().Contains("UP") ? BendDirection.Up : BendDirection.Down; - } - - private static IEnumerable GetBendNotes(SolidWorks.Interop.sldworks.View view) - { - return (view.GetNotes() as Array)?.Cast(); - } - - private static Note GetLeftMostNote(SolidWorks.Interop.sldworks.View view) - { - var notes = GetBendNotes(view); - - Note leftMostNote = null; - var leftMostValue = double.MaxValue; - - foreach (var note in notes) - { - var pt = (note.GetTextPoint() as double[]); - var x = pt[0]; - - if (x < leftMostValue) - { - leftMostValue = x; - leftMostNote = note; - } - } - - return leftMostNote; - } - - private static Note GetBottomMostNote(SolidWorks.Interop.sldworks.View view) - { - var notes = GetBendNotes(view); - - Note btmMostNote = null; - var btmMostValue = double.MaxValue; - - foreach (var note in notes) - { - var pt = (note.GetTextPoint() as double[]); - var y = pt[1]; - - if (y < btmMostValue) - { - btmMostValue = y; - btmMostNote = note; - } - } - - return btmMostNote; - } - - private static IEnumerable GetBendAngles(SolidWorks.Interop.sldworks.View view) - { - var angles = new List(); - var notes = GetBendNotes(view); - - foreach (var note in notes) - { - var angle = RadiansToDegrees(note.Angle); - angles.Add(angle); - } - - return angles; - } - - private static List GetBends(SolidWorks.Interop.sldworks.View view) - { - var bends = new List(); - var notes = GetBendNotes(view); - - const string pattern = @"(?(UP|DOWN))\s*(?(\d+))°"; - - foreach (var note in notes) - { - var pos = note.GetTextPoint2() as double[]; - - var x = pos[0] / 0.0254; - var y = pos[1] / 0.0254; - - var text = note.GetText(); - var match = Regex.Match(text, pattern, RegexOptions.IgnoreCase); - - if (!match.Success) - continue; - - var angle = double.Parse(match.Groups["ANGLE"].Value); - var direection = match.Groups["DIRECTION"].Value; - - var bend = new Bend - { - ParallelBendAngle = RadiansToDegrees(note.Angle), - Angle = angle, - Direction = direection == "UP" ? BendDirection.Up : BendDirection.Down, - X = x, - Y = y - }; - - bends.Add(bend); - } - - return bends; - } - - private static BendOrientation GetOrientation(SolidWorks.Interop.sldworks.View view) - { - var angles = GetBendAngles(view); - - var bends = GetBends(view); - - var vertical = 0; - var horizontal = 0; - - foreach (var angle in angles) - { - var o = GetAngleOrientation(angle); - - switch (o) - { - case BendOrientation.Horizontal: - horizontal++; - break; - - case BendOrientation.Vertical: - vertical++; - break; - } - } - - if (vertical == 0 && horizontal == 0) - return BendOrientation.Unknown; - - return vertical > horizontal ? BendOrientation.Vertical : BendOrientation.Horizontal; - } - - private static BendOrientation GetAngleOrientation(double angleInDegrees) - { - if (angleInDegrees < 10 || angleInDegrees > 350) - return BendOrientation.Horizontal; - - if (angleInDegrees > 170 && angleInDegrees < 190) - return BendOrientation.Horizontal; - - if (angleInDegrees > 80 && angleInDegrees < 100) - return BendOrientation.Vertical; - - if (angleInDegrees > 260 && angleInDegrees < 280) - return BendOrientation.Vertical; - - return BendOrientation.Unknown; - } - - private static double RadiansToDegrees(double angleInRadians) - { - return Math.Round(angleInRadians * 180.0 / Math.PI, 8); - } - } - - class Bend - { - public BendDirection Direction { get; set; } - - public double ParallelBendAngle { get; set; } - - public double Angle { get; set; } - - public double X { get; set; } - public double Y { get; set; } - } - - enum BendDirection - { - Up, - Down - } - - enum BendOrientation - { - Vertical, - Horizontal, - Unknown - } - - class Size - { - public double Width { get; set; } - public double Height { get; set; } - } - - class Bounds - { - public double X { get; set; } - public double Y { get; set; } - public double Width { get; set; } - public double Height { get; set; } - - public double Left - { - get { return X; } - } - - public double Right - { - get { return X + Width; } - } - - public double Bottom - { - get { return Y; } - } - - public double Top - { - get { return Y + Height; } - } - } } diff --git a/ExportDXF/Helper.cs b/ExportDXF/Helper.cs new file mode 100644 index 0000000..49e2cdd --- /dev/null +++ b/ExportDXF/Helper.cs @@ -0,0 +1,160 @@ +using SolidWorks.Interop.sldworks; +using SolidWorks.Interop.swconst; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace ExportDXF +{ + public static class Helper + { + public static Feature GetFeatureByTypeName(this ModelDoc2 model, string featureName) + { + var feature = model.FirstFeature() as Feature; + + while (feature != null) + { + if (feature.GetTypeName() == featureName) + return feature; + + feature = feature.GetNextFeature() as Feature; + } + + return feature; + } + + public static List GetAllFeaturesByTypeName(this ModelDoc2 model, string featureName) + { + var feature = model.FirstFeature() as Feature; + var list = new List(); + + while (feature != null) + { + if (feature.GetTypeName() == featureName) + list.Add(feature); + + feature = feature.GetNextFeature() as Feature; + } + + return list; + } + + public static bool HasFlatPattern(this ModelDoc2 model) + { + return model.GetBendState() != (int)swSMBendState_e.swSMBendStateNone; + } + + public static bool IsSheetMetal(this ModelDoc2 model) + { + if (model is PartDoc == false) + return false; + + if (model.HasFlatPattern() == false) + return false; + + return true; + } + + public static bool IsPart(this ModelDoc2 model) + { + return model is PartDoc; + } + + public static bool IsDrawing(this ModelDoc2 model) + { + return model is DrawingDoc; + } + + public static bool IsAssembly(this ModelDoc2 model) + { + return model is AssemblyDoc; + } + + public static string GetTitle(this Component2 component) + { + var model = component.GetModelDoc2() as ModelDoc2; + return model.GetTitle(); + } + + public static void AppendText(this RichTextBox box, string text, Color color) + { + box.SelectionStart = box.TextLength; + box.SelectionLength = 0; + + box.SelectionColor = color; + box.AppendText(text); + box.SelectionColor = box.ForeColor; + } + + public static string ToReadableFormat(this TimeSpan ts) + { + var s = new StringBuilder(); + + if (ts.TotalHours >= 1) + { + var hrs = ts.Hours + ts.Days * 24.0; + + s.Append(string.Format("{0}hrs ", hrs)); + s.Append(string.Format("{0}min ", ts.Minutes)); + s.Append(string.Format("{0}sec", ts.Seconds)); + } + else if (ts.TotalMinutes >= 1) + { + s.Append(string.Format("{0}min ", ts.Minutes)); + s.Append(string.Format("{0}sec", ts.Seconds)); + } + else + { + s.Append(string.Format("{0} seconds", ts.Seconds)); + } + + return s.ToString(); + } + + public static string GetNumWithSuffix(int i) + { + if (i >= 11 && i <= 13) + return i.ToString() + "th"; + + var j = i % 10; + + switch (j) + { + case 1: return i.ToString() + "st"; + case 2: return i.ToString() + "nd"; + case 3: return i.ToString() + "rd"; + default: return i.ToString() + "th"; + } + } + + public static int IndexOfColumnType(this TableAnnotation table, swTableColumnTypes_e columnType) + { + for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) + { + var currentColumnType = (swTableColumnTypes_e)table.GetColumnType(columnIndex); + + if (currentColumnType == columnType) + return columnIndex; + } + + return -1; + } + + public static int IndexOfColumnTitle(this TableAnnotation table, string columnTitle) + { + var lowercaseColumnTitle = columnTitle.ToLower(); + + for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) + { + var currentColumnType = table.GetColumnTitle(columnIndex); + + if (currentColumnType.ToLower() == lowercaseColumnTitle) + return columnIndex; + } + + return -1; + } + } +} diff --git a/ExportDXF/IViewFlipDecider.cs b/ExportDXF/IViewFlipDecider.cs new file mode 100644 index 0000000..44bab75 --- /dev/null +++ b/ExportDXF/IViewFlipDecider.cs @@ -0,0 +1,7 @@ +namespace ExportDXF +{ + public interface IViewFlipDecider + { + bool ShouldFlip(SolidWorks.Interop.sldworks.View view); + } +} diff --git a/ExportDXF/Item.cs b/ExportDXF/Item.cs new file mode 100644 index 0000000..1f23434 --- /dev/null +++ b/ExportDXF/Item.cs @@ -0,0 +1,13 @@ +using SolidWorks.Interop.sldworks; + +namespace ExportDXF +{ + public class Item + { + public string Name { get; set; } + + public int Quantity { get; set; } + + public Component2 Component { get; set; } + } +} diff --git a/ExportDXF/ViewFlipDecider.cs b/ExportDXF/ViewFlipDecider.cs new file mode 100644 index 0000000..da77c11 --- /dev/null +++ b/ExportDXF/ViewFlipDecider.cs @@ -0,0 +1,293 @@ +using SolidWorks.Interop.sldworks; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace ExportDXF +{ + public class ViewFlipDecider : IViewFlipDecider + { + public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) + { + var orientation = GetOrientation(view); + var bounds = GetBounds(view); + var bends = GetBends(view); + + var up = bends.Where(b => b.Direction == BendDirection.Up).ToList(); + var down = bends.Where(b => b.Direction == BendDirection.Down).ToList(); + + if (down.Count == 0) + return false; + + if (up.Count == 0) + return true; + + var bend = ClosestToBounds(bounds, bends); + + return bend.Direction == BendDirection.Down; + } + + private static Bounds GetBounds(SolidWorks.Interop.sldworks.View view) + { + var outline = view.GetOutline() as double[]; + + var minX = outline[0] / 0.0254; + var minY = outline[1] / 0.0254; + var maxX = outline[2] / 0.0254; + var maxY = outline[3] / 0.0254; + + var width = Math.Abs(minX) + Math.Abs(maxX); + var height = Math.Abs(minY) + Math.Abs(maxY); + + return new Bounds + { + X = minX, + Y = minY, + Width = width, + Height = height + }; + } + + private static Bend ClosestToBounds(Bounds bounds, IList bends) + { + var hBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Horizontal).ToList(); + var vBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Vertical).ToList(); + + Bend minVBend = null; + double minVBendDist = double.MaxValue; + + foreach (var bend in vBends) + { + double distFromLft = Math.Abs(bend.X - bounds.Left); + double distFromRgt = Math.Abs(bounds.Right - bend.X); + + double minDist = Math.Min(distFromLft, distFromRgt); + + if (minDist < minVBendDist) + { + minVBendDist = minDist; + minVBend = bend; + } + } + + Bend minHBend = null; + double minHBendDist = double.MaxValue; + + foreach (var bend in hBends) + { + double distFromBtm = Math.Abs(bend.Y - bounds.Bottom); + double distFromTop = Math.Abs(bounds.Top - bend.Y); + + double minDist = Math.Min(distFromBtm, distFromTop); + + if (minDist < minHBendDist) + { + minHBendDist = minDist; + minHBend = bend; + } + } + + return minHBendDist < minVBendDist ? minHBend : minVBend; + } + + private static Bend SmallestYCoordinate(IList bends) + { + double dist = double.MaxValue; + int index = -1; + + for (int i = 0; i < bends.Count; i++) + { + var bend = bends[i]; + + if (bend.Y < dist) + { + dist = bend.Y; + index = i; + } + } + + return index == -1 ? null : bends[index]; + } + + private static Bend SmallestXCoordinate(IList bends) + { + double dist = double.MaxValue; + int index = -1; + + for (int i = 0; i < bends.Count; i++) + { + var bend = bends[i]; + + if (bend.X < dist) + { + dist = bend.X; + index = i; + } + } + + return index == -1 ? null : bends[index]; + } + + private static BendDirection GetBendDirection(Note note) + { + var txt = note.GetText(); + + return txt.ToUpper().Contains("UP") ? BendDirection.Up : BendDirection.Down; + } + + private static IEnumerable GetBendNotes(SolidWorks.Interop.sldworks.View view) + { + return (view.GetNotes() as Array)?.Cast(); + } + + private static Note GetLeftMostNote(SolidWorks.Interop.sldworks.View view) + { + var notes = GetBendNotes(view); + + Note leftMostNote = null; + var leftMostValue = double.MaxValue; + + foreach (var note in notes) + { + var pt = (note.GetTextPoint() as double[]); + var x = pt[0]; + + if (x < leftMostValue) + { + leftMostValue = x; + leftMostNote = note; + } + } + + return leftMostNote; + } + + private static Note GetBottomMostNote(SolidWorks.Interop.sldworks.View view) + { + var notes = GetBendNotes(view); + + Note btmMostNote = null; + var btmMostValue = double.MaxValue; + + foreach (var note in notes) + { + var pt = (note.GetTextPoint() as double[]); + var y = pt[1]; + + if (y < btmMostValue) + { + btmMostValue = y; + btmMostNote = note; + } + } + + return btmMostNote; + } + + private static IEnumerable GetBendAngles(SolidWorks.Interop.sldworks.View view) + { + var angles = new List(); + var notes = GetBendNotes(view); + + foreach (var note in notes) + { + var angle = RadiansToDegrees(note.Angle); + angles.Add(angle); + } + + return angles; + } + + private static List GetBends(SolidWorks.Interop.sldworks.View view) + { + var bends = new List(); + var notes = GetBendNotes(view); + + const string pattern = @"(?(UP|DOWN))\s*(?(\d+))°"; + + foreach (var note in notes) + { + var pos = note.GetTextPoint2() as double[]; + + var x = pos[0] / 0.0254; + var y = pos[1] / 0.0254; + + var text = note.GetText(); + var match = Regex.Match(text, pattern, RegexOptions.IgnoreCase); + + if (!match.Success) + continue; + + var angle = double.Parse(match.Groups["ANGLE"].Value); + var direection = match.Groups["DIRECTION"].Value; + + var bend = new Bend + { + ParallelBendAngle = RadiansToDegrees(note.Angle), + Angle = angle, + Direction = direection == "UP" ? BendDirection.Up : BendDirection.Down, + X = x, + Y = y + }; + + bends.Add(bend); + } + + return bends; + } + + private static BendOrientation GetOrientation(SolidWorks.Interop.sldworks.View view) + { + var angles = GetBendAngles(view); + + var bends = GetBends(view); + + var vertical = 0; + var horizontal = 0; + + foreach (var angle in angles) + { + var o = GetAngleOrientation(angle); + + switch (o) + { + case BendOrientation.Horizontal: + horizontal++; + break; + + case BendOrientation.Vertical: + vertical++; + break; + } + } + + if (vertical == 0 && horizontal == 0) + return BendOrientation.Unknown; + + return vertical > horizontal ? BendOrientation.Vertical : BendOrientation.Horizontal; + } + + private static BendOrientation GetAngleOrientation(double angleInDegrees) + { + if (angleInDegrees < 10 || angleInDegrees > 350) + return BendOrientation.Horizontal; + + if (angleInDegrees > 170 && angleInDegrees < 190) + return BendOrientation.Horizontal; + + if (angleInDegrees > 80 && angleInDegrees < 100) + return BendOrientation.Vertical; + + if (angleInDegrees > 260 && angleInDegrees < 280) + return BendOrientation.Vertical; + + return BendOrientation.Unknown; + } + + private static double RadiansToDegrees(double angleInRadians) + { + return Math.Round(angleInRadians * 180.0 / Math.PI, 8); + } + } +}