From 77c8a9bdfd447820519937b50320ef520975312e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Fri, 25 Aug 2023 08:44:27 +0000 Subject: [PATCH 01/14] update README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 艾竹 --- README.md | 1 + thank.png | Bin 0 -> 3470 bytes 2 files changed, 1 insertion(+) create mode 100644 thank.png diff --git a/README.md b/README.md index cd80f21..975729f 100644 --- a/README.md +++ b/README.md @@ -757,5 +757,6 @@ nuget地址:![输入图片说明](Images/nuget.png) QQ技术交流群:51286643(如果您还喜欢,帮忙点个星,谢谢) 特别感谢:https://dotnet9.com/ 的站长:dotnet9。 + 鸣谢列表:![输入图片说明](thank.png) 有想加入开发的朋友可以联系我。 \ No newline at end of file diff --git a/thank.png b/thank.png new file mode 100644 index 0000000000000000000000000000000000000000..d92841a63533d4e047f4577bc6598bfe5aae5411 GIT binary patch literal 3470 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 Date: Fri, 25 Aug 2023 08:45:13 +0000 Subject: [PATCH 02/14] update README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 艾竹 --- Images/微信图片_20230825164357.png | Bin 0 -> 2782 bytes README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 Images/微信图片_20230825164357.png diff --git a/Images/微信图片_20230825164357.png b/Images/微信图片_20230825164357.png new file mode 100644 index 0000000000000000000000000000000000000000..7db792e1b0c066c920959d6d85442504df53abf4 GIT binary patch literal 2782 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 kUnpD Date: Fri, 25 Aug 2023 08:46:01 +0000 Subject: [PATCH 03/14] update README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 艾竹 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5618f31..afeda10 100644 --- a/README.md +++ b/README.md @@ -746,6 +746,8 @@ nuget地址:![输入图片说明](Images/nuget.png) +## 捐赠列表:![输入图片说明](Images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230825164357.png) + 相关链接地址: Fluent.Ribbon: https://github.com/fluentribbon/Fluent.Ribbon @@ -756,7 +758,6 @@ nuget地址:![输入图片说明](Images/nuget.png) QQ技术交流群:51286643(如果您还喜欢,帮忙点个星,谢谢) - 特别感谢:https://dotnet9.com/ 的站长:dotnet9。 - 鸣谢列表:![输入图片说明](Images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230825164357.png) + 特别感谢:https://dotnet9.com/ 的站长:dotnet9。 有想加入开发的朋友可以联系我。 \ No newline at end of file From a896426adcd9c09b1c159de19dc436d1cc50b11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Fri, 25 Aug 2023 08:46:32 +0000 Subject: [PATCH 04/14] update README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 艾竹 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index afeda10..0af4e80 100644 --- a/README.md +++ b/README.md @@ -746,7 +746,9 @@ nuget地址:![输入图片说明](Images/nuget.png) -## 捐赠列表:![输入图片说明](Images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230825164357.png) +## 捐赠列表: + +![输入图片说明](Images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230825164357.png) 相关链接地址: From d4c347b19e23ee875c7e8894c6e698ade1ea1f64 Mon Sep 17 00:00:00 2001 From: kwai Date: Fri, 25 Aug 2023 19:06:39 +0800 Subject: [PATCH 05/14] block --- .../Helpers/BitmapHelper.cs | 41 +++++++++++++++++++ .../Serializables/SelectableItemBase.cs | 18 ++++++++ 2 files changed, 59 insertions(+) diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs index 5ab7b2b..dcf6dc2 100644 --- a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs @@ -192,5 +192,46 @@ namespace AIStudio.Wpf.DiagramDesigner } } + public static string ToBase64String(this BitmapImage bitmap) + { + byte[] bytearray = null; + Stream smarket = bitmap.StreamSource; + if (smarket != null && smarket.Length > 0) + { + //设置当前位置 + smarket.Position = 0; + using (BinaryReader br = new BinaryReader(smarket)) + { + bytearray = br.ReadBytes((int)smarket.Length); + } + } + return Convert.ToBase64String(bytearray); + } + + public static BitmapImage ToBitmapImage(this string base64String, int width = 0, int height =0) + { + if (string.IsNullOrEmpty(base64String)) + return null; + + try + { + var byteArray = Convert.FromBase64String(base64String); + BitmapImage bitmapImage = null; + bitmapImage = new BitmapImage(); + bitmapImage.BeginInit(); + bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; + bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + bitmapImage.DecodePixelWidth = width;//需要缩略图的解码宽度 + bitmapImage.DecodePixelHeight = height;//缩略图的解码高度 + bitmapImage.StreamSource = new MemoryStream(byteArray); + bitmapImage.EndInit(); + + return bitmapImage; + } + catch + { + return null; + } + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/SelectableItemBase.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/SelectableItemBase.cs index ce71f1c..6278390 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/SelectableItemBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/SelectableItemBase.cs @@ -12,6 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; +using System.Windows.Media.Imaging; using System.Xml; using System.Xml.Serialization; @@ -646,6 +647,23 @@ namespace AIStudio.Wpf.DiagramDesigner return new Matrix(double.Parse(pieces[0]), double.Parse(pieces[1]), double.Parse(pieces[2]), double.Parse(pieces[3]), double.Parse(pieces[4]), double.Parse(pieces[5])); } + public static string SerializeBitmapImage(BitmapImage bitmapImage) + { + return bitmapImage.ToBase64String(); + } + + public static BitmapImage DeserializeBitmapImage(string bitmapImagestring) + { + try + { + return bitmapImagestring.ToBitmapImage(); + } + catch + { + return null; + } + } + public static string SerializeObject(object obj, string serializableType = null) { if (serializableType?.ToLower() == ".xml") From 045a724ee208ce08c5ecfd8d18dbcbeba74159c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sat, 26 Aug 2023 15:02:43 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E4=B8=80=E7=82=B9=E5=B0=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=92=8C=E4=B8=80=E7=82=B9=E5=B0=8Fbug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/PageViewModel.cs | 70 +--- AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml | 8 +- .../Controls/DiagramTabControl.cs | 318 ++++++++++++++++++ .../Controls/DragThumb.cs | 2 +- .../Controls/MyTabControl.cs | 46 --- .../PathGenerators/PathGenerators.Boundary.cs | 4 +- .../BaseViewModel/DiagramViewModel.cs | 3 +- .../BlockViewModel/BlockDiagramViewModel.cs | 5 + 8 files changed, 342 insertions(+), 114 deletions(-) create mode 100644 AIStudio.Wpf.DiagramDesigner/Controls/DiagramTabControl.cs delete mode 100644 AIStudio.Wpf.DiagramDesigner/Controls/MyTabControl.cs diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs index e8ca2dc..738179b 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs @@ -391,36 +391,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels List viewModels = new List(); foreach (var diagramItem in diagramDocument.DiagramItems) { - var viewModel = GetDiagramViewModel(diagramItem.Name, diagramItem.DiagramType, false); - viewModel.Init(diagramItem); - - foreach (var diagramItemData in diagramItem.DesignerItems) - { - Type type = TypeHelper.GetType(diagramItemData.ModelTypeName); - DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, viewModel, diagramItemData, ext) as DesignerItemViewModelBase; - viewModel.Items.Add(itemBase); - } - - foreach (var connection in diagramItem.Connections) - { - Type type = TypeHelper.GetType(connection.SerializableTypeName); - var connectionItem = SerializeHelper.DeserializeObject(type, connection.SerializableString, ext) as ConnectionItem; - - connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName); - connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName); - DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SourceId, connectionItem.SourceType); - ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation; - FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceInnerPoint); - - DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SinkId, connectionItem.SinkType); - ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation; - FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkInnerPoint); - - ConnectionViewModel connectionVM = new ConnectionViewModel(viewModel, sourceConnectorInfo, sinkConnectorInfo, connectionItem); - connectionVM.Id = Guid.NewGuid(); - viewModel.Items.Add(connectionVM); - } - + var viewModel = GetDiagramViewModel(diagramItem, ext); viewModels.Add(viewModel); } DiagramViewModels = new ObservableCollection(viewModels); @@ -498,6 +469,11 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels InitDiagramViewModel(); } + protected virtual DiagramViewModel GetDiagramViewModel(DiagramItem diagramItem, string ext) + { + return new BlockDiagramViewModel(diagramItem, ext); + } + protected virtual DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType, bool initNew) { return new BlockDiagramViewModel() { Name = name ?? NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType }; @@ -513,37 +489,11 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels var selectedDesignerItems = viewModel.Items.OfType(); var selectedConnections = viewModel.Items.OfType(); - 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.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), "页-"); - viewModel = GetDiagramViewModel(NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), diagramItem.DiagramType, false); - viewModel.Init(diagramItem); - - foreach (var diagramItemData in diagramItem.DesignerItems) - { - Type type = TypeHelper.GetType(diagramItemData.ModelTypeName); - DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, viewModel, diagramItemData, "json") as DesignerItemViewModelBase; - viewModel.Items.Add(itemBase); - } - - foreach (var connection in diagramItem.Connections) - { - var connectionItem = JsonConvert.DeserializeObject(connection.SerializableString); - - connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName); - connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName); - DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SourceId, connectionItem.SourceType); - ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation; - FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceIsPortless); - - DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SinkId, connectionItem.SinkType); - ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation; - FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkIsPortless); - - ConnectionViewModel connectionVM = new ConnectionViewModel(viewModel, sourceConnectorInfo, sinkConnectorInfo, connectionItem); - connectionVM.Id = Guid.NewGuid(); - viewModel.Items.Add(connectionVM); - } + viewModel = GetDiagramViewModel(diagramItem, ".json"); DiagramViewModels.Add(viewModel); DiagramViewModel = viewModel; diff --git a/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml b/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml index 19936cc..ed9f781 100644 --- a/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml +++ b/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml @@ -2660,14 +2660,14 @@ - - + - - + + diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DiagramTabControl.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DiagramTabControl.cs new file mode 100644 index 0000000..ecf9af3 --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DiagramTabControl.cs @@ -0,0 +1,318 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Markup; + +namespace AIStudio.Wpf.DiagramDesigner.Controls +{ + //public class DiagramTabControl : TabControl + //{ + // public DiagramTabControl() + // { + // // Attach event handler to TabControl.SelectionChanged event + // this.SelectionChanged += DiagramTabControl_SelectionChanged; + // this.IsVisibleChanged += DiagramTabControl_IsVisibleChanged; + // } + + // private void DiagramTabControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) + // { + // foreach (var item in this.Items) + // { + // if (item is DiagramViewModel viewModel) + // { + // viewModel.ShowSearch = false; + // } + // } + // } + + // private void DiagramTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) + // { + // // Iterate through all TabItems and manually set the Visibility property + // foreach (var item in this.Items) + // { + // if (item is DiagramViewModel viewModel) + // { + // if (item != this.SelectedItem) + // { + // viewModel.ShowSearch = false; + // } + // } + // } + // } + //} + + /// + /// Attached properties for persistent tab control + /// + /// By default WPF TabControl bound to an ItemsSource destroys visual state of invisible tabs. + /// Set ikriv:DiagramTabControl.IsCached="True" to preserve visual state of each tab. + /// + public static class DiagramTabControl + { + public static bool GetIsCached(DependencyObject obj) + { + return (bool)obj.GetValue(IsCachedProperty); + } + + public static void SetIsCached(DependencyObject obj, bool value) + { + obj.SetValue(IsCachedProperty, value); + } + + /// + /// Controls whether tab content is cached or not + /// + /// When DiagramTabControl.IsCached is true, visual state of each tab is preserved (cached), even when the tab is hidden + public static readonly DependencyProperty IsCachedProperty = + DependencyProperty.RegisterAttached("IsCached", typeof(bool), typeof(DiagramTabControl), new UIPropertyMetadata(false, OnIsCachedChanged)); + + + public static DataTemplate GetTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(TemplateProperty); + } + + public static void SetTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(TemplateProperty, value); + } + + /// + /// Used instead of TabControl.ContentTemplate for cached tabs + /// + public static readonly DependencyProperty TemplateProperty = + DependencyProperty.RegisterAttached("Template", typeof(DataTemplate), typeof(DiagramTabControl), new UIPropertyMetadata(null)); + + + public static DataTemplateSelector GetTemplateSelector(DependencyObject obj) + { + return (DataTemplateSelector)obj.GetValue(TemplateSelectorProperty); + } + + public static void SetTemplateSelector(DependencyObject obj, DataTemplateSelector value) + { + obj.SetValue(TemplateSelectorProperty, value); + } + + /// + /// Used instead of TabControl.ContentTemplateSelector for cached tabs + /// + public static readonly DependencyProperty TemplateSelectorProperty = + DependencyProperty.RegisterAttached("TemplateSelector", typeof(DataTemplateSelector), typeof(DiagramTabControl), new UIPropertyMetadata(null)); + + [EditorBrowsable(EditorBrowsableState.Never)] + public static TabControl GetInternalTabControl(DependencyObject obj) + { + return (TabControl)obj.GetValue(InternalTabControlProperty); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public static void SetInternalTabControl(DependencyObject obj, TabControl value) + { + obj.SetValue(InternalTabControlProperty, value); + } + + // Using a DependencyProperty as the backing store for InternalTabControl. This enables animation, styling, binding, etc... + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly DependencyProperty InternalTabControlProperty = + DependencyProperty.RegisterAttached("InternalTabControl", typeof(TabControl), typeof(DiagramTabControl), new UIPropertyMetadata(null, OnInternalTabControlChanged)); + + + [EditorBrowsable(EditorBrowsableState.Never)] + public static ContentControl GetInternalCachedContent(DependencyObject obj) + { + return (ContentControl)obj.GetValue(InternalCachedContentProperty); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public static void SetInternalCachedContent(DependencyObject obj, ContentControl value) + { + obj.SetValue(InternalCachedContentProperty, value); + } + + // Using a DependencyProperty as the backing store for InternalCachedContent. This enables animation, styling, binding, etc... + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly DependencyProperty InternalCachedContentProperty = + DependencyProperty.RegisterAttached("InternalCachedContent", typeof(ContentControl), typeof(DiagramTabControl), new UIPropertyMetadata(null)); + + [EditorBrowsable(EditorBrowsableState.Never)] + public static object GetInternalContentManager(DependencyObject obj) + { + return (object)obj.GetValue(InternalContentManagerProperty); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public static void SetInternalContentManager(DependencyObject obj, object value) + { + obj.SetValue(InternalContentManagerProperty, value); + } + + // Using a DependencyProperty as the backing store for InternalContentManager. This enables animation, styling, binding, etc... + public static readonly DependencyProperty InternalContentManagerProperty = + DependencyProperty.RegisterAttached("InternalContentManager", typeof(object), typeof(DiagramTabControl), new UIPropertyMetadata(null)); + + private static void OnIsCachedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) + { + if (obj == null) return; + + var tabControl = obj as TabControl; + if (tabControl == null) + { + throw new InvalidOperationException("Cannot set DiagramTabControl.IsCached on object of type " + args.NewValue.GetType().Name + + ". Only objects of type TabControl can have DiagramTabControl.IsCached property."); + } + + bool newValue = (bool)args.NewValue; + + if (!newValue) + { + if (args.OldValue != null && ((bool)args.OldValue)) + { + throw new NotImplementedException("Cannot change DiagramTabControl.IsCached from True to False. Turning tab caching off is not implemented"); + } + + return; + } + + EnsureContentTemplateIsNull(tabControl); + tabControl.ContentTemplate = CreateContentTemplate(); + EnsureContentTemplateIsNotModified(tabControl); + } + + private static DataTemplate CreateContentTemplate() + { + const string xaml = + ""; + + var context = new ParserContext(); + + context.XamlTypeMapper = new XamlTypeMapper(new string[0]); + context.XamlTypeMapper.AddMappingProcessingInstruction("b", typeof(DiagramTabControl).Namespace, typeof(DiagramTabControl).Assembly.FullName); + + context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); + context.XmlnsDictionary.Add("b", "b"); + + var template = (DataTemplate)XamlReader.Parse(xaml, context); + return template; + } + + private static void OnInternalTabControlChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) + { + if (obj == null) return; + var container = obj as Decorator; + + if (container == null) + { + var message = "Cannot set DiagramTabControl.InternalTabControl on object of type " + obj.GetType().Name + + ". Only controls that derive from Decorator, such as Border can have a DiagramTabControl.InternalTabControl."; + throw new InvalidOperationException(message); + } + + if (args.NewValue == null) return; + if (!(args.NewValue is TabControl)) + { + throw new InvalidOperationException("Value of DiagramTabControl.InternalTabControl cannot be of type " + args.NewValue.GetType().Name + ", it must be of type TabControl"); + } + + var tabControl = (TabControl)args.NewValue; + var contentManager = GetContentManager(tabControl, container); + contentManager.UpdateSelectedTab(); + } + + private static ContentManager GetContentManager(TabControl tabControl, Decorator container) + { + var contentManager = (ContentManager)GetInternalContentManager(tabControl); + if (contentManager != null) + { + /* + * Content manager already exists for the tab control. This means that tab content template is applied + * again, and new instance of the Border control (container) has been created. The old container + * referenced by the content manager is no longer visible and needs to be replaced + */ + contentManager.ReplaceContainer(container); + } + else + { + // create content manager for the first time + contentManager = new ContentManager(tabControl, container); + SetInternalContentManager(tabControl, contentManager); + } + + return contentManager; + } + + private static void EnsureContentTemplateIsNull(TabControl tabControl) + { + if (tabControl.ContentTemplate != null) + { + throw new InvalidOperationException("TabControl.ContentTemplate value is not null. If DiagramTabControl.IsCached is True, use DiagramTabControl.Template instead of ContentTemplate"); + } + } + + private static void EnsureContentTemplateIsNotModified(TabControl tabControl) + { + var descriptor = DependencyPropertyDescriptor.FromProperty(TabControl.ContentTemplateProperty, typeof(TabControl)); + descriptor.AddValueChanged(tabControl, (sender, args) => + { + throw new InvalidOperationException("Cannot assign to TabControl.ContentTemplate when DiagramTabControl.IsCached is True. Use DiagramTabControl.Template instead"); + }); + } + + public class ContentManager + { + TabControl _tabControl; + Decorator _border; + + public ContentManager(TabControl tabControl, Decorator border) + { + _tabControl = tabControl; + _border = border; + _tabControl.SelectionChanged += (sender, args) => { UpdateSelectedTab(); }; + } + + public void ReplaceContainer(Decorator newBorder) + { + if (Object.ReferenceEquals(_border, newBorder)) return; + + _border.Child = null; // detach any tab content that old border may hold + _border = newBorder; + } + + public void UpdateSelectedTab() + { + _border.Child = GetCurrentContent(); + } + + private ContentControl GetCurrentContent() + { + var item = _tabControl.SelectedItem; + if (item == null) return null; + + var tabItem = _tabControl.ItemContainerGenerator.ContainerFromItem(item); + if (tabItem == null) return null; + + var cachedContent = DiagramTabControl.GetInternalCachedContent(tabItem); + if (cachedContent == null) + { + cachedContent = new ContentControl + { + DataContext = item, + ContentTemplate = DiagramTabControl.GetTemplate(_tabControl), + ContentTemplateSelector = DiagramTabControl.GetTemplateSelector(_tabControl) + }; + + cachedContent.SetBinding(ContentControl.ContentProperty, new Binding()); + DiagramTabControl.SetInternalCachedContent(tabItem, cachedContent); + } + + return cachedContent; + } + } + } +} \ No newline at end of file diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs index f9b11ee..e543d0d 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs @@ -213,7 +213,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { - base.OnPreviewMouseLeftButtonDown(e); + base.OnPreviewMouseLeftButtonUp(e); if (EditClickCount == 1) { diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/MyTabControl.cs b/AIStudio.Wpf.DiagramDesigner/Controls/MyTabControl.cs deleted file mode 100644 index e50a061..0000000 --- a/AIStudio.Wpf.DiagramDesigner/Controls/MyTabControl.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; - -namespace AIStudio.Wpf.DiagramDesigner.Controls -{ - public class DiagramTabControl : TabControl - { - public DiagramTabControl() - { - // Attach event handler to TabControl.SelectionChanged event - this.SelectionChanged += DiagramTabControl_SelectionChanged; - this.IsVisibleChanged += DiagramTabControl_IsVisibleChanged; - } - - private void DiagramTabControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) - { - foreach (var item in this.Items) - { - if (item is DiagramViewModel viewModel) - { - viewModel.ShowSearch = false; - } - } - } - - private void DiagramTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - // Iterate through all TabItems and manually set the Visibility property - foreach (var item in this.Items) - { - if (item is DiagramViewModel viewModel) - { - if (item != this.SelectedItem) - { - viewModel.ShowSearch = false; - } - } - } - } - } -} \ No newline at end of file diff --git a/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Boundary.cs b/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Boundary.cs index b81fb9e..58ac7fc 100644 --- a/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Boundary.cs +++ b/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Boundary.cs @@ -33,8 +33,8 @@ namespace AIStudio.Wpf.DiagramDesigner private static PointBase[] GetRouteWithMiddlePoints(IDiagramViewModel _, ConnectionViewModel link, PointBase[] route) { var middle = GetMiddlePoints( - link.SourceConnectorInfoFully.MiddlePosition, - link.SourceConnectorInfoFully.Orientation, + link.SourceConnectorInfo.MiddlePosition, + link.SourceConnectorInfo.Orientation, link.SinkConnectorInfo.MiddlePosition, link.IsFullConnection ? link.SinkConnectorInfoFully.Orientation : (link.SinkConnectorInfo.MiddlePosition.Y >= link.SourceConnectorInfo.MiddlePosition.Y ? ConnectorOrientation.Top : ConnectorOrientation.Bottom), _.DiagramOption.LayoutOption.GridCellSize, diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index e8bc873..f09e824 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -814,7 +814,7 @@ namespace AIStudio.Wpf.DiagramDesigner BuildMenuOptions(); } - public DiagramViewModel(DiagramItem diagramItem, string ext) : this() + public DiagramViewModel(DiagramItem diagramItem, string ext =".json") : this() { Init(diagramItem); @@ -849,6 +849,7 @@ namespace AIStudio.Wpf.DiagramDesigner public void Init(DiagramItem diagramItem) { DiagramType = diagramItem.DiagramType; + Name = diagramItem.Name; DiagramOption.LayoutOption.ShowGrid = diagramItem.ShowGrid; DiagramOption.LayoutOption.PhysicalGridCellSize = diagramItem.PhysicalGridCellSize; DiagramOption.LayoutOption.CellHorizontalAlignment = diagramItem.CellHorizontalAlignment; diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDiagramViewModel.cs index e963fb7..ecab8d6 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDiagramViewModel.cs @@ -14,6 +14,11 @@ namespace AIStudio.Wpf.DiagramDesigner { } + public BlockDiagramViewModel(DiagramItem diagramItem, string ext) : base(diagramItem, ext) + { + + } + #region private ICommand _addNextCommand; public ICommand AddNextCommand From d50ec045ea4f299c970d510f32b6f1e53964eb32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sat, 26 Aug 2023 21:30:31 +0800 Subject: [PATCH 07/14] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/PageViewModel.cs | 16 +---- .../Helpers/BitmapHelper.cs | 61 +++++++++++++++---- .../Container/BlockItemsContainerInfoItem.cs | 9 ++- .../Container/ConstParameterItem.cs | 31 ++++++++++ .../Models/Serializables/DiagramItem.cs | 30 ++++++++- .../Models/Values/ConstParameter.cs | 8 +++ .../Container/BlockItemsContainerInfo.cs | 5 +- .../BaseViewModel/DiagramViewModel.cs | 3 +- 8 files changed, 130 insertions(+), 33 deletions(-) create mode 100644 AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs index 738179b..8346818 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs @@ -426,15 +426,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels foreach (var viewModel in DiagramViewModels) { - DiagramItem diagramItem = new DiagramItem(viewModel); - - var selectedDesignerItems = viewModel.Items.OfType(); - var selectedConnections = viewModel.Items.OfType(); - - 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(); - - + DiagramItem diagramItem = new DiagramItem(viewModel); diagramDocument.DiagramItems.Add(diagramItem); } @@ -485,12 +477,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels { var viewModel = DiagramViewModel; DiagramItem diagramItem = new DiagramItem(viewModel); - - var selectedDesignerItems = viewModel.Items.OfType(); - var selectedConnections = viewModel.Items.OfType(); - - 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), "页-"); viewModel = GetDiagramViewModel(diagramItem, ".json"); diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs index dcf6dc2..b33d7ed 100644 --- a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs @@ -143,7 +143,7 @@ namespace AIStudio.Wpf.DiagramDesigner { var bitmap = (imageBrush.ImageSource as BitmapImage); byte[] bytearray = null; - Stream smarket = bitmap.StreamSource; + Stream smarket = bitmap.StreamSource; if (smarket != null && smarket.Length > 0) { //设置当前位置 @@ -194,21 +194,27 @@ namespace AIStudio.Wpf.DiagramDesigner public static string ToBase64String(this BitmapImage bitmap) { - byte[] bytearray = null; - Stream smarket = bitmap.StreamSource; - if (smarket != null && smarket.Length > 0) - { - //设置当前位置 - smarket.Position = 0; - using (BinaryReader br = new BinaryReader(smarket)) - { - bytearray = br.ReadBytes((int)smarket.Length); - } - } + //byte[] bytearray = null; + //Stream smarket = bitmap.StreamSource; + //if (smarket != null && smarket.Length > 0) + //{ + // //设置当前位置 + // smarket.Position = 0; + // using (BinaryReader br = new BinaryReader(smarket)) + // { + // 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); } - 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)) return null; @@ -233,5 +239,34 @@ namespace AIStudio.Wpf.DiagramDesigner 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; + + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/BlockItemsContainerInfoItem.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/BlockItemsContainerInfoItem.cs index 1e624a7..2798633 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/BlockItemsContainerInfoItem.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/BlockItemsContainerInfoItem.cs @@ -23,6 +23,7 @@ namespace AIStudio.Wpf.DiagramDesigner this.ChildFlag = viewmodel.ChildFlag; this.PhysicalItemWidth = viewmodel.PhysicalItemWidth; this.PhysicalItemHeight = viewmodel.PhysicalItemHeight; + this.Parameter = new ConstParameterItem(viewmodel.Parameter); Children = new List(viewmodel.Children.Select(p => new BlockDesignerItem(p))); } @@ -52,10 +53,16 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } + [XmlElement] + public ConstParameterItem Parameter + { + get; set; + } + [XmlArray] public List Children { get; set; - } + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs new file mode 100644 index 0000000..dcba14d --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs @@ -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(); + } + } +} diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DiagramItem.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DiagramItem.cs index 74105a5..09b0b02 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DiagramItem.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DiagramItem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows; using System.Windows.Media; 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; DiagramType = diagramView.DiagramType; @@ -30,9 +31,16 @@ namespace AIStudio.Wpf.DiagramDesigner PageSizeType = diagramView.DiagramOption.LayoutOption.PageSizeType; PhysicalGridMarginSize = diagramView.DiagramOption.LayoutOption.PhysicalGridMarginSize; GridColor = diagramView.DiagramOption.LayoutOption.GridColor; + PageBackground = diagramView.DiagramOption.LayoutOption.PageBackground; AllowDrop = diagramView.DiagramOption.LayoutOption.AllowDrop; Thumbnail = diagramView.Thumbnail.ToBase64String(); + + var selectedDesignerItems = diagramView.Items.OfType(); + var selectedConnections = diagramView.Items.OfType(); + + 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] @@ -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] public bool AllowDrop { diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs b/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs index 4f375b8..5d9f111 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs @@ -4,7 +4,15 @@ namespace AIStudio.Wpf.DiagramDesigner { public class ConstParameter : BindableBase, IParameter { + public ConstParameter() + { + } + public ConstParameter(ConstParameterItem item) + { + Text = item.Text; + Value = item.Value.ToString(); + } private string _text; diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs index a704de7..c0e10dc 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs @@ -65,6 +65,7 @@ namespace AIStudio.Wpf.DiagramDesigner this.ChildFlag = designer.ChildFlag; this.PhysicalItemWidth = designer.PhysicalItemWidth; this.PhysicalItemHeight = designer.PhysicalItemHeight; + this.Parameter = new ConstParameter(designer.Parameter); if (designer.Children != null) { foreach (var child in designer.Children) @@ -178,8 +179,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private IParameter _parameter; - public IParameter Parameter + private ConstParameter _parameter; + public ConstParameter Parameter { get { diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index f09e824..de24da7 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -859,7 +859,8 @@ namespace AIStudio.Wpf.DiagramDesigner DiagramOption.LayoutOption.PageSizeType = diagramItem.PageSizeType; DiagramOption.LayoutOption.PhysicalGridMarginSize = diagramItem.PhysicalGridMarginSize; 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); Init(true); From 476d0c57d3b78602884db03c9ce926db00d94e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 27 Aug 2023 15:09:03 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E5=A3=B0=E9=9F=B3=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helpers/BitmapHelper.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs index b33d7ed..5d361b4 100644 --- a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; +using System.IO.Pipes; using System.Runtime.InteropServices.ComTypes; using System.Windows; using System.Windows.Media.Imaging; @@ -268,5 +269,52 @@ namespace AIStudio.Wpf.DiagramDesigner return bitmapImage; } + + public static string ToBase64String(this Stream stream) + { + byte[] bytearray = new byte[stream.Length]; + stream.Seek(0, SeekOrigin.Begin); + stream.Read(bytearray, 0, bytearray.Length); + + return Convert.ToBase64String(bytearray); + } + + public static MemoryStream ToMemoryStream(this string base64String, int width = 0, int height = 0) + { + if (string.IsNullOrEmpty(base64String)) + return null; + + try + { + var byteArray = Convert.FromBase64String(base64String); + var stream = new MemoryStream(byteArray); + stream.Seek(0, SeekOrigin.Begin); + + return stream; + } + catch + { + return null; + } + } + + public static FileStream ToFileStream(this string base64String, string filename, int width = 0, int height = 0) + { + if (string.IsNullOrEmpty(base64String)) + return null; + + try + { + var byteArray = Convert.FromBase64String(base64String); + FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); + fs.Write(byteArray, 0, byteArray.Length); + fs.Seek(0, SeekOrigin.Begin); + return fs; + } + catch + { + return null; + } + } } } From 2ffc7b3e52c835d3997c567023e71f20136874ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 27 Aug 2023 16:02:28 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E6=8B=96=E6=8B=BD=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=A0=8F=E4=BF=A1=E6=81=AF=E5=B8=A6=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AttachedProperties/DragAndDropProps.cs | 10 ++++---- .../Controls/DesignerCanvas.cs | 24 +++++++++++++++++++ .../Container/ConstParameterItem.cs | 4 ++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/AIStudio.Wpf.DiagramDesigner/AttachedProperties/DragAndDropProps.cs b/AIStudio.Wpf.DiagramDesigner/AttachedProperties/DragAndDropProps.cs index 526f05d..8c59fdf 100644 --- a/AIStudio.Wpf.DiagramDesigner/AttachedProperties/DragAndDropProps.cs +++ b/AIStudio.Wpf.DiagramDesigner/AttachedProperties/DragAndDropProps.cs @@ -86,11 +86,11 @@ namespace AIStudio.Wpf.DiagramDesigner dataObject.Icon = toolBoxData.Icon; dataObject.Text = toolBoxData.Text; dataObject.ColorViewModel = toolBoxData.ColorViewModel; - //if (toolBoxData.Addition is DesignerItemViewModelBase designerItemViewModelBase) - //{ - // dataObject.DesignerItem = designerItemViewModelBase.ToSerializableItem(); - //} - //else + if (toolBoxData.Addition is DesignerItemViewModelBase designerItemViewModelBase) + { + dataObject.DesignerItem = designerItemViewModelBase.ToSerializableItem(); + } + else { dataObject.DesignerItem = toolBoxData.Addition; } diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index eaf0582..715a65a 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -6,6 +6,7 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Resources; +using AIStudio.Wpf.DiagramDesigner.Helpers; using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.ViewModels; using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel; @@ -714,6 +715,29 @@ namespace AIStudio.Wpf.DiagramDesigner } _viewModel.AddCommand.Execute(designerItems); } + else if (dragObject.DesignerItem is SerializableItem serializableItem) + { + Type type = TypeHelper.GetType(serializableItem.ModelTypeName); + DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, _viewModel, serializableItem, ".json") as DesignerItemViewModelBase; + itemBase.Left = Math.Max(0, position.X - itemBase.GetItemWidth() / 2); + itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2); + if (dragObject.DesiredSize != null) + { + itemBase.ItemWidth = dragObject.DesiredSize.Value.Width; + itemBase.ItemHeight = dragObject.DesiredSize.Value.Height; + } + if (dragObject.DesiredMinSize != null) + { + itemBase.MinItemWidth = dragObject.DesiredMinSize.Value.Width; + itemBase.MinItemHeight = dragObject.DesiredMinSize.Value.Height; + } + _viewModel.AddCommand.Execute(itemBase); + + if (itemBase is BlockDesignerItemViewModel block) + { + (_viewModel as IBlockDiagramViewModel).FinishNearBlock(new System.Collections.Generic.List { block }); + } + } else { DesignerItemViewModelBase itemBase = null; diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs index dcba14d..ab2f3c7 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Container/ConstParameterItem.cs @@ -24,8 +24,8 @@ namespace AIStudio.Wpf.DiagramDesigner public ConstParameterItem(ConstParameter viewmodel) { - Text = viewmodel.Text; - Value = viewmodel.Value?.ToString(); + Text = viewmodel?.Text; + Value = viewmodel?.Value?.ToString(); } } } From b83f4fad7f9a209ad1c07bb1447d5d6c25464566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 27 Aug 2023 23:03:07 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AIStudio.Wpf.DiagramDesigner.csproj | 1 + .../Models/Values/ConstParameter.cs | 2 +- .../Container/BlockItemsContainerInfo.cs | 10 ++++++++++ .../BlockViewModel/BlockDesignerItemViewModel.cs | 13 +++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj b/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj index 5c56737..83c64dd 100644 --- a/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj +++ b/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj @@ -31,6 +31,7 @@ + diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs b/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs index 5d9f111..5602648 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Values/ConstParameter.cs @@ -11,7 +11,7 @@ namespace AIStudio.Wpf.DiagramDesigner public ConstParameter(ConstParameterItem item) { Text = item.Text; - Value = item.Value.ToString(); + Value = item.Value?.ToString(); } private string _text; diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs index c0e10dc..b0d4df7 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs @@ -351,5 +351,15 @@ namespace AIStudio.Wpf.DiagramDesigner return null; } } + + public override void Dispose() + { + base.Dispose(); + + foreach (var child in Children) + { + child.Dispose(); + } + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModel.cs index efb7a0a..5b2f417 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModel.cs @@ -530,6 +530,19 @@ namespace AIStudio.Wpf.DiagramDesigner return null; } #endregion + + public override void Dispose() + { + base.Dispose(); + + if (ParentContainer == null) + { + foreach (var container in Containers) + { + container.Dispose(); + } + } + } } #region 扩展 From 2f12bfa82913656dd546858937159cf3fc4b6ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 3 Sep 2023 16:48:56 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs | 11 +++++++++++ .../Services/IUIVisualizerService.cs | 2 +- .../Services/WPFUIVisualizerService.cs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs index 5d361b4..92d7c75 100644 --- a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Drawing; using System.Drawing.Imaging; using System.IO; @@ -316,5 +317,15 @@ namespace AIStudio.Wpf.DiagramDesigner return null; } } + + public static Stream CopyStream(this Stream stream) + { + byte[] bytearray = new byte[stream.Length]; + stream.Seek(0, SeekOrigin.Begin); + stream.Read(bytearray, 0, bytearray.Length); + + var destination = new MemoryStream(bytearray); + return destination; + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/Services/IUIVisualizerService.cs b/AIStudio.Wpf.DiagramDesigner/Services/IUIVisualizerService.cs index 375dc04..5025f5f 100644 --- a/AIStudio.Wpf.DiagramDesigner/Services/IUIVisualizerService.cs +++ b/AIStudio.Wpf.DiagramDesigner/Services/IUIVisualizerService.cs @@ -17,7 +17,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Services /// /// Object state to associate with the dialog /// True/False if UI is displayed. - bool? ShowDialog(object dataContextForPopup); + bool? ShowDialog(object dataContextForPopup, bool buttonVisable = true); /// /// This method displays a modal dialog associated with the given key. diff --git a/AIStudio.Wpf.DiagramDesigner/Services/WPFUIVisualizerService.cs b/AIStudio.Wpf.DiagramDesigner/Services/WPFUIVisualizerService.cs index b5c9058..5f209e0 100644 --- a/AIStudio.Wpf.DiagramDesigner/Services/WPFUIVisualizerService.cs +++ b/AIStudio.Wpf.DiagramDesigner/Services/WPFUIVisualizerService.cs @@ -12,7 +12,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Services /// /// Object state to associate with the dialog /// True/False if UI is displayed. - public bool? ShowDialog(object dataContextForPopup) + public bool? ShowDialog(object dataContextForPopup, bool buttonVisable = true) { Window win = new PopupWindow(); win.DataContext = dataContextForPopup; From 0badb714a08682470c08b169745d05102ef06bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 3 Sep 2023 16:57:02 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E6=94=B9=E4=B8=8B=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8E=A7=E4=BB=B6=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml | 4 ++-- .../AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs | 2 +- Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml | 2 +- Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml b/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml index fb4852f..e6f4b68 100644 --- a/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml +++ b/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml @@ -18,13 +18,13 @@ - + - + diff --git a/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs b/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs index 832daeb..8c81be6 100644 --- a/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs +++ b/Extensions/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs @@ -18,7 +18,7 @@ namespace AIStudio.Wpf.Flowchart.Controls /// FlowchartEditor.xaml 的交互逻辑 /// [TemplatePart(Name = PART_DiagramControl, Type = typeof(DiagramControl))] - public partial class FlowchartEditor : UserControl + public partial class FlowchartEditor : Control { public const string PART_DiagramControl = "PART_DiagramControl"; private DiagramControl _diagramControl; diff --git a/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml b/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml index 04556a1..567570e 100644 --- a/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml +++ b/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml @@ -21,7 +21,7 @@ - + diff --git a/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml.cs b/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml.cs index 39c7f63..dec24f0 100644 --- a/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml.cs +++ b/Extensions/AIStudio.Wpf.Mind/Controls/MindEditor.xaml.cs @@ -21,7 +21,7 @@ namespace AIStudio.Wpf.Mind.Controls [TemplatePart(Name = PART_DiagramControl, Type = typeof(DiagramControl))] [TemplatePart(Name = PART_ContentControl, Type = typeof(ContentControl))] [TemplatePart(Name = PART_SearchControl, Type = typeof(Border))] - public partial class MindEditor : UserControl + public partial class MindEditor : Control { public const string PART_DiagramControl = "PART_DiagramControl"; public const string PART_ContentControl = "PART_ContentControl"; From 2b8fe03f250101028802f79b8e2bca5512c5e89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 3 Sep 2023 21:11:23 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E6=80=9D=E7=BB=B4=E5=AF=BC=E5=9B=BE?= =?UTF-8?q?=E6=89=93=E5=BC=80i=E6=8A=A5=E9=94=99=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...udio.Wpf.DiagramApp_bypphsza_wpftmp.csproj | 1040 +++++++++++++++++ .../ViewModels/MindViewModel.cs | 13 +- .../ViewModels/PageViewModel.cs | 4 + 3 files changed, 1053 insertions(+), 4 deletions(-) create mode 100644 AIStudio.Wpf.DiagramApp/AIStudio.Wpf.DiagramApp_bypphsza_wpftmp.csproj diff --git a/AIStudio.Wpf.DiagramApp/AIStudio.Wpf.DiagramApp_bypphsza_wpftmp.csproj b/AIStudio.Wpf.DiagramApp/AIStudio.Wpf.DiagramApp_bypphsza_wpftmp.csproj new file mode 100644 index 0000000..7163875 --- /dev/null +++ b/AIStudio.Wpf.DiagramApp/AIStudio.Wpf.DiagramApp_bypphsza_wpftmp.csproj @@ -0,0 +1,1040 @@ + + + AIStudio.Wpf.DiagramApp + obj\Debug\ + obj\ + F:\aistudio.-wpf.-diagram\AIStudio.Wpf.DiagramApp\obj\ + <_TargetAssemblyProjectName>AIStudio.Wpf.DiagramApp + + + + WinExe + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + 8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs index 8cb473d..4695b61 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs @@ -22,15 +22,20 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels { public MindViewModel(string title, string status, DiagramType diagramType, MindType mindType) : base(title, status, diagramType, mindType.ToString()) { - + } public MindViewModel(string filename, DiagramDocument diagramDocument) : base(filename, diagramDocument) { + + } + + protected override void OpenFile(DiagramDocument diagramDocument, string ext) + { + base.OpenFile(diagramDocument, ext); foreach (var vm in DiagramViewModels) { vm.Init(false); } - if (MindDiagramViewModel != null) { SubType = MindDiagramViewModel.MindType.ToString(); @@ -72,11 +77,11 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels public MindTheme MindTheme { - get; + get;set; } protected override void Init(bool initNew) - { + { DiagramViewModels = new ObservableCollection() { GetDiagramViewModel("页-1", DiagramType, initNew), diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs index 8346818..c26fab7 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs @@ -395,6 +395,10 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels viewModels.Add(viewModel); } DiagramViewModels = new ObservableCollection(viewModels); + foreach (var vm in DiagramViewModels) + { + vm.Init(false); + } DiagramViewModel = DiagramViewModels.FirstOrDefault(); } From 9e6000f27863bd606fa2b1c71a66f70133e3960a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Tue, 5 Sep 2023 22:51:08 +0800 Subject: [PATCH 14/14] block --- .../Helpers/BitmapHelper.cs | 178 +++++++++--------- 1 file changed, 93 insertions(+), 85 deletions(-) diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs index 92d7c75..c137ff7 100644 --- a/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/BitmapHelper.cs @@ -31,11 +31,6 @@ namespace AIStudio.Wpf.DiagramDesigner rtb.Render(element); var bit = BitmapSourceToBitmap(rtb); - ////测试代码 - //DirectoryInfo d = new DirectoryInfo(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Cache")); - //if (!d.Exists) d.Create(); - //bit.Save(System.IO.Path.Combine(d.FullName, "控件截图.png")); - return bit; } @@ -53,11 +48,6 @@ namespace AIStudio.Wpf.DiagramDesigner var bit = BitmapSourceToBitmap(rtb); - ////测试代码 - //DirectoryInfo d = new DirectoryInfo(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Cache")); - //if (!d.Exists) d.Create(); - //bit.Save(System.IO.Path.Combine(d.FullName, "控件截图.png")); - return bit; } @@ -125,48 +115,7 @@ namespace AIStudio.Wpf.DiagramDesigner bitmapImage.StreamSource = stream; bitmapImage.EndInit(); return bitmapImage; - } - - public static string ToBase64String(this System.Windows.Media.Brush brush) - { - try - { - if (brush is System.Windows.Media.VisualBrush visualBrush) - { - var size = ((UIElement)visualBrush.Visual).DesiredSize; - var image = visualBrush.ToBitmap(new Rect(size)); - MemoryStream stream = new MemoryStream(); - image.Save(stream, ImageFormat.Bmp); - stream.Position = 0; - var bytearray = stream.ToArray(); - return Convert.ToBase64String(bytearray); - } - else if (brush is System.Windows.Media.ImageBrush imageBrush) - { - var bitmap = (imageBrush.ImageSource as BitmapImage); - byte[] bytearray = null; - Stream smarket = bitmap.StreamSource; - if (smarket != null && smarket.Length > 0) - { - //设置当前位置 - smarket.Position = 0; - using (BinaryReader br = new BinaryReader(smarket)) - { - bytearray = br.ReadBytes((int)smarket.Length); - } - } - return Convert.ToBase64String(bytearray); - } - else - { - return null; - } - } - catch (Exception ex) - { - return null; - } - } + } public static System.Windows.Media.Brush ToBrush(this string base64String, int width, int height) { @@ -175,16 +124,7 @@ namespace AIStudio.Wpf.DiagramDesigner try { - var byteArray = Convert.FromBase64String(base64String); - BitmapImage bitmapImage = null; - bitmapImage = new BitmapImage(); - bitmapImage.BeginInit(); - bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; - bitmapImage.CacheOption = BitmapCacheOption.OnLoad; - bitmapImage.DecodePixelWidth = width;//需要缩略图的解码宽度 - bitmapImage.DecodePixelHeight = height;//缩略图的解码高度 - bitmapImage.StreamSource = new MemoryStream(byteArray); - bitmapImage.EndInit(); + var bitmapImage = base64String.ToBitmapImage(width, height); return new System.Windows.Media.ImageBrush(bitmapImage) { Stretch = System.Windows.Media.Stretch.Uniform }; } @@ -194,28 +134,6 @@ namespace AIStudio.Wpf.DiagramDesigner } } - public static string ToBase64String(this BitmapImage bitmap) - { - //byte[] bytearray = null; - //Stream smarket = bitmap.StreamSource; - //if (smarket != null && smarket.Length > 0) - //{ - // //设置当前位置 - // smarket.Position = 0; - // using (BinaryReader br = new BinaryReader(smarket)) - // { - // 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); - } - public static BitmapImage ToBitmapImage(this string base64String, int width = 0, int height = 0) { if (string.IsNullOrEmpty(base64String)) @@ -260,7 +178,7 @@ namespace AIStudio.Wpf.DiagramDesigner 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(); + System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; @@ -271,6 +189,96 @@ namespace AIStudio.Wpf.DiagramDesigner } + public static Bitmap ToBitmap(this string base64String, int width = 0, int height = 0) + { + if (string.IsNullOrEmpty(base64String)) + return null; + + try + { + var byteArray = Convert.FromBase64String(base64String); + + return byteArray.ToBitmap(); + } + catch + { + return null; + } + } + + public static Bitmap ToBitmap(this byte[] byteArray) + { + //var stream = new MemoryStream(byteArray); + //return new Bitmap(stream); + MemoryStream ms = new MemoryStream(byteArray); + Bitmap bitmap = (Bitmap)Image.FromStream(ms); + ms.Close(); + + return bitmap; + } + + public static string ToBase64String(this System.Windows.Media.Brush brush) + { + try + { + if (brush is System.Windows.Media.VisualBrush visualBrush) + { + var size = ((UIElement)visualBrush.Visual).DesiredSize; + var image = visualBrush.ToBitmap(new Rect(size)); + MemoryStream stream = new MemoryStream(); + image.Save(stream, ImageFormat.Bmp); + stream.Position = 0; + var bytearray = stream.ToArray(); + return Convert.ToBase64String(bytearray); + } + else if (brush is System.Windows.Media.ImageBrush imageBrush) + { + var bitmap = (imageBrush.ImageSource as BitmapImage); + byte[] bytearray = null; + Stream smarket = bitmap.StreamSource; + if (smarket != null && smarket.Length > 0) + { + //设置当前位置 + smarket.Position = 0; + using (BinaryReader br = new BinaryReader(smarket)) + { + bytearray = br.ReadBytes((int)smarket.Length); + } + } + return Convert.ToBase64String(bytearray); + } + else + { + return null; + } + } + catch (Exception ex) + { + return null; + } + } + + public static string ToBase64String(this BitmapImage bitmap) + { + 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); + } + + public static string ToBase64String(this Bitmap bitmap) + { + var ms = new MemoryStream(); + bitmap.Save(ms, bitmap.RawFormat); + byte[] bytearray = new byte[ms.Length]; + bytearray = ms.ToArray(); + + return Convert.ToBase64String(bytearray); + } + + public static string ToBase64String(this Stream stream) { byte[] bytearray = new byte[stream.Length];