using System.Collections.Generic; using System.IO; namespace fis.Vid.Visuals { public class VinnoVisual { /// /// Gets or sets the Display mode of this image. /// public VinnoDisplayMode DisplayMode { get; set; } /// /// Gets the visual type of this Visual. /// protected VinnoVisualType VisualType; /// /// Gets or sets the Indicator of this Visual. /// public VinnoVisualIndicator Indicator { get; set; } /// /// Gets or set the active mode type of this visual. /// public VinnoModeType ActiveModeType { get; set; } /// /// Gets all modse of this visual. /// public IList Modes { get; } public VinnoVisual() { ActiveModeType = VinnoModeType.Undefined; Modes = new List(); //Default is A Indicator = VinnoVisualIndicator.A; //Default is Normal DisplayMode = VinnoDisplayMode.Normal; } public virtual byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var writer = new VinnoStreamWriter(stream); writer.WriteByte((byte)VisualType); writer.WriteByte((byte)DisplayMode); writer.WriteByte((byte)Indicator); writer.WriteByte((byte)ActiveModeType); writer.WriteByte((byte)Modes.Count); foreach (var mode in Modes) { writer.WriteBytes(mode.ToBytes()); } result = stream.ToArray(); } return result; } public static VinnoVisual FromBytes(byte[] bytes) { VinnoVisual result = null; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var visualType = (VinnoVisualType)reader.ReadByte(); if (visualType == VinnoVisualType.V2D) { result = Vinno2DVisual.FromBytes(bytes); } if (visualType == VinnoVisualType.V3D) { result = Vinno3DVisual.FromBytes(bytes); } } return result; } } }