146 lines
5.0 KiB
C#
146 lines
5.0 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.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;
|
|
|
|
|
|
}
|
|
}
|
|
}
|