public IEnumerable <DxfCodePair> GetValuePairs(DxfAcadVersion version, bool outputHandles)
            {
                var list = new List <DxfCodePair>();

                list.Add(new DxfCodePair(0, EndBlockText));
                if (outputHandles && ((IDxfItemInternal)this).Handle != 0u)
                {
                    list.Add(new DxfCodePair(5, DxfCommonConverters.UIntHandle(((IDxfItemInternal)this).Handle)));
                }

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

                if (version >= DxfAcadVersion.R14)
                {
                    foreach (var group in ExtensionDataGroups)
                    {
                        group.AddValuePairs(list, version, outputHandles);
                    }
                }

                if (version >= DxfAcadVersion.R2000)
                {
                    list.Add(new DxfCodePair(330, DxfCommonConverters.UIntHandle(((IDxfItemInternal)Parent).OwnerHandle)));
                }

                if (version >= DxfAcadVersion.R13)
                {
                    list.Add(new DxfCodePair(100, AcDbEntityText));
                }

                if (Parent.IsInPaperSpace)
                {
                    list.Add(new DxfCodePair(67, DxfCommonConverters.BoolShort(Parent.IsInPaperSpace)));
                }

                list.Add(new DxfCodePair(8, Parent.Layer));

                if (version >= DxfAcadVersion.R13)
                {
                    list.Add(new DxfCodePair(100, AcDbBlockEndText));
                }
                return(list);
            }
示例#2
0
 protected static short BoolShort(bool b)
 {
     return DxfCommonConverters.BoolShort(b);
 }
示例#3
0
 protected static bool BoolShort(short s)
 {
     return DxfCommonConverters.BoolShort(s);
 }
示例#4
0
        internal static DxfBlock FromBuffer(DxfCodePairBufferReader buffer)
        {
            if (!buffer.ItemsRemain)
            {
                return null;
            }

            var block = new DxfBlock();
            var readingBlockStart = true;
            var readingBlockEnd = false;
            var entities = new List<DxfEntity>();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading blocks
                    buffer.Advance(); // swallow (0, ENDSEC)
                    break;
                }
                else if (IsBlockStart(pair))
                {
                    if (readingBlockStart)
                    {
                        // if another block is found, stop reading this one because some blocks don't specify (0, ENDBLK)
                        break;
                    }

                    break;
                }
                else if (IsBlockEnd(pair))
                {
                    if (!readingBlockStart) throw new DxfReadException("Unexpected block end", pair);
                    readingBlockStart = false;
                    readingBlockEnd = true;
                    buffer.Advance(); // swallow (0, ENDBLK)
                }
                else if (pair.Code == 0)
                {
                    // should be an entity
                    var entity = DxfEntity.FromBuffer(buffer);
                    if (entity != null)
                    {
                        // entity could be null if it's unsupported
                        entities.Add(entity);
                    }
                }
                else
                {
                    // read value pair
                    if (readingBlockStart)
                    {
                        buffer.Advance();
                        switch (pair.Code)
                        {
                            case 1:
                                block.XrefName = pair.StringValue;
                                break;
                            case 2:
                                block.Name = pair.StringValue;
                                break;
                            case 3:
                                break;
                            case 4:
                                block.Description = pair.StringValue;
                                break;
                            case 5:
                                ((IDxfItemInternal)block).Handle = DxfCommonConverters.UIntHandle(pair.StringValue);
                                break;
                            case 8:
                                block.Layer = pair.StringValue;
                                break;
                            case 10:
                                block.BasePoint = block.BasePoint.WithUpdatedX(pair.DoubleValue);
                                break;
                            case 20:
                                block.BasePoint = block.BasePoint.WithUpdatedY(pair.DoubleValue);
                                break;
                            case 30:
                                block.BasePoint = block.BasePoint.WithUpdatedZ(pair.DoubleValue);
                                break;
                            case 67:
                                block.IsInPaperSpace = DxfCommonConverters.BoolShort(pair.ShortValue);
                                break;
                            case 70:
                                block.Flags = pair.ShortValue;
                                break;
                            case 330:
                                ((IDxfItemInternal)block).OwnerHandle = DxfCommonConverters.UIntHandle(pair.StringValue);
                                break;
                            case DxfCodePairGroup.GroupCodeNumber:
                                var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                                block.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                                break;
                            case (int)DxfXDataType.ApplicationName:
                                block.XData = DxfXData.FromBuffer(buffer, pair.StringValue);
                                break;
                        }
                    }
                    else if (readingBlockEnd)
                    {
                        block.EndBlock.ApplyCodePairs(buffer);
                    }
                    else
                    {
                        throw new DxfReadException("Unexpected pair in block", pair);
                    }
                }
            }

            var collected = DxfEntitiesSection.GatherEntities(entities);
            foreach (var entity in collected)
            {
                block.Entities.Add(entity);
            }

            return block;
        }
示例#5
0
        internal IEnumerable<DxfCodePair> GetValuePairs(DxfAcadVersion version, bool outputHandles)
        {
            var list = new List<DxfCodePair>();
            list.Add(new DxfCodePair(0, BlockText));
            if (outputHandles && ((IDxfItemInternal)this).Handle != 0u)
            {
                list.Add(new DxfCodePair(5, DxfCommonConverters.UIntHandle(((IDxfItemInternal)this).Handle)));
            }

            if (version >= DxfAcadVersion.R14)
            {
                foreach (var group in ExtensionDataGroups)
                {
                    group.AddValuePairs(list, version, outputHandles);
                }
            }

            if (version >= DxfAcadVersion.R13)
            {
                if (((IDxfItemInternal)this).OwnerHandle != 0u)
                {
                    list.Add(new DxfCodePair(330, DxfCommonConverters.UIntHandle(((IDxfItemInternal)this).OwnerHandle)));
                }

                list.Add(new DxfCodePair(100, AcDbEntityText));
            }

            if (IsInPaperSpace)
            {
                list.Add(new DxfCodePair(67, DxfCommonConverters.BoolShort(IsInPaperSpace)));
            }

            list.Add(new DxfCodePair(8, Layer));
            if (version >= DxfAcadVersion.R13)
            {
                list.Add(new DxfCodePair(100, AcDbBlockBeginText));
            }

            list.Add(new DxfCodePair(2, Name));
            list.Add(new DxfCodePair(70, (short)Flags));
            list.Add(new DxfCodePair(10, BasePoint.X));
            list.Add(new DxfCodePair(20, BasePoint.Y));
            list.Add(new DxfCodePair(30, BasePoint.Z));
            if (version >= DxfAcadVersion.R12)
            {
                list.Add(new DxfCodePair(3, Name));
            }

            list.Add(new DxfCodePair(1, XrefName));

            if (!string.IsNullOrEmpty(Description))
            {
                list.Add(new DxfCodePair(4, Description));
            }

            // entities in blocks need handles for some applications
            list.AddRange(Entities.SelectMany(e => e.GetValuePairs(version, outputHandles)));

            list.AddRange(EndBlock.GetValuePairs(version, outputHandles));

            return list;
        }
示例#6
0
        internal static DxfTableCellStyle FromBuffer(DxfCodePairBufferReader buffer)
        {
            var seenName = false;
            var style    = new DxfTableCellStyle();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                switch (pair.Code)
                {
                case 7:
                    if (seenName)
                    {
                        // found another cell style; return without consuming
                        return(style);
                    }
                    else
                    {
                        style.Name = pair.StringValue;
                        seenName   = true;
                    }
                    break;

                case 62:
                    style.TextColor = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 63:
                    style.CellFillColor = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 64:
                    style.Border1Color = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 65:
                    style.Border2Color = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 66:
                    style.Border3Color = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 67:
                    style.Border4Color = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 68:
                    style.Border5Color = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 69:
                    style.Border6Color = DxfColor.FromRawValue(pair.ShortValue);
                    break;

                case 90:
                    style.CellDataType = pair.IntegerValue;
                    break;

                case 91:
                    style.CellUnitType = pair.IntegerValue;
                    break;

                case 140:
                    style.TextHeight = pair.DoubleValue;
                    break;

                case 170:
                    style.CellAlignment = pair.ShortValue;
                    break;

                case 274:
                    style.BorderLineweight1 = pair.ShortValue;
                    break;

                case 275:
                    style.BorderLineweight2 = pair.ShortValue;
                    break;

                case 276:
                    style.BorderLineweight3 = pair.ShortValue;
                    break;

                case 277:
                    style.BorderLineweight4 = pair.ShortValue;
                    break;

                case 278:
                    style.BorderLineweight5 = pair.ShortValue;
                    break;

                case 279:
                    style.BorderLineweight6 = pair.ShortValue;
                    break;

                case 283:
                    style.IsBackgroundColorEnabled = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 284:
                    style.IsBorder1Visible = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 285:
                    style.IsBorder2Visible = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 286:
                    style.IsBorder3Visible = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 287:
                    style.IsBorder4Visible = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 288:
                    style.IsBorder5Visible = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 289:
                    style.IsBorder6Visible = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                default:
                    // unknown code, return without consuming the pair
                    return(style);
                }

                buffer.Advance();
            }

            return(style);
        }