Example #1
0
        /// <summary>
        /// Construct a DXFReader given a stream reader representing teh DXF file content and the units to use
        /// </summary>
        /// <param name="dxfFile"></param>
        /// <param name="units"></param>
        public DXFReader(MemoryStream dxfFile, DxfUnitsType units)
        {
            DXFFileIsBinary = IsBinaryDXF(dxfFile, out _dXFFileIsPostR13c3);

            if (DXFFileIsBinary)
            {
                _binarydxfFile          = dxfFile;
                _binarydxfFile.Position = BinaryACADDXFSignature.Length; // Skip the sentinel
            }
            else
            {
                dxfFile.Position = 0;
                _aSCIIdxfFile    = new StreamReader(dxfFile);
            }

            Units = units;

            DXFImportConvFactor = units switch
            {
                DxfUnitsType.Meters => UnitUtils.DistToMeters(DistanceUnitsType.Meters),
                DxfUnitsType.UsSurveyFeet => UnitUtils.DistToMeters(DistanceUnitsType.US_feet),
                DxfUnitsType.ImperialFeet => UnitUtils.DistToMeters(DistanceUnitsType.Feet),
                _ => 1.0
            };
        }
    }
Example #2
0
        public void Units(DxfUnitsType sourceUnits, DistanceUnitsType destUnits)
        {
            var reader = new DXFReader(CreateTestPolyline(), sourceUnits);

            reader.Should().NotBeNull();

            reader.FindEntitiesSection().Should().BeTrue();

            var success = reader.GetBoundaryFromPolyLineEntity(true, out var eof, out var boundary);

            success.Should().BeTrue();

            boundary.Boundary.Points.Should().BeEquivalentTo(new List <FencePoint>
            {
                new FencePoint(0, 0),
                new FencePoint(10 * UnitUtils.DistToMeters(destUnits), 0),
                new FencePoint(0, 10 * UnitUtils.DistToMeters(destUnits))
            });
        }
Example #3
0
 public static double DXFDistance(double value, DistanceUnitsType outputUnits)
 {
     // Takes a value in SI units (ie: meters) and converts it to the project units for writing out to a DXF file
     return(value / UnitUtils.DistToMeters(outputUnits));
 }
Example #4
0
        public bool ConstructSVLCenterlineDXFAlignment(NFFGuidableAlignmentEntity alignment,
                                                       out DesignProfilerRequestResult calcResult, out MemoryStream ms)
        {
            ms = null;
            if ((calcResult = Validate(alignment)) != DesignProfilerRequestResult.OK)
            {
                return(false);
            }

            DXF = new DXFFile();
            DXF.Layers.Add("B");

            // Run through the entities in the alignment and add them to the DXF file
            for (var I = 0; I < alignment.Entities.Count; I++)
            {
                AddEntityToDXF(alignment.Entities[I]);
            }

            // Construct the stationing text entities along the alignment
            var StationIncrement = AlignmentLabelingInterval;
            var CurrentStation   = alignment.StartStation;

            while (CurrentStation <= alignment.EndStation + 0.001)
            {
                alignment.ComputeXY(CurrentStation, 0, out var X1, out var Y1);
                alignment.ComputeXY(CurrentStation, -1, out var X2, out var Y2);

                GeometryUtils.RectToPolar(Y1, X1, Y2, X2, out var textOrientation, out _);

                DXF.Entities.Add(new DXFTextEntity("B",
                                                   kAlignmentCenterLineColor,
                                                   X1, Y1, Consts.NullDouble,
                                                   $"{CurrentStation / UnitUtils.DistToMeters(Units):F2}",
                                                   textOrientation - (Math.PI / 2),
                                                   2,
                                                   "Arial",
                                                   //[],
                                                   //0,
                                                   0, 0));

                if (CurrentStation + StationIncrement <= alignment.EndStation)
                {
                    CurrentStation = CurrentStation + StationIncrement;
                }
                else if (CurrentStation > alignment.EndStation - 0.001)
                {
                    break;
                }
                else
                {
                    CurrentStation = alignment.EndStation;
                }
            }

            if (DXF.Entities.Count > 0)
            {
                ms = new MemoryStream();
                using var writer = new StreamWriter(ms);
                DXF.SaveToFile(writer);
            }

            calcResult = DesignProfilerRequestResult.OK;

            return(true);
        }