Пример #1
0
        public void RenderArcTest()
        {
            var arc  = new DxfArc(new DxfPoint(1.0, 2.0, 3.0), 4.0, 0.0, 90.0);
            var path = arc.GetSvgPath();

            Assert.Equal(2, path.Segments.Count);

            var first = (SvgMoveToPath)path.Segments[0];

            AssertClose(5.0, first.LocationX);
            AssertClose(2.0, first.LocationY);

            var arcPathSegment = (SvgArcToPath)path.Segments[1];

            AssertClose(1.0, arcPathSegment.EndPointX);
            AssertClose(6.0, arcPathSegment.EndPointY);
            Assert.Equal(4.0, arcPathSegment.RadiusX);
            Assert.Equal(4.0, arcPathSegment.RadiusY);
            Assert.Equal(0.0, arcPathSegment.XAxisRotation);
            Assert.False(arcPathSegment.IsLargeArc);
            Assert.True(arcPathSegment.IsCounterClockwiseSweep);

            var expected = new XElement("path",
                                        new XAttribute("d", path.ToString()),
                                        new XAttribute("fill-opacity", "0"),
                                        new XAttribute("stroke-width", "1.0px"),
                                        new XAttribute("vector-effect", "non-scaling-stroke"));
            var actual = arc.ToXElement();

            AssertXElement(expected, actual);
        }
Пример #2
0
        public void ShouldNotContainAngle(double startAngle, double endAngle, double angle)
        {
            var radius = 1.0;
            var arc    = new DxfArc(DxfPoint.Origin, radius, startAngle, endAngle);

            Assert.False(arc.ContainsAngle(angle));
        }
Пример #3
0
        public void ArcPathOf180DegreesTest()
        {
            var arc  = new DxfArc(new DxfPoint(0.0, 0.0, 0.0), 1.0, 0.0, 180.0);
            var path = arc.GetSvgPath();

            Assert.Equal(3, path.Segments.Count);

            var move = (SvgMoveToPath)path.Segments[0];

            AssertClose(1.0, move.LocationX);
            AssertClose(0.0, move.LocationY);

            // 180 degree arcs are difficult to render; split it into two 90s
            var first = (SvgArcToPath)path.Segments[1];

            AssertClose(0.0, first.EndPointX);
            AssertClose(1.0, first.EndPointY);
            Assert.Equal(1.0, first.RadiusX);
            Assert.Equal(1.0, first.RadiusY);
            Assert.Equal(0.0, first.XAxisRotation);
            Assert.False(first.IsLargeArc);
            Assert.True(first.IsCounterClockwiseSweep);
            var second = (SvgArcToPath)path.Segments[2];

            AssertClose(-1.0, second.EndPointX);
            AssertClose(0.0, second.EndPointY);
            Assert.Equal(1.0, second.RadiusX);
            Assert.Equal(1.0, second.RadiusY);
            Assert.Equal(0.0, second.XAxisRotation);
            Assert.False(second.IsLargeArc);
            Assert.True(second.IsCounterClockwiseSweep);
        }
Пример #4
0
        public void ShouldContainAngle(double startAngle, double endAngle, double angle)
        {
            var radius = 1.0; // negative radius only for DxfVertex.Bulge, but not for arcs (?)
            var arc    = new DxfArc(DxfPoint.Origin, radius, startAngle, endAngle);

            Assert.True(arc.ContainsAngle(angle));
        }
Пример #5
0
        internal static SvgPath GetSvgPath(this DxfArc arc)
        {
            var startAngle = arc.StartAngle * Math.PI / 180.0;
            var endAngle   = arc.EndAngle * Math.PI / 180.0;

            return(SvgPath.FromEllipse(arc.Center.X, arc.Center.Y, arc.Radius, 0.0, 1.0, startAngle, endAngle));
        }
Пример #6
0
 private void WriteArc(DxfArc arc)
 {
     WriteItemType(DxbItemType.Arc);
     WriteN(arc.Center.X);
     WriteN(arc.Center.Y);
     WriteN(arc.Radius);
     WriteA(arc.StartAngle);
     WriteA(arc.EndAngle);
 }
Пример #7
0
        public static XElement ToXElement(this DxfArc arc)
        {
            var path = arc.GetSvgPath();

            return(new XElement(DxfToSvgConverter.Xmlns + "path",
                                new XAttribute("d", path.ToString()),
                                new XAttribute("fill-opacity", 0))
                   .AddStroke(arc.Color)
                   .AddStrokeWidth(arc.Thickness)
                   .AddVectorEffect());
        }
Пример #8
0
        public float GetEntityLength(DxfArc dxfArc)
        {
            var startAngle = (float)dxfArc.StartAngle;
            var endAngle   = (float)dxfArc.EndAngle;

            startAngle *= -1;
            endAngle   *= -1;

            var sweep = (endAngle - startAngle - 360) % 360;

            return((float)(2 * Math.PI * dxfArc.Radius * Math.Abs(sweep) / 360f));
        }
Пример #9
0
        public void ArcFlagsSizeTest2()
        {
            // arc from 350->10
            var arc  = new DxfArc(new DxfPoint(1.0, 2.0, 3.0), 4.0, 350.0, 10.0);
            var path = arc.GetSvgPath();

            Assert.Equal(2, path.Segments.Count);
            var arcTo = (SvgArcToPath)path.Segments[1];

            Assert.False(arcTo.IsLargeArc);
            Assert.True(arcTo.IsCounterClockwiseSweep);
        }
Пример #10
0
        public void ShouldContainStartAndEndAngle()
        {
            var radius = 1.0; // negative radius only for DxfVertex.Bulge, but not for arcs (?)

            for (var start = 0; start <= 360; start += 10)
            {
                for (var end = 0; end <= 360; end += 10)
                {
                    var arc = new DxfArc(DxfPoint.Origin, radius, start, end);
                    Assert.True(arc.ContainsAngle(start), $"{start}°=>{end}° arc contains {start}°");
                    Assert.True(arc.ContainsAngle(end), $"{start}°=>{end}° arc contains {end}°");
                }
            }
        }
Пример #11
0
        void ProcessDxfArc(DxfArc dxfArc)
        {
            double angle0 = dxfArc.StartAngle;
            double angle1 = dxfArc.EndAngle;
            double angle  = dxfArc.EndAngle - dxfArc.StartAngle;

            if (angle > 0.0)
            {
                PicArc picArc = Factory.AddArc(
                    DxfColor2PicLT(dxfArc), DxfLayer2PicGrp(dxfArc.Layer), 0
                    , new Vector2D(dxfArc.Center.X, dxfArc.Center.Y)
                    , dxfArc.Radius
                    , angle0, angle1
                    );
            }
            else
            {
                while (angle < 0)
                {
                    angle += 360.0;
                }
                while (angle > 360.0)
                {
                    angle -= 360.0;
                }


                angle0 += angle;
                angle1 -= angle;
                while (angle0 < 0.0)
                {
                    angle0 += 360.0;
                    angle1 += 360.0;
                }
                while (angle0 >= 360.0)
                {
                    angle0 -= 360.0;
                }



                PicArc picArc = Factory.AddArc(
                    DxfColor2PicLT(dxfArc), DxfLayer2PicGrp(dxfArc.Layer), 0
                    , new Vector2D(dxfArc.Center.X, dxfArc.Center.Y)
                    , dxfArc.Radius
                    , angle0, angle1
                    );
            }
        }
Пример #12
0
        private static IEnumerable <IPdfPathItem> ConvertArc(DxfArc arc, DxfLayer layer, Matrix4 affine, Matrix4 scale)
        {
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(arc, layer),
                strokeWidth: GetStrokeWidth(arc, layer));
            var center = affine.Transform(arc.Center).ToPdfPoint(PdfMeasurementType.Point);
            var radius = scale.Transform(new Vector(arc.Radius, arc.Radius, arc.Radius))
                         .ToPdfPoint(PdfMeasurementType.Point);
            const double rotation      = 0;
            double       startAngleRad = arc.StartAngle * Math.PI / 180;
            double       endAngleRad   = arc.EndAngle * Math.PI / 180;

            yield return(new PdfEllipse(center, radius.X, radius.Y, rotation, startAngleRad, endAngleRad,
                                        pdfStreamState));
        }
Пример #13
0
        public void ArcBoundingBox()
        {
            var radius     = 1.0;
            var startAngle = 90;
            var endAngle   = 180;

            var arc = new DxfArc(DxfPoint.Origin, radius, startAngle, endAngle);
            var bb  = arc.GetBoundingBox().Value;

            var expectedMin = new DxfPoint(-1, 0, 0);
            var expectedMax = new DxfPoint(0, 1, 0);

            Assert.Equal(expectedMin.X, bb.MinimumPoint.X, 10);
            Assert.Equal(expectedMin.Y, bb.MinimumPoint.Y, 10);
            Assert.Equal(expectedMin.X, bb.MinimumPoint.X, 10);
            Assert.Equal(expectedMax.Y, bb.MaximumPoint.Y, 10);
        }
Пример #14
0
        public string EntityToJson(DxfArc dxfArc)
        {
            // float startAngle = (float)dxfArc.StartAngle;
            // float endAngle = (float)dxfArc.EndAngle;

            // startAngle *= -1;
            // endAngle *= -1;
            //
            // float sweep = (endAngle - startAngle - 360) % 360;

            return(string.Format(Format, "[\"arc\",{0:F},{1:F},{2:F},{3:F},{4:F}]",
                                 dxfArc.Center.X,
                                 dxfArc.Center.Y,
                                 dxfArc.Radius,
                                 dxfArc.StartAngle,
                                 dxfArc.EndAngle));
        }
Пример #15
0
        public void RenderEntity(DxfArc dxfArc, Graphics graphics, int height)
        {
            var startAngle = (float)dxfArc.StartAngle;
            var endAngle   = (float)dxfArc.EndAngle;

            startAngle *= -1;
            endAngle   *= -1;

            var sweep = (endAngle - startAngle - 360) % 360;

            graphics.DrawArc(Pens.Black,
                             (float)(dxfArc.Center.X - dxfArc.Radius) * ScaleFactor + OffsetX,
                             height - (float)(dxfArc.Center.Y + dxfArc.Radius) * ScaleFactor + OffsetY,
                             (float)dxfArc.Radius * 2f * ScaleFactor,
                             (float)dxfArc.Radius * 2f * ScaleFactor,
                             startAngle,
                             sweep);
        }
 /// <summary>
 /// Visits the specified entity.
 /// See the <see cref="IEntityVisitor"/> for more details.
 /// </summary>
 public override void Visit(DxfArc arc)
 {
     HandleEntity(arc);
 }
Пример #17
0
 public virtual void Visit(DxfArc arc)
 {
 }
Пример #18
0
        public static completeDxfStruct processDxfFile(string in_obtainedFileName)
        {
            completeDxfStruct valueToReturn = new completeDxfStruct();
            DxfFile           dxfFile;

            using (System.IO.FileStream fs = new System.IO.FileStream(in_obtainedFileName, System.IO.FileMode.Open))
            {
                dxfFile = DxfFile.Load(fs);
                IList <DxfBlock>  allBlocks = dxfFile.Blocks;
                IList <DxfEntity> usedEntities;
                if ((allBlocks.Count == 0) || (allBlocks[0].Name.ToUpper().Contains("MODEL") == false))
                {
                    usedEntities = dxfFile.Entities;
                }
                else
                {
                    usedEntities = allBlocks[0].Entities;
                }

                foreach (DxfEntity entity in dxfFile.Entities)
                {
                    switch (entity.EntityType)
                    {
                    case DxfEntityType.Line:
                    {
                        DxfLine   line       = (DxfLine)entity;
                        MyDxfLine TransfLine = new MyDxfLine(line.P1.X, line.P1.Y, line.P2.X, line.P2.Y, line.Layer);
                        valueToReturn.addDxfDrawingEntry(TransfLine);
                        break;
                    }

                    case DxfEntityType.Arc:
                    {
                        DxfArc   arc       = (DxfArc)entity;
                        MyDxfArc TransfArc = new MyDxfArc(arc.Center.X, arc.Center.Y, arc.StartAngle, arc.EndAngle, arc.Radius, arc.Layer);
                        valueToReturn.addDxfDrawingEntry(TransfArc);
                        break;
                    }

                    case DxfEntityType.LwPolyline:
                    {         //polyline. It has vertices.
                        DxfLwPolyline polylineS             = entity as DxfLwPolyline;
                        int           totalnumberOfVertices = polylineS.Vertices.Count;
                        for (int i = 0; i < totalnumberOfVertices - 1; i++)
                        {         //iterate through vertices, taking them by 2. A figure is between these two
                            DxfLwPolylineVertex point1 = polylineS.Vertices[i];
                            DxfLwPolylineVertex point2 = polylineS.Vertices[i + 1];
                            if (point1.Bulge == 0)
                            {
                                MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y, polylineS.Layer);
                                valueToReturn.addDxfDrawingEntry(TransfLine);
                            }
                            else             //it is arc
                            // The bulge is the tangent of one fourth the included angle for an arc segment,
                            // made negative if the arc goes clockwise from the start point to the endpoint.
                            // A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle
                            {
                                double angleOfArcRad = System.Math.Atan(Math.Abs(point1.Bulge)) * 4;
                                // http://mymathforum.com/algebra/21368-find-equation-circle-given-two-points-arc-angle.html
                                // tides of Internet have almost washed this post in forum
                                double xA; double xB; double yA; double yB;
                                if (point1.Bulge < 0)
                                {
                                    xA = point2.X; yA = point2.Y;
                                    xB = point1.X; yB = point1.Y;
                                }
                                else
                                {
                                    xA = point1.X;  yA = point1.Y;
                                    xB = point2.X;  yB = point2.Y;
                                }
                                double d_square = (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB);
                                double r_square = (d_square) / (2.0 * (1.0 - Math.Cos(angleOfArcRad)));
                                double m = (xA - xB) / (yB - yA);
                                double a = Math.Sqrt(r_square - d_square / 4.0);
                                double xM = (xA + xB) / 2.0; double yM = (yA + yB) / 2.0;
                                double xC_plus  = xM + a / Math.Sqrt(m * m + 1);
                                double xC_minus = xM - a / Math.Sqrt(m * m + 1);
                                double yC_plus  = yM + m * a / Math.Sqrt(m * m + 1);
                                double yC_minus = yM - m * a / Math.Sqrt(m * m + 1);
                                // https://en.wikipedia.org/wiki/Linear_equation#Point%E2%80%93slope_form
                                double usedXCenter; double usedYCenter; double usedAngle1; double usedAngle2;
                                // https://stackoverflow.com/questions/1311049/how-to-map-atan2-to-degrees-0-360
                                double angle1_candidate1 = (Math.Atan2(yA - yC_plus, xA - xC_plus) * 180 / Math.PI + 360) % 360;
                                double angle2_candidate1 = (Math.Atan2(yB - yC_plus, xB - xC_plus) * 180 / Math.PI + 360) % 360;
                                double angle1_candidate2 = (Math.Atan2(yA - yC_minus, xA - xC_minus) * 180 / Math.PI + 360) % 360;
                                double angle2_candidate2 = (Math.Atan2(yB - yC_minus, xB - xC_minus) * 180 / Math.PI + 360) % 360;
                                //mydxfarc expects angles counterclockwise
                                if (point1.Bulge > 0)
                                {
                                    if (angle1_candidate1 < angle2_candidate1)
                                    {
                                        usedAngle1  = angle1_candidate1;
                                        usedAngle2  = angle2_candidate1;
                                        usedXCenter = xC_plus; usedYCenter = yC_plus;
                                    }
                                    else
                                    {
                                        usedAngle1  = angle1_candidate2;
                                        usedAngle2  = angle2_candidate2;
                                        usedXCenter = xC_minus; usedYCenter = yC_minus;
                                    }
                                }
                                else
                                {
                                    if (angle1_candidate1 > angle2_candidate1)
                                    {
                                        usedAngle1  = angle1_candidate2;
                                        usedAngle2  = angle2_candidate2;
                                        usedXCenter = xC_minus; usedYCenter = yC_minus;
                                    }
                                    else
                                    {
                                        usedAngle1  = angle1_candidate1;
                                        usedAngle2  = angle2_candidate1;
                                        usedXCenter = xC_plus; usedYCenter = yC_plus;
                                    }
                                }
                                MyDxfArc TransfArc = new MyDxfArc(usedXCenter, usedYCenter,
                                                                  usedAngle1,
                                                                  usedAngle2,
                                                                  Math.Sqrt(r_square),
                                                                  polylineS.Layer);
                                valueToReturn.addDxfDrawingEntry(TransfArc);
                            }
                        }
                        if (polylineS.IsClosed)
                        {
                            DxfLwPolylineVertex point1 = polylineS.Vertices[totalnumberOfVertices - 1];
                            DxfLwPolylineVertex point2 = polylineS.Vertices[0];
                            if (point1.Bulge == 0)
                            {
                                MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y, polylineS.Layer);
                                valueToReturn.addDxfDrawingEntry(TransfLine);
                            }
                            else             // arc
                                             // I so like the code above, so I cannot resist to copypaste it

                            {
                                double angleOfArcRad = System.Math.Atan(Math.Abs(point1.Bulge)) * 4;
                                double xA; double xB; double yA; double yB;
                                if (point1.Bulge < 0)
                                {
                                    xA = point2.X; yA = point2.Y;   xB = point1.X; yB = point1.Y;
                                }
                                else
                                {
                                    xA = point1.X; yA = point1.Y;   xB = point2.X; yB = point2.Y;
                                }
                                double d_square = (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB);
                                double r_square = (d_square) / (2.0 * (1.0 - Math.Cos(angleOfArcRad)));
                                double m = (xA - xB) / (yB - yA);
                                double a = Math.Sqrt(r_square - d_square / 4.0);
                                double xM = (xA + xB) / 2.0; double yM = (yA + yB) / 2.0;
                                double xC_plus  = xM + a / Math.Sqrt(m * m + 1);
                                double xC_minus = xM - a / Math.Sqrt(m * m + 1);
                                double yC_plus  = yM + m * a / Math.Sqrt(m * m + 1);
                                double yC_minus = yM - m * a / Math.Sqrt(m * m + 1);
                                // https://en.wikipedia.org/wiki/Linear_equation#Point%E2%80%93slope_form
                                double usedXCenter; double usedYCenter; double usedAngle1; double usedAngle2;
                                // https://stackoverflow.com/questions/1311049/how-to-map-atan2-to-degrees-0-360
                                double angle1_candidate1 = (Math.Atan2(yA - yC_plus, xA - xC_plus) * 180 / Math.PI + 360) % 360;
                                double angle2_candidate1 = (Math.Atan2(yB - yC_plus, xB - xC_plus) * 180 / Math.PI + 360) % 360;
                                double angle1_candidate2 = (Math.Atan2(yA - yC_minus, xA - xC_minus) * 180 / Math.PI + 360) % 360;
                                double angle2_candidate2 = (Math.Atan2(yB - yC_minus, xB - xC_minus) * 180 / Math.PI + 360) % 360;
                                //mydxfarc expects angles counterclockwise
                                if (point1.Bulge > 0)
                                {
                                    if (angle1_candidate1 < angle2_candidate1)
                                    {
                                        usedAngle1  = angle1_candidate1; usedAngle2 = angle2_candidate1;
                                        usedXCenter = xC_plus; usedYCenter = yC_plus;
                                    }
                                    else
                                    {
                                        usedAngle1  = angle1_candidate2; usedAngle2 = angle2_candidate2;
                                        usedXCenter = xC_minus; usedYCenter = yC_minus;
                                    }
                                }
                                else
                                {
                                    if (angle1_candidate1 > angle2_candidate1)
                                    {
                                        usedAngle1  = angle1_candidate2; usedAngle2 = angle2_candidate2;
                                        usedXCenter = xC_minus; usedYCenter = yC_minus;
                                    }
                                    else
                                    {
                                        usedAngle1  = angle1_candidate1; usedAngle2 = angle2_candidate1;
                                        usedXCenter = xC_plus; usedYCenter = yC_plus;
                                    }
                                }
                                MyDxfArc TransfArc = new MyDxfArc(usedXCenter, usedYCenter,
                                                                  usedAngle1, usedAngle2, Math.Sqrt(r_square), polylineS.Layer);
                                valueToReturn.addDxfDrawingEntry(TransfArc);
                            }
                        }

                        break;
                    }

                    case DxfEntityType.Polyline:
                    {
                        //this is a spawn of autocad. Either copypaste code from LwPolyline section. Or just save the file in QCad.
                        //QCad replaces all polylines by lwPolylines
                        //https://github.com/IxMilia/Dxf/issues/90
                        DxfPolyline polyline = entity as DxfPolyline;

                        break;
                    }
                    }
                }
            }
            return(valueToReturn);
        }
Пример #19
0
    /// <summary>
    /// Parse DXF into VectorShape list.
    /// </summary>
    public static List <VectorShape> ReadDXF(Stream dxfStream)
    {
        List <VectorShape> shapes = new List <VectorShape>();

        DxfFile dxfFile = DxfFile.Load(dxfStream);

        Dictionary <string, Color32> layerColors = new Dictionary <string, Color32>();

        foreach (DxfLayer layer in dxfFile.Layers)
        {
            layerColors.Add(layer.Name, ConvertColor(layer.Color));
        }

        foreach (DxfEntity entity in dxfFile.Entities)
        {
            VectorShape shape = null;

            switch (entity.EntityType)
            {
            case DxfEntityType.Point:
                DxfModelPoint point = entity as DxfModelPoint;
                shape = new PointShape(ConvertPoint(point.Location));
                break;

            case DxfEntityType.Line:
                DxfLine   line      = entity as DxfLine;
                Vector2[] endpoints = new Vector2[2];
                endpoints[0] = ConvertPoint(line.P1);
                endpoints[1] = ConvertPoint(line.P2);
                shape        = new PolyShape(endpoints);
                break;

            case DxfEntityType.Spline:
                DxfSpline spline = entity as DxfSpline;
                if ((spline.NumberOfControlPoints % spline.DegreeOfCurve) != 1)
                {
                    Debug.LogError("Invalid spline data! Wrong number of points. " + spline);
                    break;
                }

                Vector2[] controlPoints = new Vector2[spline.NumberOfControlPoints];
                for (int i = 0; i < controlPoints.Length; i++)
                {
                    controlPoints[i] = ConvertPoint(spline.ControlPoints[i]);
                }
                shape = new PolyShape(controlPoints[0]);
                PolyShape shapeSpline = shape as PolyShape;

                switch (spline.DegreeOfCurve)
                {
                case 1:

                    for (int i = 1; i < controlPoints.Length; i++)
                    {
                        shapeSpline.LineTo(controlPoints[i]);
                    }
                    break;

                case 2:
                    for (int i = 1; i < controlPoints.Length; i += 2)
                    {
                        shapeSpline.CurveTo(controlPoints[i + 1], controlPoints[i]);
                    }
                    break;

                case 3:
                    for (int i = 1; i < controlPoints.Length; i += 3)
                    {
                        shapeSpline.CurveTo(controlPoints[i + 2], controlPoints[i], controlPoints[i + 1]);
                    }
                    break;

                default:
                    Debug.LogWarning("Spline with unsupported curve of degree: " + spline.DegreeOfCurve);
                    break;
                }
                break;

            case DxfEntityType.Arc:
                DxfArc arc = entity as DxfArc;
                // If the arc is a complete circle just make one of those
                float startAngle = (float)arc.StartAngle;
                while (startAngle < 0f)
                {
                    startAngle += 360f;
                }
                float endAngle = (float)arc.EndAngle;
                while (endAngle < startAngle)
                {
                    endAngle += 360f;
                }

                float sweep = endAngle - startAngle;
                shape = new CircleShape(ConvertPoint(arc.Center), (float)arc.Radius, startAngle, sweep);
                break;

            case DxfEntityType.Circle:
                DxfCircle circle = entity as DxfCircle;
                shape = new CircleShape(ConvertPoint(circle.Center), (float)circle.Radius * dxfScale);
                break;

            case DxfEntityType.Ellipse:
                DxfEllipse ellipse = entity as DxfEllipse;
                // If the ellipse is actually a circle just make one of those
                if (Mathf.Approximately((float)ellipse.MinorAxisRatio, 1f))
                {
                    shape = new CircleShape(ConvertPoint(ellipse.Center), (float)ellipse.MajorAxis.Length * dxfScale);
                }
                else
                {
                    shape = new EllipseShape(ConvertPoint(ellipse.Center), ConvertVector(ellipse.MajorAxis), (float)ellipse.MinorAxisRatio);
                }
                break;

            case DxfEntityType.Polyline:
                DxfPolyline polyline = entity as DxfPolyline;
                if (polyline.ContainsVertices)
                {
                    Vector2[] vertices = new Vector2[polyline.Vertices.Count];
                    for (int i = 0; i < vertices.Length; i++)
                    {
                        vertices[i] = ConvertPoint(polyline.Vertices[i].Location);
                    }

                    shape = new PolyShape(vertices[0]);
                    PolyShape shapePolyline = shape as PolyShape;

                    for (int i = 1; i < vertices.Length; i++)
                    {
                        float bulge = (float)polyline.Vertices[i - 1].Bulge;
                        shapePolyline.ArcToDXF(vertices[i], bulge);
                    }

                    if (polyline.IsClosed)
                    {
                        float bulge = (float)polyline.Vertices[vertices.Length - 1].Bulge;
                        shapePolyline.ArcToDXF(vertices[0], bulge);
                        shape.Closed = true;
                    }
                }
                break;

            case DxfEntityType.LwPolyline:
            {
                DxfLwPolyline lwPolyline = entity as DxfLwPolyline;
                Vector2[]     vertices   = new Vector2[lwPolyline.Vertices.Count];
                for (int i = 0; i < vertices.Length; i++)
                {
                    DxfLwPolylineVertex lwpVertex = lwPolyline.Vertices[i];
                    vertices[i] = ConvertPoint(lwpVertex.X, lwpVertex.Y);
                }

                shape = new PolyShape(vertices[0]);
                PolyShape shapePolyline = shape as PolyShape;

                for (int i = 1; i < vertices.Length; i++)
                {
                    float bulge = (float)lwPolyline.Vertices[i - 1].Bulge;
                    shapePolyline.ArcToDXF(vertices[i], bulge);
                }

                if (lwPolyline.IsClosed)
                {
                    float bulge = (float)lwPolyline.Vertices[vertices.Length - 1].Bulge;
                    shapePolyline.ArcToDXF(vertices[0], bulge);
                    shape.Closed = true;
                }
            }
            break;

            default:
                Debug.Log("Unhandled entity of type: " + entity.EntityType);
                break;
            }

            if (shape != null)
            {
                if (entity.IsVisible)
                {
                    Color32 shapeColor = ConvertColor(entity.Color);
                    //layerColors.TryGetValue(entity.Layer, out shapeColor);

                    shape.colorOutline = shapeColor;
                    shapes.Add(shape);
                }
            }
        }

        return(shapes);
    }
Пример #20
0
        public static RawDetail LoadDxf(string path)
        {
            FileInfo  fi      = new FileInfo(path);
            DxfFile   dxffile = DxfFile.Load(fi.FullName);
            RawDetail s       = new RawDetail();

            s.Name = fi.FullName;
            IEnumerable <DxfEntity> entities = dxffile.Entities.ToArray();

            List <LineElement> elems = new List <LineElement>();

            foreach (DxfEntity ent in entities)
            {
                switch (ent.EntityType)
                {
                case DxfEntityType.LwPolyline:
                {
                    DxfLwPolyline poly = (DxfLwPolyline)ent;
                    if (poly.Vertices.Count() < 2)
                    {
                        continue;
                    }
                    LocalContour points = new LocalContour();
                    foreach (DxfLwPolylineVertex vert in poly.Vertices)
                    {
                        points.Points.Add(new PointF((float)vert.X, (float)vert.Y));
                    }
                    for (int i = 0; i < points.Points.Count; i++)
                    {
                        var p0 = points.Points[i];
                        var p1 = points.Points[(i + 1) % points.Points.Count];
                        elems.Add(new LineElement()
                            {
                                Start = p0, End = p1
                            });
                    }
                }
                break;

                case DxfEntityType.Arc:
                {
                    DxfArc        arc = (DxfArc)ent;
                    List <PointF> pp  = new List <PointF>();

                    if (arc.StartAngle > arc.EndAngle)
                    {
                        arc.StartAngle -= 360;
                    }

                    for (double i = arc.StartAngle; i < arc.EndAngle; i += 15)
                    {
                        var tt = arc.GetPointFromAngle(i);
                        pp.Add(new PointF((float)tt.X, (float)tt.Y));
                    }
                    var t = arc.GetPointFromAngle(arc.EndAngle);
                    pp.Add(new PointF((float)t.X, (float)t.Y));
                    for (int j = 1; j < pp.Count; j++)
                    {
                        var p1 = pp[j - 1];
                        var p2 = pp[j];
                        elems.Add(new LineElement()
                            {
                                Start = new PointF((float)p1.X, (float)p1.Y), End = new PointF((float)p2.X, (float)p2.Y)
                            });
                    }
                }
                break;

                case DxfEntityType.Circle:
                {
                    DxfCircle    cr = (DxfCircle)ent;
                    LocalContour cc = new LocalContour();

                    for (int i = 0; i <= 360; i += 15)
                    {
                        var ang = i * Math.PI / 180f;
                        var xx  = cr.Center.X + cr.Radius * Math.Cos(ang);
                        var yy  = cr.Center.Y + cr.Radius * Math.Sin(ang);
                        cc.Points.Add(new PointF((float)xx, (float)yy));
                    }
                    for (int i = 1; i < cc.Points.Count; i++)
                    {
                        var p1 = cc.Points[i - 1];
                        var p2 = cc.Points[i];
                        elems.Add(new LineElement()
                            {
                                Start = p1, End = p2
                            });
                    }
                }
                break;

                case DxfEntityType.Line:
                {
                    DxfLine poly = (DxfLine)ent;
                    elems.Add(new LineElement()
                        {
                            Start = new PointF((float)poly.P1.X, (float)poly.P1.Y), End = new PointF((float)poly.P2.X, (float)poly.P2.Y)
                        });
                    break;
                }

                case DxfEntityType.Polyline:
                {
                    DxfPolyline poly = (DxfPolyline)ent;
                    if (poly.Vertices.Count() < 2)
                    {
                        continue;
                    }
                    LocalContour points = new LocalContour();
                    for (int i = 0; i < poly.Vertices.Count; i++)
                    {
                        DxfVertex vert = poly.Vertices[i];
                        points.Points.Add(new PointF((float)vert.Location.X, (float)vert.Location.Y));
                    }
                    for (int i = 0; i < points.Points.Count; i++)
                    {
                        var p0 = points.Points[i];
                        var p1 = points.Points[(i + 1) % points.Points.Count];
                        elems.Add(new LineElement()
                            {
                                Start = p0, End = p1
                            });
                    }
                    break;
                }

                default:
                    throw new ArgumentException("unsupported entity type: " + ent);
                }
                ;
            }


            elems = elems.Where(z => z.Start.DistTo(z.End) > RemoveThreshold).ToList();
            var cntrs2 = ConnectElements(elems.ToArray());

            s.Outers.AddRange(cntrs2);
            if (s.Outers.Any(z => z.Points.Count < 3))
            {
                throw new Exception("few points");
            }

            return(s);
        }
Пример #21
0
        static void FindEntities(DxfEntityCollection Entities)
        {
            foreach (var entityGroups in Entities)
            {
                if (typeof(DxfLine) != entityGroups.GetType() && typeof(DxfLwPolyline) != entityGroups.GetType() && typeof(DxfMText) != entityGroups.GetType() && typeof(DxfText) != entityGroups.GetType() && typeof(DxfCircle) != entityGroups.GetType() && typeof(DxfHatch) != entityGroups.GetType() && typeof(DxfInsert) != entityGroups.GetType() && typeof(DxfSpline) != entityGroups.GetType())
                {
                    // Console.WriteLine(entityGroups.GetType());
                }

                dxfType.Add(entityGroups.GetType().Name);
                if (typeof(DxfLine) == entityGroups.GetType())
                {
                    dxfLine = entityGroups as DxfLine;

                    int color;

                    if (dxfLine.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfLine.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfLine.Color.Rgb;
                    }


                    CADLine cADLine = new CADLine
                    {
                        parentHandle = dxfLine.OwnerObjectSoftReference.Handle,
                        type         = dxfLine.GetType().Name,
                        color        = color,
                        transform    = dxfLine.Transform.DebugString,
                        startPoint   = dxfLine.Start.ToString(),
                        endPoint     = dxfLine.End.ToString(),
                        lineWeight   = dxfLine.LineWeight
                    };

                    cadEntities.Add(cADLine);
                }


                if (typeof(DxfLwPolyline) == entityGroups.GetType())
                {
                    //Console.WriteLine(dxfLwPolyline);

                    dxfLwPolyline = entityGroups as DxfLwPolyline;

                    string[] arrVertices = new string[dxfLwPolyline.Vertices.Count];
                    for (int i = 0; i < dxfLwPolyline.Vertices.Count; i++)
                    {
                        arrVertices[i] = dxfLwPolyline.Vertices[i].ToString();
                    }

                    int color;
                    if (dxfLwPolyline.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfLwPolyline.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfLwPolyline.Color.Rgb;
                    }


                    CADLwPolyLine cADLwPolyLine = new CADLwPolyLine
                    {
                        parentHandle = dxfLwPolyline.OwnerObjectSoftReference.Handle,
                        type         = dxfLwPolyline.GetType().Name,
                        color        = color,
                        transform    = dxfLwPolyline.Transform.DebugString,

                        vertices = arrVertices,
                        closed   = dxfLwPolyline.Closed.ToString(),
                    };

                    cadEntities.Add(cADLwPolyLine);
                }


                if (typeof(DxfXLine) == entityGroups.GetType())
                {
                    dxfXLine = entityGroups as DxfXLine;
                }

                if (typeof(DxfSpline) == entityGroups.GetType())
                {
                    dxfSpline = entityGroups as DxfSpline;

                    string[] arrFitPoints = new string[dxfSpline.FitPoints.Count];
                    for (int i = 0; i < dxfSpline.FitPoints.Count; i++)
                    {
                        arrFitPoints[i] = dxfSpline.FitPoints[i].ToString();
                    }

                    int color;
                    if (dxfSpline.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfSpline.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfSpline.Color.Rgb;
                    }


                    CADSpline cADSpline = new CADSpline
                    {
                        parentHandle = dxfSpline.OwnerObjectSoftReference.Handle,
                        type         = dxfSpline.GetType().Name,
                        color        = color,
                        transform    = dxfSpline.Transform.DebugString,

                        fitPoints = arrFitPoints,
                    };

                    cadEntities.Add(cADSpline);
                }


                if (typeof(DxfCircle) == entityGroups.GetType())
                {
                    dxfCircle = entityGroups as DxfCircle;

                    int color;
                    if (dxfCircle.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfCircle.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfCircle.Color.Rgb;
                    }


                    CADCircle cADCircle = new CADCircle
                    {
                        parentHandle = dxfCircle.OwnerObjectSoftReference.Handle,
                        type         = dxfCircle.GetType().Name,
                        color        = color,
                        transform    = dxfCircle.Transform.DebugString,

                        center = dxfCircle.Center.ToString(),
                        radius = dxfCircle.Radius
                    };

                    cadEntities.Add(cADCircle);

                    kcircle.Add(dxfCircle);
                }

                if (typeof(DxfArc) == entityGroups.GetType())
                {
                    dxfArc = entityGroups as DxfArc;

                    int color;
                    if (dxfArc.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfArc.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfArc.Color.Rgb;
                    }

                    CADArc cADArc = new CADArc
                    {
                        parentHandle = dxfArc.OwnerObjectSoftReference.Handle,
                        type         = dxfArc.GetType().Name,
                        color        = color,
                        transform    = dxfArc.Transform.DebugString,

                        center     = dxfArc.Center.ToString(),
                        startAngle = dxfArc.StartAngle,
                        endAngle   = dxfArc.EndAngle,
                        radius     = dxfArc.Radius
                    };

                    cadEntities.Add(cADArc);
                }

                if (typeof(DxfEllipse) == entityGroups.GetType())
                {
                    dxfEllipse = entityGroups as DxfEllipse;

                    int color;
                    if (dxfEllipse.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfEllipse.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfEllipse.Color.Rgb;
                    }

                    CADEllipse cADEllipse = new CADEllipse
                    {
                        parentHandle = dxfEllipse.OwnerObjectSoftReference.Handle,
                        type         = dxfEllipse.GetType().Name,
                        color        = color,
                        transform    = dxfEllipse.Transform.DebugString,

                        center            = dxfEllipse.Center.ToString(),
                        majorAxisEndPoint = dxfEllipse.MajorAxisEndPoint.ToString(),
                        minorAxisEndPoint = dxfEllipse.MinorAxisEndPoint.ToString(),
                        startParameter    = dxfEllipse.StartParameter,
                        endParameter      = dxfEllipse.EndParameter
                    };

                    cadEntities.Add(cADEllipse);
                }



                if (typeof(DxfMText) == entityGroups.GetType())
                {
                    dxfMText = entityGroups as DxfMText;

                    int color;
                    if (dxfMText.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfMText.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfMText.Color.Rgb;
                    }


                    if (dxfMText.SimplifiedText == "C座一层平面图")
                    {
                        ktls.Add(dxfMText);
                    }


                    CADMText cADMText = new CADMText
                    {
                        parentHandle = dxfMText.OwnerObjectSoftReference.Handle,
                        type         = dxfMText.GetType().Name,
                        color        = color,
                        transform    = dxfMText.Transform.DebugString,

                        simplifiedText = dxfMText.SimplifiedText.ToString(),
                        fontStyle      = dxfMText.Style.ToString(),
                        size           = dxfMText.Height,

                        attachmentPoint = dxfMText.AttachmentPoint.ToString(),
                        boxHeight       = dxfMText.BoxHeight,
                        boxWidth        = dxfMText.BoxWidth
                    };

                    cadEntities.Add(cADMText);

                    if (dxfMText.SimplifiedText.ToString() == "图 纸 目 录")
                    {
                        //Console.WriteLine(222222);
                        ktls.Add(dxfMText);
                    }
                    if (dxfMText.SimplifiedText.ToString() == "JS-T5-302")
                    {
                        //Console.WriteLine(222222);
                        ktls.Add(dxfMText);
                    }
                }


                if (typeof(DxfText) == entityGroups.GetType())
                {
                    dxfText = entityGroups as DxfText;

                    int color;
                    if (dxfText.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfText.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfText.Color.Rgb;
                    }

                    CADText cADText = new CADText
                    {
                        parentHandle = dxfText.OwnerObjectSoftReference.Handle,
                        type         = dxfText.GetType().Name,
                        color        = color,
                        transform    = dxfText.Transform.DebugString,

                        simplifiedText = dxfText.SimplifiedText.ToString(),
                        fontStyle      = dxfText.Style.ToString(),
                        size           = dxfText.Height,

                        alignMentPoint1 = dxfText.AlignmentPoint1.ToString(),
                        rotationAngle   = dxfText.Rotation,
                    };


                    if (dxfText.SimplifiedText == "JS-T5-001 ")
                    {
                        ktest.Add(dxfText);
                    }

                    cadEntities.Add(cADText);
                }

                if (typeof(DxfInsert) == entityGroups.GetType())
                {
                    dxfInsert = entityGroups as DxfInsert;
                    kins.Add(dxfInsert);


                    if (dxfInsert.Block != null)
                    {
                        ulong count;
                        if (dxfInsert.Block != null)
                        {
                            count = dxfInsert.Block.Handle;
                        }
                        else
                        {
                            count = 0;
                        }

                        CADInsert cADInsert = new CADInsert();


                        cADInsert.parentHandle = dxfInsert.OwnerObjectSoftReference.Handle;
                        cADInsert.type         = dxfInsert.GetType().Name;
                        cADInsert.transform    = dxfInsert.Transform.DebugString;

                        cADInsert.insertPoint   = dxfInsert.InsertionPoint.ToString();
                        cADInsert.rotationAngle = dxfInsert.Rotation;
                        cADInsert.insertName    = dxfInsert.Block.Name;
                        cADInsert.nowHandle     = count;
                        cADInsert.insertScale   = dxfInsert.ScaleFactor.ToString();

                        cadEntities.Add(cADInsert);

                        FindEntities(dxfInsert.Block.Entities);
                    }
                }



                if (typeof(DxfAttributeDefinition) == entityGroups.GetType())
                {
                    dxfAttributeDefinition = entityGroups as DxfAttributeDefinition;
                    //Console.WriteLine(dxfAttributeDefinition);
                }

                if (typeof(DxfDimension.Linear) == entityGroups.GetType())
                {
                    Console.WriteLine(11111);
                }
            }
        }
Пример #22
0
        private static List <DxfEntity> OffsetToNest(IList <DxfEntity> dxfEntities, DxfPoint pivot, DxfPoint offset, double rotationAngle)
        {
            List <DxfEntity> dxfreturn = new List <DxfEntity>();
            List <DxfPoint>  tmpPts;

            foreach (DxfEntity entity in dxfEntities)
            {
                switch (entity.EntityType)
                {
                case DxfEntityType.Arc:
                    DxfArc dxfArc = (DxfArc)entity;
                    dxfArc.Center      = RotateLocation(rotationAngle, dxfArc.Center);
                    dxfArc.Center     += offset;
                    dxfArc.StartAngle += rotationAngle;
                    dxfArc.EndAngle   += rotationAngle;
                    dxfreturn.Add(dxfArc);
                    break;

                case DxfEntityType.ArcAlignedText:
                    DxfArcAlignedText dxfArcAligned = (DxfArcAlignedText)entity;
                    dxfArcAligned.CenterPoint  = RotateLocation(rotationAngle, dxfArcAligned.CenterPoint);
                    dxfArcAligned.CenterPoint += offset;
                    dxfArcAligned.StartAngle  += rotationAngle;
                    dxfArcAligned.EndAngle    += rotationAngle;
                    dxfreturn.Add(dxfArcAligned);
                    break;

                case DxfEntityType.Attribute:
                    DxfAttribute dxfAttribute = (DxfAttribute)entity;
                    dxfAttribute.Location  = RotateLocation(rotationAngle, dxfAttribute.Location);
                    dxfAttribute.Location += offset;
                    dxfreturn.Add(dxfAttribute);
                    break;

                case DxfEntityType.AttributeDefinition:
                    DxfAttributeDefinition dxfAttributecommon = (DxfAttributeDefinition)entity;
                    dxfAttributecommon.Location  = RotateLocation(rotationAngle, dxfAttributecommon.Location);
                    dxfAttributecommon.Location += offset;
                    dxfreturn.Add(dxfAttributecommon);
                    break;

                case DxfEntityType.Circle:
                    DxfCircle dxfCircle = (DxfCircle)entity;
                    dxfCircle.Center  = RotateLocation(rotationAngle, dxfCircle.Center);
                    dxfCircle.Center += offset;
                    dxfreturn.Add(dxfCircle);
                    break;

                case DxfEntityType.Ellipse:
                    DxfEllipse dxfEllipse = (DxfEllipse)entity;
                    dxfEllipse.Center  = RotateLocation(rotationAngle, dxfEllipse.Center);
                    dxfEllipse.Center += offset;
                    dxfreturn.Add(dxfEllipse);
                    break;

                case DxfEntityType.Image:
                    DxfImage dxfImage = (DxfImage)entity;
                    dxfImage.Location  = RotateLocation(rotationAngle, dxfImage.Location);
                    dxfImage.Location += offset;

                    dxfreturn.Add(dxfImage);
                    break;

                case DxfEntityType.Leader:
                    DxfLeader dxfLeader = (DxfLeader)entity;
                    tmpPts = new List <DxfPoint>();

                    foreach (DxfPoint vrt in dxfLeader.Vertices)
                    {
                        var tmppnt = RotateLocation(rotationAngle, vrt);
                        tmppnt += offset;
                        tmpPts.Add(tmppnt);
                    }

                    dxfLeader.Vertices.Clear();
                    dxfLeader.Vertices.Concat(tmpPts);
                    dxfreturn.Add(dxfLeader);
                    break;

                case DxfEntityType.Line:
                    DxfLine dxfLine = (DxfLine)entity;
                    dxfLine.P1  = RotateLocation(rotationAngle, dxfLine.P1);
                    dxfLine.P2  = RotateLocation(rotationAngle, dxfLine.P2);
                    dxfLine.P1 += offset;
                    dxfLine.P2 += offset;
                    dxfreturn.Add(dxfLine);
                    break;

                case DxfEntityType.LwPolyline:
                    DxfPolyline dxfPoly = (DxfPolyline)entity;
                    foreach (DxfVertex vrt in dxfPoly.Vertices)
                    {
                        vrt.Location  = RotateLocation(rotationAngle, vrt.Location);
                        vrt.Location += offset;
                    }

                    dxfreturn.Add(dxfPoly);
                    break;

                case DxfEntityType.MLine:
                    DxfMLine mLine = (DxfMLine)entity;
                    tmpPts            = new List <DxfPoint>();
                    mLine.StartPoint += offset;

                    mLine.StartPoint = RotateLocation(rotationAngle, mLine.StartPoint);

                    foreach (DxfPoint vrt in mLine.Vertices)
                    {
                        var tmppnt = RotateLocation(rotationAngle, vrt);
                        tmppnt += offset;
                        tmpPts.Add(tmppnt);
                    }

                    mLine.Vertices.Clear();
                    mLine.Vertices.Concat(tmpPts);
                    dxfreturn.Add(mLine);
                    break;

                case DxfEntityType.Polyline:
                    DxfPolyline polyline = (DxfPolyline)entity;

                    List <DxfVertex> verts = new List <DxfVertex>();
                    foreach (DxfVertex vrt in polyline.Vertices)
                    {
                        var tmppnt = vrt;
                        tmppnt.Location  = RotateLocation(rotationAngle, tmppnt.Location);
                        tmppnt.Location += offset;
                        verts.Add(tmppnt);
                    }

                    DxfPolyline polyout = new DxfPolyline(verts);
                    polyout.Location = polyline.Location + offset;
                    polyout.IsClosed = polyline.IsClosed;
                    polyout.Layer    = polyline.Layer;
                    dxfreturn.Add(polyout);

                    break;

                case DxfEntityType.Body:
                case DxfEntityType.DgnUnderlay:
                case DxfEntityType.Dimension:
                case DxfEntityType.DwfUnderlay:
                case DxfEntityType.Face:
                case DxfEntityType.Helix:
                case DxfEntityType.Insert:
                case DxfEntityType.Light:
                case DxfEntityType.ModelerGeometry:
                case DxfEntityType.MText:
                case DxfEntityType.OleFrame:
                case DxfEntityType.Ole2Frame:
                case DxfEntityType.PdfUnderlay:
                case DxfEntityType.Point:
                case DxfEntityType.ProxyEntity:
                case DxfEntityType.Ray:
                case DxfEntityType.Region:
                case DxfEntityType.RText:
                case DxfEntityType.Section:
                case DxfEntityType.Seqend:
                case DxfEntityType.Shape:
                case DxfEntityType.Solid:
                case DxfEntityType.Spline:
                case DxfEntityType.Text:
                case DxfEntityType.Tolerance:
                case DxfEntityType.Trace:
                case DxfEntityType.Underlay:
                case DxfEntityType.Vertex:
                case DxfEntityType.WipeOut:
                case DxfEntityType.XLine:
                    throw new ArgumentException("unsupported entity type: " + entity.EntityType);
                }
            }

            return(dxfreturn);
        }
Пример #23
0
        public void DrawArc(
            Pen pen,
            float x,
            float y,
            float width,
            float height,
            float startAngle,
            float sweepAngle)
        {
            double a    = -(double)startAngle * System.Math.PI / 180.0;
            double num1 = -(double)sweepAngle * System.Math.PI / 180.0;
            double b    = a + num1;

            if (num1 < 0.0)
            {
                MathUtil.Swap(ref a, ref b);
            }
            double radius = 0.5 * (double)width;

            WW.Math.Point3D center = new WW.Math.Point3D((double)x + radius, -(double)y - 0.5 * (double)height, 0.0);
            if ((double)width == (double)height)
            {
                if (MathUtil.AreApproxEqual(System.Math.Abs(num1), 2.0 * System.Math.PI))
                {
                    DxfCircle dxfCircle = new DxfCircle(center, radius);
                    dxfCircle.Color = EntityColor.CreateFrom((ArgbColor)pen.Color);
                    this.list_0.Add((DxfEntity)dxfCircle);
                }
                else
                {
                    DxfArc dxfArc = new DxfArc(center, radius, a, b);
                    dxfArc.Color = EntityColor.CreateFrom((ArgbColor)pen.Color);
                    this.list_0.Add((DxfEntity)dxfArc);
                }
            }
            else
            {
                double   num2 = (double)System.Math.Abs(width);
                double   num3 = (double)System.Math.Abs(height);
                double   minorToMajorRatio;
                Vector3D majorAxisEndPoint;
                double   num4;
                double   num5;
                if (num2 > num3)
                {
                    minorToMajorRatio = num3 / num2;
                    majorAxisEndPoint = new Vector3D(0.5 * num2, 0.0, 0.0);
                    num4 = a;
                    num5 = b;
                }
                else
                {
                    minorToMajorRatio = num2 / num3;
                    majorAxisEndPoint = new Vector3D(0.0, 0.5 * num3, 0.0);
                    if (MathUtil.AreApproxEqual(System.Math.Abs(num1), 2.0 * System.Math.PI))
                    {
                        num4 = 0.0;
                        num5 = 2.0 * System.Math.PI;
                    }
                    else
                    {
                        num4 = a - System.Math.PI / 2.0;
                        num5 = b - System.Math.PI / 2.0;
                    }
                }
                DxfEllipse dxfEllipse = new DxfEllipse(center, majorAxisEndPoint, minorToMajorRatio);
                dxfEllipse.Color          = EntityColor.CreateFrom((ArgbColor)pen.Color);
                dxfEllipse.StartParameter = num4;
                dxfEllipse.EndParameter   = num5;
                this.list_0.Add((DxfEntity)dxfEllipse);
            }
        }
Пример #24
0
        public completeDxfStruct processDxfFile(string in_obtainedFileName)
        {
            completeDxfStruct valueToReturn = new completeDxfStruct();
            DxfFile           dxfFile;

            using (System.IO.FileStream fs = new System.IO.FileStream(in_obtainedFileName, System.IO.FileMode.Open))
            {
                dxfFile = DxfFile.Load(fs);
                IList <DxfBlock>  allBlocks = dxfFile.Blocks;
                IList <DxfEntity> usedEntities;
                if ((allBlocks.Count == 0) || (allBlocks[0].Name.ToUpper().Contains("MODEL") == false))
                {
                    usedEntities = dxfFile.Entities;
                }
                else
                {
                    usedEntities = allBlocks[0].Entities;
                }

                foreach (DxfEntity entity in dxfFile.Entities)
                {
                    switch (entity.EntityType)
                    {
                    case DxfEntityType.Line:
                    {
                        DxfLine   line       = (DxfLine)entity;
                        MyDxfLine TransfLine = new MyDxfLine(line.P1.X, line.P1.Y, line.P2.X, line.P2.Y);
                        valueToReturn.addDxfDrawingEntry(TransfLine);
                        break;
                    }

                    case DxfEntityType.Arc:
                    {
                        DxfArc   arc       = (DxfArc)entity;
                        MyDxfArc TransfArc = new MyDxfArc(arc.Center.X, arc.Center.Y, arc.StartAngle, arc.EndAngle, arc.Radius);
                        valueToReturn.addDxfDrawingEntry(TransfArc);
                        break;
                    }

                    case DxfEntityType.LwPolyline: {    //polyline. It has vertices.
                        DxfLwPolyline polylineS             = entity as DxfLwPolyline;
                        int           totalnumberOfVertices = polylineS.Vertices.Count;
                        for (int i = 0; i < totalnumberOfVertices - 1; i++)
                        {         //iterate through vertices, taking them by 2. A figure is between these two
                            DxfLwPolylineVertex point1 = polylineS.Vertices[i];
                            DxfLwPolylineVertex point2 = polylineS.Vertices[i + 1];
                            if (point1.Bulge == 0)
                            {
                                MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y);
                                valueToReturn.addDxfDrawingEntry(TransfLine);
                            }
                            else             //it is arc
                            // The bulge is the tangent of one fourth the included angle for an arc segment,
                            // made negative if the arc goes clockwise from the start point to the endpoint.
                            // A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle
                            {
                                double angleOfArc = System.Math.Atan(point1.Bulge) * 180.0 / Math.PI * 4;
                                double startAngle = Math.Atan(point1.Y / point1.X) * 180.0 / Math.PI;
                                //double endAngle =
                            }
                        }

                        break;
                    }

                    case DxfEntityType.Polyline:  {
                        //https://github.com/IxMilia/Dxf/issues/90
                        DxfPolyline polyline = entity as DxfPolyline;

                        break;
                    }
                    }
                }
            }
            return(valueToReturn);
        }
Пример #25
0
 public static Arc ToArc(this DxfArc arc)
 {
     return(new Arc(arc.Center.ToPoint(), arc.Radius, arc.StartAngle, arc.EndAngle, arc.Normal.ToVector(), arc.GetEntityColor(), arc, arc.Thickness));
 }
Пример #26
0
        /// <summary>
        /// 门把手绘制
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="DLocation"></param>
        public static void Draw(DxfModel dxf, DLocation DLocation)
        {
            double factor = 0.05f;
             double distance = 30;
            //底部小圆的圆心
             Point3D sDxfCircle = new Point3D(DLocation.X + 10 * factor, DLocation.Y, DLocation.Z);
            //上部同心圆圆心
             Point3D bDxfCircle = new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor + distance*factor, DLocation.Z);

             double alpha = Math.Asin(3 / distance);
             double beta = Math.Acos(0.8);

             Point3D v1 = new Point3D(
                 DLocation.X + 10 * factor - double.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                 DLocation.Y + 5 * factor - double.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                 DLocation.Z);

             Point3D v2 = new Point3D(
                  DLocation.X + 10 * factor + double.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                  DLocation.Y + 5 * factor - double.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                  DLocation.Z);

             Point3D v4 = new Point3D(
                 DLocation.X + 10 * factor -double.Parse((8*factor* Math.Cos(alpha)).ToString()),
                 DLocation.Y + 5 * factor + distance * factor - double.Parse((8 * factor * Math.Sin(alpha)).ToString()),
                 DLocation.Z
                 );

             Point3D v5 = new Point3D(
             DLocation.X + 10 * factor  + double.Parse((8*factor*Math.Cos(alpha)).ToString()),
             DLocation.Y + 5 * factor + distance * factor - double.Parse((8 * factor * Math.Sin(alpha)).ToString()),
             DLocation.Z
             );
             DxfLine DxfLine14 = new DxfLine(v1, v4);
             dxf.Entities.Add(DxfLine14);

             DxfLine DxfLine25 = new DxfLine(v2, v5);
             dxf.Entities.Add(DxfLine25);

             //DxfArc
             DxfArc DxfArc = new DxfArc(
                 new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor, DLocation.Z),
                 5 * factor, Convert.ToInt32(180 + alpha * 180 / Math.PI), Convert.ToInt32(360 - alpha * 180 / Math.PI));
             dxf.Entities.Add(DxfArc);

             //DxfArcup
             DxfArc DxfArcup = new DxfArc(
                 new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor + distance * factor, DLocation.Z),
                 8 * factor, Convert.ToInt32(-alpha * 180 / Math.PI), Convert.ToInt32(180 + alpha * 180 / Math.PI));
             dxf.Entities.Add(DxfArcup);

             //DxfArcround
             DxfArc DxfArcround = new DxfArc(
                 new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor + distance * factor, DLocation.Z),
                 10 * factor,
                 Convert.ToInt32(-(alpha +beta) * 180 / Math.PI),
                 Convert.ToInt32(180 + (alpha +beta) * 180 / Math.PI));
             dxf.Entities.Add(DxfArcround);

             //DxfCircle
             Point3D centerWCS = new Point3D(DLocation.X+10*factor, DLocation.Y+5*factor+distance*factor, DLocation.Z);
             DxfCircle DxfCircle = new DxfCircle((Point3D)centerWCS, 7 * factor);
             dxf.Entities.Add(DxfCircle);

             //上部同心圆圆心
             Point3D t1 = new Point3D(
                 DLocation.X + 8 * factor,
                 DLocation.Y + 5 * factor + (distance - 7) * factor * 0.7f,
                 DLocation.Z);
             Point3D t2 = new Point3D(
                 DLocation.X + 8 * factor,
                 DLocation.Y + 5 * factor + (distance - 7) * factor * 0.5f,
                 DLocation.Z);
             Point3D t3 = new Point3D(
                 DLocation.X + 8 * factor,
                 DLocation.Y + 5 * factor + (distance - 7) * factor * 0.3f,
                 DLocation.Z);
             Point3D t4 = new Point3D(
                 DLocation.X + 8 * factor,
                 DLocation.Y + 5 * factor + (distance - 7) * factor * 0.1f,
                 DLocation.Z);

             //DxfText
             DxfText DxfText1 = new DxfText("A", t1, 0.2f);
             dxf.Entities.Add(DxfText1);

             //DxfText
             DxfText DxfText2 = new DxfText("A", t2, 0.2f);
             dxf.Entities.Add(DxfText2);

             //DxfText
             DxfText DxfText3 = new DxfText("O", t3, 0.2f);
             dxf.Entities.Add(DxfText3);

             //DxfText
             DxfText DxfText4 = new DxfText("N", t4, 0.2f);
             dxf.Entities.Add(DxfText4);
        }
Пример #27
0
 public virtual void Visit(DxfArc arc)
 {
     this.VisitEntity((DxfEntity)arc);
 }
Пример #28
0
 public void Visit(DxfArc arc)
 {
     this.method_0((DxfEntity)arc);
 }
Пример #29
0
 public void Visit(DxfArc arc)
 {
     this.bool_0 = true;
 }