コード例 #1
0
ファイル: DxfArc.cs プロジェクト: tevfikoguz/dxf
        public static bool TryCreateFromVertices(DxfVertex v1, DxfVertex v2, out DxfArc arc)
        {
            // To the best of my knowledge, 3D Arcs are not defined via z but a normal vector.
            // Thus, simply ignore non-zero z values.

            var bulge = v1.Bulge;

            if (Math.Abs(bulge) < 1e-10)
            {
                //throw new ArgumentException("arc bulge too small: " + bulge);
                arc = null;
                return(false);
            }

            var startPoint = v1.Location;
            var endPoint   = v2.Location;
            var delta      = endPoint - startPoint;
            var length     = delta.Length;

            if (length <= double.Epsilon)
            {
                //throw new ArgumentException("arc startpoint == endpoint");
                arc = null;
                return(false);
            }

            var alpha     = 4.0 * Math.Atan(bulge);
            var radius    = length / (2.0 * Math.Abs(Math.Sin(alpha * 0.5)));
            var deltaNorm = delta.Normalize();
            int bulgeSign = Math.Sign(bulge);

            // 2D only solution (z=0)
            var normal = new DxfVector(-deltaNorm.Y, +deltaNorm.X, 0.0) * bulgeSign;
            var center = (startPoint + endPoint) * 0.5
                         + normal * Math.Cos(alpha * 0.5) * radius;

            // bulge<0 indicates CW arc, but DxfArc is CCW always
            double startAngleDeg;
            double endAngleDeg;

            if (bulge > 0)
            {
                startAngleDeg = NormalizedAngleDegree(startPoint, center);
                endAngleDeg   = NormalizedAngleDegree(endPoint, center);
            }
            else
            {
                endAngleDeg   = NormalizedAngleDegree(startPoint, center);
                startAngleDeg = NormalizedAngleDegree(endPoint, center);
            }

            arc = new DxfArc(center, radius, startAngleDeg, endAngleDeg);
            return(true);
        }
コード例 #2
0
        private static bool TryGetArcBoundingBox(DxfVertex v1, DxfVertex v2, out DxfBoundingBox bbox)
        {
            if (!DxfArc.TryCreateFromVertices(v1, v2, out var arc))
            {
                bbox = default(DxfBoundingBox);
                return(false);
            }

            var boundingBox = arc.GetBoundingBox();

            if (!boundingBox.HasValue)
            {
                bbox = default(DxfBoundingBox);
                return(false);
            }

            bbox = boundingBox.Value;
            return(true);
        }
コード例 #3
0
ファイル: DxfPolyline.cs プロジェクト: zakb120/dxf
        private IEnumerable <DxfPoint> ProcessVertexPair(DxfVertex vertex1, DxfVertex vertex2)
        {
            if (Math.Abs(vertex1.Bulge) <= 1e-10)
            {
                yield return(vertex1.Location);
            }
            else
            {
                // the segment between `vertex.Location` and `next.Location` is an arc
                if (TryGetArcBoundingBox(vertex1, vertex2, out var bbox))
                {
                    yield return(bbox.MinimumPoint);

                    yield return(bbox.MaximumPoint);
                }
                else
                {
                    // fallback if points are too close / bulge is tiny
                    yield return(vertex1.Location);
                }
            }
        }
コード例 #4
0
ファイル: DxfArc.cs プロジェクト: zakb120/dxf
 public static bool TryCreateFromVertices(DxfVertex v1, DxfVertex v2, out DxfArc arc)
 {
     return(TryCreateFromVertices(v1.Location.X, v1.Location.Y, v1.Bulge, v2.Location.X, v2.Location.Y, out arc));
 }
コード例 #5
0
        internal static DxfEntity FromBuffer(DxfCodePairBufferReader buffer)
        {
            var first = buffer.Peek();

            buffer.Advance();
            DxfEntity entity;

            switch (first.StringValue)
            {
            case "3DFACE":
                entity = new Dxf3DFace();
                break;

            case "3DSOLID":
                entity = new Dxf3DSolid();
                break;

            case "ACAD_PROXY_ENTITY":
                entity = new DxfProxyEntity();
                break;

            case "ARC":
                entity = new DxfArc();
                break;

            case "ARCALIGNEDTEXT":
                entity = new DxfArcAlignedText();
                break;

            case "ATTDEF":
                entity = new DxfAttributeDefinition();
                break;

            case "ATTRIB":
                entity = new DxfAttribute();
                break;

            case "BODY":
                entity = new DxfBody();
                break;

            case "CIRCLE":
                entity = new DxfCircle();
                break;

            case "DIMENSION":
                entity = new DxfDimensionBase();
                break;

            case "ELLIPSE":
                entity = new DxfEllipse();
                break;

            case "HELIX":
                entity = new DxfHelix();
                break;

            case "IMAGE":
                entity = new DxfImage();
                break;

            case "INSERT":
                entity = new DxfInsert();
                break;

            case "LEADER":
                entity = new DxfLeader();
                break;

            case "LIGHT":
                entity = new DxfLight();
                break;

            case "LINE":
            case "3DLINE":
                entity = new DxfLine();
                break;

            case "LWPOLYLINE":
                entity = new DxfLwPolyline();
                break;

            case "MLINE":
                entity = new DxfMLine();
                break;

            case "MTEXT":
                entity = new DxfMText();
                break;

            case "OLEFRAME":
                entity = new DxfOleFrame();
                break;

            case "OLE2FRAME":
                entity = new DxfOle2Frame();
                break;

            case "POINT":
                entity = new DxfModelPoint();
                break;

            case "POLYLINE":
                entity = new DxfPolyline();
                break;

            case "RAY":
                entity = new DxfRay();
                break;

            case "REGION":
                entity = new DxfRegion();
                break;

            case "RTEXT":
                entity = new DxfRText();
                break;

            case "SECTION":
                entity = new DxfEntitySection();
                break;

            case "SEQEND":
                entity = new DxfSeqend();
                break;

            case "SHAPE":
                entity = new DxfShape();
                break;

            case "SOLID":
                entity = new DxfSolid();
                break;

            case "SPLINE":
                entity = new DxfSpline();
                break;

            case "TEXT":
                entity = new DxfText();
                break;

            case "TOLERANCE":
                entity = new DxfTolerance();
                break;

            case "TRACE":
                entity = new DxfTrace();
                break;

            case "UNDERLAY":
                entity = new DxfUnderlay();
                break;

            case "DGNUNDERLAY":
                entity = new DxfDgnUnderlay();
                break;

            case "DWFUNDERLAY":
                entity = new DxfDwfUnderlay();
                break;

            case "PDFUNDERLAY":
                entity = new DxfPdfUnderlay();
                break;

            case "VERTEX":
                entity = new DxfVertex();
                break;

            case "WIPEOUT":
                entity = new DxfWipeout();
                break;

            case "XLINE":
                entity = new DxfXLine();
                break;

            default:
                SwallowEntity(buffer);
                entity = null;
                break;
            }

            if (entity != null)
            {
                entity = entity.PopulateFromBuffer(buffer);
            }

            return(entity);
        }
コード例 #6
0
ファイル: DxfEntityGenerated.cs プロジェクト: nakijun/Dxf
        internal static DxfEntity FromBuffer(DxfCodePairBufferReader buffer)
        {
            var first = buffer.Peek();
            buffer.Advance();
            DxfEntity entity;
            switch (first.StringValue)
            {
                case "3DFACE":
                    entity = new Dxf3DFace();
                    break;
                case "3DSOLID":
                    entity = new Dxf3DSolid();
                    break;
                case "ACAD_PROXY_ENTITY":
                    entity = new DxfProxyEntity();
                    break;
                case "ARC":
                    entity = new DxfArc();
                    break;
                case "ARCALIGNEDTEXT":
                    entity = new DxfArcAlignedText();
                    break;
                case "ATTDEF":
                    entity = new DxfAttributeDefinition();
                    break;
                case "ATTRIB":
                    entity = new DxfAttribute();
                    break;
                case "BODY":
                    entity = new DxfBody();
                    break;
                case "CIRCLE":
                    entity = new DxfCircle();
                    break;
                case "DIMENSION":
                    entity = new DxfDimensionBase();
                    break;
                case "ELLIPSE":
                    entity = new DxfEllipse();
                    break;
                case "HELIX":
                    entity = new DxfHelix();
                    break;
                case "IMAGE":
                    entity = new DxfImage();
                    break;
                case "INSERT":
                    entity = new DxfInsert();
                    break;
                case "LEADER":
                    entity = new DxfLeader();
                    break;
                case "LIGHT":
                    entity = new DxfLight();
                    break;
                case "LINE":
                case "3DLINE":
                    entity = new DxfLine();
                    break;
                case "LWPOLYLINE":
                    entity = new DxfLwPolyline();
                    break;
                case "MLINE":
                    entity = new DxfMLine();
                    break;
                case "MLEADERSTYLE":
                    entity = new DxfMLeaderStyle();
                    break;
                case "MTEXT":
                    entity = new DxfMText();
                    break;
                case "OLEFRAME":
                    entity = new DxfOleFrame();
                    break;
                case "OLE2FRAME":
                    entity = new DxfOle2Frame();
                    break;
                case "POINT":
                    entity = new DxfModelPoint();
                    break;
                case "POLYLINE":
                    entity = new DxfPolyline();
                    break;
                case "RAY":
                    entity = new DxfRay();
                    break;
                case "REGION":
                    entity = new DxfRegion();
                    break;
                case "RTEXT":
                    entity = new DxfRText();
                    break;
                case "SECTION":
                    entity = new DxfEntitySection();
                    break;
                case "SEQEND":
                    entity = new DxfSeqend();
                    break;
                case "SHAPE":
                    entity = new DxfShape();
                    break;
                case "SOLID":
                    entity = new DxfSolid();
                    break;
                case "SPLINE":
                    entity = new DxfSpline();
                    break;
                case "SUN":
                    entity = new DxfSun();
                    break;
                case "TEXT":
                    entity = new DxfText();
                    break;
                case "TOLERANCE":
                    entity = new DxfTolerance();
                    break;
                case "TRACE":
                    entity = new DxfTrace();
                    break;
                case "UNDERLAY":
                    entity = new DxfUnderlay();
                    break;
                case "DGNUNDERLAY":
                    entity = new DxfDgnUnderlay();
                    break;
                case "DWFUNDERLAY":
                    entity = new DxfDwfUnderlay();
                    break;
                case "PDFUNDERLAY":
                    entity = new DxfPdfUnderlay();
                    break;
                case "VERTEX":
                    entity = new DxfVertex();
                    break;
                case "WIPEOUT":
                    entity = new DxfWipeout();
                    break;
                case "XLINE":
                    entity = new DxfXLine();
                    break;
                default:
                    SwallowEntity(buffer);
                    entity = null;
                    break;
            }

            if (entity != null)
            {
                entity = entity.PopulateFromBuffer(buffer);
            }

            return entity;
        }
コード例 #7
0
ファイル: DxbWriter.cs プロジェクト: nakijun/Dxf
 private void WriteVertex(DxfVertex vertex)
 {
     WriteItemType(DxbItemType.Vertex);
     WriteN(vertex.Location.X);
     WriteN(vertex.Location.Y);
 }