458 lines
13 KiB
C#
458 lines
13 KiB
C#
using Autodesk.Revit.DB;
|
||
using KDCS.Utils;
|
||
using System;
|
||
|
||
|
||
namespace KMBIM.Revit.Tools.Cmd.Hanger
|
||
{
|
||
class HangerFamily
|
||
{
|
||
|
||
private Level AnchorLevel;
|
||
private View3DHanger View3DHanger;
|
||
|
||
|
||
private Autodesk.Revit.DB.XYZ Location;
|
||
|
||
|
||
private double Diameter;
|
||
|
||
|
||
private double Width;
|
||
|
||
|
||
private double Height;
|
||
|
||
|
||
private double LocationElevation;
|
||
|
||
|
||
private double AnchorElevation;
|
||
|
||
|
||
private double IntersectionParameter;
|
||
|
||
|
||
private double AngleOnPlane;
|
||
|
||
|
||
private Autodesk.Revit.DB.Element _MEPCurve;
|
||
|
||
|
||
private Line _Line;
|
||
|
||
|
||
private Autodesk.Revit.DB.Level _Level;
|
||
|
||
|
||
private KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType _KMBIMMEPCurveType;
|
||
|
||
|
||
private bool _IsSupport;
|
||
|
||
private Autodesk.Revit.DB.FamilySymbol _FamilySymbol;
|
||
|
||
|
||
public View3DHanger GetView3DHanger()
|
||
{
|
||
return View3DHanger;
|
||
}
|
||
|
||
|
||
public void SetView3dHanger(View3DHanger view3DHanger)
|
||
{
|
||
View3DHanger = view3DHanger;
|
||
if (View3DHanger != null)
|
||
{
|
||
if (AnchorLevel != null) View3DHanger.SetAncholLevel(AnchorLevel);
|
||
}
|
||
}
|
||
|
||
|
||
public Autodesk.Revit.DB.XYZ GetLocation()
|
||
{
|
||
return Location;
|
||
}
|
||
|
||
|
||
public void SetLocation(Autodesk.Revit.DB.XYZ pt)
|
||
{
|
||
Location = pt;
|
||
}
|
||
|
||
|
||
public double getDiameter()
|
||
{
|
||
return Diameter;
|
||
}
|
||
|
||
|
||
public void setDiameter(double d)
|
||
{
|
||
Diameter = d;
|
||
}
|
||
|
||
|
||
public double getWidth()
|
||
{
|
||
return Width;
|
||
}
|
||
|
||
|
||
public void setWidth(double w)
|
||
{
|
||
Width = w;
|
||
}
|
||
|
||
|
||
public double getHeight()
|
||
{
|
||
return Height;
|
||
}
|
||
|
||
|
||
public void setHeight(double h)
|
||
{
|
||
Height = h;
|
||
}
|
||
|
||
|
||
public double getLocationElevation()
|
||
{
|
||
return LocationElevation;
|
||
}
|
||
|
||
|
||
public void setLocationElevation(double locationElevation)
|
||
{
|
||
LocationElevation = locationElevation;
|
||
}
|
||
|
||
|
||
public double getAnchorElevation()
|
||
{
|
||
return AnchorElevation;
|
||
}
|
||
|
||
|
||
public void setAnchorElevation(double anchorElevation)
|
||
{
|
||
AnchorElevation = anchorElevation;
|
||
}
|
||
|
||
|
||
public double getIntersectionParameter()
|
||
{
|
||
return IntersectionParameter;
|
||
}
|
||
|
||
|
||
public void setIntersectionParameter(double parm)
|
||
{
|
||
IntersectionParameter = parm;
|
||
}
|
||
|
||
|
||
public double getAngleOnPlane()
|
||
{
|
||
return AngleOnPlane;
|
||
}
|
||
|
||
|
||
public void setAngleOnPlane(double angleOnPlane)
|
||
{
|
||
AngleOnPlane = angleOnPlane;
|
||
}
|
||
|
||
|
||
public Autodesk.Revit.DB.Element GetElement()
|
||
{
|
||
return _MEPCurve;
|
||
}
|
||
|
||
|
||
public void SetElement(Autodesk.Revit.DB.Element element)
|
||
{
|
||
_MEPCurve = element;
|
||
}
|
||
|
||
|
||
public Line GetLine()
|
||
{
|
||
return _Line;
|
||
}
|
||
|
||
|
||
public void SetLine(Line line)
|
||
{
|
||
_Line = line;
|
||
}
|
||
|
||
|
||
public Autodesk.Revit.DB.Level GetLevel()
|
||
{
|
||
return _Level;
|
||
}
|
||
|
||
|
||
public void SetLevel(Autodesk.Revit.DB.Level level)
|
||
{
|
||
_Level = level;
|
||
}
|
||
|
||
|
||
public KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType GetKMBIMMEPCurveType()
|
||
{
|
||
return _KMBIMMEPCurveType;
|
||
}
|
||
|
||
|
||
public void SetKMBIMMEPCurveType(KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType curveType)
|
||
{
|
||
_KMBIMMEPCurveType = curveType;
|
||
}
|
||
|
||
|
||
public bool IsSupport()
|
||
{
|
||
return _IsSupport;
|
||
}
|
||
|
||
|
||
public void SetSupport(bool val)
|
||
{
|
||
_IsSupport = val;
|
||
}
|
||
|
||
public Autodesk.Revit.DB.FamilySymbol GetFamilySymbol()
|
||
{
|
||
return _FamilySymbol;
|
||
}
|
||
|
||
public void SetFamilySymbol(Autodesk.Revit.DB.FamilySymbol fs)
|
||
{
|
||
_FamilySymbol = fs;
|
||
SetSupport(false);
|
||
if (_FamilySymbol != null)
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter = Util.GetParameter(fs, "isSupport");
|
||
if (parameter != null)
|
||
{
|
||
SetSupport(parameter.AsInteger() != 0);
|
||
}
|
||
}
|
||
}
|
||
|
||
public HangerFamily(Level anchorLevel)
|
||
{
|
||
AnchorLevel = anchorLevel;
|
||
SetView3dHanger((View3DHanger)null);
|
||
SetLocation((Autodesk.Revit.DB.XYZ)null);
|
||
setDiameter(0.0);
|
||
setWidth(0.0);
|
||
setHeight(0.0);
|
||
setLocationElevation(0.0);
|
||
setAnchorElevation(double.NaN);
|
||
setIntersectionParameter(0.0);
|
||
setAngleOnPlane(0.0);
|
||
SetFamilySymbol((Autodesk.Revit.DB.FamilySymbol)null);
|
||
SetElement((Autodesk.Revit.DB.Element)null);
|
||
SetLine((Line)null);
|
||
SetLevel((Autodesk.Revit.DB.Level)null);
|
||
SetKMBIMMEPCurveType(KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe);
|
||
}
|
||
|
||
public bool af()
|
||
{
|
||
if (GetLocation() == null || GetFamilySymbol() == null || GetElement() == null || GetLine() == null || GetLevel() == null)
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="element">Ŀ<><C4BF></param>
|
||
/// <param name="hangerSettings"><3E><><EFBFBD><EFBFBD></param>
|
||
/// <returns></returns>
|
||
public bool getSize(Autodesk.Revit.DB.Element element, HangerSettings hangerSettings)
|
||
{
|
||
SetElement(element);
|
||
if (GetElement() == null)
|
||
{
|
||
return false;
|
||
}
|
||
MEPCurve mEPCurve = element as MEPCurve;
|
||
if (mEPCurve == null)
|
||
{
|
||
return false;
|
||
}
|
||
SetKMBIMMEPCurveType(HangerSchema.GetMEPCurveType(mEPCurve));
|
||
SetLine(HangerSchema.GetLine(element));
|
||
if (GetLine() == null)
|
||
{
|
||
return false;
|
||
}
|
||
if (GetLine().Direction.CrossProduct(new Autodesk.Revit.DB.XYZ(0.0, 0.0, 1.0)).IsZeroLength())
|
||
{
|
||
return false;
|
||
}
|
||
Autodesk.Revit.DB.XYZ right = new Autodesk.Revit.DB.XYZ(1.0, 0.0, 0.0);
|
||
Autodesk.Revit.DB.XYZ source = new Autodesk.Revit.DB.XYZ(GetLine().Direction.X, GetLine().Direction.Y, 0.0);
|
||
if (GetLine().Direction.AngleTo(source) > Math.PI / 9.0)
|
||
{
|
||
return false;
|
||
}
|
||
Autodesk.Revit.DB.XYZ xYZ = new Autodesk.Revit.DB.XYZ(GetLine().Direction.X, GetLine().Direction.Y, 0.0);
|
||
setAngleOnPlane(xYZ.AngleOnPlaneTo(right, new Autodesk.Revit.DB.XYZ(0.0, 0.0, -1.0)) + Math.PI / 2.0);
|
||
if (Util.LT_ET(getAngleOnPlane(), Math.PI * 2.0))
|
||
{
|
||
setAngleOnPlane(getAngleOnPlane() - Math.PI * 2.0);
|
||
}
|
||
switch (GetKMBIMMEPCurveType())
|
||
{
|
||
|
||
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RoundDuct:
|
||
setDiameter(GetDuctDiameter(mEPCurve, hangerSettings));
|
||
break;
|
||
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RectDuct:
|
||
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.OvalDuct:
|
||
setWidth(GetDuctWidth(mEPCurve, hangerSettings));
|
||
setHeight(GetDuctHeight(mEPCurve, hangerSettings));
|
||
break;
|
||
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe:
|
||
setDiameter(GetPipeOuterDiameter(element, hangerSettings));
|
||
break;
|
||
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.CableTray:
|
||
setWidth(mEPCurve.Width);
|
||
setHeight(mEPCurve.Height);
|
||
break;
|
||
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Conduit:
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter = element.get_Parameter(BuiltInParameter.RBS_CONDUIT_OUTER_DIAM_PARAM);
|
||
if (parameter == null)
|
||
{
|
||
return false;
|
||
}
|
||
setDiameter(parameter.AsDouble());
|
||
break;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public void q(Autodesk.Revit.DB.FamilyInstance A_0)
|
||
{
|
||
if (GetElement() == null || A_0 == null)
|
||
{
|
||
return;
|
||
}
|
||
Autodesk.Revit.DB.Parameter parameter = GetElement().get_Parameter(BuiltInParameter.RBS_SYSTEM_NAME_PARAM);
|
||
if (parameter == null || parameter.StorageType != StorageType.String)
|
||
{
|
||
return;
|
||
}
|
||
string value = parameter.AsString();
|
||
if (!string.IsNullOrEmpty(value))
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter2 = ((Autodesk.Revit.DB.Element)A_0).get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
|
||
if (parameter2 != null && parameter2.StorageType == StorageType.String)
|
||
{
|
||
parameter2.Set(value);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public static double GetPipeOuterDiameter(Autodesk.Revit.DB.Element A_0, HangerSettings hangerSettings)
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter = A_0.get_Parameter(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER);
|
||
if (parameter == null)
|
||
{
|
||
return 0.0;
|
||
}
|
||
double num = parameter.AsDouble();
|
||
if (hangerSettings.PipeInsulation) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
{
|
||
parameter = A_0.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS);
|
||
if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.Double)
|
||
{
|
||
num += parameter.AsDouble() * 2.0;
|
||
}
|
||
}
|
||
return num;
|
||
}
|
||
|
||
public static double GetDuctDiameter(MEPCurve A_0, HangerSettings hangerSettings)
|
||
{
|
||
double num = A_0.Diameter;
|
||
if (hangerSettings.DuctInsulation)
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter = ((Autodesk.Revit.DB.Element)A_0).get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS);
|
||
if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.Double)
|
||
{
|
||
num += parameter.AsDouble() * 2.0;
|
||
}
|
||
}
|
||
return num;
|
||
}
|
||
|
||
public static double GetDuctWidth(MEPCurve A_0, HangerSettings hangerSettings)
|
||
{
|
||
double num = A_0.Width;
|
||
if (hangerSettings.DuctInsulation)
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter = ((Autodesk.Revit.DB.Element)A_0).get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS);
|
||
if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.Double)
|
||
{
|
||
num += parameter.AsDouble() * 2.0;
|
||
}
|
||
}
|
||
return num;
|
||
}
|
||
|
||
public static double GetDuctHeight(MEPCurve A_0, HangerSettings hangerSettings)
|
||
{
|
||
double num = A_0.Height;
|
||
if (hangerSettings.DuctInsulation)
|
||
{
|
||
Autodesk.Revit.DB.Parameter parameter = ((Autodesk.Revit.DB.Element)A_0).get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS);
|
||
if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.Double)
|
||
{
|
||
num += parameter.AsDouble() * 2.0;
|
||
}
|
||
}
|
||
return num;
|
||
}
|
||
|
||
public bool GetElevation(Autodesk.Revit.DB.XYZ A_0, EnumAnchorInstallBase anchorInstallBase)
|
||
{
|
||
if (GetLine() == null)
|
||
{
|
||
return false;
|
||
}
|
||
IntersectionResult intersectionResult = GetLine().Project(A_0);
|
||
if (intersectionResult == null)
|
||
{
|
||
return false;
|
||
}
|
||
SetLocation(intersectionResult.XYZPoint);
|
||
setIntersectionParameter(intersectionResult.Parameter);
|
||
double anchorElevation = 0.0;
|
||
double locationElevation = 0.0;
|
||
Level level;
|
||
View3DHanger view3dHanger = GetView3DHanger();
|
||
view3dHanger.GetAnchorElevation(GetLocation(), IsSupport(), anchorInstallBase, out level, out locationElevation, out anchorElevation);
|
||
if (level == null)
|
||
{
|
||
return false;
|
||
}
|
||
setAnchorElevation(anchorElevation);
|
||
setLocationElevation(locationElevation);
|
||
SetLevel(level);
|
||
return true;
|
||
}
|
||
}
|
||
} |