2023-05-07 23:01:38 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Media3D;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DrawingDesignerItemViewModelBase : DesignerItemViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public DrawingDesignerItemViewModelBase() : this(null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DrawingDesignerItemViewModelBase(IDiagramViewModel root) : base(root)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, Point startPoint, bool erasable) : this(root, drawMode, new List<Point> { startPoint }, erasable)
|
|
|
|
|
|
{
|
2023-05-09 19:21:48 +08:00
|
|
|
|
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, List<Point> points, bool erasable) : base(root)
|
|
|
|
|
|
{
|
|
|
|
|
|
DrawMode = drawMode;
|
|
|
|
|
|
Points = points;
|
|
|
|
|
|
Erasable = erasable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsFinish)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateLocation();
|
|
|
|
|
|
|
|
|
|
|
|
Geometry.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
|
|
|
|
|
|
|
|
|
|
|
if (Erasable)
|
|
|
|
|
|
{
|
2023-05-09 19:21:48 +08:00
|
|
|
|
var aPen = new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth);
|
2023-05-07 23:01:38 +08:00
|
|
|
|
Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除,需要把Geometry转成几何图像,所以不能有填充色
|
|
|
|
|
|
}
|
2023-05-09 19:21:48 +08:00
|
|
|
|
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool Erase(Geometry erase)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Erasable)
|
|
|
|
|
|
{
|
|
|
|
|
|
erase.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
|
|
|
|
|
Geometry = Geometry.Combine(Geometry, erase, GeometryCombineMode.Exclude, null);
|
|
|
|
|
|
|
|
|
|
|
|
if (Geometry.IsEmpty())
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-05-09 19:21:48 +08:00
|
|
|
|
if (this.GetBounds().IntersectsWith(erase.Bounds))//相交
|
|
|
|
|
|
{
|
2023-05-07 23:01:38 +08:00
|
|
|
|
return true;
|
2023-05-09 19:21:48 +08:00
|
|
|
|
}
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Erasable
|
|
|
|
|
|
{
|
2023-05-09 19:21:48 +08:00
|
|
|
|
get; set;
|
2023-05-07 23:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Geometry _geometry;
|
|
|
|
|
|
public Geometry Geometry
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _geometry;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _geometry, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsFinish
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Point> _points;
|
|
|
|
|
|
public List<Point> Points
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _points;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _points, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public DrawMode DrawMode
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateLocation()
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemWidth = Geometry.Bounds.Width + ColorViewModel.LineWidth;
|
|
|
|
|
|
ItemHeight = Geometry.Bounds.Height + ColorViewModel.LineWidth;
|
|
|
|
|
|
Left = Geometry.Bounds.Left;
|
|
|
|
|
|
Top = Geometry.Bounds.Top;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Init(root, initNew);
|
|
|
|
|
|
IsHitTestVisible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void InitNew()
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearConnectors();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|