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