Added PreferUpViewFlipDecider
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -88,10 +88,8 @@
|
|||||||
<Compile Include="BendOrientation.cs" />
|
<Compile Include="BendOrientation.cs" />
|
||||||
<Compile Include="Bounds.cs" />
|
<Compile Include="Bounds.cs" />
|
||||||
<Compile Include="DrawingInfo.cs" />
|
<Compile Include="DrawingInfo.cs" />
|
||||||
<Compile Include="AskViewFlipDecider.cs" />
|
|
||||||
<Compile Include="Item.cs" />
|
<Compile Include="Item.cs" />
|
||||||
<Compile Include="IViewFlipDecider.cs" />
|
<Compile Include="IViewFlipDecider.cs" />
|
||||||
<Compile Include="ViewFlipDecider.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>
|
||||||
@@ -101,6 +99,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ViewHelper.cs" />
|
||||||
<EmbeddedResource Include="Forms\MainForm.resx">
|
<EmbeddedResource Include="Forms\MainForm.resx">
|
||||||
<DependentUpon>MainForm.cs</DependentUpon>
|
<DependentUpon>MainForm.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|||||||
@@ -662,9 +662,3 @@ namespace ExportDXF.Forms
|
|||||||
public IViewFlipDecider ViewFlipDecider { get; set; }
|
public IViewFlipDecider ViewFlipDecider { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Helpers
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace ExportDXF
|
using System.Linq;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ExportDXF
|
||||||
{
|
{
|
||||||
public interface IViewFlipDecider
|
public interface IViewFlipDecider
|
||||||
{
|
{
|
||||||
@@ -6,4 +9,70 @@
|
|||||||
|
|
||||||
string Name { get; }
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,11 @@
|
|||||||
using SolidWorks.Interop.sldworks;
|
using SolidWorks.Interop.sldworks;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace ExportDXF
|
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
|
internal static class ViewHelper
|
||||||
{
|
{
|
||||||
public static Bounds GetBounds(SolidWorks.Interop.sldworks.View view)
|
public static Bounds GetBounds(SolidWorks.Interop.sldworks.View view)
|
||||||
Reference in New Issue
Block a user