123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System.IO;
- using System.Collections.Generic;
- namespace fis.Vid.Visuals
- {
- public class Vinno2DVisual:VinnoVisual
- {
- /// <summary>
- /// Gets all LogicalCoordinates of this visual.
- /// </summary>
- public Dictionary<VinnoVisualAreaType, VinnoLogicalCoordinate> LogicalCoordinates { get; }
- /// <summary>
- /// Gets all PhysicalCoordinates of this visual.
- /// </summary>
- public Dictionary<VinnoVisualAreaType, VinnoPhysicalCoordinate> PhysicalCoordinates { get; }
- public Vinno2DVisual()
- {
- VisualType = VinnoVisualType.V2D;
- LogicalCoordinates = new Dictionary<VinnoVisualAreaType, VinnoLogicalCoordinate>();
- PhysicalCoordinates = new Dictionary<VinnoVisualAreaType, VinnoPhysicalCoordinate>();
- }
- public override byte[] ToBytes()
- {
- var baseData = base.ToBytes();
- byte[] result;
- using (var stream = new MemoryStream())
- {
- stream.Write(baseData,0, baseData.Length);
- var writer = new VinnoStreamWriter(stream);
- writer.WriteByte((byte)PhysicalCoordinates.Count);
- foreach (var key in PhysicalCoordinates.Keys)
- {
- writer.WriteByte((byte)key);
- writer.WriteBytes(PhysicalCoordinates[key].ToBytes());
- }
- writer.WriteByte((byte)LogicalCoordinates.Count);
- foreach (var key in LogicalCoordinates.Keys)
- {
- writer.WriteByte((byte)key);
- writer.WriteBytes(LogicalCoordinates[key].ToBytes());
- }
- result = stream.ToArray();
- }
- return result;
- }
- public new static VinnoVisual FromBytes(byte[] bytes)
- {
- Vinno2DVisual result = null;
- using (var stream = new MemoryStream(bytes))
- {
- stream.Position = 0;
- var reader = new VinnoStreamReader(stream);
- var visualType = (VinnoVisualType)reader.ReadByte();
- var displayMode = (VinnoDisplayMode)reader.ReadByte();
- if (visualType == VinnoVisualType.V2D)
- {
- var indicator = (VinnoVisualIndicator) reader.ReadByte();
- var activeModeType = (VinnoModeType)reader.ReadByte();
- var modeCount = reader.ReadByte();
- var modes = new List<VinnoMode>();
- for (var i = 0; i < modeCount; i++)
- {
- var mode = VinnoMode.FromBytes(reader.ReadBytes());
- modes.Add(mode);
- }
- result = new Vinno2DVisual {Indicator = indicator };
- foreach (var mode in modes)
- {
- result.Modes.Add(mode);
- }
- result.ActiveModeType = activeModeType;
- var physicalCoordinateCount = reader.ReadByte();
- var physicalCoordinates = new Dictionary<VinnoVisualAreaType, VinnoPhysicalCoordinate>();
- for (var i = 0; i < physicalCoordinateCount; i++)
- {
- var visualAreaType = (VinnoVisualAreaType)reader.ReadByte();
- var physicalCoordinate = VinnoPhysicalCoordinate.FromBytes(reader.ReadBytes());
- physicalCoordinates.Add(visualAreaType, physicalCoordinate);
- }
- var logicalCoordinateCount = reader.ReadByte();
- var logicalCoordinates = new Dictionary<VinnoVisualAreaType, VinnoLogicalCoordinate>();
- for (var i = 0; i < logicalCoordinateCount; i++)
- {
- var visualAreaType = (VinnoVisualAreaType)reader.ReadByte();
- var logicalCoordinate = VinnoLogicalCoordinate.FromBytes(reader.ReadBytes());
- logicalCoordinates.Add(visualAreaType, logicalCoordinate);
- }
- foreach (var key in physicalCoordinates.Keys)
- {
- result.PhysicalCoordinates.Add(key, physicalCoordinates[key]);
- }
- foreach (var key in logicalCoordinates.Keys)
- {
- result.LogicalCoordinates.Add(key, logicalCoordinates[key]);
- }
- result.DisplayMode = displayMode;
- }
- }
- return result;
- }
- }
- }
|