Example #1
0
        internal static DxfXDataItem FromBuffer(DxfCodePairBufferReader buffer)
        {
            var pair = buffer.Peek();

            buffer.Advance();
            switch ((DxfXDataType)pair.Code)
            {
            case DxfXDataType.String:
                return(new DxfXDataString(pair.StringValue));

            case DxfXDataType.ControlString:
                return(DxfXDataItemList.ListFromBuffer(buffer));

            case DxfXDataType.Layer:
                return(new DxfXDataLayerName(pair.StringValue));

            case DxfXDataType.BinaryData:
                return(new DxfXDataBinaryData(DxfCommonConverters.HexBytes(pair.StringValue)));

            case DxfXDataType.Handle:
                return(new DxfXDataHandle(DxfCommonConverters.UIntHandle(pair.StringValue)));

            case DxfXDataType.RealTriple:
                return(new DxfXData3Reals(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.WorldSpacePosition:
                return(new DxfXDataWorldSpacePosition(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.WorldSpaceDisplacement:
                return(new DxfXDataWorldSpaceDisplacement(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.WorldDirection:
                return(new DxfXDataWorldDirection(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.Real:
                return(new DxfXDataReal(pair.DoubleValue));

            case DxfXDataType.Distance:
                return(new DxfXDataDistance(pair.DoubleValue));

            case DxfXDataType.ScaleFactor:
                return(new DxfXDataScaleFactor(pair.DoubleValue));

            case DxfXDataType.Integer:
                return(new DxfXDataInteger(pair.ShortValue));

            case DxfXDataType.Long:
                return(new DxfXDataLong(pair.IntegerValue));

            default:
                return(null);    // unexpected XDATA code pair
            }
        }
        protected internal override IEnumerable <DxfCodePair> GetSpecificPairs(DxfAcadVersion version, bool outputHandles, HashSet <IDxfItem> writtenItems)
        {
            var list = new List <DxfCodePair>();

            list.Add(new DxfCodePair(90, RawData.Length));

            // write lines in 128-byte chunks (expands to 256 hex bytes)
            var hex   = DxfCommonConverters.HexBytes(RawData);
            var lines = DxfCommonConverters.SplitIntoLines(hex, 256);

            list.AddRange(lines.Select(l => new DxfCodePair(310, l)));
            return(list);
        }
Example #3
0
        private IEnumerable <string> GetHexStrings()
        {
            if (Data == null)
            {
                yield break;
            }

            var pos = 0;

            while (pos < Data.Length)
            {
                var slice = Data.Skip(pos).Take(128).ToArray();
                pos += slice.Length;
                yield return(DxfCommonConverters.HexBytes(slice));
            }
        }
        internal static DxfThumbnailImageSection ThumbnailImageSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            if (buffer.ItemsRemain)
            {
                var lengthPair = buffer.Peek();
                buffer.Advance();

                if (lengthPair.Code != 90)
                {
                    return(null);
                }

                var length = lengthPair.IntegerValue;
                var lines  = new List <string>();
                while (buffer.ItemsRemain)
                {
                    var pair = buffer.Peek();
                    buffer.Advance();

                    if (DxfCodePair.IsSectionEnd(pair))
                    {
                        break;
                    }

                    Debug.Assert(pair.Code == 310);
                    lines.Add(pair.StringValue);
                }

                var section = new DxfThumbnailImageSection();
                section.Clear();
                section.RawData = DxfCommonConverters.HexBytes(string.Join(string.Empty, lines.ToArray()));
                return(section);
            }

            return(null);
        }
Example #5
0
 protected override DxfObject PostParse()
 {
     Data = _hexData.SelectMany(h => DxfCommonConverters.HexBytes(h)).ToArray();
     _hexData.Clear();
     return(this);
 }
Example #6
0
        internal void AddValuePairs(List <DxfCodePair> pairs, DxfAcadVersion version, bool outputHandles)
        {
            var code = (int)Type;

            switch (this)
            {
            case DxfXDataString s:
                pairs.Add(new DxfCodePair(code, s.Value));
                break;

            case DxfXDataItemList l:
                AddListValuePairs(l.Items, pairs, version, outputHandles);
                break;

            case DxfXDataLayerName l:
                pairs.Add(new DxfCodePair(code, l.Value));
                break;

            case DxfXDataBinaryData b:
                pairs.Add(new DxfCodePair(code, DxfCommonConverters.HexBytes(b.Value)));
                break;

            case DxfXDataHandle h:
                pairs.Add(new DxfCodePair(code, DxfCommonConverters.UIntHandle(h.Value)));
                break;

            case DxfXData3Reals r:
                pairs.Add(new DxfCodePair(code, r.Value.X));
                pairs.Add(new DxfCodePair(code + 10, r.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, r.Value.Z));
                break;

            case DxfXDataWorldSpacePosition w:
                pairs.Add(new DxfCodePair(code, w.Value.X));
                pairs.Add(new DxfCodePair(code + 10, w.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, w.Value.Z));
                break;

            case DxfXDataWorldSpaceDisplacement w:
                pairs.Add(new DxfCodePair(code, w.Value.X));
                pairs.Add(new DxfCodePair(code + 10, w.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, w.Value.Z));
                break;

            case DxfXDataWorldDirection w:
                pairs.Add(new DxfCodePair(code, w.Value.X));
                pairs.Add(new DxfCodePair(code + 10, w.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, w.Value.Z));
                break;

            case DxfXDataReal r:
                pairs.Add(new DxfCodePair(code, r.Value));
                break;

            case DxfXDataDistance d:
                pairs.Add(new DxfCodePair(code, d.Value));
                break;

            case DxfXDataScaleFactor s:
                pairs.Add(new DxfCodePair(code, s.Value));
                break;

            case DxfXDataInteger i:
                pairs.Add(new DxfCodePair(code, i.Value));
                break;

            case DxfXDataLong l:
                pairs.Add(new DxfCodePair(code, l.Value));
                break;

            default:
                throw new InvalidOperationException("Unexpected XDATA item " + Type);
            }
        }