Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorInfoBase.cs

180 lines
4.6 KiB
C#
Raw Normal View History

2021-07-23 09:42:22 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
2023-01-12 23:02:53 +08:00
using AIStudio.Wpf.DiagramDesigner.Geometrys;
2023-01-25 11:11:27 +08:00
using AIStudio.Wpf.DiagramDesigner.Models;
2021-07-23 09:42:22 +08:00
2022-10-28 22:45:39 +08:00
namespace AIStudio.Wpf.DiagramDesigner
2021-07-23 09:42:22 +08:00
{
2023-06-28 12:06:58 +08:00
public abstract class ConnectorInfoBase : SelectableViewModelBase, IAttachTo
2021-07-23 09:42:22 +08:00
{
2024-11-24 21:46:31 +08:00
2023-01-27 14:54:03 +08:00
public ConnectorInfoBase(ConnectorOrientation orientation) : this(null, orientation)
{
}
public ConnectorInfoBase(IDiagramViewModel root, ConnectorOrientation orientation) : base(root)
2023-01-24 16:20:39 +08:00
{
this.Orientation = orientation;
}
2023-01-24 17:53:04 +08:00
public ConnectorInfoBase(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
{
}
2023-01-25 11:11:27 +08:00
public ConnectorInfoBase(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
2023-01-24 17:53:04 +08:00
{
}
2023-01-25 11:11:27 +08:00
public override SelectableItemBase GetSerializableObject()
{
return new ConnectorInfoItemBase(this);
}
2024-02-18 16:40:33 +08:00
public override void Init(IDiagramViewModel root, bool initNew)
2023-03-25 11:59:31 +08:00
{
base.Init(root, initNew);
}
protected override void InitNew()
2023-01-24 16:20:39 +08:00
{
ColorViewModel = new ColorViewModel()
{
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
FillColor = new ColorObject() { Color = Colors.Lavender },
};
}
2023-01-27 14:54:03 +08:00
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
2023-01-24 17:53:04 +08:00
{
2023-01-27 14:54:03 +08:00
base.LoadDesignerItemViewModel(designerbase);
2023-01-24 17:53:04 +08:00
if (designerbase is ConnectorInfoItemBase designer)
{
2023-02-11 22:20:24 +08:00
PhysicalConnectorWidth = designer.PhysicalConnectorWidth;
PhysicalConnectorHeight = designer.PhysicalConnectorHeight;
2023-01-24 17:53:04 +08:00
Orientation = designer.Orientation;
}
}
2023-01-24 16:20:39 +08:00
#region
2023-01-15 20:27:39 +08:00
public virtual PointBase Position
2023-01-08 09:22:37 +08:00
{
2023-05-03 09:59:46 +08:00
get;set;
2023-01-15 20:27:39 +08:00
}
public virtual PointBase MiddlePosition
{
get
{
return new PointBase(Position.X + ConnectorWidth / 2, Position.Y + ConnectorHeight / 2);
}
2023-01-24 16:20:39 +08:00
}
2021-07-23 09:42:22 +08:00
private ConnectorOrientation _orientation;
public ConnectorOrientation Orientation
{
2023-01-08 09:22:37 +08:00
get
{
return _orientation;
}
2021-07-23 09:42:22 +08:00
set
{
SetProperty(ref _orientation, value);
}
}
2023-02-11 22:20:24 +08:00
private double _connectorWidth = 8;
2021-07-23 09:42:22 +08:00
public double ConnectorWidth
{
2023-01-08 09:22:37 +08:00
get
{
2023-02-11 22:20:24 +08:00
return _connectorWidth;
2023-01-08 09:22:37 +08:00
}
set
{
2023-02-11 22:20:24 +08:00
if (SetProperty(ref _connectorWidth, value))
{
RaisePropertyChanged(nameof(PhysicalConnectorWidth));
}
2023-01-08 09:22:37 +08:00
}
2021-07-23 09:42:22 +08:00
}
2023-02-11 22:20:24 +08:00
private double _connectorHeight = 8;
2021-07-23 09:42:22 +08:00
public double ConnectorHeight
{
2023-01-08 09:22:37 +08:00
get
{
2023-02-11 22:20:24 +08:00
return _connectorHeight;
2023-01-08 09:22:37 +08:00
}
set
{
2023-02-11 22:20:24 +08:00
if (SetProperty(ref _connectorHeight, value))
{
RaisePropertyChanged(nameof(PhysicalConnectorHeight));
}
2023-01-08 09:22:37 +08:00
}
2021-07-23 09:42:22 +08:00
}
2023-02-11 22:20:24 +08:00
public double PhysicalConnectorWidth
2021-07-23 09:42:22 +08:00
{
get
{
2023-02-11 23:51:48 +08:00
return ScreenHelper.WidthToMm(ConnectorWidth);
2021-07-23 09:42:22 +08:00
}
set
{
2023-02-11 23:51:48 +08:00
ConnectorWidth = ScreenHelper.MmToWidth(value);
2021-07-23 09:42:22 +08:00
}
2023-01-08 09:22:37 +08:00
}
2023-02-11 22:20:24 +08:00
public double PhysicalConnectorHeight
{
get
{
2023-02-11 23:51:48 +08:00
return ScreenHelper.WidthToMm(ConnectorHeight);
2023-02-11 22:20:24 +08:00
}
set
{
2023-02-11 23:51:48 +08:00
ConnectorHeight = ScreenHelper.MmToWidth(value);
2023-02-11 22:20:24 +08:00
}
}
private bool _beAttachTo;
public bool BeAttachTo
{
get
{
return _beAttachTo;
}
set
{
SetProperty(ref _beAttachTo, value);
}
}
2023-05-03 18:35:01 +08:00
private bool _disableAttachTo;
public bool DisableAttachTo
{
get
{
return _disableAttachTo;
}
set
{
SetProperty(ref _disableAttachTo, value);
}
}
public virtual bool CanAttachTo(ConnectorInfoBase port)
2023-05-03 18:35:01 +08:00
=> port != null && port != this && !port.IsReadOnly;
2023-01-24 16:20:39 +08:00
#endregion
2021-07-23 09:42:22 +08:00
}
}