protected override void DumpBody(XmlWriter writer, SwfTagCode shapeType) { writer.WriteAttributeString("state", State.ToString()); if ((State & SwfStyleState.HasMoveTo) != 0) { writer.WriteAttributeString("dx", DeltaX.ToString()); writer.WriteAttributeString("dy", DeltaY.ToString()); } if ((State & SwfStyleState.HasFillStyle0) != 0) { writer.WriteAttributeString("fs0", FillStyle0.ToString()); } if ((State & SwfStyleState.HasFillStyle1) != 0) { writer.WriteAttributeString("fs1", FillStyle1.ToString()); } if ((State & SwfStyleState.HasLineStyle) != 0) { writer.WriteAttributeString("ls", LineStyle.ToString()); } if ((State & SwfStyleState.HasNewStyles) != 0) { Styles.Dump(writer, shapeType); } }
public string DataToString(FileFormat fileFormat) { // all file types are explicitly designed for MSDOS // for this the newline is hard coded as "CR LF" Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; StringBuilder sb = new StringBuilder(); switch (fileFormat) { case FileFormat.Txt: // ********************************************************** // Very simple format, no place for comments etc. // http://resource.npl.co.uk/softgauges/Help.htm // ********************************************************** sb.Append($"{DeltaX:F3}\r\n"); foreach (double z in zData) { sb.Append($"{z:F6}\r\n"); } break; case FileFormat.SigmaSurf: // ********************************************************** // Format used by the freeware SigmaSurf // http://www.digitalmetrology.com // ********************************************************** sb.Append("SigmaSurf_Data 1.0\r\n"); sb.Append($"IDENTIFICATION: {SampleIdentification}\r\n"); sb.Append($"DATE: {CreationDate.ToString("dd MMM yyyy - HH:mm")}\r\n"); sb.Append($"SPACING_UM: {DeltaX.ToString("F5")}\r\n"); sb.Append($"NUMBER_OF_POINTS: {zData.Length}\r\n"); sb.Append($"PROFILE_UM:\r\n"); foreach (double z in zData) { sb.Append($"{z:F6}\r\n"); // resolution 1 pm } break; case FileFormat.Prf: // ********************************************************** // not well documented, implementation taken // from the following NPL site: // http://resource.npl.co.uk/softgauges/Help.htm // ********************************************************** sb.Append("1 2\r\n"); sb.Append("SG2004 0.000000e+000 PRF\r\n"); sb.Append(string.Format("CX M {0:e} MM 1.000000e+000 D\r\n", (double)zData.Length)); sb.Append(string.Format("CZ M {0:e} MM 1.000000e-009 L\r\n", (double)zData.Length)); sb.Append("EOR\r\n"); sb.Append("STYLUS_RADIUS 0.000000e+000 MM\r\n"); sb.Append(string.Format("SPACING CX {0:e}\r\n", DeltaX * 1000.0)); // in mm! sb.Append("MAP 1.000000e+000 CZ CZ 1.000000e+000 1.000000e+000\r\n"); sb.Append("MAP 2.000000e+000 CZ CX 1.000000e+000 0.000000e+000\r\n"); sb.Append($"COMMENT {SampleIdentification}\r\n"); sb.Append("EOR\r\n"); foreach (double z in zData) { sb.Append($"{z * 1e6:F0}\r\n"); // resolution 1 pm, as in example } sb.Append("EOR\r\n"); sb.Append("EOF\r\n"); break; case FileFormat.PrDE: case FileFormat.PrEN: // ********************************************************** // This format was propably developed by PTB and documented // on the following web site: // http://www.ptb.de/en/org/5/51/517/rptb_web/wizard/greeting.php // Umlaute are part of the definition! // It seems to originate from MSDOS times. // update in format definition to avoid Umlaute as described in: // https://ptb.de/rptb // ********************************************************** double xLen = DeltaX * (zData.Length - 1); double xResolution = 1000.0 / DeltaX; sb.Append($"Profil {FileName}\r\n"); if (fileFormat == FileFormat.PrDE) { sb.Append($"X-Maß = {xLen:F8} X-Auflösung {xResolution:F6} Punkte/Zeile : {zData.Length}\r\n"); } if (fileFormat == FileFormat.PrEN) { sb.Append($"X-len = {xLen:F8} X-resolution {xResolution:F6} points/scanline: {zData.Length}\r\n"); } foreach (double z in zData) { sb.Append($"{z:F6}\r\n"); // resolution 1 pm, as in example } // from the format definition: // "The last of all z-values shall be in the last line and not followed by a line feed." sb.Length--; sb.Length--; break; case FileFormat.Smd: // ********************************************************** // Standardized format used by the surface texture community // uses some non printeable characters // This format was designed for F1 softgauges (only?) // ISO 5436-2:2012 // ********************************************************** string endOfRecord = $"{(char)3}\r\n"; sb.Append($"ISO 5436-2:2012\0{FileName}\0\r\n"); sb.Append("PRF\0 1 ISO5436\0\r\n"); sb.Append($"CX\0 I\0 {zData.Length} mm\0 1.0e0 D\0 {DeltaX / 1000:e5} \r\n"); sb.Append($"CZ\0 A\0 {zData.Length} um\0 1.0e0 D\0\r\n"); sb.Append(endOfRecord); // end of record 1 sb.Append($"DATE: {CreationDate.ToString("dd-MMMM-yyyy")}\0\r\n"); sb.Append($"TIME: {CreationDate.ToString("HH:mm")}\0\r\n"); sb.Append("CREATED_BY Michael Matus, BEV\0\r\n"); //TODO sb.Append($"COMMENT /* {UserComment} */\0\r\n"); sb.Append(endOfRecord); // end of record 2 foreach (double z in zData) { sb.Append($"{z:F5}\r\n"); } sb.Append(endOfRecord); // end of record 3 // checksum calculation ushort chkSum = 0; string s = sb.ToString(); byte[] buffer = System.Text.Encoding.ASCII.GetBytes(s); foreach (byte byt in buffer) { chkSum += (ushort)byt; } sb.Append($"{chkSum.ToString()}\r\n"); sb.Append(endOfRecord); // end of record 4 sb.Append($"{(char)26}"); // end of file break; case FileFormat.Bcr: // ********************************************************** // GPS data files according to // ISO 25178-7, ISO 25178-71 and EUNA 15178. // ********************************************************** sb.AppendLine("aBCR - 1.0"); sb.AppendLine($"ManufacID = BEV / SIOS NMM"); sb.AppendLine($"CreateDate = {CreationDate.ToString("ddMMyyyyHHmm")}"); sb.AppendLine($"ModDate = {DateTime.UtcNow.ToString("ddMMyyyyHHmm")}"); sb.AppendLine($"NumPoints = {zData.Length}"); sb.AppendLine("NumProfiles = 1"); sb.AppendLine($"Xscale = {(DeltaX * 1e-6).ToString("G17")}"); sb.AppendLine($"Yscale = 0"); sb.AppendLine($"Zscale = 1.0e-6"); sb.AppendLine("Zresolution = -1"); // clause 5.2.8, do not modify! sb.AppendLine("Compression = 0"); // clause 5.2.9, do not modify! sb.AppendLine("DataType = 7"); sb.AppendLine("CheckType = 0"); // clause 5.2.11, do not modify! sb.AppendLine("*"); foreach (double z in zData) { sb.AppendLine($"{z:G17}"); // round-trip format } sb.AppendLine("*"); string AppName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; string AppVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); sb.AppendLine($"ConvertedBy = {AppName} version {AppVer}"); sb.AppendLine($"SampleIdentification = {SampleIdentification}"); sb.AppendLine($"FileName = {FileName}"); // this is useless sb.AppendLine($"UserComment = {UserComment}"); sb.AppendLine($"TrimmedStart = {Start} µm"); sb.AppendLine($"TrimmedLength = {Length} µm"); sb.AppendLine($"TipConvolution = {TipConvolutionMessage}"); sb.AppendLine("*"); break; case FileFormat.Csv: double x = 0.0; sb.AppendLine("x in µm,z in µm"); foreach (double z in zData) { sb.AppendLine($"{x:G17},{z:G17}"); x += DeltaX; } break; case FileFormat.Unknown: case FileFormat.X3p: // will not be implemented! throw new NotImplementedException(); default: break; } return(sb.ToString()); }
protected override void DumpBody(XmlWriter writer, SwfTagCode shapeType) { writer.WriteAttributeString("dx", DeltaX.ToString()); writer.WriteAttributeString("dy", DeltaY.ToString()); }