dxfexport.cs

来自「导出dxf的原码类库,根据国外一个反编译的」· CS 代码 · 共 265 行

CS
265
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SunDXFDll
{
    public class DXFExport
    {
        // Fields
        public static float accuracy = 1E-06f;
        public static bool alternativeBlack = true;
        public static AutoCADVersion autoCADVer = AutoCADVersion.R2000;
        private ArrayList blkRecs = new ArrayList();
        private string block;
        private bool blockMode;
        private ArrayList blocks = new ArrayList();
        public ArrayList current = new ArrayList();
        private DXFLayer currentLayer;
        public static int[] DXFLineWeights = new int[] { 
        0, 5, 9, 13, 15, 0x12, 20, 0x19, 30, 0x23, 40, 50, 0x35, 60, 70, 80, 
        90, 100, 0x6a, 120, 140, 0x9e, 200, 0xd3
     };
        public int ellipses;
        private ArrayList entities = new ArrayList();
        private ArrayList figuresList;
        public float fOffset;
        private int handle;
        public static bool isParseWhite = false;
        private ArrayList layers;
        private DXFPoint limMax = new DXFPoint();
        private DXFPoint limMin = new DXFPoint();
        private ArrayList lTypes = new ArrayList();
        private string nameCurrentLayer;
        public static float offsetX = 0f;
        public static float offsetY = 0f;
        public float penWidthRatio;
        public static bool use01MM = false;

        // Methods
        public DXFExport()
        {
            this.current = this.entities;
            this.figuresList = new ArrayList();
            this.handle = 0x20;
            this.layers = new ArrayList();
            this.layers.Add(new DXFLayer("0"));
            this.SetCurrentLayer((DXFLayer)this.layers[0]);
            this.fOffset = 300f;
            this.penWidthRatio = -1f;
        }

        public void AddThickness(DXFData Data)
        {
            if (autoCADVer == AutoCADVersion.R2000)
            {
                int num;
                if (Data.text != "")
                {
                    this.current.Add("  6");
                    this.current.Add(Data.text);
                }
                try
                {
                    if (use01MM)
                    {
                        num = (int)Math.Round((double)Data.thickness);
                    }
                    else
                    {
                        num = ((int)Math.Round((double)Data.thickness)) * 10;
                        if (this.penWidthRatio > 0f)
                        {
                            num = (int)Math.Round((double)((Data.thickness * 100f) * this.penWidthRatio));
                        }
                    }
                }
                catch
                {
                    num = 100;
                }
                if (num >= 5)
                {
                    if (num >= 0xd3)
                    {
                        num = 0xd3;
                    }
                    else
                    {
                        for (int i = 0; i < (DXFLineWeights.Length - 1); i++)
                        {
                            if (num < DXFLineWeights[i])
                            {
                                num = DXFLineWeights[i - 1];
                                break;
                            }
                        }
                        this.AddInt(370, num);
                    }
                }
            }
        }

        public void AddColor(DXFData Data)
        {
            if ((Data.color != 0x100) && (Data.color != 0))
            {
                this.AddInt(0x3e, Data.color);
            }
        }
        public void AddInt(int code, int Value)
        {
            string str = this.SpecialFormat(code);
            this.current.Add(str);
            this.current.Add("" + Value);
        }
        public void AddName(string aName, string aSub)
        {
            this.current.Add("  0");
            this.current.Add(aName);
            this.AddHandle();
            if (aName == DXFTables.sHatchEntity)
            {
                this.current.Add("330");
                this.current.Add("1F");
            }
            this.current.Add("100");
            if ((this.current == this.lTypes) || (this.current == this.blkRecs))
            {
                this.current.Add("AcDbSymbolTableRecord");
            }
            else
            {
                this.current.Add("AcDbEntity");
                this.current.Add("  8");
                this.current.Add(this.nameCurrentLayer);
            }
            this.current.Add("100");
            this.current.Add(aSub);
        }
        public void AddHandle()
        {
            string str = string.Format("{0:X}", this.handle);
            this.AddString(5, str);
            this.handle++;
        }

        public void AddString(int code, string str)
        {
            string str2 = this.SpecialFormat(code);
            this.current.Add(str2);
            this.current.Add(str);
        }

        private string SpecialFormat(int aDt)
        {
            string str = "";
            if (aDt < 100)
            {
                if (aDt < 10)
                {
                    str = "  ";
                }
                else
                {
                    str = " ";
                }
            }
            return (str + aDt);
        }
        private void SetCurrentLayer(DXFLayer Value)
        {
            this.currentLayer = Value;
            this.nameCurrentLayer = this.currentLayer.Name;
            if (this.layers.IndexOf(Value) == -1)
            {
                this.layers.Add(this.currentLayer);
            }
        }
        public void Add3DPoint(int code, DXFPoint p)
        {
            this.AddPoint(code, p);
            if (p.Z != 0f)
            {
                this.AddFloat(code + 20, p.Z);
            }
        }

        public void AddPoint(int code, DXFPoint P)
        {
            this.AddFloat(code, this.MM(P.X));
            this.AddFloat(code + 10, this.MM(P.Y));
            if (this.current == this.entities)
            {
                if (this.limMin.X > P.X)
                {
                    this.limMin.X = P.X;
                }
                if (this.limMin.Y > P.Y)
                {
                    this.limMin.Y = P.Y;
                }
                if (this.limMax.X < P.X)
                {
                    this.limMax.X = P.X;
                }
                if (this.limMax.Y < P.Y)
                {
                    this.limMax.Y = P.Y;
                }
            }
        }

        public void AddFloat(int code, float Value)
        {
            string str = this.SpecialFormat(code);
            this.current.Add(str);
            str = "" + Value;
            this.current.Add(str.Replace(',', '.'));
        }
        // Properties
        //public string Block
        //{
        //    get
        //    {
        //        return this.block;
        //    }
        //    set
        //    {
        //        this.BeginBlock(value);
        //    }
        //}

        public DXFLayer CurrentLayer
        {
            get
            {
                return this.currentLayer;
            }
            set
            {
                this.currentLayer = (DXFLayer)value.Clone();
                this.nameCurrentLayer = this.currentLayer.Name;
                if (this.layers.IndexOf(value) == -1)
                {
                    this.layers.Add(this.currentLayer);
                }
            }
        }

        public float PenWidthRatio
        {
            get
            {
                return this.penWidthRatio;
            }
            set
            {
                this.penWidthRatio = value;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?