Ejemplo n.º 1
0
        public IldFrame(IldHeader header, IEnumerable<IldRecord> records, ITransformation transformation)
        {
            Header = header;
            Records = records;

            Transformation = transformation;

            TracePoints = Records
                .Select(rec => rec.ToTracePoint())
                .ToArray();
            Name = Header.FrameName + " #" + Header.FrameNumber;
        }
Ejemplo n.º 2
0
        public IldFrame(IldHeader header, IEnumerable <IldRecord> records, ITransformation transformation)
        {
            Header  = header;
            Records = records;

            Transformation = transformation;

            TracePoints = Records
                          .Select(rec => rec.ToTracePoint())
                          .ToArray();
            Name = Header.FrameName + " #" + Header.FrameNumber;
        }
Ejemplo n.º 3
0
        public IEnumerable <IFrameable> Create(string fileName)
        {
            using (var fs = new FileStream(fileName, FileMode.Open))
            {
                using (var br = new BinaryReader(fs))
                {
                    var frames = new List <IldFrame>();
                    while (true)
                    {
                        var header = new IldHeader(BytesConverter.ByteToType <IldHeaderRaw>(br));

                        if (header.FormatCode != 0)
                        {
                            return(frames);
                        }

                        if (header.TotalPoints == 0 || header.FrameNumber == header.TotalFrames)
                        {
                            return(frames);
                        }

                        var records = new List <IldRecord>();
                        while (true)
                        {
                            var record = new IldRecord(BytesConverter.ByteToType <IldRecordRaw>(br));
                            if (record.IsLast)
                            {
                                break;
                            }
                            records.Add(record);
                        }

                        var frame = new IldFrame(header, records, Transformation);
                        frames.Add(frame);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Save(string fileName, IFrameable frameable)
        {
            var startHeaderRaw = new IldHeaderRaw();

            startHeaderRaw.Init();
            var startHeader = new IldHeader(startHeaderRaw)
            {
                FileFormat  = "ILDA",
                FormatCode  = 0,
                FrameName   = frameable.Name,
                CompanyName = "Peleton",
                TotalPoints = frameable.TracePoints.Length + 1,
                FrameNumber = 0,
                TotalFrames = 1,
                ScannerHead = 0,
                Future      = 0
            };

            var finishHeaderRaw = new IldHeaderRaw();

            finishHeaderRaw.Init();
            var finishHeader = new IldHeader(finishHeaderRaw)
            {
                FileFormat  = "ILDA",
                FormatCode  = 0,
                FrameName   = frameable.Name,
                CompanyName = "Peleton",
                TotalPoints = 0,
                FrameNumber = 1,
                TotalFrames = 1,
                ScannerHead = 0,
                Future      = 0
            };

            var transformation = new CompositeTransformation(
                new ReverseTransformation(frameable.Transformation),
                Transformation);
            var recordRawArray = new IldRecordRaw[frameable.TracePoints.Length];

            for (var i = 0; i < recordRawArray.Length; i++)
            {
                var tracePoint = frameable.TracePoints[i];
                var recordRaw  = new IldRecordRaw();
                recordRaw.Init();

                var point = transformation.Transform(tracePoint.Point);

                var record = new IldRecord(recordRaw)
                {
                    X      = (int)point.X,
                    Y      = (int)point.Y,
                    Z      = -16,
                    Status = 56,
                    IsMove = !tracePoint.Trace,
                    IsLast = false
                };
                recordRawArray[i] = recordRaw;
            }

            var finishRecordRaw = new IldRecordRaw();

            finishRecordRaw.Init();

            var finishRecord = new IldRecord(finishRecordRaw)
            {
                X      = 0,
                Y      = 0,
                Z      = -16,
                Status = 56,
                IsMove = true,
                IsLast = true
            };

            SaveToFile(fileName, startHeaderRaw, recordRawArray, finishRecordRaw, finishHeaderRaw);
        }