2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
2022-12-08 20:54:45 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-01-24 09:02:40 +08:00
|
|
|
|
public abstract class SelectableViewModelBase : BindableBase, ISelectable
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-01-24 09:02:40 +08:00
|
|
|
|
protected IDiagramServiceProvider _service
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return DiagramServicesProvider.Instance.Provider;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-22 22:10:39 +08:00
|
|
|
|
public SelectableViewModelBase()
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
Init();
|
|
|
|
|
|
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 16:20:39 +08:00
|
|
|
|
public SelectableViewModelBase(IDiagramViewModel root, SelectableItemBase designer)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
Init();
|
2023-01-24 16:20:39 +08:00
|
|
|
|
LoadDesignerItemViewModel(root, designer);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
public SelectableViewModelBase(IDiagramViewModel root, SerializableItem serializableItem, string serializableType)
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
Init();
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
SelectableItemBase obj = SerializeHelper.DeserializeObject(serializableItem.SerializableTypeName, serializableItem.SerializableString, serializableType);
|
2023-01-24 23:10:57 +08:00
|
|
|
|
LoadDesignerItemViewModel(root, obj);
|
|
|
|
|
|
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
2022-12-08 20:54:45 +08:00
|
|
|
|
|
2023-01-24 23:10:57 +08:00
|
|
|
|
public virtual SerializableItem ToSerializableItem(string serializableType)
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
2023-01-24 23:10:57 +08:00
|
|
|
|
var obj = GetSerializableObject();
|
2022-12-08 20:54:45 +08:00
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
2023-01-25 11:11:27 +08:00
|
|
|
|
return new SerializableItem() { ModelTypeName = this.GetType().FullName, SerializableTypeName = obj.GetType().FullName, SerializableString = SerializeHelper.SerializeObject(obj, serializableType) };
|
2022-12-08 20:54:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 23:10:57 +08:00
|
|
|
|
public virtual SelectableItemBase GetSerializableObject()
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
protected virtual void Init()
|
|
|
|
|
|
{
|
2021-08-01 22:30:12 +08:00
|
|
|
|
ColorViewModel = _service.CopyDefaultColorViewModel();
|
|
|
|
|
|
FontViewModel = _service.CopyDefaultFontViewModel();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
LockObjectViewModel = new LockObjectViewModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 16:20:39 +08:00
|
|
|
|
protected virtual void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-01-24 16:20:39 +08:00
|
|
|
|
this.Root = root;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
this.Id = designerbase.Id;
|
|
|
|
|
|
this.ParentId = designerbase.ParentId;
|
|
|
|
|
|
this.IsGroup = designerbase.IsGroup;
|
|
|
|
|
|
this.ZIndex = designerbase.ZIndex;
|
|
|
|
|
|
this.Text = designerbase.Text;
|
|
|
|
|
|
|
|
|
|
|
|
ColorViewModel = CopyHelper.Mapper(designerbase.ColorItem);
|
|
|
|
|
|
FontViewModel = CopyHelper.Mapper<FontViewModel, FontItem>(designerbase.FontItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 16:20:39 +08:00
|
|
|
|
public IDiagramViewModel Root
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
2023-01-24 16:20:39 +08:00
|
|
|
|
|
|
|
|
|
|
public SelectableViewModelBase Parent
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-08 20:54:45 +08:00
|
|
|
|
public Guid Id
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
private Guid _parentId;
|
|
|
|
|
|
public Guid ParentId
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _parentId;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _parentId, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-08 20:54:45 +08:00
|
|
|
|
public bool IsGroup
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 09:02:40 +08:00
|
|
|
|
protected bool _isSelected;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
[Browsable(false)]
|
2023-01-24 09:02:40 +08:00
|
|
|
|
public virtual bool IsSelected
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _isSelected;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-01-24 09:02:40 +08:00
|
|
|
|
SetProperty(ref _isSelected, value);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int _zIndex;
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
|
[CanDo]
|
|
|
|
|
|
public int ZIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _zIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _zIndex, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _isReadOnly;
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
|
public bool IsReadOnly
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-01-24 16:20:39 +08:00
|
|
|
|
if (Root?.IsReadOnly == true && Root?.IsLoading == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Parent?.IsReadOnly == true)
|
2022-12-04 23:07:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-01-24 16:20:39 +08:00
|
|
|
|
|
2022-12-04 23:07:20 +08:00
|
|
|
|
if (LockObjectViewModel?.LockObject.FirstOrDefault(p => p.LockFlag == LockFlag.All)?.IsChecked == true)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _isReadOnly;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _isReadOnly, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _isHitTestVisible = true;
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
|
public bool IsHitTestVisible
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-01-24 16:20:39 +08:00
|
|
|
|
if (Parent?.IsHitTestVisible == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
return _isHitTestVisible;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
2023-01-24 16:20:39 +08:00
|
|
|
|
{
|
2021-07-23 09:42:22 +08:00
|
|
|
|
if (SetProperty(ref _isHitTestVisible, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged("IsReadOnly");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IColorViewModel _colorViewModel;
|
|
|
|
|
|
public IColorViewModel ColorViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _colorViewModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _colorViewModel, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IFontViewModel _fontViewModel;
|
|
|
|
|
|
public IFontViewModel FontViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _fontViewModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _fontViewModel, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-08 20:54:45 +08:00
|
|
|
|
public ILockObjectViewModel LockObjectViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
private string _text;
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
|
[CanDo]
|
2023-01-24 09:02:40 +08:00
|
|
|
|
public virtual string Text
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2021-07-27 21:58:55 +08:00
|
|
|
|
var text = _text;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
if (FontViewModel.FontCase == FontCase.Upper)
|
|
|
|
|
|
{
|
2021-07-27 21:58:55 +08:00
|
|
|
|
return text?.ToUpper();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (FontViewModel.FontCase == FontCase.Lower)
|
|
|
|
|
|
{
|
2021-07-27 21:58:55 +08:00
|
|
|
|
return text?.ToLower();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-07-27 21:58:55 +08:00
|
|
|
|
return text;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-01-24 09:02:40 +08:00
|
|
|
|
if (SetProperty(ref _text, value))
|
2021-07-27 21:58:55 +08:00
|
|
|
|
{
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 09:02:40 +08:00
|
|
|
|
|
|
|
|
|
|
public virtual void AddToSelection(bool selected)
|
2023-01-22 21:46:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 23:55:30 +08:00
|
|
|
|
protected bool Command_Enable(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsReadOnly == false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
private void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.PropertyName == "FontCase")
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged("Text");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|