202 lines
8.3 KiB
C#
202 lines
8.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
using netDxf;
|
|
using netDxf.Tables;
|
|
|
|
namespace MetroGauges.Controls
|
|
{
|
|
public class BlockArc : BaseShap
|
|
{
|
|
public BlockArc(FrameworkElement shap) : base(shap)
|
|
{
|
|
}
|
|
|
|
public override void CopyBlock()
|
|
{
|
|
Path path = shapeitem as Path;
|
|
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
|
|
ShapDataContext shapDataContext = path.DataContext as ShapDataContext;
|
|
|
|
List<Point> ps = new List<Point>();
|
|
ps.Add(new Point() { X = figure.StartPoint.X, Y = figure.StartPoint.Y }); //起点
|
|
ps.Add(new Point() { X = arcs.Point.X, Y = arcs.Point.Y }); //终点
|
|
ps.Add(new Point() { X = shapDataContext.Arc.Center.X, Y = shapDataContext.Arc.Center.Y }); //中心点
|
|
|
|
shapeitem.Tag = ps; //存储当前图形坐标
|
|
|
|
|
|
List<Point> ps1 = new List<Point>();
|
|
ps1.Add(new Point() { X = figure.StartPoint.X / shapDataContext.ShapScaleRate, Y = figure.StartPoint.Y / shapDataContext.ShapScaleRate });
|
|
ps1.Add(new Point() { X = arcs.Point.X/ shapDataContext.ShapScaleRate, Y = arcs.Point.Y/ shapDataContext.ShapScaleRate });
|
|
ps1.Add(new Point() { X = shapDataContext.Arc.Center.X / shapDataContext.ShapScaleRate, Y = shapDataContext.Arc.Center.Y/ shapDataContext.ShapScaleRate });
|
|
|
|
shapDataContext.OringLocation = ps1;
|
|
|
|
|
|
}
|
|
|
|
public override FrameworkElement DirectionShap(Point dirPoint)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void DrawDxfBlocks(DxfDocument dxf, Layer layer)
|
|
{
|
|
Path path = shapeitem as Path;
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
|
|
//List<Point> ps= shapeitem.Tag as List<Point>;
|
|
|
|
//Point arcStartPt = figure.StartPoint;
|
|
//Point arcEndPt = arcs.Point;
|
|
//Point centerPoint = ps[2];
|
|
|
|
//double startAngleInRadian = Math.Acos((arcStartPt.X - centerPoint.X) / arcs.Size.Width );
|
|
//double StartAngle = startAngleInRadian * 180 / Math.PI; //起始角度
|
|
//double endAngleInRadian = Math.Asin((arcEndPt.Y - centerPoint.Y ) / arcs.Size.Width );
|
|
//double EndAngle = endAngleInRadian * 180 / Math.PI; //结束角度
|
|
|
|
|
|
//Vector3 center = new Vector3(centerPoint.X, centerPoint.Y, 0);
|
|
//double radius = arcs.Size.Width * m_ScaleRale;
|
|
//netDxf.Entities.Arc arc = new netDxf.Entities.Arc(center, radius, StartAngle, EndAngle);
|
|
|
|
ShapDataContext shapDataContext = shapeitem.DataContext as ShapDataContext;
|
|
netDxf.Entities.Arc arc = shapDataContext.Arc;
|
|
|
|
Vector3 center = new Vector3() { X = arc.Center.X * m_ScaleRale, Y = -arc.Center.Y * m_ScaleRale };
|
|
netDxf.Entities.Arc expArc = new netDxf.Entities.Arc(center, arc.Radius * m_ScaleRale, arc.StartAngle, arc.EndAngle) ;
|
|
|
|
expArc.Layer = layer;
|
|
dxf.AddEntity(expArc);
|
|
}
|
|
|
|
public override List<Point> GetPoints()
|
|
{
|
|
List<Point> points = new List<Point>();
|
|
|
|
Path path = shapeitem as Path;
|
|
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
|
|
points.Add(figure.StartPoint);
|
|
points.Add(arcs.Point);
|
|
|
|
return points;
|
|
}
|
|
|
|
public override void MoveBlock( Point currentPoint, System.Windows.Point dragPoint)
|
|
{
|
|
double moveX = currentPoint.X - dragPoint.X;
|
|
double moveY = currentPoint.Y - dragPoint.Y;
|
|
|
|
Path path = shapeitem as Path;
|
|
|
|
List<Point> ps = (List<Point>)shapeitem.Tag;
|
|
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
|
|
|
|
if ((shapeitem.DataContext as ShapDataContext).IsDirection)
|
|
{
|
|
moveX = -moveX;
|
|
}
|
|
|
|
figure.StartPoint = new Point() { X = ps[0].X + moveX, Y = ps[0].Y + moveY }; //起点
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
arcs.Point = new Point() { X = ps[1].X + moveX, Y = ps[1].Y + moveY }; //结束点
|
|
|
|
//计算dxf arc 原来的中心点,跟着移动坐标
|
|
ShapDataContext shapDataContext = shapeitem.DataContext as ShapDataContext;
|
|
netDxf.Entities.Arc arc = shapDataContext.Arc;
|
|
arc.Center = new Vector3() { X = ps[2].X + moveX, Y = ps[2].Y + moveY }; //中心点
|
|
}
|
|
|
|
public override void MoveByX(double x)
|
|
{
|
|
Path path = shapeitem as Path;
|
|
|
|
List<Point> ps = (List<Point>)shapeitem.Tag;
|
|
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
figure.StartPoint = new Point() { X = ps[0].X + x/m_ScaleRale, Y = figure.StartPoint.Y }; //起点
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
arcs.Point = new Point() { X = ps[1].X + x/m_ScaleRale, Y = arcs.Point.Y }; //结束点
|
|
|
|
//计算dxf arc 原来的中心点,跟着移动坐标
|
|
ShapDataContext shapDataContext = shapeitem.DataContext as ShapDataContext;
|
|
netDxf.Entities.Arc arc = shapDataContext.Arc;
|
|
arc.Center = new Vector3() { X = ps[2].X + x/m_ScaleRale, Y = arc.Center.Y };
|
|
}
|
|
|
|
public override void MoveByY(double y)
|
|
{
|
|
Path path = shapeitem as Path;
|
|
|
|
List<Point> ps = (List<Point>)shapeitem.Tag;
|
|
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
figure.StartPoint = new Point() { X = figure.StartPoint.X, Y = ps[0].Y - y/m_ScaleRale }; //起点
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
arcs.Point = new Point() { X = arcs.Point.X, Y = ps[1].Y -y/m_ScaleRale }; //结束点
|
|
|
|
//计算dxf arc 原来的中心点,跟着移动坐标
|
|
ShapDataContext shapDataContext = shapeitem.DataContext as ShapDataContext;
|
|
netDxf.Entities.Arc arc = shapDataContext.Arc;
|
|
arc.Center = new Vector3() { X = arc.Center.X, Y = ps[2].Y - y/m_ScaleRale };
|
|
}
|
|
|
|
public override void ScaleBlock(double rate)
|
|
{
|
|
|
|
Path path = shapeitem as Path;
|
|
List<Point> ps0 = (List<Point>)shapeitem.Tag;
|
|
|
|
(shapeitem.DataContext as ShapDataContext).ShapScaleRate = rate;
|
|
List<Point> ps = (List<Point>)(shapeitem.DataContext as ShapDataContext).OringLocation;
|
|
|
|
PathGeometry pathGeometry = path.Data as PathGeometry;
|
|
PathFigure figure = pathGeometry.Figures[0] as PathFigure;
|
|
Point StartPoint = new Point() { X = ps[0].X * rate, Y = ps[0].Y * rate };
|
|
figure.StartPoint = new Point() { X = ps[0].X * rate, Y = ps[0].Y * rate }; //起点
|
|
ArcSegment arcs = figure.Segments[0] as ArcSegment;
|
|
Point endPoint = new Point() { X = ps[1].X * rate, Y = ps[1].Y * rate };
|
|
arcs.Point = new Point() { X = ps[1].X * rate, Y = ps[1].Y * rate }; //结束点
|
|
|
|
//arcs.Size = new Size() { Width = arcs.Size.Width * rate, Height = arcs.Size.Height * rate };
|
|
|
|
|
|
|
|
|
|
//计算dxf arc 原来的中心点,跟着移动坐标
|
|
ShapDataContext shapDataContext = shapeitem.DataContext as ShapDataContext;
|
|
netDxf.Entities.Arc arc = shapDataContext.Arc;
|
|
arc.Center = new Vector3() { X = ps[2].X * rate, Y = ps[2].Y * rate }; //中心点
|
|
arc.Radius = arcs.Size.Width * rate;
|
|
|
|
|
|
ps0[0] = StartPoint;
|
|
ps0[1] = endPoint;
|
|
ps0[2] = new Point() { X = ps[2].X * rate, Y = ps[2].Y * rate };
|
|
}
|
|
}
|
|
}
|