Пример #1
0
        public DXFUtilitiesResult Extract(DxfUnitsType units, uint maxBoundariesToProcess, bool convertLineStringCoordsToPolygon)
        {
            bool atEOF;

            Boundaries = new PolyLineBoundaries(units, maxBoundariesToProcess);

            do
            {
                if (_reader.GetBoundaryFromPolyLineEntity(!convertLineStringCoordsToPolygon, out atEOF, out var boundary))
                {
                    if (boundary != null && boundary.Boundary.Points.Count >= 3)
                    {
                        if (boundary.Type == DXFLineWorkBoundaryType.Unknown)
                        {
                            boundary.Type = DXFLineWorkBoundaryType.GenericBoundary;
                        }

                        if (string.IsNullOrEmpty(boundary.Name))
                        {
                            boundary.Name = $"{Boundaries.Boundaries.Count + 1}";
                        }

                        Boundaries.Boundaries.Add(boundary);
                    }
                }
            } while (Boundaries.Boundaries.Count < maxBoundariesToProcess && !atEOF);

            // Determine units in file
            return(DXFUtilitiesResult.Ok);
        }
Пример #2
0
        public static DXFUtilitiesResult RequestBoundariesFromLineWork(string dxfFileContext, DxfUnitsType units, uint maxBoundariesToProcess, bool convertLineStringCoordsToPolygon, out PolyLineBoundaries boundaries)
        {
            using var stream = new MemoryStream(Convert.FromBase64String(dxfFileContext));

            return(DXFFileUtilities.RequestBoundariesFromLineWork(stream, units, maxBoundariesToProcess, convertLineStringCoordsToPolygon, out boundaries));
        }
Пример #3
0
        public static DXFUtilitiesResult RequestBoundariesFromLineWork(MemoryStream dxfFileStream, DxfUnitsType units, uint maxBoundariesToProcess, bool convertLineStringCoordsToPolygon, out PolyLineBoundaries boundaries)
        {
            boundaries = null;
            var reader = new DXFReader(dxfFileStream, units);

            try
            {
                if (!reader.FindEntitiesSection())
                {
                    return(DXFUtilitiesResult.NoEntitiesSectionFound);
                }

                var extractor = new PolyLineBoundaryExtractor(reader);
                var result    = extractor.Extract(units, maxBoundariesToProcess, convertLineStringCoordsToPolygon);

                if (result == DXFUtilitiesResult.Ok)
                {
                    boundaries = extractor.Boundaries;
                }

                return(result);
            }
            catch (FormatException e)
            {
                Log.LogError(e, "DXF file not in expected format");
                return(DXFUtilitiesResult.UnknownFileFormat);
            }
            catch (Exception e)
            {
                Log.LogError(e, "Exception processing DXF file");
                throw;
            }
        }