mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-02 15:50:51 +08:00
group 和 line 优化
This commit is contained in:
@@ -35,7 +35,10 @@
|
||||
<Canvas x:Name="rootCanvas">
|
||||
<Path x:Name="line" StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}"
|
||||
Style="{StaticResource LineStyle}">
|
||||
Style="{StaticResource LineStyle}"
|
||||
StrokeLineJoin="Round"
|
||||
StrokeStartLineCap="Round"
|
||||
StrokeEndLineCap="Round">
|
||||
<Path.Data>
|
||||
<MultiBinding Converter="{x:Static s:ConnectionPathConverter.Instance}">
|
||||
<Binding Path="PathGeneratorResult"/>
|
||||
|
||||
@@ -161,11 +161,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return _selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
{
|
||||
if (SetProperty(ref _selectedItem, value))
|
||||
{
|
||||
if (_selectedItem == null)
|
||||
@@ -183,10 +179,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
LockObjectViewModel = _selectedItem.LockObjectViewModel;
|
||||
}
|
||||
}
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
set
|
||||
{
|
||||
if (value <= 0) return;
|
||||
|
||||
if (this is GroupDesignerItemViewModel && value < 70)
|
||||
{
|
||||
|
||||
}
|
||||
SetProperty(ref _itemWidth, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public Func<KeyEventArgs, bool> Group
|
||||
{
|
||||
get; set;
|
||||
} = e => e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift) && e.Key == Key.G;
|
||||
} = e => e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.G;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,7 +778,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
private void Add(SelectableDesignerItemViewModelBase item)
|
||||
{
|
||||
item.Root = this;
|
||||
item.ZIndex = Items.Count;
|
||||
item.ZIndex = Items.Any() ? Items.Max(p => p.ZIndex) + 1 : 0;
|
||||
if (item.Id == Guid.Empty)
|
||||
{
|
||||
item.Id = Guid.NewGuid();
|
||||
@@ -1690,24 +1690,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return;
|
||||
}
|
||||
|
||||
RectangleBase rect = GetBoundingRectangle(items);
|
||||
RectangleBase rect = DiagramViewModelHelper.GetBoundingRectangle(items);
|
||||
|
||||
if (groupItem == null)
|
||||
{
|
||||
groupItem = new GroupDesignerItemViewModel();
|
||||
}
|
||||
groupItem.IsGroup = true;
|
||||
groupItem.ItemWidth = rect.Width;
|
||||
groupItem.ItemHeight = rect.Height;
|
||||
groupItem.Left = rect.Left;
|
||||
groupItem.Top = rect.Top;
|
||||
groupItem.ZIndex = Items.Count;
|
||||
|
||||
DirectAddItemCommand.Execute(groupItem);
|
||||
|
||||
foreach (DesignerItemViewModelBase item in items)
|
||||
item.ParentId = groupItem.Id;
|
||||
|
||||
groupItem.Resize();
|
||||
|
||||
ClearSelectedItemsCommand.Execute(null);
|
||||
//groupItem.IsSelected = true;
|
||||
SelectionService.AddToSelection(groupItem);
|
||||
@@ -1826,25 +1822,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
|
||||
public RectangleBase GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items)
|
||||
{
|
||||
double x1 = Double.MaxValue;
|
||||
double y1 = Double.MaxValue;
|
||||
double x2 = Double.MinValue;
|
||||
double y2 = Double.MinValue;
|
||||
|
||||
foreach (DesignerItemViewModelBase item in items)
|
||||
{
|
||||
x1 = Math.Min(item.Left, x1);
|
||||
y1 = Math.Min(item.Top, y1);
|
||||
|
||||
x2 = Math.Max(item.Left + item.ItemWidth, x2);
|
||||
y2 = Math.Max(item.Top + item.ItemHeight, y2);
|
||||
}
|
||||
|
||||
return new RectangleBase(new PointBase(x1, y1), new PointBase(x2, y2));
|
||||
}
|
||||
|
||||
#region 用于wpf大小与物理像素之间转换
|
||||
public void SetScreenScale()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -12,5 +13,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
DesignerItemViewModelBase dataItem = items.OfType<DesignerItemViewModelBase>().Single(x => x.Id == conectorDataItemId);
|
||||
return dataItem;
|
||||
}
|
||||
|
||||
public static RectangleBase GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items)
|
||||
{
|
||||
double x1 = Double.MaxValue;
|
||||
double y1 = Double.MaxValue;
|
||||
double x2 = Double.MinValue;
|
||||
double y2 = Double.MinValue;
|
||||
|
||||
foreach (DesignerItemViewModelBase item in items)
|
||||
{
|
||||
x1 = Math.Min(item.Left, x1);
|
||||
y1 = Math.Min(item.Top, y1);
|
||||
|
||||
x2 = Math.Max(item.Left + item.ItemWidth, x2);
|
||||
y2 = Math.Max(item.Top + item.ItemHeight, y2);
|
||||
}
|
||||
|
||||
return new RectangleBase(new PointBase(x1, y1), new PointBase(x2, y2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -12,7 +14,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public GroupDesignerItemViewModel() : this(null)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public GroupDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
@@ -34,6 +36,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.Init(root);
|
||||
|
||||
this.IsGroup = true;
|
||||
this.IsHitTestVisible = true;
|
||||
}
|
||||
|
||||
@@ -46,6 +49,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public void Resize()
|
||||
{
|
||||
if (this.Root == null) return;
|
||||
|
||||
var items = this.Root.Items.Where(p => p.ParentId == Id).OfType<DesignerItemViewModelBase>();
|
||||
RectangleBase rect = DiagramViewModelHelper.GetBoundingRectangle(items);
|
||||
|
||||
this.ItemWidth = rect.Width;
|
||||
this.ItemHeight = rect.Height;
|
||||
this.Left = rect.Left;
|
||||
this.Top = rect.Top;
|
||||
}
|
||||
|
||||
public void AddItem(DesignerItemViewModelBase item)
|
||||
{
|
||||
if (this.Root == null) return;
|
||||
|
||||
item.ParentId = Id;
|
||||
if (item.ZIndex > this.ZIndex)
|
||||
{
|
||||
var zindex = item.ZIndex;
|
||||
item.ZIndex = this.ZIndex;
|
||||
this.ZIndex = zindex;
|
||||
}
|
||||
Resize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打标记使用
|
||||
|
||||
Reference in New Issue
Block a user