mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
117 lines
3.2 KiB
C#
117 lines
3.2 KiB
C#
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.Shapes;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public class ShapeDesignerItemViewModel : DesignerItemViewModelBase
|
|
{
|
|
public ShapeDesignerItemViewModel() : this(null)
|
|
{
|
|
|
|
}
|
|
|
|
public ShapeDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public ShapeDesignerItemViewModel(DrawMode drawMode, List<Point> points) : this(null, drawMode, points)
|
|
{
|
|
}
|
|
|
|
public ShapeDesignerItemViewModel(IDiagramViewModel root, DrawMode drawMode, List<Point> points) : base(root)
|
|
{
|
|
DrawMode = drawMode;
|
|
ConnectionPoints = points;
|
|
|
|
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
|
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
|
Left = ConnectionPoints.Min(p => p.X);
|
|
Top = ConnectionPoints.Min(p => p.Y);
|
|
}
|
|
|
|
private List<Point> _connectionPoints;
|
|
public List<Point> ConnectionPoints
|
|
{
|
|
get
|
|
{
|
|
return _connectionPoints;
|
|
}
|
|
private set
|
|
{
|
|
SetProperty(ref _connectionPoints, value);
|
|
}
|
|
}
|
|
public DrawMode DrawMode
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
private bool _showConnectors = false;
|
|
public new bool ShowConnectors
|
|
{
|
|
get
|
|
{
|
|
return _showConnectors;
|
|
}
|
|
set
|
|
{
|
|
if (SetProperty(ref _showConnectors, value))
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public ICommand MenuItemCommand
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
private void UpdatePoints()
|
|
{
|
|
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
|
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
|
Left = ConnectionPoints.Min(p => p.X);
|
|
Top = ConnectionPoints.Min(p => p.Y);
|
|
}
|
|
|
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
|
{
|
|
MenuItemCommand = new SimpleCommand(Command_Enable, ExecuteMenuItemCommand);
|
|
base.Init(root, initNew);
|
|
|
|
BuildMenuOptions();
|
|
}
|
|
|
|
protected override void InitNew()
|
|
{
|
|
this.ClearConnectors();
|
|
}
|
|
|
|
private void ExecuteMenuItemCommand(object obj)
|
|
{
|
|
ShowConnectors = (obj as CinchMenuItem).IsChecked;
|
|
}
|
|
|
|
private void BuildMenuOptions()
|
|
{
|
|
menuOptions = new ObservableCollection<CinchMenuItem>();
|
|
CinchMenuItem menuItem = new CinchMenuItem();
|
|
menuItem.Text = "显示点";
|
|
menuItem.IsCheckable = true;
|
|
menuItem.Command = MenuItemCommand;
|
|
menuItem.CommandParameter = menuItem;
|
|
menuOptions.Add(menuItem);
|
|
}
|
|
}
|
|
}
|