009_DI-Elec/newFront/c#前端/SWS.Electrical/ViewModels/DialogAutoArrangeLayoutViewModel.cs

840 lines
35 KiB
C#
Raw Normal View History

2025-08-15 16:44:13 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2025-09-02 11:21:40 +08:00
using System.Windows.Controls;
2025-08-15 16:44:13 +08:00
using System.Windows.Forms;
using System.Windows.Input;
2025-09-02 11:21:40 +08:00
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using Bricscad.EditorInput;
using Newtonsoft.Json;
2025-08-15 16:44:13 +08:00
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;
2025-09-02 11:21:40 +08:00
using Teigha.Geometry;
using Teigha.GraphicsSystem;
2025-08-15 16:44:13 +08:00
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));
}
}
}
2025-09-02 11:21:40 +08:00
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));
}
}
}
2025-08-15 16:44:13 +08:00
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);
2025-08-15 16:44:13 +08:00
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));
}
}
}
2025-08-15 16:44:13 +08:00
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; }
2025-09-02 11:21:40 +08:00
public ICommand Command_GetBasePoint { get; set; }
public ICommand Command_SelectedTag { get; set; }
public ICommand Command_SelectedAll { get; set; }
2025-08-15 16:44:13 +08:00
PlotLayoutService _ServicePlotLayout;
DrawingServce _ServiceDrawing;
2025-09-02 11:21:40 +08:00
AnnexesService _ServiceAnnexes;
LibraryFileService _ServiceLibraryFile;
DrawingCatalogueService _ServiceDrawingCatalogue;
EnginedataService _ServiceEnginedata;
ObjectTypeService _ServiceObjectType;
ProjectSettingsService _ServiceProjectSettings;
DataItemService _ServiceDataItem;
2025-09-02 11:21:40 +08:00
List<string> listTagNumberSucc = new List<string>();
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>();//所属系统值列表
2025-08-15 16:44:13 +08:00
public DialogAutoArrangeLayoutViewModel()
{
Command_StartDrawing = new DelegateCommand(onStartDrawing);
2025-09-02 11:21:40 +08:00
Command_GetBasePoint = new DelegateCommand(onGetBasePoint);
Command_SelectedTag = new DelegateCommand(onSelectedTag);
Command_SelectedAll = new DelegateCommand(onSelectedAll);
2025-08-15 16:44:13 +08:00
title = "布置图自动绘制";
_ServicePlotLayout = GlobalObject.container.Resolve<PlotLayoutService>();
_ServiceDrawing = GlobalObject.container.Resolve<DrawingServce>();
2025-09-02 11:21:40 +08:00
_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>();
2025-08-15 16:44:13 +08:00
listDrawings = new ObservableCollection<DtoDrawing>();
2025-09-02 11:21:40 +08:00
listBasePoint = new ObservableCollection<DtoAutoPlotLayout>();
listMsg = new ObservableCollection<TextBlock>();
2025-08-15 16:44:13 +08:00
var list = new ObservableCollection<KeyValueModel>();
list.Add(new KeyValueModel { Key = "甲板号", Value = "甲板号" });
//list.Add(new KeyValueModel { Key = "区域", Value = "区域" });
2025-09-02 11:21:40 +08:00
list.Add(new KeyValueModel { Key = "所属系统", Value = "所属系统" });
2025-08-15 16:44:13 +08:00
listRange = new ObservableCollection<KeyValueModel>(list);
listOperator = new ObservableCollection<KeyValueModel>()
2025-09-02 11:21:40 +08:00
{ new KeyValueModel { Key = "等于", Value = "=" }
2025-08-15 16:44:13 +08:00
};
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;
}
}
2025-09-02 11:21:40 +08:00
public async void OnDialogOpened(IDialogParameters parameters)
2025-08-15 16:44:13 +08:00
{
2025-09-02 11:21:40 +08:00
try
2025-08-15 16:44:13 +08:00
{
//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 });
// }
// }
// }
// }
// }
// }
//}
IsBusy = true;
BusyContent = "数据加载中...";
2025-09-02 11:21:40 +08:00
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 });
}
}
2025-09-02 11:21:40 +08:00
}
}
}
}
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];
IsBusy = false;
2025-09-02 11:21:40 +08:00
}
catch (Exception ex)
{
IsBusy = false;
2025-09-02 11:21:40 +08:00
MessageBox.Show("DialogOpened异常" + ex.Message);
}
2025-08-15 16:44:13 +08:00
}
/// <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); }
}
2025-09-02 11:21:40 +08:00
/// <summary>
/// 获取基点信息
/// </summary>
/// <param name="o"></param>
public async void onGetBasePoint(object o)
2025-08-15 16:44:13 +08:00
{
if (isDrawing)
2025-09-02 11:21:40 +08:00
{
MessageBox.Show("正在自动绘制元件中,请勿操作...");
2025-09-02 11:21:40 +08:00
return;
}
var listSelDwg = listDrawings.Where(a => a.IsSelected == true).ToList();
2025-08-15 16:44:13 +08:00
if (!listSelDwg.Any())
{
2025-09-02 11:21:40 +08:00
AddMsg("请先选择布置图!");
2025-08-15 16:44:13 +08:00
MessageBox.Show("请先选择布置图!");
2025-09-02 11:21:40 +08:00
return;
}
try
{
IsBusy = true;
BusyContent = "数据加载中...";
2025-09-02 11:21:40 +08:00
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.area != null && basePoint.area.ToLower() == "err")
{ continue; }
2025-09-02 11:21:40 +08:00
if (basePoint.Tags.Any())
{
foreach (var tag in basePoint.Tags)
{
if (tag.area != null && tag.area.ToLower() == "err")
{ continue; }
2025-09-02 11:21:40 +08:00
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;
AddMsg("布置图基点元件信息查询完成!");
IsBusy = false;
2025-09-02 11:21:40 +08:00
}
catch (Exception ex)
{
AddMsg("基点元件信息查询异常:" + ex.Message);
IsBusy = false;
2025-09-02 11:21:40 +08:00
}
}
public async void onStartDrawing(object o)
{
if (isDrawing)
{
MessageBox.Show("正在自动绘制元件中,请勿操作...");
return;
2025-08-15 16:44:13 +08:00
}
2025-09-02 11:21:40 +08:00
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();
for (int i = 0; i < listDto.Count; i++)
//foreach (var basePoint in listDto)
2025-09-02 11:21:40 +08:00
{
var basePoint = listDto[i];
2025-09-02 11:21:40 +08:00
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;
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");
string blockName = string.Empty;
if (string.IsNullOrEmpty(tag.FileId))
2025-09-02 11:21:40 +08:00
{
//元件ID为空 用本地默认图块图纸
if (!string.IsNullOrEmpty(tag.TagNumber_Lower))
{
var blockDwgPath = Path.Combine(GlobalObject.GetDllPath(), "Template\\常规矩形两行图块.dwg");
if (!File.Exists(blockDwgPath))
{
AddMsg($"默认图块找不到:{blockDwgPath}", false);
continue;
}
//默认上下图块
blockName = "常规矩形两行图块";
File.Copy(blockDwgPath, filePath, true);
}
else
{
var blockDwgPath = Path.Combine(GlobalObject.GetDllPath(), "Template\\常规矩形单行图块.dwg");
if (!File.Exists(blockDwgPath))
{
AddMsg($"默认图块找不到:{blockDwgPath}", false);
continue;
}
//默认图块,只有中间部分
blockName = "常规矩形单行图块";
File.Copy(blockDwgPath, filePath, true);
}
2025-09-02 11:21:40 +08:00
}
else
2025-09-02 11:21:40 +08:00
{
//下载元件图纸文件
var obj = await _ServiceLibraryFile.GetEntity(tag.FileId);
blockName = obj.LibraryFileName;
AddMsg($"元件图纸:{tag.TagNumber} 开始下载...");
msg = await _ServiceAnnexes.DownloadFile(filePath, obj.FolderId);
if (!string.IsNullOrEmpty(msg))
{
AddMsg($"元件图纸下载失败,信息:" + msg, false);
continue;
}
AddMsg($"元件图纸:{tag.TagNumber} 下载成功");
2025-09-02 11:21:40 +08:00
}
//filePath = "D:\\BricsCAD\\Temp\\测试11.dwg";
//把元件的位号属性改成要绘制的位号值
var flag = General.UpdateCableNo(filePath, listLibraryTagName, tag.TagNumber, tag.IsNotDefaultSymbol, tag.TagNumber_Upper, tag.TagNumber_Lower);
2025-09-02 11:21:40 +08:00
//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, blockName, filePath, tagPoint);
2025-09-02 11:21:40 +08:00
if (string.IsNullOrEmpty(msg))
{
AddMsg($"布置图:{basePoint.DrawingFileName},成功插入元件:" + tag.TagNumber);
basePoint.AutoDrawing = "已绘制";
//当下一个要画元件的图纸和当前图纸不一样时,保存图纸
if (i + 1 >= listDto.Count)
{ General.SetDrawingReadOnly(dwgName, false); }
else
{
var nextTag = listDto[i + 1];
if (basePoint.DrawingFileID != nextTag.DrawingFileID)
{ General.SetDrawingReadOnly(dwgName, false); }
}
2025-09-02 11:21:40 +08:00
}
else { AddMsg($"元件:{tag.TagNumber},绘制异常:{msg}"); }
}
AddMsg("操作已完成!");
isDrawing = false;
}
catch (Exception ex)
2025-08-15 16:44:13 +08:00
{
2025-09-02 11:21:40 +08:00
MessageBox.Show("绘图异常:" + ex.Message);
isDrawing = false;
2025-08-15 16:44:13 +08:00
}
}
2025-09-02 11:21:40 +08:00
/// <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 + ",图纸文件不存在,请先检出到本地!";
}
if (dwgObj.DrawingFileName == General.GetDwgName())
{
return res;
}
2025-09-02 11:21:40 +08:00
var listName = General.GetAllOpenDrawingNames();
if (!listName.Contains(fullpath))
{
General.OpenDwg(fullpath);
dwgName = fullpath;
return res;
}
else
{
General.SwitchToDocument(fullpath);
dwgName = fullpath;
return res;
}
2025-08-15 16:44:13 +08:00
2025-09-02 11:21:40 +08:00
}
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 == null ? "" : dwgLibrary.LibraryFileID,
2025-09-02 11:21:40 +08:00
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);
}
}
2025-08-15 16:44:13 +08:00
}
}