예제 #1
0
파일: DxfXData.cs 프로젝트: r3sist0r/dxf
        private static DxfPoint ReadPoint(DxfCodePair xCoord, DxfCodePairBufferReader buffer, int expectedFirstCode)
        {
            // first value
            var pair = xCoord;

            Debug.Assert(pair.Code == expectedFirstCode);
            var x = pair.DoubleValue;

            // second value
            Debug.Assert(buffer.ItemsRemain);
            pair = buffer.Peek();
            Debug.Assert(pair.Code == expectedFirstCode + 10);
            var y = pair.DoubleValue;

            buffer.Advance();

            // third value
            Debug.Assert(buffer.ItemsRemain);
            pair = buffer.Peek();
            Debug.Assert(pair.Code == expectedFirstCode + 20);
            var z = pair.DoubleValue;

            buffer.Advance();

            return(new DxfPoint(x, y, z));
        }
예제 #2
0
파일: DxfHeader.cs 프로젝트: nakijun/Dxf
 private static void EnsureCode(DxfCodePair pair, int code)
 {
     if (pair.Code != code)
     {
         Debug.Assert(false, string.Format("Expected code {0}, got {1}", code, pair.Code));
     }
 }
예제 #3
0
파일: DxfHeader.cs 프로젝트: tevfikoguz/dxf
 private static void EnsureCode(DxfCodePair pair, int code)
 {
     if (pair.Code != code)
     {
         Debug.Assert(false, string.Format("Expected code {0}, got {1}", code, pair.Code));
     }
 }
예제 #4
0
파일: DxfBinaryReader.cs 프로젝트: atph/Dxf
        private DxfCodePair GetCodePair()
        {
            if (CanRead())
            {
                var codeOffset = (int)_reader.BaseStream.Position;
                var code = ReadCode();
                var expectedType = DxfCodePair.ExpectedType(code);
                DxfCodePair pair;
                if (expectedType == typeof(short))
                {
                    pair = new DxfCodePair(code, _reader.ReadInt16());
                }
                else if (expectedType == typeof(double))
                {
                    pair = new DxfCodePair(code, _reader.ReadDouble());
                }
                else if (expectedType == typeof(int))
                {
                    pair = new DxfCodePair(code, _reader.ReadInt32());
                }
                else if (expectedType == typeof(long))
                {
                    pair = new DxfCodePair(code, _reader.ReadInt64());
                }
                else if (expectedType == typeof(string))
                {
                    var sb = new StringBuilder();
                    for (int b = _reader.Read(); b != 0; b = _reader.Read())
                        sb.Append((char)b);
                    pair = new DxfCodePair(code, DxfReader.TransformControlCharacters(sb.ToString()));
                }
                else if (expectedType == typeof(bool))
                {
                    pair = new DxfCodePair(code, _reader.ReadInt16() != 0);
                }
                else
                {
                    throw new DxfReadException("Unsupported code " + code, codeOffset);
                }

                pair.Offset = codeOffset;
                return pair;
            }
            else
            {
                return null;
            }
        }
예제 #5
0
파일: DxfHeader.cs 프로젝트: tevfikoguz/dxf
        private static DxfPoint UpdatePoint(DxfCodePair pair, DxfPoint point)
        {
            switch (pair.Code)
            {
            case 10:
                return(point.WithUpdatedX(pair.DoubleValue));

            case 20:
                return(point.WithUpdatedY(pair.DoubleValue));

            case 30:
                return(point.WithUpdatedZ(pair.DoubleValue));

            default:
                return(point);
            }
        }
        internal void TrySetPair(DxfCodePair pair)
        {
            switch (pair.Code)
            {
            case 2:
                Name = pair.StringValue;
                break;

            case 5:
                Handle = DxfCommonConverters.UIntHandle(pair.StringValue);
                break;

            case 330:
                OwnerHandle = DxfCommonConverters.UIntHandle(pair.StringValue);
                break;
            }
        }
예제 #7
0
파일: DxfHeader.cs 프로젝트: nakijun/Dxf
 private static void SetPoint(DxfCodePair pair, DxfPoint point)
 {
     switch (pair.Code)
     {
         case 10:
             point.X = pair.DoubleValue;
             break;
         case 20:
             point.Y = pair.DoubleValue;
             break;
         case 30:
             point.Z = pair.DoubleValue;
             break;
         default:
             break;
     }
 }
예제 #8
0
파일: DxfWriter.cs 프로젝트: zakb120/dxf
        private void WriteValue(int code, object value)
        {
            var type = DxfCodePair.ExpectedType(code);

            if (type == typeof(string))
            {
                WriteString((string)value);
            }
            else if (type == typeof(double))
            {
                WriteDouble((double)value);
            }
            else if (type == typeof(short))
            {
                WriteShort((short)value);
            }
            else if (type == typeof(int))
            {
                WriteInt((int)value);
            }
            else if (type == typeof(long))
            {
                WriteLong((long)value);
            }
            else if (type == typeof(bool))
            {
                if (DxfCodePair.IsPotentialShortAsBool(code) && value.GetType() == typeof(short))
                {
                    WriteShort((short)value);
                }
                else
                {
                    WriteBool((bool)value);
                }
            }
            else if (type == typeof(byte[]))
            {
                WriteBinary((byte[])value);
            }
            else
            {
                throw new InvalidOperationException("No writer available");
            }
        }
예제 #9
0
        public static bool TrySetExtensionData <THasXData>(this THasXData hasXData, DxfCodePair pair, DxfCodePairBufferReader buffer)
            where THasXData : IDxfHasXData, IDxfHasXDataHidden
        {
            if (pair.Code == DxfCodePairGroup.GroupCodeNumber && pair.StringValue.StartsWith("{"))
            {
                buffer.Advance();
                var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                hasXData.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                return(true);
            }
            else if (pair.Code == (int)DxfXDataType.ApplicationName)
            {
                buffer.Advance();
                hasXData.XDataHidden = DxfXData.FromBuffer(buffer, pair.StringValue);
                return(true);
            }

            return(false);
        }
예제 #10
0
        private static void SetPoint(DxfCodePair pair, DxfPoint point)
        {
            switch (pair.Code)
            {
            case 10:
                point.X = pair.DoubleValue;
                break;

            case 20:
                point.Y = pair.DoubleValue;
                break;

            case 30:
                point.Z = pair.DoubleValue;
                break;

            default:
                break;
            }
        }
예제 #11
0
        public DxfCodePair GetCodePair()
        {
            if (_lineEnumerator.MoveNext())
            {
                var codeLine       = _lineEnumerator.Current;
                var codeLineNumber = _lineNumber;
                int code;
                if (string.IsNullOrEmpty(codeLine))
                {
                    // a blank line when expecting a code means we can't parse any further
                    return(null);
                }
                else if (int.TryParse(codeLine, NumberStyles.Integer, CultureInfo.InvariantCulture, out code))
                {
                    if (_lineEnumerator.MoveNext())
                    {
                        DxfCodePair pair         = null;
                        var         valueLine    = _lineEnumerator.Current;
                        var         expectedType = DxfCodePair.ExpectedType(code);
                        if (expectedType == typeof(short))
                        {
                            pair = GetCodePair <short>(code, valueLine, TryParseShortValue, (c, v) => new DxfCodePair(c, v), minValue: short.MinValue, maxValue: short.MaxValue);
                        }
                        else if (expectedType == typeof(double))
                        {
                            pair = GetCodePair <double>(code, valueLine, TryParseDoubleValue, (c, v) => new DxfCodePair(c, v));
                        }
                        else if (expectedType == typeof(int))
                        {
                            pair = GetCodePair <int>(code, valueLine, TryParseIntValue, (c, v) => new DxfCodePair(c, v), minValue: int.MinValue, maxValue: int.MaxValue);
                        }
                        else if (expectedType == typeof(long))
                        {
                            pair = GetCodePair <long>(code, valueLine, TryParseLongValue, (c, v) => new DxfCodePair(c, v), minValue: long.MinValue, maxValue: long.MaxValue);
                        }
                        else if (expectedType == typeof(string))
                        {
                            var value = valueLine.Trim();
                            if (_encoding == null)
                            {
                                // read as ASCII, transform UTF codes
                                value = DxfReader.TransformUnicodeCharacters(value);
                            }

                            pair = new DxfCodePair(code, DxfReader.TransformControlCharacters(value));
                        }
                        else if (expectedType == typeof(bool))
                        {
                            // this should really parse as a short, but it could be anything
                            double result;
                            if (double.TryParse(valueLine, NumberStyles.Float, CultureInfo.InvariantCulture, out result))
                            {
                                if (result < short.MinValue)
                                {
                                    result = short.MinValue;
                                }

                                if (result > short.MaxValue)
                                {
                                    result = short.MaxValue;
                                }

                                pair = DxfCodePair.IsPotentialShortAsBool(code)
                                    ? new DxfCodePair(code, (short)result)
                                    : new DxfCodePair(code, result != 0.0);
                            }
                            else
                            {
                                throw new DxfReadException($"Unsupported value '{valueLine}' for code '{code}'", _lineNumber);
                            }
                        }
                        else if (expectedType == typeof(byte[]))
                        {
                            var data = DxfCommonConverters.HexBytes(valueLine);
                            pair = new DxfCodePair(code, data);
                        }
                        else
                        {
                            throw new DxfReadException("Unsupported code " + code, codeLineNumber);
                        }

                        if (pair != null)
                        {
                            pair.Offset = codeLineNumber;
                        }

                        return(pair);
                    }
                    else
                    {
                        throw new DxfReadException("Expected value", _lineNumber);
                    }
                }
                else
                {
                    if (codeLineNumber == 1)
                    {
                        // parsing the very first code pair failed
                        throw new DxfReadException($"Not a valid DXF file header: `{codeLine}`.", _lineNumber);
                    }
                    else
                    {
                        throw new DxfReadException("Unexpected code value", _lineNumber);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
예제 #12
0
        private DxfCodePair GetCodePair()
        {
            if (_lineEnumerator.MoveNext())
            {
                var codeLine       = _lineEnumerator.Current;
                var codeLineNumber = _lineNumber;
                int code;
                if (string.IsNullOrEmpty(codeLine))
                {
                    // a blank line when expecting a code means we can't parse any further
                    return(null);
                }
                else if (int.TryParse(codeLine, NumberStyles.Integer, CultureInfo.InvariantCulture, out code))
                {
                    if (_lineEnumerator.MoveNext())
                    {
                        DxfCodePair pair         = null;
                        var         valueLine    = _lineEnumerator.Current;
                        var         expectedType = DxfCodePair.ExpectedType(code);
                        if (expectedType == typeof(short))
                        {
                            pair = GetCodePair <short>(code, _lineEnumerator.Current, short.TryParse, NumberStyles.Integer, (c, v) => new DxfCodePair(c, v), minValue: short.MinValue, maxValue: short.MaxValue);
                        }
                        else if (expectedType == typeof(double))
                        {
                            pair = GetCodePair <double>(code, _lineEnumerator.Current, double.TryParse, NumberStyles.Float, (c, v) => new DxfCodePair(c, v));
                        }
                        else if (expectedType == typeof(int))
                        {
                            pair = GetCodePair <int>(code, _lineEnumerator.Current, int.TryParse, NumberStyles.Integer, (c, v) => new DxfCodePair(c, v), minValue: int.MinValue, maxValue: int.MaxValue);
                        }
                        else if (expectedType == typeof(long))
                        {
                            pair = GetCodePair <long>(code, _lineEnumerator.Current, long.TryParse, NumberStyles.Integer, (c, v) => new DxfCodePair(c, v), minValue: long.MinValue, maxValue: long.MaxValue);
                        }
                        else if (expectedType == typeof(string))
                        {
                            pair = new DxfCodePair(code, DxfReader.TransformControlCharacters(_lineEnumerator.Current.Trim()));
                        }
                        else if (expectedType == typeof(bool))
                        {
                            // this should really parse as a short, but it could be anything
                            double result;
                            if (double.TryParse(_lineEnumerator.Current, NumberStyles.Float, CultureInfo.InvariantCulture, out result))
                            {
                                if (result < short.MinValue)
                                {
                                    result = short.MinValue;
                                }

                                if (result > short.MaxValue)
                                {
                                    result = short.MaxValue;
                                }

                                pair = DxfCodePair.IsPotentialShortAsBool(code)
                                    ? new DxfCodePair(code, (short)result)
                                    : new DxfCodePair(code, result != 0.0);
                            }
                            else
                            {
                                throw new DxfReadException($"Unsupported value '{_lineEnumerator.Current}' for code '{code}'", _lineNumber);
                            }
                        }
                        else
                        {
                            throw new DxfReadException("Unsupported code " + code, codeLineNumber);
                        }

                        if (pair != null)
                        {
                            pair.Offset = codeLineNumber;
                        }

                        return(pair);
                    }
                    else
                    {
                        throw new DxfReadException("Expected value", _lineNumber);
                    }
                }
                else
                {
                    throw new DxfReadException("Unexpected code value", _lineNumber);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #13
0
파일: DxfCodePair.cs 프로젝트: atph/Dxf
 public static bool IsEof(DxfCodePair pair)
 {
     return pair.Code == 0 && pair.StringValue == DxfFile.EofText;
 }
예제 #14
0
파일: DxfCodePair.cs 프로젝트: atph/Dxf
 public static bool IsSectionStart(DxfCodePair pair)
 {
     return pair.Code == 0 && pair.StringValue == DxfSection.SectionText;
 }
예제 #15
0
 public DxfReadException(string message, DxfCodePair pair)
     : base(message)
 {
     Offset = pair == null ? -1 : pair.Offset;
 }
예제 #16
0
 public DxfReadException(string message, DxfCodePair pair)
     : base(message)
 {
     Offset = pair == null ? -1 : pair.Offset;
 }
예제 #17
0
 public void WriteCodeValuePair(DxfCodePair pair)
 {
     WriteCode(pair.Code);
     WriteValue(pair.Code, pair.Value);
 }
예제 #18
0
파일: DxfDimStyle.cs 프로젝트: zakb120/dxf
        public bool TryGetStyleFromXDataDifference(DxfXDataApplicationItemCollection xdataItemCollection, out DxfDimStyle style)
        {
            // style data is encoded as
            //   1001 DSTYLE
            //   1002 {
            //     ... style overrides
            //   1002 }

            style = default(DxfDimStyle);
            if (xdataItemCollection == null)
            {
                return(false);
            }

            for (int i = 0; i < xdataItemCollection.Count - 1; i++)
            {
                if (xdataItemCollection[i] is DxfXDataString xdataString && xdataString.Value == XDataStyleName &&
                    xdataItemCollection[i + 1] is DxfXDataItemList itemList)
                {
                    if (itemList.Items.Count % 2 != 0)
                    {
                        // must be an even number
                        return(false);
                    }

                    var codePairs = new List <DxfCodePair>();
                    for (int j = 0; j < itemList.Items.Count; j += 2)
                    {
                        if (!(itemList.Items[j] is DxfXDataInteger codeItem))
                        {
                            // must alternate between int/<data>
                            return(false);
                        }

                        DxfCodePair pair;
                        var         valueItem = itemList.Items[j + 1];
                        var         code      = codeItem.Value;
                        switch (DxfCodePair.ExpectedType(code).Name)
                        {
                        case nameof(Boolean):
                            pair = new DxfCodePair(code, true);
                            break;

                        case nameof(Double) when valueItem is DxfXDataDistance dist:
                            pair = new DxfCodePair(code, dist.Value);
                            break;

                        case nameof(Double) when valueItem is DxfXDataReal real:
                            pair = new DxfCodePair(code, real.Value);
                            break;

                        case nameof(Double) when valueItem is DxfXDataScaleFactor scale:
                            pair = new DxfCodePair(code, scale.Value);
                            break;

                        case nameof(Int16) when valueItem is DxfXDataInteger i32:
                            pair = new DxfCodePair(code, i32.Value);
                            break;

                        case nameof(Int32) when valueItem is DxfXDataLong i32:
                            pair = new DxfCodePair(code, i32.Value);
                            break;

                        case nameof(Int64) when valueItem is DxfXDataLong i32:
                            pair = new DxfCodePair(code, i32.Value);
                            break;

                        case nameof(String) when valueItem is DxfXDataString str:
                            pair = new DxfCodePair(code, str.Value);
                            break;

                        default:
                            // unexpected code pair type
                            return(false);
                        }

                        codePairs.Add(pair);
                    }

                    if (codePairs.Count == 0)
                    {
                        // no difference to apply
                        return(false);
                    }

                    // if we made it this far, there is a difference that should be applied
                    style = Clone();
                    foreach (var pair in codePairs)
                    {
                        style.ApplyCodePair(pair);
                    }

                    return(true);
                }
            }

            return(false);
        }
예제 #19
0
        private DxfCodePair GetCodePair()
        {
            var codeOffset = _totalBytesRead + _miniBufferStart;
            int code;
            if (!TryReadCode(out code))
            {
                return null;
            }

            var expectedType = DxfCodePair.ExpectedType(code);
            DxfCodePair pair;
            if (expectedType == typeof(short))
            {
                short s;
                if (!TryReadInt16(out s))
                {
                    return null;
                }

                pair = new DxfCodePair(code, s);
            }
            else if (expectedType == typeof(double))
            {
                double d;
                if (!TryReadDouble(out d))
                {
                    return null;
                }

                pair = new DxfCodePair(code, d);
            }
            else if (expectedType == typeof(int))
            {
                int i;
                if (!TryReadInt32(out i))
                {
                    return null;
                }

                pair = new DxfCodePair(code, i);
            }
            else if (expectedType == typeof(long))
            {
                long l;
                if (!TryReadInt64(out l))
                {
                    return null;
                }

                pair = new DxfCodePair(code, l);
            }
            else if (expectedType == typeof(string))
            {
                var sb = new StringBuilder();
                byte b;
                for (; TryReadByte(out b) && b != 0;)
                {
                    sb.Append((char)b);
                }

                pair = new DxfCodePair(code, DxfReader.TransformControlCharacters(sb.ToString()));
            }
            else if (expectedType == typeof(bool))
            {
                var value = _reader.ReadInt16();
                pair = DxfCodePair.IsPotentialShortAsBool(code)
                    ? new DxfCodePair(code, value)
                    : new DxfCodePair(code, value != 0);
            }
            else
            {
                throw new DxfReadException("Unsupported code " + code, codeOffset);
            }

            pair.Offset = codeOffset;
            return pair;
        }
예제 #20
0
        public bool TryGetStyleFromXDataDifference(DxfXData xdata, out DxfDimStyle style)
        {
            style = default(DxfDimStyle);
            var dimStyleList = xdata?.Items.OfType <DxfXDataNamedList>().FirstOrDefault(l => l.Name == XDataStyleName);

            if (dimStyleList == null)
            {
                // no dim style override
                return(false);
            }

            if (dimStyleList.Items.Count % 2 != 0)
            {
                // must be an even number
                return(false);
            }

            var codePairs = new List <DxfCodePair>();

            for (int i = 0; i < dimStyleList.Items.Count; i += 2)
            {
                if (!(dimStyleList.Items[i] is DxfXDataInteger codeItem))
                {
                    // must alternate between int/<data>
                    return(false);
                }

                DxfCodePair pair;
                var         valueItem = dimStyleList.Items[i + 1];
                var         code      = codeItem.Value;
                switch (DxfCodePair.ExpectedType(code).Name)
                {
                case nameof(Boolean):
                    pair = new DxfCodePair(code, true);
                    break;

                case nameof(Double) when valueItem is DxfXDataDistance dist:
                    pair = new DxfCodePair(code, dist.Value);
                    break;

                case nameof(Double) when valueItem is DxfXDataReal real:
                    pair = new DxfCodePair(code, real.Value);
                    break;

                case nameof(Double) when valueItem is DxfXDataScaleFactor scale:
                    pair = new DxfCodePair(code, scale.Value);
                    break;

                case nameof(Int16) when valueItem is DxfXDataInteger i32:
                    pair = new DxfCodePair(code, i32.Value);
                    break;

                case nameof(Int32) when valueItem is DxfXDataLong i32:
                    pair = new DxfCodePair(code, i32.Value);
                    break;

                case nameof(Int64) when valueItem is DxfXDataLong i32:
                    pair = new DxfCodePair(code, i32.Value);
                    break;

                case nameof(String) when valueItem is DxfXDataString str:
                    pair = new DxfCodePair(code, str.Value);
                    break;

                default:
                    // unexpected code pair type
                    return(false);
                }

                codePairs.Add(pair);
            }

            if (codePairs.Count == 0)
            {
                // no difference to apply
                return(false);
            }

            // if we made it this far, there is a differnce that should be applied
            style = Clone();
            foreach (var pair in codePairs)
            {
                style.ApplyCodePair(pair);
            }

            return(true);
        }
예제 #21
0
파일: DxfCodePair.cs 프로젝트: zakb120/dxf
 public static bool IsEof(DxfCodePair pair)
 {
     return(pair.Code == 0 && pair.StringValue == DxfFile.EofText);
 }
예제 #22
0
파일: DxfCodePair.cs 프로젝트: zakb120/dxf
 public static bool IsComment(DxfCodePair pair)
 {
     return(pair.Code == CommentCode);
 }
예제 #23
0
        private DxfCodePair GetCodePair()
        {
            if (_lineEnumerator.MoveNext())
            {
                var codeLine       = _lineEnumerator.Current;
                var codeLineNumber = _lineNumber;
                int code;
                if (int.TryParse(codeLine, NumberStyles.Integer, CultureInfo.InvariantCulture, out code))
                {
                    if (_lineEnumerator.MoveNext())
                    {
                        DxfCodePair pair         = null;
                        var         valueLine    = _lineEnumerator.Current;
                        var         expectedType = DxfCodePair.ExpectedType(code);
                        if (expectedType == typeof(short))
                        {
                            pair = GetCodePair <short>(code, _lineEnumerator.Current, short.TryParse, NumberStyles.Integer, (c, v) => new DxfCodePair(c, v));
                        }
                        else if (expectedType == typeof(double))
                        {
                            pair = GetCodePair <double>(code, _lineEnumerator.Current, double.TryParse, NumberStyles.Float, (c, v) => new DxfCodePair(c, v));
                        }
                        else if (expectedType == typeof(int))
                        {
                            pair = GetCodePair <int>(code, _lineEnumerator.Current, int.TryParse, NumberStyles.Integer, (c, v) => new DxfCodePair(c, v));
                        }
                        else if (expectedType == typeof(long))
                        {
                            pair = GetCodePair <long>(code, _lineEnumerator.Current, long.TryParse, NumberStyles.Integer, (c, v) => new DxfCodePair(c, v));
                        }
                        else if (expectedType == typeof(string))
                        {
                            pair = new DxfCodePair(code, DxfReader.TransformControlCharacters(_lineEnumerator.Current.Trim()));
                        }
                        else if (expectedType == typeof(bool))
                        {
                            short result;
                            if (short.TryParse(_lineEnumerator.Current, NumberStyles.Integer, CultureInfo.InvariantCulture, out result))
                            {
                                pair = DxfCodePair.IsPotentialShortAsBool(code)
                                    ? new DxfCodePair(code, result)
                                    : new DxfCodePair(code, result != 0);
                            }
                            else
                            {
                                throw new DxfReadException("Unsupported value for code", _lineNumber);
                            }
                        }
                        else
                        {
                            throw new DxfReadException("Unsupported code " + code, codeLineNumber);
                        }

                        if (pair != null)
                        {
                            pair.Offset = codeLineNumber;
                        }

                        return(pair);
                    }
                    else
                    {
                        throw new DxfReadException("Expected value", _lineNumber);
                    }
                }
                else
                {
                    throw new DxfReadException("Unexpected code value", _lineNumber);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #24
0
        internal static DxfFile LoadFromReader(IDxfCodePairReader reader)
        {
            var file = new DxfFile();

            file.Clear();
            var buffer  = new DxfCodePairBufferReader(reader);
            var version = DxfAcadVersion.R14;

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionStart(pair))
                {
                    buffer.Advance(); // swallow (0, SECTION) pair
                    var section = DxfSection.FromBuffer(buffer, file, version);
                    if (section != null)
                    {
                        switch (section.Type)
                        {
                        case DxfSectionType.Blocks:
                            file.BlocksSection = (DxfBlocksSection)section;
                            break;

                        case DxfSectionType.Entities:
                            file.EntitiesSection = (DxfEntitiesSection)section;
                            break;

                        case DxfSectionType.Classes:
                            file.ClassSection = (DxfClassesSection)section;
                            break;

                        case DxfSectionType.Header:
                            file.HeaderSection = (DxfHeaderSection)section;
                            version            = file.Header.Version;
                            break;

                        case DxfSectionType.Objects:
                            file.ObjectsSection = (DxfObjectsSection)section;
                            break;

                        case DxfSectionType.Tables:
                            file.TablesSection = (DxfTablesSection)section;
                            break;

                        case DxfSectionType.Thumbnail:
                            file.ThumbnailImageSection = (DxfThumbnailImageSection)section;
                            break;
                        }
                    }
                }
                else if (DxfCodePair.IsEof(pair))
                {
                    // swallow and quit
                    buffer.Advance();
                    break;
                }
                else if (DxfCodePair.IsComment(pair))
                {
                    // swallow comments
                    buffer.Advance();
                }
                else
                {
                    // swallow unexpected code pair
                    buffer.Advance();
                }
            }

            Debug.Assert(!buffer.ItemsRemain);
            DxfPointer.BindPointers(file);

            return(file);
        }
예제 #25
0
파일: DxfCodePair.cs 프로젝트: zakb120/dxf
 public static bool IsSectionEnd(DxfCodePair pair)
 {
     return(pair.Code == 0 && pair.StringValue == DxfSection.EndSectionText);
 }
예제 #26
0
파일: DxfWriter.cs 프로젝트: atph/Dxf
 public void WriteCodeValuePair(DxfCodePair pair)
 {
     WriteCode(pair.Code);
     WriteValue(pair.Code, pair.Value);
 }
예제 #27
0
 // setter method
 internal static void SetHeaderVariable(string keyName, DxfCodePair pair, DxfHeader header)
 {
     switch (keyName)
     {
         case ACADMAINTVER:
             EnsureCode(pair, 70);
             header.MaintenenceVersion = (pair.ShortValue);
             break;
         case ACADVER:
             EnsureCode(pair, 1);
             header.Version = DxfAcadVersionStrings.StringToVersion(pair.StringValue);
             break;
         case ANGBASE:
             EnsureCode(pair, 50);
             header.AngleZeroDirection = (pair.DoubleValue);
             break;
         case ANGDIR:
             EnsureCode(pair, 70);
             header.AngleDirection = (DxfAngleDirection)(pair.ShortValue);
             break;
         case ATTDIA:
             EnsureCode(pair, 70);
             header.ShowAttributeEntryDialogs = BoolShort(pair.ShortValue);
             break;
         case ATTMODE:
             EnsureCode(pair, 70);
             header.AttributeVisibility = (DxfAttributeVisibility)(pair.ShortValue);
             break;
         case ATTREQ:
             EnsureCode(pair, 70);
             header.PromptForAttributeOnInsert = BoolShort(pair.ShortValue);
             break;
         case AUNITS:
             EnsureCode(pair, 70);
             header.AngleUnitFormat = (DxfAngleFormat)(pair.ShortValue);
             break;
         case AUPREC:
             EnsureCode(pair, 70);
             header.AngleUnitPrecision = (pair.ShortValue);
             break;
         case AXISMODE:
             EnsureCode(pair, 70);
             header.AxisOn = BoolShort(pair.ShortValue);
             break;
         case AXISUNIT:
             SetPoint(pair, header.AxisTickSpacing);
             break;
         case BLIPMODE:
             EnsureCode(pair, 70);
             header.BlipMode = BoolShort(pair.ShortValue);
             break;
         case CECOLOR:
             EnsureCode(pair, 62);
             header.CurrentEntityColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case CELTSCALE:
             EnsureCode(pair, 40);
             header.CurrentEntityLinetypeScale = (pair.DoubleValue);
             break;
         case CELTYPE:
             EnsureCode(pair, 6);
             header.CurrentEntityLinetype = (pair.StringValue);
             break;
         case CELWEIGHT:
             EnsureCode(pair, 370);
             header.NewObjectLineWeight = (pair.ShortValue);
             break;
         case CEPSNID:
             EnsureCode(pair, 390);
             header.NewObjectPlotStyleHandle = (pair.StringValue);
             break;
         case CEPSNTYPE:
             EnsureCode(pair, 380);
             header.NewObjectPlotStyle = (DxfPlotStyle)(pair.DoubleValue);
             break;
         case CHAMFERA:
             EnsureCode(pair, 40);
             header.FirstChamferDistance = (pair.DoubleValue);
             break;
         case CHAMFERB:
             EnsureCode(pair, 40);
             header.SecondChamferDistance = (pair.DoubleValue);
             break;
         case CHAMFERC:
             EnsureCode(pair, 40);
             header.ChamferLength = (pair.DoubleValue);
             break;
         case CHAMFERD:
             EnsureCode(pair, 40);
             header.ChamferAngle = (pair.DoubleValue);
             break;
         case CLAYER:
             EnsureCode(pair, 8);
             header.CurrentLayer = (pair.StringValue);
             break;
         case CMLJUST:
             EnsureCode(pair, 70);
             header.CurrentMultilineJustification = (DxfJustification)(pair.ShortValue);
             break;
         case CMLSCALE:
             EnsureCode(pair, 40);
             header.CurrentMultilineScale = (pair.DoubleValue);
             break;
         case CMLSTYLE:
             switch (pair.Code)
             {
                 case 7:
                     header.CurrentMultilineStyle = (pair.StringValue);
                     break;
                 case 2:
                     header.CurrentMultilineStyle = (pair.StringValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [7, 2], got {0}", pair.Code));
                     break;
             }
             break;
         case COORDS:
             EnsureCode(pair, 70);
             header.CoordinateDisplay = (DxfCoordinateDisplay)(pair.ShortValue);
             break;
         case CPSNID:
             EnsureCode(pair, 390);
             header.NewObjectPlotStyleHandle = (pair.StringValue);
             break;
         case CSHADOW:
             EnsureCode(pair, 280);
             header.ShadowMode = (DxfShadowMode)(pair.ShortValue);
             break;
         case DELOBJ:
             EnsureCode(pair, 70);
             header.RetainDeletedObjects = BoolShort(pair.ShortValue);
             break;
         case DIMADEC:
             EnsureCode(pair, 70);
             header.AngularDimensionPrecision = (pair.ShortValue);
             break;
         case DIMALT:
             EnsureCode(pair, 70);
             header.UseAlternateDimensioning = BoolShort(pair.ShortValue);
             break;
         case DIMALTD:
             EnsureCode(pair, 70);
             header.AlternateDimensioningDecimalPlaces = (pair.ShortValue);
             break;
         case DIMALTF:
             EnsureCode(pair, 40);
             header.AlternateDimensioningScaleFactor = (pair.DoubleValue);
             break;
         case DIMALTRND:
             EnsureCode(pair, 40);
             header.AlternateDimensioningUnitRounding = (pair.DoubleValue);
             break;
         case DIMALTTD:
             EnsureCode(pair, 70);
             header.AlternateDimensioningToleranceDecimalPlaces = (pair.ShortValue);
             break;
         case DIMALTTZ:
             EnsureCode(pair, 70);
             header.AlternateDimensioningToleranceZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue);
             break;
         case DIMALTU:
             EnsureCode(pair, 70);
             header.AlternateDimensioningUnits = (DxfUnitFormat)(pair.ShortValue);
             break;
         case DIMALTZ:
             EnsureCode(pair, 70);
             header.AlternateDimensioningZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue);
             break;
         case DIMAPOST:
             EnsureCode(pair, 1);
             header.AlternateDimensioningSuffix = (pair.StringValue);
             break;
         case DIMASO:
             EnsureCode(pair, 70);
             header.CreateAssociativeDimensioning = BoolShort(pair.ShortValue);
             break;
         case DIMASSOC:
             EnsureCode(pair, 280);
             header.DimensionObjectAssociativity = (DxfDimensionAssociativity)(pair.ShortValue);
             break;
         case DIMASZ:
             EnsureCode(pair, 40);
             header.DimensioningArrowSize = (pair.DoubleValue);
             break;
         case DIMATFIT:
             EnsureCode(pair, 70);
             header.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue);
             break;
         case DIMAUNIT:
             EnsureCode(pair, 70);
             header.DimensioningAngleFormat = (DxfAngleFormat)(pair.ShortValue);
             break;
         case DIMAZIN:
             EnsureCode(pair, 70);
             header.DimensionAngleZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue);
             break;
         case DIMBLK:
             switch (pair.Code)
             {
                 case 2:
                     header.ArrowBlockName = (pair.StringValue);
                     break;
                 case 1:
                     header.ArrowBlockName = (pair.StringValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [2, 1], got {0}", pair.Code));
                     break;
             }
             break;
         case DIMBLK1:
             EnsureCode(pair, 1);
             header.FirstArrowBlockName = (pair.StringValue);
             break;
         case DIMBLK2:
             EnsureCode(pair, 1);
             header.SecondArrowBlockName = (pair.StringValue);
             break;
         case DIMCEN:
             EnsureCode(pair, 40);
             header.CenterMarkSize = (pair.DoubleValue);
             break;
         case DIMCLRD:
             EnsureCode(pair, 70);
             header.DimensionLineColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case DIMCLRE:
             EnsureCode(pair, 70);
             header.DimensionExtensionLineColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case DIMCLRT:
             EnsureCode(pair, 70);
             header.DimensionTextColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case DIMDEC:
             EnsureCode(pair, 70);
             header.DimensionUnitToleranceDecimalPlaces = (pair.ShortValue);
             break;
         case DIMDLE:
             EnsureCode(pair, 40);
             header.DimensionLineExtension = (pair.DoubleValue);
             break;
         case DIMDLI:
             EnsureCode(pair, 40);
             header.DimensionLineIncrement = (pair.DoubleValue);
             break;
         case DIMDSEP:
             EnsureCode(pair, 70);
             header.DimensionDecimalSeparatorChar = (char)(pair.ShortValue);
             break;
         case DIMEXE:
             EnsureCode(pair, 40);
             header.DimensionExtensionLineExtension = (pair.DoubleValue);
             break;
         case DIMEXO:
             EnsureCode(pair, 40);
             header.DimensionExtensionLineOffset = (pair.DoubleValue);
             break;
         case DIMFAC:
             EnsureCode(pair, 40);
             header.DimensionTextHeightScaleFactor = (pair.DoubleValue);
             break;
         case DIMFIT:
             EnsureCode(pair, 70);
             header.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue);
             break;
         case DIMGAP:
             EnsureCode(pair, 40);
             header.DimensionLineGap = (pair.DoubleValue);
             break;
         case DIMJUST:
             EnsureCode(pair, 70);
             header.DimensionTextJustification = (DxfDimensionTextJustification)(pair.ShortValue);
             break;
         case DIMLDRBLK:
             EnsureCode(pair, 1);
             header.DimensionLeaderBlockName = (pair.StringValue);
             break;
         case DIMLFAC:
             EnsureCode(pair, 40);
             header.DimensionLinearMeasurementsScaleFactor = (pair.DoubleValue);
             break;
         case DIMLIM:
             EnsureCode(pair, 70);
             header.GenerateDimensionLimits = BoolShort(pair.ShortValue);
             break;
         case DIMLUNIT:
             EnsureCode(pair, 70);
             header.DimensionNonAngularUnits = (DxfNonAngularUnits)(pair.ShortValue);
             break;
         case DIMLWD:
             EnsureCode(pair, 70);
             header.DimensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue);
             break;
         case DIMLWE:
             EnsureCode(pair, 70);
             header.DimensionExtensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue);
             break;
         case DIMPOST:
             EnsureCode(pair, 1);
             header.DimensioningSuffix = (pair.StringValue);
             break;
         case DIMRND:
             EnsureCode(pair, 40);
             header.DimensionDistanceRoundingValue = (pair.DoubleValue);
             break;
         case DIMSAH:
             EnsureCode(pair, 70);
             header.UseSeparateArrowBlocksForDimensions = BoolShort(pair.ShortValue);
             break;
         case DIMSCALE:
             EnsureCode(pair, 40);
             header.DimensioningScaleFactor = (pair.DoubleValue);
             break;
         case DIMSD1:
             EnsureCode(pair, 70);
             header.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue);
             break;
         case DIMSD2:
             EnsureCode(pair, 70);
             header.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue);
             break;
         case DIMSE1:
             EnsureCode(pair, 70);
             header.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue);
             break;
         case DIMSE2:
             EnsureCode(pair, 70);
             header.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue);
             break;
         case DIMSHO:
             EnsureCode(pair, 70);
             header.RecomputeDimensionsWhileDragging = BoolShort(pair.ShortValue);
             break;
         case DIMSOXD:
             EnsureCode(pair, 70);
             header.SuppressOutsideExtensionDimensionLines = BoolShort(pair.ShortValue);
             break;
         case DIMSTYLE:
             EnsureCode(pair, 2);
             header.DimensionStyleName = (pair.StringValue);
             break;
         case DIMTAD:
             EnsureCode(pair, 70);
             header.TextAboveDimensionLine = BoolShort(pair.ShortValue);
             break;
         case DIMTDEC:
             EnsureCode(pair, 70);
             header.DimensionToleranceDecimalPlaces = (pair.ShortValue);
             break;
         case DIMTFAC:
             EnsureCode(pair, 40);
             header.DimensionToleranceDisplayScaleFactor = (pair.DoubleValue);
             break;
         case DIMTIH:
             EnsureCode(pair, 70);
             header.DimensionTextInsideHorizontal = BoolShort(pair.ShortValue);
             break;
         case DIMTIX:
             EnsureCode(pair, 70);
             header.ForceDimensionTextInsideExtensions = BoolShort(pair.ShortValue);
             break;
         case DIMTM:
             EnsureCode(pair, 40);
             header.DimensionMinusTolerance = (pair.DoubleValue);
             break;
         case DIMTMOVE:
             EnsureCode(pair, 70);
             header.DimensionTextMovementRule = (DxfDimensionTextMovementRule)(pair.ShortValue);
             break;
         case DIMTOFL:
             EnsureCode(pair, 70);
             header.ForceDimensionLineExtensionsOutsideIfTextIs = BoolShort(pair.ShortValue);
             break;
         case DIMTOH:
             EnsureCode(pair, 70);
             header.DimensionTextOutsideHorizontal = BoolShort(pair.ShortValue);
             break;
         case DIMTOL:
             EnsureCode(pair, 70);
             header.GenerateDimensionTolerances = BoolShort(pair.ShortValue);
             break;
         case DIMTOLJ:
             EnsureCode(pair, 70);
             header.DimensionToleranceVerticalJustification = (DxfJustification)(pair.ShortValue);
             break;
         case DIMTP:
             EnsureCode(pair, 40);
             header.DimensionPlusTolerance = (pair.DoubleValue);
             break;
         case DIMTSZ:
             EnsureCode(pair, 40);
             header.DimensioningTickSize = (pair.DoubleValue);
             break;
         case DIMTVP:
             EnsureCode(pair, 40);
             header.DimensionVerticalTextPosition = (pair.DoubleValue);
             break;
         case DIMTXSTY:
             EnsureCode(pair, 7);
             header.DimensionTextStyle = (pair.StringValue);
             break;
         case DIMTXT:
             EnsureCode(pair, 40);
             header.DimensioningTextHeight = (pair.DoubleValue);
             break;
         case DIMTZIN:
             EnsureCode(pair, 70);
             header.DimensionToleranceZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue);
             break;
         case DIMUNIT:
             EnsureCode(pair, 70);
             header.DimensionUnitFormat = (DxfUnitFormat)(pair.ShortValue);
             break;
         case DIMUPT:
             EnsureCode(pair, 70);
             header.DimensionCursorControlsTextPosition = BoolShort(pair.ShortValue);
             break;
         case DIMZIN:
             EnsureCode(pair, 70);
             header.DimensionUnitZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue);
             break;
         case DISPSILH:
             EnsureCode(pair, 70);
             header.DisplaySilhouetteCurvesInWireframeMode = BoolShort(pair.ShortValue);
             break;
         case DRAGMODE:
             EnsureCode(pair, 70);
             header.DragMode = (DxfDragMode)(pair.ShortValue);
             break;
         case DRAGVS:
             EnsureCode(pair, 349);
             header.ThreeDSolidCreationVisualStyle = (pair.StringValue);
             break;
         case DWGCODEPAGE:
             switch (pair.Code)
             {
                 case 70:
                     header.DrawingCodePage = StringShort(pair.ShortValue);
                     break;
                 case 3:
                     header.DrawingCodePage = (pair.StringValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [70, 3], got {0}", pair.Code));
                     break;
             }
             break;
         case ELEVATION:
             EnsureCode(pair, 40);
             header.Elevation = (pair.DoubleValue);
             break;
         case ENDCAPS:
             EnsureCode(pair, 280);
             header.EndCapSetting = (DxfEndCapSetting)(pair.ShortValue);
             break;
         case EXTMAX:
             SetPoint(pair, header.MaximumDrawingExtents);
             break;
         case EXTMIN:
             SetPoint(pair, header.MinimumDrawingExtents);
             break;
         case EXTNAMES:
             EnsureCode(pair, 290);
             header.UseACad2000SymbolTableNaming = (pair.BoolValue);
             break;
         case FILLETRAD:
             EnsureCode(pair, 40);
             header.FilletRadius = (pair.DoubleValue);
             break;
         case FILLMODE:
             EnsureCode(pair, 70);
             header.FillModeOn = BoolShort(pair.ShortValue);
             break;
         case FINGERPRINTGUID:
             EnsureCode(pair, 2);
             header.FingerprintGuid = GuidString(pair.StringValue);
             break;
         case HALOGAP:
             EnsureCode(pair, 280);
             header.HaloGapPercent = (double)(pair.ShortValue);
             break;
         case HANDLING:
             EnsureCode(pair, 70);
             header.HandlesEnabled = BoolShort(pair.ShortValue);
             break;
         case HANDSEED:
             EnsureCode(pair, 5);
             header.NextAvailableHandle = UIntHandle(pair.StringValue);
             break;
         case HIDETEXT:
             switch (pair.Code)
             {
                 case 290:
                     header.HideTextObjectsWhenProducintHiddenView = (pair.BoolValue);
                     break;
                 case 280:
                     header.HideTextObjectsWhenProducintHiddenView = BoolShort(pair.ShortValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [290, 280], got {0}", pair.Code));
                     break;
             }
             break;
         case HYPERLINKBASE:
             EnsureCode(pair, 1);
             header.HyperlinBase = (pair.StringValue);
             break;
         case INDEXCTL:
             EnsureCode(pair, 280);
             header.LayerAndSpatialIndexSaveMode = (DxfLayerAndSpatialIndexSaveMode)(pair.ShortValue);
             break;
         case INSBASE:
             SetPoint(pair, header.InsertionBase);
             break;
         case INSUNITS:
             EnsureCode(pair, 70);
             header.DefaultDrawingUnits = (DxfUnits)(pair.ShortValue);
             break;
         case INTERFERECOLOR:
             EnsureCode(pair, 62);
             header.InterferenceObjectColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case INTERFEREOBJVS:
             EnsureCode(pair, 345);
             header.InterferenceObjectVisualStylePointer = (pair.StringValue);
             break;
         case INTERFEREVPVS:
             EnsureCode(pair, 346);
             header.InterferenceViewPortVisualStylePointer = (pair.StringValue);
             break;
         case INTERSECTIONCOLOR:
             EnsureCode(pair, 70);
             header.IntersectionPolylineColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case INTERSECTIONDISPLAY:
             switch (pair.Code)
             {
                 case 290:
                     header.DisplayIntersectionPolylines = (pair.BoolValue);
                     break;
                 case 280:
                     header.DisplayIntersectionPolylines = BoolShort(pair.ShortValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [290, 280], got {0}", pair.Code));
                     break;
             }
             break;
         case JOINSTYLE:
             EnsureCode(pair, 280);
             header.LineweightJointSetting = (DxfJoinStyle)(pair.ShortValue);
             break;
         case LIMCHECK:
             EnsureCode(pair, 70);
             header.UseLimitsChecking = BoolShort(pair.ShortValue);
             break;
         case LIMMAX:
             SetPoint(pair, header.MaximumDrawingLimits);
             break;
         case LIMMIN:
             SetPoint(pair, header.MinimumDrawingLimits);
             break;
         case LTSCALE:
             EnsureCode(pair, 40);
             header.LinetypeScale = (pair.DoubleValue);
             break;
         case LUNITS:
             EnsureCode(pair, 70);
             header.UnitFormat = (DxfUnitFormat)(pair.ShortValue);
             break;
         case LUPREC:
             EnsureCode(pair, 70);
             header.UnitPrecision = (pair.ShortValue);
             break;
         case LWDISPLAY:
             EnsureCode(pair, 290);
             header.DisplayLinewieghtInModelAndLayoutTab = (pair.BoolValue);
             break;
         case MAXACTVP:
             EnsureCode(pair, 70);
             header.MaximumActiveViewports = (pair.ShortValue);
             break;
         case MEASUREMENT:
             EnsureCode(pair, 70);
             header.DrawingUnits = (DxfDrawingUnits)(pair.ShortValue);
             break;
         case MENU:
             EnsureCode(pair, 1);
             header.FileName = (pair.StringValue);
             break;
         case MIRRTEXT:
             EnsureCode(pair, 70);
             header.MirrorText = BoolShort(pair.ShortValue);
             break;
         case OBSCOLOR:
             EnsureCode(pair, 70);
             header.ObscuredLineColor = DxfColor.FromRawValue(pair.ShortValue);
             break;
         case OBSLTYPE:
             EnsureCode(pair, 280);
             header.ObscuredLineTypeStyle = (DxfLinetypeStyle)(pair.ShortValue);
             break;
         case ORTHOMODE:
             EnsureCode(pair, 70);
             header.DrawOrthoganalLines = BoolShort(pair.ShortValue);
             break;
         case OSMODE:
             EnsureCode(pair, 70);
             header.ObjectSnapFlags = (int)(pair.ShortValue);
             break;
         case PDMODE:
             EnsureCode(pair, 70);
             header.PointDisplayMode = (int)(pair.ShortValue);
             break;
         case PDSIZE:
             EnsureCode(pair, 40);
             header.PointDisplaySize = (pair.DoubleValue);
             break;
         case PELEVATION:
             EnsureCode(pair, 40);
             header.PaperspaceElevation = (pair.DoubleValue);
             break;
         case PEXTMAX:
             SetPoint(pair, header.PaperspaceMaximumDrawingExtents);
             break;
         case PEXTMIN:
             SetPoint(pair, header.PaperspaceMinimumDrawingExtents);
             break;
         case PICKSTYLE:
             EnsureCode(pair, 70);
             header.PickStyle = (DxfPickStyle)(pair.ShortValue);
             break;
         case PINSBASE:
             SetPoint(pair, header.PaperspaceInsertionBase);
             break;
         case PLIMCHECK:
             EnsureCode(pair, 70);
             header.LimitCheckingInPaperspace = BoolShort(pair.ShortValue);
             break;
         case PLIMMAX:
             SetPoint(pair, header.PaperspaceMaximumDrawingLimits);
             break;
         case PLIMMIN:
             SetPoint(pair, header.PaperspaceMinimumDrawingLimits);
             break;
         case PLINEGEN:
             EnsureCode(pair, 70);
             header.IsPolylineContinuousAroundVerticies = BoolShort(pair.ShortValue);
             break;
         case PLINEWID:
             EnsureCode(pair, 40);
             header.DefaultPolylineWidth = (pair.DoubleValue);
             break;
         case PROJECTNAME:
             EnsureCode(pair, 1);
             header.ProjectName = (pair.StringValue);
             break;
         case PROXYGRAPHICS:
             EnsureCode(pair, 70);
             header.SaveProxyGraphics = BoolShort(pair.ShortValue);
             break;
         case PSLTSCALE:
             EnsureCode(pair, 70);
             header.ScaleLinetypesInPaperspace = BoolShort(pair.ShortValue);
             break;
         case PSTYLEMODE:
             EnsureCode(pair, 290);
             header.UsesColorDependentPlotStyleTables = (pair.BoolValue);
             break;
         case PSVPSCALE:
             EnsureCode(pair, 40);
             header.ViewportViewScaleFactor = (pair.DoubleValue);
             break;
         case PUCSBASE:
             EnsureCode(pair, 2);
             header.PaperspaceUCSDefinitionName = (pair.StringValue);
             break;
         case PUCSNAME:
             EnsureCode(pair, 2);
             header.PaperspaceUCSName = (pair.StringValue);
             break;
         case PUCSORG:
             SetPoint(pair, header.PaperspaceUCSOrigin);
             break;
         case PUCSORGBACK:
             SetPoint(pair, header.PaperspaceUCSOriginBack);
             break;
         case PUCSORGBOTTOM:
             SetPoint(pair, header.PaperspaceUCSOriginBottom);
             break;
         case PUCSORGFRONT:
             SetPoint(pair, header.PaperspaceUCSOriginFront);
             break;
         case PUCSORGLEFT:
             SetPoint(pair, header.PaperspaceUCSOriginLeft);
             break;
         case PUCSORGRIGHT:
             SetPoint(pair, header.PaperspaceUCSOriginRight);
             break;
         case PUCSORGTOP:
             SetPoint(pair, header.PaperspaceUCSOriginTop);
             break;
         case PUCSORTHOREF:
             EnsureCode(pair, 2);
             header.PaperspaceOrthoUCSReference = (pair.StringValue);
             break;
         case PUCSORTHOVIEW:
             EnsureCode(pair, 70);
             header.PaperspaceOrthographicViewType = (DxfOrthographicViewType)(pair.ShortValue);
             break;
         case PUCSXDIR:
             SetPoint(pair, header.PaperspaceXAxis);
             break;
         case PUCSYDIR:
             SetPoint(pair, header.PaperspaceYAxis);
             break;
         case QTEXTMODE:
             EnsureCode(pair, 70);
             header.UseQuickTextMode = BoolShort(pair.ShortValue);
             break;
         case REGENMODE:
             EnsureCode(pair, 70);
             header.UseRegenMode = BoolShort(pair.ShortValue);
             break;
         case SHADEDGE:
             EnsureCode(pair, 70);
             header.EdgeShading = (DxfShadeEdgeMode)(pair.ShortValue);
             break;
         case SHADEDIF:
             EnsureCode(pair, 70);
             header.PercentAmbientToDiffuse = (pair.ShortValue);
             break;
         case SHADOWPLANELOCATION:
             EnsureCode(pair, 40);
             header.ShadowPlaneZOffset = (pair.DoubleValue);
             break;
         case SKETCHINC:
             EnsureCode(pair, 40);
             header.SketchRecordIncrement = (pair.DoubleValue);
             break;
         case SKPOLY:
             EnsureCode(pair, 70);
             header.PolylineSketchMode = (DxfPolySketchMode)(pair.ShortValue);
             break;
         case SORTENTS:
             EnsureCode(pair, 280);
             header.ObjectSortingMethodsFlags = (int)(pair.ShortValue);
             break;
         case SPLFRAME:
             EnsureCode(pair, 70);
             header.DisplaySplinePolygonControl = BoolShort(pair.ShortValue);
             break;
         case SPLINESEGS:
             EnsureCode(pair, 70);
             header.LineSegmentsPerSplinePatch = (pair.ShortValue);
             break;
         case SPLINETYPE:
             EnsureCode(pair, 70);
             header.PEditSplineCurveType = (DxfPolylineCurvedAndSmoothSurfaceType)(pair.ShortValue);
             break;
         case SURFTAB1:
             EnsureCode(pair, 70);
             header.MeshTabulationsInFirstDirection = (pair.ShortValue);
             break;
         case SURFTAB2:
             EnsureCode(pair, 70);
             header.MeshTabulationsInSecondDirection = (pair.ShortValue);
             break;
         case SURFTYPE:
             EnsureCode(pair, 70);
             header.PEditSmoothSurfaceType = (DxfPolylineCurvedAndSmoothSurfaceType)(pair.ShortValue);
             break;
         case SURFU:
             EnsureCode(pair, 70);
             header.PEditSmoothMDensith = (pair.ShortValue);
             break;
         case SURFV:
             EnsureCode(pair, 70);
             header.PEditSmoothNDensith = (pair.ShortValue);
             break;
         case TDCREATE:
             EnsureCode(pair, 40);
             header.CreationDate = DateDouble(pair.DoubleValue);
             break;
         case TDINDWG:
             EnsureCode(pair, 40);
             header.TimeInDrawing = TimeSpanDouble(pair.DoubleValue);
             break;
         case TDUCREATE:
             EnsureCode(pair, 40);
             header.CreationDateUniversal = DateDouble(pair.DoubleValue);
             break;
         case TDUPDATE:
             EnsureCode(pair, 40);
             header.UpdateDate = DateDouble(pair.DoubleValue);
             break;
         case TDUSRTIMER:
             EnsureCode(pair, 40);
             header.UserElapsedTimer = TimeSpanDouble(pair.DoubleValue);
             break;
         case TDUUPDATE:
             EnsureCode(pair, 40);
             header.UpdateDateUniversal = DateDouble(pair.DoubleValue);
             break;
         case TEXTSIZE:
             EnsureCode(pair, 40);
             header.DefaultTextHeight = (pair.DoubleValue);
             break;
         case TEXTSTYLE:
             EnsureCode(pair, 7);
             header.TextStyle = (pair.StringValue);
             break;
         case THICKNESS:
             EnsureCode(pair, 40);
             header.Thickness = (pair.DoubleValue);
             break;
         case TILEMODE:
             EnsureCode(pair, 70);
             header.PreviousReleaseTileCompatability = BoolShort(pair.ShortValue);
             break;
         case TRACEWID:
             EnsureCode(pair, 40);
             header.TraceWidth = (pair.DoubleValue);
             break;
         case TREEDEPTH:
             EnsureCode(pair, 70);
             header.SpacialIndexMaxDepth = (pair.ShortValue);
             break;
         case UCSBASE:
             EnsureCode(pair, 2);
             header.UCSDefinitionName = (pair.StringValue);
             break;
         case UCSNAME:
             switch (pair.Code)
             {
                 case 1:
                     header.UCSName = (pair.StringValue);
                     break;
                 case 2:
                     header.UCSName = (pair.StringValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [1, 2], got {0}", pair.Code));
                     break;
             }
             break;
         case UCSORG:
             SetPoint(pair, header.UCSOrigin);
             break;
         case UCSORGBACK:
             SetPoint(pair, header.UCSOriginBack);
             break;
         case UCSORGBOTTOM:
             SetPoint(pair, header.UCSOriginBottom);
             break;
         case UCSORGFRONT:
             SetPoint(pair, header.UCSOriginFront);
             break;
         case UCSORGLEFT:
             SetPoint(pair, header.UCSOriginLeft);
             break;
         case UCSORGRIGHT:
             SetPoint(pair, header.UCSOriginRight);
             break;
         case UCSORGTOP:
             SetPoint(pair, header.UCSOriginTop);
             break;
         case UCSORTHOREF:
             EnsureCode(pair, 2);
             header.OrthoUCSReference = (pair.StringValue);
             break;
         case UCSORTHOVIEW:
             EnsureCode(pair, 70);
             header.OrthgraphicViewType = (DxfOrthographicViewType)(pair.ShortValue);
             break;
         case UCSXDIR:
             SetPoint(pair, header.UCSXAxis);
             break;
         case UCSYDIR:
             SetPoint(pair, header.UCSYAxis);
             break;
         case UNITMODE:
             EnsureCode(pair, 70);
             header.DisplayFractionsInInput = BoolShort(pair.ShortValue);
             break;
         case USERI1:
             EnsureCode(pair, 70);
             header.UserInt1 = (pair.ShortValue);
             break;
         case USERI2:
             EnsureCode(pair, 70);
             header.UserInt2 = (pair.ShortValue);
             break;
         case USERI3:
             EnsureCode(pair, 70);
             header.UserInt3 = (pair.ShortValue);
             break;
         case USERI4:
             EnsureCode(pair, 70);
             header.UserInt4 = (pair.ShortValue);
             break;
         case USERI5:
             EnsureCode(pair, 70);
             header.UserInt5 = (pair.ShortValue);
             break;
         case USERR1:
             EnsureCode(pair, 40);
             header.UserReal1 = (pair.DoubleValue);
             break;
         case USERR2:
             EnsureCode(pair, 40);
             header.UserReal2 = (pair.DoubleValue);
             break;
         case USERR3:
             EnsureCode(pair, 40);
             header.UserReal3 = (pair.DoubleValue);
             break;
         case USERR4:
             EnsureCode(pair, 40);
             header.UserReal4 = (pair.DoubleValue);
             break;
         case USERR5:
             EnsureCode(pair, 40);
             header.UserReal5 = (pair.DoubleValue);
             break;
         case USRTIMER:
             EnsureCode(pair, 70);
             header.UserTimerOn = BoolShort(pair.ShortValue);
             break;
         case VERSIONGUID:
             EnsureCode(pair, 2);
             header.VersionGuid = GuidString(pair.StringValue);
             break;
         case VISRETAIN:
             EnsureCode(pair, 70);
             header.RetainXRefDependentVisibilitySettings = BoolShort(pair.ShortValue);
             break;
         case WORLDVIEW:
             EnsureCode(pair, 70);
             header.SetUCSToWCSInDViewOrVPoint = BoolShort(pair.ShortValue);
             break;
         case XCLIPFRAME:
             switch (pair.Code)
             {
                 case 290:
                     header.IsXRefClippingBoundaryVisible = (pair.BoolValue);
                     break;
                 case 280:
                     header.IsXRefClippingBoundaryVisible = BoolShort(pair.ShortValue);
                     break;
                 default:
                     Debug.Assert(false, string.Format("Expected code [290, 280], got {0}", pair.Code));
                     break;
             }
             break;
         case XEDIT:
             EnsureCode(pair, 290);
             header.CanUseInPlaceReferenceEditing = (pair.BoolValue);
             break;
         default:
             // unsupported variable
             break;
     }
 }
예제 #28
0
        private DxfCodePair GetCodePair()
        {
            var codeOffset = _totalBytesRead + _miniBufferStart;
            int code;

            if (!TryReadCode(out code))
            {
                return(null);
            }

            var         expectedType = DxfCodePair.ExpectedType(code);
            DxfCodePair pair;

            if (expectedType == typeof(short))
            {
                short s;
                if (!TryReadInt16(out s))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, s);
            }
            else if (expectedType == typeof(double))
            {
                double d;
                if (!TryReadDouble(out d))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, d);
            }
            else if (expectedType == typeof(int))
            {
                int i;
                if (!TryReadInt32(out i))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, i);
            }
            else if (expectedType == typeof(long))
            {
                long l;
                if (!TryReadInt64(out l))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, l);
            }
            else if (expectedType == typeof(string))
            {
                var  sb = new StringBuilder();
                byte b;
                for (; TryReadByte(out b) && b != 0;)
                {
                    sb.Append((char)b);
                }

                pair = new DxfCodePair(code, DxfReader.TransformControlCharacters(sb.ToString()));
            }
            else if (expectedType == typeof(bool))
            {
                var value = _reader.ReadInt16();
                pair = DxfCodePair.IsPotentialShortAsBool(code)
                    ? new DxfCodePair(code, value)
                    : new DxfCodePair(code, value != 0);
            }
            else
            {
                throw new DxfReadException("Unsupported code " + code, codeOffset);
            }

            pair.Offset = codeOffset;
            return(pair);
        }
예제 #29
0
파일: DxfCodePair.cs 프로젝트: atph/Dxf
 public static bool IsComment(DxfCodePair pair)
 {
     return pair.Code == CommentCode;
 }
예제 #30
0
 internal void TrySetPair(DxfCodePair pair)
 {
     switch (pair.Code)
     {
         case 2:
             Name = pair.StringValue;
             break;
         case 5:
             Handle = DxfCommonConverters.UIntHandle(pair.StringValue);
             break;
         case 330:
             OwnerHandle = DxfCommonConverters.UIntHandle(pair.StringValue);
             break;
     }
 }
예제 #31
0
        internal DxfCodePair GetCodePair()
        {
            var codeOffset = _totalBytesRead + _miniBufferStart;
            int code;

            if (!TryReadCode(out code))
            {
                return(null);
            }

            var         expectedType = DxfCodePair.ExpectedType(code);
            DxfCodePair pair;

            if (expectedType == typeof(short))
            {
                short s;
                if (!TryReadInt16(out s))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, s);
            }
            else if (expectedType == typeof(double))
            {
                double d;
                if (!TryReadDouble(out d))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, d);
            }
            else if (expectedType == typeof(int))
            {
                int i;
                if (!TryReadInt32(out i))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, i);
            }
            else if (expectedType == typeof(long))
            {
                long l;
                if (!TryReadInt64(out l))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, l);
            }
            else if (expectedType == typeof(string))
            {
                var  sb = new StringBuilder();
                byte b;
                for (; TryReadByte(out b) && b != 0;)
                {
                    sb.Append((char)b);
                }

                pair = new DxfCodePair(code, sb.ToString());
            }
            else if (expectedType == typeof(bool))
            {
                if (_isPostR13File)
                {
                    // after R13 bools are encoded as a single byte
                    if (!TryReadByte(out var value))
                    {
                        return(null);
                    }

                    pair = new DxfCodePair(code, value != 0);
                }
                else
                {
                    if (!TryReadInt16(out var value))
                    {
                        return(null);
                    }

                    pair = DxfCodePair.IsPotentialShortAsBool(code)
                        ? new DxfCodePair(code, value)
                        : new DxfCodePair(code, value != 0);
                }
            }
            else if (expectedType == typeof(byte[]))
            {
                if (!TryReadByte(out var length))
                {
                    return(null);
                }

                if (!TryReadBytes(length, out var data))
                {
                    return(null);
                }

                pair = new DxfCodePair(code, data);
            }
            else
            {
                throw new DxfReadException("Unsupported code " + code, codeOffset);
            }

            pair.Offset = codeOffset;
            return(pair);
        }