// procedure DumpToText(Stream: TTextDumpStream; const OriginX, OriginY : Double); // Procedure SaveToNFFStream(Stream : TStream; const OriginX, OriginY : Double; FileVersion : NFFFileVersion); public void LoadFromNFFStream(BinaryReader reader, double OriginX, double OriginY, bool HasGuidanceID, NFFFileVersion FileVersion) { throw new NotImplementedException(); }
public void CreateFromFile(string fileName, NFFFileType fileType, NFFFileVersion fileVersion) { var f = NFFFile.CreateFromFile(Path.Combine("TestData", "Common", fileName)); f.ErrorStatus.Should().Be(NFFErrorStatus.OK); f.NFFFileType.Should().Be(fileType); f.FileVersion.Should().Be(fileVersion); }
public void DetermineBoundary(string fileName, NFFFileType fileType, NFFFileVersion fileVersion) { var f = NFFFile.CreateFromFile(Path.Combine("TestData", "Common", fileName)); f.ErrorStatus.Should().Be(NFFErrorStatus.OK); f.NFFFileType.Should().Be(fileType); f.FileVersion.Should().Be(fileVersion); var master = f.GuidanceAlignments?.Where(x => x.IsMasterAlignment()).FirstOrDefault(); var determinator = new SVLAlignmentBoundaryDeterminator(master, master.StartStation, master.EndStation, -1, 1); determinator.Should().NotBeNull(); determinator.DetermineBoundary(out DesignProfilerRequestResult calcResult, out Fence fence); calcResult.Should().Be(DesignProfilerRequestResult.OK); fence.Should().NotBeNull(); }
public static bool SetFileVersionFromMinorMajorVersionNumbers(byte MajorVer, byte MinorVer, out NFFFileVersion FileVersion) { bool Result = true; // Convert the minor/major version numbering into the file version enum if (MajorVer == 1 && MinorVer == 0) { FileVersion = NFFFileVersion.Version1_0; } else if (MajorVer == 1 && MinorVer == 1) { FileVersion = NFFFileVersion.Version1_1; } else if (MajorVer == 1 && MinorVer == 2) { FileVersion = NFFFileVersion.Version1_2; } else if (MajorVer == 1 && MinorVer == 3) { FileVersion = NFFFileVersion.Version1_3; } else if (MajorVer == 1 && MinorVer == 4) { FileVersion = NFFFileVersion.Version1_4; } else if (MajorVer == 1 && MinorVer == 5) { FileVersion = NFFFileVersion.Version1_5; } else if (MajorVer == 1 && MinorVer == 6) { FileVersion = NFFFileVersion.Version1_6; } else { FileVersion = NFFFileVersion.Version_Undefined; Result = false; } return(Result); }
// Procedure SaveToStream(NFFFileVersion : NFFFileVersion; Stream : TStream); public void LoadFromStream(NFFFileVersion NFFFileVersion, BinaryReader reader) { var DirectoryHeader = new NFFDirectoryStreamHeader(); var b = reader.ReadBytes(Marshal.SizeOf(DirectoryHeader)); var handle = GCHandle.Alloc(b, GCHandleType.Pinned); DirectoryHeader = (NFFDirectoryStreamHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(NFFDirectoryStreamHeader)); if (NFFUtils.MagicNumberToANSIString(DirectoryHeader.MagicNumber) != NFFConsts.kNFFIndexFileMagicNumber) { return; } // No stream lists are read from pre version 1.2 format files. if (NFFFileVersion < NFFFileVersion.Version1_2) { return; } int Offset = 0; int Length = 0; int Number = reader.ReadInt32(); for (int I = 0; I < Number; I++) { string Name = NFFUtils.ReadWideStringFromStream(reader); if (NFFFileVersion >= NFFFileVersion.Version1_2) { Offset = reader.ReadInt32(); Length = reader.ReadInt32(); } Add(new NFFStreamInfo(Name, Offset, Length)); } // Be paranoid and resort the stream list Sort(); }
public NFFFile(NFFFileType ANFFFileType, NFFFileVersion ANFFFileVersion, int AGridSize) : this(ANFFFileType, ANFFFileVersion) { GridSize = AGridSize; }
public NFFFile(NFFFileType ANFFFileType, NFFFileVersion ANFFFileVersion) : this(ANFFFileType) { FileVersion = ANFFFileVersion; }
// NormaliseArcs scans the elements in the guidance alignment and swaps the // 'WasClockWise' flag in them to make then consistent with the sense of // direction along the guidance alignment. This is necessary due to the // way arcs are stored in clockwise direction only in SVL files, and do // not retain the original sense of direction from the arc that was originally // used to define it. // procedure NormaliseArcs; // procedure Assign(Entity: NFFLineworkEntity); override; // property Entities : NFFGuidableAlignmentOwnedEntitiesList read FEntities; // procedure DumpToText(Stream: TTextDumpStream; const OriginX, OriginY : Double); override; // Procedure SaveToNFFStream(Stream : TStream; // const OriginX, OriginY : Double; // FileVersion : NFFFileVersion); override; public override void LoadFromNFFStream(BinaryReader reader, double OriginX, double OriginY, bool HasGuidanceID, NFFFileVersion FileVersion) { NFFLineWorkElementType EntityType; // The file version passed into here is ignored in favour of the file version contained in the header information Debug.Assert(FileVersion == NFFFileVersion.Version_Undefined, "Specific file version sent to NFFGuidableAlignmentEntity.LoadFromNFFStream"); var Header = new NFFLineworkGridFileHeader(); var b = reader.ReadBytes(Marshal.SizeOf(Header)); var handle = GCHandle.Alloc(b, GCHandleType.Pinned); Header = (NFFLineworkGridFileHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(NFFLineworkGridFileHeader)); if (NFFUtils.MagicNumberToANSIString(Header.MagicNumber) != NFFConsts.kNFFLineworkFileMagicNumber) { throw new IOException($"Expected {NFFConsts.kNFFLineworkFileMagicNumber} as the magic number, not: {Header.MagicNumber}"); } if (!NFFUtils.SetFileVersionFromMinorMajorVersionNumbers(Header.MajorVer, Header.MinorVer, out FileVersion)) { throw new IOException($"Unexpected file version, Major = {Header.MajorVer}, Minor - {Header.MinorVer}"); } if (FileVersion < NFFFileVersion.Version1_2) { throw new IOException("File version less than 1.2 - unsupported"); } var factory = new NFFElementFactory(); // Read the list of items from the stream... while (reader.BaseStream.Position < reader.BaseStream.Length) { byte EntityTypeVal = reader.ReadByte(); // The flags moved into a following byte after the element type in v1.5 if (FileVersion >= NFFFileVersion.Version1_5) { EntityType = (NFFLineWorkElementType)EntityTypeVal; } else { EntityType = (NFFLineWorkElementType)(EntityTypeVal & 0x0f); } if (EntityType == NFFLineWorkElementType.kNFFLineWorkLineElement) { return; } byte FlagsByte = 0; if (FileVersion >= NFFFileVersion.Version1_5) { // v1.5 and later store the flags as a separate byte. However, the flags // that were in the most significant 4 bits were being thrown away in favour // or a separate flags byte stored in each entity. So we will preserve this // behaviour for post v1.4 too FlagsByte = reader.ReadByte(); } else { if ((EntityTypeVal & NFFConsts.kNFFHasGuidanceID) != 0) { FlagsByte |= NFFConsts.kNFFElementHeaderHasGuidanceID; } if ((EntityTypeVal & NFFConsts.kNFFHasStationing) != 0) { FlagsByte |= NFFConsts.kNFFElementHeaderHasStationing; } if ((EntityTypeVal & NFFConsts.kNFFHasHeight) != 0) { FlagsByte |= NFFConsts.kNFFElementHeaderHasElevation; } } if (EntityType == NFFLineWorkElementType.kNFFLineworkEndElement) { return; } var Entity = factory.NewElement(EntityType); if (!(Entity is NFFStationedLineworkEntity)) { // Inappropriate entity type in file throw new Exception("Non stationed element created from guidable alignment geometry"); } Entity.HeaderFlags = FlagsByte; Entity.LoadFromNFFStream(reader, Header.Origin.X, Header.Origin.Y, HasGuidanceID, FileVersion); if (Entities.Count == 0) { // Loading first contained entity, write entities <Flags> and <GuidanceID> // to self BEFORE adding it GuidanceID = (Entity as NFFStationedLineworkEntity).GuidanceID; HeaderFlags = Entity.HeaderFlags; } Entities.Add(Entity as NFFStationedLineworkEntity); } }
/* * function GetVertexLeftCrossSlope(VertexNum: Integer): Double; Override; * procedure SetVertexLeftCrossSlope(VertexNum: Integer; * const Value: Double); Override; * * function GetVertexRightCrossSlope(VertexNum: Integer): Double; Override; * procedure SetVertexRightCrossSlope(VertexNum: Integer; * const Value: Double); Override; */ //public procedure Assign(Entity: NFFLineworkEntity); override; // procedure DumpToText(Stream: TTextDumpStream; const OriginX, OriginY : Double); override; // The SavetoSream/LoadFromNFFStream method with origin parameters are intended // for saving this entity to an NFF file. // Procedure SaveToNFFStream(Stream : TStream; // const OriginX, OriginY : Double; // FileVersion : NFFFileVersion); Overload; Override; public override void LoadFromNFFStream(BinaryReader reader, double OriginX, double OriginY, bool HasGuidanceID, NFFFileVersion FileVersion) { double Alpha = Consts.NullDouble; // Keep compiler quite double Beta = Consts.NullDouble; // Keep compiler quite try { // Prevent <fVertices> list complaining about additions to processed polyline //fSuppressAssertions= True; // There is no need to read the entity type as this will have already been // read in order to determine we should be reading this type of entity! if (HasGuidanceID) { GuidanceID = reader.ReadUInt16(); } // Read in the linewidth (always 1) var _ = reader.ReadByte(); // Read out the rest of the information for the entity Colour = NFFUtils.ReadColourFromStream(reader); // Read the flags... _entityFlags = reader.ReadByte(); // Read the bounding box of the smoothed polyline NFFUtils.ReadRectFromStream(reader, out double MinX, out double MinY, out double MaxX, out double MaxY, OriginX, OriginY); // Read the number of vertices in the polyline (this includes the first point) int VertexCount = reader.ReadInt16(); // Read in the list vertices from the stream for (int I = 0; I < VertexCount; I++) { NFFUtils.ReadCoordFromStream(reader, out double X, out double Y, OriginX, OriginY); double Z; if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasElevation) != 0) { Z = NFFUtils.ReadFixedPoint32FromStream(reader); } else { Z = Consts.NullDouble; } double LeftCrossSlope; double RightCrossSlope; if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasCrossSlope) != 0) { NFFUtils.ReadCrossSlopeInformationFromStream(reader, out LeftCrossSlope, out RightCrossSlope); } else { LeftCrossSlope = Consts.NullDouble; RightCrossSlope = Consts.NullDouble; } if (I > 0) { Alpha = reader.ReadSingle(); Beta = reader.ReadSingle(); } double Chainage; if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasStationing) != 0) { Chainage = reader.ReadDouble(); } else { Chainage = Consts.NullDouble; } Vertices.Add(new NFFLineworkSmoothedPolyLineVertexEntity(this, X, Y, Z, Chainage, Consts.NullDouble)); if (I > 0) { Vertices.Last().Alpha = Alpha; Vertices.Last().Beta = Beta; } Vertices.Last().LeftCrossSlope = LeftCrossSlope; Vertices.Last().RightCrossSlope = RightCrossSlope; } } finally { // fSuppressAssertions= False; } }
// Procedure SaveToStream(Stream : TStream); Override; /* * public override void LoadFromStream(BinaryReader reader) * { * base.LoadFromStream(reader); * * NFFUtils.ReadXYZFromStream(reader, out X1, out Y1, out Z1); * NFFUtils.ReadXYZFromStream(reader, out X2, out Y2, out Z2); * NFFUtils.ReadXYFromStream(reader, out CX, out CY); * SingleArcEdgePoint = reader.ReadBoolean(); * WasClockWise = reader.ReadBoolean(); * * byte ReadByte = reader.ReadByte(); * if (Range.InRange(ReadByte, (byte)NFFLineworkArcTransitDirection.atdUnknown, (byte)NFFLineworkArcTransitDirection.atdEndToStart)) * TransitDirection = (NFFLineworkArcTransitDirection)ReadByte; * else * TransitDirection = NFFLineworkArcTransitDirection.atdUnknown; * * OriginalEndPointsHash = reader.ReadDouble(); * * StartLeftCrossSlope= reader.ReadDouble(); * EndLeftCrossSlope = reader.ReadDouble(); * StartRightCrossSlope = reader.ReadDouble(); * EndRightCrossSlope = reader.ReadDouble(); * } */ // procedure DumpToText(Stream: TTextDumpStream; const OriginX, OriginY : Double); override; //Procedure SaveToNFFStream(Stream : TStream; //const OriginX, OriginY : Double; // FileVersion : NFFFileVersion); Override; public override void LoadFromNFFStream(BinaryReader reader, double OriginX, double OriginY, bool HasGuidanceID, NFFFileVersion FileVersion) { // There is no need to read the entity type as this will have already been // read in order to determine we should be reading this type of entity! if (HasGuidanceID) { _guidanceID = reader.ReadUInt16(); } byte _ = reader.ReadByte(); //{ LineWidth= } Colour = NFFUtils.ReadColourFromStream(reader); _entityFlags = reader.ReadByte(); NFFUtils.ReadRectFromStream(reader, out double MinX, out double MinY, out double MaxX, out double MaxY, OriginX, OriginY); NFFUtils.ReadCoordFromStream(reader, out CX, out CY, OriginX, OriginY); // CZ = NullReal; //SPR 8763: Remove height field from arcs in SVL files // if (FFlags and kNFFElementHeaderHasElevation) <> 0 then // ReadFixedPoint32FromStream(Stream); NFFUtils.ReadCoordFromStream(reader, out X1, out Y1, OriginX, OriginY); if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasElevation) != 0) { Z1 = NFFUtils.ReadFixedPoint32FromStream(reader); } else { Z1 = Consts.NullDouble; } if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasCrossSlope) != 0) { NFFUtils.ReadCrossSlopeInformationFromStream(reader, out StartLeftCrossSlope, out StartRightCrossSlope); } else { StartLeftCrossSlope = Consts.NullDouble; StartRightCrossSlope = Consts.NullDouble; } NFFUtils.ReadCoordFromStream(reader, out X2, out Y2, OriginX, OriginY); if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasElevation) != 0) { Z2 = NFFUtils.ReadFixedPoint32FromStream(reader); } else { Z2 = Consts.NullDouble; } if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasCrossSlope) != 0) { NFFUtils.ReadCrossSlopeInformationFromStream(reader, out EndLeftCrossSlope, out EndRightCrossSlope); } else { EndLeftCrossSlope = Consts.NullDouble; EndRightCrossSlope = Consts.NullDouble; } double start_angle = reader.ReadSingle(); double end_angle = reader.ReadSingle(); double radius = reader.ReadSingle(); if ((_headerFlags & NFFConsts.kNFFElementHeaderHasStationing) != 0) { // Read the Start Station StartStation = reader.ReadDouble(); // Read and discard EndStation value (it can be re-calculated any time it is needed) var TempEndStation = reader.ReadDouble(); // Within SVD/ SVL no record is kept of whether arc was initially described as // CW or CCW, Stationing is stored with convention that arc is CW.When // creating / reading a arc entity from stream, we need to figure out and restore // <WasClockWise> value in order for any subsequent write to stream to write // Stationing around the right way if (StartStation > TempEndStation) { // Arc was initially defined CCW WasClockWise = false; StartStation = TempEndStation; TransitDirection = NFFLineworkArcTransitDirection.atdEndToStart; } else { WasClockWise = true; TransitDirection = NFFLineworkArcTransitDirection.atdStartToEnd; } } // Convert the start/end angle into end points. Even though we have // read in the end points, we recalculate then to undo loss of precision when written // into the NFF file // Angles are mathematical angles, PolarToRect wants azimuth angles GeometryUtils.PolarToRect(CY, CX, out Y1, out X1, Math.PI / 2 - start_angle, radius); GeometryUtils.PolarToRect(CY, CX, out Y2, out X2, Math.PI / 2 - end_angle, radius); }
/* * function GetVertexLeftCrossSlope(VertexNum: Integer): Double; Override; * procedure SetVertexLeftCrossSlope(VertexNum: Integer; * const Value: Double); Override; * * function GetVertexRightCrossSlope(VertexNum: Integer): Double; Override; * procedure SetVertexRightCrossSlope(VertexNum: Integer; * const Value: Double); Override; */ /* * public override void Assign(NFFLineworkEntity Entity) * { * base.Assign(Entity); * * Vertices.Clear(); * * for (int I = 0; I < (Entity as NFFLineworkPolyLineEntity).Vertices.Count; I++) * Vertices.Add((Entity as NFFLineworkPolyLineEntity).Vertices[I].Clone()); * * for (int I = 0; I < Vertices.Count; I++) * Vertices[I].Parent = this; * } */ // procedure DumpToText(Stream: TTextDumpStream; const OriginX, OriginY : Double); override; // Procedure SaveToNFFStream(Stream : TStream; // const OriginX, OriginY : Double; // FileVersion : NFFFileVersion); Override; public override void LoadFromNFFStream(BinaryReader reader, double OriginX, double OriginY, bool HasGuidanceID, NFFFileVersion FileVersion) { // There is no need to read the entity type as this will have already been // read in order to determine we should be reading this type of entity! if (HasGuidanceID) { GuidanceID = reader.ReadUInt16(); } // Linewidth is always 1 byte _ = reader.ReadByte(); // LineWidth:= Colour = NFFUtils.ReadColourFromStream(reader); _entityFlags = reader.ReadByte(); //Read the bounding box NFFUtils.ReadRectFromStream(reader, out double MinX, out double MinY, out double MaxX, out double MaxY, OriginX, OriginY); // Read in number of points var EntCount = reader.ReadUInt16(); // Read the vertices constructing line elements in the polygon entity for (int I = 0; I < EntCount; I++) { NFFUtils.ReadCoordFromStream(reader, out double X1, out double Y1, OriginX, OriginY); double Z1; if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasElevation) != 0) { Z1 = NFFUtils.ReadFixedPoint32FromStream(reader); } else { Z1 = Consts.NullDouble; } double FLeftCrossSlope; double FRightCrossSlope; if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasCrossSlope) != 0) { NFFUtils.ReadCrossSlopeInformationFromStream(reader, out FLeftCrossSlope, out FRightCrossSlope); } else { FLeftCrossSlope = Consts.NullDouble; FRightCrossSlope = Consts.NullDouble; } double Chainage; if ((HeaderFlags & NFFConsts.kNFFElementHeaderHasStationing) != 0) { Chainage = reader.ReadDouble(); } else { Chainage = Consts.NullDouble; } Vertices.Add(new NFFLineworkPolyLineVertexEntity(this, X1, Y1, Z1, Chainage)); Vertices.Last().LeftCrossSlope = FLeftCrossSlope; Vertices.Last().RightCrossSlope = FRightCrossSlope; Vertices.Last().Parent = this; } }