mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-09 18:56:35 +08:00
整理序列化
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user