Example #1
0
        public void Test()
        {
            DxfModel model = new DxfModel(DxfVersion.Dxf14);

            DxfHatch hatch = new DxfHatch();
            hatch.Color = EntityColors.Green;
            hatch.ElevationPoint = new Point3D(10,10, 0);
            hatch.ZAxis = new Vector3D(0, 0, 0);

            // A boundary path bounded by lines.
            DxfHatch.BoundaryPath boundaryPath1 = new DxfHatch.BoundaryPath();
            boundaryPath1.Type = BoundaryPathType.None;
            hatch.BoundaryPaths.Add(boundaryPath1);
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(0, 0), new Point2D(1, 0)));
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(1, 0), new Point2D(1, 1)));
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(1, 1), new Point2D(0, 1)));
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(0, 1), new Point2D(0, 0)));

            // Define the hatch fill pattern.
            // Don't set a pattern for solid fill.
            hatch.Pattern = new DxfPattern();
            DxfPattern.Line patternLine = new DxfPattern.Line();
            hatch.Pattern.Lines.Add(patternLine);
            patternLine.Angle = System.Math.PI / 4d;
            patternLine.Offset = new Vector2D(0.02, -0.01d);
            patternLine.DashLengths.Add(0.02d);
            patternLine.DashLengths.Add(-0.01d);
            patternLine.DashLengths.Add(0d);
            patternLine.DashLengths.Add(-0.01d);

            model.Entities.Add(hatch);

            DxfWriter.Write("DxfWriteHatchTest.dxf", model, false);
        }
Example #2
0
        public static DxfPattern[] ReadPatterns(TextReader reader)
        {
            int num1 = 0;
            List <DxfPattern> dxfPatternList = new List <DxfPattern>();
            DxfPattern        dxfPattern     = (DxfPattern)null;

            try
            {
                while (true)
                {
                    string str1;
                    do
                    {
                        do
                        {
                            string str2 = reader.ReadLine();
                            ++num1;
                            if (str2 != null)
                            {
                                str1 = str2.Trim('\x001A');
                            }
                            else
                            {
                                goto label_14;
                            }
                        }while (string.IsNullOrEmpty(str1) || str1.StartsWith(";"));
                        if (str1.StartsWith("*"))
                        {
                            int    num2 = str1.IndexOf(',');
                            string name;
                            string str2;
                            if (num2 < 0)
                            {
                                name = str1.Substring(1);
                                str2 = (string)null;
                            }
                            else
                            {
                                name = str1.Substring(1, num2 - 1);
                                str2 = str1.Substring(num2 + 1);
                            }
                            dxfPattern             = new DxfPattern(name);
                            dxfPattern.Description = str2;
                            dxfPatternList.Add(dxfPattern);
                        }
                    }while (dxfPattern == null);
                    DxfPattern.Line line     = new DxfPattern.Line();
                    string[]        strArray = str1.Split(',');
                    line.Angle     = System.Math.PI / 180.0 * double.Parse(strArray[0], (IFormatProvider)CultureInfo.InvariantCulture);
                    line.BasePoint = new Point2D(double.Parse(strArray[1], (IFormatProvider)CultureInfo.InvariantCulture), double.Parse(strArray[2], (IFormatProvider)CultureInfo.InvariantCulture));
                    Vector2D vector2D = new Vector2D(double.Parse(strArray[3], (IFormatProvider)CultureInfo.InvariantCulture), double.Parse(strArray[4], (IFormatProvider)CultureInfo.InvariantCulture));
                    double   num3     = System.Math.Cos(line.Angle);
                    double   num4     = System.Math.Sin(line.Angle);
                    line.Offset = new Vector2D(vector2D.X * num3 - vector2D.Y * num4, vector2D.X * num4 + vector2D.Y * num3);
                    for (int index = 5; index < strArray.Length; ++index)
                    {
                        line.DashLengths.Add(double.Parse(strArray[index], (IFormatProvider)CultureInfo.InvariantCulture));
                    }
                    dxfPattern.Lines.Add(line);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Parse error at line {0}: ", (object)num1), ex);
            }
label_14:
            return(dxfPatternList.ToArray());
        }