Made it more possible to do matter cad like operations on IVertexSource paths
Made Braille Object have option for key chain hook Put ResolutionScalle into Vertex objects
This commit is contained in:
parent
5b8a690bef
commit
991be45a85
8 changed files with 228 additions and 17 deletions
|
|
@ -28,6 +28,8 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg.Transform;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
|
|
@ -63,6 +65,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
Top = 0x20,
|
||||
};
|
||||
|
||||
[Flags]
|
||||
public enum Side2D
|
||||
{
|
||||
Left = 0x01,
|
||||
Right = 0x02,
|
||||
Bottom = 0x10,
|
||||
Top = 0x20,
|
||||
};
|
||||
|
||||
public class Align : Object3D
|
||||
{
|
||||
public Align()
|
||||
|
|
@ -74,7 +85,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
if (objectToAlign == objectToAlignTo)
|
||||
{
|
||||
throw new Exception("You cannot align an object ot itself.");
|
||||
throw new Exception("You cannot align an object to itself.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,4 +176,92 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class Align2D : VertexSourceApplyTransform
|
||||
{
|
||||
public Align2D()
|
||||
{
|
||||
}
|
||||
|
||||
public Align2D(IVertexSource objectToAlign, Side2D boundingFacesToAlign, IVertexSource objectToAlignTo, Side2D boundingFacesToAlignTo, double offsetX = 0, double offsetY = 0, string name = "")
|
||||
: this(objectToAlign, boundingFacesToAlign, GetPositionToAlignTo(objectToAlignTo, boundingFacesToAlignTo, new Vector2(offsetX, offsetY)), name)
|
||||
{
|
||||
if (objectToAlign == objectToAlignTo)
|
||||
{
|
||||
throw new Exception("You cannot align an object to itself.");
|
||||
}
|
||||
}
|
||||
|
||||
public Align2D(IVertexSource objectToAlign, Side2D boundingFacesToAlign, double positionToAlignToX = 0, double positionToAlignToY = 0, string name = "")
|
||||
: this(objectToAlign, boundingFacesToAlign, new Vector2(positionToAlignToX, positionToAlignToY), name)
|
||||
{
|
||||
}
|
||||
|
||||
public Align2D(IVertexSource objectToAlign, Side2D boundingFacesToAlign, Vector2 positionToAlignTo, double offsetX, double offsetY, string name = "")
|
||||
: this(objectToAlign, boundingFacesToAlign, positionToAlignTo + new Vector2(offsetX, offsetY), name)
|
||||
{
|
||||
}
|
||||
|
||||
public Align2D(IVertexSource item, Side2D boundingFacesToAlign, Vector2 positionToAlignTo, string name = "")
|
||||
{
|
||||
var bounds = item.Bounds();
|
||||
|
||||
if (IsSet(boundingFacesToAlign, Side2D.Left, Side2D.Right))
|
||||
{
|
||||
positionToAlignTo.X = positionToAlignTo.X - bounds.Left;
|
||||
}
|
||||
if (IsSet(boundingFacesToAlign, Side2D.Right, Side2D.Left))
|
||||
{
|
||||
positionToAlignTo.X = positionToAlignTo.X - bounds.Left - (bounds.Right - bounds.Left);
|
||||
}
|
||||
if (IsSet(boundingFacesToAlign, Side2D.Bottom, Side2D.Top))
|
||||
{
|
||||
positionToAlignTo.Y = positionToAlignTo.Y - bounds.Bottom;
|
||||
}
|
||||
if (IsSet(boundingFacesToAlign, Side2D.Top, Side2D.Bottom))
|
||||
{
|
||||
positionToAlignTo.Y = positionToAlignTo.Y - bounds.Bottom - (bounds.Top - bounds.Bottom);
|
||||
}
|
||||
|
||||
Transform = Affine.NewTranslation(positionToAlignTo);
|
||||
VertexSource = item;
|
||||
}
|
||||
|
||||
public static Vector2 GetPositionToAlignTo(IVertexSource objectToAlignTo, Side2D boundingFacesToAlignTo, Vector2 extraOffset)
|
||||
{
|
||||
Vector2 positionToAlignTo = new Vector2();
|
||||
if (IsSet(boundingFacesToAlignTo, Side2D.Left, Side2D.Right))
|
||||
{
|
||||
positionToAlignTo.X = objectToAlignTo.Bounds().Left;
|
||||
}
|
||||
if (IsSet(boundingFacesToAlignTo, Side2D.Right, Side2D.Left))
|
||||
{
|
||||
positionToAlignTo.X = objectToAlignTo.Bounds().Right;
|
||||
}
|
||||
if (IsSet(boundingFacesToAlignTo, Side2D.Bottom, Side2D.Top))
|
||||
{
|
||||
positionToAlignTo.Y = objectToAlignTo.Bounds().Bottom;
|
||||
}
|
||||
if (IsSet(boundingFacesToAlignTo, Side2D.Top, Side2D.Bottom))
|
||||
{
|
||||
positionToAlignTo.Y = objectToAlignTo.Bounds().Top;
|
||||
}
|
||||
|
||||
return positionToAlignTo + extraOffset;
|
||||
}
|
||||
|
||||
private static bool IsSet(Side2D variableToCheck, Side2D faceToCheckFor, Side2D faceToAssertNot)
|
||||
{
|
||||
if ((variableToCheck & faceToCheckFor) != 0)
|
||||
{
|
||||
if ((variableToCheck & faceToAssertNot) != 0)
|
||||
{
|
||||
throw new Exception("You cannot have both " + faceToCheckFor.ToString() + " and " + faceToAssertNot.ToString() + " set when calling Align. The are mutually exclusive.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,20 +27,16 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using MatterHackers.Agg.Font;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using ClipperLib;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.DataConverters2D;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.DataConverters3D.UndoCommands;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
|
|
@ -64,6 +60,26 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
return resultsA;
|
||||
}
|
||||
|
||||
private static VertexStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType)
|
||||
{
|
||||
List<List<IntPoint>> aPolys = VertexSourceToClipperPolygons.CreatePolygons(a);
|
||||
List<List<IntPoint>> bPolys = VertexSourceToClipperPolygons.CreatePolygons(b);
|
||||
|
||||
Clipper clipper = new Clipper();
|
||||
|
||||
clipper.AddPaths(aPolys, PolyType.ptSubject, true);
|
||||
clipper.AddPaths(bPolys, PolyType.ptClip, true);
|
||||
|
||||
List<List<IntPoint>> intersectedPolys = new List<List<IntPoint>>();
|
||||
clipper.Execute(clipType, intersectedPolys);
|
||||
|
||||
VertexStorage output = VertexSourceToClipperPolygons.CreateVertexStorage(intersectedPolys);
|
||||
|
||||
output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public static IObject3D Plus(this IObject3D a, IObject3D b)
|
||||
{
|
||||
var results = new Object3D();
|
||||
|
|
@ -74,6 +90,16 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
return results;
|
||||
}
|
||||
|
||||
public static IVertexSource Minus(this IVertexSource a, IVertexSource b)
|
||||
{
|
||||
return CombinePaths(a, b, ClipType.ctDifference);
|
||||
}
|
||||
|
||||
public static IVertexSource Plus(this IVertexSource a, IVertexSource b)
|
||||
{
|
||||
return CombinePaths(a, b, ClipType.ctUnion);
|
||||
}
|
||||
|
||||
public static double XSize(this IObject3D item)
|
||||
{
|
||||
return item.GetAxisAlignedBoundingBox().XSize;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.Agg.Transform;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
|
|
@ -40,7 +42,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
public SetCenter(IObject3D item, Vector3 position)
|
||||
{
|
||||
Matrix *= Matrix4X4.CreateTranslation(position - item.GetCenter());
|
||||
Matrix = Matrix4X4.CreateTranslation(position - item.GetCenter());
|
||||
Children.Add(item.Clone());
|
||||
}
|
||||
|
||||
|
|
@ -67,8 +69,44 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
consideredOffset.Z = offset.Z - center.Z;
|
||||
}
|
||||
|
||||
Matrix *= Matrix4X4.CreateTranslation(consideredOffset);
|
||||
Matrix = Matrix4X4.CreateTranslation(consideredOffset);
|
||||
Children.Add(item.Clone());
|
||||
}
|
||||
}
|
||||
|
||||
public class SetCenter2D : VertexSourceApplyTransform
|
||||
{
|
||||
public SetCenter2D()
|
||||
{
|
||||
}
|
||||
|
||||
public SetCenter2D(IVertexSource item, Vector2 position)
|
||||
{
|
||||
Transform = Affine.NewTranslation(position - item.Bounds().Center);
|
||||
VertexSource = item;
|
||||
}
|
||||
|
||||
public SetCenter2D(IVertexSource item, double x, double y)
|
||||
: this(item, new Vector2(x, y))
|
||||
{
|
||||
}
|
||||
|
||||
public SetCenter2D(IVertexSource item, Vector2 offset, bool onX = true, bool onY = true)
|
||||
{
|
||||
var center = item.Bounds().Center;
|
||||
|
||||
Vector2 consideredOffset = Vector2.Zero; // zero out anything we don't want
|
||||
if (onX)
|
||||
{
|
||||
consideredOffset.X = offset.X - center.X;
|
||||
}
|
||||
if (onY)
|
||||
{
|
||||
consideredOffset.Y = offset.Y - center.Y;
|
||||
}
|
||||
|
||||
Transform = Affine.NewTranslation(consideredOffset);
|
||||
VertexSource = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue