diff --git a/PROMS/XYPlots/XYPlots.cs b/PROMS/XYPlots/XYPlots.cs index c66ed9f3..d14ee178 100644 --- a/PROMS/XYPlots/XYPlots.cs +++ b/PROMS/XYPlots/XYPlots.cs @@ -20,7 +20,6 @@ namespace XYPlots private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion public static string MyFontFamily { get; set; } = "Letter Gothic Tall"; - private static Color _BlackColor = Color.Red; public static Color BlackColor { get { return VG.VG.BlackColor; } @@ -30,25 +29,24 @@ namespace XYPlots public float Height => 72 * (TopMargin + BottomMargin) + printerunits[1] * .05F; public float PlotWidth => (float)userunits[X]; public float PlotHeight => (float)userunits[Y]; - private double ConvertToTwips = 4.8; - static int MAX_XY_STACK = 8; /* this is max of CIE cursor/font stack */ - static int DPI = 1440; //300; - static int CWIDEDOTS = 120; //25; - static int CHIGHDOTS = 240; //50; - static int STRAIGHT = 0; - static int CURVE = 1; - static int X = 0; - static int Y = 1; - static int Dimensions = 2; - static int USER = 0; - static int PLOT = 1; - static double PI = 3.141592653; - static double Zero = 0.0; - static double ANGLELIMIT = 1.0; + private readonly double ConvertToTwips = 4.8; + static readonly int MAX_XY_STACK = 8; /* this is max of CIE cursor/font stack */ + static readonly int DPI = 1440; //300; + static readonly int CWIDEDOTS = 120; //25; + static readonly int CHIGHDOTS = 240; //50; + static readonly int STRAIGHT = 0; + static readonly int CURVE = 1; + static readonly int X = 0; + static readonly int Y = 1; + static readonly int Dimensions = 2; + static readonly int USER = 0; + static readonly int PLOT = 1; + static readonly double PI = 3.141592653; + static readonly double Zero = 0.0; + static readonly double ANGLELIMIT = 1.0; // !!!! NEED REAL SUPERSCRIPT ON/OFF TOKENS - static string[] SuperScript = { "##", "##" }; - static string[] SubScript = { "~~", "~~" }; - FileStream XYPlotFile; + static readonly string[] SuperScript = { "##", "##" }; + static readonly string[] SubScript = { "~~", "~~" }; private int[] SavedX; private int[] SavedY; private int stack; @@ -106,27 +104,27 @@ namespace XYPlots private string valuestring; private string powerstring; private int GridOnFlag, Visible, ShadowFlag; - private char[] type = new char[Dimensions]; - private double FontPitch = 10.0; - private double[] minimum = new double[Dimensions]; - private double[] maximum = new double[Dimensions]; - private double[] userunits = new double[Dimensions]; - private int[] printerunits = new int[Dimensions]; - private int[] Position = new int[Dimensions]; - private double[,] Scale = new double[2, Dimensions]; - private double[,] Offset = new double[2, Dimensions]; - private double[] delta = new double[Dimensions]; - private int[] cycles = new int[Dimensions]; - private int[] onecycle = new int[Dimensions]; - private int[] minor = new int[Dimensions]; - private int[] spcminor = new int[Dimensions]; - private string[] AxisTitles = new string[Dimensions]; - private int[] AxisLabel = new int[Dimensions];// 1 for YES(default), 0 for NO + private readonly char[] type = new char[Dimensions]; + private readonly double FontPitch = 10.0; + private readonly double[] minimum = new double[Dimensions]; + private readonly double[] maximum = new double[Dimensions]; + private readonly double[] userunits = new double[Dimensions]; + private readonly int[] printerunits = new int[Dimensions]; + private readonly int[] Position = new int[Dimensions]; + private readonly double[,] Scale = new double[2, Dimensions]; + private readonly double[,] Offset = new double[2, Dimensions]; + private readonly double[] delta = new double[Dimensions]; + private readonly int[] cycles = new int[Dimensions]; + private readonly int[] onecycle = new int[Dimensions]; + private readonly int[] minor = new int[Dimensions]; + private readonly int[] spcminor = new int[Dimensions]; + private readonly string[] AxisTitles = new string[Dimensions]; + private readonly int[] AxisLabel = new int[Dimensions];// 1 for YES(default), 0 for NO private int CurPenWidth, DrawDirection, LineFlag, LineDiv; private int EndFlag = 0; public string Buff; private int BuffPtr = 0; - private bool[,] doLOG10 = { { false, false }, { false, false } }; + private readonly bool[,] doLOG10 = { { false, false }, { false, false } }; public struct point { public int[] xyValue; @@ -141,8 +139,8 @@ namespace XYPlots public class XyBoxes : List { } - private XyBoxes AllBoxes = new XyBoxes(); - private XyBoxes ActiveBoxes = new XyBoxes(); + private readonly XyBoxes AllBoxes = new XyBoxes(); + private readonly XyBoxes ActiveBoxes = new XyBoxes(); public class DataPoint { // Make it easier to Debug @@ -165,7 +163,8 @@ namespace XYPlots public int PlotDivisions; public DataPoints PlotDataPoints; }; - private List AllPlots = new List(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] + private List AllPlots = new List(); private int YLandScape = 0; /* y axis title is horizontal */ private point YTitleOrigin; /* y axis title origin if vertical */ private double FixAngle(double a1) @@ -234,72 +233,6 @@ namespace XYPlots else return false; } - private bool LoadBuff(string FileName) - { - if (!File.Exists(FileName)) - { - if (!BaseLnSettings.blBaseLine) // B2026-056 suppress messages when running baseline. - { - // File does not exist, show error message - MessageBox.Show(String.Format("X/Y Plot File {0} Does Not Exist", FileName), "Error Opening X/Y Plot File"); - return false; - } - } - // Open the X/Y Plot file - try - { - XYPlotFile = File.OpenRead(FileName); - } - catch (Exception e) - { - if (!BaseLnSettings.blBaseLine) // B2026-056 suppress messages when running baseline. - { - // cannot open the x/y plot file - MessageBox.Show(e.Message, String.Format("Error Opening {0} for Reading", FileName)); - return false; - } - } - int blen = (int)XYPlotFile.Length; - int bread = 0; - // initialize a byte array to read into - byte[] bbuf = new byte[blen + 1]; - for (int i = 0; i < blen; i++) bbuf[i] = 0; - // Read the contents of the x/y plot file into the byte array - try - { - bread = XYPlotFile.Read(bbuf, 0, blen); - } - catch (Exception e) - { - if (!BaseLnSettings.blBaseLine) // B2026-056 suppress messages when running baseline. - { - MessageBox.Show(e.Message, String.Format("Error Reading {0}", FileName)); - return false; - } - } - try - { - XYPlotFile.Close(); - } - catch (Exception e) - { - if (!BaseLnSettings.blBaseLine) // B2026-056 suppress messages when running baseline. - { - MessageBox.Show(e.Message, String.Format("Error Closing {0}", FileName)); - return false; - } - } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bbuf.Length; i++) - { - if (bbuf[i] == '\r' && bbuf[i - 1] == ' ') - sb.Remove(i - 1, 1); - sb.Append(Convert.ToChar(bbuf[i])); - } - Buff = sb.ToString(); - BuffPtr = 0; - return true; - } private void LoadBuffFromString(string str) => Buff = str; private int getint() { @@ -356,9 +289,11 @@ namespace XYPlots public string XYPlotIssue { get; set; } private point GetPair(int flag) { - point retval = new point(); - retval.xyValue = new int[Dimensions]; - double x, y; + point retval = new point + { + xyValue = new int[Dimensions] + }; + double x, y; char[] sepchar = { ',' }; string nextPiece = NextPiece(); // Plot Definition string[] xystr = nextPiece.Split(sepchar); @@ -413,7 +348,7 @@ namespace XYPlots if (retval == ' ') { Lbuff.Append('\n'); - retval = NextChar(); + _ = NextChar(); retval = NextChar(); } break; @@ -484,7 +419,7 @@ namespace XYPlots if (LinesUsed == 0) LinesUsed = (int)(1.5 * CHIGHDOTS); /* adjust for x axis tics */ LinesUsed += printerunits[Y]; - LinesUsed = LinesUsed / CHIGHDOTS; + LinesUsed /= CHIGHDOTS; } private void GetScaleInfo() { @@ -560,24 +495,27 @@ namespace XYPlots } private point DetermineBoxMax(XyBox boxptr) { - point newval = new point(); - newval.xyValue = new int[Dimensions]; - string tmp; + point newval = new point + { + xyValue = new int[Dimensions] + }; + string tmp; int pos = 0, prevPos = 0; - int nl = 0, xmax = 0, ilen = 0; - tmp = stripSuperSub(boxptr.BoxText); + int nl = 0, xmax = 0; + tmp = stripSuperSub(boxptr.BoxText); tmp = tmp.Replace("\r\n", "\n"); - while ((pos = tmp.IndexOf('\n', pos)) > -1) - { - ilen = pos - prevPos; - xmax = Math.Max(xmax, ilen); - // OLD: prevPos = pos; - prevPos = pos + 1; - pos++; - nl++; - } - // OLD: ilen = tmp.Substring(prevPos + 1).Length; - ilen = tmp.Length - prevPos; // tmp.Substring(prevPos).Length; + int ilen; + while ((pos = tmp.IndexOf('\n', pos)) > -1) + { + ilen = pos - prevPos; + xmax = Math.Max(xmax, ilen); + // OLD: prevPos = pos; + prevPos = pos + 1; + pos++; + nl++; + } + // OLD: ilen = tmp.Substring(prevPos + 1).Length; + ilen = tmp.Length - prevPos; // tmp.Substring(prevPos).Length; xmax = Math.Max(xmax, ilen) + 2; newval.xyValue[X] = boxptr.BoxMinimum.xyValue[X] + (xmax * CWIDEDOTS); // OLD: newval.xyValue[Y] = boxptr.BoxMinimum.xyValue[Y] - (nl * CHIGHDOTS) - (int)(30 * ConvertToTwips); @@ -596,11 +534,15 @@ namespace XYPlots NewBox.Shadow = ShadowFlag; ShadowFlag = 0; NewBox.BoxMaximum = DetermineBoxMax(NewBox); - point minPoint = new point(); - minPoint.xyValue = new int[Dimensions]; - point maxPoint = new point(); - maxPoint.xyValue = new int[Dimensions]; - minPoint.xyValue[X] = Origin.xyValue[X]; + point minPoint = new point + { + xyValue = new int[Dimensions] + }; + point maxPoint = new point + { + xyValue = new int[Dimensions] + }; + minPoint.xyValue[X] = Origin.xyValue[X]; minPoint.xyValue[Y] = NewBox.BoxMaximum.xyValue[Y]; maxPoint.xyValue[X] = NewBox.BoxMaximum.xyValue[X]; maxPoint.xyValue[Y] = Origin.xyValue[Y]; @@ -618,9 +560,11 @@ namespace XYPlots pointcount = EndFlag = 0; while (EndFlag == 0) { - DataPoint pl = new DataPoint(); - pl.APoint = new point(); - pl.APoint = GetPair(PLOT); + DataPoint pl = new DataPoint + { + APoint = new point() + }; + pl.APoint = GetPair(PLOT); pointcount++; dataPoints.Add(pl); } @@ -662,7 +606,6 @@ namespace XYPlots DataPoint thispt, prevpt, firstpt; long yval, y1, y3; int PlAryIdx = 0; - int PlAryNumItems = dataPoints.Count; prevpt = dataPoints[PlAryIdx]; PlAryIdx++; thispt = dataPoints[PlAryIdx]; @@ -684,11 +627,13 @@ namespace XYPlots } private void AddAPlot(DataPoints ptr) { - PlotLine NewLine = new PlotLine(); - NewLine.PlotType = LineFlag; - NewLine.PlotDivisions = LineDiv; - NewLine.PlotDataPoints = ptr; - AllPlots.Insert(0, NewLine); + PlotLine NewLine = new PlotLine + { + PlotType = LineFlag, + PlotDivisions = LineDiv, + PlotDataPoints = ptr + }; + AllPlots.Insert(0, NewLine); } private void GenerateGrid(VG.Page pg, IVGOutput vgOutput) { @@ -899,7 +844,7 @@ namespace XYPlots { int tlen; powerstring = string.Format("x10{0}{1}{2}", SuperScript[0], i.ToString(), SuperScript[1]); - valuestring = valuestring + powerstring; + valuestring += powerstring; tlen = SuperScript[0].Length + SuperScript[1].Length; return (powerstring.Length - tlen); } @@ -917,7 +862,9 @@ namespace XYPlots LinesUsed += (3 * CHIGHDOTS); AxisTitles[X] = null; } - if ((AxisTitles[Y] != null) && (len = AxisTitles[Y].Length) > 0) +#pragma warning disable IDE0059 // Unnecessary assignment of a value + //Keeping len = AxisTitles[Y].Length for Debugging + if ((AxisTitles[Y] != null) && (len = AxisTitles[Y].Length) > 0) { if (YLandScape > 0) { @@ -938,7 +885,8 @@ namespace XYPlots } AxisTitles[Y] = null; } - RecallPosition(); +#pragma warning restore IDE0059 // Unnecessary assignment of a value + RecallPosition(); } private void DoBoxes(VG.Page pg, IVGOutput vgOutput) { @@ -1040,9 +988,11 @@ namespace XYPlots } private point FindModifiedCenter(double rprime, point PtOnArc, double ang) { - point newcenter = new point(); - newcenter.xyValue = new int[Dimensions]; - newcenter.xyValue[X] = (int)(PtOnArc.xyValue[X] - rprime * cos_deg(ang)); + point newcenter = new point + { + xyValue = new int[Dimensions] + }; + newcenter.xyValue[X] = (int)(PtOnArc.xyValue[X] - rprime * cos_deg(ang)); newcenter.xyValue[Y] = (int)(PtOnArc.xyValue[Y] - rprime * sin_deg(ang)); return (newcenter); } @@ -1060,9 +1010,11 @@ namespace XYPlots x2 = pt2.APoint.xyValue[X]; y2 = pt2.APoint.xyValue[Y]; midpt = new DataPoint(); - pt = new point(); - pt.xyValue = new int[Dimensions]; - so = FindSlope(pt1.APoint, pt2.APoint); + pt = new point + { + xyValue = new int[Dimensions] + }; + so = FindSlope(pt1.APoint, pt2.APoint); midpt.slope = (4.0 * so - pt1.slope - pt2.slope) / 2.0; pt.xyValue[X] = x1 + (x2 - x1) / 2; pt.xyValue[Y] = y1 + (y2 - y1) / 2; @@ -1173,9 +1125,11 @@ namespace XYPlots double c1, c2, s1, s2; double t3a, t4a; point cp1, cp2; - t3 = FixAngle(t3a=GetAngle(pt1.slope)); - t4 = FixAngle(t4a=GetAngle(pt2.slope)); - thetaa = GetAngleBetweenPoints(pt1.APoint, pt2.APoint); +#pragma warning disable IDE0059 // Unnecessary assignment of a value - Keeping t3a,t4a for Debugging + t3 = FixAngle(t3a=GetAngle(pt1.slope)); + t4 = FixAngle(t4a=GetAngle(pt2.slope)); +#pragma warning restore IDE0059 // Unnecessary assignment of a value + thetaa = GetAngleBetweenPoints(pt1.APoint, pt2.APoint); if ((t3 - thetaa) * (t4 - thetaa) >= 0.0) { double tprime; @@ -1417,7 +1371,6 @@ namespace XYPlots y = Position[Y] - pty; DrawGridRelative(x, y, pg, vgOutput); } - private void relval(string ptr, int i) => ptr = string.Format("+{0}", i.ToString()); private void MoveRelative(int x, int y) { Position[X] += x; @@ -1450,7 +1403,6 @@ namespace XYPlots private void DrawArc(double radius, double Sangle, double Eangle, point cp, int x, int y, VG.Page pg, IVGOutput vgOutput) { DebugOutput("r={0} sAngle={1} eAngle={2} cp={3},{4} x={5} y={6}", radius, Sangle, Eangle, cp.xyValue[0], cp.xyValue[1], x, y); - int dx, dy; long radchk; radchk = (long)radius; if (radchk > 72000L) @@ -1458,8 +1410,9 @@ namespace XYPlots DrawAbsolute(x, y, pg, vgOutput); return; } - dx = x - cp.xyValue[X]; //jj - dy = Math.Abs(cp.xyValue[Y] - Position[Y]); //jj + //For Debugging + //int dx = x - cp.xyValue[X]; //jj + //int dy = Math.Abs(cp.xyValue[Y] - Position[Y]); //jj float x1 = cp.xyValue[X] - (float)radius; float y1 = cp.xyValue[Y] - (float)radius; float w1 = (float)radius * 2; @@ -1648,9 +1601,8 @@ namespace XYPlots else if (wn > DPI / 5) dn = dd / 5; else dn = dd / 2; GenGrid(flag, n - dd, n, dn, wn, lw - 1, val, pg, vgOutput); - wn = 0; - } - val = valn; + } + val = valn; if (flag == Y) val = printerunits[Y] - val; //jj MoveAbsolute((flag == X ? val : 0), (flag == Y ? val : 0)); @@ -1763,72 +1715,72 @@ namespace XYPlots // - break up the string (if needed) and change the font pitch // for the text that is to be super/subscripted VG_Text drawText; - string tstr = ""; - int Xpos, Ypos; - int sidx = 0; // beginning of string + int Xpos, Ypos; + int sidx = 0; // beginning of string int idx = 0; // current position in string Xpos = Position[X]; Ypos = Position[Y]; - while (idx < txt.Length) - { - int tidx; - if ((tidx = txt.IndexOf(SuperScript[0], idx)) > -1) - { - // print text up to the superscript - tstr = txt.Substring(sidx, tidx - sidx); - drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); - drawText.Draw(vgOutput); - Xpos += (CWIDEDOTS * tstr.Length); - tidx += SuperScript[0].Length; - idx = tidx; - sidx = idx; - tidx = txt.IndexOf(SuperScript[1], idx); - if (tidx > 0) - { - // switch font pitch, move up some, and print the superscript text - tstr = txt.Substring(sidx, tidx - sidx); - Ypos -= (CHIGHDOTS / 2); // move up half a char heigth - drawText = new VG_Text(Xpos, Ypos, (int)(FontPitch / 2), tstr, MyFontFamily, "", "", "", pg); - drawText.Draw(vgOutput); - Ypos += (CHIGHDOTS / 2); // move back down - Xpos += ((CWIDEDOTS / 2) * tstr.Length); // positon half the width of the string - tidx += SuperScript[1].Length; - idx = tidx; - sidx = idx; - continue; // go back to beginning of while loop - } - } - else if ((tidx = txt.IndexOf(SubScript[0], idx)) > -1) - { - // print text up to the superscript - tstr = txt.Substring(sidx, tidx - sidx); - drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); - drawText.Draw(vgOutput); - Xpos += (CWIDEDOTS * tstr.Length); - tidx += SubScript[0].Length; - idx = tidx; - sidx = idx; - tidx = txt.IndexOf(SubScript[1], idx); - if (tidx > 0) - { - // switch font pitch, move up some, and print the superscript text - tstr = txt.Substring(sidx, tidx - sidx); - drawText = new VG_Text(Xpos, Ypos, (int)(FontPitch / 2), tstr, MyFontFamily, "", "", "", pg); - drawText.Draw(vgOutput); - Xpos += ((CWIDEDOTS / 2) * tstr.Length); // positon half the width of the string - tidx += SubScript[1].Length; - idx = tidx; - sidx = idx; - continue; // go back to beginning of while loop - } - } - else - { - idx++; - } - } // end while + string tstr; + while (idx < txt.Length) + { + int tidx; + if ((tidx = txt.IndexOf(SuperScript[0], idx)) > -1) + { + // print text up to the superscript + tstr = txt.Substring(sidx, tidx - sidx); + drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Xpos += (CWIDEDOTS * tstr.Length); + tidx += SuperScript[0].Length; + idx = tidx; + sidx = idx; + tidx = txt.IndexOf(SuperScript[1], idx); + if (tidx > 0) + { + // switch font pitch, move up some, and print the superscript text + tstr = txt.Substring(sidx, tidx - sidx); + Ypos -= (CHIGHDOTS / 2); // move up half a char heigth + drawText = new VG_Text(Xpos, Ypos, (int)(FontPitch / 2), tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Ypos += (CHIGHDOTS / 2); // move back down + Xpos += ((CWIDEDOTS / 2) * tstr.Length); // positon half the width of the string + tidx += SuperScript[1].Length; + idx = tidx; + sidx = idx; + continue; // go back to beginning of while loop + } + } + else if ((tidx = txt.IndexOf(SubScript[0], idx)) > -1) + { + // print text up to the superscript + tstr = txt.Substring(sidx, tidx - sidx); + drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Xpos += (CWIDEDOTS * tstr.Length); + tidx += SubScript[0].Length; + idx = tidx; + sidx = idx; + tidx = txt.IndexOf(SubScript[1], idx); + if (tidx > 0) + { + // switch font pitch, move up some, and print the superscript text + tstr = txt.Substring(sidx, tidx - sidx); + drawText = new VG_Text(Xpos, Ypos, (int)(FontPitch / 2), tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Xpos += ((CWIDEDOTS / 2) * tstr.Length); // positon half the width of the string + tidx += SubScript[1].Length; + idx = tidx; + sidx = idx; + continue; // go back to beginning of while loop + } + } + else + { + idx++; + } + } // end while - if (sidx < txt.Length) + if (sidx < txt.Length) { tstr = txt.Substring(sidx); drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); @@ -1943,7 +1895,9 @@ namespace XYPlots throw new Exception(String.Format("X/Y Plot Error - {0} - {1}",step,XYPlotIssue ?? "Unknown Issue")); } } - private void ShowPoints(DataPoints dataPoints) + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Kept for Debugging")] + private void ShowPoints(DataPoints dataPoints) { //#if DEBUG //foreach (DataPoint pl in dataPoints) @@ -1953,7 +1907,8 @@ namespace XYPlots //#endif } public static string Key = ""; - private void DebugOutput(string format, params object[] args) + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping args for future use/Debugging")] + private void DebugOutput(string format, params object[] args) { //#if DEBUG //if (args.Length == 0) @@ -1961,7 +1916,8 @@ namespace XYPlots //Console.WriteLine(format, args); //#endif } - private void DebugShowLocation(string command) + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping command for Debugging")] + private void DebugShowLocation(string command) { //Console.WriteLine("'{0}',{1},{2}", command, Position[X], Position[Y]); }