diff --git a/PROMS/Volian.Controls.Library/DisplayRO.cs b/PROMS/Volian.Controls.Library/DisplayRO.cs index c80f8af5..92b8a7df 100644 --- a/PROMS/Volian.Controls.Library/DisplayRO.cs +++ b/PROMS/Volian.Controls.Library/DisplayRO.cs @@ -9,6 +9,8 @@ using System.Windows.Forms; using VEPROMS.CSLA.Library; using XYPlots; using DevComponents.DotNetBar; +using System.Text.RegularExpressions; +using VG; namespace Volian.Controls.Library { @@ -552,6 +554,7 @@ namespace Volian.Controls.Library } else if (selectedChld.type == 4) // x/y plot { +/* //PreviewMultiLineRO pmlROTable = new PreviewMultiLineRO(selectedChld.value, selectedChld.title); //pmlROTable.ShowDialog(); // This will show the graph commands this.Cursor = Cursors.WaitCursor; @@ -562,7 +565,10 @@ namespace Volian.Controls.Library pdfname += "\\" + selectedChld.appid + ".pdf"; //if (File.Exists(pdfname)) // File.Delete(pdfname); - XYPlot ROGraph = new XYPlot(selectedChld.value, pdfname); + XYPlot ROGraph = new XYPlot(selectedChld.value); + VGOut_C1PDF pdf = VGOut_C1PDF.Create(); + ROGraph.Process(pdf); + pdf.Save(pdfname); this.Cursor = Cursors.Default; // Run an internet browser window @@ -578,6 +584,9 @@ namespace Volian.Controls.Library // wait for a one minute max if (!WaitToDeleteFile(pdfname,1)) MessageBox.Show(string.Format("The PDF viewer was holding this file open: \n\n{0}",pdfname),"Cannot Delete Temporary File"); +*/ + frmXYPlot plot = new frmXYPlot(selectedChld.appid + " - " + selectedChld.title, selectedChld.value); + plot.Show(); } } private void ProgressBar_Initialize(int max, string desc) @@ -654,164 +663,186 @@ namespace Volian.Controls.Library //if (DoCaret) s2 = s2.Replace("^", @"\u916"); outstr = outstr.Replace("^", @"\u916"); - outstr = ConvertDOSSuperAndSubScripts(outstr); + // OLD: This function is now handled in the ConvertFortranFormatToScienctificNotation + //outstr = ConvertDOSSuperAndSubScripts(outstr); outstr = ConvertFortranFormatToScienctificNotation(outstr); return outstr; } - private string ConvertFortranFormatToScienctificNotation(string str) + //public static string ConvertFortranFormatToScienctificNotation(string str) + //{ + // string outstr = ""; + // int orglen = str.Length; + // int cnt = 0; + // int ptr; + + // int nbytes; + // int tstr, tstr2, rptr, start = 0; + + // while (cnt < orglen) + // { + // // position up to the the next number, sign, or period + // ptr = str.IndexOfAny("+-0123456789.".ToCharArray(), cnt); + // if (ptr == -1) + // { + // outstr += str.Substring(cnt); + // break; // jump out of while loop - nothing else to process + // } + // if ((ptr - cnt) > 0) + // { + // outstr += str.Substring(cnt, ptr - cnt); + // cnt = ptr; + // } + + // if (cnt > start && str[cnt - 1] == '\'') + // { + // //B2003-053: only remove the single quote character + // // if str ptr is not at the end of the string or + // // the next char (after the str ptr) is not a space + // // or newline... (as per Paul Linn on 7/17/03) + // int len = orglen - cnt; + // if (len <= 1 || str[cnt + 1] == ' ' || str[cnt + 1] == '\n') + // start = cnt; + // else + // start = cnt - 1; + // } + // else start = cnt; + // tstr = cnt; + + // //Skip preceeding signs + // if (str[cnt] == '+' || str[cnt] == '-') + // cnt++; + + // cnt = NextNonNumber(str, cnt); + // if (str[cnt] == '.') + // { + // cnt = NextNonNumber(str, cnt + 1); + // if (cnt >= str.Length) //jsj bug fix + // { + // outstr += str.Substring(tstr); + // break; // jump out of while loop - nothing else to process + // } + // if (str[start] == '\'') + // { + // start++; + // } + // else if (str[cnt] == 'E' && cnt > tstr) + // { + // nbytes = (cnt - tstr); // don't include the 'E' + // outstr += str.Substring(tstr, nbytes); + // cnt++; + + // rptr = outstr.Length - 1; + // while (outstr[rptr] == '0') rptr--; + // if (outstr[rptr] != '.') rptr++; + // if (rptr < (outstr.Length - 1)) + // outstr = outstr.Substring(0, rptr + 1); // trim trailing 0's + // //outstr = outstr.TrimEnd(".".ToCharArray()); + // int poutstr = 0; + // if (outstr[poutstr] == '+' || outstr[poutstr] == '-') poutstr++; + // if (!outstr.Substring(poutstr).Equals("1")) + // { + // outstr += "x1"; + // } + // outstr += "0\\super "; + + // tstr2 = cnt; + // if (str[cnt] == '+' || str[cnt] == '-') cnt++; + // cnt = NextNonNumber(str, cnt); + + // if (str[cnt] == '.' && char.IsDigit(str, cnt + 1)) + // cnt = NextNonNumber(str, cnt + 1); + + // nbytes = cnt - tstr2; // +1; + // outstr += str.Substring(tstr2, nbytes); + // outstr += "\\nosupersub "; + + // if (!char.IsLetterOrDigit(str, cnt) && !char.IsWhiteSpace(str, cnt)) + // return (str.Substring(tstr)); + // } + // } + // else + // { + // outstr += str.Substring(start, cnt - start + 1); + // cnt++; + // } + // } + // return (outstr); + //} + + //private static int NextNonNumber(string str, int cnt) + //{ + // int rtn = 0; + // string tstr = str.Substring(cnt); + // int len = tstr.Length; + // while (rtn < len && char.IsDigit(tstr, rtn)) rtn++; + // return rtn + cnt; + //} + public static string ConvertFortranFormatToScienctificNotation(string str) { - string outstr = ""; - int orglen = str.Length; - int cnt = 0; - int ptr; - - int nbytes; - int tstr, tstr2, rptr, start = 0; - - while (cnt < orglen) - { - // position up to the the next number, sign, or period - ptr = str.IndexOfAny("+-0123456789.".ToCharArray(), cnt); - if (ptr == -1) - { - outstr += str.Substring(cnt); - break; // jump out of while loop - nothing else to process - } - if ((ptr - cnt) > 0) - { - outstr += str.Substring(cnt, ptr - cnt); - cnt = ptr; - } - - if (cnt > start && str[cnt - 1] == '\'') - { - //B2003-053: only remove the single quote character - // if str ptr is not at the end of the string or - // the next char (after the str ptr) is not a space - // or newline... (as per Paul Linn on 7/17/03) - int len = orglen - cnt; - if (len <= 1 || str[cnt + 1] == ' ' || str[cnt + 1] == '\n') - start = cnt; - else - start = cnt - 1; - } - else start = cnt; - tstr = cnt; - - //Skip preceeding signs - if (str[cnt] == '+' || str[cnt] == '-') - cnt++; - - cnt = NextNonNumber(str, cnt); - if (str[cnt] == '.') - { - cnt = NextNonNumber(str, cnt + 1); - if (cnt >= str.Length) //jsj bug fix - { - outstr += str.Substring(tstr); - break; // jump out of while loop - nothing else to process - } - if (str[start] == '\'') - { - start++; - } - else if (str[cnt] == 'E' && cnt > tstr) - { - nbytes = (cnt - tstr); // don't include the 'E' - outstr += str.Substring(tstr, nbytes); - cnt++; - - rptr = outstr.Length - 1; - while (outstr[rptr] == '0') rptr--; - if (outstr[rptr] != '.') rptr++; - if (rptr < (outstr.Length - 1)) - outstr = outstr.Substring(0, rptr + 1); // trim trailing 0's - - int poutstr = 0; - if (outstr[poutstr] == '+' || outstr[poutstr] == '-') poutstr++; - if (!outstr[poutstr].Equals("1")) - { - outstr += "x1"; - } - outstr += "0\\super "; - - tstr2 = cnt; - if (str[cnt] == '+' || str[cnt] == '-') cnt++; - cnt = NextNonNumber(str, cnt); - - if (str[cnt] == '.' && char.IsDigit(str, cnt + 1)) - cnt = NextNonNumber(str, cnt + 1); - - nbytes = cnt - tstr2; // +1; - outstr += str.Substring(tstr2, nbytes); - outstr += "\\nosupersub "; - - if (!char.IsLetterOrDigit(str, cnt) && !char.IsWhiteSpace(str, cnt)) - return (str.Substring(tstr)); - } - } - else - { - outstr += str.Substring(start, cnt - start + 1); - cnt++; - } - } - return (outstr); + // Convert E style numbers to RTF with \super and \nosupersub + string retval = Regex.Replace(str, "([+-]?)([0-9]+)[.]?([0-9]*?)0*E([+-]?[0-9]+)", new MatchEvaluator(FixFortranNumber)); + retval = Regex.Replace(retval, "[#](.*?)[#]", "\\super $1\\nosupersub ");// DOS Superscript + retval = Regex.Replace(retval, "[~](.*?)[~]", "\\sub $1\\nosupersub ");// DOS Subscript + return retval; + } + private static string FixFortranNumber(Match match) + { + StringBuilder sb = new StringBuilder(match.Groups[1].Value); + if (match.Groups[3].Length == 0) // Nothing to the right of the decimal + if (match.Groups[2].Value != "1") // Other than "1", multiply it times 10 raised to a power + sb.Append(match.Groups[2].Value + "x10"); + else // The number is simply 1 so it can be ignored and 10 can be raised to a power + sb.Append("10"); + else // A number with a decimal point + sb.Append(match.Groups[2].Value + "." + match.Groups[3].Value + "x10"); + // Add the exponent as superscript + return sb.ToString() + "\\super " + match.Groups[4].Value + "\\nosupersub "; } - private int NextNonNumber(string str, int cnt) - { - int rtn = 0; - string tstr = str.Substring(cnt); - int len = tstr.Length; - while (rtn < len && char.IsDigit(tstr,rtn)) rtn++; - return rtn + cnt; - } + //private string ConvertDOSSuperAndSubScripts(string instr) + //{ + // string outstr = ""; + // string tstr = instr; + // int cnt = 0; + // int ptr = 0; + // bool issupper=false, issub = false; - private string ConvertDOSSuperAndSubScripts(string instr) - { - string outstr = ""; - string tstr = instr; - int cnt = 0; - int ptr = 0; - bool issupper=false, issub = false; - - while (tstr != null && (ptr = tstr.IndexOfAny("#~".ToCharArray(), cnt)) >= 0) - { - if (ptr > cnt) - outstr += tstr.Substring(cnt, ptr - cnt); - switch (tstr[ptr]) - { - case '#': - if (issub || issupper) - outstr += "\\nosupersub "; - else - outstr += "\\super "; - issupper = !issupper; - issub = false; - break; - case '~': - if (issupper || issub) - outstr += "\\nosupersub "; - else - outstr += "\\sub "; - issub = !issub; - issupper = false; - break; - } - cnt = ptr + 1; - if (cnt >= tstr.Length) - tstr = null; - else - tstr = instr.Substring(cnt); - cnt = 0; - } - if (tstr != null) - outstr += tstr; - return outstr; - } + // while (tstr != null && (ptr = tstr.IndexOfAny("#~".ToCharArray(), cnt)) >= 0) + // { + // if (ptr > cnt) + // outstr += tstr.Substring(cnt, ptr - cnt); + // switch (tstr[ptr]) + // { + // case '#': + // if (issub || issupper) + // outstr += "\\nosupersub "; + // else + // outstr += "\\super "; + // issupper = !issupper; + // issub = false; + // break; + // case '~': + // if (issupper || issub) + // outstr += "\\nosupersub "; + // else + // outstr += "\\sub "; + // issub = !issub; + // issupper = false; + // break; + // } + // cnt = ptr + 1; + // if (cnt >= tstr.Length) + // tstr = null; + // else + // tstr = instr.Substring(cnt); + // cnt = 0; + // } + // if (tstr != null) + // outstr += tstr; + // return outstr; + //} private static string _TemporaryFolder = null; public static string TemporaryFolder