diff --git a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Learun.Application.TwoDevelopment.csproj.user b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Learun.Application.TwoDevelopment.csproj.user index 0b246432..a607660d 100644 --- a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Learun.Application.TwoDevelopment.csproj.user +++ b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Learun.Application.TwoDevelopment.csproj.user @@ -1,6 +1,6 @@ - ProjectFiles + ShowAllFiles \ No newline at end of file diff --git a/newFront/c#前端/SWS.CAD.Base/General.cs b/newFront/c#前端/SWS.CAD.Base/General.cs index 36bdcaf5..8df9cbb4 100644 --- a/newFront/c#前端/SWS.CAD.Base/General.cs +++ b/newFront/c#前端/SWS.CAD.Base/General.cs @@ -14,6 +14,7 @@ using Entity = Teigha.DatabaseServices.Entity; using Path = System.IO.Path; using Color = Teigha.Colors.Color; using System.Security.Cryptography; +using System.Threading.Tasks; namespace SWS.CAD.Base { public static class General @@ -137,7 +138,7 @@ namespace SWS.CAD.Base using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; - ObjectId idBtr = doc.Database.Insert(blockName, blockName, blockDb, true); + ObjectId idBtr = doc.Database.Insert(blockName, blockName, blockDb, true); BlockTableRecord curBtr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; var block = new BlockReference(Point3d.Origin, idBtr); block.Position = position; @@ -1065,12 +1066,13 @@ namespace SWS.CAD.Base } #endregion - #region 获取当前图纸所有实体 + #region 获取当前图纸XData不为空的所有实体 /// /// 获取当前图纸XData不为空的所有实体 /// + /// 要删除的位号 /// - public static List GetAllEntity() + public static List GetAllEntity(List listTagNumber) { doc = Application.DocumentManager.MdiActiveDocument; ed = doc.Editor; @@ -1084,18 +1086,20 @@ namespace SWS.CAD.Base { // 获取模型空间块表记录 BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; - BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord; - + BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord; + // 收集要删除的块参照 + ObjectIdCollection idsToErase = new ObjectIdCollection(); // 遍历模型空间中的所有实体 - foreach (ObjectId objId in modelSpace) + foreach (ObjectId objId in btr) { - Entity entity = tr.GetObject(objId, OpenMode.ForRead) as Entity; + Entity entity = tr.GetObject(objId, OpenMode.ForWrite) as Entity; if (entity != null && entity.XData != null) { // 提取句柄(十六进制格式) var blockRef = entity as BlockReference; if (blockRef != null) { + bool flag = true; var dto = new DtoBasePoint() { Handle = entity.Handle.ToString(), @@ -1113,14 +1117,27 @@ namespace SWS.CAD.Base if (attRef.Tag == "HKSK_TAG") { dto.TagNumber = attRef.TextString; + if (listTagNumber != null && listTagNumber.Contains(attRef.TextString)) + { + idsToErase.Add(objId); + flag = false; + } break; } } - - handles.Add(dto); + if (flag) + { handles.Add(dto); } } } } + if (idsToErase.Count > 0) + { + foreach (ObjectId id in idsToErase) + { + Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite); + ent.Erase(); + } + } tr.Commit(); } @@ -1920,15 +1937,18 @@ namespace SWS.CAD.Base /// 位号值 /// true:默认块,false:异性块 /// - public static bool UpdateCableNo(string dwgName, List listTagName, string tagNumber, bool IsNotDefaultSymbol, string tag, string system) + public static string UpdateCableNo(string dwgName, List listTagName, string tagNumber, bool IsNotDefaultSymbol, string tag, string system) { try { - OpenDwg(dwgName); + //OpenDwg(dwgName); + Application.DocumentManager.Open(dwgName); + //Thread.Sleep(1000); doc = Application.DocumentManager.MdiActiveDocument; ed = doc.Editor; db = doc.Database; + var s=doc.Name; // 开启事务 using (Transaction tr = db.TransactionManager.StartTransaction()) { @@ -1986,12 +2006,13 @@ namespace SWS.CAD.Base tr.Commit(); } doc.CloseAndSave(dwgName); - return true; + Thread.Sleep(20); + return ""; } catch (Exception ex) { SendMessage(ex.Message); - return false; + return ex.Message; } } @@ -2019,7 +2040,7 @@ namespace SWS.CAD.Base // 创建多行文字对象 MText mText = new MText(); mText.Contents = textInfo.Text; - mText.Location = textInfo.Position; + mText.Location = textInfo.Position; mText.TextHeight = textInfo.Height; mText.Width = textInfo.Width; // 设置文本宽度,控制自动换行 if (textInfo.Align == 0) @@ -2040,7 +2061,7 @@ namespace SWS.CAD.Base DBText dbText = new DBText(); dbText.TextString = textInfo.Text; dbText.Position = textInfo.Position; - dbText.AlignmentPoint= textInfo.Position; + dbText.AlignmentPoint = textInfo.Position; dbText.Height = textInfo.Height; if (textInfo.Align == 0) { @@ -2078,7 +2099,7 @@ namespace SWS.CAD.Base /// 坐标位置 /// public static ObjectId AddBlockDWG(string filePath, string blockName, Point3d position) - { + { Document doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; ObjectId oid = ObjectId.Null; @@ -2118,10 +2139,10 @@ namespace SWS.CAD.Base // 处理插入结果 btr.AppendEntity(br); - tr.AddNewlyCreatedDBObject(br, true); + tr.AddNewlyCreatedDBObject(br, true); tr.Commit(); - oid = br.Id; - } + oid = br.Id; + } } catch (Exception ex) { diff --git a/newFront/c#前端/SWS.CAD.Base/bin/Debug/log4net.config b/newFront/c#前端/SWS.CAD.Base/bin/Debug/log4net.config index dc48092d..2e52c6ab 100644 --- a/newFront/c#前端/SWS.CAD.Base/bin/Debug/log4net.config +++ b/newFront/c#前端/SWS.CAD.Base/bin/Debug/log4net.config @@ -8,13 +8,30 @@ - + + + + + + + + + + + + + + + + + + + - - + @@ -29,7 +46,25 @@ - + + + + + + + + + + + + + + + + + + + @@ -70,24 +105,6 @@ - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/newFront/c#前端/SWS.CAD/Commands.cs b/newFront/c#前端/SWS.CAD/Commands.cs index a28f2dcd..d89cee31 100644 --- a/newFront/c#前端/SWS.CAD/Commands.cs +++ b/newFront/c#前端/SWS.CAD/Commands.cs @@ -25,6 +25,10 @@ using GlobalObject = SWS.Commons.GlobalObject; using SWS.Model; using SWS.Service; using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using SWS.CAD.ViewModels; +using SWS.CAD.Base; +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; [assembly: CommandClass(typeof(Commands))] @@ -67,6 +71,15 @@ namespace SWS.CAD panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); panel.Visible = true; + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); } catch (System.Exception e) { @@ -191,9 +204,17 @@ namespace SWS.CAD login.ButtonStyle = RibbonButtonStyle.SmallWithText; login.CommandHandler = new DelegateCommand(x => { - var loginView = GlobalObject.container.Resolve(); - //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 - Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } }); login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); login.Id = "用户登录"; @@ -414,9 +435,106 @@ namespace SWS.CAD btnSwitchbox.ToolTip = "分电箱"; btnSwitchbox.Text = "分电箱"; btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; - btnSwitchbox.CommandHandler = new DelegateCommand(x => + btnSwitchbox.CommandHandler = new DelegateCommand(async x => { - MessageBox.Show("功能开发中..."); + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + }); btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); btnSwitchbox.Id = "分电箱"; @@ -569,7 +687,7 @@ namespace SWS.CAD var handId = (cable.Handle.ToString()); _objectTypeService = GlobalObject.container.Resolve(); var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); - if (res != null) + if (res != null) { if (res.Count == 1) { @@ -584,7 +702,7 @@ namespace SWS.CAD } } - + } tr.Commit(); } @@ -909,6 +1027,7 @@ namespace SWS.CAD //选择的元素返回的属性信息 var ResTagInfosByPixels = new Model.ec_objecttype(); var listPropertys = new List(); + //获取服务接口 var _objectTypeService = GlobalObject.container.Resolve(); var _iOModuleService = GlobalObject.container.Resolve(); // 持续选择直到获取有效电缆 @@ -981,7 +1100,7 @@ namespace SWS.CAD //获取位号的电缆属性,判断是否设置电缆规格 var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); - if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) { System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; @@ -1128,11 +1247,11 @@ namespace SWS.CAD } else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) { - Tag = Tag + (char)('A' + (n-1)); + Tag = Tag + (char)('A' + (n - 1)); } else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) { - Tag = (i+1)+"-"+ n.ToString(); + Tag = (i + 1) + "-" + n.ToString(); } break; case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 @@ -1146,7 +1265,7 @@ namespace SWS.CAD } else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) { - Tag = (i+1) + "-" + (j+1).ToString(); + Tag = (i + 1) + "-" + (j + 1).ToString(); } break; } diff --git a/newFront/c#前端/SWS.CAD/Commands_BACKUP_547.cs b/newFront/c#前端/SWS.CAD/Commands_BACKUP_547.cs new file mode 100644 index 00000000..39f172cf --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_BACKUP_547.cs @@ -0,0 +1,1643 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +<<<<<<< HEAD +using SWS.CAD.ViewModels; +using SWS.CAD.Base; +======= +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; +>>>>>>> c78178035f19e4ed599c777c75da005f0d2787ad + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(async x => + { + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + //获取服务接口 + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_BACKUP_608.cs b/newFront/c#前端/SWS.CAD/Commands_BACKUP_608.cs new file mode 100644 index 00000000..39f172cf --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_BACKUP_608.cs @@ -0,0 +1,1643 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +<<<<<<< HEAD +using SWS.CAD.ViewModels; +using SWS.CAD.Base; +======= +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; +>>>>>>> c78178035f19e4ed599c777c75da005f0d2787ad + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(async x => + { + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + //获取服务接口 + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_BACKUP_669.cs b/newFront/c#前端/SWS.CAD/Commands_BACKUP_669.cs new file mode 100644 index 00000000..39f172cf --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_BACKUP_669.cs @@ -0,0 +1,1643 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +<<<<<<< HEAD +using SWS.CAD.ViewModels; +using SWS.CAD.Base; +======= +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; +>>>>>>> c78178035f19e4ed599c777c75da005f0d2787ad + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(async x => + { + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + //获取服务接口 + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_BASE_547.cs b/newFront/c#前端/SWS.CAD/Commands_BASE_547.cs new file mode 100644 index 00000000..a28f2dcd --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_BASE_547.cs @@ -0,0 +1,1521 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n-1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1)+"-"+ n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1) + "-" + (j+1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_BASE_608.cs b/newFront/c#前端/SWS.CAD/Commands_BASE_608.cs new file mode 100644 index 00000000..a28f2dcd --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_BASE_608.cs @@ -0,0 +1,1521 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n-1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1)+"-"+ n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1) + "-" + (j+1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_BASE_669.cs b/newFront/c#前端/SWS.CAD/Commands_BASE_669.cs new file mode 100644 index 00000000..a28f2dcd --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_BASE_669.cs @@ -0,0 +1,1521 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n-1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1)+"-"+ n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1) + "-" + (j+1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_LOCAL_547.cs b/newFront/c#前端/SWS.CAD/Commands_LOCAL_547.cs new file mode 100644 index 00000000..e5d7383d --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_LOCAL_547.cs @@ -0,0 +1,1629 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using SWS.CAD.ViewModels; +using SWS.CAD.Base; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(async x => + { + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + //获取服务接口 + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_LOCAL_608.cs b/newFront/c#前端/SWS.CAD/Commands_LOCAL_608.cs new file mode 100644 index 00000000..e5d7383d --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_LOCAL_608.cs @@ -0,0 +1,1629 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using SWS.CAD.ViewModels; +using SWS.CAD.Base; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(async x => + { + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + //获取服务接口 + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_LOCAL_669.cs b/newFront/c#前端/SWS.CAD/Commands_LOCAL_669.cs new file mode 100644 index 00000000..e5d7383d --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_LOCAL_669.cs @@ -0,0 +1,1629 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using SWS.CAD.ViewModels; +using SWS.CAD.Base; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + try + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(async x => + { + //if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + //{ + // MessageBox.Show("请先登录系统并选择项目!"); + // return; + //} + ////在SWS系统内打开且不是只读的图纸才可 + //var dwgName = General.GetDwgName(); + //var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + //if (dwgFile == null) + //{ return; } + //Document doc = Application.DocumentManager.MdiActiveDocument; + //Database db = doc.Database; + //Editor ed = doc.Editor; + ////选择的元素返回的属性信息 + //var ResTagInfosByPixels = new Model.ec_objecttype(); + //var listPropertys = new List(); + ////获取服务接口 + //var _objectTypeService = GlobalObject.container.Resolve(); + //var _iOModuleService = GlobalObject.container.Resolve(); + //// 持续选择直到获取有效电缆 + //bool isValidCable = false; + + //try + //{ + // #region 选择电缆 + // // 创建选择选项(禁用回车确认) + // PromptEntityOptions options = new PromptEntityOptions("\n请单击选择对象: "); + // options.AllowNone = false; // 禁止空选 + + // // 执行选择(直接单击生效) + // PromptEntityResult resultEntity = ed.GetEntity(options); + // //WindowVisibility = System.Windows.Visibility.Hidden; + + // while (resultEntity.Status == PromptStatus.OK) + // { + // using (Transaction tr = db.TransactionManager.StartTransaction()) + // { + // // 获取选中的电缆实体 + // Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + // //if (cable != null&&cable.XData != null) + // if (cable != null) + // { + // // 获取句柄(Handle 是字符串类型) + // var handId = (cable.Handle.ToString()); + // var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + // if (res != null) + // { + // if (res.Count == 1) + // { + // var item = res[0]; + // var objTypeName = item.ObjectTypeName; + // if (!objTypeName.Contains("电缆")) + // { + // ResTagInfosByPixels = item; + // isValidCable = true; // 校验通过 + // ed.WriteMessage($"\n已选择对象:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + // } + + // } + // } + + // } + // tr.Commit(); + // } + // if (isValidCable) + // { + // break; + // } + // else + // { + // ed.WriteMessage($"\n已选择电缆:"); + // resultEntity = ed.GetEntity(options); + // } + + // } + // #endregion + //} + //catch (System.Exception ex) + //{ + // ed.WriteMessage($"\n错误: {ex.Message}"); + //} + + if (true) + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSectionBox), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + //获取服务接口 + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_REMOTE_547.cs b/newFront/c#前端/SWS.CAD/Commands_REMOTE_547.cs new file mode 100644 index 00000000..76c62baf --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_REMOTE_547.cs @@ -0,0 +1,1532 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n-1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1)+"-"+ n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1) + "-" + (j+1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_REMOTE_608.cs b/newFront/c#前端/SWS.CAD/Commands_REMOTE_608.cs new file mode 100644 index 00000000..76c62baf --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_REMOTE_608.cs @@ -0,0 +1,1532 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n-1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1)+"-"+ n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1) + "-" + (j+1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/Commands_REMOTE_669.cs b/newFront/c#前端/SWS.CAD/Commands_REMOTE_669.cs new file mode 100644 index 00000000..76c62baf --- /dev/null +++ b/newFront/c#前端/SWS.CAD/Commands_REMOTE_669.cs @@ -0,0 +1,1532 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Bricscad.Ribbon; +using Bricscad.Windows; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD; +using SWS.CAD.CADFunc; +using SWS.CAD.Event; +using SWS.CAD.Views; +using SWS.CAD.Views.Dialog; +using Teigha.DatabaseServices; +using Teigha.Runtime; +using Telerik.Windows.Controls; +using Unity; +using Application = Bricscad.ApplicationServices.Application; +using Panel = Bricscad.Windows.Panel; +using GlobalObject = SWS.Commons.GlobalObject; +using SWS.Model; +using SWS.Service; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using System.Windows; +using MessageBox = System.Windows.Forms.MessageBox; + + +[assembly: CommandClass(typeof(Commands))] +[assembly: ExtensionApplication(typeof(Commands))] +namespace SWS.CAD +{ + public partial class Commands : IExtensionApplication + { + + public void Initialize() + { + + try + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (RibbonServices.RibbonPaletteSet == null) + RibbonServices.CreateRibbonPaletteSet(); //needed for ribbon samples + Start.RegisterTypes(); + DockingTemplate dockTemplate = new DockingTemplate(); + dockTemplate.DefaultStackId = "DI-ELEC_LDock"; //default stack is RDOCK panelset + dockTemplate.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate.DefaultDock = DockSides.Left; //dock alone at right in case RDOCK panelset isn't available + + var drawingView = GlobalObject.container.Resolve(); + Panel panel = new Panel(nameof(LeftPanel), dockTemplate, drawingView); + panel.Title = "DI_左面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + AddTab(); + + DockingTemplate dockTemplate2 = new DockingTemplate(); + dockTemplate2.DefaultStackId = "RDOCK"; //default stack is RDOCK panelset + dockTemplate2.DefaultStackZ = 20; //default to position 20 (bottom of the stack) + dockTemplate2.DefaultDock = DockSides.Right; //dock alone at right in case RDOCK panelset isn't available + + var drawingView2 = GlobalObject.container.Resolve(); + panel = new Panel(nameof(RightPanel), dockTemplate2, drawingView2); + panel.Title = "DI_右面板"; + panel.Icon = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CSharp.ico"); + panel.Visible = true; + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); + } + catch (System.Exception e) + { + Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); + } + } + + + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + // 记录异常信息到日志文件,这里简单打印到控制台 + System.Exception ex = e.ExceptionObject as System.Exception; + Console.WriteLine($"发生未处理的异常: {ex.Message}"); + Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + + // 关闭所有打开的对话框窗口 + + + // 提示用户发生了错误 + MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (System.Exception innerEx) + { + // 如果在处理异常时又发生了异常,简单打印信息 + Console.WriteLine($"处理异常时发生错误: {innerEx.Message}"); + } + } + + public void Terminate() + { + } + + #region 显示属性弹窗 + /// + /// 显示属性弹窗 + /// + private ObservableCollection ShowPropertyMessage(string title, List listPropertys) + { + + ObservableCollection ReslistPro = new ObservableCollection(); + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.title.ToString(), title); + para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); + } + else if (RES.Result == ButtonResult.No) + { + } + }); + return ReslistPro; + } + #endregion + + void AddTab() + { + RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab + + if (rbnCtrl == null) return; + #region create Ribbon tab + RibbonTab tab1 = new RibbonTab(); + tab1.Title = "智设电气(2)"; + tab1.Id = "智设电气(2)"; + rbnCtrl.Tabs.Add(tab1);//一个就行了 + #endregion + //RibbonControl - RibbonTab - RibbonPanel - RibbonPanelSource - RibbonButton + #region Ribbon 项目操作 + RibbonPanelSource userSource = new RibbonPanelSource(); + userSource.Title = "项目操作"; + userSource.Id = "项目操作"; + RibbonPanel userPanel = new RibbonPanel(); + userPanel.Source = userSource; + tab1.Panels.Add(userPanel); + #region buttons 选择项目 + RibbonButton project = new RibbonButton(); + project.ToolTip = "选择项目"; + project.Text = "选择项目"; + project.ButtonStyle = RibbonButtonStyle.LargeWithText; + project.CommandHandler = new DelegateCommand(x => + { + var projectView = GlobalObject.container.Resolve(); + if (GlobalObject.userInfo != null) + { + Application.ShowModalWindow(Application.MainWindow.Handle, projectView); + } + + }); + project.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OpenProject.png"); + project.Id = "选择项目"; + userSource.Items.Add(project); + #endregion + #region buttons 刷新项目 + RibbonButton btnRefresh = new RibbonButton(); + btnRefresh.ToolTip = "刷新项目"; + btnRefresh.Text = "刷新项目"; + btnRefresh.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefresh.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefresh.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshProject.png"); + btnRefresh.Id = "刷新项目"; + userSource.Items.Add(btnRefresh); + #endregion + + //垂直排列按钮panel + RibbonRowPanel ribbonRowPanel = new RibbonRowPanel(); + + #region buttons 用户登录 + + RibbonButton login = new RibbonButton(); + login.ToolTip = "用户登录"; + login.Text = "用户登录"; + login.ButtonStyle = RibbonButtonStyle.SmallWithText; + login.CommandHandler = new DelegateCommand(x => + { + var loginView = GlobalObject.container.Resolve(); + //Application.ShowModalDialog(Application.MainWindow,);// 用来显示WinForms对话框 + Application.ShowModalWindow(Application.MainWindow.Handle, loginView);//用来显示WPF的对话框,任务栏里可以看到2个Windows + }); + login.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Login.png"); + login.Id = "用户登录"; + //userSource.Items.Add(login); + ribbonRowPanel.Items.Add(login); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性窗口 + RibbonButton btnProperty = new RibbonButton(); + btnProperty.ToolTip = "属性窗口"; + btnProperty.Text = "属性窗口"; + btnProperty.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnProperty.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnProperty.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + btnProperty.Id = "属性窗口"; + ribbonRowPanel.Items.Add(btnProperty); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 项目消息 + RibbonButton UserNotification = new RibbonButton(); + UserNotification.ToolTip = "项目消息"; + UserNotification.Text = "项目消息"; + UserNotification.ButtonStyle = RibbonButtonStyle.SmallWithText; + UserNotification.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + try + { + var View = GlobalObject.container.Resolve(); + var eventAggregator = GlobalObject.container.Resolve(); + eventAggregator.GetEvent().Publish(new List()); + Application.ShowModalWindow(Application.MainWindow.Handle, View); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + }); + UserNotification.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Message.png"); + UserNotification.Id = "项目消息"; + //userSource.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(UserNotification); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + + userSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 快速计算 + RibbonPanelSource calcSource = new RibbonPanelSource(); + calcSource.Title = "快速计算"; + calcSource.Id = "快速计算"; + RibbonPanel calcPanel = new RibbonPanel(); + calcPanel.Source = calcSource; + tab1.Panels.Add(calcPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆压降 + RibbonButton btnCableDrop = new RibbonButton(); + btnCableDrop.ToolTip = "电缆压降"; + btnCableDrop.Text = "电缆压降"; + btnCableDrop.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableDrop.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCableDrop.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalCable.png"); + btnCableDrop.Id = "电缆压降"; + ribbonRowPanel.Items.Add(btnCableDrop); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 启动顺序 + RibbonButton btnCalBoot = new RibbonButton(); + btnCalBoot.ToolTip = "启动顺序"; + btnCalBoot.Text = "启动顺序"; + btnCalBoot.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCalBoot.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCalBoot.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CalBoot.png"); + btnCalBoot.Id = "启动顺序"; + ribbonRowPanel.Items.Add(btnCalBoot); + #endregion + calcSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 设计成图 + RibbonPanelSource designSource = new RibbonPanelSource(); + designSource.Title = "设计成图"; + designSource.Id = "设计成图"; + RibbonPanel designPanel = new RibbonPanel(); + designPanel.Source = designSource; + tab1.Panels.Add(designPanel); + //大按钮 + #region buttons 绘照明线路 + RibbonButton btnLightLine = new RibbonButton(); + btnLightLine.ToolTip = "绘照明线路"; + btnLightLine.Text = "绘照明线路"; + btnLightLine.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnLightLine.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLine.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLine.Id = "绘照明线路"; + designSource.Items.Add(btnLightLine); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成端子图 + RibbonButton btnEquipmentjoin = new RibbonButton(); + btnEquipmentjoin.ToolTip = "生成端子图"; + btnEquipmentjoin.Text = "生成端子图"; + btnEquipmentjoin.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentjoin.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentjoin.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Equipmentjoin.png"); + btnEquipmentjoin.Id = "生成端子图"; + ribbonRowPanel.Items.Add(btnEquipmentjoin); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成系统图 + RibbonButton btnJoinSys = new RibbonButton(); + btnJoinSys.ToolTip = "生成系统图"; + btnJoinSys.Text = "生成系统图"; + btnJoinSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnJoinSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnJoinSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"joinsys.png"); + btnJoinSys.Id = "生成系统图"; + ribbonRowPanel.Items.Add(btnJoinSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成OPC + RibbonButton btnOPC = new RibbonButton(); + btnOPC.ToolTip = "生成OPC"; + btnOPC.Text = "生成OPC"; + btnOPC.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnOPC.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnOPC.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"OPC.png"); + btnOPC.Id = "生成OPC"; + ribbonRowPanel.Items.Add(btnOPC); + #endregion + designSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 生成布置图 + RibbonButton btnPlaneLayout = new RibbonButton(); + btnPlaneLayout.ToolTip = "生成布置图"; + btnPlaneLayout.Text = "生成布置图"; + btnPlaneLayout.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPlaneLayout.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPlaneLayout.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"PlaneLayout.png"); + btnPlaneLayout.Id = "生成布置图"; + ribbonRowPanel.Items.Add(btnPlaneLayout); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 生成链路系统图 + RibbonButton btnEquipmentSys = new RibbonButton(); + btnEquipmentSys.ToolTip = "生成链路系统图"; + btnEquipmentSys.Text = "生成链路系统图"; + btnEquipmentSys.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnEquipmentSys.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnEquipmentSys.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"EquipmentSys.png"); + btnEquipmentSys.Id = "生成链路系统图"; + ribbonRowPanel.Items.Add(btnEquipmentSys); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 照明回路开关 + RibbonButton btnBatchSwitch = new RibbonButton(); + btnBatchSwitch.ToolTip = "照明回路开关"; + btnBatchSwitch.Text = "照明回路开关"; + btnBatchSwitch.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnBatchSwitch.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnBatchSwitch.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"BatchSwitch.png"); + btnBatchSwitch.Id = "照明回路开关"; + ribbonRowPanel.Items.Add(btnBatchSwitch); + #endregion + designSource.Items.Add(ribbonRowPanel); + + #endregion + + #region Ribbon 数据管理 + RibbonPanelSource dataSource = new RibbonPanelSource(); + dataSource.Title = "数据管理"; + dataSource.Id = "数据管理"; + RibbonPanel dataPanel = new RibbonPanel(); + dataPanel.Source = dataSource; + tab1.Panels.Add(dataPanel); + //大按钮 + #region buttons 分电箱 + RibbonButton btnSwitchbox = new RibbonButton(); + btnSwitchbox.ToolTip = "分电箱"; + btnSwitchbox.Text = "分电箱"; + btnSwitchbox.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnSwitchbox.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnSwitchbox.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Switchbox.png"); + btnSwitchbox.Id = "分电箱"; + dataSource.Items.Add(btnSwitchbox); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 平行电缆 + RibbonButton btnParallel = new RibbonButton(); + btnParallel.ToolTip = "平行电缆"; + btnParallel.Text = "平行电缆"; + btnParallel.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnParallel.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 平行电缆 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + if (string.IsNullOrEmpty(GlobalObject.currentTagNumber)) + { return; } + //选择集数量只有1才行 + int count = General.SelectedCount(); + if (count != 1) + { + MessageBox.Show("请选择1个电缆!"); + return; + } + //var listHandid = General.GetSelectedHandles(); + //if (listHandid.Count != 1) + //{ + // MessageBox.Show("请选择1个电缆!"); + // return; + //} + //var tagNumber = listHandid[0]; + var _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByTags(GlobalObject.currentTagNumber); + if (!res.Any()) + { + //MessageBox.Show("获取位号数据异常:"); + return; + } + if (!GlobalObject.IsCable(res[0])) + { + MessageBox.Show("选中的元素不是电缆!"); + return; + } + //取“平行电缆”和“平行电缆位号”属性 + + var listPro = res[0].props; + var listTaginfo = res[0].tags[0].EngineDataProperty; + var pro1 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var tag1 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆"); + var model1 = new propertyModel() + { + Id = tag1.EngineDataID, + DisplayText = pro1.PropertyName, + PropertyValue = tag1.PropertyValue, + DetailId = tag1.EngineDataPropertyID + }; + var pro2 = listPro.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var tag2 = listTaginfo.FirstOrDefault(a => a.PropertyName == "平行电缆位号"); + var model2 = new propertyModel() + { + Id = tag2.EngineDataID, + DisplayText = pro2.PropertyName, + PropertyValue = tag2.PropertyValue, + DetailId = tag2.EngineDataPropertyID, + Unit = "", + IsRefreshUI = true + }; + + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + para.Add(GlobalObject.dialogPar.info.ToString(), res[0]); + para.Add(GlobalObject.dialogPar.para1.ToString(), model1); + para.Add(GlobalObject.dialogPar.para2.ToString(), model2); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogParallelCable), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + #endregion + }); + btnParallel.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Parallel.png"); + btnParallel.Id = "平行电缆"; + ribbonRowPanel.Items.Add(btnParallel); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 电缆连接 + RibbonButton btnCableConnect = new RibbonButton(); + btnCableConnect.ToolTip = "电缆连接"; + btnCableConnect.Text = "电缆连接"; + btnCableConnect.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableConnect.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + #region 电缆连接 + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if (string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), dwgFile.Id); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogCableConnection), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + + #endregion + }); + btnCableConnect.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableConnect.png"); + btnCableConnect.Id = "电缆连接"; + ribbonRowPanel.Items.Add(btnCableConnect); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons IO分配 + RibbonButton btnIO = new RibbonButton(); + btnIO.ToolTip = "IO分配"; + btnIO.Text = "IO分配"; + btnIO.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnIO.CommandHandler = new DelegateCommand(x => + { + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogIODistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnIO.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"IO.png"); + btnIO.Id = "IO分配"; + ribbonRowPanel.Items.Add(btnIO); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 信号管理 + RibbonButton btnSinalManage = new RibbonButton(); + btnSinalManage.ToolTip = "信号管理"; + btnSinalManage.Text = "信号管理"; + btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSinalManage.CommandHandler = new DelegateCommand(x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(SWS.WPF.Views.DialogSignalManagement), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + }); + btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SinalManage.png"); + btnSinalManage.Id = "信号管理"; + ribbonRowPanel.Items.Add(btnSinalManage); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 信号预分配 + RibbonButton btnCableSinal = new RibbonButton(); + btnCableSinal.ToolTip = "信号预分配"; + btnCableSinal.Text = "信号预分配"; + btnCableSinal.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCableSinal.CommandHandler = new DelegateCommand(async x => + { + if (GlobalObject.userInfo == null || GlobalObject.curProject == null) + { + MessageBox.Show("请先登录系统并选择项目!"); + return; + } + + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + var _objectTypeService = GlobalObject.container.Resolve(); + var _iOModuleService = GlobalObject.container.Resolve(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + #region 选择电缆 + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + //WindowVisibility = System.Windows.Visibility.Hidden; + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + + } + #endregion + + + //Thread.Sleep(2000); + if (isValidCable) + { + var ResTagNumberById = await _objectTypeService.GetTagNumberById(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault(); + CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1); + var LatestSerialNumber = await _objectTypeService.GetLatestSerialNumber(ResTagInfosByPixels.tags.FirstOrDefault().ObjectTypeID); + //获取位号的电缆属性,判断是否设置电缆规格 + var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(ResTagInfosByPixels.tags.FirstOrDefault().TagNumber)).FirstOrDefault(); + if(string.IsNullOrEmpty(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + //if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault())) + { + System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); return; + + } + var ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + //如果配置不存在 + if (ResCableEngID == null) + { + listPropertys = new List(); + System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question); + if (result == System.Windows.MessageBoxResult.OK) + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "homerun";//母线 + ec_Cable.Cable_Format = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault(); + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n - 1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + n.ToString(); + } + break; + case "按电缆对编号": + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i + 1) + "-" + (j + 1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + else + { + listPropertys = new List(); + Dictionary pulldownlist; + + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("数字", "数字"); + pulldownlist.Add("字母", "字母"); + pulldownlist.Add("电缆对序号", "电缆对序号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + pulldownlist = new Dictionary(); + pulldownlist.Add("按电缆编号", "按电缆编号"); + pulldownlist.Add("按电缆对编号", "按电缆对编号"); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, }); + listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, }); + //显示属性弹窗 + var ReslistPro = ShowPropertyMessage("新建" + ResTagInfosByPixels.tags.FirstOrDefault().TagNumber + "电缆配置", listPropertys); + if (ReslistPro == null || ReslistPro.Count() == 0) return; + ec_Cable ec_Cable = new ec_Cable(); + ec_Cable.CableClass = "conventional";//常规电缆 + ec_Cable.EngineerDataID = ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID; + ec_Cable.Sets = new List(); + int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0; + int n = 0; + for (int i = 0; i < CableSetCount; i++) + { + ec_CableSet ec_CableSet = new ec_CableSet(); + ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1); + ec_CableSet.CableSetSeq = i + 1; + ec_CableSet.Wires = new List(); + int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0; + for (int j = 0; j < WireCount; j++) + { + n++; + ec_CableSetWire ec_CableSetWire = new ec_CableSetWire(); + ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)]; + ec_CableSetWire.SetLevel = j + 1; + string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀 + string Tag = "";//线号名的中间部分 + switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault()) + { + case "按电缆编号"://所有的电缆对中的电芯一起编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = n.ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + (n-1)); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1)+"-"+ n.ToString(); + } + break; + case "按电缆对编号"://一个电缆对中线号按顺序编号,另一个电缆对中线号重新从1开始编号 + if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字")) + { + Tag = (j + 1).ToString(); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母")) + { + Tag = Tag + (char)('A' + j); + } + else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号")) + { + Tag = (i+1) + "-" + (j+1).ToString(); + } + break; + } + ec_CableSetWire.Wire_Tag = a + Tag; + ec_CableSet.Wires.Add(ec_CableSetWire); + } + ec_Cable.Sets.Add(ec_CableSet); + } + var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable); + ResCableEngID = await _iOModuleService.GetCableByEngID(ResTagInfosByPixels.tags.FirstOrDefault().EngineDataID); + } + } + if (ResCableEngID != null) + { + + IntPtr cadHandle = Bricscad.ApplicationServices.Application.MainWindow.Handle; + //打开窗体 + var para = new Prism.Services.Dialogs.DialogParameters(); + //para.Add(GlobalObject.dialogPar.para1.ToString(), "6e2919e4-28cd-4fb6-9035-10b2ff0e30fb"); + para.Add(GlobalObject.dialogPar.info.ToString(), cadHandle); + + para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID); + para.Add(GlobalObject.dialogPar.para2.ToString(), ResTagInfosByPixels.tags.FirstOrDefault().TagNumber); + var _dialogService = GlobalObject._prismContainer.Resolve(); + _dialogService.ShowDialog(nameof(DialogSignalPredistribution), para, (RES) => + { + if (RES.Result == ButtonResult.Yes) + { + + } + else if (RES.Result == ButtonResult.No) + { } + }); + } + + } + + } + catch (System.Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + }); + btnCableSinal.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CableSinal.png"); + btnCableSinal.Id = "信号预分配"; + ribbonRowPanel.Items.Add(btnCableSinal); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 批量反向关联 + RibbonButton btnRelevancy = new RibbonButton(); + btnRelevancy.ToolTip = "批量反向关联"; + btnRelevancy.Text = "批量反向关联"; + btnRelevancy.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRelevancy.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRelevancy.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"relevancy.png"); + btnRelevancy.Id = "批量反向关联"; + ribbonRowPanel.Items.Add(btnRelevancy); + #endregion + dataSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 系统图识别 + RibbonButton btnGraphRec = new RibbonButton(); + btnGraphRec.ToolTip = "系统图识别"; + btnGraphRec.Text = "系统图识别"; + btnGraphRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnGraphRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnGraphRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"GraphRec.png"); + btnGraphRec.Id = "系统图识别"; + ribbonRowPanel.Items.Add(btnGraphRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 竖向图识别 + RibbonButton btnVerticalRec = new RibbonButton(); + btnVerticalRec.ToolTip = "竖向图识别"; + btnVerticalRec.Text = "竖向图识别"; + btnVerticalRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnVerticalRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnVerticalRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"VerticalRec.png"); + btnVerticalRec.Id = "竖向图识别"; + ribbonRowPanel.Items.Add(btnVerticalRec); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 链路图识别 + RibbonButton btnLightLineRec = new RibbonButton(); + btnLightLineRec.ToolTip = "链路图识别"; + btnLightLineRec.Text = "链路图识别"; + btnLightLineRec.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnLightLineRec.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnLightLineRec.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"lightLine.png"); + btnLightLineRec.Id = "链路图识别"; + ribbonRowPanel.Items.Add(btnLightLineRec); + #endregion + dataSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 图形刷新 + RibbonPanelSource dwgRefreshSource = new RibbonPanelSource(); + dwgRefreshSource.Title = "图形刷新"; + dwgRefreshSource.Id = "图形刷新"; + RibbonPanel dwgRefreshPanel = new RibbonPanel(); + dwgRefreshPanel.Source = dwgRefreshSource; + tab1.Panels.Add(dwgRefreshPanel); + //大按钮 + #region buttons 刷新标注 + RibbonButton btnRefreshText = new RibbonButton(); + btnRefreshText.ToolTip = "刷新标注"; + btnRefreshText.Text = "刷新标注"; + btnRefreshText.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnRefreshText.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshText.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshText.png"); + btnRefreshText.Id = "刷新标注"; + dwgRefreshSource.Items.Add(btnRefreshText); + #endregion + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 刷新元件 + RibbonButton btnRefreshBlock = new RibbonButton(); + btnRefreshBlock.ToolTip = "刷新元件"; + btnRefreshBlock.Text = "刷新元件"; + btnRefreshBlock.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshBlock.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshBlock.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshBlock.png"); + btnRefreshBlock.Id = "刷新元件"; + ribbonRowPanel.Items.Add(btnRefreshBlock); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新图框 + RibbonButton btnRefreshFrame = new RibbonButton(); + btnRefreshFrame.ToolTip = "刷新图框"; + btnRefreshFrame.Text = "刷新图框"; + btnRefreshFrame.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshFrame.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshFrame.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshFrame.png"); + btnRefreshFrame.Id = "刷新图框"; + ribbonRowPanel.Items.Add(btnRefreshFrame); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新连接 + RibbonButton btnRefreshLink = new RibbonButton(); + btnRefreshLink.ToolTip = "刷新连接"; + btnRefreshLink.Text = "刷新连接"; + btnRefreshLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshLink.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnRefreshLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshLink.png"); + btnRefreshLink.Id = "刷新连接"; + ribbonRowPanel.Items.Add(btnRefreshLink); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 查看链路 + RibbonButton btnShowLink = new RibbonButton(); + btnShowLink.ToolTip = "查看链路"; + btnShowLink.Text = "查看链路"; + btnShowLink.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnShowLink.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnShowLink.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ShowLink.png"); + btnShowLink.Id = "查看链路"; + ribbonRowPanel.Items.Add(btnShowLink); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新位置 + RibbonButton btnUpdatePosition = new RibbonButton(); + btnUpdatePosition.ToolTip = "刷新位置"; + btnUpdatePosition.Text = "刷新位置"; + btnUpdatePosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnUpdatePosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnUpdatePosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"UpdatePosition.png"); + btnUpdatePosition.Id = "刷新位置"; + ribbonRowPanel.Items.Add(btnUpdatePosition); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 刷新坐标 + RibbonButton btnRefreshPosition = new RibbonButton(); + btnRefreshPosition.ToolTip = "刷新坐标"; + btnRefreshPosition.Text = "刷新坐标"; + btnRefreshPosition.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnRefreshPosition.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnRefreshPosition.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"RefreshPosition.png"); + btnRefreshPosition.Id = "刷新坐标"; + ribbonRowPanel.Items.Add(btnRefreshPosition); + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 图元高亮 + RibbonButton btnActiveObject = new RibbonButton(); + btnActiveObject.ToolTip = "图元高亮"; + btnActiveObject.Text = "图元高亮"; + btnActiveObject.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnActiveObject.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnActiveObject.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"ActiveObject.png"); + btnActiveObject.Id = "图元高亮"; + ribbonRowPanel.Items.Add(btnActiveObject); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + dwgRefreshSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 数据交换 + RibbonPanelSource dataExchangeSource = new RibbonPanelSource(); + dataExchangeSource.Title = "数据交换"; + dataExchangeSource.Id = "数据交换"; + RibbonPanel dataExchangePanel = new RibbonPanel(); + dataExchangePanel.Source = dataExchangeSource; + tab1.Panels.Add(dataExchangePanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 元件导入 + RibbonButton btnImput = new RibbonButton(); + btnImput.ToolTip = "元件导入"; + btnImput.Text = "元件导入"; + btnImput.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnImput.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnImput.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Imput.png"); + btnImput.Id = "元件导入"; + ribbonRowPanel.Items.Add(btnImput); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 元件导出 + RibbonButton btnExport = new RibbonButton(); + btnExport.ToolTip = "元件导出"; + btnExport.Text = "元件导出"; + btnExport.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnExport.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnExport.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Export.png"); + btnExport.Id = "元件导出"; + ribbonRowPanel.Items.Add(btnExport); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + //垂直排列按钮panel + ribbonRowPanel = new RibbonRowPanel(); + #region buttons 电缆检查 + RibbonButton btnCheckCable = new RibbonButton(); + btnCheckCable.ToolTip = "电缆检查"; + btnCheckCable.Text = "电缆检查"; + btnCheckCable.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnCheckCable.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnCheckCable.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CheckCable.png"); + btnCheckCable.Id = "电缆检查"; + ribbonRowPanel.Items.Add(btnCheckCable); + ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 + #endregion + #region buttons 属性检查 + RibbonButton btnPropertyCheck = new RibbonButton(); + btnPropertyCheck.ToolTip = "属性检查"; + btnPropertyCheck.Text = "属性检查"; + btnPropertyCheck.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnPropertyCheck.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnPropertyCheck.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"Property.png"); + btnPropertyCheck.Id = "属性检查"; + ribbonRowPanel.Items.Add(btnPropertyCheck); + #endregion + dataExchangeSource.Items.Add(ribbonRowPanel); + #endregion + + #region Ribbon 软件配置 + RibbonPanelSource systemSource = new RibbonPanelSource(); + systemSource.Title = "软件配置"; + systemSource.Id = "软件配置"; + RibbonPanel systemPanel = new RibbonPanel(); + systemPanel.Source = systemSource; + tab1.Panels.Add(systemPanel); + //下拉按钮列表 + RibbonSplitButton splitButton = new RibbonSplitButton(); + splitButton.Text = "软件配置"; + splitButton.ShowText = true; + splitButton.ShowImage = true; + splitButton.IsVisible = true; + splitButton.ButtonStyle = RibbonButtonStyle.SmallWithText; + #region buttons 绘图配置 + RibbonButton btnDwgConfig = new RibbonButton(); + btnDwgConfig.ToolTip = "绘图配置"; + btnDwgConfig.Text = "绘图配置"; + btnDwgConfig.ButtonStyle = RibbonButtonStyle.LargeWithText; + btnDwgConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnDwgConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"DConfig.png"); + btnDwgConfig.Id = "绘图配置"; + splitButton.Items.Add(btnDwgConfig); + #endregion + #region buttons 标注配置 + RibbonButton btnAaConfig = new RibbonButton(); + btnAaConfig.ToolTip = "标注配置"; + btnAaConfig.Text = "标注配置"; + btnAaConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnAaConfig.CommandHandler = new DelegateCommand(x => + { + MessageBox.Show("功能开发中..."); + }); + btnAaConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"TConfig.png"); + btnAaConfig.Id = "标注配置"; + splitButton.Items.Add(btnAaConfig); + #endregion + #region buttons 系统配置 + RibbonButton btnSystemConfig = new RibbonButton(); + btnSystemConfig.ToolTip = "系统配置"; + btnSystemConfig.Text = "系统配置"; + btnSystemConfig.ButtonStyle = RibbonButtonStyle.SmallWithText; + btnSystemConfig.CommandHandler = new DelegateCommand(x => + { + var configView = GlobalObject.container.Resolve(); + Application.ShowModalWindow(Application.MainWindow.Handle, configView); + }); + btnSystemConfig.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"SConfig.png"); + btnSystemConfig.Id = "系统配置"; + splitButton.Items.Add(btnSystemConfig); + #endregion + systemSource.Items.Add(splitButton); + + #endregion + } + + } +} + + + + + diff --git a/newFront/c#前端/SWS.CAD/SWS.CAD.csproj b/newFront/c#前端/SWS.CAD/SWS.CAD.csproj index 109ea715..10b7ad9a 100644 --- a/newFront/c#前端/SWS.CAD/SWS.CAD.csproj +++ b/newFront/c#前端/SWS.CAD/SWS.CAD.csproj @@ -150,9 +150,7 @@ - - @@ -205,6 +203,7 @@ + @@ -286,7 +285,6 @@ - @@ -313,6 +311,9 @@ DialogNewTagNumber.xaml + + DialogSectionBox.xaml + DialogSignalPredistribution.xaml @@ -448,6 +449,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/newFront/c#前端/SWS.CAD/Start.cs b/newFront/c#前端/SWS.CAD/Start.cs index a3ae1d18..9557004b 100644 --- a/newFront/c#前端/SWS.CAD/Start.cs +++ b/newFront/c#前端/SWS.CAD/Start.cs @@ -37,6 +37,10 @@ namespace SWS.CAD GlobalObject.container.RegisterSingleton(); GlobalObject.container.RegisterSingleton(); GlobalObject.container.RegisterSingleton(); + GlobalObject.container.RegisterSingleton(); + GlobalObject.container.RegisterSingleton(); + + GlobalObject._prismContainer = new DryIocContainerExtension(); GlobalObject._prismContainer.Register(); @@ -73,6 +77,7 @@ namespace SWS.CAD GlobalObject._prismContainer.RegisterDialog(); GlobalObject._prismContainer.RegisterDialog(); GlobalObject._prismContainer.RegisterDialog(); + GlobalObject._prismContainer.RegisterDialog(); } } } diff --git a/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogCablePreAssignResultViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogCablePreAssignResultViewModel.cs index af171f8f..e8ef9973 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogCablePreAssignResultViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogCablePreAssignResultViewModel.cs @@ -11,6 +11,7 @@ using SWS.Service; using Unity; using System.Linq; using Telerik.Windows.Controls.MaskedInput.Tokens.Numeric; +using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; namespace SWS.CAD.ViewModels { @@ -156,7 +157,11 @@ namespace SWS.CAD.ViewModels { if (PreAssignCable.AssignedPanel!=null) { - PreAssignCables.Add(PreAssignCable); + if (PreAssignCable.Sets!=null&&!string.IsNullOrEmpty(PreAssignCable.Sets.FirstOrDefault().ConnectionInfo)) + { + PreAssignCables.Add(PreAssignCable); + } + } } } @@ -164,10 +169,17 @@ namespace SWS.CAD.ViewModels { foreach (var PreAssignCable in AllPreAssignCables) { - if (PreAssignCable.AssignedPanel == null) - { - PreAssignCables.Add(PreAssignCable); - } + if (PreAssignCable.Sets == null || PreAssignCable.Sets.Count()==0) + { + PreAssignCables.Add(PreAssignCable); + } + else + { + if (string.IsNullOrEmpty(PreAssignCable.Sets.FirstOrDefault().ConnectionInfo)) + { + PreAssignCables.Add(PreAssignCable); + } + } } } } @@ -188,15 +200,54 @@ namespace SWS.CAD.ViewModels preAllocationResult.CablePair = Set.CableSetName; preAllocationResult.IOType = cable.PreAssignIOType; preAllocationResult.ToPanel_TagNumber = cable.AssignedPanel == null ? "" : cable.AssignedPanel.TagNumber; - preAllocationResult.Panel_TagNumber = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[0].Split(':')[1].Trim(); - preAllocationResult.StripName = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[1].Split(':')[1].Trim(); - preAllocationResult.Terms = new ObservableCollection(Set.AssignedTerms); + if (!string.IsNullOrEmpty(Set.ConnectionInfo)) + { + preAllocationResult.Panel_TagNumber = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[0].Split(':')[1].Trim(); + + if (Set.ConnectionInfo.Split('/').Count()>1) + { + preAllocationResult.StripName = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[1].Split(':')[1].Trim(); + } + } + preAllocationResult.Terms = Set.AssignedTerms==null?new ObservableCollection(): new ObservableCollection(Set.AssignedTerms); PreAllocationResultls.Add(preAllocationResult); } } } + public ICommand HeadButtonCmd => new DelegateCommand(HeadButton_Click); + /// + /// 导出按钮 + /// + /// + public virtual async void HeadButton_Click(object parameter) + { + if (parameter.Equals("导出电缆预分配结果明细表")) + { + System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*"; + saveFileDialog.Title = "选择保存路径"; + + if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + + string selectedPath = saveFileDialog.FileName; + if (System.IO.File.Exists(selectedPath)) + { System.IO.File.Delete(selectedPath); } + + var msg = await _iOModuleService.AutoAssignCable2Channel_ResExport(selectedPath); + if (string.IsNullOrEmpty(msg)) + { + System.Windows.MessageBox.Show("下载文件成功!"); + } + else { System.Windows.MessageBox.Show("下载文件异常:" + msg); } + + } + } + + } + public ICommand EditEndCmd => new DelegateCommand(EditEnd); /// /// 编辑结束事件 diff --git a/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogIODistributionViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogIODistributionViewModel.cs index 935edecd..45febc17 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogIODistributionViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogIODistributionViewModel.cs @@ -14,6 +14,7 @@ using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; using Prism.Events; using Prism.Ioc; using Prism.Services.Dialogs; +using SWS.CAD.Base; using SWS.CAD.CADFunc; using SWS.CAD.Event; using SWS.CAD.ViewModels.myViewModelBase; @@ -180,9 +181,20 @@ namespace SWS.CAD.ViewModels } public async void OnDialogOpened(IDialogParameters parameters) { - IsBusy = true; - PanelTreels.AddRange(await _iOModuleService.GetPanelTree()); - IsBusy = false; + try + { + IsBusy = true; + var resPanelTreels = await _iOModuleService.GetPanelTree(); + PanelTreels.AddRange(resPanelTreels); + } + catch (Exception) + { + System.Windows.MessageBox.Show("网络连接失败", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); + } + finally + { + IsBusy = false; + } } diff --git a/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogNewComponentViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogNewComponentViewModel.cs index b7553748..18446055 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogNewComponentViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogNewComponentViewModel.cs @@ -17,6 +17,7 @@ using SWS.Commons; using SWS.Model; using SWS.WPF.ViewModels; using SWS.Service; +using SWS.CAD.Base; namespace SWS.CAD.ViewModels { diff --git a/newFront/c#前端/SWS.CAD/ViewModels/DialogSectionBoxViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/DialogSectionBoxViewModel.cs new file mode 100644 index 00000000..bfdc479f --- /dev/null +++ b/newFront/c#前端/SWS.CAD/ViewModels/DialogSectionBoxViewModel.cs @@ -0,0 +1,559 @@ + +using Bricscad.ApplicationServices; +using Bricscad.EditorInput; +using Prism.Events; +using Prism.Ioc; +using Prism.Services.Dialogs; +using SWS.CAD.Base; +using SWS.CAD.Event; +using SWS.CAD.ViewModels.myViewModelBase; +using SWS.CAD.Views; +using SWS.CAD.Views.CustomControl; +using SWS.Commons; +using SWS.Model; +using SWS.Service; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using Teigha.DatabaseServices; +using Telerik.Windows.Controls; +using Unity; + +namespace SWS.CAD.ViewModels +{ + /// + /// 信号预分配页面的模型类 + /// + public class DialogSectionBoxViewModel : DialogBase, IDialogAware + { + #region 字段 + private ObservableCollection _CircuitBreakerInfos = new ObservableCollection(); + /// + /// 表格数据 + /// + public ObservableCollection CircuitBreakerInfos + { + get { return _CircuitBreakerInfos; } + set + { + _CircuitBreakerInfos = value; + RaisePropertyChanged(nameof(CircuitBreakerInfos)); + } + } + + private CircuitBreakerInfo _SelectCircuitBreaker; + /// + /// 表格选中行 + /// + public CircuitBreakerInfo SelectCircuitBreaker + { + get { return _SelectCircuitBreaker; } + set { _SelectCircuitBreaker = value; } + } + + private string _DefaultBreakerType; + /// + /// 开关类型 + /// + public string DefaultBreakerType + { + get { return _DefaultBreakerType; } + set + { + _DefaultBreakerType = value; + RaisePropertyChanged(nameof(DefaultBreakerType)); + } + } + + private List _BreakerTypels = new List() { "MCCB", "ACB" }; + /// + /// 开关类型的下拉列表 + /// + public List BreakerTypels + { + get { return _BreakerTypels; } + set { _BreakerTypels = value; } + } + + private List _CB_Typels = new List() { "输入", "输出" }; + /// + /// 分电箱类型列的下拉列表 + /// + public List CB_Typels + { + get { return _CB_Typels; } + set + { + _CB_Typels = value; + + } + } + + + /// + /// 表示要删除的开关id集合 + /// + public List DeleBreakerIds = new List(); + #endregion + + IOModuleService _iOModuleService; + ObjectTypeService _objectTypeService; + RelService _relService; + PDBService _pDBService; + IEventAggregator _eventAggregator; + + public DialogSectionBoxViewModel() + { + _iOModuleService = GlobalObject.container.Resolve(); + _pDBService = GlobalObject.container.Resolve(); + _relService = GlobalObject.container.Resolve(); + _objectTypeService = GlobalObject.container.Resolve(); + _eventAggregator = GlobalObject.container.Resolve(); + + } + public string Title => ""; + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + private ec_Panel resBreakers; + public async void OnDialogOpened(IDialogParameters parameters) + { + //title = $"电缆信号({parameters.GetValue(GlobalObject.dialogPar.para2.ToString())})预分配"; + var resTagInfos = await _objectTypeService.GetTagInfosByPixels("857e8ae5-d9b4-4dc7-8ebc-d7e752a4b31c", "2C01C"); + + //var resRel = await _relService.GetRelDefByName("主配电板"); + //获取分电箱的开关信息 + IsBusy = true; + resBreakers = await _pDBService.GetBreakers(resTagInfos.FirstOrDefault().tags.FirstOrDefault().EngineDataID); + if (resBreakers != null) + { + int i = 0; + foreach (var Breaker in resBreakers.Breakers) + { + i++; + CircuitBreakerInfo breakerInfo = new CircuitBreakerInfo(Breaker); + breakerInfo.Index = i; + CircuitBreakerInfos.Add(breakerInfo); + } + DefaultBreakerType = resBreakers.DefaultBreakerType; + } + + title = $"{resTagInfos.FirstOrDefault().tags.FirstOrDefault().ObjectTypeName + resTagInfos.FirstOrDefault().tags.FirstOrDefault().TagNumber}开关管理"; + IsBusy = false; + + + } + public override async void ExecuteOKCommandAsync(object para) + { + await SavePanelAndBreaker(); + + IDialogParameters res = new Prism.Services.Dialogs.DialogParameters(); + //res.Add(GlobalObject.dialogPar.info.ToString(), TagNumber); + RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res)); + } + public override void ExecuteCloseCommand(object parameter) + { + if (parameter as string == "ClickNo") + { + DialogResult res = new DialogResult(ButtonResult.No); + RequestClose.Invoke(res); + } + else + { + RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); + } + this.Dispose(); + } + #region 方法 + + #region 按钮点击事件 + public ICommand ButtonCmd => new DelegateCommand(Button_Click); + /// + /// 页面左侧按钮 + /// + /// + public virtual async void Button_Click(object parameter) + { + #region 新增 + if (parameter.ToString().Equals("新增")) + { + CircuitBreakerInfo breakerInfo = new CircuitBreakerInfo(); + breakerInfo.Index = CircuitBreakerInfos.Count() + 1; + breakerInfo.Name = "开关" + (CircuitBreakerInfos.Count() + 1); + breakerInfo.Phase = 1; + breakerInfo.OrderId = CircuitBreakerInfos.Count(); + breakerInfo.CB_Type = "输出"; + breakerInfo.IsModified = true; + CircuitBreakerInfos.Add(breakerInfo); + return; + } + #endregion + + #region 删除 + if (parameter.ToString().Equals("删除")) + { + //当前选择不为空 + if (SelectCircuitBreaker != null) + { + if (!string.IsNullOrEmpty(SelectCircuitBreaker.EngineerDataID)) + { + DeleBreakerIds.Add(SelectCircuitBreaker.EngineerDataID); + } + CircuitBreakerInfos.Remove(SelectCircuitBreaker); + } + else + { + System.Windows.MessageBox.Show("请先选择删除行", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return; + } + //删除之后重新排序 + int i = 0; + foreach (var CircuitBreakerInfo in CircuitBreakerInfos) + { + i++; + CircuitBreakerInfo.Index = i; + } + + return; + } + #endregion + + #region 关联电缆 + if (parameter.ToString().Equals("关联电缆")) + { + //当前选择不为空 + if (SelectCircuitBreaker != null) + { + //在SWS系统内打开且不是只读的图纸才可 + var dwgName = General.GetDwgName(); + var dwgFile = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName && a.IsReadOnly == false); + if (dwgFile == null) + { return; } + Document doc = Bricscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument; + Database db = doc.Database; + Editor ed = doc.Editor; + //选择的元素返回的属性信息 + var ResTagInfosByPixels = new Model.ec_objecttype(); + var listPropertys = new List(); + // 持续选择直到获取有效电缆 + bool isValidCable = false; + + try + { + + // 创建选择选项(禁用回车确认) + PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: "); + options.AllowNone = false; // 禁止空选 + + // 执行选择(直接单击生效) + PromptEntityResult resultEntity = ed.GetEntity(options); + + while (resultEntity.Status == PromptStatus.OK) + { + using (Transaction tr = db.TransactionManager.StartTransaction()) + { + // 获取选中的电缆实体 + Entity cable = tr.GetObject(resultEntity.ObjectId, OpenMode.ForRead) as Entity; + //if (cable != null&&cable.XData != null) + if (cable != null) + { + // 获取句柄(Handle 是字符串类型) + var handId = (cable.Handle.ToString()); + _objectTypeService = GlobalObject.container.Resolve(); + var res = await _objectTypeService.GetTagInfosByPixels(dwgFile.Id, handId); + if (res != null) + { + if (res.Count == 1) + { + var item = res[0]; + var objTypeName = item.ObjectTypeName; + if (objTypeName.Contains("电缆")) + { + ResTagInfosByPixels = item; + isValidCable = true; // 校验通过 + ed.WriteMessage($"\n已选择电缆:{ResTagInfosByPixels.tags.FirstOrDefault().TagNumber}"); + } + + } + } + + } + tr.Commit(); + } + if (isValidCable) + { + break; + } + else + { + ed.WriteMessage($"\n已选择电缆:"); + resultEntity = ed.GetEntity(options); + } + } + } + catch (Exception ex) + { + ed.WriteMessage($"\n错误: {ex.Message}"); + } + + } + else + { + System.Windows.MessageBox.Show("请先选择行", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return; + } + + return; + } + #endregion + + #region 放置开关 + if (parameter.ToString().Equals("放置开关")) + { + + //当前选择不为空 + if (SelectCircuitBreaker != null) + { + + } + else + { + System.Windows.MessageBox.Show("请先选择行", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return; + } + return; + } + #endregion + + } + #endregion + + #region 表格编辑结束事件 + public ICommand EditEndCmd => new DelegateCommand(EditEnd); + /// + /// 编辑结束事件 + /// + /// + public virtual void EditEnd(object parameter) + { + //做个标记表示该项修改过 + SelectCircuitBreaker.IsModified = true; + + } + #endregion + + #region 保存 + /// + /// 保存 + /// + public async Task SavePanelAndBreaker() + { + //SavePanel + ec_Panel panel = new ec_Panel(); + panel.CreateTime = resBreakers.CreateTime; + panel.CreateUserID = resBreakers.CreateUserID; + panel.DefaultBreakerType = DefaultBreakerType; + panel.EngineerDataID = resBreakers.EngineerDataID; + panel.MaxStripNumber = resBreakers.MaxStripNumber; + panel.ObjectTypeName = resBreakers.ObjectTypeName; + panel.PanelID = resBreakers.PanelID; + panel.Panel_Loc_ID = resBreakers.Panel_Loc_ID; + panel.TagNumber = resBreakers.TagNumber; + panel.UpdateTime = resBreakers.UpdateTime; + panel.UpdateUserID = resBreakers.UpdateUserID; + panel.allowedIOTypes = resBreakers.allowedIOTypes; + panel.strips = resBreakers.strips; + panel.systempanel = resBreakers.systempanel; + var resSavePanel = await _iOModuleService.SavePanel(panel); + + //SaveBreakers + List circuitBreakerls = new List(); + foreach (var CircuitBreakerInfo in CircuitBreakerInfos) + { + if (CircuitBreakerInfo.IsModified) + { + ec_CircuitBreaker circuitBreaker = new ec_CircuitBreaker(); + circuitBreaker.Name = CircuitBreakerInfo.Name; + circuitBreaker.Phase = CircuitBreakerInfo.Phase; + circuitBreaker.CB_Type = CircuitBreakerInfo.CB_Type; + circuitBreaker.Capacity_Act = CircuitBreakerInfo.Capacity_Act; + circuitBreaker.Capacity_Max = CircuitBreakerInfo.Capacity_Max; + circuitBreaker.Capacity_Set = CircuitBreakerInfo.Capacity_Set; + circuitBreaker.EngineerDataID = CircuitBreakerInfo.EngineerDataID; + circuitBreaker.OrderId = CircuitBreakerInfo.OrderId; + circuitBreakerls.Add(circuitBreaker); + } + } + var resSaveBreaker = await _pDBService.SaveBreakers(resBreakers.EngineerDataID, circuitBreakerls); + + //DeleteBreaker + if (DeleBreakerIds.Count > 0) + { + var BreakerIds = string.Join(",", DeleBreakerIds); + var resDele = await _pDBService.Delete(BreakerIds); + } + } + #endregion + + + #endregion + + } + + public class CircuitBreakerInfo : ViewBase + { + #region 页面显示字段 + private int _Index; + /// + /// 序号 + /// + public int Index + { + get { return _Index; } + set { _Index = value; } + } + + private string _Name; + /// + /// 开关名字 + /// + public string Name + { + get { return _Name; } + set { _Name = value; } + } + + private int _Phase; + /// + /// 相数 + /// + public int Phase + { + get { return _Phase; } + set { _Phase = value; } + } + + private string _CB_Type; + /// + /// 分电箱类型 + /// 输出或输入 + /// + public string CB_Type + { + get { return _CB_Type; } + set { _CB_Type = value; } + } + private string _Capacity_Max; + /// + /// 额定电流 + /// + public string Capacity_Max + { + get { return _Capacity_Max; } + set { _Capacity_Max = value; } + } + private string _Capacity_Set; + /// + /// 整定电流 + /// + public string Capacity_Set + { + get { return _Capacity_Set; } + set { _Capacity_Set = value; } + } + private string _Capacity_Act; + /// + /// 实际电流 + /// + public string Capacity_Act + { + get { return _Capacity_Act; } + set { _Capacity_Act = value; } + } + private string _CableTagNumber; + /// + /// 电缆位号 + /// + public string CableTagNumber + { + get { return _CableTagNumber; } + set { _CableTagNumber = value; } + } + + private string _RemoteDeviceId; + /// + /// 对面的设备信息 + /// + public string RemoteDeviceId + { + get { return _RemoteDeviceId; } + set { _RemoteDeviceId = value; } + } + #endregion + + #region 扩展字段 + private string _EngineerDataID; + /// + /// 开关工程ID + /// + public string EngineerDataID + { + get { return _EngineerDataID; } + set { _EngineerDataID = value; } + } + + private int _OrderId; + + public int OrderId + { + get { return _OrderId; } + set { _OrderId = value; } + } + + + private bool _IsModified; + /// + /// 标记行数据是否修改 + /// + public bool IsModified + { + get { return _IsModified; } + set { _IsModified = value; } + } + + #endregion + + public CircuitBreakerInfo() + { + + } + public CircuitBreakerInfo(ec_CircuitBreaker ec_CircuitBreaker) + { + Name = ec_CircuitBreaker.Name; + CB_Type = ec_CircuitBreaker.CB_Type; + Phase = ec_CircuitBreaker.Phase; + Capacity_Max = ec_CircuitBreaker.Capacity_Max; + Capacity_Set = ec_CircuitBreaker.Capacity_Set; + Capacity_Act = ec_CircuitBreaker.Capacity_Act; + CableTagNumber = ec_CircuitBreaker.CableTagNumbers.FirstOrDefault(); + + EngineerDataID = ec_CircuitBreaker.EngineerDataID; + OrderId = ec_CircuitBreaker.OrderId; + + } + } + +} diff --git a/newFront/c#前端/SWS.CAD/ViewModels/DialogSignalPredistributionViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/DialogSignalPredistributionViewModel.cs index 5b96a500..871fddb0 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/DialogSignalPredistributionViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/DialogSignalPredistributionViewModel.cs @@ -1,4 +1,5 @@  +using Aspose.Cells; using Prism.Events; using Prism.Ioc; using Prism.Services.Dialogs; @@ -111,22 +112,37 @@ namespace SWS.CAD.ViewModels RaisePropertyChanged(nameof(SignalColumnName)); if (value.Equals("Digital")) { + //判断是否输入输出是否有值,有值下拉可选项需要设置为已有值 + string tempIntorOut= SignalPredistributionInfos.Where(s => !string.IsNullOrEmpty(s.InorOut)).Select(s => s.InorOut).FirstOrDefault(); + if (string.IsNullOrEmpty(tempIntorOut)) + { + InorOuts = new List() { "输出", "输入" }; + } + else + { + InorOuts = new List() { tempIntorOut }; + } + SignalTypeColumn = new ObservableCollection() { "无公共端接线(断开报警NC)", "无公共端接线(闭合报警NO)", "带公共端接线(断开报警NC)", "带公共端接线(闭合报警NO)" }; } else if (value.Equals("4-20mA")) { + InorOuts= new List() { "输出", "输入" }; SignalTypeColumn = new ObservableCollection() { "无源", "有源" }; } else if (value.Equals("-10V-10V")) { + InorOuts = new List() { "输出", "输入" }; SignalTypeColumn = new ObservableCollection() { "无源", "有源" }; } else if (value.Equals("PT100")) { + InorOuts = new List() { "输出", "输入" }; SignalTypeColumn = new ObservableCollection() { "量程100", "量程150", "量程200", "量程600" }; } else if (value.Equals("Pulse")) { + InorOuts = new List() { "输出", "输入" }; SignalTypeColumn = new ObservableCollection() { "脉冲信号" }; } } @@ -275,7 +291,7 @@ namespace SWS.CAD.ViewModels if (string.IsNullOrEmpty(Set.PreAssignInOrOut)) { - predistributionInfo.InorOut = InorOuts.FirstOrDefault(); + //predistributionInfo.InorOut = InorOuts.FirstOrDefault(); } else { @@ -283,6 +299,8 @@ namespace SWS.CAD.ViewModels } predistributionInfo.SensorCode = Set.PreAssignSensorCode; + //给每一行添加委托事件 + predistributionInfo.UpdateInorOutsChanged += (sender, e) => UpdateInorOuts((SignalPredistributionInfo)sender); SignalPredistributionInfos.Add(predistributionInfo); } @@ -423,6 +441,39 @@ namespace SWS.CAD.ViewModels #endregion } + #region 修改输出和输入的可选项 + public void UpdateInorOuts(SignalPredistributionInfo sender) + { + if (SignalColumnName.Equals("Digital")) + { + string tempIntorOut = SignalPredistributionInfos.Where(s => !string.IsNullOrEmpty(s.InorOut)).Select(s => s.InorOut).FirstOrDefault(); + if (string.IsNullOrEmpty(tempIntorOut)) + { + InorOuts = new List() { sender.InorOut }; + if (sender.SignalType.Contains("带公共端")) + { + InorOuts = new List() { "输入" }; + } + } + else + { + if (tempIntorOut.Equals("输出")) + { + if (sender.SignalType.Contains("带公共端")) + { + MessageBox.Show("带公共端只能跟输入信号搭配", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); + //需要还原信号类型的选项 + var Set = CableBy.Sets.FirstOrDefault(s => s.CableSetName.Equals(sender.CablePair)); + sender.SignalType = SignalTypeColumn.FirstOrDefault(); + + } + + } + } + + } + } + #endregion #region 查找节点路径 public List FindNodePath(ObservableCollection nodes, TreeModel targetNode) @@ -454,6 +505,8 @@ namespace SWS.CAD.ViewModels public class SignalPredistributionInfo : DialogBase { + public event EventHandler UpdateInorOutsChanged; + #region 字段 private ObservableCollection _Index = new ObservableCollection(); /// @@ -510,6 +563,8 @@ namespace SWS.CAD.ViewModels { _SignalType = value; RaisePropertyChanged(nameof(SignalType)); + UpdateInorOutsChanged?.Invoke(this, EventArgs.Empty); + } } @@ -553,6 +608,8 @@ namespace SWS.CAD.ViewModels { _InorOut = value; RaisePropertyChanged(nameof(InorOut)); + UpdateInorOutsChanged?.Invoke(this, EventArgs.Empty); + } } diff --git a/newFront/c#前端/SWS.CAD/ViewModels/DialogTagSelectViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/DialogTagSelectViewModel.cs index 281363d4..6c576ce8 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/DialogTagSelectViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/DialogTagSelectViewModel.cs @@ -5,6 +5,7 @@ using SWS.CAD.ViewModels.myViewModelBase; using SWS.CAD.Views; using SWS.CAD.Views.CustomControl; using SWS.Commons; +using SWS.Model; using System; using System.Collections.ObjectModel; using System.Windows; diff --git a/newFront/c#前端/SWS.CAD/ViewModels/LeftPanelViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/LeftPanelViewModel.cs index 89930e29..c476f065 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/LeftPanelViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/LeftPanelViewModel.cs @@ -36,6 +36,7 @@ using SWS.Commons; using SWS.Model; using SWS.Service; using SWS.WPF.Views; +using SWS.CAD.Base; namespace SWS.CAD.ViewModels { public class LeftPanelViewModel : ViewModelBase @@ -833,7 +834,7 @@ namespace SWS.CAD.ViewModels { MessageBox.Show("图纸文件下载失败,信息:" + msg); return; } } } - msg = CADFunc.General.OpenDwg(filePath);//打开编辑图纸 + msg = General.OpenDwg(filePath);//打开编辑图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); @@ -868,7 +869,7 @@ namespace SWS.CAD.ViewModels msg = await _annexesService.DownloadFile(filePath, dwgfileDto.F_Id); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show("图纸文件下载失败,信息:" + msg); return; } - msg = CADFunc.General.OpenDwg(filePath, true);//以只读模式打开图纸 + msg = General.OpenDwg(filePath, true);//以只读模式打开图纸 if (!string.IsNullOrEmpty(msg)) { @@ -996,7 +997,7 @@ namespace SWS.CAD.ViewModels else { //以只读模式打开图纸 - msg = CADFunc.General.OpenDwg(filePath, true); + msg = General.OpenDwg(filePath, true); InitDrawingSelectedAdd(dwgObj, true); } //获取当前图纸所有句柄 @@ -1191,7 +1192,7 @@ namespace SWS.CAD.ViewModels } //打开图纸文件 filePath = Path.Combine(GlobalObject.GetDwgFileFolder(), model.Text); - msg = CADFunc.General.OpenDwg(filePath); + msg = General.OpenDwg(filePath); //更新图纸节点图标和字体颜色 dwgObj.CheckOutUserID = GlobalObject.userInfo.userId; @@ -1693,7 +1694,7 @@ namespace SWS.CAD.ViewModels #region 当图纸文件已被打开时,直接打开图纸并选中图元 if (FileHelper.IsFileLocked(filePath)) { - msg = CADFunc.General.OpenDwg(filePath);//打开编辑图纸 + msg = General.OpenDwg(filePath);//打开编辑图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); @@ -1716,7 +1717,7 @@ namespace SWS.CAD.ViewModels msg = await _annexesService.DownloadFile(filePath, dwgfileDto.F_Id); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show("图纸文件下载失败,信息:" + msg); return; } - msg = CADFunc.General.OpenDwg(filePath);//打开编辑图纸 + msg = General.OpenDwg(filePath);//打开编辑图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); @@ -1740,7 +1741,7 @@ namespace SWS.CAD.ViewModels #region 当图纸文件已被打开时,直接打开图纸并选中图元 if (FileHelper.IsFileLocked(filePath)) { - msg = CADFunc.General.OpenDwg(filePath, true);//只读打开图纸 + msg = General.OpenDwg(filePath, true);//只读打开图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); @@ -1764,7 +1765,7 @@ namespace SWS.CAD.ViewModels if (!string.IsNullOrEmpty(msg)) { MessageBox.Show("图纸文件下载失败,信息:" + msg); return; } - msg = CADFunc.General.OpenDwg(filePath, true);//只读打开图纸 + msg = General.OpenDwg(filePath, true);//只读打开图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); @@ -2142,7 +2143,7 @@ namespace SWS.CAD.ViewModels var dwgPublishObj = JsonConvert.DeserializeObject(model.NodeExtData.ToString()); if (File.Exists(filePath)) { - msg = CADFunc.General.OpenDwg(filePath, true);//以只读模式打开图纸 + msg = General.OpenDwg(filePath, true);//以只读模式打开图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); @@ -2156,7 +2157,7 @@ namespace SWS.CAD.ViewModels msg = await _annexesService.DownloadFile(filePath, dwgfileDto.F_Id); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show("图纸文件下载失败,信息:" + msg); return; } - msg = CADFunc.General.OpenDwg(filePath, true);//以只读模式打开图纸 + msg = General.OpenDwg(filePath, true);//以只读模式打开图纸 if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{model.Text} 打开失败,信息:{msg}"); diff --git a/newFront/c#前端/SWS.CAD/ViewModels/NewDrawingViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/NewDrawingViewModel.cs index 8c032e26..ceb7e9b8 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/NewDrawingViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/NewDrawingViewModel.cs @@ -1,4 +1,5 @@ using Prism.Services.Dialogs; +using SWS.CAD.Base; using SWS.CAD.ViewModels.myViewModelBase; using SWS.Commons; using SWS.Model; @@ -382,7 +383,7 @@ namespace SWS.CAD.ViewModels { MessageBox.Show("新建图纸成功!"); //新建图纸完,自动打开图纸 - msg = CADFunc.General.OpenDwg(filePath); + msg = General.OpenDwg(filePath); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show($"本地图纸文件:{dwgObj.DrawingFileName} 打开失败,信息:{msg}"); diff --git a/newFront/c#前端/SWS.CAD/ViewModels/RightPanelViewModel.cs b/newFront/c#前端/SWS.CAD/ViewModels/RightPanelViewModel.cs index e315e341..ab579d0f 100644 --- a/newFront/c#前端/SWS.CAD/ViewModels/RightPanelViewModel.cs +++ b/newFront/c#前端/SWS.CAD/ViewModels/RightPanelViewModel.cs @@ -3,6 +3,7 @@ using Bricscad.EditorInput; using Prism.Events; using Prism.Ioc; using Prism.Services.Dialogs; +using SWS.CAD.Base; using SWS.CAD.CADFunc; using SWS.CAD.Event; using SWS.CAD.Views; diff --git a/newFront/c#前端/SWS.CAD/Views/CustomControl/PropertyGrid/PropertyGrid.cs b/newFront/c#前端/SWS.CAD/Views/CustomControl/PropertyGrid/PropertyGrid.cs index 06d435cd..54e5f9a3 100644 --- a/newFront/c#前端/SWS.CAD/Views/CustomControl/PropertyGrid/PropertyGrid.cs +++ b/newFront/c#前端/SWS.CAD/Views/CustomControl/PropertyGrid/PropertyGrid.cs @@ -225,7 +225,11 @@ namespace SWS.CAD.Views.CustomControl { var item = listPro[i]; var list = listPro.Where(a => a.IsBasicGroup = item.IsBasicGroup).ToList(); - isLast = item.DisplayText == list.Last().DisplayText; + if (list != null && list.Count() != 0) + { + isLast = item.DisplayText == list.Last().DisplayText; + } + } CreatePropertyControl(sender, listPro[i], i, isLast); } diff --git a/newFront/c#前端/SWS.CAD/Views/Dialog/DialogIODistributions/DialogCablePreAssignResult.xaml b/newFront/c#前端/SWS.CAD/Views/Dialog/DialogIODistributions/DialogCablePreAssignResult.xaml index b7e290ff..da182e13 100644 --- a/newFront/c#前端/SWS.CAD/Views/Dialog/DialogIODistributions/DialogCablePreAssignResult.xaml +++ b/newFront/c#前端/SWS.CAD/Views/Dialog/DialogIODistributions/DialogCablePreAssignResult.xaml @@ -60,19 +60,27 @@ - - - - + + + + + + + + + + - @@ -82,11 +90,11 @@ - - - + - - - + + + diff --git a/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSectionBox.xaml b/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSectionBox.xaml index df6bae5f..0efa42dc 100644 --- a/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSectionBox.xaml +++ b/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSectionBox.xaml @@ -4,9 +4,109 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SWS.CAD.Views.Dialog" - mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> - - - + xmlns:CustomControl="clr-namespace:SWS.CAD.Views.CustomControl" + xmlns:prism="http://prismlibrary.com/" + xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" + mc:Ignorable="d" > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSignalPredistribution.xaml b/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSignalPredistribution.xaml index 2e526ce3..ef3b84b3 100644 --- a/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSignalPredistribution.xaml +++ b/newFront/c#前端/SWS.CAD/Views/Dialog/DialogSignalPredistribution.xaml @@ -413,7 +413,7 @@ diff --git a/newFront/c#前端/SWS.CAD/Views/LeftPanel.xaml b/newFront/c#前端/SWS.CAD/Views/LeftPanel.xaml index bec49049..b2b277ab 100644 --- a/newFront/c#前端/SWS.CAD/Views/LeftPanel.xaml +++ b/newFront/c#前端/SWS.CAD/Views/LeftPanel.xaml @@ -7,6 +7,7 @@ xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:local="clr-namespace:SWS.CAD.Views" xmlns:local2="clr-namespace:SWS.Model;assembly=SWS.Model" + xmlns:Behaviors="clr-namespace:SWS.Commons.Helper.Behaviours;assembly=SWS.Commons" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Width="250" Loaded="UserControl_Loaded"> @@ -183,17 +184,17 @@ TextAlignment="Center" /> - - + Behaviors:TreeViewSelectedItemBehavior.SelectedItem="{Binding selectedNode, Mode=TwoWay}"> + - + - + - - + + - - + Behaviors:TreeViewSelectedItemBehavior.SelectedItem="{Binding selectedHistoryDwg, Mode=TwoWay}"> + - - + + - + - + - - + + @@ -337,15 +337,15 @@ TextChanged="TextBox_TextChanged" /> - - + Behaviors:TreeViewSelectedItemBehavior.SelectedItem="{Binding selectType, Mode=TwoWay}"> + @@ -357,8 +357,8 @@ - - + + @@ -377,14 +377,21 @@ VirtualizingPanel.IsVirtualizingWhenGrouping="True" VirtualizingPanel.ScrollUnit="Pixel" VirtualizingPanel.VirtualizationMode="Recycling"> - + + + + @@ -431,14 +438,14 @@ Style="{StaticResource sysTextBox}" Tag="设计浏览" TextChanged="TextBox_TextChanged" /> - - + Behaviors:TreeViewSelectedItemBehavior.SelectedItem="{Binding selectDesign, Mode=TwoWay}"> + + + + + + + - - + + - - + + diff --git a/newFront/c#前端/SWS.CAD/Views/RightPanel.xaml b/newFront/c#前端/SWS.CAD/Views/RightPanel.xaml index 7b2e3f6b..b6f5d003 100644 --- a/newFront/c#前端/SWS.CAD/Views/RightPanel.xaml +++ b/newFront/c#前端/SWS.CAD/Views/RightPanel.xaml @@ -123,12 +123,12 @@ Text="{Binding objectTypeName}" />--> - + /> diff --git a/newFront/c#前端/SWS.Commons/GlobalObject.cs b/newFront/c#前端/SWS.Commons/GlobalObject.cs index 4cae166c..3734edde 100644 --- a/newFront/c#前端/SWS.Commons/GlobalObject.cs +++ b/newFront/c#前端/SWS.Commons/GlobalObject.cs @@ -85,7 +85,7 @@ namespace SWS.Commons public static List designTree = new List(); #endregion - + public enum DBConst { /// @@ -316,19 +316,50 @@ namespace SWS.Commons return dllPath; } #endregion - /// - /// - /// - /// 包括命名空间 - /// + + #region 获取日志文件夹路径 + /// + /// 获取日志文件夹路径 + /// + /// + public static string GetLogPath() + { + string path = Path.Combine(GetDllPath(),"SWSLogs"); + return path; + } + #endregion + + #region 清理超时日志文件 + public static void ClearLog() + { + try + { + var path = Path.Combine(GlobalObject.GetDllPath(), "SWSLogs\\"); + int retainDays = 7;//保留7天的日志 + + foreach (var file in Directory.GetFiles(path, "*.log")) + { + if (File.GetCreationTime(file) < DateTime.Now.AddDays(-retainDays)) + { + File.Delete(file); + } + } + } + catch + { + } + } + #endregion + + /// + /// + /// + /// 包括命名空间 + /// public static System.Windows.Media.ImageSource ImageSourceFromEmbeddedResourceStream(string resName) { string imgPath = $"SWS.Commons.Images.{resName}"; System.Reflection.Assembly assy = System.Reflection.Assembly.GetExecutingAssembly(); - //foreach (string resource in assy.GetManifestResourceNames()) - //{ - // Console.WriteLine(resource);//遍历所有的内嵌资源 - //} System.IO.Stream stream = assy.GetManifestResourceStream(imgPath); if (stream == null) return null; @@ -341,9 +372,8 @@ namespace SWS.Commons public static string GetPCInfo() { - string computerName = Environment.MachineName; // 获取计算机名称 + string computerName = Environment.MachineName; // 获取计算机名称 string userName = Environment.UserName; // 获取当前用户名称 - return $"{computerName} 计算机{userName} 用户"; } diff --git a/newFront/c#前端/SWS.Commons/Helper/Behaviours/TreeViewSelectedItemBehavior.cs b/newFront/c#前端/SWS.Commons/Helper/Behaviours/TreeViewSelectedItemBehavior.cs new file mode 100644 index 00000000..818a912d --- /dev/null +++ b/newFront/c#前端/SWS.Commons/Helper/Behaviours/TreeViewSelectedItemBehavior.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Microsoft.Xaml.Behaviors; + +namespace SWS.Commons.Helper.Behaviours +{ + /// + /// 让 WPF TreeView 支持 SelectedItem 双向绑定的行为类。 + /// 应用于 TreeView 后,可在 ViewModel 中直接使用绑定方式访问/设置选中项。 + /// + public static class TreeViewSelectedItemBehavior + { + public static readonly DependencyProperty SelectedItemProperty = + DependencyProperty.RegisterAttached( + "SelectedItem", + typeof(object), + typeof(TreeViewSelectedItemBehavior), + new FrameworkPropertyMetadata( + null, + FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, + OnSelectedItemChanged)); + + // 获取附加属性值 + public static object GetSelectedItem(TreeView treeView) => + treeView.GetValue(SelectedItemProperty); + + // 设置附加属性值 + public static void SetSelectedItem(TreeView treeView, object value) => + treeView.SetValue(SelectedItemProperty, value); + + // 属性变化时的事件处理 + private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + if (sender is TreeView treeView) + { + // 解耦旧事件处理器 + treeView.SelectedItemChanged -= OnTreeViewSelectedItemChanged; + // 连接新事件处理器 + treeView.SelectedItemChanged += OnTreeViewSelectedItemChanged; + } + } + + // TreeView选择项变化时的处理 + private static void OnTreeViewSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) + { + var treeView = (TreeView)sender; + // 更新附加属性值 + treeView.SetCurrentValue(SelectedItemProperty, e.NewValue); + } + } + +} diff --git a/newFront/c#前端/SWS.Commons/Helper/LoggerHelper.cs b/newFront/c#前端/SWS.Commons/Helper/LoggerHelper.cs index ca5bc6d4..534dacce 100644 --- a/newFront/c#前端/SWS.Commons/Helper/LoggerHelper.cs +++ b/newFront/c#前端/SWS.Commons/Helper/LoggerHelper.cs @@ -1,12 +1,16 @@ using System; using System.IO; using System.Reflection; +using System.Windows; +using log4net.Appender; +using log4net.Config; +using log4net.Layout; using Newtonsoft.Json.Linq; namespace SWS.Commons { /// - /// nLog使用帮助类 + /// Log使用帮助类 /// public class LoggerHelper { @@ -19,13 +23,42 @@ namespace SWS.Commons private static LoggerHelper _obj = null; private static string logPath = string.Empty; private LoggerHelper() - { - - logPath = Path.Combine(GlobalObject.GetDllPath(), "Logs\\"); - if (!Directory.Exists(logPath)) - { Directory.CreateDirectory(logPath); } - var configFile = new FileInfo(Path.Combine(GlobalObject.GetDllPath(), "log4net.config")); - log4net.Config.XmlConfigurator.ConfigureAndWatch(configFile); + { + try + { + logPath = Path.Combine(GlobalObject.GetDllPath(), "Logs\\"); + if (!Directory.Exists(logPath)) + { Directory.CreateDirectory(logPath); } + var configFile = new FileInfo(Path.Combine(GlobalObject.GetDllPath(), "log4net.config")); + log4net.Config.XmlConfigurator.ConfigureAndWatch(configFile); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message+"\n\r"+ex.ToString()); + } + + } + #region 初始 + + #endregion + public static bool ChangeLogFileName(string name) + { + var path = Path.Combine(GlobalObject.GetDllPath(), "SWSLogs\\"); + if (!Directory.Exists(path)) + { Directory.CreateDirectory(path); } + var rootRepository = log4net.LogManager.GetRepository(); + foreach (var appender in rootRepository.GetAppenders()) + { + if (appender is log4net.Appender.FileAppender fileAppender&&!string.IsNullOrEmpty(fileAppender.File) && appender.Name.ToLower().Contains(name)) + { + // string filename= Path.Combine(GlobalObject.GetDllPath(),$"SWSLogs\\"); + //fileAppender.Close(); + fileAppender.File = path; + fileAppender.ActivateOptions(); + return true; + } + } + return false; } /// /// 获取当前的日志记录对象。 @@ -55,6 +88,7 @@ namespace SWS.Commons /// 需要记录的信息。 public void Info(string msg) { + ChangeLogFileName("info"); loginfo.Info(msg); } @@ -67,6 +101,7 @@ namespace SWS.Commons /// 需要记录的信息。 public void Warn(string msg) { + ChangeLogFileName("warn"); logwarn.Warn(msg); } @@ -79,6 +114,7 @@ namespace SWS.Commons /// 需要记录的信息。 public void Error(string msg) { + ChangeLogFileName("error"); logerror.Error("----------------------------Error BEGIN------------------------------"); logerror.Error(msg); logerror.Error("-----------------------------Error END-------------------------------"); @@ -93,9 +129,10 @@ namespace SWS.Commons /// 需要记录的系统异常。 public void Fatal(string msg) { + ChangeLogFileName("fatal"); logfatal.Fatal("----------------------------Fatal BEGIN------------------------------"); - logerror.Fatal(msg); - logerror.Fatal("-----------------------------Fatal END-------------------------------"); + logfatal.Fatal(msg); + logfatal.Fatal("-----------------------------Fatal END-------------------------------"); } #endregion diff --git a/newFront/c#前端/SWS.Commons/SWS.Commons.csproj b/newFront/c#前端/SWS.Commons/SWS.Commons.csproj index 5c21d070..7f8c8a7d 100644 --- a/newFront/c#前端/SWS.Commons/SWS.Commons.csproj +++ b/newFront/c#前端/SWS.Commons/SWS.Commons.csproj @@ -104,6 +104,7 @@ + diff --git a/newFront/c#前端/SWS.Commons/bin/Debug/log4net.config b/newFront/c#前端/SWS.Commons/bin/Debug/log4net.config index dc48092d..2e52c6ab 100644 --- a/newFront/c#前端/SWS.Commons/bin/Debug/log4net.config +++ b/newFront/c#前端/SWS.Commons/bin/Debug/log4net.config @@ -8,13 +8,30 @@ - + + + + + + + + + + + + + + + + + + + - - + @@ -29,7 +46,25 @@ - + + + + + + + + + + + + + + + + + + + @@ -70,24 +105,6 @@ - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/newFront/c#前端/SWS.Commons/log4net.config b/newFront/c#前端/SWS.Commons/log4net.config index dc48092d..2e52c6ab 100644 --- a/newFront/c#前端/SWS.Commons/log4net.config +++ b/newFront/c#前端/SWS.Commons/log4net.config @@ -8,13 +8,30 @@ - + + + + + + + + + + + + + + + + + + + - - + @@ -29,7 +46,25 @@ - + + + + + + + + + + + + + + + + + + + @@ -70,24 +105,6 @@ - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/newFront/c#前端/SWS.Electrical/Commands.cs b/newFront/c#前端/SWS.Electrical/Commands.cs index 79ddf8bb..4a00b482 100644 --- a/newFront/c#前端/SWS.Electrical/Commands.cs +++ b/newFront/c#前端/SWS.Electrical/Commands.cs @@ -1,5 +1,11 @@ using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; using System.Windows.Forms; +using Bricscad.ApplicationServices; using Bricscad.Ribbon; using Bricscad.Windows; using Prism.Events; @@ -16,6 +22,7 @@ using Telerik.Windows.Controls; using Unity; using Application = Bricscad.ApplicationServices.Application; using DialogParameters = Prism.Services.Dialogs.DialogParameters; +using MessageBox = System.Windows.Forms.MessageBox; [assembly: CommandClass(typeof(Commands))] [assembly: ExtensionApplication(typeof(Commands))] @@ -23,27 +30,71 @@ namespace SWS.Electrical { public partial class Commands : IExtensionApplication { - public void Initialize() { try { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; if (RibbonServices.RibbonPaletteSet == null) RibbonServices.CreateRibbonPaletteSet(); Start.RegisterTypes(); Start.AutoLogin(); - AddTab(); + // 延迟初始化UI组件 + InitializeCustomUI(); + + System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + timer.Interval = 50; // 50ms延迟 + timer.Tick += (s, e) => + { + timer.Stop(); + var ribbonControl = ComponentManager.Ribbon; + if (ribbonControl != null) + { + //先切换到常用标签,再切换到电气系统标签 + ribbonControl.Tabs[0].IsActive = true; + Thread.Sleep(5); + foreach (var tab in ribbonControl.Tabs) + { + if (tab.Name == "Electric") + { + // 激活选项卡 + tab.IsActive = true; + } + } + } + }; + timer.Start(); + + if (System.Windows.Application.Current == null) + { + var app = new System.Windows.Application + { + // 设置为显式关闭,防止窗口关闭时 Application 被自动终结 + ShutdownMode = ShutdownMode.OnExplicitShutdown + }; + } + GlobalObject.ClearLog(); } catch (System.Exception e) { Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString()); } } - - + private void InitializeCustomUI() + { + try + { + //在这里初始化你的自定义UI + AddTab(); + } + catch (System.Exception ex) + { + LoggerHelper.Current.Error("UI初始化失败: " + ex.Message); + } + } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { @@ -51,26 +102,27 @@ namespace SWS.Electrical { // 记录异常信息到日志文件,这里简单打印到控制 ? System.Exception ex = e.ExceptionObject as System.Exception; - Console.WriteLine($"发生未处理的异常: {ex.Message}"); - Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}"); + LoggerHelper.Current.Error($"发生未处理的异常: {ex.Message}"); + LoggerHelper.Current.Error($"异常信息: {ex.ToString()}"); + LoggerHelper.Current.Error($"异常堆栈跟踪: {ex.StackTrace}"); // 关闭所有打开的对话框窗口 // 提示用户发生了错 ? - MessageBox.Show("发生错误,请检查日志文件以获取更多信息 ?", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + var result= MessageBox.Show("发生错误,是否打开日志文件以获取更多信息?", "错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); + if(result== System.Windows.Forms.DialogResult.OK) + { + System.Diagnostics.Process.Start("explorer.exe", GlobalObject.GetLogPath()); + } } catch (System.Exception innerEx) { // 如果在处理异常时又发生了异常,简单打印信 ? - Console.WriteLine($"处理异常时发生错 ? {innerEx.Message}"); + LoggerHelper.Current.Error($"处理异常时发生错: {innerEx.Message}"); } } - public void Terminate() - { - } - void AddTab() { RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab @@ -235,10 +287,10 @@ namespace SWS.Electrical ribbonRowPanel.Items.Add(btnMenu); ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列 #endregion - + dataSource.Items.Add(ribbonRowPanel); #endregion - + #region Ribbon 材料管理 dataSource = new RibbonPanelSource(); dataSource.Title = "材料表管理"; @@ -249,7 +301,7 @@ namespace SWS.Electrical //垂直排列按钮panel ribbonRowPanel = new RibbonRowPanel(); - + #region buttons 材料表自动生成 btnMenu = new RibbonButton(); btnMenu.ToolTip = "材料表自动生成"; @@ -290,6 +342,9 @@ namespace SWS.Electrical } + public void Terminate() + { + } } } diff --git a/newFront/c#前端/SWS.Electrical/Event/checkInEvent.cs b/newFront/c#前端/SWS.Electrical/Event/checkInEvent.cs new file mode 100644 index 00000000..cb649d61 --- /dev/null +++ b/newFront/c#前端/SWS.Electrical/Event/checkInEvent.cs @@ -0,0 +1,10 @@ +using Prism.Events; +using SWS.Electrical.ViewModels; +using SWS.Model; + +namespace SWS.Electrical +{ + public class sendMessageEvent : PubSubEvent + { + } +} diff --git a/newFront/c#前端/SWS.Electrical/GlobalObj.cs b/newFront/c#前端/SWS.Electrical/GlobalObj.cs index e5d7d323..45168dad 100644 --- a/newFront/c#前端/SWS.Electrical/GlobalObj.cs +++ b/newFront/c#前端/SWS.Electrical/GlobalObj.cs @@ -42,19 +42,7 @@ namespace SWS.Electrical public static async Task CheckLogin() { try - { - //var parser = new FileIniDataParser(); - //string[] lines = File.ReadAllLines(GlobalObject.configPath); - //IniData data = parser.Parser.Parse(File.ReadAllText(GlobalObject.configPath)); - //var data = configIni.ReadFile(GlobalObject.configPath); - //string token = data["LoginInfo"]["LoginToken"]; - //string loginkey = data["LoginInfo"]["LoginMark"]; - //string curProjId = data["LoginInfo"]["CurProjId"]; - //LocalWorkDir= data["Profile"]["strLocalWorkDir"]; - //string address = data["Profile"]["strIPAddress"]; - //string port = data["Profile"]["nPort"]; - //string dbType = data["Profile"]["nConType"]; - //string domain= data["Profile"]["strDomainName"]; + { string token = IniHelper.ReadValueFromIniFile("LoginInfo", "LoginToken"); string loginkey = IniHelper.ReadValueFromIniFile("LoginInfo", "LoginMark"); string curProjId = IniHelper.ReadValueFromIniFile("LoginInfo", "CurProjId"); @@ -69,7 +57,7 @@ namespace SWS.Electrical GlobalObject.client = new HttpClient() { BaseAddress = new Uri($"{strDomain}/api/"), - Timeout = TimeSpan.FromSeconds(120) + Timeout = TimeSpan.FromSeconds(600) }; } else if (dbType == "0") @@ -77,7 +65,7 @@ namespace SWS.Electrical GlobalObject.client = new HttpClient() { BaseAddress = new Uri($"http://{address}:{port}/api/"), - Timeout = TimeSpan.FromSeconds(120) + Timeout = TimeSpan.FromSeconds(600) }; } GlobalObject.client.DefaultRequestHeaders.Add("logintoken", token); @@ -105,7 +93,7 @@ namespace SWS.Electrical } } if (GlobalObject.curProject == null) - { GlobalObject.curProject = new ec_project() { ProjectId = curProjId }; } + { GlobalObject.curProject = new ec_project() { ProjectId = curProjId }; } return flag; } catch (System.Exception ex) diff --git a/newFront/c#前端/SWS.Electrical/Models/DtoAutoPlotLayout.cs b/newFront/c#前端/SWS.Electrical/Models/DtoAutoPlotLayout.cs index 383e614c..2d05237b 100644 --- a/newFront/c#前端/SWS.Electrical/Models/DtoAutoPlotLayout.cs +++ b/newFront/c#前端/SWS.Electrical/Models/DtoAutoPlotLayout.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using SWS.Model; +using SWS.Share; using Telerik.Windows.Controls; namespace SWS.Electrical.Models @@ -31,9 +32,13 @@ namespace SWS.Electrical.Models /// public string BasePointTagNumber { get; set; } = ""; /// + /// 房间号 + /// + public string RoomNo { get; set; } + /// /// 比例 /// - public double Scale { get; set; } + public double Scale { get; set; } /// /// true:默认块,false:异性块 /// @@ -68,7 +73,7 @@ namespace SWS.Electrical.Models { get { return _TagPixelOnDwg; } set { _TagPixelOnDwg = value; RaisePropertyChanged(nameof(TagPixelOnDwg)); } - } + } /// /// 肋位号 和 偏移量 /// diff --git a/newFront/c#前端/SWS.Electrical/SWS.Electrical.csproj b/newFront/c#前端/SWS.Electrical/SWS.Electrical.csproj index 74cedada..49673316 100644 --- a/newFront/c#前端/SWS.Electrical/SWS.Electrical.csproj +++ b/newFront/c#前端/SWS.Electrical/SWS.Electrical.csproj @@ -133,6 +133,7 @@ + diff --git a/newFront/c#前端/SWS.Electrical/ViewModels/DialogAutoArrangeLayoutViewModel.cs b/newFront/c#前端/SWS.Electrical/ViewModels/DialogAutoArrangeLayoutViewModel.cs index b91a8efe..2835a6ab 100644 --- a/newFront/c#前端/SWS.Electrical/ViewModels/DialogAutoArrangeLayoutViewModel.cs +++ b/newFront/c#前端/SWS.Electrical/ViewModels/DialogAutoArrangeLayoutViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.IO; using System.Linq; using System.Threading; @@ -12,7 +13,11 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Media3D; using Bricscad.EditorInput; +using ImTools; +using IniParser.Model; +using Microsoft.Win32; using Newtonsoft.Json; +using Prism.Events; using Prism.Services.Dialogs; using SWS.CAD.Base; using SWS.Commons; @@ -29,6 +34,17 @@ using Visibility = System.Windows.Visibility; namespace SWS.Electrical.ViewModels { + public class MessageModel + { + /// + /// 信息 + /// + public string Message { get; set; } + /// + /// 是否成功 + /// + public bool IsSuccess { get; set; } = true; + } public class DialogAutoArrangeLayoutViewModel : DialogBase, IDialogAware { private ObservableCollection _listDrawings; @@ -227,6 +243,15 @@ namespace SWS.Electrical.ViewModels get { return _ErrTagCount; } set { _ErrTagCount = value; OnPropertyChanged(nameof(ErrTagCount)); } } + private bool _isCheckDelete = false; + /// + /// 删除现有元件再绘制 + /// + public bool isCheckDelete + { + get { return _isCheckDelete; } + set { _isCheckDelete = value; OnPropertyChanged(nameof(isCheckDelete)); } + } /// /// 命令事件 @@ -252,8 +277,11 @@ namespace SWS.Electrical.ViewModels private string dwgName = string.Empty; private List listLibraryTagName = new List();//元件图纸上的位号属性名称, private List listDeck = new List();//甲板号值列表 - private List listArea = new List();//区域值列表 - private List listSystem = new List();//所属系统值列表 + private List listSystem = new List();//所属系统值列表 + List listEnginedata = new List();//要绘制的多个位号的位号信息 + List listObjecttype = new List();//要绘制的多个位号的属性信息列表 + List listUpdateEnginedata = new List();//要绘制的多个位号的关联图纸属性列表 + IEventAggregator eventAggregator; public DialogAutoArrangeLayoutViewModel() { Command_StartDrawing = new DelegateCommand(onStartDrawing); @@ -270,10 +298,12 @@ namespace SWS.Electrical.ViewModels _ServiceObjectType = GlobalObject.container.Resolve(); _ServiceProjectSettings = GlobalObject.container.Resolve(); _ServiceDataItem = GlobalObject.container.Resolve(); + eventAggregator = GlobalObject.container.Resolve(); listDrawings = new ObservableCollection(); listBasePoint = new ObservableCollection(); listErrBasePoint = new ObservableCollection(); - listMsg = new ObservableCollection(); + listMsg = new ObservableCollection(); + eventAggregator.GetEvent().Subscribe(onReceviceMsg, ThreadOption.UIThread, true); var list = new ObservableCollection(); list.Add(new KeyValueModel { Key = "甲板号", Value = "甲板号" }); //list.Add(new KeyValueModel { Key = "区域", Value = "区域" }); @@ -364,11 +394,12 @@ namespace SWS.Electrical.ViewModels { AddMsg($"布置图列表加载中..."); var listDwg = await _ServiceDrawing.GetDrawingCatalogue(); - if (listDwg == null) + if (listDwg == null || !listDwg.Any()) { AddMsg($"布置图列表没有数据!"); return; } + GlobalObject.AllDrawings = listDwg.ToList(); foreach (var model in listDwg) { if (model.Text == "布置图") @@ -409,14 +440,14 @@ namespace SWS.Electrical.ViewModels } 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 }); } - } + //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("甲板号"); + var listDetail = await _ServiceDataItem.GetDetails("甲板号"); if (listDetail != null && listDetail.Any()) { foreach (var item in listDetail) @@ -505,7 +536,7 @@ namespace SWS.Electrical.ViewModels { string strErr = isBasePointErr ? "基点异常;" : ""; strErr += isTagErr ? "元件异常" : ""; - strErr = strErr.Replace(";",""); + strErr = strErr.EndsWith(";") ? strErr.Replace(";", "") : strErr; listErrDto.Add(new DtoAutoPlotLayout() { IsSelected = true, @@ -513,6 +544,7 @@ namespace SWS.Electrical.ViewModels DrawingFileName = dwg.DrawingFileName, EngineDataID = basePoint.EngineDataID, BasePointTagNumber = basePoint.TagNumber, + RoomNo = basePoint.RoomNo, Scale = basePoint.Scale, FileId = basePoint.FileId, PixelOnDwg = basePoint.PixelOnDwg, @@ -538,6 +570,7 @@ namespace SWS.Electrical.ViewModels DrawingFileName = dwg.DrawingFileName, EngineDataID = basePoint.EngineDataID, BasePointTagNumber = basePoint.TagNumber, + RoomNo = basePoint.RoomNo, Scale = basePoint.Scale, FileId = basePoint.FileId, PixelOnDwg = basePoint.PixelOnDwg, @@ -588,41 +621,499 @@ namespace SWS.Electrical.ViewModels MessageBox.Show("请先勾选基点元件信息!"); return; } + listMsg.Clear(); + var progress = new Progress(UpdateProgress); + await DoWorkAsync(progress, new CancellationTokenSource()); + + + #region back + + //try + //{ + // isDrawing = true; + // List listFile = new List(); + // List listBlockDwgPath = new List(); //图块下载路径列表,同个异形块下载一次,先下载后删除 + // listMsg.Clear(); + // listUpdateEnginedata.Clear(); + // //获取多个位号属性 + // AddMsg($"开始获取全部位号属性..."); + // string strTagNumbers = string.Join(",", listDto.Select(a => a.TagNumber).ToList()); + // listObjecttype = await _ServiceObjectType.GetTagInfosByTags(strTagNumbers); + // listEnginedata = await _ServiceObjectType.GetEngineDataListByTags(strTagNumbers); + // AddMsg($"获取全部位号类型属性完成,共有{listObjecttype.Count}种类型!"); + // //循环画图 + // for (int i = 0; i < listDto.Count; i++) + // { + // var basePoint = listDto[i]; + // if (basePoint.AutoDrawing == "已绘制") + // { + // AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已绘制,跳至下一个元件"); + // continue; + // } + // if (basePoint.AutoDrawing == "已存在" && !isCheckDelete) + // { + // AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已存在,跳至下一个元件"); + // continue; + // } + + // msg = OpenDwg(basePoint); + // if (!string.IsNullOrEmpty(msg)) + // { + // AddMsg($"图纸打开失败:{msg}", false); + // continue; + // } + // var listTag = listDto.Where(a => a.DrawingFileID == basePoint.DrawingFileID).Select(a => a.TagNumber).ToList(); + // var listEntitys = isCheckDelete ? General.GetAllEntity(listTag) : General.GetAllEntity(new List());//获取图纸所有实体 + // 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; + // } + // filePath = Path.Combine(GlobalObject.GetCacheFolder(), $"{tag.TagNumber}.dwg"); + // string blockName = string.Empty; + // if (string.IsNullOrEmpty(tag.FileId)) + // { + // //元件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); + // AddMsg($"本地默认常规图块图纸复制成功"); + // } + // else + // { + // var blockDwgPath = Path.Combine(GlobalObject.GetDllPath(), "Template\\常规矩形单行图块.dwg"); + // if (!File.Exists(blockDwgPath)) + // { + // AddMsg($"默认图块找不到:{blockDwgPath}", false); + // continue; + // } + // //默认图块,只有中间部分 + // blockName = "常规矩形单行图块"; + // File.Copy(blockDwgPath, filePath, true); + // AddMsg($"本地默认常规图块图纸复制成功"); + // } + // } + // else + // { + // string blockDwgPath = Path.Combine(GlobalObject.GetCacheFolder(), $"{tag.FileId}.dwg"); + // if (File.Exists(blockDwgPath)) + // { + // File.Copy(blockDwgPath, filePath, true); + // var item = listFile.FirstOrDefault(a => a.LibraryFileID == tag.FileId); + // if (item != null) + // { + // blockName = item.LibraryFileName; + // } + // else { blockName = tag.TagNumber; } + // AddMsg($"元件图纸:{tag.TagNumber},已下载过,复制本地缓存块图纸文件成功"); + // } + // else + // { + // //下载元件图纸文件 + // var obj = await _ServiceLibraryFile.GetEntity(tag.FileId); + // blockName = obj.LibraryFileName; + // AddMsg($"元件图纸:{tag.TagNumber}, 开始下载..."); + // msg = await _ServiceAnnexes.DownloadFile(blockDwgPath, obj.FolderId); + // if (!string.IsNullOrEmpty(msg)) + // { + // AddMsg($"元件图纸下载失败,信息:" + msg, false); + // continue; + // } + // File.Copy(blockDwgPath, filePath, true); + // listBlockDwgPath.Add(blockDwgPath); + // listFile.Add(obj); + // AddMsg($"元件图纸:{tag.TagNumber}, 下载成功"); + // } + // } + // listBlockDwgPath.Add(filePath); + // //把元件的位号属性改成要绘制的位号值 + // var flag = General.UpdateCableNo(filePath, listLibraryTagName, tag.TagNumber, tag.IsNotDefaultSymbol, tag.TagNumber_Upper, tag.TagNumber_Lower); + + // //X轴:图上基点的坐标X +(接口数据元件的X + 接口数据元件的XOFF -接口数据基点的X-接口数据基点的Xoff)*比例系数 + // //Y轴:图上基点的坐标Y +(接口数据元件的Yoff-接口数据基点的Yoff)*比例系数 + // double scale = basePoint.Scale;//比例系数 + // double x = entity.X + (tag.X + double.Parse(tag.XOff) - basePoint.X - double.Parse(basePoint.XOff)) * scale; + // AddMsg($"块X坐标计算:{entity.X}+({tag.X}+{tag.XOff}-{basePoint.X}-{basePoint.XOff})*{scale}={x}"); + // double y = entity.Y + (double.Parse(tag.YOff) - double.Parse(basePoint.XOff)) * scale; + // AddMsg($"块Y坐标计算:{entity.Y}+({tag.YOff}-{basePoint.XOff})*{scale}={y}"); + // AddMsg($"块最后坐标:{x},{y},0"); + // double z = entity.Z; + // Point3d tagPoint = new Point3d(x, y, z); + // AddMsg($"元件图纸:{tag.TagNumber}, 开始添加进布置图中..."); + // msg =await AddBlock(basePoint, blockName, filePath, tagPoint); + // 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); } + // } + // } + // else + // { + // basePoint.AutoDrawing = "已失败"; + // AddMsg($"元件:{tag.TagNumber},绘制异常:{msg}", false); + // } + + // } + // if (listUpdateEnginedata.Any()) + // { + // AddMsg($"开始批量位号关联属性,数量:{listUpdateEnginedata.Count}......"); + // msg = await _ServiceObjectType.UpdatePixelAndPropBatch(listUpdateEnginedata); + // if (string.IsNullOrEmpty(msg)) + // { + // AddMsg("位号关联属性成功,数量:" + listUpdateEnginedata.Count); + // } + // else + // { + // AddMsg($"位号关联属性失败,数量:{listUpdateEnginedata.Count},异常:{msg}", false); + // } + // } + // foreach (var file in listBlockDwgPath) + // { + // File.Delete(file);//删除缓存图块图纸文件 + // File.Delete(file.Replace(".dwg", ".bak")); + // } + // AddMsg("操作已完成!"); + // isDrawing = false; + //} + //catch (Exception ex) + //{ + // MessageBox.Show("绘图异常:" + ex.Message); + // isDrawing = false; + //} + #endregion + } + #region DoWork + private void UpdateProgress(MessageModel dto) + { + System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => + { + AddMsg(dto.Message, dto.IsSuccess); + })); + } + + private async Task DoWorkAsync(IProgress progress, CancellationTokenSource cts) + { try { + int time = 1; + var msg = string.Empty; + var filePath = string.Empty; + var listDto = listBasePoint.Where(a => a.IsSelected == true).ToList(); isDrawing = true; + List listFile = new List(); + List listBlockDwgPath = new List(); //图块下载路径列表,同个异形块下载一次,先下载后删除 listMsg.Clear(); + listUpdateEnginedata.Clear(); + //获取多个位号属性 + AddMsg($"开始获取全部位号属性..."); + await Task.Delay(time, cts.Token); + string strTagNumbers = string.Join(",", listDto.Select(a => a.TagNumber).ToList()); + listObjecttype = await _ServiceObjectType.GetTagInfosByTags(strTagNumbers); + listEnginedata = await _ServiceObjectType.GetEngineDataListByTags(strTagNumbers); + AddMsg($"获取全部位号类型属性完成,共有{listObjecttype.Count}种类型!"); + await Task.Delay(time, cts.Token); + //循环画图 for (int i = 0; i < listDto.Count; i++) - //foreach (var basePoint in listDto) { + cts.Token.ThrowIfCancellationRequested(); var basePoint = listDto[i]; - if (basePoint.AutoDrawing == "已绘制") + if (basePoint.AutoDrawing == "已绘制" && !isCheckDelete) + { + AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已绘制,跳至下一个元件", false); + await Task.Delay(time, cts.Token); + continue; + } + if (basePoint.AutoDrawing == "已存在" && !isCheckDelete) + { + AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已存在,跳至下一个元件", false); + await Task.Delay(time, cts.Token); + continue; + } + + msg = OpenDwg(basePoint); + if (!string.IsNullOrEmpty(msg)) + { + AddMsg($"图纸打开失败:{msg}", false); + await Task.Delay(time, cts.Token); + continue; + } + var listTag = listDto.Where(a => a.DrawingFileID == basePoint.DrawingFileID).Select(a => a.TagNumber).ToList(); + var listEntitys = isCheckDelete ? General.GetAllEntity(listTag) : General.GetAllEntity(new List());//获取图纸所有实体 + var entity = listEntitys.FirstOrDefault(a => a.Handle.ToString() == basePoint.PixelOnDwg); + if (entity == null) + { + AddMsg($"当前基点:{basePoint.BasePointTagNumber} 在图上找不到,不添加此元件,跳至下一个元件", false); + await Task.Delay(time, cts.Token); + 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; + await Task.Delay(time, cts.Token); + continue; + } + filePath = Path.Combine(GlobalObject.GetCacheFolder(), $"{tag.TagNumber}.dwg"); + string blockName = string.Empty; + if (string.IsNullOrEmpty(tag.FileId)) + { + //元件ID为空 用本地默认图块图纸 + if (!string.IsNullOrEmpty(tag.TagNumber_Lower)) + { + var blockDwgPath = Path.Combine(GlobalObject.GetDllPath(), "Template\\常规矩形两行图块.dwg"); + if (!File.Exists(blockDwgPath)) + { + AddMsg($"默认图块找不到:{blockDwgPath}", false); + await Task.Delay(time, cts.Token); + continue; + } + //默认上下图块 + blockName = "常规矩形两行图块"; + File.Copy(blockDwgPath, filePath, true); + } + else + { + var blockDwgPath = Path.Combine(GlobalObject.GetDllPath(), "Template\\常规矩形单行图块.dwg"); + if (!File.Exists(blockDwgPath)) + { + AddMsg($"默认图块找不到:{blockDwgPath}", false); + await Task.Delay(time, cts.Token); + continue; + } + //默认图块,只有中间部分 + blockName = "常规矩形单行图块"; + File.Copy(blockDwgPath, filePath, true); + } + } + else + { + string blockDwgPath = Path.Combine(GlobalObject.GetCacheFolder(), $"{tag.FileId}.dwg"); + if (File.Exists(blockDwgPath)) + { + File.Copy(blockDwgPath, filePath, true); + var item = listFile.FirstOrDefault(a => a.LibraryFileID == tag.FileId); + if (item != null) + { + blockName = item.LibraryFileName; + } + else { blockName = tag.TagNumber; } + } + else + { + //下载元件图纸文件 + var obj = await _ServiceLibraryFile.GetEntity(tag.FileId); + blockName = obj.LibraryFileName; + AddMsg($"元件图纸:{tag.TagNumber}, 开始下载..."); + await Task.Delay(time, cts.Token); + msg = await _ServiceAnnexes.DownloadFile(blockDwgPath, obj.FolderId); + if (!string.IsNullOrEmpty(msg)) + { + AddMsg($"元件图纸下载失败,信息:{msg}", false); + await Task.Delay(time, cts.Token); + continue; + } + File.Copy(blockDwgPath, filePath, true); + listBlockDwgPath.Add(blockDwgPath); + listFile.Add(obj); + AddMsg($"元件图纸:{tag.TagNumber}, 下载成功"); + await Task.Delay(time, cts.Token); + } + } + listBlockDwgPath.Add(filePath); + //把元件的位号属性改成要绘制的位号值 + var flag = General.UpdateCableNo(filePath, listLibraryTagName, tag.TagNumber, tag.IsNotDefaultSymbol, tag.TagNumber_Upper, tag.TagNumber_Lower); + //X轴:图上基点的坐标X +(接口数据元件的X + 接口数据元件的XOFF -接口数据基点的X-接口数据基点的Xoff)*比例系数 + //Y轴:图上基点的坐标Y +(接口数据元件的Yoff-接口数据基点的Yoff)*比例系数 + double scale = basePoint.Scale;//比例系数 + double x = 0; + double y = 0; + if (tag.X != 0)//肋位号不为0的时候,去肋位号相关数据去算坐标 + { + x = entity.X + (tag.X + double.Parse(tag.XOff) - basePoint.X - double.Parse(basePoint.XOff)) * scale; + msg = $"块X坐标计算:{entity.X}+({tag.X}+{tag.XOff}-{basePoint.X}-{basePoint.XOff})*{scale}={x}"; + AddMsg(msg); + y = entity.Y + (double.Parse(tag.YOff) - double.Parse(basePoint.XOff)) * scale; + msg = $"块Y坐标计算:{entity.Y}+({tag.YOff}-{basePoint.XOff})*{scale}={y}"; + AddMsg(msg); + await Task.Delay(time, cts.Token); + } + else + { + if (!string.IsNullOrEmpty(tag.RoomNo)) + { + int rnd = new Random().Next(1, 5); + x = entity.X + rnd; + msg = $"块X坐标取房间号基点附近:{entity.X}+{rnd}={x}"; + AddMsg(msg); + y = entity.Y + rnd; + msg = $"块Y坐标取房间号基点附近:{entity.Y}+{rnd}={y}"; + AddMsg(msg); + await Task.Delay(time, cts.Token); + } + else + { + x = entity.X + (tag.X + double.Parse(tag.XOff) - basePoint.X - double.Parse(basePoint.XOff)) * scale; + msg = $"块X坐标计算:{entity.X}+({tag.X}+{tag.XOff}-{basePoint.X}-{basePoint.XOff})*{scale}={x}"; + AddMsg(msg); + y = entity.Y + (double.Parse(tag.YOff) - double.Parse(basePoint.XOff)) * scale; + msg = $"块Y坐标计算:{entity.Y}+({tag.YOff}-{basePoint.XOff})*{scale}={y}"; + AddMsg(msg); + await Task.Delay(time, cts.Token); + } + } + double z = entity.Z; + Point3d tagPoint = new Point3d(x, y, z); + AddMsg($"元件图纸:{tag.TagNumber}, 开始添加进布置图中..."); + await Task.Delay(time, cts.Token); + msg = await AddBlock(basePoint, blockName, filePath, tagPoint); + if (string.IsNullOrEmpty(msg)) + { + AddMsg($"布置图:{basePoint.DrawingFileName},成功插入元件:{tag.TagNumber}"); + basePoint.AutoDrawing = "已绘制"; + await Task.Delay(time, cts.Token); + //当下一个要画元件的图纸和当前图纸不一样时,保存图纸 + if (i + 1 >= listDto.Count) + { + AddMsg($"布置图:{basePoint.DrawingFileName},开始保存..."); + await Task.Delay(time, cts.Token); + General.SetDrawingReadOnly(dwgName, false); + msg = $"布置图:{basePoint.DrawingFileName},保存完成"; + await Task.Delay(time, cts.Token); + } + else + { + var nextTag = listDto[i + 1]; + if (basePoint.DrawingFileID != nextTag.DrawingFileID) + { + AddMsg($"布置图:{basePoint.DrawingFileName},开始保存..."); + await Task.Delay(time, cts.Token); + General.SetDrawingReadOnly(dwgName, false); + AddMsg($"布置图:{basePoint.DrawingFileName},保存完成"); + await Task.Delay(time, cts.Token); + } + } + } + else + { + basePoint.AutoDrawing = "已失败"; + AddMsg($"元件:{tag.TagNumber},绘制异常:{msg}"); + await Task.Delay(time, cts.Token); + } + } + if (listUpdateEnginedata.Any()) + { + AddMsg($"开始批量位号关联属性,数量:{listUpdateEnginedata.Count}......"); + await Task.Delay(time, cts.Token); + msg = await _ServiceObjectType.UpdatePixelAndPropBatch(listUpdateEnginedata); + if (string.IsNullOrEmpty(msg)) + { + AddMsg("位号关联属性成功,数量:" + listUpdateEnginedata.Count); + await Task.Delay(time, cts.Token); + } + else + { + AddMsg($"位号关联属性失败,数量:{listUpdateEnginedata.Count},异常:{msg}"); + await Task.Delay(time, cts.Token); + } + } + foreach (var file in listBlockDwgPath) + { + File.Delete(file);//删除缓存图块图纸文件 + File.Delete(file.Replace(".dwg", ".bak")); + } + AddMsg("操作已完成!"); + isDrawing = false; + } + catch (Exception ex) + { + MessageBox.Show("绘图异常:" + ex.Message); + LoggerHelper.Current.Error("绘图异常:" + ex.ToString()); + isDrawing = false; + } + } + + #endregion + private async void onAutoDrawing() + { + #region back + var msg = string.Empty; + var filePath = string.Empty; + var listDto = listBasePoint.Where(a => a.IsSelected == true).ToList(); + if (!listDto.Any()) + { + MessageBox.Show("请先勾选基点元件信息!"); + return; + } + try + { + List listFile = new List(); + List listBlockDwgPath = new List(); //图块下载路径列表,同个异形块下载一次,先下载后删除 + isDrawing = true; + listUpdateEnginedata.Clear(); + //获取多个位号属性 + AddMsg($"开始获取全部位号属性..."); + string strTagNumbers = string.Join(",", listDto.Select(a => a.TagNumber).ToList()); + listObjecttype = await _ServiceObjectType.GetTagInfosByTags(strTagNumbers); + listEnginedata = await _ServiceObjectType.GetEngineDataListByTags(strTagNumbers); + AddMsg($"获取全部位号类型属性完成,共有{listObjecttype.Count}种类型!"); + //循环画图 + for (int i = 0; i < listDto.Count; i++) + { + var basePoint = listDto[i]; + if (basePoint.AutoDrawing == "已绘制" && !isCheckDelete) { AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已绘制,跳至下一个元件"); continue; } - if (basePoint.AutoDrawing == "已存在") + if (basePoint.AutoDrawing == "已存在" && !isCheckDelete) { AddMsg($"当前基点[{basePoint.BasePointTagNumber}]和元件[{basePoint.TagNumber}]已存在,跳至下一个元件"); continue; } - msg = await OpenDwg(basePoint.DrawingFileID); + msg = OpenDwg(basePoint); if (!string.IsNullOrEmpty(msg)) { AddMsg($"图纸打开失败:{msg}", false); continue; } - - AddMsg($"打开图纸:{basePoint.DrawingFileName} "); - var listEntitys = General.GetAllEntity();//获取图纸所有实体 + var listTag = listDto.Where(a => a.DrawingFileID == basePoint.DrawingFileID).Select(a => a.TagNumber).ToList(); + var listEntitys = isCheckDelete ? General.GetAllEntity(listTag) : General.GetAllEntity(new List());//获取图纸所有实体 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) @@ -632,12 +1123,6 @@ namespace SWS.Electrical.ViewModels 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)) @@ -654,6 +1139,7 @@ namespace SWS.Electrical.ViewModels //默认上下图块 blockName = "常规矩形两行图块"; File.Copy(blockDwgPath, filePath, true); + AddMsg($"本地默认常规图块图纸复制成功"); } else { @@ -666,31 +1152,53 @@ namespace SWS.Electrical.ViewModels //默认图块,只有中间部分 blockName = "常规矩形单行图块"; File.Copy(blockDwgPath, filePath, true); + AddMsg($"本地默认常规图块图纸复制成功"); } } else { - //下载元件图纸文件 - var obj = await _ServiceLibraryFile.GetEntity(tag.FileId); - blockName = obj.LibraryFileName; - AddMsg($"元件图纸:{tag.TagNumber}, 开始下载..."); - msg = await _ServiceAnnexes.DownloadFile(filePath, obj.FolderId); - if (!string.IsNullOrEmpty(msg)) + string blockDwgPath = Path.Combine(GlobalObject.GetCacheFolder(), $"{tag.FileId}.dwg"); + if (File.Exists(blockDwgPath)) { - AddMsg($"元件图纸下载失败,信息:" + msg, false); - continue; + File.Copy(blockDwgPath, filePath, true); + var item = listFile.FirstOrDefault(a => a.LibraryFileID == tag.FileId); + if (item != null) + { + blockName = item.LibraryFileName; + } + else { blockName = tag.TagNumber; } + AddMsg($"元件图纸:{tag.TagNumber},已下载过,复制本地缓存块图纸文件成功"); + } + else + { + //下载元件图纸文件 + var obj = await _ServiceLibraryFile.GetEntity(tag.FileId); + blockName = obj.LibraryFileName; + AddMsg($"元件图纸:{tag.TagNumber}, 开始下载..."); + msg = await _ServiceAnnexes.DownloadFile(blockDwgPath, obj.FolderId); + if (!string.IsNullOrEmpty(msg)) + { + AddMsg($"元件图纸下载失败,信息:" + msg, false); + continue; + } + File.Copy(blockDwgPath, filePath, true); + listBlockDwgPath.Add(blockDwgPath); + listFile.Add(obj); + AddMsg($"元件图纸:{tag.TagNumber}, 下载成功"); } - AddMsg($"元件图纸:{tag.TagNumber}, 下载成功"); } - //filePath = "D:\\BricsCAD\\Temp\\测试11.dwg"; + listBlockDwgPath.Add(filePath); //把元件的位号属性改成要绘制的位号值 var flag = General.UpdateCableNo(filePath, listLibraryTagName, tag.TagNumber, tag.IsNotDefaultSymbol, tag.TagNumber_Upper, tag.TagNumber_Lower); //X轴:图上基点的坐标X +(接口数据元件的X + 接口数据元件的XOFF -接口数据基点的X-接口数据基点的Xoff)*比例系数 //Y轴:图上基点的坐标Y +(接口数据元件的Yoff-接口数据基点的Yoff)*比例系数 - double scale = 1;//比例系数 + double scale = basePoint.Scale;//比例系数 double x = entity.X + (tag.X + double.Parse(tag.XOff) - basePoint.X - double.Parse(basePoint.XOff)) * scale; + AddMsg($"块X坐标计算:{entity.X}+({tag.X}+{tag.XOff}-{basePoint.X}-{basePoint.XOff})*{scale}={x}"); double y = entity.Y + (double.Parse(tag.YOff) - double.Parse(basePoint.XOff)) * scale; + AddMsg($"块Y坐标计算:{entity.Y}+({tag.YOff}-{basePoint.XOff})*{scale}={y}"); + AddMsg($"块最后坐标:{x},{y},0"); double z = entity.Z; Point3d tagPoint = new Point3d(x, y, z); AddMsg($"元件图纸:{tag.TagNumber}, 开始添加进布置图中..."); @@ -709,9 +1217,31 @@ namespace SWS.Electrical.ViewModels { General.SetDrawingReadOnly(dwgName, false); } } } - else { AddMsg($"元件:{tag.TagNumber},绘制异常:{msg}"); } + else + { + basePoint.AutoDrawing = "已失败"; + AddMsg($"元件:{tag.TagNumber},绘制异常:{msg}", false); + } } + if (listUpdateEnginedata.Any()) + { + AddMsg($"开始批量位号关联属性,数量:{listUpdateEnginedata.Count}......"); + msg = await _ServiceObjectType.UpdatePixelAndPropBatch(listUpdateEnginedata); + if (string.IsNullOrEmpty(msg)) + { + AddMsg("位号关联属性成功,数量:" + listUpdateEnginedata.Count); + } + else + { + AddMsg($"位号关联属性失败,数量:{listUpdateEnginedata.Count},异常:{msg}", false); + } + } + foreach (var file in listBlockDwgPath) + { + File.Delete(file);//删除缓存图块图纸文件 + File.Delete(file.Replace(".dwg", ".bak")); + } AddMsg("操作已完成!"); isDrawing = false; } @@ -720,36 +1250,26 @@ namespace SWS.Electrical.ViewModels MessageBox.Show("绘图异常:" + ex.Message); isDrawing = false; } + #endregion } /// /// 打开图纸 /// /// - private async Task OpenDwg(string dwgId) + private string OpenDwg(DtoAutoPlotLayout dto) { 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); + string folderpath = GlobalObject.GetDwgPath(dto.DrawingFileID); + fullpath = Path.Combine(GlobalObj.LocalWorkDir, GlobalObject.curProject.ProjectName, folderpath, $"{dto.DrawingFileName}"); + if (!File.Exists(fullpath)) { - return dwgObj.DrawingFileName + ",图纸文件不存在,请先检出到本地!"; + return dto.DrawingFileName + ",图纸文件不存在,请先检出到本地!"; } - if (dwgObj.DrawingFileName == General.GetDwgName()) + if (dto.DrawingFileName == General.GetDwgName()) { return res; } @@ -758,12 +1278,14 @@ namespace SWS.Electrical.ViewModels { General.OpenDwg(fullpath); dwgName = fullpath; + AddMsg($"打开图纸:{dto.DrawingFileName} "); return res; } else { General.SwitchToDocument(fullpath); dwgName = fullpath; + AddMsg($"已打开图纸:{dto.DrawingFileName} "); return res; } @@ -784,46 +1306,54 @@ namespace SWS.Electrical.ViewModels 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()) + //string tagNum = string.Empty; + //var lsitEnginedata = await _ServiceObjectType.GetEngineDataListByTags(tagNumber); + //if (!lsitEnginedata.Any()) + //{ + // msg = $"元件位号:{tagNumber},属性未绑定,_ServiceObjectType.GetEngineDataListByTags({tagNumber})接口无数据"; + // AddMsg(msg, false); + // return msg; + //} + var enginedata = listEnginedata.FirstOrDefault(a => a.TagNumber == tagNumber); + if (enginedata == null) { - msg = $"元件位号:{tagNumber},属性未绑定,ServiceEnginedata.GetTagPixelsById({enginedataId})接口无数据"; - AddMsg(msg, false); + msg = $"元件位号:{tagNumber},找不到位号工程属性,无法关联属性!"; return msg; } - string objTypeId = lsitEnginedata[0].ObjectTypeID; - string objTypeName = lsitEnginedata[0].ObjectTypeName; + string objTypeId = enginedata.ObjectTypeID; + string objTypeName = enginedata.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); + //AddMsg($"元件已添加至图纸,句柄:{objId.Handle.ToString()}"); + //RefreshUI(999, $"元件已添加至图纸,句柄:{objId.Handle.ToString()}"); + //var dwgLibrary = await _ServiceLibraryFile.GetEntity(blockDwgId); List listPro = new List(); var handlid = objId.Handle.ToString();//添加图元返回的句柄 ec_enginedata item = new ec_enginedata(); + item.EngineDataID = enginedataId; 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()) + //item.Layout_Block_File = dwgLibrary; + var tagInfo = listObjecttype.FirstOrDefault(a => a.ObjectTypeID == enginedata.ObjectTypeID); + if (tagInfo == null) { - foreach (var dto in res[0].tags[0].EngineDataProperty) + msg = $"元件位号:{tagNumber},找不到位号属性信息,无法关联属性!"; + return msg; + } + foreach (var dto in tagInfo.tags[0].EngineDataProperty) + { + listPro.Add(new ec_enginedata_property() { - 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 - }); - } + 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 listPixel = new List(); @@ -831,7 +1361,7 @@ namespace SWS.Electrical.ViewModels { TagNumber = tagNumber, DrawingFileID = dwgId, - LibraryFileID = dwgLibrary == null ? "" : dwgLibrary.LibraryFileID, + LibraryFileID = blockDwgId,// == null ? "" : dwgLibrary.LibraryFileID PixelCode = handlid, ObjectTypeID = objTypeId, ObjectTypeName = objTypeName, @@ -839,25 +1369,13 @@ namespace SWS.Electrical.ViewModels }; 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 ""; - } + basePoint.TagPixelOnDwg = handlid; + listUpdateEnginedata.Add(item); + return ""; } else { msg = $"元件:{blockDwg} ,添加失败"; - AddMsg(msg, false); return msg; } #endregion @@ -891,11 +1409,14 @@ namespace SWS.Electrical.ViewModels foreach (var item in listBasePoint) { item.IsSelected = IsSelectAll; - } - + } } + + string message = string.Empty; + bool isSuccess = false; + /// - /// 添加提示信息 + /// 添加 提示信息 /// /// 信息 /// 是否成功 @@ -903,15 +1424,23 @@ namespace SWS.Electrical.ViewModels { 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); + System.Windows.Application.Current.Dispatcher.Invoke((System.Action)(() => + { + TextBlock tb = new TextBlock(); + tb.Text = DateTime.Now.ToString("yyyy-MM-6dd HH:mm:ss:ffff") + "==>> " + msg; + tb.Foreground = isSucc ? Brushes.LightSeaGreen : Brushes.Red; + listMsg.Add(tb); + })); + //Task.Delay(100); } catch (Exception ex) { MessageBox.Show("添加提示信息异常:" + ex.Message); } } + private void onReceviceMsg(MessageModel model) + { + AddMsg(model.Message, model.IsSuccess); + } } } diff --git a/newFront/c#前端/SWS.Electrical/ViewModels/DialogGenerateBOMViewModel.cs b/newFront/c#前端/SWS.Electrical/ViewModels/DialogGenerateBOMViewModel.cs index b5469d1b..2b88fee9 100644 --- a/newFront/c#前端/SWS.Electrical/ViewModels/DialogGenerateBOMViewModel.cs +++ b/newFront/c#前端/SWS.Electrical/ViewModels/DialogGenerateBOMViewModel.cs @@ -420,7 +420,7 @@ namespace SWS.Electrical.ViewModels if (dwg.AutoGenerate == "已存在") { AddMsg($"当前图纸[{dwg.DrawingFileName}]的材料表已存在,跳至下一个图纸"); - //continue; + continue; } if (dwg.AutoGenerate == "无材料信息") { @@ -433,7 +433,7 @@ namespace SWS.Electrical.ViewModels { AddMsg($"当前图纸[{dwg.DrawingFileName}]的材料表已存在,跳至下一个图纸", false); dwg.AutoGenerate = "已存在"; - //continue; + continue; } var listBomGroup = await _ServicePlotBOM.GetBOMGroupInfo(dwg.DrawingFileID); diff --git a/newFront/c#前端/SWS.Electrical/Views/DialogAutoArrangeLayout.xaml b/newFront/c#前端/SWS.Electrical/Views/DialogAutoArrangeLayout.xaml index 494936aa..91d91195 100644 --- a/newFront/c#前端/SWS.Electrical/Views/DialogAutoArrangeLayout.xaml +++ b/newFront/c#前端/SWS.Electrical/Views/DialogAutoArrangeLayout.xaml @@ -217,7 +217,7 @@ Orientation="Horizontal">