Exemplo n.º 1
0
        /// <summary>
        /// Determines whether the the given object is equal to the current object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Line2DStyle))
            { // wrong type.
                return(false);
            }
            Line2DStyle other = (obj as Line2DStyle);

            if (this.Dashes != null)
            {
                if (this.CasingColor == other.CasingColor &&
                    this.CasingWidth == other.CasingWidth &&
                    this.Color == other.Color &&
                    this.Layer == other.Layer &&
                    this.LineJoin == other.LineJoin &&
                    this.MaxZoom == other.MaxZoom &&
                    this.MinZoom == other.MinZoom &&
                    this.Width == other.Width)
                {
                    if (this.Dashes == null &&
                        other.Dashes == null)
                    {
                        return(true);
                    }
                    else if (this.Dashes == null |
                             other.Dashes == null)
                    {
                        return(false);
                    }
                    else if (this.Dashes.Length == other.Dashes.Length)
                    {
                        for (int idx = 0; idx < this.Dashes.Length; idx++)
                        {
                            if (this.Dashes[idx] != other.Dashes[idx])
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }
                return(false);
            }
            return(this.CasingColor == other.CasingColor &&
                   this.CasingWidth == other.CasingWidth &&
                   this.Color == other.Color &&
                   this.Layer == other.Layer &&
                   this.LineJoin == other.LineJoin &&
                   this.MaxZoom == other.MaxZoom &&
                   this.MinZoom == other.MinZoom &&
                   this.Width == other.Width);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new style and returns it's index.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public ushort AddStyle(Line2D line, int layer)
        {
            Line2DStyle newStyle = Line2DStyle.From(line, layer);
            int         indexOf  = this.LineStyles.IndexOf(newStyle);

            if (indexOf < 0)
            { // the style is not found yet.
                indexOf = this.LineStyles.Count;
                this.LineStyles.Add(newStyle);
            }
            return((ushort)indexOf);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Extracts style information.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public static Line2DStyle From(Line2D line, int layer)
        {
            Line2DStyle newStyle = new Line2DStyle();

            newStyle.Color    = line.Color;
            newStyle.Dashes   = line.Dashes;
            newStyle.LineJoin = line.LineJoin;
            newStyle.MaxZoom  = line.MaxZoom;
            newStyle.MinZoom  = line.MinZoom;
            newStyle.Width    = line.Width;
            newStyle.Layer    = layer;
            return(newStyle);
        }
        /// <summary>
        /// Converts this basic entry into a scene object.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        internal Line2D To(Line2DStyle style)
        {
            Line2D line = new Line2D();

            line.Color    = style.Color;
            line.Dashes   = style.Dashes;
            line.LineJoin = style.LineJoin;
            line.MaxZoom  = style.MaxZoom;
            line.MinZoom  = style.MinZoom;
            line.Width    = style.Width;

            line.X = this.X;
            line.Y = this.Y;

            line.MinX = int.MaxValue;
            line.MaxX = int.MinValue;
            for (int idx = 0; idx < line.X.Length; idx++)
            {
                if (line.X[idx] > line.MaxX)
                {
                    line.MaxX = line.X[idx];
                }
                if (line.X[idx] < line.MinX)
                {
                    line.MinX = line.X[idx];
                }
            }
            line.MinY = int.MaxValue;
            line.MaxY = int.MinValue;
            for (int idx = 0; idx < line.Y.Length; idx++)
            {
                if (line.Y[idx] > line.MaxY)
                {
                    line.MaxY = line.Y[idx];
                }
                if (line.Y[idx] < line.MinY)
                {
                    line.MinY = line.Y[idx];
                }
            }
            return(line);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Extracts style information.
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public static Line2DStyle From(Line2D line, int layer)
 {
     Line2DStyle newStyle = new Line2DStyle();
     newStyle.Color = line.Color;
     newStyle.Dashes = line.Dashes;
     newStyle.LineJoin = line.LineJoin;
     newStyle.MaxZoom = line.MaxZoom;
     newStyle.MinZoom = line.MinZoom;
     newStyle.Width = line.Width;
     newStyle.Layer = layer;
     return newStyle;
 }
        /// <summary>
        /// Deserializes the actual data.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override List <Scene2DEntry> DeSerialize(RuntimeTypeModel typeModel, byte[] data,
                                                           out List <BoxF2D> boxes)
        {
            // decompress if needed.
            Stream stream = null;

            if (_compress)
            {
                stream = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
            }
            else
            { // uncompressed stream.
                stream = new MemoryStream(data);
            }

            // create the memory stream.
            var collection = typeModel.Deserialize(stream, null,
                                                   typeof(PrimitivesCollection)) as PrimitivesCollection;

            if (collection == null)
            {
                throw new Exception("Could not deserialize primitives.");
            }

            // create the collection
            var primitives = new List <Scene2DEntry>();

            if (collection.Icons != null)
            {
                foreach (var primitive in collection.Icons)
                {
                    Icon2DStyle style = _styleIndex.IconStyles[primitive.StyleId];
                    Icon2D      icon  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = icon
                    });
                }
            }
            if (collection.Images != null)
            {
                foreach (var primitive in collection.Images)
                {
                    Image2DStyle style = _styleIndex.ImageStyles[primitive.StyleId];
                    Image2D      image = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = image
                    });
                }
            }
            if (collection.Lines != null)
            {
                foreach (var primitive in collection.Lines)
                {
                    Line2DStyle style = _styleIndex.LineStyles[primitive.StyleId];
                    Line2D      line  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = line
                    });
                }
            }
            if (collection.Points != null)
            {
                foreach (var primitive in collection.Points)
                {
                    Point2DStyle style = _styleIndex.PointStyles[primitive.StyleId];
                    Point2D      point = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = point
                    });
                }
            }
            if (collection.Polygons != null)
            {
                foreach (var primitive in collection.Polygons)
                {
                    Polygon2DStyle style   = _styleIndex.PolygonStyles[primitive.StyleId];
                    Polygon2D      polygon = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = polygon
                    });
                }
            }
            if (collection.Texts != null)
            {
                foreach (var primitive in collection.Texts)
                {
                    Text2DStyle style = _styleIndex.TextStyles[primitive.StyleId];
                    Text2D      text  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = text
                    });
                }
            }
            if (collection.LineTexts != null)
            {
                foreach (var primitive in collection.LineTexts)
                {
                    LineText2DStyle style    = _styleIndex.LineTextStyles[primitive.StyleId];
                    LineText2D      lineText = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = lineText
                    });
                }
            }

            // build the boxes list.
            boxes = new List <BoxF2D>();
            for (int idx = 0; idx < primitives.Count; idx++)
            {
                boxes.Add(primitives[idx].Scene2DPrimitive.GetBox());
            }
            return(primitives);
        }