2023-05-07 23:01:38 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
2023-05-10 22:46:39 +08:00
|
|
|
|
using System.Windows.Documents;
|
2023-05-07 23:01:38 +08:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
2023-05-14 00:31:25 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
2023-05-07 23:01:38 +08:00
|
|
|
|
using SvgPathProperties;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
public class EraserDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public EraserDrawingDesignerItemViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-31 22:50:19 +08:00
|
|
|
|
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, ColorViewModel colorViewModel) : base(root, DrawMode.Eraser, startPoint, colorViewModel, true)
|
2023-05-07 23:01:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-31 22:50:19 +08:00
|
|
|
|
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, DrawMode drawMode, ColorViewModel colorViewModel, bool erasable) : base(root, drawMode, null, colorViewModel, erasable)
|
2023-05-14 23:26:08 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-14 00:31:25 +08:00
|
|
|
|
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
2023-05-07 23:01:38 +08:00
|
|
|
|
{
|
2023-05-14 00:31:25 +08:00
|
|
|
|
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-14 00:31:25 +08:00
|
|
|
|
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
2023-05-07 23:01:38 +08:00
|
|
|
|
{
|
2023-05-14 00:31:25 +08:00
|
|
|
|
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
2023-05-10 22:46:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
2023-05-07 23:01:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
var point = e.GetPosition(sender);
|
|
|
|
|
|
if (Points == null || Points.Count == 0)//没有起始点
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-05-09 19:21:48 +08:00
|
|
|
|
|
|
|
|
|
|
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
2023-05-07 23:01:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-05-09 19:21:48 +08:00
|
|
|
|
|
2023-05-10 22:46:39 +08:00
|
|
|
|
var geometry = new PathGeometry();
|
|
|
|
|
|
var figure = new PathFigure { IsClosed = true, IsFilled = true };
|
|
|
|
|
|
geometry.Figures.Add(figure);
|
2023-05-09 19:21:48 +08:00
|
|
|
|
|
2023-05-10 22:46:39 +08:00
|
|
|
|
var radius = ColorViewModel.LineWidth / 2;
|
|
|
|
|
|
var positiveX = radius * (point.X > Points[0].X ? 1 : -1);
|
|
|
|
|
|
var positiveY = radius * (point.Y > Points[0].Y ? 1 : -1);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
|
2023-05-10 22:46:39 +08:00
|
|
|
|
figure.StartPoint = new Point(Points[0].X - positiveX, Points[0].Y - positiveY);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
|
2023-05-10 22:46:39 +08:00
|
|
|
|
var line = new LineSegment(new Point(Points[0].X + positiveX, Points[0].Y - positiveY), false);
|
|
|
|
|
|
figure.Segments.Add(line);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
|
2023-05-10 22:46:39 +08:00
|
|
|
|
line = new LineSegment(new Point(point.X + positiveX, point.Y - positiveY), false);
|
|
|
|
|
|
figure.Segments.Add(line);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
|
2023-05-10 22:46:39 +08:00
|
|
|
|
line = new LineSegment(new Point(point.X + positiveX, point.Y + positiveY), false);
|
|
|
|
|
|
figure.Segments.Add(line);
|
|
|
|
|
|
|
|
|
|
|
|
line = new LineSegment(new Point(point.X - positiveX, point.Y + positiveY), false);
|
|
|
|
|
|
figure.Segments.Add(line);
|
|
|
|
|
|
|
|
|
|
|
|
line = new LineSegment(new Point(Points[0].X - positiveX, Points[0].Y + positiveY), false);
|
|
|
|
|
|
figure.Segments.Add(line);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
|
|
|
|
|
|
Geometry = geometry;
|
2023-05-09 19:21:48 +08:00
|
|
|
|
Points[0] = point;
|
|
|
|
|
|
Erase(Geometry);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-05-10 22:46:39 +08:00
|
|
|
|
|
2023-05-07 23:01:38 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
return base.OnMouseUp(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private new bool Erase(Geometry geometry)
|
|
|
|
|
|
{
|
|
|
|
|
|
var empty = true;
|
|
|
|
|
|
List<DrawingDesignerItemViewModelBase> deleteDrawGeometries = new List<DrawingDesignerItemViewModelBase>();
|
|
|
|
|
|
foreach (var g in this.Root.Items.OfType<DrawingDesignerItemViewModelBase>())
|
|
|
|
|
|
{
|
2023-05-10 22:46:39 +08:00
|
|
|
|
if (g.Erase(geometry.CloneCurrentValue()))
|
2023-05-07 23:01:38 +08:00
|
|
|
|
deleteDrawGeometries.Add(g);
|
|
|
|
|
|
else
|
|
|
|
|
|
empty = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var g in deleteDrawGeometries)
|
|
|
|
|
|
{
|
2023-05-21 22:06:59 +08:00
|
|
|
|
this.Root.Delete(g);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|