bug修复

This commit is contained in:
艾竹
2023-08-26 21:30:31 +08:00
parent 045a724ee2
commit d50ec045ea
8 changed files with 130 additions and 33 deletions

View File

@@ -426,15 +426,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
foreach (var viewModel in DiagramViewModels) foreach (var viewModel in DiagramViewModels)
{ {
DiagramItem diagramItem = new DiagramItem(viewModel); DiagramItem diagramItem = new DiagramItem(viewModel);
var selectedDesignerItems = viewModel.Items.OfType<DesignerItemViewModelBase>();
var selectedConnections = viewModel.Items.OfType<ConnectionViewModel>();
diagramItem.DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem(ext)).Where(p => p != null).ToList();
diagramItem.Connections = selectedConnections.Select(p => p.ToSerializableItem(ext)).Where(p => p != null).ToList();
diagramDocument.DiagramItems.Add(diagramItem); diagramDocument.DiagramItems.Add(diagramItem);
} }
@@ -485,12 +477,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
{ {
var viewModel = DiagramViewModel; var viewModel = DiagramViewModel;
DiagramItem diagramItem = new DiagramItem(viewModel); DiagramItem diagramItem = new DiagramItem(viewModel);
var selectedDesignerItems = viewModel.Items.OfType<DesignerItemViewModelBase>();
var selectedConnections = viewModel.Items.OfType<ConnectionViewModel>();
diagramItem.DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList();
diagramItem.Connections = selectedConnections.Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList();
diagramItem.Name = NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"); diagramItem.Name = NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-");
viewModel = GetDiagramViewModel(diagramItem, ".json"); viewModel = GetDiagramViewModel(diagramItem, ".json");

View File

@@ -143,7 +143,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
var bitmap = (imageBrush.ImageSource as BitmapImage); var bitmap = (imageBrush.ImageSource as BitmapImage);
byte[] bytearray = null; byte[] bytearray = null;
Stream smarket = bitmap.StreamSource; Stream smarket = bitmap.StreamSource;
if (smarket != null && smarket.Length > 0) if (smarket != null && smarket.Length > 0)
{ {
//设置当前位置 //设置当前位置
@@ -194,21 +194,27 @@ namespace AIStudio.Wpf.DiagramDesigner
public static string ToBase64String(this BitmapImage bitmap) public static string ToBase64String(this BitmapImage bitmap)
{ {
byte[] bytearray = null; //byte[] bytearray = null;
Stream smarket = bitmap.StreamSource; //Stream smarket = bitmap.StreamSource;
if (smarket != null && smarket.Length > 0) //if (smarket != null && smarket.Length > 0)
{ //{
//设置当前位置 // //设置当前位置
smarket.Position = 0; // smarket.Position = 0;
using (BinaryReader br = new BinaryReader(smarket)) // using (BinaryReader br = new BinaryReader(smarket))
{ // {
bytearray = br.ReadBytes((int)smarket.Length); // bytearray = br.ReadBytes((int)smarket.Length);
} // }
} //}
Stream stream = bitmap.StreamSource;
byte[] bytearray = new byte[stream.Length];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(bytearray, 0, bytearray.Length);
return Convert.ToBase64String(bytearray); return Convert.ToBase64String(bytearray);
} }
public static BitmapImage ToBitmapImage(this string base64String, int width = 0, int height =0) public static BitmapImage ToBitmapImage(this string base64String, int width = 0, int height = 0)
{ {
if (string.IsNullOrEmpty(base64String)) if (string.IsNullOrEmpty(base64String))
return null; return null;
@@ -233,5 +239,34 @@ namespace AIStudio.Wpf.DiagramDesigner
return null; return null;
} }
} }
public static BitmapImage ToBitmapImage(this System.Drawing.Bitmap ImageOriginal, int width = 0, int height = 0)
{
System.Drawing.Bitmap ImageOriginalBase = new System.Drawing.Bitmap(ImageOriginal);
BitmapImage bitmapImage = new BitmapImage() { DecodePixelWidth = width, DecodePixelHeight = height };
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ImageOriginalBase.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
public static BitmapImage ToBitmapImage(this byte[] byteArray, int width = 0, int height = 0)
{
BitmapImage bitmapImage = new BitmapImage() { DecodePixelWidth = width, DecodePixelHeight = height };
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
} }
} }

View File

@@ -23,6 +23,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.ChildFlag = viewmodel.ChildFlag; this.ChildFlag = viewmodel.ChildFlag;
this.PhysicalItemWidth = viewmodel.PhysicalItemWidth; this.PhysicalItemWidth = viewmodel.PhysicalItemWidth;
this.PhysicalItemHeight = viewmodel.PhysicalItemHeight; this.PhysicalItemHeight = viewmodel.PhysicalItemHeight;
this.Parameter = new ConstParameterItem(viewmodel.Parameter);
Children = new List<BlockDesignerItem>(viewmodel.Children.Select(p => new BlockDesignerItem(p))); Children = new List<BlockDesignerItem>(viewmodel.Children.Select(p => new BlockDesignerItem(p)));
} }
@@ -52,10 +53,16 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set; get; set;
} }
[XmlElement]
public ConstParameterItem Parameter
{
get; set;
}
[XmlArray] [XmlArray]
public List<BlockDesignerItem> Children public List<BlockDesignerItem> Children
{ {
get; set; get; set;
} }
} }
} }

View File

@@ -0,0 +1,31 @@
using AIStudio.Wpf.DiagramDesigner;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace AIStudio.Wpf.DiagramDesigner
{
[XmlInclude(typeof(ConstParameterItem))]
public class ConstParameterItem
{
[XmlAttribute]
public string Text { get; set; }
[XmlAttribute]
public virtual string Value { get; set; }
public ConstParameterItem()
{
}
public ConstParameterItem(ConstParameter viewmodel)
{
Text = viewmodel.Text;
Value = viewmodel.Value?.ToString();
}
}
}

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Xml; using System.Xml;
@@ -17,7 +18,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
public DiagramItem(IDiagramViewModel diagramView) public DiagramItem(IDiagramViewModel diagramView, string ext = ".json")
{ {
Name = diagramView.Name; Name = diagramView.Name;
DiagramType = diagramView.DiagramType; DiagramType = diagramView.DiagramType;
@@ -30,9 +31,16 @@ namespace AIStudio.Wpf.DiagramDesigner
PageSizeType = diagramView.DiagramOption.LayoutOption.PageSizeType; PageSizeType = diagramView.DiagramOption.LayoutOption.PageSizeType;
PhysicalGridMarginSize = diagramView.DiagramOption.LayoutOption.PhysicalGridMarginSize; PhysicalGridMarginSize = diagramView.DiagramOption.LayoutOption.PhysicalGridMarginSize;
GridColor = diagramView.DiagramOption.LayoutOption.GridColor; GridColor = diagramView.DiagramOption.LayoutOption.GridColor;
PageBackground = diagramView.DiagramOption.LayoutOption.PageBackground;
AllowDrop = diagramView.DiagramOption.LayoutOption.AllowDrop; AllowDrop = diagramView.DiagramOption.LayoutOption.AllowDrop;
Thumbnail = diagramView.Thumbnail.ToBase64String(); Thumbnail = diagramView.Thumbnail.ToBase64String();
var selectedDesignerItems = diagramView.Items.OfType<DesignerItemViewModelBase>();
var selectedConnections = diagramView.Items.OfType<ConnectionViewModel>();
DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem(ext)).Where(p => p != null).ToList();
Connections = selectedConnections.Select(p => p.ToSerializableItem(ext)).Where(p => p != null).ToList();
} }
[XmlAttribute] [XmlAttribute]
@@ -157,6 +165,26 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
[XmlIgnore]
public Color PageBackground
{
get; set;
}
[JsonIgnore]
[XmlAttribute("PageBackground")]
public string XmlPageBackground
{
get
{
return SerializeHelper.SerializeColor(PageBackground);
}
set
{
PageBackground = SerializeHelper.DeserializeColor(value);
}
}
[XmlAttribute] [XmlAttribute]
public bool AllowDrop public bool AllowDrop
{ {

View File

@@ -4,7 +4,15 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
public class ConstParameter : BindableBase, IParameter public class ConstParameter : BindableBase, IParameter
{ {
public ConstParameter()
{
}
public ConstParameter(ConstParameterItem item)
{
Text = item.Text;
Value = item.Value.ToString();
}
private string _text; private string _text;

View File

@@ -65,6 +65,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.ChildFlag = designer.ChildFlag; this.ChildFlag = designer.ChildFlag;
this.PhysicalItemWidth = designer.PhysicalItemWidth; this.PhysicalItemWidth = designer.PhysicalItemWidth;
this.PhysicalItemHeight = designer.PhysicalItemHeight; this.PhysicalItemHeight = designer.PhysicalItemHeight;
this.Parameter = new ConstParameter(designer.Parameter);
if (designer.Children != null) if (designer.Children != null)
{ {
foreach (var child in designer.Children) foreach (var child in designer.Children)
@@ -178,8 +179,8 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
private IParameter _parameter; private ConstParameter _parameter;
public IParameter Parameter public ConstParameter Parameter
{ {
get get
{ {

View File

@@ -859,7 +859,8 @@ namespace AIStudio.Wpf.DiagramDesigner
DiagramOption.LayoutOption.PageSizeType = diagramItem.PageSizeType; DiagramOption.LayoutOption.PageSizeType = diagramItem.PageSizeType;
DiagramOption.LayoutOption.PhysicalGridMarginSize = diagramItem.PhysicalGridMarginSize; DiagramOption.LayoutOption.PhysicalGridMarginSize = diagramItem.PhysicalGridMarginSize;
DiagramOption.LayoutOption.GridColor = diagramItem.GridColor; DiagramOption.LayoutOption.GridColor = diagramItem.GridColor;
DiagramOption.LayoutOption.AllowDrop = diagramItem.AllowDrop; DiagramOption.LayoutOption.PageBackground = diagramItem.PageBackground;
DiagramOption.LayoutOption.AllowDrop = diagramItem.AllowDrop;
Thumbnail = diagramItem.Thumbnail.ToBrush((int)DiagramOption.LayoutOption.PageSize.Width / 4, (int)DiagramOption.LayoutOption.PageSize.Height / 4); Thumbnail = diagramItem.Thumbnail.ToBrush((int)DiagramOption.LayoutOption.PageSize.Width / 4, (int)DiagramOption.LayoutOption.PageSize.Height / 4);
Init(true); Init(true);