mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
修复demo中彩色节点的bug
This commit is contained in:
@@ -41,36 +41,56 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private Point? rubberbandSelectionStartPoint = null;
|
||||
|
||||
private Connector sourceConnector;
|
||||
private Connector _sourceConnector;
|
||||
public Connector SourceConnector
|
||||
{
|
||||
get
|
||||
{
|
||||
return sourceConnector;
|
||||
return _sourceConnector;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (sourceConnector != value)
|
||||
if (_sourceConnector != value)
|
||||
{
|
||||
sourceConnector = value;
|
||||
_sourceConnector = value;
|
||||
if (_sourceConnector != null)
|
||||
{
|
||||
ConnectorInfoBase sourceDataItem = _sourceConnector.Info;
|
||||
|
||||
ConnectorInfoBase sourceDataItem = sourceConnector.Info;
|
||||
//Rect rectangleBounds = _sourceConnector.TransformToVisual(this).TransformBounds(new Rect(_sourceConnector.RenderSize));
|
||||
//Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
// rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
|
||||
//Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
|
||||
//Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
// rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
Point point = sourceDataItem.MiddlePosition;
|
||||
|
||||
Point point = sourceDataItem.MiddlePosition;
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(partialConnection);
|
||||
partialConnection.ZIndex = -1;
|
||||
_viewModel.Add(partialConnection);
|
||||
partialConnection.ZIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Connector sinkConnector;
|
||||
private Connector _sinkConnector;
|
||||
public Connector SinkConnector
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sinkConnector;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_sinkConnector != null)
|
||||
{
|
||||
_sinkConnector.Info.DisableAttachTo = false;
|
||||
}
|
||||
if (_sinkConnector != value)
|
||||
{
|
||||
_sinkConnector = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode DrawMode
|
||||
{
|
||||
@@ -406,7 +426,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
partialConnection.SinkConnectorInfo = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
sinkConnector = HitTesting(currentPoint);
|
||||
|
||||
SinkConnector = HitTesting(currentPoint);
|
||||
if (SinkConnector?.Info?.CanAttachTo(SourceConnector?.Info) == false)
|
||||
{
|
||||
SinkConnector.Info.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
if (EnableSnapping)
|
||||
{
|
||||
@@ -452,12 +477,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
Mediator.Instance.NotifyColleagues<bool>("DoneDrawingMessage", true);
|
||||
|
||||
if (sourceConnector != null)
|
||||
if (SourceConnector != null)
|
||||
{
|
||||
ConnectorInfoBase sourceDataItem = sourceConnector.Info;
|
||||
if (sinkConnector != null)
|
||||
ConnectorInfoBase sourceDataItem = SourceConnector.Info;
|
||||
if (SinkConnector != null && SinkConnector.Info?.DisableAttachTo == false)
|
||||
{
|
||||
ConnectorInfoBase sinkDataItem = sinkConnector.Info;
|
||||
ConnectorInfoBase sinkDataItem = SinkConnector.Info;
|
||||
|
||||
_viewModel.Remove(partialConnection);
|
||||
_viewModel.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode));
|
||||
@@ -481,8 +506,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
sourceConnector = null;
|
||||
sinkConnector = null;
|
||||
SourceConnector = null;
|
||||
SinkConnector = null;
|
||||
partialConnection = null;
|
||||
|
||||
if (_service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
|
||||
|
||||
@@ -40,6 +40,12 @@
|
||||
<Setter TargetName="innter" Property="Fill" Value="#f73438" />
|
||||
<Setter TargetName="innter" Property="Stroke" Value="#f73438" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DisableAttachTo}" Value="True">
|
||||
<Setter TargetName="outer" Property="Margin" Value="-6" />
|
||||
<Setter TargetName="outer" Property="Fill" Value="Gray" />
|
||||
<Setter TargetName="innter" Property="Fill" Value="Gray" />
|
||||
<Setter TargetName="innter" Property="Stroke" Value="Gray" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
|
||||
@@ -640,6 +640,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Verify()
|
||||
{
|
||||
return IsFullConnection == false || SourceConnectorInfo?.CanAttachTo(SinkConnectorInfo) == true;
|
||||
}
|
||||
|
||||
private void UpdateArea()
|
||||
{
|
||||
Area = new RectangleBase(SourceA, SourceB);
|
||||
|
||||
@@ -158,8 +158,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _disableAttachTo;
|
||||
public bool DisableAttachTo
|
||||
{
|
||||
get
|
||||
{
|
||||
return _disableAttachTo;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _disableAttachTo, value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool CanAttachTo(ConnectorInfoBase port)
|
||||
=> port != this && !port.IsReadOnly;
|
||||
=> port != null && port != this && !port.IsReadOnly;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1367,7 +1367,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public bool AddVerify(SelectableDesignerItemViewModelBase item)
|
||||
{
|
||||
if (item.InitData() == false)
|
||||
if (item.Verify() == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -1462,7 +1462,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Remove(olditems);
|
||||
},
|
||||
() => {
|
||||
Add(olditems);
|
||||
Add(olditems);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3298,9 +3298,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (SearchCaseMatch == true)
|
||||
{
|
||||
return input.Replace(searchtext, replcetext);
|
||||
return input.Replace(searchtext, replcetext);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return Regex.Replace(input, searchtext, replcetext, RegexOptions.IgnoreCase);
|
||||
}
|
||||
@@ -3362,22 +3362,38 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (connectorVertexType == ConnectorVertexType.Start)
|
||||
{
|
||||
if (partialConnection.SourceConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius &&
|
||||
partialConnection.SinkConnectorInfo?.CanAttachTo(port) == true)
|
||||
if (partialConnection.SourceConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
if (partialConnection.SinkConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.DisableAttachTo = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (connectorVertexType == ConnectorVertexType.End)
|
||||
{
|
||||
if (partialConnection.SinkConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius &&
|
||||
partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
if (partialConnection.SinkConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
if (partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.DisableAttachTo = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3393,12 +3409,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ClearNearPort();
|
||||
foreach (var port in Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (partialConnection.OnGoingPosition.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius &&
|
||||
partialConnection.SourceConnectorInfoFully?.CanAttachTo(port) == true)
|
||||
if (partialConnection.OnGoingPosition.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
if (partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3407,7 +3431,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void ClearNearPort()
|
||||
{
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true).ToList().ForEach(p => p.BeAttachTo = false);
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
}
|
||||
|
||||
public virtual bool InitData()
|
||||
public virtual bool Verify()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.ItemHeight = this.ImageHeight;
|
||||
}
|
||||
|
||||
public override bool InitData()
|
||||
public override bool Verify()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Icon))
|
||||
return EditData();
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
EditData();
|
||||
}
|
||||
|
||||
public override bool InitData()
|
||||
public override bool Verify()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Icon))
|
||||
return EditData();
|
||||
|
||||
Reference in New Issue
Block a user