Moved ViewFlipDeciders to separate namespace.

This commit is contained in:
AJ
2021-03-21 22:13:17 -04:00
parent 16c9d97e22
commit 016e32c2e3
7 changed files with 95 additions and 80 deletions

View File

@@ -100,7 +100,9 @@
<Compile Include="ItemExtractors\ItemExtractor.cs" /> <Compile Include="ItemExtractors\ItemExtractor.cs" />
<Compile Include="Forms\ViewFlipDeciderComboboxItem.cs" /> <Compile Include="Forms\ViewFlipDeciderComboboxItem.cs" />
<Compile Include="Item.cs" /> <Compile Include="Item.cs" />
<Compile Include="IViewFlipDecider.cs" /> <Compile Include="ViewFlipDeciders\AskViewFlipDecider.cs" />
<Compile Include="ViewFlipDeciders\AutoViewFlipDecider.cs" />
<Compile Include="ViewFlipDeciders\IViewFlipDecider.cs" />
<Compile Include="Helper.cs" /> <Compile Include="Helper.cs" />
<Compile Include="Forms\MainForm.cs"> <Compile Include="Forms\MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
@@ -112,6 +114,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SolidWorksExtensions.cs" /> <Compile Include="SolidWorksExtensions.cs" />
<Compile Include="Units.cs" /> <Compile Include="Units.cs" />
<Compile Include="ViewFlipDeciders\PreferUpViewFlipDecider.cs" />
<Compile Include="ViewHelper.cs" /> <Compile Include="ViewHelper.cs" />
<EmbeddedResource Include="Forms\MainForm.resx"> <EmbeddedResource Include="Forms\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>

View File

@@ -1,4 +1,6 @@
namespace ExportDXF.Forms using ExportDXF.ViewFlipDeciders;
namespace ExportDXF.Forms
{ {
public class ViewFlipDeciderComboboxItem public class ViewFlipDeciderComboboxItem
{ {

View File

@@ -1,78 +0,0 @@
using System.Linq;
using System.Windows.Forms;
namespace ExportDXF
{
public interface IViewFlipDecider
{
bool ShouldFlip(SolidWorks.Interop.sldworks.View view);
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.GetBendClosestToBounds(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;
}
}
}
}

View File

@@ -0,0 +1,24 @@
using System.Windows.Forms;
namespace ExportDXF.ViewFlipDeciders
{
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;
}
}
}

View File

@@ -0,0 +1,29 @@
using System.Linq;
namespace ExportDXF.ViewFlipDeciders
{
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.GetBendClosestToBounds(bounds, bends);
return bend.Direction == BendDirection.Down;
}
}
}

View File

@@ -0,0 +1,9 @@
namespace ExportDXF.ViewFlipDeciders
{
public interface IViewFlipDecider
{
bool ShouldFlip(SolidWorks.Interop.sldworks.View view);
string Name { get; }
}
}

View File

@@ -0,0 +1,26 @@
using System.Linq;
using System.Windows.Forms;
namespace ExportDXF.ViewFlipDeciders
{
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;
}
}
}
}