示例#1
0
 private void ValidateColor(DxfColor value)
 {
     if (!value.IsIndex)
     {
         throw new ArgumentOutOfRangeException(nameof(value), "Layer colors must be an indexable value: [1, 255]");
     }
 }
示例#2
0
 public DxfLayer()
     : base()
 {
     Color            = DxfColor.FromIndex(7);
     LineTypeName     = "CONTINUOUS";
     IsLayerPlotted   = true;
     LineWeight       = new DxfLineWeight();
     PlotStylePointer = 0u;
     MaterialHandle   = 0u;
 }
示例#3
0
 public DxfViewPort()
     : base()
 {
     LowerLeft           = DxfPoint.Origin;
     UpperRight          = new DxfPoint(1.0, 1.0, 0.0);
     ViewCenter          = DxfPoint.Origin;
     SnapBasePoint       = DxfPoint.Origin;
     SnapSpacing         = new DxfVector(1.0, 1.0, 0.0);
     GridSpacing         = new DxfVector(1.0, 1.0, 0.0);
     ViewDirection       = DxfVector.ZAxis;
     TargetViewPoint     = DxfPoint.Origin;
     ViewHeight          = 1.0;
     ViewPortAspectRatio = 1.0;
     LensLength          = 50.0;
     FrontClippingPlane  = 0.0;
     BackClippingPlane   = 0.0;
     ViewHeight          = 1.0;
     SnapRotationAngle   = 0.0;
     ViewTwistAngle      = 0.0;
     ViewMode            = 0;
     CircleSides         = 1000;
     FastZoom            = true;
     UCSIcon             = 3;
     SnapOn                   = false;
     GridOn                   = false;
     SnapStyle                = DxfSnapStyle.Standard;
     SnapIsometricPlane       = DxfSnapIsometricPlane.Left;
     PlotStyleSheet           = null;
     RenderMode               = DxfViewRenderMode.Classic2D;
     HasOwnUCS                = false;
     UCSOrigin                = DxfPoint.Origin;
     UCSXAxis                 = DxfVector.XAxis;
     UCSYAxis                 = DxfVector.YAxis;
     OrthographicViewType     = DxfOrthographicViewType.None;
     UCSElevation             = 0.0;
     UCSHandle                = 0u;
     BaseUCSHandle            = 0u;
     ShadePlotSetting         = DxfShadeEdgeMode.FacesShadedEdgeNotHighlighted;
     MajorGridLines           = false;
     BackgroundObjectPointer  = 0u;
     ShadePlotObjectPointer   = 0u;
     VisualStyleObjectPointer = 0u;
     IsDefaultLightingOn      = true;
     DefaultLightingType      = DxfDefaultLightingType.OneDistantLight;
     Brightness               = 0.0;
     Contrast                 = 0.0;
     AmbientColor             = DxfColor.FromRawValue(7);
     AmbientColorInt          = 0;
     AmbientColorName         = "BLACK";
 }
        private short GetWritableColorValue(DxfColor color)
        {
            var value = Math.Abs(color?.RawValue ?? 7);

            if (value == 0 || value == 256)
            {
                // BYLAYER and BYBLOCK aren't valid colors
                value = 7;
            }

            return(IsLayerOn
                ? value
                : (short)-value);
        }
示例#5
0
        internal static DxfViewPort FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfViewPort();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == 0)
                {
                    break;
                }

                buffer.Advance();
                switch (pair.Code)
                {
                case 70:
                    item.StandardFlags = (int)pair.ShortValue;
                    break;

                case DxfCodePairGroup.GroupCodeNumber:
                    var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                    item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                    break;

                case 10:
                    item.LowerLeft.X = (pair.DoubleValue);
                    break;

                case 20:
                    item.LowerLeft.Y = (pair.DoubleValue);
                    break;

                case 11:
                    item.UpperRight.X = (pair.DoubleValue);
                    break;

                case 21:
                    item.UpperRight.Y = (pair.DoubleValue);
                    break;

                case 12:
                    item.ViewCenter.X = (pair.DoubleValue);
                    break;

                case 22:
                    item.ViewCenter.Y = (pair.DoubleValue);
                    break;

                case 13:
                    item.SnapBasePoint.X = (pair.DoubleValue);
                    break;

                case 23:
                    item.SnapBasePoint.Y = (pair.DoubleValue);
                    break;

                case 14:
                    item.SnapSpacing.X = (pair.DoubleValue);
                    break;

                case 24:
                    item.SnapSpacing.Y = (pair.DoubleValue);
                    break;

                case 15:
                    item.GridSpacing.X = (pair.DoubleValue);
                    break;

                case 25:
                    item.GridSpacing.Y = (pair.DoubleValue);
                    break;

                case 16:
                    item.ViewDirection.X = (pair.DoubleValue);
                    break;

                case 26:
                    item.ViewDirection.Y = (pair.DoubleValue);
                    break;

                case 36:
                    item.ViewDirection.Z = (pair.DoubleValue);
                    break;

                case 17:
                    item.TargetViewPoint.X = (pair.DoubleValue);
                    break;

                case 27:
                    item.TargetViewPoint.Y = (pair.DoubleValue);
                    break;

                case 37:
                    item.TargetViewPoint.Z = (pair.DoubleValue);
                    break;

                case 40:
                    item.ViewHeight = (pair.DoubleValue);
                    break;

                case 41:
                    item.ViewPortAspectRatio = (pair.DoubleValue);
                    break;

                case 42:
                    item.LensLength = (pair.DoubleValue);
                    break;

                case 43:
                    item.FrontClippingPlane = (pair.DoubleValue);
                    break;

                case 44:
                    item.BackClippingPlane = (pair.DoubleValue);
                    break;

                case 45:
                    item.ViewHeight = (pair.DoubleValue);
                    break;

                case 50:
                    item.SnapRotationAngle = (pair.DoubleValue);
                    break;

                case 51:
                    item.ViewTwistAngle = (pair.DoubleValue);
                    break;

                case 71:
                    item.ViewMode = (DxfViewMode)(pair.ShortValue);
                    break;

                case 72:
                    item.CircleSides = (int)(pair.ShortValue);
                    break;

                case 73:
                    item.FastZoom = BoolShort(pair.ShortValue);
                    break;

                case 74:
                    item.UCSIcon = (pair.ShortValue);
                    break;

                case 75:
                    item.SnapOn = BoolShort(pair.ShortValue);
                    break;

                case 76:
                    item.GridOn = BoolShort(pair.ShortValue);
                    break;

                case 77:
                    item.SnapStyle = (DxfSnapStyle)(pair.ShortValue);
                    break;

                case 78:
                    item.SnapIsometricPlane = (DxfSnapIsometricPlane)(pair.ShortValue);
                    break;

                case 1:
                    item.PlotStyleSheet = (pair.StringValue);
                    break;

                case 281:
                    item.RenderMode = (DxfViewRenderMode)(pair.ShortValue);
                    break;

                case 65:
                    item.HasOwnUCS = BoolShort(pair.ShortValue);
                    break;

                case 110:
                    item.UCSOrigin.X = (pair.DoubleValue);
                    break;

                case 120:
                    item.UCSOrigin.Y = (pair.DoubleValue);
                    break;

                case 130:
                    item.UCSOrigin.Z = (pair.DoubleValue);
                    break;

                case 111:
                    item.UCSXAxis.X = (pair.DoubleValue);
                    break;

                case 121:
                    item.UCSXAxis.Y = (pair.DoubleValue);
                    break;

                case 131:
                    item.UCSXAxis.Z = (pair.DoubleValue);
                    break;

                case 112:
                    item.UCSYAxis.X = (pair.DoubleValue);
                    break;

                case 122:
                    item.UCSYAxis.Y = (pair.DoubleValue);
                    break;

                case 132:
                    item.UCSYAxis.Z = (pair.DoubleValue);
                    break;

                case 79:
                    item.OrthographicViewType = (DxfOrthographicViewType)(pair.ShortValue);
                    break;

                case 146:
                    item.UCSElevation = (pair.DoubleValue);
                    break;

                case 345:
                    item.UCSHandle = UIntHandle(pair.StringValue);
                    break;

                case 346:
                    item.BaseUCSHandle = UIntHandle(pair.StringValue);
                    break;

                case 170:
                    item.ShadePlotSetting = (DxfShadeEdgeMode)(pair.ShortValue);
                    break;

                case 61:
                    item.MajorGridLines = BoolShort(pair.ShortValue);
                    break;

                case 332:
                    item.BackgroundObjectPointer = UIntHandle(pair.StringValue);
                    break;

                case 333:
                    item.ShadePlotObjectPointer = UIntHandle(pair.StringValue);
                    break;

                case 348:
                    item.VisualStyleObjectPointer = UIntHandle(pair.StringValue);
                    break;

                case 292:
                    item.IsDefaultLightingOn = (pair.BoolValue);
                    break;

                case 282:
                    item.DefaultLightingType = (DxfDefaultLightingType)(pair.ShortValue);
                    break;

                case 141:
                    item.Brightness = (pair.DoubleValue);
                    break;

                case 142:
                    item.Contrast = (pair.DoubleValue);
                    break;

                case 62:
                    item.AmbientColor = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 421:
                    item.AmbientColorInt = (pair.IntegerValue);
                    break;

                case 431:
                    item.AmbientColorName = (pair.StringValue);
                    break;

                case (int)DxfXDataType.ApplicationName:
                    item.XData = DxfXData.FromBuffer(buffer, pair.StringValue);
                    break;

                default:
                    item.TrySetPair(pair);
                    break;
                }
            }

            return(item);
        }
示例#6
0
        internal override void AddValuePairs(List <DxfCodePair> pairs, DxfAcadVersion version, bool outputHandles)
        {
            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(100, AcDbText));
            }

            pairs.Add(new DxfCodePair(2, Name));
            pairs.Add(new DxfCodePair(70, (short)StandardFlags));
            pairs.Add(new DxfCodePair(10, (LowerLeft?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(20, (LowerLeft?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(11, (UpperRight?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(21, (UpperRight?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(12, (ViewCenter?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(22, (ViewCenter?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(13, (SnapBasePoint?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(23, (SnapBasePoint?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(14, EnsurePositiveOrDefault(1.0)(SnapSpacing?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(24, EnsurePositiveOrDefault(1.0)(SnapSpacing?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(15, EnsurePositiveOrDefault(1.0)(GridSpacing?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(25, EnsurePositiveOrDefault(1.0)(GridSpacing?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(16, (ViewDirection?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(26, (ViewDirection?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(36, (ViewDirection?.Z ?? 0.0)));
            pairs.Add(new DxfCodePair(17, (TargetViewPoint?.X ?? 0.0)));
            pairs.Add(new DxfCodePair(27, (TargetViewPoint?.Y ?? 0.0)));
            pairs.Add(new DxfCodePair(37, (TargetViewPoint?.Z ?? 0.0)));
            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(40, EnsurePositiveOrDefault(1.0)(ViewHeight)));
            }

            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(41, EnsurePositiveOrDefault(1.0)(ViewPortAspectRatio)));
            }

            pairs.Add(new DxfCodePair(42, EnsurePositiveOrDefault(50.0)(LensLength)));
            pairs.Add(new DxfCodePair(43, (FrontClippingPlane)));
            pairs.Add(new DxfCodePair(44, (BackClippingPlane)));
            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(45, EnsurePositiveOrDefault(1.0)(ViewHeight)));
            }

            pairs.Add(new DxfCodePair(50, (SnapRotationAngle)));
            pairs.Add(new DxfCodePair(51, (ViewTwistAngle)));
            pairs.Add(new DxfCodePair(71, (short)(ViewMode)));
            pairs.Add(new DxfCodePair(72, (short)EnsurePositiveOrDefault(1000)(CircleSides)));
            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(73, BoolShort(FastZoom)));
            }

            pairs.Add(new DxfCodePair(74, (short)EnsurePositiveOrDefault(3)(UCSIcon)));
            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(75, BoolShort(SnapOn)));
            }

            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(76, BoolShort(GridOn)));
            }

            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(77, (short)(SnapStyle)));
            }

            if (version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(78, (short)(SnapIsometricPlane)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(1, (PlotStyleSheet)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(281, (short)(RenderMode)));
            }

            if (version >= DxfAcadVersion.R2000 && version <= DxfAcadVersion.R2004)
            {
                pairs.Add(new DxfCodePair(65, BoolShort(HasOwnUCS)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(110, (UCSOrigin?.X ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(120, (UCSOrigin?.Y ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(130, (UCSOrigin?.Z ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(111, (UCSXAxis?.X ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(121, (UCSXAxis?.Y ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(131, (UCSXAxis?.Z ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(112, (UCSYAxis?.X ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(122, (UCSYAxis?.Y ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(132, (UCSYAxis?.Z ?? 0.0)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(79, (short)(OrthographicViewType)));
            }

            if (HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(146, (UCSElevation)));
            }

            if (UCSHandle != 0u && HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(345, UIntHandle(UCSHandle)));
            }

            if (BaseUCSHandle != 0u && HasOwnUCS && version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(346, UIntHandle(BaseUCSHandle)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(170, (short)(ShadePlotSetting)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(61, BoolShort(MajorGridLines)));
            }

            if (BackgroundObjectPointer != 0u && version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(332, UIntHandle(BackgroundObjectPointer)));
            }

            if (ShadePlotObjectPointer != 0u && version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(333, UIntHandle(ShadePlotObjectPointer)));
            }

            if (VisualStyleObjectPointer != 0u && version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(348, UIntHandle(VisualStyleObjectPointer)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(292, (IsDefaultLightingOn)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(282, (short)(DefaultLightingType)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(141, (Brightness)));
            }

            if (version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(142, (Contrast)));
            }

            if (AmbientColor?.RawValue != 7 && version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(62, DxfColor.GetRawValue(AmbientColor)));
            }

            if (AmbientColorInt != 0 && version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(421, (AmbientColorInt)));
            }

            if (AmbientColorName != "BLACK" && version >= DxfAcadVersion.R2007)
            {
                pairs.Add(new DxfCodePair(431, (AmbientColorName)));
            }

            if (XData != null)
            {
                XData.AddValuePairs(pairs, version, outputHandles);
            }
        }
示例#7
0
文件: DxfColor.cs 项目: nakijun/Dxf
 public static short GetRawValue(DxfColor color)
 {
     return color?.RawValue ?? 0;
 }
 private DxfColor ReadColorValue(short value)
 {
     IsLayerOn = value >= 0;
     return(DxfColor.FromRawValue(Math.Abs(value)));
 }
示例#9
0
        public DxfFile ReadFile(BinaryReader reader)
        {
            // swallow next two characters
            var sub = reader.ReadChar();

            Debug.Assert(sub == 0x1A);
            var nul = reader.ReadChar();

            Debug.Assert(nul == 0x00);

            DxfPoint?blockBase    = null;
            var      entities     = new List <DxfEntity>();
            var      stillReading = true;
            Action <Func <BinaryReader, DxfEntity> > addEntity = (entityReader) =>
            {
                var entity = entityReader(reader);
                AssignCommonValues(entity);
                entities.Add(entity);
            };
            Func <DxfVertex> getLastVertex = () => entities.LastOrDefault() as DxfVertex;

            while (stillReading)
            {
                var itemType = (DxbItemType)reader.ReadByte();
                switch (itemType)
                {
                case DxbItemType.Line:
                    addEntity(ReadLine);
                    break;

                case DxbItemType.Point:
                    addEntity(ReadPoint);
                    break;

                case DxbItemType.Circle:
                    addEntity(ReadCircle);
                    break;

                case DxbItemType.Arc:
                    addEntity(ReadArc);
                    break;

                case DxbItemType.Trace:
                    addEntity(ReadTrace);
                    break;

                case DxbItemType.Solid:
                    addEntity(ReadSolid);
                    break;

                case DxbItemType.Seqend:
                    addEntity(ReadSeqend);
                    break;

                case DxbItemType.Polyline:
                    addEntity(ReadPolyline);
                    break;

                case DxbItemType.Vertex:
                    addEntity(ReadVertex);
                    break;

                case DxbItemType.Face:
                    addEntity(ReadFace);
                    break;

                case DxbItemType.ScaleFactor:
                    _scaleFactor = ReadF(reader);
                    break;

                case DxbItemType.NewLayer:
                    var sb = new StringBuilder();
                    for (int b = reader.ReadByte(); b != 0; b = reader.ReadByte())
                    {
                        sb.Append((char)b);
                    }
                    _layerName = sb.ToString();
                    break;

                case DxbItemType.LineExtension:
                    addEntity(ReadLineExtension);
                    break;

                case DxbItemType.TraceExtension:
                    addEntity(ReadTraceExtension);
                    break;

                case DxbItemType.BlockBase:
                    var x = ReadN(reader);
                    var y = ReadN(reader);
                    if (blockBase == null && entities.Count == 0)
                    {
                        // only if this is the first item encountered
                        blockBase = new DxfPoint(x, y, 0.0);
                    }
                    break;

                case DxbItemType.Bulge:
                {
                    var bulge      = ReadU(reader);
                    var lastVertex = getLastVertex();
                    if (lastVertex != null)
                    {
                        lastVertex.Bulge = bulge;
                    }
                }
                break;

                case DxbItemType.Width:
                {
                    var startWidth = ReadN(reader);
                    var endWidth   = ReadN(reader);
                    var lastVertex = getLastVertex();
                    if (lastVertex != null)
                    {
                        lastVertex.StartingWidth = startWidth;
                        lastVertex.EndingWidth   = endWidth;
                    }
                }
                break;

                case DxbItemType.NumberMode:
                    _isIntegerMode = ReadW(reader) == 0;
                    break;

                case DxbItemType.NewColor:
                    _color = DxfColor.FromRawValue((short)ReadW(reader));
                    break;

                case DxbItemType.LineExtension3D:
                    addEntity(ReadLineExtension3D);
                    break;

                case 0:
                    stillReading = false;
                    break;
                }
            }

            var file = new DxfFile();

            foreach (var section in file.Sections)
            {
                section.Clear();
            }

            // collect the entities (e.g., polylines, etc.)
            entities = DxfEntitiesSection.GatherEntities(entities);

            if (blockBase != null)
            {
                // entities are all contained in a block
                var block = new DxfBlock();
                block.BasePoint = blockBase.GetValueOrDefault();
                foreach (var entity in entities)
                {
                    block.Entities.Add(entity);
                }

                file.Blocks.Add(block);
            }
            else
            {
                // just a normal collection of entities
                foreach (var entity in entities)
                {
                    file.Entities.Add(entity);
                }
            }

            return(file);
        }
示例#10
0
文件: DxfColor.cs 项目: zakb120/dxf
 public static short GetRawValue(DxfColor color)
 {
     return(color?.RawValue ?? 0);
 }
示例#11
0
文件: DxbReader.cs 项目: nakijun/Dxf
        public DxfFile ReadFile(BinaryReader reader)
        {
            // swallow next two characters
            var sub = reader.ReadChar();
            Debug.Assert(sub == 0x1A);
            var nul = reader.ReadChar();
            Debug.Assert(nul == 0x00);

            DxfPoint blockBase = null;
            var entities = new List<DxfEntity>();
            var stillReading = true;
            Action<Func<BinaryReader, DxfEntity>> addEntity = (entityReader) =>
            {
                var entity = entityReader(reader);
                AssignCommonValues(entity);
                entities.Add(entity);
            };
            Func<DxfVertex> getLastVertex = () => entities.LastOrDefault() as DxfVertex;
            while (stillReading)
            {
                var itemType = (DxbItemType)reader.ReadByte();
                switch (itemType)
                {
                    case DxbItemType.Line:
                        addEntity(ReadLine);
                        break;
                    case DxbItemType.Point:
                        addEntity(ReadPoint);
                        break;
                    case DxbItemType.Circle:
                        addEntity(ReadCircle);
                        break;
                    case DxbItemType.Arc:
                        addEntity(ReadArc);
                        break;
                    case DxbItemType.Trace:
                        addEntity(ReadTrace);
                        break;
                    case DxbItemType.Solid:
                        addEntity(ReadSolid);
                        break;
                    case DxbItemType.Seqend:
                        addEntity(ReadSeqend);
                        break;
                    case DxbItemType.Polyline:
                        addEntity(ReadPolyline);
                        break;
                    case DxbItemType.Vertex:
                        addEntity(ReadVertex);
                        break;
                    case DxbItemType.Face:
                        addEntity(ReadFace);
                        break;
                    case DxbItemType.ScaleFactor:
                        _scaleFactor = ReadF(reader);
                        break;
                    case DxbItemType.NewLayer:
                        var sb = new StringBuilder();
                        for (int b = reader.ReadByte(); b != 0; b = reader.ReadByte())
                            sb.Append((char)b);
                        _layerName = sb.ToString();
                        break;
                    case DxbItemType.LineExtension:
                        addEntity(ReadLineExtension);
                        break;
                    case DxbItemType.TraceExtension:
                        addEntity(ReadTraceExtension);
                        break;
                    case DxbItemType.BlockBase:
                        var x = ReadN(reader);
                        var y = ReadN(reader);
                        if (blockBase == null && entities.Count == 0)
                        {
                            // only if this is the first item encountered
                            blockBase = new DxfPoint(x, y, 0.0);
                        }
                        break;
                    case DxbItemType.Bulge:
                        {
                            var bulge = ReadU(reader);
                            var lastVertex = getLastVertex();
                            if (lastVertex != null)
                            {
                                lastVertex.Bulge = bulge;
                            }
                        }
                        break;
                    case DxbItemType.Width:
                        {
                            var startWidth = ReadN(reader);
                            var endWidth = ReadN(reader);
                            var lastVertex = getLastVertex();
                            if (lastVertex != null)
                            {
                                lastVertex.StartingWidth = startWidth;
                                lastVertex.EndingWidth = endWidth;
                            }
                        }
                        break;
                    case DxbItemType.NumberMode:
                        _isIntegerMode = ReadW(reader) == 0;
                        break;
                    case DxbItemType.NewColor:
                        _color = DxfColor.FromRawValue((short)ReadW(reader));
                        break;
                    case DxbItemType.LineExtension3D:
                        addEntity(ReadLineExtension3D);
                        break;
                    case 0:
                        stillReading = false;
                        break;
                }
            }

            var file = new DxfFile();

            // collect the entities (e.g., polylines, etc.)
            entities = DxfEntitiesSection.GatherEntities(entities);

            if (blockBase != null)
            {
                // entities are all contained in a block
                var block = new DxfBlock();
                block.BasePoint = blockBase;
                block.Entities.AddRange(entities);
                file.Blocks.Add(block);
            }
            else
            {
                // just a normal collection of entities
                file.Entities.AddRange(entities);
            }

            return file;
        }
        internal static DxfDimStyle FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfDimStyle();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == 0)
                {
                    break;
                }

                buffer.Advance();
                switch (pair.Code)
                {
                case 70:
                    item.StandardFlags = (int)pair.ShortValue;
                    break;

                case DxfCodePairGroup.GroupCodeNumber:
                    var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                    item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                    break;

                case 3:
                    item.DimensioningSuffix = (pair.StringValue);
                    break;

                case 4:
                    item.AlternateDimensioningSuffix = (pair.StringValue);
                    break;

                case 5:
                    item.ArrowBlockName = (pair.StringValue);
                    break;

                case 6:
                    item.FirstArrowBlockName = (pair.StringValue);
                    break;

                case 7:
                    item.SecondArrowBlockName = (pair.StringValue);
                    break;

                case 40:
                    item.DimensioningScaleFactor = (pair.DoubleValue);
                    break;

                case 41:
                    item.DimensioningArrowSize = (pair.DoubleValue);
                    break;

                case 42:
                    item.DimensionExtensionLineOffset = (pair.DoubleValue);
                    break;

                case 43:
                    item.DimensionLineIncrement = (pair.DoubleValue);
                    break;

                case 44:
                    item.DimensionExtensionLineExtension = (pair.DoubleValue);
                    break;

                case 45:
                    item.DimensionDistanceRoundingValue = (pair.DoubleValue);
                    break;

                case 46:
                    item.DimensionLineExtension = (pair.DoubleValue);
                    break;

                case 47:
                    item.DimensionPlusTolerance = (pair.DoubleValue);
                    break;

                case 48:
                    item.DimensionMinusTolerance = (pair.DoubleValue);
                    break;

                case 71:
                    item.GenerateDimensionTolerances = BoolShort(pair.ShortValue);
                    break;

                case 72:
                    item.GenerateDimensionLimits = BoolShort(pair.ShortValue);
                    break;

                case 73:
                    item.DimensionTextInsideHorizontal = BoolShort(pair.ShortValue);
                    break;

                case 74:
                    item.DimensionTextOutsideHorizontal = BoolShort(pair.ShortValue);
                    break;

                case 75:
                    item.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue);
                    break;

                case 76:
                    item.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue);
                    break;

                case 77:
                    item.TextAboveDimensionLine = BoolShort(pair.ShortValue);
                    break;

                case 78:
                    item.DimensionUnitZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue);
                    break;

                case 79:
                    item.DimensionAngleZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue);
                    break;

                case 140:
                    item.DimensioningTextHeight = (pair.DoubleValue);
                    break;

                case 141:
                    item.CenterMarkSize = (pair.DoubleValue);
                    break;

                case 142:
                    item.DimensioningTickSize = (pair.DoubleValue);
                    break;

                case 143:
                    item.AlternateDimensioningScaleFactor = (pair.DoubleValue);
                    break;

                case 144:
                    item.DimensionLinearMeasurementScaleFactor = (pair.DoubleValue);
                    break;

                case 145:
                    item.DimensionVerticalTextPosition = (pair.DoubleValue);
                    break;

                case 146:
                    item.DimensionToleranceDisplaceScaleFactor = (pair.DoubleValue);
                    break;

                case 147:
                    item.DimensionLineGap = (pair.DoubleValue);
                    break;

                case 148:
                    item.AlternateDimensioningUnitRounding = (pair.DoubleValue);
                    break;

                case 170:
                    item.UseAlternateDimensioning = BoolShort(pair.ShortValue);
                    break;

                case 171:
                    item.AlternateDimensioningDecimalPlaces = (pair.ShortValue);
                    break;

                case 172:
                    item.ForceDimensionLineExtensionsOutsideIfTextExists = BoolShort(pair.ShortValue);
                    break;

                case 173:
                    item.UseSeparateArrowBlocksForDimensions = BoolShort(pair.ShortValue);
                    break;

                case 174:
                    item.ForceDimensionTextInsideExtensions = BoolShort(pair.ShortValue);
                    break;

                case 175:
                    item.SuppressOutsideExtensionDimensionLines = BoolShort(pair.ShortValue);
                    break;

                case 176:
                    item.DimensionLineColor = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 177:
                    item.DimensionExtensionLineColor = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 178:
                    item.DimensionTextColor = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 179:
                    item.AngularDimensionPrecision = (pair.ShortValue);
                    break;

                case 270:
                    item.DimensionUnitFormat = (DxfUnitFormat)(pair.ShortValue);
                    break;

                case 271:
                    item.DimensionUnitToleranceDecimalPlaces = (pair.ShortValue);
                    break;

                case 272:
                    item.DimensionToleranceDecimalPlaces = (pair.ShortValue);
                    break;

                case 273:
                    item.AlternateDimensioningUnits = (DxfUnitFormat)(pair.ShortValue);
                    break;

                case 274:
                    item.AlternateDimensioningToleranceDecimalPlaces = (pair.ShortValue);
                    break;

                case 275:
                    item.DimensioningAngleFormat = (DxfAngleFormat)(pair.ShortValue);
                    break;

                case 276:
                    item.DimensionFractionFormat = (DxfDimensionFractionFormat)(pair.ShortValue);
                    break;

                case 277:
                    item.DimensionNonAngularUnits = (DxfNonAngularUnits)(pair.ShortValue);
                    break;

                case 278:
                    item.DimensionDecimalSeparatorChar = (char)(pair.ShortValue);
                    break;

                case 279:
                    item.DimensionTextMovementRule = (DxfDimensionTextMovementRule)(pair.ShortValue);
                    break;

                case 280:
                    item.DimensionTextJustification = (DxfDimensionTextJustification)(pair.ShortValue);
                    break;

                case 281:
                    item.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue);
                    break;

                case 282:
                    item.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue);
                    break;

                case 283:
                    item.DimensionToleranceVerticalJustification = (DxfJustification)(pair.ShortValue);
                    break;

                case 284:
                    item.DimensionToleranceZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue);
                    break;

                case 285:
                    item.AlternateDimensioningZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue);
                    break;

                case 286:
                    item.AlternateDimensioningToleranceZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue);
                    break;

                case 287:
                    item.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue);
                    break;

                case 288:
                    item.DimensionCursorControlsTextPosition = BoolShort(pair.ShortValue);
                    break;

                case 289:
                    item.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue);
                    break;

                case 340:
                    item.DimensionTextStyle = (pair.StringValue);
                    break;

                case 341:
                    item.DimensionLeaderBlockName = (pair.StringValue);
                    break;

                case 342:
                    item.ArrowBlockName = (pair.StringValue);
                    break;

                case 343:
                    item.FirstArrowBlockName = (pair.StringValue);
                    break;

                case 344:
                    item.SecondArrowBlockName = (pair.StringValue);
                    break;

                case 371:
                    item.DimensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue);
                    break;

                case 372:
                    item.DimensionExtensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue);
                    break;

                case (int)DxfXDataType.ApplicationName:
                    item.XData = DxfXData.FromBuffer(buffer, pair.StringValue);
                    break;

                default:
                    item.TrySetPair(pair);
                    break;
                }
            }

            return(item);
        }
        internal override void AddValuePairs(List <DxfCodePair> pairs, DxfAcadVersion version, bool outputHandles)
        {
            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(100, AcDbText));
            }

            pairs.Add(new DxfCodePair(2, Name));
            pairs.Add(new DxfCodePair(70, (short)StandardFlags));
            pairs.Add(new DxfCodePair(3, (DimensioningSuffix)));
            pairs.Add(new DxfCodePair(4, (AlternateDimensioningSuffix)));
            if (version <= DxfAcadVersion.R14)
            {
                pairs.Add(new DxfCodePair(5, (ArrowBlockName)));
            }

            if (version <= DxfAcadVersion.R14)
            {
                pairs.Add(new DxfCodePair(6, (FirstArrowBlockName)));
            }

            if (version <= DxfAcadVersion.R14)
            {
                pairs.Add(new DxfCodePair(7, (SecondArrowBlockName)));
            }

            pairs.Add(new DxfCodePair(40, (DimensioningScaleFactor)));
            pairs.Add(new DxfCodePair(41, (DimensioningArrowSize)));
            pairs.Add(new DxfCodePair(42, (DimensionExtensionLineOffset)));
            pairs.Add(new DxfCodePair(43, (DimensionLineIncrement)));
            pairs.Add(new DxfCodePair(44, (DimensionExtensionLineExtension)));
            pairs.Add(new DxfCodePair(45, (DimensionDistanceRoundingValue)));
            pairs.Add(new DxfCodePair(46, (DimensionLineExtension)));
            pairs.Add(new DxfCodePair(47, (DimensionPlusTolerance)));
            pairs.Add(new DxfCodePair(48, (DimensionMinusTolerance)));
            pairs.Add(new DxfCodePair(71, BoolShort(GenerateDimensionTolerances)));
            pairs.Add(new DxfCodePair(72, BoolShort(GenerateDimensionLimits)));
            pairs.Add(new DxfCodePair(73, BoolShort(DimensionTextInsideHorizontal)));
            pairs.Add(new DxfCodePair(74, BoolShort(DimensionTextOutsideHorizontal)));
            pairs.Add(new DxfCodePair(75, BoolShort(SuppressFirstDimensionExtensionLine)));
            pairs.Add(new DxfCodePair(76, BoolShort(SuppressSecondDimensionExtensionLine)));
            pairs.Add(new DxfCodePair(77, BoolShort(TextAboveDimensionLine)));
            pairs.Add(new DxfCodePair(78, (short)(DimensionUnitZeroSuppression)));
            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(79, (short)(DimensionAngleZeroSuppression)));
            }

            pairs.Add(new DxfCodePair(140, (DimensioningTextHeight)));
            pairs.Add(new DxfCodePair(141, (CenterMarkSize)));
            pairs.Add(new DxfCodePair(142, (DimensioningTickSize)));
            pairs.Add(new DxfCodePair(143, (AlternateDimensioningScaleFactor)));
            pairs.Add(new DxfCodePair(144, (DimensionLinearMeasurementScaleFactor)));
            pairs.Add(new DxfCodePair(145, (DimensionVerticalTextPosition)));
            pairs.Add(new DxfCodePair(146, (DimensionToleranceDisplaceScaleFactor)));
            pairs.Add(new DxfCodePair(147, (DimensionLineGap)));
            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(148, (AlternateDimensioningUnitRounding)));
            }

            pairs.Add(new DxfCodePair(170, BoolShort(UseAlternateDimensioning)));
            pairs.Add(new DxfCodePair(171, (AlternateDimensioningDecimalPlaces)));
            pairs.Add(new DxfCodePair(172, BoolShort(ForceDimensionLineExtensionsOutsideIfTextExists)));
            pairs.Add(new DxfCodePair(173, BoolShort(UseSeparateArrowBlocksForDimensions)));
            pairs.Add(new DxfCodePair(174, BoolShort(ForceDimensionTextInsideExtensions)));
            pairs.Add(new DxfCodePair(175, BoolShort(SuppressOutsideExtensionDimensionLines)));
            pairs.Add(new DxfCodePair(176, DxfColor.GetRawValue(DimensionLineColor)));
            pairs.Add(new DxfCodePair(177, DxfColor.GetRawValue(DimensionExtensionLineColor)));
            pairs.Add(new DxfCodePair(178, DxfColor.GetRawValue(DimensionTextColor)));
            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(179, (AngularDimensionPrecision)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(270, (short)(DimensionUnitFormat)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(271, (DimensionUnitToleranceDecimalPlaces)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(272, (DimensionToleranceDecimalPlaces)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(273, (short)(AlternateDimensioningUnits)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(274, (AlternateDimensioningToleranceDecimalPlaces)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(275, (short)(DimensioningAngleFormat)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(276, (short)(DimensionFractionFormat)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(277, (short)(DimensionNonAngularUnits)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(278, (short)(DimensionDecimalSeparatorChar)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(279, (short)(DimensionTextMovementRule)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(280, (short)(DimensionTextJustification)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(281, BoolShort(SuppressFirstDimensionExtensionLine)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(282, BoolShort(SuppressSecondDimensionExtensionLine)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(283, (short)(DimensionToleranceVerticalJustification)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(284, (short)(DimensionToleranceZeroSuppression)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(285, (short)(AlternateDimensioningZeroSupression)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(286, (short)(AlternateDimensioningToleranceZeroSupression)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(287, (short)(DimensionTextAndArrowPlacement)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(288, BoolShort(DimensionCursorControlsTextPosition)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(289, (short)(DimensionTextAndArrowPlacement)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                pairs.Add(new DxfCodePair(340, (DimensionTextStyle)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(341, (DimensionLeaderBlockName)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(342, (ArrowBlockName)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(343, (FirstArrowBlockName)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(344, (SecondArrowBlockName)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(371, DxfLineWeight.GetRawValue(DimensionLineWeight)));
            }

            if (version >= DxfAcadVersion.R2000)
            {
                pairs.Add(new DxfCodePair(372, DxfLineWeight.GetRawValue(DimensionExtensionLineWeight)));
            }

            if (XData != null)
            {
                XData.AddValuePairs(pairs, version, outputHandles);
            }
        }