mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 08:10:50 +08:00
整理序列化
This commit is contained in:
@@ -8,8 +8,25 @@ using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class ConnectorInfoBase : BindableBase
|
||||
public abstract class ConnectorInfoBase : SelectableViewModelBase
|
||||
{
|
||||
public ConnectorInfoBase(ConnectorOrientation orientation)
|
||||
{
|
||||
this.Orientation = orientation;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
#region 属性
|
||||
public virtual PointBase Position
|
||||
{
|
||||
get;
|
||||
@@ -21,17 +38,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return new PointBase(Position.X + ConnectorWidth / 2, Position.Y + ConnectorHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectorInfoBase(ConnectorOrientation orientation)
|
||||
{
|
||||
this.Orientation = orientation;
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectorOrientation _orientation;
|
||||
public ConnectorOrientation Orientation
|
||||
@@ -72,19 +79,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
public IColorViewModel ColorViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double _connectorValue;
|
||||
public double ConnectorValue
|
||||
{
|
||||
@@ -97,5 +91,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SetProperty(ref _connectorValue, value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,43 +4,29 @@ using SvgPathProperties;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorLabelModel : ConnectorPoint, ISelectable
|
||||
public class ConnectorLabelModel : ConnectorPointModel, ISelectable
|
||||
{
|
||||
public ConnectorLabelModel(ConnectorViewModel parent, string content, double? distance = null, PointBase? offset = null)
|
||||
public ConnectorLabelModel(ConnectorViewModel connector, string content, double? distance = null, PointBase? offset = null)
|
||||
{
|
||||
Parent = parent;
|
||||
Parent = connector;
|
||||
Text = content;
|
||||
Distance = distance;
|
||||
Offset = offset ?? new PointBase();
|
||||
FontViewModel = Parent.FontViewModel;
|
||||
ColorViewModel = Parent.ColorViewModel;
|
||||
Offset = offset ?? new PointBase();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
DeleteLabelCommand = new SimpleCommand(DeleteLabel);
|
||||
}
|
||||
|
||||
public ConnectorViewModel Parent
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public bool IsHitTestVisible
|
||||
#region 属性
|
||||
public ConnectorViewModel Connector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent.IsHitTestVisible;
|
||||
}
|
||||
}
|
||||
|
||||
private string _text;
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return _text;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _text, value);
|
||||
return Parent as ConnectorViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +45,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
private bool _isSelected;
|
||||
public bool IsSelected
|
||||
//private bool _isSelected;
|
||||
public override bool IsSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -73,7 +59,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
//如果没有文字,失去焦点自动清除
|
||||
if (_isSelected == false && string.IsNullOrEmpty(Text))
|
||||
{
|
||||
Parent.Labels.Remove(this);
|
||||
Connector.Labels.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +70,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
private bool updating = false;
|
||||
|
||||
@@ -120,7 +107,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
length = totalLength * (Parent.Labels.IndexOf(this) + 1) / (Parent.Labels.Count + 1);
|
||||
length = totalLength * (Connector.Labels.IndexOf(this) + 1) / (Connector.Labels.Count + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,9 +140,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Offset += new VectorBase(0, newvalue - oldvalue);
|
||||
}
|
||||
|
||||
public void AddToSelection(bool selected)
|
||||
public override void AddToSelection(bool selected)
|
||||
{
|
||||
foreach (var item in Parent.Labels.ToList())
|
||||
foreach (var item in Connector.Labels.ToList())
|
||||
item.IsSelected = false;
|
||||
|
||||
if (selected == true)
|
||||
@@ -168,7 +155,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (parameter is ConnectorLabelModel label)
|
||||
{
|
||||
Parent.Labels.Remove(label);
|
||||
Connector.Labels.Remove(label);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,29 +8,35 @@ using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorPoint : BindableBase
|
||||
public class ConnectorPointModel : SelectableViewModelBase
|
||||
{
|
||||
public ConnectorPoint()
|
||||
public ConnectorPointModel()
|
||||
{
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public ConnectorPoint(PointBase point) : this()
|
||||
public ConnectorPointModel(PointBase point) : this()
|
||||
{
|
||||
X = point.X;
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
public ConnectorPoint(double x, double y) : this()
|
||||
public ConnectorPointModel(double x, double y) : this()
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中间X
|
||||
/// </summary>
|
||||
@@ -114,54 +120,28 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
set { connectorHeight = value; }
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
public IColorViewModel ColorViewModel
|
||||
public static ConnectorPointModel operator -(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
}
|
||||
return new ConnectorPointModel(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
public static ConnectorPointModel operator +(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
return new ConnectorPointModel(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
|
||||
private IFontViewModel _fontViewModel;
|
||||
public IFontViewModel FontViewModel
|
||||
public static implicit operator ConnectorPointModel(PointBase point)
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _fontViewModel, value);
|
||||
}
|
||||
return new ConnectorPointModel(point);
|
||||
}
|
||||
|
||||
public static ConnectorPoint operator -(ConnectorPoint a, ConnectorPoint b)
|
||||
{
|
||||
return new ConnectorPoint(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
public static ConnectorPoint operator +(ConnectorPoint a, ConnectorPoint b)
|
||||
{
|
||||
return new ConnectorPoint(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
|
||||
public static implicit operator ConnectorPoint(PointBase point)
|
||||
{
|
||||
return new ConnectorPoint(point);
|
||||
}
|
||||
|
||||
public static implicit operator PointBase(ConnectorPoint pointInfoBase)
|
||||
public static implicit operator PointBase(ConnectorPointModel pointInfoBase)
|
||||
{
|
||||
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
|
||||
}
|
||||
|
||||
public static List<ConnectorPoint> ToList(List<PointBase> lst)
|
||||
public static List<ConnectorPointModel> ToList(List<PointBase> lst)
|
||||
{
|
||||
return lst.Select(p => (ConnectorPoint)p).ToList();
|
||||
return lst.Select(p => (ConnectorPointModel)p).ToList();
|
||||
}
|
||||
|
||||
public override string ToString() => $"ConnectorPoint(x={X}, y={Y})";
|
||||
@@ -2,31 +2,45 @@
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorVertexModel : ConnectorPoint
|
||||
public class ConnectorVertexModel : ConnectorPointModel
|
||||
{
|
||||
public ConnectorVertexModel(ConnectorViewModel parent, PointBase? position = null)
|
||||
public ConnectorVertexModel(ConnectorViewModel connector, PointBase? position = null)
|
||||
{
|
||||
Parent = parent;
|
||||
Parent = connector;
|
||||
X = position?.X ?? 0;
|
||||
Y = position?.Y ?? 0;
|
||||
Y = position?.Y ?? 0;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
DeleteVertexCommand = new SimpleCommand(DeleteVertex);
|
||||
}
|
||||
|
||||
public ConnectorViewModel Parent
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
get;
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
}
|
||||
|
||||
public ConnectorViewModel Connector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as ConnectorViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(Parent.Area.Left + Left, Parent.Area.Top + Top);
|
||||
return new PointBase(Connector.Area.Left + Left, Connector.Area.Top + Top);
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase MiddlePosition => new PointBase(Parent.Area.Left + Left + ConnectorWidth / 2, Parent.Area.Top + Top + ConnectorHeight / 2);
|
||||
public override PointBase MiddlePosition => new PointBase(Connector.Area.Left + Left + ConnectorWidth / 2, Connector.Area.Top + Top + ConnectorHeight / 2);
|
||||
|
||||
public SimpleCommand DeleteVertexCommand
|
||||
{
|
||||
@@ -37,7 +51,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (parameter is ConnectorVertexModel vertice)
|
||||
{
|
||||
Parent.Vertices.Remove(vertice);
|
||||
Connector.Vertices.Remove(vertice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorViewModel : SelectableDesignerItemViewModelBase
|
||||
{
|
||||
public ConnectorViewModel(IDiagramViewModel parent, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode drawMode, RouterMode routerMode)
|
||||
public ConnectorViewModel(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode drawMode, RouterMode routerMode)
|
||||
{
|
||||
Parent = parent;
|
||||
Root = root;
|
||||
PathMode = drawMode.ToString();
|
||||
RouterMode = routerMode.ToString();
|
||||
Init(sourceConnectorInfo, sinkConnectorInfo);
|
||||
}
|
||||
|
||||
public ConnectorViewModel(IDiagramViewModel parent, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo, ConnectionItem designer) : base(parent, designer)
|
||||
public ConnectorViewModel(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo, ConnectionItem designer) : base(root, designer)
|
||||
{
|
||||
PathMode = designer.PathMode;
|
||||
RouterMode = designer.RouterMode;
|
||||
@@ -39,11 +39,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
protected virtual void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Parent = sourceConnectorInfo.DataItem.Parent;
|
||||
this.Root = sourceConnectorInfo.DataItem.Root;
|
||||
|
||||
if (Parent != null && Parent.ColorViewModel != null)
|
||||
if (Root != null && Root.ColorViewModel != null)
|
||||
{
|
||||
this.ColorViewModel = CopyHelper.Mapper(Parent.ColorViewModel);
|
||||
this.ColorViewModel = CopyHelper.Mapper(Root.ColorViewModel);
|
||||
}
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
{
|
||||
@@ -65,14 +65,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
AddLabelCommand = new SimpleCommand(AddLabel);
|
||||
}
|
||||
|
||||
protected void LoadDesignerItemViewModel(SelectableDesignerItemBase designerbase)
|
||||
protected void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||
{
|
||||
ConnectionItem designer = designerbase as ConnectionItem;
|
||||
Vertices = new ObservableCollection<ConnectorVertexModel>(designer.Vertices.Select(p => new ConnectorVertexModel(this, new PointBase(p.X, p.Y))));
|
||||
|
||||
}
|
||||
|
||||
public override SelectableDesignerItemBase ToXmlObject()
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
if (IsFullConnection)
|
||||
{
|
||||
@@ -92,6 +92,51 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
#region 属性
|
||||
private string _text;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public override string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
var text = _text;
|
||||
if (Labels?.Count > 0)
|
||||
{
|
||||
text = Labels[0].Text;
|
||||
}
|
||||
|
||||
if (FontViewModel.FontCase == FontCase.Upper)
|
||||
{
|
||||
return text?.ToUpper();
|
||||
}
|
||||
else if (FontViewModel.FontCase == FontCase.Lower)
|
||||
{
|
||||
return text?.ToLower();
|
||||
}
|
||||
else
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _text, value))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_text))
|
||||
{
|
||||
if (Labels?.Count > 0)
|
||||
{
|
||||
Labels[0].Text = _text;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddLabel(_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PointBase _sourceA;
|
||||
public PointBase SourceA
|
||||
{
|
||||
@@ -438,8 +483,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(ConnectorPoint.X):
|
||||
case nameof(ConnectorPoint.Y):
|
||||
case nameof(ConnectorPointModel.X):
|
||||
case nameof(ConnectorPointModel.Y):
|
||||
UpdatePathGeneratorResult();
|
||||
break;
|
||||
|
||||
@@ -449,7 +494,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(ConnectorPoint.X):
|
||||
case nameof(ConnectorPointModel.X):
|
||||
{
|
||||
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
|
||||
{
|
||||
@@ -457,7 +502,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
break;
|
||||
}
|
||||
case nameof(ConnectorPoint.Y):
|
||||
case nameof(ConnectorPointModel.Y):
|
||||
{
|
||||
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
|
||||
{
|
||||
@@ -479,13 +524,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (SourceConnectorInfo == null || SinkConnectorInfo == null)
|
||||
return;
|
||||
|
||||
var route = Router.Get(Parent, this);
|
||||
var route = Router.Get(Root, this);
|
||||
|
||||
(var source, var target) = FindConnectionPoints(route);
|
||||
if (source == null || target == null)
|
||||
return;
|
||||
|
||||
PathGeneratorResult = PathGenerator.Get(Parent, this, route, source.Value, target.Value);
|
||||
PathGeneratorResult = PathGenerator.Get(Root, this, route, source.Value, target.Value);
|
||||
|
||||
//修正旋转
|
||||
switch (SourceConnectorInfo.Orientation)
|
||||
@@ -560,9 +605,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void DeleteConnection(object args)
|
||||
{
|
||||
if (this.Parent is IDiagramViewModel)
|
||||
if (this.Root is IDiagramViewModel)
|
||||
{
|
||||
var diagramVM = this.Parent as IDiagramViewModel;
|
||||
var diagramVM = this.Root as IDiagramViewModel;
|
||||
diagramVM.RemoveItemCommand.Execute(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ShapeDefiner = Shapes.Rectangle;
|
||||
}
|
||||
|
||||
public DesignerItemViewModelBase(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
public DesignerItemViewModelBase(IDiagramViewModel root, DesignerItemBase designer) : base(root, designer)
|
||||
{
|
||||
ShapeDefiner = Shapes.Rectangle;
|
||||
}
|
||||
|
||||
public DesignerItemViewModelBase(IDiagramViewModel parent, string json) : base(parent, json)
|
||||
public DesignerItemViewModelBase(IDiagramViewModel root, string json) : base(root, json)
|
||||
{
|
||||
ShapeDefiner = Shapes.Rectangle;
|
||||
}
|
||||
@@ -35,9 +35,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
InitConnector();
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
DesignerItemBase designer = designerbase as DesignerItemBase;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.Icon = designer.Icon;
|
||||
}
|
||||
|
||||
public override SelectableDesignerItemBase ToXmlObject()
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return new DesignerItemBase(this);
|
||||
}
|
||||
@@ -382,41 +382,41 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (!(this is TextDesignerItemViewModel))
|
||||
{
|
||||
if (Parent.CellHorizontalAlignment == CellHorizontalAlignment.Center)
|
||||
if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Center)
|
||||
{
|
||||
if (Parent.GridCellSize.Width > this.ItemWidth)
|
||||
if (Root.GridCellSize.Width > this.ItemWidth)
|
||||
{
|
||||
this.Left = (int)(this.Left / Parent.GridCellSize.Width) * Parent.GridCellSize.Width + Parent.GridMargin + (Parent.GridCellSize.Width - this.ItemWidth) / 2;
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin + (Root.GridCellSize.Width - this.ItemWidth) / 2;
|
||||
}
|
||||
}
|
||||
else if (Parent.CellHorizontalAlignment == CellHorizontalAlignment.Left)
|
||||
else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Left)
|
||||
{
|
||||
this.Left = (int)(this.Left / Parent.GridCellSize.Width) * Parent.GridCellSize.Width + Parent.GridMargin;
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin;
|
||||
}
|
||||
else if (Parent.CellHorizontalAlignment == CellHorizontalAlignment.Right)
|
||||
else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Right)
|
||||
{
|
||||
if (Parent.GridCellSize.Width > this.ItemWidth)
|
||||
if (Root.GridCellSize.Width > this.ItemWidth)
|
||||
{
|
||||
this.Left = (int)(this.Left / Parent.GridCellSize.Width) * Parent.GridCellSize.Width + Parent.GridMargin + (Parent.GridCellSize.Width - this.ItemWidth);
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin + (Root.GridCellSize.Width - this.ItemWidth);
|
||||
}
|
||||
}
|
||||
|
||||
if (Parent.CellVerticalAlignment == CellVerticalAlignment.Center)
|
||||
if (Root.CellVerticalAlignment == CellVerticalAlignment.Center)
|
||||
{
|
||||
if (Parent.GridCellSize.Height > this.ItemHeight)
|
||||
if (Root.GridCellSize.Height > this.ItemHeight)
|
||||
{
|
||||
this.Top = (int)(this.Top / Parent.GridCellSize.Height) * Parent.GridCellSize.Height + Parent.GridMargin + (Parent.GridCellSize.Height - this.ItemHeight) / 2;
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin + (Root.GridCellSize.Height - this.ItemHeight) / 2;
|
||||
}
|
||||
}
|
||||
else if (Parent.CellVerticalAlignment == CellVerticalAlignment.Top)
|
||||
else if (Root.CellVerticalAlignment == CellVerticalAlignment.Top)
|
||||
{
|
||||
this.Top = (int)(this.Top / Parent.GridCellSize.Height) * Parent.GridCellSize.Height + Parent.GridMargin;
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin;
|
||||
}
|
||||
else if (Parent.CellVerticalAlignment == CellVerticalAlignment.Bottom)
|
||||
else if (Root.CellVerticalAlignment == CellVerticalAlignment.Bottom)
|
||||
{
|
||||
if (Parent.GridCellSize.Height > this.ItemHeight)
|
||||
if (Root.GridCellSize.Height > this.ItemHeight)
|
||||
{
|
||||
this.Top = (int)(this.Top / Parent.GridCellSize.Height) * Parent.GridCellSize.Height + Parent.GridMargin + (Parent.GridCellSize.Height - this.ItemHeight);
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin + (Root.GridCellSize.Height - this.ItemHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -743,7 +743,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void Add(SelectableDesignerItemViewModelBase item)
|
||||
{
|
||||
item.Parent = this;
|
||||
item.Root = this;
|
||||
item.ZIndex = Items.Count;
|
||||
if (item.Id == Guid.Empty)
|
||||
{
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
|
||||
public SelectableDesignerItemViewModelBase(IDiagramViewModel parent, SelectableDesignerItemBase designer):base(parent, designer)
|
||||
public SelectableDesignerItemViewModelBase(IDiagramViewModel root, SelectableItemBase designer):base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SelectableDesignerItemViewModelBase(IDiagramViewModel parent, string json) : base(parent, json)
|
||||
public SelectableDesignerItemViewModelBase(IDiagramViewModel root, string json) : base(root, json)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -134,7 +134,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (newselect)
|
||||
{
|
||||
foreach (var designerItemViewModelBase in Parent.SelectedItems.ToList())
|
||||
foreach (var designerItemViewModelBase in Root.SelectedItems.ToList())
|
||||
{
|
||||
designerItemViewModelBase._isSelected = false;
|
||||
}
|
||||
@@ -145,13 +145,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public override void AddToSelection(bool selected)
|
||||
{
|
||||
foreach (SelectableDesignerItemViewModelBase item in Parent.SelectedItems.ToList())
|
||||
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
|
||||
item.IsSelected = false;
|
||||
|
||||
Parent.SelectedItems.Clear();
|
||||
Root.SelectedItems.Clear();
|
||||
if (selected == true)
|
||||
{
|
||||
Parent.SelectionService.AddToSelection(this);
|
||||
Root.SelectionService.AddToSelection(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,21 +26,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
public SelectableViewModelBase(IDiagramViewModel parent, SelectableDesignerItemBase designer)
|
||||
public SelectableViewModelBase(IDiagramViewModel root, SelectableItemBase designer)
|
||||
{
|
||||
Init();
|
||||
LoadDesignerItemViewModel(parent, designer);
|
||||
LoadDesignerItemViewModel(root, designer);
|
||||
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
public SelectableViewModelBase(IDiagramViewModel parent, string json)
|
||||
public SelectableViewModelBase(IDiagramViewModel root, string json)
|
||||
{
|
||||
Init();
|
||||
LoadDesignerItemViewModel(parent, JsonConvert.DeserializeObject(json, ToXmlType()) as SelectableDesignerItemBase);
|
||||
LoadDesignerItemViewModel(root, JsonConvert.DeserializeObject(json, ToXmlType()) as SelectableItemBase);
|
||||
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
public virtual SelectableDesignerItemBase ToXmlObject()
|
||||
public virtual SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -72,9 +72,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
LockObjectViewModel = new LockObjectViewModel();
|
||||
}
|
||||
|
||||
protected virtual void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
protected virtual void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
this.Parent = parent;
|
||||
this.Root = root;
|
||||
|
||||
this.Id = designerbase.Id;
|
||||
this.ParentId = designerbase.ParentId;
|
||||
@@ -86,10 +86,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FontViewModel = CopyHelper.Mapper<FontViewModel, FontItem>(designerbase.FontItem);
|
||||
}
|
||||
|
||||
public IDiagramViewModel Parent
|
||||
public IDiagramViewModel Root
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public SelectableViewModelBase Parent
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public Guid Id
|
||||
{
|
||||
get; set;
|
||||
@@ -148,10 +154,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Parent?.IsReadOnly == true && Parent?.IsLoading == false)
|
||||
if (Root?.IsReadOnly == true && Root?.IsLoading == false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Parent?.IsReadOnly == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (LockObjectViewModel?.LockObject.FirstOrDefault(p => p.LockFlag == LockFlag.All)?.IsChecked == true)
|
||||
{
|
||||
return true;
|
||||
@@ -170,10 +182,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Parent?.IsHitTestVisible == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _isHitTestVisible;
|
||||
}
|
||||
set
|
||||
{
|
||||
{
|
||||
if (SetProperty(ref _isHitTestVisible, value))
|
||||
{
|
||||
RaisePropertyChanged("IsReadOnly");
|
||||
|
||||
Reference in New Issue
Block a user