134 lines
4.2 KiB
C#
134 lines
4.2 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 BlockPolyline : BaseShap
|
|
{
|
|
public BlockPolyline(FrameworkElement shap) : base(shap)
|
|
{
|
|
}
|
|
|
|
public override void CopyBlock()
|
|
{
|
|
Polyline line = shapeitem as Polyline;
|
|
line.Tag = line.Points; //存储当前图形坐标
|
|
|
|
ShapDataContext shapDataContext = line.DataContext as ShapDataContext;
|
|
|
|
PointCollection ps = new PointCollection();
|
|
foreach (var item in line.Points)
|
|
{
|
|
ps.Add(new Point() { X = item.X / shapDataContext.ShapScaleRate, Y = item.Y / shapDataContext.ShapScaleRate } );
|
|
}
|
|
shapDataContext.OringLocation = ps; //
|
|
|
|
}
|
|
|
|
public override FrameworkElement DirectionShap(Point dirPoint)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void DrawDxfBlocks(DxfDocument dxf, Layer layer)
|
|
{
|
|
Polyline line = shapeitem as Polyline;
|
|
bool isClosed = (line.DataContext as ShapDataContext).IsClosed;
|
|
|
|
netDxf.Entities.LwPolyline poly = new netDxf.Entities.LwPolyline() { IsClosed = isClosed };
|
|
|
|
foreach (var p in line.Points)
|
|
{
|
|
poly.Vertexes.Add(new netDxf.Entities.LwPolylineVertex(p.X * m_ScaleRale, -p.Y * m_ScaleRale));
|
|
}
|
|
poly.Layer = layer;
|
|
dxf.AddEntity(poly);
|
|
}
|
|
|
|
public override List<Point> GetPoints()
|
|
{
|
|
List<Point> points = new List<Point>();
|
|
Polyline line = shapeitem as Polyline;
|
|
foreach (var p in line.Points)
|
|
{
|
|
points.Add(p);
|
|
}
|
|
return points;
|
|
}
|
|
|
|
public override void MoveBlock(Point currentPoint, System.Windows.Point dragPoint)
|
|
{
|
|
double moveX = currentPoint.X - dragPoint.X;
|
|
double moveY = currentPoint.Y - dragPoint.Y;
|
|
|
|
Polyline line = shapeitem as Polyline;
|
|
PointCollection ptcol = new PointCollection();
|
|
PointCollection pt = line.Tag as PointCollection;
|
|
foreach (var p in pt)
|
|
{
|
|
if ((shapeitem.DataContext as ShapDataContext).IsDirection)
|
|
{
|
|
ptcol.Add(new Point() { X = p.X - moveX, Y = p.Y + moveY });
|
|
}
|
|
else
|
|
{
|
|
ptcol.Add(new Point() { X = p.X + moveX, Y = p.Y + moveY });
|
|
}
|
|
|
|
}
|
|
(shapeitem as Polyline).Points = ptcol;
|
|
|
|
}
|
|
|
|
public override void MoveByX(double x)
|
|
{
|
|
Polyline line = shapeitem as Polyline;
|
|
PointCollection ptcol = new PointCollection();
|
|
|
|
PointCollection pt = (line.DataContext as ShapDataContext).OringLocation as PointCollection;
|
|
|
|
//PointCollection pt = line.Points as PointCollection;
|
|
foreach (var p in pt)
|
|
{
|
|
ptcol.Add(new Point() { X = p.X + x/ m_ScaleRale, Y = p.Y });
|
|
}
|
|
(shapeitem as Polyline).Points = ptcol;
|
|
|
|
}
|
|
|
|
public override void MoveByY(double y)
|
|
{
|
|
Polyline line = shapeitem as Polyline;
|
|
PointCollection ptcol = new PointCollection();
|
|
PointCollection pt = line.Points as PointCollection;
|
|
foreach (var p in pt)
|
|
{
|
|
ptcol.Add(new Point() { X = p.X , Y = p.Y - y/ m_ScaleRale });
|
|
}
|
|
(shapeitem as Polyline).Points = ptcol;
|
|
}
|
|
|
|
public override void ScaleBlock(double rate)
|
|
{
|
|
|
|
(shapeitem.DataContext as ShapDataContext).ShapScaleRate = rate;
|
|
PointCollection ptcol = new PointCollection();
|
|
PointCollection pt = (shapeitem.DataContext as ShapDataContext).OringLocation as PointCollection;
|
|
foreach (var p in pt)
|
|
{
|
|
ptcol.Add(new Point() { X = p.X * rate, Y = p.Y * rate });
|
|
}
|
|
(shapeitem as Polyline).Points = ptcol;
|
|
}
|
|
}
|
|
}
|