161 lines
4.5 KiB
C#
161 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Autodesk.Revit.DB;
|
|
using KDCS.Utils;
|
|
using KMBIM.Revit.Tools.Utils;
|
|
|
|
namespace KMBIM.Revit.Tools.Cmd.Hanger
|
|
{
|
|
public class InstallOption
|
|
{
|
|
|
|
public List<UnitInstallOption> Options { get; set; }
|
|
public string Name { get; set; }
|
|
public DisplayUnit DisUnit { get; set; }
|
|
public EnumAnchorInstallBase AnchorInstallBase { get; set; } // 앵커설치기준
|
|
private Level AnchorLevel;
|
|
|
|
|
|
|
|
public InstallOption()
|
|
{
|
|
AnchorLevel = null;
|
|
Name = "";
|
|
DisUnit = DisplayUnit.METRIC;
|
|
Options = new List<UnitInstallOption>();
|
|
AnchorInstallBase = EnumAnchorInstallBase.Structrual;
|
|
}
|
|
|
|
public InstallOption(string name, DisplayUnit disu)
|
|
{
|
|
AnchorLevel = null;
|
|
Name = name;
|
|
DisUnit = disu;
|
|
Options = new List<UnitInstallOption>();
|
|
AnchorInstallBase = EnumAnchorInstallBase.Structrual;
|
|
}
|
|
|
|
public void SetAnchorLevel(Level level){
|
|
AnchorLevel = level;
|
|
}
|
|
|
|
public Level GetAnchorLevel(){
|
|
return AnchorLevel;
|
|
}
|
|
public void addOption(UnitInstallOption rule)
|
|
{
|
|
Options.Add(rule);
|
|
Sort();
|
|
}
|
|
|
|
internal bool Remove(double size)
|
|
{
|
|
for (int i = 0; i < Options.Count; i++)
|
|
{
|
|
if (size == Options[i].Size)
|
|
{
|
|
Options.RemoveAt(i);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void Sort()
|
|
{
|
|
Options.Sort(funCompare);
|
|
}
|
|
|
|
private static int funCompare(UnitInstallOption sr1, UnitInstallOption sr2)
|
|
{
|
|
if (sr1 == null && sr2 == null)
|
|
{
|
|
return 0;
|
|
}
|
|
if (sr1 != null && sr2 == null)
|
|
{
|
|
return 1;
|
|
}
|
|
if (sr1 == null && sr2 != null)
|
|
{
|
|
return -1;
|
|
}
|
|
if (sr1.Size == sr2.Size)
|
|
{
|
|
return 0;
|
|
}
|
|
if (!(sr1.Size < sr2.Size))
|
|
{
|
|
return 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
public UnitInstallOption GetOption(MEPCurve curve)
|
|
{
|
|
if (curve == null)
|
|
{
|
|
return null;
|
|
}
|
|
Autodesk.Revit.DB.ConnectorProfileType connectorProfileType = Autodesk.Revit.DB.ConnectorProfileType.Invalid;
|
|
|
|
var enumerator = curve.ConnectorManager.Connectors.GetEnumerator();
|
|
try
|
|
{
|
|
if (enumerator.MoveNext())
|
|
{
|
|
connectorProfileType = ((Autodesk.Revit.DB.Connector)enumerator.Current).Shape;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
IDisposable disposable = enumerator as IDisposable;
|
|
if (disposable != null)
|
|
{
|
|
disposable.Dispose();
|
|
}
|
|
}
|
|
|
|
// 커넥터 프로파일 유형이 일치하지 않으면 null을 넘겨준다.
|
|
if (connectorProfileType == Autodesk.Revit.DB.ConnectorProfileType.Invalid)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
|
|
// MEP곡선의 크기(직경)를 가져온다.
|
|
double dia = AutomaticHangerPlacement.GetDiameter(curve);
|
|
// MEP곡선의 크기와 일치하는 행거 배치 옵션을 선택한다.
|
|
foreach (UnitInstallOption option in Options)
|
|
{
|
|
if (Util.GT_ET(dia, option.Size))
|
|
{
|
|
return option;
|
|
}
|
|
}
|
|
// 행거 옵션을 선택하지 못했기때문에 널을 넘겨준다.
|
|
return Options[0]; // 일단 기본값으로
|
|
//return null;
|
|
}
|
|
|
|
public Autodesk.Revit.DB.FamilySymbol GetFamilySymbol(MEPCurve curve)
|
|
{
|
|
UnitInstallOption option = GetOption(curve);
|
|
if (option == null)
|
|
{
|
|
return null;
|
|
}
|
|
Document document = curve.Document;
|
|
MEPCurveType a_ = HangerSchema.GetMEPCurveType(curve);
|
|
string fmailyname = option.FamilyFileName;
|
|
return HangerFamilySymbol.GetFamilysymbol(document, a_, fmailyname);
|
|
}
|
|
|
|
|
|
}
|
|
}
|