From 1753f753054ce27f8ec66ad2088a8484dfbbb93d Mon Sep 17 00:00:00 2001 From: aj Date: Sun, 10 Jun 2018 11:29:42 -0400 Subject: [PATCH] Added PreferUpViewFlipDecider --- ExportDXF/AskViewFlipDecider.cs | 24 ------- ExportDXF/ExportDXF.csproj | 3 +- ExportDXF/Forms/MainForm.cs | 6 -- ExportDXF/IViewFlipDecider.cs | 71 ++++++++++++++++++- .../{ViewFlipDecider.cs => ViewHelper.cs} | 29 -------- 5 files changed, 71 insertions(+), 62 deletions(-) delete mode 100644 ExportDXF/AskViewFlipDecider.cs rename ExportDXF/{ViewFlipDecider.cs => ViewHelper.cs} (90%) diff --git a/ExportDXF/AskViewFlipDecider.cs b/ExportDXF/AskViewFlipDecider.cs deleted file mode 100644 index 1e93a2a..0000000 --- a/ExportDXF/AskViewFlipDecider.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Windows.Forms; - -namespace ExportDXF -{ - public class AskViewFlipDecider : IViewFlipDecider - { - public string Name => "Ask to flip"; - - public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) - { - var bends = ViewHelper.GetBends(view); - - if (bends.Count == 0) - return false; - - return MessageBox.Show("Flip view?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; - } - - public override string ToString() - { - return Name; - } - } -} diff --git a/ExportDXF/ExportDXF.csproj b/ExportDXF/ExportDXF.csproj index 58066b6..0eea85e 100644 --- a/ExportDXF/ExportDXF.csproj +++ b/ExportDXF/ExportDXF.csproj @@ -88,10 +88,8 @@ - - Form @@ -101,6 +99,7 @@ + MainForm.cs diff --git a/ExportDXF/Forms/MainForm.cs b/ExportDXF/Forms/MainForm.cs index e46030e..814dc18 100644 --- a/ExportDXF/Forms/MainForm.cs +++ b/ExportDXF/Forms/MainForm.cs @@ -662,9 +662,3 @@ namespace ExportDXF.Forms public IViewFlipDecider ViewFlipDecider { get; set; } } } - - - -namespace Helpers -{ -} diff --git a/ExportDXF/IViewFlipDecider.cs b/ExportDXF/IViewFlipDecider.cs index 141ca59..eac0cad 100644 --- a/ExportDXF/IViewFlipDecider.cs +++ b/ExportDXF/IViewFlipDecider.cs @@ -1,4 +1,7 @@ -namespace ExportDXF +using System.Linq; +using System.Windows.Forms; + +namespace ExportDXF { public interface IViewFlipDecider { @@ -6,4 +9,70 @@ string Name { get; } } + + public class AutoViewFlipDecider : IViewFlipDecider + { + public string Name => "Automatic"; + + public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) + { + var orientation = ViewHelper.GetOrientation(view); + var bounds = ViewHelper.GetBounds(view); + var bends = ViewHelper.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 = ViewHelper.ClosestToBounds(bounds, bends); + + return bend.Direction == BendDirection.Down; + } + } + + public class AskViewFlipDecider : IViewFlipDecider + { + public string Name => "Ask to flip"; + + public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) + { + var bends = ViewHelper.GetBends(view); + + if (bends.Count == 0) + return false; + + return MessageBox.Show("Flip view?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; + } + + public override string ToString() + { + return Name; + } + } + + public class PreferUpViewFlipDecider : IViewFlipDecider + { + public string Name => "Prefer up bends, ask if up/down"; + + public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) + { + var bends = ViewHelper.GetBends(view); + var up = bends.Where(b => b.Direction == BendDirection.Up).ToList(); + var down = bends.Where(b => b.Direction == BendDirection.Down).ToList(); + + if (up.Count > 0 && down.Count > 0) + { + return MessageBox.Show("Flip view?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; + } + else + { + return down.Count > 0; + } + } + } } diff --git a/ExportDXF/ViewFlipDecider.cs b/ExportDXF/ViewHelper.cs similarity index 90% rename from ExportDXF/ViewFlipDecider.cs rename to ExportDXF/ViewHelper.cs index 933c8b6..4510622 100644 --- a/ExportDXF/ViewFlipDecider.cs +++ b/ExportDXF/ViewHelper.cs @@ -1,40 +1,11 @@ using SolidWorks.Interop.sldworks; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text.RegularExpressions; namespace ExportDXF { - [DisplayName("Automatic")] - public class ViewFlipDecider : IViewFlipDecider - { - public string Name => "Automatic"; - - public bool ShouldFlip(SolidWorks.Interop.sldworks.View view) - { - var orientation = ViewHelper.GetOrientation(view); - var bounds = ViewHelper.GetBounds(view); - var bends = ViewHelper.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 = ViewHelper.ClosestToBounds(bounds, bends); - - return bend.Direction == BendDirection.Down; - } - - - } - internal static class ViewHelper { public static Bounds GetBounds(SolidWorks.Interop.sldworks.View view)