using NEIntelligentControl2.Service.Station;
using SVGViewer.Models.Info;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace NEIntelligentControl2.Windows.BoostStation
{
///
/// 图形标记窗口
///
public partial class ShapeAddWindow : Window
{
public ShapeInfo Info { get; set; }
///
/// 编辑类型
///
public BoostStationEditType EditType { get; set; }
private StationManager _StationManager;
public ShapeAddWindow(List customizeShapes)
{
InitializeComponent();
_StationManager = App.ServiceProvider.GetService(typeof(StationManager)) as StationManager;
_esv.CustomizeShapes = customizeShapes;
_esv.CustomizeEdited = OnCustomizeEdited;
}
public ShapeAddWindow(ShapeInfo info, List customizeShapes) : this(customizeShapes)
{
Info = info;
_esv.SwitchShapeInfo(info);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
switch (((Control)sender).Tag)
{
case "ok": // 确认
Ok();
break;
case "cancel": // 取消
this.DialogResult = false;
break;
case "output":
Output();
break;
default: return;
}
}
private void Output()
{
SVGViewer.Manager.SVGOutput2 so = new SVGViewer.Manager.SVGOutput2(_esv.Canvas, _esv.CustomizeShapes);
Task.Run(output);
void output()
{
var v = so.GetSvgFileInfo();
var info = so.SvgInfo;
string s = _StationManager.OutputSvgInfo(v, info);
if (s == "success")
{
Dispatcher.Invoke(() => MessageWindow.ShowMessage("导出成功!"));
return;
}
Dispatcher.Invoke(() => MessageWindow.ShowMessage(s));
}
}
///
/// 自定义控件编辑
///
private bool OnCustomizeEdited(ShapeInfo arg1, string arg2)
{
var v = _StationManager.AddOrRemoveCustomizeShape(arg1, arg2);
if (v != "success")
{
MessageWindow.ShowMessage(v);
return false;
}
return true;
}
private void Ok()
{
var info = _esv.SharpInfo;
var v = _StationManager.AddOrUpdateStation(info, this.EditType);
if (v != "success")
{
MessageWindow.ShowMessage(v);
return;
}
Info = _esv.SharpInfo;
this.DialogResult = true;
}
public static ShapeInfo Show(BoostStationEditType type, string title, List customizeShapes, Func shapeAdding, ShapeInfo info = null)
{
ShapeAddWindow saw = info == null ? new ShapeAddWindow(customizeShapes) : new ShapeAddWindow(info, customizeShapes);
saw.EditType = type;
saw.Owner = Application.Current.MainWindow;
saw.Title = title;
//saw.CustomizeEdited = shapeAdding;
var b = saw.ShowDialog();
if (b == true)
{
return saw.Info;
}
return null;
}
private void Undo_CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
_esv.Undo();
}
private void Redo_CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
_esv.Redo();
}
}
///
/// 升压站编辑类型
///
public enum BoostStationEditType
{
///
/// 升压站编辑
///
BoostStationEdit,
///
/// 升压站添加
///
BoostStationAdd,
///
/// 二次图编辑
///
SubStationEdit,
///
/// 二次图添加
///
SubStationAdd,
}
}