Use graphics to display preview of plots

This commit is contained in:
Rich 2010-02-02 20:57:54 +00:00
parent 771df71108
commit b58965c823

View File

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