添加项目文件。

This commit is contained in:
GG Z
2026-02-23 17:02:55 +08:00
parent a5a8cdf79e
commit 7609f67a2b
166 changed files with 353566 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Shapes;
namespace MetroGauges.Controls
{
public abstract class BaseShap
{
protected FrameworkElement shapeitem;
public double m_ScaleRale { get; set; }
public BaseShap(FrameworkElement shap)
{
shapeitem = shap;
}
public abstract List<Point> GetPoints();
public abstract void DrawDxfBlocks(netDxf.DxfDocument dxf, netDxf.Tables.Layer layer);
public abstract void CopyBlock();
public abstract void MoveBlock(System.Windows.Point currentPoint, System.Windows.Point dragPoint);
public abstract void MoveByX(double x);
public abstract void MoveByY(double y);
public abstract void ScaleBlock(double rate);
public abstract FrameworkElement DirectionShap(Point dirPoint);
}
}

View File

@@ -0,0 +1,201 @@
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 };
}
}
}

View File

@@ -0,0 +1,145 @@
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.BlockShaps
{
public class BlockEllipse : BaseShap
{
public BlockEllipse(FrameworkElement shap) : base(shap)
{
}
public override void CopyBlock()
{
Path path = shapeitem as Path;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
shapeitem.Tag = new Point() { X = ellipseGeometry.Center.X, Y = ellipseGeometry.Center.Y }; //存储当前图形坐标
ShapDataContext shapDataContext = shapeitem.DataContext as ShapDataContext;
EllipseGeometry geometry = new EllipseGeometry();
geometry.Center = new Point() { X = ellipseGeometry.Center.X/ shapDataContext.ShapScaleRate, Y = ellipseGeometry.Center.Y/ shapDataContext.ShapScaleRate };
geometry.RadiusX = ellipseGeometry.RadiusX / shapDataContext.ShapScaleRate;
geometry.RadiusY = ellipseGeometry.RadiusY / shapDataContext.ShapScaleRate;
shapDataContext.OringLocation = geometry;
}
public override FrameworkElement DirectionShap(Point dirPoint)
{
throw new NotImplementedException();
}
public override void DrawDxfBlocks(DxfDocument dxf, Layer layer)
{
Path path = shapeitem as Path;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
Vector3 center = new Vector3() { X = ellipseGeometry.Center.X * m_ScaleRale, Y = -ellipseGeometry.Center.Y * m_ScaleRale };
if (ellipseGeometry.RadiusX == ellipseGeometry.RadiusY) // 圆
{
netDxf.Entities.Circle circle = new netDxf.Entities.Circle(center, ellipseGeometry.RadiusX * m_ScaleRale);
circle.Layer = layer;
dxf.AddEntity(circle);
}
else //椭圆
{
netDxf.Entities.Ellipse ellipse = new netDxf.Entities.Ellipse(center, ellipseGeometry.RadiusX * m_ScaleRale, ellipseGeometry.RadiusY * m_ScaleRale);
//ellipse.Rotation = 30;
ellipse.Layer = layer;
dxf.AddEntity(ellipse);
}
}
public override List<Point> GetPoints()
{
List<Point> points = new List<Point>();
Path path = shapeitem as Path;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
Point point = new Point();
point.X = ellipseGeometry.Center.X - ellipseGeometry.RadiusX ;
point.Y = ellipseGeometry.Center.Y + ellipseGeometry.RadiusY ;
points.Add(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;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
Point p = (Point)shapeitem.Tag;
if ((shapeitem.DataContext as ShapDataContext).IsDirection)
{
moveX = -moveX;
}
Point center = new Point() { X = p.X + moveX, Y = p.Y + moveY };
ellipseGeometry.Center = center;
}
public override void MoveByX(double x)
{
Path path = shapeitem as Path;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
Point p = (Point)shapeitem.Tag;
Point center = new Point() { X = p.X + x/m_ScaleRale, Y = ellipseGeometry.Center.Y };
ellipseGeometry.Center = center;
}
public override void MoveByY(double y)
{
Path path = shapeitem as Path;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
Point p = (Point)shapeitem.Tag;
Point center = new Point() { X = ellipseGeometry.Center.X, Y = p.Y-y / m_ScaleRale };
ellipseGeometry.Center = center;
}
public override void ScaleBlock(double rate)
{
Path path = shapeitem as Path;
EllipseGeometry ellipseGeometry = path.Data as EllipseGeometry;
(shapeitem.DataContext as ShapDataContext).ShapScaleRate = rate;
EllipseGeometry ellipseGeometry1 = (shapeitem.DataContext as ShapDataContext).OringLocation as EllipseGeometry; //path.Data as EllipseGeometry;
Point p = ellipseGeometry1.Center;
Point center = new Point() { X = p.X * rate, Y = p.Y *rate };
ellipseGeometry.Center = center;
ellipseGeometry.RadiusX = ellipseGeometry1.RadiusX * rate;
ellipseGeometry.RadiusY = ellipseGeometry1.RadiusY * rate;
}
}
}

View File

@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Shapes;
using netDxf;
using netDxf.Tables;
namespace MetroGauges.Controls
{
public class BlockLine : BaseShap
{
public BlockLine(FrameworkElement shap) : base(shap)
{
}
public override void CopyBlock()
{
Line line = shapeitem as Line;
shapeitem.Tag = new Line() { X1 = line.X1, Y1 = line.Y1, X2 = line.X2, Y2 = line.Y2 }; //存储当前图形坐标
ShapDataContext shapDataContext = line.DataContext as ShapDataContext;
shapDataContext.OringLocation = new Line() { X1 = line.X1 / shapDataContext.ShapScaleRate, Y1 = line.Y1 / shapDataContext.ShapScaleRate, X2 = line.X2 / shapDataContext.ShapScaleRate, Y2 = line.Y2 / shapDataContext.ShapScaleRate } ;
}
public override FrameworkElement DirectionShap(Point dirPoint)
{
throw new NotImplementedException();
}
public override void DrawDxfBlocks(DxfDocument dxf, Layer layer)
{
Line line = shapeitem as Line;
netDxf.Entities.Line dline = new netDxf.Entities.Line(new Vector2(line.X1 * m_ScaleRale, -line.Y1 * m_ScaleRale), new Vector2(line.X2 * m_ScaleRale, -line.Y2 * m_ScaleRale));
dline.Layer = layer;
dxf.AddEntity(dline);
}
public override List<Point> GetPoints()
{
List<Point> points = new List<Point>();
Line line = shapeitem as Line;
points.Add(new Point() { X = line.X1, Y = line.Y1 });
points.Add(new Point() { X = line.X2, Y = line.Y2 });
return points;
}
public override void MoveBlock( Point currentPoint, System.Windows.Point dragPoint)
{
double moveX = currentPoint.X - dragPoint.X;
double moveY = currentPoint.Y - dragPoint.Y;
Line line = shapeitem.Tag as Line;
if ((shapeitem.DataContext as ShapDataContext).IsDirection)
{
(shapeitem as Line).X1 = line.X1 - moveX;
(shapeitem as Line).X2 = line.X2 - moveX;
}
else
{
(shapeitem as Line).X1 = line.X1 + moveX;
(shapeitem as Line).X2 = line.X2 + moveX;
}
(shapeitem as Line).Y1 = line.Y1 + moveY;
(shapeitem as Line).Y2 = line.Y2 + moveY;
}
public override void MoveByX(double x)
{
Line line = shapeitem.Tag as Line;
(shapeitem as Line).X1 = line.X1 + x/ m_ScaleRale;
(shapeitem as Line).X2 = line.X2 + x/ m_ScaleRale;
}
public override void MoveByY(double y)
{
Line line = shapeitem.Tag as Line;
(shapeitem as Line).Y1 = line.Y1 - y/ m_ScaleRale;
(shapeitem as Line).Y2 = line.Y2 - y/ m_ScaleRale;
}
public override void ScaleBlock(double rate)
{
(shapeitem.DataContext as ShapDataContext).ShapScaleRate = rate;
Line line = (shapeitem.DataContext as ShapDataContext).OringLocation as Line; //shapeitem.Tag as Line;
(shapeitem as Line).X1 = line.X1 * rate;
(shapeitem as Line).X2 = line.X2 * rate;
(shapeitem as Line).Y1 = line.Y1 * rate;
(shapeitem as Line).Y2 = line.Y2 * rate;
}
}
}

View File

@@ -0,0 +1,213 @@
using netDxf.Blocks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MetroGauges.Controls.BlockShaps
{
/// <summary>
/// 操作方法
/// </summary>
public enum OprType
{
DrawDxfBlocks,
ExportSourceBlock,//通过源bock插入
CopyBlock,
MoveBlock,
MoveByX,
MoveByY,
ScaleBlock
}
public class BlockOpr
{
public double ScaleRale { get; set; }
public netDxf.DxfDocument dxf { get; set; }
public BlockData BlockData { get; set; }
public netDxf.Tables.Layer layer { get; set; }
public System.Windows.Point currentPoint { get; set; }
public System.Windows.Point dragPoint { get; set; }
public double rate { get; set; }
private BaseShap GetBaseShap(FrameworkElement shapeitem)
{
BaseShap baseShap = null;
if (shapeitem is Line) //线段
{
baseShap = new BlockLine(shapeitem) { m_ScaleRale = this.ScaleRale };
}
else if (shapeitem is Polyline) //多义线
{
baseShap = new BlockPolyline(shapeitem) { m_ScaleRale = this.ScaleRale };
}
else if (shapeitem is Path) //
{
Path path = shapeitem as Path;
if (path.Data is EllipseGeometry) //圆
{
baseShap = new BlockEllipse(shapeitem) { m_ScaleRale = this.ScaleRale };
}
else if (path.Data is PathGeometry) //圆弧
{
baseShap = new BlockArc(shapeitem) { m_ScaleRale = this.ScaleRale };
}
}
else if (shapeitem is TextBlock)
{
baseShap = new BlockText(shapeitem) { m_ScaleRale = this.ScaleRale };
}
else if (shapeitem is Rectangle)
{
baseShap = new BlockRectangle(shapeitem) { m_ScaleRale = this.ScaleRale };
}
return baseShap;
}
/// <summary>
/// 执行方法
/// </summary>
/// <param name="block"></param>
/// <param name="oprType"></param>
public void ExctecOpr(List<FrameworkElement> block, OprType oprType)
{
if (oprType == OprType.ExportSourceBlock)
{
ExportBlock();
return;
}
foreach (var shapeitem in block)
{
BaseShap baseShap = GetBaseShap(shapeitem);
switch (oprType)
{
case OprType.CopyBlock:
baseShap.CopyBlock();
break;
case OprType.DrawDxfBlocks: //拆分导出
baseShap.DrawDxfBlocks(this.dxf, this.layer);
break;
case OprType.MoveBlock:
baseShap.MoveBlock(this.currentPoint, this.dragPoint);
break;
case OprType.MoveByX:
baseShap.MoveByX(this.currentPoint.X);
break;
case OprType.MoveByY:
baseShap.MoveByY(this.currentPoint.Y);
break;
case OprType.ScaleBlock:
baseShap.ScaleBlock(this.rate);
break;
}
}
}
/// <summary>
/// 插入块
/// </summary>
private void ExportBlock()
{
if (this.BlockData != null)
{
netDxf.DxfDocument dxf2 = netDxf.DxfDocument.Load(this.BlockData.FilePath);
double moveX = 0, moveY = 0;
string blockName = BlockData.BlockName.Split('_')[0];
Block block = dxf2.Blocks[blockName];
Block forBlock = BlockData.SourceBlock;
if (BlockData.IsDirection)
{
block = BlockData.ReverseBlock;
forBlock = BlockData.ReverseBlock;
}
//通过两个点计算块的偏移量
foreach (netDxf.Entities.EntityObject item in forBlock.Entities)
{
if (item.Type.ToString() == "Line")
{
Line line = item.DataContext as Line; //最终块图的某个点
netDxf.Entities.Line dataLine = item as netDxf.Entities.Line; //对应原始块的某个点
if (BlockData.IsDirection)
{
moveX = -line.X1 * ScaleRale - dataLine.StartPoint.X;
}
else
{
moveX = line.X1 * ScaleRale - dataLine.StartPoint.X;
}
moveY = line.Y1 * ScaleRale + dataLine.StartPoint.Y;
break;
}
}
netDxf.Entities.Insert insert = new netDxf.Entities.Insert(block, new netDxf.Vector3(moveX, -moveY, 0));
//netDxf.Entities.Insert insert2 = new netDxf.Entities.Insert(block, new netDxf.Vector3(0, 0, 0));
insert.Layer = new netDxf.Tables.Layer("block");
insert.Layer.Color.Index = 1;
dxf.AddEntity(insert);
}
}
/// <summary>
/// 获取块的所有坐标点
/// </summary>
/// <param name="block"></param>
/// <returns></returns>
public List<Point> GetBlockPoints(List<FrameworkElement> block,out Point minPont,out Point centerPoint)
{
List<Point> points = new List<Point>();
minPont = new Point() { X= double.MaxValue, Y=double.MinValue };
centerPoint = new Point() { X=double.MaxValue, Y= double.MaxValue };
foreach (var shapeitem in block)
{
BaseShap baseShap = GetBaseShap(shapeitem);
baseShap.m_ScaleRale = this.ScaleRale;
List<Point> ps = baseShap.GetPoints(); //获取图形外围框左下角坐标
foreach (var item in ps)
{
if (item.X < minPont.X)
{
minPont.X = item.X;
}
if (item.Y > minPont.Y)
{
minPont.Y = item.Y;
}
}
points.AddRange(ps);
}
return points;
}
}
}

View File

@@ -0,0 +1,133 @@
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;
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MetroGauges.Controls
{
/// <summary>
/// 块图形数据存储
/// </summary>
public class ShapDataContext
{
public object OringLocation { get; set; }
public netDxf.Entities.Arc Arc { get; set; }
public double ShapScaleRate { get; set; }
public bool IsClosed { get; set; }
public bool IsDirection { get; set; }
public ShapDataContext()
{
ShapScaleRate = 1;
}
}
}