123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- /* ==============================================================================
- * 功能描述:Command
- * 创 建 者:Garrett
- * 创建日期:2018/3/27 11:42:20
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Windows;
- using Autodesk.Revit.Attributes;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.ExtensibleStorage;
- using Autodesk.Revit.DB.Mechanical;
- using Autodesk.Revit.UI;
- using CEFSharpWpf;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Logger;
- using SAGA.MBI.Calc;
- using SAGA.MBI.Common;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.Interaction;
- using SAGA.MBI.Login;
- using SAGA.MBI.Model;
- using SAGA.MBI.RequestData;
- using SAGA.MBI.Tools;
- using SAGA.MBI.WinView;
- using SAGA.MBI.WinView.BeModingDutyList;
- using SAGA.MBI.WinView.Login;
- using SAGA.MBI.WinView.ModeInfoMaintenance;
- using SAGA.MBI.WinView.PositionBeaconModeling;
- using SAGA.MBI.WinView.Space;
- using SAGA.MBI.WinView.Upload;
- using SAGA.Models;
- using SAGA.RevitUtils;
- using SAGA.RevitUtils.Extends;
- using SAGA.RevitUtils.Windows;
- using Application = Autodesk.Revit.Creation.Application;
- using Visibility = System.Windows.Visibility;
- namespace SAGA.MBI
- {
- /// <summary>
- /// 打开楼层模型
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class OpenModeFileCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- WinOpenFile win = new WinOpenFile();
- win.ShowWindow();
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 模型文件管理
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class EditModeFileCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- Log4Net.Debug("开始命令:模型文件管理");
- if (DalUploadFloor.IsAllFloorClosed())
- {
- WinModeFileManage win = new WinModeFileManage();
- win.ShowDialog();
- }
- Log4Net.Debug("结束命令:模型文件管理");
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 申请模型权限
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class LockFloorCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var doc = ExternalDataWrapper.Current.Doc;
- if (doc == null) return Result.Cancelled;
- string floorId = doc.PathName.GetFileName();
- DalLock.LockFloor(floorId, true);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 模型信息点值维护
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class EditModeInfoCommand : ExternalCommand//, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- WinModeInfoMaintenance win = WinModeInfoMaintenance.GetWindow();
- if (win.Visibility != Visibility.Visible)
- {
- win.Show();
- IdlingEditInstance.RefrushInstance();
- ExternalDataWrapper.Current.UiApp.Idling += IdlingEditInstance.EditInstance_Idling;
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- ExternalDataWrapper.Current.UiApp.Idling -= IdlingEditInstance.EditInstance_Idling;
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 待建模型清单
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class BeModeDutyListCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- Log4Net.Debug("开始命令:待建模型清单");
- var doc = ExternalDataWrapper.Current.Doc;
- if (doc == null) return Result.Cancelled;
- VMBeModeDutyList vm = new VMBeModeDutyList();
- WinBeModeDutyList win = new WinBeModeDutyList();
- win.DataContext = vm;
- win.Show();
- Log4Net.Debug("结束命令:待建模型清单");
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 未实体化模型清单
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class ShowMissFMListCommand : ExternalCommand//, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- Log4Net.Debug("开始命令:未实体化模型清单");
- var doc = ExternalDataWrapper.Current.Doc;
- if (doc == null) return Result.Cancelled;
- string floorId = doc.PathName.GetFileName();
- WinMissFMList win = new WinMissFMList(floorId);
- win.Show();
- Log4Net.Debug("结束命令:未实体化模型清单");
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 高亮显示空模型
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class HeightLightMissFMListCommand : ExternalCommand//, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var doc = ExternalDataWrapper.Current.Doc;
- if (doc == null) return Result.Cancelled;
- string floorId = doc.PathName.GetFileName();
- WinMissFMList win = new WinMissFMList(floorId);
- List<Element> ids = win.MissFMEquips.Select(t => doc.GetElement(t.Equipment.BimID.GetBIMID())).Where(tt => tt != null).ToList();
- ExternalDataWrapper.Current.UiApp.SetShowElements(ids);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 位置信标建模
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class PositionBeaconModelingCommand : ExternalCommand//, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var doc = ExternalDataWrapper.Current.Doc;
- if (doc == null) return Result.Cancelled;
- string floorId = doc.PathName.GetFileName();
- WinBeacon win = new WinBeacon(floorId);
- win.Show();
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 上传模型
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class UploadModeCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- if (DalUploadFloor.IsAllFloorClosed())
- {
- if (DalUploadFloor.IsNeedUpdataFile())
- return Result.Succeeded;
- VMUploadModeManage vm = DalUploadFloor.PrepareUploadFloors();
- if (vm != null)
- {
- WinUploadModeManage win = new WinUploadModeManage();
- win.DataContext = vm;
- win.ShowDialog();
- }
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 空间管理
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CreateSpaceCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var win = new WinCreateSpaces();
- win.Show();
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 同步模型本地名称
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class SyncLocalNameCommand : ExternalCommand//, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- WaitingView wait = new WaitingView();
- wait.Start();
- var floors = DalUploadFloor.GetHasFileFloors();
- List<CalcContext> contexts = new List<CalcContext>();
- foreach (UploadFloor floor in floors)
- {
- if (floor.MFloor.FloorLock.LockState != MFloorLockState.LockBySelf)
- {
- continue;
- }
- contexts.Add(new CalcContext(floor.MFloor));
- }
- MBIModelInfoManager.SyncPlatformToRevit(contexts);
- wait.Close();
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- }
|