790 lines
32 KiB
C#
790 lines
32 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Forms;
|
||
using System.Windows.Input;
|
||
using System.Windows.Interop;
|
||
using System.Windows.Media;
|
||
using System.Windows.Media.Media3D;
|
||
using Bricscad.EditorInput;
|
||
using Newtonsoft.Json;
|
||
using Prism.Services.Dialogs;
|
||
using SWS.CAD.Base;
|
||
using SWS.Commons;
|
||
using SWS.Electrical.Models;
|
||
using SWS.Model;
|
||
using SWS.Service;
|
||
using SWS.WPF.ViewModels;
|
||
using Teigha.DatabaseServices;
|
||
using Teigha.Geometry;
|
||
using Teigha.GraphicsSystem;
|
||
using Telerik.Windows.Controls;
|
||
using Unity;
|
||
using Visibility = System.Windows.Visibility;
|
||
|
||
namespace SWS.Electrical.ViewModels
|
||
{
|
||
public class DialogAutoArrangeLayoutViewModel : DialogBase, IDialogAware
|
||
{
|
||
private ObservableCollection<DtoDrawing> _listDrawings;
|
||
/// <summary>
|
||
/// 布置图列表
|
||
/// </summary>
|
||
public ObservableCollection<DtoDrawing> listDrawings
|
||
{
|
||
get { return this._listDrawings; }
|
||
set
|
||
{
|
||
if (value != this._listDrawings)
|
||
{
|
||
this._listDrawings = value;
|
||
RaisePropertyChanged(nameof(listDrawings));
|
||
}
|
||
}
|
||
}
|
||
private ObservableCollection<DtoAutoPlotLayout> _listBasePoint;
|
||
/// <summary>
|
||
/// 基点元件列表
|
||
/// </summary>
|
||
public ObservableCollection<DtoAutoPlotLayout> listBasePoint
|
||
{
|
||
get { return this._listBasePoint; }
|
||
set
|
||
{
|
||
if (value != this._listBasePoint)
|
||
{
|
||
this._listBasePoint = value;
|
||
RaisePropertyChanged(nameof(listBasePoint));
|
||
}
|
||
}
|
||
}
|
||
private DtoAutoPlotLayout _SelectedTag;
|
||
/// <summary>
|
||
/// 基点元件
|
||
/// </summary>
|
||
public DtoAutoPlotLayout SelectedTag
|
||
{
|
||
get { return this._SelectedTag; }
|
||
set
|
||
{
|
||
this._SelectedTag = value;
|
||
RaisePropertyChanged(nameof(SelectedTag));
|
||
}
|
||
}
|
||
private bool _IsSelectAll = false;
|
||
public bool IsSelectAll
|
||
{
|
||
get { return _IsSelectAll; }
|
||
set
|
||
{
|
||
_IsSelectAll = value;
|
||
RaisePropertyChanged(nameof(IsSelectAll));
|
||
}
|
||
}
|
||
private ObservableCollection<TextBlock> _listMsg;
|
||
/// <summary>
|
||
/// 信息列表
|
||
/// </summary>
|
||
public ObservableCollection<TextBlock> listMsg
|
||
{
|
||
get { return this._listMsg; }
|
||
set
|
||
{
|
||
if (value != this._listMsg)
|
||
{
|
||
this._listMsg = value;
|
||
RaisePropertyChanged(nameof(listMsg));
|
||
}
|
||
}
|
||
}
|
||
private ObservableCollection<KeyValueModel> _listRange;
|
||
/// <summary>
|
||
/// 范围
|
||
/// </summary>
|
||
public ObservableCollection<KeyValueModel> listRange
|
||
{
|
||
get { return this._listRange; }
|
||
set
|
||
{
|
||
if (value != this._listRange)
|
||
{
|
||
this._listRange = value;
|
||
RaisePropertyChanged(nameof(listRange));
|
||
}
|
||
}
|
||
}
|
||
private KeyValueModel _selectRange;
|
||
/// <summary>
|
||
/// 选中范围
|
||
/// </summary>
|
||
public KeyValueModel selectRange
|
||
{
|
||
get { return this._selectRange; }
|
||
set
|
||
{
|
||
if (value != this._selectRange)
|
||
{
|
||
this._selectRange = value;
|
||
RangeChange(value);
|
||
RaisePropertyChanged(nameof(selectRange));
|
||
}
|
||
}
|
||
}
|
||
|
||
private ObservableCollection<KeyValueModel> _listOperator;
|
||
/// <summary>
|
||
/// 判断
|
||
/// </summary>
|
||
public ObservableCollection<KeyValueModel> listOperator
|
||
{
|
||
get { return this._listOperator; }
|
||
set
|
||
{
|
||
if (value != this._listOperator)
|
||
{
|
||
this._listOperator = value;
|
||
RaisePropertyChanged(nameof(listOperator));
|
||
}
|
||
}
|
||
}
|
||
private KeyValueModel _selectOperator;
|
||
/// <summary>
|
||
/// 选中判断
|
||
/// </summary>
|
||
public KeyValueModel selectOperator
|
||
{
|
||
get { return this._selectOperator; }
|
||
set
|
||
{
|
||
if (value != this._selectOperator)
|
||
{
|
||
this._selectOperator = value;
|
||
RaisePropertyChanged(nameof(selectOperator));
|
||
}
|
||
}
|
||
}
|
||
private ObservableCollection<KeyValueModel> _listValue;
|
||
/// <summary>
|
||
/// 输入值 列表
|
||
/// </summary>
|
||
public ObservableCollection<KeyValueModel> listValue
|
||
{
|
||
get { return this._listValue; }
|
||
set
|
||
{
|
||
if (value != this._listValue)
|
||
{
|
||
this._listValue = value;
|
||
RaisePropertyChanged(nameof(listValue));
|
||
}
|
||
}
|
||
}
|
||
private string _inputValue = "";
|
||
/// <summary>
|
||
/// 输入值
|
||
/// </summary>
|
||
public string inputValue
|
||
{
|
||
get { return _inputValue; }
|
||
set { _inputValue = value; OnPropertyChanged(nameof(inputValue)); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 命令事件
|
||
/// </summary>
|
||
public ICommand Command_StartDrawing { get; set; }
|
||
public ICommand Command_GetBasePoint { get; set; }
|
||
|
||
public ICommand Command_SelectedTag { get; set; }
|
||
|
||
public ICommand Command_SelectedAll { get; set; }
|
||
|
||
PlotLayoutService _ServicePlotLayout;
|
||
DrawingServce _ServiceDrawing;
|
||
AnnexesService _ServiceAnnexes;
|
||
LibraryFileService _ServiceLibraryFile;
|
||
DrawingCatalogueService _ServiceDrawingCatalogue;
|
||
EnginedataService _ServiceEnginedata;
|
||
ObjectTypeService _ServiceObjectType;
|
||
ProjectSettingsService _ServiceProjectSettings;
|
||
DataItemService _ServiceDataItem;
|
||
List<string> listTagNumberSucc = new List<string>();
|
||
private bool isSearch = false;//是否正在查询
|
||
private bool isDrawing = false;//是否正在画图
|
||
private string dwgName = string.Empty;
|
||
private List<string> listLibraryTagName = new List<string>();//元件图纸上的位号属性名称,
|
||
private List<KeyValueModel> listDeck=new List<KeyValueModel>();//甲板号值列表
|
||
private List<KeyValueModel> listArea = new List<KeyValueModel>();//区域值列表
|
||
private List<KeyValueModel> listSystem = new List<KeyValueModel>();//所属系统值列表
|
||
public DialogAutoArrangeLayoutViewModel()
|
||
{
|
||
Command_StartDrawing = new DelegateCommand(onStartDrawing);
|
||
Command_GetBasePoint = new DelegateCommand(onGetBasePoint);
|
||
Command_SelectedTag = new DelegateCommand(onSelectedTag);
|
||
Command_SelectedAll = new DelegateCommand(onSelectedAll);
|
||
title = "布置图自动绘制";
|
||
_ServicePlotLayout = GlobalObject.container.Resolve<PlotLayoutService>();
|
||
_ServiceDrawing = GlobalObject.container.Resolve<DrawingServce>();
|
||
_ServiceAnnexes = GlobalObject.container.Resolve<AnnexesService>();
|
||
_ServiceLibraryFile = GlobalObject.container.Resolve<LibraryFileService>();
|
||
_ServiceDrawingCatalogue = GlobalObject.container.Resolve<DrawingCatalogueService>();
|
||
_ServiceEnginedata = GlobalObject.container.Resolve<EnginedataService>();
|
||
_ServiceObjectType = GlobalObject.container.Resolve<ObjectTypeService>();
|
||
_ServiceProjectSettings = GlobalObject.container.Resolve<ProjectSettingsService>();
|
||
_ServiceDataItem= GlobalObject.container.Resolve<DataItemService>();
|
||
listDrawings = new ObservableCollection<DtoDrawing>();
|
||
listBasePoint = new ObservableCollection<DtoAutoPlotLayout>();
|
||
listMsg = new ObservableCollection<TextBlock>();
|
||
var list = new ObservableCollection<KeyValueModel>();
|
||
list.Add(new KeyValueModel { Key = "甲板号", Value = "甲板号" });
|
||
list.Add(new KeyValueModel { Key = "区域", Value = "区域" });
|
||
list.Add(new KeyValueModel { Key = "所属系统", Value = "所属系统" });
|
||
listRange = new ObservableCollection<KeyValueModel>(list);
|
||
listOperator = new ObservableCollection<KeyValueModel>()
|
||
{ new KeyValueModel { Key = "等于", Value = "=" }
|
||
};
|
||
selectOperator = listOperator[0];
|
||
}
|
||
|
||
public string Title => "";
|
||
|
||
public event Action<IDialogResult> RequestClose;
|
||
|
||
public bool CanCloseDialog()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnDialogClosed()
|
||
{
|
||
|
||
}
|
||
private List<TreeModel> GetChildNodes(TreeModel treeModel)
|
||
{
|
||
List<TreeModel> listModel = new List<TreeModel>();
|
||
if (treeModel.ChildNodes != null && treeModel.ChildNodes.Any())
|
||
{
|
||
foreach (var item in treeModel.ChildNodes)
|
||
{
|
||
if (item.NodeType == "1")
|
||
{
|
||
listModel.Add(item);
|
||
}
|
||
else
|
||
{
|
||
var list = GetChildNodes(item);
|
||
if (list.Any())
|
||
{
|
||
listModel.AddRange(list);
|
||
}
|
||
}
|
||
}
|
||
return listModel;
|
||
}
|
||
else
|
||
{
|
||
return listModel;
|
||
}
|
||
}
|
||
public async void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
try
|
||
{
|
||
if (GlobalObj.treeDrawings.Any())
|
||
{
|
||
foreach (var model in GlobalObj.treeDrawings)
|
||
{
|
||
if (model.Text == "布置图")
|
||
{
|
||
foreach (var item in model.ChildNodes)
|
||
{
|
||
if (item.NodeType == "1")
|
||
{
|
||
listDrawings.Add(new DtoDrawing() { DrawingFileID = item.ID, DrawingFileName = item.Text });
|
||
}
|
||
else
|
||
{
|
||
if (item.Text == "封面、目录、设计说明" || item.Text == "材料表")
|
||
{ continue; }
|
||
var list = GetChildNodes(item);
|
||
if (list.Any())
|
||
{
|
||
foreach (var dto in list)
|
||
{
|
||
listDrawings.Add(new DtoDrawing() { DrawingFileID = dto.ID, DrawingFileName = dto.Text });
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!listDrawings.Any())
|
||
{
|
||
AddMsg($"布置图列表加载中...");
|
||
var listDwg = await _ServiceDrawing.GetDrawingCatalogue();
|
||
if (listDwg == null)
|
||
{
|
||
AddMsg($"布置图列表没有数据!");
|
||
return;
|
||
}
|
||
foreach (var model in listDwg)
|
||
{
|
||
if (model.Text == "布置图")
|
||
{
|
||
if (model.ChildNodes == null)
|
||
{
|
||
AddMsg($"布置图列表没有数据!");
|
||
continue;
|
||
}
|
||
foreach (var item in model.ChildNodes)
|
||
{
|
||
if (item.NodeType == "1")
|
||
{
|
||
listDrawings.Add(new DtoDrawing() { DrawingFileID = item.ID, DrawingFileName = item.Text });
|
||
}
|
||
else
|
||
{
|
||
if (item.Text == "封面、目录、设计说明" || item.Text == "材料表")
|
||
{ continue; }
|
||
var list = GetChildNodes(item);
|
||
if (list.Any())
|
||
{
|
||
foreach (var dto in list)
|
||
{
|
||
listDrawings.Add(new DtoDrawing() { DrawingFileID = dto.ID, DrawingFileName = dto.Text });
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
AddMsg($"布置图列表加载完成!");
|
||
}
|
||
var settingModel = await _ServiceProjectSettings.GetEntity("布置图图例显示位号名称");
|
||
if (settingModel == null)
|
||
{
|
||
listLibraryTagName.Add("位号");//默认
|
||
}
|
||
else { listLibraryTagName = settingModel.SettingValue.Split(',').ToList(); }
|
||
//区域下拉框对应值列表
|
||
var listDetail = await _ServiceDataItem.GetDetails("Area");
|
||
if (listDetail != null && listDetail.Any())
|
||
{
|
||
foreach (var item in listDetail)
|
||
{ listArea.Add(new KeyValueModel() { Key=item.DataItemName, Value=item.DataItemName }); }
|
||
}
|
||
//甲板号下拉框对应值列表
|
||
listDetail = await _ServiceDataItem.GetDetails("甲板号");
|
||
if (listDetail != null && listDetail.Any())
|
||
{
|
||
foreach (var item in listDetail)
|
||
{ listDeck.Add(new KeyValueModel() { Key = item.DataItemName, Value = item.DataItemName }); }
|
||
}
|
||
//所属系统下拉框对应值列表
|
||
listDetail = await _ServiceDataItem.GetDetails("Be_DrawingSystem");
|
||
if (listDetail != null && listDetail.Any())
|
||
{
|
||
foreach (var item in listDetail)
|
||
{ listSystem.Add(new KeyValueModel() { Key = item.DataItemName, Value = item.DataItemName }); }
|
||
}
|
||
selectRange = listRange[0];
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("DialogOpened异常:" + ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 下拉值列表绑定
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
private void RangeChange(KeyValueModel model)
|
||
{
|
||
inputValue = "";
|
||
if (model.Value == "甲板号")
|
||
{ listValue = new ObservableCollection<KeyValueModel>(listDeck); }
|
||
else if (model.Value == "区域")
|
||
{ listValue = new ObservableCollection<KeyValueModel>(listArea); }
|
||
else if (model.Value == "所属系统")
|
||
{ listValue = new ObservableCollection<KeyValueModel>(listSystem); }
|
||
}
|
||
/// <summary>
|
||
/// 获取基点信息
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public async void onGetBasePoint(object o)
|
||
{
|
||
if (isSearch)
|
||
{
|
||
MessageBox.Show("正在查询基点元件信息中...");
|
||
return;
|
||
}
|
||
var listSelDwg = listDrawings.Where(a => a.IsSelected == true).ToList();
|
||
if (!listSelDwg.Any())
|
||
{
|
||
AddMsg("请先选择布置图!");
|
||
MessageBox.Show("请先选择布置图!");
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
isSearch = true;
|
||
AddMsg("开始查询布置图基点元件信息...");
|
||
List<DtoAutoPlotLayout> listDto = new List<DtoAutoPlotLayout>();
|
||
foreach (var dwg in listSelDwg)
|
||
{
|
||
var list = await _ServicePlotLayout.GetBasePointByDwg(selectRange.Value, selectOperator.Value, inputValue, dwg.DrawingFileID);
|
||
if (list == null)
|
||
{ continue; }
|
||
foreach (var basePoint in list)
|
||
{
|
||
if (basePoint.Tags.Any())
|
||
{
|
||
foreach (var tag in basePoint.Tags)
|
||
{
|
||
listDto.Add(new DtoAutoPlotLayout()
|
||
{
|
||
IsSelected = true,
|
||
DrawingFileID = dwg.DrawingFileID,
|
||
DrawingFileName = dwg.DrawingFileName,
|
||
EngineDataID = basePoint.EngineDataID,
|
||
BasePointTagNumber = basePoint.TagNumber,
|
||
Scale = basePoint.Scale,
|
||
FileId = basePoint.FileId,
|
||
PixelOnDwg = basePoint.PixelOnDwg,
|
||
IsNotDefaultSymbol = basePoint.IsNotDefaultSymbol,
|
||
X = basePoint.X,
|
||
XOff = basePoint.XOff,
|
||
YOff = basePoint.YOff,
|
||
deck = basePoint.deck,
|
||
area = basePoint.area,
|
||
AutoDrawing = "未绘制",
|
||
TagNumber = tag.TagNumber,
|
||
TagNumber_Upper = basePoint.TagNumber_Upper,
|
||
TagNumber_Lower = basePoint.TagNumber_Lower,
|
||
Tag = tag
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
listBasePoint = new ObservableCollection<DtoAutoPlotLayout>(listDto);
|
||
IsSelectAll = listBasePoint.Any() ? true : false;
|
||
isSearch = false;
|
||
AddMsg("布置图基点元件信息查询完成!");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
AddMsg("基点元件信息查询异常:" + ex.Message);
|
||
isSearch = false;
|
||
}
|
||
}
|
||
public async void onStartDrawing(object o)
|
||
{
|
||
if (isDrawing)
|
||
{
|
||
MessageBox.Show("正在自动绘制元件中,请勿操作...");
|
||
return;
|
||
}
|
||
|
||
var msg = string.Empty;
|
||
var filePath = string.Empty;
|
||
var listDto = listBasePoint.Where(a => a.IsSelected == true).ToList();
|
||
if (!listDto.Any())
|
||
{
|
||
MessageBox.Show("请先勾选基点元件信息!");
|
||
return;
|
||
}
|
||
try
|
||
{
|
||
isDrawing = true;
|
||
listMsg.Clear();
|
||
foreach (var basePoint in listDto)
|
||
{
|
||
if (basePoint.AutoDrawing == "已绘制")
|
||
{
|
||
AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已绘制,跳至下一个元件");
|
||
continue;
|
||
}
|
||
if (basePoint.AutoDrawing == "已存在")
|
||
{
|
||
AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已存在,跳至下一个元件");
|
||
continue;
|
||
}
|
||
|
||
msg = await OpenDwg(basePoint.DrawingFileID);
|
||
if (!string.IsNullOrEmpty(msg))
|
||
{
|
||
AddMsg($"图纸打开失败:{msg}", false);
|
||
continue;
|
||
}
|
||
|
||
AddMsg($"打开图纸:{basePoint.DrawingFileName} ");
|
||
var listEntitys = General.GetAllEntity();//获取图纸所有实体
|
||
var entity = listEntitys.FirstOrDefault(a => a.Handle.ToString() == basePoint.PixelOnDwg);
|
||
if (entity == null)
|
||
{
|
||
AddMsg($"当前基点:{basePoint.BasePointTagNumber} 在图上找不到,不添加此元件,跳至下一个元件", false);
|
||
continue;
|
||
}
|
||
|
||
var tag = basePoint.Tag;
|
||
if (string.IsNullOrEmpty(tag.FileId))
|
||
{
|
||
AddMsg($"当前元件:{tag.TagNumber} 的元件ID为空,不添加此元件,跳至下一个", false);
|
||
continue;
|
||
}
|
||
var tagDto = listEntitys.FirstOrDefault(a => a.TagNumber == basePoint.TagNumber);
|
||
if (tagDto != null)
|
||
{
|
||
AddMsg($"当前元件:{basePoint.TagNumber} 在图上已存在,句柄:{tagDto.Handle},不添加此元件,跳至下一个元件", false);
|
||
basePoint.AutoDrawing = "已存在";
|
||
basePoint.TagPixelOnDwg = tagDto.Handle;
|
||
continue;
|
||
}
|
||
var flag = basePoint.deck == tag.deck && basePoint.area == tag.area;
|
||
if (!flag)
|
||
{
|
||
AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{tag.TagNumber}] 的deck和area不一致,不添加此元件,跳至下一个元件", false);
|
||
continue;
|
||
}
|
||
//下载元件图纸文件
|
||
filePath = Path.Combine(GlobalObject.GetCacheFolder(), $"{tag.TagNumber}.dwg");
|
||
var obj = await _ServiceLibraryFile.GetEntity(tag.FileId);
|
||
AddMsg($"元件图纸:{tag.TagNumber}, 开始下载...");
|
||
msg = await _ServiceAnnexes.DownloadFile(filePath, obj.FolderId);
|
||
if (!string.IsNullOrEmpty(msg))
|
||
{
|
||
AddMsg($"元件图纸下载失败,信息:" + msg, false);
|
||
continue;
|
||
}
|
||
AddMsg($"元件图纸:{tag.TagNumber}, 下载成功");
|
||
//filePath = "D:\\BricsCAD\\Temp\\测试11.dwg";
|
||
//把元件的位号属性改成要绘制的位号值
|
||
flag = General.UpdateCableNo(filePath, listLibraryTagName, tag.TagNumber, tag.IsNotDefaultSymbol, tag.TagNumber_Lower, tag.TagNumber_Upper);
|
||
|
||
//X轴:图上基点的坐标X +(接口数据元件的X + 接口数据元件的XOFF -接口数据基点的X-接口数据基点的Xoff)*比例系数
|
||
//Y轴:图上基点的坐标Y +(接口数据元件的Yoff-接口数据基点的Yoff)*比例系数
|
||
double scale = 1;//比例系数
|
||
double x = entity.X + (tag.X + double.Parse(tag.XOff) - basePoint.X - double.Parse(basePoint.XOff)) * scale;
|
||
double y = entity.Y + (double.Parse(tag.YOff) - double.Parse(basePoint.XOff)) * scale;
|
||
double z = entity.Z;
|
||
Point3d tagPoint = new Point3d(x, y, z);
|
||
AddMsg($"元件图纸:{tag.TagNumber}, 开始添加进布置图中...");
|
||
msg = await AddBlock(basePoint, obj.LibraryFileName, filePath, tagPoint);
|
||
if (string.IsNullOrEmpty(msg))
|
||
{
|
||
AddMsg($"布置图:{basePoint.DrawingFileName},成功插入元件:" + tag.TagNumber);
|
||
basePoint.AutoDrawing = "已绘制";
|
||
General.SetDrawingReadOnly(dwgName, false);
|
||
}
|
||
else { AddMsg($"元件:{tag.TagNumber},绘制异常:{msg}"); }
|
||
|
||
}
|
||
AddMsg("操作已完成!");
|
||
isDrawing = false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("绘图异常:" + ex.Message);
|
||
isDrawing = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 打开图纸
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private async Task<string> OpenDwg(string dwgId)
|
||
{
|
||
try
|
||
{
|
||
|
||
string res = string.Empty;
|
||
string fullpath = string.Empty;
|
||
var dwgObj = await _ServiceDrawing.GetDrawingFile(dwgId);
|
||
var cate = await _ServiceDrawingCatalogue.GetEntity(dwgObj.DrawingCatalogueID);
|
||
if (cate.FullPath != cate.DrawingCatalogueID)
|
||
{
|
||
foreach (var id in cate.FullPath.Split(',').ToList())
|
||
{
|
||
cate = await _ServiceDrawingCatalogue.GetEntity(id);
|
||
fullpath += $"{cate.DrawingCatalogueName}\\";
|
||
}
|
||
}
|
||
else { fullpath = $"{cate.DrawingCatalogueName}\\"; }
|
||
fullpath += dwgObj.DrawingFileName;
|
||
fullpath = Path.Combine(GlobalObj.LocalWorkDir, GlobalObject.curProject.ProjectName, fullpath);
|
||
if (!File.Exists(fullpath))
|
||
{
|
||
return dwgObj.DrawingFileName + ",图纸文件不存在,请先检出到本地!";
|
||
}
|
||
var listName = General.GetAllOpenDrawingNames();
|
||
if (!listName.Contains(fullpath))
|
||
{
|
||
General.OpenDwg(fullpath);
|
||
dwgName = fullpath;
|
||
return res;
|
||
}
|
||
else
|
||
{
|
||
General.SwitchToDocument(fullpath);
|
||
dwgName = fullpath;
|
||
return res;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ex.Message;
|
||
}
|
||
}
|
||
|
||
private async Task<string> AddBlock(DtoAutoPlotLayout basePoint, string tagName, string blockDwg, Point3d tagPoint)
|
||
{
|
||
try
|
||
{
|
||
string dwgId = basePoint.DrawingFileID;
|
||
string enginedataId = basePoint.Tag.EngineDataID;
|
||
string blockDwgId = basePoint.Tag.FileId;
|
||
string tagNumber = basePoint.Tag.TagNumber;
|
||
double scale = basePoint.Scale;
|
||
string msg = string.Empty;
|
||
string tagNum = string.Empty;
|
||
var lsitEnginedata = await _ServiceObjectType.GetEngineDataListByTags(tagNumber);
|
||
if (!lsitEnginedata.Any())
|
||
{
|
||
msg = $"元件位号:{tagNumber},属性未绑定,ServiceEnginedata.GetTagPixelsById({enginedataId})接口无数据";
|
||
AddMsg(msg, false);
|
||
return msg;
|
||
}
|
||
string objTypeId = lsitEnginedata[0].ObjectTypeID;
|
||
string objTypeName = lsitEnginedata[0].ObjectTypeName;
|
||
var objId = General.AddTagDWG(blockDwg, tagName, tagNumber, objTypeId, scale, tagPoint);
|
||
#region 图纸上保存图元属性
|
||
if (!objId.IsNull)
|
||
{
|
||
AddMsg($"元件已添加至图纸,句柄:{objId.Handle.ToString()}");
|
||
AddMsg("开始关联元件属性至图纸...");
|
||
var dwgLibrary = await _ServiceLibraryFile.GetEntity(blockDwgId);
|
||
List<ec_enginedata_property> listPro = new List<ec_enginedata_property>();
|
||
var handlid = objId.Handle.ToString();//添加图元返回的句柄
|
||
ec_enginedata item = new ec_enginedata();
|
||
item.TagNumber = tagNumber;
|
||
item.ObjectTypeID = objTypeId;
|
||
item.Layout_Block_File = dwgLibrary;
|
||
//var result = await _ServiceObjectType.GetObjectTypePById(objTypeId);//添加属性
|
||
var res = await _ServiceObjectType.GetTagInfosByTags(tagNumber);
|
||
if (res.Any())
|
||
{
|
||
foreach (var dto in res[0].tags[0].EngineDataProperty)
|
||
{
|
||
listPro.Add(new ec_enginedata_property()
|
||
{
|
||
EngineDataPropertyID = dto.PropertyID,
|
||
PropertyName = dto.PropertyName,
|
||
PropertyNameEN = dto.PropertyNameEN,
|
||
PropertyValue = dto.PropertyValue,
|
||
MeasuringUnit = dto.MeasuringUnit,
|
||
PropertyGID = dto.PropertyGID,
|
||
PropertyGroupName = dto.PropertyGroupName
|
||
});
|
||
}
|
||
}
|
||
item.EngineDataProperty = listPro;
|
||
List<ec_enginedata_pixel> listPixel = new List<ec_enginedata_pixel>();
|
||
var pixelDto = new ec_enginedata_pixel()
|
||
{
|
||
TagNumber = tagNumber,
|
||
DrawingFileID = dwgId,
|
||
LibraryFileID = dwgLibrary.LibraryFileID,
|
||
PixelCode = handlid,
|
||
ObjectTypeID = objTypeId,
|
||
ObjectTypeName = objTypeName,
|
||
EngineDataProperty = listPro
|
||
};
|
||
listPixel.Add(pixelDto);
|
||
item.EngineDataPixel = listPixel;
|
||
|
||
msg = await _ServiceObjectType.UpdatePixelAndProp(item);
|
||
if (msg != string.Empty)
|
||
{
|
||
msg = "保存元件属性至图纸异常:" + msg;
|
||
AddMsg(msg, false);
|
||
return msg;
|
||
}
|
||
else
|
||
{
|
||
basePoint.TagPixelOnDwg = handlid;
|
||
AddMsg("添加元件属性至图纸成功!");
|
||
return "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
msg = $"元件:{blockDwg} ,添加失败";
|
||
AddMsg(msg, false);
|
||
return msg;
|
||
}
|
||
#endregion
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ex.Message;
|
||
}
|
||
}
|
||
public void onSelectedTag(object o)
|
||
{
|
||
var dto = listBasePoint.Where(p => p.TagNumber == o.ToString()).FirstOrDefault();
|
||
if (dto != null)
|
||
{
|
||
if (!dto.IsSelected && IsSelectAll)
|
||
{
|
||
IsSelectAll = false;
|
||
}
|
||
else if (dto.IsSelected && !IsSelectAll)
|
||
{
|
||
foreach (var item in listBasePoint)
|
||
{
|
||
if (!item.IsSelected) return;
|
||
}
|
||
IsSelectAll = true;
|
||
}
|
||
}
|
||
}
|
||
public void onSelectedAll(object o)
|
||
{
|
||
foreach (var item in listBasePoint)
|
||
{
|
||
item.IsSelected = IsSelectAll;
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 添加提示信息
|
||
/// </summary>
|
||
/// <param name="msg">信息</param>
|
||
/// <param name="isSucc">是否成功</param>
|
||
private void AddMsg(string msg, bool isSucc = true)
|
||
{
|
||
try
|
||
{
|
||
TextBlock tb = new TextBlock();
|
||
tb.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "==>> " + msg;
|
||
tb.Foreground = isSucc ? Brushes.LightSeaGreen : Brushes.Red;
|
||
listMsg.Add(tb);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("添加提示信息异常:" + ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|