1165 lines
41 KiB
C#
1165 lines
41 KiB
C#
using CoreUnit.Common;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Drawing;
|
||
using System.Text.Json;
|
||
using System.Windows.Forms;
|
||
using System.Xml;
|
||
|
||
namespace CoreUnit.Control.UserControl.Canvas
|
||
{
|
||
public class NodePointZigZag : INodePoint
|
||
{
|
||
public enum ePoint
|
||
{
|
||
P1,
|
||
P2,
|
||
}
|
||
|
||
static bool m_angleLocked = false;
|
||
ZigZag m_owner;
|
||
ZigZag m_clone;
|
||
|
||
UnitPoint m_originalPoint;
|
||
public UnitPoint OriginalPoint {
|
||
get { lock (this) { return m_originalPoint; } }
|
||
set { lock (this) { m_originalPoint = value; } }
|
||
}
|
||
|
||
UnitPoint m_endPoint;
|
||
public UnitPoint EndPoint {
|
||
get { lock (this) { return m_endPoint; } }
|
||
set { lock (this) { m_endPoint = value; } }
|
||
}
|
||
|
||
ePoint m_pointId;
|
||
public ePoint PointId {
|
||
get { lock (this) { return m_pointId; } }
|
||
set { lock (this) { m_pointId = value; } }
|
||
}
|
||
|
||
public NodePointZigZag(ZigZag owner, ePoint id)
|
||
{
|
||
m_owner = owner;
|
||
m_clone = m_owner.Clone() as ZigZag;
|
||
m_pointId = id;
|
||
m_originalPoint = GetPoint(m_pointId);
|
||
}
|
||
|
||
#region INodePoint Members
|
||
public IDrawObject GetClone()
|
||
{
|
||
return m_clone;
|
||
}
|
||
|
||
public IDrawObject GetOriginal()
|
||
{
|
||
return m_owner;
|
||
}
|
||
|
||
public void SetPosition(UnitPoint pos)
|
||
{
|
||
if (System.Windows.Forms.Control.ModifierKeys == Keys.Control)
|
||
pos = HitUtil.OrthoPointD(OtherPoint(m_pointId), pos, 45);
|
||
if (m_angleLocked || System.Windows.Forms.Control.ModifierKeys == (Keys)(Keys.Control | Keys.Shift))
|
||
pos = HitUtil.NearestPointOnLine(m_owner.P1, m_owner.P2, pos, true);
|
||
SetPoint(m_pointId, pos, m_clone);
|
||
}
|
||
|
||
public void Finish()
|
||
{
|
||
m_endPoint = GetPoint(m_pointId);
|
||
m_owner.P1 = m_clone.P1;
|
||
m_owner.P2 = m_clone.P2;
|
||
m_clone = null;
|
||
}
|
||
|
||
public void Cancel()
|
||
{
|
||
}
|
||
|
||
public void Undo()
|
||
{
|
||
SetPoint(m_pointId, m_originalPoint, m_owner);
|
||
}
|
||
|
||
public void Redo()
|
||
{
|
||
SetPoint(m_pointId, m_endPoint, m_owner);
|
||
}
|
||
|
||
public void OnKeyDown(ICanvas canvas, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode == Keys.L) {
|
||
m_angleLocked = !m_angleLocked;
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
protected UnitPoint GetPoint(ePoint pointid)
|
||
{
|
||
if (pointid == ePoint.P1)
|
||
return m_clone.P1;
|
||
if (pointid == ePoint.P2)
|
||
return m_clone.P2;
|
||
return m_owner.P1;
|
||
}
|
||
|
||
protected UnitPoint OtherPoint(ePoint currentpointid)
|
||
{
|
||
if (currentpointid == ePoint.P1)
|
||
return GetPoint(ePoint.P2);
|
||
return GetPoint(ePoint.P1);
|
||
}
|
||
|
||
protected void SetPoint(ePoint pointid, UnitPoint point, ZigZag line)
|
||
{
|
||
if (pointid == ePoint.P1)
|
||
line.P1 = point;
|
||
if (pointid == ePoint.P2)
|
||
line.P2 = point;
|
||
}
|
||
}
|
||
|
||
public class ZigZag : DrawObjectBase, IDrawObject, ISerialize
|
||
{
|
||
[Browsable(false)]
|
||
private bool _isLoading = true;
|
||
|
||
UnitPoint m_p1, m_p2;
|
||
|
||
[Browsable(false)]
|
||
public UnitPoint P1 {
|
||
get { return m_p1; }
|
||
set { m_p1 = value; }
|
||
}
|
||
|
||
[Browsable(false)]
|
||
public UnitPoint P2 {
|
||
get { return m_p2; }
|
||
set { m_p2 = value; }
|
||
}
|
||
List<UnitPoint> m_arcStartPoints = new List<UnitPoint>();
|
||
[Browsable(false)]
|
||
public List<UnitPoint> ArcStartPoints {
|
||
get { return new List<UnitPoint>(m_arcStartPoints); }
|
||
set { m_arcStartPoints = new List<UnitPoint>(value); }
|
||
}
|
||
List<UnitPoint> m_arcEndPoints = new List<UnitPoint>();
|
||
[Browsable(false)]
|
||
public List<UnitPoint> ArcEndPoints {
|
||
get { return new List<UnitPoint>(m_arcEndPoints); }
|
||
set { m_arcEndPoints = new List<UnitPoint>(value); }
|
||
}
|
||
|
||
List<UnitPoint> m_arcCenterPoints = new List<UnitPoint>();
|
||
[Browsable(false)]
|
||
public List<UnitPoint> ArcCenterPoints {
|
||
get { return new List<UnitPoint>(m_arcCenterPoints); }
|
||
set { m_arcCenterPoints = new List<UnitPoint>(value); }
|
||
}
|
||
|
||
List<UnitPoint> m_lineStartPoints = new List<UnitPoint>();
|
||
[Browsable(false)]
|
||
public List<UnitPoint> LineStartPoints {
|
||
get { return new List<UnitPoint>(m_lineStartPoints); }
|
||
set { m_lineStartPoints = new List<UnitPoint>(value); }
|
||
}
|
||
|
||
List<UnitPoint> m_lineCenterPoints = new List<UnitPoint>();
|
||
[Browsable(false)]
|
||
public List<UnitPoint> LineCenterPoints {
|
||
get { return new List<UnitPoint>(m_lineCenterPoints); }
|
||
set { m_lineCenterPoints = new List<UnitPoint>(value); }
|
||
}
|
||
|
||
List<UnitPoint> m_lineEndPoints = new List<UnitPoint>();
|
||
[Browsable(false)]
|
||
public List<UnitPoint> LineEndPoints {
|
||
get { return new List<UnitPoint>(m_lineEndPoints); }
|
||
set { m_lineEndPoints = new List<UnitPoint>(value); }
|
||
}
|
||
public static string ObjectType {
|
||
get { return "ZigZag"; }
|
||
}
|
||
|
||
public ZigZag()
|
||
{
|
||
}
|
||
|
||
public ZigZag(UnitPoint point, UnitPoint endpoint, float width, Color color)
|
||
{
|
||
P1 = point;
|
||
P2 = endpoint;
|
||
Width = width;
|
||
Color = color;
|
||
Selected = false;
|
||
}
|
||
|
||
public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
|
||
{
|
||
P1 = P2 = point;
|
||
Width = layer.Width;
|
||
//Color = layer.Color;
|
||
Selected = true;
|
||
_isLoading = false;
|
||
}
|
||
|
||
static int ThresholdPixel = 6;
|
||
static float ThresholdWidth(ICanvas canvas, float objectwidth)
|
||
{
|
||
return ThresholdWidth(canvas, objectwidth, ThresholdPixel);
|
||
}
|
||
|
||
public static float ThresholdWidth(ICanvas canvas, float objectwidth, float pixelwidth)
|
||
{
|
||
double minWidth = canvas.ToUnit(pixelwidth);
|
||
double width = Math.Max(objectwidth / 2, minWidth);
|
||
return (float)width;
|
||
}
|
||
|
||
public virtual void Copy(ZigZag acopy)
|
||
{
|
||
base.Copy(acopy);
|
||
P1 = acopy.P1;
|
||
P2 = acopy.P2;
|
||
Type = acopy.Type;
|
||
m_no = acopy.m_no;
|
||
m_amplitude = acopy.m_amplitude;
|
||
m_radius = acopy.m_radius;
|
||
m_pitch = acopy.m_pitch;
|
||
m_drawDirection = acopy.m_drawDirection;
|
||
|
||
|
||
//<2F><>ŷ<EFBFBD><C5B7>ü<EFBFBD><C3BC> <20><><EFBFBD><EFBFBD> <20>Ӽ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
ScannerParamNo = acopy.ScannerParamNo;
|
||
Enabled = acopy.Enabled;
|
||
Selected = acopy.Selected;
|
||
WeldingParameterID = acopy.WeldingParameterID;
|
||
|
||
m_objectOffset = acopy.m_objectOffset;
|
||
m_reverse = acopy.m_reverse;
|
||
m_lock = acopy.m_lock;
|
||
|
||
m_tag = acopy.m_tag;
|
||
m_PMU_ID = acopy.m_PMU_ID;
|
||
|
||
m_visionOffset = acopy.m_visionOffset;
|
||
m_alignType = acopy.m_alignType;
|
||
m_alignID = acopy.m_alignID;
|
||
m_alignOffset = acopy.m_alignOffset;
|
||
}
|
||
|
||
#region IDrawObject Members
|
||
|
||
#region <EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>Ӽ<EFBFBD>
|
||
|
||
bool m_enabled = true;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Enable Mark", 6, 6)]
|
||
[Description("Enable Mark")]
|
||
[XmlSerializable]
|
||
public bool Enabled {
|
||
get { return m_enabled; }
|
||
set { m_enabled = value; }
|
||
}
|
||
|
||
bool m_reverse = false;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Reverse", 4, 6)]
|
||
[Description("Reverse")]
|
||
[XmlSerializable]
|
||
public bool Reverse {
|
||
get { return m_reverse; }
|
||
set { m_reverse = value; }
|
||
}
|
||
|
||
bool m_lock = false;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Lock", 5, 6)]
|
||
[Description("Lock")]
|
||
[XmlSerializable]
|
||
public bool Lock {
|
||
get { return m_lock; }
|
||
set { m_lock = value; }
|
||
}
|
||
|
||
int m_tag = 0;
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Misc", 4, 6)]
|
||
[CustomSortedDisplayName("Tag", 1, 1)]
|
||
[Description("Tag")]
|
||
[XmlSerializable]
|
||
public int Tag {
|
||
get { return m_tag; }
|
||
set { m_tag = value; }
|
||
}
|
||
|
||
int m_PMU_ID = 0;
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[Category("Misc")]
|
||
[DisplayName("PMU_ID")]
|
||
[Description("PMU_ID")]
|
||
[XmlSerializable]
|
||
public int PMU_ID {
|
||
get { return m_PMU_ID; }
|
||
set { m_PMU_ID = value; }
|
||
}
|
||
|
||
int m_scannerParamNo = 0;
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[Category("3. Marking Parameter")]
|
||
[DisplayName("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȣ")]
|
||
[Description("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><>ĵ<EFBFBD>ӵ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ŀ<EFBFBD> <20><><EFBFBD><EFBFBD>..) <20><>ȣ <20><><EFBFBD><EFBFBD>")]
|
||
[XmlSerializable]
|
||
public int ScannerParamNo {
|
||
get { return m_scannerParamNo; }
|
||
set { m_scannerParamNo = value; }
|
||
}
|
||
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[Category("3. Marking Parameter")]
|
||
[DisplayName("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ID")]
|
||
[Description("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><>ĵ<EFBFBD>ӵ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ŀ<EFBFBD> <20><><EFBFBD><EFBFBD>..) ID <20><><EFBFBD><EFBFBD>")]
|
||
[XmlSerializable]
|
||
public int ScannerParamID {
|
||
get { return m_scannerParamNo + 1; }
|
||
set { m_scannerParamNo = value - 1; }
|
||
}
|
||
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Pen", 2, 6)]
|
||
[CustomSortedDisplayName("Parameter", 1, 1)]
|
||
[Description("Welding Paramter ID")]
|
||
[Editor(typeof(WeldingParameterIDEditor.WeldingParamterNoUITypeEditor), typeof(System.Drawing.Design.UITypeEditor))]
|
||
[XmlSerializable]
|
||
public WeldingParameterIDEditor.eWeldingParamterID WeldingParameterID {
|
||
get { return (WeldingParameterIDEditor.eWeldingParamterID)ScannerParamID; }
|
||
set { ScannerParamID = (int)value; }
|
||
}
|
||
|
||
PointF m_objectOffset = new PointF();
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[Category("Pen")]
|
||
[DisplayName("Object Offset")]
|
||
[Description("Offset for Shot position when wleding, Expert Use Only")]
|
||
[TypeConverter(typeof(PointFConverter))]
|
||
[XmlSerializable]
|
||
public PointF ObjectOffset {
|
||
get { return m_objectOffset; }
|
||
set { m_objectOffset = value; }
|
||
}
|
||
|
||
PointF m_visionOffset = new PointF();
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Vision Align", 4, 6)]
|
||
[CustomSortedDisplayName("Vision Offset", 4, 4)]
|
||
[Description("Vision Offset")]
|
||
[TypeConverter(typeof(PointFConverter))]
|
||
[XmlSerializable]
|
||
public PointF VisionOffset {
|
||
get { return m_visionOffset; }
|
||
set { m_visionOffset = value; }
|
||
}
|
||
|
||
public enum eAlignType { XY_ANGLE, XY_OFFSET, X_OFFSET, Y_OFFSET, ABSOLUTE_XY }
|
||
eAlignType m_alignType = eAlignType.ABSOLUTE_XY;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Vision Align", 4, 6)]
|
||
[CustomSortedDisplayName("Align Type", 1, 2)]
|
||
[Description("Align Type")]
|
||
[XmlSerializable]
|
||
public eAlignType AlignType {
|
||
get { return m_alignType; }
|
||
set { m_alignType = value; }
|
||
}
|
||
|
||
int m_alignID = -1;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Vision Align", 4, 6)]
|
||
[CustomSortedDisplayName("Align ID", 2, 2)]
|
||
[Description("Align ID")]
|
||
[XmlSerializable]
|
||
public int AlignID {
|
||
get { return m_alignID; }
|
||
set { m_alignID = value; }
|
||
}
|
||
|
||
PointF m_alignOffset = new PointF();
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[Category("Vision Align")]
|
||
[DisplayName("Align Offset")]
|
||
[Description("Align Offset")]
|
||
[TypeConverter(typeof(PointFConverter))]
|
||
[XmlSerializable]
|
||
public PointF AlignOffset {
|
||
get { return m_alignOffset; }
|
||
set { m_alignOffset = value; }
|
||
}
|
||
#endregion
|
||
|
||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>Ӽ<EFBFBD>
|
||
|
||
int m_no;
|
||
[Browsable(false)]
|
||
[XmlSerializable]
|
||
public int No {
|
||
get { return m_no; }
|
||
set { m_no = value; }
|
||
}
|
||
|
||
string m_type;
|
||
[Browsable(false)]
|
||
[ReadOnly(true)]
|
||
[Category("1. <20><>ü")]
|
||
[DisplayName("<22><><EFBFBD><EFBFBD>")]
|
||
[Description("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ü <20><><EFBFBD><EFBFBD>")]
|
||
[XmlSerializable]
|
||
public string Type {
|
||
get {
|
||
m_type = ZigZag.ObjectType;
|
||
return m_type;
|
||
}
|
||
|
||
set { m_type = value; }
|
||
}
|
||
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Start[X,Y](mm)", 1, 6)]
|
||
[Description("Starting Point Of Drawing Object")]
|
||
[TypeConverter(typeof(PointFConverter))]
|
||
[XmlSerializable]
|
||
public PointF PF1 {
|
||
get { lock (this) { return P1.Point; } }
|
||
set { lock (this) { P1 = new UnitPoint(value); } }
|
||
}
|
||
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("End[X,Y](mm)", 2, 6)]
|
||
[Description("Ending Point Of Drawing Object")]
|
||
[TypeConverter(typeof(PointFConverter))]
|
||
[XmlSerializable]
|
||
public PointF PF2 {
|
||
get { lock (this) { return P2.Point; } }
|
||
set { lock (this) { P2 = new UnitPoint(value); } }
|
||
}
|
||
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[Category("2. Geometry")]
|
||
[DisplayName("3.<2E>߽<EFBFBD><DFBD><EFBFBD>[X,Y](mm)")]
|
||
[Description("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> <20>߽<EFBFBD><DFBD><EFBFBD>")]
|
||
[TypeConverter(typeof(PointFConverter))]
|
||
public PointF MiddlePoint {
|
||
get { return HitUtil.LineMidpoint(P1, P2).Point; }
|
||
set {
|
||
PointF offset = new PointF();
|
||
offset.X = (value.X - MiddlePoint.X);
|
||
offset.Y = (value.Y - MiddlePoint.Y);
|
||
Move(new UnitPoint(offset));
|
||
}
|
||
}
|
||
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Angle(degree)", 3, 6)]
|
||
[Description("Angle Of Drawing Object")]
|
||
public float Angle {
|
||
get { return (float)Math.Round(HitUtil.RadiansToDegrees(HitUtil.LineAngleR(P1, P2, 0)), 3); }
|
||
set {
|
||
float angle = value - Angle;
|
||
Rotate(angle, P1);
|
||
}
|
||
}
|
||
|
||
[Browsable(true)]
|
||
[ReadOnly(true)]
|
||
[CustomSortedCategory("Boundary", 1, 6)]
|
||
[CustomSortedDisplayName("Left,Bottom,Right,Top", 1, 1)]
|
||
[Description("Boundary of Object")]
|
||
[TypeConverter(typeof(RectangleFConverter))]
|
||
public RectangleF ClientRect {
|
||
get {
|
||
lock (this) { return ScreenUtils.GetRect(P1, P2, 0); }
|
||
}
|
||
}
|
||
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Line Length(mm)", 4, 6)]
|
||
[Description("Length of Drawing Object")]
|
||
public double Distance {
|
||
get { return Math.Round(HitUtil.Distance(P1, P2), 3); }
|
||
set {
|
||
double distance = value;
|
||
if (distance < m_pitch * 0.5f) {
|
||
distance = m_pitch * 0.5f;
|
||
MakeLength((float)distance);
|
||
} else {
|
||
MakeLength((float)distance);
|
||
}
|
||
}
|
||
}
|
||
double m_totalLength;
|
||
[Browsable(false)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("Geometry", 3, 6)]
|
||
[CustomSortedDisplayName("Total Length(mm)", 5, 6)]
|
||
[Description("Total Length of Drawing Object")]
|
||
public double TotalLength {
|
||
get { return m_totalLength; }
|
||
set {
|
||
m_totalLength = value;
|
||
}
|
||
}
|
||
double m_vertexAngle = 30;
|
||
[Browsable(true)]
|
||
[CustomSortedCategory("ZigZag Paramter", 4, 6)]
|
||
[CustomSortedDisplayName("Vertex Angle", 1, 6)]
|
||
[Description("vertex angle between 2 lines")]
|
||
public double VertexAngle {
|
||
get { return (float)m_vertexAngle; }
|
||
}
|
||
|
||
public enum eDrawDirection { Left, Right }
|
||
eDrawDirection m_drawDirection = eDrawDirection.Left;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("ZigZag Paramter", 4, 6)]
|
||
[CustomSortedDisplayName("Draw Direction", 2, 6)]
|
||
[Description("Draw Direction (Left, Right)")]
|
||
[XmlSerializable]
|
||
public eDrawDirection DrawDirection {
|
||
get { return m_drawDirection; }
|
||
set { m_drawDirection = value;
|
||
CreateZigZagPointList();
|
||
}
|
||
}
|
||
|
||
double m_radius = 0.1;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("ZigZag Paramter", 4, 6)]
|
||
[CustomSortedDisplayName("Radius", 3, 6)]
|
||
[Description("Radius of Arc bewtween 2 lines")]
|
||
[XmlSerializable]
|
||
public double Radius {
|
||
get { return m_radius; }
|
||
set {
|
||
if (value > m_pitch * 0.25) {
|
||
if (!_isLoading) {
|
||
m_radius = m_pitch * 0.25;
|
||
}else {
|
||
m_radius = value;
|
||
}
|
||
} else {
|
||
m_radius = value;
|
||
}
|
||
if (!_isLoading)
|
||
CreateZigZagPointList();
|
||
}
|
||
}
|
||
|
||
double m_amplitude = 0.8;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("ZigZag Paramter", 4, 6)]
|
||
[CustomSortedDisplayName("Amplitude", 4, 6)]
|
||
[Description("Amplitude of Zigzag")]
|
||
[XmlSerializable]
|
||
public double Amplitude {
|
||
get {
|
||
return m_amplitude;
|
||
}
|
||
set {
|
||
if (value < m_radius * 2) {
|
||
if (!_isLoading) {
|
||
m_amplitude = m_radius * 2;
|
||
}else {
|
||
m_amplitude = value;
|
||
}
|
||
} else {
|
||
m_amplitude = value;
|
||
}
|
||
if (!_isLoading)
|
||
CreateZigZagPointList();
|
||
}
|
||
}
|
||
|
||
double m_pitch = 0.8;
|
||
[Browsable(true)]
|
||
[ReadOnly(false)]
|
||
[CustomSortedCategory("ZigZag Paramter", 4, 6)]
|
||
[CustomSortedDisplayName("Pitch", 5, 6)]
|
||
[Description("Pitch of Zigzag")]
|
||
[XmlSerializable]
|
||
public double Pitch {
|
||
get {
|
||
return m_pitch;
|
||
}
|
||
set {
|
||
if (value < m_radius * 4) {
|
||
if (!_isLoading) {
|
||
m_pitch = m_radius * 4;
|
||
} else {
|
||
m_pitch = value;
|
||
}
|
||
} else if (value * 0.5f > Distance) {
|
||
if (!_isLoading) {
|
||
m_pitch = Distance * 2;
|
||
} else {
|
||
m_pitch = value;
|
||
}
|
||
} else {
|
||
m_pitch = value;
|
||
}
|
||
if (!_isLoading)
|
||
CreateZigZagPointList();
|
||
}
|
||
}
|
||
|
||
int m_zigZagCount = 10;
|
||
[Browsable(true)]
|
||
[ReadOnly(true)]
|
||
[CustomSortedCategory("ZigZag Paramter", 4, 6)]
|
||
[CustomSortedDisplayName("ZigZag Count", 6, 6)]
|
||
[Description("ZigZag Count")]
|
||
public int ZigZagCount {
|
||
get {
|
||
return m_zigZagCount;
|
||
}
|
||
}
|
||
|
||
public virtual IDrawObject Clone()
|
||
{
|
||
ZigZag l = new ZigZag();
|
||
l.Copy(this);
|
||
l._isLoading = false;
|
||
return l;
|
||
}
|
||
|
||
public RectangleF GetBoundingRect(ICanvas canvas)
|
||
{
|
||
float thWidth = ThresholdWidth(canvas, Width);
|
||
return ScreenUtils.GetRect(P1, P2, thWidth);
|
||
}
|
||
|
||
public UnitPoint m_bufferP;
|
||
public void ClearDrawing(ICanvas canvas, RectangleF unitrect)
|
||
{
|
||
Color color = Color.White;
|
||
Pen pen = canvas.CreatePen(color, Width);
|
||
canvas.DrawLine(canvas, pen, P1, P2);
|
||
|
||
if (Highlighted) {
|
||
canvas.DrawLine(canvas, DrawUtils.SelectedPen, P1, P2);
|
||
}
|
||
|
||
if (Selected) {
|
||
canvas.DrawLine(canvas, DrawUtils.SelectedPen, P1, P2);
|
||
|
||
if (P1.IsEmpty == false) {
|
||
DrawUtils.DrawNode(canvas, P1);
|
||
}
|
||
|
||
if (P2.IsEmpty == false) {
|
||
DrawUtils.DrawTriangleNode(canvas, P2);
|
||
}
|
||
}
|
||
}
|
||
|
||
public virtual void Draw(ICanvas canvas, RectangleF unitrect)
|
||
{
|
||
Color color = WeldingParameterIDEditor.weldingColorList[(int)WeldingParameterID - 1];
|
||
Pen pen = canvas.CreatePen(color, Width);
|
||
|
||
pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
|
||
pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
|
||
|
||
//PointList <20><><EFBFBD><EFBFBD>
|
||
CreateZigZagPointList();
|
||
|
||
DrawZigZag(canvas, pen);
|
||
|
||
if (Highlighted) {
|
||
DrawZigZag(canvas, DrawUtils.SelectedPen);
|
||
}
|
||
|
||
if (Selected) {
|
||
DrawZigZag(canvas, DrawUtils.SelectedPen);
|
||
|
||
if (P1.IsEmpty == false) {
|
||
DrawUtils.DrawNode(canvas, P1);
|
||
}
|
||
|
||
if (P2.IsEmpty == false) {
|
||
DrawUtils.DrawTriangleNode(canvas, P2);
|
||
}
|
||
}
|
||
_isLoading = false;
|
||
}
|
||
|
||
private void DrawZigZag(ICanvas canvas, Pen pen)
|
||
{
|
||
for (int i = 0; i < m_zigZagCount; i++) {
|
||
canvas.DrawLine(canvas, pen, m_lineStartPoints[i], m_arcStartPoints[i]);
|
||
|
||
bool clockwise = DrawDirection == eDrawDirection.Left ? true : false;
|
||
|
||
if (i % 2 == 0) {
|
||
canvas.DrawArc(canvas, pen, m_arcCenterPoints[i], m_arcStartPoints[i], m_arcEndPoints[i], clockwise);
|
||
} else {
|
||
canvas.DrawArc(canvas, pen, m_arcCenterPoints[i], m_arcStartPoints[i], m_arcEndPoints[i], !clockwise);
|
||
}
|
||
|
||
canvas.DrawLine(canvas, pen, m_arcEndPoints[i], m_lineEndPoints[i]);
|
||
}
|
||
|
||
if (m_zigZagCount > 0) {
|
||
float angle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_arcEndPoints[m_zigZagCount - 1], m_lineEndPoints[m_zigZagCount - 1], 0));
|
||
|
||
DrawUtils.DrawArrowNode(canvas, m_lineEndPoints[m_zigZagCount - 1], angle, pen);
|
||
}
|
||
}
|
||
|
||
private void CreateZigZagPointList()
|
||
{
|
||
m_lineStartPoints.Clear();
|
||
m_lineCenterPoints.Clear();
|
||
m_lineEndPoints.Clear();
|
||
m_arcStartPoints.Clear();
|
||
m_arcCenterPoints.Clear();
|
||
m_arcEndPoints.Clear();
|
||
|
||
m_zigZagCount = (int)(Distance / (m_pitch * 0.5f));
|
||
|
||
double lineStartX = 0;
|
||
double lineStartY = 0;
|
||
double lineCenterX = 0;
|
||
double lineCenterY = 0;
|
||
double lineEndX = 0;
|
||
double lineEndY = 0;
|
||
double arcStartX = 0;
|
||
double arcStartY = 0;
|
||
double arcCenterX = 0;
|
||
double arcCenterY = 0;
|
||
double arcEndX = 0;
|
||
double arcEndY = 0;
|
||
|
||
m_vertexAngle = Math.Atan(m_pitch * 0.5f / m_amplitude);//Radian
|
||
|
||
for (int i = 0; i < m_zigZagCount; i++) {
|
||
if (m_drawDirection == eDrawDirection.Left) {
|
||
if (i % 2 == 0) {
|
||
lineStartX = lineEndX;
|
||
lineStartY = lineEndY;
|
||
lineCenterX = lineStartX + m_pitch * 0.25f;
|
||
lineCenterY = lineStartY + m_amplitude * 0.5f;
|
||
lineEndX = lineCenterX + m_pitch * 0.25f;
|
||
lineEndY = lineStartY;
|
||
|
||
arcCenterX = lineCenterX;
|
||
arcCenterY = lineCenterY - m_radius / Math.Sin(m_vertexAngle);
|
||
arcStartX = lineCenterX - m_radius * Math.Cos(m_vertexAngle);
|
||
arcStartY = arcCenterY + m_radius * Math.Sin(m_vertexAngle);
|
||
arcEndX = lineCenterX + m_radius * Math.Cos(m_vertexAngle);
|
||
arcEndY = arcCenterY + m_radius * Math.Sin(m_vertexAngle);
|
||
|
||
} else {
|
||
lineStartX = lineEndX;
|
||
lineStartY = lineEndY;
|
||
lineCenterX = lineStartX + m_pitch * 0.25f;
|
||
lineCenterY = lineStartY - m_amplitude * 0.5f;
|
||
lineEndX = lineCenterX + m_pitch * 0.25f;
|
||
lineEndY = lineStartY;
|
||
|
||
arcCenterX = lineCenterX;
|
||
arcCenterY = lineCenterY + m_radius / Math.Sin(m_vertexAngle);
|
||
arcStartX = lineCenterX - m_radius * Math.Cos(m_vertexAngle);
|
||
arcStartY = arcCenterY - m_radius * Math.Sin(m_vertexAngle);
|
||
arcEndX = lineCenterX + m_radius * Math.Cos(m_vertexAngle);
|
||
arcEndY = arcCenterY - m_radius * Math.Sin(m_vertexAngle);
|
||
}
|
||
} else {
|
||
if (i % 2 == 0) {
|
||
lineStartX = lineEndX;
|
||
lineStartY = lineEndY;
|
||
lineCenterX = lineStartX + m_pitch * 0.25f;
|
||
lineCenterY = lineStartY - m_amplitude * 0.5f;
|
||
lineEndX = lineCenterX + m_pitch * 0.25f;
|
||
lineEndY = lineStartY;
|
||
|
||
arcCenterX = lineCenterX;
|
||
arcCenterY = lineCenterY + m_radius / Math.Sin(m_vertexAngle);
|
||
arcStartX = lineCenterX - m_radius * Math.Cos(m_vertexAngle);
|
||
arcStartY = arcCenterY - m_radius * Math.Sin(m_vertexAngle);
|
||
arcEndX = lineCenterX + m_radius * Math.Cos(m_vertexAngle);
|
||
arcEndY = arcCenterY - m_radius * Math.Sin(m_vertexAngle);
|
||
} else {
|
||
lineStartX = lineEndX;
|
||
lineStartY = lineEndY;
|
||
lineCenterX = lineStartX + m_pitch * 0.25f;
|
||
lineCenterY = lineStartY + m_amplitude * 0.5f;
|
||
lineEndX = lineCenterX + m_pitch * 0.25f;
|
||
lineEndY = lineStartY;
|
||
|
||
arcCenterX = lineCenterX;
|
||
arcCenterY = lineCenterY - m_radius / Math.Sin(m_vertexAngle);
|
||
arcStartX = lineCenterX - m_radius * Math.Cos(m_vertexAngle);
|
||
arcStartY = arcCenterY + m_radius * Math.Sin(m_vertexAngle);
|
||
arcEndX = lineCenterX + m_radius * Math.Cos(m_vertexAngle);
|
||
arcEndY = arcCenterY + m_radius * Math.Sin(m_vertexAngle);
|
||
}
|
||
}
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȯ
|
||
double lineStartTransX = P1.X + lineStartX * Math.Cos(Angle * Math.PI / 180) - lineStartY * Math.Sin(Angle * Math.PI / 180);
|
||
double lineStartTransY = P1.Y + lineStartX * Math.Sin(Angle * Math.PI / 180) + lineStartY * Math.Cos(Angle * Math.PI / 180);
|
||
double lineCenterTransX = P1.X + lineCenterX * Math.Cos(Angle * Math.PI / 180) - lineCenterY * Math.Sin(Angle * Math.PI / 180);
|
||
double lineCenterTransY = P1.Y + lineCenterX * Math.Sin(Angle * Math.PI / 180) + lineCenterY * Math.Cos(Angle * Math.PI / 180);
|
||
double lineEndTransX = P1.X + lineEndX * Math.Cos(Angle * Math.PI / 180) - lineEndY * Math.Sin(Angle * Math.PI / 180);
|
||
double lineEndTransY = P1.Y + lineEndX * Math.Sin(Angle * Math.PI / 180) + lineEndY * Math.Cos(Angle * Math.PI / 180);
|
||
|
||
double arcStartTransX = P1.X + arcStartX * Math.Cos(Angle * Math.PI / 180) - arcStartY * Math.Sin(Angle * Math.PI / 180);
|
||
double arcStartTransY = P1.Y + arcStartX * Math.Sin(Angle * Math.PI / 180) + arcStartY * Math.Cos(Angle * Math.PI / 180);
|
||
double arcCenterTransX = P1.X + arcCenterX * Math.Cos(Angle * Math.PI / 180) - arcCenterY * Math.Sin(Angle * Math.PI / 180);
|
||
double arcCenterTransY = P1.Y + arcCenterX * Math.Sin(Angle * Math.PI / 180) + arcCenterY * Math.Cos(Angle * Math.PI / 180);
|
||
double arcEndTransX = P1.X + arcEndX * Math.Cos(Angle * Math.PI / 180) - arcEndY * Math.Sin(Angle * Math.PI / 180);
|
||
double arcEndTransY = P1.Y + arcEndX * Math.Sin(Angle * Math.PI / 180) + arcEndY * Math.Cos(Angle * Math.PI / 180);
|
||
|
||
m_lineStartPoints.Add(new UnitPoint(lineStartTransX, lineStartTransY));
|
||
m_lineCenterPoints.Add(new UnitPoint(lineCenterTransX, lineCenterTransY));
|
||
m_lineEndPoints.Add(new UnitPoint(lineEndTransX, lineEndTransY));
|
||
m_arcStartPoints.Add(new UnitPoint(arcStartTransX, arcStartTransY));
|
||
m_arcCenterPoints.Add(new UnitPoint(arcCenterTransX, arcCenterTransY));
|
||
m_arcEndPoints.Add(new UnitPoint(arcEndTransX, arcEndTransY));
|
||
}
|
||
|
||
// === <20><>ü <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ===
|
||
m_totalLength = 0.0;
|
||
|
||
// Line <20><><EFBFBD><EFBFBD>
|
||
for (int i = 0; i < m_lineStartPoints.Count; i++) {
|
||
double dx = m_arcStartPoints[i].X - m_lineStartPoints[i].X;
|
||
double dy = m_arcStartPoints[i].Y - m_lineStartPoints[i].Y;
|
||
var startLineLength = Math.Sqrt(dx * dx + dy * dy);
|
||
m_totalLength += startLineLength;
|
||
}
|
||
|
||
for (int i = 0; i < m_lineStartPoints.Count; i++) {
|
||
double dx = m_lineEndPoints[i].X - m_arcEndPoints[i].X;
|
||
double dy = m_lineEndPoints[i].Y - m_arcEndPoints[i].Y;
|
||
var endLineLength = Math.Sqrt(dx * dx + dy * dy);
|
||
m_totalLength += endLineLength;
|
||
}
|
||
|
||
// Arc <20><><EFBFBD><EFBFBD>
|
||
for (int i = 0; i < m_arcStartPoints.Count; i++) {
|
||
double dx = m_arcCenterPoints[i].X - m_arcStartPoints[i].X;
|
||
double dy = m_arcCenterPoints[i].Y - m_arcStartPoints[i].Y;
|
||
double radius = Math.Sqrt(dx * dx + dy * dy);
|
||
|
||
float startAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_arcCenterPoints[i], m_arcStartPoints[i], 0));
|
||
float endAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_arcCenterPoints[i], m_arcEndPoints[i], 0));
|
||
float sweepAngle = 0;
|
||
|
||
if (DrawDirection == ZigZag.eDrawDirection.Left) {
|
||
sweepAngle = (-1) * Math.Abs(startAngle - endAngle);
|
||
if (sweepAngle < -180) {
|
||
sweepAngle = (360 + sweepAngle) * (-1);
|
||
}
|
||
} else {
|
||
sweepAngle = Math.Abs(startAngle - endAngle);
|
||
if (sweepAngle > 180) {
|
||
sweepAngle = (360 - sweepAngle);
|
||
}
|
||
}
|
||
|
||
var arcLength = Math.Abs(sweepAngle) * (radius * (float)Math.PI / 180);
|
||
|
||
m_totalLength += arcLength;
|
||
}
|
||
}
|
||
|
||
UnitPoint MidPoint(ICanvas canvas, UnitPoint p1, UnitPoint p2, UnitPoint hitpoint)
|
||
{
|
||
UnitPoint mid = HitUtil.LineMidpoint(p1, p2);
|
||
float thWidth = ThresholdWidth(canvas, Width);
|
||
if (HitUtil.CircleHitPoint(mid, thWidth, hitpoint))
|
||
return mid;
|
||
return UnitPoint.Empty;
|
||
}
|
||
|
||
public bool PointInObject(ICanvas canvas, UnitPoint point)
|
||
{
|
||
float thWidth = ThresholdWidth(canvas, Width);
|
||
return HitUtil.IsPointInLine(P1, P2, point, thWidth);
|
||
}
|
||
|
||
public bool ObjectInRectangle(ICanvas canvas, RectangleF rect, bool anyPoint)
|
||
{
|
||
RectangleF boundingrect = GetBoundingRect(canvas);
|
||
if (anyPoint)
|
||
return HitUtil.LineIntersectWithRect(P1, P2, rect);
|
||
return rect.Contains(boundingrect);
|
||
}
|
||
|
||
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point)
|
||
{
|
||
if (System.Windows.Forms.Control.ModifierKeys == Keys.Control)
|
||
point = HitUtil.OrthoPointD(P1, point, 45);
|
||
P2 = point;
|
||
}
|
||
|
||
public virtual eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
|
||
{
|
||
|
||
Selected = false;
|
||
if (System.Windows.Forms.Control.ModifierKeys == Keys.Control)
|
||
point = HitUtil.OrthoPointD(P1, point, 45);
|
||
P2 = point;
|
||
return eDrawObjectMouseDown.Done;
|
||
}
|
||
|
||
public void OnMouseUp(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
|
||
{
|
||
}
|
||
|
||
public virtual void OnKeyDown(ICanvas canvas, KeyEventArgs e)
|
||
{
|
||
}
|
||
|
||
[Browsable(false)]
|
||
public UnitPoint RepeatStartingPoint {
|
||
get { return P2; }
|
||
}
|
||
|
||
public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
|
||
{
|
||
float thWidth = ThresholdWidth(canvas, Width);
|
||
|
||
if (HitUtil.CircleHitPoint(P1, thWidth, point)) {
|
||
return new NodePointZigZag(this, NodePointZigZag.ePoint.P1);
|
||
}
|
||
if (HitUtil.CircleHitPoint(P2, thWidth, point)) {
|
||
return new NodePointZigZag(this, NodePointZigZag.ePoint.P2);
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List<IDrawObject> otherobjs, Type[] runningsnaptypes, Type usersnaptype)
|
||
{
|
||
float thWidth = ThresholdWidth(canvas, Width);
|
||
if (runningsnaptypes != null) {
|
||
foreach (Type snaptype in runningsnaptypes) {
|
||
if (snaptype == typeof(VertextSnapPoint)) {
|
||
if (HitUtil.CircleHitPoint(P1, thWidth, point))
|
||
return new VertextSnapPoint(canvas, this, P1);
|
||
if (HitUtil.CircleHitPoint(P2, thWidth, point))
|
||
return new VertextSnapPoint(canvas, this, P2);
|
||
}
|
||
if (snaptype == typeof(MidpointSnapPoint)) {
|
||
UnitPoint p = MidPoint(canvas, P1, P2, point);
|
||
if (p != UnitPoint.Empty)
|
||
return new MidpointSnapPoint(canvas, this, p);
|
||
}
|
||
if (snaptype == typeof(IntersectSnapPoint)) {
|
||
Line otherline = Utils.FindObjectTypeInList(this, otherobjs, typeof(Line)) as Line;
|
||
if (otherline == null)
|
||
continue;
|
||
UnitPoint p = HitUtil.LinesIntersectPoint(P1, P2, otherline.P1, otherline.P2);
|
||
if (p != UnitPoint.Empty)
|
||
return new IntersectSnapPoint(canvas, this, p);
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
if (usersnaptype == typeof(MidpointSnapPoint))
|
||
return new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(P1, P2));
|
||
if (usersnaptype == typeof(IntersectSnapPoint)) {
|
||
Line otherline = Utils.FindObjectTypeInList(this, otherobjs, typeof(Line)) as Line;
|
||
if (otherline == null)
|
||
return null;
|
||
UnitPoint p = HitUtil.LinesIntersectPoint(P1, P2, otherline.P1, otherline.P2);
|
||
if (p != UnitPoint.Empty)
|
||
return new IntersectSnapPoint(canvas, this, p);
|
||
}
|
||
if (usersnaptype == typeof(VertextSnapPoint)) {
|
||
double d1 = HitUtil.Distance(point, P1);
|
||
double d2 = HitUtil.Distance(point, P2);
|
||
if (d1 <= d2)
|
||
return new VertextSnapPoint(canvas, this, P1);
|
||
return new VertextSnapPoint(canvas, this, P2);
|
||
}
|
||
if (usersnaptype == typeof(NearestSnapPoint)) {
|
||
UnitPoint p = HitUtil.NearestPointOnLine(P1, P2, point);
|
||
if (p != UnitPoint.Empty)
|
||
return new NearestSnapPoint(canvas, this, p);
|
||
}
|
||
if (usersnaptype == typeof(PerpendicularSnapPoint)) {
|
||
UnitPoint p = HitUtil.NearestPointOnLine(P1, P2, point);
|
||
if (p != UnitPoint.Empty)
|
||
return new PerpendicularSnapPoint(canvas, this, p);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public void Move(UnitPoint offset)
|
||
{
|
||
m_p1.X += offset.X;
|
||
m_p1.Y += offset.Y;
|
||
m_p2.X += offset.X;
|
||
m_p2.Y += offset.Y;
|
||
}
|
||
|
||
public void Rotate(float angle, UnitPoint center)
|
||
{
|
||
// UnitPoint mid = Center;
|
||
P1 = HitUtil.RotatePoint(angle, P1, center);
|
||
P2 = HitUtil.RotatePoint(angle, P2, center);
|
||
}
|
||
|
||
public void MakeLength(float distance)
|
||
{
|
||
/*float slope =0;
|
||
double gapX =0;
|
||
double gapY = 0;
|
||
|
||
if (P1.X != P2.X)
|
||
{
|
||
slope = (float)((P2.Y - P1.Y) / (P2.X - P1.X));
|
||
gapX= distance / (2 * Math.Sqrt(Math.Pow(slope, 2) + 1));
|
||
gapY = (distance * slope) / (2 * Math.Sqrt(Math.Pow(slope, 2) + 1));
|
||
}
|
||
else
|
||
{
|
||
gapY = distance * 0.5;
|
||
}
|
||
|
||
PointF pt1 = new PointF();
|
||
PointF pt2 = new PointF();
|
||
|
||
//<2F><><EFBFBD><EFBFBD>-<2D>ȿ<EFBFBD><C8BF><EFBFBD>-161017-<2D><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȯ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
if(P1.X>P2.X)
|
||
{
|
||
pt1.X = (float)(MiddlePoint.X + gapX);
|
||
pt2.X = (float)(MiddlePoint.X - gapX);
|
||
}
|
||
else
|
||
{
|
||
pt1.X = (float)(MiddlePoint.X - gapX);
|
||
pt2.X = (float)(MiddlePoint.X + gapX);
|
||
}
|
||
|
||
if (P1.Y > P2.Y)
|
||
{
|
||
pt1.Y= (float)(MiddlePoint.Y - gapY);
|
||
pt2.Y = (float)(MiddlePoint.Y + gapY);
|
||
}
|
||
else
|
||
{
|
||
pt1.Y = (float)(MiddlePoint.Y + gapY);
|
||
pt2.Y = (float)(MiddlePoint.Y - gapY);
|
||
}
|
||
|
||
|
||
P1 = new UnitPoint(pt1.X, pt1.Y);
|
||
P2 = new UnitPoint(pt2.X, pt2.Y);
|
||
*/
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||
float x, y;
|
||
double delta;
|
||
|
||
if (P1.X == P2.X) {
|
||
delta = P1.Y < P2.Y ? distance : -distance;
|
||
P2 = new UnitPoint(P2.X, P1.Y + delta);
|
||
} else if (P1.Y == P2.Y) {
|
||
delta = P1.X < P2.X ? distance : -distance;
|
||
P2 = new UnitPoint(P1.X + delta, P2.Y);
|
||
} else {
|
||
float slope = (float)((P2.Y - P1.Y) / (P2.X - P1.X));
|
||
delta = (Math.Sqrt(Math.Pow(distance, 2) / (1 + Math.Pow(slope, 2))));
|
||
|
||
x = (P2.X > P1.X) ? (float)P1.X + (float)delta : (float)P1.X - (float)delta;
|
||
y = slope * (x - (float)P1.X) + (float)P1.Y;
|
||
|
||
P2 = new UnitPoint(x, y);
|
||
}
|
||
}
|
||
|
||
public virtual string GetInfoAsString()
|
||
{
|
||
return string.Format("{1:D3} {0}@{2},{3} - L={4:f4} <{5:f4}",
|
||
this.Type,
|
||
No + 1,
|
||
P1.PosAsString(),
|
||
P2.PosAsString(),
|
||
Distance,
|
||
Angle);
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
public void ExtendLineToPoint(UnitPoint newpoint)
|
||
{
|
||
UnitPoint newlinepoint = HitUtil.NearestPointOnLine(P1, P2, newpoint, true);
|
||
if (HitUtil.Distance(newlinepoint, P1) < HitUtil.Distance(newlinepoint, P2))
|
||
P1 = newlinepoint;
|
||
else
|
||
P2 = newlinepoint;
|
||
}
|
||
|
||
#region ISerialize Interface
|
||
public void GetObjectData(XmlWriter wr)
|
||
{
|
||
wr.WriteStartElement(Type);
|
||
Common.XmlUtil.WriteProperties(this, wr);
|
||
wr.WriteEndElement();
|
||
}
|
||
|
||
public virtual string GetObjectData()
|
||
{
|
||
string jsonString = string.Empty;
|
||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||
try {
|
||
jsonString += JsonSerializer.Serialize(this, options);
|
||
} catch {
|
||
|
||
}
|
||
return jsonString;
|
||
}
|
||
public void AfterSerializedIn()
|
||
{
|
||
}
|
||
#endregion
|
||
}
|
||
}
|
||
|