Flowchart

This commit is contained in:
艾竹
2022-12-04 23:07:20 +08:00
parent dc42f75610
commit 0487857d7b
30 changed files with 1621 additions and 383 deletions

View File

@@ -42,7 +42,7 @@
<Setter Property="PropertiesBox">
<Setter.Value>
<ControlTemplate TargetType="Control">
<dd:PropertiesView CustomSetting="True"
<dd:PropertiesView
SelectedObject="{Binding Path=SelectedObject,RelativeSource={RelativeSource AncestorType={x:Type controls:FlowchartEditor}}}"
Width="200">
<dd:PropertiesView.Resources>

View File

@@ -1,20 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.Flowchart.Models;
using AIStudio.Wpf.Flowchart.ViewModels;
namespace AIStudio.Wpf.Flowchart.Controls
{
@@ -26,24 +18,8 @@ namespace AIStudio.Wpf.Flowchart.Controls
{
public const string PART_DiagramControl = "PART_DiagramControl";
private DiagramControl _diagramControl;
private IDiagramServiceProvider _service
{
get
{
return DiagramServicesProvider.Instance.Provider;
}
}
private DiagramViewModel _diagramViewModel = new DiagramViewModel()
{
ShowGrid = true,
GridCellSize = new Size(100, 60),
GridMargin = 0d,
CellHorizontalAlignment = CellHorizontalAlignment.Center,
CellVerticalAlignment = CellVerticalAlignment.Center,
PageSizeType = PageSizeType.Custom,
PageSize = new Size(double.NaN, double.NaN),
};
private IDiagramViewModel _diagramViewModel;
static FlowchartEditor()
{
@@ -51,7 +27,18 @@ namespace AIStudio.Wpf.Flowchart.Controls
}
public FlowchartEditor()
{
{
_diagramViewModel = new DiagramViewModel();
_diagramViewModel.SetScreenScale();
_diagramViewModel.ShowGrid = true;
_diagramViewModel.GridCellSize = new Size(125 / _diagramViewModel.ScreenScale, 125 / _diagramViewModel.ScreenScale);
_diagramViewModel.GridMargin = 0d;
_diagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
_diagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
_diagramViewModel.PageSizeType = PageSizeType.Custom;
_diagramViewModel.PageSize = new Size(double.NaN, double.NaN);
_diagramViewModel.VectorLineDrawMode = DrawMode.BoundaryConnectingLine;
_diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
}
@@ -63,6 +50,8 @@ namespace AIStudio.Wpf.Flowchart.Controls
_diagramControl.HorizontalAlignment = HorizontalAlignment.Stretch;
_diagramControl.VerticalAlignment = VerticalAlignment.Stretch;
_diagramControl.DataContext = _diagramViewModel;
GetDataFunc = GetData;
}
private void DiagramViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -74,47 +63,95 @@ namespace AIStudio.Wpf.Flowchart.Controls
}
//一点要绑定不为空的FlowchartModel才能用即便为空的也要new一个再来绑定
public static readonly DependencyProperty FlowchartModelProperty =
DependencyProperty.Register(nameof(FlowchartModel),
typeof(FlowchartModel),
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register(nameof(Data),
typeof(string),
typeof(FlowchartEditor),
new FrameworkPropertyMetadata(null, OnFlowchartModelChanged));
new FrameworkPropertyMetadata(null, OnDataChanged));
public FlowchartModel FlowchartModel
public string Data
{
get
{
return (FlowchartModel)GetValue(FlowchartModelProperty);
return (string)GetValue(DataProperty);
}
set
{
SetValue(FlowchartModelProperty, value);
SetValue(DataProperty, value);
}
}
private static void OnFlowchartModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var view = d as FlowchartEditor;
var model = e.NewValue as FlowchartModel;
if (model != null)
var json = e.NewValue as string;
if (json != null)
{
view.CreateFlowchartModel(model);
view.CreateFlowchartModel(json);
}
}
private void CreateFlowchartModel(FlowchartModel model)
private void CreateFlowchartModel(string json)
{
_service.DrawModeViewModel.VectorLineDrawMode = DrawMode.BoundaryConnectingLine;
_diagramViewModel.Items.Clear();
if (model != null)
_diagramViewModel.ToObject(json);
}
public static readonly DependencyProperty GetDataFuncProperty =
DependencyProperty.Register(nameof(GetDataFunc),
typeof(Func<string>),
typeof(FlowchartEditor),
new FrameworkPropertyMetadata(null));
public Func<string> GetDataFunc
{
get
{
foreach (var node in model.Nodes)
{
_diagramViewModel.DirectAddItemCommand.Execute(node);
}
foreach (var link in model.Links)
{
_diagramViewModel.DirectAddItemCommand.Execute(link);
}
return (Func<string>)this.GetValue(GetDataFuncProperty);
}
set
{
this.SetValue(GetDataFuncProperty, value);
}
}
public Func<string> GetData
{
get
{
return new Func<string>(() => _diagramViewModel.ToJson());
}
}
public static readonly DependencyProperty ModeProperty =
DependencyProperty.Register(nameof(Mode),
typeof(string),
typeof(FlowchartEditor),
new FrameworkPropertyMetadata("Edit", OnModeChanged));
public string Mode
{
get
{
return (string)GetValue(ModeProperty);
}
set
{
SetValue(ModeProperty, value);
}
}
private static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var view = d as FlowchartEditor;
var mode = e.NewValue as string;
if (mode != "Edit")
{
view._diagramViewModel.IsReadOnly = true;
}
else
{
view._diagramViewModel.IsReadOnly = false;
}
}

View File

@@ -0,0 +1,408 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace AIStudio.Wpf.Flowchart.Models
{
/// <summary>
///
/// </summary>
public class DiagramData
{
/// <summary>
/// Gets or sets the nodes.
/// </summary>
/// <value>
/// The nodes.
/// </value>
public DiagramNode[] Nodes
{
get; set;
}
/// <summary>
/// Gets or sets the links.
/// </summary>
/// <value>
/// The links.
/// </value>
public DiagramLink[] Links
{
get; set;
}
/// <summary>
/// Gets or sets the groups.
/// </summary>
/// <value>
/// The groups.
/// </value>
public DiagramGroup[] Groups
{
get; set;
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagramData"/> class.
/// </summary>
public DiagramData()
{
Nodes = new DiagramNode[0];
Links = new DiagramLink[0];
Groups = new DiagramGroup[0];
}
}
/// <summary>
/// DiagramNode
/// </summary>
public class DiagramNode
{
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public string Id
{
get; set;
}
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name
{
get; set;
}
/// <summary>
/// Gets or sets the color.
/// </summary>
/// <value>
/// The color.
/// </value>
public string Color
{
get; set;
}
/// <summary>
/// Gets or sets the label.
/// </summary>
/// <value>
/// The label.
/// </value>
public string Label
{
get; set;
}
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public double Width
{
get; set;
}
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>
/// The height.
/// </value>
public double Height
{
get; set;
}
/// <summary>
/// Gets or sets the x.
/// </summary>
/// <value>
/// The x.
/// </value>
public double X
{
get; set;
}
/// <summary>
/// Gets or sets the y.
/// </summary>
/// <value>
/// The y.
/// </value>
public double Y
{
get; set;
}
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>
/// The type.
/// </value>
public string Type
{
get; set;
}
/// <summary>
/// Gets or sets the index of the z.
/// </summary>
/// <value>
/// The index of the z.
/// </value>
public int ZIndex
{
get; set;
}
/// <summary>
/// Gets or sets the port alignment list.
/// </summary>
/// <value>
/// The port alignment list.
/// </value>
public List<string> PortAlignmentList
{
get; set;
}
}
/// <summary>
///
/// </summary>
public class DiagramLink
{
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public string Id
{
get; set;
}
/// <summary>
/// Gets or sets the color.
/// </summary>
/// <value>
/// The color.
/// </value>
public string Color
{
get; set;
}
/// <summary>
/// Gets or sets the color of the selected.
/// </summary>
/// <value>
/// The color of the selected.
/// </value>
public string SelectedColor
{
get; set;
}
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public double Width
{
get; set;
}
/// <summary>
/// Gets or sets the label.
/// </summary>
/// <value>
/// The label.
/// </value>
public string Label
{
get; set;
}//TODO
/// <summary>
/// Gets or sets the source identifier.
/// </summary>
/// <value>
/// The source identifier.
/// </value>
public string SourceId
{
get; set;
}
/// <summary>
/// Gets or sets the target identifier.
/// </summary>
/// <value>
/// The target identifier.
/// </value>
public string TargetId
{
get; set;
}
/// <summary>
/// Gets or sets the source port alignment.
/// </summary>
/// <value>
/// The source port alignment.
/// </value>
public string SourcePortAlignment
{
get; set;
}
/// <summary>
/// Gets or sets the target port alignment.
/// </summary>
/// <value>
/// The target port alignment.
/// </value>
public string TargetPortAlignment
{
get; set;
}
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>
/// The type.
/// </value>
public string Type
{
get; set;
}
/// <summary>
/// Gets or sets the router.
/// </summary>
/// <value>
/// The router.
/// </value>
public string Router
{
get; set;
}
/// <summary>
/// Gets or sets the path generator.
/// </summary>
/// <value>
/// The path generator.
/// </value>
public string PathGenerator
{
get; set;
}
/// <summary>
/// Gets or sets the source marker path.
/// </summary>
/// <value>
/// The source marker path.
/// </value>
public string SourceMarkerPath
{
get; set;
}
/// <summary>
/// Gets or sets the width of the source marker.
/// </summary>
/// <value>
/// The width of the source marker.
/// </value>
public double? SourceMarkerWidth
{
get; set;
}
/// <summary>
/// Gets or sets the target marker path.
/// </summary>
/// <value>
/// The target marker path.
/// </value>
public string TargetMarkerPath
{
get; set;
}
/// <summary>
/// Gets or sets the width of the target marker.
/// </summary>
/// <value>
/// The width of the target marker.
/// </value>
public double? TargetMarkerWidth
{
get; set;
}
}
/// <summary>
///
/// </summary>
/// <seealso cref="AIStudio.Util.DiagramEntity.DiagramNode" />
public class FlowchartNode : DiagramNode
{
/// <summary>
/// Gets or sets the kind.
/// </summary>
/// <value>
/// The kind.
/// </value>
public NodeKinds Kind
{
get; set;
}
/// <summary>
/// Gets or sets the user ids.
/// </summary>
/// <value>
/// The user ids.
/// </value>
public IEnumerable<string> UserIds
{
get; set;
}
/// <summary>
/// Gets or sets the role ids.
/// </summary>
/// <value>
/// The role ids.
/// </value>
public IEnumerable<string> RoleIds
{
get; set;
}
/// <summary>
/// Gets or sets the type of the act.
/// </summary>
/// <value>
/// The type of the act.
/// </value>
public string ActType
{
get; set;
}
}
/// <summary>
///
/// </summary>
public class DiagramGroup
{
/// <summary>
/// Gets or sets the flow node ids.
/// </summary>
/// <value>
/// The flow node ids.
/// </value>
public List<string> FlowNodeIds { get; set; } = new List<string>();
}
}

View File

@@ -0,0 +1,103 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AIStudio.Wpf.Flowchart.Models
{
public class DiagramNodeConverter : DATACreationConverter<DiagramNode>
{
protected override DiagramNode Create(Type objectType, JObject jObject)
{
//第一种方法:判断属性值来确认是哪个派生类
if (FieldExists("Type", jObject, out string type))
{
if (type == "FlowchartNode")
{
return new FlowchartNode();
}
else
{
return new DiagramNode();
}
}
else
{
return new DiagramNode();
}
//第二种方法:判断字段是否存在来确认是哪个派生类
}
private bool FieldExists(string fieldName, JObject jObject, out string entityName)
{
entityName = jObject[fieldName] == null ? "" : jObject[fieldName].ToString();
return jObject[fieldName] != null;
}
}
public class DiagramLinkConverter : DATACreationConverter<DiagramLink>
{
protected override DiagramLink Create(Type objectType, JObject jObject)
{
//第一种方法:判断属性值来确认是哪个派生类
if (FieldExists("Type", jObject, out string type))
{
return new DiagramLink();
}
else
{
return new DiagramLink();
}
//第二种方法:判断字段是否存在来确认是哪个派生类
}
private bool FieldExists(string fieldName, JObject jObject, out string entityName)
{
entityName = jObject[fieldName] == null ? "" : jObject[fieldName].ToString();
return jObject[fieldName] != null;
}
}
public abstract class DATACreationConverter<T> : JsonConverter
{
/// <summary>
/// Create an instance of objectType, based properties in the JSON object
/// </summary>
/// <param name="objectType">type of object expected</param>
/// <param name="jObject">
/// contents of JSON object that will be deserialized
/// </param>
/// <returns></returns>
protected abstract T Create(Type objectType, JObject jObject);
public override bool CanConvert(Type objectType)
{
return typeof(T).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader,
Type objectType,
object existingValue,
JsonSerializer serializer)
{
// Load JObject from stream
JObject jObject = JObject.Load(reader);
// Create target object based on JObject
T target = Create(objectType, jObject);
// Populate the object properties
serializer.Populate(jObject.CreateReader(), target);
return target;
}
public override void WriteJson(JsonWriter writer,
object value,
JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,244 @@
using System;
using System.Collections.Generic;
using System.Text;
using AIStudio.Wpf.DiagramDesigner;
using Newtonsoft.Json;
using System.Linq;
using System.Windows.Media;
using AIStudio.Wpf.Flowchart.ViewModels;
namespace AIStudio.Wpf.Flowchart.Models
{
public static class DiagramDataExtention
{
#region ToJson
public static string ToJson(this IDiagramViewModel diagram)
{
var json = JsonConvert.SerializeObject(new {
Nodes = diagram.Items.OfType<DesignerItemViewModelBase>().Select(p => p.ToDiagramNode()),
Links = diagram.Items.OfType<ConnectorViewModel>().Select(p => p.ToDiagramLink())
}, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return json;
}
public static DiagramNode ToDiagramNode(this DesignerItemViewModelBase nodeModel)
{
DiagramNode diagramNode;
if (nodeModel is FlowNode flowNode)
{
var flowchartNode = new FlowchartNode();
diagramNode = flowchartNode;
diagramNode.Name = flowNode.Name;
flowchartNode.Color = flowNode.Color;
flowchartNode.Kind = flowNode.Kind;
if (nodeModel is MiddleFlowNode middleflowNode)
{
flowchartNode.UserIds = middleflowNode.UserIds;
flowchartNode.RoleIds = middleflowNode.RoleIds;
flowchartNode.ActType = middleflowNode.ActType;
}
}
else
{
diagramNode = new DiagramNode();
}
diagramNode.Id = nodeModel.Id.ToString();
diagramNode.Label = nodeModel.Text;
diagramNode.Width = nodeModel.ItemWidth * nodeModel.Parent.ScreenScale;
diagramNode.Height = nodeModel.ItemHeight * nodeModel.Parent.ScreenScale;
diagramNode.X = nodeModel.Left * nodeModel.Parent.ScreenScale;
diagramNode.Y = nodeModel.Top * nodeModel.Parent.ScreenScale;
diagramNode.ZIndex = nodeModel.ZIndex;
diagramNode.Type = diagramNode.GetType().Name;
diagramNode.PortAlignmentList = nodeModel.Connectors.Select(p => p.Orientation.ToString()).ToList();
return diagramNode;
}
public static DiagramLink ToDiagramLink(this ConnectorViewModel linkModel)
{
DiagramLink diagramLink = new DiagramLink();
diagramLink.Id = linkModel.Id.ToString();
diagramLink.Color = SerializeHelper.SerializeColor(linkModel.ColorViewModel.LineColor.Color);
diagramLink.SelectedColor = SerializeHelper.SerializeColor(Colors.Black);
diagramLink.Width = linkModel.ColorViewModel.LineWidth;
if (linkModel.SinkConnectorInfo is FullyCreatedConnectorInfo sinkConnector)
{
diagramLink.SourceId = linkModel.SourceConnectorInfo.DataItem.Id.ToString();
diagramLink.TargetId = sinkConnector.DataItem.Id.ToString();
//线条形状与箭头待处理
//diagramLink.Router = baseLinkModel.Router?.Method.Name;
//diagramLink.PathGenerator = baseLinkModel.PathGenerator?.Method.Name;
//diagramLink.SourceMarkerPath = baseLinkModel.SourceMarker?.Path;
//diagramLink.SourceMarkerWidth = baseLinkModel.SourceMarker?.Width;
//diagramLink.TargetMarkerPath = baseLinkModel.TargetMarker?.Path;
//diagramLink.TargetMarkerWidth = baseLinkModel.TargetMarker?.Width;
diagramLink.Type = diagramLink.GetType().Name;
diagramLink.SourcePortAlignment = linkModel.SourceConnectorInfo.Orientation.ToString();
diagramLink.TargetPortAlignment = sinkConnector.Orientation.ToString();
}
return diagramLink;
}
#endregion
#region ToObject
public static void ToObject(this IDiagramViewModel diagram, string json)
{
var data = JsonConvert.DeserializeObject<DiagramData>(json, new JsonConverter[] { new DiagramNodeConverter(), new DiagramLinkConverter() });
if (data != null)
{
ToObject(diagram, data);
}
}
public static void ToObject(this IDiagramViewModel diagram, DiagramData data)
{
diagram.Items.Clear();
List<DesignerItemViewModelBase> nodes = new List<DesignerItemViewModelBase>();
if (data.Nodes != null)
{
foreach (var node in data.Nodes)
{
var nodemodel = node.ToNodelModel(diagram);
nodes.Add(nodemodel);
diagram.Items.Add(nodemodel);
}
}
if (data.Links != null)
{
foreach (var link in data.Links)
{
var source = nodes.FirstOrDefault(p => p.Id == new Guid(link.SourceId));
var target = nodes.FirstOrDefault(p => p.Id == new Guid(link.TargetId));
var linkmodel = link.ToLinkModel(diagram, source, target);
diagram.Items.Add(linkmodel);
}
}
}
private static DesignerItemViewModelBase ToNodelModel(this DiagramNode diagramNode, IDiagramViewModel diagram)
{
DesignerItemViewModelBase nodeModel;
if (diagramNode is FlowchartNode flowchartNode)
{
FlowNode flowNode = null;
switch (flowchartNode.Kind)
{
case NodeKinds.Start:
{
var flowchartNodelModel = new StartFlowNode();
flowNode = flowchartNodelModel;
break;
}
case NodeKinds.End:
{
var flowchartNodelModel = new EndFlowNode();
flowNode = flowchartNodelModel;
break;
}
case NodeKinds.Decide:
{
var flowchartNodelModel = new DecideFlowNode();
flowNode = flowchartNodelModel;
break;
}
case NodeKinds.COBegin:
{
var flowchartNodelModel = new COBeginFlowNode();
flowNode = flowchartNodelModel;
break;
}
case NodeKinds.COEnd:
{
var flowchartNodelModel = new COEndFlowNode();
flowNode = flowchartNodelModel;
break;
}
case NodeKinds.Middle:
{
var flowchartNodelModel = new MiddleFlowNode();
flowNode = flowchartNodelModel;
flowchartNodelModel.UserIds = flowchartNode.UserIds?.ToList();
flowchartNodelModel.RoleIds = flowchartNode.RoleIds?.ToList();
flowchartNodelModel.ActType = flowchartNode.ActType;
break;
}
default:
{
var flowNodelModel = new FlowNode(NodeKinds.Normal);
flowNode = flowNodelModel;
break;
}
}
nodeModel = flowNode;
flowNode.Name = flowchartNode.Name;
flowNode.Color = flowchartNode.Color;
flowNode.Kind = flowchartNode.Kind;
}
else
{
nodeModel = new TextDesignerItemViewModel();
}
nodeModel.Id = new Guid(diagramNode.Id);
nodeModel.Parent = diagram;
nodeModel.Text = diagramNode.Label;
nodeModel.ItemWidth = diagramNode.Width / diagram.ScreenScale;
nodeModel.ItemHeight = diagramNode.Height / diagram.ScreenScale;
nodeModel.Left = diagramNode.X / diagram.ScreenScale;
nodeModel.Top = diagramNode.Y / diagram.ScreenScale;
nodeModel.ZIndex = diagramNode.ZIndex;
diagramNode.PortAlignmentList?.ForEach(p => nodeModel.AddConnector(new FullyCreatedConnectorInfo(nodeModel, p.ToEnum<ConnectorOrientation>())));
return nodeModel;
}
public static ConnectorViewModel ToLinkModel(this DiagramLink diagramLink, IDiagramViewModel diagram, DesignerItemViewModelBase sourceNode, DesignerItemViewModelBase targetNode)
{
FullyCreatedConnectorInfo sourceConnectorInfo = sourceNode.Connectors.FirstOrDefault(p => p.Orientation.ToString() == diagramLink.SourcePortAlignment);
FullyCreatedConnectorInfo sinkConnectorInfo = targetNode.Connectors.FirstOrDefault(p => p.Orientation.ToString() == diagramLink.TargetPortAlignment);
ConnectorViewModel linkModel = new ConnectorViewModel(sourceConnectorInfo, sinkConnectorInfo, diagram.VectorLineDrawMode ?? DrawMode.BoundaryConnectingLine);
linkModel.ColorViewModel.LineColor.Color = SerializeHelper.DeserializeColor(diagramLink.Color);
linkModel.ColorViewModel.LineWidth = diagramLink.Width;
//线条形状与箭头待处理
//switch (diagramLink.Router)
//{
// case "Normal": linkModel.Router = Routers.Normal; break;
// case "Orthogonal": linkModel.Router = Routers.Orthogonal; break;
//}
//switch (diagramLink.PathGenerator)
//{
// case "Smooth": linkModel.PathGenerator = PathGenerators.Smooth; break;
// case "Straight": linkModel.PathGenerator = PathGenerators.Straight; break;
//}
//if (!string.IsNullOrEmpty(diagramLink.SourceMarkerPath))
//{
// linkModel.SourceMarker = new LinkMarker(diagramLink.SourceMarkerPath, diagramLink.SourceMarkerWidth ?? 10.0);
//}
//if (!string.IsNullOrEmpty(diagramLink.TargetMarkerPath))
//{
// linkModel.TargetMarker = new LinkMarker(diagramLink.TargetMarkerPath, diagramLink.TargetMarkerWidth ?? 10.0);
//}
return linkModel;
}
#endregion
}
}

View File

@@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.Flowchart.ViewModels;
namespace AIStudio.Wpf.Flowchart.Models
{
public class FlowchartModel
{
private List<FlowNode> _nodes = new List<FlowNode>();
public List<FlowNode> Nodes
{
get
{
return _nodes;
}
}
private List<ConnectorViewModel> _links = new List<ConnectorViewModel>();
public List<ConnectorViewModel> Links
{
get
{
return _links;
}
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Helpers;
@@ -14,7 +15,7 @@ namespace AIStudio.Wpf.Flowchart.Models
get; set;
}
public FlowchartToolBoxData(NodeKinds kind, Type type, double width = 32, double height = 32) : base(kind.GetDescription(), null, type, width, height)
public FlowchartToolBoxData(NodeKinds kind, Type type, double width, double height, Size? desiredSize) : base(kind.GetDescription(), null, type, width, height, desiredSize)
{
Kind = kind;
ColorViewModel.LineColor.Color = Colors.Black;

View File

@@ -15,9 +15,6 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
Kind = kind;
Text = Kind.GetDescription();
ItemWidth = 80;
ItemHeight = 40;
}
public FlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
@@ -70,6 +67,9 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
[Browsable(false)]
public string StateImage { get; set; }
[Browsable(true)]
public string Name{ get; set; }
#region 使,
private int _status;
@@ -102,7 +102,8 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
get
{
return new Dictionary<string, string>()
{
{
{ "Name","名称" },
{ "Text","文本" },
};
}

View File

@@ -87,6 +87,7 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
return new Dictionary<string, string>()
{
{ "Name","名称" },
{ "Text","文本" },
{"UserIds", "用户" },
{"RoleIds", "角色" },

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Helpers;
using AIStudio.Wpf.Flowchart;
using AIStudio.Wpf.Flowchart.Models;
@@ -15,12 +17,13 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
public ToolBoxViewModel()
{
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.Start, typeof(StartFlowNode), 80, 48));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.End, typeof(EndFlowNode), 80, 48));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.Middle, typeof(MiddleFlowNode), 80, 48));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.Decide, typeof(DecideFlowNode), 80, 48));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.COBegin, typeof(COBeginFlowNode), 80, 48));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.COEnd, typeof(COEndFlowNode), 80, 48));
var screenScale = ScreenHelper.ResetScreenScale();
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.Start, typeof(StartFlowNode), 80, 60, new Size(100 / screenScale, 80/ screenScale)));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.End, typeof(EndFlowNode), 80, 60, new Size(100 / screenScale, 80 / screenScale)));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.Middle, typeof(MiddleFlowNode), 80, 60, new Size(100 / screenScale, 80 / screenScale)));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.Decide, typeof(DecideFlowNode), 80, 60, new Size(100 / screenScale, 80 / screenScale)));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.COBegin, typeof(COBeginFlowNode), 80, 60, new Size(100 / screenScale, 80 / screenScale)));
toolBoxItems.Add(new FlowchartToolBoxData(NodeKinds.COEnd, typeof(COEndFlowNode), 80, 60, new Size(100 / screenScale, 80 / screenScale)));
}
public List<ToolBoxData> ToolBoxItems