/* ==============================================================================
* 功能描述: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
{
///
/// 打开楼层模型
///
[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;
}
///
/// 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 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;
}
///
/// 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 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;
}
///
/// 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 false;
}
}
///
/// 模型信息点值维护
///
[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;
}
///
/// 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 false;
}
}
///
/// 待建模型清单
///
[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;
}
///
/// 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 false;
}
}
///
/// 未实体化模型清单
///
[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;
}
///
/// 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 false;
}
}
///
/// 高亮显示空模型
///
[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 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;
}
///
/// 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 false;
}
}
///
/// 位置信标建模
///
[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;
}
///
/// 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 false;
}
}
///
/// 上传模型
///
[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;
}
///
/// 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 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;
}
}
///
/// 同步模型本地名称
///
[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 contexts = new List();
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;
}
}
}