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-22 22:10:39 +08:00
|
|
|
|
public SelectableViewModelBase(IDiagramViewModel parent, SelectableDesignerItemBase designer)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
Init();
|
|
|
|
|
|
LoadDesignerItemViewModel(parent, designer);
|
|
|
|
|
|
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-22 22:10:39 +08:00
|
|
|
|
public SelectableViewModelBase(IDiagramViewModel parent, string json)
|
2022-12-08 20:54:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
Init();
|
|
|
|
|
|
LoadDesignerItemViewModel(parent, JsonConvert.DeserializeObject(json, ToXmlType()) as SelectableDesignerItemBase);
|
|
|
|
|
|
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual SelectableDesignerItemBase ToXmlObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual SerializableItem ToSerializabObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
var obj = ToXmlObject();
|
|
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new SerializableItem() { TypeName = this.GetType().FullName, ObjectJson = obj.ToJson() };
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual Type ToXmlType()
|
|
|
|
|
|
{
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Parent = parent;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-08 20:54:45 +08:00
|
|
|
|
public IDiagramViewModel Parent
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
2022-12-05 22:48:00 +08:00
|
|
|
|
if (Parent?.IsReadOnly == true && Parent?.IsLoading == false)
|
2022-12-04 23:07:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
return _isHitTestVisible;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|