Print Library, Svg Library, Utils Library, XYPlots
This commit is contained in:
+62
-165
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
@@ -18,36 +17,19 @@ namespace XYPlots
|
||||
#region Log4Net
|
||||
// C2018-035 Added error Handling to provide more useful information when a plot fails
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#endregion
|
||||
static string _MyFontFamily = "Letter Gothic Tall";
|
||||
public static string MyFontFamily
|
||||
{
|
||||
get { return _MyFontFamily; }
|
||||
set { _MyFontFamily = value; }
|
||||
}
|
||||
private static Color _BlackColor = Color.Red;
|
||||
#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; }
|
||||
set { VG.VG.BlackColor = value; }
|
||||
}
|
||||
public float Width
|
||||
{
|
||||
get { return 72 * (LeftMargin + RightMargin) + printerunits[0] * .05F; }
|
||||
}
|
||||
public float Height
|
||||
{
|
||||
get { return 72 * (TopMargin + BottomMargin) + printerunits[1] * .05F; }
|
||||
}
|
||||
public float PlotWidth
|
||||
{
|
||||
get { return (float) userunits[X]; }
|
||||
}
|
||||
public float PlotHeight
|
||||
{
|
||||
get { return (float) userunits[Y]; }
|
||||
}
|
||||
private double ConvertToTwips = 4.8;
|
||||
public float Width => 72 * (LeftMargin + RightMargin) + printerunits[0] * .05F;
|
||||
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;
|
||||
@@ -146,7 +128,7 @@ namespace XYPlots
|
||||
private bool[,] doLOG10 = { { false, false }, { false, false } };
|
||||
public struct point
|
||||
{
|
||||
public int[] xyValue; //new int[Dimensions];
|
||||
public int[] xyValue;
|
||||
}
|
||||
public struct XyBox
|
||||
{
|
||||
@@ -162,23 +144,17 @@ namespace XYPlots
|
||||
private XyBoxes ActiveBoxes = new XyBoxes();
|
||||
public class DataPoint
|
||||
{
|
||||
public override string ToString() // Make it easier to Debug
|
||||
{
|
||||
return string.Format("{0},{1}", APoint.xyValue[X],APoint.xyValue[Y]);
|
||||
}
|
||||
private point m_APoint;
|
||||
// Make it easier to Debug
|
||||
public override string ToString() => string.Format("{0},{1}", APoint.xyValue[X], APoint.xyValue[Y]);
|
||||
private point m_APoint;
|
||||
public point APoint
|
||||
{
|
||||
get { return m_APoint; }
|
||||
set { m_APoint = value; }
|
||||
}
|
||||
private double m_slope; // slope of tangent to circle at this point
|
||||
public double slope
|
||||
{
|
||||
get { return m_slope; }
|
||||
set { m_slope = value; }
|
||||
}
|
||||
}
|
||||
|
||||
public double slope { get; set; }
|
||||
}
|
||||
public class DataPoints : List<DataPoint>
|
||||
{
|
||||
}
|
||||
@@ -211,41 +187,20 @@ namespace XYPlots
|
||||
result = (double)(val * val);
|
||||
return result;
|
||||
}
|
||||
private double FMin(double f1, double f2)
|
||||
{
|
||||
return ((f1 >= f2) ? f2 : f1);
|
||||
}
|
||||
private double FMax(double f1, double f2)
|
||||
{
|
||||
return ((f1 >= f2) ? f1 : f2);
|
||||
}
|
||||
private double atan_deg(double x)
|
||||
{
|
||||
return (Math.Atan(x) * 180.0 / PI);
|
||||
}
|
||||
private double cos_deg(double x)
|
||||
{
|
||||
return (Math.Cos(x * PI / 180.0));
|
||||
}
|
||||
private double tan_deg(double x)
|
||||
{
|
||||
return (Math.Tan(x * PI / 180.0));
|
||||
}
|
||||
private double sin_deg(double x)
|
||||
{
|
||||
return (Math.Sin(x * PI / 180.0));
|
||||
}
|
||||
/// <summary>
|
||||
/// the following function is pointed to by a function pointer
|
||||
/// and is provided for compatibility with log10() function usage
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <returns></returns>
|
||||
private double linear(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
private bool isWhiteSpace(char cptr)
|
||||
private double FMin(double f1, double f2) => ((f1 >= f2) ? f2 : f1);
|
||||
private double FMax(double f1, double f2) => ((f1 >= f2) ? f1 : f2);
|
||||
private double atan_deg(double x) => (Math.Atan(x) * 180.0 / PI);
|
||||
private double cos_deg(double x) => (Math.Cos(x * PI / 180.0));
|
||||
private double tan_deg(double x) => (Math.Tan(x * PI / 180.0));
|
||||
private double sin_deg(double x) => (Math.Sin(x * PI / 180.0));
|
||||
/// <summary>
|
||||
/// the following function is pointed to by a function pointer
|
||||
/// and is provided for compatibility with log10() function usage
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <returns></returns>
|
||||
private double linear(double x) => x;
|
||||
private bool isWhiteSpace(char cptr)
|
||||
{
|
||||
bool rtnval = false;
|
||||
if (!cptr.Equals(null))
|
||||
@@ -332,11 +287,8 @@ namespace XYPlots
|
||||
BuffPtr = 0;
|
||||
return true;
|
||||
}
|
||||
private void LoadBuffFromString(string str)
|
||||
{
|
||||
Buff = str;
|
||||
}
|
||||
private int getint()
|
||||
private void LoadBuffFromString(string str) => Buff = str;
|
||||
private int getint()
|
||||
{
|
||||
int retval;
|
||||
string np = NextPiece();
|
||||
@@ -381,26 +333,15 @@ namespace XYPlots
|
||||
retval = Convert.ToDouble(NextPiece());
|
||||
return retval;
|
||||
}
|
||||
private char NextChar()
|
||||
{
|
||||
return Buff[BuffPtr++];
|
||||
}
|
||||
private char getchr()
|
||||
private char NextChar() => Buff[BuffPtr++];
|
||||
private char getchr()
|
||||
{
|
||||
string nxtstring = NextPiece();
|
||||
if (nxtstring.Equals(""))
|
||||
return '\0';
|
||||
else
|
||||
return nxtstring[0];
|
||||
}
|
||||
// C2018-035 Added error Handling to provide more useful information when a plot fails
|
||||
private string _XYPlotIssue;
|
||||
public string XYPlotIssue
|
||||
{
|
||||
get { return _XYPlotIssue; }
|
||||
set { _XYPlotIssue = value; }
|
||||
}
|
||||
private point GetPair(int flag)
|
||||
return nxtstring.Equals("") ? '\0' : nxtstring[0];
|
||||
}
|
||||
|
||||
public string XYPlotIssue { get; set; }
|
||||
private point GetPair(int flag)
|
||||
{
|
||||
point retval = new point();
|
||||
retval.xyValue = new int[Dimensions];
|
||||
@@ -489,7 +430,6 @@ namespace XYPlots
|
||||
Buff = Buff.Substring(4);
|
||||
}
|
||||
// remove an extra spaces between ><
|
||||
//Buff = Regex.Replace(Buff, @"[ ]+<", "<");
|
||||
Buff = Buff.Replace(">\r ", ">\r\n ");
|
||||
Buff = Buff.Replace(">\n ", ">\r\n "); // C2022-003 if RO has symbols
|
||||
Buff = Regex.Replace(Buff, @"[ ]+<", "<");
|
||||
@@ -595,11 +535,8 @@ namespace XYPlots
|
||||
Offset[PLOT, Y] = -Scale[PLOT, Y] * Math.Log10(minimum[Y]);
|
||||
}
|
||||
}
|
||||
private void GetAxisTitle(int flag)
|
||||
{
|
||||
AxisTitles[flag] = GetString();
|
||||
}
|
||||
private string stripSuperSub(string instr)
|
||||
private void GetAxisTitle(int flag) => AxisTitles[flag] = GetString();
|
||||
private string stripSuperSub(string instr)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(instr);
|
||||
sb.Replace(SuperScript[0], "");
|
||||
@@ -749,27 +686,14 @@ namespace XYPlots
|
||||
SetPenDiameter(5);
|
||||
BoxRelative(printerunits[X], printerunits[Y], CurPenWidth, pg, vgOutput);
|
||||
if (GridOnFlag == 0) Visible = 0;
|
||||
//if (vgOutput is VGOut_Graphics)
|
||||
//{
|
||||
DoGrid(X, pg, vgOutput, 1);
|
||||
DoGrid(Y, pg, vgOutput, 1);
|
||||
DoGrid(X, pg, vgOutput, 2);
|
||||
DoGrid(Y, pg, vgOutput, 2);
|
||||
DoGrid(X, pg, vgOutput, 3);
|
||||
DoGrid(Y, pg, vgOutput, 3);
|
||||
//}
|
||||
//else if (vgOutput is VGOut_C1PDF)
|
||||
//{
|
||||
// DrawDirection = Y;
|
||||
// DoGrid(X, pg, vgOutput);
|
||||
// DrawDirection = X;
|
||||
// DoGrid(Y, pg, vgOutput);
|
||||
//}
|
||||
DoGrid(X, pg, vgOutput, 1);
|
||||
DoGrid(Y, pg, vgOutput, 1);
|
||||
DoGrid(X, pg, vgOutput, 2);
|
||||
DoGrid(Y, pg, vgOutput, 2);
|
||||
DoGrid(X, pg, vgOutput, 3);
|
||||
DoGrid(Y, pg, vgOutput, 3);
|
||||
Visible = 1;
|
||||
RecallPosition();
|
||||
// Draw outline last to overlap any grid lines.
|
||||
//SetPenDiameter(5);
|
||||
//BoxRelative(printerunits[X], printerunits[Y], CurPenWidth, pg, vgOutput);
|
||||
}
|
||||
private void DoGrid(int flag, VG.Page pg, IVGOutput vgOutput)
|
||||
{
|
||||
@@ -890,7 +814,7 @@ namespace XYPlots
|
||||
{
|
||||
if (!SubLogValue)
|
||||
DrawGridRelative((int)(-30 * ConvertToTwips), 0, pg, vgOutput);
|
||||
// OLD: MoveRelative((int)(-(15 + 300 * size / (int)FontPitch) * ConvertToTwips), (int)(-15 * ConvertToTwips));
|
||||
|
||||
MoveRelative((int)(-(14 + 250 * size / (int)FontPitch) * ConvertToTwips), (int)(-16 * ConvertToTwips));
|
||||
if ((AxisLabel[1]) != 0)
|
||||
{
|
||||
@@ -1438,11 +1362,8 @@ namespace XYPlots
|
||||
CurPenWidth = (int)(pd * ConvertToTwips);
|
||||
}
|
||||
}
|
||||
private void PrintStackError(string relation, int limit)
|
||||
{
|
||||
MessageBox.Show(String.Format("Position Stack Pointer {0} {1}", relation, limit.ToString()), "Print Stack Error");
|
||||
}
|
||||
private void SavePosition()
|
||||
private void PrintStackError(string relation, int limit) => MessageBox.Show(String.Format("Position Stack Pointer {0} {1}", relation, limit.ToString()), "Print Stack Error");
|
||||
private void SavePosition()
|
||||
{
|
||||
if (stack >= MAX_XY_STACK) PrintStackError(">=", MAX_XY_STACK);
|
||||
SavedX[stack] = Position[X];
|
||||
@@ -1454,15 +1375,9 @@ namespace XYPlots
|
||||
Position[X] = SavedX[--stack];
|
||||
Position[Y] = SavedY[stack];
|
||||
}
|
||||
private void MoveTo(point pnt)
|
||||
{
|
||||
MoveAbsolute(pnt.xyValue[X], pnt.xyValue[Y]);
|
||||
}
|
||||
private void DrawTo(point pnt, VG.Page pg, IVGOutput vgOutput)
|
||||
{
|
||||
DrawAbsolute(pnt.xyValue[X], pnt.xyValue[Y], pg, vgOutput);
|
||||
}
|
||||
private void MoveAbsolute(int ptx, int pty)
|
||||
private void MoveTo(point pnt) => MoveAbsolute(pnt.xyValue[X], pnt.xyValue[Y]);
|
||||
private void DrawTo(point pnt, VG.Page pg, IVGOutput vgOutput) => DrawAbsolute(pnt.xyValue[X], pnt.xyValue[Y], pg, vgOutput);
|
||||
private void MoveAbsolute(int ptx, int pty)
|
||||
{
|
||||
int x, y;
|
||||
x = ptx - Position[X];
|
||||
@@ -1483,11 +1398,8 @@ 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)
|
||||
private void relval(string ptr, int i) => ptr = string.Format("+{0}", i.ToString());
|
||||
private void MoveRelative(int x, int y)
|
||||
{
|
||||
Position[X] += x;
|
||||
Position[Y] -= y;
|
||||
@@ -1760,15 +1672,9 @@ namespace XYPlots
|
||||
GraphText(tstr.ToString(), pg, vgOutput);
|
||||
RecallPosition();
|
||||
}
|
||||
private void FreeBoxList()
|
||||
{
|
||||
AllBoxes.Clear();
|
||||
}
|
||||
private void FreeLineList()
|
||||
{
|
||||
AllPlots.Clear();
|
||||
}
|
||||
private void Init_Graphic_Vars()
|
||||
private void FreeBoxList() => AllBoxes.Clear();
|
||||
private void FreeLineList() => AllPlots.Clear();
|
||||
private void Init_Graphic_Vars()
|
||||
{
|
||||
int i;
|
||||
SavedX = new int[MAX_XY_STACK];
|
||||
@@ -1923,19 +1829,10 @@ namespace XYPlots
|
||||
//VG.VG_Arc.iColor = 0;
|
||||
//#endif
|
||||
}
|
||||
private int _OffsetX = 0;
|
||||
public int OffsetX
|
||||
{
|
||||
get { return _OffsetX; }
|
||||
set { _OffsetX = value; }
|
||||
}
|
||||
private int _OffsetY = 0;
|
||||
public int OffsetY
|
||||
{
|
||||
get { return _OffsetY; }
|
||||
set { _OffsetY = value; }
|
||||
}
|
||||
public void Setup()
|
||||
|
||||
public int OffsetX { get; set; } = 0;
|
||||
public int OffsetY { get; set; } = 0;
|
||||
public void Setup()
|
||||
{
|
||||
char Command, PrevCommand = ' ';
|
||||
Init_Graphic_Vars();
|
||||
@@ -2014,7 +1911,7 @@ namespace XYPlots
|
||||
step = "FreeLineList";FreeLineList();
|
||||
step = "CloseGraph";CloseGraph();
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
_MyLog.WarnFormat("X/Y Plot Error - {0} - {1} - {2}", step, XYPlotIssue ?? "Unknown Issue");
|
||||
throw new Exception(String.Format("X/Y Plot Error - {0} - {1}",step,XYPlotIssue ?? "Unknown Issue"));
|
||||
|
||||
Reference in New Issue
Block a user