Exemple #1
0
        private static LayerState Read(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            TextCodeValueReader chunk = new TextCodeValueReader(new StreamReader(stream, Encoding.UTF8, true));

            chunk.Next();
            if (chunk.Code == 0)
            {
                if (chunk.ReadString() != LayerStateDictionary)
                {
                    throw new Exception("File not valid.");
                }
            }
            else
            {
                throw new Exception("File not valid.");
            }
            chunk.Next();
            return(ReadLayerState(chunk));
        }
Exemple #2
0
        private static LayerStateProperties ReadLayerProperties(TextCodeValueReader chunk)
        {
            LayerPropertiesFlags flags = LayerPropertiesFlags.Plot;
            string lineType            = String.Empty;
            //string plotStyle = string.Empty;
            AciColor     color        = AciColor.Default;
            Lineweight   lineweight   = Lineweight.Default;
            Transparency transparency = new Transparency(0);

            string name = chunk.ReadString();

            chunk.Next();

            while (chunk.Code != 8 && chunk.Code != 0)
            {
                switch (chunk.Code)
                {
                case 90:
                    flags = (LayerPropertiesFlags)chunk.ReadInt();
                    chunk.Next();
                    break;

                case 62:
                    color = AciColor.FromCadIndex(chunk.ReadShort());
                    chunk.Next();
                    break;

                case 370:
                    lineweight = (Lineweight)chunk.ReadShort();
                    chunk.Next();
                    break;

                case 6:
                    lineType = chunk.ReadString();
                    chunk.Next();
                    break;

                case 2:
                    //plotStyle = chunk.ReadString();
                    chunk.Next();
                    break;

                case 440:
                    int alpha = chunk.ReadInt();
                    transparency = alpha == 0 ? new Transparency(0) : Transparency.FromAlphaValue(alpha);
                    chunk.Next();
                    break;

                case 92:
                    color = AciColor.FromTrueColor(chunk.ReadInt());
                    chunk.Next();
                    break;

                default:
                    chunk.Next();
                    break;
                }
            }

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            LayerStateProperties properties = new LayerStateProperties(name)
            {
                Flags        = flags,
                Color        = color,
                Lineweight   = lineweight,
                LinetypeName = lineType,
                //PlotStyleName = plotStyle,
                Transparency = transparency
            };

            return(properties);
        }
Exemple #3
0
        private static LayerState ReadLayerState(TextCodeValueReader chunk)
        {
            string name         = string.Empty;
            string description  = string.Empty;
            string currentLayer = Layer.DefaultName;
            bool   paperSpace   = false;
            List <LayerStateProperties> layerProperties = new List <LayerStateProperties>();

            if (chunk.Code == 0)
            {
                if (chunk.ReadString() != LayerStateName)
                {
                    throw new Exception("File not valid.");
                }
            }
            else
            {
                throw new Exception("File not valid.");
            }
            chunk.Next();

            while (chunk.Code != 0)
            {
                switch (chunk.Code)
                {
                case 1:
                    name = chunk.ReadString();
                    chunk.Next();
                    break;

                case 91:     // unknown code
                    chunk.Next();
                    break;

                case 301:
                    description = chunk.ReadString();
                    chunk.Next();
                    break;

                case 290:
                    paperSpace = chunk.ReadBool();
                    chunk.Next();
                    break;

                case 302:     // active layer
                    currentLayer = chunk.ReadString();
                    chunk.Next();
                    break;

                case 8:     // begin reading layer properties
                    layerProperties.Add(ReadLayerProperties(chunk));
                    break;

                default:
                    chunk.Next();
                    break;
                }
            }

            LayerState states = new LayerState(name)
            {
                Description  = description,
                CurrentLayer = currentLayer,
                PaperSpace   = paperSpace
            };

            foreach (LayerStateProperties lp in layerProperties)
            {
                if (!states.Properties.ContainsKey(lp.Name))
                {
                    states.Properties.Add(lp.Name, lp);
                }
            }

            return(states);
        }