This commit is contained in:
艾竹
2023-03-07 22:59:27 +08:00
parent f042f95ee0
commit f48838f54a
7 changed files with 66 additions and 35 deletions

View File

@@ -30,6 +30,11 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
{ {
// we only move DesignerItems // we only move DesignerItems
designerItems = designerItem.Root.SelectedItems.ToList(); designerItems = designerItem.Root.SelectedItems.ToList();
if (designerItem is IGroupable groupable)
{
designerItems.AddRange(designerItem.Root.SelectionService.GetGroupMembers(groupable).OfType<SelectableDesignerItemViewModelBase>());
}
if (designerItem is ConnectionViewModel connector) if (designerItem is ConnectionViewModel connector)
{ {
designerItems.Add(connector.SourceConnectorInfo.DataItem); designerItems.Add(connector.SourceConnectorInfo.DataItem);
@@ -44,6 +49,8 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
designerItems = new List<SelectableDesignerItemViewModelBase> { designerItem }; designerItems = new List<SelectableDesignerItemViewModelBase> { designerItem };
} }
designerItems = designerItems.Distinct().ToList();
foreach (DesignerItemViewModelBase item in designerItems.OfType<DesignerItemViewModelBase>()) foreach (DesignerItemViewModelBase item in designerItems.OfType<DesignerItemViewModelBase>())
{ {
item.BeginDo = true; item.BeginDo = true;

View File

@@ -115,7 +115,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
private void DragLeft(double scale, DesignerItemViewModelBase item, SelectionService selectionService) private void DragLeft(double scale, DesignerItemViewModelBase item, SelectionService selectionService)
{ {
IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item).Cast<DesignerItemViewModelBase>(); IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item, false).Cast<DesignerItemViewModelBase>();
double groupLeft = item.Left + item.ItemWidth; double groupLeft = item.Left + item.ItemWidth;
foreach (DesignerItemViewModelBase groupItem in groupItems) foreach (DesignerItemViewModelBase groupItem in groupItems)
@@ -129,7 +129,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
private void DragTop(double scale, DesignerItemViewModelBase item, SelectionService selectionService) private void DragTop(double scale, DesignerItemViewModelBase item, SelectionService selectionService)
{ {
IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item).Cast<DesignerItemViewModelBase>(); IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item, false).Cast<DesignerItemViewModelBase>();
double groupBottom = item.Top + item.ItemHeight; double groupBottom = item.Top + item.ItemHeight;
foreach (DesignerItemViewModelBase groupItem in groupItems) foreach (DesignerItemViewModelBase groupItem in groupItems)
{ {
@@ -142,7 +142,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
private void DragRight(double scale, DesignerItemViewModelBase item, SelectionService selectionService) private void DragRight(double scale, DesignerItemViewModelBase item, SelectionService selectionService)
{ {
IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item).Cast<DesignerItemViewModelBase>(); IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item, false).Cast<DesignerItemViewModelBase>();
double groupLeft = item.Left; double groupLeft = item.Left;
foreach (DesignerItemViewModelBase groupItem in groupItems) foreach (DesignerItemViewModelBase groupItem in groupItems)
@@ -157,7 +157,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
private void DragBottom(double scale, DesignerItemViewModelBase item, SelectionService selectionService) private void DragBottom(double scale, DesignerItemViewModelBase item, SelectionService selectionService)
{ {
IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item).Cast<DesignerItemViewModelBase>(); IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item, false).Cast<DesignerItemViewModelBase>();
double groupTop = item.Top; double groupTop = item.Top;
foreach (DesignerItemViewModelBase groupItem in groupItems) foreach (DesignerItemViewModelBase groupItem in groupItems)
{ {

View File

@@ -415,6 +415,13 @@
</MultiDataTrigger.Conditions> </MultiDataTrigger.Conditions>
<Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/> <Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
</MultiDataTrigger> </MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="True" Binding="{Binding IsSelected}"/>
<Condition Value="True" Binding="{Binding AlwayForResized}"/>
</MultiDataTrigger.Conditions>
<Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
</MultiDataTrigger>
<Trigger Property="IsMouseOver" <Trigger Property="IsMouseOver"
Value="true"> Value="true">
<Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/> <Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>

View File

@@ -315,6 +315,24 @@ namespace AIStudio.Wpf.DiagramDesigner
public bool ShowArrow { get; set; } = true; public bool ShowArrow { get; set; } = true;
public bool ShowResized
{
get; set;
}
private bool alwayForResized;
public bool AlwayForResized
{
get
{
return alwayForResized;
}
set
{
SetProperty(ref alwayForResized, value);
}
}
private bool enabledForConnection = true; private bool enabledForConnection = true;
public bool EnabledForConnection public bool EnabledForConnection
{ {

View File

@@ -48,7 +48,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
internal List<IGroupable> GetGroupMembers(IGroupable item) internal List<IGroupable> GetGroupMembers(IGroupable item, bool withchildren=true)
{ {
IEnumerable<IGroupable> list = DiagramViewModel.Items.OfType<IGroupable>(); IEnumerable<IGroupable> list = DiagramViewModel.Items.OfType<IGroupable>();
IGroupable rootItem = GetRoot(list, item); IGroupable rootItem = GetRoot(list, item);
@@ -56,7 +56,18 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
return new List<IGroupable>(); return new List<IGroupable>();
} }
return GetGroupMembers(list, rootItem);
if (rootItem.IsGroup)//分组状态下,获取全部成员
{
return GetGroupMembers(list, rootItem);
}
else
{
if (withchildren)
return GetGroupMembers(list, item);//普通的Parent关系获取其Children
else
return new List<IGroupable>() { item };
}
} }
internal IGroupable GetGroupRoot(IGroupable item) internal IGroupable GetGroupRoot(IGroupable item)
@@ -98,5 +109,7 @@ namespace AIStudio.Wpf.DiagramDesigner
return groupMembers; return groupMembers;
} }
} }
} }

View File

@@ -172,7 +172,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
public MindDiagramViewModel() public MindDiagramViewModel()
{ {
MindNode level1node = new MindNode(this) { Left = 200, Top = 200, Text = "思维导图" }; MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Left = 200, Top = 200, Text = "思维导图" };
level1node.InitLayout(true); level1node.InitLayout(true);
Items.Add(level1node); Items.Add(level1node);
level1node.IsSelected = true; level1node.IsSelected = true;

View File

@@ -54,6 +54,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
base.Init(root); base.Init(root);
EnabledForConnection = false; EnabledForConnection = false;
AlwayForResized = true;
AddChildCommand = (Root as IMindDiagramViewModel)?.AddChildCommand; AddChildCommand = (Root as IMindDiagramViewModel)?.AddChildCommand;
AddParentCommand = (Root as IMindDiagramViewModel)?.AddParentCommand; AddParentCommand = (Root as IMindDiagramViewModel)?.AddParentCommand;
@@ -100,22 +101,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
return mindNodeModel; return mindNodeModel;
} }
public override void AddToSelection(bool selected)
{
if (NodeLevel == 0)
{
base.AddToSelection(selected);
}
else
{
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
item.IsSelected = false;
this.IsSelected= true;
}
}
#region #region
public IMindLayout MindLayout public IMindLayout MindLayout
{ {
@@ -389,11 +374,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
this.Children.Add(item); this.Children.Add(item);
} }
item.Parent = this; item.Parent = this;
item.ParentId = this.Id;
item.InitLayout(true); item.InitLayout(true);
ConnectionViewModel connector = MindLayout?.GetOrSetConnectionViewModel(this, item); ConnectionViewModel connector = MindLayout?.GetOrSetConnectionViewModel(this, item);
Root?.DirectAddItemCommand.Execute(new SelectableDesignerItemViewModelBase[] { item, connector }); Root?.DirectAddItemCommand.Execute(new SelectableDesignerItemViewModelBase[] { item, connector });
connector.ZIndex = -1; connector.ZIndex = -1;
connector.IsSelected = false;
item.IsSelected = false;
this.IsSelected = true; this.IsSelected = true;
} }
@@ -450,14 +438,9 @@ namespace AIStudio.Wpf.Mind.ViewModels
{ {
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs) if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{ {
if (NodeLevel == 0) if (NodeLevel > 0 && IsSelected)
{
//LayoutUpdated();
}
else
{ {
UpdateOffsetX((double)valuePropertyChangedEventArgs.OldValue, (double)valuePropertyChangedEventArgs.NewValue); UpdateOffsetX((double)valuePropertyChangedEventArgs.OldValue, (double)valuePropertyChangedEventArgs.NewValue);
//LayoutUpdated();
} }
} }
break; break;
@@ -466,14 +449,9 @@ namespace AIStudio.Wpf.Mind.ViewModels
{ {
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs) if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{ {
if (NodeLevel == 0) if (NodeLevel > 0 && IsSelected)
{
//LayoutUpdated();
}
else
{ {
UpdateOffsetY((double)valuePropertyChangedEventArgs.OldValue, (double)valuePropertyChangedEventArgs.NewValue); UpdateOffsetY((double)valuePropertyChangedEventArgs.OldValue, (double)valuePropertyChangedEventArgs.NewValue);
//LayoutUpdated();
} }
} }
break; break;
@@ -487,6 +465,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
} }
} }
public override void AddToSelection(bool selected)
{
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
item.IsSelected = false;
Root.SelectedItems.Clear();
IsSelected = selected;
}
#region #region
public MindNode GetLevel1Node() public MindNode GetLevel1Node()
{ {