diff --git a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/PlantComponentGeometryReader.cs b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/PlantComponentGeometryReader.cs index 71bd715..4636cda 100644 --- a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/PlantComponentGeometryReader.cs +++ b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/PlantComponentGeometryReader.cs @@ -24,19 +24,28 @@ internal sealed class PlantComponentGeometryReader(Database database) : IPlantCo var parameters = new Dictionary(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(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 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 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); + } }