Added Files

This commit is contained in:
2025-10-27 18:48:23 -04:00
commit ab916dc82a
89 changed files with 7575 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
namespace PepLib.Codes
{
public class CircularMove : Motion
{
public CircularMove()
{
}
public CircularMove(Vector endPoint, Vector centerPoint, RotationType rotation = RotationType.CCW)
{
EndPoint = endPoint;
CenterPoint = centerPoint;
Rotation = rotation;
}
public CircularMove(double x, double y, double i, double j, RotationType rotation = RotationType.CCW)
{
EndPoint = new Vector(x, y);
CenterPoint = new Vector(i, j);
Rotation = rotation;
}
public RotationType Rotation { get; set; }
public EntityType Type { get; set; }
public Vector CenterPoint { get; set; }
public override void Rotate(double angle)
{
base.Rotate(angle);
CenterPoint = CenterPoint.Rotate(angle);
}
public override void Rotate(double angle, Vector origin)
{
base.Rotate(angle, origin);
CenterPoint = CenterPoint.Rotate(angle, origin);
}
public override void Offset(double x, double y)
{
base.Offset(x, y);
CenterPoint = new Vector(CenterPoint.X + x, CenterPoint.Y + y);
}
public override void Offset(Vector voffset)
{
base.Offset(voffset);
CenterPoint += voffset;
}
public override CodeType CodeType()
{
return Codes.CodeType.CircularMove;
}
public override ICode Clone()
{
return new CircularMove(EndPoint, CenterPoint, Rotation)
{
Type = Type
};
}
public override string ToString()
{
return Rotation == RotationType.CW ?
string.Format("G02 X{0} Y{1} I{2} J{3}", EndPoint.X, EndPoint.Y, CenterPoint.X, CenterPoint.Y) :
string.Format("G03 X{0} Y{1} I{2} J{3}", EndPoint.X, EndPoint.Y, CenterPoint.X, CenterPoint.Y);
}
}
}

View File

@@ -0,0 +1,14 @@
namespace PepLib.Codes
{
public enum CodeType
{
CircularMove,
Comment,
LinearMove,
RapidMove,
SetFeedrate,
SetKerf,
SubProgramCall
}
}

View File

@@ -0,0 +1,32 @@
namespace PepLib.Codes
{
public class Comment : ICode
{
public Comment()
{
}
public Comment(string value)
{
Value = value;
}
public string Value { get; set; }
public CodeType CodeType()
{
return Codes.CodeType.Comment;
}
public ICode Clone()
{
return new Comment(Value);
}
public override string ToString()
{
return ':' + Value;
}
}
}

View File

@@ -0,0 +1,13 @@
namespace PepLib.Codes
{
public enum EntityType
{
Display,
Scribe,
Cut,
InternalLeadin,
InternalLeadout,
ExternalLeadin,
ExternalLeadout
}
}

View File

@@ -0,0 +1,8 @@
namespace PepLib.Codes
{
public interface ICode
{
CodeType CodeType();
ICode Clone();
}
}

View File

@@ -0,0 +1,42 @@
namespace PepLib.Codes
{
public class LinearMove : Motion
{
public LinearMove()
: this(new Vector())
{
}
public LinearMove(double x, double y)
: this(new Vector(x, y))
{
}
public LinearMove(Vector endPoint)
{
EndPoint = endPoint;
Type = EntityType.Cut;
}
public EntityType Type { get; set; }
public override CodeType CodeType()
{
return Codes.CodeType.LinearMove;
}
public override ICode Clone()
{
return new LinearMove(EndPoint)
{
Type = Type
};
}
public override string ToString()
{
return string.Format("G01 X{0} Y{1}", EndPoint.X, EndPoint.Y);
}
}
}

View File

@@ -0,0 +1,32 @@
namespace PepLib.Codes
{
public abstract class Motion : IMovable, ICode
{
public Vector EndPoint { get; set; }
public virtual void Rotate(double angle)
{
EndPoint = EndPoint.Rotate(angle);
}
public virtual void Rotate(double angle, Vector origin)
{
EndPoint = EndPoint.Rotate(angle, origin);
}
public virtual void Offset(double x, double y)
{
EndPoint = new Vector(EndPoint.X + x, EndPoint.Y + y);
}
public virtual void Offset(Vector voffset)
{
EndPoint += voffset;
}
public abstract CodeType CodeType();
public abstract ICode Clone();
}
}

View File

@@ -0,0 +1,34 @@
namespace PepLib.Codes
{
public class RapidMove : Motion
{
public RapidMove()
{
}
public RapidMove(Vector endPoint)
{
EndPoint = endPoint;
}
public RapidMove(double x, double y)
{
EndPoint = new Vector(x, y);
}
public override CodeType CodeType()
{
return Codes.CodeType.RapidMove;
}
public override ICode Clone()
{
return new RapidMove(EndPoint);
}
public override string ToString()
{
return string.Format("G00 X{0} Y{1}", EndPoint.X, EndPoint.Y);
}
}
}

View File

@@ -0,0 +1,32 @@
namespace PepLib.Codes
{
public class SetFeedrate : ICode
{
public SetFeedrate()
{
}
public SetFeedrate(double value)
{
Value = value;
}
public double Value { get; set; }
public CodeType CodeType()
{
return Codes.CodeType.SetFeedrate;
}
public ICode Clone()
{
return new SetFeedrate(Value);
}
public override string ToString()
{
return string.Format("F{0}", Value);
}
}
}

View File

@@ -0,0 +1,34 @@
namespace PepLib.Codes
{
public class SetKerf : ICode
{
public SetKerf(KerfType kerf = KerfType.Left)
{
Kerf = kerf;
}
public KerfType Kerf { get; set; }
public CodeType CodeType()
{
return Codes.CodeType.SetKerf;
}
public ICode Clone()
{
return new SetKerf(Kerf);
}
public override string ToString()
{
if (Kerf == KerfType.None)
return "G40";
if (Kerf == KerfType.Left)
return "G41";
return "G42";
}
}
}

View File

@@ -0,0 +1,85 @@
namespace PepLib.Codes
{
public class SubProgramCall : ICode
{
private double rotation;
private Loop loop;
public SubProgramCall()
{
}
public SubProgramCall(int loopId, int repeatCount, double rotation)
{
LoopId = loopId;
RepeatCount = repeatCount;
Rotation = rotation;
}
/// <summary>
/// The id associated with the current set loop.
/// </summary>
public int LoopId { get; set; }
/// <summary>
/// Number of times the loop is cut.
/// </summary>
public int RepeatCount { get; set; }
/// <summary>
/// Gets or sets the loop associated with the loop id.
/// </summary>
public Loop Loop
{
get { return loop; }
set
{
loop = (Loop)value.Clone();
UpdateLoopRotation();
}
}
/// <summary>
/// Gets or sets the current rotation of the loop in degrees.
/// </summary>
public double Rotation
{
get { return rotation; }
set
{
rotation = value;
UpdateLoopRotation();
}
}
private void UpdateLoopRotation()
{
if (loop != null)
{
var diffAngle = AngleConverter.ToRadians(rotation) - loop.Rotation;
if (!diffAngle.IsEqualTo(0.0))
loop.Rotate(diffAngle);
}
}
public CodeType CodeType()
{
return Codes.CodeType.SubProgramCall;
}
public ICode Clone()
{
return new SubProgramCall(LoopId, RepeatCount, Rotation)
{
Loop = Loop
};
}
public override string ToString()
{
return string.Format("G92 L{0} R{1} P{2}", LoopId, RepeatCount, Rotation);
}
}
}