mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-07 17:56:35 +08:00
Flowchart
This commit is contained in:
@@ -25,6 +25,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private Point? rubberbandSelectionStartPoint = null;
|
||||
|
||||
private DrawMode VectorLineDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_viewModel.VectorLineDrawMode != null)
|
||||
{
|
||||
return _viewModel.VectorLineDrawMode.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _service.DrawModeViewModel.VectorLineDrawMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region GridCellSize
|
||||
|
||||
public static readonly DependencyProperty GridCellSizeProperty =
|
||||
@@ -188,7 +203,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
|
||||
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
partialConnection = new ConnectorViewModel(sourceDataItem, new PartCreatedConnectionInfo(point), _service.DrawModeViewModel.VectorLineDrawMode);
|
||||
partialConnection = new ConnectorViewModel(sourceDataItem, new PartCreatedConnectionInfo(point), VectorLineDrawMode);
|
||||
_viewModel.DirectAddItemCommand.Execute(partialConnection);
|
||||
}
|
||||
}
|
||||
@@ -209,7 +224,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Rect rectangleBounds = new Rect(sourceConnectorInfo.DataItem.Left, sourceConnectorInfo.DataItem.Top, 3, 3);
|
||||
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
partialConnection = new ConnectorViewModel(sourceConnectorInfo, new PartCreatedConnectionInfo(point), _service.DrawModeViewModel.VectorLineDrawMode);
|
||||
partialConnection = new ConnectorViewModel(sourceConnectorInfo, new PartCreatedConnectionInfo(point), VectorLineDrawMode);
|
||||
_viewModel.DirectAddItemCommand.Execute(partialConnection);
|
||||
}
|
||||
}
|
||||
@@ -218,6 +233,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (_viewModel.IsReadOnly) return;
|
||||
|
||||
if (_service.DrawModeViewModel.CursorMode == CursorMode.Format)
|
||||
{
|
||||
@@ -271,6 +287,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
|
||||
if (_viewModel.IsReadOnly) return;
|
||||
|
||||
Point currentPoint = e.GetPosition(this);
|
||||
_viewModel.CurrentPoint = currentPoint;
|
||||
var point = CursorPointManager.GetCursorPosition();
|
||||
@@ -323,6 +341,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
|
||||
if (_viewModel.IsReadOnly) return;
|
||||
|
||||
if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
|
||||
{
|
||||
return;
|
||||
@@ -341,7 +361,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
int indexOfLastTempConnection = sinkDataItem.DataItem.Parent.Items.Count - 1;
|
||||
sinkDataItem.DataItem.Parent.DirectRemoveItemCommand.Execute(
|
||||
sinkDataItem.DataItem.Parent.Items[indexOfLastTempConnection]);
|
||||
sinkDataItem.DataItem.Parent.AddItemCommand.Execute(new ConnectorViewModel(sourceDataItem, sinkDataItem, _service.DrawModeViewModel.VectorLineDrawMode));
|
||||
sinkDataItem.DataItem.Parent.AddItemCommand.Execute(new ConnectorViewModel(sourceDataItem, sinkDataItem, VectorLineDrawMode));
|
||||
}
|
||||
else if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.ConnectingLine && connectorsHit.Count() == 1)
|
||||
{
|
||||
@@ -352,7 +372,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
_viewModel.DirectRemoveItemCommand.Execute(_viewModel.Items[indexOfLastTempConnection]);
|
||||
_viewModel.DirectAddItemCommand.Execute(pointItemView);
|
||||
|
||||
var connector = new ConnectorViewModel(sourceDataItem, sinkDataItem, _service.DrawModeViewModel.VectorLineDrawMode);
|
||||
var connector = new ConnectorViewModel(sourceDataItem, sinkDataItem, VectorLineDrawMode);
|
||||
_viewModel.AddItemCommand.Execute(connector);
|
||||
|
||||
sourceDataItem.DataItem.ZIndex++;
|
||||
@@ -380,6 +400,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.OnPreviewKeyDown(e);
|
||||
|
||||
if (_viewModel.IsReadOnly) return;
|
||||
|
||||
if (e.Key == Key.Left)
|
||||
{
|
||||
if (_viewModel.SelectedItems != null)
|
||||
@@ -472,6 +494,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected override void OnDrop(DragEventArgs e)
|
||||
{
|
||||
base.OnDrop(e);
|
||||
|
||||
if (_viewModel.IsReadOnly) return;
|
||||
|
||||
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
|
||||
if (dragObject != null)
|
||||
{
|
||||
@@ -480,17 +505,22 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
DesignerItemViewModelBase itemBase = null;
|
||||
if (dragObject.DesignerItem != null)
|
||||
{
|
||||
itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType, null, dragObject.DesignerItem);
|
||||
itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType, _viewModel, dragObject.DesignerItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType);
|
||||
itemBase.Icon = dragObject.Icon;
|
||||
itemBase.ColorViewModel = CopyHelper.Mapper(dragObject.ColorViewModel);
|
||||
if (dragObject.DesiredSize != null)
|
||||
{
|
||||
itemBase.ItemWidth = dragObject.DesiredSize.Value.Width;
|
||||
itemBase.ItemHeight = dragObject.DesiredSize.Value.Height;
|
||||
}
|
||||
}
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
|
||||
(DataContext as IDiagramViewModel).AddItemCommand.Execute(itemBase);
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
}
|
||||
var dragFile = e.Data.GetData(DataFormats.FileDrop);
|
||||
if (dragFile != null && dragFile is string[] files)
|
||||
|
||||
Reference in New Issue
Block a user