|
@@ -0,0 +1,193 @@
|
|
|
+/*-------------------------------------------------------------------------
|
|
|
+ * 功能描述:SpaceManager
|
|
|
+ * 作者:xulisong
|
|
|
+ * 创建时间: 2018/12/14 10:11:22
|
|
|
+ * 版本号:v1.0
|
|
|
+ * -------------------------------------------------------------------------*/
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Autodesk.Revit.DB;
|
|
|
+using SAGA.MBI.Common;
|
|
|
+using SAGA.MBI.Model;
|
|
|
+using SAGA.RevitUtils;
|
|
|
+using SAGA.RevitUtils.Extends;
|
|
|
+
|
|
|
+namespace SAGA.MBI.WinView.Space
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 元空间管理相关模操作
|
|
|
+ /// </summary>
|
|
|
+ public class SpaceManager
|
|
|
+ {
|
|
|
+ #region 物理世界空间管理
|
|
|
+ public static List<MSpace> GetPhysicalSpaces(List<string> bimIds)
|
|
|
+ {
|
|
|
+ List<MSpace> spaces = new List<MSpace>();
|
|
|
+
|
|
|
+
|
|
|
+ return spaces;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新项目中的空间分割
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="doc"></param>
|
|
|
+ /// <param name="separations"></param>
|
|
|
+ /// <param name="deletedIds"></param>
|
|
|
+ public static void UpdateSpaceSequarate(Document doc,List<SpaceSeparation> separations,List<int> deletedIds)
|
|
|
+ {
|
|
|
+ using (Transaction trans = new Transaction(doc, "更新空间分隔符"))
|
|
|
+ {
|
|
|
+ trans.Start();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FailureHandlingOptions fho = trans.GetFailureHandlingOptions();
|
|
|
+ //警告不提示,但不捕获冲突空间
|
|
|
+ fho.SetFailuresPreprocessor(new SpaceFailuresPreprocessor());
|
|
|
+ trans.SetFailureHandlingOptions(fho);
|
|
|
+ //读取空间所在视图
|
|
|
+ var view = doc.GetUseView();
|
|
|
+ if (view == null)
|
|
|
+ {
|
|
|
+ MessageShow.Infomation("无法找到-saga标志的视图");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //创建空间分隔符
|
|
|
+ CreateSpaceSeparation(view, separations);
|
|
|
+ doc.Delete(deletedIds.Select(id => new ElementId(id)).ToList());
|
|
|
+ trans.Commit();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ trans.RollBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 创建空间分隔符
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="view"></param>
|
|
|
+ /// <param name="separations"></param>
|
|
|
+ public static void CreateSpaceSeparation(ViewPlan view, List<SpaceSeparation> separations)
|
|
|
+ {
|
|
|
+ if (view == null)
|
|
|
+ return;
|
|
|
+ double z = view.GenLevel.Elevation;
|
|
|
+ Document doc = view.Document;
|
|
|
+ Plane p =Plane.CreateByNormalAndOrigin(view.ViewDirection,XYZ.Zero);
|
|
|
+ var sp = SketchPlane.Create(doc, p);
|
|
|
+ foreach (var pair in separations)
|
|
|
+ {
|
|
|
+ XYZ start = pair.Start.NewZ(z);
|
|
|
+ XYZ end = pair.End.NewZ(z);
|
|
|
+ Line line = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ line = start.NewLine(end);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine(e.StackTrace);
|
|
|
+ }
|
|
|
+ if (line != null)
|
|
|
+ {
|
|
|
+ var curveArray = new CurveArray();
|
|
|
+ curveArray.Append(line);
|
|
|
+ var newLIneId = doc.Create.NewSpaceBoundaryLines(sp, curveArray, view).get_Item(0).Id;
|
|
|
+ pair.Id = newLIneId.IntegerValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 手动创建空间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="doc"></param>
|
|
|
+ public static void CreateSpace(Document doc)
|
|
|
+ {
|
|
|
+ using (Transaction trans = new Transaction(doc, "创建空间"))
|
|
|
+ {
|
|
|
+ {
|
|
|
+ trans.Start();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ doc.LoadFamilySymbolExt(MBIConst.SpaceTagFamilyFilePath);
|
|
|
+ FailureHandlingOptions fho = trans.GetFailureHandlingOptions();
|
|
|
+ fho.SetFailuresPreprocessor(new FailuresPreprocessor());
|
|
|
+ trans.SetFailureHandlingOptions(fho);
|
|
|
+ var view = doc.GetUseView();
|
|
|
+ if (view != null)
|
|
|
+ {
|
|
|
+ Parameter para = view.GetParameter(BuiltInParameter.VIEW_PHASE);
|
|
|
+ ElementId phaseId = para.AsElementId();
|
|
|
+
|
|
|
+ var phase = doc.GetElement(phaseId) as Phase;
|
|
|
+ var level = view.GenLevel;
|
|
|
+ //如果视图范围不对,也不能很好的创建空间
|
|
|
+
|
|
|
+ ICollection<ElementId> elements = doc.Create.NewSpaces2(level, phase, view);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageShow.Infomation("没有找到名称以-saga结尾的平面");
|
|
|
+ }
|
|
|
+ //doc.Regenerate();
|
|
|
+ trans.Commit();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ trans.RollBack();
|
|
|
+ MessageShow.Show(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 处理冲突信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="doc"></param>
|
|
|
+ /// <param name="failItem"></param>
|
|
|
+ public static void DealSpaceFailuresPreprocessor(Document doc, List<FailItem> failItem)
|
|
|
+ {
|
|
|
+ //处理错误空间,会出现手动交互的情况
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 上传模型
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="doc"></param>
|
|
|
+ public void UploadModel(Document doc)
|
|
|
+ {
|
|
|
+ doc.Save();
|
|
|
+ string str = "";
|
|
|
+ UploadModeCommand command = new UploadModeCommand();
|
|
|
+ command.Execute(null, ref str, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 空间分割信息
|
|
|
+ /// </summary>
|
|
|
+ public class SpaceSeparation
|
|
|
+ {
|
|
|
+ public SpaceSeparation(XYZ start, XYZ end)
|
|
|
+ {
|
|
|
+ this.Start = start;
|
|
|
+ this.End = end;
|
|
|
+ }
|
|
|
+
|
|
|
+ public XYZ Start { get; private set; }
|
|
|
+ public XYZ End { get; private set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 关联Id
|
|
|
+ /// </summary>
|
|
|
+ public int Id { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|