添加节点可删除

This commit is contained in:
艾竹
2023-01-23 15:43:44 +08:00
parent bb2882c618
commit 2c76aacc66
13 changed files with 158 additions and 45 deletions

View File

@@ -14,6 +14,8 @@ namespace AIStudio.Wpf.DiagramDesigner
Offset = offset ?? new PointBase();
FontViewModel = Parent.FontViewModel;
ColorViewModel = Parent.ColorViewModel;
DeleteLabelCommand = new SimpleCommand(DeleteLabel);
}
public ConnectorViewModel Parent
@@ -78,16 +80,11 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public override PointBase Position
public SimpleCommand DeleteLabelCommand
{
get
{
return new PointBase(Parent.Area.Left + Left, Parent.Area.Top + Top);
}
get; set;
}
public override PointBase MiddlePosition => new PointBase(Parent.Area.Left + Left + ConnectorWidth / 2, Parent.Area.Top + Top + ConnectorHeight / 2);
private bool updating = false;
public void UpdatePosition(SvgPath[] paths)
@@ -167,5 +164,13 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private void DeleteLabel(object parameter)
{
if (parameter is ConnectorLabelModel label)
{
Parent.Labels.Remove(label);
}
}
}
}

View File

@@ -9,6 +9,8 @@ namespace AIStudio.Wpf.DiagramDesigner
Parent = parent;
X = position?.X ?? 0;
Y = position?.Y ?? 0;
DeleteVertexCommand = new SimpleCommand(DeleteVertex);
}
public ConnectorViewModel Parent
@@ -26,5 +28,18 @@ namespace AIStudio.Wpf.DiagramDesigner
public override PointBase MiddlePosition => new PointBase(Parent.Area.Left + Left + ConnectorWidth / 2, Parent.Area.Top + Top + ConnectorHeight / 2);
public SimpleCommand DeleteVertexCommand
{
get; set;
}
private void DeleteVertex(object parameter)
{
if (parameter is ConnectorVertexModel vertice)
{
Parent.Vertices.Remove(vertice);
}
}
}
}

View File

@@ -61,7 +61,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.SinkConnectorInfo = sinkConnectorInfo;
DeleteConnectionCommand = new SimpleCommand(DeleteConnection);
AddVertexCommand = new SimpleCommand(AddVertex);
AddTextCommand = new SimpleCommand(AddText);
AddLabelCommand = new SimpleCommand(AddLabel);
}
protected void LoadDesignerItemViewModel(SelectableDesignerItemBase designerbase)
@@ -339,7 +339,7 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set;
}
public SimpleCommand AddTextCommand
public SimpleCommand AddLabelCommand
{
get; set;
}
@@ -643,10 +643,10 @@ namespace AIStudio.Wpf.DiagramDesigner
protected override void ExecuteEditCommand(object param)
{
AddText();
AddLabel();
}
public void AddText(object text = null)
public void AddLabel(object text = null)
{
var label = new ConnectorLabelModel(this, text?.ToString());
label.PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
@@ -656,6 +656,8 @@ namespace AIStudio.Wpf.DiagramDesigner
var paths = Labels.Count > 0 ? PathGeneratorResult.Paths.Select(p => new SvgPath(p)).ToArray() : Array.Empty<SvgPath>();
label.UpdatePosition(paths);
}
#endregion
}
}

View File

@@ -69,6 +69,7 @@ namespace AIStudio.Wpf.DiagramDesigner
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right));
}
#region
public FullyCreatedConnectorInfo TopConnector
{
get { return (connectors != null && connectors.Count >= 1) ? connectors[0] : null; }
@@ -89,6 +90,11 @@ namespace AIStudio.Wpf.DiagramDesigner
get { return (connectors != null && connectors.Count >= 4) ? connectors[3] : null; }
}
public Style ConnectorStyle
{
get; set;
}
public ShapeDefiner ShapeDefiner
{
get;
@@ -348,6 +354,9 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
#endregion
#region
public void AddConnector(FullyCreatedConnectorInfo connector)
{
if (!connectors.Contains(connector))
@@ -449,5 +458,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
public IShape GetShape() => ShapeDefiner(this);
#endregion
}
}

View File

@@ -136,6 +136,19 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private Style _style;
public Style Style
{
get
{
return _style;
}
set
{
SetProperty(ref _style, value);
}
}
public SimpleCommand DeleteCommand
{
get; private set;