mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block 可以拖拽到内部,还有少量问题待解决
This commit is contained in:
48
AIStudio.Wpf.DiagramApp/ViewModels/BlockViewModel.cs
Normal file
48
AIStudio.Wpf.DiagramApp/ViewModels/BlockViewModel.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
//using AIStudio.Wpf.Block.ViewModels;
|
||||
using AIStudio.Wpf.DiagramApp.Models;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
internal class BlockViewModel : PageViewModel
|
||||
{
|
||||
public BlockViewModel(string title, string status, DiagramType diagramType) : base(title, status, diagramType)
|
||||
{
|
||||
|
||||
}
|
||||
public BlockViewModel(string filename, DiagramDocument diagramDocument) : base(filename, diagramDocument)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void InitDiagramViewModel()
|
||||
{
|
||||
base.InitDiagramViewModel();
|
||||
|
||||
DiagramViewModel.DiagramOption.LayoutOption.ShowGrid = false;
|
||||
}
|
||||
|
||||
protected override void Init(bool initNew)
|
||||
{
|
||||
base.Init(initNew);
|
||||
|
||||
//StartBlockItemViewModel start = new StartBlockItemViewModel(DiagramViewModel) { Left = 28, Top = 28 };
|
||||
//DiagramViewModel.Add(start);
|
||||
|
||||
//WaitTimeBlockItemViewModel waittime = new WaitTimeBlockItemViewModel(DiagramViewModel) { Left = 28, Top = 28 };
|
||||
//DiagramViewModel.Add(waittime);
|
||||
|
||||
//AddBlockItemViewModel add = new AddBlockItemViewModel(DiagramViewModel) { Left = 28, Top = 28 };
|
||||
//DiagramViewModel.Add(add);
|
||||
|
||||
//KeyboardPressBlockItemViewModel keyboardPress = new KeyboardPressBlockItemViewModel(DiagramViewModel) { Left = 28, Top = 28 };
|
||||
//DiagramViewModel.Add(keyboardPress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ using AIStudio.Wpf.DiagramDesigner.ViewModels;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel;
|
||||
using AIStudio.Wpf.Mind;
|
||||
using AIStudio.Wpf.Mind.Models;
|
||||
using ControlzEx.Controls;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
@@ -545,6 +546,10 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
flow = new DrawingViewModel(filename, diagram);
|
||||
}
|
||||
else if (diagram.DiagramType == DiagramType.Block)
|
||||
{
|
||||
flow = new BlockViewModel(filename, diagram);
|
||||
}
|
||||
else
|
||||
{
|
||||
flow = new PageViewModel(filename, diagram);
|
||||
@@ -668,6 +673,10 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
PageViewModel = new DrawingViewModel(NewNameHelper.GetNewName(PageViewModels.Select(p => p.Title), "新建-"), "*", (DiagramType)Enum.Parse(typeof(DiagramType), type));
|
||||
}
|
||||
else if (type == DiagramType.Block.ToString())
|
||||
{
|
||||
PageViewModel = new BlockViewModel(NewNameHelper.GetNewName(PageViewModels.Select(p => p.Title), "新建-"), "*", (DiagramType)Enum.Parse(typeof(DiagramType), type));
|
||||
}
|
||||
else
|
||||
{
|
||||
PageViewModel = new PageViewModel(NewNameHelper.GetNewName(PageViewModels.Select(p => p.Title), "新建-"), "*", (DiagramType)Enum.Parse(typeof(DiagramType), type));
|
||||
|
||||
@@ -20,6 +20,7 @@ using ZXing;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
@@ -34,29 +35,48 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PageViewModel(string title, string status, DiagramType diagramType, string subType = null)
|
||||
{
|
||||
Title = title;
|
||||
Status = status;
|
||||
DiagramType = diagramType;
|
||||
SubType = subType;
|
||||
Init(true);
|
||||
|
||||
}
|
||||
public PageViewModel(string filename)
|
||||
{
|
||||
FileName = filename;
|
||||
string ext = Path.GetExtension(filename);
|
||||
var diagramDocument = OpenFile(filename, ext);
|
||||
OpenFile(diagramDocument, ext);
|
||||
DiagramDocument = OpenFile(filename, ext);
|
||||
}
|
||||
|
||||
public PageViewModel(string filename, DiagramDocument diagramDocument)
|
||||
{
|
||||
FileName = filename;
|
||||
string ext = Path.GetExtension(filename);
|
||||
OpenFile(diagramDocument, ext);
|
||||
DiagramDocument = diagramDocument;
|
||||
}
|
||||
|
||||
DiagramDocument DiagramDocument;
|
||||
public virtual void View_Loaded(object sender, EventArgs e)
|
||||
{
|
||||
//await Task.Run(() => {
|
||||
//Application.Current.Dispatcher.Invoke(() => {
|
||||
if (string.IsNullOrEmpty(FileName))
|
||||
{
|
||||
Init(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
string ext = Path.GetExtension(FileName);
|
||||
OpenFile(DiagramDocument, ext);
|
||||
}
|
||||
//});
|
||||
//});
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected virtual void InitDiagramViewModel()
|
||||
{
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
public SFCViewModel(string title, string status, DiagramType diagramType) : base(title, status, diagramType)
|
||||
{
|
||||
Init(true);
|
||||
|
||||
}
|
||||
|
||||
public SFCViewModel(string filename, DiagramDocument diagramDocument) : base(filename, diagramDocument)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
|
||||
public ScriptViewModel(string title, string status, DiagramType diagramType) : base(title, status, diagramType)
|
||||
{
|
||||
Init(true);
|
||||
|
||||
}
|
||||
|
||||
public ScriptViewModel(string filename, DiagramDocument diagramDocument) : base(filename, diagramDocument)
|
||||
@@ -61,8 +61,8 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
ConsoleLogViewModel logNode = new ConsoleLogViewModel(DiagramViewModel) { Name = "Log", Left = 150, Top = 420 };
|
||||
DiagramViewModel.Add(logNode);
|
||||
|
||||
IntScriptViewModel intLog = new IntScriptViewModel(DiagramViewModel) { Name = "Int", Left = 40, Top = 220 };
|
||||
DiagramViewModel.Add(intLog);
|
||||
IntScriptViewModel intNode = new IntScriptViewModel(DiagramViewModel) { Name = "Int", Left = 40, Top = 220 };
|
||||
DiagramViewModel.Add(intNode);
|
||||
|
||||
ColorBoxFactoryScriptViewModel factoryNode = new ColorBoxFactoryScriptViewModel(DiagramViewModel) { Name = "ColorBoxFactory", Left = 150, Top = 150 };
|
||||
DiagramViewModel.Add(factoryNode);
|
||||
@@ -111,7 +111,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
collectorNode7.Tag = new ColorBoxModel("紫色|六边形", "M 0,20 L 10,0 H 50 L 60,20 L 50,40 H10 Z", Colors.Purple);
|
||||
DiagramViewModel.Add(collectorNode7);
|
||||
|
||||
ConnectionViewModel int_factoryConnector = new ConnectionViewModel(DiagramViewModel, intLog.Output[0], factoryNode.Input[0], DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
|
||||
ConnectionViewModel int_factoryConnector = new ConnectionViewModel(DiagramViewModel, intNode.Output[0], factoryNode.Input[0], DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
|
||||
DiagramViewModel.Add(int_factoryConnector);
|
||||
|
||||
ConnectionViewModel bool_switchConnector = new ConnectionViewModel(DiagramViewModel, boolNode.Output[0], switchNode.Input[0], DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
|
||||
@@ -191,7 +191,9 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
item.Execute();
|
||||
}
|
||||
readDataTimer.Start();
|
||||
|
||||
if (readDataTimer != null)
|
||||
readDataTimer.Start();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -200,6 +202,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
|
||||
readDataTimer.Stop();
|
||||
readDataTimer.Dispose();
|
||||
readDataTimer = null;
|
||||
|
||||
foreach (var item in DiagramViewModel.Items.OfType<LogicalGateItemViewModelBase>().OrderBy(p => p.OrderNumber).ToList())
|
||||
{
|
||||
|
||||
@@ -119,9 +119,16 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
|
||||
List<ToolBoxData> defaultToolBoxItems = new List<ToolBoxData>();
|
||||
defaultToolBoxItems.Add(new TextToolBoxData("", typeof(DefaultDesignerItemViewModel)));
|
||||
var blockitem = new TextToolBoxData("", typeof(BlockDesignerItemViewModel), 64, 32, new Size(130, 65));
|
||||
var blockitem = new TextToolBoxData("Block", typeof(BlockDesignerItemViewModel), 64, 32, desiredMinSize: new Size(130, 65));
|
||||
blockitem.ColorViewModel.FillColor.Color = Color.FromRgb(0x00, 0x2F, 0xA7);
|
||||
defaultToolBoxItems.Add(blockitem);
|
||||
var blockitem2 = new TextToolBoxData("Contain", typeof(BlockContainDesignerItemViewModel), 64, 32, desiredMinSize: new Size(130, 65));
|
||||
blockitem2.ColorViewModel.FillColor.Color = Color.FromRgb(0x00, 0x2F, 0xA7);
|
||||
defaultToolBoxItems.Add(blockitem2);
|
||||
var blockitem3 = new TextToolBoxData("ContainList", typeof(BlockContainListDesignerItemViewModel), 64, 32, desiredMinSize: new Size(130, 65));
|
||||
blockitem3.ColorViewModel.FillColor.Color = Color.FromRgb(0x00, 0x2F, 0xA7);
|
||||
defaultToolBoxItems.Add(blockitem3);
|
||||
|
||||
ToolBoxCategory.Add(new ToolBoxCategory() { Header = "Default", ToolBoxItems = new ObservableCollection<ToolBoxData>(defaultToolBoxItems), IsExpanded = true });
|
||||
|
||||
ToolBoxCategory.Add(new ToolBoxCategory() { Header = "Svg", ToolBoxItems = new ObservableCollection<ToolBoxData>() });
|
||||
|
||||
Reference in New Issue
Block a user