using Autodesk.Revit.DB;
using FWindSoft.SystemExtensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FWindSoft.Revit.Mep
{
///
/// 旋转策略
///
public class RotationStrategy:List
{
public RotationStrategy()
{ }
public RotationStrategy(XYZ location, XYZ axis, double angle)
{
this.Add(new RotationItem(location,axis, angle));
}
public RotationStrategy(List rotationItems):base(rotationItems)
{
}
///
/// 向旋转策略中,增加旋转项
///
///
///
public void Add(XYZ location, XYZ axis, double angle)
{
this.Add(new RotationItem(location,axis, angle));
}
///
/// 旋转指定实例
///
///
public void Rotate(FamilyInstance familyInstance)
{
this.ForEach(ri => ri.Rotate(familyInstance));
}
}
///
/// 旋转数据
///
public class RotationItem
{
public RotationItem(XYZ location,XYZ axis,double angle)
{
Location = location;
Axis = axis;
Angle = angle;
}
///
/// 旋转中心
///
public XYZ Location { get; set; }
///
/// 旋转轴
///
public XYZ Axis { get; set; }
///
/// 旋转角度
///
public double Angle { get; set; }
///
/// 旋转指定familyInstance
///
///
public void Rotate(FamilyInstance familyInstance)
{
if(Angle.IsEqual(0))
{//暂时粗糙判断,不考虑2π周期性的东西
return;
}
var line = Line.CreateUnbound(Location, Axis);
ElementTransformUtils.RotateElement(familyInstance.Document, familyInstance.Id, line, Angle);
}
}
}