Exemplo n.º 1
0
        /// <summary>
        ///     Saves the contours and hatches in layers corresponding to its tile
        /// </summary>
        /// <param name="outputDirectory"></param>
        /// <param name="outputName"></param>
        /// <returns></returns>
        public bool ExportAsDXF(string outputDirectory, string outputName)
        {
            var outputFilePath = Path.Combine(outputDirectory, outputName);
            var document       = new DxfDocument(new HeaderVariables());

            // combine geometries
            var geometries = HatchLines.Concat(ContourLines).ToArray();

            // clip geometries in tiles and results to dxf layer
            for (int i = 0; i < Tiles.Count; i++)
            {
                for (int j = 0; j < geometries.Length; j++)
                {
                    var results = GeometricArithmeticModule.ClipGeometry(
                        geometries[j],
                        Tiles[i]
                        );

                    for (int k = 0; k < results?.Count; k++)
                    {
                        document.AddEntity(
                            results[k].GetAsDXFEntity(
                                $"Tile {i}"
                                )
                            );
                    }
                }
            }

            document.Save(outputFilePath);
            return(File.Exists(outputFilePath));
        }
Exemplo n.º 2
0
        public bool SaveAsDXF(string outputFilePath)
        {
            var document = new DxfDocument(new HeaderVariables());

            // combine contour and hatches
            foreach (var geometry in HatchLines.Concat(ContourLines))
            {
                document.AddEntity(
                    geometry.GetAsDXFEntity()
                    );
            }


            document.Save(outputFilePath);
            return(File.Exists(outputFilePath));
        }
Exemplo n.º 3
0
        public bool GenerateHatches(MHatchSettings settings)
        {
            HatchLines.Clear();
            _totalHatchesJumpDistance = 0;
            _totalHatchesMarkDistance = 0;

            var lines    = new List <MarkGeometryLine>();
            var angleRad = GeometricArithmeticModule.ToRadians(settings.Angle);

            var size    = Extents.Hypotenuse;
            var howmany = (int)Math.Ceiling(size / settings.Pitch);
            var yStart  = Extents.Centre.Y - (0.5 * size);

            // generate lines to calculate intersections for hatch
            if (settings.Style == HatchStyle.RASTER || settings.Style == HatchStyle.RASTER_GRID)
            {
                for (int i = 0; i < howmany; i++)
                {
                    double y = yStart + (i * settings.Pitch);

                    var line = new MarkGeometryLine(
                        new MarkGeometryPoint(
                            -size + Extents.Centre.X, y
                            ),
                        new MarkGeometryPoint(
                            size + Extents.Centre.X, y
                            )
                        );

                    // apply angular rotation
                    GeometricArithmeticModule.Rotate(line, 0, 0, angleRad, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z);

                    lines.Add(line);
                }
            }
            else if (settings.Style == HatchStyle.SERPENTINE || settings.Style == HatchStyle.SERPENTINE_GRID)
            {
                for (int i = 0; i < howmany; i++)
                {
                    double y = yStart + (i * settings.Pitch);

                    if (i % 2 == 0)
                    {
                        var line = new MarkGeometryLine(
                            new MarkGeometryPoint(
                                -size + Extents.Centre.X, y
                                ),
                            new MarkGeometryPoint(
                                size + Extents.Centre.X, y
                                )
                            );

                        // apply angular rotation
                        GeometricArithmeticModule.Rotate(line, 0, 0, angleRad, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z);

                        lines.Add(line);
                    }
                    else
                    {
                        var line = new MarkGeometryLine(
                            new MarkGeometryPoint(
                                size + Extents.Centre.X, y
                                ),
                            new MarkGeometryPoint(
                                -size + Extents.Centre.X, y
                                )
                            );

                        // apply angular rotation
                        GeometricArithmeticModule.Rotate(line, 0, 0, angleRad, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z);

                        lines.Add(line);
                    }
                }
            }

            // duplicate lines if using grid
            var perpendicularAngleForGridLines = GeometricArithmeticModule.ToRadians(90);

            if (settings.Style == HatchStyle.RASTER_GRID || settings.Style == HatchStyle.SERPENTINE_GRID)
            {
                int startIndex = lines.Count - 1;
                for (int i = startIndex; i >= 0; i--)
                {
                    var ln = (MarkGeometryLine)lines[i].Clone();
                    GeometricArithmeticModule.Rotate(ln, 0, 0, perpendicularAngleForGridLines, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z);

                    lines.Add(ln);
                }
            }

            // used to track jumps
            MarkGeometryPoint lastPoint = null;

            // generate hatch lines with extension
            for (int i = 0; i < lines.Count; i++)
            {
                List <MarkGeometryPoint> intersections = _contourQuadTree.Intersect(lines[i])?.ToList();

                if (intersections == null)
                {
                    continue;
                }

                int startIndex = (settings.Invert) ? 1 : 0;
                int endIndex   = intersections.Count - 1;

                while (startIndex < endIndex)
                {
                    var hatch = new MarkGeometryLine(
                        intersections[startIndex], intersections[startIndex + 1]
                        );

                    HatchLines.Add(hatch);

                    // increase mark and jump distance
                    if (lastPoint != null)
                    {
                        _totalHatchesJumpDistance += GeometricArithmeticModule.ABSMeasure2D(
                            lastPoint, hatch.StartPoint
                            );
                    }
                    _totalHatchesMarkDistance += hatch.Length;

                    lastPoint   = hatch.EndPoint;
                    startIndex += 2;
                }
            }

            return(true);
        }