207 lines
6.6 KiB
C#
207 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using Bricscad.Windows;
|
|
using CAD.Extend.Model;
|
|
using Prism.Commands;
|
|
using Prism.Dialogs;
|
|
using SWS.CAD.Base;
|
|
using Teigha.Colors;
|
|
using Teigha.DatabaseServices;
|
|
using Brush = System.Windows.Media.Brush;
|
|
using Color = System.Windows.Media.Color;
|
|
|
|
namespace CAD.Extend.ViewModels
|
|
{
|
|
public class DialogConvertBaseMapViewModel : DialogBase, IDialogAware
|
|
{
|
|
#region binding
|
|
private ObservableCollection<KeyValueModel> _listLayerName = new ObservableCollection<KeyValueModel>();
|
|
/// <summary>
|
|
/// 底图名列表
|
|
/// </summary>
|
|
public ObservableCollection<KeyValueModel> listLayerName
|
|
{
|
|
get { return _listLayerName; }
|
|
set { _listLayerName = value; RaisePropertyChanged(nameof(listLayerName)); }
|
|
}
|
|
private KeyValueModel _SelectedLayerName;
|
|
/// <summary>
|
|
/// 选中的底图名
|
|
/// </summary>
|
|
public KeyValueModel SelectedLayerName
|
|
{
|
|
get { return _SelectedLayerName; }
|
|
set { _SelectedLayerName = value; RaisePropertyChanged(nameof(SelectedLayerName)); }
|
|
}
|
|
private bool _IsToBlock;
|
|
/// <summary>
|
|
/// 是否转为图块
|
|
/// </summary>
|
|
public bool IsToBlock
|
|
{
|
|
get { return _IsToBlock; }
|
|
set { _IsToBlock = value; RaisePropertyChanged(nameof(IsToBlock)); }
|
|
}
|
|
#endregion
|
|
|
|
private string _BlockName = "EI-Elec专用底图";
|
|
/// <summary>
|
|
/// 块名
|
|
/// </summary>
|
|
public string BlockName
|
|
{
|
|
get { return _BlockName; }
|
|
set { _BlockName = value; RaisePropertyChanged(nameof(BlockName)); }
|
|
}
|
|
private Brush _BlockColor;
|
|
/// <summary>
|
|
/// 图层颜色
|
|
/// </summary>
|
|
public Brush BlockColor
|
|
{
|
|
get { return _BlockColor; }
|
|
set { _BlockColor = value; RaisePropertyChanged(nameof(BlockColor)); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 随机块名
|
|
/// </summary>
|
|
public ICommand Command_BlockName { get; set; }
|
|
/// <summary>
|
|
/// 颜色
|
|
/// </summary>
|
|
public ICommand Command_Color { get; set; }
|
|
/// <summary>
|
|
/// 图层颜色 默认灰色
|
|
/// </summary>
|
|
Teigha.Colors.Color layerColor = Teigha.Colors.Color.FromColorIndex(ColorMethod.ByAci, 8);
|
|
List<ObjectId> listObjectId = new List<ObjectId>();
|
|
string layerName = "EI-Elec专用底图图层";
|
|
public DialogConvertBaseMapViewModel()
|
|
{
|
|
title = "背景底图设置";
|
|
Command_BlockName = new DelegateCommand(onBlockName);
|
|
Command_Color = new DelegateCommand(onColor);
|
|
System.Drawing.Color winColor = layerColor.ColorValue;
|
|
var c = Color.FromArgb(winColor.A, winColor.R, winColor.G, winColor.B);
|
|
BlockColor = new SolidColorBrush(c);
|
|
}
|
|
/// <summary>
|
|
/// 颜色选择
|
|
/// </summary>
|
|
public void onColor()
|
|
{
|
|
var list=General.GetTopLevelDictionaryNames();
|
|
|
|
ColorDialog dlg = new ColorDialog();
|
|
|
|
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
layerColor = dlg.Color;
|
|
System.Drawing.Color winColor = dlg.Color.ColorValue;
|
|
var b = Color.FromArgb(winColor.A, winColor.R, winColor.G, winColor.B);
|
|
BlockColor = new SolidColorBrush(b);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 随机块名
|
|
/// </summary>
|
|
public void onBlockName()
|
|
{
|
|
var a = GetRndABC();
|
|
Thread.Sleep(10);
|
|
var b = GetRndABC();
|
|
Thread.Sleep(10);
|
|
var c = GetRndABC();
|
|
BlockName = "EI-Elec图块" + a + b + c;
|
|
}
|
|
public string GetRndABC()
|
|
{
|
|
// a-z ASCII值 97-122
|
|
// A-Z ASCII值 65-90
|
|
int i = new Random().Next(65, 90);
|
|
char c = (char)i;
|
|
return c.ToString();
|
|
}
|
|
|
|
#region Dialog
|
|
|
|
public DialogCloseListener RequestClose { get; }
|
|
|
|
public bool CanCloseDialog()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnDialogClosed()
|
|
{
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
listObjectId = parameters.GetValue<List<ObjectId>>(GlobalObject.dialogPar.info.ToString());
|
|
var list = General.GetAllLayerNames();
|
|
foreach (var layerName in list)
|
|
{
|
|
if (layerName.Equals(layerName))
|
|
{ listLayerName.Insert(0, new KeyValueModel() { Key = layerName, Value = layerName }); }
|
|
else
|
|
{
|
|
listLayerName.Add(new KeyValueModel() { Key = layerName, Value = layerName });
|
|
}
|
|
}
|
|
if (!listLayerName.Where(a => a.Key == layerName).Any())
|
|
{ listLayerName.Insert(0, new KeyValueModel() { Key = layerName, Value = layerName }); }
|
|
SelectedLayerName = listLayerName[0];
|
|
}
|
|
public override void ExecuteOKCommandAsync(object para)
|
|
{
|
|
if (IsToBlock)
|
|
{
|
|
if (string.IsNullOrEmpty(BlockName))
|
|
{
|
|
MessageBox.Show("块名不能为空!");
|
|
return;
|
|
}
|
|
if (General.CheckHasBlockName(BlockName))
|
|
{
|
|
MessageBox.Show("块名已存在,请更换块名!");
|
|
return;
|
|
}
|
|
General.SetEntityToLayer(listObjectId, SelectedLayerName.Value, layerColor, BlockName);
|
|
}
|
|
else
|
|
{
|
|
General.SetEntityToLayer(listObjectId, SelectedLayerName.Value, layerColor);
|
|
}
|
|
MessageBox.Show("底图设置成功!");
|
|
//Prism.Dialogs.DialogParameters resPara = new Prism.Dialogs.DialogParameters();
|
|
//RequestClose.Invoke(resPara, ButtonResult.Yes);
|
|
}
|
|
public override void ExecuteCloseCommand(object parameter)
|
|
{
|
|
if (parameter as string == "ClickNo")
|
|
{
|
|
RequestClose.Invoke(ButtonResult.No);
|
|
}
|
|
else
|
|
{
|
|
RequestClose.Invoke(ButtonResult.Cancel);
|
|
}
|
|
this.Dispose();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|