Files
MetroGauges-Old/MetroGauges/Controls/BlockShaps/BlockLine.cs

107 lines
3.5 KiB
C#
Raw Normal View History

2026-02-23 17:02:55 +08:00
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;
}
}
}