mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
添加block快,不需要连接线,直接吸附。
This commit is contained in:
@@ -231,9 +231,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public DesignerCanvas()
|
||||
{
|
||||
this.Focusable = true;
|
||||
Mediator.Instance.Register(this);
|
||||
|
||||
_service.PropertyChanged += _service_PropertyChanged;
|
||||
this.Loaded += DesignerCanvas_Loaded;
|
||||
this.IsVisibleChanged += DesignerCanvas_IsVisibleChanged;
|
||||
}
|
||||
@@ -248,7 +246,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void DesignerCanvas_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Mediator.Instance.Register(this);
|
||||
this.Focus();
|
||||
_service.PropertyChanged += _service_PropertyChanged;
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
@@ -394,16 +394,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
_viewModel.ClearSelectedItems();
|
||||
|
||||
}
|
||||
|
||||
if (_service.DrawModeViewModel.LineDrawModeSelected)//画线模式,可以不命中实体
|
||||
{
|
||||
if (SourceConnector == null)
|
||||
{
|
||||
//新建一个Part连接点
|
||||
SourceConnector = new Connector() { Content = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y), Tag = "虚拟的连接点" };
|
||||
}
|
||||
}
|
||||
else if (_service.DrawModeViewModel.SharpDrawModeSelected ||
|
||||
|
||||
if (_service.DrawModeViewModel.SharpDrawModeSelected ||
|
||||
(_service.DrawModeViewModel.DrawingDrawModeSelected && _service.DrawModeViewModel.DrawingDrawMode != DrawMode.Select))
|
||||
{
|
||||
// create rubberband adorner
|
||||
@@ -417,7 +409,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (_service.DrawModeViewModel.LineDrawModeSelected)//画线模式,可以不命中实体
|
||||
{
|
||||
if (SourceConnector == null)
|
||||
{
|
||||
//新建一个Part连接点
|
||||
SourceConnector = new Connector() { Content = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y), Tag = "虚拟的连接点" };
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -511,8 +510,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
ConnectorInfoBase sinkDataItem = SinkConnector.Info;
|
||||
|
||||
_viewModel.Remove(partialConnection);
|
||||
_viewModel.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, LineDrawMode, RouterMode));
|
||||
_viewModel.Delete(partialConnection);
|
||||
_viewModel.AddCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, LineDrawMode, RouterMode));
|
||||
}
|
||||
else if (partialConnection.IsFullConnection)//自动连接模式
|
||||
{
|
||||
@@ -523,13 +522,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Point currentPoint = e.GetPosition(this);
|
||||
ConnectorInfoBase sinkDataItem = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
|
||||
_viewModel.Remove(partialConnection);
|
||||
_viewModel.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, LineDrawMode, RouterMode));
|
||||
_viewModel.Delete(partialConnection);
|
||||
_viewModel.AddCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, LineDrawMode, RouterMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
//Need to remove last item as we did not finish drawing the path
|
||||
_viewModel.Remove(partialConnection);
|
||||
_viewModel.Delete(partialConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,7 +634,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
item.Left += position.X - itemswidth / 2;
|
||||
item.Top += position.Y - itemsheight / 2;
|
||||
}
|
||||
_viewModel.AddItemCommand.Execute(designerItems);
|
||||
_viewModel.AddCommand.Execute(designerItems);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -657,7 +656,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
_viewModel.AddCommand.Execute(itemBase);
|
||||
}
|
||||
}
|
||||
var dragFile = e.Data.GetData(DataFormats.FileDrop);
|
||||
@@ -675,7 +674,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
_viewModel.AddCommand.Execute(itemBase);
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
|
||||
@@ -96,9 +96,53 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
item.SetCellAlignment();
|
||||
}
|
||||
|
||||
var blocks = designerItems.OfType<BlockDesignerItemViewModel>().ToList();
|
||||
if (blocks.Any())
|
||||
{
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
{
|
||||
var portTuple = DiagramViewModel.FindNearPortToAttachTo(item, true);
|
||||
var portParent = portTuple.Item1;
|
||||
var portNext = portTuple.Item2;
|
||||
|
||||
if (portParent != null)
|
||||
{
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item);
|
||||
portParent.BeAttachTo = false;
|
||||
portParent.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Parent != null)
|
||||
{
|
||||
(item.Parent as BlockDesignerItemViewModel).Next = null;
|
||||
item.Parent = null;
|
||||
item.ParentId = new Guid();
|
||||
}
|
||||
}
|
||||
|
||||
if (portNext != null)
|
||||
{
|
||||
item.AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
portNext.BeAttachTo = false;
|
||||
portNext.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Next != null)
|
||||
{
|
||||
item.Next.Parent = null;
|
||||
item.Next.ParentId = new Guid();
|
||||
item.Next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//-DiagramViewModel.ClearNearPort();
|
||||
}
|
||||
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<PointBase, PointBase>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<PointBase, PointBase>(p.GetOldValue<PointBase>(nameof(p.TopLeft)), p.TopLeft));
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<PointBase, PointBase>(p.GetOldValue<PointBase>(nameof(p.TopLeft)), p.TopLeft));
|
||||
|
||||
//部分连接点可以移动
|
||||
Dictionary<ConnectionViewModel, Tuple<Tuple<PointBase?, PointBase?>, Tuple<PointBase?, PointBase?>>> conncetorinfos =
|
||||
@@ -162,6 +206,15 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
item.SetPartPostion(sourcePoint, sinkPoint);
|
||||
}
|
||||
|
||||
var blocks = designerItems.OfType<BlockDesignerItemViewModel>().ToList();
|
||||
if (blocks.Any())
|
||||
{
|
||||
DiagramViewModel.ClearNearPort();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
{
|
||||
DiagramViewModel.FindNearPortToAttachTo(item, false);
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user