|
@@ -18,6 +18,7 @@ using WpfLine = System.Windows.Shapes.Line;
|
|
|
using DxfLine = netDxf.Entities.Line;
|
|
using DxfLine = netDxf.Entities.Line;
|
|
|
using DxfLwPolyline = netDxf.Entities.Polyline2D;
|
|
using DxfLwPolyline = netDxf.Entities.Polyline2D;
|
|
|
using Microsoft.Win32;
|
|
using Microsoft.Win32;
|
|
|
|
|
+using System.Drawing;
|
|
|
|
|
|
|
|
namespace TeamAAS_VP.DxfModule
|
|
namespace TeamAAS_VP.DxfModule
|
|
|
{
|
|
{
|
|
@@ -37,6 +38,28 @@ namespace TeamAAS_VP.DxfModule
|
|
|
_dxfParser = new DxfParserService();
|
|
_dxfParser = new DxfParserService();
|
|
|
InitializeInteractionController();
|
|
InitializeInteractionController();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ #region 依赖属性-PointF集合
|
|
|
|
|
+ public static readonly DependencyProperty PointsProperty =
|
|
|
|
|
+ DependencyProperty.Register("Points", typeof(List<PointF>), typeof(DxfView),
|
|
|
|
|
+ new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnPointsChanged)));
|
|
|
|
|
+ public List<PointF> Points
|
|
|
|
|
+ {
|
|
|
|
|
+ get { return (List<PointF>)GetValue(PointsProperty); }
|
|
|
|
|
+ set { SetValue(PointsProperty, value); }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void OnPointsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
+ {
|
|
|
|
|
+ var view = d as DxfView;
|
|
|
|
|
+ if (view != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Handle points changed
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
private void InitializeInteractionController()
|
|
private void InitializeInteractionController()
|
|
|
{
|
|
{
|
|
|
_interactionController = new InteractionController(DrawingCanvas);
|
|
_interactionController = new InteractionController(DrawingCanvas);
|
|
@@ -179,6 +202,48 @@ namespace TeamAAS_VP.DxfModule
|
|
|
{
|
|
{
|
|
|
sb.AppendLine($"\n... 还有 {e.SelectedEntities.Count - 10} 个实体");
|
|
sb.AppendLine($"\n... 还有 {e.SelectedEntities.Count - 10} 个实体");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //如果选中的是圆,则输出圆心坐标,如果是直线,则输出中心点坐标,如果是矩形,则输出中心点坐标,如果是点,则输出点坐标,如果是圆弧,则输出中心点坐标
|
|
|
|
|
+ if (Points!=null)
|
|
|
|
|
+ {
|
|
|
|
|
+ Points = new List<PointF>();
|
|
|
|
|
+ }
|
|
|
|
|
+ Points.Clear();
|
|
|
|
|
+ foreach (var item in e.SelectedEntities)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (item is Circle circle)
|
|
|
|
|
+ {
|
|
|
|
|
+ Points.Add(new PointF((float)circle.Center.X, (float)circle.Center.Y));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (item is DxfLine line)
|
|
|
|
|
+ {
|
|
|
|
|
+ float centerX = (float)((line.StartPoint.X + line.EndPoint.X) / 2);
|
|
|
|
|
+ float centerY = (float)((line.StartPoint.Y + line.EndPoint.Y) / 2);
|
|
|
|
|
+ Points.Add(new PointF(centerX, centerY));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (item is DxfLwPolyline polyline && polyline.IsClosed)
|
|
|
|
|
+ {
|
|
|
|
|
+ //计算多边形中心点
|
|
|
|
|
+ float centerX = 0;
|
|
|
|
|
+ float centerY = 0;
|
|
|
|
|
+ foreach (var vertex in polyline.Vertexes)
|
|
|
|
|
+ {
|
|
|
|
|
+ centerX += (float)vertex.Position.X;
|
|
|
|
|
+ centerY += (float)vertex.Position.Y;
|
|
|
|
|
+ }
|
|
|
|
|
+ centerX /= polyline.Vertexes.Count;
|
|
|
|
|
+ centerY /= polyline.Vertexes.Count;
|
|
|
|
|
+ Points.Add(new PointF(centerX, centerY));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (item is netDxf.Entities.Point point)
|
|
|
|
|
+ {
|
|
|
|
|
+ Points.Add(new PointF((float)point.Position.X, (float)point.Position.Y));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (item is Arc arc)
|
|
|
|
|
+ {
|
|
|
|
|
+ Points.Add(new PointF((float)arc.Center.X, (float)arc.Center.Y));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -213,6 +278,7 @@ namespace TeamAAS_VP.DxfModule
|
|
|
|
|
|
|
|
private void BtnClearSelection_Click(object sender, RoutedEventArgs e)
|
|
private void BtnClearSelection_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
{
|
|
|
|
|
+ Points?.Clear();
|
|
|
_interactionController?.ClearSelection();
|
|
_interactionController?.ClearSelection();
|
|
|
}
|
|
}
|
|
|
|
|
|