feat: expand p-rec-annot component geometry adapter
This commit is contained in:
@@ -24,19 +24,28 @@ internal sealed class PlantComponentGeometryReader(Database database) : IPlantCo
|
||||
var parameters = new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
["D"] = Format(pipe.OuterDiameter * factor),
|
||||
["L"] = Format(pipe.Length * factor)
|
||||
["L"] = Format(pipe.Length * factor),
|
||||
["StartX"] = Format(pipe.StartPoint.X), ["StartY"] = Format(pipe.StartPoint.Y), ["StartZ"] = Format(pipe.StartPoint.Z),
|
||||
["EndX"] = Format(pipe.EndPoint.X), ["EndY"] = Format(pipe.EndPoint.Y), ["EndZ"] = Format(pipe.EndPoint.Z)
|
||||
};
|
||||
AddDerivedGeometry(parameters, pipe.StartPoint, pipe.EndPoint);
|
||||
AddPorts(parameters, pipe.GetPorts(PortType.Both));
|
||||
return new(true, new("CPP", parameters, bounds, factor != 1));
|
||||
}
|
||||
if (entity is Part part)
|
||||
{
|
||||
var factor = Factor(convertToMetric, part.PartSizeProperties.LinearUnit);
|
||||
var center = extents.MinPoint + (extents.MaxPoint - extents.MinPoint) / 2d;
|
||||
var parameters = new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
["BoundsX"] = Format((extents.MaxPoint.X - extents.MinPoint.X) * factor),
|
||||
["BoundsY"] = Format((extents.MaxPoint.Y - extents.MinPoint.Y) * factor),
|
||||
["BoundsZ"] = Format((extents.MaxPoint.Z - extents.MinPoint.Z) * factor)
|
||||
["BoundsZ"] = Format((extents.MaxPoint.Z - extents.MinPoint.Z) * factor),
|
||||
["CenterX"] = Format(center.X), ["CenterY"] = Format(center.Y), ["CenterZ"] = Format(center.Z)
|
||||
};
|
||||
var ports = part.GetPorts(PortType.Both);
|
||||
AddPorts(parameters, ports);
|
||||
if (ports.Count >= 2) AddDerivedGeometry(parameters, ports[0].Position, ports[1].Position);
|
||||
return new(true, new("PART", parameters, bounds, factor != 1));
|
||||
}
|
||||
return new(false, null, "COMPONENT_GEOMETRY_UNSUPPORTED_ENTITY");
|
||||
@@ -57,4 +66,25 @@ internal sealed class PlantComponentGeometryReader(Database database) : IPlantCo
|
||||
|
||||
private static double Factor(bool convertToMetric, object? unit) => convertToMetric && string.Equals(unit?.ToString(), "Inch", StringComparison.OrdinalIgnoreCase) ? 25.4 : 1d;
|
||||
private static string Format(double value) => value.ToString("0.###############", System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
private static void AddPorts(Dictionary<string, string> parameters, PortCollection ports)
|
||||
{
|
||||
parameters["PortCount"] = ports.Count.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
for (var index = 0; index < ports.Count; index++)
|
||||
{
|
||||
var port = ports[index]; var prefix = "Port" + index;
|
||||
parameters[prefix + "Name"] = port.Name ?? string.Empty;
|
||||
parameters[prefix + "X"] = Format(port.Position.X); parameters[prefix + "Y"] = Format(port.Position.Y); parameters[prefix + "Z"] = Format(port.Position.Z);
|
||||
parameters[prefix + "DirectionX"] = Format(port.Direction.X); parameters[prefix + "DirectionY"] = Format(port.Direction.Y); parameters[prefix + "DirectionZ"] = Format(port.Direction.Z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddDerivedGeometry(Dictionary<string, string> parameters, Autodesk.AutoCAD.Geometry.Point3d start, Autodesk.AutoCAD.Geometry.Point3d end)
|
||||
{
|
||||
var axis = start.GetVectorTo(end); var center = start + axis / 2d;
|
||||
parameters["CenterX"] = Format(center.X); parameters["CenterY"] = Format(center.Y); parameters["CenterZ"] = Format(center.Z);
|
||||
if (axis.Length <= Autodesk.AutoCAD.Geometry.Tolerance.Global.EqualPoint) return;
|
||||
var direction = axis.GetNormal();
|
||||
parameters["AxisX"] = Format(direction.X); parameters["AxisY"] = Format(direction.Y); parameters["AxisZ"] = Format(direction.Z);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user