Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        internal static DxfXData FromBuffer(DxfCodePairBufferReader buffer, string applicationName)
        {
            DxfXDataItem last  = null;
            var          items = new List <DxfXDataItem>();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == (int)DxfXDataType.ApplicationName || pair.Code < 1000)
                {
                    // new xdata or non-xdata
                    break;
                }

                var item = DxfXDataItem.FromBuffer(buffer);
                if (item != null)
                {
                    if (last is DxfXDataString xdataString && item is DxfXDataItemList list)
                    {
                        // re-build last and current item as named group
                        items.RemoveAt(items.Count - 1);
                        item = new DxfXDataNamedList(xdataString.Value, list.Items);
                    }

                    items.Add(item);
                    last = item;
                }
            }

            return(new DxfXData(applicationName, items));
        }
Esempio n. 3
0
        internal static DxfXDataItemList ListFromBuffer(DxfCodePairBufferReader buffer)
        {
            Debug.Assert(buffer.ItemsRemain);
            DxfCodePair pair;
            var         items = new List <DxfXDataItem>();

            while (buffer.ItemsRemain)
            {
                pair = buffer.Peek();
                Debug.Assert(pair.Code >= 1000, "Unexpected non-XDATA code pair");
                if (pair.Code == (int)DxfXDataType.ControlString && pair.StringValue == "}")
                {
                    buffer.Advance();
                    break;
                }

                var item = DxfXDataItem.FromBuffer(buffer);
                if (item != null)
                {
                    items.Add(item);
                }
            }

            return(new DxfXDataItemList(items));
        }
Esempio n. 4
0
        internal static DxfLayer FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfLayer();

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

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

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

                case 62:
                    item.Color = item.ReadColorValue(pair.ShortValue);
                    break;

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

                case 290:
                    item.IsLayerPlotted = (pair.BoolValue);
                    break;

                case 370:
                    item.LineWeight = DxfLineWeight.FromRawValue(pair.ShortValue);
                    break;

                case 390:
                    item.PlotStylePointer = UIntHandle(pair.StringValue);
                    break;

                case 347:
                    item.MaterialHandle = UIntHandle(pair.StringValue);
                    break;

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

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

            return(item);
        }
Esempio n. 5
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
            }
        }
Esempio n. 6
0
        internal static DxfBlockRecord FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfBlockRecord();

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

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

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

                case 70:
                    item.InsertionUnits = (DxfUnits)(pair.ShortValue);
                    break;

                case 280:
                    item.Explodability = BoolShort(pair.ShortValue);
                    break;

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

                case 310:
                    item._bitmapPreviewData.Add((pair.StringValue));
                    break;

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

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

            return(item);
        }
Esempio n. 7
0
        internal static DxfXData FromBuffer(DxfCodePairBufferReader buffer, string applicationName)
        {
            var items = new List <DxfXDataItem>();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == (int)DxfXDataType.ApplicationName || pair.Code < 1000)
                {
                    // new xdata or non-xdata
                    break;
                }

                items.Add(DxfXDataItem.FromBuffer(buffer));
            }

            return(new DxfXData(applicationName, items));
        }
Esempio n. 8
0
        internal static void PopulateFromBuffer(DxfCodePairBufferReader buffer, IDictionary <string, DxfXDataApplicationItemCollection> xdata, string applicationName)
        {
            xdata[applicationName] = new DxfXDataApplicationItemCollection();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == (int)DxfXDataType.ApplicationName || pair.Code < 1000)
                {
                    return;
                }

                var item = DxfXDataItem.FromBuffer(buffer);
                if (item != null)
                {
                    xdata[applicationName].Add(item);
                }
            }
        }
Esempio n. 9
0
        internal static DxfCodePairGroup FromBuffer(DxfCodePairBufferReader buffer, string groupName)
        {
            var items = new List <IDxfCodePairOrGroup>();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == 0)
                {
                    Debug.Assert(false, "Unexpected end of section/file while parsing group.");
                    break;
                }

                buffer.Advance();
                if (pair.Code == GroupCodeNumber)
                {
                    if (pair.StringValue == "}")
                    {
                        // end of group
                        break;
                    }
                    else if (pair.StringValue.StartsWith("{"))
                    {
                        // nested group
                        var subGroupName = GetGroupName(pair.StringValue);
                        var subGroup     = FromBuffer(buffer, subGroupName);
                        items.Add(subGroup);
                    }
                    else
                    {
                        throw new DxfReadException("Unexpected code pair group text", pair);
                    }
                }
                else
                {
                    items.Add(pair);
                }
            }

            return(new DxfCodePairGroup(groupName, items));
        }
        internal static DxfAppId FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfAppId();

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

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

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

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

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

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

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

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

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

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

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

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

                case 71:
                    item.TextGenerationFlags = (int)(pair.ShortValue);
                    break;

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

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

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

                case 1071:
                    item.FontFlags = (pair.IntegerValue);
                    break;

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

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

            return(item);
        }
Esempio n. 12
0
        internal static DxfClass FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version)
        {
            var cls = new DxfClass();

            // version R13 has varying values for the leading 0 code pair
            var pair = buffer.Peek();

            Debug.Assert(pair.Code == 0);
            if (version <= DxfAcadVersion.R13)
            {
                cls.ClassDxfRecordName = pair.StringValue;
            }
            else
            {
                // swallow (0, CLASS)
                Debug.Assert(pair.StringValue == ClassText);
            }

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

                buffer.Advance();
                switch (pair.Code)
                {
                case 1:
                    if (version <= DxfAcadVersion.R13)
                    {
                        cls.CppClassName = pair.StringValue;
                    }
                    else
                    {
                        cls.ClassDxfRecordName = pair.StringValue;
                    }
                    break;

                case 2:
                    if (version <= DxfAcadVersion.R13)
                    {
                        cls.ApplicationName = pair.StringValue;
                    }
                    else
                    {
                        cls.CppClassName = pair.StringValue;
                    }
                    break;

                case 3:
                    if (version >= DxfAcadVersion.R14)
                    {
                        cls.ApplicationName = pair.StringValue;
                    }
                    break;

                case 90:
                    if (version <= DxfAcadVersion.R13)
                    {
                        cls.ClassVersionNumber = pair.IntegerValue;
                    }
                    else
                    {
                        cls.ProxyCapabilities = new DxfProxyCapabilities(pair.IntegerValue);
                    }
                    break;

                case 91:
                    cls.InstanceCount = pair.IntegerValue;
                    break;

                case 280:
                    cls.WasClassLoadedWithFile = !DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;

                case 281:
                    cls.IsEntity = DxfCommonConverters.BoolShort(pair.ShortValue);
                    break;
                }
            }

            return(cls);
        }
Esempio n. 13
0
        internal static DxfView FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfView();

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

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

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

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

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

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

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

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

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

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

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

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

                case 32:
                    item.TargetPoint.Z = (pair.DoubleValue);
                    break;

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

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

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

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

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

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

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

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

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

                case 334:
                    item.SelectionObjectPointer = UIntHandle(pair.StringValue);
                    break;

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

                case 361:
                    item.SunOwnershipPointer = UIntHandle(pair.StringValue);
                    break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(item);
        }
Esempio n. 14
0
        internal static DxfUcs FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfUcs();

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

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

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

                case 10:
                    item.Origin = item.Origin.WithUpdatedX(pair.DoubleValue);
                    break;

                case 20:
                    item.Origin = item.Origin.WithUpdatedY(pair.DoubleValue);
                    break;

                case 30:
                    item.Origin = item.Origin.WithUpdatedZ(pair.DoubleValue);
                    break;

                case 11:
                    item.XAxis = item.XAxis.WithUpdatedX(pair.DoubleValue);
                    break;

                case 21:
                    item.XAxis = item.XAxis.WithUpdatedY(pair.DoubleValue);
                    break;

                case 31:
                    item.XAxis = item.XAxis.WithUpdatedZ(pair.DoubleValue);
                    break;

                case 12:
                    item.YAxis = item.YAxis.WithUpdatedX(pair.DoubleValue);
                    break;

                case 22:
                    item.YAxis = item.YAxis.WithUpdatedY(pair.DoubleValue);
                    break;

                case 32:
                    item.YAxis = item.YAxis.WithUpdatedZ(pair.DoubleValue);
                    break;

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

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

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

                case 71:
                    item.OrthographicType = (DxfOrthographicViewType)(pair.ShortValue);
                    break;

                case 13:
                    item.OrthographicOrigin = item.OrthographicOrigin.WithUpdatedX(pair.DoubleValue);
                    break;

                case 23:
                    item.OrthographicOrigin = item.OrthographicOrigin.WithUpdatedY(pair.DoubleValue);
                    break;

                case 33:
                    item.OrthographicOrigin = item.OrthographicOrigin.WithUpdatedZ(pair.DoubleValue);
                    break;

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

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

            return(item);
        }
Esempio n. 15
0
        internal static DxfLineType FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfLineType();

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

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

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

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

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

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

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

                case 49:
                    // start a new element
                    item.Elements.Add(new DxfLineTypeElement()
                    {
                        DashDotSpaceLength = pair.DoubleValue
                    });
                    break;

                case 74:
                    // add to last element
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().ComplexFlags = pair.ShortValue;
                    }
                    break;

                case 75:
                    // add to last element
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().ShapeNumber = pair.ShortValue;
                    }
                    break;

                case 340:
                    // add to last element
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().StylePointer.Handle = UIntHandle(pair.StringValue);
                    }
                    break;

                case 46:
                    // add to last element
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().ScaleValues.Add(pair.DoubleValue);
                    }
                    break;

                case 50:
                    // add to last element
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().RotationAngle = pair.DoubleValue;
                    }
                    break;

                case 44:
                    // add to last element, start a new offset value
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().Offsets.Add(new DxfVector(pair.DoubleValue, 0.0, 0.0));
                    }
                    break;

                case 45:
                    // add to last element, add to last offset value
                    if (item.Elements.Count > 0 && item.Elements.Last().Offsets.Count > 0)
                    {
                        item.Elements.Last().Offsets.Last().Y = pair.DoubleValue;
                    }
                    break;

                case 9:
                    // add to last element
                    if (item.Elements.Count > 0)
                    {
                        item.Elements.Last().TextString = pair.StringValue;
                    }
                    break;

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

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

            return(item);
        }
Esempio n. 16
0
        internal static DxfViewPort FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfViewPort();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(item);
        }
Esempio n. 17
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);
        }
        internal static DxfDimStyle FromBuffer(DxfCodePairBufferReader buffer)
        {
            var item = new DxfDimStyle();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(item);
        }