在对图纸图元进行解析的过程中,发现有时候图纸中包含UCS坐标系,对于未旋转的UCS坐标系,按世界坐标系对图元进行解析没有太大影响。但对于旋转的UCS坐标系,发现用世界坐标系反应图元的几何数据,会产生一定的影响(包围盒)。
在实际应用中,一开始获取的Editor类的 CurrentUserCoordinateSystem 属性。跑了一些图纸又发现有些图纸模型空间有选择,但是CurrentUserCoordinateSystem 是一个标准矩阵。后面又采用Editor 类获取当前视图,再获取视图的UCS坐标矩阵。为考虑兼容问题在前期算法中采用了两个矩阵坐标相乘。
但在跑图纸的过程中,发现CurrentUserCoordinateSystem与view.Ucs 都可能是非标准矩阵即两者皆有值并且相同(暂时还未找到不同的情况)。所以最后只能取其一。
Matrix3d parentMatrix = Matrix3d.Identity;
parentMatrix = _doc.Editor.CurrentUserCoordinateSystem;
if(parentMatrix == Matrix3d.Identity)
{
var view = _doc.Editor.GetCurrentView();
var ucs = view.Ucs;
if (ucs != null)
{
parentMatrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, ucs.Origin, ucs.Xaxis, ucs.Yaxis, ucs.Zaxis);
}
}
//计算世界坐标在ucs中的位置关系,所以取逆矩阵
parentMatrix = parentMatrix.Inverse();