/* ============================================================================== * 功能描述:ToolCommand * 创 建 者:Garrett * 创建日期:2018/7/11 14:25:22 * ==============================================================================*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using DevExpress.Xpf.Core; using FWindSoft.DataFramework; using SAGA.DotNetUtils; using SAGA.DotNetUtils.Logger; using SAGA.DotNetUtils.Others; using SAGA.MBI.Common; using SAGA.MBI.DataArrange; using SAGA.MBI.Model; using SAGA.MBI.Tools; using SAGA.MBI.ToolsData; using SAGA.MBI.ToolsData.CheckBase; using SAGA.MBI.ToolsData.DataCheck; using SAGA.MBI.ToolsData.ModeCheck; using SAGA.MBI.WinView.Login; using SAGA.RevitUtils; using SAGA.RevitUtils.Extends; using SAGA.RevitUtils.MEP; using Line = Autodesk.Revit.DB.Line; using WinModeCheckSetting = SAGA.MBI.ToolsData.ModeCheck.WinModeCheckSetting; namespace SAGA.MBI { #region 工具 /// /// 隔离立管 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class VerticalPipeIsolationCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var elems = ExternalDataWrapper.Current.UiApp.WindowSelectElement("请框选...",new CommonFilter(t => { if (t is Pipe pipe) { var line = pipe.GetCurve() as Line; if (line != null) { var connectors = pipe.GetConnectors(); return connectors.Any(tt=>!tt.IsConnected)&&line.Direction.IsParallel(XYZ.BasisZ); } } return false; })); ExternalDataWrapper.Current.UiApp.SetShowElements(elems,true); } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 立管对齐 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class VerticalPipeAlginCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { int count = 0; WinSelectCheckFloors win =new WinSelectCheckFloors(); if (win.ShowDialog() == true) { VerticalPipeAlign.Instance.Execute(); VerticalPipeAlign.Instance.ShowResult(); } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 批量删除无用的空间 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class DeleteZeroSpaceCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { int count = 0; var tip = MessageShowBase.Question2("确定要删除所有楼层周长为零的空间?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。"); switch (tip) { case DialogResult.Yes: count=DelZeroSpace.OperateAll(); break; case DialogResult.No: count=DelZeroSpace.OperateCurFloor(); break; default: break; } if(tip== DialogResult.Yes||tip== DialogResult.No) MessageShowBase.Infomation($"此次操作共删除{count}个空间"); } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 导出类别 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExportCategoriesCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question("确定要导出所有的族类别?"); if (tip) BllFactory.Instance.Operate(); } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 报告设备所在空间 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ReportEquipInSpaceCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance; var space = fi.GetReferenceSpace(); MessageShowBase.Infomation($"设备所在空间Id为{space?.Id}"); } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } } /// /// 导出所有的岗位 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExportAllDutyCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShowBase.Question2("确定要导出所有岗位?\r\n是:全部楼层\r\n否:当前楼层\r\n取消:取消。"); switch (tip) { case DialogResult.Yes: ExportAllDuty.OperateAll(); break; case DialogResult.No: ExportAllDuty.OperateCurFloor(); break; default: break; } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } #endregion #region 数据修正 /// /// 修正云平台族类型和本地族类型不一致 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class CheckCloudAndLocalFamilyCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question2("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。"); switch (tip) { case DialogResult.Yes: CheckEquipCategory.OperateAll(); break; case DialogResult.No: CheckEquipCategory.OperateCurFloor(); break; default: break; } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 更新所有楼层设备的坐标信息 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class AddEquipLocationCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question2("确定要更新所有楼层设备的坐标信息?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。"); switch (tip) { case DialogResult.Yes: AddEquipLocation.OperateAll(); break; case DialogResult.No: AddEquipLocation.OperateCurFloor(); break; default: break; } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 检查设备所在楼层关系 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class CheckEquipinFloorCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question("确定要执行所有楼层设备所在楼层关系检查?"); if (tip) UpdateRelationEquipinFloor.OperateAll(); ; } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 更新设备所在空间关系 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class UpdateEquipinSpaceCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question2("确定要更新设备所在空间关系?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。"); switch (tip) { case DialogResult.Yes: UpdateRelationEquipinSpace.OperateAll(); break; case DialogResult.No: UpdateRelationEquipinSpace.OperateCurFloor(); break; default: break; } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 模型规范检查 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ModeSpecificationCheckCommand : ExternalCommand, IExternalCommandAvailability { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var checkType = CheckType.ModeCheck; var checkItems = CheckOperation.GetCheckItems(checkType); WinModeCheckSetting win = new WinModeCheckSetting(checkItems, checkType); if (win.ShowDialog() != true) return Result.Cancelled; CheckOperation.Execute(checkItems, win.GetCheckContext()); } catch (Exception e) { CheckProgressBarClient.Stop(); MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 垃圾数据检查 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class JunkDataCheckCommand : ExternalCommand, IExternalCommandAvailability { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var checkType = CheckType.DataCheck; var checkItems = CheckOperation.GetCheckItems(checkType); WinDataCheckSetting win = new WinDataCheckSetting(checkItems, CheckType.DataCheck); if (win.ShowDialog() != true) return Result.Cancelled; CheckOperation.Execute(checkItems, win.GetCheckContext()); } catch (Exception e) { CheckProgressBarClient.Stop(); MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 修正岗位缺失 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class CorrectLossDutyCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question2("是否开始修正岗位缺失问题?\r\n本功能会删除找不到对应模型的岗位和重新创建有模型没有岗位的数据。\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。"); switch (tip) { case DialogResult.Yes: CorrectLossDuty.OperateAll(); break; case DialogResult.No: CorrectLossDuty.OperateCurFloor(); break; default: break; } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } /// /// 是否开始修正BIMID重复问题 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class CorrectBIMIDDutyCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var tip = MessageShow.Question("是否开始修正BIMID重复问题?\r\n本功能将会保留信息点最全的岗位,删除其它岗位\r\n是:开始修正全部建筑\r\n取消:取消修正。"); if (tip) { CheckDuplicationBIMId.CorrectAll(); MessageBox.Show("修正成功"); } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } #endregion /// /// 增加缺失元空间 /// [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class AddSiSpaceCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { List errorIds = new List(); List totalIds = new List(); try { var tip = MessageShow.Question("确认增加缺失元空间信息"); if (tip) { MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor(); if (floor != null) { var context = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor); context.OpenDocument(); var doc = context.RevitDoc; var revitSpaces = doc.GetSpaces(); var platSpaces = context.MSpaces; foreach (var space in revitSpaces) { if (!space.IsSpace()) { continue; } var spaceid = space.GetCloudBIMId(); var mspace = platSpaces.FirstOrDefault(t => t.BimID == spaceid); if (mspace == null) { totalIds.Add(space.Id.ToString()); mspace = DalSpace.GetSpace(space); mspace.Operator = DocumentChangedOperator.Add; if (!mspace.AddObject()) { errorIds.Add(space.Id.ToString()); } } } } MessageBox.Show("总共修改:"+totalIds.Count); if (errorIds.Any()) ; { MessageBox.Show("错误Ids:" + string.Join(";",errorIds)); } } } catch (Exception e) { MessageShow.Show(e); return Result.Cancelled; } return Result.Succeeded; } /// /// Onlys show the dialog when a document is open, as Dockable dialogs are only available /// when a document is open. /// public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; } } }